Skip to content

Commit

Permalink
feat: rename identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
iFergal committed Oct 15, 2024
1 parent 1b747f8 commit e6fec86
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
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().rename('aid3', '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);
26 changes: 21 additions & 5 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 @@ -111,14 +110,31 @@ 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
* @returns {Promise<HabState>} A promise to the identifier information
*/
async get(name: string): Promise<HabState> {
const path = `/identifiers/${encodeURIComponent(name)}`;
const data = null;
const method = 'GET';
const res = await this.client.fetch(path, method, data);
return await res.json();
return res.json();
}

/**
* Rename managed identifier
* @async
* @param {string} name Name or alias of the identifier
* @param {string} newName New name for the identifier
* @returns {Promise<HabState>} A promise to the identifier information after updating
*/
async rename(name: string, newName: string): Promise<HabState> {
const path = `/identifiers/${name}`;
const method = 'PUT';
const data = {
name: newName,
};
const res = await this.client.fetch(path, method, data);
return res.json();
}

/**
Expand Down Expand Up @@ -472,7 +488,7 @@ export class Identifier {
'GET',
undefined
);
return await res.json();
return res.json();
}
}

Expand Down Expand Up @@ -502,6 +518,6 @@ export class EventResult {

async op(): Promise<any> {
const res = await this.promise;
return await res.json();
return res.json();
}
}
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().rename('aid1', '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

0 comments on commit e6fec86

Please sign in to comment.