Skip to content

Commit

Permalink
fix: πŸ› align client contracts to work in the same way (#66)
Browse files Browse the repository at this point in the history
* fix: πŸ› align clinet contracts to works in the same way

Add CLIENT_FOLDER variable to makefile in case different contracts need to be used other than the general one;
context is loaded during the request phase instead of the pubkeys creation phase;

* fix(clinet): πŸ› remove did_spec from issuer did-settings.json

This lead to collision in zenroom input during make commands

* test(units): 🚨 update test to latest client contracts modification

* fix(bindings): πŸ› update js binding to latest client contracts modification
  • Loading branch information
matteo-cristino authored Jan 18, 2024
1 parent 41aa62b commit 1a10830
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 27 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ RR_SCHEMA := https
HOSTNAME := $(shell hostname)
DOMAIN ?= sandbox
REQUEST ?= did_doc.json
CLIENT_FOLDER ?= ""

$(info __/________/__________/)
$(info / did / ο½„ο½™ο½Žο½… /)
Expand All @@ -23,14 +24,14 @@ keyring: CONTROLLER ?= ${USER}@${HOSTNAME}
keyring: ## Generate a new admin keyring [ OUT, CONTROLLER ]
$(if $(wildcard ${OUT}),$(error Local authority ${OUT} found, cannot overwrite))
@echo "{\"controller\": \"${CONTROLLER}\"}" > ${tmp}
@zenroom -z -k ${tmp} client/v1/create-keyring.zen > ${OUT} || rm ${OUT}
@zenroom -z -k ${tmp} client/v1/${CLIENT_FOLDER}create-keyring.zen > ${OUT} || rm ${OUT}
@rm -f ${tmp}

request: KEYRING ?= secrets/keyring.json
request: OUT ?= did_doc.json
request: DOMAIN ?= sandbox
request: ## Generate an admin request [ DOMAIN, KEYRING ]
@sh ./scripts/req.sh ${DOMAIN} ${KEYRING} > ${OUT}
@sh ./scripts/req.sh ${DOMAIN} ${KEYRING} ${CLIENT_FOLDER} > ${OUT}

sign: tmp := $(shell mktemp)
sign: REQUEST ?= did_doc.json
Expand Down
20 changes: 10 additions & 10 deletions bindings/javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,29 @@ const prepareZencodeKeyring = (
}

const preparePks = async (
requestKeyring: ControllerKeyring,
additionalData: string
requestKeyring: ControllerKeyring
) :Promise<string> => {
const contractPks = readFromFile('client/v1/create-identity-pubkeys.zen');
const data = readFromFile(additionalData);
const keys = prepareZencodeKeyring(requestKeyring);
let {result} = await zencode_exec(contractPks, {data, keys});
let {result} = await zencode_exec(contractPks, {data: "{}", keys});
return result;
}

const prepareRequest= async (
requestDomain: string,
requestType: string,
data: string,
settings: string,
contractPath: string
) :Promise<string> => {
const keys = readFromFile(settings);
data = JSON.parse(data);
data["did_spec"] = requestDomain;
data = JSON.stringify(data);
let res: string = null;
if (requestType == DidActions.CREATE || requestType == DidActions.UPDATE) {
const contractRequest = readFromFile(contractPath);
const {result} = await zencode_exec(contractRequest, {data, keys : "{}"});
const {result} = await zencode_exec(contractRequest, {data, keys});
res = result;
} else if (requestType == DidActions.DEACTIVATE) {
const id = `did:dyne:${requestDomain}:${JSON.parse(data)["eddsa_public_key"]}`;
Expand Down Expand Up @@ -128,8 +128,8 @@ export const createRequest = async (
requestDomain: string,
requestType: DidActions
) :Promise<DidRequest> => {
const data = await preparePks(requestKeyring, "client/v1/did-settings.json");
const result = await prepareRequest(requestDomain, requestType, data, "client/v1/pubkeys-request-unsigned.zen");
const data = await preparePks(requestKeyring);
const result = await prepareRequest(requestDomain, requestType, data, "client/v1/did-settings.json", "client/v1/pubkeys-request-unsigned.zen");
return JSON.parse(result).request;
}

Expand All @@ -147,11 +147,11 @@ export const createIfacerRequest = async (
requestType: DidActions,
requestIdentifier: string,
) :Promise<DidRequest> => {
let data = await preparePks(requestKeyring, "client/v1/ifacer/did-settings.json");
let data = await preparePks(requestKeyring);
const dataDict = JSON.parse(data);
dataDict.identifier = requestIdentifier;
data = JSON.stringify(dataDict);
const result = await prepareRequest(requestDomain, requestType, data, "client/v1/ifacer/pubkeys-request-unsigned.zen");
const result = await prepareRequest(requestDomain, requestType, data, "client/v1/ifacer/did-settings.json", "client/v1/ifacer/pubkeys-request-unsigned.zen");
return JSON.parse(result).request;
}

Expand Down Expand Up @@ -191,4 +191,4 @@ export const sendRequest = async (
{ data: request, keys: "{}"}
)
return res.data;
}
}
4 changes: 0 additions & 4 deletions client/v1/create-identity-pubkeys.zen
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Scenario reflow

Given my name is in a 'string' named 'controller'
and I have my 'keyring'
and I have a 'string array' named '@context'
and I have a 'string dictionary' named 'proof'

When I create the ecdh public key
and I create the eddsa public key
Expand All @@ -21,5 +19,3 @@ and I print the 'ecdh public key' as 'base58'
and I print the 'bitcoin public key' as 'base58'
and I print the 'reflow public key' as 'base58'
and I print my name in 'identity'
and print the '@context'
and print the 'proof'
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"did_spec": "sandbox.genericissuer",
"@context": [
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/suites/ed25519-2018/v1",
Expand Down
13 changes: 8 additions & 5 deletions scripts/req.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,33 @@ keyring=secrets/keyring.json
[ "$1" = "" ] && { >&2 echo "$0 spec"; exit 1;}
[ "$2" = "" ] || keyring="$2"

contracts=client/v1
contracts="client/v1/$3"

# different specs can have different did-settings
case $1 in
ifacer*)
did_settings=client/v1/ifacer/did-settings.json
;;
sandbox.genericissuer*)
did_settings=client/v1/issuer/did-settings.json
;;
*)
did_settings=client/v1/did-settings.json
;;
esac

