@taquito/signer 22.0.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.
- package/dist/lib/bls-key.js +73 -0
- package/dist/lib/ec-key.js +74 -65
- package/dist/lib/ed-key.js +52 -51
- package/dist/lib/helpers.js +3 -3
- package/dist/lib/key-interface.js +6 -0
- package/dist/lib/signer.js +6 -0
- package/dist/lib/taquito-signer.js +90 -35
- package/dist/lib/version.js +2 -2
- package/dist/taquito-signer.es6.js +261 -143
- package/dist/taquito-signer.es6.js.map +1 -1
- package/dist/taquito-signer.umd.js +261 -144
- package/dist/taquito-signer.umd.js.map +1 -1
- package/dist/types/bls-key.d.ts +13 -0
- package/dist/types/ec-key.d.ts +6 -22
- package/dist/types/ed-key.d.ts +6 -13
- package/dist/types/key-interface.d.ts +12 -0
- package/dist/types/signer.d.ts +16 -0
- package/dist/types/taquito-signer.d.ts +6 -8
- package/package.json +6 -5
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@stablelib/nacl'), require('@
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@stablelib/nacl', '@
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoSigner = {}, global.nacl, global.
|
|
5
|
-
})(this, (function (exports, nacl,
|
|
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
|
|
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,
|
|
70
|
-
this
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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
|
|
116
|
+
sign(bytes) {
|
|
98
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
|
|
100
|
-
const signature = ed25519$1.sign(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
146
|
-
sk: utils.
|
|
147
|
-
pkh: utils.
|
|
148
|
-
sig: utils.
|
|
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.
|
|
152
|
-
sk: utils.
|
|
153
|
-
pkh: utils.
|
|
154
|
-
sig: utils.
|
|
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(
|
|
170
|
-
|
|
171
|
-
this
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
178
|
-
|
|
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
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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": "
|
|
631
|
-
"version": "
|
|
704
|
+
"commitHash": "13639ef56845fbb7e93bcbd37d3f6d0457b0872b",
|
|
705
|
+
"version": "23.0.0-RC.0"
|
|
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.
|
|
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
|
-
|
|
683
|
-
|
|
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 = (
|
|
689
|
-
const salt = toBuffer(
|
|
690
|
-
const encryptedSk =
|
|
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
|
-
|
|
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 (
|
|
696
|
-
case
|
|
697
|
-
case
|
|
698
|
-
|
|
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
|
|
701
|
-
case
|
|
702
|
-
|
|
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
|
|
705
|
-
case
|
|
706
|
-
this
|
|
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(
|
|
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
|
-
|
|
720
|
-
|
|
721
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
+
}
|
package/dist/types/ec-key.d.ts
CHANGED
|
@@ -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
|
|
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(
|
|
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:
|
|
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;
|