Skip to content

Commit

Permalink
return a copy for did export
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Oct 16, 2024
1 parent c3f971f commit 227b7e3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/agent/src/bearer-identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class BearerIdentity {
public async export(): Promise<PortableIdentity> {
return {
portableDid : await this.did.export(),
metadata : this.metadata
metadata : { ...this.metadata },
};
}
}
3 changes: 1 addition & 2 deletions packages/agent/src/identity-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TKeyManager extends AgentKeyManager> {
Expand Down Expand Up @@ -229,7 +228,7 @@ export class AgentIdentityApi<TKeyManager extends AgentKeyManager = AgentKeyMana
throw new Error(`AgentIdentityApi: Failed to set DWN endpoints due to DID not found: ${didUri}`);
}

const portableDid = JSON.parse(JSON.stringify(await bearerDid.export())) as PortableDid;
const portableDid = await bearerDid.export();
const dwnService = portableDid.document.service?.find(service => service.id.endsWith('dwn'));
if (dwnService) {
// Update the existing DWN Service with the provided endpoints
Expand Down
6 changes: 3 additions & 3 deletions packages/dids/src/bearer-did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit 227b7e3

Please sign in to comment.