@taquito/signer 23.0.0-beta.1 → 23.0.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.
@@ -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('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';
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('elliptic/lib/elliptic/ec/key'), require('@taquito/core'), require('pbkdf2'), require('bip39'), require('@stablelib/hmac'), require('@stablelib/sha512'), 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', 'elliptic/lib/elliptic/ec/key', '@taquito/core', 'pbkdf2', 'bip39', '@stablelib/hmac', '@stablelib/sha512', '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.KeyPair, global.core, global.pbkdf2, global.Bip39, global.hmac, global.sha512, global.BN, global.bls12381));
5
+ })(this, (function (exports, nacl, utils, toBuffer, blake2b, ed25519$1, elliptic, KeyPair, core, pbkdf2, Bip39, hmac, sha512, BN, bls12381) { 'use strict';
6
6
 
7
7
  function _interopNamespaceDefault(e) {
8
8
  var n = Object.create(null);
@@ -68,7 +68,7 @@
68
68
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
69
69
  };
70
70
 
71
- var _EdKey_secretKey, _EdKey_publicKey;
71
+ var _EdKey_keyPair, _EdPublicKey_key;
72
72
  /**
73
73
  * @description Provide signing logic for ed25519 curve based key (tz1)
74
74
  */
@@ -81,8 +81,7 @@
81
81
  * @throws {@link InvalidKeyError}
82
82
  */
83
83
  constructor(key, decrypt) {
84
- _EdKey_secretKey.set(this, void 0);
85
- _EdKey_publicKey.set(this, void 0);
84
+ _EdKey_keyPair.set(this, void 0);
86
85
  const tmp = utils.b58DecodeAndCheckPrefix(key, [
87
86
  utils.PrefixV2.Ed25519SecretKey,
88
87
  utils.PrefixV2.Ed25519EncryptedSeed,
@@ -91,8 +90,10 @@
91
90
  let [keyData] = tmp;
92
91
  const [, prefix] = tmp;
93
92
  if (prefix === utils.PrefixV2.Ed25519SecretKey) {
94
- __classPrivateFieldSet(this, _EdKey_secretKey, keyData, "f");
95
- __classPrivateFieldSet(this, _EdKey_publicKey, keyData.slice(32), "f");
93
+ __classPrivateFieldSet(this, _EdKey_keyPair, {
94
+ secretKey: keyData,
95
+ publicKey: keyData.slice(32),
96
+ }, "f");
96
97
  }
97
98
  else {
98
99
  if (prefix === utils.PrefixV2.Ed25519EncryptedSeed) {
@@ -103,9 +104,7 @@
103
104
  throw new Error('decryption function is not provided');
104
105
  }
105
106
  }
106
- const { publicKey, secretKey } = ed25519$1.generateKeyPairFromSeed(keyData);
107
- __classPrivateFieldSet(this, _EdKey_publicKey, publicKey, "f");
108
- __classPrivateFieldSet(this, _EdKey_secretKey, secretKey, "f");
107
+ __classPrivateFieldSet(this, _EdKey_keyPair, ed25519$1.generateKeyPairFromSeed(keyData), "f");
109
108
  }
110
109
  }
111
110
  /**
@@ -114,154 +113,64 @@
114
113
  * @param bytesHash Blake2b hash of the bytes to sign
115
114
  */
116
115
  sign(bytes) {
117
- return __awaiter(this, void 0, void 0, function* () {
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
- });
125
- });
116
+ const hash = blake2b.hash(bytes, 32);
117
+ const signature = ed25519$1.sign(__classPrivateFieldGet(this, _EdKey_keyPair, "f").secretKey, hash);
118
+ return {
119
+ rawSignature: signature,
120
+ sig: utils.b58Encode(signature, utils.PrefixV2.GenericSignature),
121
+ prefixSig: utils.b58Encode(signature, utils.PrefixV2.Ed25519Signature),
122
+ };
126
123
  }
127
124
  /**
128
125
  * @returns Encoded public key
129
126
  */
130
127
  publicKey() {
131
- return Promise.resolve(utils.b58Encode(__classPrivateFieldGet(this, _EdKey_publicKey, "f"), utils.PrefixV2.Ed25519PublicKey));
132
- }
133
- /**
134
- * @returns Encoded public key hash
135
- */
136
- publicKeyHash() {
137
- return Promise.resolve(utils.b58Encode(blake2b.hash(__classPrivateFieldGet(this, _EdKey_publicKey, "f"), 20), utils.PrefixV2.Ed25519PublicKeyHash));
128
+ return new EdPublicKey(__classPrivateFieldGet(this, _EdKey_keyPair, "f").publicKey);
138
129
  }
139
130
  /**
140
131
  * @returns Encoded private key
141
132
  */
142
133
  secretKey() {
143
- return Promise.resolve(utils.b58Encode(__classPrivateFieldGet(this, _EdKey_secretKey, "f"), utils.PrefixV2.Ed25519SecretKey));
134
+ return utils.b58Encode(__classPrivateFieldGet(this, _EdKey_keyPair, "f").secretKey, utils.PrefixV2.Ed25519SecretKey);
144
135
  }
145
136
  }
146
- _EdKey_secretKey = new WeakMap(), _EdKey_publicKey = new WeakMap();
147
-
148
- var _ECKey_key, _ECKey_publicKey, _ECKey_curve;
149
- const pref = {
150
- p256: {
151
- pk: utils.PrefixV2.P256PublicKey,
152
- sk: utils.PrefixV2.P256SecretKey,
153
- pkh: utils.PrefixV2.P256PublicKeyHash,
154
- sig: utils.PrefixV2.P256Signature,
155
- },
156
- secp256k1: {
157
- pk: utils.PrefixV2.Secp256k1PublicKey,
158
- sk: utils.PrefixV2.Secp256k1SecretKey,
159
- pkh: utils.PrefixV2.Secp256k1PublicKeyHash,
160
- sig: utils.PrefixV2.Secp256k1Signature,
161
- },
162
- };
163
- /**
164
- * @description Provide signing logic for elliptic curve based key (tz2, tz3)
165
- */
166
- class ECKey {
167
- /**
168
- *
169
- * @param key Encoded private key
170
- * @param decrypt Decrypt function
171
- * @throws {@link InvalidKeyError}
172
- */
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;
137
+ _EdKey_keyPair = new WeakMap();
138
+ class EdPublicKey {
139
+ constructor(src) {
140
+ _EdPublicKey_key.set(this, void 0);
141
+ if (typeof src === 'string') {
142
+ const [key, _] = utils.b58DecodeAndCheckPrefix(src, [utils.PrefixV2.Ed25519PublicKey]);
143
+ __classPrivateFieldSet(this, _EdPublicKey_key, key, "f");
144
+ }
145
+ else {
146
+ __classPrivateFieldSet(this, _EdPublicKey_key, src, "f");
208
147
  }
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
211
148
  }
212
- /**
213
- *
214
- * @param bytes Bytes to sign
215
- * @param bytesHash Blake2b hash of the bytes to sign
216
- */
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),
230
- });
149
+ compare(other) {
150
+ if (other instanceof EdPublicKey) {
151
+ return utils.compareArrays(this.bytes(), other.bytes());
152
+ }
153
+ else {
154
+ throw new utils.InvalidPublicKeyError('EdDSA key expected');
155
+ }
231
156
  }
