From 227b7e3dffd31e6f6658682f04a62c1c665fb6ce Mon Sep 17 00:00:00 2001 From: Liran Cohen Date: Wed, 16 Oct 2024 16:58:48 -0400 Subject: [PATCH] return a copy for did export --- packages/agent/src/bearer-identity.ts | 2 +- packages/agent/src/identity-api.ts | 3 +-- packages/dids/src/bearer-did.ts | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/agent/src/bearer-identity.ts b/packages/agent/src/bearer-identity.ts index 8221f3035..41949909d 100644 --- a/packages/agent/src/bearer-identity.ts +++ b/packages/agent/src/bearer-identity.ts @@ -36,7 +36,7 @@ export class BearerIdentity { public async export(): Promise { return { portableDid : await this.did.export(), - metadata : this.metadata + metadata : { ...this.metadata }, }; } } \ No newline at end of file diff --git a/packages/agent/src/identity-api.ts b/packages/agent/src/identity-api.ts index c807d4548..1e51cb85c 100644 --- a/packages/agent/src/identity-api.ts +++ b/packages/agent/src/identity-api.ts @@ -10,7 +10,6 @@ import { BearerIdentity } from './bearer-identity.js'; import { isPortableDid } from './prototyping/dids/utils.js'; import { InMemoryIdentityStore } from './store-identity.js'; import { getDwnServiceEndpointUrls } from './utils.js'; -import { canonicalize } from '@web5/crypto'; import { PortableDid } from '@web5/dids'; export interface IdentityApiParams { @@ -229,7 +228,7 @@ export class AgentIdentityApi service.id.endsWith('dwn')); if (dwnService) { // Update the existing DWN Service with the provided endpoints diff --git a/packages/dids/src/bearer-did.ts b/packages/dids/src/bearer-did.ts index cdecee834..4ed3dbd58 100644 --- a/packages/dids/src/bearer-did.ts +++ b/packages/dids/src/bearer-did.ts @@ -128,12 +128,12 @@ export class BearerDid { throw new Error(`DID document for '${this.uri}' is missing verification methods`); } - // Create a new `PortableDid` object to store the exported data. - let portableDid: PortableDid = { + // Create a new `PortableDid` copy object to store the exported data. + let portableDid: PortableDid = JSON.parse(JSON.stringify({ uri : this.uri, document : this.document, metadata : this.metadata - }; + })); // If the BearerDid's key manager supports exporting private keys, add them to the portable DID. if ('exportKey' in this.keyManager && typeof this.keyManager.exportKey === 'function') {