Skip to content

Commit

Permalink
fix(indy-vdr): role property not included in nym request
Browse files Browse the repository at this point in the history
  • Loading branch information
auer-martin committed Jun 20, 2023
1 parent 38a0578 commit 5f5c546
Show file tree
Hide file tree
Showing 2 changed files with 13 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'
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 5f5c546

Please sign in to comment.