@me2em/core 0.7.0-alpha.1 → 1.0.0-rc.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/README.md +242 -47
- package/dist/attestation.d.ts +26 -17
- package/dist/attestation.d.ts.map +1 -1
- package/dist/attestation.js +76 -29
- package/dist/attestation.js.map +1 -1
- package/dist/canonical-name.d.ts +18 -0
- package/dist/canonical-name.d.ts.map +1 -1
- package/dist/canonical-name.js +28 -1
- package/dist/canonical-name.js.map +1 -1
- package/dist/crypto/derivation-paths.d.ts +33 -2
- package/dist/crypto/derivation-paths.d.ts.map +1 -1
- package/dist/crypto/derivation-paths.js +33 -2
- package/dist/crypto/derivation-paths.js.map +1 -1
- package/dist/crypto/derivation.d.ts +47 -0
- package/dist/crypto/derivation.d.ts.map +1 -0
- package/dist/crypto/derivation.js +68 -0
- package/dist/crypto/derivation.js.map +1 -0
- package/dist/crypto/ecdh.d.ts +19 -0
- package/dist/crypto/ecdh.d.ts.map +1 -0
- package/dist/crypto/ecdh.js +33 -0
- package/dist/crypto/ecdh.js.map +1 -0
- package/dist/crypto/ed25519.d.ts +24 -3
- package/dist/crypto/ed25519.d.ts.map +1 -1
- package/dist/crypto/ed25519.js +39 -6
- package/dist/crypto/ed25519.js.map +1 -1
- package/dist/crypto/hkdf.d.ts +11 -2
- package/dist/crypto/hkdf.d.ts.map +1 -1
- package/dist/crypto/hkdf.js +13 -1
- package/dist/crypto/hkdf.js.map +1 -1
- package/dist/crypto/index.d.ts +25 -0
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/index.js +25 -0
- package/dist/crypto/index.js.map +1 -1
- package/dist/disposed-error.d.ts +24 -0
- package/dist/disposed-error.d.ts.map +1 -0
- package/dist/disposed-error.js +39 -0
- package/dist/disposed-error.js.map +1 -0
- package/dist/errors.d.ts +67 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +54 -0
- package/dist/errors.js.map +1 -0
- package/dist/handle.d.ts +300 -14
- package/dist/handle.d.ts.map +1 -1
- package/dist/handle.js +463 -54
- package/dist/handle.js.map +1 -1
- package/dist/identity.d.ts +55 -11
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +105 -35
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/seed.d.ts +33 -22
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +59 -31
- package/dist/seed.js.map +1 -1
- package/dist/session.d.ts +42 -5
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +248 -117
- package/dist/session.js.map +1 -1
- package/dist/subhandle.d.ts +1 -125
- package/dist/subhandle.d.ts.map +1 -1
- package/dist/subhandle.js +12 -179
- package/dist/subhandle.js.map +1 -1
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +47 -0
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +72 -20
- package/dist/util.js.map +1 -1
- package/package.json +12 -5
- package/src/attestation.ts +88 -38
- package/src/canonical-name.ts +33 -1
- package/src/crypto/derivation-paths.ts +37 -2
- package/src/crypto/derivation.ts +90 -0
- package/src/crypto/ecdh.ts +37 -0
- package/src/crypto/ed25519.ts +39 -6
- package/src/crypto/hkdf.ts +13 -1
- package/src/crypto/index.ts +28 -1
- package/src/disposed-error.ts +45 -0
- package/src/errors.ts +88 -0
- package/src/handle.ts +630 -65
- package/src/identity.ts +111 -64
- package/src/index.ts +13 -7
- package/src/seed.ts +75 -32
- package/src/session.ts +336 -132
- package/src/subhandle.ts +12 -251
- package/src/types.ts +26 -0
- package/src/util.ts +78 -20
package/dist/attestation.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
// attestation.ts
|
|
2
2
|
//
|
|
3
3
|
// Attestation module: cryptographically signed, self-contained
|
|
4
|
-
// authorization attestations for the
|
|
4
|
+
// authorization attestations for the Me2eM protocol.
|
|
5
5
|
import { normalizeName } from './canonical-name.js';
|
|
6
|
-
import { base64urlEncode, base64urlDecode } from './util.js';
|
|
6
|
+
import { base64urlEncode, base64urlDecode, randomUUID, safeJsonParse } from './util.js';
|
|
7
7
|
import { ed } from './crypto/init.js';
|
|
8
|
+
import { AttestationError } from './errors.js';
|
|
9
|
+
export { AttestationError } from './errors.js';
|
|
8
10
|
export const ATTESTATION_TYPE = 'me2em/attestation/v1';
|
|
9
11
|
export const ATTESTATION_MAX_PAYLOAD = 2048;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
level;
|
|
13
|
-
constructor(code, level, msg) {
|
|
14
|
-
super(`[${level}/${code}] ${msg}`);
|
|
15
|
-
this.code = code;
|
|
16
|
-
this.level = level;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
12
|
+
/** Maximum accepted length of an attestation `jti` (hardening, PR-7). */
|
|
13
|
+
const MAX_JTI_LENGTH = 256;
|
|
19
14
|
function throwFormat(code, msg) {
|
|
20
15
|
throw new AttestationError(code, 'FORMAT', msg);
|
|
21
16
|
}
|
|
@@ -32,19 +27,33 @@ function parseToken(token) {
|
|
|
32
27
|
if (!b64urlRegex.test(payloadB64) || !b64urlRegex.test(signatureB64)) {
|
|
33
28
|
throwFormat('MALFORMED', 'Payload and signature must be valid Base64URL');
|
|
34
29
|
}
|
|
35
|
-
|
|
30
|
+
let payloadBytes;
|
|
31
|
+
try {
|
|
32
|
+
payloadBytes = base64urlDecode(payloadB64);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
throwFormat('MALFORMED', 'Payload and signature must be valid Base64URL');
|
|
36
|
+
}
|
|
36
37
|
if (payloadBytes.length > ATTESTATION_MAX_PAYLOAD) {
|
|
37
38
|
throwFormat('MALFORMED', `Payload exceeds maximum size of ${ATTESTATION_MAX_PAYLOAD} bytes`);
|
|
38
39
|
}
|
|
39
40
|
let payload;
|
|
40
41
|
try {
|
|
41
42
|
const jsonString = new TextDecoder().decode(payloadBytes);
|
|
42
|
-
payload =
|
|
43
|
+
payload = safeJsonParse(jsonString);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
throwFormat('MALFORMED', e instanceof SyntaxError && e.message.includes('__proto__')
|
|
47
|
+
? `Payload is not valid JSON — ${e.message}`
|
|
48
|
+
: 'Payload is not valid JSON');
|
|
49
|
+
}
|
|
50
|
+
let signatureBytes;
|
|
51
|
+
try {
|
|
52
|
+
signatureBytes = base64urlDecode(signatureB64);
|
|
43
53
|
}
|
|
44
54
|
catch {
|
|
45
|
-
throwFormat('MALFORMED', 'Payload
|
|
55
|
+
throwFormat('MALFORMED', 'Payload and signature must be valid Base64URL');
|
|
46
56
|
}
|
|
47
|
-
const signatureBytes = base64urlDecode(signatureB64);
|
|
48
57
|
return { payloadBytes, signatureBytes, payload };
|
|
49
58
|
}
|
|
50
59
|
/**
|
|
@@ -61,22 +70,20 @@ function parseToken(token) {
|
|
|
61
70
|
* ```ts
|
|
62
71
|
* import { ed25519 } from '@noble/curves/ed25519.js';
|
|
63
72
|
*
|
|
64
|
-
* //
|
|
65
|
-
* const
|
|
66
|
-
* const signerPub = ed25519.getPublicKey(signerPriv);
|
|
73
|
+
* // Issuer (a Signer — Identity/Handle qualify) and subject public key:
|
|
74
|
+
* const identity = await Identity.fromSeed(seed);
|
|
67
75
|
* const childPub = ed25519.getPublicKey(ed25519.utils.randomPrivateKey());
|
|
68
76
|
*
|
|
69
|
-
* const A = await Attestation.issue(
|
|
77
|
+
* const A = await Attestation.issue(identity, childPub, 'station-001', {
|
|
70
78
|
* audiences: ['ev-app.com'],
|
|
71
79
|
* scopes: ['charge:start', 'charge:stop'],
|
|
72
80
|
* maxSessionTtl: 7200,
|
|
73
81
|
* subNamePatterns: ['connector-*'],
|
|
74
82
|
* });
|
|
75
83
|
*
|
|
76
|
-
* const ok = await Attestation.verifySignature(A.token,
|
|
84
|
+
* const ok = await Attestation.verifySignature(A.token, identity.getPublicKey()); // true
|
|
77
85
|
* const payload = Attestation.decode(A.token); // structure only — no sig, no time
|
|
78
|
-
*
|
|
79
|
-
* ```
|
|
86
|
+
* ```
|
|
80
87
|
*
|
|
81
88
|
* @category Core Primitives
|
|
82
89
|
*/
|
|
@@ -144,14 +151,29 @@ export class Attestation {
|
|
|
144
151
|
if (typeof payload.exp !== 'number') {
|
|
145
152
|
throwFormat('MALFORMED', 'Missing required field: exp');
|
|
146
153
|
}
|
|
147
|
-
|
|
154
|
+
// Non-finite numbers survive JSON.parse only as `Infinity` (e.g. 1e999);
|
|
155
|
+
// unchecked, `now > exp + skew` would be false forever — fail-open expiry.
|
|
156
|
+
if (!Number.isFinite(payload.iat) || !Number.isFinite(payload.exp)) {
|
|
157
|
+
throwFormat('MALFORMED', 'iat/exp must be finite numbers');
|
|
158
|
+
}
|
|
159
|
+
if (payload.exp <= payload.iat) {
|
|
160
|
+
throwFormat('MALFORMED', 'exp must be greater than iat');
|
|
161
|
+
}
|
|
162
|
+
if (typeof payload.jti !== 'string' || payload.jti.length === 0) {
|
|
148
163
|
throwFormat('MALFORMED', 'Missing required field: jti');
|
|
149
164
|
}
|
|
165
|
+
if (payload.jti.length > MAX_JTI_LENGTH) {
|
|
166
|
+
throwFormat('MALFORMED', `jti exceeds the maximum length of ${MAX_JTI_LENGTH} characters`);
|
|
167
|
+
}
|
|
150
168
|
return payload;
|
|
151
169
|
}
|
|
152
170
|
/**
|
|
153
171
|
* Verifies the token signature against a public key.
|
|
154
172
|
*
|
|
173
|
+
* A signature whose length differs from the 64-byte Ed25519 size is
|
|
174
|
+
* rejected with `false` before any crypto runs (PR-7 pre-check) —
|
|
175
|
+
* the method therefore never throws for short/long signatures.
|
|
176
|
+
*
|
|
155
177
|
* @returns `false` for a bad signature or a wrong key. Returns
|
|
156
178
|
* `false` for any invalid signature, including malformed lengths.
|
|
157
179
|
* It still throws `AttestationError` `MALFORMED`/`FORMAT` for
|
|
@@ -159,6 +181,11 @@ export class Attestation {
|
|
|
159
181
|
*/
|
|
160
182
|
static async verifySignature(token, signerPublicKey) {
|
|
161
183
|
const { signatureBytes, payloadBytes } = parseToken(token);
|
|
184
|
+
// Ed25519 signatures are exactly 64 bytes — reject other lengths
|
|
185
|
+
// before the curve math (the underlying library throws RangeError).
|
|
186
|
+
if (signatureBytes.length !== 64) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
162
189
|
try {
|
|
163
190
|
return ed.verify(signatureBytes, payloadBytes, signerPublicKey);
|
|
164
191
|
}
|
|
@@ -202,7 +229,16 @@ export class Attestation {
|
|
|
202
229
|
* `undefined` grant fields are omitted from the JSON entirely
|
|
203
230
|
* (distinguishable from `[]`).
|
|
204
231
|
*
|
|
205
|
-
*
|
|
232
|
+
* The `signer` is a {@link Signer} — typically the issuing
|
|
233
|
+
* {@link Identity} (root attestations) or {@link Handle} (SubHandle
|
|
234
|
+
* attestations). Raw private keys never cross a trust boundary as
|
|
235
|
+
* function arguments (D2): the key material stays encapsulated in the
|
|
236
|
+
* signer object.
|
|
237
|
+
*
|
|
238
|
+
* @param signer - Object producing the Ed25519 signature via
|
|
239
|
+
* `sign(data)`. `Identity` and `Handle` implement `Signer`; custom
|
|
240
|
+
* implementations (remote/HSM-backed signing) are accepted
|
|
241
|
+
* structurally.
|
|
206
242
|
* @param subjectPublicKey - 32-byte Ed25519 public key being attested.
|
|
207
243
|
* @param subjectName - Child name; canonicalized before signing.
|
|
208
244
|
* @param grant - Constraints enforced by verifiers (Mode 2).
|
|
@@ -213,18 +249,29 @@ export class Attestation {
|
|
|
213
249
|
* @throws {AttestationError} `MALFORMED`/`FORMAT` if the grant is
|
|
214
250
|
* structurally invalid (bad scopes/TTL/audiences or a wildcard
|
|
215
251
|
* not at the end of a `subNamePatterns` entry).
|
|
252
|
+
* @throws {TypeError} If `signer` has no callable `sign` method — e.g.
|
|
253
|
+
* when a raw private key is passed (the pre-v1.0 form is no longer
|
|
254
|
+
* accepted).
|
|
216
255
|
* @throws {Error} If `subjectPublicKey` is not 32 bytes.
|
|
217
256
|
*
|
|
218
257
|
* @example
|
|
219
258
|
* ```ts
|
|
220
|
-
* const att = await Attestation.issue(
|
|
259
|
+
* const att = await Attestation.issue(rootIdentity, childPub, 'Station-1',
|
|
221
260
|
* { scopes: ['read'], maxSessionTtl: 3600 }, { ttlSeconds: 600 });
|
|
222
261
|
* ```
|
|
223
262
|
*/
|
|
224
|
-
static async issue(
|
|
263
|
+
static async issue(signer, subjectPublicKey, subjectName, grant, opts) {
|
|
264
|
+
if (typeof signer?.sign !== 'function') {
|
|
265
|
+
throw new TypeError('Attestation.issue requires a Signer — an object with a sign(data) ' +
|
|
266
|
+
'method (Identity or Handle). Raw private keys are no longer accepted.');
|
|
267
|
+
}
|
|
225
268
|
const name = normalizeName(subjectName);
|
|
226
269
|
if (subjectPublicKey.length !== 32) {
|
|
227
|
-
|
|
270
|
+
throwFormat('MALFORMED', 'subject public key must be 32 bytes');
|
|
271
|
+
}
|
|
272
|
+
if (opts?.jti !== undefined &&
|
|
273
|
+
(typeof opts.jti !== 'string' || opts.jti.length === 0 || opts.jti.length > MAX_JTI_LENGTH)) {
|
|
274
|
+
throwFormat('MALFORMED', `opts.jti must be a non-empty string of at most ${MAX_JTI_LENGTH} characters`);
|
|
228
275
|
}
|
|
229
276
|
// Validate grant
|
|
230
277
|
if (!Array.isArray(grant.scopes) || !grant.scopes.every((s) => typeof s === 'string')) {
|
|
@@ -251,7 +298,7 @@ export class Attestation {
|
|
|
251
298
|
}
|
|
252
299
|
const now = opts?.now ?? Math.floor(Date.now() / 1000);
|
|
253
300
|
const exp = opts?.expiresAt ?? (now + (opts?.ttlSeconds ?? 31536000));
|
|
254
|
-
const jti = opts?.jti ??
|
|
301
|
+
const jti = opts?.jti ?? randomUUID();
|
|
255
302
|
const grantJson = {};
|
|
256
303
|
if (grant.audiences !== undefined)
|
|
257
304
|
grantJson.audiences = [...grant.audiences];
|
|
@@ -269,7 +316,7 @@ export class Attestation {
|
|
|
269
316
|
jti,
|
|
270
317
|
};
|
|
271
318
|
const payloadBytes = new TextEncoder().encode(JSON.stringify(payload));
|
|
272
|
-
const signature = await
|
|
319
|
+
const signature = await signer.sign(payloadBytes);
|
|
273
320
|
const payloadB64 = base64urlEncode(payloadBytes);
|
|
274
321
|
const signatureB64 = base64urlEncode(signature);
|
|
275
322
|
const token = `${payloadB64}.${signatureB64}`;
|
package/dist/attestation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attestation.js","sourceRoot":"","sources":["../src/attestation.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,EAAE;AACF,+DAA+D;AAC/D,qDAAqD;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"attestation.js","sourceRoot":"","sources":["../src/attestation.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,EAAE;AACF,+DAA+D;AAC/D,qDAAqD;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACxF,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAA6B,MAAM,aAAa,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAoD,MAAM,aAAa,CAAC;AAEjG,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AACvD,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAE5C,yEAAyE;AACzE,MAAM,cAAc,GAAG,GAAG,CAAC;AAqC3B,SAAS,WAAW,CAAC,IAA0B,EAAE,GAAW;IAC1D,MAAM,IAAI,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;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C,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QACrC,SAAS,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;QAC9C,IAAI,KAAK,CAAC,eAAe,KAAK,SAAS;YACrC,SAAS,CAAC,eAAe,GAAG,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC;QAEzD,MAAM,OAAO,GAAuB;YAClC,GAAG,EAAE,gBAAgB;YACrB,WAAW,EAAE,IAAI;YACjB,SAAS,EAAE,eAAe,CAAC,gBAAgB,CAAC;YAC5C,KAAK,EAAE,SAAwC;YAC/C,GAAG,EAAE,GAAG;YACR,GAAG;YACH,GAAG;SACJ,CAAC;QAEF,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QACvE,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,MAAM,UAAU,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;QACjD,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,GAAG,UAAU,IAAI,YAAY,EAAE,CAAC;QAE9C,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;CACF"}
|
package/dist/canonical-name.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
1
|
export declare const NAME_PATTERN: RegExp;
|
|
2
2
|
export declare function normalizeName(raw: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Canonicalizes a password/channel context: NFKC → lowercase → trim.
|
|
5
|
+
*
|
|
6
|
+
* Same canonical form as {@link normalizeName} names use, minus the
|
|
7
|
+
* character-set pattern — a context is a caller-defined HKDF label, not
|
|
8
|
+
* a wire identifier. The canonical context is embedded verbatim into the
|
|
9
|
+
* derivation salt (`me2em/secret/{context}`, `me2em/channel/{context}`),
|
|
10
|
+
* so `' GitHub '`, `'github'` and the fullwidth `'GitHub'` all map to
|
|
11
|
+
* the same secret (specs/v1.0.md §1, since the revisions PR-8; the
|
|
12
|
+
* pre-revision rule was lowercase → trim without NFKC).
|
|
13
|
+
*
|
|
14
|
+
* @param raw - Caller-defined context, e.g. `'github'`, `'telemetry-v1'`.
|
|
15
|
+
* @returns The canonical context.
|
|
16
|
+
* @throws TypeError if `raw` is not a string (API misuse).
|
|
17
|
+
* @throws AttestationError `MALFORMED`/`FORMAT` if the context is empty
|
|
18
|
+
* after canonicalization.
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeContext(raw: string): string;
|
|
3
21
|
//# sourceMappingURL=canonical-name.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonical-name.d.ts","sourceRoot":"","sources":["../src/canonical-name.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"canonical-name.d.ts","sourceRoot":"","sources":["../src/canonical-name.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY,QAAiC,CAAC;AAE3D,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAWpD"}
|
package/dist/canonical-name.js
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
// canonical-name.ts
|
|
2
|
+
import { AttestationError } from './errors.js';
|
|
2
3
|
export const NAME_PATTERN = /^[a-z0-9][a-z0-9._@-]{0,62}$/;
|
|
3
4
|
export function normalizeName(raw) {
|
|
4
5
|
if (typeof raw !== 'string')
|
|
5
6
|
throw new TypeError('Name must be a string');
|
|
6
7
|
const name = raw.normalize('NFKC').toLowerCase().trim();
|
|
7
8
|
if (!NAME_PATTERN.test(name)) {
|
|
8
|
-
throw new
|
|
9
|
+
throw new AttestationError('MALFORMED', 'FORMAT', `Invalid name: ${JSON.stringify(raw)}`);
|
|
9
10
|
}
|
|
10
11
|
return name;
|
|
11
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Canonicalizes a password/channel context: NFKC → lowercase → trim.
|
|
15
|
+
*
|
|
16
|
+
* Same canonical form as {@link normalizeName} names use, minus the
|
|
17
|
+
* character-set pattern — a context is a caller-defined HKDF label, not
|
|
18
|
+
* a wire identifier. The canonical context is embedded verbatim into the
|
|
19
|
+
* derivation salt (`me2em/secret/{context}`, `me2em/channel/{context}`),
|
|
20
|
+
* so `' GitHub '`, `'github'` and the fullwidth `'GitHub'` all map to
|
|
21
|
+
* the same secret (specs/v1.0.md §1, since the revisions PR-8; the
|
|
22
|
+
* pre-revision rule was lowercase → trim without NFKC).
|
|
23
|
+
*
|
|
24
|
+
* @param raw - Caller-defined context, e.g. `'github'`, `'telemetry-v1'`.
|
|
25
|
+
* @returns The canonical context.
|
|
26
|
+
* @throws TypeError if `raw` is not a string (API misuse).
|
|
27
|
+
* @throws AttestationError `MALFORMED`/`FORMAT` if the context is empty
|
|
28
|
+
* after canonicalization.
|
|
29
|
+
*/
|
|
30
|
+
export function normalizeContext(raw) {
|
|
31
|
+
if (typeof raw !== 'string')
|
|
32
|
+
throw new TypeError('Context must be a string');
|
|
33
|
+
const ctx = raw.normalize('NFKC').toLowerCase().trim();
|
|
34
|
+
if (ctx.length === 0) {
|
|
35
|
+
throw new AttestationError('MALFORMED', 'FORMAT', `Context must not be empty after canonicalization: ${JSON.stringify(raw)}`);
|
|
36
|
+
}
|
|
37
|
+
return ctx;
|
|
38
|
+
}
|
|
12
39
|
//# sourceMappingURL=canonical-name.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonical-name.js","sourceRoot":"","sources":["../src/canonical-name.ts"],"names":[],"mappings":"AAAA,oBAAoB;AAEpB,MAAM,CAAC,MAAM,YAAY,GAAG,8BAA8B,CAAC;AAE3D,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,IAAI,OAAO,GAAG,KA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AAM,IAAI,gBAAgB,CACxB,WAAW,EACX,QAAQ,EACR,qDAAqD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAC3E,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Deterministic derivation paths for the
|
|
2
|
+
* Deterministic derivation paths for the Me2eM protocol.
|
|
3
3
|
*
|
|
4
4
|
* All HKDF info strings used to derive Identity, Handle, and SubHandle keys
|
|
5
5
|
* are centralized here. This guarantees that:
|
|
@@ -31,11 +31,42 @@ export declare const DERIVATION_PATHS: {
|
|
|
31
31
|
*/
|
|
32
32
|
readonly subhandle: (handleName: string, subName: string) => string;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* Info string for peer-to-peer channel key derivation.
|
|
35
35
|
* v2 binds both peers' public keys into the derivation, preventing
|
|
36
36
|
* unknown key-share attacks. The peer keys are appended in sorted
|
|
37
37
|
* order so both parties derive the identical string.
|
|
38
38
|
*/
|
|
39
39
|
readonly p2pChannelV2: "me2em/p2p-channel/v2";
|
|
40
|
+
/**
|
|
41
|
+
* Builds the info string for password (secret) derivation.
|
|
42
|
+
*
|
|
43
|
+
* Revision model (PR-8, D3): revision `1` — the initial revision — and
|
|
44
|
+
* an omitted revision both yield the frozen v1 info string, so the
|
|
45
|
+
* default derivation is byte-identical to the pre-revision protocol.
|
|
46
|
+
* Revision `N ≥ 2` appends a `/rN` path segment and derives a secret
|
|
47
|
+
* that is cryptographically independent of revision 1 for the same
|
|
48
|
+
* context — the sanctioned rotation path (specs/v1.0.md §3, PLAN-LTS
|
|
49
|
+
* §4 derivation-freeze rule).
|
|
50
|
+
*
|
|
51
|
+
* @param revision - Positive integer revision; default `1`.
|
|
52
|
+
* @returns The info string, e.g. `"me2em/secret/v1"` or `"me2em/secret/v1/r2"`.
|
|
53
|
+
*
|
|
54
|
+
* @since 0.8.0
|
|
55
|
+
*/
|
|
56
|
+
readonly password: (revision?: number) => string;
|
|
57
|
+
/**
|
|
58
|
+
* Builds the info string for channel-key derivation.
|
|
59
|
+
*
|
|
60
|
+
* Same revision model as {@link DERIVATION_PATHS.password}: revision
|
|
61
|
+
* `1`/omitted yields the frozen `"me2em/channel/v1"`; revision
|
|
62
|
+
* `N ≥ 2` yields `"me2em/channel/v1/rN"` — an independent key for
|
|
63
|
+
* rotating a compromised channel without changing the context.
|
|
64
|
+
*
|
|
65
|
+
* @param revision - Positive integer revision; default `1`.
|
|
66
|
+
* @returns The info string, e.g. `"me2em/channel/v1"` or `"me2em/channel/v1/r2"`.
|
|
67
|
+
*
|
|
68
|
+
* @since 0.8.0
|
|
69
|
+
*/
|
|
70
|
+
readonly channel: (revision?: number) => string;
|
|
40
71
|
};
|
|
41
72
|
//# sourceMappingURL=derivation-paths.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derivation-paths.d.ts","sourceRoot":"","sources":["../../src/crypto/derivation-paths.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB;IAC3B;;;OAGG;;IAGH;;;;;OAKG;4BACY,MAAM,KAAG,MAAM;IAG9B;;;;;;OAMG;qCACqB,MAAM,WAAW,MAAM,KAAG,MAAM;IAGxD;;;;;OAKG;;
|
|
1
|
+
{"version":3,"file":"derivation-paths.d.ts","sourceRoot":"","sources":["../../src/crypto/derivation-paths.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB;IAC3B;;;OAGG;;IAGH;;;;;OAKG;4BACY,MAAM,KAAG,MAAM;IAG9B;;;;;;OAMG;qCACqB,MAAM,WAAW,MAAM,KAAG,MAAM;IAGxD;;;;;OAKG;;IAGH;;;;;;;;;;;;;;;OAeG;mCACkB,MAAM,KAAO,MAAM;IAGxC;;;;;;;;;;;;OAYG;kCACiB,MAAM,KAAO,MAAM;CAE/B,CAAC"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// protocol version.
|
|
9
9
|
import { normalizeName } from '../canonical-name.js';
|
|
10
10
|
/**
|
|
11
|
-
* Deterministic derivation paths for the
|
|
11
|
+
* Deterministic derivation paths for the Me2eM protocol.
|
|
12
12
|
*
|
|
13
13
|
* All HKDF info strings used to derive Identity, Handle, and SubHandle keys
|
|
14
14
|
* are centralized here. This guarantees that:
|
|
@@ -40,11 +40,42 @@ export const DERIVATION_PATHS = {
|
|
|
40
40
|
*/
|
|
41
41
|
subhandle: (handleName, subName) => `me2em/subhandle/v1/${normalizeName(handleName)}/${normalizeName(subName)}`,
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Info string for peer-to-peer channel key derivation.
|
|
44
44
|
* v2 binds both peers' public keys into the derivation, preventing
|
|
45
45
|
* unknown key-share attacks. The peer keys are appended in sorted
|
|
46
46
|
* order so both parties derive the identical string.
|
|
47
47
|
*/
|
|
48
48
|
p2pChannelV2: 'me2em/p2p-channel/v2',
|
|
49
|
+
/**
|
|
50
|
+
* Builds the info string for password (secret) derivation.
|
|
51
|
+
*
|
|
52
|
+
* Revision model (PR-8, D3): revision `1` — the initial revision — and
|
|
53
|
+
* an omitted revision both yield the frozen v1 info string, so the
|
|
54
|
+
* default derivation is byte-identical to the pre-revision protocol.
|
|
55
|
+
* Revision `N ≥ 2` appends a `/rN` path segment and derives a secret
|
|
56
|
+
* that is cryptographically independent of revision 1 for the same
|
|
57
|
+
* context — the sanctioned rotation path (specs/v1.0.md §3, PLAN-LTS
|
|
58
|
+
* §4 derivation-freeze rule).
|
|
59
|
+
*
|
|
60
|
+
* @param revision - Positive integer revision; default `1`.
|
|
61
|
+
* @returns The info string, e.g. `"me2em/secret/v1"` or `"me2em/secret/v1/r2"`.
|
|
62
|
+
*
|
|
63
|
+
* @since 0.8.0
|
|
64
|
+
*/
|
|
65
|
+
password: (revision = 1) => revision === 1 ? 'me2em/secret/v1' : `me2em/secret/v1/r${revision}`,
|
|
66
|
+
/**
|
|
67
|
+
* Builds the info string for channel-key derivation.
|
|
68
|
+
*
|
|
69
|
+
* Same revision model as {@link DERIVATION_PATHS.password}: revision
|
|
70
|
+
* `1`/omitted yields the frozen `"me2em/channel/v1"`; revision
|
|
71
|
+
* `N ≥ 2` yields `"me2em/channel/v1/rN"` — an independent key for
|
|
72
|
+
* rotating a compromised channel without changing the context.
|
|
73
|
+
*
|
|
74
|
+
* @param revision - Positive integer revision; default `1`.
|
|
75
|
+
* @returns The info string, e.g. `"me2em/channel/v1"` or `"me2em/channel/v1/r2"`.
|
|
76
|
+
*
|
|
77
|
+
* @since 0.8.0
|
|
78
|
+
*/
|
|
79
|
+
channel: (revision = 1) => revision === 1 ? 'me2em/channel/v1' : `me2em/channel/v1/r${revision}`,
|
|
49
80
|
};
|
|
50
81
|
//# sourceMappingURL=derivation-paths.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derivation-paths.js","sourceRoot":"","sources":["../../src/crypto/derivation-paths.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,wEAAwE;AACxE,EAAE;AACF,wEAAwE;AACxE,oBAAoB;AAEpB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,QAAQ,EAAE,wBAAwB;IAElC;;;;;OAKG;IACH,MAAM,EAAE,CAAC,IAAY,EAAU,EAAE,CAC/B,mBAAmB,aAAa,CAAC,IAAI,CAAC,EAAE;IAE1C;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,UAAkB,EAAE,OAAe,EAAU,EAAE,CACzD,sBAAsB,aAAa,CAAC,UAAU,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE;IAE7E;;;;;OAKG;IACH,YAAY,EAAE,sBAAsB;
|
|
1
|
+
{"version":3,"file":"derivation-paths.js","sourceRoot":"","sources":["../../src/crypto/derivation-paths.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,wEAAwE;AACxE,EAAE;AACF,wEAAwE;AACxE,oBAAoB;AAEpB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,QAAQ,EAAE,wBAAwB;IAElC;;;;;OAKG;IACH,MAAM,EAAE,CAAC,IAAY,EAAU,EAAE,CAC/B,mBAAmB,aAAa,CAAC,IAAI,CAAC,EAAE;IAE1C;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,UAAkB,EAAE,OAAe,EAAU,EAAE,CACzD,sBAAsB,aAAa,CAAC,UAAU,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE;IAE7E;;;;;OAKG;IACH,YAAY,EAAE,sBAAsB;IAEpC;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,EAAE,CAAC,WAAmB,CAAC,EAAU,EAAE,CACzC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,oBAAoB,QAAQ,EAAE;IAErE;;;;;;;;;;;;OAYG;IACH,OAAO,EAAE,CAAC,WAAmB,CAAC,EAAU,EAAE,CACxC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,qBAAqB,QAAQ,EAAE;CAC/D,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derives the root Identity key from the 64-byte seed.
|
|
3
|
+
*
|
|
4
|
+
* `HKDF-SHA256(seed, salt = "", info = "me2em/identity/v1/root", 32)`
|
|
5
|
+
* (specs/v1.0.md §2–§3). This is the exact computation
|
|
6
|
+
* `Identity.fromSeed` performs; exposed so advanced callers can
|
|
7
|
+
* reproduce or audit the derivation without holding an Identity
|
|
8
|
+
* instance.
|
|
9
|
+
*
|
|
10
|
+
* @param seed - The 64-byte BIP39 seed (specs/v1.0.md §2).
|
|
11
|
+
* @returns The 32-byte Ed25519 root private key.
|
|
12
|
+
* @since 0.8.0
|
|
13
|
+
*/
|
|
14
|
+
export declare function deriveRootKey(seed: Uint8Array): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Derives a Handle key from the root Identity key.
|
|
17
|
+
*
|
|
18
|
+
* `HKDF-SHA256(rootKey, salt = "", info = "me2em/handle/v1/{name}", 32)`.
|
|
19
|
+
* `name` is canonicalized (NFKC → lowercase → trim) by
|
|
20
|
+
* {@link DERIVATION_PATHS.handle}.
|
|
21
|
+
*
|
|
22
|
+
* @param rootKey - The 32-byte root private key (see {@link deriveRootKey}).
|
|
23
|
+
* @param name - The Handle name.
|
|
24
|
+
* @returns The 32-byte Ed25519 Handle private key.
|
|
25
|
+
* @since 0.8.0
|
|
26
|
+
*/
|
|
27
|
+
export declare function deriveHandleKey(rootKey: Uint8Array, name: string): Uint8Array;
|
|
28
|
+
/**
|
|
29
|
+
* Derives a SubHandle key from its parent Handle key — the single
|
|
30
|
+
* implementation shared by `Handle.deriveSubHandle` (autonomous,
|
|
31
|
+
* two-step from the Handle) and `Identity.deriveSubHandle` (atomic,
|
|
32
|
+
* from the Identity). Byte-parity of both entry points is pinned by
|
|
33
|
+
* test 5.3.3 (`derivation.spec.ts`) and by the golden vectors.
|
|
34
|
+
*
|
|
35
|
+
* `HKDF-SHA256(handleKey, salt = "",
|
|
36
|
+
* info = "me2em/subhandle/v1/{handleName}/{subName}", 32)`. Both names
|
|
37
|
+
* are canonicalized (NFKC → lowercase → trim) by
|
|
38
|
+
* {@link DERIVATION_PATHS.subhandle}.
|
|
39
|
+
*
|
|
40
|
+
* @param handleKey - The 32-byte parent Handle private key.
|
|
41
|
+
* @param handleName - The parent Handle name.
|
|
42
|
+
* @param subName - The SubHandle name.
|
|
43
|
+
* @returns The 32-byte Ed25519 SubHandle private key.
|
|
44
|
+
* @since 0.8.0
|
|
45
|
+
*/
|
|
46
|
+
export declare function deriveSubHandleKey(handleKey: Uint8Array, handleName: string, subName: string): Uint8Array;
|
|
47
|
+
//# sourceMappingURL=derivation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derivation.d.ts","sourceRoot":"","sources":["../../src/crypto/derivation.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAO1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAO7E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,UAAU,EACrB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,UAAU,CAOZ"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// packages/core/src/crypto/derivation.ts
|
|
2
|
+
//
|
|
3
|
+
// Key-derivation helpers shared by every derivation entry point
|
|
4
|
+
// (PR-10, tasks 3.2/5.3.3). `Identity.fromSeed`, `Identity.deriveHandle`,
|
|
5
|
+
// `Identity.deriveSubHandle` and `Handle.deriveSubHandle` all route
|
|
6
|
+
// through these functions, which is what guarantees the byte-parity the
|
|
7
|
+
// spec pins (specs/v1.0.md §3): the two-step derivation
|
|
8
|
+
// (`handle.deriveSubHandle`) and the atomic derivation
|
|
9
|
+
// (`identity.deriveSubHandle`) MUST produce the same SubHandle key.
|
|
10
|
+
//
|
|
11
|
+
// All functions derive with HKDF-SHA256 (RFC 5869), salt = "" (zero
|
|
12
|
+
// length), 32-byte output — see specs/v1.0.md §3. The info strings come
|
|
13
|
+
// exclusively from {@link DERIVATION_PATHS} (single source of truth).
|
|
14
|
+
import { hkdf } from './hkdf.js';
|
|
15
|
+
import { DERIVATION_PATHS } from './derivation-paths.js';
|
|
16
|
+
/**
|
|
17
|
+
* Derives the root Identity key from the 64-byte seed.
|
|
18
|
+
*
|
|
19
|
+
* `HKDF-SHA256(seed, salt = "", info = "me2em/identity/v1/root", 32)`
|
|
20
|
+
* (specs/v1.0.md §2–§3). This is the exact computation
|
|
21
|
+
* `Identity.fromSeed` performs; exposed so advanced callers can
|
|
22
|
+
* reproduce or audit the derivation without holding an Identity
|
|
23
|
+
* instance.
|
|
24
|
+
*
|
|
25
|
+
* @param seed - The 64-byte BIP39 seed (specs/v1.0.md §2).
|
|
26
|
+
* @returns The 32-byte Ed25519 root private key.
|
|
27
|
+
* @since 0.8.0
|
|
28
|
+
*/
|
|
29
|
+
export function deriveRootKey(seed) {
|
|
30
|
+
return hkdf(seed, new Uint8Array(0), new TextEncoder().encode(DERIVATION_PATHS.identity), 32);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Derives a Handle key from the root Identity key.
|
|
34
|
+
*
|
|
35
|
+
* `HKDF-SHA256(rootKey, salt = "", info = "me2em/handle/v1/{name}", 32)`.
|
|
36
|
+
* `name` is canonicalized (NFKC → lowercase → trim) by
|
|
37
|
+
* {@link DERIVATION_PATHS.handle}.
|
|
38
|
+
*
|
|
39
|
+
* @param rootKey - The 32-byte root private key (see {@link deriveRootKey}).
|
|
40
|
+
* @param name - The Handle name.
|
|
41
|
+
* @returns The 32-byte Ed25519 Handle private key.
|
|
42
|
+
* @since 0.8.0
|
|
43
|
+
*/
|
|
44
|
+
export function deriveHandleKey(rootKey, name) {
|
|
45
|
+
return hkdf(rootKey, new Uint8Array(0), new TextEncoder().encode(DERIVATION_PATHS.handle(name)), 32);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Derives a SubHandle key from its parent Handle key — the single
|
|
49
|
+
* implementation shared by `Handle.deriveSubHandle` (autonomous,
|
|
50
|
+
* two-step from the Handle) and `Identity.deriveSubHandle` (atomic,
|
|
51
|
+
* from the Identity). Byte-parity of both entry points is pinned by
|
|
52
|
+
* test 5.3.3 (`derivation.spec.ts`) and by the golden vectors.
|
|
53
|
+
*
|
|
54
|
+
* `HKDF-SHA256(handleKey, salt = "",
|
|
55
|
+
* info = "me2em/subhandle/v1/{handleName}/{subName}", 32)`. Both names
|
|
56
|
+
* are canonicalized (NFKC → lowercase → trim) by
|
|
57
|
+
* {@link DERIVATION_PATHS.subhandle}.
|
|
58
|
+
*
|
|
59
|
+
* @param handleKey - The 32-byte parent Handle private key.
|
|
60
|
+
* @param handleName - The parent Handle name.
|
|
61
|
+
* @param subName - The SubHandle name.
|
|
62
|
+
* @returns The 32-byte Ed25519 SubHandle private key.
|
|
63
|
+
* @since 0.8.0
|
|
64
|
+
*/
|
|
65
|
+
export function deriveSubHandleKey(handleKey, handleName, subName) {
|
|
66
|
+
return hkdf(handleKey, new Uint8Array(0), new TextEncoder().encode(DERIVATION_PATHS.subhandle(handleName, subName)), 32);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=derivation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derivation.js","sourceRoot":"","sources":["../../src/crypto/derivation.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,gEAAgE;AAChE,0EAA0E;AAC1E,oEAAoE;AACpE,wEAAwE;AACxE,wDAAwD;AACxD,uDAAuD;AACvD,oEAAoE;AACpE,EAAE;AACF,oEAAoE;AACpE,wEAAwE;AACxE,sEAAsE;AAEtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,IAAgB;IAC5C,OAAO,IAAI,CACT,IAAI,EACJ,IAAI,UAAU,CAAC,CAAC,CAAC,EACjB,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EACnD,EAAE,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAAC,OAAmB,EAAE,IAAY;IAC/D,OAAO,IAAI,CACT,OAAO,EACP,IAAI,UAAU,CAAC,CAAC,CAAC,EACjB,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EACvD,EAAE,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAAqB,EACrB,UAAkB,EAClB,OAAe;IAEf,OAAO,IAAI,CACT,SAAS,EACT,IAAI,UAAU,CAAC,CAAC,CAAC,EACjB,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,EACzE,EAAE,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the raw X25519 shared secret between this party's Ed25519
|
|
3
|
+
* private key and the peer's Ed25519 public key (both converted to the
|
|
4
|
+
* Montgomery form, RFC 7748). ECDH is symmetric, so the result is
|
|
5
|
+
* order-independent — and byte-identical on both peers.
|
|
6
|
+
*
|
|
7
|
+
* This is only the raw ECDH output. The protocol derivation
|
|
8
|
+
* ({@link Handle.deriveSharedSecret}) additionally binds both peers'
|
|
9
|
+
* public keys into the HKDF salt and expands with the P2P info string;
|
|
10
|
+
* never encrypt with the raw output alone.
|
|
11
|
+
*
|
|
12
|
+
* @param myPrivateKey - This party's 32-byte Ed25519 private key.
|
|
13
|
+
* @param otherPublicKey - The peer's 32-byte Ed25519 public key.
|
|
14
|
+
* @returns The 32-byte raw ECDH output — the HKDF IKM of the P2P
|
|
15
|
+
* derivation.
|
|
16
|
+
* @since 0.8.0
|
|
17
|
+
*/
|
|
18
|
+
export declare function rawX25519SharedSecret(myPrivateKey: Uint8Array, otherPublicKey: Uint8Array): Uint8Array;
|
|
19
|
+
//# sourceMappingURL=ecdh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecdh.d.ts","sourceRoot":"","sources":["../../src/crypto/ecdh.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,UAAU,EACxB,cAAc,EAAE,UAAU,GACzB,UAAU,CAIZ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// packages/core/src/crypto/ecdh.ts
|
|
2
|
+
//
|
|
3
|
+
// X25519 (Montgomery) ECDH step of the P2P shared-secret derivation
|
|
4
|
+
// (specs/v1.0.md §3 "P2P"): both Ed25519 keypairs are converted to the
|
|
5
|
+
// Montgomery form (RFC 7748) and the raw X25519 output becomes the HKDF
|
|
6
|
+
// IKM. Isolated here (PR-10, task 3.3.1) so that no protocol module
|
|
7
|
+
// imports `@noble/curves` directly — every crypto primitive lives
|
|
8
|
+
// under `crypto/` and reaches the rest of the codebase through
|
|
9
|
+
// documented wrappers.
|
|
10
|
+
import { ed25519, x25519 } from '@noble/curves/ed25519.js';
|
|
11
|
+
/**
|
|
12
|
+
* Computes the raw X25519 shared secret between this party's Ed25519
|
|
13
|
+
* private key and the peer's Ed25519 public key (both converted to the
|
|
14
|
+
* Montgomery form, RFC 7748). ECDH is symmetric, so the result is
|
|
15
|
+
* order-independent — and byte-identical on both peers.
|
|
16
|
+
*
|
|
17
|
+
* This is only the raw ECDH output. The protocol derivation
|
|
18
|
+
* ({@link Handle.deriveSharedSecret}) additionally binds both peers'
|
|
19
|
+
* public keys into the HKDF salt and expands with the P2P info string;
|
|
20
|
+
* never encrypt with the raw output alone.
|
|
21
|
+
*
|
|
22
|
+
* @param myPrivateKey - This party's 32-byte Ed25519 private key.
|
|
23
|
+
* @param otherPublicKey - The peer's 32-byte Ed25519 public key.
|
|
24
|
+
* @returns The 32-byte raw ECDH output — the HKDF IKM of the P2P
|
|
25
|
+
* derivation.
|
|
26
|
+
* @since 0.8.0
|
|
27
|
+
*/
|
|
28
|
+
export function rawX25519SharedSecret(myPrivateKey, otherPublicKey) {
|
|
29
|
+
const montgomerySecret = ed25519.utils.toMontgomerySecret(myPrivateKey);
|
|
30
|
+
const montgomeryPeer = ed25519.utils.toMontgomery(otherPublicKey);
|
|
31
|
+
return x25519.getSharedSecret(montgomerySecret, montgomeryPeer);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ecdh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecdh.js","sourceRoot":"","sources":["../../src/crypto/ecdh.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,EAAE;AACF,oEAAoE;AACpE,uEAAuE;AACvE,wEAAwE;AACxE,oEAAoE;AACpE,kEAAkE;AAClE,+DAA+D;AAC/D,uBAAuB;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAE3D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,qBAAqB,CACnC,YAAwB,EACxB,cAA0B;IAE1B,MAAM,gBAAgB,GAAG,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACxE,MAAM,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;IAClE,OAAO,MAAM,CAAC,eAAe,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;AAClE,CAAC"}
|