232
- /**
233
- * @returns Encoded public key
234
- */
235
- publicKey() {
236
- return Promise.resolve(utils.b58Encode(__classPrivateFieldGet(this, _ECKey_publicKey, "f"), pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].pk));
157
+ hash() {
158
+ return utils.b58Encode(blake2b.hash(__classPrivateFieldGet(this, _EdPublicKey_key, "f"), 20), utils.PrefixV2.Ed25519PublicKeyHash);
237
159
  }
238
- /**
239
- * @returns Encoded public key hash
240
- */
241
- publicKeyHash() {
242
- return Promise.resolve(utils.b58Encode(blake2b.hash(new Uint8Array(__classPrivateFieldGet(this, _ECKey_publicKey, "f")), 20), pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].pkh));
160
+ bytes() {
161
+ return __classPrivateFieldGet(this, _EdPublicKey_key, "f");
243
162
  }
244
- /**
245
- * @returns Encoded private key
246
- */
247
- secretKey() {
248
- return Promise.resolve(utils.b58Encode(__classPrivateFieldGet(this, _ECKey_key, "f"), pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].sk));
163
+ toProtocol() {
164
+ const res = new Uint8Array(__classPrivateFieldGet(this, _EdPublicKey_key, "f").length + 1);
165
+ res[0] = 0;
166
+ res.set(__classPrivateFieldGet(this, _EdPublicKey_key, "f"), 1);
167
+ return res;
249
168
  }
