diff --git a/packages/rest/src/controllers/did/DidController.ts b/packages/rest/src/controllers/did/DidController.ts index 0b90d480..d482450c 100644 --- a/packages/rest/src/controllers/did/DidController.ts +++ b/packages/rest/src/controllers/did/DidController.ts @@ -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') @@ -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) { diff --git a/packages/rest/src/controllers/types.ts b/packages/rest/src/controllers/types.ts index fdc44f95..a9f912ce 100644 --- a/packages/rest/src/controllers/types.ts +++ b/packages/rest/src/controllers/types.ts @@ -68,7 +68,7 @@ type ProofFormats = [LegacyIndyProofFormat, AnonCredsProofFormat] interface PrivateKey { keyType: KeyType - privateKey: Buffer + privateKey: string } export interface ImportDidOptions { diff --git a/packages/rest/src/routes/routes.ts b/packages/rest/src/routes/routes.ts index 510dbc86..2273c629 100644 --- a/packages/rest/src/routes/routes.ts +++ b/packages/rest/src/routes/routes.ts @@ -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, }, @@ -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, }, diff --git a/packages/rest/src/routes/swagger.json b/packages/rest/src/routes/swagger.json index db49fbd7..e34283aa 100644 --- a/packages/rest/src/routes/swagger.json +++ b/packages/rest/src/routes/swagger.json @@ -743,8 +743,7 @@ "$ref": "#/components/schemas/KeyType" }, "privateKey": { - "type": "string", - "format": "byte" + "type": "string" } }, "required": [ @@ -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": [ @@ -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": {} + } + } + } } } },