@kumiai/mls 0.13.2 → 0.13.3
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/capability.d.ts +1 -0
- package/lib/capability.js +1 -1
- package/lib/crypto.js +15 -7
- package/lib/group-credential.d.ts +5 -3
- package/lib/group-credential.js +15 -16
- package/package.json +4 -4
package/lib/capability.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare function assertCapabilityLifetime(payload: CapabilityTimeClaims,
|
|
|
24
24
|
export declare function capabilityKey(payload: CapabilityPayload): import("@kokuin/controller").TaggedKey;
|
|
25
25
|
export declare function assertControllerGrant(payload: CapabilityPayload, controllerID: string): void;
|
|
26
26
|
export type MintLeafCapabilityParams = {
|
|
27
|
+
nowSeconds?: number;
|
|
27
28
|
signer: SigningIdentity;
|
|
28
29
|
controllerID: string;
|
|
29
30
|
audience: string;
|
package/lib/capability.js
CHANGED
|
@@ -66,7 +66,7 @@ function issuingPayload(params, maximum) {
|
|
|
66
66
|
if (!params.controllerID.startsWith('did:kokuin:')) {
|
|
67
67
|
throw new LeafBindingError('controller-mismatch');
|
|
68
68
|
}
|
|
69
|
-
const iat = now();
|
|
69
|
+
const { nowSeconds: iat = now() } = params;
|
|
70
70
|
assertCapabilityLifetime({
|
|
71
71
|
iat,
|
|
72
72
|
exp: params.exp
|
package/lib/crypto.js
CHANGED
|
@@ -94,7 +94,14 @@ function makeKdf(kdfName) {
|
|
|
94
94
|
size
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// Signature (Ed25519)
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// Ed25519 and X25519 secret keys are 32 random bytes, drawn from the suite RNG so an injected source
|
|
101
|
+
// controls every key and encapsulation. X25519 takes them verbatim (noble clamps on use), and its
|
|
102
|
+
// typed randomSecretKey() accepts no seed.
|
|
103
|
+
const SECRET_KEY_SEED_LENGTH = 32;
|
|
104
|
+
function makeSignature({ name, crypto, rng }) {
|
|
98
105
|
if (name !== 'Ed25519') {
|
|
99
106
|
throw new Error(`Unsupported signature algorithm: ${name}. Only Ed25519 is supported.`);
|
|
100
107
|
}
|
|
@@ -115,7 +122,7 @@ function makeSignature({ name, crypto }) {
|
|
|
115
122
|
});
|
|
116
123
|
},
|
|
117
124
|
async keygen () {
|
|
118
|
-
const signKey = ed25519.utils.randomSecretKey();
|
|
125
|
+
const signKey = ed25519.utils.randomSecretKey(rng.randomBytes(SECRET_KEY_SEED_LENGTH));
|
|
119
126
|
return {
|
|
120
127
|
signKey,
|
|
121
128
|
publicKey: ed25519.getPublicKey(signKey)
|
|
@@ -173,7 +180,7 @@ const KEM_SUITE_ID = concatBytes(new TextEncoder().encode('KEM'), i2osp(KEM_ID_X
|
|
|
173
180
|
publicKey: pk
|
|
174
181
|
};
|
|
175
182
|
}
|
|
176
|
-
function makeHpke(hpkeAlg) {
|
|
183
|
+
function makeHpke(hpkeAlg, rng) {
|
|
177
184
|
if (!hpkeAlg.kem.includes('X25519')) {
|
|
178
185
|
throw new Error(`Unsupported KEM: ${hpkeAlg.kem}. Only DHKEM-X25519-HKDF-SHA256 is supported.`);
|
|
179
186
|
}
|
|
@@ -227,7 +234,7 @@ function makeHpke(hpkeAlg) {
|
|
|
227
234
|
/**
|
|
228
235
|
* Encap (RFC 9180 §4.1) — generate ephemeral keypair and shared secret
|
|
229
236
|
*/ function encap(recipientPublicKey) {
|
|
230
|
-
const ek =
|
|
237
|
+
const ek = rng.randomBytes(SECRET_KEY_SEED_LENGTH);
|
|
231
238
|
const enc = x25519.getPublicKey(ek);
|
|
232
239
|
const dh = x25519.getSharedSecret(ek, recipientPublicKey);
|
|
233
240
|
const kemContext = concatBytes(enc, recipientPublicKey);
|
|
@@ -328,7 +335,7 @@ function makeHpke(hpkeAlg) {
|
|
|
328
335
|
};
|
|
329
336
|
},
|
|
330
337
|
async generateKeyPair () {
|
|
331
|
-
const privateKey =
|
|
338
|
+
const privateKey = rng.randomBytes(SECRET_KEY_SEED_LENGTH);
|
|
332
339
|
const publicKey = x25519.getPublicKey(privateKey);
|
|
333
340
|
return {
|
|
334
341
|
privateKey: wrapPrivateKey(privateKey),
|
|
@@ -378,9 +385,10 @@ export function createNobleCryptoProvider(options) {
|
|
|
378
385
|
kdf: makeKdf(config.hpke.kdf),
|
|
379
386
|
signature: makeSignature({
|
|
380
387
|
name: config.signature,
|
|
381
|
-
crypto
|
|
388
|
+
crypto,
|
|
389
|
+
rng
|
|
382
390
|
}),
|
|
383
|
-
hpke: makeHpke(config.hpke),
|
|
391
|
+
hpke: makeHpke(config.hpke, rng),
|
|
384
392
|
rng,
|
|
385
393
|
id
|
|
386
394
|
};
|
|
@@ -7,7 +7,7 @@ export type MakeMLSCredentialParams = {
|
|
|
7
7
|
controller?: ControllerBinding;
|
|
8
8
|
};
|
|
9
9
|
export declare function makeMLSCredential({ identity, controller }: MakeMLSCredentialParams): Credential;
|
|
10
|
-
export declare function assertBindingAuthorTime(controller?: ControllerBinding): void;
|
|
10
|
+
export declare function assertBindingAuthorTime(controller?: ControllerBinding, nowSeconds?: number): void;
|
|
11
11
|
/**
|
|
12
12
|
* How long an ordinary, single-use key package stays valid, in days.
|
|
13
13
|
*
|
|
@@ -19,9 +19,10 @@ export declare function assertBindingAuthorTime(controller?: ControllerBinding):
|
|
|
19
19
|
export declare const ORDINARY_KEY_PACKAGE_LIFETIME_DAYS = 30;
|
|
20
20
|
export type CreateKeyPackageBundleParams = {
|
|
21
21
|
identity: OwnIdentity;
|
|
22
|
+
nowSeconds?: number;
|
|
22
23
|
} & GroupOptions;
|
|
23
24
|
/** Generate a key package for joining groups. */
|
|
24
|
-
export declare function createKeyPackageBundle({ identity, ...options }: CreateKeyPackageBundleParams): Promise<KeyPackageBundle>;
|
|
25
|
+
export declare function createKeyPackageBundle({ identity, nowSeconds, ...options }: CreateKeyPackageBundleParams): Promise<KeyPackageBundle>;
|
|
25
26
|
/**
|
|
26
27
|
* The `last_resort` KeyPackage extension from draft-ietf-mls-extensions (NOT RFC 9420, which has
|
|
27
28
|
* no such extension). Its presence marks a key package as reusable by design; its data is empty.
|
|
@@ -53,6 +54,7 @@ export declare const LAST_RESORT_EXTENSION_TYPE = 10;
|
|
|
53
54
|
export declare const LAST_RESORT_LIFETIME_DAYS = 90;
|
|
54
55
|
export type CreateLastResortKeyPackageBundleParams = {
|
|
55
56
|
identity: OwnIdentity;
|
|
57
|
+
nowSeconds?: number;
|
|
56
58
|
} & GroupOptions;
|
|
57
59
|
/**
|
|
58
60
|
* Generate a reusable last-resort key package for joining groups.
|
|
@@ -71,4 +73,4 @@ export type CreateLastResortKeyPackageBundleParams = {
|
|
|
71
73
|
* package stops working while the hub still reports the slot as full and keeps serving it. Both
|
|
72
74
|
* obligations fail the same way: silently, and precisely when the floor is needed.
|
|
73
75
|
*/
|
|
74
|
-
export declare function createLastResortKeyPackageBundle({ identity, ...options }: CreateLastResortKeyPackageBundleParams): Promise<KeyPackageBundle>;
|
|
76
|
+
export declare function createLastResortKeyPackageBundle({ identity, nowSeconds, ...options }: CreateLastResortKeyPackageBundleParams): Promise<KeyPackageBundle>;
|
package/lib/group-credential.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPeer4
|
|
1
|
+
import { isPeer4 } from '@kokuin/token';
|
|
2
2
|
import { defaultCredentialTypes, generateKeyPackageWithKey, greaseExtensions, makeCustomExtension } from 'ts-mls';
|
|
3
3
|
import { controlCapabilities } from './anchor.js';
|
|
4
4
|
import { verifyLeafCredential } from './authentication.js';
|
|
@@ -7,6 +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
|
+
const currentSeconds = ()=>Math.floor(Date.now() / 1000);
|
|
10
11
|
export function makeMLSCredential({ identity, controller }) {
|
|
11
12
|
const id = identity.id;
|
|
12
13
|
const isPeer = isPeer4(id);
|
|
@@ -26,17 +27,17 @@ export function makeMLSCredential({ identity, controller }) {
|
|
|
26
27
|
identity: new TextEncoder().encode(JSON.stringify(payload))
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
|
-
export function assertBindingAuthorTime(controller) {
|
|
30
|
+
export function assertBindingAuthorTime(controller, nowSeconds = currentSeconds()) {
|
|
30
31
|
if (controller == null) return;
|
|
31
32
|
if (controller.member != null) {
|
|
32
|
-
if (controller.iat == null || !Number.isFinite(controller.iat) || controller.iat >
|
|
33
|
+
if (controller.iat == null || !Number.isFinite(controller.iat) || controller.iat > nowSeconds) {
|
|
33
34
|
throw new Error('Membership binding is not valid at authoring time');
|
|
34
35
|
}
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
if (controller.capability == null) throw new LeafBindingError('controller-mismatch');
|
|
38
39
|
const { iat, exp } = readCapability(controller.capability).payload;
|
|
39
|
-
const timestamp =
|
|
40
|
+
const timestamp = nowSeconds;
|
|
40
41
|
if (exp <= timestamp || iat > timestamp) {
|
|
41
42
|
throw new Error('Leaf capability is not valid at authoring time');
|
|
42
43
|
}
|
|
@@ -49,8 +50,8 @@ export function assertBindingAuthorTime(controller) {
|
|
|
49
50
|
* `extensions` is left genuinely absent (not passed as `undefined`) when the caller supplies none,
|
|
50
51
|
* so `generateKeyPackageWithKey`'s own `params.extensions ?? greaseExtensions(...)` default still
|
|
51
52
|
* applies for the ordinary path.
|
|
52
|
-
*/ async function buildBundle(identity, options, overrides = {}) {
|
|
53
|
-
assertBindingAuthorTime(options?.controller);
|
|
53
|
+
*/ async function buildBundle(identity, options, overrides = {}, nowSeconds) {
|
|
54
|
+
assertBindingAuthorTime(options?.controller, nowSeconds);
|
|
54
55
|
const credential = makeMLSCredential({
|
|
55
56
|
identity,
|
|
56
57
|
controller: options?.controller
|
|
@@ -105,17 +106,16 @@ export function assertBindingAuthorTime(controller) {
|
|
|
105
106
|
* default can move under a patch bump. 30 sits well under the 4-month `maximumTotalLifetime` ts-mls
|
|
106
107
|
* declares, and makes a weekly top-up comfortable rather than marginal.
|
|
107
108
|
*/ export const ORDINARY_KEY_PACKAGE_LIFETIME_DAYS = 30;
|
|
108
|
-
/** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function ordinaryLifetime() {
|
|
109
|
-
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
109
|
+
/** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function ordinaryLifetime(nowSeconds) {
|
|
110
110
|
return {
|
|
111
111
|
notBefore: BigInt(nowSeconds - 86_400),
|
|
112
112
|
notAfter: BigInt(nowSeconds + ORDINARY_KEY_PACKAGE_LIFETIME_DAYS * 86_400)
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
-
/** 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, nowSeconds = currentSeconds(), ...options }) {
|
|
116
116
|
return buildBundle(identity, options, {
|
|
117
|
-
lifetime: ordinaryLifetime()
|
|
118
|
-
});
|
|
117
|
+
lifetime: ordinaryLifetime(nowSeconds)
|
|
118
|
+
}, nowSeconds);
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
121
|
* The `last_resort` KeyPackage extension from draft-ietf-mls-extensions (NOT RFC 9420, which has
|
|
@@ -144,8 +144,7 @@ export function assertBindingAuthorTime(controller) {
|
|
|
144
144
|
* **This is a rotation deadline, not a solution.** A host must re-upload before it elapses, or the
|
|
145
145
|
* floor disappears exactly when it is needed.
|
|
146
146
|
*/ export const LAST_RESORT_LIFETIME_DAYS = 90;
|
|
147
|
-
/** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function lastResortLifetime() {
|
|
148
|
-
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
147
|
+
/** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function lastResortLifetime(nowSeconds) {
|
|
149
148
|
return {
|
|
150
149
|
notBefore: BigInt(nowSeconds - 86_400),
|
|
151
150
|
notAfter: BigInt(nowSeconds + LAST_RESORT_LIFETIME_DAYS * 86_400)
|
|
@@ -167,7 +166,7 @@ export function assertBindingAuthorTime(controller) {
|
|
|
167
166
|
* carries an MLS lifetime, and an inviter validates it when building the Add — so an unrotated
|
|
168
167
|
* package stops working while the hub still reports the slot as full and keeps serving it. Both
|
|
169
168
|
* obligations fail the same way: silently, and precisely when the floor is needed.
|
|
170
|
-
*/ export async function createLastResortKeyPackageBundle({ identity, ...options }) {
|
|
169
|
+
*/ export async function createLastResortKeyPackageBundle({ identity, nowSeconds = currentSeconds(), ...options }) {
|
|
171
170
|
return buildBundle(identity, options, {
|
|
172
171
|
// Supplying `extensions` at all suppresses ts-mls's own default of
|
|
173
172
|
// `greaseExtensions(defaultGreaseConfig)`. `defaultGreaseConfig` is not exported, so its 0.1
|
|
@@ -181,6 +180,6 @@ export function assertBindingAuthorTime(controller) {
|
|
|
181
180
|
extensionData: new Uint8Array(0)
|
|
182
181
|
})
|
|
183
182
|
],
|
|
184
|
-
lifetime: lastResortLifetime()
|
|
185
|
-
});
|
|
183
|
+
lifetime: lastResortLifetime(nowSeconds)
|
|
184
|
+
}, nowSeconds);
|
|
186
185
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumiai/mls",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.3",
|
|
4
4
|
"description": "E2EE group identity and membership for Enkaku using MLS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mls",
|
|
@@ -25,17 +25,17 @@
|
|
|
25
25
|
"lib/*"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@kokuin/capability": "^0.7.
|
|
28
|
+
"@kokuin/capability": "^0.7.2",
|
|
29
29
|
"@kokuin/controller": "^0.7.1",
|
|
30
30
|
"@kokuin/crypto": "^0.7.1",
|
|
31
31
|
"@kokuin/token": "^0.7.1",
|
|
32
32
|
"@noble/ciphers": "^2.4.0",
|
|
33
33
|
"@noble/curves": "^2.4.0",
|
|
34
34
|
"@noble/hashes": "^2.4.0",
|
|
35
|
-
"@sozai/async": "^0.4.
|
|
35
|
+
"@sozai/async": "^0.4.4",
|
|
36
36
|
"@sozai/codec": "^0.4.4",
|
|
37
37
|
"@sozai/event": "^0.1.6",
|
|
38
|
-
"@sozai/runtime": "^0.1.
|
|
38
|
+
"@sozai/runtime": "^0.1.1",
|
|
39
39
|
"ts-mls": "2.0.0-rc.13"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|