@prosopo/keyring 2.8.6 → 2.8.7

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 (96) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/accounts/getPair.js +33 -32
  3. package/dist/accounts/index.js +10 -4
  4. package/dist/accounts/mnemonic.js +15 -12
  5. package/dist/accounts/testAccounts.js +41 -35
  6. package/dist/cjs/accounts/getPair.cjs +2 -2
  7. package/dist/cjs/accounts/mnemonic.cjs +1 -2
  8. package/dist/index.js +19 -4
  9. package/dist/keyring/index.js +7 -3
  10. package/dist/keyring/keyring.js +255 -130
  11. package/dist/keyring/pairs.js +24 -27
  12. package/dist/pair/decode.js +26 -24
  13. package/dist/pair/defaults.js +30 -8
  14. package/dist/pair/encode.js +16 -14
  15. package/dist/pair/index.js +139 -134
  16. package/dist/pair/toJson.js +11 -6
  17. package/package.json +18 -14
  18. package/vite.cjs.config.ts +4 -1
  19. package/vite.esm.config.ts +20 -0
  20. package/vite.test.config.ts +32 -0
  21. package/dist/accounts/getPair.d.ts +0 -5
  22. package/dist/accounts/getPair.d.ts.map +0 -1
  23. package/dist/accounts/getPair.js.map +0 -1
  24. package/dist/accounts/index.d.ts +0 -4
  25. package/dist/accounts/index.d.ts.map +0 -1
  26. package/dist/accounts/index.js.map +0 -1
  27. package/dist/accounts/mnemonic.d.ts +0 -5
  28. package/dist/accounts/mnemonic.d.ts.map +0 -1
  29. package/dist/accounts/mnemonic.js.map +0 -1
  30. package/dist/accounts/testAccounts.d.ts +0 -4
  31. package/dist/accounts/testAccounts.d.ts.map +0 -1
  32. package/dist/accounts/testAccounts.js.map +0 -1
  33. package/dist/cjs/dist/accounts/getPair.cjs +0 -41
  34. package/dist/cjs/dist/accounts/index.cjs +0 -10
  35. package/dist/cjs/dist/accounts/mnemonic.cjs +0 -19
  36. package/dist/cjs/dist/accounts/testAccounts.cjs +0 -42
  37. package/dist/cjs/dist/index.cjs +0 -6
  38. package/dist/cjs/dist/keyring/index.cjs +0 -7
  39. package/dist/cjs/dist/keyring/keyring.cjs +0 -138
  40. package/dist/cjs/dist/keyring/pairs.cjs +0 -31
  41. package/dist/cjs/dist/pair/decode.cjs +0 -32
  42. package/dist/cjs/dist/pair/defaults.cjs +0 -31
  43. package/dist/cjs/dist/pair/encode.cjs +0 -18
  44. package/dist/cjs/dist/pair/index.cjs +0 -143
  45. package/dist/cjs/dist/pair/toJson.cjs +0 -11
  46. package/dist/index.d.ts +0 -4
  47. package/dist/index.d.ts.map +0 -1
  48. package/dist/index.js.map +0 -1
  49. package/dist/keyring/index.d.ts +0 -3
  50. package/dist/keyring/index.d.ts.map +0 -1
  51. package/dist/keyring/index.js.map +0 -1
  52. package/dist/keyring/keyring.d.ts +0 -36
  53. package/dist/keyring/keyring.d.ts.map +0 -1
  54. package/dist/keyring/keyring.js.map +0 -1
  55. package/dist/keyring/pairs.d.ts +0 -9
  56. package/dist/keyring/pairs.d.ts.map +0 -1
  57. package/dist/keyring/pairs.js.map +0 -1
  58. package/dist/keyring/testing.d.ts +0 -14
  59. package/dist/keyring/testing.d.ts.map +0 -1
  60. package/dist/keyring/testing.js +0 -76
  61. package/dist/keyring/testing.js.map +0 -1
  62. package/dist/keyring/testingPairs.d.ts +0 -26
  63. package/dist/keyring/testingPairs.d.ts.map +0 -1
  64. package/dist/keyring/testingPairs.js +0 -14
  65. package/dist/keyring/testingPairs.js.map +0 -1
  66. package/dist/pair/decode.d.ts +0 -6
  67. package/dist/pair/decode.d.ts.map +0 -1
  68. package/dist/pair/decode.js.map +0 -1
  69. package/dist/pair/decode.spec.d.ts +0 -2
  70. package/dist/pair/decode.spec.d.ts.map +0 -1
  71. package/dist/pair/decode.spec.js +0 -13
  72. package/dist/pair/decode.spec.js.map +0 -1
  73. package/dist/pair/defaults.d.ts +0 -7
  74. package/dist/pair/defaults.d.ts.map +0 -1
  75. package/dist/pair/defaults.js.map +0 -1
  76. package/dist/pair/encode.d.ts +0 -3
  77. package/dist/pair/encode.d.ts.map +0 -1
  78. package/dist/pair/encode.js.map +0 -1
  79. package/dist/pair/encode.spec.d.ts +0 -2
  80. package/dist/pair/encode.spec.d.ts.map +0 -1
  81. package/dist/pair/encode.spec.js +0 -16
  82. package/dist/pair/encode.spec.js.map +0 -1
  83. package/dist/pair/index.d.ts +0 -11
  84. package/dist/pair/index.d.ts.map +0 -1
  85. package/dist/pair/index.js.map +0 -1
  86. package/dist/pair/nobody.d.ts +0 -3
  87. package/dist/pair/nobody.d.ts.map +0 -1
  88. package/dist/pair/nobody.js +0 -40
  89. package/dist/pair/nobody.js.map +0 -1
  90. package/dist/pair/toJson.d.ts +0 -9
  91. package/dist/pair/toJson.d.ts.map +0 -1
  92. package/dist/pair/toJson.js.map +0 -1
  93. package/dist/pair/toJson.spec.d.ts +0 -2
  94. package/dist/pair/toJson.spec.d.ts.map +0 -1
  95. package/dist/pair/toJson.spec.js +0 -33
  96. package/dist/pair/toJson.spec.js.map +0 -1
