Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename managed identifier #283

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/integration-scripts/salty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,14 @@ test('salty', async () => {

await assertOperations(client1);

aid = await client1.identifiers().update('aid3', { name: 'aid4' });
assert.equal(aid.name, 'aid4');
aid = await client1.identifiers().get('aid4');
assert.equal(aid.name, 'aid4');
aids = await client1.identifiers().list(2, 2);
assert.equal(aids.aids.length, 1);
aid = aids.aids[0];
assert.equal(aid.name, 'aid4');

console.log('Salty test passed');
}, 30000);
28 changes: 24 additions & 4 deletions src/keri/app/aiding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { MtrDex } from '../core/matter';
import { Serder } from '../core/serder';
import { parseRangeHeaders } from '../core/httping';
import { KeyManager } from '../core/keeping';
import { Operation } from './coring';
import { HabState } from '../core/state';

/** Arguments required to create an identfier */
Expand Down Expand Up @@ -67,6 +66,13 @@ export interface IdentifierDeps {
manager: KeyManager | null;
}

/**
* Updatable information for a managed identifier
*/
export interface IdentifierInfo {
name: string;
}

/** Identifier */
export class Identifier {
public client: IdentifierDeps;
Expand Down Expand Up @@ -110,8 +116,8 @@ export class Identifier {
/**
* Get information for a managed identifier
* @async
* @param {string} name Name or alias of the identifier
* @returns {Promise<any>} A promise to the identifier information
* @param {string} name Prefix or alias of the identifier
* @returns {Promise<HabState>} A promise to the identifier information
*/
async get(name: string): Promise<HabState> {
const path = `/identifiers/${encodeURIComponent(name)}`;
Expand All @@ -121,6 +127,20 @@ export class Identifier {
return await res.json();
}

/**
* Update managed identifier
* @async
* @param {string} name Prefix or alias of the identifier
* @param {IdentifierInfo} info Information to update for the given identifier
* @returns {Promise<HabState>} A promise to the identifier information after updating
*/
async update(name: string, info: IdentifierInfo): Promise<HabState> {
const path = `/identifiers/${name}`;
const method = 'PUT';
const res = await this.client.fetch(path, method, info);
return await res.json();
}

/**
* Create a managed identifier
* @async
Expand Down Expand Up @@ -253,7 +273,7 @@ export class Identifier {
/**
* Generate an interaction event in a managed identifier
* @async
* @param {string} name Name or alias of the identifier
* @param {string} name Prefix or alias of the identifier
* @param {any} [data] Option data to be anchored in the interaction event
* @returns {Promise<EventResult>} A promise to the interaction event result
*/
Expand Down
9 changes: 9 additions & 0 deletions test/app/aiding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,15 @@ describe('Aiding', () => {
assert.deepEqual(lastCall.body.randy.transferable, true);
});

it('Can rename identifier', async () => {
client.fetch.mockResolvedValue(Response.json({}));
await client.identifiers().update('aid1', { name: 'aid2' });
const lastCall = client.getLastMockRequest();
assert.equal(lastCall.path, '/identifiers/aid1');
assert.equal(lastCall.method, 'PUT');
assert.equal(lastCall.body.name, 'aid2');
});

describe('Group identifiers', () => {
it('Can Rotate group', async () => {
const member1 = await createMockIdentifierState(
Expand Down
Loading