Skip to content

Commit

Permalink
Merge pull request WebOfTrust#212 from lenkan/multisig-inception-utils
Browse files Browse the repository at this point in the history
Multisig inception utils for testing
  • Loading branch information
pfeairheller authored Feb 13, 2024
2 parents 433a968 + 94fa319 commit 7e40b4b
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 169 deletions.
108 changes: 22 additions & 86 deletions examples/integration-scripts/delegation-multisig.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { strict as assert } from 'assert';
import signify from 'signify-ts';
import {
assertNotifications,
assertOperations,
markAndRemoveNotification,
resolveOobi,
Expand All @@ -9,6 +10,10 @@ import {
warnNotifications,
} from './utils/test-util';
import { getOrCreateClient, getOrCreateIdentifier } from './utils/test-setup';
import {
acceptMultisigIncept,
startMultisigIncept,
} from './utils/multisig-utils';

test('delegation-multisig', async () => {
await signify.ready();
Expand Down Expand Up @@ -42,102 +47,33 @@ test('delegation-multisig', async () => {
console.log('Member1 and Member2 resolved 2 OOBIs');

// First member start the creation of a multisig identifier
const rstates = [aid1['state'], aid2['state']];
const states = rstates;
const icpResult1 = await client1.identifiers().create('multisig', {
algo: signify.Algos.group,
mhab: aid1,
const op1 = await startMultisigIncept(client1, {
groupName: 'multisig',
localMemberName: aid1.name,
participants: [aid1.prefix, aid2.prefix],
isith: 2,
nsith: 2,
toad: 2,
delpre: aid0.prefix,
wits: [
'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha',
'BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM',
'BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX',
],
states: states,
rstates: rstates,
delpre: aid0.prefix,
});
const op1 = await icpResult1.op();
let serder = icpResult1.serder;

let sigs = icpResult1.sigs;
let sigers = sigs.map((sig) => new signify.Siger({ qb64: sig }));
let ims = signify.d(signify.messagize(serder, sigers));
let atc = ims.substring(serder.size);
let embeds = {
icp: [serder, atc],
};

let smids = states.map((state) => state['i']);
let recp = [aid2['state']].map((state) => state['i']);

await client1
.exchanges()
.send(
'member1',
'multisig',
aid1,
'/multisig/icp',
{ gid: serder.pre, smids: smids, rmids: smids },
embeds,
recp
);
console.log('Member1 initiated multisig, waiting for others to join...');

// Second member check notifications and join the multisig
const notifications = await waitForNotifications(client2, '/multisig/icp');
const msgSaid = notifications[notifications.length - 1].a.d;
assert(msgSaid !== undefined);
console.log('Member2 received exchange message to join multisig');

const res = await client2.groups().getRequest(msgSaid);

await Promise.all(
notifications.map((note) => markAndRemoveNotification(client2, note))
);

const exn = res[0].exn;
const icp = exn.e.icp;

const icpResult2 = await client2.identifiers().create('multisig', {
algo: signify.Algos.group,
mhab: aid2,
isith: icp.kt,
nsith: icp.nt,
toad: parseInt(icp.bt),
wits: icp.b,
states: states,
rstates: rstates,
delpre: aid0.prefix,
const [notification] = await waitForNotifications(client2, '/multisig/icp');
await markAndRemoveNotification(client2, notification);
assert(notification.a.d);
const op2 = await acceptMultisigIncept(client2, {
localMemberName: aid2.name,
groupName: 'multisig',
msgSaid: notification.a.d,
});
const op2 = await icpResult2.op();
serder = icpResult2.serder;
sigs = icpResult2.sigs;
sigers = sigs.map((sig) => new signify.Siger({ qb64: sig }));

ims = signify.d(signify.messagize(serder, sigers));
atc = ims.substring(serder.size);
embeds = {
icp: [serder, atc],
};

smids = exn.a.smids;
recp = [aid1['state']].map((state) => state['i']);

await client2
.exchanges()
.send(
'member2',
'multisig',
aid2,
'/multisig/icp',
{ gid: serder.pre, smids: smids, rmids: smids },
embeds,
recp
);
console.log('Member2 joined multisig, waiting for others...');
console.log('Member2 joined multisig, waiting for delegator...');

const delegatePrefix = op1.name.split('.')[1];
assert.equal(op2.name.split('.')[1], delegatePrefix);
Expand All @@ -150,12 +86,12 @@ test('delegation-multisig', async () => {
s: '0',
d: delegatePrefix,
};
let ixnResult = await client0.identifiers().interact('delegator', anchor);
const ixnResult = await client0.identifiers().interact('delegator', anchor);
await waitOperation(client0, await ixnResult.op());
console.log('Delegator approved delegation');

let op3 = await client1.keyStates().query(aid0.prefix, '1');
let op4 = await client2.keyStates().query(aid0.prefix, '1');
const op3 = await client1.keyStates().query(aid0.prefix, '1');
const op4 = await client2.keyStates().query(aid0.prefix, '1');

// Check for completion
await Promise.all([
Expand All @@ -170,7 +106,7 @@ test('delegation-multisig', async () => {
assert.equal(aid_delegate.prefix, delegatePrefix);

await assertOperations(client0, client1, client2);
await warnNotifications(client0, client1, client2);
await assertNotifications(client0, client1, client2);
}, 30000);

async function createAID(client: signify.SignifyClient, name: string) {
Expand Down
105 changes: 22 additions & 83 deletions examples/integration-scripts/multisig-holder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
warnNotifications,
} from './utils/test-util';
import { getOrCreateClient, getOrCreateIdentifier } from './utils/test-setup';
import {
acceptMultisigIncept,
startMultisigIncept,
} from './utils/multisig-utils';

const { vleiServerUrl } = resolveEnvironment();
const WITNESS_AIDS = [
Expand All @@ -36,7 +40,7 @@ test('multisig', async function run() {
]);

// Create three identifiers, one for each client
let [aid1, aid2, aid3] = await Promise.all([
let [aid1, aid2, _aid3] = await Promise.all([
createAID(client1, 'member1', WITNESS_AIDS),
createAID(client2, 'member2', WITNESS_AIDS),
createAID(client3, 'issuer', WITNESS_AIDS),
Expand Down Expand Up @@ -77,90 +81,25 @@ test('multisig', async function run() {
console.log('Issuer resolved 3 OOBIs');

//// First member start the creation of a multisig identifier
const rstates = [aid1['state'], aid2['state']];
const states = rstates;
const icpResult1 = await client1.identifiers().create('holder', {
algo: signify.Algos.group,
mhab: aid1,
op1 = await startMultisigIncept(client1, {
groupName: 'holder',
localMemberName: aid1.name,
isith: 2,
nsith: 2,
toad: aid1.state.b.length,
wits: aid1.state.b,
states: states,
rstates: rstates,
participants: [aid1.prefix, aid2.prefix],
});
op1 = await icpResult1.op();
let serder = icpResult1.serder;

let sigs = icpResult1.sigs;
let sigers = sigs.map((sig) => new signify.Siger({ qb64: sig }));

let ims = signify.d(signify.messagize(serder, sigers));
let atc = ims.substring(serder.size);
let embeds = {
icp: [serder, atc],
};

let smids = states.map((state) => state['i']);
let recp = [aid2['state']].map((state) => state['i']);

await client1
.exchanges()
.send(
'member1',
'multisig',
aid1,
'/multisig/icp',
{ gid: serder.pre, smids: smids, rmids: smids },
embeds,
recp
);
console.log('Member1 initiated multisig, waiting for others to join...');

// Second member check notifications and join the multisig

let msgSaid = await waitAndMarkNotification(client2, '/multisig/icp');
console.log('Member2 received exchange message to join multisig');

let res = await client2.groups().getRequest(msgSaid);
let exn = res[0].exn;
let icp = exn.e.icp;

let icpResult2 = await client2.identifiers().create('holder', {
algo: signify.Algos.group,
mhab: aid2,
isith: icp.kt,
nsith: icp.nt,
toad: parseInt(icp.bt),
wits: icp.b,
states: states,
rstates: rstates,
op2 = await acceptMultisigIncept(client2, {
groupName: 'holder',
localMemberName: aid2.name,
msgSaid,
});
op2 = await icpResult2.op();
serder = icpResult2.serder;
sigs = icpResult2.sigs;
sigers = sigs.map((sig) => new signify.Siger({ qb64: sig }));

ims = signify.d(signify.messagize(serder, sigers));
atc = ims.substring(serder.size);
embeds = {
icp: [serder, atc],
};

smids = exn.a.smids;
recp = [aid1['state']].map((state) => state['i']);

await client2
.exchanges()
.send(
'member2',
'multisig',
aid2,
'/multisig/icp',
{ gid: serder.pre, smids: smids, rmids: smids },
embeds,
recp
);
console.log('Member2 joined multisig, waiting for others...');

// Check for completion
Expand Down Expand Up @@ -208,7 +147,7 @@ test('multisig', async function run() {
.addEndRole('holder', 'agent', eid1, stamp);
op1 = await endRoleRes.op();
let rpy = endRoleRes.serder;
sigs = endRoleRes.sigs;
let sigs = endRoleRes.sigs;
let ghabState1 = ghab1['state'];
let seal = [
'SealEvent',
Expand All @@ -218,16 +157,16 @@ test('multisig', async function run() {
d: ghabState1['ee']['d'],
},
];
sigers = sigs.map((sig) => new signify.Siger({ qb64: sig }));
let sigers = sigs.map((sig: string) => new signify.Siger({ qb64: sig }));
let roleims = signify.d(
signify.messagize(rpy, sigers, seal, undefined, undefined, false)
);
atc = roleims.substring(rpy.size);
let atc = roleims.substring(rpy.size);
let roleembeds = {
rpy: [rpy, atc],
};
recp = [aid2['state']].map((state) => state['i']);
res = await client1
let recp = [aid2['state']].map((state) => state['i']);
let res = await client1
.exchanges()
.send(
'member1',
Expand All @@ -248,7 +187,7 @@ test('multisig', async function run() {
'Member2 received exchange message to join the end role authorization'
);
res = await client2.groups().getRequest(msgSaid);
exn = res[0].exn;
let exn = res[0].exn;
// stamp, eid and role are provided in the exn message
let rpystamp = exn.e.rpy.dt;
let rpyrole = exn.e.rpy.a.role;
Expand All @@ -271,7 +210,7 @@ test('multisig', async function run() {
d: ghabState2['ee']['d'],
},
];
sigers = sigs.map((sig) => new signify.Siger({ qb64: sig }));
sigers = sigs.map((sig: string) => new signify.Siger({ qb64: sig }));
roleims = signify.d(
signify.messagize(rpy, sigers, seal, undefined, undefined, false)
);
Expand Down Expand Up @@ -318,7 +257,7 @@ test('multisig', async function run() {
d: ghabState1['ee']['d'],
},
];
sigers = sigs.map((sig) => new signify.Siger({ qb64: sig }));
sigers = sigs.map((sig: string) => new signify.Siger({ qb64: sig }));
roleims = signify.d(
signify.messagize(rpy, sigers, seal, undefined, undefined, false)
);
Expand Down Expand Up @@ -372,7 +311,7 @@ test('multisig', async function run() {
},
];

sigers = sigs.map((sig) => new signify.Siger({ qb64: sig }));
sigers = sigs.map((sig: string) => new signify.Siger({ qb64: sig }));
roleims = signify.d(
signify.messagize(rpy, sigers, seal, undefined, undefined, false)
);
Expand Down
Loading

0 comments on commit 7e40b4b

Please sign in to comment.