diff --git a/examples/integration-scripts/delegation-multisig.test.ts b/examples/integration-scripts/delegation-multisig.test.ts index 39aacf68..6285227a 100644 --- a/examples/integration-scripts/delegation-multisig.test.ts +++ b/examples/integration-scripts/delegation-multisig.test.ts @@ -46,7 +46,7 @@ test('delegation-multisig', async () => { mhab: aid1, isith: 2, nsith: 2, - toad: 3, + toad: 2, wits: [ 'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha', 'BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM', @@ -148,10 +148,15 @@ test('delegation-multisig', async () => { await client0.identifiers().interact('delegator', anchor); console.log('Delegator approved delegation'); + let op3 = await client1.keyStates().query(aid0.prefix, '1'); + let op4 = await client2.keyStates().query(aid0.prefix, '1'); + // Check for completion await Promise.all([ waitOperation(client1, op1), waitOperation(client2, op2), + waitOperation(client1, op3), + waitOperation(client2, op4), ]); console.log('Delegated multisig created!'); diff --git a/examples/integration-scripts/delegation.test.ts b/examples/integration-scripts/delegation.test.ts index ae771826..c1fff692 100644 --- a/examples/integration-scripts/delegation.test.ts +++ b/examples/integration-scripts/delegation.test.ts @@ -81,6 +81,9 @@ test('delegation', async () => { await client1.identifiers().interact('delegator', anchor); console.log('Delegator approved delegation'); + let op3 = await client2.keyStates().query(aid1.prefix, '1'); + await waitOperation(client2, op3); + // Client 2 check approval await waitOperation(client2, op2); const aid2 = await client2.identifiers().get('delegate'); diff --git a/examples/integration-scripts/singlesig-dip.test.ts b/examples/integration-scripts/singlesig-dip.test.ts index 7a413e2c..626b494d 100644 --- a/examples/integration-scripts/singlesig-dip.test.ts +++ b/examples/integration-scripts/singlesig-dip.test.ts @@ -31,54 +31,59 @@ describe('singlesig-dip', () => { let op = await result.op(); let delegate1 = await client2.identifiers().get('delegate1'); expect(op.name).toEqual(`delegation.${delegate1.prefix}`); - }); - test('delegator1', async () => { - // delegator approves delegate - let delegate1 = await client2.identifiers().get('delegate1'); + + delegate1 = await client2.identifiers().get('delegate1'); let seal = { i: delegate1.prefix, s: '0', d: delegate1.prefix, }; - let result = await client1.identifiers().interact('name1', seal); - let op = waitOperation(client1, await result.op()); - }); - test('delegate1b', async () => { - // delegate waits for completion - let delegate1 = await client2.identifiers().get('delegate1'); - let op: any = { name: `delegation.${delegate1.prefix}` }; - op = await waitOperation(client2, op); + result = await client1.identifiers().interact('name1', seal); + let op1 = await result.op(); + + let op2 = await client2.keyStates().query(name1_id, '1'); + + await Promise.all([ + (op = await waitOperation(client2, op)), + waitOperation(client1, op1), + waitOperation(client2, op2), + ]); + + delegate1 = await client2.identifiers().get('delegate1'); expect(delegate1.prefix).toEqual(op.response.i); - }); - test('delegate2a', async () => { + // delegate creates identifier with default witness config let env = resolveEnvironment(); - let kargs: CreateIdentiferArgs = { + kargs = { delpre: name1_id, toad: env.witnessIds.length, wits: env.witnessIds, }; - let result = await client2.identifiers().create('delegate2', kargs); - let op = await result.op(); + result = await client2.identifiers().create('delegate2', kargs); + op = await result.op(); let delegate2 = await client2.identifiers().get('delegate2'); expect(op.name).toEqual(`delegation.${delegate2.prefix}`); - }); - test('delegator2', async () => { + // delegator approves delegate - let delegate2 = await client2.identifiers().get('delegate2'); - let seal = { + delegate2 = await client2.identifiers().get('delegate2'); + seal = { i: delegate2.prefix, s: '0', d: delegate2.prefix, }; - let result = await client1.identifiers().interact('name1', seal); - let op = waitOperation(client1, await result.op()); - }); - test('delegate2b', async () => { + result = await client1.identifiers().interact('name1', seal); + op1 = await result.op(); + + op2 = await client2.keyStates().query(name1_id, '2'); + + await Promise.all([ + (op = await waitOperation(client2, op)), + waitOperation(client1, op1), + waitOperation(client2, op2), + ]); + // delegate waits for completion - let delegate2 = await client2.identifiers().get('delegate2'); - let op: any = { name: `delegation.${delegate2.prefix}` }; - op = await waitOperation(client2, op); + delegate2 = await client2.identifiers().get('delegate2'); expect(delegate2.prefix).toEqual(op.response.i); }); }); diff --git a/examples/integration-scripts/singlesig-drt.test.ts b/examples/integration-scripts/singlesig-drt.test.ts new file mode 100644 index 00000000..4253c752 --- /dev/null +++ b/examples/integration-scripts/singlesig-drt.test.ts @@ -0,0 +1,78 @@ +import { CreateIdentiferArgs, SignifyClient } from 'signify-ts'; +import { + getOrCreateClients, + getOrCreateContact, + getOrCreateIdentifier, +} from './utils/test-setup'; +import { waitOperation } from './utils/test-util'; + +let delegator: SignifyClient, delegate: SignifyClient; +let name1_id: string, name1_oobi: string; +let contact1_id: string; + +beforeAll(async () => { + [delegator, delegate] = await getOrCreateClients(2); +}); +beforeAll(async () => { + [name1_id, name1_oobi] = await getOrCreateIdentifier(delegator, 'name1'); +}); +beforeAll(async () => { + contact1_id = await getOrCreateContact(delegate, 'contact1', name1_oobi); +}); + +describe('singlesig-drt', () => { + test('delegate1a', async () => { + // delegate creates identifier without witnesses + let kargs: CreateIdentiferArgs = { + delpre: name1_id, + }; + let result = await delegate.identifiers().create('delegate1', kargs); + let op = await result.op(); + let delegate1 = await delegate.identifiers().get('delegate1'); + expect(op.name).toEqual(`delegation.${delegate1.prefix}`); + + // delegator approves delegate + let seal = { + i: delegate1.prefix, + s: '0', + d: delegate1.prefix, + }; + result = await delegator.identifiers().interact('name1', seal); + let op1 = await result.op(); + + let op2 = await delegate.keyStates().query(name1_id, '1'); + + await Promise.all([ + waitOperation(delegate, op), + waitOperation(delegator, op1), + waitOperation(delegate, op2), + ]); + + kargs = {}; + result = await delegate.identifiers().rotate('delegate1', kargs); + op = await result.op(); + expect(op.name).toEqual(`delegation.${delegate1.prefix}`); + + // delegator approves delegate + delegate1 = await delegate.identifiers().get('delegate1'); + + seal = { + i: delegate1.prefix, + s: '1', + d: delegate1.state.d, + }; + + result = await delegator.identifiers().interact('name1', seal); + op1 = await result.op(); + op2 = await delegate.keyStates().query(name1_id, '2'); + + await Promise.all([ + (op = await waitOperation(delegate, op)), + waitOperation(delegator, op1), + waitOperation(delegate, op2), + ]); + + expect(op.response.t).toEqual(`drt`); + expect(op.response.s).toEqual(`1`); + }); +}); diff --git a/examples/integration-scripts/utils/test-util.ts b/examples/integration-scripts/utils/test-util.ts index dbb4260f..6ebecdee 100644 --- a/examples/integration-scripts/utils/test-util.ts +++ b/examples/integration-scripts/utils/test-util.ts @@ -22,6 +22,7 @@ export async function waitOperation( throw new Error(`Operation ${op.name} not done`); } + console.log('DONE', op.name); return op; }, options); } diff --git a/src/keri/app/aiding.ts b/src/keri/app/aiding.ts index aca4ac24..fb3272c7 100644 --- a/src/keri/app/aiding.ts +++ b/src/keri/app/aiding.ts @@ -2,7 +2,7 @@ import { SignifyClient } from './clienting'; import { Tier } from '../core/salter'; import { Algos } from '../core/manager'; import { incept, interact, reply, rotate } from '../core/eventing'; -import { b, Serials, Versionage } from '../core/core'; +import { b, Ilks, Serials, Versionage } from '../core/core'; import { Tholder } from '../core/tholder'; import { MtrDex } from '../core/matter'; import { Serder } from '../core/serder'; @@ -287,6 +287,7 @@ export class Identifier { const hab = await this.get(name); const pre = hab.prefix; + const delegated = hab.state.di !== ''; const state = hab.state; const count = state.k.length; @@ -326,8 +327,11 @@ export class Identifier { const adds = kargs.adds ?? []; const data = kargs.data != undefined ? [kargs.data] : []; const toad = kargs.toad; + const ilk = delegated ? Ilks.drt : Ilks.rot; + const serder = rotate({ pre: pre, + ilk: ilk, keys: keys, dig: dig, sn: ridx,