@me2em/core 0.4.4-alpha.1 → 0.6.0-alpha.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.
Files changed (92) hide show
  1. package/README.md +299 -766
  2. package/dist/attestation.d.ts +151 -0
  3. package/dist/attestation.d.ts.map +1 -0
  4. package/dist/attestation.js +279 -0
  5. package/dist/attestation.js.map +1 -0
  6. package/dist/canonical-name.d.ts +3 -0
  7. package/dist/canonical-name.d.ts.map +1 -0
  8. package/dist/canonical-name.js +12 -0
  9. package/dist/canonical-name.js.map +1 -0
  10. package/dist/crypto/derivation-paths.d.ts +41 -0
  11. package/dist/crypto/derivation-paths.d.ts.map +1 -0
  12. package/dist/crypto/derivation-paths.js +50 -0
  13. package/dist/crypto/derivation-paths.js.map +1 -0
  14. package/dist/crypto/ed25519.d.ts +52 -0
  15. package/dist/crypto/ed25519.d.ts.map +1 -0
  16. package/dist/crypto/ed25519.js +67 -0
  17. package/dist/crypto/ed25519.js.map +1 -0
  18. package/dist/crypto/hkdf.d.ts +13 -0
  19. package/dist/crypto/hkdf.d.ts.map +1 -0
  20. package/dist/crypto/hkdf.js +17 -0
  21. package/dist/crypto/hkdf.js.map +1 -0
  22. package/dist/crypto/index.d.ts +4 -0
  23. package/dist/crypto/index.d.ts.map +1 -0
  24. package/dist/crypto/index.js +5 -0
  25. package/dist/crypto/index.js.map +1 -0
  26. package/dist/crypto/init.d.ts +9 -0
  27. package/dist/crypto/init.d.ts.map +1 -0
  28. package/dist/crypto/init.js +17 -0
  29. package/dist/crypto/init.js.map +1 -0
  30. package/dist/handle.d.ts +206 -0
  31. package/dist/handle.d.ts.map +1 -0
  32. package/dist/handle.js +258 -0
  33. package/dist/handle.js.map +1 -0
  34. package/dist/identity.d.ts +123 -0
  35. package/dist/identity.d.ts.map +1 -0
  36. package/dist/identity.js +167 -0
  37. package/dist/identity.js.map +1 -0
  38. package/dist/index.d.ts +33 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +33 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/seed.d.ts +83 -0
  43. package/dist/seed.d.ts.map +1 -0
  44. package/dist/seed.js +117 -0
  45. package/dist/seed.js.map +1 -0
  46. package/dist/session.d.ts +231 -0
  47. package/dist/session.d.ts.map +1 -0
  48. package/dist/session.js +454 -0
  49. package/dist/session.js.map +1 -0
  50. package/dist/subhandle.d.ts +126 -0
  51. package/dist/subhandle.d.ts.map +1 -0
  52. package/dist/subhandle.js +158 -0
  53. package/dist/subhandle.js.map +1 -0
  54. package/dist/util.d.ts +9 -0
  55. package/dist/util.d.ts.map +1 -0
  56. package/dist/util.js +34 -0
  57. package/dist/util.js.map +1 -0
  58. package/package.json +36 -12
  59. package/src/attestation.ts +364 -0
  60. package/src/canonical-name.ts +12 -0
  61. package/src/crypto/derivation-paths.ts +56 -0
  62. package/src/crypto/ed25519.ts +86 -0
  63. package/{packages/core/src → src}/crypto/hkdf.ts +2 -0
  64. package/src/crypto/index.ts +4 -0
  65. package/{packages/core/src → src}/crypto/init.ts +1 -0
  66. package/src/handle.ts +320 -0
  67. package/src/identity.ts +218 -0
  68. package/{packages/core/src → src}/index.ts +5 -1
  69. package/{packages/core/src → src}/seed.ts +41 -54
  70. package/src/session.ts +660 -0
  71. package/src/subhandle.ts +230 -0
  72. package/src/util.ts +35 -0
  73. package/.github/workflows/ci.yml +0 -0
  74. package/CODE_OF_CONDUCT.md +0 -73
  75. package/CONTRIBUTING.md +0 -145
  76. package/GOVERNANCE.md +0 -132
  77. package/SECURITY.md +0 -70
  78. package/packages/core/README.md +0 -656
  79. package/packages/core/package.json +0 -44
  80. package/packages/core/src/crypto/ed25519.ts +0 -12
  81. package/packages/core/src/crypto/index.ts +0 -2
  82. package/packages/core/src/handle.ts +0 -130
  83. package/packages/core/src/identity.ts +0 -89
  84. package/packages/core/src/session.ts +0 -47
  85. package/packages/core/test/derivation.spec.ts +0 -117
  86. package/packages/core/tsconfig.json +0 -9
  87. package/pnpm-workspace.yaml +0 -2
  88. package/specs/core.md +0 -44
  89. package/specs/openapi/server-ref.yaml +0 -10
  90. package/specs/test-vectors.json +0 -13
  91. package/tsconfig.base.json +0 -20
  92. package/typedoc.json +0 -18
