Skip to content

Commit

Permalink
[DF-1670] feat: rename and delete aids
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolfomiranda committed Apr 6, 2024
1 parent 21e1fae commit 5c65b95
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
15 changes: 15 additions & 0 deletions examples/integration-scripts/salty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ test('salty', async () => {
assert.equal(serder.pre, ixn.pre);
assert.equal(serder.ked['d'], ixn.ked['d']);

const renameResult = await client1
.identifiers()
.rename('aid1', 'aidRenamed');
assert.equal(renameResult.name, 'aidRenamed');
aids = await client1.identifiers().list();
assert.equal(aids.aids.length, 3);
aid = aids.aids.pop();
assert.equal(aid.name, 'aidRenamed');

await client1.identifiers().delete('aidRenamed');
aids = await client1.identifiers().list();
assert.equal(aids.aids.length, 2);
aid = aids.aids.pop();
assert.equal(aid.name, 'aid3');

await assertOperations(client1);

console.log('Salty test passed');
Expand Down
36 changes: 32 additions & 4 deletions src/keri/app/aiding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,34 @@ export class Identifier {
return await res.json();
}

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

/**
* Delete a managed identifier
* @async
* @param {string} name Name or alias of the identifier
* @returns {Promise<any>} A promise to the identifier information
*/
async delete(name: string): Promise<any> {
const path = `/identifiers/${name}`;
const method = 'DELETE';
await this.client.fetch(path, method, null);
return;
}

/**
* Create a managed identifier
* @async
Expand Down Expand Up @@ -280,8 +308,8 @@ export class Identifier {
jsondata[keeper.algo] = keeper.params();

const res = await this.client.fetch(
'/identifiers/' + name + '?type=ixn',
'PUT',
'/identifiers/' + name + '/events',
'POST',
jsondata
);
return new EventResult(serder, sigs, res);
Expand Down Expand Up @@ -379,8 +407,8 @@ export class Identifier {
jsondata[keeper.algo] = keeper.params();

const res = await this.client.fetch(
'/identifiers/' + name,
'PUT',
'/identifiers/' + name + '/events',
'POST',
jsondata
);
return new EventResult(serder, sigs, res);
Expand Down
39 changes: 35 additions & 4 deletions test/app/aiding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ describe('Aiding', () => {

await client.identifiers().rotate('aid1');
const lastCall = client.getLastMockRequest();
assert.equal(lastCall.path, '/identifiers/aid1');
assert.equal(lastCall.method, 'PUT');
assert.equal(lastCall.path, '/identifiers/aid1/events');
assert.equal(lastCall.method, 'POST');
assert.deepEqual(lastCall.body.rot, {
v: 'KERI10JSON000160_',
t: 'rot',
Expand Down Expand Up @@ -208,8 +208,8 @@ describe('Aiding', () => {

const lastCall = client.getLastMockRequest();

expect(lastCall.path).toEqual('/identifiers/aid1?type=ixn');
expect(lastCall.method).toEqual('PUT');
assert.equal(lastCall.path, '/identifiers/aid1/events');
assert.equal(lastCall.method, 'POST');
expect(lastCall.body.ixn).toMatchObject({
v: 'KERI10JSON000138_',
t: 'ixn',
Expand Down Expand Up @@ -380,4 +380,35 @@ describe('Aiding', () => {
args !== null; // avoids TS6133
});
});


it('Can rename salty identifier', async () => {
const aid1 = await createMockIdentifierState('aid1', bran, {});
client.fetch.mockResolvedValueOnce(Response.json(aid1));
client.fetch.mockResolvedValueOnce(Response.json({}));

const aidRenamed = await client
.identifiers()
.rename('aid1', 'aidRenamed');
client.fetch.mockResolvedValueOnce(Response.json(aidRenamed));
client.fetch.mockResolvedValueOnce(Response.json({}));
const lastCall = client.getLastMockRequest();
assert.equal(lastCall.path, '/identifiers/aid1');
assert.equal(lastCall.method, 'PUT');
assert.deepEqual(lastCall.body, {
name: 'aidRenamed',
});
});

it('Can delete salty identifier', async () => {
const aid1 = await createMockIdentifierState('aid1', bran, {});
client.fetch.mockResolvedValueOnce(Response.json(aid1));
client.fetch.mockResolvedValueOnce(Response.json({}));

await client.identifiers().delete('aid1');
client.fetch.mockResolvedValueOnce(Response.json({}));
const lastCall = client.getLastMockRequest();
assert.equal(lastCall.path, '/identifiers/aid1');
assert.equal(lastCall.method, 'DELETE');
});
});

0 comments on commit 5c65b95

Please sign in to comment.