@smartledger/keys 1.2.2 → 1.3.0
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/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/sdk.d.ts +64 -0
- package/dist/cjs/sdk.d.ts.map +1 -1
- package/dist/cjs/sdk.js +128 -2
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/cjs/types.d.ts +36 -1
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/sdk.d.ts +64 -0
- package/dist/esm/sdk.d.ts.map +1 -1
- package/dist/esm/sdk.js +128 -3
- package/dist/esm/sdk.js.map +1 -1
- package/dist/esm/types.d.ts +36 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/lumen-keys.js +6764 -130
- package/dist/lumen-keys.js.map +4 -4
- package/dist/lumen-keys.min.js +2070 -1
- package/dist/lumen-keys.min.js.map +4 -4
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AAGzB,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AAGzB,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -19,6 +19,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
19
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.BIP32Derivation = void 0;
|
|
22
23
|
__exportStar(require("./types.js"), exports);
|
|
23
24
|
__exportStar(require("./sdk.js"), exports);
|
|
25
|
+
var crypto_1 = require("@smartledger/crypto");
|
|
26
|
+
Object.defineProperty(exports, "BIP32Derivation", { enumerable: true, get: function () { return crypto_1.BIP32Derivation; } });
|
|
24
27
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;AAEH,6CAA2B;AAC3B,2CAAyB;AAIzB,8CAAsD;AAA7C,yGAAA,eAAe,OAAA"}
|
package/dist/cjs/sdk.d.ts
CHANGED
|
@@ -57,6 +57,55 @@ export declare class DefaultKeySDK implements KeySDK {
|
|
|
57
57
|
* Get or create key (idempotent).
|
|
58
58
|
*/
|
|
59
59
|
getOrCreateKey(agentId: string, profile: CryptoProfile, options?: CreateKeyOptions): Promise<KeyRecord>;
|
|
60
|
+
/**
|
|
61
|
+
* Generate a new BIP39 mnemonic phrase.
|
|
62
|
+
*
|
|
63
|
+
* @param strength 128 (12 words) or 256 (24 words)
|
|
64
|
+
* @returns Mnemonic phrase
|
|
65
|
+
*/
|
|
66
|
+
generateMnemonic(strength?: 128 | 256): string;
|
|
67
|
+
/**
|
|
68
|
+
* Create a key from a BIP39 mnemonic using HD derivation.
|
|
69
|
+
*
|
|
70
|
+
* Only works with suites that support BIP32 derivation (e.g., bsv-ecdsa-secp256k1).
|
|
71
|
+
*
|
|
72
|
+
* @param agentId Agent identifier
|
|
73
|
+
* @param profile Crypto profile (must use derivation-capable suite)
|
|
74
|
+
* @param mnemonic BIP39 mnemonic phrase
|
|
75
|
+
* @param path BIP32 derivation path (default: "m/44'/0'/0'/0/0")
|
|
76
|
+
* @param passphrase Optional BIP39 passphrase
|
|
77
|
+
* @param options Additional key creation options
|
|
78
|
+
* @returns KeyRecord with derived key
|
|
79
|
+
*/
|
|
80
|
+
createKeyFromMnemonic(agentId: string, profile: CryptoProfile, mnemonic: string, path?: string, passphrase?: string, options?: CreateKeyOptions): Promise<KeyRecord>;
|
|
81
|
+
/**
|
|
82
|
+
* Get available capabilities for a specific suite.
|
|
83
|
+
*
|
|
84
|
+
* @param suiteId Suite identifier
|
|
85
|
+
* @returns Array of capability names
|
|
86
|
+
*/
|
|
87
|
+
getCapabilities(suiteId: string): string[];
|
|
88
|
+
/**
|
|
89
|
+
* Get all suite IDs that support a specific capability.
|
|
90
|
+
*
|
|
91
|
+
* @param capability Capability name
|
|
92
|
+
* @returns Array of suite IDs
|
|
93
|
+
*/
|
|
94
|
+
getSuitesWithCapability(capability: 'derivation' | 'encryption' | 'threshold'): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Create a Bitcoin wallet key from mnemonic (convenience method).
|
|
97
|
+
*
|
|
98
|
+
* Uses standard BIP44 Bitcoin path: m/44'/0'/account'/change/addressIndex
|
|
99
|
+
*
|
|
100
|
+
* @param agentId Agent identifier
|
|
101
|
+
* @param mnemonic BIP39 mnemonic phrase
|
|
102
|
+
* @param accountIndex Account index (default: 0)
|
|
103
|
+
* @param addressIndex Address index (default: 0)
|
|
104
|
+
* @param isChange Use change address path (default: false)
|
|
105
|
+
* @param options Additional key creation options
|
|
106
|
+
* @returns KeyRecord with Bitcoin-compatible key
|
|
107
|
+
*/
|
|
108
|
+
createBitcoinWalletKey(agentId: string, mnemonic: string, accountIndex?: number, addressIndex?: number, isChange?: boolean, options?: CreateKeyOptions): Promise<KeyRecord>;
|
|
60
109
|
/**
|
|
61
110
|
* Helper: Get hash algorithm for a suite.
|
|
62
111
|
*/
|
|
@@ -66,4 +115,19 @@ export declare class DefaultKeySDK implements KeySDK {
|
|
|
66
115
|
*/
|
|
67
116
|
private getNextCounter;
|
|
68
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Create a KeySDK instance with default configuration
|
|
120
|
+
*
|
|
121
|
+
* Uses in-memory storage and registers both ECDSA and ML-DSA suites.
|
|
122
|
+
* For custom storage or different suites, instantiate DefaultKeySDK directly.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* import { createKeySDK } from '@smartledger/keys';
|
|
127
|
+
*
|
|
128
|
+
* const sdk = createKeySDK();
|
|
129
|
+
* const key = await sdk.createKey('my-agent', { primarySignatureSuite: 'ml-dsa-87' });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function createKeySDK(config?: Partial<KeySDKConfig>): KeySDK;
|
|
69
133
|
//# sourceMappingURL=sdk.d.ts.map
|
package/dist/cjs/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,WAAW,EACX,sBAAsB,EAEtB,aAAa,
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,WAAW,EACX,sBAAsB,EAEtB,aAAa,EAMd,MAAM,qBAAqB,CAAC;AAC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AC,SAAS,CAAC;IAgBrB;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,GAAE,GAAG,GAAG,GAAS,GAAG,MAAM;IAKnD;;;;;;;;;;;;OAYG;IACG,qBAAqB,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,MAA6C,EACnD,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,SAAS,CAAC;IAarB;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAW1C;;;;;OAKG;IACH,uBAAuB,CAAC,UAAU,EAAE,YAAY,GAAG,YAAY,GAAG,WAAW,GAAG,MAAM,EAAE;IAOxF;;;;;;;;;;;;OAYG;IACG,sBAAsB,CAC1B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,YAAY,SAAI,EAChB,YAAY,SAAI,EAChB,QAAQ,UAAQ,EAChB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,SAAS,CAAC;IAarB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAOxB;;OAEG;IACH,OAAO,CAAC,cAAc;CAMvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,MAAM,CAcnE"}
|
package/dist/cjs/sdk.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.DefaultKeySDK = void 0;
|
|
10
|
+
exports.createKeySDK = createKeySDK;
|
|
10
11
|
const crypto_1 = require("@smartledger/crypto");
|
|
11
12
|
/**
|
|
12
13
|
* Default KeySDK implementation.
|
|
@@ -23,9 +24,27 @@ class DefaultKeySDK {
|
|
|
23
24
|
* Create a new key for an agent.
|
|
24
25
|
*/
|
|
25
26
|
async createKey(agentId, profile, options = {}) {
|
|
26
|
-
//
|
|
27
|
+
// Get suite
|
|
27
28
|
const suite = this.suiteRegistry.getSuite(profile.primarySignatureSuite);
|
|
28
|
-
|
|
29
|
+
// Generate keypair (with optional derivation)
|
|
30
|
+
let keypair;
|
|
31
|
+
if (options.derivationContext) {
|
|
32
|
+
// Check if suite supports derivation
|
|
33
|
+
if (!suite.capabilities?.derivation) {
|
|
34
|
+
const available = this.getSuitesWithCapability('derivation');
|
|
35
|
+
throw new Error(`Suite '${suite.suiteId}' does not support key derivation.\n` +
|
|
36
|
+
(available.length > 0
|
|
37
|
+
? `Suites with derivation capability: ${available.join(', ')}\n` +
|
|
38
|
+
`Consider using one of these suites or remove the derivationContext option.`
|
|
39
|
+
: `No suites currently support derivation. Remove the derivationContext option.`));
|
|
40
|
+
}
|
|
41
|
+
// Use derivation capability
|
|
42
|
+
keypair = await suite.capabilities.derivation.deriveKeypair(options.derivationContext);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// Standard random key generation
|
|
46
|
+
keypair = await suite.generateKeypair();
|
|
47
|
+
}
|
|
29
48
|
// Generate unique keyId
|
|
30
49
|
const counter = this.getNextCounter(agentId);
|
|
31
50
|
const suiteName = profile.primarySignatureSuite.split('-')[0]; // 'ml-dsa' or 'bsv'
|
|
@@ -167,6 +186,86 @@ class DefaultKeySDK {
|
|
|
167
186
|
// Create new key
|
|
168
187
|
return await this.createKey(agentId, profile, options);
|
|
169
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Generate a new BIP39 mnemonic phrase.
|
|
191
|
+
*
|
|
192
|
+
* @param strength 128 (12 words) or 256 (24 words)
|
|
193
|
+
* @returns Mnemonic phrase
|
|
194
|
+
*/
|
|
195
|
+
generateMnemonic(strength = 256) {
|
|
196
|
+
const bip32 = new crypto_1.BIP32Derivation();
|
|
197
|
+
return bip32.generateMnemonic(strength);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create a key from a BIP39 mnemonic using HD derivation.
|
|
201
|
+
*
|
|
202
|
+
* Only works with suites that support BIP32 derivation (e.g., bsv-ecdsa-secp256k1).
|
|
203
|
+
*
|
|
204
|
+
* @param agentId Agent identifier
|
|
205
|
+
* @param profile Crypto profile (must use derivation-capable suite)
|
|
206
|
+
* @param mnemonic BIP39 mnemonic phrase
|
|
207
|
+
* @param path BIP32 derivation path (default: "m/44'/0'/0'/0/0")
|
|
208
|
+
* @param passphrase Optional BIP39 passphrase
|
|
209
|
+
* @param options Additional key creation options
|
|
210
|
+
* @returns KeyRecord with derived key
|
|
211
|
+
*/
|
|
212
|
+
async createKeyFromMnemonic(agentId, profile, mnemonic, path = crypto_1.BIP32Derivation.bitcoinPath(0, 0, 0), passphrase, options = {}) {
|
|
213
|
+
const bip32 = new crypto_1.BIP32Derivation();
|
|
214
|
+
const seed = bip32.mnemonicToSeed(mnemonic, passphrase);
|
|
215
|
+
return await this.createKey(agentId, profile, {
|
|
216
|
+
...options,
|
|
217
|
+
derivationContext: {
|
|
218
|
+
seed,
|
|
219
|
+
path,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get available capabilities for a specific suite.
|
|
225
|
+
*
|
|
226
|
+
* @param suiteId Suite identifier
|
|
227
|
+
* @returns Array of capability names
|
|
228
|
+
*/
|
|
229
|
+
getCapabilities(suiteId) {
|
|
230
|
+
const suite = this.suiteRegistry.getSuite(suiteId);
|
|
231
|
+
const caps = [];
|
|
232
|
+
if (suite.capabilities?.derivation)
|
|
233
|
+
caps.push('derivation');
|
|
234
|
+
if (suite.capabilities?.encryption)
|
|
235
|
+
caps.push('encryption');
|
|
236
|
+
if (suite.capabilities?.threshold)
|
|
237
|
+
caps.push('threshold');
|
|
238
|
+
return caps;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Get all suite IDs that support a specific capability.
|
|
242
|
+
*
|
|
243
|
+
* @param capability Capability name
|
|
244
|
+
* @returns Array of suite IDs
|
|
245
|
+
*/
|
|
246
|
+
getSuitesWithCapability(capability) {
|
|
247
|
+
const allSuites = this.suiteRegistry.getAllSuites();
|
|
248
|
+
return allSuites
|
|
249
|
+
.filter(suite => !!suite.capabilities?.[capability])
|
|
250
|
+
.map(suite => suite.suiteId);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Create a Bitcoin wallet key from mnemonic (convenience method).
|
|
254
|
+
*
|
|
255
|
+
* Uses standard BIP44 Bitcoin path: m/44'/0'/account'/change/addressIndex
|
|
256
|
+
*
|
|
257
|
+
* @param agentId Agent identifier
|
|
258
|
+
* @param mnemonic BIP39 mnemonic phrase
|
|
259
|
+
* @param accountIndex Account index (default: 0)
|
|
260
|
+
* @param addressIndex Address index (default: 0)
|
|
261
|
+
* @param isChange Use change address path (default: false)
|
|
262
|
+
* @param options Additional key creation options
|
|
263
|
+
* @returns KeyRecord with Bitcoin-compatible key
|
|
264
|
+
*/
|
|
265
|
+
async createBitcoinWalletKey(agentId, mnemonic, accountIndex = 0, addressIndex = 0, isChange = false, options = {}) {
|
|
266
|
+
const path = crypto_1.BIP32Derivation.bitcoinPath(accountIndex, isChange ? 1 : 0, addressIndex);
|
|
267
|
+
return this.createKeyFromMnemonic(agentId, { primarySignatureSuite: 'bsv-ecdsa-secp256k1' }, mnemonic, path, undefined, options);
|
|
268
|
+
}
|
|
170
269
|
/**
|
|
171
270
|
* Helper: Get hash algorithm for a suite.
|
|
172
271
|
*/
|
|
@@ -187,4 +286,31 @@ class DefaultKeySDK {
|
|
|
187
286
|
}
|
|
188
287
|
}
|
|
189
288
|
exports.DefaultKeySDK = DefaultKeySDK;
|
|
289
|
+
/**
|
|
290
|
+
* Create a KeySDK instance with default configuration
|
|
291
|
+
*
|
|
292
|
+
* Uses in-memory storage and registers both ECDSA and ML-DSA suites.
|
|
293
|
+
* For custom storage or different suites, instantiate DefaultKeySDK directly.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* import { createKeySDK } from '@smartledger/keys';
|
|
298
|
+
*
|
|
299
|
+
* const sdk = createKeySDK();
|
|
300
|
+
* const key = await sdk.createKey('my-agent', { primarySignatureSuite: 'ml-dsa-87' });
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
function createKeySDK(config) {
|
|
304
|
+
const keyRegistry = config?.keyRegistry || new crypto_1.KeyRegistry(new crypto_1.InMemoryKeyStorage());
|
|
305
|
+
const suiteRegistry = config?.suiteRegistry || new crypto_1.SignatureSuiteRegistry();
|
|
306
|
+
// Register default suites if not provided
|
|
307
|
+
if (!config?.suiteRegistry) {
|
|
308
|
+
suiteRegistry.register(new crypto_1.BsvEcdsaSuite());
|
|
309
|
+
suiteRegistry.register(new crypto_1.MlDsa87Suite());
|
|
310
|
+
}
|
|
311
|
+
return new DefaultKeySDK({
|
|
312
|
+
keyRegistry,
|
|
313
|
+
suiteRegistry,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
190
316
|
//# sourceMappingURL=sdk.js.map
|
package/dist/cjs/sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAuaH,oCAcC;AAnbD,gDAU6B;AAmB7B;;;;GAIG;AACH,MAAa,aAAa;IAKxB,YAAY,MAAoB;QAFxB,eAAU,GAAG,IAAI,GAAG,EAAkB,CAAC,CAAC,qBAAqB;QAGnE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS,CACb,OAAe,EACf,OAAsB,EACtB,UAA4B,EAAE;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MAAM,WAAW,GAAG,MAAM,EAAE,WAAW,IAAI,IAAI,oBAAW,CAAC,IAAI,2BAAkB,EAAE,CAAC,CAAC;IACrF,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,IAAI,IAAI,+BAAsB,EAAE,CAAC;IAE5E,0CAA0C;IAC1C,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;QAC3B,aAAa,CAAC,QAAQ,CAAC,IAAI,sBAAa,EAAE,CAAC,CAAC;QAC5C,aAAa,CAAC,QAAQ,CAAC,IAAI,qBAAY,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,IAAI,aAAa,CAAC;QACvB,WAAW;QACX,aAAa;KACd,CAAC,CAAC;AACL,CAAC"}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Single source of truth for cryptographic key operations.
|
|
5
5
|
* Provides a clean API that hides complexity and ensures consistency.
|
|
6
6
|
*/
|
|
7
|
-
import { KeyMeta, CryptoProfile } from '@smartledger/crypto';
|
|
7
|
+
import { KeyMeta, CryptoProfile, DerivationContext } from '@smartledger/crypto';
|
|
8
8
|
/**
|
|
9
9
|
* Public key record (safe to expose, no private key).
|
|
10
10
|
*/
|
|
@@ -22,6 +22,8 @@ export interface CreateKeyOptions {
|
|
|
22
22
|
usage?: Array<'signing' | 'encryption' | 'both'>;
|
|
23
23
|
/** Crypto profile version (default: '1.0.0') */
|
|
24
24
|
cryptoProfileVersion?: string;
|
|
25
|
+
/** Optional derivation context for deterministic key generation */
|
|
26
|
+
derivationContext?: DerivationContext;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Key SDK - Single interface for all key operations.
|
|
@@ -105,6 +107,39 @@ export interface KeySDK {
|
|
|
105
107
|
* @returns KeyRecord (new or existing)
|
|
106
108
|
*/
|
|
107
109
|
getOrCreateKey(agentId: string, profile: CryptoProfile, options?: CreateKeyOptions): Promise<KeyRecord>;
|
|
110
|
+
/**
|
|
111
|
+
* Generate a new BIP39 mnemonic phrase.
|
|
112
|
+
*
|
|
113
|
+
* @param strength 128 (12 words) or 256 (24 words)
|
|
114
|
+
* @returns Mnemonic phrase
|
|
115
|
+
*/
|
|
116
|
+
generateMnemonic(strength?: 128 | 256): string;
|
|
117
|
+
/**
|
|
118
|
+
* Create a key from a BIP39 mnemonic using HD derivation.
|
|
119
|
+
*
|
|
120
|
+
* @param agentId Agent identifier
|
|
121
|
+
* @param profile Crypto profile (must use derivation-capable suite)
|
|
122
|
+
* @param mnemonic BIP39 mnemonic phrase
|
|
123
|
+
* @param path BIP32 derivation path
|
|
124
|
+
* @param passphrase Optional BIP39 passphrase
|
|
125
|
+
* @param options Additional key creation options
|
|
126
|
+
* @returns KeyRecord with derived key
|
|
127
|
+
*/
|
|
128
|
+
createKeyFromMnemonic(agentId: string, profile: CryptoProfile, mnemonic: string, path?: string, passphrase?: string, options?: CreateKeyOptions): Promise<KeyRecord>;
|
|
129
|
+
/**
|
|
130
|
+
* Get available capabilities for a specific suite.
|
|
131
|
+
*
|
|
132
|
+
* @param suiteId Suite identifier
|
|
133
|
+
* @returns Array of capability names
|
|
134
|
+
*/
|
|
135
|
+
getCapabilities(suiteId: string): string[];
|
|
136
|
+
/**
|
|
137
|
+
* Find suites that support a specific capability.
|
|
138
|
+
*
|
|
139
|
+
* @param capability Capability name
|
|
140
|
+
* @returns Array of suite IDs
|
|
141
|
+
*/
|
|
142
|
+
getSuitesWithCapability(capability: 'derivation' | 'encryption' | 'threshold'): string[];
|
|
108
143
|
}
|
|
109
144
|
/**
|
|
110
145
|
* Agent metadata with crypto configuration.
|
package/dist/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d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sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;IAEvE;;;;;;;OAOG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAEvD;;;;;;;;;OASG;IACH,cAAc,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,SAAS,CAAC,CAAC;IAEtB;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,MAAM,CAAC;IAE/C;;;;;;;;;;OAUG;IACH,qBAAqB,CACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,SAAS,CAAC,CAAC;IAEtB;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE3C;;;;;OAKG;IACH,uBAAuB,CAAC,UAAU,EAAE,YAAY,GAAG,YAAY,GAAG,WAAW,GAAG,MAAM,EAAE,CAAC;CAC1F;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;CAC9B"}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AAGzB,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AAGzB,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AAIzB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/esm/sdk.d.ts
CHANGED
|
@@ -57,6 +57,55 @@ export declare class DefaultKeySDK implements KeySDK {
|
|
|
57
57
|
* Get or create key (idempotent).
|
|
58
58
|
*/
|
|
59
59
|
getOrCreateKey(agentId: string, profile: CryptoProfile, options?: CreateKeyOptions): Promise<KeyRecord>;
|
|
60
|
+
/**
|
|
61
|
+
* Generate a new BIP39 mnemonic phrase.
|
|
62
|
+
*
|
|
63
|
+
* @param strength 128 (12 words) or 256 (24 words)
|
|
64
|
+
* @returns Mnemonic phrase
|
|
65
|
+
*/
|
|
66
|
+
generateMnemonic(strength?: 128 | 256): string;
|
|
67
|
+
/**
|
|
68
|
+
* Create a key from a BIP39 mnemonic using HD derivation.
|
|
69
|
+
*
|
|
70
|
+
* Only works with suites that support BIP32 derivation (e.g., bsv-ecdsa-secp256k1).
|
|
71
|
+
*
|
|
72
|
+
* @param agentId Agent identifier
|
|
73
|
+
* @param profile Crypto profile (must use derivation-capable suite)
|
|
74
|
+
* @param mnemonic BIP39 mnemonic phrase
|
|
75
|
+
* @param path BIP32 derivation path (default: "m/44'/0'/0'/0/0")
|
|
76
|
+
* @param passphrase Optional BIP39 passphrase
|
|
77
|
+
* @param options Additional key creation options
|
|
78
|
+
* @returns KeyRecord with derived key
|
|
79
|
+
*/
|
|
80
|
+
createKeyFromMnemonic(agentId: string, profile: CryptoProfile, mnemonic: string, path?: string, passphrase?: string, options?: CreateKeyOptions): Promise<KeyRecord>;
|
|
81
|
+
/**
|
|
82
|
+
* Get available capabilities for a specific suite.
|
|
83
|
+
*
|
|
84
|
+
* @param suiteId Suite identifier
|
|
85
|
+
* @returns Array of capability names
|
|
86
|
+
*/
|
|
87
|
+
getCapabilities(suiteId: string): string[];
|
|
88
|
+
/**
|
|
89
|
+
* Get all suite IDs that support a specific capability.
|
|
90
|
+
*
|
|
91
|
+
* @param capability Capability name
|
|
92
|
+
* @returns Array of suite IDs
|
|
93
|
+
*/
|
|
94
|
+
getSuitesWithCapability(capability: 'derivation' | 'encryption' | 'threshold'): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Create a Bitcoin wallet key from mnemonic (convenience method).
|
|
97
|
+
*
|
|
98
|
+
* Uses standard BIP44 Bitcoin path: m/44'/0'/account'/change/addressIndex
|
|
99
|
+
*
|
|
100
|
+
* @param agentId Agent identifier
|
|
101
|
+
* @param mnemonic BIP39 mnemonic phrase
|
|
102
|
+
* @param accountIndex Account index (default: 0)
|
|
103
|
+
* @param addressIndex Address index (default: 0)
|
|
104
|
+
* @param isChange Use change address path (default: false)
|
|
105
|
+
* @param options Additional key creation options
|
|
106
|
+
* @returns KeyRecord with Bitcoin-compatible key
|
|
107
|
+
*/
|
|
108
|
+
createBitcoinWalletKey(agentId: string, mnemonic: string, accountIndex?: number, addressIndex?: number, isChange?: boolean, options?: CreateKeyOptions): Promise<KeyRecord>;
|
|
60
109
|
/**
|
|
61
110
|
* Helper: Get hash algorithm for a suite.
|
|
62
111
|
*/
|
|
@@ -66,4 +115,19 @@ export declare class DefaultKeySDK implements KeySDK {
|
|
|
66
115
|
*/
|
|
67
116
|
private getNextCounter;
|
|
68
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Create a KeySDK instance with default configuration
|
|
120
|
+
*
|
|
121
|
+
* Uses in-memory storage and registers both ECDSA and ML-DSA suites.
|
|
122
|
+
* For custom storage or different suites, instantiate DefaultKeySDK directly.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* import { createKeySDK } from '@smartledger/keys';
|
|
127
|
+
*
|
|
128
|
+
* const sdk = createKeySDK();
|
|
129
|
+
* const key = await sdk.createKey('my-agent', { primarySignatureSuite: 'ml-dsa-87' });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function createKeySDK(config?: Partial<KeySDKConfig>): KeySDK;
|
|
69
133
|
//# sourceMappingURL=sdk.d.ts.map
|
package/dist/esm/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,WAAW,EACX,sBAAsB,EAEtB,aAAa,
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,WAAW,EACX,sBAAsB,EAEtB,aAAa,EAMd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,MAAM,EACN,SAAS,EACT,gBAAgB,EAEjB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,WAAW,EAAE,WAAW,CAAC;IAEzB,wCAAwC;IACxC,aAAa,EAAE,sBAAsB,CAAC;CACvC;AAED;;;;GAIG;AACH,qBAAa,aAA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D,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,SAAS,CAAC;IAarB;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAW1C;;;;;OAKG;IACH,uBAAuB,CAAC,UAAU,EAAE,YAAY,GAAG,YAAY,GAAG,WAAW,GAAG,MAAM,EAAE;IAOxF;;;;;;;;;;;;OAYG;IACG,sBAAsB,CAC1B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,YAAY,SAAI,EAChB,YAAY,SAAI,EAChB,QAAQ,UAAQ,EAChB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,SAAS,CAAC;IAarB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAOxB;;OAEG;IACH,OAAO,CAAC,cAAc;CAMvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,MAAM,CAcnE"}
|
package/dist/esm/sdk.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Integrates KeyRegistry and SignatureSuiteRegistry to provide
|
|
5
5
|
* a clean, high-level API for key operations.
|
|
6
6
|
*/
|
|
7
|
-
import { hashBytes, } from '@smartledger/crypto';
|
|
7
|
+
import { KeyRegistry, SignatureSuiteRegistry, hashBytes, BIP32Derivation, InMemoryKeyStorage, BsvEcdsaSuite, MlDsa87Suite, } from '@smartledger/crypto';
|
|
8
8
|
/**
|
|
9
9
|
* Default KeySDK implementation.
|
|
10
10
|
*
|
|
@@ -20,9 +20,27 @@ export class DefaultKeySDK {
|
|
|
20
20
|
* Create a new key for an agent.
|
|
21
21
|
*/
|
|
22
22
|
async createKey(agentId, profile, options = {}) {
|
|
23
|
-
//
|
|
23
|
+
// Get suite
|
|
24
24
|
const suite = this.suiteRegistry.getSuite(profile.primarySignatureSuite);
|
|
25
|
-
|
|
25
|
+
// Generate keypair (with optional derivation)
|
|
26
|
+
let keypair;
|
|
27
|
+
if (options.derivationContext) {
|
|
28
|
+
// Check if suite supports derivation
|
|
29
|
+
if (!suite.capabilities?.derivation) {
|
|
30
|
+
const available = this.getSuitesWithCapability('derivation');
|
|
31
|
+
throw new Error(`Suite '${suite.suiteId}' does not support key derivation.\n` +
|
|
32
|
+
(available.length > 0
|
|
33
|
+
? `Suites with derivation capability: ${available.join(', ')}\n` +
|
|
34
|
+
`Consider using one of these suites or remove the derivationContext option.`
|
|
35
|
+
: `No suites currently support derivation. Remove the derivationContext option.`));
|
|
36
|
+
}
|
|
37
|
+
// Use derivation capability
|
|
38
|
+
keypair = await suite.capabilities.derivation.deriveKeypair(options.derivationContext);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Standard random key generation
|
|
42
|
+
keypair = await suite.generateKeypair();
|
|
43
|
+
}
|
|
26
44
|
// Generate unique keyId
|
|
27
45
|
const counter = this.getNextCounter(agentId);
|
|
28
46
|
const suiteName = profile.primarySignatureSuite.split('-')[0]; // 'ml-dsa' or 'bsv'
|
|
@@ -164,6 +182,86 @@ export class DefaultKeySDK {
|
|
|
164
182
|
// Create new key
|
|
165
183
|
return await this.createKey(agentId, profile, options);
|
|
166
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Generate a new BIP39 mnemonic phrase.
|
|
187
|
+
*
|
|
188
|
+
* @param strength 128 (12 words) or 256 (24 words)
|
|
189
|
+
* @returns Mnemonic phrase
|
|
190
|
+
*/
|
|
191
|
+
generateMnemonic(strength = 256) {
|
|
192
|
+
const bip32 = new BIP32Derivation();
|
|
193
|
+
return bip32.generateMnemonic(strength);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Create a key from a BIP39 mnemonic using HD derivation.
|
|
197
|
+
*
|
|
198
|
+
* Only works with suites that support BIP32 derivation (e.g., bsv-ecdsa-secp256k1).
|
|
199
|
+
*
|
|
200
|
+
* @param agentId Agent identifier
|
|
201
|
+
* @param profile Crypto profile (must use derivation-capable suite)
|
|
202
|
+
* @param mnemonic BIP39 mnemonic phrase
|
|
203
|
+
* @param path BIP32 derivation path (default: "m/44'/0'/0'/0/0")
|
|
204
|
+
* @param passphrase Optional BIP39 passphrase
|
|
205
|
+
* @param options Additional key creation options
|
|
206
|
+
* @returns KeyRecord with derived key
|
|
207
|
+
*/
|
|
208
|
+
async createKeyFromMnemonic(agentId, profile, mnemonic, path = BIP32Derivation.bitcoinPath(0, 0, 0), passphrase, options = {}) {
|
|
209
|
+
const bip32 = new BIP32Derivation();
|
|
210
|
+
const seed = bip32.mnemonicToSeed(mnemonic, passphrase);
|
|
211
|
+
return await this.createKey(agentId, profile, {
|
|
212
|
+
...options,
|
|
213
|
+
derivationContext: {
|
|
214
|
+
seed,
|
|
215
|
+
path,
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get available capabilities for a specific suite.
|
|
221
|
+
*
|
|
222
|
+
* @param suiteId Suite identifier
|
|
223
|
+
* @returns Array of capability names
|
|
224
|
+
*/
|
|
225
|
+
getCapabilities(suiteId) {
|
|
226
|
+
const suite = this.suiteRegistry.getSuite(suiteId);
|
|
227
|
+
const caps = [];
|
|
228
|
+
if (suite.capabilities?.derivation)
|
|
229
|
+
caps.push('derivation');
|
|
230
|
+
if (suite.capabilities?.encryption)
|
|
231
|
+
caps.push('encryption');
|
|
232
|
+
if (suite.capabilities?.threshold)
|
|
233
|
+
caps.push('threshold');
|
|
234
|
+
return caps;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get all suite IDs that support a specific capability.
|
|
238
|
+
*
|
|
239
|
+
* @param capability Capability name
|
|
240
|
+
* @returns Array of suite IDs
|
|
241
|
+
*/
|
|
242
|
+
getSuitesWithCapability(capability) {
|
|
243
|
+
const allSuites = this.suiteRegistry.getAllSuites();
|
|
244
|
+
return allSuites
|
|
245
|
+
.filter(suite => !!suite.capabilities?.[capability])
|
|
246
|
+
.map(suite => suite.suiteId);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Create a Bitcoin wallet key from mnemonic (convenience method).
|
|
250
|
+
*
|
|
251
|
+
* Uses standard BIP44 Bitcoin path: m/44'/0'/account'/change/addressIndex
|
|
252
|
+
*
|
|
253
|
+
* @param agentId Agent identifier
|
|
254
|
+
* @param mnemonic BIP39 mnemonic phrase
|
|
255
|
+
* @param accountIndex Account index (default: 0)
|
|
256
|
+
* @param addressIndex Address index (default: 0)
|
|
257
|
+
* @param isChange Use change address path (default: false)
|
|
258
|
+
* @param options Additional key creation options
|
|
259
|
+
* @returns KeyRecord with Bitcoin-compatible key
|
|
260
|
+
*/
|
|
261
|
+
async createBitcoinWalletKey(agentId, mnemonic, accountIndex = 0, addressIndex = 0, isChange = false, options = {}) {
|
|
262
|
+
const path = BIP32Derivation.bitcoinPath(accountIndex, isChange ? 1 : 0, addressIndex);
|
|
263
|
+
return this.createKeyFromMnemonic(agentId, { primarySignatureSuite: 'bsv-ecdsa-secp256k1' }, mnemonic, path, undefined, options);
|
|
264
|
+
}
|
|
167
265
|
/**
|
|
168
266
|
* Helper: Get hash algorithm for a suite.
|
|
169
267
|
*/
|
|
@@ -183,4 +281,31 @@ export class DefaultKeySDK {
|
|
|
183
281
|
return next;
|
|
184
282
|
}
|
|
185
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Create a KeySDK instance with default configuration
|
|
286
|
+
*
|
|
287
|
+
* Uses in-memory storage and registers both ECDSA and ML-DSA suites.
|
|
288
|
+
* For custom storage or different suites, instantiate DefaultKeySDK directly.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```typescript
|
|
292
|
+
* import { createKeySDK } from '@smartledger/keys';
|
|
293
|
+
*
|
|
294
|
+
* const sdk = createKeySDK();
|
|
295
|
+
* const key = await sdk.createKey('my-agent', { primarySignatureSuite: 'ml-dsa-87' });
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
export function createKeySDK(config) {
|
|
299
|
+
const keyRegistry = config?.keyRegistry || new KeyRegistry(new InMemoryKeyStorage());
|
|
300
|
+
const suiteRegistry = config?.suiteRegistry || new SignatureSuiteRegistry();
|
|
301
|
+
// Register default suites if not provided
|
|
302
|
+
if (!config?.suiteRegistry) {
|
|
303
|
+
suiteRegistry.register(new BsvEcdsaSuite());
|
|
304
|
+
suiteRegistry.register(new MlDsa87Suite());
|
|
305
|
+
}
|
|
306
|
+
return new DefaultKeySDK({
|
|
307
|
+
keyRegistry,
|
|
308
|
+
suiteRegistry,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
186
311
|
//# sourceMappingURL=sdk.js.map
|