From b7f09561061117d4823c74749cf04201de374fb8 Mon Sep 17 00:00:00 2001 From: matteo-cristino Date: Thu, 18 Jan 2024 10:25:03 +0100 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20align=20clinet=20cont?= =?UTF-8?q?racts=20to=20works=20in=20the=20same=20way?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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; --- Makefile | 5 +++-- client/v1/create-identity-pubkeys.zen | 4 ---- .../{request_input.json => did-settings.json} | 0 scripts/req.sh | 13 ++++++++----- test/restroom/functions.sh | 8 +++++--- 5 files changed, 16 insertions(+), 14 deletions(-) rename client/v1/issuer/{request_input.json => did-settings.json} (100%) diff --git a/Makefile b/Makefile index 23ad49e..831cfd9 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ RR_SCHEMA := https HOSTNAME := $(shell hostname) DOMAIN ?= sandbox REQUEST ?= did_doc.json +CLIENT_FOLDER ?= "" $(info __/________/__________/) $(info / did / dyne /) @@ -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 diff --git a/client/v1/create-identity-pubkeys.zen b/client/v1/create-identity-pubkeys.zen index 5ce3895..0ec12bc 100644 --- a/client/v1/create-identity-pubkeys.zen +++ b/client/v1/create-identity-pubkeys.zen @@ -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 @@ -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' \ No newline at end of file diff --git a/client/v1/issuer/request_input.json b/client/v1/issuer/did-settings.json similarity index 100% rename from client/v1/issuer/request_input.json rename to client/v1/issuer/did-settings.json diff --git a/scripts/req.sh b/scripts/req.sh index 0fd288d..7c6f812 100755 --- a/scripts/req.sh +++ b/scripts/req.sh @@ -9,13 +9,16 @@ 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 ;; @@ -23,8 +26,8 @@ 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` && @@ -32,7 +35,7 @@ tmp=`mktemp` && 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} diff --git a/test/restroom/functions.sh b/test/restroom/functions.sh index d5dbfb3..f8037d5 100755 --- a/test/restroom/functions.sh +++ b/test/restroom/functions.sh @@ -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` From c40d287e611b5aa4022c662164652ee824b62fd1 Mon Sep 17 00:00:00 2001 From: matteo-cristino Date: Thu, 18 Jan 2024 10:35:39 +0100 Subject: [PATCH 2/4] =?UTF-8?q?fix(clinet):=20=F0=9F=90=9B=20remove=20did?= =?UTF-8?q?=5Fspec=20from=20issuer=20did-settings.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This lead to collision in zenroom input during make commands --- client/v1/issuer/did-settings.json | 1 - 1 file changed, 1 deletion(-) diff --git a/client/v1/issuer/did-settings.json b/client/v1/issuer/did-settings.json index f1678a8..675f04f 100644 --- a/client/v1/issuer/did-settings.json +++ b/client/v1/issuer/did-settings.json @@ -1,5 +1,4 @@ { - "did_spec": "sandbox.genericissuer", "@context": [ "https://www.w3.org/ns/did/v1", "https://w3id.org/security/suites/ed25519-2018/v1", From 0b50d025a642e506378f086f7c6c983e75c3b11c Mon Sep 17 00:00:00 2001 From: matteo-cristino Date: Thu, 18 Jan 2024 10:51:30 +0100 Subject: [PATCH 3/4] =?UTF-8?q?test(units):=20=F0=9F=9A=A8=20update=20test?= =?UTF-8?q?=20to=20latest=20client=20contracts=20modification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/zencode_units/pubkeys.bats | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/zencode_units/pubkeys.bats b/test/zencode_units/pubkeys.bats index 45e0278..f9a453d 100644 --- a/test/zencode_units/pubkeys.bats +++ b/test/zencode_units/pubkeys.bats @@ -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 @@ -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 } @@ -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 From c905da7290bf718781836b9fbf1e3fd187d2c252 Mon Sep 17 00:00:00 2001 From: matteo-cristino Date: Thu, 18 Jan 2024 11:08:40 +0100 Subject: [PATCH 4/4] =?UTF-8?q?fix(bindings):=20=F0=9F=90=9B=20update=20js?= =?UTF-8?q?=20binding=20to=20latest=20client=20contracts=20modification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bindings/javascript/src/index.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bindings/javascript/src/index.ts b/bindings/javascript/src/index.ts index 5e5666b..4ccabcf 100644 --- a/bindings/javascript/src/index.ts +++ b/bindings/javascript/src/index.ts @@ -68,13 +68,11 @@ const prepareZencodeKeyring = ( } const preparePks = async ( - requestKeyring: ControllerKeyring, - additionalData: string + requestKeyring: ControllerKeyring ) :Promise => { 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; } @@ -82,15 +80,17 @@ const prepareRequest= async ( requestDomain: string, requestType: string, data: string, + settings: string, contractPath: string ) :Promise => { + 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"]}`; @@ -128,8 +128,8 @@ export const createRequest = async ( requestDomain: string, requestType: DidActions ) :Promise => { - 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; } @@ -147,11 +147,11 @@ export const createIfacerRequest = async ( requestType: DidActions, requestIdentifier: string, ) :Promise => { - 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; } @@ -191,4 +191,4 @@ export const sendRequest = async ( { data: request, keys: "{}"} ) return res.data; -} \ No newline at end of file +}