@taquito/signer 23.0.2 → 23.1.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 +196 -207
- package/dist/taquito-signer.es6.js.map +1 -1
- package/dist/taquito-signer.umd.js +195 -208
- 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
|
@@ -3,13 +3,14 @@ import { b58DecodeAndCheckPrefix, PrefixV2, b58Encode, compareArrays, InvalidPub
|
|
|
3
3
|
import toBuffer from 'typedarray-to-buffer';
|
|
4
4
|
import { hash } from '@stablelib/blake2b';
|
|
5
5
|
import { generateKeyPairFromSeed, sign } from '@stablelib/ed25519';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { ParameterValidationError, UnsupportedActionError, InvalidHexStringError,
|
|
6
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
7
|
+
import { p256 } from '@noble/curves/nist.js';
|
|
8
|
+
import { ParameterValidationError, UnsupportedActionError, InvalidHexStringError, InvalidDerivationPathError, InvalidKeyError, ProhibitedActionError } from '@taquito/core';
|
|
9
9
|
import pbkdf2 from 'pbkdf2';
|
|
10
10
|
import * as Bip39 from 'bip39';
|
|
11
11
|
import { HMAC } from '@stablelib/hmac';
|
|
12
12
|
import { SHA512 } from '@stablelib/sha512';
|
|
13
|
+
import { p256 as p256$1 } from '@noble/curves/nist';
|
|
13
14
|
import BN from 'bn.js';
|
|
14
15
|
import { bls12_381 } from '@noble/curves/bls12-381';
|
|
15
16
|
|
|
@@ -231,6 +232,7 @@ class InvalidPassphraseError extends ParameterValidationError {
|
|
|
231
232
|
}
|
|
232
233
|
}
|
|
233
234
|
|
|
235
|
+
var _ECKey_keyPair, _ECPublicKey_key;
|
|
234
236
|
const pref = {
|
|
235
237
|
p256: {
|
|
236
238
|
pk: PrefixV2.P256PublicKey,
|
|
@@ -247,27 +249,10 @@ const pref = {
|
|
|
247
249
|
tag: 1,
|
|
248
250
|
},
|
|
249
251
|
};
|
|
250
|
-
class ECKeyBase {
|
|
251
|
-
constructor(keyPair) {
|
|
252
|
-
this.keyPair = keyPair;
|
|
253
|
-
}
|
|
254
|
-
curve() {
|
|
255
|
-
switch (this.keyPair.ec.curve) {
|
|
256
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
257
|
-
case elliptic.curves.secp256k1.curve:
|
|
258
|
-
return 'secp256k1';
|
|
259
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
260
|
-
case elliptic.curves.p256.curve:
|
|
261
|
-
return 'p256';
|
|
262
|
-
default:
|
|
263
|
-
throw new InvalidCurveError('unknown curve');
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
252
|
/**
|
|
268
253
|
* @description Provide signing logic for elliptic curve based key (tz2, tz3)
|
|
269
254
|
*/
|
|
270
|
-
class ECKey
|
|
255
|
+
class ECKey {
|
|
271
256
|
/**
|
|
272
257
|
*
|
|
273
258
|
* @param key Encoded private key
|
|
@@ -275,6 +260,7 @@ class ECKey extends ECKeyBase {
|
|
|
275
260
|
* @throws {@link InvalidKeyError}
|
|
276
261
|
*/
|
|
277
262
|
constructor(key, decrypt) {
|
|
263
|
+
_ECKey_keyPair.set(this, void 0);
|
|
278
264
|
const [keyData, prefix] = b58DecodeAndCheckPrefix(key, [
|
|
279
265
|
PrefixV2.Secp256k1EncryptedSecretKey,
|
|
280
266
|
PrefixV2.P256EncryptedSecretKey,
|
|
@@ -300,7 +286,13 @@ class ECKey extends ECKeyBase {
|
|
|
300
286
|
return [keyData, 'p256'];
|
|
301
287
|
}
|
|
302
288
|
})();
|
|
303
|
-
|
|
289
|
+
__classPrivateFieldSet(this, _ECKey_keyPair, {
|
|
290
|
+
curve,
|
|
291
|
+
secretKey: decKey,
|
|
292
|
+
publicKey: curve === 'secp256k1'
|
|
293
|
+
? secp256k1.getPublicKey(decKey, true)
|
|
294
|
+
: p256.getPublicKey(decKey, true),
|
|
295
|
+
}, "f");
|
|
304
296
|
}
|
|
305
297
|
/**
|
|
306
298
|
*
|
|
@@ -309,68 +301,71 @@ class ECKey extends ECKeyBase {
|
|
|
309
301
|
*/
|
|
310
302
|
sign(bytes) {
|
|
311
303
|
const hash$1 = hash(bytes, 32);
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
304
|
+
let signature;
|
|
305
|
+
if (__classPrivateFieldGet(this, _ECKey_keyPair, "f").curve === 'secp256k1') {
|
|
306
|
+
signature = secp256k1
|
|
307
|
+
.sign(hash$1, __classPrivateFieldGet(this, _ECKey_keyPair, "f").secretKey, {
|
|
308
|
+
lowS: true, // Use canonical signatures (prevents malleability)
|
|
309
|
+
})
|
|
310
|
+
.toBytes('compact');
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
signature = p256
|
|
314
|
+
.sign(hash$1, __classPrivateFieldGet(this, _ECKey_keyPair, "f").secretKey, {
|
|
315
|
+
lowS: true, // Use canonical signatures (prevents malleability)
|
|
316
|
+
})
|
|
317
|
+
.toBytes('compact');
|
|
318
|
+
}
|
|
318
319
|
return {
|
|
319
320
|
rawSignature: signature,
|
|
320
321
|
sig: b58Encode(signature, PrefixV2.GenericSignature),
|
|
321
|
-
prefixSig: b58Encode(signature, pref[this.curve
|
|
322
|
+
prefixSig: b58Encode(signature, pref[__classPrivateFieldGet(this, _ECKey_keyPair, "f").curve].sig),
|
|
322
323
|
};
|
|
323
324
|
}
|
|
324
325
|
/**
|
|
325
326
|
* @returns Encoded public key
|
|
326
327
|
*/
|
|
327
328
|
publicKey() {
|
|
328
|
-
return new ECPublicKey(this.
|
|
329
|
+
return new ECPublicKey(__classPrivateFieldGet(this, _ECKey_keyPair, "f").publicKey, __classPrivateFieldGet(this, _ECKey_keyPair, "f").curve);
|
|
329
330
|
}
|
|
330
331
|
/**
|
|
331
332
|
* @returns Encoded private key
|
|
332
333
|
*/
|
|
333
334
|
secretKey() {
|
|
334
|
-
return b58Encode(
|
|
335
|
+
return b58Encode(__classPrivateFieldGet(this, _ECKey_keyPair, "f").secretKey, pref[__classPrivateFieldGet(this, _ECKey_keyPair, "f").curve].sk);
|
|
335
336
|
}
|
|
336
337
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
class ECPublicKey extends ECKeyBase {
|
|
338
|
+
_ECKey_keyPair = new WeakMap();
|
|
339
|
+
class ECPublicKey {
|
|
341
340
|
constructor(src, curve) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
341
|
+
_ECPublicKey_key.set(this, void 0);
|
|
342
|
+
const [key, crv] = (() => {
|
|
343
|
+
if (typeof src === 'string') {
|
|
344
|
+
const [key, pre] = b58DecodeAndCheckPrefix(src, [
|
|
345
|
+
PrefixV2.Secp256k1PublicKey,
|
|
346
|
+
PrefixV2.P256PublicKey,
|
|
347
|
+
]);
|
|
348
|
+
return [key, pre === PrefixV2.Secp256k1PublicKey ? 'secp256k1' : 'p256'];
|
|
349
|
+
}
|
|
350
|
+
else if (curve !== undefined) {
|
|
351
|
+
return [src, curve];
|
|
345
352
|
}
|
|
346
353
|
else {
|
|
347
|
-
|
|
348
|
-
if (typeof src === 'string') {
|
|
349
|
-
const [key, pre] = b58DecodeAndCheckPrefix(src, [
|
|
350
|
-
PrefixV2.Secp256k1PublicKey,
|
|
351
|
-
PrefixV2.P256PublicKey,
|
|
352
|
-
]);
|
|
353
|
-
return [key, pre === PrefixV2.Secp256k1PublicKey ? 'secp256k1' : 'p256'];
|
|
354
|
-
}
|
|
355
|
-
else if (curve !== undefined) {
|
|
356
|
-
return [src, curve];
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
throw new InvalidCurveError('missing curve type');
|
|
360
|
-
}
|
|
361
|
-
})();
|
|
362
|
-
return new elliptic.ec(crv).keyFromPublic(key);
|
|
354
|
+
throw new InvalidCurveError('missing curve type');
|
|
363
355
|
}
|
|
364
356
|
})();
|
|
365
|
-
|
|
357
|
+
// For ECPublicKey, we don't need the private key, so we pass an empty array
|
|
358
|
+
// The public key is stored separately
|
|
359
|
+
__classPrivateFieldSet(this, _ECPublicKey_key, key, "f");
|
|
360
|
+
this.curve = crv;
|
|
366
361
|
}
|
|
367
362
|
compare(other) {
|
|
368
363
|
if (other instanceof ECPublicKey) {
|
|
369
|
-
if (this.curve
|
|
370
|
-
const compress = this.curve
|
|
364
|
+
if (this.curve === other.curve) {
|
|
365
|
+
const compress = this.curve === 'secp256k1';
|
|
371
366
|
return compareArrays(this.bytes(compress), other.bytes(compress));
|
|
372
367
|
}
|
|
373
|
-
else if (this.curve
|
|
368
|
+
else if (this.curve === 'secp256k1') {
|
|
374
369
|
return -1;
|
|
375
370
|
}
|
|
376
371
|
else {
|
|
@@ -383,23 +378,37 @@ class ECPublicKey extends ECKeyBase {
|
|
|
383
378
|
}
|
|
384
379
|
hash() {
|
|
385
380
|
const key = this.bytes();
|
|
386
|
-
return b58Encode(hash(key, 20), pref[this.curve
|
|
381
|
+
return b58Encode(hash(key, 20), pref[this.curve].pkh);
|
|
387
382
|
}
|
|
388
383
|
bytes(compress = true) {
|
|
389
|
-
|
|
384
|
+
// @noble/curves supports both compressed and uncompressed formats
|
|
385
|
+
// We need to convert the stored public key to the requested format
|
|
386
|
+
if (this.curve === 'secp256k1') {
|
|
387
|
+
// For secp256k1, we need to get the public key from the stored bytes and convert format
|
|
388
|
+
const point = secp256k1.Point.fromHex(__classPrivateFieldGet(this, _ECPublicKey_key, "f"));
|
|
389
|
+
return point.toBytes(compress);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
// For p256, we need to get the public key from the stored bytes and convert format
|
|
393
|
+
const point = p256.Point.fromHex(__classPrivateFieldGet(this, _ECPublicKey_key, "f"));
|
|
394
|
+
return point.toBytes(compress);
|
|
395
|
+
}
|
|
390
396
|
}
|
|
391
397
|
toProtocol() {
|
|
392
398
|
const key = this.bytes();
|
|
393
399
|
const res = new Uint8Array(key.length + 1);
|
|
394
|
-
res[0] = pref[this.curve
|
|
400
|
+
res[0] = pref[this.curve].tag;
|
|
395
401
|
res.set(key, 1);
|
|
396
402
|
return res;
|
|
397
403
|
}
|
|
398
404
|
toString() {
|
|
399
405
|
const key = this.bytes();
|
|
400
|
-
return b58Encode(key, pref[this.curve
|
|
406
|
+
return b58Encode(key, pref[this.curve].pk);
|
|
401
407
|
}
|
|
402
408
|
}
|
|
409
|
+
_ECPublicKey_key = new WeakMap();
|
|
410
|
+
|
|
411
|
+
const Hard = 0x80000000;
|
|
403
412
|
|
|
404
413
|
function parseHex(s) {
|
|
405
414
|
const res = [];
|
|
@@ -414,24 +423,104 @@ function parseHex(s) {
|
|
|
414
423
|
return new Uint8Array(res);
|
|
415
424
|
}
|
|
416
425
|
|
|
426
|
+
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
427
|
+
// MinSeedSize is the minimal allowed seed byte length
|
|
428
|
+
const minSeedSize$1 = 16;
|
|
429
|
+
// MaxSeedSize is the maximal allowed seed byte length
|
|
430
|
+
const maxSeedSize$1 = 64;
|
|
431
|
+
const ed25519Key = 'ed25519 seed';
|
|
432
|
+
let PrivateKey$1 = class PrivateKey {
|
|
433
|
+
/**
|
|
434
|
+
*
|
|
435
|
+
* @param priv generated keypair 0->32 private key 32->n public key
|
|
436
|
+
* @param chainCode new HMAC hash with new key
|
|
437
|
+
*/
|
|
438
|
+
constructor(priv, chainCode) {
|
|
439
|
+
this.priv = priv;
|
|
440
|
+
this.chainCode = chainCode;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
*
|
|
444
|
+
* @param seedSrc result of Bip39.mnemonicToSeed
|
|
445
|
+
* @returns instance of PrivateKey
|
|
446
|
+
* @throws {@link InvalidSeedLengthError}
|
|
447
|
+
*/
|
|
448
|
+
static fromSeed(seedSrc) {
|
|
449
|
+
const seed = typeof seedSrc === 'string' ? parseHex(seedSrc) : seedSrc;
|
|
450
|
+
if (seed.length < minSeedSize$1 || seed.length > maxSeedSize$1) {
|
|
451
|
+
throw new InvalidSeedLengthError(seed.length);
|
|
452
|
+
}
|
|
453
|
+
const key = new TextEncoder().encode(ed25519Key);
|
|
454
|
+
const sum = new HMAC(SHA512, key).update(seed).digest();
|
|
455
|
+
return new PrivateKey(generateKeyPairFromSeed(sum.subarray(0, 32)).secretKey, sum.subarray(32));
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
*
|
|
459
|
+
* @returns slice(0, 32) of current priv for new seed for next derived priv
|
|
460
|
+
*/
|
|
461
|
+
seed() {
|
|
462
|
+
return this.priv.subarray(0, 32);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* @index current derivation path item ie: 1729'
|
|
466
|
+
* @returns derivation path child of original private key pair
|
|
467
|
+
*/
|
|
468
|
+
derive(index) {
|
|
469
|
+
if ((index & Hard) === 0) {
|
|
470
|
+
throw new InvalidDerivationPathError(index.toString(), ': Non-hardened derivation path.');
|
|
471
|
+
}
|
|
472
|
+
const data = new Uint8Array(37);
|
|
473
|
+
data.set(this.seed(), 1);
|
|
474
|
+
new DataView(data.buffer).setUint32(33, index);
|
|
475
|
+
const sum = new HMAC(SHA512, this.chainCode).update(data).digest();
|
|
476
|
+
return new PrivateKey(generateKeyPairFromSeed(sum.subarray(0, 32)).secretKey, sum.subarray(32));
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* @param path array of numbers pre adjusted for hardened paths ie: 44' -> 2^31 + 44
|
|
480
|
+
* @returns final child of full derivation path private key pair
|
|
481
|
+
*/
|
|
482
|
+
derivePath(path) {
|
|
483
|
+
let key = this;
|
|
484
|
+
for (const index of path) {
|
|
485
|
+
key = key.derive(index);
|
|
486
|
+
}
|
|
487
|
+
return key;
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
var ed25519 = /*#__PURE__*/Object.freeze({
|
|
492
|
+
__proto__: null,
|
|
493
|
+
PrivateKey: PrivateKey$1
|
|
494
|
+
});
|
|
495
|
+
|
|
417
496
|
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
418
497
|
const seedKey = {
|
|
419
498
|
p256: 'Nist256p1 seed',
|
|
420
499
|
secp256k1: 'Bitcoin seed',
|
|
421
500
|
};
|
|
422
501
|
// MinSeedSize is the minimal allowed seed byte length
|
|
423
|
-
const minSeedSize
|
|
502
|
+
const minSeedSize = 16;
|
|
424
503
|
// MaxSeedSize is the maximal allowed seed byte length
|
|
425
|
-
const maxSeedSize
|
|
426
|
-
|
|
504
|
+
const maxSeedSize = 64;
|
|
505
|
+
class PrivateKey {
|
|
427
506
|
/**
|
|
428
507
|
*
|
|
429
|
-
* @param priv
|
|
508
|
+
* @param priv { secretKey: BN, curve: 'p256' | 'secp256k1' }
|
|
430
509
|
* @param chainCode slice 32->n HMAC hash key and seedkey (first instance curve default seedKey. after hmac value slice 32->n)
|
|
431
510
|
*/
|
|
432
511
|
constructor(priv, chainCode) {
|
|
512
|
+
this.priv = priv;
|
|
433
513
|
this.chainCode = chainCode;
|
|
434
|
-
|
|
514
|
+
const privateKeyBytes = priv.secretKey.toArray('be', 32);
|
|
515
|
+
const privateKeyUint8 = new Uint8Array(privateKeyBytes);
|
|
516
|
+
const publicKey = priv.curve === 'secp256k1'
|
|
517
|
+
? secp256k1.getPublicKey(privateKeyUint8, true) // compressed public key
|
|
518
|
+
: p256$1.getPublicKey(privateKeyUint8, true); // compressed public key
|
|
519
|
+
this.keyPair = {
|
|
520
|
+
curve: priv.curve,
|
|
521
|
+
secretKey: priv.secretKey,
|
|
522
|
+
publicKey: publicKey,
|
|
523
|
+
};
|
|
435
524
|
}
|
|
436
525
|
/**
|
|
437
526
|
* @param seedSrc result of Bip39.mnemonicToSeed
|
|
@@ -440,17 +529,23 @@ let PrivateKey$1 = class PrivateKey {
|
|
|
440
529
|
* @throws {@link InvalidBitSize} | {@link InvalidCurveError} | {@link InvalidSeedLengthError}
|
|
441
530
|
*/
|
|
442
531
|
static fromSeed(seedSrc, curve) {
|
|
443
|
-
var _a, _b;
|
|
444
532
|
let seed = typeof seedSrc === 'string' ? parseHex(seedSrc) : seedSrc;
|
|
445
|
-
if (seed.length < minSeedSize
|
|
533
|
+
if (seed.length < minSeedSize || seed.length > maxSeedSize) {
|
|
446
534
|
throw new InvalidSeedLengthError(seed.length);
|
|
447
535
|
}
|
|
448
536
|
if (!Object.prototype.hasOwnProperty.call(seedKey, curve)) {
|
|
449
537
|
throw new InvalidCurveError(`Unsupported curve "${curve}" expecting either "p256" or "secp256k1"`);
|
|
450
538
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
539
|
+
// Get curve order for validation
|
|
540
|
+
let curveOrder;
|
|
541
|
+
if (curve === 'secp256k1') {
|
|
542
|
+
curveOrder = new BN(secp256k1.Point.CURVE().n.toString());
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
curveOrder = new BN(p256$1.Point.CURVE().n.toString());
|
|
546
|
+
}
|
|
547
|
+
if (curveOrder.bitLength() !== 256) {
|
|
548
|
+
throw new InvalidBitSize(`Invalid curve "${curve}" with bit size "${curveOrder.bitLength()}" expecting bit size "256"`);
|
|
454
549
|
}
|
|
455
550
|
const key = new TextEncoder().encode(seedKey[curve]);
|
|
456
551
|
let d = null;
|
|
@@ -460,16 +555,14 @@ let PrivateKey$1 = class PrivateKey {
|
|
|
460
555
|
const sum = new HMAC(SHA512, key).update(seed).digest();
|
|
461
556
|
d = new BN(sum.subarray(0, 32));
|
|
462
557
|
chain = sum.subarray(32);
|
|
463
|
-
if (d.isZero() || d.cmp(
|
|
558
|
+
if (d.isZero() || d.cmp(curveOrder) >= 0) {
|
|
464
559
|
seed = sum;
|
|
465
560
|
}
|
|
466
561
|
else {
|
|
467
562
|
i++;
|
|
468
563
|
}
|
|
469
564
|
}
|
|
470
|
-
|
|
471
|
-
keyPair.priv = d;
|
|
472
|
-
return new PrivateKey(keyPair, chain);
|
|
565
|
+
return new PrivateKey({ curve, secretKey: d }, chain);
|
|
473
566
|
}
|
|
474
567
|
/**
|
|
475
568
|
*
|
|
@@ -480,10 +573,10 @@ let PrivateKey$1 = class PrivateKey {
|
|
|
480
573
|
const data = new Uint8Array(37);
|
|
481
574
|
if ((index & Hard) !== 0) {
|
|
482
575
|
// hardened derivation
|
|
483
|
-
data.set(this.keyPair.
|
|
576
|
+
data.set(this.keyPair.secretKey.toArray(), 1);
|
|
484
577
|
}
|
|
485
578
|
else {
|
|
486
|
-
data.set(this.keyPair.
|
|
579
|
+
data.set(this.keyPair.publicKey, 0);
|
|
487
580
|
}
|
|
488
581
|
new DataView(data.buffer).setUint32(33, index);
|
|
489
582
|
let d = new BN(0);
|
|
@@ -493,8 +586,16 @@ let PrivateKey$1 = class PrivateKey {
|
|
|
493
586
|
const sum = new HMAC(SHA512, this.chainCode).update(data).digest();
|
|
494
587
|
d = new BN(sum.subarray(0, 32));
|
|
495
588
|
chain = sum.subarray(32);
|
|
496
|
-
|
|
497
|
-
|
|
589
|
+
// Get curve order for comparison
|
|
590
|
+
let curveOrder;
|
|
591
|
+
if (this.keyPair.curve === 'secp256k1') {
|
|
592
|
+
curveOrder = new BN(secp256k1.Point.CURVE().n.toString());
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
curveOrder = new BN(p256$1.Point.CURVE().n.toString());
|
|
596
|
+
}
|
|
597
|
+
if (d.cmp(curveOrder) < 0) {
|
|
598
|
+
d = d.add(this.keyPair.secretKey).mod(curveOrder);
|
|
498
599
|
if (!d.isZero()) {
|
|
499
600
|
i++;
|
|
500
601
|
}
|
|
@@ -502,9 +603,7 @@ let PrivateKey$1 = class PrivateKey {
|
|
|
502
603
|
data.set(chain, 1);
|
|
503
604
|
data[0] = 1;
|
|
504
605
|
}
|
|
505
|
-
|
|
506
|
-
keyPair.priv = d;
|
|
507
|
-
return new PrivateKey(keyPair, chain);
|
|
606
|
+
return new PrivateKey({ curve: this.keyPair.curve, secretKey: d }, chain);
|
|
508
607
|
}
|
|
509
608
|
/**
|
|
510
609
|
*
|
|
@@ -524,23 +623,22 @@ let PrivateKey$1 = class PrivateKey {
|
|
|
524
623
|
* @throws {@link InvalidKeyError}
|
|
525
624
|
*/
|
|
526
625
|
bytes() {
|
|
527
|
-
if (!this.keyPair.
|
|
626
|
+
if (!this.keyPair.secretKey) {
|
|
528
627
|
throw new InvalidKeyError('missing private key');
|
|
529
628
|
}
|
|
530
629
|
// pad to 32 bytes as toArray() length argument seems to be ignored (BN bug)
|
|
531
|
-
const src = this.keyPair.
|
|
630
|
+
const src = this.keyPair.secretKey.toArray();
|
|
532
631
|
const out = new Uint8Array(32);
|
|
533
632
|
out.set(src, out.length - src.length);
|
|
534
633
|
return out;
|
|
535
634
|
}
|
|
536
|
-
}
|
|
635
|
+
}
|
|
537
636
|
|
|
538
637
|
var ecdsa = /*#__PURE__*/Object.freeze({
|
|
539
638
|
__proto__: null,
|
|
540
|
-
PrivateKey: PrivateKey
|
|
639
|
+
PrivateKey: PrivateKey
|
|
541
640
|
});
|
|
542
641
|
|
|
543
|
-
const Hard = 0x80000000;
|
|
544
642
|
class Path extends Array {
|
|
545
643
|
static from(iterable) {
|
|
546
644
|
return super.from(iterable).map((x) => x >>> 0);
|
|
@@ -576,76 +674,6 @@ class Path extends Array {
|
|
|
576
674
|
}
|
|
577
675
|
}
|
|
578
676
|
|
|
579
|
-
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
580
|
-
// MinSeedSize is the minimal allowed seed byte length
|
|
581
|
-
const minSeedSize = 16;
|
|
582
|
-
// MaxSeedSize is the maximal allowed seed byte length
|
|
583
|
-
const maxSeedSize = 64;
|
|
584
|
-
const ed25519Key = 'ed25519 seed';
|
|
585
|
-
class PrivateKey {
|
|
586
|
-
/**
|
|
587
|
-
*
|
|
588
|
-
* @param priv generated keypair 0->32 private key 32->n public key
|
|
589
|
-
* @param chainCode new HMAC hash with new key
|
|
590
|
-
*/
|
|
591
|
-
constructor(priv, chainCode) {
|
|
592
|
-
this.priv = priv;
|
|
593
|
-
this.chainCode = chainCode;
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
*
|
|
597
|
-
* @param seedSrc result of Bip39.mnemonicToSeed
|
|
598
|
-
* @returns instance of PrivateKey
|
|
599
|
-
* @throws {@link InvalidSeedLengthError}
|
|
600
|
-
*/
|
|
601
|
-
static fromSeed(seedSrc) {
|
|
602
|
-
const seed = typeof seedSrc === 'string' ? parseHex(seedSrc) : seedSrc;
|
|
603
|
-
if (seed.length < minSeedSize || seed.length > maxSeedSize) {
|
|
604
|
-
throw new InvalidSeedLengthError(seed.length);
|
|
605
|
-
}
|
|
606
|
-
const key = new TextEncoder().encode(ed25519Key);
|
|
607
|
-
const sum = new HMAC(SHA512, key).update(seed).digest();
|
|
608
|
-
return new PrivateKey(generateKeyPairFromSeed(sum.subarray(0, 32)).secretKey, sum.subarray(32));
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
*
|
|
612
|
-
* @returns slice(0, 32) of current priv for new seed for next derived priv
|
|
613
|
-
*/
|
|
614
|
-
seed() {
|
|
615
|
-
return this.priv.subarray(0, 32);
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* @index current derivation path item ie: 1729'
|
|
619
|
-
* @returns derivation path child of original private key pair
|
|
620
|
-
*/
|
|
621
|
-
derive(index) {
|
|
622
|
-
if ((index & Hard) === 0) {
|
|
623
|
-
throw new InvalidDerivationPathError(index.toString(), ': Non-hardened derivation path.');
|
|
624
|
-
}
|
|
625
|
-
const data = new Uint8Array(37);
|
|
626
|
-
data.set(this.seed(), 1);
|
|
627
|
-
new DataView(data.buffer).setUint32(33, index);
|
|
628
|
-
const sum = new HMAC(SHA512, this.chainCode).update(data).digest();
|
|
629
|
-
return new PrivateKey(generateKeyPairFromSeed(sum.subarray(0, 32)).secretKey, sum.subarray(32));
|
|
630
|
-
}
|
|
631
|
-
/**
|
|
632
|
-
* @param path array of numbers pre adjusted for hardened paths ie: 44' -> 2^31 + 44
|
|
633
|
-
* @returns final child of full derivation path private key pair
|
|
634
|
-
*/
|
|
635
|
-
derivePath(path) {
|
|
636
|
-
let key = this;
|
|
637
|
-
for (const index of path) {
|
|
638
|
-
key = key.derive(index);
|
|
639
|
-
}
|
|
640
|
-
return key;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
var ed25519 = /*#__PURE__*/Object.freeze({
|
|
645
|
-
__proto__: null,
|
|
646
|
-
PrivateKey: PrivateKey
|
|
647
|
-
});
|
|
648
|
-
|
|
649
677
|
// bip32 when supported add to @param curve bip25519
|
|
650
678
|
/**
|
|
651
679
|
*
|
|
@@ -660,16 +688,16 @@ const generateSecretKey = (seed, derivationPath, curve) => {
|
|
|
660
688
|
let node;
|
|
661
689
|
switch (curve) {
|
|
662
690
|
case 'ed25519': {
|
|
663
|
-
node = PrivateKey.fromSeed(seed).derivePath(path);
|
|
691
|
+
node = PrivateKey$1.fromSeed(seed).derivePath(path);
|
|
664
692
|
const sk = b58Encode(node.seed().slice(0, 32), PrefixV2.Ed25519Seed);
|
|
665
693
|
return sk;
|
|
666
694
|
}
|
|
667
695
|
case 'secp256k1':
|
|
668
696
|
case 'p256': {
|
|
669
697
|
const prefixType = curve === 'secp256k1' ? PrefixV2.Secp256k1SecretKey : PrefixV2.P256SecretKey;
|
|
670
|
-
let privKey = PrivateKey
|
|
698
|
+
let privKey = PrivateKey.fromSeed(seed, curve);
|
|
671
699
|
privKey = privKey.derivePath(path);
|
|
672
|
-
const uint8arr = new Uint8Array(privKey.keyPair.
|
|
700
|
+
const uint8arr = new Uint8Array(privKey.keyPair.secretKey.toArray());
|
|
673
701
|
const sk = b58Encode(uint8arr, prefixType);
|
|
674
702
|
return sk;
|
|
675
703
|
}
|
|
@@ -772,51 +800,6 @@ class BLSPublicKey {
|
|
|
772
800
|
}
|
|
773
801
|
_BLSPublicKey_key = new WeakMap();
|
|
774
802
|
|
|
775
|
-
/**
|
|
776
|
-
*
|
|
777
|
-
* @description Import a key to sign operation with the side-effect of setting the Tezos instance to use the InMemorySigner provider
|
|
778
|
-
*
|
|
779
|
-
* @warn The JSON faucets are no longer available on https://teztnets.com/
|
|
780
|
-
* @param toolkit The toolkit instance to attach a signer
|
|
781
|
-
* @param privateKeyOrEmail Key to load in memory
|
|
782
|
-
* @param passphrase If the key is encrypted passphrase to decrypt it
|
|
783
|
-
* @param mnemonic Faucet mnemonic
|
|
784
|
-
* @param secret Faucet secret
|
|
785
|
-
*/
|
|
786
|
-
function importKey(toolkit, privateKeyOrEmail, passphrase, mnemonic, secret) {
|
|
787
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
788
|
-
if (privateKeyOrEmail && passphrase && mnemonic && secret) {
|
|
789
|
-
const signer = InMemorySigner.fromFundraiser(privateKeyOrEmail, passphrase, mnemonic);
|
|
790
|
-
toolkit.setProvider({ signer });
|
|
791
|
-
const pkh = yield signer.publicKeyHash();
|
|
792
|
-
let op;
|
|
793
|
-
try {
|
|
794
|
-
op = yield toolkit.tz.activate(pkh, secret);
|
|
795
|
-
}
|
|
796
|
-
catch (ex) {
|
|
797
|
-
const isInvalidActivationError = ex && ex.body && /Invalid activation/.test(ex.body);
|
|
798
|
-
if (!isInvalidActivationError) {
|
|
799
|
-
throw ex;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
if (op) {
|
|
803
|
-
yield op.confirmation();
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
else {
|
|
807
|
-
// Fallback to regular import
|
|
808
|
-
const signer = yield InMemorySigner.fromSecretKey(privateKeyOrEmail, passphrase);
|
|
809
|
-
toolkit.setProvider({ signer });
|
|
810
|
-
}
|
|
811
|
-
});
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
815
|
-
const VERSION = {
|
|
816
|
-
"commitHash": "20b6624f217ec85f28023ca02b2d3b73777a8df9",
|
|
817
|
-
"version": "23.0.2"
|
|
818
|
-
};
|
|
819
|
-
|
|
820
803
|
var _InMemorySigner_key;
|
|
821
804
|
/**
|
|
822
805
|
* @description A local implementation of the signer. Will represent a Tezos account and be able to produce signature in its behalf
|
|
@@ -997,5 +980,11 @@ function publicKeyFromString(src) {
|
|
|
997
980
|
}
|
|
998
981
|
}
|
|
999
982
|
|
|
1000
|
-
|
|
983
|
+
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
984
|
+
const VERSION = {
|
|
985
|
+
"commitHash": "c77fe4b0989665d8b5cfd15a7cc977499021f6fd",
|
|
986
|
+
"version": "23.1.0"
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
export { ecdsa as ECDSA, ed25519 as Ed25519, Hard, InMemorySigner, InvalidPassphraseError, Path, VERSION, generateSecretKey, publicKeyFromString };
|
|
1001
990
|
//# sourceMappingURL=taquito-signer.es6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taquito-signer.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"taquito-signer.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|