@pezkuwi/keyring 14.0.10 → 14.0.11

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.
Files changed (71) hide show
  1. package/bundle-pezkuwi-keyring.js +553 -0
  2. package/bundle.d.ts +7 -0
  3. package/bundle.js +7 -0
  4. package/cjs/bundle.d.ts +7 -0
  5. package/cjs/bundle.js +19 -0
  6. package/cjs/defaults.d.ts +2 -0
  7. package/cjs/defaults.js +5 -0
  8. package/cjs/index.d.ts +4 -0
  9. package/cjs/index.js +7 -0
  10. package/cjs/keyring.d.ts +145 -0
  11. package/cjs/keyring.js +261 -0
  12. package/cjs/package.json +3 -0
  13. package/cjs/packageDetect.d.ts +1 -0
  14. package/cjs/packageDetect.js +7 -0
  15. package/cjs/packageInfo.d.ts +6 -0
  16. package/cjs/packageInfo.js +4 -0
  17. package/cjs/pair/decode.d.ts +12 -0
  18. package/cjs/pair/decode.js +45 -0
  19. package/cjs/pair/defaults.d.ts +12 -0
  20. package/cjs/pair/defaults.js +15 -0
  21. package/cjs/pair/encode.d.ts +5 -0
  22. package/cjs/pair/encode.js +22 -0
  23. package/cjs/pair/index.d.ts +40 -0
  24. package/cjs/pair/index.js +183 -0
  25. package/cjs/pair/nobody.d.ts +2 -0
  26. package/cjs/pair/nobody.js +43 -0
  27. package/cjs/pair/toJson.d.ts +8 -0
  28. package/cjs/pair/toJson.js +11 -0
  29. package/cjs/pair/types.d.ts +5 -0
  30. package/cjs/pair/types.js +2 -0
  31. package/cjs/pairs.d.ts +8 -0
  32. package/cjs/pairs.js +28 -0
  33. package/cjs/testing.d.ts +20 -0
  34. package/cjs/testing.js +126 -0
  35. package/cjs/testingPairs.d.ts +25 -0
  36. package/cjs/testingPairs.js +16 -0
  37. package/cjs/types.d.ts +111 -0
  38. package/cjs/types.js +2 -0
  39. package/defaults.d.ts +2 -0
  40. package/defaults.js +2 -0
  41. package/index.d.ts +4 -0
  42. package/index.js +4 -0
  43. package/keyring.d.ts +145 -0
  44. package/keyring.js +257 -0
  45. package/package.json +270 -8
  46. package/packageDetect.d.ts +1 -0
  47. package/packageDetect.js +5 -0
  48. package/packageInfo.d.ts +6 -0
  49. package/packageInfo.js +1 -0
  50. package/pair/decode.d.ts +12 -0
  51. package/pair/decode.js +42 -0
  52. package/pair/defaults.d.ts +12 -0
  53. package/pair/defaults.js +12 -0
  54. package/pair/encode.d.ts +5 -0
  55. package/pair/encode.js +19 -0
  56. package/pair/index.d.ts +40 -0
  57. package/pair/index.js +180 -0
  58. package/pair/nobody.d.ts +2 -0
  59. package/pair/nobody.js +40 -0
  60. package/pair/toJson.d.ts +8 -0
  61. package/pair/toJson.js +8 -0
  62. package/pair/types.d.ts +5 -0
  63. package/pair/types.js +1 -0
  64. package/pairs.d.ts +8 -0
  65. package/pairs.js +24 -0
  66. package/testing.d.ts +20 -0
  67. package/testing.js +122 -0
  68. package/testingPairs.d.ts +25 -0
  69. package/testingPairs.js +13 -0
  70. package/types.d.ts +111 -0
  71. package/types.js +1 -0
