@kumiai/mls 0.12.3 → 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/anchor.d.ts +6 -2
- package/lib/anchor.js +1 -1
- package/lib/authentication.d.ts +8 -3
- package/lib/authentication.js +139 -46
- package/lib/capability.js +16 -7
- package/lib/controller-ingest.d.ts +14 -2
- package/lib/controller-ingest.js +15 -8
- package/lib/controller-log.d.ts +12 -6
- package/lib/controller-log.js +29 -15
- package/lib/device-proof.d.ts +2 -1
- package/lib/device-proof.js +2 -1
- package/lib/embedded-resolver.d.ts +7 -2
- package/lib/embedded-resolver.js +16 -6
- package/lib/envelope-fold.d.ts +3 -2
- package/lib/envelope-fold.js +14 -6
- package/lib/fold.d.ts +17 -3
- package/lib/fold.js +9 -3
- package/lib/group-commit.d.ts +11 -2
- package/lib/group-commit.js +76 -32
- package/lib/group-context.d.ts +37 -3
- package/lib/group-context.js +65 -4
- package/lib/group-create.d.ts +5 -1
- package/lib/group-create.js +36 -14
- package/lib/group-credential.d.ts +13 -3
- package/lib/group-credential.js +17 -6
- package/lib/group-device.d.ts +32 -22
- package/lib/group-device.js +66 -51
- package/lib/group-handle.d.ts +87 -31
- package/lib/group-handle.js +377 -168
- package/lib/group-lifecycle.d.ts +44 -11
- package/lib/group-lifecycle.js +193 -85
- package/lib/group-membership.d.ts +6 -1
- package/lib/group-membership.js +2 -2
- package/lib/group-welcome.d.ts +5 -1
- package/lib/group-welcome.js +34 -10
- package/lib/head.d.ts +25 -5
- package/lib/head.js +17 -8
- package/lib/history.d.ts +14 -3
- package/lib/history.js +8 -5
- package/lib/index.d.ts +28 -1
- package/lib/index.js +1 -0
- package/lib/key-package-codec.d.ts +4 -1
- package/lib/key-package-codec.js +1 -1
- package/lib/ledger.d.ts +14 -6
- package/lib/ledger.js +56 -19
- package/lib/lifecycle-proof.d.ts +5 -4
- package/lib/lifecycle-proof.js +111 -51
- package/lib/lifecycle.d.ts +18 -9
- package/lib/lifecycle.js +184 -81
- package/lib/member-root.d.ts +54 -15
- package/lib/member-root.js +115 -53
- package/lib/policy.d.ts +5 -1
- package/lib/policy.js +1 -1
- package/lib/recovery-verdict.d.ts +12 -3
- package/lib/recovery-verdict.js +56 -22
- package/lib/recovery.d.ts +20 -5
- package/lib/recovery.js +117 -46
- package/lib/registry.d.ts +46 -10
- package/lib/registry.js +64 -38
- package/lib/roster.d.ts +7 -1
- package/lib/roster.js +18 -7
- package/lib/secret-tree.d.ts +5 -1
- package/lib/secret-tree.js +1 -1
- package/lib/types.d.ts +3 -0
- package/package.json +9 -5
package/lib/device-proof.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SignedEvent } from '@kokuin/controller';
|
|
2
|
+
import { type CryptoOptions } from '@kokuin/token';
|
|
2
3
|
import type { VerifiedLedgerEntry } from './ledger.js';
|
|
3
4
|
import type { DeviceValue } from './registry.js';
|
|
4
5
|
/** What the tree yields about a leaf for the device-proof gate: its binding, prefix, and leaf key. */
|
|
@@ -37,4 +38,4 @@ export type DeviceProofContext = {
|
|
|
37
38
|
*
|
|
38
39
|
* Pure of the fold — runs only where the tree is present (never on a bootstrap re-fold).
|
|
39
40
|
*/
|
|
40
|
-
export declare function verifyDeviceEntry(verified: VerifiedLedgerEntry<DeviceValue>, ctx: DeviceProofContext): Promise<boolean>;
|
|
41
|
+
export declare function verifyDeviceEntry(verified: VerifiedLedgerEntry<DeviceValue>, ctx: DeviceProofContext, options?: CryptoOptions): Promise<boolean>;
|
package/lib/device-proof.js
CHANGED
|
@@ -14,7 +14,7 @@ import { verifyManagementCapability } from './authentication.js';
|
|
|
14
14
|
* leaf key and `exp`-bounded. The profile's log prefix comes from the issuer's OWN bound leaf.
|
|
15
15
|
*
|
|
16
16
|
* Pure of the fold — runs only where the tree is present (never on a bootstrap re-fold).
|
|
17
|
-
*/ export async function verifyDeviceEntry(verified, ctx) {
|
|
17
|
+
*/ export async function verifyDeviceEntry(verified, ctx, options) {
|
|
18
18
|
const issuer = normalizeDID(verified.issuer);
|
|
19
19
|
const subject = normalizeDID(verified.entry.subject);
|
|
20
20
|
const value = verified.entry.value;
|
|
@@ -43,6 +43,7 @@ import { verifyManagementCapability } from './authentication.js';
|
|
|
43
43
|
if (binding?.controller == null || binding.prefix == null) return false;
|
|
44
44
|
if (normalizeDID(binding.controller) !== authorizedProfile) return false;
|
|
45
45
|
return await verifyManagementCapability({
|
|
46
|
+
...options,
|
|
46
47
|
capability: value.capability,
|
|
47
48
|
prefix: binding.prefix,
|
|
48
49
|
controllerID: authorizedProfile,
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { type ControllerLog, type ControllerResolver, type SignedEvent } from '@kokuin/controller';
|
|
2
|
+
import { type CryptoOptions } from '@kokuin/token';
|
|
2
3
|
import { type DeviceRegistry } from './registry.js';
|
|
3
|
-
export
|
|
4
|
+
export type PrefixRelationParams = {
|
|
5
|
+
recorded: ControllerLog | undefined;
|
|
6
|
+
prefix: ReadonlyArray<SignedEvent>;
|
|
7
|
+
};
|
|
8
|
+
export declare function prefixRelation({ recorded, prefix, }: PrefixRelationParams): 'contained' | 'ahead' | 'forked' | 'none';
|
|
4
9
|
/** Root keys come from the leaf prefix; member authority comes from the recorded epoch. */
|
|
5
|
-
export declare function createRegistryControllerResolver(params: {
|
|
10
|
+
export declare function createRegistryControllerResolver(params: CryptoOptions & {
|
|
6
11
|
controllerID: string;
|
|
7
12
|
prefix: ReadonlyArray<SignedEvent>;
|
|
8
13
|
registry?: DeviceRegistry;
|
package/lib/embedded-resolver.js
CHANGED
|
@@ -3,7 +3,7 @@ import { normalizeDID } from '@kokuin/token';
|
|
|
3
3
|
import { asControllerLog, hasChainRevoke } from './controller-log.js';
|
|
4
4
|
import { denySetOf, recordedLogOf } from './registry.js';
|
|
5
5
|
const EMPTY = new Set();
|
|
6
|
-
export function prefixRelation(recorded, prefix) {
|
|
6
|
+
export function prefixRelation({ recorded, prefix }) {
|
|
7
7
|
const held = recorded?.chain.at(-1);
|
|
8
8
|
const carried = prefix.at(-1);
|
|
9
9
|
if (recorded == null || held == null || carried == null) return 'none';
|
|
@@ -14,11 +14,15 @@ export function prefixRelation(recorded, prefix) {
|
|
|
14
14
|
}
|
|
15
15
|
/** Root keys come from the leaf prefix; member authority comes from the recorded epoch. */ export function createRegistryControllerResolver(params) {
|
|
16
16
|
const controller = normalizeDID(params.controllerID);
|
|
17
|
-
const recorded = params.registry == null ? undefined : recordedLogOf(
|
|
17
|
+
const recorded = params.registry == null ? undefined : recordedLogOf({
|
|
18
|
+
registry: params.registry,
|
|
19
|
+
controller
|
|
20
|
+
});
|
|
18
21
|
const denied = params.registry == null ? EMPTY : denySetOf(params.registry);
|
|
19
22
|
const prefix = asControllerLog(params.prefix);
|
|
20
23
|
const resolverFor = (log)=>{
|
|
21
24
|
return createControllerResolver({
|
|
25
|
+
crypto: params.crypto,
|
|
22
26
|
loadLog: async (did)=>normalizeDID(did) === controller && !hasChainRevoke(log.chain) ? log : undefined
|
|
23
27
|
});
|
|
24
28
|
};
|
|
@@ -38,10 +42,16 @@ export function prefixRelation(recorded, prefix) {
|
|
|
38
42
|
return denied;
|
|
39
43
|
},
|
|
40
44
|
...params.registry == null ? {} : {
|
|
41
|
-
async resolveMember (
|
|
42
|
-
if (normalizeDID(
|
|
43
|
-
if (prefixRelation(
|
|
44
|
-
|
|
45
|
+
async resolveMember ({ subject, member: query }) {
|
|
46
|
+
if (normalizeDID(subject) !== controller) throw new Error(`Unknown DID: ${subject}`);
|
|
47
|
+
if (prefixRelation({
|
|
48
|
+
recorded,
|
|
49
|
+
prefix: params.prefix
|
|
50
|
+
}) !== 'contained') throw new Error('Recorded controller log does not contain the leaf prefix');
|
|
51
|
+
const member = await members.resolveMember?.({
|
|
52
|
+
subject,
|
|
53
|
+
member: query
|
|
54
|
+
});
|
|
45
55
|
if (member == null) throw new Error('Controller member resolution is unavailable');
|
|
46
56
|
return member;
|
|
47
57
|
}
|
package/lib/envelope-fold.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CryptoOptions } from '@kokuin/token';
|
|
1
2
|
import { RevokeProofError } from './errors.js';
|
|
2
3
|
import type { FoldInput } from './fold.js';
|
|
3
4
|
import type { VerifiedLedgerEntry } from './ledger.js';
|
|
@@ -28,7 +29,7 @@ export type FoldEnvelopeContext = {
|
|
|
28
29
|
/** The controller bound to the issuer's pre-commit leaf, if any. */
|
|
29
30
|
memberController: (did: string) => string | undefined;
|
|
30
31
|
};
|
|
31
|
-
export type FoldEnvelopeParams = {
|
|
32
|
+
export type FoldEnvelopeParams = CryptoOptions & {
|
|
32
33
|
baseRoster: RosterState;
|
|
33
34
|
baseRegistry: DeviceRegistry;
|
|
34
35
|
entries: Array<FoldInput>;
|
|
@@ -51,4 +52,4 @@ export type FoldEnvelopeParams = {
|
|
|
51
52
|
* subsumes `kumiai.role`'s own authority rule. State-so-far, not a pre-commit
|
|
52
53
|
* snapshot, so an envelope of `[promote Bob, entry-issued-by-Bob]` is accepted.
|
|
53
54
|
*/
|
|
54
|
-
export declare function foldEnvelope(params: FoldEnvelopeParams): EnvelopeFoldResult
|
|
55
|
+
export declare function foldEnvelope(params: FoldEnvelopeParams): Promise<EnvelopeFoldResult>;
|
package/lib/envelope-fold.js
CHANGED
|
@@ -21,8 +21,8 @@ function isRoleValue(value) {
|
|
|
21
21
|
* entry's issuer must be an admin at its own position — the universal invariant that
|
|
22
22
|
* subsumes `kumiai.role`'s own authority rule. State-so-far, not a pre-commit
|
|
23
23
|
* snapshot, so an envelope of `[promote Bob, entry-issued-by-Bob]` is accepted.
|
|
24
|
-
*/ export function foldEnvelope(params) {
|
|
25
|
-
const { baseRoster, baseRegistry, entries, groupID, context } = params;
|
|
24
|
+
*/ export async function foldEnvelope(params) {
|
|
25
|
+
const { baseRoster, baseRegistry, entries, groupID, context, crypto } = params;
|
|
26
26
|
let workingRoster = {
|
|
27
27
|
roles: new Map(baseRoster.roles)
|
|
28
28
|
};
|
|
@@ -61,13 +61,15 @@ function isRoleValue(value) {
|
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
try {
|
|
64
|
-
workingRegistry = registryApply({
|
|
64
|
+
workingRegistry = await registryApply({
|
|
65
65
|
issuer,
|
|
66
66
|
entry: {
|
|
67
67
|
...entry,
|
|
68
68
|
value
|
|
69
69
|
}
|
|
70
|
-
}, workingRegistry, context?.controllerID
|
|
70
|
+
}, workingRegistry, context?.controllerID, {
|
|
71
|
+
crypto
|
|
72
|
+
});
|
|
71
73
|
} catch (error) {
|
|
72
74
|
return {
|
|
73
75
|
ok: false,
|
|
@@ -101,7 +103,10 @@ function isRoleValue(value) {
|
|
|
101
103
|
}
|
|
102
104
|
// The universal invariant, now authority-aware: the issuer's AUTHORITY (controller ?? id,
|
|
103
105
|
// read off the registry-so-far) must be an admin in state-so-far.
|
|
104
|
-
if (workingRoster.roles.get(authority(
|
|
106
|
+
if (workingRoster.roles.get(authority({
|
|
107
|
+
registry: workingRegistry,
|
|
108
|
+
issuer
|
|
109
|
+
})) !== 'admin') {
|
|
105
110
|
return {
|
|
106
111
|
ok: false,
|
|
107
112
|
reason: `non-admin issuer '${issuer}'`,
|
|
@@ -123,7 +128,10 @@ function isRoleValue(value) {
|
|
|
123
128
|
value: entry.value
|
|
124
129
|
}
|
|
125
130
|
};
|
|
126
|
-
workingRoster = roleReducer.apply(
|
|
131
|
+
workingRoster = roleReducer.apply({
|
|
132
|
+
verified: roleEntry,
|
|
133
|
+
stateSoFar: workingRoster
|
|
134
|
+
});
|
|
127
135
|
// A group with zero admins can never again add, remove, promote, or demote.
|
|
128
136
|
if (adminCount(workingRoster) === 0) {
|
|
129
137
|
return {
|
package/lib/fold.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { GroupAnchor } from './anchor.js';
|
|
2
2
|
import type { VerifiedLedgerEntry } from './ledger.js';
|
|
3
|
+
export type LedgerReducerVerifyAuthorityParams<TValue, TState> = {
|
|
4
|
+
verified: VerifiedLedgerEntry<TValue>;
|
|
5
|
+
stateSoFar: TState;
|
|
6
|
+
};
|
|
7
|
+
export type LedgerReducerApplyParams<TValue, TState> = {
|
|
8
|
+
verified: VerifiedLedgerEntry<TValue>;
|
|
9
|
+
stateSoFar: TState;
|
|
10
|
+
};
|
|
3
11
|
/**
|
|
4
12
|
* A per-type projection over the control ledger. The fold stays free of any
|
|
5
13
|
* admin/circle semantics: a reducer owns its own initial state (derived from
|
|
@@ -16,9 +24,9 @@ export type LedgerReducer<TValue, TState> = {
|
|
|
16
24
|
*/
|
|
17
25
|
seed(anchor: GroupAnchor): TState;
|
|
18
26
|
/** Is the verified issuer allowed to make this claim, given the state so far? */
|
|
19
|
-
verifyAuthority(
|
|
27
|
+
verifyAuthority(params: LedgerReducerVerifyAuthorityParams<TValue, TState>): boolean;
|
|
20
28
|
/** Fold step: return the next state after applying an authorized claim. */
|
|
21
|
-
apply(
|
|
29
|
+
apply(params: LedgerReducerApplyParams<TValue, TState>): TState;
|
|
22
30
|
};
|
|
23
31
|
/**
|
|
24
32
|
* A verified entry paired with its content-addressed id. The id identifies the
|
|
@@ -35,6 +43,12 @@ export type FoldDrop = {
|
|
|
35
43
|
type: string;
|
|
36
44
|
reason: string;
|
|
37
45
|
};
|
|
46
|
+
export type FoldLedgerParams<TValue, TState> = {
|
|
47
|
+
entries: Array<FoldInput<TValue>>;
|
|
48
|
+
anchor: GroupAnchor;
|
|
49
|
+
reducer: LedgerReducer<TValue, TState>;
|
|
50
|
+
onDrop?: (drop: FoldDrop) => void;
|
|
51
|
+
};
|
|
38
52
|
/**
|
|
39
53
|
* Replay the ledger into a single reducer's projection.
|
|
40
54
|
*
|
|
@@ -65,4 +79,4 @@ export type FoldDrop = {
|
|
|
65
79
|
* authority-failed drops are expected, so the caller decides whether to surface
|
|
66
80
|
* them rather than the fold emitting to the console.
|
|
67
81
|
*/
|
|
68
|
-
export declare function foldLedger<TValue, TState>(entries
|
|
82
|
+
export declare function foldLedger<TValue, TState>({ entries, anchor, reducer, onDrop, }: FoldLedgerParams<TValue, TState>): TState;
|
package/lib/fold.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* `onDrop` observer is supplied — the fold runs on every authority check, where
|
|
28
28
|
* authority-failed drops are expected, so the caller decides whether to surface
|
|
29
29
|
* them rather than the fold emitting to the console.
|
|
30
|
-
*/ export function foldLedger(entries, anchor, reducer, onDrop) {
|
|
30
|
+
*/ export function foldLedger({ entries, anchor, reducer, onDrop }) {
|
|
31
31
|
let state = reducer.seed(anchor);
|
|
32
32
|
for (const { verified, entryID } of entries){
|
|
33
33
|
const { entry } = verified;
|
|
@@ -39,7 +39,10 @@
|
|
|
39
39
|
});
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
|
-
if (!reducer.verifyAuthority(
|
|
42
|
+
if (!reducer.verifyAuthority({
|
|
43
|
+
verified,
|
|
44
|
+
stateSoFar: state
|
|
45
|
+
})) {
|
|
43
46
|
onDrop?.({
|
|
44
47
|
entryID,
|
|
45
48
|
type: entry.type,
|
|
@@ -47,7 +50,10 @@
|
|
|
47
50
|
});
|
|
48
51
|
continue;
|
|
49
52
|
}
|
|
50
|
-
state = reducer.apply(
|
|
53
|
+
state = reducer.apply({
|
|
54
|
+
verified,
|
|
55
|
+
stateSoFar: state
|
|
56
|
+
});
|
|
51
57
|
}
|
|
52
58
|
return state;
|
|
53
59
|
}
|
package/lib/group-commit.d.ts
CHANGED
|
@@ -78,6 +78,10 @@ export type CommitLedgerEntriesResult = {
|
|
|
78
78
|
/** Post-commit epoch the group is now at (== newGroup.epoch). */
|
|
79
79
|
epoch: bigint;
|
|
80
80
|
};
|
|
81
|
+
export type CommitLedgerEntriesParams = {
|
|
82
|
+
group: GroupHandle;
|
|
83
|
+
tokens: Array<string>;
|
|
84
|
+
};
|
|
81
85
|
/**
|
|
82
86
|
* The admin write path for the control ledger: a commit carrying no membership
|
|
83
87
|
* proposal, only the entries it enacts and the head move covering them. An entry that
|
|
@@ -97,7 +101,7 @@ export type CommitLedgerEntriesResult = {
|
|
|
97
101
|
* The mutex only serializes concurrent calls against one handle. A source whose commit
|
|
98
102
|
* was accepted is superseded and must never be reused.
|
|
99
103
|
*/
|
|
100
|
-
export declare function commitLedgerEntries(group
|
|
104
|
+
export declare function commitLedgerEntries({ group, tokens, }: CommitLedgerEntriesParams): Promise<CommitLedgerEntriesResult>;
|
|
101
105
|
export type CommitInviteResult = {
|
|
102
106
|
/** The input invite, updated with the complete ledger, including any preservation clock. */
|
|
103
107
|
invite: Invite;
|
|
@@ -112,6 +116,11 @@ export type CommitInviteResult = {
|
|
|
112
116
|
* readMessageEpoch). */
|
|
113
117
|
epoch: bigint;
|
|
114
118
|
};
|
|
119
|
+
export type CommitInviteParams = {
|
|
120
|
+
group: GroupHandle;
|
|
121
|
+
keyPackage: KeyPackage;
|
|
122
|
+
invite: Invite;
|
|
123
|
+
};
|
|
115
124
|
/**
|
|
116
125
|
* Commit an invite by adding the invitee's key package. Produces an MLS Commit +
|
|
117
126
|
* Welcome.
|
|
@@ -134,4 +143,4 @@ export type CommitInviteResult = {
|
|
|
134
143
|
* The mutex only serializes concurrent calls against one handle; it does not make a
|
|
135
144
|
* second commit from a superseded handle safe.
|
|
136
145
|
*/
|
|
137
|
-
export declare function commitInvite(group
|
|
146
|
+
export declare function commitInvite({ group, keyPackage, invite, }: CommitInviteParams): Promise<CommitInviteResult>;
|
package/lib/group-commit.js
CHANGED
|
@@ -50,32 +50,47 @@ const INVITE_ENTRIES = new WeakMap();
|
|
|
50
50
|
...params.entries ?? []
|
|
51
51
|
];
|
|
52
52
|
for (const token of appended){
|
|
53
|
-
const verified = await verifyLedgerEntry(
|
|
53
|
+
const verified = await verifyLedgerEntry({
|
|
54
|
+
token,
|
|
55
|
+
crypto: group.crypto
|
|
56
|
+
});
|
|
54
57
|
if (verified == null || verified.entry.groupID !== group.groupID || verified.entry.type.startsWith('kumiai.') || normalizeDID(verified.issuer) !== normalizeDID(identity.id)) throw new Error('createInvite: entries must be consumer entries signed by the inviter');
|
|
55
58
|
}
|
|
56
59
|
if (params.controllerLog != null) {
|
|
57
|
-
const delta = controllerLogDelta(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
const delta = await controllerLogDelta({
|
|
61
|
+
group,
|
|
62
|
+
log: params.controllerLog
|
|
63
|
+
});
|
|
64
|
+
if (delta != null) appended.unshift(await signLedgerEntry({
|
|
65
|
+
identity,
|
|
66
|
+
entry: {
|
|
67
|
+
type: DEVICE_ENTRY_TYPE,
|
|
68
|
+
groupID: group.groupID,
|
|
69
|
+
subject: group.anchor.controller,
|
|
70
|
+
value: {
|
|
71
|
+
op: 'log',
|
|
72
|
+
proof: delta
|
|
73
|
+
}
|
|
65
74
|
}
|
|
66
75
|
}));
|
|
67
76
|
}
|
|
68
77
|
} else {
|
|
69
78
|
if (params.permission == null) throw new Error('createInvite: standard invites require permission');
|
|
70
|
-
if (group.roster.roles.get(authority(
|
|
79
|
+
if (group.roster.roles.get(authority({
|
|
80
|
+
registry: group.registry,
|
|
81
|
+
issuer: identity.id
|
|
82
|
+
})) !== 'admin') {
|
|
71
83
|
throw new Error('createInvite: the inviter must be an admin in the group roster');
|
|
72
84
|
}
|
|
73
85
|
appended = [
|
|
74
|
-
await signLedgerEntry(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
await signLedgerEntry({
|
|
87
|
+
identity,
|
|
88
|
+
entry: {
|
|
89
|
+
type: ROLE_ENTRY_TYPE,
|
|
90
|
+
groupID: group.groupID,
|
|
91
|
+
subject: recipientDID,
|
|
92
|
+
value: params.permission
|
|
93
|
+
}
|
|
79
94
|
})
|
|
80
95
|
];
|
|
81
96
|
}
|
|
@@ -106,7 +121,10 @@ const INVITE_ENTRIES = new WeakMap();
|
|
|
106
121
|
if (current == null) {
|
|
107
122
|
throw new Error('group has no ledger head extension; it cannot enact ledger entries');
|
|
108
123
|
}
|
|
109
|
-
const next = buildLedgerHeadExtension(extendHead(
|
|
124
|
+
const next = buildLedgerHeadExtension(extendHead({
|
|
125
|
+
head: current.head,
|
|
126
|
+
entryIDs
|
|
127
|
+
}));
|
|
110
128
|
return group.state.groupContext.extensions.map((ext)=>ext.extensionType === LEDGER_HEAD_EXTENSION_TYPE ? next : ext);
|
|
111
129
|
}
|
|
112
130
|
export function proposedTree(state, proposals) {
|
|
@@ -165,7 +183,10 @@ export function proposedTree(state, proposals) {
|
|
|
165
183
|
// every receiver, so fail here rather than emitting a commit nobody will apply.
|
|
166
184
|
// Authority-aware: a device of an admin profile commits as that profile. Device-only commits
|
|
167
185
|
// (register/add/revoke/label) are authorized by proofs, not a role, so they pass requireAdmin:false.
|
|
168
|
-
if (requireAdmin && group.anchor.controller == null && group.roster.roles.get(authority(
|
|
186
|
+
if (requireAdmin && group.anchor.controller == null && group.roster.roles.get(authority({
|
|
187
|
+
registry: group.registry,
|
|
188
|
+
issuer: group.credential.id
|
|
189
|
+
})) !== 'admin') {
|
|
169
190
|
throw new Error('the committer must be an admin in the group roster');
|
|
170
191
|
}
|
|
171
192
|
// Fold the entries exactly as every receiver will; refuse to author a commit the
|
|
@@ -176,7 +197,10 @@ export function proposedTree(state, proposals) {
|
|
|
176
197
|
// dead paper no matter who commits it.
|
|
177
198
|
const inputs = [];
|
|
178
199
|
for (const token of enacted){
|
|
179
|
-
const verified = await verifyLedgerEntry(
|
|
200
|
+
const verified = await verifyLedgerEntry({
|
|
201
|
+
token,
|
|
202
|
+
crypto: group.crypto
|
|
203
|
+
});
|
|
180
204
|
if (verified == null) {
|
|
181
205
|
throw new Error('cannot enact a ledger entry whose signature does not verify');
|
|
182
206
|
}
|
|
@@ -185,7 +209,8 @@ export function proposedTree(state, proposals) {
|
|
|
185
209
|
entryID: ledgerEntryDigest(token)
|
|
186
210
|
});
|
|
187
211
|
}
|
|
188
|
-
const foldEntries = ()=>foldEnvelope({
|
|
212
|
+
const foldEntries = async ()=>await foldEnvelope({
|
|
213
|
+
crypto: group.crypto,
|
|
189
214
|
baseRoster: group.roster,
|
|
190
215
|
baseRegistry: group.registry,
|
|
191
216
|
entries: inputs,
|
|
@@ -195,7 +220,7 @@ export function proposedTree(state, proposals) {
|
|
|
195
220
|
memberController: (did)=>group.bindingOfDID(did)?.controller
|
|
196
221
|
}
|
|
197
222
|
});
|
|
198
|
-
let fold = foldEntries();
|
|
223
|
+
let fold = await foldEntries();
|
|
199
224
|
if (!fold.ok) {
|
|
200
225
|
if (fold.error != null) throw fold.error;
|
|
201
226
|
throw new Error(`cannot enact ledger entry ${fold.entryID}: ${fold.reason}`);
|
|
@@ -208,30 +233,42 @@ export function proposedTree(state, proposals) {
|
|
|
208
233
|
senderLeafIndex: sourceState.privatePath.leafIndex
|
|
209
234
|
}))
|
|
210
235
|
]);
|
|
211
|
-
const clocks = await preservationClock(
|
|
236
|
+
const clocks = await preservationClock({
|
|
237
|
+
group,
|
|
238
|
+
candidateTree: tree,
|
|
239
|
+
candidateRegistry: fold.registry
|
|
240
|
+
});
|
|
212
241
|
for (const clock of clocks){
|
|
213
|
-
const verified = await verifyLedgerEntry(
|
|
242
|
+
const verified = await verifyLedgerEntry({
|
|
243
|
+
token: clock,
|
|
244
|
+
crypto: group.crypto
|
|
245
|
+
});
|
|
214
246
|
if (verified == null) throw new Error('Invalid preservation clock');
|
|
215
247
|
enacted.push(clock);
|
|
216
248
|
inputs.push({
|
|
217
249
|
verified,
|
|
218
250
|
entryID: ledgerEntryDigest(clock)
|
|
219
251
|
});
|
|
220
|
-
fold = foldEntries();
|
|
252
|
+
fold = await foldEntries();
|
|
221
253
|
if (!fold.ok) throw fold.error ?? new Error(fold.reason);
|
|
222
254
|
}
|
|
223
255
|
// Same reason as the fold guard above: verify device entries against THIS group's tree and
|
|
224
256
|
// registry so the committer never authors a commit every receiver's own gate will reject.
|
|
225
257
|
const proofCtx = {
|
|
226
258
|
bindingOfDID: (d)=>group.bindingOfDID(d),
|
|
227
|
-
controllerOf: (d)=>controllerOf(
|
|
259
|
+
controllerOf: (d)=>controllerOf({
|
|
260
|
+
registry: group.registry,
|
|
261
|
+
deviceDID: d
|
|
262
|
+
})
|
|
228
263
|
};
|
|
229
264
|
for (const input of inputs){
|
|
230
265
|
if (input.verified.entry.type !== DEVICE_ENTRY_TYPE) continue;
|
|
231
266
|
if (group.anchor.controller != null && input.verified.entry.value.op !== 'beacon') {
|
|
232
267
|
continue;
|
|
233
268
|
}
|
|
234
|
-
const ok = await verifyDeviceEntry(input.verified, proofCtx
|
|
269
|
+
const ok = await verifyDeviceEntry(input.verified, proofCtx, {
|
|
270
|
+
crypto: group.crypto
|
|
271
|
+
});
|
|
235
272
|
if (!ok) {
|
|
236
273
|
throw new Error(`cannot enact device entry ${input.entryID}: proof verification failed`);
|
|
237
274
|
}
|
|
@@ -280,10 +317,14 @@ export function proposedTree(state, proposals) {
|
|
|
280
317
|
]
|
|
281
318
|
};
|
|
282
319
|
try {
|
|
283
|
-
gate.check(incoming);
|
|
320
|
+
await gate.check(incoming);
|
|
284
321
|
} catch (cause) {
|
|
285
322
|
if (params.pendingProposals == null) throw cause;
|
|
286
|
-
const error = new CommitRejectedError(
|
|
323
|
+
const error = new CommitRejectedError({
|
|
324
|
+
proposals: incoming.proposals,
|
|
325
|
+
senderLeafIndex: incoming.senderLeafIndex,
|
|
326
|
+
reason: rejectionReason(cause)
|
|
327
|
+
});
|
|
287
328
|
error.cause = cause;
|
|
288
329
|
throw error;
|
|
289
330
|
}
|
|
@@ -380,7 +421,7 @@ export function proposedTree(state, proposals) {
|
|
|
380
421
|
* Serialise reserve, build and consume against the source handle.
|
|
381
422
|
* The mutex only serializes concurrent calls against one handle. A source whose commit
|
|
382
423
|
* was accepted is superseded and must never be reused.
|
|
383
|
-
*/ export async function commitLedgerEntries(group, tokens) {
|
|
424
|
+
*/ export async function commitLedgerEntries({ group, tokens }) {
|
|
384
425
|
return mutexFor(group).run(async ()=>{
|
|
385
426
|
if (tokens.length === 0) {
|
|
386
427
|
throw new Error('commitLedgerEntries: no ledger entries to commit');
|
|
@@ -390,7 +431,7 @@ export function proposedTree(state, proposals) {
|
|
|
390
431
|
extraProposals: [],
|
|
391
432
|
enacted: tokens
|
|
392
433
|
});
|
|
393
|
-
const newGroup = deriveGroup(group, result.newState);
|
|
434
|
+
const newGroup = await deriveGroup(group, result.newState);
|
|
394
435
|
await newGroup.applyLedgerEntries(result.enacted);
|
|
395
436
|
return {
|
|
396
437
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
@@ -420,7 +461,7 @@ export function proposedTree(state, proposals) {
|
|
|
420
461
|
* commit: two commits from the same source handle both frame at its epoch and diverge.
|
|
421
462
|
* The mutex only serializes concurrent calls against one handle; it does not make a
|
|
422
463
|
* second commit from a superseded handle safe.
|
|
423
|
-
*/ export async function commitInvite(group, keyPackage, invite) {
|
|
464
|
+
*/ export async function commitInvite({ group, keyPackage, invite }) {
|
|
424
465
|
return mutexFor(group).run(async ()=>{
|
|
425
466
|
if (invite.groupID !== group.groupID) {
|
|
426
467
|
throw new Error(`commitInvite: invite is for group ${invite.groupID}, not ${group.groupID}`);
|
|
@@ -430,7 +471,10 @@ export function proposedTree(state, proposals) {
|
|
|
430
471
|
if (group.anchor.controller == null) {
|
|
431
472
|
let grantedTo = null;
|
|
432
473
|
for (const token of enacted){
|
|
433
|
-
const verified = await verifyLedgerEntry(
|
|
474
|
+
const verified = await verifyLedgerEntry({
|
|
475
|
+
token,
|
|
476
|
+
crypto: group.crypto
|
|
477
|
+
});
|
|
434
478
|
if (verified?.entry.type === ROLE_ENTRY_TYPE && verified.entry.groupID === group.groupID) {
|
|
435
479
|
grantedTo = verified.entry.subject;
|
|
436
480
|
}
|
|
@@ -490,7 +534,7 @@ export function proposedTree(state, proposals) {
|
|
|
490
534
|
enacted,
|
|
491
535
|
ratchetTreeExtension: true
|
|
492
536
|
});
|
|
493
|
-
const newGroup = deriveGroup(group, result.newState);
|
|
537
|
+
const newGroup = await deriveGroup(group, result.newState);
|
|
494
538
|
if (result.welcome == null) {
|
|
495
539
|
throw new Error('commitInvite: expected a Welcome message for the add proposal');
|
|
496
540
|
}
|
package/lib/group-context.d.ts
CHANGED
|
@@ -1,9 +1,43 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { CryptoOptions } from '@kokuin/token';
|
|
2
|
+
import { type Capabilities, type ClientConfig, type GroupContextExtension, type KeyRetentionConfig, type MlsContext } from 'ts-mls';
|
|
2
3
|
import type { GroupAnchor } from './anchor.js';
|
|
3
4
|
import { type JudgingContext } from './authentication.js';
|
|
4
5
|
import type { GroupOptions } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* The receive-side key retention every kumiai context carries, in place of ts-mls's
|
|
8
|
+
* defaults (10 skipped keys, a 200-generation forward window).
|
|
9
|
+
*
|
|
10
|
+
* A member has ONE application sender ratchet per epoch, and a host can spend it across
|
|
11
|
+
* several lanes a receiver drains independently (tunnel topics, a service lane, an app
|
|
12
|
+
* log). After a reconnect one lane can hold a backlog of hundreds of frames while a single
|
|
13
|
+
* newer frame on another lane opens first and moves the receiver's ratchet past them. Every
|
|
14
|
+
* backlog frame whose skipped key was not retained can then never be opened: ts-mls throws
|
|
15
|
+
* `Desired gen in the past`.
|
|
16
|
+
*
|
|
17
|
+
* - `retainKeysForGenerations: 256` — a sender that restores a persisted state advances
|
|
18
|
+
* past a lease of up to 64 generations it may have spent, which leaves that many skipped
|
|
19
|
+
* keys no frame will ever claim; the remaining 192 generations cover a cross-lane backlog.
|
|
20
|
+
* The window counts generations, not frames: in a group of three or more, a sender's
|
|
21
|
+
* frames to the other peers are generations this receiver skips and never claims, so they
|
|
22
|
+
* both fill the window and shorten the backlog it covers (one frame in `members - 1` is
|
|
23
|
+
* this receiver's). Each retained key is one 32-byte secret, about 37 bytes encoded.
|
|
24
|
+
* - `retainKeysForEpochs: 1` — the current epoch's tree and one past epoch's. A backlog
|
|
25
|
+
* sealed before the last commit is rare, and in a group of three or more every retained
|
|
26
|
+
* tree holds a full window per sender at steady state. Measured persisted receiver state
|
|
27
|
+
* at steady state: 2 members 2.6 KB, 3 members 42 KB, 5 members 82 KB, 10 members 181 KB
|
|
28
|
+
* (with ts-mls's four past epochs: 5.8, 103, 202 and 449 KB). That state is persisted on
|
|
29
|
+
* each receive advance, and ts-mls re-sorts a full window on every ratchet step.
|
|
30
|
+
* - `maximumForwardRatchetSteps: 512` — at least the retention, so the single newer frame
|
|
31
|
+
* that jumps past a full backlog still opens rather than being refused as too far ahead.
|
|
32
|
+
* A step is one KDF expansion, so the bound on a forged generation stays cheap.
|
|
33
|
+
*/
|
|
34
|
+
export declare const KUMIAI_KEY_RETENTION_CONFIG: Readonly<KeyRetentionConfig>;
|
|
35
|
+
/** A context's client config, with kumiai's key retention when none is given. */
|
|
36
|
+
export declare function kumiaiClientConfig(): ClientConfig;
|
|
37
|
+
/** Copy a client config without sharing its mutable parts with the source context. */
|
|
38
|
+
export declare function copyClientConfig(config: ClientConfig): ClientConfig;
|
|
5
39
|
/** Late-bound provider of a context's device deny set, pointed at the live handle after construction. */
|
|
6
|
-
export type DeviceDenyHolder = {
|
|
40
|
+
export type DeviceDenyHolder = CryptoOptions & {
|
|
7
41
|
provider: () => ReadonlySet<string>;
|
|
8
42
|
judging?: () => JudgingContext;
|
|
9
43
|
leafLifetime?: number;
|
|
@@ -14,7 +48,7 @@ export declare function deviceDenyHolderFor(context: MlsContext): DeviceDenyHold
|
|
|
14
48
|
/** Run with an isolated authentication service without changing the source context. */
|
|
15
49
|
export declare function withJudging<T>(context: MlsContext, judging: JudgingContext, fn: (context: MlsContext) => Promise<T>): Promise<T>;
|
|
16
50
|
export declare function resolveMlsContext(options?: GroupOptions, anchor?: GroupAnchor): Promise<MlsContext>;
|
|
17
|
-
export declare function createMlsContext(cipherSuite: MlsContext['cipherSuite'], anchor?: GroupAnchor): MlsContext;
|
|
51
|
+
export declare function createMlsContext(cipherSuite: MlsContext['cipherSuite'], anchor?: GroupAnchor, clientConfig?: ClientConfig, options?: CryptoOptions): MlsContext;
|
|
18
52
|
/**
|
|
19
53
|
* Build the leaf-node capabilities for a member joining or creating a group. RFC
|
|
20
54
|
* 9420 requires a leaf to advertise every non-default GroupContext extension type
|