From 42591a1a0808fc4cff685687b984a6af0f98f2bc Mon Sep 17 00:00:00 2001 From: volodymyr-basiuk <31999965+volodymyr-basiuk@users.noreply.github.com> Date: Wed, 10 Jul 2024 13:20:51 +0300 Subject: [PATCH] add support for privado network (#14) * add support for privado network --- .github/workflows/push-container.yaml | 8 +++++++ pkg/document/did.go | 9 ++++---- pkg/services/did.go | 20 +++++++++-------- .../http_nameservice.postman_collection.json | 22 ++++++------------- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/.github/workflows/push-container.yaml b/.github/workflows/push-container.yaml index 669e079..a7d913b 100644 --- a/.github/workflows/push-container.yaml +++ b/.github/workflows/push-container.yaml @@ -9,6 +9,7 @@ jobs: env: STATE_CONTRACT_ADDRESS_MAIN: "0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D" STATE_CONTRACT_ADDRESS_AMOY: "0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124" + STATE_CONTRACT_ADDRESS_PRIVADO: "0x975556428F077dB5877Ea2474D783D6C69233742" runs-on: ubuntu-latest steps: - name: Checkout driver-did-iden3 @@ -33,6 +34,13 @@ jobs: echo -e " main:" >> resolvers.settings.yaml echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_MAIN }}" >> resolvers.settings.yaml echo -e " networkURL: ${{ secrets.POLYGON_MAIN_NODE_URL }}" >> resolvers.settings.yaml + echo -e "privado:" > resolvers.settings.yaml + echo -e " main:" >> resolvers.settings.yaml + echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_PRIVADO }}" >> resolvers.settings.yaml + echo -e " networkURL: ${{ secrets.PRIVADO_MAIN_NODE_URL }}" >> resolvers.settings.yaml + echo -e " test:" >> resolvers.settings.yaml + echo -e " contractAddress: ${{ env.STATE_CONTRACT_ADDRESS_PRIVADO }}" >> resolvers.settings.yaml + echo -e " networkURL: ${{ secrets.PRIVADO_TEST_NODE_URL }}" >> resolvers.settings.yaml - name: Set up Docker Buildx id: buildx diff --git a/pkg/document/did.go b/pkg/document/did.go index c096c6f..715e305 100644 --- a/pkg/document/did.go +++ b/pkg/document/did.go @@ -19,10 +19,11 @@ const ( ) const ( - defaultContext = "https://w3id.org/did-resolution/v1" - defaultDidDocContext = "https://www.w3.org/ns/did/v1" - iden3Context = "https://schema.iden3.io/core/jsonld/auth.jsonld" - defaultContentType = "application/did+ld+json" + defaultContext = "https://w3id.org/did-resolution/v1" + defaultDidDocContext = "https://www.w3.org/ns/did/v1" + iden3Context = "https://schema.iden3.io/core/jsonld/auth.jsonld" + EcdsaSecp256k1RecoveryContext = "https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-2.0.jsonld" + defaultContentType = "application/did+ld+json" ) // DidResolution representation of did resolution. diff --git a/pkg/services/did.go b/pkg/services/did.go index e3a3fe1..d1d2e7f 100644 --- a/pkg/services/did.go +++ b/pkg/services/did.go @@ -11,7 +11,6 @@ import ( "github.com/iden3/driver-did-iden3/pkg/services/ens" core "github.com/iden3/go-iden3-core/v2" "github.com/iden3/go-iden3-core/v2/w3c" - "github.com/iden3/go-merkletree-sql/v2" "github.com/iden3/go-schema-processor/v2/verifiable" "github.com/pkg/errors" ) @@ -99,6 +98,7 @@ func (d *DidDocumentServices) GetDidDocument(ctx context.Context, did string, op chainIDStateAddress := resolver.BlockchainID() if err == nil { + didResolution.DidDocument.Context = append(didResolution.DidDocument.Context.([]string), document.EcdsaSecp256k1RecoveryContext) addressString := fmt.Sprintf("%x", addr) blockchainAccountID := fmt.Sprintf("eip155:%s:0x%s", strings.Split(chainIDStateAddress, ":")[0], addressString) didResolution.DidDocument.VerificationMethod = append( @@ -116,7 +116,7 @@ func (d *DidDocumentServices) GetDidDocument(ctx context.Context, did string, op didResolution.DidDocument.VerificationMethod = append( didResolution.DidDocument.VerificationMethod, verifiable.CommonVerificationMethod{ - ID: getRepresentaionID(did, identityState), + ID: fmt.Sprintf("%s#state-info", did), Type: document.StateType, StateContractAddress: chainIDStateAddress, Controller: did, @@ -237,10 +237,12 @@ func expectedError(err error) (*document.DidResolution, error) { return nil, err } -func getRepresentaionID(did string, state IdentityState) string { - if state.StateInfo != nil && state.StateInfo.State != nil { - h, _ := merkletree.NewHashFromBigInt(state.StateInfo.State) - return fmt.Sprintf("%s?state=%s", did, h.Hex()) - } - return did -} +// after discussion we decided not to include state in verification method id, +// so we can have consistent id for verification +// func getRepresentaionID(did string, state IdentityState) string { +// if state.StateInfo != nil && state.StateInfo.State != nil { +// h, _ := merkletree.NewHashFromBigInt(state.StateInfo.State) +// return fmt.Sprintf("%s?state=%s", did, h.Hex()) +// } +// return did +// } diff --git a/tests/e2e/http_nameservice.postman_collection.json b/tests/e2e/http_nameservice.postman_collection.json index f32ffb5..b0e9d67 100644 --- a/tests/e2e/http_nameservice.postman_collection.json +++ b/tests/e2e/http_nameservice.postman_collection.json @@ -125,7 +125,7 @@ "pm.test(\"Did doc not found\", () => {", " const responseJson = pm.response.json();", " pm.expect(responseJson.didDocument.id).to.eq(pm.collectionVariables.get(\"issuer_identity\"));", - " pm.expect(responseJson.didDocument.verificationMethod[0].id).to.eq(pm.collectionVariables.get(\"issuer_identity\"))", + " pm.expect(responseJson.didDocument.verificationMethod[0].id).to.eq(pm.collectionVariables.get(\"issuer_identity\")+\"#state-info\")", " pm.expect(responseJson.didDocument.verificationMethod[0].published).to.eq(false)", "});", "", @@ -174,7 +174,7 @@ "", "pm.test(\"Did doc not found\", () => {", " const responseJson = pm.response.json();", - " pm.expect(responseJson.didDocument.verificationMethod[0].id).to.eq(pm.collectionVariables.get(\"issuer_identity\"))", + " pm.expect(responseJson.didDocument.verificationMethod[0].id).to.eq(pm.collectionVariables.get(\"issuer_identity\")+\"#state-info\")", " pm.expect(responseJson.didDocument.verificationMethod[0].published).to.eq(false)", " pm.expect(responseJson.didDocument.verificationMethod[0].global).not.empty;", "});", @@ -272,7 +272,7 @@ " pm.expect(responseJson.didDocument.verificationMethod[0].global).not.empty;", "", " pm.expect(responseJson.didDocument.verificationMethod[0].id).to.eq(", - " pm.collectionVariables.get(\"issuer_identity\")", + " pm.collectionVariables.get(\"issuer_identity\") +\"#state-info\"", " )", "});", "", @@ -451,9 +451,7 @@ " pm.expect(responseJson.didDocument.verificationMethod[0].global).not.empty;", " console.log(responseJson.didDocument.verificationMethod[0].info)", " pm.expect(responseJson.didDocument.verificationMethod[0].id).to.eq(", - " pm.collectionVariables.get(\"issuer_identity\") +", - " \"?state=\" +", - " pm.response.json().didDocument.verificationMethod[0].info.state", + " pm.collectionVariables.get(\"issuer_identity\") + \"#state-info\"", " )", "});", "", @@ -505,9 +503,7 @@ " pm.expect(responseJson.didDocument.verificationMethod[0].global).to.equal(undefined);", "", " pm.expect(responseJson.didDocument.verificationMethod[0].id).to.eq(", - " pm.collectionVariables.get(\"issuer_identity\") +", - " \"?state=\" +", - " pm.response.json().didDocument.verificationMethod[0].info.state", + " pm.collectionVariables.get(\"issuer_identity\") + \"#state-info\"", " )", "});", "" @@ -610,9 +606,7 @@ " pm.expect(responseJson.didDocument.verificationMethod[0].global).not.empty;", "", " pm.expect(responseJson.didDocument.verificationMethod[0].id).to.eq(", - " pm.collectionVariables.get(\"issuer_identity\") +", - " \"?state=\" +", - " pm.response.json().didDocument.verificationMethod[0].info.state", + " pm.collectionVariables.get(\"issuer_identity\") + \"#state-info\"", " )", "});", "", @@ -668,9 +662,7 @@ " pm.expect(responseJson.didDocument.verificationMethod[0].global).to.eq(undefined);", "", " pm.expect(responseJson.didDocument.verificationMethod[0].id).to.eq(", - " pm.collectionVariables.get(\"issuer_identity\") +", - " \"?state=\" +", - " pm.collectionVariables.get(\"issuer_genesis_state\")", + " pm.collectionVariables.get(\"issuer_identity\") + \"#state-info\"", " )", "", " // check that genesis state was replaced",