@taquito/signer 22.0.0-beta.0 → 23.0.0-RC.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.
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
5
5
  exports.VERSION = {
6
- "commitHash": "f0eb755ed1e0de4d1cd86623df4496f76efd0caf",
7
- "version": "22.0.0-beta.0"
6
+ "commitHash": "13639ef56845fbb7e93bcbd37d3f6d0457b0872b",
7
+ "version": "23.0.0-RC.0"
8
8
  };
@@ -1,15 +1,16 @@
1
1
  import { openSecretBox } from '@stablelib/nacl';
2
- import { hash } from '@stablelib/blake2b';
3
- import { isValidPrefix, invalidDetail, ValidationResult, Prefix, b58cdecode, prefix, buf2hex, b58cencode, hex2buf, mergebuf } from '@taquito/utils';
2
+ import { b58DecodeAndCheckPrefix, PrefixV2, b58Encode, BLS12_381_DST, POP_DST, hex2buf, mergebuf, buf2hex } from '@taquito/utils';
4
3
  import toBuffer from 'typedarray-to-buffer';
4
+ import { hash } from '@stablelib/blake2b';
5
5
  import { generateKeyPairFromSeed, sign } from '@stablelib/ed25519';
6
- import { InvalidKeyError, InvalidHexStringError, ParameterValidationError, UnsupportedActionError, InvalidDerivationPathError } from '@taquito/core';
7
6
  import elliptic, { ec } from 'elliptic';
8
7
  import pbkdf2 from 'pbkdf2';
9
8
  import * as Bip39 from 'bip39';
10
9
  import { HMAC } from '@stablelib/hmac';
11
10
  import { SHA512 } from '@stablelib/sha512';
11
+ import { InvalidHexStringError, ParameterValidationError, UnsupportedActionError, InvalidKeyError, InvalidDerivationPathError, ProhibitedActionError } from '@taquito/core';
12
12
  import BN from 'bn.js';
13
+ import { bls12_381 } from '@noble/curves/bls12-381';
13
14
 
14
15
  /******************************************************************************
15
16
  Copyright (c) Microsoft Corporation.
@@ -38,15 +39,29 @@ function __awaiter(thisArg, _arguments, P, generator) {
38
39
  });
39
40
  }
40
41
 
42
+ function __classPrivateFieldGet(receiver, state, kind, f) {
43
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
44
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
45
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
46
+ }
47
+
48
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
49
+ if (kind === "m") throw new TypeError("Private method is not writable");
50
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
51
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
52
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
53
+ }
54
+
41
55
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
42
56
  var e = new Error(message);
43
57
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
44
58
  };
45
59
 
60
+ var _EdKey_secretKey, _EdKey_publicKey;
46
61
  /**
47
62
  * @description Provide signing logic for ed25519 curve based key (tz1)
48
63
  */