# generate pks
tmppk=`mktemp`
zenroom -z -k "$keyring" -a ${did_settings} \
${contracts}/create-identity-pubkeys.zen > ${tmppk}
zenroom -z -k "$keyring" \
${contracts}create-identity-pubkeys.zen > ${tmppk}

# set did_spec and extras if present
tmp=`mktemp` &&
jq --arg value $1 '.did_spec = $value' ${tmppk} > ${tmp} &&
mv ${tmp} ${tmppk}

# create did doc
zenroom -z -a ${tmppk} \
${contracts}/pubkeys-request-unsigned.zen
zenroom -z -a ${tmppk} -k ${did_settings} \
${contracts}pubkeys-request-unsigned.zen

rm -f ${tmppk}
8 changes: 5 additions & 3 deletions test/restroom/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ create_admin() {
[ "$2" != "" ] && out=$2
tmpctrl=`mktemp`
tmperr=`mktemp`
tmp=`mktemp`
echo "{\"controller\": \"test_admin\"}" > ${tmpctrl}
zenroom -z -k ${tmpctrl} client/v1/create-keyring.zen >secrets/$1 2>${tmperr}
check_error ${?} ${tmperr}
rm -f ${tmpctrl}
zenroom -z -k secrets/$1 -a client/v1/did-settings.json client/v1/create-identity-pubkeys.zen >${tmpctrl} 2>${tmperr}
zenroom -z -k secrets/$1 client/v1/create-identity-pubkeys.zen >${tmpctrl} 2>${tmperr}
check_error ${?} ${tmperr}
cat ${tmpctrl} | jq --arg value $(($(date +%s%N)/1000000)) '.timestamp = $value' > ${tmpctrl}
zenroom -z -a ${tmpctrl} -k secrets/$1 client/v1/admin/didgen.zen >${out} 2>${tmperr}
jq -s '.[0] * .[1]' secrets/$1 client/v1/did-settings.json > ${tmp}
zenroom -z -a ${tmpctrl} -k ${tmp} client/v1/admin/didgen.zen >${out} 2>${tmperr}
check_error ${?} ${tmperr}
rm -f ${tmpctrl}
rm -f ${tmpctrl} ${tmp}
# store admin did
didpath=`jq -r '.didDocument.id' ${out}`
did=`echo ${didpath} | cut -d: -f4`
Expand Down
5 changes: 3 additions & 2 deletions test/zencode_units/pubkeys.bats
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ EOF
}

@test "Participant identity with pubkeys" {
zexe client/v1/create-identity-pubkeys.zen client/v1/did-settings.json new-keyring.json
zexe client/v1/create-identity-pubkeys.zen new-keyring.json
save_tmp_output new-id-pubkeys.json
# add did_spec and signer_did_spec to be used in all the following contratcs
jq_insert "did_spec" "sandbox.test" new-id-pubkeys.json
Expand All @@ -85,6 +85,7 @@ EOF

@test "Signed accept request" {
jq_insert "timestamp" $(($(date +%s%N)/1000000)) new-id-pubkeys.json
json_join_two client/v1/did-settings.json controller-keyring.json
zexe client/v1/pubkeys-request-signed.zen new-id-pubkeys.json controller-keyring.json
save_tmp_output signed-request.json
}
Expand Down Expand Up @@ -119,7 +120,7 @@ EOF
@test "Update request with request-unsigned and sign" {
# unsigned request
jq_insert "identity" "update_unit_test" new-id-pubkeys.json
zexe client/v1/pubkeys-request-unsigned.zen new-id-pubkeys.json
zexe client/v1/pubkeys-request-unsigned.zen new-id-pubkeys.json client/v1/did-settings.json
save_tmp_output unsigned-request.json
# sign the request
jq_insert "timestamp" $(($(date +%s%N)/1000000)) unsigned-request.json
Expand Down

0 comments on commit 1a10830

Please sign in to comment.