@kumiai/mls 0.10.0 → 0.10.2
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 +10 -4
- package/lib/anchor.js +26 -2
- package/lib/authentication.d.ts +24 -12
- package/lib/authentication.js +192 -83
- package/lib/capability.d.ts +37 -0
- package/lib/capability.js +141 -0
- package/lib/credential.d.ts +7 -7
- package/lib/credential.js +15 -10
- package/lib/device-proof.d.ts +2 -0
- package/lib/device-proof.js +8 -12
- package/lib/envelope-fold.d.ts +16 -1
- package/lib/envelope-fold.js +49 -9
- package/lib/errors.d.ts +18 -0
- package/lib/errors.js +33 -0
- package/lib/group-commit.d.ts +24 -35
- package/lib/group-commit.js +139 -110
- package/lib/group-context.d.ts +6 -2
- package/lib/group-context.js +11 -4
- package/lib/group-create.js +56 -11
- package/lib/group-credential.d.ts +3 -1
- package/lib/group-credential.js +17 -3
- package/lib/group-device.js +34 -21
- package/lib/group-handle.d.ts +31 -8
- package/lib/group-handle.js +275 -58
- package/lib/group-lifecycle.d.ts +49 -0
- package/lib/group-lifecycle.js +341 -0
- package/lib/group-membership.js +7 -3
- package/lib/group-welcome.d.ts +11 -2
- package/lib/group-welcome.js +122 -22
- package/lib/group.d.ts +2 -1
- package/lib/group.js +1 -0
- package/lib/history.d.ts +6 -0
- package/lib/history.js +26 -0
- package/lib/index.d.ts +12 -5
- package/lib/index.js +10 -3
- package/lib/lifecycle-proof.d.ts +33 -0
- package/lib/lifecycle-proof.js +218 -0
- package/lib/lifecycle.d.ts +46 -0
- package/lib/lifecycle.js +410 -0
- package/lib/policy.d.ts +20 -0
- package/lib/policy.js +8 -5
- package/lib/recovery-verdict.d.ts +43 -0
- package/lib/recovery-verdict.js +135 -0
- package/lib/recovery.d.ts +70 -0
- package/lib/recovery.js +110 -36
- package/lib/registry.d.ts +34 -7
- package/lib/registry.js +113 -15
- package/lib/roster.d.ts +1 -1
- package/lib/roster.js +2 -2
- package/lib/secret-tree.d.ts +3 -0
- package/lib/secret-tree.js +60 -0
- package/lib/types.d.ts +13 -8
- package/package.json +5 -5
package/lib/roster.js
CHANGED
|
@@ -12,7 +12,7 @@ import { foldLedger } from './fold.js';
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Self-referential role reducer. Authority is rooted at the genesis anchor (the
|
|
15
|
-
* creator is the epoch-0 admin) and grows only through admins-so-far: every
|
|
15
|
+
* controller or creator is the epoch-0 admin) and grows only through admins-so-far: every
|
|
16
16
|
* grant or demotion must be issued by a DID already an admin in the state
|
|
17
17
|
* accumulated from strictly-earlier entries. That state-so-far check is what
|
|
18
18
|
* makes rotation sound — an admin can demote the very admin that promoted them
|
|
@@ -26,7 +26,7 @@ import { foldLedger } from './fold.js';
|
|
|
26
26
|
seed: (anchor)=>({
|
|
27
27
|
roles: new Map([
|
|
28
28
|
[
|
|
29
|
-
normalizeDID(anchor.creatorDID),
|
|
29
|
+
normalizeDID(anchor.controller ?? anchor.creatorDID),
|
|
30
30
|
'admin'
|
|
31
31
|
]
|
|
32
32
|
])
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Combine two same-epoch ratchets, retaining a skipped key only if neither side spent it. */ function mergeGenerationSecrets(a, b) {
|
|
2
|
+
const [ahead, behind] = a.generation >= b.generation ? [
|
|
3
|
+
a,
|
|
4
|
+
b
|
|
5
|
+
] : [
|
|
6
|
+
b,
|
|
7
|
+
a
|
|
8
|
+
];
|
|
9
|
+
const unusedGenerations = {};
|
|
10
|
+
for (const [generationText, secret] of Object.entries(ahead.unusedGenerations)){
|
|
11
|
+
const generation = Number(generationText);
|
|
12
|
+
if (generation >= behind.generation || Object.hasOwn(behind.unusedGenerations, generation)) {
|
|
13
|
+
unusedGenerations[generation] = secret;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
...ahead,
|
|
18
|
+
unusedGenerations
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Merge same-epoch trees without mutating inputs. The result takes `leafWidth` from `target`. */ export function mergeReceiveSecretTree(target, source) {
|
|
22
|
+
// Each side can expand a different part of the tree. Keep the most-expanded
|
|
23
|
+
// representation of every branch: an ancestor secret must disappear when
|
|
24
|
+
// either side has derived a descendant, or it could derive spent keys again.
|
|
25
|
+
// The descendants include sibling intermediate secrets needed for members
|
|
26
|
+
// who have not sent yet; simply intersecting node maps loses those keys.
|
|
27
|
+
const intermediateNodes = {
|
|
28
|
+
...target.intermediateNodes,
|
|
29
|
+
...source.intermediateNodes
|
|
30
|
+
};
|
|
31
|
+
const leafNodes = {
|
|
32
|
+
...target.leafNodes
|
|
33
|
+
};
|
|
34
|
+
for (const [indexText, node] of Object.entries(source.leafNodes)){
|
|
35
|
+
const index = Number(indexText);
|
|
36
|
+
const prior = leafNodes[index];
|
|
37
|
+
leafNodes[index] = prior == null ? node : {
|
|
38
|
+
handshake: mergeGenerationSecrets(prior.handshake, node.handshake),
|
|
39
|
+
application: mergeGenerationSecrets(prior.application, node.application)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const occupied = [
|
|
43
|
+
...Object.keys(intermediateNodes),
|
|
44
|
+
...Object.keys(leafNodes)
|
|
45
|
+
].map(Number);
|
|
46
|
+
for (const ancestorText of Object.keys(intermediateNodes)){
|
|
47
|
+
const ancestor = Number(ancestorText);
|
|
48
|
+
let level = 0;
|
|
49
|
+
while((ancestor >> level & 1) === 1)level++;
|
|
50
|
+
const span = 2 ** level - 1;
|
|
51
|
+
if (occupied.some((node)=>node !== ancestor && node >= ancestor - span && node <= ancestor + span)) {
|
|
52
|
+
delete intermediateNodes[ancestor];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
leafWidth: target.leafWidth,
|
|
57
|
+
intermediateNodes,
|
|
58
|
+
leafNodes
|
|
59
|
+
};
|
|
60
|
+
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { Capabilities, CryptoProvider, GroupContextExtension, IncomingMessageCallback, KeyPackage, PrivateKeyPackage } from 'ts-mls';
|
|
2
|
+
import type { ControllerBinding } from './credential.js';
|
|
2
3
|
import type { VerifiedLedgerEntry } from './ledger.js';
|
|
3
4
|
export type GroupOptions = {
|
|
5
|
+
/** Creator or key-package leaf binding. Creates a lifecycle group when passed to createGroup. */
|
|
6
|
+
controller?: ControllerBinding;
|
|
7
|
+
/** Lifecycle leaf lifetime in seconds. Defaults to 86,400; maximum 604,800. */
|
|
8
|
+
leafLifetime?: number;
|
|
9
|
+
/** Lifecycle trusted grant lifetime in seconds. Defaults to 2,592,000; maximum 31,536,000. */
|
|
10
|
+
trustedGrantLifetime?: number;
|
|
4
11
|
/** Custom CryptoProvider for ts-mls. Defaults to nobleCryptoProvider. */
|
|
5
12
|
cryptoProvider?: CryptoProvider;
|
|
6
13
|
/** Ciphersuite name. Defaults to MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519. */
|
|
@@ -19,13 +26,9 @@ export type GroupOptions = {
|
|
|
19
26
|
* 'reject' to refuse it (the handle stays at its pre-commit epoch and
|
|
20
27
|
* processMessage throws CommitRejectedError). Overridable per call.
|
|
21
28
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* enforcement for the resulting handle; only the decode/fold hard-reject
|
|
26
|
-
* still applies. Callers who want to extend rather than replace the default
|
|
27
|
-
* policy must call defaultCommitPolicy themselves from within their own
|
|
28
|
-
* callback.
|
|
29
|
+
* Replaces the default role rules after mandatory credential and lifecycle gates accept.
|
|
30
|
+
* A caller policy cannot admit a change rejected by those gates. To extend the default
|
|
31
|
+
* role rules, call defaultCommitPolicy from the callback.
|
|
29
32
|
*/
|
|
30
33
|
commitPolicy?: IncomingMessageCallback;
|
|
31
34
|
/**
|
|
@@ -47,10 +50,12 @@ export type GroupOptions = {
|
|
|
47
50
|
export type Invite = {
|
|
48
51
|
/** Group ID the invite is for */
|
|
49
52
|
groupID: string;
|
|
53
|
+
/** Intended recipient DID. */
|
|
54
|
+
recipientDID: string;
|
|
50
55
|
/** Inviter's DID */
|
|
51
56
|
inviterID: string;
|
|
52
57
|
/** The group's whole signed control ledger, in application order, so the joiner
|
|
53
|
-
* folds the same
|
|
58
|
+
* folds the same control state as everyone else. */
|
|
54
59
|
ledgerEntries: Array<string>;
|
|
55
60
|
};
|
|
56
61
|
export type KeyPackageBundle = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumiai/mls",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "E2EE group identity and membership for Enkaku using MLS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mls",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"lib/*"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@kokuin/capability": "^0.
|
|
28
|
+
"@kokuin/capability": "^0.4.1",
|
|
29
29
|
"@kokuin/controller": "^0.1.0",
|
|
30
|
-
"@kokuin/token": "^0.5.
|
|
30
|
+
"@kokuin/token": "^0.5.1",
|
|
31
31
|
"@noble/ciphers": "^2.4.0",
|
|
32
32
|
"@noble/curves": "^2.4.0",
|
|
33
33
|
"@noble/hashes": "^2.4.0",
|
|
34
|
-
"@sozai/codec": "^0.4.
|
|
35
|
-
"@sozai/event": "^0.1.
|
|
34
|
+
"@sozai/codec": "^0.4.2",
|
|
35
|
+
"@sozai/event": "^0.1.5",
|
|
36
36
|
"@sozai/runtime": "^0.1.0",
|
|
37
37
|
"ts-mls": "2.0.0-rc.13"
|
|
38
38
|
},
|