49
- class Tz1 {
64
+ class EdKey {
50
65
  /**
51
66
  *
52
67
  * @param key Encoded private key
@@ -54,92 +69,84 @@ class Tz1 {
54
69
  * @param decrypt Decrypt function
55
70
  * @throws {@link InvalidKeyError}
56
71
  */
57
- constructor(key, encrypted, decrypt) {
58
- this.key = key;
59
- const keyPrefix = key.substring(0, encrypted ? 5 : 4);
60
- if (!isValidPrefix(keyPrefix)) {
61
- throw new InvalidKeyError(`${invalidDetail(ValidationResult.NO_PREFIX_MATCHED)} expecting either '${Prefix.EDESK}' or '${Prefix.EDSK}'.`);
72
+ constructor(key, decrypt) {
73
+ _EdKey_secretKey.set(this, void 0);
74
+ _EdKey_publicKey.set(this, void 0);
75
+ const tmp = b58DecodeAndCheckPrefix(key, [
76
+ PrefixV2.Ed25519SecretKey,
77
+ PrefixV2.Ed25519EncryptedSeed,
78
+ PrefixV2.Ed25519Seed,
79
+ ]);
80
+ let [keyData] = tmp;
81
+ const [, prefix] = tmp;
82
+ if (prefix === PrefixV2.Ed25519SecretKey) {
83
+ __classPrivateFieldSet(this, _EdKey_secretKey, keyData, "f");
84
+ __classPrivateFieldSet(this, _EdKey_publicKey, keyData.slice(32), "f");
62
85
  }
63
- this._key = decrypt(b58cdecode(this.key, prefix[keyPrefix]));
64
- this._publicKey = this._key.slice(32);
65
- if (!this._key) {
66
- throw new InvalidKeyError('unable to decode');
67
- }
68
- this.isInit = this.init();
69
- }
70
- init() {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- if (this._key.length !== 64) {
73
- const { publicKey, secretKey } = generateKeyPairFromSeed(new Uint8Array(this._key));
74
- this._publicKey = publicKey;
75
- this._key = secretKey;
86
+ else {
87
+ if (prefix === PrefixV2.Ed25519EncryptedSeed) {
88
+ if (decrypt !== undefined) {
89
+ keyData = decrypt(keyData);
90
+ }
91
+ else {
92
+ throw new Error('decryption function is not provided');
93
+ }
76
94
  }
77
- return true;
78
- });
95
+ const { publicKey, secretKey } = generateKeyPairFromSeed(keyData);
96
+ __classPrivateFieldSet(this, _EdKey_publicKey, publicKey, "f");
97
+ __classPrivateFieldSet(this, _EdKey_secretKey, secretKey, "f");
98
+ }
79
99
  }
80
100
  /**
81
101
  *
82
102
  * @param bytes Bytes to sign
83
103
  * @param bytesHash Blake2b hash of the bytes to sign
84
104
  */
85
- sign(bytes, bytesHash) {
105
+ sign(bytes) {
86
106
  return __awaiter(this, void 0, void 0, function* () {
87
- yield this.isInit;
88
- const signature = sign(new Uint8Array(this._key), new Uint8Array(bytesHash));
89
- const signatureBuffer = toBuffer(signature);
90
- const sbytes = bytes + buf2hex(signatureBuffer);
91
- return {
92
- bytes,
93
- sig: b58cencode(signature, prefix.sig),
94
- prefixSig: b58cencode(signature, prefix.edsig),
95
- sbytes,
96
- };
107
+ const hash$1 = hash(bytes, 32);
108
+ const signature = sign(__classPrivateFieldGet(this, _EdKey_secretKey, "f"), hash$1);
109
+ return Promise.resolve({
110
+ rawSignature: signature,
111
+ sig: b58Encode(signature, PrefixV2.GenericSignature),
112
+ prefixSig: b58Encode(signature, PrefixV2.Ed25519Signature),
113
+ });
97
114
  });
98
115
  }
99
116
  /**
100
117
  * @returns Encoded public key
101
118
  */
102
119
  publicKey() {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- yield this.isInit;
105
- return b58cencode(this._publicKey, prefix['edpk']);
106
- });
120
+ return Promise.resolve(b58Encode(__classPrivateFieldGet(this, _EdKey_publicKey, "f"), PrefixV2.Ed25519PublicKey));
107
121
  }
108
122
  /**
109
123
  * @returns Encoded public key hash
110
124
  */
111
125
  publicKeyHash() {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- yield this.isInit;
114
- return b58cencode(hash(new Uint8Array(this._publicKey), 20), prefix.tz1);
115
- });
126
+ return Promise.resolve(b58Encode(hash(__classPrivateFieldGet(this, _EdKey_publicKey, "f"), 20), PrefixV2.Ed25519PublicKeyHash));
116
127
  }
117
128
  /**
118
129
  * @returns Encoded private key
119
130
  */
120
131
  secretKey() {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- yield this.isInit;
123
- let key = this._key;
124
- const { secretKey } = generateKeyPairFromSeed(new Uint8Array(key).slice(0, 32));
125
- key = toBuffer(secretKey);
126
- return b58cencode(key, prefix[`edsk`]);
127
- });
132
+ return Promise.resolve(b58Encode(__classPrivateFieldGet(this, _EdKey_secretKey, "f"), PrefixV2.Ed25519SecretKey));
128
133
  }
129
134
  }
135
+ _EdKey_secretKey = new WeakMap(), _EdKey_publicKey = new WeakMap();
130
136
 
