@kumiai/mls 0.13.0 → 0.13.1
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/crypto.d.ts +8 -1
- package/lib/crypto.js +23 -11
- package/lib/group-context.js +4 -2
- package/lib/types.d.ts +2 -2
- package/package.json +1 -1
package/lib/crypto.d.ts
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
* Pure @noble/* CryptoProvider for ts-mls.
|
|
3
3
|
*
|
|
4
4
|
* Replaces @hpke/core (which requires crypto.subtle) with direct use of:
|
|
5
|
-
* - @noble/curves for X25519 ECDH and Ed25519
|
|
5
|
+
* - @noble/curves for X25519 ECDH and Ed25519 key generation
|
|
6
|
+
* - a kokuin provider for Ed25519 signing and verification
|
|
6
7
|
* - @noble/hashes for SHA-256/384/512 and HKDF
|
|
7
8
|
* - @noble/ciphers for AES-GCM and ChaCha20-Poly1305
|
|
8
9
|
*
|
|
9
10
|
* This enables ts-mls to run on Hermes (React Native) where crypto.subtle is unavailable.
|
|
10
11
|
*/
|
|
12
|
+
import { type CryptoProvider as KokuinCryptoProvider } from '@kokuin/crypto';
|
|
11
13
|
import { type Runtime } from '@sozai/runtime';
|
|
12
14
|
import type { CryptoProvider } from 'ts-mls';
|
|
13
15
|
export type NobleCryptoProviderOptions = {
|
|
@@ -15,6 +17,11 @@ export type NobleCryptoProviderOptions = {
|
|
|
15
17
|
randomBytes?: (n: number) => Uint8Array;
|
|
16
18
|
/** Runtime providing platform primitives. Defaults to createRuntime(). */
|
|
17
19
|
runtime?: Runtime;
|
|
20
|
+
/**
|
|
21
|
+
* Signs and verifies Ed25519. Defaults to kokuin's strict noble provider, so every backend
|
|
22
|
+
* accepts the same signatures and members cannot split on a non-canonical one.
|
|
23
|
+
*/
|
|
24
|
+
crypto?: KokuinCryptoProvider;
|
|
18
25
|
};
|
|
19
26
|
export declare function createNobleCryptoProvider(options?: NobleCryptoProviderOptions): CryptoProvider;
|
|
20
27
|
/** Default noble CryptoProvider using the default runtime for RNG. */
|
package/lib/crypto.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
* Pure @noble/* CryptoProvider for ts-mls.
|
|
3
3
|
*
|
|
4
4
|
* Replaces @hpke/core (which requires crypto.subtle) with direct use of:
|
|
5
|
-
* - @noble/curves for X25519 ECDH and Ed25519
|
|
5
|
+
* - @noble/curves for X25519 ECDH and Ed25519 key generation
|
|
6
|
+
* - a kokuin provider for Ed25519 signing and verification
|
|
6
7
|
* - @noble/hashes for SHA-256/384/512 and HKDF
|
|
7
8
|
* - @noble/ciphers for AES-GCM and ChaCha20-Poly1305
|
|
8
9
|
*
|
|
9
10
|
* This enables ts-mls to run on Hermes (React Native) where crypto.subtle is unavailable.
|
|
10
|
-
*/ import {
|
|
11
|
+
*/ import { nobleCrypto } from '@kokuin/crypto';
|
|
12
|
+
import { gcm } from '@noble/ciphers/aes.js';
|
|
11
13
|
import { chacha20poly1305 } from '@noble/ciphers/chacha.js';
|
|
12
14
|
import { ed25519, x25519 } from '@noble/curves/ed25519.js';
|
|
13
15
|
import { expand as hkdfExpand, extract as hkdfExtract } from '@noble/hashes/hkdf.js';
|
|
@@ -92,19 +94,25 @@ function makeKdf(kdfName) {
|
|
|
92
94
|
size
|
|
93
95
|
};
|
|
94
96
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
function makeSignature(sigName) {
|
|
99
|
-
if (sigName !== 'Ed25519') {
|
|
100
|
-
throw new Error(`Unsupported signature algorithm: ${sigName}. Only Ed25519 is supported.`);
|
|
97
|
+
function makeSignature({ name, crypto }) {
|
|
98
|
+
if (name !== 'Ed25519') {
|
|
99
|
+
throw new Error(`Unsupported signature algorithm: ${name}. Only Ed25519 is supported.`);
|
|
101
100
|
}
|
|
102
101
|
return {
|
|
103
102
|
async sign (signKey, message) {
|
|
104
|
-
return
|
|
103
|
+
return await crypto.sign({
|
|
104
|
+
alg: 'EdDSA',
|
|
105
|
+
privateKey: signKey,
|
|
106
|
+
message
|
|
107
|
+
});
|
|
105
108
|
},
|
|
106
109
|
async verify (publicKey, message, signature) {
|
|
107
|
-
return
|
|
110
|
+
return await crypto.verify({
|
|
111
|
+
alg: 'EdDSA',
|
|
112
|
+
signature,
|
|
113
|
+
message,
|
|
114
|
+
publicKey
|
|
115
|
+
});
|
|
108
116
|
},
|
|
109
117
|
async keygen () {
|
|
110
118
|
const signKey = ed25519.utils.randomSecretKey();
|
|
@@ -358,6 +366,7 @@ const CIPHERSUITE_CONFIGS = {
|
|
|
358
366
|
export function createNobleCryptoProvider(options) {
|
|
359
367
|
const runtime = options?.runtime ?? createRuntime();
|
|
360
368
|
const rng = makeRng(runtime, options?.randomBytes);
|
|
369
|
+
const crypto = options?.crypto ?? nobleCrypto;
|
|
361
370
|
return {
|
|
362
371
|
async getCiphersuiteImpl (id) {
|
|
363
372
|
const config = CIPHERSUITE_CONFIGS[id];
|
|
@@ -367,7 +376,10 @@ export function createNobleCryptoProvider(options) {
|
|
|
367
376
|
return {
|
|
368
377
|
hash: makeHash(config.hash),
|
|
369
378
|
kdf: makeKdf(config.hpke.kdf),
|
|
370
|
-
signature: makeSignature(
|
|
379
|
+
signature: makeSignature({
|
|
380
|
+
name: config.signature,
|
|
381
|
+
crypto
|
|
382
|
+
}),
|
|
371
383
|
hpke: makeHpke(config.hpke),
|
|
372
384
|
rng,
|
|
373
385
|
id
|
package/lib/group-context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defaultCapabilities, defaultKeyPackageEqualityConfig, defaultLifetimeConfig, defaultPaddingConfig, getCiphersuiteImpl } from 'ts-mls';
|
|
2
2
|
import { createDIDAuthenticationService } from './authentication.js';
|
|
3
|
-
import {
|
|
3
|
+
import { createNobleCryptoProvider } 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();
|
|
@@ -97,7 +97,9 @@ function authenticationFor(holder) {
|
|
|
97
97
|
}
|
|
98
98
|
export async function resolveMlsContext(options, anchor) {
|
|
99
99
|
const name = options?.ciphersuiteName ?? DEFAULT_CIPHERSUITE;
|
|
100
|
-
const cipherSuite = await getCiphersuiteImpl(name, options?.cryptoProvider ??
|
|
100
|
+
const cipherSuite = await getCiphersuiteImpl(name, options?.cryptoProvider ?? createNobleCryptoProvider({
|
|
101
|
+
crypto: options?.crypto
|
|
102
|
+
}));
|
|
101
103
|
return createMlsContext(cipherSuite, anchor, undefined, options);
|
|
102
104
|
}
|
|
103
105
|
export function createMlsContext(cipherSuite, anchor, clientConfig, options) {
|
package/lib/types.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ export type GroupOptions = {
|
|
|
12
12
|
leafLifetime?: number;
|
|
13
13
|
/** Lifecycle trusted grant lifetime in seconds. Defaults to 2,592,000; maximum 31,536,000. */
|
|
14
14
|
trustedGrantLifetime?: number;
|
|
15
|
-
/** Custom CryptoProvider for ts-mls. Defaults to
|
|
15
|
+
/** Custom CryptoProvider for ts-mls. Defaults to a noble one that signs through `crypto`. */
|
|
16
16
|
cryptoProvider?: CryptoProvider;
|
|
17
|
-
/** Kokuin provider for
|
|
17
|
+
/** Kokuin provider for tokens, capabilities, controllers and, without `cryptoProvider`, MLS signatures. */
|
|
18
18
|
crypto?: KokuinCryptoProvider;
|
|
19
19
|
/** Ciphersuite name. Defaults to MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519. */
|
|
20
20
|
ciphersuiteName?: string;
|