1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@polkadot/util-crypto'), require('@polkadot/util')) :
|
3 | typeof define === 'function' && define.amd ? define(['exports', '@polkadot/util-crypto', '@polkadot/util'], factory) :
|
4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.polkadotKeyring = {}, global.polkadotUtilCrypto, global.polkadotUtil));
|
5 | })(this, (function (exports, utilCrypto, util) { 'use strict';
|
6 |
|
7 | const global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : window;
|
8 |
|
9 | var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
10 | const PKCS8_DIVIDER = new Uint8Array([161, 35, 3, 33, 0]);
|
11 | const PKCS8_HEADER = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
|
12 | const PUB_LENGTH = 32;
|
13 | const SEC_LENGTH = 64;
|
14 | const SEED_LENGTH = 32;
|
15 |
|
16 | const SEED_OFFSET = PKCS8_HEADER.length;
|
17 | function decodePair(passphrase, encrypted, _encType) {
|
18 | const encType = Array.isArray(_encType) || _encType === undefined
|
19 | ? _encType
|
20 | : [_encType];
|
21 | const decrypted = utilCrypto.jsonDecryptData(encrypted, passphrase, encType);
|
22 | const header = decrypted.subarray(0, PKCS8_HEADER.length);
|
23 | if (!util.u8aEq(header, PKCS8_HEADER)) {
|
24 | throw new Error('Invalid Pkcs8 header found in body');
|
25 | }
|
26 | let secretKey = decrypted.subarray(SEED_OFFSET, SEED_OFFSET + SEC_LENGTH);
|
27 | let divOffset = SEED_OFFSET + SEC_LENGTH;
|
28 | let divider = decrypted.subarray(divOffset, divOffset + PKCS8_DIVIDER.length);
|
29 | if (!util.u8aEq(divider, PKCS8_DIVIDER)) {
|
30 | divOffset = SEED_OFFSET + SEED_LENGTH;
|
31 | secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
|
32 | divider = decrypted.subarray(divOffset, divOffset + PKCS8_DIVIDER.length);
|
33 | if (!util.u8aEq(divider, PKCS8_DIVIDER)) {
|
34 | throw new Error('Invalid Pkcs8 divider found in body');
|
35 | }
|
36 | }
|
37 | const pubOffset = divOffset + PKCS8_DIVIDER.length;
|
38 | const publicKey = decrypted.subarray(pubOffset, pubOffset + PUB_LENGTH);
|
39 | return {
|
40 | publicKey,
|
41 | secretKey
|
42 | };
|
43 | }
|
44 |
|
45 | function encodePair({ publicKey, secretKey }, passphrase) {
|
46 | if (!secretKey) {
|
47 | throw new Error('Expected a valid secretKey to be passed to encode');
|
48 | }
|
49 | const encoded = util.u8aConcat(PKCS8_HEADER, secretKey, PKCS8_DIVIDER, publicKey);
|
50 | if (!passphrase) {
|
51 | return encoded;
|
52 | }
|
53 | const { params, password, salt } = utilCrypto.scryptEncode(passphrase);
|
54 | const { encrypted, nonce } = utilCrypto.naclEncrypt(encoded, password.subarray(0, 32));
|
55 | return util.u8aConcat(utilCrypto.scryptToU8a(salt, params), nonce, encrypted);
|
56 | }
|
57 |
|
58 | function pairToJson(type, { address, meta }, encoded, isEncrypted) {
|
59 | return util.objectSpread(utilCrypto.jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted), {
|
60 | address,
|
61 | meta
|
62 | });
|
63 | }
|
64 |
|
65 | const SIG_TYPE_NONE = new Uint8Array();
|
66 | const TYPE_FROM_SEED = {
|
67 | ecdsa: utilCrypto.secp256k1PairFromSeed,
|
68 | ed25519: utilCrypto.ed25519PairFromSeed,
|
69 | ethereum: utilCrypto.secp256k1PairFromSeed,
|
70 | sr25519: utilCrypto.sr25519PairFromSeed
|
71 | };
|
72 | const TYPE_PREFIX = {
|
73 | ecdsa: new Uint8Array([2]),
|
74 | ed25519: new Uint8Array([0]),
|
75 | ethereum: new Uint8Array([2]),
|
76 | sr25519: new Uint8Array([1])
|
77 | };
|
78 | const TYPE_SIGNATURE = {
|
79 | ecdsa: (m, p) => utilCrypto.secp256k1Sign(m, p, 'blake2'),
|
80 | ed25519: utilCrypto.ed25519Sign,
|
81 | ethereum: (m, p) => utilCrypto.secp256k1Sign(m, p, 'keccak'),
|
82 | sr25519: utilCrypto.sr25519Sign
|
83 | };
|
84 | const TYPE_ADDRESS = {
|
85 | ecdsa: (p) => p.length > 32 ? utilCrypto.blake2AsU8a(p) : p,
|
86 | ed25519: (p) => p,
|
87 | ethereum: (p) => p.length === 20 ? p : utilCrypto.keccakAsU8a(utilCrypto.secp256k1Expand(p)),
|
88 | sr25519: (p) => p
|
89 | };
|
90 | function isLocked(secretKey) {
|
91 | return !secretKey || util.u8aEmpty(secretKey);
|
92 | }
|
93 | function vrfHash(proof, context, extra) {
|
94 | return utilCrypto.blake2AsU8a(util.u8aConcat(context || '', extra || '', proof));
|
95 | }
|
96 | function createPair({ toSS58, type }, { publicKey, secretKey }, meta = {}, encoded = null, encTypes) {
|
97 | const decodePkcs8 = (passphrase, userEncoded) => {
|
98 | const decoded = decodePair(passphrase, userEncoded || encoded, encTypes);
|
99 | if (decoded.secretKey.length === 64) {
|
100 | publicKey = decoded.publicKey;
|
101 | secretKey = decoded.secretKey;
|
102 | }
|
103 | else {
|
104 | const pair = TYPE_FROM_SEED[type](decoded.secretKey);
|
105 | publicKey = pair.publicKey;
|
106 | secretKey = pair.secretKey;
|
107 | }
|
108 | };
|
109 | const recode = (passphrase) => {
|
110 | isLocked(secretKey) && encoded && decodePkcs8(passphrase, encoded);
|
111 | encoded = encodePair({ publicKey, secretKey }, passphrase);
|
112 | encTypes = undefined;
|
113 | return encoded;
|
114 | };
|
115 | const encodeAddress = () => {
|
116 | const raw = TYPE_ADDRESS[type](publicKey);
|
117 | return type === 'ethereum'
|
118 | ? utilCrypto.ethereumEncode(raw)
|
119 | : toSS58(raw);
|
120 | };
|
121 | return {
|
122 | get address() {
|
123 | return encodeAddress();
|
124 | },
|
125 | get addressRaw() {
|
126 | const raw = TYPE_ADDRESS[type](publicKey);
|
127 | return type === 'ethereum'
|
128 | ? raw.slice(-20)
|
129 | : raw;
|
130 | },
|
131 | get isLocked() {
|
132 | return isLocked(secretKey);
|
133 | },
|
134 | get meta() {
|
135 | return meta;
|
136 | },
|
137 | get publicKey() {
|
138 | return publicKey;
|
139 | },
|
140 | get type() {
|
141 | return type;
|
142 | },
|
143 | decodePkcs8,
|
144 | derive: (suri, meta) => {
|
145 | if (type === 'ethereum') {
|
146 | throw new Error('Unable to derive on this keypair');
|
147 | }
|
148 | else if (isLocked(secretKey)) {
|
149 | throw new Error('Cannot derive on a locked keypair');
|
150 | }
|
151 | const { path } = utilCrypto.keyExtractPath(suri);
|
152 | const derived = utilCrypto.keyFromPath({ publicKey, secretKey }, path, type);
|
153 | return createPair({ toSS58, type }, derived, meta, null);
|
154 | },
|
155 | encodePkcs8: (passphrase) => {
|
156 | return recode(passphrase);
|
157 | },
|
158 | lock: () => {
|
159 | secretKey = new Uint8Array();
|
160 | },
|
161 | setMeta: (additional) => {
|
162 | meta = util.objectSpread({}, meta, additional);
|
163 | },
|
164 | sign: (message, options = {}) => {
|
165 | if (isLocked(secretKey)) {
|
166 | throw new Error('Cannot sign with a locked key pair');
|
167 | }
|
168 | return util.u8aConcat(options.withType
|
169 | ? TYPE_PREFIX[type]
|
170 | : SIG_TYPE_NONE, TYPE_SIGNATURE[type](util.u8aToU8a(message), { publicKey, secretKey }));
|
171 | },
|
172 | toJson: (passphrase) => {
|
173 | const address = ['ecdsa', 'ethereum'].includes(type)
|
174 | ? publicKey.length === 20
|
175 | ? util.u8aToHex(publicKey)
|
176 | : util.u8aToHex(utilCrypto.secp256k1Compress(publicKey))
|
177 | : encodeAddress();
|
178 | return pairToJson(type, { address, meta }, recode(passphrase), !!passphrase);
|
179 | },
|
180 | unlock: (passphrase) => {
|
181 | return decodePkcs8(passphrase);
|
182 | },
|
183 | verify: (message, signature, signerPublic) => {
|
184 | return utilCrypto.signatureVerify(message, signature, TYPE_ADDRESS[type](util.u8aToU8a(signerPublic))).isValid;
|
185 | },
|
186 | vrfSign: (message, context, extra) => {
|
187 | if (isLocked(secretKey)) {
|
188 | throw new Error('Cannot sign with a locked key pair');
|
189 | }
|
190 | if (type === 'sr25519') {
|
191 | return utilCrypto.sr25519VrfSign(message, { secretKey }, context, extra);
|
192 | }
|
193 | const proof = TYPE_SIGNATURE[type](util.u8aToU8a(message), { publicKey, secretKey });
|
194 | return util.u8aConcat(vrfHash(proof, context, extra), proof);
|
195 | },
|
196 | vrfVerify: (message, vrfResult, signerPublic, context, extra) => {
|
197 | if (type === 'sr25519') {
|
198 | return utilCrypto.sr25519VrfVerify(message, vrfResult, publicKey, context, extra);
|
199 | }
|
200 | const result = utilCrypto.signatureVerify(message, util.u8aConcat(TYPE_PREFIX[type], vrfResult.subarray(32)), TYPE_ADDRESS[type](util.u8aToU8a(signerPublic)));
|
201 | return result.isValid && util.u8aEq(vrfResult.subarray(0, 32), vrfHash(vrfResult.subarray(32), context, extra));
|
202 | }
|
203 | };
|
204 | }
|
205 |
|
206 | const DEV_PHRASE = 'bottom drive obey lake curtain smoke basket hold race lonely fit walk';
|
207 | const DEV_SEED = '0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e';
|
208 |
|
209 | class Pairs {
|
210 | __internal__map = {};
|
211 | add(pair) {
|
212 | this.__internal__map[utilCrypto.decodeAddress(pair.address).toString()] = pair;
|
213 | return pair;
|
214 | }
|
215 | all() {
|
216 | return Object.values(this.__internal__map);
|
217 | }
|
218 | get(address) {
|
219 | const pair = this.__internal__map[utilCrypto.decodeAddress(address).toString()];
|
220 | if (!pair) {
|
221 | throw new Error(`Unable to retrieve keypair '${util.isU8a(address) || util.isHex(address)
|
222 | ? util.u8aToHex(util.u8aToU8a(address))
|
223 | : address}'`);
|
224 | }
|
225 | return pair;
|
226 | }
|
227 | remove(address) {
|
228 | delete this.__internal__map[utilCrypto.decodeAddress(address).toString()];
|
229 | }
|
230 | }
|
231 |
|
232 | const PairFromSeed = {
|
233 | ecdsa: (seed) => utilCrypto.secp256k1PairFromSeed(seed),
|
234 | ed25519: (seed) => utilCrypto.ed25519PairFromSeed(seed),
|
235 | ethereum: (seed) => utilCrypto.secp256k1PairFromSeed(seed),
|
236 | sr25519: (seed) => utilCrypto.sr25519PairFromSeed(seed)
|
237 | };
|
238 | function pairToPublic({ publicKey }) {
|
239 | return publicKey;
|
240 | }
|
241 | class Keyring {
|
242 | __internal__pairs;
|
243 | __internal__type;
|
244 | __internal__ss58;
|
245 | decodeAddress = utilCrypto.decodeAddress;
|
246 | constructor(options = {}) {
|
247 | options.type = options.type || 'ed25519';
|
248 | if (!['ecdsa', 'ethereum', 'ed25519', 'sr25519'].includes(options.type || 'undefined')) {
|
249 | throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${options.type || 'unknown'}`);
|
250 | }
|
251 | this.__internal__pairs = new Pairs();
|
252 | this.__internal__ss58 = options.ss58Format;
|
253 | this.__internal__type = options.type;
|
254 | }
|
255 | get pairs() {
|
256 | return this.getPairs();
|
257 | }
|
258 | get publicKeys() {
|
259 | return this.getPublicKeys();
|
260 | }
|
261 | get type() {
|
262 | return this.__internal__type;
|
263 | }
|
264 | addPair(pair) {
|
265 | return this.__internal__pairs.add(pair);
|
266 | }
|
267 | addFromAddress(address, meta = {}, encoded = null, type = this.type, ignoreChecksum, encType) {
|
268 | const publicKey = this.decodeAddress(address, ignoreChecksum);
|
269 | return this.addPair(createPair({ toSS58: this.encodeAddress, type }, { publicKey, secretKey: new Uint8Array() }, meta, encoded, encType));
|
270 | }
|
271 | addFromJson(json, ignoreChecksum) {
|
272 | return this.addPair(this.createFromJson(json, ignoreChecksum));
|
273 | }
|
274 | addFromMnemonic(mnemonic, meta = {}, type = this.type) {
|
275 | return this.addFromUri(mnemonic, meta, type);
|
276 | }
|
277 | addFromPair(pair, meta = {}, type = this.type) {
|
278 | return this.addPair(this.createFromPair(pair, meta, type));
|
279 | }
|
280 | addFromSeed(seed, meta = {}, type = this.type) {
|
281 | return this.addPair(createPair({ toSS58: this.encodeAddress, type }, PairFromSeed[type](seed), meta, null));
|
282 | }
|
283 | addFromUri(suri, meta = {}, type = this.type) {
|
284 | return this.addPair(this.createFromUri(suri, meta, type));
|
285 | }
|
286 | createFromJson({ address, encoded, encoding: { content, type, version }, meta }, ignoreChecksum) {
|
287 | if (version === '3' && content[0] !== 'pkcs8') {
|
288 | throw new Error(`Unable to decode non-pkcs8 type, [${content.join(',')}] found}`);
|
289 | }
|
290 | const cryptoType = version === '0' || !Array.isArray(content)
|
291 | ? this.type
|
292 | : content[1];
|
293 | const encType = !Array.isArray(type)
|
294 | ? [type]
|
295 | : type;
|
296 | if (!['ed25519', 'sr25519', 'ecdsa', 'ethereum'].includes(cryptoType)) {
|
297 | throw new Error(`Unknown crypto type ${cryptoType}`);
|
298 | }
|
299 | const publicKey = util.isHex(address)
|
300 | ? util.hexToU8a(address)
|
301 | : this.decodeAddress(address, ignoreChecksum);
|
302 | const decoded = util.isHex(encoded)
|
303 | ? util.hexToU8a(encoded)
|
304 | : utilCrypto.base64Decode(encoded);
|
305 | return createPair({ toSS58: this.encodeAddress, type: cryptoType }, { publicKey, secretKey: new Uint8Array() }, meta, decoded, encType);
|
306 | }
|
307 | createFromPair(pair, meta = {}, type = this.type) {
|
308 | return createPair({ toSS58: this.encodeAddress, type }, pair, meta, null);
|
309 | }
|
310 | createFromUri(_suri, meta = {}, type = this.type) {
|
311 | const suri = _suri.startsWith('//')
|
312 | ? `${DEV_PHRASE}${_suri}`
|
313 | : _suri;
|
314 | const { derivePath, password, path, phrase } = utilCrypto.keyExtractSuri(suri);
|
315 | let seed;
|
316 | const isPhraseHex = util.isHex(phrase, 256);
|
317 | if (isPhraseHex) {
|
318 | seed = util.hexToU8a(phrase);
|
319 | }
|
320 | else {
|
321 | const parts = phrase.split(' ');
|
322 | if ([12, 15, 18, 21, 24].includes(parts.length)) {
|
323 | seed = type === 'ethereum'
|
324 | ? utilCrypto.mnemonicToLegacySeed(phrase, '', false, 64)
|
325 | : utilCrypto.mnemonicToMiniSecret(phrase, password);
|
326 | }
|
327 | else {
|
328 | if (phrase.length > 32) {
|
329 | throw new Error('specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes');
|
330 | }
|
331 | seed = util.stringToU8a(phrase.padEnd(32));
|
332 | }
|
333 | }
|
334 | const derived = type === 'ethereum'
|
335 | ? isPhraseHex
|
336 | ? PairFromSeed[type](seed)
|
337 | : utilCrypto.hdEthereum(seed, derivePath.substring(1))
|
338 | : utilCrypto.keyFromPath(PairFromSeed[type](seed), path, type);
|
339 | return createPair({ toSS58: this.encodeAddress, type }, derived, meta, null);
|
340 | }
|
341 | encodeAddress = (address, ss58Format) => {
|
342 | return this.type === 'ethereum'
|
343 | ? utilCrypto.ethereumEncode(address)
|
344 | : utilCrypto.encodeAddress(address, ss58Format ?? this.__internal__ss58);
|
345 | };
|
346 | getPair(address) {
|
347 | return this.__internal__pairs.get(address);
|
348 | }
|
349 | getPairs() {
|
350 | return this.__internal__pairs.all();
|
351 | }
|
352 | getPublicKeys() {
|
353 | return this.__internal__pairs.all().map(pairToPublic);
|
354 | }
|
355 | removePair(address) {
|
356 | this.__internal__pairs.remove(address);
|
357 | }
|
358 | setSS58Format(ss58) {
|
359 | this.__internal__ss58 = ss58;
|
360 | }
|
361 | toJson(address, passphrase) {
|
362 | return this.__internal__pairs.get(address).toJson(passphrase);
|
363 | }
|
364 | }
|
365 |
|
366 | const packageInfo = { name: '@polkadot/keyring', path: (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-polkadot-keyring.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-polkadot-keyring.js', document.baseURI).href))) ? new URL((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-polkadot-keyring.js', document.baseURI).href))).pathname.substring(0, new URL((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-polkadot-keyring.js', document.baseURI).href))).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '12.6.1' };
|
367 |
|
368 | const PAIRSSR25519 = [
|
369 | {
|
370 | p: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
|
371 | s: '0x98319d4ff8a9508c4bb0cf0b5a78d760a0b2082c02775e6e82370816fedfff48925a225d97aa00682d6a59b95b18780c10d7032336e88f3442b42361f4a66011',
|
372 | seed: 'Alice',
|
373 | type: 'sr25519'
|
374 | },
|
375 | {
|
376 | p: '0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f',
|
377 | s: '0xe8da6c9d810e020f5e3c7f5af2dea314cbeaa0d72bc6421e92c0808a0c584a6046ab28e97c3ffc77fe12b5a4d37e8cd4afbfebbf2391ffc7cb07c0f38c023efd',
|
378 | seed: 'Alice//stash',
|
379 | type: 'sr25519'
|
380 | },
|
381 | {
|
382 | p: '0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48',
|
383 | s: '0x081ff694633e255136bdb456c20a5fc8fed21f8b964c11bb17ff534ce80ebd5941ae88f85d0c1bfc37be41c904e1dfc01de8c8067b0d6d5df25dd1ac0894a325',
|
384 | seed: 'Bob',
|
385 | type: 'sr25519'
|
386 | },
|
387 | {
|
388 | p: '0xfe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e',
|
389 | s: '0xc006507cdfc267a21532394c49ca9b754ca71de21e15a1cdf807c7ceab6d0b6c3ed408d9d35311540dcd54931933e67cf1ea10d46f75408f82b789d9bd212fde',
|
390 | seed: 'Bob//stash',
|
391 | type: 'sr25519'
|
392 | },
|
393 | {
|
394 | p: '0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22',
|
395 | s: '0xa8f2d83016052e5d6d77b2f6fd5d59418922a09024cda701b3c34369ec43a7668faf12ff39cd4e5d92bb773972f41a7a5279ebc2ed92264bed8f47d344f8f18c',
|
396 | seed: 'Charlie',
|
397 | type: 'sr25519'
|
398 | },
|
399 | {
|
400 | p: '0x306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc20',
|
401 | s: '0x20e05482ca4677e0edbc58ae9a3a59f6ed3b1a9484ba17e64d6fe8688b2b7b5d108c4487b9323b98b11fe36cb301b084e920f7b7895536809a6d62a451b25568',
|
402 | seed: 'Dave',
|
403 | type: 'sr25519'
|
404 | },
|
405 | {
|
406 | p: '0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e',
|
407 | s: '0x683576abfd5dc35273e4264c23095a1bf21c14517bece57c7f0cc5c0ed4ce06a3dbf386b7828f348abe15d76973a72009e6ef86a5c91db2990cb36bb657c6587',
|
408 | seed: 'Eve',
|
409 | type: 'sr25519'
|
410 | },
|
411 | {
|
412 | p: '0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c',
|
413 | s: '0xb835c20f450079cf4f513900ae9faf8df06ad86c681884122c752a4b2bf74d4303e4f21bc6cc62bb4eeed5a9cce642c25e2d2ac1464093b50f6196d78e3a7426',
|
414 | seed: 'Ferdie',
|
415 | type: 'sr25519'
|
416 | }
|
417 | ];
|
418 | const PAIRSETHEREUM = [
|
419 | {
|
420 | name: 'Alith',
|
421 | p: '0x02509540919faacf9ab52146c9aa40db68172d83777250b28e4679176e49ccdd9f',
|
422 | s: '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133',
|
423 | type: 'ethereum'
|
424 | },
|
425 | {
|
426 | name: 'Baltathar',
|
427 | p: '0x033bc19e36ff1673910575b6727a974a9abd80c9a875d41ab3e2648dbfb9e4b518',
|
428 | s: '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b',
|
429 | type: 'ethereum'
|
430 | },
|
431 | {
|
432 | name: 'Charleth',
|
433 | p: '0x0234637bdc0e89b5d46543bcbf8edff329d2702bc995e27e9af4b1ba009a3c2a5e',
|
434 | s: '0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b',
|
435 | type: 'ethereum'
|
436 | },
|
437 | {
|
438 | name: 'Dorothy',
|
439 | p: '0x02a00d60b2b408c2a14c5d70cdd2c205db8985ef737a7e55ad20ea32cc9e7c417c',
|
440 | s: '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68',
|
441 | type: 'ethereum'
|
442 | },
|
443 | {
|
444 | name: 'Ethan',
|
445 | p: '0x025cdc005b752651cd3f728fb9192182acb3a9c89e19072cbd5b03f3ee1f1b3ffa',
|
446 | s: '0x7dce9bc8babb68fec1409be38c8e1a52650206a7ed90ff956ae8a6d15eeaaef4',
|
447 | type: 'ethereum'
|
448 | },
|
449 | {
|
450 | name: 'Faith',
|
451 | p: '0x037964b6c9d546da4646ada28a99e34acaa1d14e7aba861a9055f9bd200c8abf74',
|
452 | s: '0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df',
|
453 | type: 'ethereum'
|
454 | }
|
455 | ];
|
456 | function createMeta(name, seed) {
|
457 | if (!name && !seed) {
|
458 | throw new Error('Testing pair should have either a name or a seed');
|
459 | }
|
460 | return {
|
461 | isTesting: true,
|
462 | name: name || seed?.replace('//', '_').toLowerCase()
|
463 | };
|
464 | }
|
465 | function createTestKeyring(options = {}, isDerived = true) {
|
466 | const keyring = new Keyring(options);
|
467 | const pairs = options.type === 'ethereum'
|
468 | ? PAIRSETHEREUM
|
469 | : PAIRSSR25519;
|
470 | for (const { name, p, s, seed, type } of pairs) {
|
471 | const meta = createMeta(name, seed);
|
472 | const pair = !isDerived && !name && seed
|
473 | ? keyring.addFromUri(seed, meta, options.type)
|
474 | : keyring.addPair(createPair({ toSS58: keyring.encodeAddress, type }, { publicKey: util.hexToU8a(p), secretKey: util.hexToU8a(s) }, meta));
|
475 | pair.lock = () => {
|
476 | };
|
477 | }
|
478 | return keyring;
|
479 | }
|
480 |
|
481 | const publicKey = new Uint8Array(32);
|
482 | const address = '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM';
|
483 | const meta = {
|
484 | isTesting: true,
|
485 | name: 'nobody'
|
486 | };
|
487 | const json = {
|
488 | address,
|
489 | encoded: '',
|
490 | encoding: {
|
491 | content: ['pkcs8', 'ed25519'],
|
492 | type: 'none',
|
493 | version: '0'
|
494 | },
|
495 | meta
|
496 | };
|
497 | const pair = {
|
498 | address,
|
499 | addressRaw: publicKey,
|
500 | decodePkcs8: (_passphrase, _encoded) => undefined,
|
501 | derive: (_suri, _meta) => pair,
|
502 | encodePkcs8: (_passphrase) => new Uint8Array(0),
|
503 | isLocked: true,
|
504 | lock: () => {
|
505 | },
|
506 | meta,
|
507 | publicKey,
|
508 | setMeta: (_meta) => undefined,
|
509 | sign: (_message) => new Uint8Array(64),
|
510 | toJson: (_passphrase) => json,
|
511 | type: 'ed25519',
|
512 | unlock: (_passphrase) => undefined,
|
513 | verify: (_message, _signature) => false,
|
514 | vrfSign: (_message, _context, _extra) => new Uint8Array(96),
|
515 | vrfVerify: (_message, _vrfResult, _context, _extra) => false
|
516 | };
|
517 | function nobody() {
|
518 | return pair;
|
519 | }
|
520 |
|
521 | function createTestPairs(options, isDerived = true) {
|
522 | const keyring = createTestKeyring(options, isDerived);
|
523 | const pairs = keyring.getPairs();
|
524 | const map = { nobody: nobody() };
|
525 | for (const p of pairs) {
|
526 | if (p.meta.name) {
|
527 | map[p.meta.name] = p;
|
528 | }
|
529 | }
|
530 | return map;
|
531 | }
|
532 |
|
533 | Object.defineProperty(exports, 'decodeAddress', {
|
534 | enumerable: true,
|
535 | get: function () { return utilCrypto.decodeAddress; }
|
536 | });
|
537 | Object.defineProperty(exports, 'encodeAddress', {
|
538 | enumerable: true,
|
539 | get: function () { return utilCrypto.encodeAddress; }
|
540 | });
|
541 | Object.defineProperty(exports, 'setSS58Format', {
|
542 | enumerable: true,
|
543 | get: function () { return utilCrypto.setSS58Format; }
|
544 | });
|
545 | exports.DEV_PHRASE = DEV_PHRASE;
|
546 | exports.DEV_SEED = DEV_SEED;
|
547 | exports.Keyring = Keyring;
|
548 | exports.createPair = createPair;
|
549 | exports.createTestKeyring = createTestKeyring;
|
550 | exports.createTestPairs = createTestPairs;
|
551 | exports.packageInfo = packageInfo;
|
552 |
|
553 | }));
|