@kumiai/mls 0.5.0 → 0.6.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.
@@ -1,4 +1,3 @@
1
- import { type DIDCache } from '@kokuin/token';
2
1
  import { type Credential } from 'ts-mls';
3
2
  /**
4
3
  * Local member state (never serialized to the MLS leaf). `id` is the member's own
@@ -32,14 +31,19 @@ export type GroupMember = {
32
31
  leafIndex: number;
33
32
  /** DID parsed from the leaf's MLS credential identity. */
34
33
  id: string;
34
+ /**
35
+ * The resolvable form of `id`: the leaf's `longForm` for did:peer:4, and `id` itself for
36
+ * did:key, where long form and short form are the same string. Never absent.
37
+ *
38
+ * This is why `@kumiai/mls` holds no DID cache. Every document a consumer can reach is
39
+ * already inside a signed artifact — a current member's in this leaf, which is signed and
40
+ * can never be rewritten, and a ledger author's in their own token, which `signLedgerEntry`
41
+ * gives `{ embedLongForm: true }` for exactly that reason. A cache alongside those would be
42
+ * an unsigned second copy of authenticated state.
43
+ */
44
+ longForm: string;
35
45
  };
36
46
  export declare function parseMLSCredentialIdentity(identity: Uint8Array): MLSCredentialIdentity;
37
- /**
38
- * If the parsed credential carries a did:peer:4 long form, decode it and write
39
- * to the cache. Hash binding is enforced (decoded short form must equal `id`).
40
- * No-op for did:key.
41
- */
42
- export declare function populateCacheFromCredential(parsed: MLSCredentialIdentity, cache: DIDCache): Promise<void>;
43
47
  /**
44
48
  * The normalized DID an MLS leaf credential names, or `undefined` when it names none.
45
49
  *
package/lib/credential.js CHANGED
@@ -1,4 +1,4 @@
1
- import { decodePeer4, isPeer4, normalizeDID } from '@kokuin/token';
1
+ import { normalizeDID } from '@kokuin/token';
2
2
  import { defaultCredentialTypes, isDefaultCredential } from 'ts-mls';
3
3
  export function parseMLSCredentialIdentity(identity) {
4
4
  const text = new TextDecoder().decode(identity);
@@ -37,19 +37,6 @@ export function parseMLSCredentialIdentity(identity) {
37
37
  }
38
38
  return result;
39
39
  }
40
- /**
41
- * If the parsed credential carries a did:peer:4 long form, decode it and write
42
- * to the cache. Hash binding is enforced (decoded short form must equal `id`).
43
- * No-op for did:key.
44
- */ export async function populateCacheFromCredential(parsed, cache) {
45
- if (parsed.longForm == null) return;
46
- if (!isPeer4(parsed.id)) return;
47
- const { shortForm, doc } = decodePeer4(parsed.longForm);
48
- if (shortForm !== parsed.id) {
49
- throw new Error('Credential longForm does not match credential.id');
50
- }
51
- await cache.set(shortForm, doc);
52
- }
53
40
  /**
54
41
  * The normalized DID an MLS leaf credential names, or `undefined` when it names none.
55
42
  *
@@ -1,4 +1,4 @@
1
- import { createInMemoryDIDCache, normalizeDID } from '@kokuin/token';
1
+ import { normalizeDID } from '@kokuin/token';
2
2
  import { generateKeyPackageWithKey, createGroup as mlsCreateGroup } from 'ts-mls';
3
3
  import { buildCurrentGroupAnchorExtension, decodeGroupAnchor, GROUP_ANCHOR_EXTENSION_TYPE, LEDGER_HEAD_EXTENSION_TYPE } from './anchor.js';
4
4
  import { buildLeafCapabilities, resolveMlsContext } from './group-context.js';
@@ -6,7 +6,6 @@ import { makeMLSCredential } from './group-credential.js';
6
6
  import { GroupHandle } from './group-handle.js';
7
7
  import { buildLedgerHeadExtension, genesisHead } from './head.js';
8
8
  /** Create a new MLS group. The identity becomes the sole member and admin. */ export async function createGroup(identity, groupID, options) {
9
- const cache = options?.cache ?? createInMemoryDIDCache();
10
9
  const context = await resolveMlsContext(options);
11
10
  // Every group is anchored at creation: creator is the epoch-0 admin, ledger head
12
11
  // starts at genesis. A caller-supplied anchor is left untouched (the caller owns
@@ -55,8 +54,6 @@ import { buildLedgerHeadExtension, genesisHead } from './head.js';
55
54
  state,
56
55
  credential,
57
56
  context,
58
- cache,
59
- resolver: options?.resolver,
60
57
  commitPolicy: options?.commitPolicy,
61
58
  resolveLedgerEntries: options?.resolveLedgerEntries,
62
59
  onLedgerEntries: options?.onLedgerEntries
@@ -67,15 +64,12 @@ import { buildLedgerHeadExtension, genesisHead } from './head.js';
67
64
  };
