diff --git a/.github/actions/setup-indy-pool/action.yml b/.github/actions/setup-indy-pool/action.yml index 7b755c2171..791548b809 100644 --- a/.github/actions/setup-indy-pool/action.yml +++ b/.github/actions/setup-indy-pool/action.yml @@ -21,7 +21,7 @@ runs: shell: bash - name: Register DID on ledger - run: docker exec indy-pool add-did-from-seed ${{ inputs.seed }} + run: docker exec indy-pool add-did-from-seed ${{ inputs.seed }} TRUSTEE shell: bash branding: diff --git a/DEVREADME.md b/DEVREADME.md index 84b96c7399..318d944014 100644 --- a/DEVREADME.md +++ b/DEVREADME.md @@ -54,8 +54,8 @@ docker run -d --rm --name indy-pool -p 9701-9708:9701-9708 indy-pool # Setup CLI. This creates a wallet, connects to the ledger and sets the Transaction Author Agreement docker exec indy-pool indy-cli-setup -# DID and Verkey from seed -docker exec indy-pool add-did-from-seed 000000000000000000000000Trustee9 +# DID and Verkey from seed. Set 'Trustee' role in order to be able to register public DIDs +docker exec indy-pool add-did-from-seed 000000000000000000000000Trustee9 TRUSTEE # If you want to register using the DID/Verkey you can use # docker exec indy-pool add-did "NkGXDEPgpFGjQKMYmz6SyF" "CrSA1WbYYWLJoHm16Xw1VEeWxFvXtWjtsfEzMsjB5vDT" diff --git a/network/add-did-from-seed.sh b/network/add-did-from-seed.sh index c8b1fea1fe..65b4169289 100755 --- a/network/add-did-from-seed.sh +++ b/network/add-did-from-seed.sh @@ -1,6 +1,7 @@ #!/bin/bash -export SEED=${1?"Seed missing\nUsage: $0 SEED"} +export SEED=${1?"Seed missing\nUsage: $0 SEED ROLE"} +export ROLE=$2 echo " wallet open afj-wallet key=password @@ -15,4 +16,4 @@ IFS='"' read -r -a DID_PARTS <<<"$DID_STRING" export DID=${DID_PARTS[1]} export VERKEY=${DID_PARTS[3]} -add-did "$DID" "$VERKEY" +add-did "$DID" "$VERKEY" "$ROLE" diff --git a/network/add-did.sh b/network/add-did.sh index 619794c29a..a3db49fc3a 100755 --- a/network/add-did.sh +++ b/network/add-did.sh @@ -1,13 +1,18 @@ #!/bin/bash -export DID=${1?"Did missing\nUsage: $0 DID VERKEY"} -export VERKEY=${2?"Verkey missing\nUsage: $0 DID VERKEY"} +export DID=${1?"Did missing\nUsage: $0 DID VERKEY [ROLE]"} +export VERKEY=${2?"Verkey missing\nUsage: $0 DID VERKEY [ROLE]"} +export ROLE=$3 + +if [ -z "$ROLE" ]; then + ROLE=TRUST_ANCHOR +fi echo " wallet open afj-wallet key=password pool connect afj-pool did use V4SGRU86Z58d6TV7PBUe6f -ledger nym did=${DID} verkey=${VERKEY} role=TRUST_ANCHOR" >/etc/indy/command.txt +ledger nym did=${DID} verkey=${VERKEY} role=${ROLE}" >/etc/indy/command.txt indy-cli --config /etc/indy/indy-cli-config.json /etc/indy/command.txt diff --git a/packages/core/package.json b/packages/core/package.json index fdfb75f182..8d6306c94f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -22,7 +22,7 @@ "prepublishOnly": "yarn run build" }, "dependencies": { - "@types/indy-sdk": "^1.16.5", + "@types/indy-sdk": "^1.16.6", "abort-controller": "^3.0.0", "bn.js": "^5.2.0", "borc": "^3.0.0", diff --git a/packages/core/src/modules/ledger/LedgerModule.ts b/packages/core/src/modules/ledger/LedgerModule.ts index 8bada5d98b..b2b8209968 100644 --- a/packages/core/src/modules/ledger/LedgerModule.ts +++ b/packages/core/src/modules/ledger/LedgerModule.ts @@ -1,5 +1,5 @@ import type { SchemaTemplate, CredentialDefinitionTemplate } from './services' -import type { CredDefId, Did, SchemaId } from 'indy-sdk' +import type { CredDefId, Did, NymRole, SchemaId } from 'indy-sdk' import { inject, scoped, Lifecycle } from 'tsyringe' @@ -19,8 +19,14 @@ export class LedgerModule { this.wallet = wallet } - public async registerPublicDid() { - throw new AriesFrameworkError('registerPublicDid not implemented.') + public async registerPublicDid(did: Did, verkey: string, alias: string, role?: NymRole) { + const myPublicDid = this.wallet.publicDid?.did + + if (!myPublicDid) { + throw new AriesFrameworkError('Agent has no public DID.') + } + + return this.ledgerService.registerPublicDid(myPublicDid, did, verkey, alias, role) } public async getPublicDid(did: Did) { diff --git a/packages/core/src/modules/ledger/services/LedgerService.ts b/packages/core/src/modules/ledger/services/LedgerService.ts index d382bbdb73..f0be8ee601 100644 --- a/packages/core/src/modules/ledger/services/LedgerService.ts +++ b/packages/core/src/modules/ledger/services/LedgerService.ts @@ -11,6 +11,7 @@ import type { SchemaId, LedgerReadReplyResponse, LedgerWriteReplyResponse, + NymRole, } from 'indy-sdk' import { inject, scoped, Lifecycle } from 'tsyringe' @@ -110,6 +111,34 @@ export class LedgerService { return this._poolHandle } + public async registerPublicDid(submitterDid: Did, targetDid: Did, verkey: string, alias: string, role?: NymRole) { + try { + this.logger.debug(`Register public did on ledger '${targetDid}'`) + + const request = await this.indy.buildNymRequest(submitterDid, targetDid, verkey, alias, role || null) + + const response = await this.submitWriteRequest(request, submitterDid) + + this.logger.debug(`Registered public did '${targetDid}' on ledger`, { + response, + }) + + return targetDid + } catch (error) { + this.logger.error(`Error registering public did '${targetDid}' on ledger`, { + error, + submitterDid, + targetDid, + verkey, + alias, + role, + poolHandle: await this.getPoolHandle(), + }) + + throw error + } + } + public async getPublicDid(did: Did) { try { this.logger.debug(`Get public did '${did}' from ledger`) diff --git a/packages/core/tests/ledger.test.ts b/packages/core/tests/ledger.test.ts index a6b8f3ceb6..bcf66cbd80 100644 --- a/packages/core/tests/ledger.test.ts +++ b/packages/core/tests/ledger.test.ts @@ -1,5 +1,3 @@ -import type { SchemaId } from 'indy-sdk' - import { promises } from 'fs' import * as indy from 'indy-sdk' @@ -14,7 +12,7 @@ const { config: faberConfig, agentDependencies: faberDependencies } = getBaseCon describe('ledger', () => { let faberAgent: Agent - let schemaId: SchemaId + let schemaId: indy.SchemaId beforeAll(async () => { faberAgent = new Agent(faberConfig, faberDependencies) @@ -57,11 +55,24 @@ describe('ledger', () => { expect.objectContaining({ did: faberAgent.publicDid.did, verkey: verkey, - role: '101', + role: '0', }) ) }) + test('register public DID on ledger', async () => { + if (!faberAgent.publicDid) { + throw new Error('Agent does not have public did.') + } + + const targetDid = 'PNQm3CwyXbN5e39Rw3dXYx' + const targetVerkey = '~AHtGeRXtGjVfXALtXP9WiX' + + const result = await faberAgent.ledger.registerPublicDid(targetDid, targetVerkey, 'alias', 'TRUST_ANCHOR') + + expect(result).toEqual(targetDid) + }) + test('register schema on ledger', async () => { if (!faberAgent.publicDid) { throw new Error('Agent does not have public did.') diff --git a/packages/react-native/package.json b/packages/react-native/package.json index 7bd036df5f..fcd9a609c1 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -29,7 +29,7 @@ }, "devDependencies": { "@types/react-native": "^0.64.10", - "@types/rn-indy-sdk": "npm:@types/indy-sdk@^1.16.5", + "@types/rn-indy-sdk": "npm:@types/indy-sdk@^1.16.6", "react": "17.0.1", "react-native": "0.64.2", "rimraf": "~3.0.2", diff --git a/yarn.lock b/yarn.lock index df8e03cae6..066bbacac0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2154,6 +2154,13 @@ dependencies: "@types/node" "*" +"@types/indy-sdk@^1.16.6", "@types/rn-indy-sdk@npm:@types/indy-sdk@^1.16.6": + version "1.16.6" + resolved "https://registry.yarnpkg.com/@types/indy-sdk/-/indy-sdk-1.16.6.tgz#ec8df3dd70cb939c85caa6ebcc32d851e2f3c454" + integrity sha512-BhmqsM2z65aOrg6Hum7YICX02dQA2OS05BjEypdoScmPO3ySsZ5QXngeh6pAi+se5yGYp+cL5msoTqldAhlOGA== + dependencies: + buffer "^6.0.0" + "@types/hoist-non-react-statics@^3.3.0": version "3.3.1" resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f" @@ -2162,13 +2169,6 @@ "@types/react" "*" hoist-non-react-statics "^3.3.0" -"@types/indy-sdk@^1.16.5", "@types/rn-indy-sdk@npm:@types/indy-sdk@^1.16.5": - version "1.16.5" - resolved "https://registry.yarnpkg.com/@types/indy-sdk/-/indy-sdk-1.16.5.tgz#e9b6b917f8a95b5782d9eb7bc8be713c0f971b21" - integrity sha512-eDY2RIUdHIhVytx1k9u2mQgXfw1Fs3sW05kP8h3TDXl8mVXsxQyGs336z2GIApUux8vftsQOVEhrX13OinUmwQ== - dependencies: - buffer "^6.0.0" - "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1": version "2.0.3" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762"