@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.
Files changed (65) hide show
  1. package/lib/anchor.d.ts +6 -2
  2. package/lib/anchor.js +1 -1
  3. package/lib/authentication.d.ts +8 -3
  4. package/lib/authentication.js +139 -46
  5. package/lib/capability.js +16 -7
  6. package/lib/controller-ingest.d.ts +14 -2
  7. package/lib/controller-ingest.js +15 -8
  8. package/lib/controller-log.d.ts +12 -6
  9. package/lib/controller-log.js +29 -15
  10. package/lib/device-proof.d.ts +2 -1
  11. package/lib/device-proof.js +2 -1
  12. package/lib/embedded-resolver.d.ts +7 -2
  13. package/lib/embedded-resolver.js +16 -6
  14. package/lib/envelope-fold.d.ts +3 -2
  15. package/lib/envelope-fold.js +14 -6
  16. package/lib/fold.d.ts +17 -3
  17. package/lib/fold.js +9 -3
  18. package/lib/group-commit.d.ts +11 -2
  19. package/lib/group-commit.js +76 -32
  20. package/lib/group-context.d.ts +37 -3
  21. package/lib/group-context.js +65 -4
  22. package/lib/group-create.d.ts +5 -1
  23. package/lib/group-create.js +36 -14
  24. package/lib/group-credential.d.ts +13 -3
  25. package/lib/group-credential.js +17 -6
  26. package/lib/group-device.d.ts +32 -22
  27. package/lib/group-device.js +66 -51
  28. package/lib/group-handle.d.ts +87 -31
  29. package/lib/group-handle.js +377 -168
  30. package/lib/group-lifecycle.d.ts +44 -11
  31. package/lib/group-lifecycle.js +193 -85
  32. package/lib/group-membership.d.ts +6 -1
  33. package/lib/group-membership.js +2 -2
  34. package/lib/group-welcome.d.ts +5 -1
  35. package/lib/group-welcome.js +34 -10
  36. package/lib/head.d.ts +25 -5
  37. package/lib/head.js +17 -8
  38. package/lib/history.d.ts +14 -3
  39. package/lib/history.js +8 -5
  40. package/lib/index.d.ts +28 -1
  41. package/lib/index.js +1 -0
  42. package/lib/key-package-codec.d.ts +4 -1
  43. package/lib/key-package-codec.js +1 -1
  44. package/lib/ledger.d.ts +14 -6
  45. package/lib/ledger.js +56 -19
  46. package/lib/lifecycle-proof.d.ts +5 -4
  47. package/lib/lifecycle-proof.js +111 -51
  48. package/lib/lifecycle.d.ts +18 -9
  49. package/lib/lifecycle.js +184 -81
  50. package/lib/member-root.d.ts +54 -15
  51. package/lib/member-root.js +115 -53
  52. package/lib/policy.d.ts +5 -1
  53. package/lib/policy.js +1 -1
  54. package/lib/recovery-verdict.d.ts +12 -3
  55. package/lib/recovery-verdict.js +56 -22
  56. package/lib/recovery.d.ts +20 -5
  57. package/lib/recovery.js +117 -46
  58. package/lib/registry.d.ts +46 -10
  59. package/lib/registry.js +64 -38
  60. package/lib/roster.d.ts +7 -1
  61. package/lib/roster.js +18 -7
  62. package/lib/secret-tree.d.ts +5 -1
  63. package/lib/secret-tree.js +1 -1
  64. package/lib/types.d.ts +3 -0
  65. package/package.json +9 -5
@@ -1,9 +1,65 @@
1
- import { defaultCapabilities, getCiphersuiteImpl } from 'ts-mls';
1
+ import { defaultCapabilities, defaultKeyPackageEqualityConfig, defaultLifetimeConfig, defaultPaddingConfig, getCiphersuiteImpl } from 'ts-mls';
2
2
  import { createDIDAuthenticationService } from './authentication.js';
3
3
  import { nobleCryptoProvider } from './crypto.js';
4
4
  import { denySetOf } from './registry.js';
5
5
  const DEFAULT_CIPHERSUITE = 'MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519';
6
6
  const EMPTY_DENY = new Set();