68
65
  }
69
66
  export async function restoreGroup(params) {
70
- const cache = params.options?.cache ?? createInMemoryDIDCache();
71
67
  // Construction reseeds `{creator: 'admin'}` from the anchor in the restored state;
72
68
  // an anchorless state throws (the same fail-closed guard).
73
69
  const group = new GroupHandle({
74
70
  state: params.state,
75
71
  credential: params.credential,
76
72
  context: await resolveMlsContext(params.options),
77
- cache,
78
- resolver: params.options?.resolver,
79
73
  commitPolicy: params.options?.commitPolicy,
80
74
  resolveLedgerEntries: params.options?.resolveLedgerEntries,
81
75
  onLedgerEntries: params.options?.onLedgerEntries
@@ -1,4 +1,3 @@
1
- import { type DIDCache, type DIDResolver } from '@kokuin/token';
2
1
  import { type ClientState, type IncomingMessageCallback, type MlsContext, type ProposalWithSender } from 'ts-mls';
3
2
  import { type GroupAnchor } from './anchor.js';
4
3
  import { type GroupMember, type MemberCredential } from './credential.js';
@@ -37,8 +36,6 @@ export type GroupHandleParams = {
37
36
  * derived from another (commitInvite/removeMember) inherits the parent's, so the
38
37
  * roster it folds does not revert to the anchor alone. */
39
38
  ledger?: ReadonlyArray<LedgerLogEntry>;
40
- cache: DIDCache;
41
- resolver?: DIDResolver;
42
39
  /** Default commit policy applied by processMessage. */
43
40
  commitPolicy?: IncomingMessageCallback;
44
41
  /** Fetch control-ledger entry bodies the local ledger lacks (commit pre-pass). */
@@ -56,8 +53,6 @@ export declare class GroupHandle {
56
53
  get credential(): MemberCredential;
57
54
  get state(): ClientState;
58
55
  get context(): MlsContext;
59
- get cache(): DIDCache;
60
- get resolver(): DIDResolver | undefined;
61
56
  /** The commit policy enforced by processMessage, if any. Carried onto
62
57
  * handles derived from this one (commitInvite/removeMember). */
63
58
  get commitPolicy(): IncomingMessageCallback | undefined;
@@ -138,6 +133,15 @@ export declare class GroupHandle {
138
133
  bootstrapLedger(tokens: Array<string>): Promise<void>;
139
134
  get memberCount(): number;
140
135
  findMemberLeafIndex(id: string): number | undefined;
136
+ /**
137
+ * The resolvable form of a member's DID — the string to hand a DID resolver or a JWE
138
+ * recipient — or `undefined` when the group has no such member. `undefined` carries that one
139
+ * meaning: every member has a long form.
140
+ *
141
+ * Accepts either form of `id`, normalizing both sides exactly as {@link findMemberLeafIndex}
142
+ * does, so a caller holding a long form read off another leaf need not truncate it first.
143
+ */
144
+ findMemberLongForm(id: string): string | undefined;
141
145
  /**
142
146
  * The group's current members from the ratchet tree, in ascending leaf-index
143
147
  * order. Leaves whose credential identity fails to parse are skipped (like
@@ -158,8 +158,6 @@ export function mutexFor(handle) {
158
158
  #state;
159
159
  #credential;
160
160
  #context;
161
- #cache;
162
- #resolver;
163
161
  #commitPolicy;
164
162
  #resolveLedgerEntries;
165
163
  #onLedgerEntries;
@@ -174,8 +172,6 @@ export function mutexFor(handle) {
174
172
  this.#state = params.state;
175
173
  this.#credential = params.credential;
176
174
  this.#context = params.context;
177
- this.#cache = params.cache;
178
- this.#resolver = params.resolver;
179
175
  this.#commitPolicy = params.commitPolicy;
180
176
  this.#resolveLedgerEntries = params.resolveLedgerEntries;
181
177
  this.#onLedgerEntries = params.onLedgerEntries;
@@ -217,12 +213,6 @@ export function mutexFor(handle) {
217
213
  get context() {
218
214
  return this.#context;
219
215
  }
220
- get cache() {
221
- return this.#cache;
222
- }
223
- get resolver() {
224
- return this.#resolver;
225
- }
226
216
  /** The commit policy enforced by processMessage, if any. Carried onto
227
217
  * handles derived from this one (commitInvite/removeMember). */ get commitPolicy() {
228
218
  return this.#commitPolicy;
@@ -398,9 +388,15 @@ export function mutexFor(handle) {
398
388
  } catch {
399
389
  continue;
400
390
  }
391
+ // `?? parsed.id` is the did:key case, where long form IS the id. It is unreachable
392
+ // for peer:4 for any leaf that entered through an add or a join: makeMLSCredential
393
+ // refuses to build a peer:4 identity without a long form, and validateCredential
394
+ // rejects any peer:4 leaf lacking one before it can enter a ratchet tree. restore
395
+ // trusts the host's own persisted state, so neither gate runs on that path.
401
396
  yield {
402
397
  leafIndex: i / 2,
403
- id: parsed.id
398
+ id: parsed.id,
399
+ longForm: parsed.longForm ?? parsed.id
404
400
  };
405
401
  }
406
402
  }
@@ -414,6 +410,20 @@ export function mutexFor(handle) {
414
410
  return undefined;
415
411
  }
416
412
  /**
413
+ * The resolvable form of a member's DID — the string to hand a DID resolver or a JWE
414
+ * recipient — or `undefined` when the group has no such member. `undefined` carries that one
415
+ * meaning: every member has a long form.
416
+ *
417
+ * Accepts either form of `id`, normalizing both sides exactly as {@link findMemberLeafIndex}
418
+ * does, so a caller holding a long form read off another leaf need not truncate it first.
419
+ */ findMemberLongForm(id) {
420
+ const targetNorm = normalizeDID(id);
421
+ for (const member of this.#iterateMembers()){
422
+ if (normalizeDID(member.id) === targetNorm) return member.longForm;
423
+ }
424
+ return undefined;
425
+ }
426
+ /**
417
427
  * The group's current members from the ratchet tree, in ascending leaf-index
418
428
  * order. Leaves whose credential identity fails to parse are skipped (like
419
429
  * findMemberLeafIndex). Reflects current #state — call before and after
@@ -887,8 +897,6 @@ export function mutexFor(handle) {
887
897
  credential: group.credential,
888
898
  context: group.context,
889
899
  ledger: group.ledger,
890
- cache: group.cache,
891
- resolver: group.resolver,
892
900
  commitPolicy: group.commitPolicy,
893
901
  resolveLedgerEntries: group.resolveLedgerEntries,
894
902
  onLedgerEntries: group.onLedgerEntries
@@ -1,4 +1,4 @@
1
- import { createInMemoryDIDCache, normalizeDID } from '@kokuin/token';
1
+ import { normalizeDID } from '@kokuin/token';
2
2
  import { decode, encode, generateKeyPackageWithKey, joinGroup as mlsJoinGroup, joinGroupExternal as mlsJoinGroupExternal, mlsMessageDecoder, mlsMessageEncoder, protocolVersions, wireformats } from 'ts-mls';
3
3
  import { sanitizeRatchetTree } from './codec.js';
4
4
  import { buildLeafCapabilities, resolveMlsContext } from './group-context.js';
@@ -9,7 +9,6 @@ import { ledgerEntryDigest, verifyLedgerEntry } from './ledger.js';
9
9
  import { ROLE_ENTRY_TYPE } from './roster.js';
10
10
  export async function processWelcome(params) {
11
11
  const { identity, invite, welcome, keyPackageBundle, ratchetTree, options } = params;
12
- const cache = options?.cache ?? createInMemoryDIDCache();
13
12
  const context = await resolveMlsContext(options);
14
13
  // A Welcome is only this member's when the invite carries a role entry naming
15
14
  // them: an invite minted for someone else is not an invitation to join.
@@ -51,8 +50,6 @@ export async function processWelcome(params) {
51
50
  state,
52
51
  credential,
53
52
  context,
54
- cache,
55
- resolver: options?.resolver,
56
53
  commitPolicy: options?.commitPolicy,
57
54
  resolveLedgerEntries: options?.resolveLedgerEntries,
58
55
  onLedgerEntries: options?.onLedgerEntries
@@ -113,7 +110,6 @@ export async function joinGroupExternal(params) {
113
110
  if (normalizeDID(identity.id) !== normalizeDID(credential.id)) {
114
111
  throw new Error(`joinGroupExternal: identity.id (${identity.id}) must match credential.id (${credential.id}) for resync`);
115
112
  }
116
- const cache = options?.cache ?? createInMemoryDIDCache();
117
113
  const context = await resolveMlsContext(options);
118
114
  const message = decode(mlsMessageDecoder, groupInfoBytes);
119
115
  if (message == null) {
@@ -163,8 +159,6 @@ export async function joinGroupExternal(params) {
163
159
  state: newState,
164
160
  credential,
165
161
  context,
166
- cache,
167
- resolver: options?.resolver,
168
162
  commitPolicy: options?.commitPolicy,
169
163
  resolveLedgerEntries: options?.resolveLedgerEntries,
170
164
  onLedgerEntries: options?.onLedgerEntries
package/lib/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { defaultCapabilities, defaultProposalTypes, makeCustomExtension } from '
3
3
  export { buildCurrentGroupAnchorExtension, buildGroupAnchorExtension, controlCapabilities, decodeGroupAnchor, encodeGroupAnchor, GROUP_ANCHOR_EXTENSION_TYPE, type GroupAnchor, LEDGER_HEAD_EXTENSION_TYPE, readGroupAnchor, readGroupAnchorExtension, } from './anchor.js';
4
4
  export { createDIDAuthenticationService } from './authentication.js';
5
5
  export { type ClientState, decodeClientState, encodeClientState, sanitizeRatchetTree, } from './codec.js';
6
- export { type GroupMember, type MemberCredential, type MLSCredentialIdentity, parseMLSCredentialIdentity, populateCacheFromCredential, } from './credential.js';
6
+ export { type GroupMember, type MemberCredential, type MLSCredentialIdentity, parseMLSCredentialIdentity, } from './credential.js';
7
7
  export { createNobleCryptoProvider, type NobleCryptoProviderOptions, nobleCryptoProvider, } from './crypto.js';
8
8
  export { CONTROL_ENVELOPE_VERSION, type ControlEnvelope, type DecodeResult, decodeControlEnvelope, encodeControlEnvelope, } from './envelope.js';
9
9
  export { type EnvelopeFoldResult, foldEnvelope } from './envelope-fold.js';
package/lib/index.js CHANGED
@@ -2,7 +2,7 @@ export { defaultCapabilities, defaultProposalTypes, makeCustomExtension } from '
2
2
  export { buildCurrentGroupAnchorExtension, buildGroupAnchorExtension, controlCapabilities, decodeGroupAnchor, encodeGroupAnchor, GROUP_ANCHOR_EXTENSION_TYPE, LEDGER_HEAD_EXTENSION_TYPE, readGroupAnchor, readGroupAnchorExtension } from './anchor.js';
3
3
  export { createDIDAuthenticationService } from './authentication.js';
4
4
  export { decodeClientState, encodeClientState, sanitizeRatchetTree } from './codec.js';
5
- export { parseMLSCredentialIdentity, populateCacheFromCredential } from './credential.js';
5
+ export { parseMLSCredentialIdentity } from './credential.js';
6
6
  export { createNobleCryptoProvider, nobleCryptoProvider } from './crypto.js';
7
7
  export { CONTROL_ENVELOPE_VERSION, decodeControlEnvelope, encodeControlEnvelope } from './envelope.js';
8
8
  export { foldEnvelope } from './envelope-fold.js';
package/lib/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { DIDCache, DIDResolver } from '@kokuin/token';
2
1
  import type { Capabilities, CryptoProvider, GroupContextExtension, IncomingMessageCallback, KeyPackage, PrivateKeyPackage } from 'ts-mls';
3
2
  import type { VerifiedLedgerEntry } from './ledger.js';
4
3
  export type GroupOptions = {
@@ -44,10 +43,6 @@ export type GroupOptions = {
44
43
  * into the roster, everything else is handed to the consumer here.
45
44
  */
46
45
  onLedgerEntries?: (entries: Array<VerifiedLedgerEntry>) => void;
47
- /** Optional DID cache for resolving did:peer:4 issuers when verifying ledger entries. Default: in-memory. */
48
- cache?: DIDCache;
49
- /** Optional resolver for did:peer:4 short forms not in cache. */
50
- resolver?: DIDResolver;
51
46
  };
52
47
  export type Invite = {
53
48
  /** Group ID the invite is for */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/mls",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "E2EE group identity and membership for Enkaku using MLS",
5
5
  "keywords": [
6
6
  "mls",
@@ -25,11 +25,11 @@
25
25
  "lib/*"
26
26
  ],
27
27
  "dependencies": {
28
- "@kokuin/token": "^0.3.0",
28
+ "@kokuin/token": "^0.4.0",
29
29
  "@noble/ciphers": "^2.1.1",
30
- "@noble/curves": "^2.0.1",
31
- "@noble/hashes": "^2.2.0",
32
- "@sozai/codec": "^0.3.0",
30
+ "@noble/curves": "^2.3.0",
31
+ "@noble/hashes": "^2.3.0",
32
+ "@sozai/codec": "^0.4.0",
33
33
  "@sozai/runtime": "^0.1.0",
34
34
  "ts-mls": "2.0.0-rc.13"
35
35
  },