Skip to content

Commit

Permalink
add setter and getter for the identity metadata name
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Oct 21, 2024
1 parent 5120f6f commit c2c97cd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/agent/src/identity-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,40 @@ export class AgentIdentityApi<TKeyManager extends AgentKeyManager = AgentKeyMana
await this.agent.did.update({ portableDid, tenant: this.agent.agentDid.uri });
}

public async getMetadataName({ didUri }: { didUri: string }): Promise<string> {
const identity = await this.get({ didUri });
if (!identity) {
throw new Error(`AgentIdentityApi: Failed to retrieve metadata name due to Identity not found: ${didUri}`);
}

return identity.metadata.name;
}

Check warning on line 280 in packages/agent/src/identity-api.ts

View check run for this annotation

Codecov / codecov/patch

packages/agent/src/identity-api.ts#L274-L280

Added lines #L274 - L280 were not covered by tests

public async setMetadataName({ didUri, name }: { didUri: string; name: string }): Promise<void> {
if (!name) {
throw new Error('AgentIdentityApi: Failed to set metadata name due to missing name value.');
}

const identity = await this.get({ didUri });
if (!identity) {
throw new Error(`AgentIdentityApi: Failed to set metadata name due to Identity not found: ${didUri}`);
}

if (identity.metadata.name === name) {
throw new Error('AgentIdentityApi: Metadata name is already set to the provided value.');
}

// Update the name in the Identity's metadata and store it
await this._store.set({
id : identity.did.uri,
data : { ...identity.metadata, name },
agent : this.agent,
tenant : identity.metadata.tenant,
updateExisting : true,
useCache : true
});
}

Check warning on line 305 in packages/agent/src/identity-api.ts

View check run for this annotation

Codecov / codecov/patch

packages/agent/src/identity-api.ts#L283-L305

Added lines #L283 - L305 were not covered by tests

/**
* Returns the connected Identity, if one is available.
*
Expand Down

0 comments on commit c2c97cd

Please sign in to comment.