@smartledger/keys 1.0.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/LICENSE +23 -0
- package/README.md +492 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +60 -0
- package/dist/browser.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/lumen-keys.js +5203 -0
- package/dist/lumen-keys.js.map +7 -0
- package/dist/lumen-keys.min.js +11 -0
- package/dist/lumen-keys.min.js.map +7 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +190 -0
- package/dist/sdk.js.map +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Gregory Ward (aka Codenlighten)
|
|
4
|
+
Founder: Codenlighten.org
|
|
5
|
+
Co-founder & Chief Technology Officer: SmartLedger.Technology
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
# @smartledger/keys SDK Documentation
|
|
2
|
+
|
|
3
|
+
**Single source of truth for cryptographic key operations.**
|
|
4
|
+
|
|
5
|
+
Version: 1.0.0
|
|
6
|
+
Status: ✅ Production Ready
|
|
7
|
+
Tests: 23/23 passing
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Why This SDK?
|
|
12
|
+
|
|
13
|
+
Keys are the **root of everything** in your crypto architecture:
|
|
14
|
+
- Identity
|
|
15
|
+
- Signatures
|
|
16
|
+
- PQ migration
|
|
17
|
+
- Regulatory/audit story
|
|
18
|
+
|
|
19
|
+
Without a clean SDK layer, key handling becomes **ad hoc** and **brittle**:
|
|
20
|
+
- ❌ Random `generateKeypair()` implementations scattered across repos
|
|
21
|
+
- ❌ Slightly different formats (hex here, base64 there)
|
|
22
|
+
- ❌ Surprise refactors when adding PQ suites
|
|
23
|
+
- ❌ Private keys exposed to calling code
|
|
24
|
+
|
|
25
|
+
**With `@smartledger/keys`**, all your agents/modules/bridge code simply ask:
|
|
26
|
+
```typescript
|
|
27
|
+
"Give me a signing key of suite X"
|
|
28
|
+
"Sign this payload with keyId Y"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
And **don't care** how keys are stored, rotated, or implemented.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Design Principles
|
|
36
|
+
|
|
37
|
+
1. **Private keys hidden** - Never exposed to most callers
|
|
38
|
+
2. **Crypto agility** - Suite is config, not code
|
|
39
|
+
3. **Single entry point** - Easy to audit
|
|
40
|
+
4. **Idempotent operations** - Safe for retries
|
|
41
|
+
5. **Minimal API surface** - Small, focused, easy to learn
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install @smartledger/keys
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import {
|
|
57
|
+
DefaultKeySDK,
|
|
58
|
+
KeyRecord,
|
|
59
|
+
} from '@smartledger/keys';
|
|
60
|
+
|
|
61
|
+
import {
|
|
62
|
+
KeyRegistry,
|
|
63
|
+
InMemoryKeyStorage,
|
|
64
|
+
BsvEcdsaSuite,
|
|
65
|
+
MlDsa87Suite,
|
|
66
|
+
globalRegistry,
|
|
67
|
+
} from '@smartledger/crypto';
|
|
68
|
+
|
|
69
|
+
// Setup (one-time)
|
|
70
|
+
const keyRegistry = new KeyRegistry(new InMemoryKeyStorage());
|
|
71
|
+
globalRegistry.register(new BsvEcdsaSuite());
|
|
72
|
+
globalRegistry.register(new MlDsa87Suite());
|
|
73
|
+
|
|
74
|
+
const sdk = new DefaultKeySDK({
|
|
75
|
+
keyRegistry,
|
|
76
|
+
suiteRegistry: globalRegistry,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Create a key
|
|
80
|
+
const keyRecord = await sdk.createKey('agent-resonance', {
|
|
81
|
+
primarySignatureSuite: 'ml-dsa-87',
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Sign (private key never exposed!)
|
|
85
|
+
const message = new TextEncoder().encode('agent output');
|
|
86
|
+
const signature = await sdk.signWithKey(keyRecord.meta.keyId, message);
|
|
87
|
+
|
|
88
|
+
// Verify
|
|
89
|
+
const valid = await sdk.verifySignature(
|
|
90
|
+
keyRecord.meta.keyId,
|
|
91
|
+
message,
|
|
92
|
+
signature
|
|
93
|
+
);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### KeySDK Interface
|
|
101
|
+
|
|
102
|
+
#### `createKey(agentId, profile, options?)`
|
|
103
|
+
|
|
104
|
+
Create a new key for an agent/module.
|
|
105
|
+
|
|
106
|
+
**Parameters:**
|
|
107
|
+
- `agentId` (string) - Agent identifier (e.g. `'agent-resonance'`)
|
|
108
|
+
- `profile` (CryptoProfile) - Which signature suites to use
|
|
109
|
+
- `options` (CreateKeyOptions) - Optional expiration, usage, etc.
|
|
110
|
+
|
|
111
|
+
**Returns:** `Promise<KeyRecord>` - KeyRecord with metadata and public key
|
|
112
|
+
|
|
113
|
+
**Example:**
|
|
114
|
+
```typescript
|
|
115
|
+
const key = await sdk.createKey(
|
|
116
|
+
'agent-schema',
|
|
117
|
+
{ primarySignatureSuite: 'ml-dsa-87' },
|
|
118
|
+
{
|
|
119
|
+
expiresAt: new Date(Date.now() + 365 * 86400000).toISOString(), // 1 year
|
|
120
|
+
usage: ['signing'],
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
#### `getKey(keyId)`
|
|
128
|
+
|
|
129
|
+
Get an existing key by ID.
|
|
130
|
+
|
|
131
|
+
**Parameters:**
|
|
132
|
+
- `keyId` (string) - Key identifier
|
|
133
|
+
|
|
134
|
+
**Returns:** `Promise<KeyRecord | null>` - KeyRecord or null if not found
|
|
135
|
+
|
|
136
|
+
**Example:**
|
|
137
|
+
```typescript
|
|
138
|
+
const key = await sdk.getKey('agent-resonance:pk-ml-1');
|
|
139
|
+
if (key) {
|
|
140
|
+
console.log(key.meta.suiteId); // 'ml-dsa-87'
|
|
141
|
+
console.log(key.publicKey); // Uint8Array
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
#### `signWithKey(keyId, message)`
|
|
148
|
+
|
|
149
|
+
Sign a message with a key. **Private key never leaves the SDK.**
|
|
150
|
+
|
|
151
|
+
**Parameters:**
|
|
152
|
+
- `keyId` (string) - Which key to sign with
|
|
153
|
+
- `message` (Uint8Array) - Message to sign (will be hashed internally)
|
|
154
|
+
|
|
155
|
+
**Returns:** `Promise<Uint8Array>` - Signature bytes
|
|
156
|
+
|
|
157
|
+
**Throws:** Error if key not found or not active
|
|
158
|
+
|
|
159
|
+
**Example:**
|
|
160
|
+
```typescript
|
|
161
|
+
const message = new TextEncoder().encode('agent output');
|
|
162
|
+
const signature = await sdk.signWithKey('agent-resonance:pk-ml-1', message);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
#### `verifySignature(keyId, message, signature)`
|
|
168
|
+
|
|
169
|
+
Verify a signature against a public key.
|
|
170
|
+
|
|
171
|
+
**Parameters:**
|
|
172
|
+
- `keyId` (string) - Which key to verify with
|
|
173
|
+
- `message` (Uint8Array) - Original message
|
|
174
|
+
- `signature` (Uint8Array) - Signature to verify
|
|
175
|
+
|
|
176
|
+
**Returns:** `Promise<boolean>` - true if valid
|
|
177
|
+
|
|
178
|
+
**Example:**
|
|
179
|
+
```typescript
|
|
180
|
+
const valid = await sdk.verifySignature(
|
|
181
|
+
'agent-resonance:pk-ml-1',
|
|
182
|
+
message,
|
|
183
|
+
signature
|
|
184
|
+
);
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
#### `listKeysForAgent(agentId, activeOnly?)`
|
|
190
|
+
|
|
191
|
+
List all keys for an agent.
|
|
192
|
+
|
|
193
|
+
**Parameters:**
|
|
194
|
+
- `agentId` (string) - Agent identifier
|
|
195
|
+
- `activeOnly` (boolean) - If true, only return active keys (default: true)
|
|
196
|
+
|
|
197
|
+
**Returns:** `Promise<KeyRecord[]>` - Array of KeyRecords
|
|
198
|
+
|
|
199
|
+
**Example:**
|
|
200
|
+
```typescript
|
|
201
|
+
const keys = await sdk.listKeysForAgent('agent-schema');
|
|
202
|
+
for (const key of keys) {
|
|
203
|
+
console.log(`${key.meta.keyId} (${key.meta.suiteId})`);
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
#### `getActiveCryptoProfile(agentId)`
|
|
210
|
+
|
|
211
|
+
Get the active crypto profile for an agent.
|
|
212
|
+
|
|
213
|
+
Looks up the most recent active keys and infers the profile.
|
|
214
|
+
|
|
215
|
+
**Parameters:**
|
|
216
|
+
- `agentId` (string) - Agent identifier
|
|
217
|
+
|
|
218
|
+
**Returns:** `Promise<CryptoProfile | null>` - CryptoProfile or null if no keys found
|
|
219
|
+
|
|
220
|
+
**Example:**
|
|
221
|
+
```typescript
|
|
222
|
+
const profile = await sdk.getActiveCryptoProfile('agent-schema');
|
|
223
|
+
console.log(profile.primarySignatureSuite); // 'ml-dsa-87'
|
|
224
|
+
console.log(profile.secondarySignatureSuite); // 'bsv-ecdsa-secp256k1'
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
#### `rotateAgentKeys(agentId)`
|
|
230
|
+
|
|
231
|
+
Rotate an agent's keys.
|
|
232
|
+
|
|
233
|
+
Generates new keypairs for all active keys, marks old ones as rotated.
|
|
234
|
+
|
|
235
|
+
**Parameters:**
|
|
236
|
+
- `agentId` (string) - Agent identifier
|
|
237
|
+
|
|
238
|
+
**Returns:** `Promise<KeyRecord[]>` - Array of new KeyRecords
|
|
239
|
+
|
|
240
|
+
**Example:**
|
|
241
|
+
```typescript
|
|
242
|
+
const newKeys = await sdk.rotateAgentKeys('agent-schema');
|
|
243
|
+
for (const key of newKeys) {
|
|
244
|
+
console.log(`New: ${key.meta.keyId}`);
|
|
245
|
+
console.log(`Rotated from: ${key.meta.rotatedFrom}`);
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
#### `getOrCreateKey(agentId, profile, options?)`
|
|
252
|
+
|
|
253
|
+
Create key if it doesn't exist, otherwise return existing.
|
|
254
|
+
|
|
255
|
+
**Idempotent** key creation for agent setup.
|
|
256
|
+
|
|
257
|
+
**Parameters:**
|
|
258
|
+
- `agentId` (string) - Agent identifier
|
|
259
|
+
- `profile` (CryptoProfile) - Crypto configuration
|
|
260
|
+
- `options` (CreateKeyOptions) - Creation options
|
|
261
|
+
|
|
262
|
+
**Returns:** `Promise<KeyRecord>` - KeyRecord (new or existing)
|
|
263
|
+
|
|
264
|
+
**Example:**
|
|
265
|
+
```typescript
|
|
266
|
+
// Safe to call multiple times
|
|
267
|
+
const key1 = await sdk.getOrCreateKey('agent-validator', {
|
|
268
|
+
primarySignatureSuite: 'ml-dsa-87',
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const key2 = await sdk.getOrCreateKey('agent-validator', {
|
|
272
|
+
primarySignatureSuite: 'ml-dsa-87',
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
console.log(key1.meta.keyId === key2.meta.keyId); // true
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Types
|
|
281
|
+
|
|
282
|
+
### KeyRecord
|
|
283
|
+
|
|
284
|
+
Public key record (safe to expose, no private key).
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
interface KeyRecord {
|
|
288
|
+
meta: KeyMeta; // Key metadata
|
|
289
|
+
publicKey: Uint8Array; // Public key bytes
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### CreateKeyOptions
|
|
294
|
+
|
|
295
|
+
Options for key creation.
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
interface CreateKeyOptions {
|
|
299
|
+
expiresAt?: string; // ISO 8601
|
|
300
|
+
usage?: Array<'signing' | 'encryption' | 'both'>; // Default: ['signing']
|
|
301
|
+
cryptoProfileVersion?: string; // Default: '1.0.0'
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### CryptoProfile
|
|
306
|
+
|
|
307
|
+
Per-agent/module crypto configuration.
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
interface CryptoProfile {
|
|
311
|
+
primarySignatureSuite: string; // e.g. 'ml-dsa-87'
|
|
312
|
+
secondarySignatureSuite?: string; // e.g. 'bsv-ecdsa-secp256k1' (hybrid)
|
|
313
|
+
keyEncapsulationSuite?: string; // e.g. 'ml-kem-768' (future)
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## Usage Patterns
|
|
320
|
+
|
|
321
|
+
### Single Signature (PQ-only)
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
// Agent uses only ML-DSA
|
|
325
|
+
const key = await sdk.createKey('agent-research', {
|
|
326
|
+
primarySignatureSuite: 'ml-dsa-87',
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const message = new TextEncoder().encode('research results');
|
|
330
|
+
const signature = await sdk.signWithKey(key.meta.keyId, message);
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Hybrid Signature (ECDSA + PQ)
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
// Agent uses both for migration
|
|
337
|
+
const mlKey = await sdk.createKey('agent-bridge', {
|
|
338
|
+
primarySignatureSuite: 'ml-dsa-87',
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const ecdsaKey = await sdk.createKey('agent-bridge', {
|
|
342
|
+
primarySignatureSuite: 'bsv-ecdsa-secp256k1',
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// Sign with both
|
|
346
|
+
const message = new TextEncoder().encode('bridge output');
|
|
347
|
+
const mlSig = await sdk.signWithKey(mlKey.meta.keyId, message);
|
|
348
|
+
const ecdsaSig = await sdk.signWithKey(ecdsaKey.meta.keyId, message);
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### Agent Setup (Idempotent)
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
// Safe to call on every startup
|
|
355
|
+
async function setupAgent(agentId: string) {
|
|
356
|
+
const key = await sdk.getOrCreateKey(agentId, {
|
|
357
|
+
primarySignatureSuite: 'ml-dsa-87',
|
|
358
|
+
}, {
|
|
359
|
+
expiresAt: new Date(Date.now() + 365 * 86400000).toISOString(),
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
return key;
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### Monthly Key Rotation
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
// Automated rotation job
|
|
370
|
+
async function monthlyRotation() {
|
|
371
|
+
const agents = ['agent-resonance', 'agent-schema', 'agent-validator'];
|
|
372
|
+
|
|
373
|
+
for (const agentId of agents) {
|
|
374
|
+
const newKeys = await sdk.rotateAgentKeys(agentId);
|
|
375
|
+
console.log(`✓ Rotated ${agentId}: ${newKeys.length} keys`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
## Benefits
|
|
383
|
+
|
|
384
|
+
### 🔒 Security
|
|
385
|
+
|
|
386
|
+
- **Private keys hidden** - Never exposed to calling code
|
|
387
|
+
- **Single audit point** - All key operations go through SDK
|
|
388
|
+
- **No key leakage** - Keys stay in KeyRegistry storage
|
|
389
|
+
- **Consistent hashing** - Suite-appropriate algorithms
|
|
390
|
+
|
|
391
|
+
### 🔄 Crypto Agility
|
|
392
|
+
|
|
393
|
+
- **Suite is config** - Change ML-DSA → Falcon without code changes
|
|
394
|
+
- **Profile-driven** - CryptoProfile defines agent's crypto setup
|
|
395
|
+
- **Easy migration** - Hybrid mode for ECDSA → PQ transition
|
|
396
|
+
|
|
397
|
+
### 🛠️ Developer Experience
|
|
398
|
+
|
|
399
|
+
- **Clean API** - 8 methods, easy to learn
|
|
400
|
+
- **Idempotent** - `getOrCreateKey` safe for retries
|
|
401
|
+
- **TypeScript** - Full type safety
|
|
402
|
+
- **Well-tested** - 23 tests covering all scenarios
|
|
403
|
+
|
|
404
|
+
### 📊 Operations
|
|
405
|
+
|
|
406
|
+
- **Centralized** - One SDK for all agents
|
|
407
|
+
- **Auditable** - Easy to track key operations
|
|
408
|
+
- **Scalable** - Storage backends (in-memory, file, KMS)
|
|
409
|
+
- **Rotation-friendly** - Built-in rotation support
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## Best Practices
|
|
414
|
+
|
|
415
|
+
### ✅ Do
|
|
416
|
+
|
|
417
|
+
- Use SDK for **all** key operations
|
|
418
|
+
- Call `getOrCreateKey` for idempotent setup
|
|
419
|
+
- Set expiration dates on keys
|
|
420
|
+
- Rotate keys regularly (monthly/quarterly)
|
|
421
|
+
- Use `signWithKey` (not direct registry access)
|
|
422
|
+
|
|
423
|
+
### ❌ Don't
|
|
424
|
+
|
|
425
|
+
- Expose private keys to calling code
|
|
426
|
+
- Create keys manually outside SDK
|
|
427
|
+
- Hard-code suite IDs in business logic
|
|
428
|
+
- Skip key rotation
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
## Integration with Existing Code
|
|
433
|
+
|
|
434
|
+
### Before (Direct Registry)
|
|
435
|
+
|
|
436
|
+
```typescript
|
|
437
|
+
// Scattered key operations
|
|
438
|
+
const suite = globalRegistry.getSuite('ml-dsa-87');
|
|
439
|
+
const keypair = await suite.generateKeypair();
|
|
440
|
+
await keyRegistry.registerKey('agent-1:pk-1', keypair, 'ml-dsa-87');
|
|
441
|
+
|
|
442
|
+
const key = await keyRegistry.getKey('agent-1:pk-1');
|
|
443
|
+
const sig = await suite.sign(key.keypair.privateKey, message);
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
### After (SDK)
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
// Clean, centralized
|
|
450
|
+
const key = await sdk.createKey('agent-1', {
|
|
451
|
+
primarySignatureSuite: 'ml-dsa-87',
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const sig = await sdk.signWithKey(key.meta.keyId, message);
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
---
|
|
458
|
+
|
|
459
|
+
## What's Next?
|
|
460
|
+
|
|
461
|
+
- **File Storage** - Persistent key storage (not just in-memory)
|
|
462
|
+
- **KMS Integration** - AWS KMS, Azure Key Vault, HSM
|
|
463
|
+
- **Key Backup** - Encrypted backup/recovery procedures
|
|
464
|
+
- **Multi-tenant** - Isolate keys per tenant
|
|
465
|
+
- **Hardware Keys** - Support for non-exportable hardware keys
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
## Summary
|
|
470
|
+
|
|
471
|
+
**`@smartledger/keys` is the single source of truth for cryptographic keys:**
|
|
472
|
+
|
|
473
|
+
✅ 23 tests passing
|
|
474
|
+
✅ Private keys hidden from callers
|
|
475
|
+
✅ Crypto-agnostic API (suite is config)
|
|
476
|
+
✅ Idempotent operations
|
|
477
|
+
✅ Easy to audit
|
|
478
|
+
✅ Production-ready
|
|
479
|
+
|
|
480
|
+
**Use it for all key operations. Make crypto agility a reality.**
|
|
481
|
+
|
|
482
|
+
---
|
|
483
|
+
|
|
484
|
+
**See Also:**
|
|
485
|
+
- [Key Management Guide](../docs/KEY_MANAGEMENT_GUIDE.md) - Lower-level KeyRegistry details
|
|
486
|
+
- [Algorithm Selection Guide](../docs/ALGORITHM_SELECTION_GUIDE.md) - Which suite to use?
|
|
487
|
+
- [ECDSA Implementation Strategy](../docs/ECDSA_IMPLEMENTATION_STRATEGY.md) - Why Noble
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
**Version**: 1.0.0
|
|
492
|
+
**Last Updated**: November 28, 2025
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGzC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;GAGG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAkBpD;AAED;;GAEG;;;;AACH,wBAEE"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Browser entry point for @lumen/keys SDK
|
|
4
|
+
* Includes WASM initialization and browser-compatible exports
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.InMemoryKeyStorage = void 0;
|
|
22
|
+
exports.createKeySDK = createKeySDK;
|
|
23
|
+
const sdk_js_1 = require("./sdk.js");
|
|
24
|
+
const crypto_1 = require("@smartledger/crypto");
|
|
25
|
+
// Re-export all types for browser usage
|
|
26
|
+
__exportStar(require("./types.js"), exports);
|
|
27
|
+
var crypto_2 = require("@smartledger/crypto");
|
|
28
|
+
Object.defineProperty(exports, "InMemoryKeyStorage", { enumerable: true, get: function () { return crypto_2.InMemoryKeyStorage; } });
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new KeySDK instance for browser usage
|
|
31
|
+
* Handles WASM initialization automatically
|
|
32
|
+
*/
|
|
33
|
+
async function createKeySDK() {
|
|
34
|
+
const storage = new crypto_1.InMemoryKeyStorage();
|
|
35
|
+
const keyRegistry = new crypto_1.KeyRegistry(storage);
|
|
36
|
+
// Initialize suite registry with both ECDSA and ML-DSA
|
|
37
|
+
const suiteRegistry = new crypto_1.SignatureSuiteRegistry();
|
|
38
|
+
suiteRegistry.register(new crypto_1.BsvEcdsaSuite());
|
|
39
|
+
suiteRegistry.register(new crypto_1.MlDsaSuite());
|
|
40
|
+
const sdk = new sdk_js_1.DefaultKeySDK({
|
|
41
|
+
keyRegistry,
|
|
42
|
+
suiteRegistry,
|
|
43
|
+
});
|
|
44
|
+
// Pre-initialize WASM for ML-DSA if needed
|
|
45
|
+
// The dilithium-crystals library will lazy-load WASM on first use
|
|
46
|
+
return sdk;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Browser-ready default export
|
|
50
|
+
*/
|
|
51
|
+
exports.default = {
|
|
52
|
+
createKeySDK,
|
|
53
|
+
};
|
|
54
|
+
// Global export for CDN usage
|
|
55
|
+
if (typeof window !== 'undefined') {
|
|
56
|
+
window.LumenKeys = {
|
|
57
|
+
createKeySDK,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;AAoBH,oCAkBC;AApCD,qCAAyC;AACzC,gDAM6B;AAG7B,wCAAwC;AACxC,6CAA2B;AAC3B,8CAAyD;AAAhD,4GAAA,kBAAkB,OAAA;AAE3B;;;GAGG;AACI,KAAK,UAAU,YAAY;IAChC,MAAM,OAAO,GAAG,IAAI,2BAAkB,EAAE,CAAC;IACzC,MAAM,WAAW,GAAG,IAAI,oBAAW,CAAC,OAAO,CAAC,CAAC;IAE7C,uDAAuD;IACvD,MAAM,aAAa,GAAG,IAAI,+BAAsB,EAAE,CAAC;IACnD,aAAa,CAAC,QAAQ,CAAC,IAAI,sBAAa,EAAE,CAAC,CAAC;IAC5C,aAAa,CAAC,QAAQ,CAAC,IAAI,mBAAU,EAAE,CAAC,CAAC;IAEzC,MAAM,GAAG,GAAG,IAAI,sBAAa,CAAC;QAC5B,WAAW;QACX,aAAa;KACd,CAAC,CAAC;IAEH,2CAA2C;IAC3C,kEAAkE;IAElE,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,kBAAe;IACb,YAAY;CACb,CAAC;AAEF,8BAA8B;AAC9B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IACjC,MAAc,CAAC,SAAS,GAAG;QAC1B,YAAY;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AAGtB,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @smartledger/keys - Key Management SDK
|
|
4
|
+
*
|
|
5
|
+
* Single source of truth for cryptographic key operations.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
__exportStar(require("./sdk"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,wCAAsB"}
|