@@ -0,0 +1,67 @@
1
+ // packages/core/src/crypto/ed25519.ts
2
+ //
3
+ // Documented wrappers around the @noble/ed25519 primitives used by the
4
+ // protocol. These are real functions rather than alias re-exports, so
5
+ // generated documentation is fully owned by this package and never
6
+ // inherits comments (or broken links) from the upstream library.
7
+ import { ed } from './init.js';
8
+ /**
9
+ * Derives the Ed25519 public key for a private key (synchronous).
10
+ *
11
+ * @param privateKey - 32-byte Ed25519 private key.
12
+ * @returns The 32-byte public key.
13
+ * @throws `TypeError` if the key length is invalid.
14
+ * @throws `RangeError` if the key length is invalid.
15
+ */
16
+ export function getPublicKey(privateKey) {
17
+ return ed.getPublicKey(privateKey);
18
+ }
19
+ /**
20
+ * Signs a message with an Ed25519 private key (synchronous).
21
+ *
22
+ * @param message - The bytes to sign.
23
+ * @param privateKey - 32-byte Ed25519 private key.
24
+ * @returns The 64-byte signature.
25
+ * @throws `TypeError` if an input length is invalid.
26
+ * @throws `RangeError` if an input length is invalid.
27
+ */
28
+ export function sign(message, privateKey) {
29
+ return ed.sign(message, privateKey);
30
+ }
31
+ /**
32
+ * Verifies an Ed25519 signature (synchronous).
33
+ *
34
+ * @param signature - The 64-byte signature.
35
+ * @param message - The signed message bytes.
36
+ * @param publicKey - The 32-byte signer public key.
37
+ * @param opts - Optional verification options, forwarded to the
38
+ * underlying implementation.
39
+ * @returns `true` if the signature is valid, `false` otherwise.
40
+ * @throws `TypeError` if an input length is invalid.
41
+ * @throws `RangeError` if an input length is invalid.
42
+ */
43
+ export function verify(signature, message, publicKey, opts) {
44
+ return ed.verify(signature, message, publicKey, opts);
45
+ }
46
+ /**
47
+ * Asynchronous variant of {@link getPublicKey}; same contract.
48
+ */
49
+ export async function getPublicKeyAsync(privateKey) {
50
+ return ed.getPublicKeyAsync(privateKey);
51
+ }
52
+ /**
53
+ * Asynchronous variant of {@link sign}; same contract.
54
+ */
55
+ export async function signAsync(message, privateKey) {
56
+ return ed.signAsync(message, privateKey);
57
+ }
58
+ /**
59
+ * Asynchronous variant of {@link verify}; same contract.
60
+ *
61
+ * @param opts - Optional verification options, forwarded to the
62
+ * underlying implementation.
63
+ */
64
+ export async function verifyAsync(signature, message, publicKey, opts) {
65
+ return ed.verifyAsync(signature, message, publicKey, opts);
66
+ }
67
+ //# sourceMappingURL=ed25519.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ed25519.js","sourceRoot":"","sources":["../../src/crypto/ed25519.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,EAAE;AACF,uEAAuE;AACvE,sEAAsE;AACtE,mEAAmE;AACnE,iEAAiE;AAEjE,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAK/B;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,UAAsB;IACjD,OAAO,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAC,OAAmB,EAAE,UAAsB;IAC9D,OAAO,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CACpB,SAAqB,EACrB,OAAmB,EACnB,SAAqB,EACrB,IAAiB;IAEjB,OAAO,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,UAAsB;IAC5D,OAAO,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAmB,EAAE,UAAsB;IACzE,OAAO,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,SAAqB,EACrB,OAAmB,EACnB,SAAqB,EACrB,IAA2C;IAE3C,OAAO,EAAE,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { sha256 as nobleSha256 } from '@noble/hashes/sha2.js';
2
+ /**
3
+ * HKDF-SHA256 wrapper for me2em protocol
4
+ *
5
+ * @param ikm - Input key material
6
+ * @param salt - Salt (can be empty Uint8Array)
7
+ * @param info - Context info
8
+ * @param length - Output length in bytes
9
+ * @returns Derived key as Uint8Array
10
+ */
11
+ export declare function hkdf(ikm: Uint8Array, salt: Uint8Array, info: Uint8Array, length: number): Uint8Array;
12
+ export { nobleSha256 as sha256 };
13
+ //# sourceMappingURL=hkdf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../../src/crypto/hkdf.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAClB,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,GACb,UAAU,CAEZ;AAED,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ // packages/core/src/crypto/hkdf.ts
2
+ import { hkdf as nobleHkdf } from '@noble/hashes/hkdf.js';
3
+ import { sha256 as nobleSha256 } from '@noble/hashes/sha2.js';
4
+ /**
5
+ * HKDF-SHA256 wrapper for me2em protocol
6
+ *
7
+ * @param ikm - Input key material
8
+ * @param salt - Salt (can be empty Uint8Array)
9
+ * @param info - Context info
10
+ * @param length - Output length in bytes
11
+ * @returns Derived key as Uint8Array
12
+ */
13
+ export function hkdf(ikm, salt, info, length) {
14
+ return nobleHkdf(nobleSha256, ikm, salt, info, length);
15
+ }
16
+ export { nobleSha256 as sha256 };
17
+ //# sourceMappingURL=hkdf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hkdf.js","sourceRoot":"","sources":["../../src/crypto/hkdf.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAClB,GAAe,EACf,IAAgB,EAChB,IAAgB,EAChB,MAAc;IAEd,OAAO,SAAS,CAAC,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC;AAED,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './ed25519.js';
2
+ export * from './hkdf.js';
3
+ export * from './derivation-paths.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crypto/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,5 @@
1
+ // packages/core/src/crypto/index.ts
2
+ export * from './ed25519.js';
3
+ export * from './hkdf.js';
4
+ export * from './derivation-paths.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/crypto/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import * as ed from '@noble/ed25519';
2
+ import { sha512 } from '@noble/hashes/sha2.js';
3
+ /**
4
+ * Configure @noble/ed25519 for synchronous operations.
5
+ * Must be called before any ed25519 operation (sign, verify, getPublicKey).
6
+ */
7
+ export declare function initEd25519(): void;
8
+ export { ed, sha512 };
9
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/crypto/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAKlC;AAKD,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ // packages/core/src/crypto/init.ts
2
+ import * as ed from '@noble/ed25519';
3
+ import { sha512 } from '@noble/hashes/sha2.js';
4
+ /**
5
+ * Configure @noble/ed25519 for synchronous operations.
6
+ * Must be called before any ed25519 operation (sign, verify, getPublicKey).
7
+ */
8
+ export function initEd25519() {
9
+ // Configure sha512 for sync operations (required for @noble/ed25519 v3)
10
+ if (!ed.hashes.sha512) {
11
+ ed.hashes.sha512 = sha512;
12
+ }
13
+ }
14
+ // Auto-init on module load
15
+ initEd25519();
16
+ export { ed, sha512 };
17
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/crypto/init.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,wEAAwE;IACxE,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACtB,EAAE,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,2BAA2B;AAC3B,WAAW,EAAE,CAAC;AAEd,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,206 @@
1
+ import type { SubHandleMetadata, SubHandle } from './subhandle.js';
2
+ import { Attestation, type AttestationGrant } from './attestation.js';
3
+ /**
4
+ * Metadata associated with a {@link Handle}.
5
+ *
6
+ * All fields are optional and application-defined. The protocol does not
7
+ * interpret metadata; it is carried for convenience and may be serialized
8
+ * into tokens or stored by the application.
9
+ *
10
+ * @category Types
11
+ */
12
+ export interface HandleMetadata {
13
+ /** Human-readable display name. */
14
+ displayName?: string;
15
+ /** URL or data-URI of an avatar image. */
16
+ avatar?: string;
17
+ /** Arbitrary additional fields. */
18
+ [key: string]: unknown;
19
+ }
20
+ /**
21
+ * Represents a context-specific cryptographic handle derived from an {@link Identity}.
22
+ *
23
+ * A Handle encapsulates a private key tied to a specific name (context).
24
+ * It provides methods for signing data, verifying signatures, and deriving
25
+ * secondary secrets (passwords, channel keys, shared secrets) without ever
26
+ * exposing the underlying private key.
27
+ *
28
+ * A Handle can also derive {@link SubHandle}s for hierarchical access control
29
+ * (e.g., an IoT device deriving keys for its components). The private key
30
+ * **never leaves the Handle** — derivation is performed internally using HKDF.
31
+ *
32
+ * @category Core Primitives
33
+ */
34
+ export declare class Handle {
35
+ private readonly privateKey;
36
+ private readonly publicKey;
37
+ private readonly _name;
38
+ private readonly _metadata?;
39
+ /**
40
+ * Creates a new Handle instance.
41
+ *
42
+ * @internal Typically created via {@link Identity.deriveHandle} or
43
+ * {@link Handle.deriveSubHandle}. Direct construction is discouraged.
44
+ *
45
+ * @param privateKey - The 32-byte Ed25519 private key for this handle.
46
+ * @param name - The context name this handle represents.
47
+ * @param metadata - Optional metadata associated with this handle.
48
+ */
49
+ constructor(privateKey: Uint8Array, name: string, metadata?: HandleMetadata);
50
+ /**
51
+ * Returns a URL-safe Base64-encoded identifier for this Handle,
52
+ * derived from its public key.
53
+ *
54
+ * @returns A unique, URL-safe string identifier.
55
+ */
56
+ getId(): string;
57
+ /**
58
+ * Cryptographically signs arbitrary data using the Handle's private key.
59
+ *
60
+ * @param data - The data to be signed, as a Uint8Array.
61
+ * @returns A Promise resolving to the Ed25519 signature as a Uint8Array.
62
+ */
63
+ sign(data: Uint8Array): Promise<Uint8Array>;
64
+ /**
65
+ * Verifies an Ed25519 signature against the provided data and public key.
66
+ *
67
+ * @param signature - The signature to verify (Uint8Array).
68
+ * @param data - The original data that was signed (Uint8Array).
69
+ * @param publicKey - The public key to verify against (Uint8Array).
70
+ * @returns A Promise resolving to `true` if the signature is valid, `false` otherwise.
71
+ */
72
+ static verify(signature: Uint8Array, data: Uint8Array, publicKey: Uint8Array): Promise<boolean>;
73
+ /** @returns The context name associated with this Handle. */
74
+ getName(): string;
75
+ /** @returns The metadata object associated with this Handle. */
76
+ getMetadata(): HandleMetadata | undefined;
77
+ /** @returns A Uint8Array containing the 32-byte Ed25519 public key. */
78
+ getPublicKey(): Uint8Array;
79
+ /** @returns The derivation path, or undefined for Handle (only SubHandle has a path). */
80
+ getPath(): string[] | undefined;
81
+ /**
82
+ * Validates session options against this Handle's constraints.
83
+ * Handle has no constraints.
84
+ */
85
+ validateSessionOptions(_options: {
86
+ audience: string;
87
+ scopes: string[];
88
+ ttl: number;
89
+ }): void;
90
+ /**
91
+ * Derives a {@link SubHandle} from this Handle.
92
+ *
93
+ * This is the **autonomous entry point** for IoT devices and other contexts
94
+ * where the Identity is not available locally. The Handle uses its own
95
+ * private key internally (it never leaves the class) to derive a child key
96
+ * via HKDF-SHA256.
97
+ *
98
+ * The resulting SubHandle is cryptographically identical to the one produced
99
+ * by `Identity.deriveSubHandle(this.name, subName)`.
100
+ *
101
+ * @param name - The SubHandle name (will be normalized).
102
+ * @param metadata - Optional SubHandle metadata with constraints.
103
+ * @returns A Promise resolving to the derived SubHandle with path `[this.name, name]`.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * // On an IoT device (no Identity available)
108
+ * const connector = await stationHandle.deriveSubHandle('connector-1', {
109
+ * allowedScopes: ['charge:start'],
110
+ * maxSessionTtl: 3600
111
+ * });
112
+ * ```
113
+ */
114
+ deriveSubHandle(name: string, metadata?: SubHandleMetadata): Promise<SubHandle>;
115
+ /**
116
+ * Issues an attestation for a derived SubHandle, binding its
117
+ * derived key to the name and grant. Autonomous: requires only
118
+ * this Handle's own key, no Identity and no network.
119
+ *
120
+ * The child key is derived internally, so the attestation's
121
+ * `subjectId` always equals the key produced by
122
+ * `identity.deriveSubHandle(this.name, subName)`.
123
+ *
124
+ * Note: this method does not check this Handle's own grant — it may
125
+ * not have one (Mode 1). Nesting is enforced by verifiers in
126
+ * `Session.verifyAttested` (a child grant exceeding the parent's is
127
+ * rejected with `SCOPE_EXCEEDED`/`TTL_EXCEEDED` at level ROOT).
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * const B = await station.attestSubHandle('connector-ccs', {
132
+ * audiences: ['ev-app.com'],
133
+ * scopes: ['charge:start', 'charge:stop'],
134
+ * maxSessionTtl: 7200,
135
+ * }, { ttlSeconds: 1800 });
136
+ * // Ship [A.token, B.token] together with the session token.
137
+ * ```
138
+ */
139
+ attestSubHandle(subName: string, grant: AttestationGrant, opts?: {
140
+ ttlSeconds?: number;
141
+ expiresAt?: number;
142
+ jti?: string;
143
+ now?: number;
144
+ }): Promise<Attestation>;
145
+ /**
146
+ * Deterministically derives a secret (e.g., a password or API key) for a
147
+ * specific service context.
148
+ *
149
+ * The private key **never leaves this class**, ensuring maximum security.
150
+ *
151
+ * @param context - A unique identifier for the service (e.g., `'google'`, `'github'`).
152
+ * @param length - Length of the derived raw bytes (default: 16 bytes ≈ 22 chars base64url).
153
+ * @returns A URL-safe base64 string suitable for use as a strong password.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * const githubPassword = handle.derivePassword('github', 20);
158
+ * ```
159
+ */
160
+ derivePassword(context: string, length?: number): string;
161
+ /**
162
+ * Derives a symmetric 256-bit channel key for secure communication between
163
+ * the Identity (controller) and this Handle (device/context).
164
+ *
165
+ * Both parties can independently compute this key because:
166
+ * - The Handle possesses its own private key directly.
167
+ * - The Identity can derive the same private key via `identity.deriveHandle(name)`.
168
+ *
169
+ * This enables zero-knowledge encrypted channels without key exchange protocols.
170
+ *
171
+ * @param context - Channel identifier for domain separation (e.g., `'drone-001'`).
172
+ * Both parties **MUST** use the same context.
173
+ * @returns A 32-byte Uint8Array suitable for AES-256-GCM encryption.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * // On the drone (Handle side):
178
+ * const channelKey = droneHandle.deriveChannelKey('telemetry-v1');
179
+ * const encrypted = await encryptAESGCM(telemetry, channelKey);
180
+ *
181
+ * // On the control center (Identity side):
182
+ * const droneHandle = await centerIdentity.deriveHandle('drone-001');
183
+ * const channelKey = droneHandle.deriveChannelKey('telemetry-v1');
184
+ * const decrypted = await decryptAESGCM(encrypted, channelKey);
185
+ * ```
186
+ */
187
+ deriveChannelKey(context: string): Uint8Array;
188
+ /**
189
+ * Derives a shared secret using ECDH (X25519) for P2P key exchange.
190
+ *
191
+ * Converts the Ed25519 keypair to X25519 for Diffie-Hellman key agreement,
192
+ * then applies HKDF-SHA256 to produce a clean 32-byte channel key.
193
+ *
194
+ * @param otherPublicKey - The Ed25519 public key of the other party (32 bytes).
195
+ * @returns A Promise resolving to a 32-byte shared secret suitable for AES-256-GCM.
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * const aliceShared = await aliceHandle.deriveSharedSecret(bobHandle.getPublicKey());
200
+ * const bobShared = await bobHandle.deriveSharedSecret(aliceHandle.getPublicKey());
201
+ * // aliceShared === bobShared
202
+ * ```
203
+ */
204
+ deriveSharedSecret(otherPublicKey: Uint8Array): Promise<Uint8Array>;
205
+ }
206
+ //# sourceMappingURL=handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle.d.ts","s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,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;KACjD,GAAG,IAAI;IAER;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC;IAkBrF;;;;;;;;;;;;;;;;;;;;;;;QAuBI;IACG,eAAe,CACpB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,gBAAgB,EACvB,IAAI,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GAC7E,OAAO,CAAC,WAAW,CAAC;IAYvB;;;;;;;;;;;;;;OAcG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW,GAAG,MAAM;IAU5D;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU;IAM7C;;;;;;;;;;;;;;;OAeG;IACG,kBAAkB,CAAC,cAAc,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAgC1E"}
package/dist/handle.js ADDED
@@ -0,0 +1,258 @@
1
+ // handle.ts
2
+ import { ed } from './crypto/init.js';
3
+ import { hkdf } from '@noble/hashes/hkdf.js';
4
+ import { sha256 } from '@noble/hashes/sha2.js';
5
+ import { ed25519, x25519 } from '@noble/curves/ed25519.js';
6
+ import { normalizeName } from './canonical-name.js';
7
+ import { DERIVATION_PATHS } from './crypto/derivation-paths.js';
8
+ import { Attestation } from './attestation.js';
9
+ /**
10
+ * Represents a context-specific cryptographic handle derived from an {@link Identity}.
11
+ *
12
+ * A Handle encapsulates a private key tied to a specific name (context).
13
+ * It provides methods for signing data, verifying signatures, and deriving
14
+ * secondary secrets (passwords, channel keys, shared secrets) without ever
15
+ * exposing the underlying private key.
16
+ *
17
+ * A Handle can also derive {@link SubHandle}s for hierarchical access control
18
+ * (e.g., an IoT device deriving keys for its components). The private key
19
+ * **never leaves the Handle** — derivation is performed internally using HKDF.
20
+ *
21
+ * @category Core Primitives
22
+ */
23
+ export class Handle {
24
+ privateKey;
25
+ publicKey;
26
+ _name;
27
+ _metadata;
28
+ /**
29
+ * Creates a new Handle instance.
30
+ *
31
+ * @internal Typically created via {@link Identity.deriveHandle} or
32
+ * {@link Handle.deriveSubHandle}. Direct construction is discouraged.
33
+ *
34
+ * @param privateKey - The 32-byte Ed25519 private key for this handle.
35
+ * @param name - The context name this handle represents.
36
+ * @param metadata - Optional metadata associated with this handle.
37
+ */
38
+ constructor(privateKey, name, metadata) {
39
+ this.privateKey = privateKey;
40
+ this.publicKey = ed.getPublicKey(privateKey);
41
+ this._name = name;
42
+ this._metadata = metadata;
43
+ }
44
+ /**
45
+ * Returns a URL-safe Base64-encoded identifier for this Handle,
46
+ * derived from its public key.
47
+ *
48
+ * @returns A unique, URL-safe string identifier.
49
+ */
50
+ getId() {
51
+ return btoa(String.fromCharCode(...this.publicKey))
52
+ .replace(/\+/g, '-')
53
+ .replace(/\//g, '_')
54
+ .replace(/=+$/, '');
55
+ }
56
+ /**
57
+ * Cryptographically signs arbitrary data using the Handle's private key.
58
+ *
59
+ * @param data - The data to be signed, as a Uint8Array.
60
+ * @returns A Promise resolving to the Ed25519 signature as a Uint8Array.
61
+ */
62
+ async sign(data) {
63
+ return ed.sign(data, this.privateKey);
64
+ }
65
+ /**
66
+ * Verifies an Ed25519 signature against the provided data and public key.
67
+ *
68
+ * @param signature - The signature to verify (Uint8Array).
69
+ * @param data - The original data that was signed (Uint8Array).
70
+ * @param publicKey - The public key to verify against (Uint8Array).
71
+ * @returns A Promise resolving to `true` if the signature is valid, `false` otherwise.
72
+ */
73
+ static async verify(signature, data, publicKey) {
74
+ return ed.verify(signature, data, publicKey);
75
+ }
76
+ /** @returns The context name associated with this Handle. */
77
+ getName() {
78
+ return this._name;
79
+ }
80
+ /** @returns The metadata object associated with this Handle. */
81
+ getMetadata() {
82
+ return this._metadata;
83
+ }
84
+ /** @returns A Uint8Array containing the 32-byte Ed25519 public key. */
85
+ getPublicKey() {
86
+ return this.publicKey;
87
+ }
88
+ /** @returns The derivation path, or undefined for Handle (only SubHandle has a path). */
89
+ getPath() {
90
+ return undefined;
91
+ }
92
+ /**
93
+ * Validates session options against this Handle's constraints.
94
+ * Handle has no constraints.
95
+ */
96
+ validateSessionOptions(_options) { }
97
+ /**
98
+ * Derives a {@link SubHandle} from this Handle.
99
+ *
100
+ * This is the **autonomous entry point** for IoT devices and other contexts
101
+ * where the Identity is not available locally. The Handle uses its own
102
+ * private key internally (it never leaves the class) to derive a child key
103
+ * via HKDF-SHA256.
104
+ *
105
+ * The resulting SubHandle is cryptographically identical to the one produced
106
+ * by `Identity.deriveSubHandle(this.name, subName)`.
107
+ *
108
+ * @param name - The SubHandle name (will be normalized).
109
+ * @param metadata - Optional SubHandle metadata with constraints.
110
+ * @returns A Promise resolving to the derived SubHandle with path `[this.name, name]`.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * // On an IoT device (no Identity available)
115
+ * const connector = await stationHandle.deriveSubHandle('connector-1', {
116
+ * allowedScopes: ['charge:start'],
117
+ * maxSessionTtl: 3600
118
+ * });
119
+ * ```
120
+ */
121
+ async deriveSubHandle(name, metadata) {
122
+ const normalizedName = normalizeName(name);
123
+ const info = new TextEncoder().encode(DERIVATION_PATHS.subhandle(this._name, normalizedName));
124
+ // The private key is used internally and never leaves this class.
125
+ const subKey = hkdf(sha256, this.privateKey, new Uint8Array(0), info, 32);
126
+ const path = [this._name, normalizedName];
127
+ const { SubHandle: SubHandleClass } = await import('./subhandle.js');
128
+ return new SubHandleClass(subKey, normalizedName, path, metadata);
129
+ }
130
+ /**
131
+ * Issues an attestation for a derived SubHandle, binding its
132
+ * derived key to the name and grant. Autonomous: requires only
133
+ * this Handle's own key, no Identity and no network.
134
+ *
135
+ * The child key is derived internally, so the attestation's
136
+ * `subjectId` always equals the key produced by
137
+ * `identity.deriveSubHandle(this.name, subName)`.
138
+ *
139
+ * Note: this method does not check this Handle's own grant — it may
140
+ * not have one (Mode 1). Nesting is enforced by verifiers in
141
+ * `Session.verifyAttested` (a child grant exceeding the parent's is
142
+ * rejected with `SCOPE_EXCEEDED`/`TTL_EXCEEDED` at level ROOT).
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const B = await station.attestSubHandle('connector-ccs', {
147
+ * audiences: ['ev-app.com'],
148
+ * scopes: ['charge:start', 'charge:stop'],
149
+ * maxSessionTtl: 7200,
150
+ * }, { ttlSeconds: 1800 });
151
+ * // Ship [A.token, B.token] together with the session token.
152
+ * ```
153
+ */
154
+ async attestSubHandle(subName, grant, opts) {
155
+ const normalized = normalizeName(subName);
156
+ const sub = await this.deriveSubHandle(normalized);
157
+ return Attestation.issue(this.privateKey, sub.getPublicKey(), normalized, grant, opts ?? {});
158
+ }
159
+ /**
160
+ * Deterministically derives a secret (e.g., a password or API key) for a
161
+ * specific service context.
162
+ *
163
+ * The private key **never leaves this class**, ensuring maximum security.
164
+ *
165
+ * @param context - A unique identifier for the service (e.g., `'google'`, `'github'`).
166
+ * @param length - Length of the derived raw bytes (default: 16 bytes ≈ 22 chars base64url).
167
+ * @returns A URL-safe base64 string suitable for use as a strong password.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * const githubPassword = handle.derivePassword('github', 20);
172
+ * ```
173
+ */
174
+ derivePassword(context, length = 16) {
175
+ const salt = new TextEncoder().encode(`me2em/secret/${context.toLowerCase().trim()}`);
176
+ const info = new TextEncoder().encode('me2em/secret/v1');
177
+ const secretBytes = hkdf(sha256, this.privateKey, salt, info, length);
178
+ return btoa(String.fromCharCode(...secretBytes))
179
+ .replace(/\+/g, '-')
180
+ .replace(/\//g, '_')
181
+ .replace(/=+$/, '');
182
+ }
183
+ /**
184
+ * Derives a symmetric 256-bit channel key for secure communication between
185
+ * the Identity (controller) and this Handle (device/context).
186
+ *
187
+ * Both parties can independently compute this key because:
188
+ * - The Handle possesses its own private key directly.
189
+ * - The Identity can derive the same private key via `identity.deriveHandle(name)`.
190
+ *
191
+ * This enables zero-knowledge encrypted channels without key exchange protocols.
192
+ *
193
+ * @param context - Channel identifier for domain separation (e.g., `'drone-001'`).
194
+ * Both parties **MUST** use the same context.
195
+ * @returns A 32-byte Uint8Array suitable for AES-256-GCM encryption.
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * // On the drone (Handle side):
200
+ * const channelKey = droneHandle.deriveChannelKey('telemetry-v1');
201
+ * const encrypted = await encryptAESGCM(telemetry, channelKey);
202
+ *
203
+ * // On the control center (Identity side):
204
+ * const droneHandle = await centerIdentity.deriveHandle('drone-001');
205
+ * const channelKey = droneHandle.deriveChannelKey('telemetry-v1');
206
+ * const decrypted = await decryptAESGCM(encrypted, channelKey);
207
+ * ```
208
+ */
209
+ deriveChannelKey(context) {
210
+ const salt = new TextEncoder().encode(`me2em/channel/${context.toLowerCase().trim()}`);
211
+ const info = new TextEncoder().encode('me2em/channel/v1');
212
+ return hkdf(sha256, this.privateKey, salt, info, 32);
213
+ }
214
+ /**
215
+ * Derives a shared secret using ECDH (X25519) for P2P key exchange.
216
+ *
217
+ * Converts the Ed25519 keypair to X25519 for Diffie-Hellman key agreement,
218
+ * then applies HKDF-SHA256 to produce a clean 32-byte channel key.
219
+ *
220
+ * @param otherPublicKey - The Ed25519 public key of the other party (32 bytes).
221
+ * @returns A Promise resolving to a 32-byte shared secret suitable for AES-256-GCM.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * const aliceShared = await aliceHandle.deriveSharedSecret(bobHandle.getPublicKey());
226
+ * const bobShared = await bobHandle.deriveSharedSecret(aliceHandle.getPublicKey());
227
+ * // aliceShared === bobShared
228
+ * ```
229
+ */
230
+ async deriveSharedSecret(otherPublicKey) {
231
+ const myPrivBytes = this.privateKey;
232
+ const otherPubBytes = otherPublicKey;
233
+ if (myPrivBytes.length !== 32) {
234
+ throw new Error('Handle private key must be 32 bytes');
235
+ }
236
+ if (otherPubBytes.length !== 32) {
237
+ throw new Error('Public key must be 32 bytes');
238
+ }
239
+ const x25519Priv = ed25519.utils.toMontgomerySecret(myPrivBytes);
240
+ const x25519Pub = ed25519.utils.toMontgomery(otherPubBytes);
241
+ const rawSharedSecret = x25519.getSharedSecret(x25519Priv, x25519Pub);
242
+ // Canonical, order-independent binding of both peers' public keys.
243
+ const myPub = this.getPublicKey();
244
+ const peers = [myPub, otherPubBytes].sort((a, b) => {
245
+ for (let i = 0; i < 32; i++) {
246
+ if (a[i] !== b[i])
247
+ return a[i] - b[i];
248
+ }
249
+ return 0;
250
+ });
251
+ const bound = new Uint8Array(64);
252
+ bound.set(peers[0], 0);
253
+ bound.set(peers[1], 32);
254
+ const info = new TextEncoder().encode(DERIVATION_PATHS.p2pChannelV2);
255
+ return hkdf(sha256, rawSharedSecret, bound, info, 32);
256
+ }
257
+ }
258
+ //# sourceMappingURL=handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAyB,MAAM,kBAAkB,CAAC;AAoBtE;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,MAAM;IACA,UAAU,CAAa;IACvB,SAAS,CAA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