Skip to content

Commit

Permalink
add support for privado network (#14)
Browse files Browse the repository at this point in the history
* add support for privado network
  • Loading branch information
volodymyr-basiuk authored Jul 10, 2024
1 parent 38b4991 commit 42591a1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/push-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions pkg/document/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 11 additions & 9 deletions pkg/services/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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
// }
22 changes: 7 additions & 15 deletions tests/e2e/http_nameservice.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
"});",
"",
Expand Down Expand Up @@ -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;",
"});",
Expand Down Expand Up @@ -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\"",
" )",
"});",
"",
Expand Down Expand Up @@ -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\"",
" )",
"});",
"",
Expand Down Expand Up @@ -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\"",
" )",
"});",
""
Expand Down Expand Up @@ -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\"",
" )",
"});",
"",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 42591a1

Please sign in to comment.