@talismn/crypto 0.3.5 → 1.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/LICENSE +253 -674
- package/dist/index.d.mts +113 -56
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +113 -56
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +847 -786
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +748 -709
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,816 +1,877 @@
|
|
|
1
|
-
"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
9
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
getSafeHash: () => getSafeHash,
|
|
66
|
-
hex: () => import_base4.hex,
|
|
67
|
-
isAddressEqual: () => isAddressEqual,
|
|
68
|
-
isAddressValid: () => isAddressValid,
|
|
69
|
-
isBase58CheckAddress: () => isBase58CheckAddress,
|
|
70
|
-
isBech32Address: () => isBech32Address,
|
|
71
|
-
isBech32mAddress: () => isBech32mAddress,
|
|
72
|
-
isBitcoinAddress: () => isBitcoinAddress,
|
|
73
|
-
isEthereumAddress: () => isEthereumAddress,
|
|
74
|
-
isSolanaAddress: () => isSolanaAddress,
|
|
75
|
-
isSs58Address: () => isSs58Address,
|
|
76
|
-
isValidDerivationPath: () => isValidDerivationPath,
|
|
77
|
-
isValidMnemonic: () => isValidMnemonic,
|
|
78
|
-
mnemonicToEntropy: () => mnemonicToEntropy,
|
|
79
|
-
normalizeAddress: () => normalizeAddress,
|
|
80
|
-
parseSecretKey: () => parseSecretKey,
|
|
81
|
-
pbkdf2: () => pbkdf2,
|
|
82
|
-
removeHexPrefix: () => removeHexPrefix,
|
|
83
|
-
utf8: () => import_base4.utf8
|
|
84
|
-
});
|
|
85
|
-
module.exports = __toCommonJS(index_exports);
|
|
86
|
-
|
|
87
|
-
// src/address/encoding/addressEncodingFromCurve.ts
|
|
88
|
-
var addressEncodingFromCurve = (curve) => {
|
|
89
|
-
switch (curve) {
|
|
90
|
-
case "sr25519":
|
|
91
|
-
case "ed25519":
|
|
92
|
-
case "ecdsa":
|
|
93
|
-
return "ss58";
|
|
94
|
-
case "bitcoin-ecdsa":
|
|
95
|
-
case "bitcoin-ed25519":
|
|
96
|
-
return "bech32m";
|
|
97
|
-
case "ethereum":
|
|
98
|
-
return "ethereum";
|
|
99
|
-
case "solana":
|
|
100
|
-
return "base58solana";
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// src/address/encoding/bitcoin.ts
|
|
105
|
-
var import_bech32 = require("bech32");
|
|
106
|
-
var import_bs58check = __toESM(require("bs58check"));
|
|
107
|
-
var isBitcoinAddress = (address) => isBech32mAddress(address) || isBech32Address(address) || isBase58CheckAddress(address);
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let bech32 = require("bech32");
|
|
25
|
+
let bs58check = require("bs58check");
|
|
26
|
+
bs58check = __toESM(bs58check);
|
|
27
|
+
let _noble_curves_secp256k1_js = require("@noble/curves/secp256k1.js");
|
|
28
|
+
let _noble_hashes_sha3_js = require("@noble/hashes/sha3.js");
|
|
29
|
+
let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
|
|
30
|
+
let _noble_curves_ed25519_js = require("@noble/curves/ed25519.js");
|
|
31
|
+
let _scure_base = require("@scure/base");
|
|
32
|
+
let _noble_hashes_blake2_js = require("@noble/hashes/blake2.js");
|
|
33
|
+
let _noble_hashes_blake3_js = require("@noble/hashes/blake3.js");
|
|
34
|
+
let _noble_hashes_hmac_js = require("@noble/hashes/hmac.js");
|
|
35
|
+
let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
|
|
36
|
+
let _scure_bip39 = require("@scure/bip39");
|
|
37
|
+
let _scure_bip39_wordlists_english_js = require("@scure/bip39/wordlists/english.js");
|
|
38
|
+
let scale_ts = require("scale-ts");
|
|
39
|
+
let _scure_bip32 = require("@scure/bip32");
|
|
40
|
+
let _scure_sr25519 = require("@scure/sr25519");
|
|
41
|
+
let _noble_ciphers_chacha_js = require("@noble/ciphers/chacha.js");
|
|
42
|
+
let _noble_ciphers_utils_js = require("@noble/ciphers/utils.js");
|
|
43
|
+
let mlkem = require("mlkem");
|
|
44
|
+
let _noble_ciphers_salsa_js = require("@noble/ciphers/salsa.js");
|
|
45
|
+
let _noble_hashes_scrypt_js = require("@noble/hashes/scrypt.js");
|
|
46
|
+
//#region src/address/encoding/addressEncodingFromCurve.ts
|
|
47
|
+
/** NOTE: Try not to use this too much, it will need to change */
|
|
48
|
+
const addressEncodingFromCurve = (curve) => {
|
|
49
|
+
switch (curve) {
|
|
50
|
+
case "sr25519":
|
|
51
|
+
case "ed25519":
|
|
52
|
+
case "ecdsa": return "ss58";
|
|
53
|
+
case "bitcoin-ecdsa":
|
|
54
|
+
case "bitcoin-ed25519": return "bech32m";
|
|
55
|
+
case "ethereum": return "ethereum";
|
|
56
|
+
case "solana": return "base58solana";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/address/encoding/bitcoin.ts
|
|
61
|
+
const isBitcoinAddress = (address) => isBech32mAddress(address) || isBech32Address(address) || isBase58CheckAddress(address);
|
|
108
62
|
function isBech32mAddress(address) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
63
|
+
try {
|
|
64
|
+
fromBech32m(address);
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
115
69
|
}
|
|
116
70
|
function isBech32Address(address) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
71
|
+
try {
|
|
72
|
+
fromBech32(address);
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
123
77
|
}
|
|
124
78
|
function isBase58CheckAddress(address) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
79
|
+
try {
|
|
80
|
+
fromBase58Check(address);
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
131
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Converts a Bech32m encoded address to its corresponding data representation.
|
|
88
|
+
* @param address - The Bech32m encoded address.
|
|
89
|
+
* @returns An object containing the version, prefix, and data of the address.
|
|
90
|
+
* @throws {TypeError} If the address uses the wrong encoding.
|
|
91
|
+
*/
|
|
132
92
|
function fromBech32m(address) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
93
|
+
const result = bech32.bech32m.decode(address);
|
|
94
|
+
const version = result.words[0];
|
|
95
|
+
if (version === 0) throw new TypeError(`${address} uses wrong encoding`);
|
|
96
|
+
const data = bech32.bech32m.fromWords(result.words.slice(1));
|
|
97
|
+
return {
|
|
98
|
+
version,
|
|
99
|
+
prefix: result.prefix,
|
|
100
|
+
data: Uint8Array.from(data)
|
|
101
|
+
};
|
|
142
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Converts a Bech32 encoded address to its corresponding data representation.
|
|
105
|
+
* @param address - The Bech32 encoded address.
|
|
106
|
+
* @returns An object containing the version, prefix, and data of the address.
|
|
107
|
+
* @throws {TypeError} If the address uses the wrong encoding.
|
|
108
|
+
*/
|
|
143
109
|
function fromBech32(address) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
110
|
+
const result = bech32.bech32.decode(address);
|
|
111
|
+
const version = result.words[0];
|
|
112
|
+
if (version !== 0) throw new TypeError(`${address} uses wrong encoding`);
|
|
113
|
+
const data = bech32.bech32.fromWords(result.words.slice(1));
|
|
114
|
+
return {
|
|
115
|
+
version,
|
|
116
|
+
prefix: result.prefix,
|
|
117
|
+
data: Uint8Array.from(data)
|
|
118
|
+
};
|
|
153
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Decodes a base58check encoded Bitcoin address and returns the version and hash.
|
|
122
|
+
*
|
|
123
|
+
* @param address - The base58check encoded Bitcoin address to decode.
|
|
124
|
+
* @returns An object containing the version and hash of the decoded address.
|
|
125
|
+
* @throws {TypeError} If the address is too short or too long.
|
|
126
|
+
*/
|
|
154
127
|
function fromBase58Check(address) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return { version, hash };
|
|
128
|
+
const payload = bs58check.default.decode(address);
|
|
129
|
+
if (payload.length < 21) throw new TypeError(`${address} is too short`);
|
|
130
|
+
if (payload.length > 21) throw new TypeError(`${address} is too long`);
|
|
131
|
+
function readUInt8(buffer, offset) {
|
|
132
|
+
if (offset + 1 > buffer.length) throw new Error("Offset is outside the bounds of Uint8Array");
|
|
133
|
+
return buffer[offset];
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
version: readUInt8(payload, 0),
|
|
137
|
+
hash: payload.slice(1)
|
|
138
|
+
};
|
|
167
139
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/address/encoding/ethereum.ts
|
|
142
|
+
/**
|
|
143
|
+
* Encodes a public key using H160 encoding with Ethereum checksum.
|
|
144
|
+
* Accepts both uncompressed (65 bytes) and compressed (33 bytes) public keys -
|
|
145
|
+
* polkadot-js keystores store the compressed form as the account address.
|
|
146
|
+
*/
|
|
147
|
+
const encodeAddressEthereum = (publicKey) => {
|
|
148
|
+
if (publicKey.length === 33 && (publicKey[0] === 2 || publicKey[0] === 3)) publicKey = _noble_curves_secp256k1_js.secp256k1.Point.fromBytes(publicKey).toBytes(false);
|
|
149
|
+
if (publicKey[0] !== 4) throw new Error("Invalid public key format");
|
|
150
|
+
const address = (0, _noble_hashes_sha3_js.keccak_256)(publicKey.slice(1)).slice(-20);
|
|
151
|
+
return checksumEthereumAddress(`0x${(0, _noble_hashes_utils_js.bytesToHex)(address)}`);
|
|
152
|
+
};
|
|
153
|
+
const checksumEthereumAddress = (address) => {
|
|
154
|
+
const addr = address.toLowerCase().replace(/^0x/, "");
|
|
155
|
+
const hashHex = (0, _noble_hashes_utils_js.bytesToHex)((0, _noble_hashes_sha3_js.keccak_256)(new TextEncoder().encode(addr)));
|
|
156
|
+
return `0x${addr.split("").map((char, i) => parseInt(hashHex[i], 16) >= 8 ? char.toUpperCase() : char).join("")}`;
|
|
185
157
|
};
|
|
186
158
|
function isEthereumAddress(address) {
|
|
187
|
-
|
|
159
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
188
160
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
throw new Error("Public key must be 32 bytes long for Solana base58 encoding");
|
|
195
|
-
return import_base.base58.encode(publicKey);
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/address/encoding/solana.ts
|
|
163
|
+
const encodeAddressSolana = (publicKey) => {
|
|
164
|
+
if (publicKey.length !== 32) throw new Error("Public key must be 32 bytes long for Solana base58 encoding");
|
|
165
|
+
return _scure_base.base58.encode(publicKey);
|
|
196
166
|
};
|
|
197
167
|
function isSolanaAddress(address) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
168
|
+
try {
|
|
169
|
+
return _scure_base.base58.decode(address).length === 32;
|
|
170
|
+
} catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
204
173
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Whether the address is a valid ed25519 public key (on-curve).
|
|
176
|
+
*
|
|
177
|
+
* Program-derived addresses (PDAs) are off-curve by construction: no private key can exist
|
|
178
|
+
* for them, so a regular wallet cannot recover tokens sent to an account they own.
|
|
179
|
+
*/
|
|
180
|
+
function isOnCurveSolanaAddress(address) {
|
|
181
|
+
try {
|
|
182
|
+
_noble_curves_ed25519_js.ed25519.Point.fromBytes(_scure_base.base58.decode(address));
|
|
183
|
+
return true;
|
|
184
|
+
} catch {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/hashing/index.ts
|
|
190
|
+
const blake3 = _noble_hashes_blake3_js.blake3;
|
|
191
|
+
const blake2b256 = (msg) => (0, _noble_hashes_blake2_js.blake2b)(msg, { dkLen: 32 });
|
|
192
|
+
const blake2b512 = (msg) => (0, _noble_hashes_blake2_js.blake2b)(msg, { dkLen: 64 });
|
|
193
|
+
const getSafeHash = (bytes) => {
|
|
194
|
+
return _scure_base.base58.encode((0, _noble_hashes_blake3_js.blake3)(bytes));
|
|
195
|
+
};
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/address/encoding/ss58.ts
|
|
198
|
+
const VALID_PUBLICKEY_LENGTHS = [32, 33];
|
|
199
|
+
const accountId = (publicKey) => {
|
|
200
|
+
if (!VALID_PUBLICKEY_LENGTHS.includes(publicKey.length)) throw new Error("Invalid publicKey");
|
|
201
|
+
return publicKey.length === 33 ? blake2b256(publicKey) : publicKey;
|
|
202
|
+
};
|
|
203
|
+
const SS58PRE = /* @__PURE__ */ new TextEncoder().encode("SS58PRE");
|
|
204
|
+
const CHECKSUM_LENGTH = 2;
|
|
205
|
+
const VALID_PAYLOAD_LENGTHS = [32, 33];
|
|
206
|
+
const ss58Encode = (payload, prefix = 42) => {
|
|
207
|
+
if (!VALID_PAYLOAD_LENGTHS.includes(payload.length)) throw new Error("Invalid payload");
|
|
208
|
+
const prefixBytes = prefix < 64 ? Uint8Array.of(prefix) : Uint8Array.of((prefix & 252) >> 2 | 64, prefix >> 8 | (prefix & 3) << 6);
|
|
209
|
+
const checksum = blake2b512(Uint8Array.of(...SS58PRE, ...prefixBytes, ...payload)).subarray(0, CHECKSUM_LENGTH);
|
|
210
|
+
return _scure_base.base58.encode(Uint8Array.of(...prefixBytes, ...payload, ...checksum));
|
|
211
|
+
};
|
|
212
|
+
const VALID_ADDRESS_LENGTHS = [
|
|
213
|
+
35,
|
|
214
|
+
36,
|
|
215
|
+
37
|
|
216
|
+
];
|
|
217
|
+
const decodeSs58Address = (addressStr, ignoreChecksum = false) => {
|
|
218
|
+
const address = _scure_base.base58.decode(addressStr);
|
|
219
|
+
if (!VALID_ADDRESS_LENGTHS.includes(address.length)) throw new Error("Invalid address length");
|
|
220
|
+
const addressChecksum = address.subarray(address.length - CHECKSUM_LENGTH);
|
|
221
|
+
const checksum = blake2b512(Uint8Array.of(...SS58PRE, ...address.subarray(0, address.length - CHECKSUM_LENGTH))).subarray(0, CHECKSUM_LENGTH);
|
|
222
|
+
if (!ignoreChecksum && (addressChecksum[0] !== checksum[0] || addressChecksum[1] !== checksum[1])) throw new Error("Invalid checksum");
|
|
223
|
+
const prefixLength = address[0] & 64 ? 2 : 1;
|
|
224
|
+
const prefix = prefixLength === 1 ? address[0] : (address[0] & 63) << 2 | address[1] >> 6 | (address[1] & 63) << 8;
|
|
225
|
+
return [address.slice(prefixLength, address.length - CHECKSUM_LENGTH), prefix];
|
|
226
|
+
};
|
|
227
|
+
const encodeAddressSs58 = (publicKey, prefix = 42) => {
|
|
228
|
+
if (typeof publicKey === "string") [publicKey] = decodeSs58Address(publicKey);
|
|
229
|
+
return ss58Encode(accountId(publicKey), prefix);
|
|
259
230
|
};
|
|
260
231
|
function isSs58Address(address) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
232
|
+
try {
|
|
233
|
+
decodeSs58Address(address);
|
|
234
|
+
return true;
|
|
235
|
+
} catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
267
238
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
);
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
};
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
};
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/address/encoding/detectAddressEncoding.ts
|
|
241
|
+
const CACHE$1 = /* @__PURE__ */ new Map();
|
|
242
|
+
const detectAddressEncodingInner = (address) => {
|
|
243
|
+
if (isEthereumAddress(address)) return "ethereum";
|
|
244
|
+
if (isSs58Address(address)) return "ss58";
|
|
245
|
+
if (isSolanaAddress(address)) return "base58solana";
|
|
246
|
+
if (isBech32mAddress(address)) return "bech32m";
|
|
247
|
+
if (isBech32Address(address)) return "bech32";
|
|
248
|
+
if (isBase58CheckAddress(address)) return "base58check";
|
|
249
|
+
throw new Error(`Unknown address encoding`);
|
|
250
|
+
};
|
|
251
|
+
const detectAddressEncoding = (address) => {
|
|
252
|
+
if (!CACHE$1.has(address)) CACHE$1.set(address, detectAddressEncodingInner(address));
|
|
253
|
+
return CACHE$1.get(address);
|
|
254
|
+
};
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/address/addressFromPublicKey.ts
|
|
257
|
+
const addressFromPublicKey = (publicKey, encoding, options) => {
|
|
258
|
+
switch (encoding) {
|
|
259
|
+
case "ss58": return encodeAddressSs58(publicKey, options?.ss58Prefix);
|
|
260
|
+
case "ethereum": return encodeAddressEthereum(publicKey);
|
|
261
|
+
case "base58solana": return encodeAddressSolana(publicKey);
|
|
262
|
+
case "bech32m":
|
|
263
|
+
case "bech32":
|
|
264
|
+
case "base58check": throw new Error("addressFromPublicKey is not implemented for Bitcoin");
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/address/normalizeAddress.ts
|
|
269
|
+
const CACHE = /* @__PURE__ */ new Map();
|
|
270
|
+
const normalizeAddress = (address) => {
|
|
271
|
+
try {
|
|
272
|
+
if (!CACHE.has(address)) CACHE.set(address, normalizeAnyAddress(address));
|
|
273
|
+
return CACHE.get(address);
|
|
274
|
+
} catch (cause) {
|
|
275
|
+
throw new Error(`Unable to normalize address: ${address}`, { cause });
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
const normalizeAnyAddress = (address) => {
|
|
279
|
+
switch (detectAddressEncoding(address)) {
|
|
280
|
+
case "ethereum": return checksumEthereumAddress(address);
|
|
281
|
+
case "bech32m":
|
|
282
|
+
case "bech32":
|
|
283
|
+
case "base58check":
|
|
284
|
+
case "base58solana": return address;
|
|
285
|
+
case "ss58": {
|
|
286
|
+
const [pk] = decodeSs58Address(address);
|
|
287
|
+
return encodeAddressSs58(pk, 42);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/address/encodeAnyAddress.ts
|
|
293
|
+
const encodeAnyAddress = (address, options) => {
|
|
294
|
+
if (detectAddressEncoding(address) === "ss58" && options?.ss58Format !== void 0) {
|
|
295
|
+
const [publicKey] = decodeSs58Address(address);
|
|
296
|
+
return encodeAddressSs58(publicKey, options?.ss58Format ?? 42);
|
|
297
|
+
}
|
|
298
|
+
return normalizeAddress(address);
|
|
299
|
+
};
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/address/isAddressEqual.ts
|
|
302
|
+
const isAddressEqual = (address1, address2) => {
|
|
303
|
+
try {
|
|
304
|
+
return normalizeAddress(address1) === normalizeAddress(address2);
|
|
305
|
+
} catch {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/address/isAddressValid.ts
|
|
311
|
+
const isAddressValid = (address) => {
|
|
312
|
+
try {
|
|
313
|
+
detectAddressEncoding(address);
|
|
314
|
+
return true;
|
|
315
|
+
} catch {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/derivation/deriveSolana.ts
|
|
321
|
+
const parseDerivationPath = (path) => {
|
|
322
|
+
if (!path.startsWith("m/")) throw new Error("Path must start with 'm/'");
|
|
323
|
+
return path.split("/").slice(1).map((p) => {
|
|
324
|
+
if (!p.endsWith("'")) throw new Error("Only hardened derivation is supported");
|
|
325
|
+
return parseInt(p.slice(0, -1), 10) + 2147483648;
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
const deriveSolana = (seed, derivationPath) => {
|
|
329
|
+
let I = (0, _noble_hashes_hmac_js.hmac)(_noble_hashes_sha2_js.sha512, new TextEncoder().encode("ed25519 seed"), seed);
|
|
330
|
+
let secretKey = I.slice(0, 32);
|
|
331
|
+
let chainCode = I.slice(32);
|
|
332
|
+
for (const index of parseDerivationPath(derivationPath)) {
|
|
333
|
+
const data = new Uint8Array(1 + secretKey.length + 4);
|
|
334
|
+
data.set([0], 0);
|
|
335
|
+
data.set(secretKey, 1);
|
|
336
|
+
data.set(new Uint8Array([
|
|
337
|
+
index >> 24 & 255,
|
|
338
|
+
index >> 16 & 255,
|
|
339
|
+
index >> 8 & 255,
|
|
340
|
+
index & 255
|
|
341
|
+
]), 1 + secretKey.length);
|
|
342
|
+
I = (0, _noble_hashes_hmac_js.hmac)(_noble_hashes_sha2_js.sha512, chainCode, data);
|
|
343
|
+
secretKey = I.slice(0, 32);
|
|
344
|
+
chainCode = I.slice(32);
|
|
345
|
+
}
|
|
346
|
+
const publicKey = getPublicKeySolana(secretKey);
|
|
347
|
+
return {
|
|
348
|
+
type: "solana",
|
|
349
|
+
secretKey,
|
|
350
|
+
publicKey,
|
|
351
|
+
address: addressFromPublicKey(publicKey, "base58solana")
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
const getPublicKeySolana = (secretKey) => {
|
|
355
|
+
return _noble_curves_ed25519_js.ed25519.getPublicKey(secretKey);
|
|
356
|
+
};
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/utils/pbkdf2.ts
|
|
359
|
+
const pbkdf2 = async (hash, entropy, salt, iterations, outputLenBytes) => {
|
|
360
|
+
const keyMaterial = await crypto.subtle.importKey("raw", entropy, "PBKDF2", false, ["deriveBits"]);
|
|
361
|
+
const derivedBits = await crypto.subtle.deriveBits({
|
|
362
|
+
name: "PBKDF2",
|
|
363
|
+
salt,
|
|
364
|
+
iterations,
|
|
365
|
+
hash
|
|
366
|
+
}, keyMaterial, outputLenBytes * 8);
|
|
367
|
+
return new Uint8Array(derivedBits);
|
|
368
|
+
};
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/mnemonic/index.ts
|
|
371
|
+
const mnemonicToEntropy = (mnemonic) => {
|
|
372
|
+
return (0, _scure_bip39.mnemonicToEntropy)(mnemonic, _scure_bip39_wordlists_english_js.wordlist);
|
|
373
|
+
};
|
|
374
|
+
const entropyToMnemonic = (entropy) => {
|
|
375
|
+
return (0, _scure_bip39.entropyToMnemonic)(entropy, _scure_bip39_wordlists_english_js.wordlist);
|
|
376
|
+
};
|
|
377
|
+
const entropyToSeedSubstrate = async (entropy, password) => await pbkdf2("SHA-512", entropy, mnemonicPasswordToSalt(password ?? ""), 2048, 32);
|
|
378
|
+
const entropyToSeedClassic = async (entropy, password) => await pbkdf2("SHA-512", encodeNormalized(entropyToMnemonic(entropy)), mnemonicPasswordToSalt(password ?? ""), 2048, 64);
|
|
379
|
+
const mnemonicPasswordToSalt = (password) => encodeNormalized(`mnemonic${password}`);
|
|
380
|
+
/** Normalizes a UTF-8 string using `NFKD` form, then encodes it into bytes */
|
|
381
|
+
const encodeNormalized = (utf8) => new TextEncoder().encode(utf8.normalize("NFKD"));
|
|
382
|
+
const getSeedDerivationType = (curve) => {
|
|
383
|
+
switch (curve) {
|
|
384
|
+
case "sr25519":
|
|
385
|
+
case "ed25519":
|
|
386
|
+
case "ecdsa": return "substrate";
|
|
387
|
+
case "ethereum":
|
|
388
|
+
case "solana": return "classic";
|
|
389
|
+
case "bitcoin-ecdsa":
|
|
390
|
+
case "bitcoin-ed25519": throw new Error("seed derivation is not implemented for Bitcoin");
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
const entropyToSeed = async (entropy, curve, password) => {
|
|
394
|
+
switch (getSeedDerivationType(curve)) {
|
|
395
|
+
case "classic": return await entropyToSeedClassic(entropy, password);
|
|
396
|
+
case "substrate": return await entropyToSeedSubstrate(entropy, password);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
const isValidMnemonic = (mnemonic) => {
|
|
400
|
+
return (0, _scure_bip39.validateMnemonic)(mnemonic, _scure_bip39_wordlists_english_js.wordlist);
|
|
401
|
+
};
|
|
402
|
+
const generateMnemonic = (words) => {
|
|
403
|
+
switch (words) {
|
|
404
|
+
case 12: return (0, _scure_bip39.generateMnemonic)(_scure_bip39_wordlists_english_js.wordlist, 128);
|
|
405
|
+
case 24: return (0, _scure_bip39.generateMnemonic)(_scure_bip39_wordlists_english_js.wordlist, 256);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
const DEV_MNEMONIC_POLKADOT = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
|
|
409
|
+
const DEV_MNEMONIC_ETHEREUM = "test test test test test test test test test test test junk";
|
|
410
|
+
const DEV_SEED_CACHE = /* @__PURE__ */ new Map();
|
|
411
|
+
const getDevSeed = async (curve) => {
|
|
412
|
+
const type = getSeedDerivationType(curve);
|
|
413
|
+
if (!DEV_SEED_CACHE.has(type)) switch (type) {
|
|
414
|
+
case "classic": {
|
|
415
|
+
const entropy = mnemonicToEntropy(DEV_MNEMONIC_ETHEREUM);
|
|
416
|
+
const seed = await entropyToSeedClassic(entropy);
|
|
417
|
+
DEV_SEED_CACHE.set(type, seed);
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
case "substrate": {
|
|
421
|
+
const entropy = mnemonicToEntropy(DEV_MNEMONIC_POLKADOT);
|
|
422
|
+
const seed = await entropyToSeedSubstrate(entropy);
|
|
423
|
+
DEV_SEED_CACHE.set(type, seed);
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
default: throw new Error("Unsupported derivation type");
|
|
427
|
+
}
|
|
428
|
+
return DEV_SEED_CACHE.get(type);
|
|
429
|
+
};
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region src/derivation/common.ts
|
|
432
|
+
const DERIVATION_RE = /(\/{1,2})(\w+)/g;
|
|
433
|
+
const parseSubstrateDerivations = (derivationsStr) => {
|
|
434
|
+
const derivations = [];
|
|
435
|
+
if (derivations) for (const [_, type, code] of derivationsStr.matchAll(DERIVATION_RE)) derivations.push([type === "//" ? "hard" : "soft", code]);
|
|
436
|
+
return derivations;
|
|
437
|
+
};
|
|
438
|
+
const createChainCode = (code) => {
|
|
439
|
+
const chainCode = /* @__PURE__ */ new Uint8Array(32);
|
|
440
|
+
chainCode.set(Number.isNaN(+code) ? scale_ts.str.enc(code) : scale_ts.u32.enc(+code));
|
|
441
|
+
return chainCode;
|
|
442
|
+
};
|
|
443
|
+
const derivationCodec = /* @__PURE__ */ (0, scale_ts.Tuple)(scale_ts.str, (0, scale_ts.Bytes)(32), (0, scale_ts.Bytes)(32));
|
|
444
|
+
const createSubstrateDeriveFn = (prefix) => (seed, chainCode) => blake2b256(derivationCodec.enc([
|
|
445
|
+
prefix,
|
|
446
|
+
seed,
|
|
447
|
+
chainCode
|
|
448
|
+
]));
|
|
449
|
+
const deriveSubstrateSecretKey = (seed, derivationPath, prefix) => {
|
|
450
|
+
const derivations = parseSubstrateDerivations(derivationPath);
|
|
451
|
+
const derive = createSubstrateDeriveFn(prefix);
|
|
452
|
+
return derivations.reduce((seed, [type, chainCode]) => {
|
|
453
|
+
const code = createChainCode(chainCode);
|
|
454
|
+
if (type === "soft") throw new Error("Soft derivations are not supported");
|
|
455
|
+
return derive(seed, code);
|
|
456
|
+
}, seed);
|
|
457
|
+
};
|
|
458
|
+
//#endregion
|
|
459
|
+
//#region src/derivation/deriveEcdsa.ts
|
|
460
|
+
const deriveEcdsa = (seed, derivationPath) => {
|
|
461
|
+
const secretKey = deriveSubstrateSecretKey(seed, derivationPath, "Secp256k1HDKD");
|
|
462
|
+
const publicKey = getPublicKeyEcdsa(secretKey);
|
|
463
|
+
return {
|
|
464
|
+
type: "ecdsa",
|
|
465
|
+
secretKey,
|
|
466
|
+
publicKey,
|
|
467
|
+
address: addressFromPublicKey(publicKey, "ss58")
|
|
468
|
+
};
|
|
469
|
+
};
|
|
470
|
+
const getPublicKeyEcdsa = (secretKey) => {
|
|
471
|
+
return _noble_curves_secp256k1_js.secp256k1.getPublicKey(secretKey);
|
|
472
|
+
};
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/derivation/deriveEd25519.ts
|
|
475
|
+
const deriveEd25519 = (seed, derivationPath) => {
|
|
476
|
+
const secretKey = deriveSubstrateSecretKey(seed, derivationPath, "Ed25519HDKD");
|
|
477
|
+
const publicKey = getPublicKeyEd25519(secretKey);
|
|
478
|
+
return {
|
|
479
|
+
type: "ed25519",
|
|
480
|
+
secretKey,
|
|
481
|
+
publicKey,
|
|
482
|
+
address: addressFromPublicKey(publicKey, "ss58")
|
|
483
|
+
};
|
|
484
|
+
};
|
|
485
|
+
const getPublicKeyEd25519 = (secretKey) => {
|
|
486
|
+
if (secretKey.length === 64) {
|
|
487
|
+
const [privateComponent, publicComponent] = [secretKey.slice(0, 32), secretKey.slice(32)];
|
|
488
|
+
const publicKey = _noble_curves_ed25519_js.ed25519.getPublicKey(privateComponent);
|
|
489
|
+
if (!isUint8ArrayEq(publicComponent, publicKey)) return _noble_curves_ed25519_js.ed25519.getPublicKey(secretKey);
|
|
490
|
+
return publicKey;
|
|
491
|
+
}
|
|
492
|
+
return _noble_curves_ed25519_js.ed25519.getPublicKey(secretKey);
|
|
493
|
+
};
|
|
494
|
+
/** If a is identical to b, this function returns true, otherwise it returns false */
|
|
495
|
+
const isUint8ArrayEq = (a, b) => a.length !== b.length || a.some((v, i) => v !== b[i]) ? false : true;
|
|
496
|
+
//#endregion
|
|
497
|
+
//#region src/derivation/deriveEthereum.ts
|
|
498
|
+
const deriveEthereum = (seed, derivationPath) => {
|
|
499
|
+
const childKey = _scure_bip32.HDKey.fromMasterSeed(seed).derive(derivationPath);
|
|
500
|
+
if (!childKey.privateKey) throw new Error("Invalid derivation path");
|
|
501
|
+
const secretKey = new Uint8Array(childKey.privateKey);
|
|
502
|
+
const publicKey = getPublicKeyEthereum(secretKey);
|
|
503
|
+
return {
|
|
504
|
+
type: "ethereum",
|
|
505
|
+
secretKey,
|
|
506
|
+
publicKey,
|
|
507
|
+
address: addressFromPublicKey(publicKey, "ethereum")
|
|
508
|
+
};
|
|
509
|
+
};
|
|
510
|
+
const getPublicKeyEthereum = (secretKey) => {
|
|
511
|
+
return _noble_curves_secp256k1_js.secp256k1.getPublicKey(secretKey, false);
|
|
512
|
+
};
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/derivation/deriveSr25519.ts
|
|
515
|
+
const deriveSr25519 = (seed, derivationPath) => {
|
|
516
|
+
const secretKey = parseSubstrateDerivations(derivationPath).reduce((secretKey, [type, chainCode]) => {
|
|
517
|
+
const code = createChainCode(chainCode);
|
|
518
|
+
return type === "hard" ? _scure_sr25519.HDKD.secretHard(secretKey, code) : _scure_sr25519.HDKD.secretSoft(secretKey, code);
|
|
519
|
+
}, (0, _scure_sr25519.secretFromSeed)(seed));
|
|
520
|
+
const publicKey = getPublicKeySr25519(secretKey);
|
|
521
|
+
return {
|
|
522
|
+
type: "sr25519",
|
|
523
|
+
secretKey,
|
|
524
|
+
publicKey,
|
|
525
|
+
address: addressFromPublicKey(publicKey, "ss58")
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
const getPublicKeySr25519 = _scure_sr25519.getPublicKey;
|
|
529
|
+
//#endregion
|
|
530
|
+
//#region src/derivation/utils.ts
|
|
531
|
+
const deriveKeypair = (seed, derivationPath, curve) => {
|
|
532
|
+
switch (curve) {
|
|
533
|
+
case "sr25519": return deriveSr25519(seed, derivationPath);
|
|
534
|
+
case "ed25519": return deriveEd25519(seed, derivationPath);
|
|
535
|
+
case "ecdsa": return deriveEcdsa(seed, derivationPath);
|
|
536
|
+
case "bitcoin-ecdsa":
|
|
537
|
+
case "bitcoin-ed25519": throw new Error("deriveKeypair is not implemented for Bitcoin");
|
|
538
|
+
case "ethereum": return deriveEthereum(seed, derivationPath);
|
|
539
|
+
case "solana": return deriveSolana(seed, derivationPath);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
const getPublicKeyFromSecret = (secretKey, curve) => {
|
|
543
|
+
switch (curve) {
|
|
544
|
+
case "ecdsa": return getPublicKeyEcdsa(secretKey);
|
|
545
|
+
case "ethereum": return getPublicKeyEthereum(secretKey);
|
|
546
|
+
case "sr25519": return getPublicKeySr25519(secretKey);
|
|
547
|
+
case "ed25519": return getPublicKeyEd25519(secretKey);
|
|
548
|
+
case "bitcoin-ecdsa":
|
|
549
|
+
case "bitcoin-ed25519": throw new Error("getPublicKeyFromSecret is not implemented for Bitcoin");
|
|
550
|
+
case "solana": return getPublicKeySolana(secretKey);
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
const addressFromMnemonic = async (mnemonic, derivationPath, curve) => {
|
|
554
|
+
const seed = await entropyToSeed(mnemonicToEntropy(mnemonic), curve);
|
|
555
|
+
const { address } = deriveKeypair(seed, derivationPath, curve);
|
|
556
|
+
return address;
|
|
557
|
+
};
|
|
558
|
+
const removeHexPrefix = (secretKey) => {
|
|
559
|
+
if (secretKey.startsWith("0x")) return secretKey.slice(2);
|
|
560
|
+
return secretKey;
|
|
561
|
+
};
|
|
562
|
+
const parseSecretKey = (secretKey, platform) => {
|
|
563
|
+
switch (platform) {
|
|
564
|
+
case "ethereum": {
|
|
565
|
+
const privateKey = removeHexPrefix(secretKey);
|
|
566
|
+
return _scure_base.hex.decode(privateKey);
|
|
567
|
+
}
|
|
568
|
+
case "solana": {
|
|
569
|
+
const bytes = secretKey.startsWith("[") ? Uint8Array.from(JSON.parse(secretKey)) : _scure_base.base58.decode(secretKey);
|
|
570
|
+
if (bytes.length === 64) {
|
|
571
|
+
const privateKey = bytes.slice(0, 32);
|
|
572
|
+
const publicKey = bytes.slice(32, 64);
|
|
573
|
+
const computedPublicKey = getPublicKeySolana(privateKey);
|
|
574
|
+
if (!publicKey.every((b, i) => b === computedPublicKey[i])) throw new Error("Invalid Solana secret key: public key does not match");
|
|
575
|
+
return privateKey;
|
|
576
|
+
} else if (bytes.length === 32) return bytes;
|
|
577
|
+
throw new Error("Invalid Solana secret key length");
|
|
578
|
+
}
|
|
579
|
+
default: throw new Error("Not implemented");
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
const isValidDerivationPath = async (derivationPath, curve) => {
|
|
583
|
+
try {
|
|
584
|
+
deriveKeypair(await getDevSeed(curve), derivationPath, curve);
|
|
585
|
+
return true;
|
|
586
|
+
} catch {
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region src/encryption/encryptKemAead.ts
|
|
592
|
+
/**
|
|
593
|
+
* Encrypts plaintext using ML-KEM-768 + XChaCha20-Poly1305 (KEM-AEAD).
|
|
594
|
+
*
|
|
595
|
+
* Wire format (subtensor pallet-shield v2):
|
|
596
|
+
* key_hash (16 bytes) || kem_len (2 bytes LE) || kem_ct (variable) || nonce (24 bytes) || aead_ct (variable)
|
|
597
|
+
*
|
|
598
|
+
* @param keyHash 16-byte xxhash128 of the public key (caller must compute, e.g. via Twox128)
|
|
599
|
+
* @param publicKey ML-KEM-768 encapsulation key bytes
|
|
600
|
+
* @param plaintext Data to encrypt (typically a signed extrinsic)
|
|
601
|
+
*/
|
|
602
|
+
const encryptKemAead = async (keyHash, publicKey, plaintext) => {
|
|
603
|
+
if (keyHash.length !== 16) throw new Error(`Expected 16-byte keyHash, got ${keyHash.length}`);
|
|
604
|
+
const [kemCt, sharedSecret] = await new mlkem.MlKem768().encap(publicKey);
|
|
605
|
+
if (sharedSecret.length !== 32) throw new Error(`Expected 32-byte shared secret, got ${sharedSecret.length}`);
|
|
606
|
+
const nonce = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(24));
|
|
607
|
+
const aeadCt = (0, _noble_ciphers_chacha_js.xchacha20poly1305)(sharedSecret, nonce).encrypt(plaintext);
|
|
608
|
+
const kemLen = /* @__PURE__ */ new Uint8Array(2);
|
|
609
|
+
new DataView(kemLen.buffer).setUint16(0, kemCt.length, true);
|
|
610
|
+
return (0, _noble_ciphers_utils_js.concatBytes)(keyHash, kemLen, kemCt, nonce, aeadCt);
|
|
611
|
+
};
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/keystore/index.ts
|
|
614
|
+
/**
|
|
615
|
+
* polkadot-js encrypted keystore JSON support (scrypt + xsalsa20-poly1305), byte-compatible
|
|
616
|
+
* with `@polkadot/util-crypto` `jsonEncrypt`/`jsonDecrypt`.
|
|
617
|
+
*
|
|
618
|
+
* Layout of the base64 `encoded` blob:
|
|
619
|
+
* salt(32) ++ N(u32 LE) ++ p(u32 LE) ++ r(u32 LE) ++ nonce(24) ++ ciphertext
|
|
620
|
+
*/
|
|
621
|
+
const SALT_LENGTH = 32;
|
|
622
|
+
const NONCE_LENGTH = 24;
|
|
623
|
+
const ALLOWED_SCRYPT_PARAMS = [
|
|
624
|
+
{
|
|
625
|
+
N: 8192,
|
|
626
|
+
p: 10,
|
|
627
|
+
r: 8
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
N: 16384,
|
|
631
|
+
p: 5,
|
|
632
|
+
r: 8
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
N: 32768,
|
|
636
|
+
p: 3,
|
|
637
|
+
r: 8
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
N: 32768,
|
|
641
|
+
p: 1,
|
|
642
|
+
r: 8
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
N: 65536,
|
|
646
|
+
p: 2,
|
|
647
|
+
r: 8
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
N: 1 << 17,
|
|
651
|
+
p: 1,
|
|
652
|
+
r: 8
|
|
653
|
+
}
|
|
654
|
+
];
|
|
655
|
+
const SCRYPT_N = 1 << 17;
|
|
656
|
+
const SCRYPT_P = 1;
|
|
657
|
+
const SCRYPT_R = 8;
|
|
658
|
+
const readU32LE = (bytes, offset) => bytes[offset] | bytes[offset + 1] << 8 | bytes[offset + 2] << 16 | bytes[offset + 3] << 24 >>> 0;
|
|
659
|
+
const writeU32LE = (value) => new Uint8Array([
|
|
660
|
+
value & 255,
|
|
661
|
+
value >> 8 & 255,
|
|
662
|
+
value >> 16 & 255,
|
|
663
|
+
value >> 24 & 255
|
|
664
|
+
]);
|
|
665
|
+
const deriveKey = (password, salt, params) => (0, _noble_hashes_scrypt_js.scrypt)(new TextEncoder().encode(password), salt, {
|
|
666
|
+
...params,
|
|
667
|
+
dkLen: 64
|
|
668
|
+
}).subarray(0, 32);
|
|
669
|
+
/** Decrypts a polkadot-js encrypted keystore (`jsonDecrypt` equivalent) */
|
|
670
|
+
const decryptPjsKeystore = ({ encoded, encoding }, password) => {
|
|
671
|
+
if (!encoded) throw new Error("No encrypted data available to decode");
|
|
672
|
+
const bytes = _scure_base.base64.decode(encoded);
|
|
673
|
+
if (!encoding.type.includes("xsalsa20-poly1305")) {
|
|
674
|
+
if (encoding.type.includes("none")) return bytes;
|
|
675
|
+
throw new Error(`Unsupported keystore encoding: ${encoding.type.join("/")}`);
|
|
676
|
+
}
|
|
677
|
+
let offset = 0;
|
|
678
|
+
let key;
|
|
679
|
+
if (encoding.type.includes("scrypt")) {
|
|
680
|
+
const salt = bytes.subarray(0, SALT_LENGTH);
|
|
681
|
+
const N = readU32LE(bytes, SALT_LENGTH);
|
|
682
|
+
const p = readU32LE(bytes, 36);
|
|
683
|
+
const r = readU32LE(bytes, 40);
|
|
684
|
+
if (!ALLOWED_SCRYPT_PARAMS.some((preset) => preset.N === N && preset.p === p && preset.r === r)) throw new Error("Invalid injected scrypt params found");
|
|
685
|
+
key = deriveKey(password, salt, {
|
|
686
|
+
N,
|
|
687
|
+
p,
|
|
688
|
+
r
|
|
689
|
+
});
|
|
690
|
+
offset = 44;
|
|
691
|
+
} else {
|
|
692
|
+
const padded = /* @__PURE__ */ new Uint8Array(32);
|
|
693
|
+
padded.set(new TextEncoder().encode(password).subarray(0, 32));
|
|
694
|
+
key = padded;
|
|
695
|
+
}
|
|
696
|
+
const nonce = bytes.subarray(offset, offset + NONCE_LENGTH);
|
|
697
|
+
const ciphertext = bytes.subarray(offset + NONCE_LENGTH);
|
|
698
|
+
return (0, _noble_ciphers_salsa_js.xsalsa20poly1305)(key, nonce).decrypt(ciphertext);
|
|
699
|
+
};
|
|
700
|
+
/** Encrypts data as a polkadot-js keystore (`jsonEncrypt` equivalent, always scrypt + v3) */
|
|
701
|
+
const encryptPjsKeystore = (data, contentType, password) => {
|
|
702
|
+
const salt = crypto.getRandomValues(new Uint8Array(SALT_LENGTH));
|
|
703
|
+
const nonce = crypto.getRandomValues(new Uint8Array(NONCE_LENGTH));
|
|
704
|
+
const ciphertext = (0, _noble_ciphers_salsa_js.xsalsa20poly1305)(deriveKey(password, salt, {
|
|
705
|
+
N: SCRYPT_N,
|
|
706
|
+
p: SCRYPT_P,
|
|
707
|
+
r: SCRYPT_R
|
|
708
|
+
}), nonce).encrypt(data);
|
|
709
|
+
const encoded = new Uint8Array(68 + ciphertext.length);
|
|
710
|
+
encoded.set(salt, 0);
|
|
711
|
+
encoded.set(writeU32LE(SCRYPT_N), SALT_LENGTH);
|
|
712
|
+
encoded.set(writeU32LE(SCRYPT_P), 36);
|
|
713
|
+
encoded.set(writeU32LE(SCRYPT_R), 40);
|
|
714
|
+
encoded.set(nonce, 44);
|
|
715
|
+
encoded.set(ciphertext, 68);
|
|
716
|
+
return {
|
|
717
|
+
encoded: _scure_base.base64.encode(encoded),
|
|
718
|
+
encoding: {
|
|
719
|
+
content: contentType,
|
|
720
|
+
type: ["scrypt", "xsalsa20-poly1305"],
|
|
721
|
+
version: "3"
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
};
|
|
725
|
+
//#endregion
|
|
726
|
+
//#region src/platform/index.ts
|
|
727
|
+
const getAccountPlatformFromCurve = (curve) => {
|
|
728
|
+
switch (curve) {
|
|
729
|
+
case "sr25519":
|
|
730
|
+
case "ed25519":
|
|
731
|
+
case "ecdsa": return "polkadot";
|
|
732
|
+
case "ethereum": return "ethereum";
|
|
733
|
+
case "bitcoin-ecdsa":
|
|
734
|
+
case "bitcoin-ed25519": return "bitcoin";
|
|
735
|
+
case "solana": return "solana";
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
const getAccountPlatformFromEncoding = (encoding) => {
|
|
739
|
+
switch (encoding) {
|
|
740
|
+
case "ss58": return "polkadot";
|
|
741
|
+
case "ethereum": return "ethereum";
|
|
742
|
+
case "bech32m":
|
|
743
|
+
case "bech32":
|
|
744
|
+
case "base58check": return "bitcoin";
|
|
745
|
+
case "base58solana": return "solana";
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
const getAccountPlatformFromAddress = (address) => {
|
|
749
|
+
const encoding = detectAddressEncoding(address);
|
|
750
|
+
return getAccountPlatformFromEncoding(encoding);
|
|
751
|
+
};
|
|
752
|
+
//#endregion
|
|
753
|
+
//#region src/signing/index.ts
|
|
754
|
+
/** noble's recovered signature format is v||r||s, substrate expects r||s||v */
|
|
755
|
+
const toRsv = (vrs) => {
|
|
756
|
+
const rsv = /* @__PURE__ */ new Uint8Array(65);
|
|
757
|
+
rsv.set(vrs.subarray(1), 0);
|
|
758
|
+
rsv[64] = vrs[0];
|
|
759
|
+
return rsv;
|
|
760
|
+
};
|
|
761
|
+
/**
|
|
762
|
+
* Signs a substrate payload with the given curve.
|
|
763
|
+
*
|
|
764
|
+
* Output is byte-compatible with polkadot-js `KeyringPair.sign` (without type prefix):
|
|
765
|
+
* - sr25519/ed25519: 64-byte signature over the raw message
|
|
766
|
+
* - ecdsa: 65-byte recoverable signature (r||s||v) over blake2b-256(message)
|
|
767
|
+
* - ethereum: 65-byte recoverable signature (r||s||v) over keccak-256(message)
|
|
768
|
+
*
|
|
769
|
+
* Note: callers are responsible for the substrate >256-byte rule (hash the payload
|
|
770
|
+
* with blake2b-256 before signing) — this matches where polkadot-js applies it.
|
|
771
|
+
*/
|
|
772
|
+
const signSubstrate = (curve, secretKey, message) => {
|
|
773
|
+
switch (curve) {
|
|
774
|
+
case "sr25519": return (0, _scure_sr25519.sign)(secretKey, message);
|
|
775
|
+
case "ed25519": return _noble_curves_ed25519_js.ed25519.sign(message, secretKey.length === 64 ? secretKey.subarray(0, 32) : secretKey);
|
|
776
|
+
case "ecdsa": return toRsv(_noble_curves_secp256k1_js.secp256k1.sign(blake2b256(message), secretKey, {
|
|
777
|
+
format: "recovered",
|
|
778
|
+
prehash: false
|
|
779
|
+
}));
|
|
780
|
+
case "ethereum": return toRsv(_noble_curves_secp256k1_js.secp256k1.sign((0, _noble_hashes_sha3_js.keccak_256)(message), secretKey, {
|
|
781
|
+
format: "recovered",
|
|
782
|
+
prehash: false
|
|
783
|
+
}));
|
|
784
|
+
default: throw new Error(`Unsupported curve for substrate signing: ${curve}`);
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
/** MultiSignature enum variant index per signature scheme, used to type-prefix signatures */
|
|
788
|
+
const SIGNATURE_TYPE_PREFIX = {
|
|
789
|
+
ed25519: 0,
|
|
790
|
+
sr25519: 1,
|
|
791
|
+
ecdsa: 2,
|
|
792
|
+
ethereum: 2
|
|
793
|
+
};
|
|
794
|
+
//#endregion
|
|
795
|
+
exports.DEV_MNEMONIC_ETHEREUM = DEV_MNEMONIC_ETHEREUM;
|
|
796
|
+
exports.DEV_MNEMONIC_POLKADOT = DEV_MNEMONIC_POLKADOT;
|
|
797
|
+
exports.SIGNATURE_TYPE_PREFIX = SIGNATURE_TYPE_PREFIX;
|
|
798
|
+
exports.addressEncodingFromCurve = addressEncodingFromCurve;
|
|
799
|
+
exports.addressFromMnemonic = addressFromMnemonic;
|
|
800
|
+
exports.addressFromPublicKey = addressFromPublicKey;
|
|
801
|
+
Object.defineProperty(exports, "base58", {
|
|
802
|
+
enumerable: true,
|
|
803
|
+
get: function() {
|
|
804
|
+
return _scure_base.base58;
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
Object.defineProperty(exports, "base64", {
|
|
808
|
+
enumerable: true,
|
|
809
|
+
get: function() {
|
|
810
|
+
return _scure_base.base64;
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
exports.blake2b256 = blake2b256;
|
|
814
|
+
exports.blake2b512 = blake2b512;
|
|
815
|
+
exports.blake3 = blake3;
|
|
816
|
+
exports.checksumEthereumAddress = checksumEthereumAddress;
|
|
817
|
+
exports.decodeSs58Address = decodeSs58Address;
|
|
818
|
+
exports.decryptPjsKeystore = decryptPjsKeystore;
|
|
819
|
+
exports.deriveKeypair = deriveKeypair;
|
|
820
|
+
exports.detectAddressEncoding = detectAddressEncoding;
|
|
821
|
+
Object.defineProperty(exports, "ed25519", {
|
|
822
|
+
enumerable: true,
|
|
823
|
+
get: function() {
|
|
824
|
+
return _noble_curves_ed25519_js.ed25519;
|
|
825
|
+
}
|
|
815
826
|
});
|
|
827
|
+
exports.encodeAddressEthereum = encodeAddressEthereum;
|
|
828
|
+
exports.encodeAddressSolana = encodeAddressSolana;
|
|
829
|
+
exports.encodeAddressSs58 = encodeAddressSs58;
|
|
830
|
+
exports.encodeAnyAddress = encodeAnyAddress;
|
|
831
|
+
exports.encryptKemAead = encryptKemAead;
|
|
832
|
+
exports.encryptPjsKeystore = encryptPjsKeystore;
|
|
833
|
+
exports.entropyToMnemonic = entropyToMnemonic;
|
|
834
|
+
exports.entropyToSeed = entropyToSeed;
|
|
835
|
+
exports.fromBase58Check = fromBase58Check;
|
|
836
|
+
exports.fromBech32 = fromBech32;
|
|
837
|
+
exports.fromBech32m = fromBech32m;
|
|
838
|
+
exports.generateMnemonic = generateMnemonic;
|
|
839
|
+
exports.getAccountPlatformFromAddress = getAccountPlatformFromAddress;
|
|
840
|
+
exports.getAccountPlatformFromCurve = getAccountPlatformFromCurve;
|
|
841
|
+
exports.getAccountPlatformFromEncoding = getAccountPlatformFromEncoding;
|
|
842
|
+
exports.getDevSeed = getDevSeed;
|
|
843
|
+
exports.getPublicKeyFromSecret = getPublicKeyFromSecret;
|
|
844
|
+
exports.getPublicKeySolana = getPublicKeySolana;
|
|
845
|
+
exports.getSafeHash = getSafeHash;
|
|
846
|
+
Object.defineProperty(exports, "hex", {
|
|
847
|
+
enumerable: true,
|
|
848
|
+
get: function() {
|
|
849
|
+
return _scure_base.hex;
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
exports.isAddressEqual = isAddressEqual;
|
|
853
|
+
exports.isAddressValid = isAddressValid;
|
|
854
|
+
exports.isBase58CheckAddress = isBase58CheckAddress;
|
|
855
|
+
exports.isBech32Address = isBech32Address;
|
|
856
|
+
exports.isBech32mAddress = isBech32mAddress;
|
|
857
|
+
exports.isBitcoinAddress = isBitcoinAddress;
|
|
858
|
+
exports.isEthereumAddress = isEthereumAddress;
|
|
859
|
+
exports.isOnCurveSolanaAddress = isOnCurveSolanaAddress;
|
|
860
|
+
exports.isSolanaAddress = isSolanaAddress;
|
|
861
|
+
exports.isSs58Address = isSs58Address;
|
|
862
|
+
exports.isValidDerivationPath = isValidDerivationPath;
|
|
863
|
+
exports.isValidMnemonic = isValidMnemonic;
|
|
864
|
+
exports.mnemonicToEntropy = mnemonicToEntropy;
|
|
865
|
+
exports.normalizeAddress = normalizeAddress;
|
|
866
|
+
exports.parseSecretKey = parseSecretKey;
|
|
867
|
+
exports.pbkdf2 = pbkdf2;
|
|
868
|
+
exports.removeHexPrefix = removeHexPrefix;
|
|
869
|
+
exports.signSubstrate = signSubstrate;
|
|
870
|
+
Object.defineProperty(exports, "utf8", {
|
|
871
|
+
enumerable: true,
|
|
872
|
+
get: function() {
|
|
873
|
+
return _scure_base.utf8;
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
|
|
816
877
|
//# sourceMappingURL=index.js.map
|