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 1 commit
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().rename('aid3', 'aid4');
lenkan marked this conversation as resolved.
Show resolved Hide resolved
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> {
iFergal marked this conversation as resolved.
Show resolved Hide resolved
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();
lenkan marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
Loading