@taquito/signer 23.0.3 → 24.0.0-beta.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/lib/derivation-tools/ecdsa.js +43 -22
- package/dist/lib/derivation-tools/ed25519.js +2 -2
- package/dist/lib/derivation-tools/index.js +18 -3
- package/dist/lib/derivation-tools/types.js +4 -0
- package/dist/lib/ec-key.js +78 -61
- package/dist/lib/helpers.js +1 -1
- package/dist/lib/in-memory-signer.js +216 -0
- package/dist/lib/taquito-signer.js +4 -217
- package/dist/lib/version.js +2 -2
- package/dist/taquito-signer.es6.js +197 -208
- package/dist/taquito-signer.es6.js.map +1 -1
- package/dist/taquito-signer.umd.js +196 -209
- package/dist/taquito-signer.umd.js.map +1 -1
- package/dist/types/derivation-tools/ecdsa.d.ts +15 -10
- package/dist/types/derivation-tools/ed25519.d.ts +1 -1
- package/dist/types/derivation-tools/index.d.ts +1 -10
- package/dist/types/derivation-tools/types.d.ts +10 -0
- package/dist/types/ec-key.d.ts +5 -9
- package/dist/types/in-memory-signer.d.ts +60 -0
- package/dist/types/key-interface.d.ts +20 -0
- package/dist/types/taquito-signer.d.ts +5 -61
- package/package.json +8 -10
- package/dist/lib/import-key.js +0 -51
- package/dist/types/import-key.d.ts +0 -13
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@stablelib/nacl'), require('@taquito/utils'), require('typedarray-to-buffer'), require('@stablelib/blake2b'), require('@stablelib/ed25519'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@stablelib/nacl', '@taquito/utils', 'typedarray-to-buffer', '@stablelib/blake2b', '@stablelib/ed25519', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoSigner = {}, global.nacl, global.utils, global.toBuffer, global.blake2b, global.ed25519$1, global.
|
|
5
|
-
})(this, (function (exports, nacl, utils, toBuffer, blake2b, ed25519$1,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@stablelib/nacl'), require('@taquito/utils'), require('typedarray-to-buffer'), require('@stablelib/blake2b'), require('@stablelib/ed25519'), require('@noble/curves/secp256k1'), require('@noble/curves/nist.js'), require('@taquito/core'), require('pbkdf2'), require('bip39'), require('@stablelib/hmac'), require('@stablelib/sha512'), require('@noble/curves/nist'), require('bn.js'), require('@noble/curves/bls12-381')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@stablelib/nacl', '@taquito/utils', 'typedarray-to-buffer', '@stablelib/blake2b', '@stablelib/ed25519', '@noble/curves/secp256k1', '@noble/curves/nist.js', '@taquito/core', 'pbkdf2', 'bip39', '@stablelib/hmac', '@stablelib/sha512', '@noble/curves/nist', 'bn.js', '@noble/curves/bls12-381'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoSigner = {}, global.nacl, global.utils, global.toBuffer, global.blake2b, global.ed25519$1, global.secp256k1, global.nist, global.core, global.pbkdf2, global.Bip39, global.hmac, global.sha512, global.nist, global.BN, global.bls12381));
|
|
5
|
+
})(this, (function (exports, nacl, utils, toBuffer, blake2b, ed25519$1, secp256k1, nist_js, core, pbkdf2, Bip39, hmac, sha512, nist, BN, bls12381) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
38
38
|
PERFORMANCE OF THIS SOFTWARE.
|
|
39
39
|
***************************************************************************** */
|
|
40
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
40
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
@@ -241,6 +241,7 @@
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
var _ECKey_keyPair, _ECPublicKey_key;
|
|
244
245
|
const pref = {
|
|
245
246
|
p256: {
|
|
246
247
|
pk: utils.PrefixV2.P256PublicKey,
|
|
@@ -257,27 +258,10 @@
|
|
|
257
258
|
tag: 1,
|
|
258
259
|
},
|
|
259
260
|
};
|
|
260
|
-
class ECKeyBase {
|
|
261
|
-
constructor(keyPair) {
|
|
262
|
-
this.keyPair = keyPair;
|
|
263
|
-
}
|
|
264
|
-
curve() {
|
|
265
|
-
switch (this.keyPair.ec.curve) {
|
|
266
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
267
|
-
case elliptic.curves.secp256k1.curve:
|
|
268
|
-
return 'secp256k1';
|
|
269
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
270
|
-
case elliptic.curves.p256.curve:
|
|
271
|
-
return 'p256';
|
|
272
|
-
default:
|
|
273
|
-
throw new InvalidCurveError('unknown curve');
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
261
|
/**
|
|
278
262
|
* @description Provide signing logic for elliptic curve based key (tz2, tz3)
|
|
279
263
|
*/
|
|
280
|
-
class ECKey
|
|
264
|
+
class ECKey {
|
|
281
265
|
/**
|
|
282
266
|
*
|
|
283
267
|
* @param key Encoded private key
|
|
@@ -285,6 +269,7 @@
|
|
|
285
269
|
* @throws {@link InvalidKeyError}
|
|
286
270
|
*/
|
|
287
271
|
constructor(key, decrypt) {
|
|
272
|
+
_ECKey_keyPair.set(this, void 0);
|
|
288
273
|
const [keyData, prefix] = utils.b58DecodeAndCheckPrefix(key, [
|
|
289
274
|
utils.PrefixV2.Secp256k1EncryptedSecretKey,
|
|
290
275
|
utils.PrefixV2.P256EncryptedSecretKey,
|
|
@@ -310,7 +295,13 @@
|
|
|
310
295
|
return [keyData, 'p256'];
|
|
311
296
|
}
|
|
312
297
|
})();
|
|
313
|
-
|
|
298
|
+
__classPrivateFieldSet(this, _ECKey_keyPair, {
|
|
299
|
+
curve,
|
|
300
|
+
secretKey: decKey,
|
|
301
|
+
publicKey: curve === 'secp256k1'
|
|
302
|
+
? secp256k1.secp256k1.getPublicKey(decKey, true)
|
|
303
|
+
: nist_js.p256.getPublicKey(decKey, true),
|
|
304
|
+
}, "f");
|
|
314
305
|
}
|
|
315
306
|
/**
|
|
316
307
|
*
|
|
@@ -319,68 +310,71 @@
|
|
|
319
310
|
*/
|
|
320
311
|
sign(bytes) {
|
|
321
312
|
const hash = blake2b.hash(bytes, 32);
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
313
|
+
let signature;
|
|
314
|
+
if (__classPrivateFieldGet(this, _ECKey_keyPair, "f").curve === 'secp256k1') {
|
|
315
|
+
signature = secp256k1.secp256k1
|
|
316
|
+
.sign(hash, __classPrivateFieldGet(this, _ECKey_keyPair, "f").secretKey, {
|
|
317
|
+
lowS: true, // Use canonical signatures (prevents malleability)
|
|
318
|
+
})
|
|
319
|
+
.toBytes('compact');
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
signature = nist_js.p256
|
|
323
|
+
.sign(hash, __classPrivateFieldGet(this, _ECKey_keyPair, "f").secretKey, {
|
|
324
|
+
lowS: true, // Use canonical signatures (prevents malleability)
|
|
325
|
+
})
|
|
326
|
+
.toBytes('compact');
|
|
327
|
+
}
|
|
328
328
|
return {
|
|
329
329
|
rawSignature: signature,
|
|
330
330
|
sig: utils.b58Encode(signature, utils.PrefixV2.GenericSignature),
|
|
331
|
-
prefixSig: utils.b58Encode(signature, pref[this.curve
|
|
331
|
+
prefixSig: utils.b58Encode(signature, pref[__classPrivateFieldGet(this, _ECKey_keyPair, "f").curve].sig),
|
|
332
332
|
};
|
|
333
333
|
}
|
|
334
334
|
/**
|
|
335
335
|
* @returns Encoded public key
|
|
336
336
|
*/
|
|
337
337
|
publicKey() {
|
|
338
|
-
return new ECPublicKey(this.
|
|
338
|
+
return new ECPublicKey(__classPrivateFieldGet(this, _ECKey_keyPair, "f").publicKey, __classPrivateFieldGet(this, _ECKey_keyPair, "f").curve);
|
|
339
339
|
}
|
|
340
340
|
/**
|
|
341
341
|
* @returns Encoded private key
|
|
342
342
|
*/
|
|
343
343
|
secretKey() {
|
|
344
|
-
return utils.b58Encode(
|
|
344
|
+
return utils.b58Encode(__classPrivateFieldGet(this, _ECKey_keyPair, "f").secretKey, pref[__classPrivateFieldGet(this, _ECKey_keyPair, "f").curve].sk);
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
class ECPublicKey extends ECKeyBase {
|
|
347
|
+
_ECKey_keyPair = new WeakMap();
|
|
348
|
+
class ECPublicKey {
|
|
351
349
|
constructor(src, curve) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
350
|
+
_ECPublicKey_key.set(this, void 0);
|
|
351
|
+
const [key, crv] = (() => {
|
|
352
|
+
if (typeof src === 'string') {
|
|
353
|
+
const [key, pre] = utils.b58DecodeAndCheckPrefix(src, [
|
|
354
|
+
utils.PrefixV2.Secp256k1PublicKey,
|
|
355
|
+
utils.PrefixV2.P256PublicKey,
|
|
356
|
+
]);
|
|
357
|
+
return [key, pre === utils.PrefixV2.Secp256k1PublicKey ? 'secp256k1' : 'p256'];
|
|
358
|
+
}
|
|
359
|
+
else if (curve !== undefined) {
|
|
360
|
+
return [src, curve];
|
|
355
361
|
}
|
|
356
362
|
else {
|
|
357
|
-
|
|
358
|
-
if (typeof src === 'string') {
|
|
359
|
-
const [key, pre] = utils.b58DecodeAndCheckPrefix(src, [
|
|
360
|
-
utils.PrefixV2.Secp256k1PublicKey,
|
|
361
|
-
utils.PrefixV2.P256PublicKey,
|
|
362
|
-
]);
|
|
363
|
-
return [key, pre === utils.PrefixV2.Secp256k1PublicKey ? 'secp256k1' : 'p256'];
|
|
364
|
-
}
|
|
365
|
-
else if (curve !== undefined) {
|
|
366
|
-
return [src, curve];
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
throw new InvalidCurveError('missing curve type');
|
|
370
|
-
}
|
|
371
|
-
})();
|
|
372
|
-
return new elliptic.ec(crv).keyFromPublic(key);
|
|
363
|
+
throw new InvalidCurveError('missing curve type');
|
|
373
364
|
}
|
|
374
365
|
})();
|
|
375
|
-
|
|
366
|
+
// For ECPublicKey, we don't need the private key, so we pass an empty array
|
|
367
|
+
// The public key is stored separately
|
|
368
|
+
__classPrivateFieldSet(this, _ECPublicKey_key, key, "f");
|
|
369
|
+
this.curve = crv;
|
|
376
370
|
}
|
|
377
371
|
compare(other) {
|
|
378
372
|
if (other instanceof ECPublicKey) {
|
|
379
|
-
if (this.curve
|
|
380
|
-
const compress = this.curve
|
|
373
|
+
if (this.curve === other.curve) {
|
|
374
|
+
const compress = this.curve === 'secp256k1';
|
|
381
375
|
return utils.compareArrays(this.bytes(compress), other.bytes(compress));
|
|
382
376
|
}
|
|
383
|
-
else if (this.curve
|
|
377
|
+
else if (this.curve === 'secp256k1') {
|
|
384
378
|
return -1;
|
|
385
379
|
}
|
|
386
380
|
else {
|
|
@@ -393,23 +387,37 @@
|
|
|
393
387
|
}
|
|
394
388
|
hash() {
|
|
395
389
|
const key = this.bytes();
|
|
396
|
-
return utils.b58Encode(blake2b.hash(key, 20), pref[this.curve
|
|
390
|
+
return utils.b58Encode(blake2b.hash(key, 20), pref[this.curve].pkh);
|
|
397
391
|
}
|
|
398
392
|
bytes(compress = true) {
|
|
399
|
-
|
|
393
|
+
// @noble/curves supports both compressed and uncompressed formats
|
|
394
|
+
// We need to convert the stored public key to the requested format
|
|
395
|
+
if (this.curve === 'secp256k1') {
|
|
396
|
+
// For secp256k1, we need to get the public key from the stored bytes and convert format
|
|
397
|
+
const point = secp256k1.secp256k1.Point.fromHex(__classPrivateFieldGet(this, _ECPublicKey_key, "f"));
|
|
398
|
+
return point.toBytes(compress);
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
// For p256, we need to get the public key from the stored bytes and convert format
|
|
402
|
+
const point = nist_js.p256.Point.fromHex(__classPrivateFieldGet(this, _ECPublicKey_key, "f"));
|
|
403
|
+
return point.toBytes(compress);
|
|
404
|
+
}
|
|
400
405
|
}
|
|
401
406
|
toProtocol() {
|
|
402
407
|
const key = this.bytes();
|
|
403
408
|
const res = new Uint8Array(key.length + 1);
|
|
404
|
-
res[0] = pref[this.curve
|
|
409
|
+
res[0] = pref[this.curve].tag;
|
|
405
410
|
res.set(key, 1);
|
|
406
411
|
return res;
|
|
407
412
|
}
|
|
408
413
|
toString() {
|
|
409
414
|
const key = this.bytes();
|
|
410
|
-
return utils.b58Encode(key, pref[this.curve
|
|
415
|
+
return utils.b58Encode(key, pref[this.curve].pk);
|
|
411
416
|
}
|
|
412
417
|
}
|
|
418
|
+
_ECPublicKey_key = new WeakMap();
|
|
419
|
+
|
|
420
|
+
const Hard = 0x80000000;
|
|
413
421
|
|
|
414
422
|
function parseHex(s) {
|
|
415
423
|
const res = [];
|
|
@@ -424,24 +432,104 @@
|
|
|
424
432
|
return new Uint8Array(res);
|
|
425
433
|
}
|
|
426
434
|
|
|
435
|
+
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
436
|
+
// MinSeedSize is the minimal allowed seed byte length
|
|
437
|
+
const minSeedSize$1 = 16;
|
|
438
|
+
// MaxSeedSize is the maximal allowed seed byte length
|
|
439
|
+
const maxSeedSize$1 = 64;
|
|
440
|
+
const ed25519Key = 'ed25519 seed';
|
|
441
|
+
let PrivateKey$1 = class PrivateKey {
|
|
442
|
+
/**
|
|
443
|
+
*
|
|
444
|
+
* @param priv generated keypair 0->32 private key 32->n public key
|
|
445
|
+
* @param chainCode new HMAC hash with new key
|
|
446
|
+
*/
|
|
447
|
+
constructor(priv, chainCode) {
|
|
448
|
+
this.priv = priv;
|
|
449
|
+
this.chainCode = chainCode;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
*
|
|
453
|
+
* @param seedSrc result of Bip39.mnemonicToSeed
|
|
454
|
+
* @returns instance of PrivateKey
|
|
455
|
+
* @throws {@link InvalidSeedLengthError}
|
|
456
|
+
*/
|
|
457
|
+
static fromSeed(seedSrc) {
|
|
458
|
+
const seed = typeof seedSrc === 'string' ? parseHex(seedSrc) : seedSrc;
|
|
459
|
+
if (seed.length < minSeedSize$1 || seed.length > maxSeedSize$1) {
|
|
460
|
+
throw new InvalidSeedLengthError(seed.length);
|
|
461
|
+
}
|
|
462
|
+
const key = new TextEncoder().encode(ed25519Key);
|
|
463
|
+
const sum = new hmac.HMAC(sha512.SHA512, key).update(seed).digest();
|
|
464
|
+
return new PrivateKey(ed25519$1.generateKeyPairFromSeed(sum.subarray(0, 32)).secretKey, sum.subarray(32));
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
*
|
|
468
|
+
* @returns slice(0, 32) of current priv for new seed for next derived priv
|
|
469
|
+
*/
|
|
470
|
+
seed() {
|
|
471
|
+
return this.priv.subarray(0, 32);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* @index current derivation path item ie: 1729'
|
|
475
|
+
* @returns derivation path child of original private key pair
|
|
476
|
+
*/
|
|
477
|
+
derive(index) {
|
|
478
|
+
if ((index & Hard) === 0) {
|
|
479
|
+
throw new core.InvalidDerivationPathError(index.toString(), ': Non-hardened derivation path.');
|
|
480
|
+
}
|
|
481
|
+
const data = new Uint8Array(37);
|
|
482
|
+
data.set(this.seed(), 1);
|
|
483
|
+
new DataView(data.buffer).setUint32(33, index);
|
|
484
|
+
const sum = new hmac.HMAC(sha512.SHA512, this.chainCode).update(data).digest();
|
|
485
|
+
return new PrivateKey(ed25519$1.generateKeyPairFromSeed(sum.subarray(0, 32)).secretKey, sum.subarray(32));
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* @param path array of numbers pre adjusted for hardened paths ie: 44' -> 2^31 + 44
|
|
489
|
+
* @returns final child of full derivation path private key pair
|
|
490
|
+
*/
|
|
491
|
+
derivePath(path) {
|
|
492
|
+
let key = this;
|
|
493
|
+
for (const index of path) {
|
|
494
|
+
key = key.derive(index);
|
|
495
|
+
}
|
|
496
|
+
return key;
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
var ed25519 = /*#__PURE__*/Object.freeze({
|
|
501
|
+
__proto__: null,
|
|
502
|
+
PrivateKey: PrivateKey$1
|
|
503
|
+
});
|
|
504
|
+
|
|
427
505
|
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
428
506
|
const seedKey = {
|
|
429
507
|
p256: 'Nist256p1 seed',
|
|
430
508
|
secp256k1: 'Bitcoin seed',
|
|
431
509
|
};
|
|
432
510
|
// MinSeedSize is the minimal allowed seed byte length
|
|
433
|
-
const minSeedSize
|
|
511
|
+
const minSeedSize = 16;
|
|
434
512
|
// MaxSeedSize is the maximal allowed seed byte length
|
|
435
|
-
const maxSeedSize
|
|
436
|
-
|
|
513
|
+
const maxSeedSize = 64;
|
|
514
|
+
class PrivateKey {
|
|
437
515
|
/**
|
|
438
516
|
*
|
|
439
|
-
* @param priv
|
|
517
|
+
* @param priv { secretKey: BN, curve: 'p256' | 'secp256k1' }
|
|
440
518
|
* @param chainCode slice 32->n HMAC hash key and seedkey (first instance curve default seedKey. after hmac value slice 32->n)
|
|
441
519
|
*/
|
|
442
520
|
constructor(priv, chainCode) {
|
|
521
|
+
this.priv = priv;
|
|
443
522
|
this.chainCode = chainCode;
|
|
444
|
-
|
|
523
|
+
const privateKeyBytes = priv.secretKey.toArray('be', 32);
|
|
524
|
+
const privateKeyUint8 = new Uint8Array(privateKeyBytes);
|
|
525
|
+
const publicKey = priv.curve === 'secp256k1'
|
|
526
|
+
? secp256k1.secp256k1.getPublicKey(privateKeyUint8, true) // compressed public key
|
|
527
|
+
: nist.p256.getPublicKey(privateKeyUint8, true); // compressed public key
|
|
528
|
+
this.keyPair = {
|
|
529
|
+
curve: priv.curve,
|
|
530
|
+
secretKey: priv.secretKey,
|
|
531
|
+
publicKey: publicKey,
|
|
532
|
+
};
|
|
445
533
|
}
|
|
446
534
|
/**
|
|
447
535
|
* @param seedSrc result of Bip39.mnemonicToSeed
|
|
@@ -450,17 +538,23 @@
|
|
|
450
538
|
* @throws {@link InvalidBitSize} | {@link InvalidCurveError} | {@link InvalidSeedLengthError}
|
|
451
539
|
*/
|
|
452
540
|
static fromSeed(seedSrc, curve) {
|
|
453
|
-
var _a, _b;
|
|
454
541
|
let seed = typeof seedSrc === 'string' ? parseHex(seedSrc) : seedSrc;
|
|
455
|
-
if (seed.length < minSeedSize
|
|
542
|
+
if (seed.length < minSeedSize || seed.length > maxSeedSize) {
|
|
456
543
|
throw new InvalidSeedLengthError(seed.length);
|
|
457
544
|
}
|
|
458
545
|
if (!Object.prototype.hasOwnProperty.call(seedKey, curve)) {
|
|
459
546
|
throw new InvalidCurveError(`Unsupported curve "${curve}" expecting either "p256" or "secp256k1"`);
|
|
460
547
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
548
|
+
// Get curve order for validation
|
|
549
|
+
let curveOrder;
|
|
550
|
+
if (curve === 'secp256k1') {
|
|
551
|
+
curveOrder = new BN(secp256k1.secp256k1.Point.CURVE().n.toString());
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
curveOrder = new BN(nist.p256.Point.CURVE().n.toString());
|
|
555
|
+
}
|
|
556
|
+
if (curveOrder.bitLength() !== 256) {
|
|
557
|
+
throw new InvalidBitSize(`Invalid curve "${curve}" with bit size "${curveOrder.bitLength()}" expecting bit size "256"`);
|
|
464
558
|
}
|
|
465
559
|
const key = new TextEncoder().encode(seedKey[curve]);
|
|
466
560
|
let d = null;
|
|
@@ -470,16 +564,14 @@
|
|
|
470
564
|
const sum = new hmac.HMAC(sha512.SHA512, key).update(seed).digest();
|
|
471
565
|
d = new BN(sum.subarray(0, 32));
|
|
472
566
|
chain = sum.subarray(32);
|
|
473
|
-
if (d.isZero() || d.cmp(
|
|
567
|
+
if (d.isZero() || d.cmp(curveOrder) >= 0) {
|
|
474
568
|
seed = sum;
|
|
475
569
|
}
|
|
476
570
|
else {
|
|
477
571
|
i++;
|
|
478
572
|
}
|
|
479
573
|
}
|
|
480
|
-
|
|
481
|
-
keyPair.priv = d;
|
|
482
|
-
return new PrivateKey(keyPair, chain);
|
|
574
|
+
return new PrivateKey({ curve, secretKey: d }, chain);
|
|
483
575
|
}
|
|
484
576
|
/**
|
|
485
577
|
*
|
|
@@ -490,10 +582,10 @@
|
|
|
490
582
|
const data = new Uint8Array(37);
|
|
491
583
|
if ((index & Hard) !== 0) {
|
|
492
584
|
// hardened derivation
|
|
493
|
-
data.set(this.keyPair.
|
|
585
|
+
data.set(this.keyPair.secretKey.toArray(), 1);
|
|
494
586
|
}
|
|
495
587
|
else {
|
|
496
|
-
data.set(this.keyPair.
|
|
588
|
+
data.set(this.keyPair.publicKey, 0);
|
|
497
589
|
}
|
|
498
590
|
new DataView(data.buffer).setUint32(33, index);
|
|
499
591
|
let d = new BN(0);
|
|
@@ -503,8 +595,16 @@
|
|
|
503
595
|
const sum = new hmac.HMAC(sha512.SHA512, this.chainCode).update(data).digest();
|
|
504
596
|
d = new BN(sum.subarray(0, 32));
|
|
505
597
|
chain = sum.subarray(32);
|
|
506
|
-
|
|
507
|
-
|
|
598
|
+
// Get curve order for comparison
|
|
599
|
+
let curveOrder;
|
|
600
|
+
if (this.keyPair.curve === 'secp256k1') {
|
|
601
|
+
curveOrder = new BN(secp256k1.secp256k1.Point.CURVE().n.toString());
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
curveOrder = new BN(nist.p256.Point.CURVE().n.toString());
|
|
605
|
+
}
|
|
606
|
+
if (d.cmp(curveOrder) < 0) {
|
|
607
|
+
d = d.add(this.keyPair.secretKey).mod(curveOrder);
|
|
508
608
|
if (!d.isZero()) {
|
|
509
609
|
i++;
|
|
510
610
|
}
|
|
@@ -512,9 +612,7 @@
|
|
|
512
612
|
data.set(chain, 1);
|
|
513
613
|
data[0] = 1;
|
|
514
614
|
}
|
|
515
|
-
|
|
516
|
-
keyPair.priv = d;
|
|
517
|
-
return new PrivateKey(keyPair, chain);
|
|
615
|
+
return new PrivateKey({ curve: this.keyPair.curve, secretKey: d }, chain);
|
|
518
616
|
}
|
|
519
617
|
/**
|
|
520
618
|
*
|
|
@@ -534,23 +632,22 @@
|
|
|
534
632
|
* @throws {@link InvalidKeyError}
|
|
535
633
|
*/
|
|
536
634
|
bytes() {
|
|
537
|
-
if (!this.keyPair.
|
|
635
|
+
if (!this.keyPair.secretKey) {
|
|
538
636
|
throw new core.InvalidKeyError('missing private key');
|
|
539
637
|
}
|
|
540
638
|
// pad to 32 bytes as toArray() length argument seems to be ignored (BN bug)
|
|
541
|
-
const src = this.keyPair.
|
|
639
|
+
const src = this.keyPair.secretKey.toArray();
|
|
542
640
|
const out = new Uint8Array(32);
|
|
543
641
|
out.set(src, out.length - src.length);
|
|
544
642
|
return out;
|
|
545
643
|
}
|
|
546
|
-
}
|
|
644
|
+
}
|
|
547
645
|
|
|
548
646
|
var ecdsa = /*#__PURE__*/Object.freeze({
|
|
549
647
|
__proto__: null,
|
|
550
|
-
PrivateKey: PrivateKey
|
|
648
|
+
PrivateKey: PrivateKey
|
|
551
649
|
});
|
|
552
650
|
|
|
553
|
-
const Hard = 0x80000000;
|
|
554
651
|
class Path extends Array {
|
|
555
652
|
static from(iterable) {
|
|
556
653
|
return super.from(iterable).map((x) => x >>> 0);
|
|
@@ -586,76 +683,6 @@
|
|
|
586
683
|
}
|
|
587
684
|
}
|
|
588
685
|
|
|
589
|
-
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
590
|
-
// MinSeedSize is the minimal allowed seed byte length
|
|
591
|
-
const minSeedSize = 16;
|
|
592
|
-
// MaxSeedSize is the maximal allowed seed byte length
|
|
593
|
-
const maxSeedSize = 64;
|
|
594
|
-
const ed25519Key = 'ed25519 seed';
|
|
595
|
-
class PrivateKey {
|
|
596
|
-
/**
|
|
597
|
-
*
|
|
598
|
-
* @param priv generated keypair 0->32 private key 32->n public key
|
|
599
|
-
* @param chainCode new HMAC hash with new key
|
|
600
|
-
*/
|
|
601
|
-
constructor(priv, chainCode) {
|
|
602
|
-
this.priv = priv;
|
|
603
|
-
this.chainCode = chainCode;
|
|
604
|
-
}
|
|
605
|
-
/**
|
|
606
|
-
*
|
|
607
|
-
* @param seedSrc result of Bip39.mnemonicToSeed
|
|
608
|
-
* @returns instance of PrivateKey
|
|
609
|
-
* @throws {@link InvalidSeedLengthError}
|
|
610
|
-
*/
|
|
611
|
-
static fromSeed(seedSrc) {
|
|
612
|
-
const seed = typeof seedSrc === 'string' ? parseHex(seedSrc) : seedSrc;
|
|
613
|
-
if (seed.length < minSeedSize || seed.length > maxSeedSize) {
|
|
614
|
-
throw new InvalidSeedLengthError(seed.length);
|
|
615
|
-
}
|
|
616
|
-
const key = new TextEncoder().encode(ed25519Key);
|
|
617
|
-
const sum = new hmac.HMAC(sha512.SHA512, key).update(seed).digest();
|
|
618
|
-
return new PrivateKey(ed25519$1.generateKeyPairFromSeed(sum.subarray(0, 32)).secretKey, sum.subarray(32));
|
|
619
|
-
}
|
|
620
|
-
/**
|
|
621
|
-
*
|
|
622
|
-
* @returns slice(0, 32) of current priv for new seed for next derived priv
|
|
623
|
-
*/
|
|
624
|
-
seed() {
|
|
625
|
-
return this.priv.subarray(0, 32);
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* @index current derivation path item ie: 1729'
|
|
629
|
-
* @returns derivation path child of original private key pair
|
|
630
|
-
*/
|
|
631
|
-
derive(index) {
|
|
632
|
-
if ((index & Hard) === 0) {
|
|
633
|
-
throw new core.InvalidDerivationPathError(index.toString(), ': Non-hardened derivation path.');
|
|
634
|
-
}
|
|
635
|
-
const data = new Uint8Array(37);
|
|
636
|
-
data.set(this.seed(), 1);
|
|
637
|
-
new DataView(data.buffer).setUint32(33, index);
|
|
638
|
-
const sum = new hmac.HMAC(sha512.SHA512, this.chainCode).update(data).digest();
|
|
639
|
-
return new PrivateKey(ed25519$1.generateKeyPairFromSeed(sum.subarray(0, 32)).secretKey, sum.subarray(32));
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* @param path array of numbers pre adjusted for hardened paths ie: 44' -> 2^31 + 44
|
|
643
|
-
* @returns final child of full derivation path private key pair
|
|
644
|
-
*/
|
|
645
|
-
derivePath(path) {
|
|
646
|
-
let key = this;
|
|
647
|
-
for (const index of path) {
|
|
648
|
-
key = key.derive(index);
|
|
649
|
-
}
|
|
650
|
-
return key;
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
var ed25519 = /*#__PURE__*/Object.freeze({
|
|
655
|
-
__proto__: null,
|
|
656
|
-
PrivateKey: PrivateKey
|
|
657
|
-
});
|
|
658
|
-
|
|
659
686
|
// bip32 when supported add to @param curve bip25519
|
|
660
687
|
/**
|
|
661
688
|
*
|
|
@@ -670,16 +697,16 @@
|
|
|
670
697
|
let node;
|
|
671
698
|
switch (curve) {
|
|
672
699
|
case 'ed25519': {
|
|
673
|
-
node = PrivateKey.fromSeed(seed).derivePath(path);
|
|
700
|
+
node = PrivateKey$1.fromSeed(seed).derivePath(path);
|
|
674
701
|
const sk = utils.b58Encode(node.seed().slice(0, 32), utils.PrefixV2.Ed25519Seed);
|
|
675
702
|
return sk;
|
|
676
703
|
}
|
|
677
704
|
case 'secp256k1':
|
|
678
705
|
case 'p256': {
|
|
679
706
|
const prefixType = curve === 'secp256k1' ? utils.PrefixV2.Secp256k1SecretKey : utils.PrefixV2.P256SecretKey;
|
|
680
|
-
let privKey = PrivateKey
|
|
707
|
+
let privKey = PrivateKey.fromSeed(seed, curve);
|
|
681
708
|
privKey = privKey.derivePath(path);
|
|
682
|
-
const uint8arr = new Uint8Array(privKey.keyPair.
|
|
709
|
+
const uint8arr = new Uint8Array(privKey.keyPair.secretKey.toArray());
|
|
683
710
|
const sk = utils.b58Encode(uint8arr, prefixType);
|
|
684
711
|
return sk;
|
|
685
712
|
}
|
|
@@ -782,51 +809,6 @@
|
|
|
782
809
|
}
|
|
783
810
|
_BLSPublicKey_key = new WeakMap();
|
|
784
811
|
|
|
785
|
-
/**
|
|
786
|
-
*
|
|
787
|
-
* @description Import a key to sign operation with the side-effect of setting the Tezos instance to use the InMemorySigner provider
|
|
788
|
-
*
|
|
789
|
-
* @warn The JSON faucets are no longer available on https://teztnets.com/
|
|
790
|
-
* @param toolkit The toolkit instance to attach a signer
|
|
791
|
-
* @param privateKeyOrEmail Key to load in memory
|
|
792
|
-
* @param passphrase If the key is encrypted passphrase to decrypt it
|
|
793
|
-
* @param mnemonic Faucet mnemonic
|
|
794
|
-
* @param secret Faucet secret
|
|
795
|
-
*/
|
|
796
|
-
function importKey(toolkit, privateKeyOrEmail, passphrase, mnemonic, secret) {
|
|
797
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
798
|
-
if (privateKeyOrEmail && passphrase && mnemonic && secret) {
|
|
799
|
-
const signer = InMemorySigner.fromFundraiser(privateKeyOrEmail, passphrase, mnemonic);
|
|
800
|
-
toolkit.setProvider({ signer });
|
|
801
|
-
const pkh = yield signer.publicKeyHash();
|
|
802
|
-
let op;
|
|
803
|
-
try {
|
|
804
|
-
op = yield toolkit.tz.activate(pkh, secret);
|
|
805
|
-
}
|
|
806
|
-
catch (ex) {
|
|
807
|
-
const isInvalidActivationError = ex && ex.body && /Invalid activation/.test(ex.body);
|
|
808
|
-
if (!isInvalidActivationError) {
|
|
809
|
-
throw ex;
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
if (op) {
|
|
813
|
-
yield op.confirmation();
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
else {
|
|
817
|
-
// Fallback to regular import
|
|
818
|
-
const signer = yield InMemorySigner.fromSecretKey(privateKeyOrEmail, passphrase);
|
|
819
|
-
toolkit.setProvider({ signer });
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
825
|
-
const VERSION = {
|
|
826
|
-
"commitHash": "42048d039f6d4345fc59d04b03650bcb8e27bb62",
|
|
827
|
-
"version": "23.0.3"
|
|
828
|
-
};
|
|
829
|
-
|
|
830
812
|
var _InMemorySigner_key;
|
|
831
813
|
/**
|
|
832
814
|
* @description A local implementation of the signer. Will represent a Tezos account and be able to produce signature in its behalf
|
|
@@ -1007,6 +989,12 @@
|
|
|
1007
989
|
}
|
|
1008
990
|
}
|
|
1009
991
|
|
|
992
|
+
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
993
|
+
const VERSION = {
|
|
994
|
+
"commitHash": "7912b77f57f943dff619383900bd46a7a593a244",
|
|
995
|
+
"version": "24.0.0-beta.0"
|
|
996
|
+
};
|
|
997
|
+
|
|
1010
998
|
exports.ECDSA = ecdsa;
|
|
1011
999
|
exports.Ed25519 = ed25519;
|
|
1012
1000
|
exports.Hard = Hard;
|
|
@@ -1015,7 +1003,6 @@
|
|
|
1015
1003
|
exports.Path = Path;
|
|
1016
1004
|
exports.VERSION = VERSION;
|
|
1017
1005
|
exports.generateSecretKey = generateSecretKey;
|
|
1018
|
-
exports.importKey = importKey;
|
|
1019
1006
|
exports.publicKeyFromString = publicKeyFromString;
|
|
1020
1007
|
|
|
1021
1008
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taquito-signer.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"taquito-signer.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ExtendedPrivateKey } from './index';
|
|
1
|
+
import { ExtendedPrivateKey } from './types';
|
|
3
2
|
import BN from 'bn.js';
|
|
4
3
|
export type CurveName = 'p256' | 'secp256k1';
|
|
5
|
-
interface KeyPair extends ec.KeyPair {
|
|
6
|
-
priv: BN | null;
|
|
7
|
-
pub: curve.base.BasePoint | null;
|
|
8
|
-
}
|
|
9
4
|
export declare class PrivateKey implements ExtendedPrivateKey {
|
|
5
|
+
readonly priv: {
|
|
6
|
+
curve: CurveName;
|
|
7
|
+
secretKey: BN;
|
|
8
|
+
};
|
|
10
9
|
readonly chainCode: Uint8Array;
|
|
11
|
-
readonly keyPair:
|
|
10
|
+
readonly keyPair: {
|
|
11
|
+
curve: CurveName;
|
|
12
|
+
secretKey: BN;
|
|
13
|
+
publicKey: Uint8Array;
|
|
14
|
+
};
|
|
12
15
|
/**
|
|
13
16
|
*
|
|
14
|
-
* @param priv
|
|
17
|
+
* @param priv { secretKey: BN, curve: 'p256' | 'secp256k1' }
|
|
15
18
|
* @param chainCode slice 32->n HMAC hash key and seedkey (first instance curve default seedKey. after hmac value slice 32->n)
|
|
16
19
|
*/
|
|
17
|
-
constructor(priv:
|
|
20
|
+
constructor(priv: {
|
|
21
|
+
curve: CurveName;
|
|
22
|
+
secretKey: BN;
|
|
23
|
+
}, chainCode: Uint8Array);
|
|
18
24
|
/**
|
|
19
25
|
* @param seedSrc result of Bip39.mnemonicToSeed
|
|
20
26
|
* @param curve known supported curve p256 or secp256k1
|
|
@@ -41,4 +47,3 @@ export declare class PrivateKey implements ExtendedPrivateKey {
|
|
|
41
47
|
*/
|
|
42
48
|
bytes(): Uint8Array;
|
|
43
49
|
}
|
|
44
|
-
export {};
|