@kumiai/mls-rpc 0.11.0 → 0.12.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/README.md +9 -4
- package/lib/access.d.ts +11 -2
- package/lib/access.js +22 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/mls.d.ts +1 -1
- package/lib/mls.js +5 -4
- package/lib/recovery.d.ts +0 -1
- package/lib/recovery.js +18 -27
- package/lib/revoke.d.ts +2 -1
- package/lib/revoke.js +5 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -19,6 +19,9 @@ depend on both.
|
|
|
19
19
|
|
|
20
20
|
- `simpleHandleAccess({ handle, adopt, persist? })` — serialised access to a live handle; the
|
|
21
21
|
`HandleAccess` type for a host that brings its own.
|
|
22
|
+
- `retainsKnownEffects(next)` — replacement guard refusing a handle that drops lifecycle effects the
|
|
23
|
+
live handle knows. `guardedReplace(access, next)` replaces through it, and throws afterwards if
|
|
24
|
+
`access` never invoked the guard (a broken adapter has then already adopted `next`).
|
|
22
25
|
- `createGroupCrypto({ access, entryLabel?, runtime?, pending? })` — `GroupCrypto` over that access.
|
|
23
26
|
- `createGroupMLS({ access, identity, entrySlot, recoverySecret? })` — `GroupMLS` over the same
|
|
24
27
|
access.
|
|
@@ -33,8 +36,8 @@ depend on both.
|
|
|
33
36
|
|
|
34
37
|
Both factories take the same `access` instance. The adapter reads the current handle through
|
|
35
38
|
`handle: () => GroupHandle`, because authored commits and recovery replace it wholesale. A host
|
|
36
|
-
adopts an authored commit through `access
|
|
37
|
-
publishing the replacement and publishes its synchronous epoch hint after a successful save.
|
|
39
|
+
adopts an authored commit through `guardedReplace(access, next)` after acceptance. The adapter saves
|
|
40
|
+
before publishing the replacement and publishes its synchronous epoch hint after a successful save.
|
|
38
41
|
|
|
39
42
|
Before every host commit build, `createGroupMLS` persists a handshake reservation through `access.mutate`.
|
|
40
43
|
The epoch and application ratchet stay unchanged, including when a discarded CAS winner never applies.
|
|
@@ -79,8 +82,10 @@ const mls = createGroupMLS({ access, identity, entrySlot })
|
|
|
79
82
|
A host with its own handle store implements the port instead:
|
|
80
83
|
- `read(fn)` lends the handle for the callback only. `mutate(fn)` serialises with every other
|
|
81
84
|
operation and resolves after the state is stored; `fn`'s `persist` argument goes to
|
|
82
|
-
`processMessage`, `bootstrapLedger` and `reserveHandshakeGeneration`. `replace(next)`
|
|
83
|
-
|
|
85
|
+
`processMessage`, `bootstrapLedger` and `reserveHandshakeGeneration`. `replace(next, guard)`
|
|
86
|
+
must run `guard(live)` on the live handle under the lock, abort if it throws, then store before
|
|
87
|
+
publishing. A transactional host may restore a fresh handle per mutation, discard it on rollback,
|
|
88
|
+
and publish on commit.
|
|
84
89
|
- `epoch()` is a synchronous hint. Publish it only after the outermost successful commit, and restore
|
|
85
90
|
it on rollback. No port decision reads it: every one uses an epoch read under the lock.
|
|
86
91
|
- `open(fn, persistOpened)` is the durable open. `fn` stages the open and hands its state and record
|
package/lib/access.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
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
4
|
export type HandleAccess = {
|
|
@@ -8,9 +8,18 @@ export type HandleAccess = {
|
|
|
8
8
|
admission(): SendAdmission;
|
|
9
9
|
read<TValue>(fn: (handle: GroupHandle) => TValue | Promise<TValue>): Promise<TValue>;
|
|
10
10
|
mutate<TValue>(fn: (handle: GroupHandle, persist: (handle: GroupHandle) => Promise<void>) => Promise<TValue>): Promise<TValue>;
|
|
11
|
-
|
|
11
|
+
/** Must run the guard under the replacement lock, before persistence; a throw aborts. */
|
|
12
|
+
replace(next: GroupHandle, guard: (live: GroupHandle) => void): Promise<void>;
|
|
12
13
|
open<TValue>(fn: (handle: GroupHandle, persistOpened: PersistOpened) => Promise<TValue>, persistOpened: PersistOpened): Promise<TValue>;
|
|
13
14
|
};
|
|
15
|
+
/** Refuses a replacement that drops lifecycle effects the live handle knows. */
|
|
16
|
+
export declare function retainsKnownEffects(next: GroupHandle): (live: GroupHandle) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Replaces through `retainsKnownEffects`. A guard never invoked throws after the fact (the skipping
|
|
19
|
+
* implementation has already adopted `next`): this surfaces a broken adapter, it does not undo it.
|
|
20
|
+
* It cannot prove the guard ran on the live handle or under the lock; that stays the port contract.
|
|
21
|
+
*/
|
|
22
|
+
export declare function guardedReplace(access: HandleAccess, next: GroupHandle): Promise<void>;
|
|
14
23
|
export type SimpleHandleAccessParams = {
|
|
15
24
|
handle: () => GroupHandle;
|
|
16
25
|
adopt: (next: GroupHandle) => void | Promise<void>;
|
package/lib/access.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
import { assertRetainsKnownEffects } from '@kumiai/mls';
|
|
2
|
+
/** Refuses a replacement that drops lifecycle effects the live handle knows. */ export function retainsKnownEffects(next) {
|
|
3
|
+
return (live)=>{
|
|
4
|
+
const controller = live.anchor.controller;
|
|
5
|
+
if (controller != null) assertRetainsKnownEffects(controller, live.registry, next.registry);
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Replaces through `retainsKnownEffects`. A guard never invoked throws after the fact (the skipping
|
|
10
|
+
* implementation has already adopted `next`): this surfaces a broken adapter, it does not undo it.
|
|
11
|
+
* 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) {
|
|
13
|
+
const guard = retainsKnownEffects(next);
|
|
14
|
+
let ran = false;
|
|
15
|
+
await access.replace(next, (live)=>{
|
|
16
|
+
guard(live);
|
|
17
|
+
ran = true;
|
|
18
|
+
});
|
|
19
|
+
if (!ran) throw new Error('HandleAccess.replace did not run its guard');
|
|
20
|
+
}
|
|
1
21
|
export function simpleHandleAccess(params) {
|
|
2
22
|
let publishedAdmission = params.handle().sendAdmission();
|
|
3
23
|
let tail = Promise.resolve();
|
|
@@ -33,7 +53,8 @@ export function simpleHandleAccess(params) {
|
|
|
33
53
|
publishedAdmission = handle.sendAdmission();
|
|
34
54
|
return result;
|
|
35
55
|
}),
|
|
36
|
-
replace: (next)=>serialise(async ()=>{
|
|
56
|
+
replace: (next, guard)=>serialise(async ()=>{
|
|
57
|
+
guard(params.handle());
|
|
37
58
|
await save(next);
|
|
38
59
|
await params.adopt(next);
|
|
39
60
|
publishedAdmission = next.sendAdmission();
|
package/lib/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* @module mls-rpc
|
|
20
20
|
*/
|
|
21
|
-
export { type HandleAccess, type SimpleHandleAccessParams, simpleHandleAccess } from './access.js';
|
|
21
|
+
export { guardedReplace, type HandleAccess, retainsKnownEffects, type SimpleHandleAccessParams, simpleHandleAccess, } from './access.js';
|
|
22
22
|
export { type ApplyCommitParams, type ApplyCommitResult, applyCommit } from './apply-commit.js';
|
|
23
23
|
export { createGroupCrypto, deriveEntryKey, ENTRY_SEAL_LABEL, type GroupCryptoParams, openEntries, sealEntries, } from './crypto.js';
|
|
24
24
|
export { createGroupMLS, createLedgerEntrySlot, createRecoveryPending, deriveRecoverySecret, type GroupMLSParams, type LedgerEntrySlot, RECOVERY_LABEL, type RecoveryPending, } from './mls.js';
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* failure mode the seam already has.
|
|
18
18
|
*
|
|
19
19
|
* @module mls-rpc
|
|
20
|
-
*/ export { simpleHandleAccess } from './access.js';
|
|
20
|
+
*/ export { guardedReplace, retainsKnownEffects, simpleHandleAccess } from './access.js';
|
|
21
21
|
export { applyCommit } from './apply-commit.js';
|
|
22
22
|
export { createGroupCrypto, deriveEntryKey, ENTRY_SEAL_LABEL, openEntries, sealEntries } from './crypto.js';
|
|
23
23
|
export { createGroupMLS, createLedgerEntrySlot, createRecoveryPending, deriveRecoverySecret, RECOVERY_LABEL } from './mls.js';
|
package/lib/mls.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { OwnIdentity } from '@kokuin/token';
|
|
2
2
|
import { type GroupHandle } from '@kumiai/mls';
|
|
3
3
|
import type { GroupMLS } from '@kumiai/rpc';
|
|
4
|
-
import type
|
|
4
|
+
import { type HandleAccess } from './access.js';
|
|
5
5
|
import { type RecoveryBinding } from './recovery.js';
|
|
6
6
|
export declare const groupHandleAccess: WeakMap<GroupMLS, HandleAccess>;
|
|
7
7
|
/**
|
package/lib/mls.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { confirmationKey, createRecoveryRequest, encodeGroupAnchor, ledgerEntryDigest, MissingLedgerEntriesError, openRecoveryGroupInfo, openRecoveryVerdict, openSealedLedger, readCommitEntryIDs, readMessageEpoch, recoverySignerEligible, sealGroupInfo, sealLedger, sealRecoveryVerdict, verifyRecoveryRequest } from '@kumiai/mls';
|
|
2
|
+
import { guardedReplace } from './access.js';
|
|
2
3
|
import { applyCommit } from './apply-commit.js';
|
|
3
|
-
import { createRecoveryBindingState, createVerdictJudge
|
|
4
|
+
import { createRecoveryBindingState, createVerdictJudge } from './recovery.js';
|
|
4
5
|
export const groupHandleAccess = new WeakMap();
|
|
5
6
|
const utf8 = new TextEncoder();
|
|
6
7
|
/**
|
|
@@ -294,14 +295,14 @@ export async function deriveRecoverySecret(handle) {
|
|
|
294
295
|
if (rejoined == null || 'renewalRequired' in rejoined) return rejoined;
|
|
295
296
|
return {
|
|
296
297
|
...rejoined,
|
|
297
|
-
knownRegistry:
|
|
298
|
+
knownRegistry: rejoined.group.registry
|
|
298
299
|
};
|
|
299
300
|
});
|
|
300
301
|
if (candidate == null || 'renewalRequired' in candidate) return candidate;
|
|
301
302
|
const rejoined = candidate;
|
|
302
303
|
if (rejoined.group.anchor.controller != null && !recoverySignerEligible({
|
|
303
304
|
group: rejoined.group,
|
|
304
|
-
|
|
305
|
+
registry: rejoined.knownRegistry,
|
|
305
306
|
signer: reply.signer
|
|
306
307
|
})) return null;
|
|
307
308
|
const judge = createVerdictJudge({
|
|
@@ -324,7 +325,7 @@ export async function deriveRecoverySecret(handle) {
|
|
|
324
325
|
confirmationKey: judge.confirmationKey,
|
|
325
326
|
judgeVerdict: judge.judgeVerdict,
|
|
326
327
|
onAccepted: ()=>{
|
|
327
|
-
accepted ??= access
|
|
328
|
+
accepted ??= guardedReplace(access, rejoined.group).catch((error)=>{
|
|
328
329
|
accepted = undefined;
|
|
329
330
|
throw error;
|
|
330
331
|
});
|
package/lib/recovery.d.ts
CHANGED
|
@@ -27,7 +27,6 @@ export type RecoveryCandidate = PendingRecovery & {
|
|
|
27
27
|
replyLedger: Array<string>;
|
|
28
28
|
signer: string;
|
|
29
29
|
};
|
|
30
|
-
export declare function knownRecoveryRegistry(known: DeviceRegistry, reply: DeviceRegistry): DeviceRegistry;
|
|
31
30
|
export declare function createRecoveryBindingState(identity: OwnIdentity, host?: RecoveryBinding): {
|
|
32
31
|
prepare(group: GroupHandle): Promise<"ready" | "renewal-required">;
|
|
33
32
|
join(group: GroupHandle, reply: RecoveryReply): Promise<{
|
package/lib/recovery.js
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
import { normalizeDID } from '@kokuin/token';
|
|
2
|
-
import { assertRecoveryBinding, confirmationKey, confirmationTag, joinGroupExternal, LeafBindingError, LeafLapsedError, parseMLSCredentialIdentity, RevokeProofError, recoverySignerEligible } from '@kumiai/mls';
|
|
3
|
-
export function knownRecoveryRegistry(known, reply) {
|
|
4
|
-
const devices = new Map(reply.devices);
|
|
5
|
-
for (const [did, record] of known.devices){
|
|
6
|
-
if (record.status === 'revoked' || !devices.has(did)) devices.set(did, record);
|
|
7
|
-
}
|
|
8
|
-
const controllers = new Map(reply.controllers);
|
|
9
|
-
for (const [id, projection] of known.controllers){
|
|
10
|
-
const offered = controllers.get(id);
|
|
11
|
-
controllers.set(id, offered == null ? projection : {
|
|
12
|
-
...offered,
|
|
13
|
-
genFloor: Math.max(projection.genFloor, offered.genFloor),
|
|
14
|
-
timeFloor: Math.max(projection.timeFloor, offered.timeFloor)
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
devices,
|
|
19
|
-
controllers
|
|
20
|
-
};
|
|
21
|
-
}
|
|
2
|
+
import { assertRecoveryBinding, assertRetainsKnownEffects, confirmationKey, confirmationTag, joinGroupExternal, LeafBindingError, LeafLapsedError, parseMLSCredentialIdentity, RevokeProofError, recoverySignerEligible } from '@kumiai/mls';
|
|
22
3
|
export function createRecoveryBindingState(identity, host) {
|
|
23
4
|
let binding;
|
|
24
5
|
let asked = false;
|
|
@@ -28,7 +9,9 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
28
9
|
value.id,
|
|
29
10
|
value.prefix,
|
|
30
11
|
value.capability,
|
|
31
|
-
value.holderGrant
|
|
12
|
+
value.holderGrant,
|
|
13
|
+
value.member,
|
|
14
|
+
value.iat
|
|
32
15
|
]);
|
|
33
16
|
function markBindingUnusable(id) {
|
|
34
17
|
if (id == null) return;
|
|
@@ -54,10 +37,15 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
54
37
|
}
|
|
55
38
|
function current(group) {
|
|
56
39
|
const leaf = group.bindingOfDID(identity.id);
|
|
57
|
-
return leaf?.controller == null || leaf.prefix == null
|
|
40
|
+
return leaf?.controller == null || leaf.prefix == null ? undefined : {
|
|
58
41
|
id: leaf.controller,
|
|
59
42
|
prefix: leaf.prefix,
|
|
60
|
-
|
|
43
|
+
...leaf.member == null ? {
|
|
44
|
+
capability: leaf.capability
|
|
45
|
+
} : {
|
|
46
|
+
member: leaf.member,
|
|
47
|
+
iat: leaf.iat
|
|
48
|
+
},
|
|
61
49
|
...leaf.holderGrant == null ? {} : {
|
|
62
50
|
holderGrant: leaf.holderGrant
|
|
63
51
|
}
|
|
@@ -90,6 +78,7 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
90
78
|
binding = current(group);
|
|
91
79
|
}
|
|
92
80
|
let signerEligible = group.anchor.controller == null;
|
|
81
|
+
let candidateSource;
|
|
93
82
|
const build = (controller)=>{
|
|
94
83
|
signerEligible = group.anchor.controller == null;
|
|
95
84
|
return joinGroupExternal({
|
|
@@ -100,13 +89,15 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
100
89
|
controller,
|
|
101
90
|
beforeBinding: async (pending, source)=>{
|
|
102
91
|
if (group.anchor.controller == null) return;
|
|
92
|
+
assertRetainsKnownEffects(group.anchor.controller, group.registry, source.registry);
|
|
103
93
|
if (!recoverySignerEligible({
|
|
104
94
|
group: pending,
|
|
105
|
-
|
|
95
|
+
registry: source.registry,
|
|
106
96
|
signer: reply.signer
|
|
107
97
|
})) throw new Error('Ineligible recovery attestation signer');
|
|
108
98
|
signerEligible = true;
|
|
109
|
-
|
|
99
|
+
candidateSource = source;
|
|
100
|
+
if (controller == null || !await usable(source, controller)) throw new LeafBindingError('floating-refused');
|
|
110
101
|
},
|
|
111
102
|
options: {
|
|
112
103
|
commitPolicy: group.commitPolicy,
|
|
@@ -132,7 +123,7 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
132
123
|
} catch (error) {
|
|
133
124
|
if (!signerEligible || group.anchor.controller == null || !(error instanceof LeafBindingError || error instanceof LeafLapsedError || error instanceof RevokeProofError)) return null;
|
|
134
125
|
binding = await request(group);
|
|
135
|
-
if (binding == null || !await usable(
|
|
126
|
+
if (binding == null || candidateSource == null || !await usable(candidateSource, binding)) return {
|
|
136
127
|
renewalRequired: true
|
|
137
128
|
};
|
|
138
129
|
try {
|
|
@@ -167,7 +158,7 @@ export function createVerdictJudge(params) {
|
|
|
167
158
|
if (verdict.verdict === 'confirmed' && (verdict.epoch !== Number(group.epoch) || verdict.tag !== tuple.tag)) return 'advisory';
|
|
168
159
|
if (group.anchor.controller != null) return recoverySignerEligible({
|
|
169
160
|
group,
|
|
170
|
-
known,
|
|
161
|
+
registry: known,
|
|
171
162
|
signer
|
|
172
163
|
}) ? 'authoritative' : 'advisory';
|
|
173
164
|
if (verdict.verdict === 'confirmed') return 'authoritative';
|
package/lib/revoke.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type GroupHandle, type RevokeBuildResult, type RevokeWithProofParams } from '@kumiai/mls';
|
|
1
|
+
import { type EffectClaim, type GroupHandle, type RevokeBuildResult, type RevokeWithProofParams } 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. */
|
|
@@ -7,6 +7,7 @@ export type RevokeJournalOptions = {
|
|
|
7
7
|
export type PublishRevokeResult = {
|
|
8
8
|
status: 'committed';
|
|
9
9
|
epoch: number;
|
|
10
|
+
effects: Array<EffectClaim>;
|
|
10
11
|
} | Exclude<RevokeBuildResult, {
|
|
11
12
|
status: 'built';
|
|
12
13
|
}>;
|
package/lib/revoke.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { revokeWithProof } from '@kumiai/mls';
|
|
2
|
+
import { guardedReplace } from './access.js';
|
|
2
3
|
import { groupHandleAccess } from './mls.js';
|
|
3
4
|
export async function publishRevokeProof(params) {
|
|
4
5
|
const { peer, mls, input, options } = params;
|
|
@@ -19,6 +20,7 @@ export async function publishRevokeProof(params) {
|
|
|
19
20
|
outcome = built.result;
|
|
20
21
|
throw finished;
|
|
21
22
|
}
|
|
23
|
+
const effects = built.result.effects;
|
|
22
24
|
const { newGroup, commitMessage, epoch } = built.result.result;
|
|
23
25
|
const journal = await options.serializeJournal(newGroup);
|
|
24
26
|
return {
|
|
@@ -27,10 +29,11 @@ export async function publishRevokeProof(params) {
|
|
|
27
29
|
kind: 'ledger',
|
|
28
30
|
journal,
|
|
29
31
|
onAccepted: async ()=>{
|
|
30
|
-
await access
|
|
32
|
+
await guardedReplace(access, newGroup);
|
|
31
33
|
outcome = {
|
|
32
34
|
status: 'committed',
|
|
33
|
-
epoch: Number(epoch)
|
|
35
|
+
epoch: Number(epoch),
|
|
36
|
+
effects
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
39
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumiai/mls-rpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "The @kumiai/rpc consumer ports (GroupCrypto, GroupMLS) implemented over @kumiai/mls",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mls",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"lib/*"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@kokuin/token": "^0.6.
|
|
29
|
-
"@kumiai/mls": "^0.
|
|
30
|
-
"@kumiai/rpc": "^0.
|
|
28
|
+
"@kokuin/token": "^0.6.2",
|
|
29
|
+
"@kumiai/mls": "^0.12.0",
|
|
30
|
+
"@kumiai/rpc": "^0.12.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.12.0",
|
|
36
36
|
"ts-mls": "2.0.0-rc.13",
|
|
37
37
|
"vitest": "^5.0.5"
|
|
38
38
|
},
|