7
+ /**
8
+ * The receive-side key retention every kumiai context carries, in place of ts-mls's
9
+ * defaults (10 skipped keys, a 200-generation forward window).
10
+ *
11
+ * A member has ONE application sender ratchet per epoch, and a host can spend it across
12
+ * several lanes a receiver drains independently (tunnel topics, a service lane, an app
13
+ * log). After a reconnect one lane can hold a backlog of hundreds of frames while a single
14
+ * newer frame on another lane opens first and moves the receiver's ratchet past them. Every
15
+ * backlog frame whose skipped key was not retained can then never be opened: ts-mls throws
16
+ * `Desired gen in the past`.
17
+ *
18
+ * - `retainKeysForGenerations: 256` — a sender that restores a persisted state advances
19
+ * past a lease of up to 64 generations it may have spent, which leaves that many skipped
20
+ * keys no frame will ever claim; the remaining 192 generations cover a cross-lane backlog.
21
+ * The window counts generations, not frames: in a group of three or more, a sender's
22
+ * frames to the other peers are generations this receiver skips and never claims, so they
23
+ * both fill the window and shorten the backlog it covers (one frame in `members - 1` is
24
+ * this receiver's). Each retained key is one 32-byte secret, about 37 bytes encoded.
25
+ * - `retainKeysForEpochs: 1` — the current epoch's tree and one past epoch's. A backlog
26
+ * sealed before the last commit is rare, and in a group of three or more every retained
27
+ * tree holds a full window per sender at steady state. Measured persisted receiver state
28
+ * at steady state: 2 members 2.6 KB, 3 members 42 KB, 5 members 82 KB, 10 members 181 KB
29
+ * (with ts-mls's four past epochs: 5.8, 103, 202 and 449 KB). That state is persisted on
30
+ * each receive advance, and ts-mls re-sorts a full window on every ratchet step.
31
+ * - `maximumForwardRatchetSteps: 512` — at least the retention, so the single newer frame
32
+ * that jumps past a full backlog still opens rather than being refused as too far ahead.
33
+ * A step is one KDF expansion, so the bound on a forged generation stays cheap.
34
+ */ export const KUMIAI_KEY_RETENTION_CONFIG = Object.freeze({
35
+ retainKeysForGenerations: 256,
36
+ retainKeysForEpochs: 1,
37
+ maximumForwardRatchetSteps: 512
38
+ });
39
+ /** A context's client config, with kumiai's key retention when none is given. */ export function kumiaiClientConfig() {
40
+ return {
41
+ keyRetentionConfig: {
42
+ ...KUMIAI_KEY_RETENTION_CONFIG
43
+ },
44
+ lifetimeConfig: {
45
+ ...defaultLifetimeConfig
46
+ },
47
+ paddingConfig: structuredClone(defaultPaddingConfig),
48
+ keyPackageEqualityConfig: defaultKeyPackageEqualityConfig
49
+ };
50
+ }
51
+ /** Copy a client config without sharing its mutable parts with the source context. */ export function copyClientConfig(config) {
52
+ const equality = config.keyPackageEqualityConfig;
53
+ return {
54
+ keyRetentionConfig: structuredClone(config.keyRetentionConfig),
55
+ lifetimeConfig: structuredClone(config.lifetimeConfig),
56
+ paddingConfig: structuredClone(config.paddingConfig),
57
+ keyPackageEqualityConfig: {
58
+ compareKeyPackages: equality.compareKeyPackages.bind(equality),
59
+ compareKeyPackageToLeafNode: equality.compareKeyPackageToLeafNode.bind(equality)
60
+ }
61
+ };
62
+ }
7
63
  const DENY_HOLDERS = new WeakMap();
8
64
  /** The deny holder for an internally built context, or undefined for others. */ export function deviceDenyHolderFor(context) {
9
65
  return DENY_HOLDERS.get(context);
@@ -26,6 +82,9 @@ const DENY_HOLDERS = new WeakMap();
26
82
  }