@@ -0,0 +1,553 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@pezkuwi/util-crypto'), require('@pezkuwi/util')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@pezkuwi/util-crypto', '@pezkuwi/util'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pezkuwiKeyring = {}, global.pezkuwiUtilCrypto, global.pezkuwiUtil));
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 PAIR_DIV = new Uint8Array([161, 35, 3, 33, 0]);
11
+ const PAIR_HDR = 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 = PAIR_HDR.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, PAIR_HDR.length);
23
+ if (!util.u8aEq(header, PAIR_HDR)) {
24
+ throw new Error('Invalid encoding 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 + PAIR_DIV.length);
29
+ if (!util.u8aEq(divider, PAIR_DIV)) {
30
+ divOffset = SEED_OFFSET + SEED_LENGTH;
31
+ secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
32
+ divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
33
+ if (!util.u8aEq(divider, PAIR_DIV)) {
34
+ throw new Error('Invalid encoding divider found in body');
35
+ }
36
+ }
37
+ const pubOffset = divOffset + PAIR_DIV.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(PAIR_HDR, secretKey, PAIR_DIV, 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
+ #map = {};
211
+ add(pair) {
212
+ this.#map[utilCrypto.decodeAddress(pair.address).toString()] = pair;
213
+ return pair;
214
+ }
215
+ all() {
216
+ return Object.values(this.#map);
217
+ }
218
+ get(address) {
219
+ const pair = this.#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.#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
+ #pairs;
243
+ #type;
244
+ #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.#pairs = new Pairs();
252
+ this.#ss58 = options.ss58Format;
253
+ this.#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.#type;
263
+ }
264
+ addPair(pair) {
265
+ return this.#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, wordlist) {
275
+ return this.addFromUri(mnemonic, meta, type, wordlist);
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, wordlist) {
284
+ return this.addPair(this.createFromUri(suri, meta, type, wordlist));
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, wordlist) {
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, wordlist);
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.#ss58);
345
+ };
346
+ getPair(address) {
347
+ return this.#pairs.get(address);
348
+ }
349
+ getPairs() {
350
+ return this.#pairs.all();
351
+ }
352
+ getPublicKeys() {
353
+ return this.#pairs.all().map(pairToPublic);
354
+ }
355
+ removePair(address) {
356
+ this.#pairs.remove(address);
357
+ }
358
+ setSS58Format(ss58) {
359
+ this.#ss58 = ss58;
360
+ }
361
+ toJson(address, passphrase) {
362
+ return this.#pairs.get(address).toJson(passphrase);
363
+ }
364
+ }
365
+
366
+ const packageInfo = { name: '@pezkuwi/keyring', path: (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-pezkuwi-keyring.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-pezkuwi-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.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-pezkuwi-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.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-pezkuwi-keyring.js', document.baseURI).href))).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '14.0.10' };
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
+ }));
package/bundle.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { decodeAddress, encodeAddress, setSS58Format } from '@pezkuwi/util-crypto';
2
+ export { Keyring } from './keyring.js';
3
+ export { packageInfo } from './packageInfo.js';
4
+ export { createPair } from './pair/index.js';
5
+ export { createTestKeyring } from './testing.js';
6
+ export { createTestPairs } from './testingPairs.js';
7
+ export * from './defaults.js';
package/bundle.js ADDED
@@ -0,0 +1,7 @@
1
+ export { decodeAddress, encodeAddress, setSS58Format } from '@pezkuwi/util-crypto';
2
+ export { Keyring } from './keyring.js';
3
+ export { packageInfo } from './packageInfo.js';
4
+ export { createPair } from './pair/index.js';
5
+ export { createTestKeyring } from './testing.js';
6
+ export { createTestPairs } from './testingPairs.js';
7
+ export * from './defaults.js';
@@ -0,0 +1,7 @@
1
+ export { decodeAddress, encodeAddress, setSS58Format } from '@pezkuwi/util-crypto';
2
+ export { Keyring } from './keyring.js';
3
+ export { packageInfo } from './packageInfo.js';
4
+ export { createPair } from './pair/index.js';
5
+ export { createTestKeyring } from './testing.js';
6
+ export { createTestPairs } from './testingPairs.js';
7
+ export * from './defaults.js';
package/cjs/bundle.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTestPairs = exports.createTestKeyring = exports.createPair = exports.packageInfo = exports.Keyring = exports.setSS58Format = exports.encodeAddress = exports.decodeAddress = void 0;
4
+ const tslib_1 = require("tslib");
5
+ var util_crypto_1 = require("@pezkuwi/util-crypto");
6
+ Object.defineProperty(exports, "decodeAddress", { enumerable: true, get: function () { return util_crypto_1.decodeAddress; } });
7
+ Object.defineProperty(exports, "encodeAddress", { enumerable: true, get: function () { return util_crypto_1.encodeAddress; } });
8
+ Object.defineProperty(exports, "setSS58Format", { enumerable: true, get: function () { return util_crypto_1.setSS58Format; } });
9
+ var keyring_js_1 = require("./keyring.js");
10
+ Object.defineProperty(exports, "Keyring", { enumerable: true, get: function () { return keyring_js_1.Keyring; } });
11
+ var packageInfo_js_1 = require("./packageInfo.js");
12
+ Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
13
+ var index_js_1 = require("./pair/index.js");
14
+ Object.defineProperty(exports, "createPair", { enumerable: true, get: function () { return index_js_1.createPair; } });
15
+ var testing_js_1 = require("./testing.js");
16
+ Object.defineProperty(exports, "createTestKeyring", { enumerable: true, get: function () { return testing_js_1.createTestKeyring; } });
17
+ var testingPairs_js_1 = require("./testingPairs.js");
18
+ Object.defineProperty(exports, "createTestPairs", { enumerable: true, get: function () { return testingPairs_js_1.createTestPairs; } });
19
+ tslib_1.__exportStar(require("./defaults.js"), exports);
@@ -0,0 +1,2 @@
1
+ export declare const DEV_PHRASE = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
2
+ export declare const DEV_SEED = "0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEV_SEED = exports.DEV_PHRASE = void 0;
4
+ exports.DEV_PHRASE = 'bottom drive obey lake curtain smoke basket hold race lonely fit walk';
5
+ exports.DEV_SEED = '0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e';
package/cjs/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import './packageDetect.js';
2
+ import { Keyring } from './bundle.js';
3
+ export * from './bundle.js';
4
+ export default Keyring;
package/cjs/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ require("./packageDetect.js");
5
+ const bundle_js_1 = require("./bundle.js");
6
+ tslib_1.__exportStar(require("./bundle.js"), exports);
7
+ exports.default = bundle_js_1.Keyring;