@@ -1,146 +1,271 @@
1
- var _Keyring_pairs, _Keyring_type, _Keyring_ss58;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
1
  import { stringToU8a } from "@polkadot/util";
4
2
  import { hexToU8a } from "@polkadot/util/hex";
5
3
  import { isHex } from "@polkadot/util/is";
6
- import { decodeAddress, mnemonicToMiniSecret } from "@prosopo/util-crypto";
7
- import { encodeAddress } from "@prosopo/util-crypto";
8
- import { base64Decode } from "@prosopo/util-crypto";
9
- import { sr25519FromSeed } from "@prosopo/util-crypto";
10
- import { keyExtractSuri, keyFromPath } from "@prosopo/util-crypto";
4
+ import { sr25519FromSeed, decodeAddress, encodeAddress, base64Decode, keyExtractSuri, mnemonicToMiniSecret, keyFromPath } from "@prosopo/util-crypto";
11
5
  import { createPair } from "../pair/index.js";
12
6
  import { Pairs } from "./pairs.js";
13
- export const DEV_PHRASE = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
7
+ const DEV_PHRASE = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
14
8
  const PairFromSeed = {
15
- sr25519: (seed) => sr25519FromSeed(seed),
16
- ed25519: () => {
17
- throw new Error("Not Implemented");
18
- },
19
- ecdsa: () => {
20
- throw new Error("Not Implemented");
21
- },
22
- ethereum: () => {
23
- throw new Error("Not Implemented");
24
- },
9
+ sr25519: (seed) => sr25519FromSeed(seed),
10
+ ed25519: () => {
11
+ throw new Error("Not Implemented");
12
+ },
13
+ ecdsa: () => {
14
+ throw new Error("Not Implemented");
15
+ },
16
+ ethereum: () => {
17
+ throw new Error("Not Implemented");
18
+ }
25
19
  };
26
20
  function pairToPublic({ publicKey }) {
27
- return publicKey;
21
+ return publicKey;
28
22
  }
