@taquito/signer 25.1.0-rc0 → 25.2.0-beta0
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/README.md +42 -0
- package/dist/lib/bls-key.js +17 -4
- package/dist/lib/derivation-tools/ecdsa.js +12 -9
- package/dist/lib/derivation-tools/ed25519.js +2 -2
- package/dist/lib/derivation-tools/index.js +24 -2
- package/dist/lib/ec-key.js +10 -12
- package/dist/lib/ed-key.js +3 -3
- package/dist/lib/in-memory-signer.js +40 -13
- package/dist/lib/mnemonic.js +112 -0
- package/dist/lib/taquito-signer.js +10 -1
- package/dist/lib/version.js +2 -2
- package/dist/taquito-signer.es6.js +702 -611
- package/dist/taquito-signer.es6.js.map +1 -1
- package/dist/taquito-signer.umd.js +833 -736
- package/dist/taquito-signer.umd.js.map +1 -1
- package/dist/types/bls-key.d.ts +1 -1
- package/dist/types/in-memory-signer.d.ts +4 -9
- package/dist/types/key-interface.d.ts +2 -2
- package/dist/types/mnemonic.d.ts +39 -0
- package/dist/types/taquito-signer.d.ts +5 -1
- package/package.json +13 -17
- package/dist/types/node_modules/@scure/base/index.d.ts +0 -555
package/README.md
CHANGED
|
@@ -64,6 +64,48 @@ Sending operations requires a protocol with `tz5_account_enable` enabled. This
|
|
|
64
64
|
support is validated against an isolated Octez 25.2 Ushuaia sandbox, and does not
|
|
65
65
|
imply activation on mainnet. See the [local conformance suite](../../integration-tests/tz5/README.md).
|
|
66
66
|
|
|
67
|
+
### Mnemonics and account previews
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import {
|
|
71
|
+
generateMnemonic,
|
|
72
|
+
mnemonicToEntropy,
|
|
73
|
+
entropyToMnemonic,
|
|
74
|
+
deriveKeyFromMnemonic,
|
|
75
|
+
} from '@taquito/signer';
|
|
76
|
+
|
|
77
|
+
const mnemonic = generateMnemonic();
|
|
78
|
+
const entropy = mnemonicToEntropy(mnemonic);
|
|
79
|
+
const restored = entropyToMnemonic(entropy);
|
|
80
|
+
const account = deriveKeyFromMnemonic({
|
|
81
|
+
mnemonic: restored,
|
|
82
|
+
derivationPath: "44'/1729'/0'/0'",
|
|
83
|
+
curve: 'ed25519',
|
|
84
|
+
});
|
|
85
|
+
const address = account.publicKeyHash;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The helpers use the English BIP39 wordlist. generateMnemonic defaults to 128 bits
|
|
89
|
+
and accepts 128, 160, 192, 224 or 256. mnemonicToEntropy returns Uint8Array.
|
|
90
|
+
entropyToMnemonic accepts 16, 20, 24, 28 or 32 bytes, or an unprefixed, even-length
|
|
91
|
+
hexadecimal string. Invalid phrases throw InvalidMnemonicError without including
|
|
92
|
+
the phrase in the error.
|
|
93
|
+
|
|
94
|
+
Byte input must be a Uint8Array, such as a Node.js Buffer or a subarray view.
|
|
95
|
+
The helper uses only the bytes in that view and leaves the input unchanged.
|
|
96
|
+
Plain number arrays and other typed-array kinds are not accepted.
|
|
97
|
+
|
|
98
|
+
deriveKeyFromMnemonic is synchronous and constructs no InMemorySigner. It returns
|
|
99
|
+
publicKey, publicKeyHash and secretKey. The secret key is unencrypted, so avoid
|
|
100
|
+
logging or sharing the result. Ed25519 returns the expanded secret-key form used
|
|
101
|
+
by InMemorySigner.secretKey().
|
|
102
|
+
|
|
103
|
+
Options match InMemorySigner.fromMnemonic. password is the optional BIP39
|
|
104
|
+
passphrase and defaults to an empty string. The default path is 44'/1729'/0'/0'
|
|
105
|
+
and the default curve is ed25519. Supported mnemonic curves are ed25519,
|
|
106
|
+
secp256k1 and p256. Ed25519 paths must be hardened. BLS and ML-DSA mnemonic
|
|
107
|
+
derivation are not supported.
|
|
108
|
+
|
|
67
109
|
## Additional info
|
|
68
110
|
|
|
69
111
|
See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing and versioning.
|
package/dist/lib/bls-key.js
CHANGED
|
@@ -14,9 +14,9 @@ var _BLSKey_key, _BLSKey_publicKey, _BLSPublicKey_key;
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.BLSPublicKey = exports.BLSKey = void 0;
|
|
16
16
|
const utils_1 = require("@taquito/utils");
|
|
17
|
-
const
|
|
17
|
+
const bls12_381_js_1 = require("@noble/curves/bls12-381.js");
|
|
18
18
|
const blake2_js_1 = require("@noble/hashes/blake2.js");
|
|
19
|
-
const bls =
|
|
19
|
+
const bls = bls12_381_js_1.bls12_381.longSignatures; // AKA MinPK
|
|
20
20
|
class BLSKey {
|
|
21
21
|
constructor(key, decrypt) {
|
|
22
22
|
_BLSKey_key.set(this, void 0);
|
|
@@ -53,8 +53,21 @@ class BLSKey {
|
|
|
53
53
|
sign(message) {
|
|
54
54
|
return this.signDst(message, utils_1.BLS12_381_DST);
|
|
55
55
|
}
|
|
56
|
-
provePossession() {
|
|
57
|
-
|
|
56
|
+
provePossession(overridePublicKey) {
|
|
57
|
+
let message = __classPrivateFieldGet(this, _BLSKey_publicKey, "f");
|
|
58
|
+
if (overridePublicKey !== undefined) {
|
|
59
|
+
try {
|
|
60
|
+
if (typeof overridePublicKey !== 'string')
|
|
61
|
+
throw new Error('Expected a public key');
|
|
62
|
+
message = (0, utils_1.b58DecodeAndCheckPrefix)(overridePublicKey, [utils_1.PrefixV2.BLS12_381PublicKey], true);
|
|
63
|
+
// Match Octez's compressed G1 parser, including subgroup checks and its accepted infinity encoding.
|
|
64
|
+
bls12_381_js_1.bls12_381.G1.Point.fromBytes(message).assertValidity();
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
throw new utils_1.InvalidPublicKeyError('BLS override public key', 'Expecting a valid BLS public key');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return this.signDst(message, utils_1.POP_DST);
|
|
58
71
|
}
|
|
59
72
|
publicKey() {
|
|
60
73
|
return new BLSPublicKey(__classPrivateFieldGet(this, _BLSKey_publicKey, "f"));
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.PrivateKey = void 0;
|
|
4
7
|
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
5
|
-
const
|
|
6
|
-
const
|
|
8
|
+
const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
|
|
9
|
+
const nist_js_1 = require("@noble/curves/nist.js");
|
|
7
10
|
const types_1 = require("./types");
|
|
8
11
|
const hmac_js_1 = require("@noble/hashes/hmac.js");
|
|
9
12
|
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
10
|
-
const bn_js_1 = require("bn.js");
|
|
13
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
11
14
|
const utils_1 = require("./utils");
|
|
12
15
|
const errors_1 = require("../errors");
|
|
13
16
|
const core_1 = require("@taquito/core");
|
|
@@ -31,8 +34,8 @@ class PrivateKey {
|
|
|
31
34
|
const privateKeyBytes = priv.secretKey.toArray('be', 32);
|
|
32
35
|
const privateKeyUint8 = new Uint8Array(privateKeyBytes);
|
|
33
36
|
const publicKey = priv.curve === 'secp256k1'
|
|
34
|
-
?
|
|
35
|
-
:
|
|
37
|
+
? secp256k1_js_1.secp256k1.getPublicKey(privateKeyUint8, true) // compressed public key
|
|
38
|
+
: nist_js_1.p256.getPublicKey(privateKeyUint8, true); // compressed public key
|
|
36
39
|
this.keyPair = {
|
|
37
40
|
curve: priv.curve,
|
|
38
41
|
secretKey: priv.secretKey,
|
|
@@ -56,10 +59,10 @@ class PrivateKey {
|
|
|
56
59
|
// Get curve order for validation
|
|
57
60
|
let curveOrder;
|
|
58
61
|
if (curve === 'secp256k1') {
|
|
59
|
-
curveOrder = new bn_js_1.default(
|
|
62
|
+
curveOrder = new bn_js_1.default(secp256k1_js_1.secp256k1.Point.CURVE().n.toString());
|
|
60
63
|
}
|
|
61
64
|
else {
|
|
62
|
-
curveOrder = new bn_js_1.default(
|
|
65
|
+
curveOrder = new bn_js_1.default(nist_js_1.p256.Point.CURVE().n.toString());
|
|
63
66
|
}
|
|
64
67
|
if (curveOrder.bitLength() !== 256) {
|
|
65
68
|
throw new errors_1.InvalidBitSize(`Invalid curve "${curve}" with bit size "${curveOrder.bitLength()}" expecting bit size "256"`);
|
|
@@ -106,10 +109,10 @@ class PrivateKey {
|
|
|
106
109
|
// Get curve order for comparison
|
|
107
110
|
let curveOrder;
|
|
108
111
|
if (this.keyPair.curve === 'secp256k1') {
|
|
109
|
-
curveOrder = new bn_js_1.default(
|
|
112
|
+
curveOrder = new bn_js_1.default(secp256k1_js_1.secp256k1.Point.CURVE().n.toString());
|
|
110
113
|
}
|
|
111
114
|
else {
|
|
112
|
-
curveOrder = new bn_js_1.default(
|
|
115
|
+
curveOrder = new bn_js_1.default(nist_js_1.p256.Point.CURVE().n.toString());
|
|
113
116
|
}
|
|
114
117
|
if (d.cmp(curveOrder) < 0) {
|
|
115
118
|
d = d.add(this.keyPair.secretKey).mod(curveOrder);
|
|
@@ -4,13 +4,13 @@ exports.PrivateKey = void 0;
|
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
5
5
|
const hmac_js_1 = require("@noble/hashes/hmac.js");
|
|
6
6
|
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
7
|
-
const
|
|
7
|
+
const ed25519_js_1 = require("@noble/curves/ed25519.js");
|
|
8
8
|
const types_1 = require("./types");
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
10
|
const errors_1 = require("../errors");
|
|
11
11
|
const core_1 = require("@taquito/core");
|
|
12
12
|
function generateKeyPairFromSeed(seed) {
|
|
13
|
-
const publicKey =
|
|
13
|
+
const publicKey = ed25519_js_1.ed25519.getPublicKey(seed);
|
|
14
14
|
const secretKey = new Uint8Array(64);
|
|
15
15
|
secretKey.set(seed);
|
|
16
16
|
secretKey.set(publicKey, 32);
|
|
@@ -10,6 +10,28 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
13
35
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
37
|
};
|
|
@@ -17,8 +39,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
39
|
exports.Path = exports.Ed25519 = exports.ECDSA = void 0;
|
|
18
40
|
const core_1 = require("@taquito/core");
|
|
19
41
|
const types_1 = require("./types");
|
|
20
|
-
exports.ECDSA = require("./ecdsa");
|
|
21
|
-
exports.Ed25519 = require("./ed25519");
|
|
42
|
+
exports.ECDSA = __importStar(require("./ecdsa"));
|
|
43
|
+
exports.Ed25519 = __importStar(require("./ed25519"));
|
|
22
44
|
__exportStar(require("./types"), exports);
|
|
23
45
|
class Path extends Array {
|
|
24
46
|
static from(iterable) {
|
package/dist/lib/ec-key.js
CHANGED
|
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.ECPublicKey = exports.ECKey = void 0;
|
|
16
16
|
const blake2_js_1 = require("@noble/hashes/blake2.js");
|
|
17
17
|
const utils_1 = require("@taquito/utils");
|
|
18
|
-
const
|
|
18
|
+
const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
|
|
19
19
|
const nist_js_1 = require("@noble/curves/nist.js");
|
|
20
20
|
const errors_1 = require("./errors");
|
|
21
21
|
const pref = {
|
|
@@ -75,7 +75,7 @@ class ECKey {
|
|
|
75
75
|
curve,
|
|
76
76
|
secretKey: decKey,
|
|
77
77
|
publicKey: curve === 'secp256k1'
|
|
78
|
-
?
|
|
78
|
+
? secp256k1_js_1.secp256k1.getPublicKey(decKey, true)
|
|
79
79
|
: nist_js_1.p256.getPublicKey(decKey, true),
|
|
80
80
|
}, "f");
|
|
81
81
|
}
|
|
@@ -88,18 +88,16 @@ class ECKey {
|
|
|
88
88
|
const hash = (0, blake2_js_1.blake2b)(bytes, { dkLen: 32 });
|
|
89
89
|
let signature;
|
|
90
90
|
if (__classPrivateFieldGet(this, _ECKey_keyPair, "f").curve === 'secp256k1') {
|
|
91
|
-
signature =
|
|
92
|
-
.sign(hash, __classPrivateFieldGet(this, _ECKey_keyPair, "f").secretKey, {
|
|
91
|
+
signature = secp256k1_js_1.secp256k1.sign(hash, __classPrivateFieldGet(this, _ECKey_keyPair, "f").secretKey, {
|
|
93
92
|
lowS: true, // Use canonical signatures (prevents malleability)
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
prehash: false,
|
|
94
|
+
});
|
|
96
95
|
}
|
|
97
96
|
else {
|
|
98
|
-
signature = nist_js_1.p256
|
|
99
|
-
.sign(hash, __classPrivateFieldGet(this, _ECKey_keyPair, "f").secretKey, {
|
|
97
|
+
signature = nist_js_1.p256.sign(hash, __classPrivateFieldGet(this, _ECKey_keyPair, "f").secretKey, {
|
|
100
98
|
lowS: true, // Use canonical signatures (prevents malleability)
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
prehash: false,
|
|
100
|
+
});
|
|
103
101
|
}
|
|
104
102
|
return {
|
|
105
103
|
rawSignature: signature,
|
|
@@ -171,12 +169,12 @@ class ECPublicKey {
|
|
|
171
169
|
// We need to convert the stored public key to the requested format
|
|
172
170
|
if (this.curve === 'secp256k1') {
|
|
173
171
|
// For secp256k1, we need to get the public key from the stored bytes and convert format
|
|
174
|
-
const point =
|
|
172
|
+
const point = secp256k1_js_1.secp256k1.Point.fromBytes(__classPrivateFieldGet(this, _ECPublicKey_key, "f"));
|
|
175
173
|
return point.toBytes(compress);
|
|
176
174
|
}
|
|
177
175
|
else {
|
|
178
176
|
// For p256, we need to get the public key from the stored bytes and convert format
|
|
179
|
-
const point = nist_js_1.p256.Point.
|
|
177
|
+
const point = nist_js_1.p256.Point.fromBytes(__classPrivateFieldGet(this, _ECPublicKey_key, "f"));
|
|
180
178
|
return point.toBytes(compress);
|
|
181
179
|
}
|
|
182
180
|
}
|
package/dist/lib/ed-key.js
CHANGED
|
@@ -14,10 +14,10 @@ var _EdKey_keyPair, _EdPublicKey_key;
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.EdPublicKey = exports.EdKey = void 0;
|
|
16
16
|
const blake2_js_1 = require("@noble/hashes/blake2.js");
|
|
17
|
-
const
|
|
17
|
+
const ed25519_js_1 = require("@noble/curves/ed25519.js");
|
|
18
18
|
const utils_1 = require("@taquito/utils");
|
|
19
19
|
function generateKeyPairFromSeed(seed) {
|
|
20
|
-
const publicKey =
|
|
20
|
+
const publicKey = ed25519_js_1.ed25519.getPublicKey(seed);
|
|
21
21
|
const secretKey = new Uint8Array(64);
|
|
22
22
|
secretKey.set(seed);
|
|
23
23
|
secretKey.set(publicKey, 32);
|
|
@@ -69,7 +69,7 @@ class EdKey {
|
|
|
69
69
|
sign(bytes) {
|
|
70
70
|
const hash = (0, blake2_js_1.blake2b)(bytes, { dkLen: 32 });
|
|
71
71
|
const seed = __classPrivateFieldGet(this, _EdKey_keyPair, "f").secretKey.subarray(0, 32);
|
|
72
|
-
const signature =
|
|
72
|
+
const signature = ed25519_js_1.ed25519.sign(hash, seed);
|
|
73
73
|
return {
|
|
74
74
|
rawSignature: signature,
|
|
75
75
|
sig: (0, utils_1.b58Encode)(signature, utils_1.PrefixV2.GenericSignature),
|
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
36
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
37
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -18,10 +51,10 @@ const nacl_1 = require("@stablelib/nacl");
|
|
|
18
51
|
const utils_1 = require("@taquito/utils");
|
|
19
52
|
const ed_key_1 = require("./ed-key");
|
|
20
53
|
const ec_key_1 = require("./ec-key");
|
|
21
|
-
const bip39 = require("@scure/bip39");
|
|
54
|
+
const bip39 = __importStar(require("@scure/bip39"));
|
|
22
55
|
const english_js_1 = require("@scure/bip39/wordlists/english.js");
|
|
23
56
|
const pbkdf2_js_1 = require("@noble/hashes/pbkdf2.js");
|
|
24
|
-
const
|
|
57
|
+
const mnemonic_1 = require("./mnemonic");
|
|
25
58
|
const errors_1 = require("./errors");
|
|
26
59
|
const core_1 = require("@taquito/core");
|
|
27
60
|
const key_interface_1 = require("./key-interface");
|
|
@@ -52,15 +85,9 @@ class InMemorySigner {
|
|
|
52
85
|
* @returns InMemorySigner
|
|
53
86
|
* @throws InvalidMnemonicError
|
|
54
87
|
*/
|
|
55
|
-
static fromMnemonic(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// avoiding exposing mnemonic again in case of mistake making invalid
|
|
59
|
-
throw new errors_1.InvalidMnemonicError();
|
|
60
|
-
}
|
|
61
|
-
const seed = bip39.mnemonicToSeedSync(mnemonic, password);
|
|
62
|
-
const sk = (0, helpers_1.generateSecretKey)(seed, derivationPath, curve);
|
|
63
|
-
return new InMemorySigner(sk);
|
|
88
|
+
static fromMnemonic(params) {
|
|
89
|
+
const { secretKey } = (0, mnemonic_1.deriveMnemonicSecretKey)(params);
|
|
90
|
+
return new InMemorySigner(secretKey);
|
|
64
91
|
}
|
|
65
92
|
/**
|
|
66
93
|
*
|
|
@@ -164,9 +191,9 @@ class InMemorySigner {
|
|
|
164
191
|
sbytes: (0, utils_1.buf2hex)((0, utils_1.mergebuf)(msg, signatureBytes)),
|
|
165
192
|
};
|
|
166
193
|
}
|
|
167
|
-
async provePossession() {
|
|
194
|
+
async provePossession(overridePublicKey) {
|
|
168
195
|
if ((0, key_interface_1.isPOP)(__classPrivateFieldGet(this, _InMemorySigner_key, "f"))) {
|
|
169
|
-
return __classPrivateFieldGet(this, _InMemorySigner_key, "f").provePossession();
|
|
196
|
+
return __classPrivateFieldGet(this, _InMemorySigner_key, "f").provePossession(overridePublicKey);
|
|
170
197
|
}
|
|
171
198
|
else {
|
|
172
199
|
throw new core_1.ProhibitedActionError('Only BLS keys can prove possession');
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.mnemonicToEntropy = mnemonicToEntropy;
|
|
37
|
+
exports.entropyToMnemonic = entropyToMnemonic;
|
|
38
|
+
exports.generateMnemonic = generateMnemonic;
|
|
39
|
+
exports.deriveMnemonicSecretKey = deriveMnemonicSecretKey;
|
|
40
|
+
exports.deriveKeyFromMnemonic = deriveKeyFromMnemonic;
|
|
41
|
+
const bip39 = __importStar(require("@scure/bip39"));
|
|
42
|
+
const english_js_1 = require("@scure/bip39/wordlists/english.js");
|
|
43
|
+
const errors_1 = require("./errors");
|
|
44
|
+
const helpers_1 = require("./helpers");
|
|
45
|
+
const ed_key_1 = require("./ed-key");
|
|
46
|
+
const ec_key_1 = require("./ec-key");
|
|
47
|
+
/**
|
|
48
|
+
* Converts an English BIP39 mnemonic to entropy bytes.
|
|
49
|
+
* @throws InvalidMnemonicError for an invalid phrase, without including its text.
|
|
50
|
+
*/
|
|
51
|
+
function mnemonicToEntropy(mnemonic) {
|
|
52
|
+
try {
|
|
53
|
+
return bip39.mnemonicToEntropy(mnemonic, english_js_1.wordlist);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new errors_1.InvalidMnemonicError();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Converts 16, 20, 24, 28 or 32 entropy bytes to an English BIP39 mnemonic.
|
|
61
|
+
* Strings must contain unprefixed, even-length hexadecimal. Leading zeros matter.
|
|
62
|
+
*/
|
|
63
|
+
function entropyToMnemonic(entropy) {
|
|
64
|
+
let bytes;
|
|
65
|
+
if (typeof entropy === 'string') {
|
|
66
|
+
if (!/^(?:[0-9a-fA-F]{2})+$/.test(entropy)) {
|
|
67
|
+
throw new Error('Entropy must be unprefixed, even-length hexadecimal');
|
|
68
|
+
}
|
|
69
|
+
bytes = Uint8Array.from({ length: entropy.length / 2 }, (_, index) => parseInt(entropy.slice(index * 2, index * 2 + 2), 16));
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (!(entropy instanceof Uint8Array) &&
|
|
73
|
+
!(ArrayBuffer.isView(entropy) &&
|
|
74
|
+
Object.prototype.toString.call(entropy) === '[object Uint8Array]')) {
|
|
75
|
+
throw new TypeError('Entropy must be a Uint8Array');
|
|
76
|
+
}
|
|
77
|
+
bytes = new Uint8Array(entropy);
|
|
78
|
+
}
|
|
79
|
+
return bip39.entropyToMnemonic(bytes, english_js_1.wordlist);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Generates an English BIP39 mnemonic with the dependency's secure random source.
|
|
83
|
+
* @param strength Entropy bits, 128, 160, 192, 224 or 256. Defaults to 128.
|
|
84
|
+
*/
|
|
85
|
+
function generateMnemonic(strength = 128) {
|
|
86
|
+
return bip39.generateMnemonic(english_js_1.wordlist, strength);
|
|
87
|
+
}
|
|
88
|
+
// Shared with the signer, but not exported from the package entrypoint.
|
|
89
|
+
function deriveMnemonicSecretKey({ mnemonic, password = '', derivationPath = "44'/1729'/0'/0'", curve = 'ed25519', }) {
|
|
90
|
+
if (!bip39.validateMnemonic(mnemonic, english_js_1.wordlist)) {
|
|
91
|
+
throw new errors_1.InvalidMnemonicError();
|
|
92
|
+
}
|
|
93
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic, password);
|
|
94
|
+
return { secretKey: (0, helpers_1.generateSecretKey)(seed, derivationPath, curve), curve };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Derives key material without constructing an InMemorySigner.
|
|
98
|
+
* Uses the same defaults, English BIP39 phrases, password and paths as fromMnemonic.
|
|
99
|
+
* Supports Ed25519, secp256k1 and P-256 mnemonic derivation.
|
|
100
|
+
* The returned secretKey is unencrypted and matches InMemorySigner.secretKey(),
|
|
101
|
+
* including the expanded Ed25519 form. Avoid logging or sharing the result.
|
|
102
|
+
*/
|
|
103
|
+
function deriveKeyFromMnemonic(params) {
|
|
104
|
+
const { secretKey, curve } = deriveMnemonicSecretKey(params);
|
|
105
|
+
const key = curve === 'ed25519' ? new ed_key_1.EdKey(secretKey) : new ec_key_1.ECKey(secretKey);
|
|
106
|
+
const publicKey = key.publicKey();
|
|
107
|
+
return {
|
|
108
|
+
publicKey: String(publicKey),
|
|
109
|
+
publicKeyHash: publicKey.hash(),
|
|
110
|
+
secretKey: key.secretKey(),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.InvalidPassphraseError = exports.VERSION = void 0;
|
|
17
|
+
exports.deriveKeyFromMnemonic = exports.generateMnemonic = exports.entropyToMnemonic = exports.mnemonicToEntropy = exports.InvalidMnemonicError = exports.InvalidPassphraseError = exports.VERSION = void 0;
|
|
18
18
|
/**
|
|
19
19
|
* @packageDocumentation
|
|
20
20
|
* @module @taquito/signer
|
|
@@ -26,3 +26,12 @@ __exportStar(require("./derivation-tools"), exports);
|
|
|
26
26
|
__exportStar(require("./helpers"), exports);
|
|
27
27
|
var errors_1 = require("./errors");
|
|
28
28
|
Object.defineProperty(exports, "InvalidPassphraseError", { enumerable: true, get: function () { return errors_1.InvalidPassphraseError; } });
|
|
29
|
+
Object.defineProperty(exports, "InvalidMnemonicError", { enumerable: true, get: function () { return errors_1.InvalidMnemonicError; } });
|
|
30
|
+
var mnemonic_1 = require("./mnemonic");
|
|
31
|
+
Object.defineProperty(exports, "mnemonicToEntropy", { enumerable: true, get: function () { return mnemonic_1.mnemonicToEntropy; } });
|
|
32
|
+
var mnemonic_2 = require("./mnemonic");
|
|
33
|
+
Object.defineProperty(exports, "entropyToMnemonic", { enumerable: true, get: function () { return mnemonic_2.entropyToMnemonic; } });
|
|
34
|
+
var mnemonic_3 = require("./mnemonic");
|
|
35
|
+
Object.defineProperty(exports, "generateMnemonic", { enumerable: true, get: function () { return mnemonic_3.generateMnemonic; } });
|
|
36
|
+
var mnemonic_4 = require("./mnemonic");
|
|
37
|
+
Object.defineProperty(exports, "deriveKeyFromMnemonic", { enumerable: true, get: function () { return mnemonic_4.deriveKeyFromMnemonic; } });
|
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!
|
|
5
5
|
exports.VERSION = {
|
|
6
|
-
"commitHash": "
|
|
7
|
-
"version": "25.
|
|
6
|
+
"commitHash": "78ca0b9cb430f230c3230cd28b7e89a310e84c15",
|
|
7
|
+
"version": "25.2.0-beta0"
|
|
8
8
|
};
|