@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.
- package/dist/lib/bls-key.js +43 -12
- package/dist/lib/ec-key.js +117 -60
- package/dist/lib/ed-key.js +55 -36
- package/dist/lib/taquito-signer.js +22 -3
- package/dist/lib/version.js +2 -2
- package/dist/taquito-signer.es6.js +296 -155
- package/dist/taquito-signer.es6.js.map +1 -1
- package/dist/taquito-signer.umd.js +297 -156
- package/dist/taquito-signer.umd.js.map +1 -1
- package/dist/types/bls-key.d.ts +15 -7
- package/dist/types/ec-key.d.ts +24 -11
- package/dist/types/ed-key.d.ts +14 -9
- package/dist/types/key-interface.d.ts +12 -7
- package/dist/types/taquito-signer.d.ts +4 -1
- package/package.json +5 -5
package/dist/lib/bls-key.js
CHANGED
|
@@ -10,9 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _BLSKey_key, _BLSKey_publicKey;
|
|
13
|
+
var _BLSKey_key, _BLSKey_publicKey, _BLSPublicKey_key;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.BLSKey = void 0;
|
|
15
|
+
exports.BLSPublicKey = exports.BLSKey = void 0;
|
|
16
16
|
const utils_1 = require("@taquito/utils");
|
|
17
17
|
const bls12_381_1 = require("@noble/curves/bls12-381");
|
|
18
18
|
const blake2b_1 = require("@stablelib/blake2b");
|
|
@@ -44,11 +44,11 @@ class BLSKey {
|
|
|
44
44
|
signDst(message, dst) {
|
|
45
45
|
const point = bls.hash(message, dst);
|
|
46
46
|
const sig = bls.sign(point, this.sk()).toBytes();
|
|
47
|
-
return
|
|
47
|
+
return {
|
|
48
48
|
rawSignature: sig,
|
|
49
49
|
sig: (0, utils_1.b58Encode)(sig, utils_1.PrefixV2.GenericSignature),
|
|
50
50
|
prefixSig: (0, utils_1.b58Encode)(sig, utils_1.PrefixV2.BLS12_381Signature),
|
|
51
|
-
}
|
|
51
|
+
};
|
|
52
52
|
}
|
|
53
53
|
sign(message) {
|
|
54
54
|
return this.signDst(message, utils_1.BLS12_381_DST);
|
|
@@ -57,17 +57,48 @@ class BLSKey {
|
|
|
57
57
|
return this.signDst(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"), utils_1.POP_DST);
|
|
58
58
|
}
|
|
59
59
|
publicKey() {
|
|
60
|
-
|
|
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);
|
|
60
|
+
return new BLSPublicKey(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"));
|
|
66
61
|
}
|
|
67
62
|
secretKey() {
|
|
68
|
-
|
|
69
|
-
return Promise.resolve(res);
|
|
63
|
+
return (0, utils_1.b58Encode)(__classPrivateFieldGet(this, _BLSKey_key, "f"), utils_1.PrefixV2.BLS12_381SecretKey);
|
|
70
64
|
}
|
|
71
65
|
}
|
|
72
66
|
exports.BLSKey = BLSKey;
|
|
73
67
|
_BLSKey_key = new WeakMap(), _BLSKey_publicKey = new WeakMap();
|
|
68
|
+
class BLSPublicKey {
|
|
69
|
+
constructor(src) {
|
|
70
|
+
_BLSPublicKey_key.set(this, void 0);
|
|
71
|
+
if (typeof src === 'string') {
|
|
72
|
+
const [key, _] = (0, utils_1.b58DecodeAndCheckPrefix)(src, [utils_1.PrefixV2.BLS12_381PublicKey]);
|
|
73
|
+
__classPrivateFieldSet(this, _BLSPublicKey_key, key, "f");
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
__classPrivateFieldSet(this, _BLSPublicKey_key, src, "f");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
compare(other) {
|
|
80
|
+
if (other instanceof BLSPublicKey) {
|
|
81
|
+
return (0, utils_1.compareArrays)(this.bytes(), other.bytes());
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new utils_1.InvalidPublicKeyError('BLS key expected');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
hash() {
|
|
88
|
+
return (0, utils_1.b58Encode)((0, blake2b_1.hash)(__classPrivateFieldGet(this, _BLSPublicKey_key, "f"), 20), utils_1.PrefixV2.BLS12_381PublicKeyHash);
|
|
89
|
+
}
|
|
90
|
+
bytes() {
|
|
91
|
+
return __classPrivateFieldGet(this, _BLSPublicKey_key, "f");
|
|
92
|
+
}
|
|
93
|
+
toProtocol() {
|
|
94
|
+
const res = new Uint8Array(__classPrivateFieldGet(this, _BLSPublicKey_key, "f").length + 1);
|
|
95
|
+
res[0] = 3;
|
|
96
|
+
res.set(__classPrivateFieldGet(this, _BLSPublicKey_key, "f"), 1);
|
|
97
|
+
return res;
|
|
98
|
+
}
|
|
99
|
+
toString() {
|
|
100
|
+
return (0, utils_1.b58Encode)(__classPrivateFieldGet(this, _BLSPublicKey_key, "f"), utils_1.PrefixV2.BLS12_381PublicKey);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.BLSPublicKey = BLSPublicKey;
|
|
104
|
+
_BLSPublicKey_key = new WeakMap();
|
package/dist/lib/ec-key.js
CHANGED
|
@@ -1,39 +1,48 @@
|
|
|
1
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 _ECKey_key, _ECKey_publicKey, _ECKey_curve;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ECKey = void 0;
|
|
3
|
+
exports.ECPublicKey = exports.ECKey = void 0;
|
|
16
4
|
const blake2b_1 = require("@stablelib/blake2b");
|
|
17
5
|
const utils_1 = require("@taquito/utils");
|
|
18
6
|
const elliptic_1 = require("elliptic");
|
|
7
|
+
const key_1 = require("elliptic/lib/elliptic/ec/key");
|
|
8
|
+
const errors_1 = require("./errors");
|
|
19
9
|
const pref = {
|
|
20
10
|
p256: {
|
|
21
11
|
pk: utils_1.PrefixV2.P256PublicKey,
|
|
22
12
|
sk: utils_1.PrefixV2.P256SecretKey,
|
|
23
13
|
pkh: utils_1.PrefixV2.P256PublicKeyHash,
|
|
24
14
|
sig: utils_1.PrefixV2.P256Signature,
|
|
15
|
+
tag: 2,
|
|
25
16
|
},
|
|
26
17
|
secp256k1: {
|
|
27
18
|
pk: utils_1.PrefixV2.Secp256k1PublicKey,
|
|
28
19
|
sk: utils_1.PrefixV2.Secp256k1SecretKey,
|
|
29
20
|
pkh: utils_1.PrefixV2.Secp256k1PublicKeyHash,
|
|
30
21
|
sig: utils_1.PrefixV2.Secp256k1Signature,
|
|
22
|
+
tag: 1,
|
|
31
23
|
},
|
|
32
24
|
};
|
|
25
|
+
class ECKeyBase {
|
|
26
|
+
constructor(keyPair) {
|
|
27
|
+
this.keyPair = keyPair;
|
|
28
|
+
}
|
|
29
|
+
curve() {
|
|
30
|
+
switch (this.keyPair.ec.curve) {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
case elliptic_1.default.curves.secp256k1.curve:
|
|
33
|
+
return 'secp256k1';
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
case elliptic_1.default.curves.p256.curve:
|
|
36
|
+
return 'p256';
|
|
37
|
+
default:
|
|
38
|
+
throw new errors_1.InvalidCurveError('unknown curve');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
33
42
|
/**
|
|
34
43
|
* @description Provide signing logic for elliptic curve based key (tz2, tz3)
|
|
35
44
|
*/
|
|
36
|
-
class ECKey {
|
|
45
|
+
class ECKey extends ECKeyBase {
|
|
37
46
|
/**
|
|
38
47
|
*
|
|
39
48
|
* @param key Encoded private key
|
|
@@ -41,43 +50,32 @@ class ECKey {
|
|
|
41
50
|
* @throws {@link InvalidKeyError}
|
|
42
51
|
*/
|
|
43
52
|
constructor(key, decrypt) {
|
|
44
|
-
|
|
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, [
|
|
53
|
+
const [keyData, prefix] = (0, utils_1.b58DecodeAndCheckPrefix)(key, [
|
|
49
54
|
utils_1.PrefixV2.Secp256k1EncryptedSecretKey,
|
|
50
55
|
utils_1.PrefixV2.P256EncryptedSecretKey,
|
|
51
56
|
utils_1.PrefixV2.Secp256k1SecretKey,
|
|
52
57
|
utils_1.PrefixV2.P256SecretKey,
|
|
53
58
|
]);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
break;
|
|
75
|
-
default:
|
|
76
|
-
__classPrivateFieldSet(this, _ECKey_curve, 'p256', "f");
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
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
|
+
const [decKey, curve] = (() => {
|
|
60
|
+
switch (prefix) {
|
|
61
|
+
case utils_1.PrefixV2.Secp256k1EncryptedSecretKey:
|
|
62
|
+
case utils_1.PrefixV2.P256EncryptedSecretKey:
|
|
63
|
+
if (decrypt === undefined) {
|
|
64
|
+
throw new Error('decryption function is not provided');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return [
|
|
68
|
+
decrypt(keyData),
|
|
69
|
+
prefix === utils_1.PrefixV2.Secp256k1EncryptedSecretKey ? 'secp256k1' : 'p256',
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
case utils_1.PrefixV2.Secp256k1SecretKey:
|
|
73
|
+
return [keyData, 'secp256k1'];
|
|
74
|
+
default:
|
|
75
|
+
return [keyData, 'p256'];
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
super(new elliptic_1.default.ec(curve).keyFromPrivate(decKey));
|
|
81
79
|
}
|
|
82
80
|
/**
|
|
83
81
|
*
|
|
@@ -86,37 +84,96 @@ class ECKey {
|
|
|
86
84
|
*/
|
|
87
85
|
sign(bytes) {
|
|
88
86
|
const hash = (0, blake2b_1.hash)(bytes, 32);
|
|
89
|
-
const
|
|
90
|
-
const sig = key.sign(hash, { canonical: true });
|
|
87
|
+
const sig = this.keyPair.sign(hash, { canonical: true });
|
|
91
88
|
const signature = new Uint8Array(64);
|
|
92
89
|
const r = sig.r.toArray();
|
|
93
90
|
const s = sig.s.toArray();
|
|
94
91
|
signature.set(r, 32 - r.length);
|
|
95
92
|
signature.set(s, 64 - s.length);
|
|
96
|
-
return
|
|
93
|
+
return {
|
|
97
94
|
rawSignature: signature,
|
|
98
95
|
sig: (0, utils_1.b58Encode)(signature, utils_1.PrefixV2.GenericSignature),
|
|
99
|
-
prefixSig: (0, utils_1.b58Encode)(signature, pref[
|
|
100
|
-
}
|
|
96
|
+
prefixSig: (0, utils_1.b58Encode)(signature, pref[this.curve()].sig),
|
|
97
|
+
};
|
|
101
98
|
}
|
|
102
99
|
/**
|
|
103
100
|
* @returns Encoded public key
|
|
104
101
|
*/
|
|
105
102
|
publicKey() {
|
|
106
|
-
return
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* @returns Encoded public key hash
|
|
110
|
-
*/
|
|
111
|
-
publicKeyHash() {
|
|
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));
|
|
103
|
+
return new ECPublicKey(this.keyPair.ec.keyFromPublic(this.keyPair));
|
|
113
104
|
}
|
|
114
105
|
/**
|
|
115
106
|
* @returns Encoded private key
|
|
116
107
|
*/
|
|
117
108
|
secretKey() {
|
|
118
|
-
return
|
|
109
|
+
return (0, utils_1.b58Encode)(new Uint8Array(this.keyPair.getPrivate().toArray()), pref[this.curve()].sk);
|
|
119
110
|
}
|
|
120
111
|
}
|
|
121
112
|
exports.ECKey = ECKey;
|
|
122
|
-
|
|
113
|
+
function isKeyPair(src) {
|
|
114
|
+
return src instanceof key_1.default;
|
|
115
|
+
}
|
|
116
|
+
class ECPublicKey extends ECKeyBase {
|
|
117
|
+
constructor(src, curve) {
|
|
118
|
+
const key = (() => {
|
|
119
|
+
if (isKeyPair(src)) {
|
|
120
|
+
return src;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const [key, crv] = (() => {
|
|
124
|
+
if (typeof src === 'string') {
|
|
125
|
+
const [key, pre] = (0, utils_1.b58DecodeAndCheckPrefix)(src, [
|
|
126
|
+
utils_1.PrefixV2.Secp256k1PublicKey,
|
|
127
|
+
utils_1.PrefixV2.P256PublicKey,
|
|
128
|
+
]);
|
|
129
|
+
return [key, pre === utils_1.PrefixV2.Secp256k1PublicKey ? 'secp256k1' : 'p256'];
|
|
130
|
+
}
|
|
131
|
+
else if (curve !== undefined) {
|
|
132
|
+
return [src, curve];
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
throw new errors_1.InvalidCurveError('missing curve type');
|
|
136
|
+
}
|
|
137
|
+
})();
|
|
138
|
+
return new elliptic_1.default.ec(crv).keyFromPublic(key);
|
|
139
|
+
}
|
|
140
|
+
})();
|
|
141
|
+
super(key);
|
|
142
|
+
}
|
|
143
|
+
compare(other) {
|
|
144
|
+
if (other instanceof ECPublicKey) {
|
|
145
|
+
if (this.curve() === other.curve()) {
|
|
146
|
+
const compress = this.curve() === 'secp256k1';
|
|
147
|
+
return (0, utils_1.compareArrays)(this.bytes(compress), other.bytes(compress));
|
|
148
|
+
}
|
|
149
|
+
else if (this.curve() === 'secp256k1') {
|
|
150
|
+
return -1;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
throw new utils_1.InvalidPublicKeyError('ECDSA key expected');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
hash() {
|
|
161
|
+
const key = this.bytes();
|
|
162
|
+
return (0, utils_1.b58Encode)((0, blake2b_1.hash)(key, 20), pref[this.curve()].pkh);
|
|
163
|
+
}
|
|
164
|
+
bytes(compress = true) {
|
|
165
|
+
return new Uint8Array(this.keyPair.getPublic(compress, 'array'));
|
|
166
|
+
}
|
|
167
|
+
toProtocol() {
|
|
168
|
+
const key = this.bytes();
|
|
169
|
+
const res = new Uint8Array(key.length + 1);
|
|
170
|
+
res[0] = pref[this.curve()].tag;
|
|
171
|
+
res.set(key, 1);
|
|
172
|
+
return res;
|
|
173
|
+
}
|
|
174
|
+
toString() {
|
|
175
|
+
const key = this.bytes();
|
|
176
|
+
return (0, utils_1.b58Encode)(key, pref[this.curve()].pk);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.ECPublicKey = ECPublicKey;
|
package/dist/lib/ed-key.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -19,9 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
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");
|
|
20
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
12
|
};
|
|
22
|
-
var
|
|
13
|
+
var _EdKey_keyPair, _EdPublicKey_key;
|
|
23
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.EdKey = void 0;
|
|
15
|
+
exports.EdPublicKey = exports.EdKey = void 0;
|
|
25
16
|
const blake2b_1 = require("@stablelib/blake2b");
|
|
26
17
|
const ed25519_1 = require("@stablelib/ed25519");
|
|
27
18
|
const utils_1 = require("@taquito/utils");
|
|
@@ -37,8 +28,7 @@ class EdKey {
|
|
|
37
28
|
* @throws {@link InvalidKeyError}
|
|
38
29
|
*/
|
|
39
30
|
constructor(key, decrypt) {
|
|
40
|
-
|
|
41
|
-
_EdKey_publicKey.set(this, void 0);
|
|
31
|
+
_EdKey_keyPair.set(this, void 0);
|
|
42
32
|
const tmp = (0, utils_1.b58DecodeAndCheckPrefix)(key, [
|
|
43
33
|
utils_1.PrefixV2.Ed25519SecretKey,
|
|
44
34
|
utils_1.PrefixV2.Ed25519EncryptedSeed,
|
|
@@ -47,8 +37,10 @@ class EdKey {
|
|
|
47
37
|
let [keyData] = tmp;
|
|
48
38
|
const [, prefix] = tmp;
|
|
49
39
|
if (prefix === utils_1.PrefixV2.Ed25519SecretKey) {
|
|
50
|
-
__classPrivateFieldSet(this,
|
|
51
|
-
|
|
40
|
+
__classPrivateFieldSet(this, _EdKey_keyPair, {
|
|
41
|
+
secretKey: keyData,
|
|
42
|
+
publicKey: keyData.slice(32),
|
|
43
|
+
}, "f");
|
|
52
44
|
}
|
|
53
45
|
else {
|
|
54
46
|
if (prefix === utils_1.PrefixV2.Ed25519EncryptedSeed) {
|
|
@@ -59,9 +51,7 @@ class EdKey {
|
|
|
59
51
|
throw new Error('decryption function is not provided');
|
|
60
52
|
}
|
|
61
53
|
}
|
|
62
|
-
|
|
63
|
-
__classPrivateFieldSet(this, _EdKey_publicKey, publicKey, "f");
|
|
64
|
-
__classPrivateFieldSet(this, _EdKey_secretKey, secretKey, "f");
|
|
54
|
+
__classPrivateFieldSet(this, _EdKey_keyPair, (0, ed25519_1.generateKeyPairFromSeed)(keyData), "f");
|
|
65
55
|
}
|
|
66
56
|
}
|
|
67
57
|
/**
|
|
@@ -70,34 +60,63 @@ class EdKey {
|
|
|
70
60
|
* @param bytesHash Blake2b hash of the bytes to sign
|
|
71
61
|
*/
|
|
72
62
|
sign(bytes) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
});
|
|
63
|
+
const hash = (0, blake2b_1.hash)(bytes, 32);
|
|
64
|
+
const signature = (0, ed25519_1.sign)(__classPrivateFieldGet(this, _EdKey_keyPair, "f").secretKey, hash);
|
|
65
|
+
return {
|
|
66
|
+
rawSignature: signature,
|
|
67
|
+
sig: (0, utils_1.b58Encode)(signature, utils_1.PrefixV2.GenericSignature),
|
|
68
|
+
prefixSig: (0, utils_1.b58Encode)(signature, utils_1.PrefixV2.Ed25519Signature),
|
|
69
|
+
};
|
|
82
70
|
}
|
|
83
71
|
/**
|
|
84
72
|
* @returns Encoded public key
|
|
85
73
|
*/
|
|
86
74
|
publicKey() {
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* @returns Encoded public key hash
|
|
91
|
-
*/
|
|
92
|
-
publicKeyHash() {
|
|
93
|
-
return Promise.resolve((0, utils_1.b58Encode)((0, blake2b_1.hash)(__classPrivateFieldGet(this, _EdKey_publicKey, "f"), 20), utils_1.PrefixV2.Ed25519PublicKeyHash));
|
|
75
|
+
return new EdPublicKey(__classPrivateFieldGet(this, _EdKey_keyPair, "f").publicKey);
|
|
94
76
|
}
|
|
95
77
|
/**
|
|
96
78
|
* @returns Encoded private key
|
|
97
79
|
*/
|
|
98
80
|
secretKey() {
|
|
99
|
-
return
|
|
81
|
+
return (0, utils_1.b58Encode)(__classPrivateFieldGet(this, _EdKey_keyPair, "f").secretKey, utils_1.PrefixV2.Ed25519SecretKey);
|
|
100
82
|
}
|
|
101
83
|
}
|
|
102
84
|
exports.EdKey = EdKey;
|
|
103
|
-
|
|
85
|
+
_EdKey_keyPair = new WeakMap();
|
|
86
|
+
class EdPublicKey {
|
|
87
|
+
constructor(src) {
|
|
88
|
+
_EdPublicKey_key.set(this, void 0);
|
|
89
|
+
if (typeof src === 'string') {
|
|
90
|
+
const [key, _] = (0, utils_1.b58DecodeAndCheckPrefix)(src, [utils_1.PrefixV2.Ed25519PublicKey]);
|
|
91
|
+
__classPrivateFieldSet(this, _EdPublicKey_key, key, "f");
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
__classPrivateFieldSet(this, _EdPublicKey_key, src, "f");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
compare(other) {
|
|
98
|
+
if (other instanceof EdPublicKey) {
|
|
99
|
+
return (0, utils_1.compareArrays)(this.bytes(), other.bytes());
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw new utils_1.InvalidPublicKeyError('EdDSA key expected');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
hash() {
|
|
106
|
+
return (0, utils_1.b58Encode)((0, blake2b_1.hash)(__classPrivateFieldGet(this, _EdPublicKey_key, "f"), 20), utils_1.PrefixV2.Ed25519PublicKeyHash);
|
|
107
|
+
}
|
|
108
|
+
bytes() {
|
|
109
|
+
return __classPrivateFieldGet(this, _EdPublicKey_key, "f");
|
|
110
|
+
}
|
|
111
|
+
toProtocol() {
|
|
112
|
+
const res = new Uint8Array(__classPrivateFieldGet(this, _EdPublicKey_key, "f").length + 1);
|
|
113
|
+
res[0] = 0;
|
|
114
|
+
res.set(__classPrivateFieldGet(this, _EdPublicKey_key, "f"), 1);
|
|
115
|
+
return res;
|
|
116
|
+
}
|
|
117
|
+
toString() {
|
|
118
|
+
return (0, utils_1.b58Encode)(__classPrivateFieldGet(this, _EdPublicKey_key, "f"), utils_1.PrefixV2.Ed25519PublicKey);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.EdPublicKey = EdPublicKey;
|
|
122
|
+
_EdPublicKey_key = new WeakMap();
|
|
@@ -36,6 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
36
36
|
var _InMemorySigner_key;
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.InMemorySigner = exports.InvalidPassphraseError = exports.VERSION = void 0;
|
|
39
|
+
exports.publicKeyFromString = publicKeyFromString;
|
|
39
40
|
/**
|
|
40
41
|
* @packageDocumentation
|
|
41
42
|
* @module @taquito/signer
|
|
@@ -203,20 +204,38 @@ class InMemorySigner {
|
|
|
203
204
|
* @returns Encoded public key
|
|
204
205
|
*/
|
|
205
206
|
publicKey() {
|
|
206
|
-
return __classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKey();
|
|
207
|
+
return Promise.resolve(String(__classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKey()));
|
|
207
208
|
}
|
|
208
209
|
/**
|
|
209
210
|
* @returns Encoded public key hash
|
|
210
211
|
*/
|
|
211
212
|
publicKeyHash() {
|
|
212
|
-
return __classPrivateFieldGet(this, _InMemorySigner_key, "f").
|
|
213
|
+
return Promise.resolve(__classPrivateFieldGet(this, _InMemorySigner_key, "f").publicKey().hash());
|
|
213
214
|
}
|
|
214
215
|
/**
|
|
215
216
|
* @returns Encoded private key
|
|
216
217
|
*/
|
|
217
218
|
secretKey() {
|
|
218
|
-
return __classPrivateFieldGet(this, _InMemorySigner_key, "f").secretKey();
|
|
219
|
+
return Promise.resolve(__classPrivateFieldGet(this, _InMemorySigner_key, "f").secretKey());
|
|
219
220
|
}
|
|
220
221
|
}
|
|
221
222
|
exports.InMemorySigner = InMemorySigner;
|
|
222
223
|
_InMemorySigner_key = new WeakMap();
|
|
224
|
+
function publicKeyFromString(src) {
|
|
225
|
+
const [keyData, pre] = (0, utils_1.b58DecodeAndCheckPrefix)(src, [
|
|
226
|
+
utils_1.PrefixV2.Ed25519PublicKey,
|
|
227
|
+
utils_1.PrefixV2.Secp256k1PublicKey,
|
|
228
|
+
utils_1.PrefixV2.P256PublicKey,
|
|
229
|
+
utils_1.PrefixV2.BLS12_381PublicKey,
|
|
230
|
+
]);
|
|
231
|
+
switch (pre) {
|
|
232
|
+
case utils_1.PrefixV2.Ed25519PublicKey:
|
|
233
|
+
return new ed_key_1.EdPublicKey(keyData);
|
|
234
|
+
case utils_1.PrefixV2.Secp256k1PublicKey:
|
|
235
|
+
return new ec_key_1.ECPublicKey(keyData, 'secp256k1');
|
|
236
|
+
case utils_1.PrefixV2.P256PublicKey:
|
|
237
|
+
return new ec_key_1.ECPublicKey(keyData, 'p256');
|
|
238
|
+
case utils_1.PrefixV2.BLS12_381PublicKey:
|
|
239
|
+
return new bls_key_1.BLSPublicKey(keyData);
|
|
240
|
+
}
|
|
241
|
+
}
|
package/dist/lib/version.js
CHANGED
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
5
5
|
exports.VERSION = {
|
|
6
|
-
"commitHash": "
|
|
7
|
-
"version": "23.0.0
|
|
6
|
+
"commitHash": "9065acc1b41ec205a49e64b54ef89f50bafa6210",
|
|
7
|
+
"version": "23.0.0"
|
|
8
8
|
};
|