29
- export class Keyring {
30
- constructor(options = {}) {
31
- _Keyring_pairs.set(this, void 0);
32
- _Keyring_type.set(this, void 0);
33
- _Keyring_ss58.set(this, void 0);
34
- this.decodeAddress = decodeAddress;
35
- this.encodeAddress = (address, ss58Format) => {
36
- return encodeAddress(address, ss58Format ?? __classPrivateFieldGet(this, _Keyring_ss58, "f"));
37
- };
38
- options.type = options.type || "sr25519";
39
- if (!["sr25519"].includes(options.type || "undefined")) {
40
- throw new Error(`Expected a keyring type of either 'sr25519', found '${options.type || "unknown"}`);
41
- }
42
- __classPrivateFieldSet(this, _Keyring_pairs, new Pairs(), "f");
43
- __classPrivateFieldSet(this, _Keyring_ss58, options.ss58Format, "f");
44
- __classPrivateFieldSet(this, _Keyring_type, options.type, "f");
45
- }
46
- get pairs() {
47
- return this.getPairs();
48
- }
49
- get publicKeys() {
50
- return this.getPublicKeys();
51
- }
52
- get type() {
53
- return __classPrivateFieldGet(this, _Keyring_type, "f");
54
- }
55
- addPair(pair) {
56
- return __classPrivateFieldGet(this, _Keyring_pairs, "f").add(pair);
57
- }
58
- addFromAddress(address, meta = {}, encoded = null, type = this.type, ignoreChecksum, encType) {
59
- const publicKey = this.decodeAddress(address, ignoreChecksum);
60
- return this.addPair(createPair({ toSS58: this.encodeAddress, type }, { publicKey, secretKey: new Uint8Array() }, meta, encoded, encType));
23
+ class Keyring {
24
+ constructor(options = {}) {
25
+ this.decodeAddress = decodeAddress;
26
+ this.encodeAddress = (address, ss58Format) => {
27
+ return encodeAddress(address, ss58Format ?? this.#ss58);
28
+ };
29
+ options.type = options.type || "sr25519";
30
+ if (!["sr25519"].includes(options.type || "undefined")) {
31
+ throw new Error(
32
+ `Expected a keyring type of either 'sr25519', found '${options.type || "unknown"}`
33
+ );
61
34
  }
62
- addFromJson(json, ignoreChecksum) {
63
- return this.addPair(this.createFromJson(json, ignoreChecksum));
35
+ this.#pairs = new Pairs();
36
+ this.#ss58 = options.ss58Format;
37
+ this.#type = options.type;
38
+ }
39
+ #pairs;
40
+ #type;
41
+ #ss58;
42
+ /**
43
+ * @description retrieve the pairs (alias for getPairs)
44
+ */
45
+ get pairs() {
46
+ return this.getPairs();
47
+ }
48
+ /**
49
+ * @description retrieve the publicKeys (alias for getPublicKeys)
50
+ */
51
+ get publicKeys() {
52
+ return this.getPublicKeys();
53
+ }
54
+ /**
55
+ * @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
56
+ */
57
+ get type() {
58
+ return this.#type;
59
+ }
60
+ /**
61
+ * @name addPair
62
+ * @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
63
+ */
64
+ addPair(pair) {
65
+ return this.#pairs.add(pair);
66
+ }
67
+ /**
68
+ * @name addFromAddress
69
+ * @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
70
+ * @description Allows user to explicitly provide separate inputs including account address or public key, and optionally
71
+ * the associated account metadata, and the default encoded value as arguments (that may be obtained from the json file
72
+ * of an account backup), and then generates a keyring pair from them that it passes to
73
+ * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
74
+ */
75
+ addFromAddress(address, meta = {}, encoded = null, type = this.type, ignoreChecksum, encType) {
76
+ const publicKey = this.decodeAddress(address, ignoreChecksum);
77
+ return this.addPair(
78
+ createPair(
79
+ { toSS58: this.encodeAddress, type },
80
+ { publicKey, secretKey: new Uint8Array() },
81
+ meta,
82
+ encoded,
83
+ encType
84
+ )
85
+ );
86
+ }
87
+ /**
88
+ * @name addFromJson
89
+ * @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
90
+ * @description Allows user to provide a json object argument that contains account information (that may be obtained from the json file
91
+ * of an account backup), and then generates a keyring pair from it that it passes to
92
+ * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
93
+ */
94
+ addFromJson(json, ignoreChecksum) {
95
+ return this.addPair(this.createFromJson(json, ignoreChecksum));
96
+ }
97
+ /**
98
+ * @name addFromMnemonic
99
+ * @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
100
+ * @description Allows user to provide a mnemonic (seed phrase that is provided when account is originally created)
101
+ * argument and a metadata argument that contains account information (that may be obtained from the json file
102
+ * of an account backup), and then generates a keyring pair from it that it passes to
103
+ * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
104
+ */
105
+ addFromMnemonic(mnemonic, meta = {}, type = this.type) {
106
+ return this.addFromUri(mnemonic, meta, type);
107
+ }
108
+ /**
109
+ * @name addFromPair
110
+ * @summary Stores an account created from an explicit publicKey/secreteKey combination
111
+ */
112
+ addFromPair(pair, meta = {}, type = this.type) {
113
+ return this.addPair(this.createFromPair(pair, meta, type));
114
+ }
115
+ /**
116
+ * @name addFromSeed
117
+ * @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
118
+ * @description Stores in a keyring pair dictionary the public key of the pair as a key and the pair as the associated value.
119
+ * Allows user to provide the account seed as an argument, and then generates a keyring pair from it that it passes to
120
+ * `addPair` to store in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
121
+ */
122
+ addFromSeed(seed, meta = {}, type = this.type) {
123
+ return this.addPair(
124
+ createPair(
125
+ { toSS58: this.encodeAddress, type },
126
+ PairFromSeed[type](seed),
127
+ meta,
128
+ null
129
+ )
130
+ );
131
+ }
132
+ /**
133
+ * @name addFromUri
134
+ * @summary Creates an account via an suri
135
+ * @description Extracts the phrase, path and password from a SURI format for specifying secret keys `<secret>/<soft-key>//<hard-key>///<password>` (the `///password` may be omitted, and `/<soft-key>` and `//<hard-key>` maybe repeated and mixed). The secret can be a hex string, mnemonic phrase or a string (to be padded)
136
+ */
137
+ addFromUri(suri, meta = {}, type = this.type) {
138
+ return this.addPair(this.createFromUri(suri, meta, type));
139
+ }
140
+ /**
141
+ * @name createFromJson
142
+ * @description Creates a pair from a JSON keyfile
143
+ */
144
+ createFromJson({
145
+ address,
146
+ encoded,
147
+ encoding: { content, type, version },
148
+ meta
149
+ }, ignoreChecksum) {
150
+ if (version === "3" && content[0] !== "pkcs8") {
151
+ throw new Error(
152
+ `Unable to decode non-pkcs8 type, [${content.join(",")}] found}`
153
+ );
64
154
  }
65
- addFromMnemonic(mnemonic, meta = {}, type = this.type) {
66
- return this.addFromUri(mnemonic, meta, type);
155
+ const cryptoType = version === "0" || !Array.isArray(content) ? this.type : content[1];
156
+ if (!cryptoType) {
157
+ throw new Error("cryptoType is undefined");
67
158
  }
68
- addFromPair(pair, meta = {}, type = this.type) {
69
- return this.addPair(this.createFromPair(pair, meta, type));
159
+ const encType = !Array.isArray(type) ? [type] : type;
160
+ if (!["sr25519"].includes(cryptoType)) {
161
+ throw new Error(`Unknown crypto type ${cryptoType}`);
70
162
  }
71
- addFromSeed(seed, meta = {}, type = this.type) {
72
- return this.addPair(createPair({ toSS58: this.encodeAddress, type }, PairFromSeed[type](seed), meta, null));
73
- }
74
- addFromUri(suri, meta = {}, type = this.type) {
75
- return this.addPair(this.createFromUri(suri, meta, type));
76
- }
77
- createFromJson({ address, encoded, encoding: { content, type, version }, meta, }, ignoreChecksum) {
78
- if (version === "3" && content[0] !== "pkcs8") {
79
- throw new Error(`Unable to decode non-pkcs8 type, [${content.join(",")}] found}`);
80
- }
81
- const cryptoType = version === "0" || !Array.isArray(content) ? this.type : content[1];
82
- if (!cryptoType) {
83
- throw new Error("cryptoType is undefined");
163
+ const publicKey = isHex(address) ? hexToU8a(address) : this.decodeAddress(address, ignoreChecksum);
164
+ const decoded = isHex(encoded) ? hexToU8a(encoded) : base64Decode(encoded);
165
+ return createPair(
166
+ { toSS58: this.encodeAddress, type: cryptoType },
167
+ { publicKey, secretKey: new Uint8Array() },
168
+ meta,
169
+ decoded,
170
+ encType
171
+ );
172
+ }
173
+ /**
174
+ * @name createFromPair
175
+ * @summary Creates a pair from an explicit publicKey/secreteKey combination
176
+ */
177
+ createFromPair(pair, meta = {}, type = this.type) {
178
+ return createPair({ toSS58: this.encodeAddress, type }, pair, meta, null);
179
+ }
180
+ /**
181
+ * @name createFromUri
182
+ * @summary Creates a Keypair from an suri
183
+ * @description This creates a pair from the suri, but does not add it to the keyring
184
+ */
185
+ createFromUri(_suri, meta = {}, type = this.type) {
186
+ const suri = _suri.startsWith("//") ? `${DEV_PHRASE}${_suri}` : _suri;
187
+ const { derivePath, password, path, phrase } = keyExtractSuri(suri);
188
+ let seed;
189
+ const isPhraseHex = isHex(phrase, 256);
190
+ if (isPhraseHex) {
191
+ seed = hexToU8a(phrase);
192
+ } else {
193
+ const parts = phrase.split(" ");
194
+ if ([12, 15, 18, 21, 24].includes(parts.length)) {
195
+ seed = type === "ethereum" ? (() => {
196
+ throw new Error(
197
+ "Not implemented - Prosopo Keyring supports sr25519 only"
198
+ );
199
+ })() : mnemonicToMiniSecret(phrase, password);
200
+ } else {
201
+ if (phrase.length > 32) {
202
+ throw new Error(
203
+ "specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes"
204
+ );
84
205
  }
85
- const encType = !Array.isArray(type) ? [type] : type;
86
- if (!["sr25519"].includes(cryptoType)) {
87
- throw new Error(`Unknown crypto type ${cryptoType}`);
88
- }
89
- const publicKey = isHex(address)
90
- ? hexToU8a(address)
91
- : this.decodeAddress(address, ignoreChecksum);
92
- const decoded = isHex(encoded) ? hexToU8a(encoded) : base64Decode(encoded);
93
- return createPair({ toSS58: this.encodeAddress, type: cryptoType }, { publicKey, secretKey: new Uint8Array() }, meta, decoded, encType);
94
- }
95
- createFromPair(pair, meta = {}, type = this.type) {
96
- return createPair({ toSS58: this.encodeAddress, type }, pair, meta, null);
97
- }
98
- createFromUri(_suri, meta = {}, type = this.type) {
99
- const suri = _suri.startsWith("//") ? `${DEV_PHRASE}${_suri}` : _suri;
100
- const { derivePath, password, path, phrase } = keyExtractSuri(suri);
101
- let seed;
102
- const isPhraseHex = isHex(phrase, 256);
103
- if (isPhraseHex) {
104
- seed = hexToU8a(phrase);
105
- }
106
- else {
107
- const parts = phrase.split(" ");
108
- if ([12, 15, 18, 21, 24].includes(parts.length)) {
109
- seed =
110
- type === "ethereum"
111
- ? (() => {
112
- throw new Error("Not implemented - Prosopo Keyring supports sr25519 only");
113
- })()
114
- : mnemonicToMiniSecret(phrase, password);
115
- }
116
- else {
117
- if (phrase.length > 32) {
118
- throw new Error("specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes");
119
- }
120
- seed = stringToU8a(phrase.padEnd(32));
121
- }
122
- }
123
- const derived = keyFromPath(PairFromSeed[type](seed), path, type);
124
- return createPair({ toSS58: this.encodeAddress, type }, derived, meta, null);
125
- }
126
- getPair(address) {
127
- return __classPrivateFieldGet(this, _Keyring_pairs, "f").get(address);
128
- }
129
- getPairs() {
130
- return __classPrivateFieldGet(this, _Keyring_pairs, "f").all();
131
- }
132
- getPublicKeys() {
133
- return __classPrivateFieldGet(this, _Keyring_pairs, "f").all().map(pairToPublic);
134
- }
135
- removePair(address) {
136
- __classPrivateFieldGet(this, _Keyring_pairs, "f").remove(address);
137
- }
138
- setSS58Format(ss58) {
139
- __classPrivateFieldSet(this, _Keyring_ss58, ss58, "f");
140
- }
141
- toJson(address, passphrase) {
142
- return __classPrivateFieldGet(this, _Keyring_pairs, "f").get(address).toJson(passphrase);
206
+ seed = stringToU8a(phrase.padEnd(32));
207
+ }
143
208
  }
209
+ const derived = keyFromPath(PairFromSeed[type](seed), path, type);
210
+ return createPair(
211
+ { toSS58: this.encodeAddress, type },
212
+ derived,
213
+ meta,
214
+ null
215
+ );
216
+ }
217
+ /**
218
+ * @name getPair
219
+ * @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
220
+ * @description Returns a keyring pair value from the keyring pair dictionary by performing
221
+ * a key lookup using the provided account address or public key (after decoding it).
222
+ */
223
+ getPair(address) {
224
+ return this.#pairs.get(address);
225
+ }
226
+ /**
227
+ * @name getPairs
228
+ * @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
229
+ * @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
230
+ */
231
+ getPairs() {
232
+ return this.#pairs.all();
233
+ }
234
+ /**
235
+ * @name getPublicKeys
236
+ * @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
237
+ * @description Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.
238
+ */
239
+ getPublicKeys() {
240
+ return this.#pairs.all().map(pairToPublic);
241
+ }
242
+ /**
243
+ * @name removePair
244
+ * @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
245
+ */
246
+ removePair(address) {
247
+ this.#pairs.remove(address);
248
+ }
249
+ /**
250
+ * @name setSS58Format;
251
+ * @description Sets the ss58 format for the keyring
252
+ */
253
+ setSS58Format(ss58) {
254
+ this.#ss58 = ss58;
255
+ }
256
+ /**
257
+ * @name toJson
258
+ * @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
259
+ * @description Returns a JSON object containing the metadata associated with an account
260
+ * when valid address or public key and when the account passphrase is provided if the account secret
261
+ * is not already unlocked and available in memory. Note that in [Polkadot-JS Apps](https://github.com/polkadot-js/apps) the user
262
+ * may backup their account to a JSON file that contains this information.
263
+ */
264
+ toJson(address, passphrase) {
265
+ return this.#pairs.get(address).toJson(passphrase);
266
+ }
144
267
  }
145
- _Keyring_pairs = new WeakMap(), _Keyring_type = new WeakMap(), _Keyring_ss58 = new WeakMap();
146
- //# sourceMappingURL=keyring.js.map
268
+ export {
269
+ DEV_PHRASE,
270
+ Keyring
271
+ };
@@ -1,31 +1,28 @@
1
- var _Pairs_map;
2
- import { __classPrivateFieldGet } from "tslib";
3
- import { isHex, isU8a, u8aToU8a } from "@polkadot/util";
1
+ import { isU8a, isHex, u8aToU8a } from "@polkadot/util";
4
2
  import { u8aToHex } from "@prosopo/util";
5
3
  import { decodeAddress } from "@prosopo/util-crypto";
6
- export class Pairs {
7
- constructor() {
8
- _Pairs_map.set(this, {});
9
- }
10
- add(pair) {
11
- __classPrivateFieldGet(this, _Pairs_map, "f")[decodeAddress(pair.address).toString()] = pair;
12
- return pair;
13
- }
14
- all() {
15
- return Object.values(__classPrivateFieldGet(this, _Pairs_map, "f"));
16
- }
17
- get(address) {
18
- const pair = __classPrivateFieldGet(this, _Pairs_map, "f")[decodeAddress(address).toString()];
19
- if (!pair) {
20
- throw new Error(`Unable to retrieve keypair '${isU8a(address) || isHex(address)
21
- ? u8aToHex(u8aToU8a(address))
22
- : address}'`);
23
- }
24
- return pair;
25
- }
26
- remove(address) {
27
- delete __classPrivateFieldGet(this, _Pairs_map, "f")[decodeAddress(address).toString()];
4
+ class Pairs {
5
+ #map = {};
6
+ add(pair) {
7
+ this.#map[decodeAddress(pair.address).toString()] = pair;
8
+ return pair;
9
+ }
10
+ all() {
11
+ return Object.values(this.#map);
12
+ }
13
+ get(address) {
14
+ const pair = this.#map[decodeAddress(address).toString()];
15
+ if (!pair) {
16
+ throw new Error(
17
+ `Unable to retrieve keypair '${isU8a(address) || isHex(address) ? u8aToHex(u8aToU8a(address)) : address}'`
18
+ );
28
19
  }
20
+ return pair;
21
+ }
22
+ remove(address) {
23
+ delete this.#map[decodeAddress(address).toString()];
24
+ }
29
25
  }
30
- _Pairs_map = new WeakMap();
31
- //# sourceMappingURL=pairs.js.map
26
+ export {
27
+ Pairs
28
+ };
@@ -1,30 +1,32 @@
1
1
  import { u8aEq } from "@polkadot/util";
2
2
  import { jsonDecryptData } from "@prosopo/util-crypto";
3
- import { PAIR_DIV, PAIR_HDR, PUB_LENGTH, SEC_LENGTH, SEED_LENGTH, } from "./defaults.js";
3
+ import { PAIR_HDR, SEC_LENGTH, PAIR_DIV, SEED_LENGTH, PUB_LENGTH } from "./defaults.js";
4
4
  const SEED_OFFSET = PAIR_HDR.length;
5
- export function decodePair(passphrase, encrypted, _encType) {
6
- const encType = Array.isArray(_encType) || _encType === undefined ? _encType : [_encType];
7
- const decrypted = jsonDecryptData(encrypted, passphrase, encType);
8
- const header = decrypted.subarray(0, PAIR_HDR.length);
9
- if (!u8aEq(header, PAIR_HDR)) {
10
- throw new Error("Invalid encoding header found in body");
11
- }
12
- let secretKey = decrypted.subarray(SEED_OFFSET, SEED_OFFSET + SEC_LENGTH);
13
- let divOffset = SEED_OFFSET + SEC_LENGTH;
14
- let divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
5
+ function decodePair(passphrase, encrypted, _encType) {
6
+ const encType = Array.isArray(_encType) || _encType === void 0 ? _encType : [_encType];
7
+ const decrypted = jsonDecryptData(encrypted, passphrase, encType);
8
+ const header = decrypted.subarray(0, PAIR_HDR.length);
9
+ if (!u8aEq(header, PAIR_HDR)) {
10
+ throw new Error("Invalid encoding header found in body");
11
+ }
12
+ let secretKey = decrypted.subarray(SEED_OFFSET, SEED_OFFSET + SEC_LENGTH);
13
+ let divOffset = SEED_OFFSET + SEC_LENGTH;
14
+ let divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
15
+ if (!u8aEq(divider, PAIR_DIV)) {
16
+ divOffset = SEED_OFFSET + SEED_LENGTH;
17
+ secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
18
+ divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
15
19
  if (!u8aEq(divider, PAIR_DIV)) {
16
- divOffset = SEED_OFFSET + SEED_LENGTH;
17
- secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
18
- divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
19
- if (!u8aEq(divider, PAIR_DIV)) {
20
- throw new Error("Invalid encoding divider found in body");
21
- }
20
+ throw new Error("Invalid encoding divider found in body");
22
21
  }
23
- const pubOffset = divOffset + PAIR_DIV.length;
24
- const publicKey = decrypted.subarray(pubOffset, pubOffset + PUB_LENGTH);
25
- return {
26
- publicKey,
27
- secretKey,
28
- };
22
+ }
23
+ const pubOffset = divOffset + PAIR_DIV.length;
24
+ const publicKey = decrypted.subarray(pubOffset, pubOffset + PUB_LENGTH);
25
+ return {
26
+ publicKey,
27
+ secretKey
28
+ };
29
29
  }
30
- //# sourceMappingURL=decode.js.map
30
+ export {
31
+ decodePair
32
+ };
@@ -1,9 +1,31 @@
1
- export const PAIR_DIV = new Uint8Array([161, 35, 3, 33, 0]);
2
- export const PAIR_HDR = new Uint8Array([
3
- 48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32,
1
+ const PAIR_DIV = new Uint8Array([161, 35, 3, 33, 0]);
2
+ const PAIR_HDR = new Uint8Array([
3
+ 48,
4
+ 83,
5
+ 2,
6
+ 1,
7
+ 1,
8
+ 48,
9
+ 5,
10
+ 6,
11
+ 3,
12
+ 43,
13
+ 101,
14
+ 112,
15
+ 4,
16
+ 34,
17
+ 4,
18
+ 32
4
19
  ]);
5
- export const PUB_LENGTH = 32;
6
- export const SALT_LENGTH = 32;
7
- export const SEC_LENGTH = 64;
8
- export const SEED_LENGTH = 32;
9
- //# sourceMappingURL=defaults.js.map
20
+ const PUB_LENGTH = 32;
21
+ const SALT_LENGTH = 32;
22
+ const SEC_LENGTH = 64;
23
+ const SEED_LENGTH = 32;
24
+ export {
25
+ PAIR_DIV,
26
+ PAIR_HDR,
27
+ PUB_LENGTH,
28
+ SALT_LENGTH,
29
+ SEC_LENGTH,
30
+ SEED_LENGTH
31
+ };
@@ -1,16 +1,18 @@
1
1
  import { u8aConcat } from "@polkadot/util";
2
- import { naclEncrypt, scryptEncode, scryptToU8a } from "@prosopo/util-crypto";
3
- import { PAIR_DIV, PAIR_HDR } from "./defaults.js";
4
- export function encodePair({ publicKey, secretKey }, passphrase) {
5
- if (!secretKey) {
6
- throw new Error("Expected a valid secretKey to be passed to encode");
7
- }
8
- const encoded = u8aConcat(PAIR_HDR, secretKey, PAIR_DIV, publicKey);
9
- if (!passphrase) {
10
- return encoded;
11
- }
12
- const { params, password, salt } = scryptEncode(passphrase);
13
- const { encrypted, nonce } = naclEncrypt(encoded, password.subarray(0, 32));
14
- return u8aConcat(scryptToU8a(salt, params), nonce, encrypted);
2
+ import { scryptEncode, naclEncrypt, scryptToU8a } from "@prosopo/util-crypto";
3
+ import { PAIR_HDR, PAIR_DIV } from "./defaults.js";
4
+ function encodePair({ publicKey, secretKey }, passphrase) {
5
+ if (!secretKey) {
6
+ throw new Error("Expected a valid secretKey to be passed to encode");
7
+ }
8
+ const encoded = u8aConcat(PAIR_HDR, secretKey, PAIR_DIV, publicKey);
9
+ if (!passphrase) {
10
+ return encoded;
11
+ }
12
+ const { params, password, salt } = scryptEncode(passphrase);
13
+ const { encrypted, nonce } = naclEncrypt(encoded, password.subarray(0, 32));
14
+ return u8aConcat(scryptToU8a(salt, params), nonce, encrypted);
15
15
  }
16
- //# sourceMappingURL=encode.js.map
16
+ export {
17
+ encodePair
18
+ };