250
- }
251
- _ECKey_key = new WeakMap(), _ECKey_publicKey = new WeakMap(), _ECKey_curve = new WeakMap();
252
-
253
- function parseHex(s) {
254
- const res = [];
255
- for (let i = 0; i < s.length; i += 2) {
256
- const ss = s.slice(i, i + 2);
257
- const x = parseInt(ss, 16);
258
- if (Number.isNaN(x)) {
259
- throw new core.InvalidHexStringError(ss);
260
- }
261
- res.push(x);
169
+ toString() {
170
+ return utils.b58Encode(__classPrivateFieldGet(this, _EdPublicKey_key, "f"), utils.PrefixV2.Ed25519PublicKey);
262
171
  }
263
- return new Uint8Array(res);
264
172
  }
173
+ _EdPublicKey_key = new WeakMap();
265
174
 
266
175
  /**
267
176
  * @category Error
@@ -332,6 +241,189 @@
332
241
  }
333
242
  }
334
243
 
244
+ const pref = {
245
+ p256: {
246
+ pk: utils.PrefixV2.P256PublicKey,
247
+ sk: utils.PrefixV2.P256SecretKey,
248
+ pkh: utils.PrefixV2.P256PublicKeyHash,
249
+ sig: utils.PrefixV2.P256Signature,
250
+ tag: 2,
251
+ },
252
+ secp256k1: {
253
+ pk: utils.PrefixV2.Secp256k1PublicKey,
254
+ sk: utils.PrefixV2.Secp256k1SecretKey,
255
+ pkh: utils.PrefixV2.Secp256k1PublicKeyHash,
256
+ sig: utils.PrefixV2.Secp256k1Signature,
257
+ tag: 1,
258
+ },
259
+ };
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
+ /**
278
+ * @description Provide signing logic for elliptic curve based key (tz2, tz3)
279
+ */
280
+ class ECKey extends ECKeyBase {
281
+ /**
282
+ *
283
+ * @param key Encoded private key
284
+ * @param decrypt Decrypt function
285
+ * @throws {@link InvalidKeyError}
286
+ */
287
+ constructor(key, decrypt) {
288
+ const [keyData, prefix] = utils.b58DecodeAndCheckPrefix(key, [
289
+ utils.PrefixV2.Secp256k1EncryptedSecretKey,
290
+ utils.PrefixV2.P256EncryptedSecretKey,
291
+ utils.PrefixV2.Secp256k1SecretKey,
292
+ utils.PrefixV2.P256SecretKey,
293
+ ]);
294
+ const [decKey, curve] = (() => {
295
+ switch (prefix) {
296
+ case utils.PrefixV2.Secp256k1EncryptedSecretKey:
297
+ case utils.PrefixV2.P256EncryptedSecretKey:
298
+ if (decrypt === undefined) {
299
+ throw new Error('decryption function is not provided');
300
+ }
301
+ else {
302
+ return [
303
+ decrypt(keyData),
304
+ prefix === utils.PrefixV2.Secp256k1EncryptedSecretKey ? 'secp256k1' : 'p256',
305
+ ];
306
+ }
307
+ case utils.PrefixV2.Secp256k1SecretKey:
308
+ return [keyData, 'secp256k1'];
309
+ default:
310
+ return [keyData, 'p256'];
311
+ }
312
+ })();
313
+ super(new elliptic.ec(curve).keyFromPrivate(decKey));
314
+ }
315
+ /**
316
+ *
317
+ * @param bytes Bytes to sign
318
+ * @param bytesHash Blake2b hash of the bytes to sign
319
+ */
320
+ sign(bytes) {
321
+ const hash = blake2b.hash(bytes, 32);
322
+ const sig = this.keyPair.sign(hash, { canonical: true });
323
+ const signature = new Uint8Array(64);
324
+ const r = sig.r.toArray();
325
+ const s = sig.s.toArray();
326
+ signature.set(r, 32 - r.length);
327
+ signature.set(s, 64 - s.length);
328
+ return {
329
+ rawSignature: signature,
330
+ sig: utils.b58Encode(signature, utils.PrefixV2.GenericSignature),
331
+ prefixSig: utils.b58Encode(signature, pref[this.curve()].sig),
332
+ };
333
+ }
334
+ /**
335
+ * @returns Encoded public key
336
+ */
337
+ publicKey() {
338
+ return new ECPublicKey(this.keyPair.ec.keyFromPublic(this.keyPair));
339
+ }
340
+ /**
341
+ * @returns Encoded private key
342
+ */
343
+ secretKey() {
344
+ return utils.b58Encode(new Uint8Array(this.keyPair.getPrivate().toArray()), pref[this.curve()].sk);
345
+ }
346
+ }
347
+ function isKeyPair(src) {
348
+ return src instanceof KeyPair;
349
+ }
350
+ class ECPublicKey extends ECKeyBase {
351
+ constructor(src, curve) {
352
+ const key = (() => {
353
+ if (isKeyPair(src)) {
354
+ return src;
355
+ }
356
+ else {
357
+ const [key, crv] = (() => {
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);
373
+ }
374
+ })();
375
+ super(key);
376
+ }
377
+ compare(other) {
378
+ if (other instanceof ECPublicKey) {
379
+ if (this.curve() === other.curve()) {
380
+ const compress = this.curve() === 'secp256k1';
381
+ return utils.compareArrays(this.bytes(compress), other.bytes(compress));
382
+ }
383
+ else if (this.curve() === 'secp256k1') {
384
+ return -1;
385
+ }
386
+ else {
387
+ return 1;
388
+ }
389
+ }
390
+ else {
391
+ throw new utils.InvalidPublicKeyError('ECDSA key expected');
392
+ }
393
+ }
394
+ hash() {
395
+ const key = this.bytes();
396
+ return utils.b58Encode(blake2b.hash(key, 20), pref[this.curve()].pkh);
397
+ }
398
+ bytes(compress = true) {
399
+ return new Uint8Array(this.keyPair.getPublic(compress, 'array'));
400
+ }
401
+ toProtocol() {
402
+ const key = this.bytes();
403
+ const res = new Uint8Array(key.length + 1);
404
+ res[0] = pref[this.curve()].tag;
405
+ res.set(key, 1);
406
+ return res;
407
+ }
408
+ toString() {
409
+ const key = this.bytes();
410
+ return utils.b58Encode(key, pref[this.curve()].pk);
411
+ }
412
+ }
413
+
414
+ function parseHex(s) {
415
+ const res = [];
416
+ for (let i = 0; i < s.length; i += 2) {
417
+ const ss = s.slice(i, i + 2);
418
+ const x = parseInt(ss, 16);
419
+ if (Number.isNaN(x)) {
420
+ throw new core.InvalidHexStringError(ss);
421
+ }
422
+ res.push(x);
423
+ }
424
+ return new Uint8Array(res);
425
+ }
426
+
335
427
  /* eslint-disable @typescript-eslint/no-this-alias */
336
428
  const seedKey = {
337
429
  p256: 'Nist256p1 seed',
@@ -604,7 +696,7 @@
604
696
  return 'provePossession' in k;
605
697
  }
606
698
 
607
- var _BLSKey_key, _BLSKey_publicKey;
699
+ var _BLSKey_key, _BLSKey_publicKey, _BLSPublicKey_key;
608
700
  const bls = bls12381.bls12_381.longSignatures; // AKA MinPK
609
701
  class BLSKey {
610
702
  constructor(key, decrypt) {
@@ -633,11 +725,11 @@
633
725
  signDst(message, dst) {
634
726
  const point = bls.hash(message, dst);
635
727
  const sig = bls.sign(point, this.sk()).toBytes();
636
- return Promise.resolve({
728
+ return {
637
729
  rawSignature: sig,
638
730
  sig: utils.b58Encode(sig, utils.PrefixV2.GenericSignature),
639
731
  prefixSig: utils.b58Encode(sig, utils.PrefixV2.BLS12_381Signature),
640
- });
732
+ };
641
733
  }
642
734
  sign(message) {
643
735
  return this.signDst(message, utils.BLS12_381_DST);
@@ -646,19 +738,49 @@
646
738
  return this.signDst(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"), utils.POP_DST);
647
739
  }
648
740
  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);
741
+ return new BLSPublicKey(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"));
655
742
  }
656
743
  secretKey() {
657
- const res = utils.b58Encode(__classPrivateFieldGet(this, _BLSKey_key, "f"), utils.PrefixV2.BLS12_381SecretKey);
658
- return Promise.resolve(res);
744
+ return utils.b58Encode(__classPrivateFieldGet(this, _BLSKey_key, "f"), utils.PrefixV2.BLS12_381SecretKey);
659
745
  }
660
746
  }
661
747
  _BLSKey_key = new WeakMap(), _BLSKey_publicKey = new WeakMap();
748
+ class BLSPublicKey {
749
+ constructor(src) {
750
+ _BLSPublicKey_key.set(this, void 0);
751
+ if (typeof src === 'string') {
752
+ const [key, _] = utils.b58DecodeAndCheckPrefix(src, [utils.PrefixV2.BLS12_381PublicKey]);
753
+ __classPrivateFieldSet(this, _BLSPublicKey_key, key, "f");
754
+ }
755
+ else {
756
+ __classPrivateFieldSet(this, _BLSPublicKey_key, src, "f");
757
+ }
758
+ }
759
+ compare(other) {
760
+ if (other instanceof BLSPublicKey) {
761
+ return utils.compareArrays(this.bytes(), other.bytes());
762
+ }
763
+ else {
764
+ throw new utils.InvalidPublicKeyError('BLS key expected');
765
+ }
766
+ }
767
+ hash() {
768
+ return utils.b58Encode(blake2b.hash(__classPrivateFieldGet(this, _BLSPublicKey_key, "f"), 20), utils.PrefixV2.BLS12_381PublicKeyHash);
769
+ }
770
+ bytes() {
771
+ return __classPrivateFieldGet(this, _BLSPublicKey_key, "f");
772
+ }
773
+ toProtocol() {
774
+ const res = new Uint8Array(__classPrivateFieldGet(this, _BLSPublicKey_key, "f").length + 1);
775
+ res[0] = 3;
776
+ res.set(__classPrivateFieldGet(this, _BLSPublicKey_key, "f"), 1);
777
+ return res;
778
+ }
779
+ toString() {
780
+ return utils.b58Encode(__classPrivateFieldGet(this, _BLSPublicKey_key, "f"), utils.PrefixV2.BLS12_381PublicKey);
781
+ }
782
+ }
783
+ _BLSPublicKey_key = new WeakMap();
662
784
 
663
785
  /**
664
786
  *
@@ -701,8 +823,8 @@
701
823
 
702
824
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
703
825
  const VERSION = {
704
- "commitHash": "10b3de10de15ae68d47b1fca922d3129d2f79641",
705
- "version": "23.0.0-beta.1"
826
+ "commitHash": "9065acc1b41ec205a49e64b54ef89f50bafa6210",
827
+ "version": "23.0.0"
706
828
  };
707
829
 
708
830
  var _InMemorySigner_key;
@@ -850,22 +972,40 @@
850
972
  * @returns Encoded public key
851
973
  */
852
974
  publicKey() {
853
- return __classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKey();
975
+ return Promise.resolve(String(__classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKey()));
854
976
  }
855
977
  /**
856
978
  * @returns Encoded public key hash
857
979
  */
858
980
  publicKeyHash() {
859
- return __classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKeyHash();
981
+ return Promise.resolve(__classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKey().hash());
860
982
  }
861
983
  /**
862
984
  * @returns Encoded private key
863
985
  */
864
986
  secretKey() {
865
- return __classPrivateFieldGet(this, _InMemorySigner_key, "f").secretKey();
987
+ return Promise.resolve(__classPrivateFieldGet(this, _InMemorySigner_key, "f").secretKey());
866
988
  }
867
989
  }
868
990
  _InMemorySigner_key = new WeakMap();
991
+ function publicKeyFromString(src) {
992
+ const [keyData, pre] = utils.b58DecodeAndCheckPrefix(src, [
993
+ utils.PrefixV2.Ed25519PublicKey,
994
+ utils.PrefixV2.Secp256k1PublicKey,
995
+ utils.PrefixV2.P256PublicKey,
996
+ utils.PrefixV2.BLS12_381PublicKey,
997
+ ]);
998
+ switch (pre) {
999
+ case utils.PrefixV2.Ed25519PublicKey:
1000
+ return new EdPublicKey(keyData);
1001
+ case utils.PrefixV2.Secp256k1PublicKey:
1002
+ return new ECPublicKey(keyData, 'secp256k1');
1003
+ case utils.PrefixV2.P256PublicKey:
1004
+ return new ECPublicKey(keyData, 'p256');
1005
+ case utils.PrefixV2.BLS12_381PublicKey:
1006
+ return new BLSPublicKey(keyData);
1007
+ }
1008
+ }
869
1009
 
870
1010
  exports.ECDSA = ecdsa;
871
1011
  exports.Ed25519 = ed25519;
@@ -876,6 +1016,7 @@
876
1016
  exports.VERSION = VERSION;
877
1017
  exports.generateSecretKey = generateSecretKey;
878
1018
  exports.importKey = importKey;
1019
+ exports.publicKeyFromString = publicKeyFromString;
879
1020
 
880
1021
  }));
