Skip to content

Commit

Permalink
fix(indy-vdr): role property not included in nym request (#1488)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Auer <[email protected]>
  • Loading branch information
auer-martin authored Jul 6, 2023
1 parent 6c2dda5 commit 002be4f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 81 deletions.
10 changes: 8 additions & 2 deletions packages/indy-vdr/src/dids/IndyVdrIndyDidRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export class IndyVdrIndyDidRegistrar implements DidRegistrar {
verificationKey,
alias,
diddocContent,
role: options.options.role,
})

if (services && useEndpointAttrib) {
Expand Down Expand Up @@ -388,6 +389,7 @@ export class IndyVdrIndyDidRegistrar implements DidRegistrar {
signingKey?: Key
alias: string | undefined
diddocContent?: Record<string, unknown>
role?: NymRequestRole
}) {
const {
agentContext,
Expand All @@ -397,6 +399,7 @@ export class IndyVdrIndyDidRegistrar implements DidRegistrar {
verificationKey,
alias,
signingKey,
role,
} = options

// FIXME: Add diddocContent when supported by indy-vdr
Expand All @@ -408,7 +411,8 @@ export class IndyVdrIndyDidRegistrar implements DidRegistrar {
submitterDid: submitterNamespaceIdentifier,
dest: namespaceIdentifier,
verkey: verificationKey.publicKeyBase58,
alias: alias,
alias,
role,
})

if (!signingKey) return request
Expand Down Expand Up @@ -487,7 +491,7 @@ interface IndyVdrDidCreateOptionsBase extends DidCreateOptions {
didDocument?: never // Not yet supported
options: {
alias?: string
role?: string
role?: NymRequestRole
services?: DidDocumentService[]
useEndpointAttrib?: boolean
verkey?: string
Expand Down Expand Up @@ -566,3 +570,5 @@ export interface EndorseDidTxAction extends DidOperationStateActionBase {
}

export type IndyVdrDidCreateResult = DidCreateResult<EndorseDidTxAction>

export type NymRequestRole = 'STEWARD' | 'TRUSTEE' | 'ENDORSER' | 'NETWORK_MONITOR'
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ describe('IndyVdrIndyDidRegistrar', () => {
verificationKey: expect.any(Key),
alias: 'Hello',
diddocContent: undefined,
role: 'STEWARD',
})

expect(registerPublicDidSpy).toHaveBeenCalledWith(agentContext, poolMock, undefined)
Expand Down Expand Up @@ -307,6 +308,7 @@ describe('IndyVdrIndyDidRegistrar', () => {
verificationKey: expect.any(Key),
alias: 'Hello',
diddocContent: undefined,
role: 'STEWARD',
})

expect(registerPublicDidSpy).toHaveBeenCalledWith(
Expand Down Expand Up @@ -402,6 +404,7 @@ describe('IndyVdrIndyDidRegistrar', () => {
namespaceIdentifier: 'B6xaJg1c2xU3D9ppCtt1CZ',
verificationKey: expect.any(Key),
alias: 'Hello',
role: 'STEWARD',
diddocContent: {
'@context': [],
authentication: [],
Expand Down Expand Up @@ -583,6 +586,7 @@ describe('IndyVdrIndyDidRegistrar', () => {
verificationKey: expect.any(Key),
alias: 'Hello',
diddocContent: undefined,
role: 'STEWARD',
})

expect(registerPublicDidSpy).toHaveBeenCalledWith(
Expand Down
84 changes: 5 additions & 79 deletions packages/indy-vdr/tests/indy-vdr-did-registrar.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,91 +155,17 @@ describe('Indy VDR Indy Did Registrar', () => {
})
})

test('can register a did:indy without services with endorser', async () => {
const didCreateTobeEndorsedResult = (await agent.dids.create<IndyVdrDidCreateOptions>({
test('cannot create a did with TRUSTEE role', async () => {
const didRegistrationResult = await endorser.dids.create<IndyVdrDidCreateOptions>({
method: 'indy',
options: {
endorserMode: 'external',
endorserDid,
},
})) as IndyVdrDidCreateResult

const didState = didCreateTobeEndorsedResult.didState
if (didState.state !== 'action' || didState.action !== 'endorseIndyTransaction') throw Error('unexpected did state')

const signedNymRequest = await endorser.modules.indyVdr.endorseTransaction(
didState.nymRequest,
didState.endorserDid
)
const didCreateSubmitResult = await agent.dids.create<IndyVdrDidCreateOptions>({
did: didState.did,
options: {
endorserMode: 'external',
endorsedTransaction: {
nymRequest: signedNymRequest,
},
},
secret: didState.secret,
})

expect(JsonTransformer.toJSON(didCreateSubmitResult)).toMatchObject({
didDocumentMetadata: {},
didRegistrationMetadata: {},
didState: {
state: 'finished',
did: expect.stringMatching(didIndyRegex),
didDocument: {
'@context': ['https://w3id.org/did/v1', 'https://w3id.org/security/suites/ed25519-2018/v1'],
id: expect.stringMatching(didIndyRegex),
alsoKnownAs: undefined,
controller: undefined,
verificationMethod: [
{
type: 'Ed25519VerificationKey2018',
controller: expect.stringMatching(didIndyRegex),
id: expect.stringContaining('#verkey'),
publicKeyBase58: expect.any(String),
},
],
capabilityDelegation: undefined,
capabilityInvocation: undefined,
authentication: [expect.stringContaining('#verkey')],
service: undefined,
},
endorserMode: 'internal',
role: 'TRUSTEE',
},
})

const did = didCreateSubmitResult.didState.did
if (!did) throw Error('did not defined')

// Wait some time pass to let ledger settle the object
await sleep(1000)

const didResolutionResult = await endorser.dids.resolve(did)
expect(JsonTransformer.toJSON(didResolutionResult)).toMatchObject({
didDocument: {
'@context': ['https://w3id.org/did/v1', 'https://w3id.org/security/suites/ed25519-2018/v1'],
id: did,
alsoKnownAs: undefined,
controller: undefined,
verificationMethod: [
{
type: 'Ed25519VerificationKey2018',
controller: did,
id: `${did}#verkey`,
publicKeyBase58: expect.any(String),
},
],
capabilityDelegation: undefined,
capabilityInvocation: undefined,
authentication: [`${did}#verkey`],
service: undefined,
},
didDocumentMetadata: {},
didResolutionMetadata: {
contentType: 'application/did+ld+json',
},
})
expect(JsonTransformer.toJSON(didRegistrationResult.didState.state)).toBe('failed')
})

test('can register an endorsed did:indy without services - did and verkey specified', async () => {
Expand Down

0 comments on commit 002be4f

Please sign in to comment.