@me2em/core 0.7.0-alpha.2 → 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 +179 -32
- 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 +10 -1
- package/dist/crypto/hkdf.d.ts.map +1 -1
- package/dist/crypto/hkdf.js +10 -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 +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/seed.d.ts +15 -11
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +23 -17
- 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 +10 -4
- 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 +10 -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 +10 -6
- package/src/seed.ts +27 -17
- 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/subhandle.d.ts
CHANGED
|
@@ -1,126 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Metadata for a {@link SubHandle}, extending {@link HandleMetadata} with
|
|
4
|
-
* constraints that govern session creation.
|
|
5
|
-
*
|
|
6
|
-
* All constraint fields are optional. When present, they are enforced by
|
|
7
|
-
* {@link SubHandle.validateSessionOptions} at session creation time.
|
|
8
|
-
*
|
|
9
|
-
* @category Types
|
|
10
|
-
*/
|
|
11
|
-
export interface SubHandleMetadata extends HandleMetadata {
|
|
12
|
-
/**
|
|
13
|
-
* Restricts the set of audiences this SubHandle may create sessions for.
|
|
14
|
-
* `undefined` = unrestricted; `[]` = deny all.
|
|
15
|
-
*/
|
|
16
|
-
allowedAudiences?: string[];
|
|
17
|
-
/**
|
|
18
|
-
* Restricts the set of scopes this SubHandle may request in sessions.
|
|
19
|
-
* `undefined` = unrestricted; `[]` = deny all.
|
|
20
|
-
*/
|
|
21
|
-
allowedScopes?: string[];
|
|
22
|
-
/**
|
|
23
|
-
* Maximum allowed TTL (in seconds) for sessions created by this SubHandle.
|
|
24
|
-
* Attempts to create a session with a larger TTL will be rejected.
|
|
25
|
-
*/
|
|
26
|
-
maxSessionTtl?: number;
|
|
27
|
-
/**
|
|
28
|
-
* Unix timestamp (in seconds) at which this SubHandle itself expires.
|
|
29
|
-
* After this time, any attempt to create a session will fail.
|
|
30
|
-
* Useful for temporary access grants (e.g., contractor access for 2 weeks).
|
|
31
|
-
*/
|
|
32
|
-
expiresAt?: number;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Represents a context-isolated child Handle in the Me2em hierarchy.
|
|
36
|
-
*
|
|
37
|
-
* A SubHandle is always derived from a parent {@link Handle} and represents
|
|
38
|
-
* a leaf node in the derivation tree (MAX_DEPTH = 2). It inherits all
|
|
39
|
-
* cryptographic capabilities of Handle (signing, key derivation, etc.) but
|
|
40
|
-
* adds:
|
|
41
|
-
*
|
|
42
|
-
* - A **derivation path** (`[handleName, subName]`) carried in session tokens.
|
|
43
|
-
* - **Constraint enforcement** on audience, scopes, and TTL at session creation.
|
|
44
|
-
* - An optional **expiration timestamp** for temporary access grants.
|
|
45
|
-
*
|
|
46
|
-
* SubHandle is used for polymorphism in {@link Session}: both Handle and
|
|
47
|
-
* SubHandle can create and verify sessions, but SubHandle sessions carry
|
|
48
|
-
* the additional `hPath` field for hierarchical auditing.
|
|
49
|
-
*
|
|
50
|
-
* @category Core Primitives
|
|
51
|
-
*/
|
|
52
|
-
export declare class SubHandle extends Handle {
|
|
53
|
-
private readonly _path;
|
|
54
|
-
private readonly _subMetadata;
|
|
55
|
-
/**
|
|
56
|
-
* Creates a new SubHandle instance.
|
|
57
|
-
*
|
|
58
|
-
* @internal Typically created via {@link Handle.deriveSubHandle} or
|
|
59
|
-
* {@link Identity.deriveSubHandle}. Direct construction is discouraged.
|
|
60
|
-
*
|
|
61
|
-
* @param privateKey - The 32-byte Ed25519 private key for this SubHandle.
|
|
62
|
-
* @param name - The SubHandle name.
|
|
63
|
-
* @param path - The derivation path, must have exactly 2 elements: `[handleName, subName]`.
|
|
64
|
-
* @param subMetadata - Optional constraints and metadata.
|
|
65
|
-
* @throws {Error} If the path does not have exactly 2 elements.
|
|
66
|
-
*/
|
|
67
|
-
constructor(privateKey: Uint8Array, name: string, path: string[], subMetadata?: SubHandleMetadata);
|
|
68
|
-
/**
|
|
69
|
-
* Returns the full derivation path of this SubHandle.
|
|
70
|
-
*
|
|
71
|
-
* @returns A copy of the path array, e.g. `["station-001", "connector-1"]`.
|
|
72
|
-
*/
|
|
73
|
-
getPath(): string[];
|
|
74
|
-
/**
|
|
75
|
-
* Returns the derivation path as a slash-separated string.
|
|
76
|
-
*
|
|
77
|
-
* @returns The path string, e.g. `"station-001/connector-1"`.
|
|
78
|
-
*/
|
|
79
|
-
getPathString(): string;
|
|
80
|
-
/**
|
|
81
|
-
* Returns the depth of this SubHandle in the derivation hierarchy.
|
|
82
|
-
*
|
|
83
|
-
* With MAX_DEPTH = 2, this is always `2` (Identity = 0, Handle = 1, SubHandle = 2).
|
|
84
|
-
*
|
|
85
|
-
* @returns The depth, always `2`.
|
|
86
|
-
*/
|
|
87
|
-
getDepth(): number;
|
|
88
|
-
/**
|
|
89
|
-
* Returns whether this SubHandle is a leaf node.
|
|
90
|
-
*
|
|
91
|
-
* With MAX_DEPTH = 2, a SubHandle is **always** a leaf and cannot derive children.
|
|
92
|
-
*
|
|
93
|
-
* @returns Always `true`.
|
|
94
|
-
*/
|
|
95
|
-
isLeaf(): boolean;
|
|
96
|
-
/**
|
|
97
|
-
* SubHandle is a leaf node (depth = 2) and cannot derive children.
|
|
98
|
-
* Overrides the inherited `Handle.deriveSubHandle` to throw an error.
|
|
99
|
-
*/
|
|
100
|
-
deriveSubHandle(): Promise<never>;
|
|
101
|
-
/**
|
|
102
|
-
* Returns the SubHandle-specific metadata (constraints).
|
|
103
|
-
*
|
|
104
|
-
* @returns The SubHandleMetadata object.
|
|
105
|
-
*/
|
|
106
|
-
getSubMetadata(): SubHandleMetadata;
|
|
107
|
-
/**
|
|
108
|
-
* Validates session options against this SubHandle's constraints.
|
|
109
|
-
*
|
|
110
|
-
* Called internally by {@link Session.create} before signing. Throws if
|
|
111
|
-
* any constraint is violated:
|
|
112
|
-
* - `audience` not in `allowedAudiences`
|
|
113
|
-
* - any `scope` not in `allowedScopes`
|
|
114
|
-
* - `ttl` exceeds `maxSessionTtl`
|
|
115
|
-
* - current time is past `expiresAt`
|
|
116
|
-
*
|
|
117
|
-
* @param options - The session options to validate.
|
|
118
|
-
* @throws {Error} If any constraint is violated.
|
|
119
|
-
*/
|
|
120
|
-
validateSessionOptions(options: {
|
|
121
|
-
audience: string;
|
|
122
|
-
scopes: string[];
|
|
123
|
-
ttl: number;
|
|
124
|
-
}): void;
|
|
125
|
-
}
|
|
1
|
+
export { SubHandle, type SubHandleMetadata } from './handle.js';
|
|
126
2
|
//# sourceMappingURL=subhandle.d.ts.map
|
package/dist/subhandle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subhandle.d.ts","sourceRoot":"","sources":["../src/subhandle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"subhandle.d.ts","sourceRoot":"","sources":["../src/subhandle.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/subhandle.js
CHANGED
|
@@ -1,182 +1,15 @@
|
|
|
1
1
|
// subhandle.ts
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return undefined;
|
|
16
|
-
const display = {};
|
|
17
|
-
if (meta.displayName !== undefined)
|
|
18
|
-
display.displayName = meta.displayName;
|
|
19
|
-
if (meta.avatar !== undefined)
|
|
20
|
-
display.avatar = meta.avatar;
|
|
21
|
-
// copy any other custom fields, but never the constraint ones
|
|
22
|
-
const CONSTRAINT_KEYS = new Set([
|
|
23
|
-
'allowedAudiences', 'allowedScopes', 'maxSessionTtl', 'expiresAt',
|
|
24
|
-
]);
|
|
25
|
-
for (const [k, v] of Object.entries(meta)) {
|
|
26
|
-
if (!CONSTRAINT_KEYS.has(k)) {
|
|
27
|
-
display[k] = v;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return display;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Represents a context-isolated child Handle in the Me2em hierarchy.
|
|
34
|
-
*
|
|
35
|
-
* A SubHandle is always derived from a parent {@link Handle} and represents
|
|
36
|
-
* a leaf node in the derivation tree (MAX_DEPTH = 2). It inherits all
|
|
37
|
-
* cryptographic capabilities of Handle (signing, key derivation, etc.) but
|
|
38
|
-
* adds:
|
|
39
|
-
*
|
|
40
|
-
* - A **derivation path** (`[handleName, subName]`) carried in session tokens.
|
|
41
|
-
* - **Constraint enforcement** on audience, scopes, and TTL at session creation.
|
|
42
|
-
* - An optional **expiration timestamp** for temporary access grants.
|
|
43
|
-
*
|
|
44
|
-
* SubHandle is used for polymorphism in {@link Session}: both Handle and
|
|
45
|
-
* SubHandle can create and verify sessions, but SubHandle sessions carry
|
|
46
|
-
* the additional `hPath` field for hierarchical auditing.
|
|
47
|
-
*
|
|
48
|
-
* @category Core Primitives
|
|
49
|
-
*/
|
|
50
|
-
export class SubHandle extends Handle {
|
|
51
|
-
_path;
|
|
52
|
-
_subMetadata;
|
|
53
|
-
/**
|
|
54
|
-
* Creates a new SubHandle instance.
|
|
55
|
-
*
|
|
56
|
-
* @internal Typically created via {@link Handle.deriveSubHandle} or
|
|
57
|
-
* {@link Identity.deriveSubHandle}. Direct construction is discouraged.
|
|
58
|
-
*
|
|
59
|
-
* @param privateKey - The 32-byte Ed25519 private key for this SubHandle.
|
|
60
|
-
* @param name - The SubHandle name.
|
|
61
|
-
* @param path - The derivation path, must have exactly 2 elements: `[handleName, subName]`.
|
|
62
|
-
* @param subMetadata - Optional constraints and metadata.
|
|
63
|
-
* @throws {Error} If the path does not have exactly 2 elements.
|
|
64
|
-
*/
|
|
65
|
-
constructor(privateKey, name, path, subMetadata) {
|
|
66
|
-
super(privateKey, name, extractDisplayFields(subMetadata));
|
|
67
|
-
if (path.length !== 2) {
|
|
68
|
-
throw new Error(`SubHandle path must have exactly 2 elements: [handleName, subName]. Got ${path.length}.`);
|
|
69
|
-
}
|
|
70
|
-
const normalizedName = normalizeName(name);
|
|
71
|
-
if (path[1] !== normalizedName) {
|
|
72
|
-
throw new Error(`path[1] must equal normalized name: path[1]=${JSON.stringify(path[1])}, name=${JSON.stringify(normalizedName)}`);
|
|
73
|
-
}
|
|
74
|
-
this._path = path;
|
|
75
|
-
this._subMetadata = subMetadata ?? {};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Returns the full derivation path of this SubHandle.
|
|
79
|
-
*
|
|
80
|
-
* @returns A copy of the path array, e.g. `["station-001", "connector-1"]`.
|
|
81
|
-
*/
|
|
82
|
-
getPath() {
|
|
83
|
-
return [...this._path];
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Returns the derivation path as a slash-separated string.
|
|
87
|
-
*
|
|
88
|
-
* @returns The path string, e.g. `"station-001/connector-1"`.
|
|
89
|
-
*/
|
|
90
|
-
getPathString() {
|
|
91
|
-
return this._path.join('/');
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Returns the depth of this SubHandle in the derivation hierarchy.
|
|
95
|
-
*
|
|
96
|
-
* With MAX_DEPTH = 2, this is always `2` (Identity = 0, Handle = 1, SubHandle = 2).
|
|
97
|
-
*
|
|
98
|
-
* @returns The depth, always `2`.
|
|
99
|
-
*/
|
|
100
|
-
getDepth() {
|
|
101
|
-
return 2;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Returns whether this SubHandle is a leaf node.
|
|
105
|
-
*
|
|
106
|
-
* With MAX_DEPTH = 2, a SubHandle is **always** a leaf and cannot derive children.
|
|
107
|
-
*
|
|
108
|
-
* @returns Always `true`.
|
|
109
|
-
*/
|
|
110
|
-
isLeaf() {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* SubHandle is a leaf node (depth = 2) and cannot derive children.
|
|
115
|
-
* Overrides the inherited `Handle.deriveSubHandle` to throw an error.
|
|
116
|
-
*/
|
|
117
|
-
async deriveSubHandle() {
|
|
118
|
-
throw new Error('Cannot derive child: maximum depth (2) reached or this SubHandle is marked as leaf');
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Returns the SubHandle-specific metadata (constraints).
|
|
122
|
-
*
|
|
123
|
-
* @returns The SubHandleMetadata object.
|
|
124
|
-
*/
|
|
125
|
-
getSubMetadata() {
|
|
126
|
-
return {
|
|
127
|
-
...this._subMetadata,
|
|
128
|
-
allowedAudiences: this._subMetadata.allowedAudiences !== undefined
|
|
129
|
-
? [...this._subMetadata.allowedAudiences]
|
|
130
|
-
: undefined,
|
|
131
|
-
allowedScopes: this._subMetadata.allowedScopes !== undefined
|
|
132
|
-
? [...this._subMetadata.allowedScopes]
|
|
133
|
-
: undefined,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Validates session options against this SubHandle's constraints.
|
|
138
|
-
*
|
|
139
|
-
* Called internally by {@link Session.create} before signing. Throws if
|
|
140
|
-
* any constraint is violated:
|
|
141
|
-
* - `audience` not in `allowedAudiences`
|
|
142
|
-
* - any `scope` not in `allowedScopes`
|
|
143
|
-
* - `ttl` exceeds `maxSessionTtl`
|
|
144
|
-
* - current time is past `expiresAt`
|
|
145
|
-
*
|
|
146
|
-
* @param options - The session options to validate.
|
|
147
|
-
* @throws {Error} If any constraint is violated.
|
|
148
|
-
*/
|
|
149
|
-
validateSessionOptions(options) {
|
|
150
|
-
// Audience check: undefined = unrestricted, [] = deny all
|
|
151
|
-
if (this._subMetadata.allowedAudiences !== undefined) {
|
|
152
|
-
if (!this._subMetadata.allowedAudiences.includes(options.audience)) {
|
|
153
|
-
throw new Error(`Audience "${options.audience}" not allowed for this SubHandle. ` +
|
|
154
|
-
`Allowed: ${this._subMetadata.allowedAudiences.length === 0
|
|
155
|
-
? '(none — empty list denies all)'
|
|
156
|
-
: this._subMetadata.allowedAudiences.join(', ')}`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
// Scopes check: undefined = unrestricted, [] = deny all
|
|
160
|
-
if (this._subMetadata.allowedScopes !== undefined) {
|
|
161
|
-
const forbidden = options.scopes.filter(s => !this._subMetadata.allowedScopes.includes(s));
|
|
162
|
-
// An empty allow-list denies every requested scope.
|
|
163
|
-
if (forbidden.length > 0) {
|
|
164
|
-
throw new Error(`Scopes not allowed for this SubHandle: ${forbidden.join(', ')}`);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
// TTL check
|
|
168
|
-
if (this._subMetadata.maxSessionTtl !== undefined &&
|
|
169
|
-
options.ttl > this._subMetadata.maxSessionTtl) {
|
|
170
|
-
throw new Error(`TTL ${options.ttl}s exceeds max allowed ` +
|
|
171
|
-
`${this._subMetadata.maxSessionTtl}s for this SubHandle`);
|
|
172
|
-
}
|
|
173
|
-
// SubHandle expiration check
|
|
174
|
-
if (this._subMetadata.expiresAt !== undefined) {
|
|
175
|
-
const now = Math.floor(Date.now() / 1000);
|
|
176
|
-
if (now >= this._subMetadata.expiresAt) {
|
|
177
|
-
throw new Error('SubHandle has expired');
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
3
|
+
// Public import path for SubHandle. Since PR-10 (D4) the class pair
|
|
4
|
+
// `Handle`/`SubHandle` lives in `handle.ts`: `SubHandle extends Handle`,
|
|
5
|
+
// and a static cross-file import of the subclass would create an ESM
|
|
6
|
+
// module cycle that crashes at import time depending on the graph root
|
|
7
|
+
// (reproduced: "Cannot access 'Handle' before initialization"). The
|
|
8
|
+
// pre-PR-10 dynamic `import()` dodge is gone; co-location keeps the
|
|
9
|
+
// module graph acyclic and 100% static.
|
|
10
|
+
//
|
|
11
|
+
// This facade re-exports the class and its metadata type unchanged, so
|
|
12
|
+
// `import { SubHandle } from '@me2em/core'` and internal imports of
|
|
13
|
+
// `./subhandle.js` keep working exactly as before.
|
|
14
|
+
export { SubHandle } from './handle.js';
|
|
182
15
|
//# sourceMappingURL=subhandle.js.map
|
package/dist/subhandle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subhandle.js","sourceRoot":"","sources":["../src/subhandle.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,EAAE;AACF,
|
|
1
|
+
{"version":3,"file":"subhandle.js","sourceRoot":"","sources":["../src/subhandle.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,EAAE;AACF,oEAAoE;AACpE,yEAAyE;AACzE,qEAAqE;AACrE,uEAAuE;AACvE,oEAAoE;AACpE,oEAAoE;AACpE,wCAAwC;AACxC,EAAE;AACF,uEAAuE;AACvE,oEAAoE;AACpE,mDAAmD;AAEnD,OAAO,EAAE,SAAS,EAA0B,MAAM,aAAa,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An object capable of producing Ed25519 signatures.
|
|
3
|
+
*
|
|
4
|
+
* The normative v1.0 issuance contract (specs/v1.0.md §8): raw private
|
|
5
|
+
* keys never cross a trust boundary as function arguments —
|
|
6
|
+
* `Attestation.issue` accepts a `Signer`, not key bytes. `Identity` and
|
|
7
|
+
* `Handle` implement this interface; custom implementations (e.g.
|
|
8
|
+
* remote- or HSM-backed signing) are accepted structurally — no
|
|
9
|
+
* inheritance from a base class is required.
|
|
10
|
+
*
|
|
11
|
+
* @category Types
|
|
12
|
+
*/
|
|
13
|
+
export interface Signer {
|
|
14
|
+
/**
|
|
15
|
+
* Signs `data` with the signer's own private key.
|
|
16
|
+
*
|
|
17
|
+
* @param data - The bytes to sign.
|
|
18
|
+
* @returns A promise resolving to the 64-byte Ed25519 signature.
|
|
19
|
+
*/
|
|
20
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC7C"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,EAAE;AACF,wEAAwE;AACxE,0DAA0D"}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,9 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js console/inspect hook (`util.inspect.custom`), referenced by
|
|
3
|
+
* `Symbol.for` so that no `node:util` import — and therefore no Node
|
|
4
|
+
* dependency — leaks into browser bundles. In non-Node runtimes the
|
|
5
|
+
* symbol simply has no meaning and the method is never called.
|
|
6
|
+
*/
|
|
7
|
+
export declare const INSPECT_SYMBOL: unique symbol;
|
|
1
8
|
/**
|
|
2
9
|
* Encodes a Uint8Array to a URL-safe Base64 string (no padding).
|
|
10
|
+
*
|
|
11
|
+
* Implemented on top of the audited `@scure/base` codec (A3) — a crypto
|
|
12
|
+
* library must not hand-roll its own base64 alphabet handling. The
|
|
13
|
+
* output is byte-identical to the previous hand-rolled encoder
|
|
14
|
+
* (unpadded URL-safe Base64), so token serialization does not change.
|
|
15
|
+
*
|
|
16
|
+
* @param bytes - The bytes to encode.
|
|
17
|
+
* @returns The unpadded URL-safe Base64 string (`''` for empty input).
|
|
3
18
|
*/
|
|
4
19
|
export declare function base64urlEncode(bytes: Uint8Array): string;
|
|
5
20
|
/**
|
|
6
21
|
* Decodes a URL-safe Base64 string to a Uint8Array.
|
|
22
|
+
*
|
|
23
|
+
* Implemented on top of the audited `@scure/base` codec (A3). Throws a
|
|
24
|
+
* generic `Error` on inputs with characters outside the URL-safe
|
|
25
|
+
* alphabet or an impossible length — token parsers wrap this call and
|
|
26
|
+
* translate failures into `AttestationError` `MALFORMED`/`FORMAT`.
|
|
27
|
+
*
|
|
28
|
+
* @param input - The unpadded URL-safe Base64 string.
|
|
29
|
+
* @returns The decoded bytes.
|
|
7
30
|
*/
|
|
8
31
|
export declare function base64urlDecode(input: string): Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* RFC 4122 version-4 UUID with a runtime-portability fallback (PR-7):
|
|
34
|
+
* uses `crypto.randomUUID` where available (Node ≥14.17, modern
|
|
35
|
+
* browsers) and otherwise builds the UUID from
|
|
36
|
+
* `crypto.getRandomValues` bytes with the version/variant bits set.
|
|
37
|
+
* Keeps `Attestation.issue` and `Session.create` working on runtimes
|
|
38
|
+
* without `randomUUID` (older React Native JS engines, non-secure
|
|
39
|
+
* browser contexts).
|
|
40
|
+
*
|
|
41
|
+
* @returns A random UUID in the canonical 8-4-4-4-12 hex form.
|
|
42
|
+
*/
|
|
43
|
+
export declare function randomUUID(): string;
|
|
44
|
+
/**
|
|
45
|
+
* `JSON.parse` hardened against prototype pollution (PR-7): parsing
|
|
46
|
+
* aborts when any key named `__proto__` appears in the payload, so a
|
|
47
|
+
* hostile token can never plant properties on `Object.prototype` —
|
|
48
|
+
* neither directly (the parse is aborted) nor via later spreads of the
|
|
49
|
+
* parsed value into fresh objects.
|
|
50
|
+
*
|
|
51
|
+
* @param input - The JSON text to parse.
|
|
52
|
+
* @returns The parsed value.
|
|
53
|
+
* @throws {SyntaxError} On invalid JSON or a forbidden `__proto__` key.
|
|
54
|
+
*/
|
|
55
|
+
export declare function safeJsonParse(input: string): unknown;
|
|
9
56
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,eAAO,MAAM,cAAc,eAA2C,CAAC;AAEvE;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAiBnC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOpD"}
|
package/dist/util.js
CHANGED
|
@@ -1,34 +1,86 @@
|
|
|
1
1
|
// util.ts
|
|
2
2
|
//
|
|
3
|
-
// Shared utility functions for the
|
|
3
|
+
// Shared utility functions for the Me2eM protocol.
|
|
4
|
+
import { base64urlnopad } from '@scure/base';
|
|
5
|
+
/**
|
|
6
|
+
* Node.js console/inspect hook (`util.inspect.custom`), referenced by
|
|
7
|
+
* `Symbol.for` so that no `node:util` import — and therefore no Node
|
|
8
|
+
* dependency — leaks into browser bundles. In non-Node runtimes the
|
|
9
|
+
* symbol simply has no meaning and the method is never called.
|
|
10
|
+
*/
|
|
11
|
+
export const INSPECT_SYMBOL = Symbol.for('nodejs.util.inspect.custom');
|
|
4
12
|
/**
|
|
5
13
|
* Encodes a Uint8Array to a URL-safe Base64 string (no padding).
|
|
14
|
+
*
|
|
15
|
+
* Implemented on top of the audited `@scure/base` codec (A3) — a crypto
|
|
16
|
+
* library must not hand-roll its own base64 alphabet handling. The
|
|
17
|
+
* output is byte-identical to the previous hand-rolled encoder
|
|
18
|
+
* (unpadded URL-safe Base64), so token serialization does not change.
|
|
19
|
+
*
|
|
20
|
+
* @param bytes - The bytes to encode.
|
|
21
|
+
* @returns The unpadded URL-safe Base64 string (`''` for empty input).
|
|
6
22
|
*/
|
|
7
23
|
export function base64urlEncode(bytes) {
|
|
8
|
-
|
|
9
|
-
for (const byte of bytes) {
|
|
10
|
-
binary += String.fromCharCode(byte);
|
|
11
|
-
}
|
|
12
|
-
return btoa(binary)
|
|
13
|
-
.replace(/\+/g, '-')
|
|
14
|
-
.replace(/\//g, '_')
|
|
15
|
-
.replace(/=+$/, '');
|
|
24
|
+
return base64urlnopad.encode(bytes);
|
|
16
25
|
}
|
|
17
26
|
/**
|
|
18
27
|
* Decodes a URL-safe Base64 string to a Uint8Array.
|
|
28
|
+
*
|
|
29
|
+
* Implemented on top of the audited `@scure/base` codec (A3). Throws a
|
|
30
|
+
* generic `Error` on inputs with characters outside the URL-safe
|
|
31
|
+
* alphabet or an impossible length — token parsers wrap this call and
|
|
32
|
+
* translate failures into `AttestationError` `MALFORMED`/`FORMAT`.
|
|
33
|
+
*
|
|
34
|
+
* @param input - The unpadded URL-safe Base64 string.
|
|
35
|
+
* @returns The decoded bytes.
|
|
19
36
|
*/
|
|
20
37
|
export function base64urlDecode(input) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
return base64urlnopad.decode(input);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* RFC 4122 version-4 UUID with a runtime-portability fallback (PR-7):
|
|
42
|
+
* uses `crypto.randomUUID` where available (Node ≥14.17, modern
|
|
43
|
+
* browsers) and otherwise builds the UUID from
|
|
44
|
+
* `crypto.getRandomValues` bytes with the version/variant bits set.
|
|
45
|
+
* Keeps `Attestation.issue` and `Session.create` working on runtimes
|
|
46
|
+
* without `randomUUID` (older React Native JS engines, non-secure
|
|
47
|
+
* browser contexts).
|
|
48
|
+
*
|
|
49
|
+
* @returns A random UUID in the canonical 8-4-4-4-12 hex form.
|
|
50
|
+
*/
|
|
51
|
+
export function randomUUID() {
|
|
52
|
+
const c = globalThis.crypto;
|
|
53
|
+
if (typeof c?.randomUUID === 'function') {
|
|
54
|
+
return c.randomUUID();
|
|
31
55
|
}
|
|
32
|
-
|
|
56
|
+
const bytes = new Uint8Array(16);
|
|
57
|
+
c.getRandomValues(bytes);
|
|
58
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40; // version 4
|
|
59
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant 10xx
|
|
60
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0'));
|
|
61
|
+
return (hex.slice(0, 4).join('') + '-' +
|
|
62
|
+
hex.slice(4, 6).join('') + '-' +
|
|
63
|
+
hex.slice(6, 8).join('') + '-' +
|
|
64
|
+
hex.slice(8, 10).join('') + '-' +
|
|
65
|
+
hex.slice(10, 16).join(''));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `JSON.parse` hardened against prototype pollution (PR-7): parsing
|
|
69
|
+
* aborts when any key named `__proto__` appears in the payload, so a
|
|
70
|
+
* hostile token can never plant properties on `Object.prototype` —
|
|
71
|
+
* neither directly (the parse is aborted) nor via later spreads of the
|
|
72
|
+
* parsed value into fresh objects.
|
|
73
|
+
*
|
|
74
|
+
* @param input - The JSON text to parse.
|
|
75
|
+
* @returns The parsed value.
|
|
76
|
+
* @throws {SyntaxError} On invalid JSON or a forbidden `__proto__` key.
|
|
77
|
+
*/
|
|
78
|
+
export function safeJsonParse(input) {
|
|
79
|
+
return JSON.parse(input, (key, value) => {
|
|
80
|
+
if (key === '__proto__') {
|
|
81
|
+
throw new SyntaxError('payload contains the forbidden key "__proto__"');
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
84
|
+
});
|
|
33
85
|
}
|
|
34
86
|
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,EAAE;AACF,mDAAmD;AAEnD
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,EAAE;AACF,mDAAmD;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAEvE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,OAAO,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC;IAC5B,IAAI,OAAO,CAAC,EAAE,UAAU,KAAK,UAAU,EAAE,CAAC;QACxC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;IACxB,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IACzB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,YAAY;IACjD,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,eAAe;IACpD,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACtE,OAAO,CACL,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG;QAC9B,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG;QAC9B,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG;QAC9B,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG;QAC/B,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAC3B,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,GAAW,EAAE,KAAc,EAAE,EAAE;QACvD,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;YACxB,MAAM,IAAI,WAAW,CAAC,gDAAgD,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@me2em/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Core primitives for the
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
|
+
"description": "Core primitives for the Me2eM authorization protocol: Identity, Handle, and Session",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"LICENSE"
|
|
19
19
|
],
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=22.6.0"
|
|
23
|
+
},
|
|
21
24
|
"publishConfig": {
|
|
22
25
|
"access": "public"
|
|
23
26
|
},
|
|
@@ -25,12 +28,12 @@
|
|
|
25
28
|
"@noble/curves": "^1.8.1",
|
|
26
29
|
"@noble/ed25519": "^3.1.0",
|
|
27
30
|
"@noble/hashes": "^2.2.0",
|
|
31
|
+
"@scure/base": "^2.4.0",
|
|
28
32
|
"@scure/bip39": "^1.3.0"
|
|
29
33
|
},
|
|
30
34
|
"devDependencies": {
|
|
31
35
|
"@types/node": "^25.9.1",
|
|
32
36
|
"@vitest/coverage-v8": "^4.1.11",
|
|
33
|
-
"eslint": "^10.4.1",
|
|
34
37
|
"typescript": "^6.0.3",
|
|
35
38
|
"vitest": "^4.1.7"
|
|
36
39
|
},
|
|
@@ -38,7 +41,10 @@
|
|
|
38
41
|
"build": "tsc -p tsconfig.json",
|
|
39
42
|
"test": "vitest run",
|
|
40
43
|
"test:coverage": "vitest run --coverage",
|
|
41
|
-
"
|
|
44
|
+
"bench": "vitest bench --run",
|
|
45
|
+
"bench:baseline": "vitest bench --run --outputJson bench/baseline.json && node scripts/normalize-baseline.mjs",
|
|
46
|
+
"vectors": "tsc -p tsconfig.json && node --experimental-strip-types scripts/generate-vectors.ts",
|
|
47
|
+
"lint": "eslint .",
|
|
42
48
|
"typecheck": "tsc --noEmit",
|
|
43
49
|
"build-docs": "typedoc"
|
|
44
50
|
}
|