881
1022
  //# sourceMappingURL=taquito-signer.umd.js.map
@@ -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,13 +1,21 @@
1
- import { SigningKeyWithProofOfPossession } from './key-interface';
2
- import { RawSignResult } from '@taquito/taquito';
1
+ import { PublicKey, SigningKeyWithProofOfPossession } from './key-interface';
2
+ import { RawSignResult } from '@taquito/core';
3
3
  export declare class BLSKey implements SigningKeyWithProofOfPossession {
4
4
  #private;
5
5
  constructor(key: string, decrypt?: (k: Uint8Array) => Uint8Array);
6
6
  private sk;
7
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>;
8
+ sign(message: Uint8Array): RawSignResult;
9
+ provePossession(): RawSignResult;
10
+ publicKey(): PublicKey;
11
+ secretKey(): string;
12
+ }
13
+ export declare class BLSPublicKey implements PublicKey {
14
+ #private;
15
+ constructor(src: string | Uint8Array);
16
+ compare(other: PublicKey): number;
17
+ hash(): string;
18
+ bytes(): Uint8Array;
19
+ toProtocol(): Uint8Array;
20
+ toString(): string;
13
21
  }
@@ -1,10 +1,16 @@
1
- import { SigningKey } from './key-interface';
2
- import { RawSignResult } from '@taquito/taquito';
1
+ import elliptic from 'elliptic';
2
+ import { SigningKey, PublicKey } from './key-interface';
3
+ import { RawSignResult } from '@taquito/core';
4
+ type Curve = 'p256' | 'secp256k1';
5
+ declare class ECKeyBase {
6
+ readonly keyPair: elliptic.ec.KeyPair;
7
+ constructor(keyPair: elliptic.ec.KeyPair);
8
+ curve(): Curve;
9
+ }
3
10
  /**
4
11
  * @description Provide signing logic for elliptic curve based key (tz2, tz3)
5
12
  */
