-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultisig-join-registry-problem.test.ts
206 lines (179 loc) · 5.79 KB
/
multisig-join-registry-problem.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { beforeAll, describe, expect, test } from "vitest";
import { TestWallet } from "../test-wallet.ts";
import { createTimestamp, introduce } from "../test-utils.ts";
import { b, Serder } from "signify-ts";
let wallets: TestWallet[];
const groupAlias = "group";
const registryName = "vlei";
let registryNonce: string;
let wits: string[];
let toad: number;
beforeAll(async () => {
wallets = Array.from({ length: 2 }).map(
(_, idx) =>
new TestWallet({
alias: `member${(idx + 1).toString().padStart(2, "0")}`,
})
);
await Promise.all(wallets.map((w) => w.init()));
registryNonce = TestWallet.randomNonce();
wits = process.env.WITNESS_IDS?.split(";") ?? [];
toad = Math.min(wits.length, Math.max(wits.length - 1, 0));
});
describe("join multisig group with credential registry", () => {
test("resolve all OOBIs", async () => {
await introduce(wallets);
});
test("multisig members create multisig group", async () => {
const smids = wallets.map((w) => w.identifier.prefix);
const isith = wallets.length;
await Promise.all(
wallets.map(async (wallet) => {
const operation = await wallet.createGroup(groupAlias, {
smids,
isith,
wits,
toad,
});
await wallet.wait(operation, {
signal: AbortSignal.timeout(10_000),
});
})
);
});
test("multisig members create agent endroles", async () => {
const dt = createTimestamp();
await Promise.all(
wallets.map(async (wallet) => {
await Promise.all(
wallets.map(async (agentWallet) => {
const operation = await wallet.addEndRole(
groupAlias,
dt,
agentWallet.client.agent!.pre
);
await wallet.wait(operation, {
signal: AbortSignal.timeout(10_000),
});
})
);
})
);
});
test("multisig creates registry", async () => {
const results = await Promise.all(
wallets.map(async (wallet) => {
const operation = await wallet.createRegistry({
name: groupAlias,
registryName,
nonce: registryNonce,
});
return wallet.wait(operation, {
signal: AbortSignal.timeout(10_000),
});
})
);
const [registry] = await wallets[0].client.registries().list(groupAlias);
expect(registry).toHaveProperty("regk");
});
describe("new multisig member", () => {
let allWallets: TestWallet[];
let newWallet: TestWallet;
beforeAll(async () => {
newWallet = new TestWallet({
alias: `newMember`,
});
await newWallet.init();
allWallets = [...wallets, newWallet];
});
test("resolve all oobis", async () => {
await introduce(allWallets);
});
test("multisig members rotate their own identifiers", async () => {
await Promise.all(
wallets.map(async (wallet) => {
const operation = await wallet.rotateIdentifier({
identifierAlias: wallet.identifier.name,
});
await wallet.wait(operation, {
signal: AbortSignal.timeout(10_000),
});
await wallet.refreshIdentifier();
})
);
});
test("multisig rotates in a new member, to next keys", async () => {
const newMemberStates = allWallets.map(
(wallet) => wallet.identifier.state
);
await Promise.all(
wallets.map(async (wallet) => {
const operation = await wallet.rotateIdentifier({
identifierAlias: groupAlias,
rotationStates: newMemberStates,
});
await wallet.wait(operation, {
signal: AbortSignal.timeout(20_000),
});
})
);
});
test("multisig members rotate their own identifiers", async () => {
await Promise.all(
allWallets.map(async (wallet) => {
await wallet.clearNotifications();
const operation = await wallet.rotateIdentifier({
identifierAlias: wallet.identifier.name,
});
await wallet.wait(operation, {
signal: AbortSignal.timeout(10_000),
});
await wallet.refreshIdentifier();
})
);
});
test("multisig rotates in a new member, to signing keys", async () => {
const newMemberStates = allWallets.map(
(wallet) => wallet.identifier.state
);
await Promise.all(
wallets.map(async (wallet) => {
const operation = await wallet.rotateIdentifier({
identifierAlias: groupAlias,
rotationStates: newMemberStates,
});
await wallet.wait(operation, {
signal: AbortSignal.timeout(20_000),
});
})
);
});
test("new member joins group", async () => {
const rotationNotification = await newWallet.waitNotification(
"/multisig/rot",
AbortSignal.timeout(20_000)
);
const exchangeResult = await newWallet.client
.exchanges()
.get(rotationNotification.a.d);
const { exn } = exchangeResult;
await newWallet.resolveOobi(
(await wallets[0].generateOobi(groupAlias)).split("/agent/")[0],
groupAlias
);
const serder = new Serder(exn.e.rot);
const keeper = newWallet.client.manager!.get(newWallet.identifier);
const sigs = keeper.sign(b(serder.raw));
const joinOperation = await newWallet.client
.groups()
.join(groupAlias, serder, sigs, exn.a.gid, exn.a.smids, exn.a.rmids);
await newWallet.wait(joinOperation, {
signal: AbortSignal.timeout(20_000),
});
});
test("new member list group registry", async () => {
const registry = await newWallet.client.registries().list(groupAlias);
expect(registry.length).toBe(1);
});
});
});