@kumiai/mls 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/lib/anchor.d.ts +10 -4
- package/lib/anchor.js +26 -2
- package/lib/authentication.d.ts +11 -14
- package/lib/authentication.js +127 -86
- package/lib/capability.d.ts +37 -0
- package/lib/capability.js +141 -0
- package/lib/codec.js +2 -1
- package/lib/device-proof.d.ts +1 -0
- package/lib/device-proof.js +8 -12
- package/lib/envelope-fold.d.ts +16 -1
- package/lib/envelope-fold.js +49 -9
- package/lib/errors.d.ts +18 -0
- package/lib/errors.js +33 -0
- package/lib/group-commit.d.ts +22 -35
- package/lib/group-commit.js +122 -103
- package/lib/group-context.d.ts +6 -2
- package/lib/group-context.js +11 -4
- package/lib/group-create.js +56 -11
- package/lib/group-credential.d.ts +3 -1
- package/lib/group-credential.js +17 -3
- package/lib/group-device.js +34 -21
- package/lib/group-handle.d.ts +60 -24
- package/lib/group-handle.js +331 -77
- package/lib/group-info.d.ts +8 -0
- package/lib/group-info.js +29 -1
- package/lib/group-lifecycle.d.ts +32 -0
- package/lib/group-lifecycle.js +300 -0
- package/lib/group-membership.js +7 -3
- package/lib/group-welcome.d.ts +13 -4
- package/lib/group-welcome.js +113 -21
- package/lib/group.d.ts +3 -2
- package/lib/group.js +2 -1
- package/lib/history.d.ts +6 -0
- package/lib/history.js +26 -0
- package/lib/index.d.ts +10 -4
- package/lib/index.js +9 -3
- package/lib/lifecycle-proof.d.ts +24 -0
- package/lib/lifecycle-proof.js +193 -0
- package/lib/lifecycle.d.ts +44 -0
- package/lib/lifecycle.js +385 -0
- package/lib/policy.d.ts +20 -0
- package/lib/policy.js +8 -4
- package/lib/recovery-verdict.d.ts +43 -0
- package/lib/recovery-verdict.js +135 -0
- package/lib/recovery.d.ts +70 -0
- package/lib/recovery.js +110 -36
- package/lib/registry.d.ts +34 -7
- package/lib/registry.js +113 -15
- package/lib/roster.d.ts +1 -1
- package/lib/roster.js +2 -2
- package/lib/types.d.ts +13 -8
- package/lib/welcome-refs.d.ts +2 -1
- package/package.json +6 -6
package/lib/lifecycle.js
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { foldLog } from '@kokuin/controller';
|
|
2
|
+
import { normalizeDID } from '@kokuin/token';
|
|
3
|
+
import { defaultCredentialTypes, defaultProposalTypes, isDefaultCredential, isDefaultProposal, nodeTypes } from 'ts-mls';
|
|
4
|
+
import { LEDGER_HEAD_EXTENSION_TYPE } from './anchor.js';
|
|
5
|
+
import { verifyLeafCredential } from './authentication.js';
|
|
6
|
+
import { assertCapabilityLifetime, MAX_LEAF_LIFETIME, MAX_TRUSTED_GRANT_LIFETIME, readCapability } from './capability.js';
|
|
7
|
+
import { parseMLSCredentialIdentity } from './credential.js';
|
|
8
|
+
import { LeafBindingError, LeafLapsedError, RevokeProofError } from './errors.js';
|
|
9
|
+
import { assertBindingAuthorTime, makeMLSCredential } from './group-credential.js';
|
|
10
|
+
import { decodeLedgerHead, extendHead, genesisHead, headsMatch } from './head.js';
|
|
11
|
+
import { HISTORY_HORIZON, historySize } from './history.js';
|
|
12
|
+
import { verifyLifecycleProof } from './lifecycle-proof.js';
|
|
13
|
+
import { evaluateGroupContextExtensions } from './policy.js';
|
|
14
|
+
import { DEVICE_ENTRY_TYPE, denySetOf } from './registry.js';
|
|
15
|
+
export function rejectionReason(error) {
|
|
16
|
+
if (error instanceof LeafLapsedError) return 'lapse';
|
|
17
|
+
if (error instanceof LeafBindingError) {
|
|
18
|
+
if (error.reason === 'generation-floor') return 'floor';
|
|
19
|
+
return [
|
|
20
|
+
'denied-id',
|
|
21
|
+
'identity-change'
|
|
22
|
+
].includes(error.reason) ? 'invalid' : 'binding';
|
|
23
|
+
}
|
|
24
|
+
if (error instanceof RevokeProofError && [
|
|
25
|
+
'generation-floor',
|
|
26
|
+
'time-regression'
|
|
27
|
+
].includes(error.reason)) return 'floor';
|
|
28
|
+
return 'invalid';
|
|
29
|
+
}
|
|
30
|
+
function identity(leaf) {
|
|
31
|
+
if (!isDefaultCredential(leaf.credential) || leaf.credential.credentialType !== defaultCredentialTypes.basic) {
|
|
32
|
+
throw new LeafBindingError('identity-change');
|
|
33
|
+
}
|
|
34
|
+
return parseMLSCredentialIdentity(leaf.credential.identity);
|
|
35
|
+
}
|
|
36
|
+
export function leafAt(tree, index) {
|
|
37
|
+
const node = tree[index * 2];
|
|
38
|
+
return node?.nodeType === nodeTypes.leaf ? node.leaf : undefined;
|
|
39
|
+
}
|
|
40
|
+
function attestedTime(leaf, controllerID) {
|
|
41
|
+
const binding = identity(leaf).controller;
|
|
42
|
+
if (binding == null || normalizeDID(binding.id) !== normalizeDID(controllerID)) return 0;
|
|
43
|
+
const payload = readCapability(binding.capability).payload;
|
|
44
|
+
const parent = Array.isArray(payload.cap) ? payload.cap[0] : payload.cap;
|
|
45
|
+
return parent == null ? payload.iat : readCapability(parent).payload.iat;
|
|
46
|
+
}
|
|
47
|
+
function timeOf(tree, controllerID, floor) {
|
|
48
|
+
let time = floor;
|
|
49
|
+
for (const node of tree){
|
|
50
|
+
if (node?.nodeType === nodeTypes.leaf) time = Math.max(time, attestedTime(node.leaf, controllerID));
|
|
51
|
+
}
|
|
52
|
+
return time;
|
|
53
|
+
}
|
|
54
|
+
export function treeTime(group, controllerID) {
|
|
55
|
+
const floor = group.anchor.controller == null ? 0 : group.registry.controllers.get(normalizeDID(controllerID))?.timeFloor ?? 0;
|
|
56
|
+
return timeOf(group.state.ratchetTree, controllerID, floor);
|
|
57
|
+
}
|
|
58
|
+
export function isLapsed(group, leaf) {
|
|
59
|
+
const controller = group.anchor.controller;
|
|
60
|
+
if (controller == null) return false;
|
|
61
|
+
const binding = identity(leaf).controller;
|
|
62
|
+
return binding != null && readCapability(binding.capability).payload.exp < treeTime(group, controller);
|
|
63
|
+
}
|
|
64
|
+
function bytesEqual(a, b) {
|
|
65
|
+
return a.length === b.length && a.every((byte, index)=>byte === b[index]);
|
|
66
|
+
}
|
|
67
|
+
function credentialEqual(a, b) {
|
|
68
|
+
return isDefaultCredential(a.credential) && isDefaultCredential(b.credential) && a.credential.credentialType === defaultCredentialTypes.basic && b.credential.credentialType === defaultCredentialTypes.basic && bytesEqual(a.credential.identity, b.credential.identity);
|
|
69
|
+
}
|
|
70
|
+
function checkBinding(group, leaf, previous) {
|
|
71
|
+
const parsed = identity(leaf);
|
|
72
|
+
const binding = parsed.controller;
|
|
73
|
+
const controller = group.anchor.controller;
|
|
74
|
+
if (controller != null && binding == null) throw new LeafBindingError('floating-refused');
|
|
75
|
+
if (controller != null && binding != null && normalizeDID(binding.id) !== normalizeDID(controller)) throw new LeafBindingError('controller-mismatch');
|
|
76
|
+
const denied = denySetOf(group.registry);
|
|
77
|
+
if (denied.has(normalizeDID(parsed.id))) throw new LeafBindingError('denied-id');
|
|
78
|
+
const record = group.registry.devices.get(normalizeDID(parsed.id));
|
|
79
|
+
if (record != null && (binding == null || normalizeDID(binding.id) !== record.controller)) throw new LeafBindingError('controller-mismatch');
|
|
80
|
+
if (previous != null) {
|
|
81
|
+
const old = identity(previous);
|
|
82
|
+
if (parsed.id !== old.id || parsed.longForm !== old.longForm || !bytesEqual(leaf.signaturePublicKey, previous.signaturePublicKey) || old.controller != null && (binding == null || binding.id !== old.controller.id)) throw new LeafBindingError('identity-change');
|
|
83
|
+
if (binding != null && old.controller != null && readCapability(binding.capability).payload.iat < readCapability(old.controller.capability).payload.iat) throw new LeafBindingError('renewal-order');
|
|
84
|
+
}
|
|
85
|
+
if (binding == null) return;
|
|
86
|
+
const payload = readCapability(binding.capability).payload;
|
|
87
|
+
assertCapabilityLifetime(payload, controller == null ? MAX_LEAF_LIFETIME : group.anchor.leafLifetime ?? 86_400);
|
|
88
|
+
const parent = Array.isArray(payload.cap) ? payload.cap[0] : payload.cap;
|
|
89
|
+
if (parent != null) assertCapabilityLifetime(readCapability(parent).payload, controller == null ? MAX_TRUSTED_GRANT_LIFETIME : group.anchor.trustedGrantLifetime ?? 2_592_000);
|
|
90
|
+
if (payload.cap != null && denied.has(normalizeDID(payload.iss))) throw new LeafBindingError('denied-issuer');
|
|
91
|
+
const folded = foldLog(binding.id, binding.prefix);
|
|
92
|
+
if (!folded.ok) throw new LeafBindingError('controller-mismatch');
|
|
93
|
+
if (controller != null && (folded.states.at(-1)?.gen ?? 0) < (group.registry.controllers.get(normalizeDID(controller))?.genFloor ?? 0)) throw new LeafBindingError('generation-floor');
|
|
94
|
+
}
|
|
95
|
+
function checkAdmissionExpiry(group, leaf) {
|
|
96
|
+
const binding = identity(leaf).controller;
|
|
97
|
+
if (binding != null && readCapability(binding.capability).payload.exp <= treeTime(group, binding.id)) throw new LeafLapsedError('lapsed');
|
|
98
|
+
}
|
|
99
|
+
function checkEntry(group, leaf, previous) {
|
|
100
|
+
checkBinding(group, leaf, previous);
|
|
101
|
+
checkAdmissionExpiry(group, leaf);
|
|
102
|
+
}
|
|
103
|
+
async function validateBoundLeaf(group, leaf, previous) {
|
|
104
|
+
checkBinding(group, leaf, previous);
|
|
105
|
+
await verifyLeafCredential(leaf.credential, leaf.signaturePublicKey, {
|
|
106
|
+
deviceDenySet: ()=>denySetOf(group.registry),
|
|
107
|
+
leafLifetime: ()=>group.anchor.controller == null ? undefined : group.anchor.leafLifetime ?? 86_400,
|
|
108
|
+
trustedGrantLifetime: ()=>group.anchor.controller == null ? undefined : group.anchor.trustedGrantLifetime ?? 2_592_000
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
export async function validateEntry(group, leaf, previous) {
|
|
112
|
+
await validateBoundLeaf(group, leaf, previous);
|
|
113
|
+
checkAdmissionExpiry(group, leaf);
|
|
114
|
+
}
|
|
115
|
+
function checkSurvivors(group, tree, registry) {
|
|
116
|
+
const denied = denySetOf(registry);
|
|
117
|
+
const controller = group.anchor.controller;
|
|
118
|
+
for (const node of tree){
|
|
119
|
+
if (node?.nodeType !== nodeTypes.leaf) continue;
|
|
120
|
+
const parsed = identity(node.leaf);
|
|
121
|
+
if (denied.has(normalizeDID(parsed.id))) throw new LeafBindingError('denied-id');
|
|
122
|
+
if (parsed.controller == null) {
|
|
123
|
+
if (controller != null) throw new LeafBindingError('floating-refused');
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const binding = parsed.controller;
|
|
127
|
+
const payload = readCapability(binding.capability).payload;
|
|
128
|
+
if (payload.cap != null && denied.has(normalizeDID(payload.iss))) throw new LeafBindingError('denied-issuer');
|
|
129
|
+
if (controller != null) {
|
|
130
|
+
const folded = foldLog(binding.id, binding.prefix);
|
|
131
|
+
if (normalizeDID(binding.id) !== normalizeDID(controller) || !folded.ok) throw new LeafBindingError('controller-mismatch');
|
|
132
|
+
if ((folded.states.at(-1)?.gen ?? 0) < (registry.controllers.get(normalizeDID(controller))?.genFloor ?? 0)) throw new LeafBindingError('generation-floor');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export async function validateWelcomeTree(group) {
|
|
137
|
+
for (const [index, node] of group.state.ratchetTree.entries()){
|
|
138
|
+
if (node?.nodeType !== nodeTypes.leaf) continue;
|
|
139
|
+
await validateBoundLeaf(group, node.leaf);
|
|
140
|
+
if (index === group.state.privatePath.leafIndex * 2) checkAdmissionExpiry(group, node.leaf);
|
|
141
|
+
}
|
|
142
|
+
checkSurvivors(group, group.state.ratchetTree, group.registry);
|
|
143
|
+
}
|
|
144
|
+
/** The callback judges proposals; survivors check the path before any state is installed. */ export async function prepareLifecycleGate(params) {
|
|
145
|
+
const { group, entries, candidateRegistry, context, externalLeaf } = params;
|
|
146
|
+
const controller = group.anchor.controller;
|
|
147
|
+
if (controller == null) {
|
|
148
|
+
for (const { entry, issuer } of entries){
|
|
149
|
+
if (entry.type !== DEVICE_ENTRY_TYPE) continue;
|
|
150
|
+
const capability = entry.value.capability;
|
|
151
|
+
const binding = group.bindingOfDID(issuer);
|
|
152
|
+
if (capability != null && binding?.controller != null && readCapability(capability).payload.exp < treeTime(group, binding.controller)) throw new LeafLapsedError('lapsed');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const before = group.state.ratchetTree;
|
|
156
|
+
const ledger = group.ledger.map(({ verified })=>verified);
|
|
157
|
+
const afterLedger = [
|
|
158
|
+
...ledger,
|
|
159
|
+
...entries
|
|
160
|
+
];
|
|
161
|
+
const beforeSize = controller == null ? 0 : historySize(before, ledger);
|
|
162
|
+
const beforeTime = controller == null ? 0 : treeTime(group, controller);
|
|
163
|
+
const lapsed = new Set();
|
|
164
|
+
if (controller != null) {
|
|
165
|
+
for(let index = 0; index * 2 < before.length; index++){
|
|
166
|
+
const leaf = leafAt(before, index);
|
|
167
|
+
const binding = leaf == null ? undefined : identity(leaf).controller;
|
|
168
|
+
if (binding != null && readCapability(binding.capability).payload.exp < beforeTime) lapsed.add(index);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const opOf = ({ entry })=>entry.value.op;
|
|
172
|
+
const lifecycleEntries = entries.filter((verified)=>verified.entry.type === DEVICE_ENTRY_TYPE && [
|
|
173
|
+
'revoke',
|
|
174
|
+
'reset',
|
|
175
|
+
'clock'
|
|
176
|
+
].includes(opOf(verified)));
|
|
177
|
+
const proofs = lifecycleEntries.filter((verified)=>opOf(verified) !== 'clock');
|
|
178
|
+
const clocks = lifecycleEntries.filter((verified)=>opOf(verified) === 'clock');
|
|
179
|
+
// A proof commit enacts its proof and at most one clock, nothing else.
|
|
180
|
+
const proofCarriesOtherEntries = proofs.length > 0 && entries.length !== proofs.length + clocks.length;
|
|
181
|
+
if (controller != null && (proofs.length > 1 || clocks.length > 1 || proofCarriesOtherEntries)) throw new RevokeProofError('effects-mismatch');
|
|
182
|
+
const expectedRemoves = new Set();
|
|
183
|
+
if (controller != null) {
|
|
184
|
+
for (const entry of lifecycleEntries){
|
|
185
|
+
const effects = await verifyLifecycleProof(group, entry);
|
|
186
|
+
if (opOf(entry) !== 'clock') for (const index of effects.removeLeafIndices)expectedRemoves.add(index);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (externalLeaf != null) await validateEntry(group, externalLeaf);
|
|
190
|
+
let incomingCommit;
|
|
191
|
+
function checkSize(tree) {
|
|
192
|
+
if (controller == null) return;
|
|
193
|
+
const size = historySize(tree, afterLedger);
|
|
194
|
+
if (size > HISTORY_HORIZON && size > beforeSize) throw new LeafBindingError('history-horizon');
|
|
195
|
+
}
|
|
196
|
+
function checkTime(tree) {
|
|
197
|
+
if (controller == null) return;
|
|
198
|
+
const floor = candidateRegistry.controllers.get(normalizeDID(controller))?.timeFloor ?? 0;
|
|
199
|
+
if (timeOf(tree, controller, floor) < beforeTime) throw new RevokeProofError('time-regression');
|
|
200
|
+
}
|
|
201
|
+
function checkRegistryAdds(proposals) {
|
|
202
|
+
for (const { entry } of entries){
|
|
203
|
+
if (entry.type !== DEVICE_ENTRY_TYPE) continue;
|
|
204
|
+
const value = entry.value;
|
|
205
|
+
if (value.op !== 'register' && value.op !== 'add') continue;
|
|
206
|
+
const subject = normalizeDID(entry.subject);
|
|
207
|
+
const held = group.registry.devices.get(subject);
|
|
208
|
+
if (held != null && held.controller !== normalizeDID(value.controller)) throw new LeafBindingError('controller-mismatch');
|
|
209
|
+
const current = group.bindingOfDID(subject);
|
|
210
|
+
if (current != null && current.controller !== normalizeDID(value.controller)) throw new LeafBindingError('controller-mismatch');
|
|
211
|
+
for (const { proposal } of proposals){
|
|
212
|
+
if (!isDefaultProposal(proposal) || proposal.proposalType !== defaultProposalTypes.add) continue;
|
|
213
|
+
const parsed = identity(proposal.add.keyPackage.leafNode);
|
|
214
|
+
if (normalizeDID(parsed.id) === subject && (parsed.controller == null || normalizeDID(parsed.controller.id) !== normalizeDID(value.controller))) throw new LeafBindingError('controller-mismatch');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const check = (incoming)=>{
|
|
219
|
+
const proposals = incoming.kind === 'commit' ? incoming.proposals : [
|
|
220
|
+
incoming.proposal
|
|
221
|
+
];
|
|
222
|
+
if (incoming.kind === 'commit') incomingCommit = incoming;
|
|
223
|
+
checkRegistryAdds(proposals);
|
|
224
|
+
const external = proposals.some(({ proposal })=>proposal.proposalType === defaultProposalTypes.external_init);
|
|
225
|
+
const removes = proposals.filter(({ proposal })=>isDefaultProposal(proposal) && proposal.proposalType === defaultProposalTypes.remove);
|
|
226
|
+
if (external) {
|
|
227
|
+
if (incoming.kind !== 'commit' || externalLeaf == null || proposals.length !== 2 || removes.length !== 1) throw new Error('Invalid external replacement');
|
|
228
|
+
const remove = removes[0]?.proposal;
|
|
229
|
+
if (remove == null || !isDefaultProposal(remove) || remove.proposalType !== defaultProposalTypes.remove) throw new Error('Missing replacement target');
|
|
230
|
+
const old = leafAt(before, remove.remove.removed);
|
|
231
|
+
if (old == null) throw new LeafBindingError('identity-change');
|
|
232
|
+
checkEntry(group, externalLeaf, old);
|
|
233
|
+
const tree = before.slice();
|
|
234
|
+
tree[remove.remove.removed * 2] = {
|
|
235
|
+
nodeType: nodeTypes.leaf,
|
|
236
|
+
leaf: externalLeaf
|
|
237
|
+
};
|
|
238
|
+
checkTime(tree);
|
|
239
|
+
checkSize(tree);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (controller != null && proofs.length > 0) {
|
|
243
|
+
const actual = removes.map(({ proposal })=>isDefaultProposal(proposal) && proposal.proposalType === defaultProposalTypes.remove ? proposal.remove.removed : -1);
|
|
244
|
+
if (actual.length !== expectedRemoves.size || new Set(actual).size !== expectedRemoves.size || actual.some((index)=>!expectedRemoves.has(index))) throw new RevokeProofError('removes-mismatch');
|
|
245
|
+
if (incoming.kind !== 'commit' || incoming.senderLeafIndex == null || expectedRemoves.has(incoming.senderLeafIndex)) throw new RevokeProofError('effects-mismatch');
|
|
246
|
+
}
|
|
247
|
+
const tree = before.slice();
|
|
248
|
+
for (const { proposal, senderLeafIndex: proposalSender } of proposals){
|
|
249
|
+
if (!isDefaultProposal(proposal)) {
|
|
250
|
+
if (controller != null) throw new Error('Unsupported lifecycle proposal');
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const sender = proposalSender ?? (incoming.kind === 'commit' ? incoming.senderLeafIndex : undefined);
|
|
254
|
+
if (controller != null && proofs.length > 0 && proposal.proposalType !== defaultProposalTypes.remove && proposal.proposalType !== defaultProposalTypes.group_context_extensions) throw new RevokeProofError('effects-mismatch');
|
|
255
|
+
switch(proposal.proposalType){
|
|
256
|
+
case defaultProposalTypes.add:
|
|
257
|
+
{
|
|
258
|
+
checkEntry(group, proposal.add.keyPackage.leafNode);
|
|
259
|
+
const parsed = identity(proposal.add.keyPackage.leafNode);
|
|
260
|
+
const record = candidateRegistry.devices.get(normalizeDID(parsed.id));
|
|
261
|
+
if (record != null && (parsed.controller == null || normalizeDID(parsed.controller.id) !== record.controller)) throw new LeafBindingError('controller-mismatch');
|
|
262
|
+
tree.push({
|
|
263
|
+
nodeType: nodeTypes.leaf,
|
|
264
|
+
leaf: proposal.add.keyPackage.leafNode
|
|
265
|
+
});
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
case defaultProposalTypes.update:
|
|
269
|
+
{
|
|
270
|
+
const old = sender == null ? undefined : leafAt(before, sender);
|
|
271
|
+
if (old == null || sender == null) throw new LeafBindingError('identity-change');
|
|
272
|
+
checkEntry(group, proposal.update.leafNode, old);
|
|
273
|
+
tree[sender * 2] = {
|
|
274
|
+
nodeType: nodeTypes.leaf,
|
|
275
|
+
leaf: proposal.update.leafNode
|
|
276
|
+
};
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
case defaultProposalTypes.remove:
|
|
280
|
+
{
|
|
281
|
+
const target = proposal.remove.removed;
|
|
282
|
+
const old = leafAt(before, target);
|
|
283
|
+
// A self-removal proposal is honoured only when another member commits it.
|
|
284
|
+
const selfRemoval = proposalSender === target && (incoming.kind === 'proposal' || incoming.senderLeafIndex !== target);
|
|
285
|
+
const authorised = proofs.length > 0 || lapsed.has(target) || selfRemoval;
|
|
286
|
+
if (controller != null && (old == null || !authorised)) throw new Error('Unauthorised Remove');
|
|
287
|
+
tree[target * 2] = undefined;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case defaultProposalTypes.group_context_extensions:
|
|
291
|
+
if (evaluateGroupContextExtensions(proposal.groupContextExtensions.extensions, context) === 'reject') throw new Error('Invalid extensions');
|
|
292
|
+
break;
|
|
293
|
+
default:
|
|
294
|
+
if (controller != null) throw new Error('Unsupported lifecycle proposal');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (incoming.kind === 'commit' && context.commitEnactsEntries && !proposals.some(({ proposal })=>proposal.proposalType === defaultProposalTypes.group_context_extensions)) throw new Error('Missing head move');
|
|
298
|
+
if (controller != null && incoming.kind === 'commit' && incoming.senderLeafIndex != null) {
|
|
299
|
+
const sender = leafAt(before, incoming.senderLeafIndex);
|
|
300
|
+
// A lapsed sender may only commit clock entries and the head move they need.
|
|
301
|
+
const changesMoreThanHead = proposals.some(({ proposal })=>proposal.proposalType !== defaultProposalTypes.group_context_extensions);
|
|
302
|
+
const enactsNonClock = entries.some((verified)=>verified.entry.type !== DEVICE_ENTRY_TYPE || opOf(verified) !== 'clock');
|
|
303
|
+
if (sender != null && lapsed.has(incoming.senderLeafIndex) && (changesMoreThanHead || enactsNonClock)) throw new LeafLapsedError('lapsed');
|
|
304
|
+
}
|
|
305
|
+
if (incoming.kind === 'commit') checkTime(tree);
|
|
306
|
+
checkSize(tree);
|
|
307
|
+
checkSurvivors(group, tree, candidateRegistry);
|
|
308
|
+
};
|
|
309
|
+
const postApply = async (state)=>{
|
|
310
|
+
if (incomingCommit == null || state.groupActiveState.kind === 'removedFromGroup') return;
|
|
311
|
+
const external = incomingCommit.senderLeafIndex == null;
|
|
312
|
+
const senderIndex = incomingCommit.senderLeafIndex;
|
|
313
|
+
const hasRemoves = incomingCommit.proposals.some(({ proposal })=>proposal.proposalType === defaultProposalTypes.remove);
|
|
314
|
+
if (!external && senderIndex != null) {
|
|
315
|
+
const next = leafAt(state.ratchetTree, senderIndex);
|
|
316
|
+
const old = leafAt(before, senderIndex);
|
|
317
|
+
if (next != null && old != null && (!credentialEqual(next, old) || !bytesEqual(next.signaturePublicKey, old.signaturePublicKey))) {
|
|
318
|
+
if (controller != null && (hasRemoves || proofs.length > 0)) throw new LeafBindingError('identity-change');
|
|
319
|
+
await validateEntry(group, next, old);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (controller != null && senderIndex != null) {
|
|
323
|
+
const old = leafAt(before, senderIndex);
|
|
324
|
+
const next = leafAt(state.ratchetTree, senderIndex);
|
|
325
|
+
if (old != null && lapsed.has(senderIndex) && (next == null || credentialEqual(old, next) || readCapability(identity(next).controller?.capability ?? '').payload.exp < beforeTime)) throw new LeafLapsedError('lapsed');
|
|
326
|
+
}
|
|
327
|
+
checkTime(state.ratchetTree);
|
|
328
|
+
checkSize(state.ratchetTree);
|
|
329
|
+
checkSurvivors(group, state.ratchetTree, candidateRegistry);
|
|
330
|
+
};
|
|
331
|
+
return {
|
|
332
|
+
check,
|
|
333
|
+
postApply
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/** Historical messages use the tree and clock floor authenticated in their own epoch. */ export function assertSenderNotLapsed(params) {
|
|
337
|
+
const { group, tree, leafIndex, extensions } = params;
|
|
338
|
+
const controller = group.anchor.controller;
|
|
339
|
+
if (controller == null || leafIndex == null) return;
|
|
340
|
+
const leaf = leafAt(tree, leafIndex);
|
|
341
|
+
if (leaf == null) return;
|
|
342
|
+
const data = extensions.find((extension)=>extension.extensionType === LEDGER_HEAD_EXTENSION_TYPE)?.extensionData;
|
|
343
|
+
const expected = data instanceof Uint8Array ? decodeLedgerHead(data) : null;
|
|
344
|
+
if (expected == null) throw new Error('Missing epoch ledger head');
|
|
345
|
+
let head = genesisHead(group.groupID);
|
|
346
|
+
let floor = 0;
|
|
347
|
+
for (const held of group.ledger){
|
|
348
|
+
if (headsMatch(head, expected.head)) break;
|
|
349
|
+
head = extendHead(head, [
|
|
350
|
+
held.entryID
|
|
351
|
+
]);
|
|
352
|
+
const { entry } = held.verified;
|
|
353
|
+
if (entry.type !== DEVICE_ENTRY_TYPE) continue;
|
|
354
|
+
const value = entry.value;
|
|
355
|
+
if (value.op === 'clock') floor = Math.max(floor, value.time ?? 0);
|
|
356
|
+
}
|
|
357
|
+
if (!headsMatch(head, expected.head)) throw new Error('Unknown epoch ledger head');
|
|
358
|
+
const binding = identity(leaf).controller;
|
|
359
|
+
if (binding != null && readCapability(binding.capability).payload.exp < timeOf(tree, controller, floor)) throw new LeafLapsedError('lapsed');
|
|
360
|
+
}
|
|
361
|
+
/** @internal Check a replacement against the complete external admission predicates. */ export async function assertRecoveryBinding(params) {
|
|
362
|
+
const { group, identity: ownIdentity, controller } = params;
|
|
363
|
+
assertBindingAuthorTime(controller);
|
|
364
|
+
const index = group.findMemberLeafIndex(normalizeDID(ownIdentity.id));
|
|
365
|
+
const old = index == null ? undefined : leafAt(group.state.ratchetTree, index);
|
|
366
|
+
if (old == null || index == null) throw new LeafBindingError('identity-change');
|
|
367
|
+
const leaf = {
|
|
368
|
+
...old,
|
|
369
|
+
signaturePublicKey: ownIdentity.publicKey,
|
|
370
|
+
credential: makeMLSCredential(ownIdentity, controller)
|
|
371
|
+
};
|
|
372
|
+
await validateEntry(group, leaf, old);
|
|
373
|
+
const tree = group.state.ratchetTree.slice();
|
|
374
|
+
tree[index * 2] = {
|
|
375
|
+
nodeType: nodeTypes.leaf,
|
|
376
|
+
leaf
|
|
377
|
+
};
|
|
378
|
+
const controllerID = group.anchor.controller;
|
|
379
|
+
if (controllerID == null) return;
|
|
380
|
+
const floor = group.registry.controllers.get(normalizeDID(controllerID))?.timeFloor ?? 0;
|
|
381
|
+
if (timeOf(tree, controllerID, floor) < treeTime(group, controllerID)) throw new RevokeProofError('effects-mismatch');
|
|
382
|
+
const ledger = group.ledger.map(({ verified })=>verified);
|
|
383
|
+
const size = historySize(tree, ledger);
|
|
384
|
+
if (size > HISTORY_HORIZON && size > historySize(group.state.ratchetTree, ledger)) throw new LeafBindingError('history-horizon');
|
|
385
|
+
}
|
package/lib/policy.d.ts
CHANGED
|
@@ -55,6 +55,26 @@ type IncomingMessage = {
|
|
|
55
55
|
kind: 'proposal';
|
|
56
56
|
proposal: ProposalWithSender;
|
|
57
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* The group-context-extensions rule: an admin may replace the extension list only to move the
|
|
60
|
+
* ledger-head to the head this commit's envelope accounts for, or to also install
|
|
61
|
+
* {@link RESERVED_EXTENSION_TYPE} empty in a standard group. Lifecycle groups permit only the
|
|
62
|
+
* head move. A GCE proposal replaces the *entire* list, so the
|
|
63
|
+
* proposed list must positionally equal the current one — same length, types, positions,
|
|
64
|
+
* byte-identical data — except the ledger_head entry (must equal the expected head) and at
|
|
65
|
+
* most one added `RESERVED_EXTENSION_TYPE` entry with empty data. This pins every other
|
|
66
|
+
* extension, so an admin can't inject or strip one (e.g. external_senders, which lets a
|
|
67
|
+
* non-member inject proposals) inside a head move, nor install the reserved type with
|
|
68
|
+
* non-empty data — it isn't consumed by anything yet, so no policy exists for its data.
|
|
69
|
+
*
|
|
70
|
+
* The head must equal the current head extended by the envelope's entry ids in order; moved to
|
|
71
|
+
* anything else, or moved by a commit enacting nothing, and it stops proving what the group
|
|
72
|
+
* enacted.
|
|
73
|
+
*/
|
|
74
|
+
export declare function evaluateGroupContextExtensions(extensions: Array<{
|
|
75
|
+
extensionType: number;
|
|
76
|
+
extensionData: unknown;
|
|
77
|
+
}>, context: CommitPolicyContext): IncomingMessageAction;
|
|
58
78
|
/**
|
|
59
79
|
* Pure receiving-side commit policy: given the resolved context, decides whether an incoming
|
|
60
80
|
* commit or standalone proposal is admissible. Never throws.
|
package/lib/policy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { normalizeDID } from '@kokuin/token';
|
|
2
2
|
import { defaultProposalTypes, isDefaultProposal } from 'ts-mls';
|
|
3
|
-
import { LEDGER_HEAD_EXTENSION_TYPE, RESERVED_EXTENSION_TYPE } from './anchor.js';
|
|
3
|
+
import { decodeGroupAnchor, GROUP_ANCHOR_EXTENSION_TYPE, LEDGER_HEAD_EXTENSION_TYPE, RESERVED_EXTENSION_TYPE } from './anchor.js';
|
|
4
4
|
import { didFromCredential } from './credential.js';
|
|
5
5
|
function bytesEqual(a, b) {
|
|
6
6
|
if (a.length !== b.length) {
|
|
@@ -42,7 +42,8 @@ function bytesEqual(a, b) {
|
|
|
42
42
|
/**
|
|
43
43
|
* The group-context-extensions rule: an admin may replace the extension list only to move the
|
|
44
44
|
* ledger-head to the head this commit's envelope accounts for, or to also install
|
|
45
|
-
* {@link RESERVED_EXTENSION_TYPE} empty
|
|
45
|
+
* {@link RESERVED_EXTENSION_TYPE} empty in a standard group. Lifecycle groups permit only the
|
|
46
|
+
* head move. A GCE proposal replaces the *entire* list, so the
|
|
46
47
|
* proposed list must positionally equal the current one — same length, types, positions,
|
|
47
48
|
* byte-identical data — except the ledger_head entry (must equal the expected head) and at
|
|
48
49
|
* most one added `RESERVED_EXTENSION_TYPE` entry with empty data. This pins every other
|
|
@@ -53,7 +54,7 @@ function bytesEqual(a, b) {
|
|
|
53
54
|
* The head must equal the current head extended by the envelope's entry ids in order; moved to
|
|
54
55
|
* anything else, or moved by a commit enacting nothing, and it stops proving what the group
|
|
55
56
|
* enacted.
|
|
56
|
-
*/ function evaluateGroupContextExtensions(extensions, context) {
|
|
57
|
+
*/ export function evaluateGroupContextExtensions(extensions, context) {
|
|
57
58
|
const expected = context.currentExtensions.map((ext)=>ext.extensionType === LEDGER_HEAD_EXTENSION_TYPE ? {
|
|
58
59
|
extensionType: LEDGER_HEAD_EXTENSION_TYPE,
|
|
59
60
|
extensionData: context.expectedHeadExtensionData
|
|
@@ -64,7 +65,9 @@ function bytesEqual(a, b) {
|
|
|
64
65
|
// rejected as before.
|
|
65
66
|
let candidate = extensions;
|
|
66
67
|
const reservedAlreadyInstalled = expected.some((ext)=>ext.extensionType === RESERVED_EXTENSION_TYPE);
|
|
67
|
-
|
|
68
|
+
const anchorData = expected.find((ext)=>ext.extensionType === GROUP_ANCHOR_EXTENSION_TYPE)?.extensionData;
|
|
69
|
+
const lifecycle = anchorData instanceof Uint8Array && decodeGroupAnchor(anchorData)?.controller != null;
|
|
70
|
+
if (!lifecycle && !reservedAlreadyInstalled && extensions.length === expected.length + 1) {
|
|
68
71
|
const reservedIndex = extensions.findIndex((ext)=>{
|
|
69
72
|
return ext.extensionType === RESERVED_EXTENSION_TYPE && ext.extensionData instanceof Uint8Array && ext.extensionData.length === 0;
|
|
70
73
|
});
|
|
@@ -76,6 +79,7 @@ function bytesEqual(a, b) {
|
|
|
76
79
|
for(let i = 0; i < expected.length; i++){
|
|
77
80
|
const got = candidate[i];
|
|
78
81
|
const want = expected[i];
|
|
82
|
+
if (got === undefined || want === undefined) return 'reject';
|
|
79
83
|
if (got.extensionType !== want.extensionType) return 'reject';
|
|
80
84
|
// Both sides must be raw bytes to compare. ts-mls's extensionsEqual isn't re-exported, so
|
|
81
85
|
// this hand-rolled compare only handles Uint8Array data; a decoded-object extension (e.g.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type SigningIdentity } from '@kokuin/token';
|
|
2
|
+
import type { GroupHandle } from './group-handle.js';
|
|
3
|
+
import { type OpenSealedGroupInfoParams } from './recovery.js';
|
|
4
|
+
import type { DeviceRegistry } from './registry.js';
|
|
5
|
+
export type RecoveryRefusalReason = 'binding' | 'lapse' | 'floor' | 'policy' | 'invalid';
|
|
6
|
+
export type RecoveryVerdict = {
|
|
7
|
+
groupID: string;
|
|
8
|
+
requestID: string;
|
|
9
|
+
position: string;
|
|
10
|
+
commitDigest: string;
|
|
11
|
+
} & ({
|
|
12
|
+
verdict: 'confirmed';
|
|
13
|
+
epoch: number;
|
|
14
|
+
tag: string;
|
|
15
|
+
} | {
|
|
16
|
+
verdict: 'superseded';
|
|
17
|
+
} | {
|
|
18
|
+
verdict: 'refused';
|
|
19
|
+
reason: RecoveryRefusalReason;
|
|
20
|
+
});
|
|
21
|
+
export type OpenedRecoveryVerdict = {
|
|
22
|
+
signer: string;
|
|
23
|
+
verdict: RecoveryVerdict;
|
|
24
|
+
};
|
|
25
|
+
export declare function confirmationKey(group: GroupHandle, position: string, commitDigest: string): Promise<Uint8Array>;
|
|
26
|
+
export declare function confirmationTag(key: Uint8Array, requestID: string): string;
|
|
27
|
+
export type SealRecoveryVerdictParams = {
|
|
28
|
+
group: GroupHandle;
|
|
29
|
+
identity: SigningIdentity;
|
|
30
|
+
/** The signed recovery request token being answered. */
|
|
31
|
+
request: string;
|
|
32
|
+
verdict: RecoveryVerdict;
|
|
33
|
+
};
|
|
34
|
+
export declare function sealRecoveryVerdict(params: SealRecoveryVerdictParams): Promise<Uint8Array>;
|
|
35
|
+
export declare function openRecoveryVerdict(params: OpenSealedGroupInfoParams): Promise<OpenedRecoveryVerdict>;
|
|
36
|
+
export type RecoverySignerEligibleParams = {
|
|
37
|
+
group: GroupHandle;
|
|
38
|
+
known: DeviceRegistry;
|
|
39
|
+
signer: string;
|
|
40
|
+
/** Seconds since epoch; defaults to the current time. */
|
|
41
|
+
now?: number;
|
|
42
|
+
};
|
|
43
|
+
export declare function recoverySignerEligible(params: RecoverySignerEligibleParams): boolean;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { foldLog } from '@kokuin/controller';
|
|
2
|
+
import { encodeMultibase, isVerifiedToken, normalizeDID, stringifyToken, verifyToken } from '@kokuin/token';
|
|
3
|
+
import { hmac } from '@noble/hashes/hmac.js';
|
|
4
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
5
|
+
import { readCapability } from './capability.js';
|
|
6
|
+
import { openSealedReply, sealToRequest, verifyRecoveryRequest } from './recovery.js';
|
|
7
|
+
const utf8 = new TextEncoder();
|
|
8
|
+
const VERDICT_TYPE = 'kumiai.recovery-verdict';
|
|
9
|
+
const VERDICT_REPLY = {
|
|
10
|
+
hpkeInfo: utf8.encode('kumiai/mls/recovery-verdict/v1'),
|
|
11
|
+
aadDomain: utf8.encode('kumiai/mls/recovery-verdict-aad/v1'),
|
|
12
|
+
version: 1,
|
|
13
|
+
fail: (_reason, message, options)=>new Error(message, options)
|
|
14
|
+
};
|
|
15
|
+
function frame(value) {
|
|
16
|
+
const bytes = utf8.encode(value);
|
|
17
|
+
const out = new Uint8Array(4 + bytes.length);
|
|
18
|
+
new DataView(out.buffer).setUint32(0, bytes.length, false);
|
|
19
|
+
out.set(bytes, 4);
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
export async function confirmationKey(group, position, commitDigest) {
|
|
23
|
+
const fields = [
|
|
24
|
+
group.groupID,
|
|
25
|
+
position,
|
|
26
|
+
commitDigest
|
|
27
|
+
].map(frame);
|
|
28
|
+
const context = new Uint8Array(fields.reduce((size, field)=>size + field.length, 0));
|
|
29
|
+
let offset = 0;
|
|
30
|
+
for (const field of fields){
|
|
31
|
+
context.set(field, offset);
|
|
32
|
+
offset += field.length;
|
|
33
|
+
}
|
|
34
|
+
return await group.exportSecret('kumiai.rejoin-confirm', context, 32);
|
|
35
|
+
}
|
|
36
|
+
export function confirmationTag(key, requestID) {
|
|
37
|
+
return encodeMultibase(hmac(sha256, key, utf8.encode(requestID)));
|
|
38
|
+
}
|
|
39
|
+
function isRecoveryVerdict(value) {
|
|
40
|
+
if (value == null || typeof value !== 'object') return false;
|
|
41
|
+
const v = value;
|
|
42
|
+
if (![
|
|
43
|
+
v.groupID,
|
|
44
|
+
v.requestID,
|
|
45
|
+
v.position,
|
|
46
|
+
v.commitDigest
|
|
47
|
+
].every((field)=>typeof field === 'string' && field.length > 0)) return false;
|
|
48
|
+
return v.verdict === 'superseded' || v.verdict === 'confirmed' && Number.isSafeInteger(v.epoch) && v.epoch >= 0 && typeof v.tag === 'string' || v.verdict === 'refused' && [
|
|
49
|
+
'binding',
|
|
50
|
+
'lapse',
|
|
51
|
+
'floor',
|
|
52
|
+
'policy',
|
|
53
|
+
'invalid'
|
|
54
|
+
].includes(v.reason);
|
|
55
|
+
}
|
|
56
|
+
export async function sealRecoveryVerdict(params) {
|
|
57
|
+
const { group, identity, request, verdict } = params;
|
|
58
|
+
const verified = await verifyRecoveryRequest(request);
|
|
59
|
+
if (normalizeDID(identity.id) !== normalizeDID(group.credential.id) || !isRecoveryVerdict(verdict) || verdict.groupID !== group.groupID || verdict.groupID !== verified.groupID || verdict.requestID !== verified.requestID) throw new Error('Recovery verdict does not bind the signed request');
|
|
60
|
+
const token = await identity.signToken({
|
|
61
|
+
...verdict,
|
|
62
|
+
type: VERDICT_TYPE
|
|
63
|
+
}, {
|
|
64
|
+
embedLongForm: true
|
|
65
|
+
});
|
|
66
|
+
// A refusal can answer an agent whose leaf the responder no longer holds.
|
|
67
|
+
return await sealToRequest({
|
|
68
|
+
kind: VERDICT_REPLY,
|
|
69
|
+
group,
|
|
70
|
+
request,
|
|
71
|
+
plaintext: utf8.encode(stringifyToken(token)),
|
|
72
|
+
requireMember: false
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export async function openRecoveryVerdict(params) {
|
|
76
|
+
const { group, sealed, requestID, ephemeralPrivateKey } = params;
|
|
77
|
+
const plaintext = await openSealedReply({
|
|
78
|
+
kind: VERDICT_REPLY,
|
|
79
|
+
group,
|
|
80
|
+
sealed,
|
|
81
|
+
requestID,
|
|
82
|
+
ephemeralPrivateKey
|
|
83
|
+
});
|
|
84
|
+
const token = await verifyToken(new TextDecoder().decode(plaintext));
|
|
85
|
+
if (!isVerifiedToken(token) || token.payload.type !== VERDICT_TYPE || !isRecoveryVerdict(token.payload) || token.payload.groupID !== group.groupID || token.payload.requestID !== requestID) throw new Error('Unauthenticated recovery verdict');
|
|
86
|
+
const { groupID, position, commitDigest } = token.payload;
|
|
87
|
+
const binding = {
|
|
88
|
+
groupID,
|
|
89
|
+
requestID,
|
|
90
|
+
position,
|
|
91
|
+
commitDigest
|
|
92
|
+
};
|
|
93
|
+
const verdict = token.payload.verdict === 'confirmed' ? {
|
|
94
|
+
...binding,
|
|
95
|
+
verdict: 'confirmed',
|
|
96
|
+
epoch: token.payload.epoch,
|
|
97
|
+
tag: token.payload.tag
|
|
98
|
+
} : token.payload.verdict === 'refused' ? {
|
|
99
|
+
...binding,
|
|
100
|
+
verdict: 'refused',
|
|
101
|
+
reason: token.payload.reason
|
|
102
|
+
} : {
|
|
103
|
+
...binding,
|
|
104
|
+
verdict: 'superseded'
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
signer: normalizeDID(token.payload.iss),
|
|
108
|
+
verdict
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function recoverySignerEligible(params) {
|
|
112
|
+
const { group, known, signer, now = Date.now() / 1000 } = params;
|
|
113
|
+
const controller = group.anchor.controller;
|
|
114
|
+
if (controller == null) return false;
|
|
115
|
+
try {
|
|
116
|
+
const binding = group.bindingOfDID(signer);
|
|
117
|
+
if (binding?.controller !== controller || binding.capability == null || binding.prefix == null) return false;
|
|
118
|
+
const payload = readCapability(binding.capability).payload;
|
|
119
|
+
if (known.devices.get(normalizeDID(signer))?.status === 'revoked' || payload.cap != null && known.devices.get(normalizeDID(payload.iss))?.status === 'revoked') return false;
|
|
120
|
+
const folded = foldLog(controller, binding.prefix);
|
|
121
|
+
const projection = known.controllers.get(normalizeDID(controller));
|
|
122
|
+
if (!folded.ok || (folded.states.at(-1)?.gen ?? 0) < (projection?.genFloor ?? 0)) return false;
|
|
123
|
+
let time = projection?.timeFloor ?? 0;
|
|
124
|
+
for (const member of group.listMembers()){
|
|
125
|
+
const leaf = group.bindingOfDID(member.id);
|
|
126
|
+
if (leaf?.controller !== controller || leaf.capability == null) continue;
|
|
127
|
+
const capability = readCapability(leaf.capability).payload;
|
|
128
|
+
const parent = Array.isArray(capability.cap) ? capability.cap[0] : capability.cap;
|
|
129
|
+
time = Math.max(time, parent == null ? capability.iat : readCapability(parent).payload.iat);
|
|
130
|
+
}
|
|
131
|
+
return payload.exp >= Math.max(time, now - 300);
|
|
132
|
+
} catch {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|