137
+ var _ECKey_key, _ECKey_publicKey, _ECKey_curve;
131
138
  const pref = {
132
139
  p256: {
133
- pk: prefix['p2pk'],
134
- sk: prefix['p2sk'],
135
- pkh: prefix.tz3,
136
- sig: prefix.p2sig,
140
+ pk: PrefixV2.P256PublicKey,
141
+ sk: PrefixV2.P256SecretKey,
142
+ pkh: PrefixV2.P256PublicKeyHash,
143
+ sig: PrefixV2.P256Signature,
137
144
  },
138
145
  secp256k1: {
139
- pk: prefix['sppk'],
140
- sk: prefix['spsk'],
141
- pkh: prefix.tz2,
142
- sig: prefix.spsig,
146
+ pk: PrefixV2.Secp256k1PublicKey,
147
+ sk: PrefixV2.Secp256k1SecretKey,
148
+ pkh: PrefixV2.Secp256k1PublicKeyHash,
149
+ sig: PrefixV2.Secp256k1Signature,
143
150
  },
144
151
  };
145
152
  /**
@@ -148,81 +155,89 @@ const pref = {
148
155
  class ECKey {
149
156
  /**
150
157
  *
151
- * @param curve Curve to use with the key
152
158
  * @param key Encoded private key
153
- * @param encrypted Is the private key encrypted
154
159
  * @param decrypt Decrypt function
155
160
  * @throws {@link InvalidKeyError}
156
161
  */
157
- constructor(curve, key, encrypted, decrypt) {
158
- this.curve = curve;
159
- this.key = key;
160
- const keyPrefix = key.substring(0, encrypted ? 5 : 4);
161
- if (!isValidPrefix(keyPrefix)) {
162
- throw new InvalidKeyError(invalidDetail(ValidationResult.NO_PREFIX_MATCHED) +
163
- ` expecting one of the following prefix '${Prefix.SPSK}', '${Prefix.SPESK}', '${Prefix.P2SK}' or '${Prefix.P2ESK}'.`);
162
+ constructor(key, decrypt) {
163
+ var _a;
164
+ _ECKey_key.set(this, void 0);
165
+ _ECKey_publicKey.set(this, void 0);
166
+ _ECKey_curve.set(this, void 0);
167
+ const tmp = b58DecodeAndCheckPrefix(key, [
168
+ PrefixV2.Secp256k1EncryptedSecretKey,
169
+ PrefixV2.P256EncryptedSecretKey,
170
+ PrefixV2.Secp256k1SecretKey,
171
+ PrefixV2.P256SecretKey,
172
+ ]);
173
+ _a = this, [({ set value(_b) { __classPrivateFieldSet(_a, _ECKey_key, _b, "f"); } }).value] = tmp;
174
+ const [, prefix] = tmp;
175
+ switch (prefix) {
176
+ case PrefixV2.Secp256k1EncryptedSecretKey:
177
+ case PrefixV2.P256EncryptedSecretKey:
178
+ if (decrypt !== undefined) {
179
+ __classPrivateFieldSet(this, _ECKey_key, decrypt(__classPrivateFieldGet(this, _ECKey_key, "f")), "f");
180
+ }
181
+ else {
182
+ throw new Error('decryption function is not provided');
183
+ }
184
+ if (prefix === PrefixV2.Secp256k1EncryptedSecretKey) {
185
+ __classPrivateFieldSet(this, _ECKey_curve, 'secp256k1', "f");
186
+ }
187
+ else {
188
+ __classPrivateFieldSet(this, _ECKey_curve, 'p256', "f");
189
+ }
190
+ break;
191
+ case PrefixV2.Secp256k1SecretKey:
192
+ __classPrivateFieldSet(this, _ECKey_curve, 'secp256k1', "f");
193
+ break;
194
+ default:
195
+ __classPrivateFieldSet(this, _ECKey_curve, 'p256', "f");
196
+ break;
164
197
  }
165
- this._key = decrypt(b58cdecode(this.key, prefix[keyPrefix]));
166
- const keyPair = new elliptic.ec(this.curve).keyFromPrivate(this._key);
167
- const keyPairY = keyPair.getPublic().getY().toArray();
168
- const parityByte = keyPairY.length < 32 ? keyPairY[keyPairY.length - 1] : keyPairY[31];
169
- const pref = parityByte % 2 ? 3 : 2;
170
- const pad = new Array(32).fill(0);
171
- this._publicKey = toBuffer(new Uint8Array([pref].concat(pad.concat(keyPair.getPublic().getX().toArray()).slice(-32))));
198
+ const keyPair = new elliptic.ec(__classPrivateFieldGet(this, _ECKey_curve, "f")).keyFromPrivate(__classPrivateFieldGet(this, _ECKey_key, "f"));
199
+ __classPrivateFieldSet(this, _ECKey_publicKey, new Uint8Array(keyPair.getPublic(true, 'array')), "f"); // compress
172
200
  }
173
201
  /**
174
202
  *
175
203
  * @param bytes Bytes to sign
176
204
  * @param bytesHash Blake2b hash of the bytes to sign
177
205
  */
178
- sign(bytes, bytesHash) {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- const key = new elliptic.ec(this.curve).keyFromPrivate(this._key);
181
- const sig = key.sign(bytesHash, { canonical: true });
182
- const signature = sig.r.toString('hex', 64) + sig.s.toString('hex', 64);
183
- const sbytes = bytes + signature;
184
- return {
185
- bytes,
186
- sig: b58cencode(signature, prefix.sig),
187
- prefixSig: b58cencode(signature, pref[this.curve].sig),
188
- sbytes,
189
- };
206
+ sign(bytes) {
207
+ const hash$1 = hash(bytes, 32);
208
+ const key = new elliptic.ec(__classPrivateFieldGet(this, _ECKey_curve, "f")).keyFromPrivate(__classPrivateFieldGet(this, _ECKey_key, "f"));
209
+ const sig = key.sign(hash$1, { canonical: true });
210
+ const signature = new Uint8Array(64);
211
+ const r = sig.r.toArray();
212
+ const s = sig.s.toArray();
213
+ signature.set(r, 32 - r.length);
214
+ signature.set(s, 64 - s.length);
215
+ return Promise.resolve({
216
+ rawSignature: signature,
217
+ sig: b58Encode(signature, PrefixV2.GenericSignature),
218
+ prefixSig: b58Encode(signature, pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].sig),
190
219
  });
191
220
  }
192
221
  /**
193
222
  * @returns Encoded public key
194
223
  */
195
224
  publicKey() {
196
- return __awaiter(this, void 0, void 0, function* () {
197
- return b58cencode(this._publicKey, pref[this.curve].pk);
198
- });
225
+ return Promise.resolve(b58Encode(__classPrivateFieldGet(this, _ECKey_publicKey, "f"), pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].pk));
199
226
  }
200
227
  /**
201
228
  * @returns Encoded public key hash
202
229
  */
203
230
  publicKeyHash() {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- return b58cencode(hash(new Uint8Array(this._publicKey), 20), pref[this.curve].pkh);
206
- });
231
+ return Promise.resolve(b58Encode(hash(new Uint8Array(__classPrivateFieldGet(this, _ECKey_publicKey, "f")), 20), pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].pkh));
207
232
  }