27
83
  function authenticationFor(holder) {
28
84
  return createDIDAuthenticationService({
85
+ get crypto () {
86
+ return holder.crypto;
87
+ },
29
88
  deviceDenySet: ()=>holder.provider(),
30
89
  judging: ()=>holder.judging?.() ?? {
31
90
  stage: 'full',
@@ -39,12 +98,13 @@ function authenticationFor(holder) {
39
98
  export async function resolveMlsContext(options, anchor) {
40
99
  const name = options?.ciphersuiteName ?? DEFAULT_CIPHERSUITE;
41
100
  const cipherSuite = await getCiphersuiteImpl(name, options?.cryptoProvider ?? nobleCryptoProvider);
42
- return createMlsContext(cipherSuite, anchor);
101
+ return createMlsContext(cipherSuite, anchor, undefined, options);
43
102
  }
44
- export function createMlsContext(cipherSuite, anchor) {
103
+ export function createMlsContext(cipherSuite, anchor, clientConfig, options) {
45
104
  // The deny set cannot be known here — the handle that folds it does not exist yet. Bind a mutable
46
105
  // holder the auth service reads; the GroupHandle constructor points it at its own currentDenySet().
47
106
  const holder = {
107
+ crypto: options?.crypto,
48
108
  provider: ()=>EMPTY_DENY,
49
109
  leafLifetime: anchor?.controller == null ? undefined : anchor.leafLifetime ?? 86_400,
50
110
  trustedGrantLifetime: anchor?.controller == null ? undefined : anchor.trustedGrantLifetime ?? 2_592_000
@@ -52,7 +112,8 @@ export function createMlsContext(cipherSuite, anchor) {
52
112
  const authService = authenticationFor(holder);
53
113
  const context = {
54
114
  cipherSuite,
55
- authService
115
+ authService,
116
+ clientConfig: clientConfig == null ? kumiaiClientConfig() : copyClientConfig(clientConfig)
56
117
  };
57
118
  DENY_HOLDERS.set(context, holder);
58
119
  return context;
@@ -7,8 +7,12 @@ export type CreateGroupResult = {
7
7
  group: GroupHandle;
8
8
  credential: MemberCredential;
9
9
  };
10
+ export type CreateGroupParams = {
11
+ identity: OwnIdentity;
12
+ groupID: string;
13
+ } & GroupOptions;
10
14
  /** Create a new MLS group. The identity becomes the sole member and admin. */
11
- export declare function createGroup(identity: OwnIdentity, groupID: string, options?: GroupOptions): Promise<CreateGroupResult>;
15
+ export declare function createGroup({ identity, groupID, ...options }: CreateGroupParams): Promise<CreateGroupResult>;
12
16
  export type RestoreGroupParams = {
13
17
  state: ClientState;
14
18
  credential: MemberCredential;
@@ -10,7 +10,7 @@ import { GroupHandle } from './group-handle.js';
10
10
  import { buildLedgerHeadExtension, extendHead, genesisHead } from './head.js';
11
11
  import { ledgerEntryDigest, signLedgerEntry } from './ledger.js';
12
12
  import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
13
- /** Create a new MLS group. The identity becomes the sole member and admin. */ export async function createGroup(identity, groupID, options) {
13
+ /** Create a new MLS group. The identity becomes the sole member and admin. */ export async function createGroup({ identity, groupID, ...options }) {
14
14
  assertBindingAuthorTime(options?.controller);
15
15
  // A binding enriches a supplied anchor before genesis; standard anchor bytes stay untouched.
16
16
  // Existing lifecycle fields must agree with the authored policy before the tree is validated.
@@ -45,7 +45,9 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
45
45
  }
46
46
  }
47
47
  if (suppliedAnchorExtension == null) {
48
- extensions.push(options?.controller == null ? buildCurrentGroupAnchorExtension(identity.id) : buildGroupAnchorExtension({
48
+ extensions.push(options?.controller == null ? buildCurrentGroupAnchorExtension({
49
+ creatorDID: identity.id
50
+ }) : buildGroupAnchorExtension({
49
51
  creatorDID: identity.id,
50
52
  version: 1,
51
53
  controller: options.controller.id,
@@ -66,23 +68,38 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
66
68
  throw new LeafBindingError('controller-mismatch');
67
69
  }
68
70
  if (anchor.controller != null && options?.controllerLog == null) throw new LeafBindingError('member-unavailable');
69
- const registry = anchor.controller == null || options?.controllerLog == null ? undefined : registryForLog(anchor.controller, options.controllerLog);
71
+ const registry = anchor.controller == null || options?.controllerLog == null ? undefined : await registryForLog({
72
+ controller: anchor.controller,
73
+ log: options.controllerLog,
74
+ crypto: options.crypto
75
+ });
70
76
  const tokens = [];
71
77
  if (anchor.controller != null && options?.controllerLog != null) {
72
- tokens.push(await signLedgerEntry(identity, {
73
- type: DEVICE_ENTRY_TYPE,
74
- groupID,
75
- subject: anchor.controller,
76
- value: {
77
- op: 'seed',
78
- proof: pruneLog(anchor.controller, options.controllerLog)
78
+ tokens.push(await signLedgerEntry({
79
+ identity,
80
+ entry: {
81
+ type: DEVICE_ENTRY_TYPE,
82
+ groupID,
83
+ subject: anchor.controller,
84
+ value: {
85
+ op: 'seed',
86
+ proof: await pruneLog({
87
+ crypto: options.crypto,
88
+ did: anchor.controller,
89
+ input: options.controllerLog
90
+ })
91
+ }
79
92
  }
80
93
  }));
81
94
  }
82
95
  const context = await resolveMlsContext(options, anchor);
83
- const mlsCredential = makeMLSCredential(identity, options?.controller);
96
+ const mlsCredential = makeMLSCredential({
97
+ identity,
98
+ controller: options?.controller
99
+ });
84
100
  if (options?.controller != null) {
85
101
  await verifyLeafCredential(mlsCredential, identity.publicKey, {
102
+ crypto: options.crypto,
86
103
  judging: ()=>({
87
104
  registry,
88
105
  stage: 'full',
@@ -92,7 +109,10 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
92
109
  trustedGrantLifetime: ()=>anchor.trustedGrantLifetime ?? 2_592_000
93
110
  });
94
111
  }
95
- const head = buildLedgerHeadExtension(extendHead(genesisHead(groupID), tokens.map(ledgerEntryDigest)));
112
+ const head = buildLedgerHeadExtension(extendHead({
113
+ head: genesisHead(groupID),
114
+ entryIDs: tokens.map(ledgerEntryDigest)
115
+ }));
96
116
  const headIndex = extensions.findIndex((ext)=>ext.extensionType === LEDGER_HEAD_EXTENSION_TYPE);
97
117
  if (tokens.length > 0 && headIndex >= 0) extensions[headIndex] = head;
98
118
  else if (headIndex < 0) extensions.push(head);
@@ -122,7 +142,8 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
122
142
  id: identity.id,
123
143
  groupID
124
144
  };
125
- const group = new GroupHandle({
145
+ const group = await GroupHandle.create({
146
+ crypto: options?.crypto,
126
147
  state,
127
148
  credential,
128
149
  context,
@@ -139,7 +160,8 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
139
160
  export async function restoreGroup(params) {
140
161
  // Construction reseeds control authority from the anchor in the restored state;
141
162
  // an anchorless state throws (the same fail-closed guard).
142
- const group = new GroupHandle({
163
+ const group = await GroupHandle.create({
164
+ crypto: params.options?.crypto,
143
165
  state: params.state,
144
166
  credential: params.credential,
145
167
  context: await resolveMlsContext(params.options),
@@ -2,7 +2,11 @@ import { type OwnIdentity } from '@kokuin/token';
2
2
  import { type Credential } from 'ts-mls';
3
3
  import type { ControllerBinding } from './credential.js';
4
4
  import type { GroupOptions, KeyPackageBundle } from './types.js';
5
- export declare function makeMLSCredential(identity: OwnIdentity, controller?: ControllerBinding): Credential;
5
+ export type MakeMLSCredentialParams = {
6
+ identity: OwnIdentity;
7
+ controller?: ControllerBinding;
8
+ };
9
+ export declare function makeMLSCredential({ identity, controller }: MakeMLSCredentialParams): Credential;
6
10
  export declare function assertBindingAuthorTime(controller?: ControllerBinding): void;
7
11
  /**
8
12
  * How long an ordinary, single-use key package stays valid, in days.
@@ -13,8 +17,11 @@ export declare function assertBindingAuthorTime(controller?: ControllerBinding):
13
17
  * declares, and makes a weekly top-up comfortable rather than marginal.
14
18
  */
15
19
  export declare const ORDINARY_KEY_PACKAGE_LIFETIME_DAYS = 30;
20
+ export type CreateKeyPackageBundleParams = {
21
+ identity: OwnIdentity;
22
+ } & GroupOptions;
16
23
  /** Generate a key package for joining groups. */
17
- export declare function createKeyPackageBundle(identity: OwnIdentity, options?: GroupOptions): Promise<KeyPackageBundle>;
24
+ export declare function createKeyPackageBundle({ identity, ...options }: CreateKeyPackageBundleParams): Promise<KeyPackageBundle>;
18
25
  /**
19
26
  * The `last_resort` KeyPackage extension from draft-ietf-mls-extensions (NOT RFC 9420, which has
20
27
  * no such extension). Its presence marks a key package as reusable by design; its data is empty.
@@ -44,6 +51,9 @@ export declare const LAST_RESORT_EXTENSION_TYPE = 10;
44
51
  * floor disappears exactly when it is needed.
45
52
  */
46
53
  export declare const LAST_RESORT_LIFETIME_DAYS = 90;
54
+ export type CreateLastResortKeyPackageBundleParams = {
55
+ identity: OwnIdentity;
56
+ } & GroupOptions;
47
57
  /**
48
58
  * Generate a reusable last-resort key package for joining groups.
49
59
  *
@@ -61,4 +71,4 @@ export declare const LAST_RESORT_LIFETIME_DAYS = 90;
61
71
  * package stops working while the hub still reports the slot as full and keeps serving it. Both
62
72
  * obligations fail the same way: silently, and precisely when the floor is needed.
63
73
  */
64
- export declare function createLastResortKeyPackageBundle(identity: OwnIdentity, options?: GroupOptions): Promise<KeyPackageBundle>;
74
+ export declare function createLastResortKeyPackageBundle({ identity, ...options }: CreateLastResortKeyPackageBundleParams): Promise<KeyPackageBundle>;
@@ -7,7 +7,7 @@ import { LeafBindingError } from './errors.js';
7
7
  import { resolveMlsContext } from './group-context.js';
8
8
  import { memberRootsOf } from './member-root.js';
9
9
  import { registryForLog } from './registry.js';
10
- export function makeMLSCredential(identity, controller) {
10
+ export function makeMLSCredential({ identity, controller }) {
11
11
  const id = identity.id;
12
12
  const isPeer = isPeer4(id);
13
13
  if (isPeer && !('longForm' in identity && typeof identity.longForm === 'string')) {
@@ -51,12 +51,23 @@ export function assertBindingAuthorTime(controller) {
51
51
  * applies for the ordinary path.
52
52
  */ async function buildBundle(identity, options, overrides = {}) {
53
53
  assertBindingAuthorTime(options?.controller);
54
- const credential = makeMLSCredential(identity, options?.controller);
54
+ const credential = makeMLSCredential({
55
+ identity,
56
+ controller: options?.controller
57
+ });
55
58
  if (options?.controller != null) {
56
- const memberRooted = memberRootsOf(options.controller, identity.id).some(({ root })=>root.kind === 'member');
59
+ const memberRooted = memberRootsOf({
60
+ binding: options.controller,
61
+ leafDID: identity.id
62
+ }).some(({ root })=>root.kind === 'member');
57
63
  if (memberRooted && options.controllerLog == null) throw new LeafBindingError('member-unavailable');
58
- const registry = memberRooted && options.controllerLog != null ? registryForLog(options.controller.id, options.controllerLog) : undefined;
64
+ const registry = memberRooted && options.controllerLog != null ? await registryForLog({
65
+ controller: options.controller.id,
66
+ log: options.controllerLog,
67
+ crypto: options.crypto
68
+ }) : undefined;
59
69
  await verifyLeafCredential(credential, identity.publicKey, {
70
+ crypto: options.crypto,
60
71
  judging: ()=>({
61
72
  registry,
62
73
  stage: 'full',
@@ -101,7 +112,7 @@ export function assertBindingAuthorTime(controller) {
101
112
  notAfter: BigInt(nowSeconds + ORDINARY_KEY_PACKAGE_LIFETIME_DAYS * 86_400)
102
113
  };
103
114
  }
104
- /** Generate a key package for joining groups. */ export async function createKeyPackageBundle(identity, options) {
115
+ /** Generate a key package for joining groups. */ export async function createKeyPackageBundle({ identity, ...options }) {
105
116
  return buildBundle(identity, options, {
106
117
  lifetime: ordinaryLifetime()
107
118
  });
@@ -156,7 +167,7 @@ export function assertBindingAuthorTime(controller) {
156
167
  * carries an MLS lifetime, and an inviter validates it when building the Add — so an unrotated
157
168
  * package stops working while the hub still reports the slot as full and keeps serving it. Both
158
169
  * obligations fail the same way: silently, and precisely when the floor is needed.
159
- */ export async function createLastResortKeyPackageBundle(identity, options) {
170
+ */ export async function createLastResortKeyPackageBundle({ identity, ...options }) {
160
171
  return buildBundle(identity, options, {
161
172
  // Supplying `extensions` at all suppresses ts-mls's own default of
162
173
  // `greaseExtensions(defaultGreaseConfig)`. `defaultGreaseConfig` is not exported, so its 0.1
@@ -8,40 +8,51 @@ export type DeviceWriteResult = {
8
8
  /** Post-commit epoch (== newGroup.epoch). */
9
9
  epoch: bigint;
10
10
  };
11
+ type GroupSigner = {
12
+ group: GroupHandle;
13
+ identity: SigningIdentity;
14
+ };
15
+ export type RegisterDeviceParams = GroupSigner & {
16
+ device: string;
17
+ controller: string;
18
+ capability?: string;
19
+ };
11
20
  /**
12
21
  * Record a `device -> controller` binding: self-attested (leaf) when `device` is the caller's own,
13
22
  * or management-capability-authorized (`capability`) when recording a co-device already in the
14
23
  * group. Proof gating runs in `commitWithEntries` (authoring side) and every receiver's pipeline —
15
24
  * no admin role is required. Returns the commit bytes to broadcast.
16
25
  */
17
- export declare function registerDevice(group: GroupHandle, identity: SigningIdentity, params: {
26
+ export declare function registerDevice({ group, identity, ...params }: RegisterDeviceParams): Promise<DeviceWriteResult>;
27
+ export type LabelDeviceParams = GroupSigner & {
18
28
  device: string;
19
- controller: string;
20
- capability?: string;
21
- }): Promise<DeviceWriteResult>;
29
+ label: string;
30
+ capability: string;
31
+ };
22
32
  /**
23
33
  * Rename a device already bound in the registry. A manage op — authorized by the profile's
24
34
  * management capability (the issuer is a device of `controllerOf(device)`); no admin role required.
25
35
  */
26
- export declare function labelDevice(group: GroupHandle, identity: SigningIdentity, params: {
36
+ export declare function labelDevice({ group, identity, ...params }: LabelDeviceParams): Promise<DeviceWriteResult>;
37
+ export type AddDeviceParams = GroupSigner & {
38
+ keyPackage: KeyPackage;
27
39
  device: string;
28
- label: string;
40
+ controller: string;
29
41
  capability: string;
30
- }): Promise<DeviceWriteResult>;
42
+ };
31
43
  /**
32
44
  * Bring a co-device into the group WITHOUT a group admin: an MLS Add of the new device's key
33
45
  * package plus a `kumiai.device` `add` entry, both authorized by the profile's management
34
46
  * capability. Binds the added leaf to `device`/`controller` (the key package must present `device`).
35
47
  * Returns the Commit + Welcome bytes.
36
48
  */
37
- export declare function addDevice(group: GroupHandle, identity: SigningIdentity, params: {
38
- keyPackage: KeyPackage;
39
- device: string;
40
- controller: string;
41
- capability: string;
42
- }): Promise<DeviceWriteResult & {
49
+ export declare function addDevice({ group, identity, ...params }: AddDeviceParams): Promise<DeviceWriteResult & {
43
50
  welcomeMessage: Uint8Array;
44
51
  }>;
52
+ export type RevokeDeviceParams = GroupSigner & {
53
+ device: string;
54
+ capability: string;
55
+ };
45
56
  /**
46
57
  * Revoke a device: ONE commit, TWO effects, matching the two surfaces the kokuin security doc
47
58
  * sanctions. (1) a `kumiai.device` `revoke` entry — folds the subject to `revoked`, so the derived
@@ -50,18 +61,17 @@ export declare function addDevice(group: GroupHandle, identity: SigningIdentity,
50
61
  * stale leaf; the Remove alone lets it rejoin on its still-valid bound-leaf capability). Both are
51
62
  * required. Authorized by the profile's management capability; no admin role.
52
63
  */
53
- export declare function revokeDevice(group: GroupHandle, identity: SigningIdentity, params: {
54
- device: string;
55
- capability: string;
56
- }): Promise<DeviceWriteResult>;
64
+ export declare function revokeDevice({ group, identity, ...params }: RevokeDeviceParams): Promise<DeviceWriteResult>;
65
+ export type AnnounceControllerBeaconParams = GroupSigner & {
66
+ controller: string;
67
+ logLength: number;
68
+ headDigest: string;
69
+ };
57
70
  /**
58
71
  * Announce the controller's FULL log head into the group as folded, cross-peer-consistent state.
59
72
  * Advisory only — it gates nothing. Authored by any bound device of `controller` (self-scoped, no
60
73
  * management capability). Publish only-on-change and only when the log meaningfully advances: each
61
74
  * call is a permanent ledger entry (replayed at every welcome, no compaction).
62
75
  */
63
- export declare function announceControllerBeacon(group: GroupHandle, identity: SigningIdentity, params: {
64
- controller: string;
65
- logLength: number;
66
- headDigest: string;
67
- }): Promise<DeviceWriteResult>;
76
+ export declare function announceControllerBeacon({ group, identity, ...params }: AnnounceControllerBeaconParams): Promise<DeviceWriteResult>;
77
+ export {};
@@ -10,18 +10,21 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
10
10
  * or management-capability-authorized (`capability`) when recording a co-device already in the
11
11
  * group. Proof gating runs in `commitWithEntries` (authoring side) and every receiver's pipeline —
12
12
  * no admin role is required. Returns the commit bytes to broadcast.
13
- */ export async function registerDevice(group, identity, params) {
13
+ */ export async function registerDevice({ group, identity, ...params }) {
14
14
  return mutexFor(group).run(async ()=>{
15
- const token = await signLedgerEntry(identity, {
16
- type: DEVICE_ENTRY_TYPE,
17
- groupID: group.groupID,
18
- subject: params.device,
19
- value: {
20
- op: 'register',
21
- controller: params.controller,
22
- ...params.capability != null ? {
23
- capability: params.capability
24
- } : {}
15
+ const token = await signLedgerEntry({
16
+ identity,
17
+ entry: {
18
+ type: DEVICE_ENTRY_TYPE,
19
+ groupID: group.groupID,
20
+ subject: params.device,
21
+ value: {
22
+ op: 'register',
23
+ controller: params.controller,
24
+ ...params.capability != null ? {
25
+ capability: params.capability
26
+ } : {}
27
+ }
25
28
  }
26
29
  });
27
30
  const result = await commitWithEntries({
@@ -32,7 +35,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
32
35
  ],
33
36
  requireAdmin: false
34
37
  });
35
- const newGroup = deriveGroup(group, result.newState);
38
+ const newGroup = await deriveGroup(group, result.newState);
36
39
  await newGroup.applyLedgerEntries(result.enacted);
37
40
  return {
38
41
  commitMessage: encode(mlsMessageEncoder, result.commit),
@@ -44,16 +47,19 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
44
47
  /**
45
48
  * Rename a device already bound in the registry. A manage op — authorized by the profile's
46
49
  * management capability (the issuer is a device of `controllerOf(device)`); no admin role required.
47
- */ export async function labelDevice(group, identity, params) {
50
+ */ export async function labelDevice({ group, identity, ...params }) {
48
51
  return mutexFor(group).run(async ()=>{
49
- const token = await signLedgerEntry(identity, {
50
- type: DEVICE_ENTRY_TYPE,
51
- groupID: group.groupID,
52
- subject: params.device,
53
- value: {
54
- op: 'label',
55
- label: params.label,
56
- capability: params.capability
52
+ const token = await signLedgerEntry({
53
+ identity,
54
+ entry: {
55
+ type: DEVICE_ENTRY_TYPE,
56
+ groupID: group.groupID,
57
+ subject: params.device,
58
+ value: {
59
+ op: 'label',
60
+ label: params.label,
61
+ capability: params.capability
62
+ }
57
63
  }
58
64
  });
59
65
  const result = await commitWithEntries({
@@ -64,7 +70,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
64
70
  ],
65
71
  requireAdmin: false
66
72
  });
67
- const newGroup = deriveGroup(group, result.newState);
73
+ const newGroup = await deriveGroup(group, result.newState);
68
74
  await newGroup.applyLedgerEntries(result.enacted);
69
75
  return {
70
76
  commitMessage: encode(mlsMessageEncoder, result.commit),
@@ -78,7 +84,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
78
84
  * package plus a `kumiai.device` `add` entry, both authorized by the profile's management
79
85
  * capability. Binds the added leaf to `device`/`controller` (the key package must present `device`).
80
86
  * Returns the Commit + Welcome bytes.
81
- */ export async function addDevice(group, identity, params) {
87
+ */ export async function addDevice({ group, identity, ...params }) {
82
88
  return mutexFor(group).run(async ()=>{
83
89
  // Bind the added leaf to the entry's subject — the key package must present `device`.
84
90
  const credential = params.keyPackage.leafNode.credential;
@@ -89,14 +95,17 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
89
95
  if (presentedDID !== normalizeDID(params.device)) {
90
96
  throw new Error(`addDevice: the key package presents ${presentedDID}, not the device ${normalizeDID(params.device)}`);
91
97
  }
92
- const token = await signLedgerEntry(identity, {
93
- type: DEVICE_ENTRY_TYPE,
94
- groupID: group.groupID,
95
- subject: params.device,
96
- value: {
97
- op: 'add',
98
- controller: params.controller,
99
- capability: params.capability
98
+ const token = await signLedgerEntry({
99
+ identity,
100
+ entry: {
101
+ type: DEVICE_ENTRY_TYPE,
102
+ groupID: group.groupID,
103
+ subject: params.device,
104
+ value: {
105
+ op: 'add',
106
+ controller: params.controller,
107
+ capability: params.capability
108
+ }
100
109
  }
101
110
  });
102
111
  const addProposal = {
@@ -119,7 +128,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
119
128
  if (result.welcome == null) {
120
129
  throw new Error('addDevice: expected a Welcome message for the add proposal');
121
130
  }
122
- const newGroup = deriveGroup(group, result.newState);
131
+ const newGroup = await deriveGroup(group, result.newState);
123
132
  await newGroup.applyLedgerEntries(result.enacted);
124
133
  return {
125
134
  commitMessage: encode(mlsMessageEncoder, result.commit),
@@ -136,15 +145,18 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
136
145
  * subject currently holds a leaf, an MLS Remove of it in the SAME commit (the deny set alone leaves a
137
146
  * stale leaf; the Remove alone lets it rejoin on its still-valid bound-leaf capability). Both are
138
147
  * required. Authorized by the profile's management capability; no admin role.
139
- */ export async function revokeDevice(group, identity, params) {
148
+ */ export async function revokeDevice({ group, identity, ...params }) {
140
149
  return mutexFor(group).run(async ()=>{
141
- const token = await signLedgerEntry(identity, {
142
- type: DEVICE_ENTRY_TYPE,
143
- groupID: group.groupID,
144
- subject: params.device,
145
- value: {
146
- op: 'revoke',
147
- capability: params.capability
150
+ const token = await signLedgerEntry({
151
+ identity,
152
+ entry: {
153
+ type: DEVICE_ENTRY_TYPE,
154
+ groupID: group.groupID,
155
+ subject: params.device,
156
+ value: {
157
+ op: 'revoke',
158
+ capability: params.capability
159
+ }
148
160
  }
149
161
  });
150
162
  const leafIndex = group.findMemberLeafIndex(params.device);
@@ -164,7 +176,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
164
176
  ],
165
177
  requireAdmin: false
166
178
  });
167
- const newGroup = deriveGroup(group, result.newState);
179
+ const newGroup = await deriveGroup(group, result.newState);
168
180
  await newGroup.applyLedgerEntries(result.enacted);
169
181
  return {
170
182
  commitMessage: encode(mlsMessageEncoder, result.commit),
@@ -178,16 +190,19 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
178
190
  * Advisory only — it gates nothing. Authored by any bound device of `controller` (self-scoped, no
179
191
  * management capability). Publish only-on-change and only when the log meaningfully advances: each
180
192
  * call is a permanent ledger entry (replayed at every welcome, no compaction).
181
- */ export async function announceControllerBeacon(group, identity, params) {
193
+ */ export async function announceControllerBeacon({ group, identity, ...params }) {
182
194
  return mutexFor(group).run(async ()=>{
183
- const token = await signLedgerEntry(identity, {
184
- type: DEVICE_ENTRY_TYPE,
185
- groupID: group.groupID,
186
- subject: params.controller,
187
- value: {
188
- op: 'beacon',
189
- logLength: params.logLength,
190
- headDigest: params.headDigest
195
+ const token = await signLedgerEntry({
196
+ identity,
197
+ entry: {
198
+ type: DEVICE_ENTRY_TYPE,
199
+ groupID: group.groupID,
200
+ subject: params.controller,
201
+ value: {
202
+ op: 'beacon',
203
+ logLength: params.logLength,
204
+ headDigest: params.headDigest
205
+ }
191
206
  }
192
207
  });
193
208
  const result = await commitWithEntries({
@@ -198,7 +213,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
198
213
  ],
199
214
  requireAdmin: false
200
215
  });
201
- const newGroup = deriveGroup(group, result.newState);
216
+ const newGroup = await deriveGroup(group, result.newState);
202
217
  await newGroup.applyLedgerEntries(result.enacted);
203
218
  return {
204
219
  commitMessage: encode(mlsMessageEncoder, result.commit),