6
- export declare class ECKey implements SigningKey {
7
- #private;
13
+ export declare class ECKey extends ECKeyBase implements SigningKey {
8
14
  /**
9
15
  *
10
16
  * @param key Encoded private key
@@ -17,17 +23,24 @@ export declare class ECKey implements SigningKey {
17
23
  * @param bytes Bytes to sign
18
24
  * @param bytesHash Blake2b hash of the bytes to sign
19
25
  */
20
- sign(bytes: Uint8Array): Promise<RawSignResult>;
26
+ sign(bytes: Uint8Array): RawSignResult;
21
27
  /**
22
28
  * @returns Encoded public key
23
29
  */
24
- publicKey(): Promise<string>;
25
- /**
26
- * @returns Encoded public key hash
27
- */
28
- publicKeyHash(): Promise<string>;
30
+ publicKey(): PublicKey;
29
31
  /**
30
32
  * @returns Encoded private key
31
33
  */
32
- secretKey(): Promise<string>;
34
+ secretKey(): string;
35
+ }
36
+ export declare class ECPublicKey extends ECKeyBase implements PublicKey {
37
+ constructor(src: string);
38
+ constructor(src: elliptic.ec.KeyPair);
39
+ constructor(src: Uint8Array, curve: Curve);
40
+ compare(other: PublicKey): number;
41
+ hash(): string;
42
+ bytes(compress?: boolean): Uint8Array;
43
+ toProtocol(): Uint8Array;
44
+ toString(): string;
33
45
  }
46
+ export {};