208
233
  /**
209
234
  * @returns Encoded private key
210
235
  */
211
236
  secretKey() {
212
- return __awaiter(this, void 0, void 0, function* () {
213
- const key = this._key;
214
- return b58cencode(key, pref[this.curve].sk);
215
- });
237
+ return Promise.resolve(b58Encode(__classPrivateFieldGet(this, _ECKey_key, "f"), pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].sk));
216
238
  }
217
239
  }
218
- /**
219
- * @description Tz3 key class using the p256 curve
220
- */
221
- const Tz3 = ECKey.bind(null, 'p256');
222
- /**
223
- * @description Tz2 key class using the secp256k1 curve
224
- */
225
- const Tz2 = ECKey.bind(null, 'secp256k1');
240
+ _ECKey_key = new WeakMap(), _ECKey_publicKey = new WeakMap(), _ECKey_curve = new WeakMap();
226
241
 
227
242
  function parseHex(s) {
228
243
  const res = [];
@@ -553,16 +568,16 @@ const generateSecretKey = (seed, derivationPath, curve) => {
553
568
  switch (curve) {
554
569
  case 'ed25519': {
555
570
  node = PrivateKey.fromSeed(seed).derivePath(path);
556
- const sk = b58cencode(node.seed().slice(0, 32), prefix.edsk2);
571
+ const sk = b58Encode(node.seed().slice(0, 32), PrefixV2.Ed25519Seed);
557
572
  return sk;
558
573
  }
559
574
  case 'secp256k1':
560
575
  case 'p256': {
561
- const prefixType = curve === 'secp256k1' ? prefix.spsk : prefix.p2sk;
576
+ const prefixType = curve === 'secp256k1' ? PrefixV2.Secp256k1SecretKey : PrefixV2.P256SecretKey;
562
577
  let privKey = PrivateKey$1.fromSeed(seed, curve);
563
578
  privKey = privKey.derivePath(path);
564
579
  const uint8arr = new Uint8Array(privKey.keyPair.getPrivate().toArray());
565
- const sk = b58cencode(uint8arr, prefixType);
580
+ const sk = b58Encode(uint8arr, prefixType);
566
581
  return sk;
567
582
  }
568
583
  case 'bip25519': {
@@ -574,6 +589,66 @@ const generateSecretKey = (seed, derivationPath, curve) => {
574
589
  }
575
590
  };
576
591
 
592
+ function isPOP(k) {
593
+ return 'provePossession' in k;
594
+ }
595
+
596
+ var _BLSKey_key, _BLSKey_publicKey;
597
+ const bls = bls12_381.longSignatures; // AKA MinPK
598
+ class BLSKey {
599
+ constructor(key, decrypt) {
600
+ _BLSKey_key.set(this, void 0);
601
+ _BLSKey_publicKey.set(this, void 0);
602
+ const tmp = b58DecodeAndCheckPrefix(key, [
603
+ PrefixV2.BLS12_381EncryptedSecretKey,
604
+ PrefixV2.BLS12_381SecretKey,
605
+ ]);
606
+ let [keyData] = tmp;
607
+ const [, prefix] = tmp;
608
+ if (prefix === PrefixV2.BLS12_381EncryptedSecretKey) {
609
+ if (decrypt !== undefined) {
610
+ keyData = decrypt(keyData);
611
+ }
612
+ else {
613
+ throw new Error('decryption function is not provided');
614
+ }
615
+ }
616
+ __classPrivateFieldSet(this, _BLSKey_key, keyData, "f");
617
+ __classPrivateFieldSet(this, _BLSKey_publicKey, bls.getPublicKey(this.sk()).toBytes(), "f");
618
+ }
619
+ sk() {
620
+ return new Uint8Array(__classPrivateFieldGet(this, _BLSKey_key, "f")).reverse();
621
+ }
622
+ signDst(message, dst) {
623
+ const point = bls.hash(message, dst);
624
+ const sig = bls.sign(point, this.sk()).toBytes();
625
+ return Promise.resolve({
626
+ rawSignature: sig,
627
+ sig: b58Encode(sig, PrefixV2.GenericSignature),
628
+ prefixSig: b58Encode(sig, PrefixV2.BLS12_381Signature),
629
+ });
630
+ }
631
+ sign(message) {
632
+ return this.signDst(message, BLS12_381_DST);
633
+ }
634
+ provePossession() {
635
+ return this.signDst(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"), POP_DST);
636
+ }
637
+ publicKey() {
638
+ const res = b58Encode(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"), PrefixV2.BLS12_381PublicKey);
639
+ return Promise.resolve(res);
640
+ }
641
+ publicKeyHash() {
642
+ const res = b58Encode(hash(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"), 20), PrefixV2.BLS12_381PublicKeyHash);
643
+ return Promise.resolve(res);
644
+ }
645
+ secretKey() {
646
+ const res = b58Encode(__classPrivateFieldGet(this, _BLSKey_key, "f"), PrefixV2.BLS12_381SecretKey);
647
+ return Promise.resolve(res);
648
+ }
649
+ }
650
+ _BLSKey_key = new WeakMap(), _BLSKey_publicKey = new WeakMap();
651
+
577
652
  /**
578
653
  *
579
654
  * @description Import a key to sign operation with the side-effect of setting the Tezos instance to use the InMemorySigner provider
@@ -615,10 +690,11 @@ function importKey(toolkit, privateKeyOrEmail, passphrase, mnemonic, secret) {
615
690
 
616
691
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
617
692
  const VERSION = {
618
- "commitHash": "f0eb755ed1e0de4d1cd86623df4496f76efd0caf",
619
- "version": "22.0.0-beta.0"
693
+ "commitHash": "13639ef56845fbb7e93bcbd37d3f6d0457b0872b",
694
+ "version": "23.0.0-RC.0"
620
695
  };
621
696
 
697
+ var _InMemorySigner_key;
622
698
  /**
623
699
  * @description A local implementation of the signer. Will represent a Tezos account and be able to produce signature in its behalf
624
700
  *
@@ -631,7 +707,7 @@ class InMemorySigner {
631
707
  throw new InvalidMnemonicError(mnemonic);
632
708
  }
633
709
  const seed = Bip39.mnemonicToSeedSync(mnemonic, `${email}${password}`);
634
- const key = b58cencode(seed.slice(0, 32), prefix.edsk2);
710
+ const key = b58Encode(seed.subarray(0, 32), PrefixV2.Ed25519Seed);
635
711
  return new InMemorySigner(key);
636
712
  }
637
713
  static fromSecretKey(key, passphrase) {
@@ -667,34 +743,63 @@ class InMemorySigner {
667
743
  *
668
744
  */
669
745
  constructor(key, passphrase) {
670
- const encrypted = key.substring(2, 3) === 'e';
671
- let decrypt = (k) => k;
746
+ _InMemorySigner_key.set(this, void 0);
747
+ const keyPrefixes = [
748
+ PrefixV2.Ed25519EncryptedSeed,
749
+ PrefixV2.Ed25519Seed,
750
+ PrefixV2.Ed25519SecretKey,
751
+ PrefixV2.Secp256k1EncryptedSecretKey,
752
+ PrefixV2.Secp256k1SecretKey,
753
+ PrefixV2.P256EncryptedSecretKey,
754
+ PrefixV2.P256SecretKey,
755
+ PrefixV2.BLS12_381EncryptedSecretKey,
756
+ PrefixV2.BLS12_381SecretKey,
757
+ ];
758
+ const pre = (() => {
759
+ try {
760
+ const [, pre] = b58DecodeAndCheckPrefix(key, keyPrefixes);
761
+ return pre;
762
+ }
763
+ catch (_a) {
764
+ throw new InvalidKeyError(`Invalid private key, expecting one of the following prefixes '${keyPrefixes}'.`);
765
+ }
766
+ })();
767
+ const encrypted = pre === PrefixV2.Ed25519EncryptedSeed ||
768
+ pre === PrefixV2.Secp256k1EncryptedSecretKey ||
769
+ pre === PrefixV2.P256EncryptedSecretKey ||
770
+ pre === PrefixV2.BLS12_381EncryptedSecretKey;
771
+ let decrypt;
672
772
  if (encrypted) {
673
773
  if (!passphrase) {
674
774
  throw new InvalidPassphraseError('No passphrase provided to decrypt encrypted key');
675
775
  }
676
- decrypt = (constructedKey) => {
677
- const salt = toBuffer(constructedKey.slice(0, 8));
678
- const encryptedSk = constructedKey.slice(8);
776
+ decrypt = (data) => {
777
+ const salt = toBuffer(data.slice(0, 8));
778
+ const encryptedSk = data.slice(8);
679
779
  const encryptionKey = pbkdf2.pbkdf2Sync(passphrase, salt, 32768, 32, 'sha512');
680
- return openSecretBox(new Uint8Array(encryptionKey), new Uint8Array(24), new Uint8Array(encryptedSk));
780
+ const res = openSecretBox(new Uint8Array(encryptionKey), new Uint8Array(24), new Uint8Array(encryptedSk));
781
+ if (!res) {
782
+ throw new Error("can't decrypt secret key");
783
+ }
784
+ return res;
681
785
  };
682
786
  }
683
- switch (key.substring(0, 4)) {
684
- case 'edes':
685
- case 'edsk':
686
- this._key = new Tz1(key, encrypted, decrypt);
787
+ switch (pre) {
788
+ case PrefixV2.Ed25519EncryptedSeed:
789
+ case PrefixV2.Ed25519Seed:
790
+ case PrefixV2.Ed25519SecretKey:
791
+ __classPrivateFieldSet(this, _InMemorySigner_key, new EdKey(key, decrypt), "f");
687
792
  break;
688
- case 'spsk':
689
- case 'spes':
690
- this._key = new Tz2(key, encrypted, decrypt);
793
+ case PrefixV2.Secp256k1EncryptedSecretKey:
794
+ case PrefixV2.Secp256k1SecretKey:
795
+ case PrefixV2.P256EncryptedSecretKey:
796
+ case PrefixV2.P256SecretKey:
797
+ __classPrivateFieldSet(this, _InMemorySigner_key, new ECKey(key, decrypt), "f");
691
798
  break;
692
- case 'p2sk':
693
- case 'p2es':
694
- this._key = new Tz3(key, encrypted, decrypt);
799
+ case PrefixV2.BLS12_381EncryptedSecretKey:
800
+ case PrefixV2.BLS12_381SecretKey:
801
+ __classPrivateFieldSet(this, _InMemorySigner_key, new BLSKey(key, decrypt), "f");
695
802
  break;
696
- default:
697
- throw new InvalidKeyError(`${invalidDetail(ValidationResult.NO_PREFIX_MATCHED)} expecting one of the following '${Prefix.EDESK}', '${Prefix.EDSK}', '${Prefix.SPSK}', '${Prefix.SPESK}', '${Prefix.P2SK}' or '${Prefix.P2ESK}'.`);
698
803
  }
699
804
  }
700
805
  /**
@@ -702,41 +807,54 @@ class InMemorySigner {
702
807
  * @param bytes Bytes to sign
703
808
  * @param watermark Watermark to append to the bytes
704
809
  */
705
- sign(bytes, watermark) {
810
+ sign(message, watermark) {
811
+ return __awaiter(this, void 0, void 0, function* () {
812
+ const msg = typeof message == 'string' ? hex2buf(message) : message;
813
+ const watermarkMsg = watermark !== undefined ? mergebuf(watermark, msg) : msg;
814
+ const { rawSignature, sig: signature, prefixSig: prefixedSignature, } = yield __classPrivateFieldGet(this, _InMemorySigner_key, "f").sign(watermarkMsg);
815
+ return {
816
+ bytes: buf2hex(msg),
817
+ sig: signature,
818
+ prefixSig: prefixedSignature,
819
+ sbytes: buf2hex(mergebuf(msg,
820
+ // bls only Signature_prefix ff03 ref:https://octez.tezos.com/docs/shell/p2p_api.html#signature-prefix-tag-255 & https://octez.tezos.com/docs/shell/p2p_api.html#bls-prefix-tag-3
821
+ isPOP(__classPrivateFieldGet(this, _InMemorySigner_key, "f")) ? mergebuf(new Uint8Array([255, 3]), rawSignature) : rawSignature)),
822
+ };
823
+ });
824
+ }
825
+ provePossession() {
706
826
  return __awaiter(this, void 0, void 0, function* () {
707
- let bb = hex2buf(bytes);
708
- if (typeof watermark !== 'undefined') {
709
- bb = mergebuf(watermark, bb);
827
+ if (isPOP(__classPrivateFieldGet(this, _InMemorySigner_key, "f"))) {
828
+ return __classPrivateFieldGet(this, _InMemorySigner_key, "f").provePossession();
829
+ }
830
+ else {
831
+ throw new ProhibitedActionError('Only BLS keys can prove possession');
710
832
  }
711
- const bytesHash = hash(bb, 32);
712
- return this._key.sign(bytes, bytesHash);
713
833
  });
714
834
  }
835
+ get canProvePossession() {
836
+ return isPOP(__classPrivateFieldGet(this, _InMemorySigner_key, "f"));
837
+ }
715
838
  /**
716
839
  * @returns Encoded public key
717
840
  */
718
841
  publicKey() {
719
- return __awaiter(this, void 0, void 0, function* () {
720
- return this._key.publicKey();
721
- });
842
+ return __classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKey();
722
843
  }
723
844
  /**
724
845
  * @returns Encoded public key hash
725
846
  */
726
847
  publicKeyHash() {
727
- return __awaiter(this, void 0, void 0, function* () {
728
- return this._key.publicKeyHash();
729
- });
848
+ return __classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKeyHash();
730
849
  }
731
850
  /**
732
851
  * @returns Encoded private key
733
852
  */
734
853
  secretKey() {
735
- return __awaiter(this, void 0, void 0, function* () {
736
- return this._key.secretKey();
737
- });
854
+ return __classPrivateFieldGet(this, _InMemorySigner_key, "f").secretKey();
738
855
  }
739
856
  }
857
+ _InMemorySigner_key = new WeakMap();
740
858
 
741
859
  export { ecdsa as ECDSA, ed25519 as Ed25519, Hard, InMemorySigner, InvalidPassphraseError, Path, VERSION, generateSecretKey, importKey };
742
860
  //# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}