From e6fec86a6266ab596449c35bc2b5855c0d7a62c5 Mon Sep 17 00:00:00 2001 From: iFergal Date: Tue, 15 Oct 2024 08:53:38 +0100 Subject: [PATCH 1/4] feat: rename identifier --- examples/integration-scripts/salty.test.ts | 9 ++++++++ src/keri/app/aiding.ts | 26 +++++++++++++++++----- test/app/aiding.test.ts | 9 ++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/examples/integration-scripts/salty.test.ts b/examples/integration-scripts/salty.test.ts index 5c460796..e9e74ba0 100644 --- a/examples/integration-scripts/salty.test.ts +++ b/examples/integration-scripts/salty.test.ts @@ -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); diff --git a/src/keri/app/aiding.ts b/src/keri/app/aiding.ts index 7bab1c48..5fbdbd4f 100644 --- a/src/keri/app/aiding.ts +++ b/src/keri/app/aiding.ts @@ -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 */ @@ -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} A promise to the identifier information + * @returns {Promise} A promise to the identifier information */ async get(name: string): Promise { 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} A promise to the identifier information after updating + */ + async rename(name: string, newName: string): Promise { + const path = `/identifiers/${name}`; + const method = 'PUT'; + const data = { + name: newName, + }; + const res = await this.client.fetch(path, method, data); + return res.json(); } /** @@ -472,7 +488,7 @@ export class Identifier { 'GET', undefined ); - return await res.json(); + return res.json(); } } @@ -502,6 +518,6 @@ export class EventResult { async op(): Promise { const res = await this.promise; - return await res.json(); + return res.json(); } } diff --git a/test/app/aiding.test.ts b/test/app/aiding.test.ts index fbb885ac..6c95423c 100644 --- a/test/app/aiding.test.ts +++ b/test/app/aiding.test.ts @@ -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( From 9a496269a9fdb37ea8acbd8c4e697b4a74945c55 Mon Sep 17 00:00:00 2001 From: iFergal Date: Wed, 16 Oct 2024 14:38:32 +0100 Subject: [PATCH 2/4] feat: updated interface and await before return --- examples/integration-scripts/salty.test.ts | 2 +- src/keri/app/aiding.ts | 32 ++++++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/integration-scripts/salty.test.ts b/examples/integration-scripts/salty.test.ts index e9e74ba0..b74833dc 100644 --- a/examples/integration-scripts/salty.test.ts +++ b/examples/integration-scripts/salty.test.ts @@ -168,7 +168,7 @@ test('salty', async () => { await assertOperations(client1); - aid = await client1.identifiers().rename('aid3', 'aid4'); + aid = await client1.identifiers().update('aid3', { name: 'aid4' }); assert.equal(aid.name, 'aid4'); aid = await client1.identifiers().get('aid4'); assert.equal(aid.name, 'aid4'); diff --git a/src/keri/app/aiding.ts b/src/keri/app/aiding.ts index 5fbdbd4f..c8abc6d7 100644 --- a/src/keri/app/aiding.ts +++ b/src/keri/app/aiding.ts @@ -66,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; @@ -109,7 +116,7 @@ export class Identifier { /** * Get information for a managed identifier * @async - * @param {string} name Name or alias of the identifier + * @param {string} name Prefix or alias of the identifier * @returns {Promise} A promise to the identifier information */ async get(name: string): Promise { @@ -117,24 +124,21 @@ export class Identifier { const data = null; const method = 'GET'; const res = await this.client.fetch(path, method, data); - return res.json(); + return await res.json(); } /** - * Rename managed identifier + * Update managed identifier * @async - * @param {string} name Name or alias of the identifier - * @param {string} newName New name for the identifier + * @param {string} name Prefix or alias of the identifier + * @param {IdentifierInfo} info Information to update for the given identifier * @returns {Promise} A promise to the identifier information after updating */ - async rename(name: string, newName: string): Promise { + async update(name: string, info: IdentifierInfo): Promise { const path = `/identifiers/${name}`; const method = 'PUT'; - const data = { - name: newName, - }; - const res = await this.client.fetch(path, method, data); - return res.json(); + const res = await this.client.fetch(path, method, info); + return await res.json(); } /** @@ -269,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} A promise to the interaction event result */ @@ -488,7 +492,7 @@ export class Identifier { 'GET', undefined ); - return res.json(); + return await res.json(); } } @@ -518,6 +522,6 @@ export class EventResult { async op(): Promise { const res = await this.promise; - return res.json(); + return await res.json(); } } From 4b1dbd75c1448ecd4c14fd7540919215e1d40247 Mon Sep 17 00:00:00 2001 From: iFergal Date: Wed, 16 Oct 2024 14:42:23 +0100 Subject: [PATCH 3/4] refactor: prettier run --- src/keri/app/aiding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keri/app/aiding.ts b/src/keri/app/aiding.ts index c8abc6d7..a0863748 100644 --- a/src/keri/app/aiding.ts +++ b/src/keri/app/aiding.ts @@ -70,7 +70,7 @@ export interface IdentifierDeps { * Updatable information for a managed identifier */ export interface IdentifierInfo { - name: string + name: string; } /** Identifier */ From 2fb6988616c7b5cbd939c41eaf305c789045817d Mon Sep 17 00:00:00 2001 From: iFergal Date: Wed, 16 Oct 2024 14:44:11 +0100 Subject: [PATCH 4/4] test: update unit test with new interface --- test/app/aiding.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/app/aiding.test.ts b/test/app/aiding.test.ts index 6c95423c..bbe910c7 100644 --- a/test/app/aiding.test.ts +++ b/test/app/aiding.test.ts @@ -371,7 +371,7 @@ describe('Aiding', () => { it('Can rename identifier', async () => { client.fetch.mockResolvedValue(Response.json({})); - await client.identifiers().rename('aid1', 'aid2'); + await client.identifiers().update('aid1', { name: 'aid2' }); const lastCall = client.getLastMockRequest(); assert.equal(lastCall.path, '/identifiers/aid1'); assert.equal(lastCall.method, 'PUT');