@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
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _BLSKey_key, _BLSKey_publicKey;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BLSKey = void 0;
|
|
16
|
+
const utils_1 = require("@taquito/utils");
|
|
17
|
+
const bls12_381_1 = require("@noble/curves/bls12-381");
|
|
18
|
+
const blake2b_1 = require("@stablelib/blake2b");
|
|
19
|
+
const bls = bls12_381_1.bls12_381.longSignatures; // AKA MinPK
|
|
20
|
+
class BLSKey {
|
|
21
|
+
constructor(key, decrypt) {
|
|
22
|
+
_BLSKey_key.set(this, void 0);
|
|
23
|
+
_BLSKey_publicKey.set(this, void 0);
|
|
24
|
+
const tmp = (0, utils_1.b58DecodeAndCheckPrefix)(key, [
|
|
25
|
+
utils_1.PrefixV2.BLS12_381EncryptedSecretKey,
|
|
26
|
+
utils_1.PrefixV2.BLS12_381SecretKey,
|
|
27
|
+
]);
|
|
28
|
+
let [keyData] = tmp;
|
|
29
|
+
const [, prefix] = tmp;
|
|
30
|
+
if (prefix === utils_1.PrefixV2.BLS12_381EncryptedSecretKey) {
|
|
31
|
+
if (decrypt !== undefined) {
|
|
32
|
+
keyData = decrypt(keyData);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error('decryption function is not provided');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
__classPrivateFieldSet(this, _BLSKey_key, keyData, "f");
|
|
39
|
+
__classPrivateFieldSet(this, _BLSKey_publicKey, bls.getPublicKey(this.sk()).toBytes(), "f");
|
|
40
|
+
}
|
|
41
|
+
sk() {
|
|
42
|
+
return new Uint8Array(__classPrivateFieldGet(this, _BLSKey_key, "f")).reverse();
|
|
43
|
+
}
|
|
44
|
+
signDst(message, dst) {
|
|
45
|
+
const point = bls.hash(message, dst);
|
|
46
|
+
const sig = bls.sign(point, this.sk()).toBytes();
|
|
47
|
+
return Promise.resolve({
|
|
48
|
+
rawSignature: sig,
|
|
49
|
+
sig: (0, utils_1.b58Encode)(sig, utils_1.PrefixV2.GenericSignature),
|
|
50
|
+
prefixSig: (0, utils_1.b58Encode)(sig, utils_1.PrefixV2.BLS12_381Signature),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
sign(message) {
|
|
54
|
+
return this.signDst(message, utils_1.BLS12_381_DST);
|
|
55
|
+
}
|
|
56
|
+
provePossession() {
|
|
57
|
+
return this.signDst(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"), utils_1.POP_DST);
|
|
58
|
+
}
|
|
59
|
+
publicKey() {
|
|
60
|
+
const res = (0, utils_1.b58Encode)(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"), utils_1.PrefixV2.BLS12_381PublicKey);
|
|
61
|
+
return Promise.resolve(res);
|
|
62
|
+
}
|
|
63
|
+
publicKeyHash() {
|
|
64
|
+
const res = (0, utils_1.b58Encode)((0, blake2b_1.hash)(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"), 20), utils_1.PrefixV2.BLS12_381PublicKeyHash);
|
|
65
|
+
return Promise.resolve(res);
|
|
66
|
+
}
|
|
67
|
+
secretKey() {
|
|
68
|
+
const res = (0, utils_1.b58Encode)(__classPrivateFieldGet(this, _BLSKey_key, "f"), utils_1.PrefixV2.BLS12_381SecretKey);
|
|
69
|
+
return Promise.resolve(res);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.BLSKey = BLSKey;
|
|
73
|
+
_BLSKey_key = new WeakMap(), _BLSKey_publicKey = new WeakMap();
|
package/dist/lib/ec-key.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
10
7
|
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _ECKey_key, _ECKey_publicKey, _ECKey_curve;
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
15
|
+
exports.ECKey = void 0;
|
|
13
16
|
const blake2b_1 = require("@stablelib/blake2b");
|
|
14
17
|
const utils_1 = require("@taquito/utils");
|
|
15
|
-
const typedarray_to_buffer_1 = require("typedarray-to-buffer");
|
|
16
18
|
const elliptic_1 = require("elliptic");
|
|
17
|
-
const core_1 = require("@taquito/core");
|
|
18
19
|
const pref = {
|
|
19
20
|
p256: {
|
|
20
|
-
pk: utils_1.
|
|
21
|
-
sk: utils_1.
|
|
22
|
-
pkh: utils_1.
|
|
23
|
-
sig: utils_1.
|
|
21
|
+
pk: utils_1.PrefixV2.P256PublicKey,
|
|
22
|
+
sk: utils_1.PrefixV2.P256SecretKey,
|
|
23
|
+
pkh: utils_1.PrefixV2.P256PublicKeyHash,
|
|
24
|
+
sig: utils_1.PrefixV2.P256Signature,
|
|
24
25
|
},
|
|
25
26
|
secp256k1: {
|
|
26
|
-
pk: utils_1.
|
|
27
|
-
sk: utils_1.
|
|
28
|
-
pkh: utils_1.
|
|
29
|
-
sig: utils_1.
|
|
27
|
+
pk: utils_1.PrefixV2.Secp256k1PublicKey,
|
|
28
|
+
sk: utils_1.PrefixV2.Secp256k1SecretKey,
|
|
29
|
+
pkh: utils_1.PrefixV2.Secp256k1PublicKeyHash,
|
|
30
|
+
sig: utils_1.PrefixV2.Secp256k1Signature,
|
|
30
31
|
},
|
|
31
32
|
};
|
|
32
33
|
/**
|
|
@@ -35,79 +36,87 @@ const pref = {
|
|
|
35
36
|
class ECKey {
|
|
36
37
|
/**
|
|
37
38
|
*
|
|
38
|
-
* @param curve Curve to use with the key
|
|
39
39
|
* @param key Encoded private key
|
|
40
|
-
* @param encrypted Is the private key encrypted
|
|
41
40
|
* @param decrypt Decrypt function
|
|
42
41
|
* @throws {@link InvalidKeyError}
|
|
43
42
|
*/
|
|
44
|
-
constructor(
|
|
45
|
-
|
|
46
|
-
this
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
constructor(key, decrypt) {
|
|
44
|
+
var _a;
|
|
45
|
+
_ECKey_key.set(this, void 0);
|
|
46
|
+
_ECKey_publicKey.set(this, void 0);
|
|
47
|
+
_ECKey_curve.set(this, void 0);
|
|
48
|
+
const tmp = (0, utils_1.b58DecodeAndCheckPrefix)(key, [
|
|
49
|
+
utils_1.PrefixV2.Secp256k1EncryptedSecretKey,
|
|
50
|
+
utils_1.PrefixV2.P256EncryptedSecretKey,
|
|
51
|
+
utils_1.PrefixV2.Secp256k1SecretKey,
|
|
52
|
+
utils_1.PrefixV2.P256SecretKey,
|
|
53
|
+
]);
|
|
54
|
+
_a = this, [({ set value(_b) { __classPrivateFieldSet(_a, _ECKey_key, _b, "f"); } }).value] = tmp;
|
|
55
|
+
const [, prefix] = tmp;
|
|
56
|
+
switch (prefix) {
|
|
57
|
+
case utils_1.PrefixV2.Secp256k1EncryptedSecretKey:
|
|
58
|
+
case utils_1.PrefixV2.P256EncryptedSecretKey:
|
|
59
|
+
if (decrypt !== undefined) {
|
|
60
|
+
__classPrivateFieldSet(this, _ECKey_key, decrypt(__classPrivateFieldGet(this, _ECKey_key, "f")), "f");
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new Error('decryption function is not provided');
|
|
64
|
+
}
|
|
65
|
+
if (prefix === utils_1.PrefixV2.Secp256k1EncryptedSecretKey) {
|
|
66
|
+
__classPrivateFieldSet(this, _ECKey_curve, 'secp256k1', "f");
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
__classPrivateFieldSet(this, _ECKey_curve, 'p256', "f");
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
case utils_1.PrefixV2.Secp256k1SecretKey:
|
|
73
|
+
__classPrivateFieldSet(this, _ECKey_curve, 'secp256k1', "f");
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
__classPrivateFieldSet(this, _ECKey_curve, 'p256', "f");
|
|
77
|
+
break;
|
|
51
78
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const keyPairY = keyPair.getPublic().getY().toArray();
|
|
55
|
-
const parityByte = keyPairY.length < 32 ? keyPairY[keyPairY.length - 1] : keyPairY[31];
|
|
56
|
-
const pref = parityByte % 2 ? 3 : 2;
|
|
57
|
-
const pad = new Array(32).fill(0);
|
|
58
|
-
this._publicKey = (0, typedarray_to_buffer_1.default)(new Uint8Array([pref].concat(pad.concat(keyPair.getPublic().getX().toArray()).slice(-32))));
|
|
79
|
+
const keyPair = new elliptic_1.default.ec(__classPrivateFieldGet(this, _ECKey_curve, "f")).keyFromPrivate(__classPrivateFieldGet(this, _ECKey_key, "f"));
|
|
80
|
+
__classPrivateFieldSet(this, _ECKey_publicKey, new Uint8Array(keyPair.getPublic(true, 'array')), "f"); // compress
|
|
59
81
|
}
|
|
60
82
|
/**
|
|
61
83
|
*
|
|
62
84
|
* @param bytes Bytes to sign
|
|
63
85
|
* @param bytesHash Blake2b hash of the bytes to sign
|
|
64
86
|
*/
|
|
65
|
-
sign(bytes
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
sign(bytes) {
|
|
88
|
+
const hash = (0, blake2b_1.hash)(bytes, 32);
|
|
89
|
+
const key = new elliptic_1.default.ec(__classPrivateFieldGet(this, _ECKey_curve, "f")).keyFromPrivate(__classPrivateFieldGet(this, _ECKey_key, "f"));
|
|
90
|
+
const sig = key.sign(hash, { canonical: true });
|
|
91
|
+
const signature = new Uint8Array(64);
|
|
92
|
+
const r = sig.r.toArray();
|
|
93
|
+
const s = sig.s.toArray();
|
|
94
|
+
signature.set(r, 32 - r.length);
|
|
95
|
+
signature.set(s, 64 - s.length);
|
|
96
|
+
return Promise.resolve({
|
|
97
|
+
rawSignature: signature,
|
|
98
|
+
sig: (0, utils_1.b58Encode)(signature, utils_1.PrefixV2.GenericSignature),
|
|
99
|
+
prefixSig: (0, utils_1.b58Encode)(signature, pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].sig),
|
|
77
100
|
});
|
|
78
101
|
}
|
|
79
102
|
/**
|
|
80
103
|
* @returns Encoded public key
|
|
81
104
|
*/
|
|
82
105
|
publicKey() {
|
|
83
|
-
return
|
|
84
|
-
return (0, utils_1.b58cencode)(this._publicKey, pref[this.curve].pk);
|
|
85
|
-
});
|
|
106
|
+
return Promise.resolve((0, utils_1.b58Encode)(__classPrivateFieldGet(this, _ECKey_publicKey, "f"), pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].pk));
|
|
86
107
|
}
|
|
87
108
|
/**
|
|
88
109
|
* @returns Encoded public key hash
|
|
89
110
|
*/
|
|
90
111
|
publicKeyHash() {
|
|
91
|
-
return
|
|
92
|
-
return (0, utils_1.b58cencode)((0, blake2b_1.hash)(new Uint8Array(this._publicKey), 20), pref[this.curve].pkh);
|
|
93
|
-
});
|
|
112
|
+
return Promise.resolve((0, utils_1.b58Encode)((0, blake2b_1.hash)(new Uint8Array(__classPrivateFieldGet(this, _ECKey_publicKey, "f")), 20), pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].pkh));
|
|
94
113
|
}
|
|
95
114
|
/**
|
|
96
115
|
* @returns Encoded private key
|
|
97
116
|
*/
|
|
98
117
|
secretKey() {
|
|
99
|
-
return
|
|
100
|
-
const key = this._key;
|
|
101
|
-
return (0, utils_1.b58cencode)(key, pref[this.curve].sk);
|
|
102
|
-
});
|
|
118
|
+
return Promise.resolve((0, utils_1.b58Encode)(__classPrivateFieldGet(this, _ECKey_key, "f"), pref[__classPrivateFieldGet(this, _ECKey_curve, "f")].sk));
|
|
103
119
|
}
|
|
104
120
|
}
|
|
105
121
|
exports.ECKey = ECKey;
|
|
106
|
-
|
|
107
|
-
* @description Tz3 key class using the p256 curve
|
|
108
|
-
*/
|
|
109
|
-
exports.Tz3 = ECKey.bind(null, 'p256');
|
|
110
|
-
/**
|
|
111
|
-
* @description Tz2 key class using the secp256k1 curve
|
|
112
|
-
*/
|
|
113
|
-
exports.Tz2 = ECKey.bind(null, 'secp256k1');
|
|
122
|
+
_ECKey_key = new WeakMap(), _ECKey_publicKey = new WeakMap(), _ECKey_curve = new WeakMap();
|
package/dist/lib/ed-key.js
CHANGED
|
@@ -8,17 +8,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
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");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
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");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var _EdKey_secretKey, _EdKey_publicKey;
|
|
11
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
24
|
+
exports.EdKey = void 0;
|
|
13
25
|
const blake2b_1 = require("@stablelib/blake2b");
|
|
14
26
|
const ed25519_1 = require("@stablelib/ed25519");
|
|
15
27
|
const utils_1 = require("@taquito/utils");
|
|
16
|
-
const typedarray_to_buffer_1 = require("typedarray-to-buffer");
|
|
17
|
-
const core_1 = require("@taquito/core");
|
|
18
28
|
/**
|
|
19
29
|
* @description Provide signing logic for ed25519 curve based key (tz1)
|
|
20
30
|
*/
|
|
21
|
-
class
|
|
31
|
+
class EdKey {
|
|
22
32
|
/**
|
|
23
33
|
*
|
|
24
34
|
* @param key Encoded private key
|
|
@@ -26,77 +36,68 @@ class Tz1 {
|
|
|
26
36
|
* @param decrypt Decrypt function
|
|
27
37
|
* @throws {@link InvalidKeyError}
|
|
28
38
|
*/
|
|
29
|
-
constructor(key,
|
|
30
|
-
this
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
constructor(key, decrypt) {
|
|
40
|
+
_EdKey_secretKey.set(this, void 0);
|
|
41
|
+
_EdKey_publicKey.set(this, void 0);
|
|
42
|
+
const tmp = (0, utils_1.b58DecodeAndCheckPrefix)(key, [
|
|
43
|
+
utils_1.PrefixV2.Ed25519SecretKey,
|
|
44
|
+
utils_1.PrefixV2.Ed25519EncryptedSeed,
|
|
45
|
+
utils_1.PrefixV2.Ed25519Seed,
|
|
46
|
+
]);
|
|
47
|
+
let [keyData] = tmp;
|
|
48
|
+
const [, prefix] = tmp;
|
|
49
|
+
if (prefix === utils_1.PrefixV2.Ed25519SecretKey) {
|
|
50
|
+
__classPrivateFieldSet(this, _EdKey_secretKey, keyData, "f");
|
|
51
|
+
__classPrivateFieldSet(this, _EdKey_publicKey, keyData.slice(32), "f");
|
|
34
52
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
if (this._key.length !== 64) {
|
|
45
|
-
const { publicKey, secretKey } = (0, ed25519_1.generateKeyPairFromSeed)(new Uint8Array(this._key));
|
|
46
|
-
this._publicKey = publicKey;
|
|
47
|
-
this._key = secretKey;
|
|
53
|
+
else {
|
|
54
|
+
if (prefix === utils_1.PrefixV2.Ed25519EncryptedSeed) {
|
|
55
|
+
if (decrypt !== undefined) {
|
|
56
|
+
keyData = decrypt(keyData);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error('decryption function is not provided');
|
|
60
|
+
}
|
|
48
61
|
}
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
const { publicKey, secretKey } = (0, ed25519_1.generateKeyPairFromSeed)(keyData);
|
|
63
|
+
__classPrivateFieldSet(this, _EdKey_publicKey, publicKey, "f");
|
|
64
|
+
__classPrivateFieldSet(this, _EdKey_secretKey, secretKey, "f");
|
|
65
|
+
}
|
|
51
66
|
}
|
|
52
67
|
/**
|
|
53
68
|
*
|
|
54
69
|
* @param bytes Bytes to sign
|
|
55
70
|
* @param bytesHash Blake2b hash of the bytes to sign
|
|
56
71
|
*/
|
|
57
|
-
sign(bytes
|
|
72
|
+
sign(bytes) {
|
|
58
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
|
|
60
|
-
const signature = (0, ed25519_1.sign)(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
prefixSig: (0, utils_1.b58cencode)(signature, utils_1.prefix.edsig),
|
|
67
|
-
sbytes,
|
|
68
|
-
};
|
|
74
|
+
const hash = (0, blake2b_1.hash)(bytes, 32);
|
|
75
|
+
const signature = (0, ed25519_1.sign)(__classPrivateFieldGet(this, _EdKey_secretKey, "f"), hash);
|
|
76
|
+
return Promise.resolve({
|
|
77
|
+
rawSignature: signature,
|
|
78
|
+
sig: (0, utils_1.b58Encode)(signature, utils_1.PrefixV2.GenericSignature),
|
|
79
|
+
prefixSig: (0, utils_1.b58Encode)(signature, utils_1.PrefixV2.Ed25519Signature),
|
|
80
|
+
});
|
|
69
81
|
});
|
|
70
82
|
}
|
|
71
83
|
/**
|
|
72
84
|
* @returns Encoded public key
|
|
73
85
|
*/
|
|
74
86
|
publicKey() {
|
|
75
|
-
return
|
|
76
|
-
yield this.isInit;
|
|
77
|
-
return (0, utils_1.b58cencode)(this._publicKey, utils_1.prefix['edpk']);
|
|
78
|
-
});
|
|
87
|
+
return Promise.resolve((0, utils_1.b58Encode)(__classPrivateFieldGet(this, _EdKey_publicKey, "f"), utils_1.PrefixV2.Ed25519PublicKey));
|
|
79
88
|
}
|
|
80
89
|
/**
|
|
81
90
|
* @returns Encoded public key hash
|
|
82
91
|
*/
|
|
83
92
|
publicKeyHash() {
|
|
84
|
-
return
|
|
85
|
-
yield this.isInit;
|
|
86
|
-
return (0, utils_1.b58cencode)((0, blake2b_1.hash)(new Uint8Array(this._publicKey), 20), utils_1.prefix.tz1);
|
|
87
|
-
});
|
|
93
|
+
return Promise.resolve((0, utils_1.b58Encode)((0, blake2b_1.hash)(__classPrivateFieldGet(this, _EdKey_publicKey, "f"), 20), utils_1.PrefixV2.Ed25519PublicKeyHash));
|
|
88
94
|
}
|
|
89
95
|
/**
|
|
90
96
|
* @returns Encoded private key
|
|
91
97
|
*/
|
|
92
98
|
secretKey() {
|
|
93
|
-
return
|
|
94
|
-
yield this.isInit;
|
|
95
|
-
let key = this._key;
|
|
96
|
-
const { secretKey } = (0, ed25519_1.generateKeyPairFromSeed)(new Uint8Array(key).slice(0, 32));
|
|
97
|
-
key = (0, typedarray_to_buffer_1.default)(secretKey);
|
|
98
|
-
return (0, utils_1.b58cencode)(key, utils_1.prefix[`edsk`]);
|
|
99
|
-
});
|
|
99
|
+
return Promise.resolve((0, utils_1.b58Encode)(__classPrivateFieldGet(this, _EdKey_secretKey, "f"), utils_1.PrefixV2.Ed25519SecretKey));
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
exports.
|
|
102
|
+
exports.EdKey = EdKey;
|
|
103
|
+
_EdKey_secretKey = new WeakMap(), _EdKey_publicKey = new WeakMap();
|
package/dist/lib/helpers.js
CHANGED
|
@@ -21,16 +21,16 @@ const generateSecretKey = (seed, derivationPath, curve) => {
|
|
|
21
21
|
switch (curve) {
|
|
22
22
|
case 'ed25519': {
|
|
23
23
|
node = ed25519_1.PrivateKey.fromSeed(seed).derivePath(path);
|
|
24
|
-
const sk = (0, utils_1.
|
|
24
|
+
const sk = (0, utils_1.b58Encode)(node.seed().slice(0, 32), utils_1.PrefixV2.Ed25519Seed);
|
|
25
25
|
return sk;
|
|
26
26
|
}
|
|
27
27
|
case 'secp256k1':
|
|
28
28
|
case 'p256': {
|
|
29
|
-
const prefixType = curve === 'secp256k1' ? utils_1.
|
|
29
|
+
const prefixType = curve === 'secp256k1' ? utils_1.PrefixV2.Secp256k1SecretKey : utils_1.PrefixV2.P256SecretKey;
|
|
30
30
|
let privKey = ecdsa_1.PrivateKey.fromSeed(seed, curve);
|
|
31
31
|
privKey = privKey.derivePath(path);
|
|
32
32
|
const uint8arr = new Uint8Array(privKey.keyPair.getPrivate().toArray());
|
|
33
|
-
const sk = (0, utils_1.
|
|
33
|
+
const sk = (0, utils_1.b58Encode)(uint8arr, prefixType);
|
|
34
34
|
return sk;
|
|
35
35
|
}
|
|
36
36
|
case 'bip25519': {
|
|
@@ -22,6 +22,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
22
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
26
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
27
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
28
|
+
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");
|
|
29
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
30
|
+
};
|
|
31
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
32
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
33
|
+
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");
|
|
34
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
35
|
+
};
|
|
36
|
+
var _InMemorySigner_key;
|
|
25
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
38
|
exports.InMemorySigner = exports.InvalidPassphraseError = exports.VERSION = void 0;
|
|
27
39
|
/**
|
|
@@ -29,7 +41,6 @@ exports.InMemorySigner = exports.InvalidPassphraseError = exports.VERSION = void
|
|
|
29
41
|
* @module @taquito/signer
|
|
30
42
|
*/
|
|
31
43
|
const nacl_1 = require("@stablelib/nacl");
|
|
32
|
-
const blake2b_1 = require("@stablelib/blake2b");
|
|
33
44
|
const utils_1 = require("@taquito/utils");
|
|
34
45
|
const typedarray_to_buffer_1 = require("typedarray-to-buffer");
|
|
35
46
|
const ed_key_1 = require("./ed-key");
|
|
@@ -39,6 +50,8 @@ const Bip39 = require("bip39");
|
|
|
39
50
|
const helpers_1 = require("./helpers");
|
|
40
51
|
const errors_1 = require("./errors");
|
|
41
52
|
const core_1 = require("@taquito/core");
|
|
53
|
+
const key_interface_1 = require("./key-interface");
|
|
54
|
+
const bls_key_1 = require("./bls-key");
|
|
42
55
|
__exportStar(require("./import-key"), exports);
|
|
43
56
|
var version_1 = require("./version");
|
|
44
57
|
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
|
|
@@ -58,7 +71,7 @@ class InMemorySigner {
|
|
|
58
71
|
throw new errors_1.InvalidMnemonicError(mnemonic);
|
|
59
72
|
}
|
|
60
73
|
const seed = Bip39.mnemonicToSeedSync(mnemonic, `${email}${password}`);
|
|
61
|
-
const key = (0, utils_1.
|
|
74
|
+
const key = (0, utils_1.b58Encode)(seed.subarray(0, 32), utils_1.PrefixV2.Ed25519Seed);
|
|
62
75
|
return new InMemorySigner(key);
|
|
63
76
|
}
|
|
64
77
|
static fromSecretKey(key, passphrase) {
|
|
@@ -94,34 +107,63 @@ class InMemorySigner {
|
|
|
94
107
|
*
|
|
95
108
|
*/
|
|
96
109
|
constructor(key, passphrase) {
|
|
97
|
-
|
|
98
|
-
|
|
110
|
+
_InMemorySigner_key.set(this, void 0);
|
|
111
|
+
const keyPrefixes = [
|
|
112
|
+
utils_1.PrefixV2.Ed25519EncryptedSeed,
|
|
113
|
+
utils_1.PrefixV2.Ed25519Seed,
|
|
114
|
+
utils_1.PrefixV2.Ed25519SecretKey,
|
|
115
|
+
utils_1.PrefixV2.Secp256k1EncryptedSecretKey,
|
|
116
|
+
utils_1.PrefixV2.Secp256k1SecretKey,
|
|
117
|
+
utils_1.PrefixV2.P256EncryptedSecretKey,
|
|
118
|
+
utils_1.PrefixV2.P256SecretKey,
|
|
119
|
+
utils_1.PrefixV2.BLS12_381EncryptedSecretKey,
|
|
120
|
+
utils_1.PrefixV2.BLS12_381SecretKey,
|
|
121
|
+
];
|
|
122
|
+
const pre = (() => {
|
|
123
|
+
try {
|
|
124
|
+
const [, pre] = (0, utils_1.b58DecodeAndCheckPrefix)(key, keyPrefixes);
|
|
125
|
+
return pre;
|
|
126
|
+
}
|
|
127
|
+
catch (_a) {
|
|
128
|
+
throw new core_1.InvalidKeyError(`Invalid private key, expecting one of the following prefixes '${keyPrefixes}'.`);
|
|
129
|
+
}
|
|
130
|
+
})();
|
|
131
|
+
const encrypted = pre === utils_1.PrefixV2.Ed25519EncryptedSeed ||
|
|
132
|
+
pre === utils_1.PrefixV2.Secp256k1EncryptedSecretKey ||
|
|
133
|
+
pre === utils_1.PrefixV2.P256EncryptedSecretKey ||
|
|
134
|
+
pre === utils_1.PrefixV2.BLS12_381EncryptedSecretKey;
|
|
135
|
+
let decrypt;
|
|
99
136
|
if (encrypted) {
|
|
100
137
|
if (!passphrase) {
|
|
101
138
|
throw new errors_1.InvalidPassphraseError('No passphrase provided to decrypt encrypted key');
|
|
102
139
|
}
|
|
103
|
-
decrypt = (
|
|
104
|
-
const salt = (0, typedarray_to_buffer_1.default)(
|
|
105
|
-
const encryptedSk =
|
|
140
|
+
decrypt = (data) => {
|
|
141
|
+
const salt = (0, typedarray_to_buffer_1.default)(data.slice(0, 8));
|
|
142
|
+
const encryptedSk = data.slice(8);
|
|
106
143
|
const encryptionKey = pbkdf2_1.default.pbkdf2Sync(passphrase, salt, 32768, 32, 'sha512');
|
|
107
|
-
|
|
144
|
+
const res = (0, nacl_1.openSecretBox)(new Uint8Array(encryptionKey), new Uint8Array(24), new Uint8Array(encryptedSk));
|
|
145
|
+
if (!res) {
|
|
146
|
+
throw new Error("can't decrypt secret key");
|
|
147
|
+
}
|
|
148
|
+
return res;
|
|
108
149
|
};
|
|
109
150
|
}
|
|
110
|
-
switch (
|
|
111
|
-
case
|
|
112
|
-
case
|
|
113
|
-
|
|
151
|
+
switch (pre) {
|
|
152
|
+
case utils_1.PrefixV2.Ed25519EncryptedSeed:
|
|
153
|
+
case utils_1.PrefixV2.Ed25519Seed:
|
|
154
|
+
case utils_1.PrefixV2.Ed25519SecretKey:
|
|
155
|
+
__classPrivateFieldSet(this, _InMemorySigner_key, new ed_key_1.EdKey(key, decrypt), "f");
|
|
114
156
|
break;
|
|
115
|
-
case
|
|
116
|
-
case
|
|
117
|
-
|
|
157
|
+
case utils_1.PrefixV2.Secp256k1EncryptedSecretKey:
|
|
158
|
+
case utils_1.PrefixV2.Secp256k1SecretKey:
|
|
159
|
+
case utils_1.PrefixV2.P256EncryptedSecretKey:
|
|
160
|
+
case utils_1.PrefixV2.P256SecretKey:
|
|
161
|
+
__classPrivateFieldSet(this, _InMemorySigner_key, new ec_key_1.ECKey(key, decrypt), "f");
|
|
118
162
|
break;
|
|
119
|
-
case
|
|
120
|
-
case
|
|
121
|
-
this
|
|
163
|
+
case utils_1.PrefixV2.BLS12_381EncryptedSecretKey:
|
|
164
|
+
case utils_1.PrefixV2.BLS12_381SecretKey:
|
|
165
|
+
__classPrivateFieldSet(this, _InMemorySigner_key, new bls_key_1.BLSKey(key, decrypt), "f");
|
|
122
166
|
break;
|
|
123
|
-
default:
|
|
124
|
-
throw new core_1.InvalidKeyError(`${(0, utils_1.invalidDetail)(utils_1.ValidationResult.NO_PREFIX_MATCHED)} expecting one of the following '${utils_1.Prefix.EDESK}', '${utils_1.Prefix.EDSK}', '${utils_1.Prefix.SPSK}', '${utils_1.Prefix.SPESK}', '${utils_1.Prefix.P2SK}' or '${utils_1.Prefix.P2ESK}'.`);
|
|
125
167
|
}
|
|
126
168
|
}
|
|
127
169
|
/**
|
|
@@ -129,39 +171,52 @@ class InMemorySigner {
|
|
|
129
171
|
* @param bytes Bytes to sign
|
|
130
172
|
* @param watermark Watermark to append to the bytes
|
|
131
173
|
*/
|
|
132
|
-
sign(
|
|
174
|
+
sign(message, watermark) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const msg = typeof message == 'string' ? (0, utils_1.hex2buf)(message) : message;
|
|
177
|
+
const watermarkMsg = watermark !== undefined ? (0, utils_1.mergebuf)(watermark, msg) : msg;
|
|
178
|
+
const { rawSignature, sig: signature, prefixSig: prefixedSignature, } = yield __classPrivateFieldGet(this, _InMemorySigner_key, "f").sign(watermarkMsg);
|
|
179
|
+
return {
|
|
180
|
+
bytes: (0, utils_1.buf2hex)(msg),
|
|
181
|
+
sig: signature,
|
|
182
|
+
prefixSig: prefixedSignature,
|
|
183
|
+
sbytes: (0, utils_1.buf2hex)((0, utils_1.mergebuf)(msg,
|
|
184
|
+
// 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
|
|
185
|
+
(0, key_interface_1.isPOP)(__classPrivateFieldGet(this, _InMemorySigner_key, "f")) ? (0, utils_1.mergebuf)(new Uint8Array([255, 3]), rawSignature) : rawSignature)),
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
provePossession() {
|
|
133
190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
191
|
+
if ((0, key_interface_1.isPOP)(__classPrivateFieldGet(this, _InMemorySigner_key, "f"))) {
|
|
192
|
+
return __classPrivateFieldGet(this, _InMemorySigner_key, "f").provePossession();
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
throw new core_1.ProhibitedActionError('Only BLS keys can prove possession');
|
|
137
196
|
}
|
|
138
|
-
const bytesHash = (0, blake2b_1.hash)(bb, 32);
|
|
139
|
-
return this._key.sign(bytes, bytesHash);
|
|
140
197
|
});
|
|
141
198
|
}
|
|
199
|
+
get canProvePossession() {
|
|
200
|
+
return (0, key_interface_1.isPOP)(__classPrivateFieldGet(this, _InMemorySigner_key, "f"));
|
|
201
|
+
}
|
|
142
202
|
/**
|
|
143
203
|
* @returns Encoded public key
|
|
144
204
|
*/
|
|
145
205
|
publicKey() {
|
|
146
|
-
return
|
|
147
|
-
return this._key.publicKey();
|
|
148
|
-
});
|
|
206
|
+
return __classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKey();
|
|
149
207
|
}
|
|
150
208
|
/**
|
|
151
209
|
* @returns Encoded public key hash
|
|
152
210
|
*/
|
|
153
211
|
publicKeyHash() {
|
|
154
|
-
return
|
|
155
|
-
return this._key.publicKeyHash();
|
|
156
|
-
});
|
|
212
|
+
return __classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKeyHash();
|
|
157
213
|
}
|
|
158
214
|
/**
|
|
159
215
|
* @returns Encoded private key
|
|
160
216
|
*/
|
|
161
217
|
secretKey() {
|
|
162
|
-
return
|
|
163
|
-
return this._key.secretKey();
|
|
164
|
-
});
|
|
218
|
+
return __classPrivateFieldGet(this, _InMemorySigner_key, "f").secretKey();
|
|
165
219
|
}
|
|
166
220
|
}
|
|
167
221
|
exports.InMemorySigner = InMemorySigner;
|
|
222
|
+
_InMemorySigner_key = new WeakMap();
|