Skip to content

Commit

Permalink
Add did import and create
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Dean <[email protected]>
  • Loading branch information
mattdean-digicatapult committed Sep 4, 2023
1 parent 2e26389 commit 973eaeb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
13 changes: 10 additions & 3 deletions packages/rest/src/controllers/did/DidController.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { DidCreateResult, DidResolutionResultProps } from '../types'

import { Agent, AriesFrameworkError, ImportDidOptions } from '@aries-framework/core'
import { Agent, AriesFrameworkError, TypedArrayEncoder } from '@aries-framework/core'
import { Body, Controller, Example, Get, Path, Post, Res, Route, Tags, TsoaResponse } from 'tsoa'
import { injectable } from 'tsyringe'

import { Did, DidRecordExample, DidStateExample } from '../examples'
import { DidCreateOptions } from '../types'
import { DidCreateOptions, ImportDidOptions } from '../types'

@Tags('Dids')
@Route('/dids')
Expand Down Expand Up @@ -50,7 +50,14 @@ export class DidController extends Controller {
@Res() internalServerError: TsoaResponse<500, { message: string }>
) {
try {
await this.agent.dids.import(options)
const { privateKeys, ...rest } = options
await this.agent.dids.import({
...rest,
privateKeys: privateKeys?.map(({ keyType, privateKey }) => ({
keyType,
privateKey: TypedArrayEncoder.fromString(privateKey),
})),
})
return this.getDidRecordByDid(options.did)
} catch (error) {
if (error instanceof AriesFrameworkError) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/controllers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type ProofFormats = [LegacyIndyProofFormat, AnonCredsProofFormat]

interface PrivateKey {
keyType: KeyType
privateKey: Buffer
privateKey: string
}

export interface ImportDidOptions {
Expand Down
4 changes: 2 additions & 2 deletions packages/rest/src/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ const models: TsoaRoute.Models = {
"dataType": "refObject",
"properties": {
"keyType": {"ref":"KeyType","required":true},
"privateKey": {"dataType":"buffer","required":true},
"privateKey": {"dataType":"string","required":true},
},
"additionalProperties": false,
},
Expand All @@ -399,7 +399,7 @@ const models: TsoaRoute.Models = {
"did": {"dataType":"string","required":true},
"didDocument": {"ref":"DidDocument"},
"privateKeys": {"dataType":"array","array":{"dataType":"refObject","ref":"PrivateKey"}},
"overwrite": {"dataType":"boolean","default":"false"},
"overwrite": {"dataType":"boolean"},
},
"additionalProperties": false,
},
Expand Down
62 changes: 50 additions & 12 deletions packages/rest/src/routes/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,7 @@
"$ref": "#/components/schemas/KeyType"
},
"privateKey": {
"type": "string",
"format": "byte"
"type": "string"
}
},
"required": [
Expand All @@ -757,24 +756,19 @@
"ImportDidOptions": {
"properties": {
"did": {
"type": "string",
"description": "The did to import."
"type": "string"
},
"didDocument": {
"$ref": "#/components/schemas/DidDocument",
"description": "Optional did document to import. If not provided, the did document will be resolved using the did resolver."
"$ref": "#/components/schemas/DidDocument"
},
"privateKeys": {
"items": {
"$ref": "#/components/schemas/PrivateKey"
},
"type": "array",
"description": "List of private keys associated with the did document that should be stored in the wallet."
"type": "array"
},
"overwrite": {
"type": "boolean",
"description": "Whether to overwrite an existing did record if it exists. If set to false,\nan error will be thrown if the did record already exists.",
"default": "false"
"type": "boolean"
}
},
"required": [
Expand Down Expand Up @@ -3666,7 +3660,51 @@
"description": "DidResolutionResultProps",
"content": {
"application/json": {
"schema": {}
"schema": {},
"examples": {
"Example 1": {
"value": {
"did": "did:key:z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc",
"didDocument": {
"@context": [
"https://w3id.org/did/v1",
"https://w3id.org/security/suites/ed25519-2018/v1",
"https://w3id.org/security/suites/x25519-2019/v1"
],
"id": "did:key:z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc",
"verificationMethod": [
{
"id": "did:key:z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc#z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc",
"type": "Ed25519VerificationKey2018",
"controller": "did:key:z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc",
"publicKeyBase58": "ApexJxnhZHC6Ctq4fCoNHKYgu87HuRTZ7oSyfehG57zE"
}
],
"authentication": [
"did:key:z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc#z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc"
],
"assertionMethod": [
"did:key:z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc#z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc"
],
"keyAgreement": [
{
"id": "did:key:z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc#z6LSm5B4fB9NA55xB7PSeMYTMS9sf8uboJvyZBaDLLSZ7Ryd",
"type": "X25519KeyAgreementKey2019",
"controller": "did:key:z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc",
"publicKeyBase58": "APzu8sLW4cND5j1g7i2W2qwPozNV6hkpgCrXqso2Q4Cs"
}
],
"capabilityInvocation": [
"did:key:z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc#z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc"
],
"capabilityDelegation": [
"did:key:z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc#z6MkpGuzuD38tpgZKPfmLmmD8R6gihP9KJhuopMuVvfGzLmc"
]
},
"secret": {}
}
}
}
}
}
},
Expand Down

0 comments on commit 973eaeb

Please sign in to comment.