@kumiai/mls-rpc 0.12.0 → 0.13.0
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/lib/access.d.ts +16 -4
- package/lib/access.js +17 -9
- package/lib/apply-commit.js +2 -1
- package/lib/crypto.d.ts +16 -3
- package/lib/crypto.js +77 -37
- package/lib/index.d.ts +3 -0
- package/lib/mls.d.ts +6 -1
- package/lib/mls.js +30 -14
- package/lib/recovery.d.ts +3 -3
- package/lib/recovery.js +21 -8
- package/lib/revoke.d.ts +2 -2
- package/lib/revoke.js +35 -28
- package/package.json +6 -6
package/lib/access.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { type GroupHandle } from '@kumiai/mls';
|
|
2
2
|
import type { PendingAppFrame, SendAdmission } from '@kumiai/rpc';
|
|
3
3
|
type PersistOpened = (stagedState: Uint8Array, record: PendingAppFrame) => Promise<void>;
|
|
4
|
+
export type HandleAccessReplaceParams = {
|
|
5
|
+
next: GroupHandle;
|
|
6
|
+
guard: (live: GroupHandle) => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export type HandleAccessOpenParams<TValue> = {
|
|
9
|
+
fn: (handle: GroupHandle, persistOpened: PersistOpened) => Promise<TValue>;
|
|
10
|
+
persistOpened: PersistOpened;
|
|
11
|
+
};
|
|
4
12
|
export type HandleAccess = {
|
|
5
13
|
/** Published with admission after mutation/open and after replacement adoption resolves. */
|
|
6
14
|
epoch(): number;
|
|
@@ -9,17 +17,21 @@ export type HandleAccess = {
|
|
|
9
17
|
read<TValue>(fn: (handle: GroupHandle) => TValue | Promise<TValue>): Promise<TValue>;
|
|
10
18
|
mutate<TValue>(fn: (handle: GroupHandle, persist: (handle: GroupHandle) => Promise<void>) => Promise<TValue>): Promise<TValue>;
|
|
11
19
|
/** Must run the guard under the replacement lock, before persistence; a throw aborts. */
|
|
12
|
-
replace(
|
|
13
|
-
open<TValue>(
|
|
20
|
+
replace(params: HandleAccessReplaceParams): Promise<void>;
|
|
21
|
+
open<TValue>(params: HandleAccessOpenParams<TValue>): Promise<TValue>;
|
|
14
22
|
};
|
|
15
23
|
/** Refuses a replacement that drops lifecycle effects the live handle knows. */
|
|
16
|
-
export declare function retainsKnownEffects(next: GroupHandle): (live: GroupHandle) => void
|
|
24
|
+
export declare function retainsKnownEffects(next: GroupHandle): (live: GroupHandle) => Promise<void>;
|
|
25
|
+
export type GuardedReplaceParams = {
|
|
26
|
+
access: HandleAccess;
|
|
27
|
+
next: GroupHandle;
|
|
28
|
+
};
|
|
17
29
|
/**
|
|
18
30
|
* Replaces through `retainsKnownEffects`. A guard never invoked throws after the fact (the skipping
|
|
19
31
|
* implementation has already adopted `next`): this surfaces a broken adapter, it does not undo it.
|
|
20
32
|
* It cannot prove the guard ran on the live handle or under the lock; that stays the port contract.
|
|
21
33
|
*/
|
|
22
|
-
export declare function guardedReplace(access
|
|
34
|
+
export declare function guardedReplace({ access, next }: GuardedReplaceParams): Promise<void>;
|
|
23
35
|
export type SimpleHandleAccessParams = {
|
|
24
36
|
handle: () => GroupHandle;
|
|
25
37
|
adopt: (next: GroupHandle) => void | Promise<void>;
|
package/lib/access.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { assertRetainsKnownEffects } from '@kumiai/mls';
|
|
2
2
|
/** Refuses a replacement that drops lifecycle effects the live handle knows. */ export function retainsKnownEffects(next) {
|
|
3
|
-
return (live)=>{
|
|
3
|
+
return async (live)=>{
|
|
4
4
|
const controller = live.anchor.controller;
|
|
5
|
-
if (controller != null) assertRetainsKnownEffects(
|
|
5
|
+
if (controller != null) await assertRetainsKnownEffects({
|
|
6
|
+
controller,
|
|
7
|
+
known: live.registry,
|
|
8
|
+
candidate: next.registry,
|
|
9
|
+
crypto: live.crypto
|
|
10
|
+
});
|
|
6
11
|
};
|
|
7
12
|
}
|
|
8
13
|
/**
|
|
9
14
|
* Replaces through `retainsKnownEffects`. A guard never invoked throws after the fact (the skipping
|
|
10
15
|
* implementation has already adopted `next`): this surfaces a broken adapter, it does not undo it.
|
|
11
16
|
* It cannot prove the guard ran on the live handle or under the lock; that stays the port contract.
|
|
12
|
-
*/ export async function guardedReplace(access, next) {
|
|
17
|
+
*/ export async function guardedReplace({ access, next }) {
|
|
13
18
|
const guard = retainsKnownEffects(next);
|
|
14
19
|
let ran = false;
|
|
15
|
-
await access.replace(
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
await access.replace({
|
|
21
|
+
next,
|
|
22
|
+
guard: async (live)=>{
|
|
23
|
+
await guard(live);
|
|
24
|
+
ran = true;
|
|
25
|
+
}
|
|
18
26
|
});
|
|
19
27
|
if (!ran) throw new Error('HandleAccess.replace did not run its guard');
|
|
20
28
|
}
|
|
@@ -53,14 +61,14 @@ export function simpleHandleAccess(params) {
|
|
|
53
61
|
publishedAdmission = handle.sendAdmission();
|
|
54
62
|
return result;
|
|
55
63
|
}),
|
|
56
|
-
replace: (next, guard)=>serialise(async ()=>{
|
|
57
|
-
guard(params.handle());
|
|
64
|
+
replace: ({ next, guard })=>serialise(async ()=>{
|
|
65
|
+
await guard(params.handle());
|
|
58
66
|
await save(next);
|
|
59
67
|
await params.adopt(next);
|
|
60
68
|
publishedAdmission = next.sendAdmission();
|
|
61
69
|
next.confirmAdopted();
|
|
62
70
|
}),
|
|
63
|
-
open: (fn, persistOpened)=>serialise(async ()=>{
|
|
71
|
+
open: ({ fn, persistOpened })=>serialise(async ()=>{
|
|
64
72
|
const handle = params.handle();
|
|
65
73
|
const result = await fn(handle, persistOpened);
|
|
66
74
|
publishedAdmission = handle.sendAdmission();
|
package/lib/apply-commit.js
CHANGED
package/lib/crypto.d.ts
CHANGED
|
@@ -10,9 +10,22 @@ import type { HandleAccess } from './access.js';
|
|
|
10
10
|
* from a caller (see below).
|
|
11
11
|
*/
|
|
12
12
|
export declare const ENTRY_SEAL_LABEL = "kumiai/ledger-entries/v1";
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export type DeriveEntryKeyParams = {
|
|
14
|
+
handle: GroupHandle;
|
|
15
|
+
label?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function deriveEntryKey({ handle, label }: DeriveEntryKeyParams): Promise<Uint8Array>;
|
|
18
|
+
export type SealEntriesParams = {
|
|
19
|
+
key: Uint8Array;
|
|
20
|
+
entries: Uint8Array;
|
|
21
|
+
runtime?: Runtime;
|
|
22
|
+
};
|
|
23
|
+
export declare function sealEntries({ key, entries, runtime, }: SealEntriesParams): Uint8Array;
|
|
24
|
+
export type OpenEntriesParams = {
|
|
25
|
+
key: Uint8Array;
|
|
26
|
+
sealed: Uint8Array;
|
|
27
|
+
};
|
|
28
|
+
export declare function openEntries({ key, sealed }: OpenEntriesParams): Uint8Array;
|
|
16
29
|
export type GroupCryptoParams = {
|
|
17
30
|
access: HandleAccess;
|
|
18
31
|
/**
|
package/lib/crypto.js
CHANGED
|
@@ -30,10 +30,14 @@ import { createRuntime } from '@sozai/runtime';
|
|
|
30
30
|
* no v1 peer can read a v2 blob regardless, but the failure reads as "unsupported version"
|
|
31
31
|
* rather than an AEAD refusal indistinguishable from a wrong epoch or a tampered frame.
|
|
32
32
|
*/ const ENTRY_VERSION = 1;
|
|
33
|
-
export function deriveEntryKey(handle, label) {
|
|
34
|
-
return handle.exportSecret(
|
|
33
|
+
export function deriveEntryKey({ handle, label }) {
|
|
34
|
+
return handle.exportSecret({
|
|
35
|
+
label: label ?? ENTRY_SEAL_LABEL,
|
|
36
|
+
context: new Uint8Array(),
|
|
37
|
+
length: SECRET_LENGTH
|
|
38
|
+
});
|
|
35
39
|
}
|
|
36
|
-
export function sealEntries(key, entries, runtime = createRuntime()) {
|
|
40
|
+
export function sealEntries({ key, entries, runtime = createRuntime() }) {
|
|
37
41
|
// Random per seal: two members can frame a commit at the same epoch.
|
|
38
42
|
const nonce = runtime.getRandomValues(new Uint8Array(ENTRY_NONCE_BYTES));
|
|
39
43
|
const ciphertext = xchacha20poly1305(key, nonce).encrypt(entries);
|
|
@@ -49,7 +53,7 @@ function assertSealedEntryBlob(sealed) {
|
|
|
49
53
|
throw new Error(`openEntries: unsupported blob version ${sealed[0]}`);
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
|
-
export function openEntries(key, sealed) {
|
|
56
|
+
export function openEntries({ key, sealed }) {
|
|
53
57
|
assertSealedEntryBlob(sealed);
|
|
54
58
|
return xchacha20poly1305(key, sealed.subarray(1, 1 + ENTRY_NONCE_BYTES)).decrypt(sealed.subarray(1 + ENTRY_NONCE_BYTES));
|
|
55
59
|
}
|
|
@@ -61,24 +65,38 @@ export function createGroupCrypto(params) {
|
|
|
61
65
|
// not be an independent export — it's the exact exporter call `sealEntries`/`openEntries`
|
|
62
66
|
// make below (same context, same `SECRET_LENGTH`), so it would hand back the ledger-entry
|
|
63
67
|
// seal key under another name. Refused here, loudly, rather than left to the doc alone.
|
|
64
|
-
exportSecret: (label, length = SECRET_LENGTH)=>{
|
|
68
|
+
exportSecret: ({ label, length = SECRET_LENGTH })=>{
|
|
65
69
|
if (label === entryLabel) {
|
|
66
70
|
throw new Error(`exportSecret: label '${label}' is reserved for the ledger-entry seal`);
|
|
67
71
|
}
|
|
68
72
|
return access.read(async (group)=>({
|
|
69
|
-
secret: await group.exportSecret(
|
|
73
|
+
secret: await group.exportSecret({
|
|
74
|
+
label,
|
|
75
|
+
context: EXPORT_CONTEXT,
|
|
76
|
+
length
|
|
77
|
+
}),
|
|
70
78
|
epoch: Number(group.epoch)
|
|
71
79
|
}));
|
|
72
80
|
},
|
|
73
|
-
wrap: (bytes, opts)=>access.mutate((group)=>group.encrypt(
|
|
81
|
+
wrap: ({ bytes, ...opts })=>access.mutate((group)=>group.encrypt({
|
|
82
|
+
plaintext: bytes,
|
|
83
|
+
...opts
|
|
84
|
+
})),
|
|
74
85
|
sealEntries: async (bytes)=>{
|
|
75
86
|
const { key, epoch } = await access.read(async (group)=>({
|
|
76
|
-
key: await deriveEntryKey(
|
|
87
|
+
key: await deriveEntryKey({
|
|
88
|
+
handle: group,
|
|
89
|
+
label: entryLabel
|
|
90
|
+
}),
|
|
77
91
|
epoch: Number(group.epoch)
|
|
78
92
|
}));
|
|
79
93
|
try {
|
|
80
94
|
return {
|
|
81
|
-
sealed: sealEntries(
|
|
95
|
+
sealed: sealEntries({
|
|
96
|
+
key,
|
|
97
|
+
entries: bytes,
|
|
98
|
+
runtime
|
|
99
|
+
}),
|
|
82
100
|
epoch
|
|
83
101
|
};
|
|
84
102
|
} finally{
|
|
@@ -87,14 +105,20 @@ export function createGroupCrypto(params) {
|
|
|
87
105
|
},
|
|
88
106
|
openEntries: async (sealed)=>{
|
|
89
107
|
assertSealedEntryBlob(sealed);
|
|
90
|
-
const key = await access.read((group)=>deriveEntryKey(
|
|
108
|
+
const key = await access.read((group)=>deriveEntryKey({
|
|
109
|
+
handle: group,
|
|
110
|
+
label: entryLabel
|
|
111
|
+
}));
|
|
91
112
|
try {
|
|
92
|
-
return openEntries(
|
|
113
|
+
return openEntries({
|
|
114
|
+
key,
|
|
115
|
+
sealed
|
|
116
|
+
});
|
|
93
117
|
} finally{
|
|
94
118
|
key.fill(0);
|
|
95
119
|
}
|
|
96
120
|
},
|
|
97
|
-
unwrap: async (bytes, opts)=>{
|
|
121
|
+
unwrap: async ({ bytes, ...opts })=>{
|
|
98
122
|
if (opts?.frame != null) {
|
|
99
123
|
if (pending == null) throw new Error('unwrap: pending store required for durable open');
|
|
100
124
|
const frame = opts.frame;
|
|
@@ -113,22 +137,29 @@ export function createGroupCrypto(params) {
|
|
|
113
137
|
const epoch = Number(group.epoch);
|
|
114
138
|
const frameEpoch = readMessageEpoch(bytes);
|
|
115
139
|
if (frameEpoch != null && Number(frameEpoch) !== epoch) {
|
|
116
|
-
throw new FrameEpochError(
|
|
140
|
+
throw new FrameEpochError({
|
|
141
|
+
frameEpoch: Number(frameEpoch),
|
|
142
|
+
handleEpoch: epoch
|
|
143
|
+
});
|
|
117
144
|
}
|
|
118
|
-
const result = await group.decryptStaged(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
const result = await group.decryptStaged({
|
|
146
|
+
message: bytes,
|
|
147
|
+
opts,
|
|
148
|
+
persist: async (stagedState, result)=>{
|
|
149
|
+
// The handle adopts the staged state only after this returns: a fault here leaves
|
|
150
|
+
// the key unspent, so the frame must be retried, not dropped.
|
|
151
|
+
try {
|
|
152
|
+
await persistStaged(stagedState, {
|
|
153
|
+
frame,
|
|
154
|
+
payload: result.payload,
|
|
155
|
+
senderDID: result.senderDID
|
|
156
|
+
});
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (isAppFrameStorageError(error)) throw error;
|
|
159
|
+
throw new AppFrameStorageError('failed to stage opened app frame', {
|
|
160
|
+
cause: error
|
|
161
|
+
});
|
|
162
|
+
}
|
|
132
163
|
}
|
|
133
164
|
});
|
|
134
165
|
return {
|
|
@@ -138,14 +169,17 @@ export function createGroupCrypto(params) {
|
|
|
138
169
|
};
|
|
139
170
|
let opened;
|
|
140
171
|
try {
|
|
141
|
-
opened = await access.open(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
172
|
+
opened = await access.open({
|
|
173
|
+
fn: async (group, persistStaged)=>{
|
|
174
|
+
try {
|
|
175
|
+
return await open(group, persistStaged);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
openError = error;
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
persistOpened
|
|
182
|
+
});
|
|
149
183
|
} catch (error) {
|
|
150
184
|
// The open's own refusal says whether the frame is dead. Anything the adapter raised
|
|
151
185
|
// around it (a restore, a read) left the key unspent, so the lane must retry.
|
|
@@ -164,9 +198,15 @@ export function createGroupCrypto(params) {
|
|
|
164
198
|
const epoch = Number(group.epoch);
|
|
165
199
|
const frameEpoch = readMessageEpoch(bytes);
|
|
166
200
|
if (frameEpoch != null && Number(frameEpoch) !== epoch) {
|
|
167
|
-
throw new FrameEpochError(
|
|
201
|
+
throw new FrameEpochError({
|
|
202
|
+
frameEpoch: Number(frameEpoch),
|
|
203
|
+
handleEpoch: epoch
|
|
204
|
+
});
|
|
168
205
|
}
|
|
169
|
-
const opened = await group.decrypt(
|
|
206
|
+
const opened = await group.decrypt({
|
|
207
|
+
message: bytes,
|
|
208
|
+
...opts
|
|
209
|
+
});
|
|
170
210
|
return {
|
|
171
211
|
...opened,
|
|
172
212
|
epoch
|
package/lib/index.d.ts
CHANGED
|
@@ -18,8 +18,11 @@
|
|
|
18
18
|
*
|
|
19
19
|
* @module mls-rpc
|
|
20
20
|
*/
|
|
21
|
+
export type { GuardedReplaceParams, HandleAccessOpenParams, HandleAccessReplaceParams, } from './access.js';
|
|
21
22
|
export { guardedReplace, type HandleAccess, retainsKnownEffects, type SimpleHandleAccessParams, simpleHandleAccess, } from './access.js';
|
|
22
23
|
export { type ApplyCommitParams, type ApplyCommitResult, applyCommit } from './apply-commit.js';
|
|
24
|
+
export type { DeriveEntryKeyParams, OpenEntriesParams, SealEntriesParams } from './crypto.js';
|
|
23
25
|
export { createGroupCrypto, deriveEntryKey, ENTRY_SEAL_LABEL, type GroupCryptoParams, openEntries, sealEntries, } from './crypto.js';
|
|
26
|
+
export type { RecoveryPendingPutParams } from './mls.js';
|
|
24
27
|
export { createGroupMLS, createLedgerEntrySlot, createRecoveryPending, deriveRecoverySecret, type GroupMLSParams, type LedgerEntrySlot, RECOVERY_LABEL, type RecoveryPending, } from './mls.js';
|
|
25
28
|
export { type PublishRevokeProofParams, type PublishRevokeResult, publishRevokeProof, type RevokeJournalOptions, } from './revoke.js';
|
package/lib/mls.d.ts
CHANGED
|
@@ -50,9 +50,14 @@ export type GroupMLSParams = {
|
|
|
50
50
|
/** Fresh own-leaf binding, at most once per attempt. Return null without waiting on the user. */
|
|
51
51
|
recoveryBinding?: RecoveryBinding;
|
|
52
52
|
};
|
|
53
|
+
export type RecoveryPendingPutParams = {
|
|
54
|
+
requestID: string;
|
|
55
|
+
ephemeralPrivateKey: Uint8Array;
|
|
56
|
+
deadlineMs?: number;
|
|
57
|
+
};
|
|
53
58
|
export type RecoveryPending = {
|
|
54
59
|
get(requestID: string): Uint8Array | null;
|
|
55
|
-
put(
|
|
60
|
+
put(params: RecoveryPendingPutParams): void;
|
|
56
61
|
delete(requestID: string): void;
|
|
57
62
|
};
|
|
58
63
|
export declare function createRecoveryPending(options?: {
|
package/lib/mls.js
CHANGED
|
@@ -55,7 +55,7 @@ export function createRecoveryPending(options) {
|
|
|
55
55
|
sweep();
|
|
56
56
|
return requests.get(requestID)?.ephemeralPrivateKey ?? null;
|
|
57
57
|
},
|
|
58
|
-
put: (requestID, ephemeralPrivateKey, deadlineMs = 0)=>{
|
|
58
|
+
put: ({ requestID, ephemeralPrivateKey, deadlineMs = 0 })=>{
|
|
59
59
|
const retentionMs = Math.max(ttlMS, deadlineMs);
|
|
60
60
|
sweep();
|
|
61
61
|
const previous = requests.get(requestID);
|
|
@@ -114,7 +114,11 @@ export async function deriveRecoverySecret(handle) {
|
|
|
114
114
|
const port = {
|
|
115
115
|
async verifyRecoveryRequest (request) {
|
|
116
116
|
try {
|
|
117
|
-
const
|
|
117
|
+
const crypto = await access.read((group)=>group.crypto);
|
|
118
|
+
const verified = await verifyRecoveryRequest({
|
|
119
|
+
token: new TextDecoder().decode(request),
|
|
120
|
+
crypto
|
|
121
|
+
});
|
|
118
122
|
return await access.read((group)=>verified.groupID === group.groupID ? {
|
|
119
123
|
groupID: verified.groupID,
|
|
120
124
|
requestID: verified.requestID,
|
|
@@ -124,13 +128,17 @@ export async function deriveRecoverySecret(handle) {
|
|
|
124
128
|
return null;
|
|
125
129
|
}
|
|
126
130
|
},
|
|
127
|
-
async confirmationKey (position, commitDigest) {
|
|
131
|
+
async confirmationKey ({ position, commitDigest }) {
|
|
128
132
|
return await access.read(async (group)=>({
|
|
129
133
|
epoch: Number(group.epoch),
|
|
130
|
-
key: await confirmationKey(
|
|
134
|
+
key: await confirmationKey({
|
|
135
|
+
group,
|
|
136
|
+
position,
|
|
137
|
+
commitDigest
|
|
138
|
+
})
|
|
131
139
|
}));
|
|
132
140
|
},
|
|
133
|
-
async sealRecoveryVerdict (request, verdict) {
|
|
141
|
+
async sealRecoveryVerdict ({ request, verdict }) {
|
|
134
142
|
return await access.read((group)=>sealRecoveryVerdict({
|
|
135
143
|
group,
|
|
136
144
|
identity,
|
|
@@ -138,7 +146,7 @@ export async function deriveRecoverySecret(handle) {
|
|
|
138
146
|
verdict
|
|
139
147
|
}));
|
|
140
148
|
},
|
|
141
|
-
async openRecoveryVerdict (sealed, requestID) {
|
|
149
|
+
async openRecoveryVerdict ({ sealed, requestID }) {
|
|
142
150
|
const held = pending.get(requestID);
|
|
143
151
|
if (held == null) return null;
|
|
144
152
|
try {
|
|
@@ -188,7 +196,7 @@ export async function deriveRecoverySecret(handle) {
|
|
|
188
196
|
}
|
|
189
197
|
};
|
|
190
198
|
},
|
|
191
|
-
async processCommit (commit, context) {
|
|
199
|
+
async processCommit ({ commit, context }) {
|
|
192
200
|
const frameEpoch = readMessageEpoch(commit);
|
|
193
201
|
const eligible = await access.read(async (group)=>{
|
|
194
202
|
const header = await group.readCommitHeader(commit);
|
|
@@ -256,13 +264,17 @@ export async function deriveRecoverySecret(handle) {
|
|
|
256
264
|
throw error;
|
|
257
265
|
}
|
|
258
266
|
},
|
|
259
|
-
async createRecoveryRequest (requestID, deadlineMs) {
|
|
267
|
+
async createRecoveryRequest ({ requestID, deadlineMs }) {
|
|
260
268
|
const { request, ephemeralPrivateKey } = await access.read((group)=>createRecoveryRequest({
|
|
261
269
|
group,
|
|
262
270
|
identity,
|
|
263
271
|
requestID
|
|
264
272
|
}));
|
|
265
|
-
pending.put(
|
|
273
|
+
pending.put({
|
|
274
|
+
requestID,
|
|
275
|
+
ephemeralPrivateKey,
|
|
276
|
+
deadlineMs: Math.max(REQUEST_TTL_MS, deadlineMs ?? 0)
|
|
277
|
+
});
|
|
266
278
|
return utf8.encode(request);
|
|
267
279
|
},
|
|
268
280
|
async sealGroupInfo (request) {
|
|
@@ -274,7 +286,7 @@ export async function deriveRecoverySecret(handle) {
|
|
|
274
286
|
request: new TextDecoder().decode(request)
|
|
275
287
|
}));
|
|
276
288
|
},
|
|
277
|
-
async applyRecovery (sealed, requestID) {
|
|
289
|
+
async applyRecovery ({ sealed, requestID }) {
|
|
278
290
|
const held = pending.get(requestID);
|
|
279
291
|
if (held == null) return null;
|
|
280
292
|
let reply;
|
|
@@ -300,7 +312,7 @@ export async function deriveRecoverySecret(handle) {
|
|
|
300
312
|
});
|
|
301
313
|
if (candidate == null || 'renewalRequired' in candidate) return candidate;
|
|
302
314
|
const rejoined = candidate;
|
|
303
|
-
if (rejoined.group.anchor.controller != null && !recoverySignerEligible({
|
|
315
|
+
if (rejoined.group.anchor.controller != null && !await recoverySignerEligible({
|
|
304
316
|
group: rejoined.group,
|
|
305
317
|
registry: rejoined.knownRegistry,
|
|
306
318
|
signer: reply.signer
|
|
@@ -325,7 +337,10 @@ export async function deriveRecoverySecret(handle) {
|
|
|
325
337
|
confirmationKey: judge.confirmationKey,
|
|
326
338
|
judgeVerdict: judge.judgeVerdict,
|
|
327
339
|
onAccepted: ()=>{
|
|
328
|
-
accepted ??= guardedReplace(
|
|
340
|
+
accepted ??= guardedReplace({
|
|
341
|
+
access,
|
|
342
|
+
next: rejoined.group
|
|
343
|
+
}).catch((error)=>{
|
|
329
344
|
accepted = undefined;
|
|
330
345
|
throw error;
|
|
331
346
|
});
|
|
@@ -346,7 +361,7 @@ export async function deriveRecoverySecret(handle) {
|
|
|
346
361
|
request: new TextDecoder().decode(request)
|
|
347
362
|
}));
|
|
348
363
|
},
|
|
349
|
-
async openSealedLedger (sealed, requestID) {
|
|
364
|
+
async openSealedLedger ({ sealed, requestID }) {
|
|
350
365
|
const held = pending.get(requestID);
|
|
351
366
|
if (held == null) return null;
|
|
352
367
|
try {
|
|
@@ -368,7 +383,8 @@ export async function deriveRecoverySecret(handle) {
|
|
|
368
383
|
await access.mutate(async (group, persist)=>{
|
|
369
384
|
let persisted = false;
|
|
370
385
|
try {
|
|
371
|
-
await group.bootstrapLedger(
|
|
386
|
+
await group.bootstrapLedger({
|
|
387
|
+
tokens,
|
|
372
388
|
persist: async (current)=>{
|
|
373
389
|
await persist(current);
|
|
374
390
|
persisted = true;
|
package/lib/recovery.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type OwnIdentity } from '@kokuin/token';
|
|
2
2
|
import { type ClientState, type ControllerBinding, type DeviceRegistry, type GroupHandle } from '@kumiai/mls';
|
|
3
|
-
import type { OpenedRecoveryVerdict, PendingRecovery } from '@kumiai/rpc';
|
|
3
|
+
import type { OpenedRecoveryVerdict, PendingRecovery, PendingRecoveryConfirmationKeyParams } from '@kumiai/rpc';
|
|
4
4
|
export type RecoveryBindingRequest = {
|
|
5
5
|
groupID: string;
|
|
6
6
|
controllerID: string;
|
|
@@ -40,6 +40,6 @@ export declare function createRecoveryBindingState(identity: OwnIdentity, host?:
|
|
|
40
40
|
} | null>;
|
|
41
41
|
};
|
|
42
42
|
export declare function createVerdictJudge(params: VerdictJudgeParams): {
|
|
43
|
-
confirmationKey(position
|
|
44
|
-
judgeVerdict(opened: OpenedRecoveryVerdict): "authoritative" | "advisory"
|
|
43
|
+
confirmationKey({ position, commitDigest }: PendingRecoveryConfirmationKeyParams): Promise<Uint8Array<ArrayBufferLike>>;
|
|
44
|
+
judgeVerdict(opened: OpenedRecoveryVerdict): Promise<"authoritative" | "advisory">;
|
|
45
45
|
};
|
package/lib/recovery.js
CHANGED
|
@@ -87,10 +87,15 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
87
87
|
credential: group.credential,
|
|
88
88
|
resync: true,
|
|
89
89
|
controller,
|
|
90
|
-
beforeBinding: async (pending, source)=>{
|
|
90
|
+
beforeBinding: async ({ pending, source })=>{
|
|
91
91
|
if (group.anchor.controller == null) return;
|
|
92
|
-
assertRetainsKnownEffects(
|
|
93
|
-
|
|
92
|
+
await assertRetainsKnownEffects({
|
|
93
|
+
controller: group.anchor.controller,
|
|
94
|
+
known: group.registry,
|
|
95
|
+
candidate: source.registry,
|
|
96
|
+
crypto: group.crypto
|
|
97
|
+
});
|
|
98
|
+
if (!await recoverySignerEligible({
|
|
94
99
|
group: pending,
|
|
95
100
|
registry: source.registry,
|
|
96
101
|
signer: reply.signer
|
|
@@ -100,6 +105,7 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
100
105
|
if (controller == null || !await usable(source, controller)) throw new LeafBindingError('floating-refused');
|
|
101
106
|
},
|
|
102
107
|
options: {
|
|
108
|
+
crypto: group.crypto,
|
|
103
109
|
commitPolicy: group.commitPolicy,
|
|
104
110
|
resolveLedgerEntries: group.resolveLedgerEntries,
|
|
105
111
|
onLedgerEntries: group.onLedgerEntries
|
|
@@ -142,21 +148,28 @@ export function createVerdictJudge(params) {
|
|
|
142
148
|
const { group, sourceTree, known, requestID } = params;
|
|
143
149
|
let tuple;
|
|
144
150
|
return {
|
|
145
|
-
async confirmationKey (position, commitDigest) {
|
|
151
|
+
async confirmationKey ({ position, commitDigest }) {
|
|
146
152
|
if (tuple != null && (tuple.position !== position || tuple.commitDigest !== commitDigest)) throw new Error('Pending recovery already bound to another commit');
|
|
147
153
|
tuple ??= {
|
|
148
154
|
position,
|
|
149
155
|
commitDigest
|
|
150
156
|
};
|
|
151
|
-
const key = await confirmationKey(
|
|
152
|
-
|
|
157
|
+
const key = await confirmationKey({
|
|
158
|
+
group,
|
|
159
|
+
position,
|
|
160
|
+
commitDigest
|
|
161
|
+
});
|
|
162
|
+
tuple.tag = confirmationTag({
|
|
163
|
+
key,
|
|
164
|
+
requestID
|
|
165
|
+
});
|
|
153
166
|
return key;
|
|
154
167
|
},
|
|
155
|
-
judgeVerdict (opened) {
|
|
168
|
+
async judgeVerdict (opened) {
|
|
156
169
|
const { signer, verdict } = opened;
|
|
157
170
|
if (normalizeDID(signer) === normalizeDID(group.credential.id) || tuple == null || verdict.groupID !== group.groupID || verdict.requestID !== requestID || verdict.position !== tuple.position || verdict.commitDigest !== tuple.commitDigest) return 'advisory';
|
|
158
171
|
if (verdict.verdict === 'confirmed' && (verdict.epoch !== Number(group.epoch) || verdict.tag !== tuple.tag)) return 'advisory';
|
|
159
|
-
if (group.anchor.controller != null) return recoverySignerEligible({
|
|
172
|
+
if (group.anchor.controller != null) return await recoverySignerEligible({
|
|
160
173
|
group,
|
|
161
174
|
registry: known,
|
|
162
175
|
signer
|
package/lib/revoke.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type EffectClaim, type GroupHandle, type RevokeBuildResult, type
|
|
1
|
+
import { type EffectClaim, type GroupHandle, type RevokeBuildResult, type RevokeProofInput } from '@kumiai/mls';
|
|
2
2
|
import type { GroupMLS, GroupPeer, GroupProtocolDefinition } from '@kumiai/rpc';
|
|
3
3
|
export type RevokeJournalOptions = {
|
|
4
4
|
/** Must restore the derived handle INCLUDING its ledger through the host's adoptJournalled. */
|
|
@@ -14,7 +14,7 @@ export type PublishRevokeResult = {
|
|
|
14
14
|
export type PublishRevokeProofParams<Protocols extends Record<string, GroupProtocolDefinition>> = {
|
|
15
15
|
peer: GroupPeer<Protocols>;
|
|
16
16
|
mls: GroupMLS;
|
|
17
|
-
input:
|
|
17
|
+
input: RevokeProofInput;
|
|
18
18
|
options: RevokeJournalOptions;
|
|
19
19
|
};
|
|
20
20
|
export declare function publishRevokeProof<Protocols extends Record<string, GroupProtocolDefinition>>(params: PublishRevokeProofParams<Protocols>): Promise<PublishRevokeResult>;
|
package/lib/revoke.js
CHANGED
|
@@ -8,36 +8,43 @@ export async function publishRevokeProof(params) {
|
|
|
8
8
|
const finished = Symbol('proof needs no commit');
|
|
9
9
|
let outcome;
|
|
10
10
|
try {
|
|
11
|
-
await peer.commit(
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
throw finished;
|
|
22
|
-
}
|
|
23
|
-
const effects = built.result.effects;
|
|
24
|
-
const { newGroup, commitMessage, epoch } = built.result.result;
|
|
25
|
-
const journal = await options.serializeJournal(newGroup);
|
|
26
|
-
return {
|
|
27
|
-
commit: commitMessage,
|
|
28
|
-
bodies: newGroup.ledgerTokens.filter((token)=>!built.priorTokens.has(token)),
|
|
29
|
-
kind: 'ledger',
|
|
30
|
-
journal,
|
|
31
|
-
onAccepted: async ()=>{
|
|
32
|
-
await guardedReplace(access, newGroup);
|
|
33
|
-
outcome = {
|
|
34
|
-
status: 'committed',
|
|
35
|
-
epoch: Number(epoch),
|
|
36
|
-
effects
|
|
11
|
+
await peer.commit({
|
|
12
|
+
build: async ()=>{
|
|
13
|
+
const built = await access.read(async (group)=>{
|
|
14
|
+
const result = await revokeWithProof({
|
|
15
|
+
group,
|
|
16
|
+
...input
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
result,
|
|
20
|
+
priorTokens: new Set(group.ledgerTokens)
|
|
37
21
|
};
|
|
22
|
+
});
|
|
23
|
+
if (built.result.status !== 'built') {
|
|
24
|
+
outcome = built.result;
|
|
25
|
+
throw finished;
|
|
38
26
|
}
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
const effects = built.result.effects;
|
|
28
|
+
const { newGroup, commitMessage, epoch } = built.result.result;
|
|
29
|
+
const journal = await options.serializeJournal(newGroup);
|
|
30
|
+
return {
|
|
31
|
+
commit: commitMessage,
|
|
32
|
+
bodies: newGroup.ledgerTokens.filter((token)=>!built.priorTokens.has(token)),
|
|
33
|
+
kind: 'ledger',
|
|
34
|
+
journal,
|
|
35
|
+
onAccepted: async ()=>{
|
|
36
|
+
await guardedReplace({
|
|
37
|
+
access,
|
|
38
|
+
next: newGroup
|
|
39
|
+
});
|
|
40
|
+
outcome = {
|
|
41
|
+
status: 'committed',
|
|
42
|
+
epoch: Number(epoch),
|
|
43
|
+
effects
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
},
|
|
41
48
|
holdLogSends: true
|
|
42
49
|
});
|
|
43
50
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumiai/mls-rpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "The @kumiai/rpc consumer ports (GroupCrypto, GroupMLS) implemented over @kumiai/mls",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mls",
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"lib/*"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@kokuin/token": "^0.
|
|
29
|
-
"@kumiai/mls": "^0.
|
|
30
|
-
"@kumiai/rpc": "^0.
|
|
28
|
+
"@kokuin/token": "^0.7.0",
|
|
29
|
+
"@kumiai/mls": "^0.13.0",
|
|
30
|
+
"@kumiai/rpc": "^0.13.0",
|
|
31
31
|
"@noble/ciphers": "^2.4.0",
|
|
32
32
|
"@sozai/runtime": "^0.1.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@kumiai/rpc-conformance": "^0.
|
|
35
|
+
"@kumiai/rpc-conformance": "^0.13.0",
|
|
36
36
|
"ts-mls": "2.0.0-rc.13",
|
|
37
|
-
"vitest": "^5.0
|
|
37
|
+
"vitest": "^5.1.0"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|