@taquito/signer 23.0.0-beta.0 → 23.0.0-beta.1

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