quantumcoin 6.14.1 → 6.14.2

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 (141) hide show
  1. package/README.md +2 -0
  2. package/dist/quantumcoin.js +2697 -7812
  3. package/dist/quantumcoin.js.map +1 -1
  4. package/dist/quantumcoin.min.js +1 -1
  5. package/dist/quantumcoin.min.js'.gz' +0 -0
  6. package/dist/quantumcoin.umd.js +2698 -7835
  7. package/dist/quantumcoin.umd.js.map +1 -1
  8. package/dist/quantumcoin.umd.min.js +1 -1
  9. package/dist/quantumcoin.umd.min.js'.gz' +0 -0
  10. package/dist/wordlists-extra.min.js'.gz' +0 -0
  11. package/lib.commonjs/address/address.d.ts +1 -21
  12. package/lib.commonjs/address/address.d.ts.map +1 -1
  13. package/lib.commonjs/address/address.js +2 -30
  14. package/lib.commonjs/address/address.js.map +1 -1
  15. package/lib.commonjs/address/index.d.ts +1 -1
  16. package/lib.commonjs/address/index.d.ts.map +1 -1
  17. package/lib.commonjs/address/index.js +1 -2
  18. package/lib.commonjs/address/index.js.map +1 -1
  19. package/lib.commonjs/crypto/signature.d.ts +4 -17
  20. package/lib.commonjs/crypto/signature.d.ts.map +1 -1
  21. package/lib.commonjs/crypto/signature.js +57 -60
  22. package/lib.commonjs/crypto/signature.js.map +1 -1
  23. package/lib.commonjs/crypto/signing-key.d.ts +5 -64
  24. package/lib.commonjs/crypto/signing-key.d.ts.map +1 -1
  25. package/lib.commonjs/crypto/signing-key.js +27 -101
  26. package/lib.commonjs/crypto/signing-key.js.map +1 -1
  27. package/lib.commonjs/providers/default-provider.d.ts +0 -8
  28. package/lib.commonjs/providers/default-provider.d.ts.map +1 -1
  29. package/lib.commonjs/providers/default-provider.js +0 -108
  30. package/lib.commonjs/providers/default-provider.js.map +1 -1
  31. package/lib.commonjs/providers/index.d.ts +0 -9
  32. package/lib.commonjs/providers/index.d.ts.map +1 -1
  33. package/lib.commonjs/providers/index.js +1 -21
  34. package/lib.commonjs/providers/index.js.map +1 -1
  35. package/lib.commonjs/providers/network.js +1 -99
  36. package/lib.commonjs/providers/network.js.map +1 -1
  37. package/lib.commonjs/quantumcoin.d.ts +4 -4
  38. package/lib.commonjs/quantumcoin.d.ts.map +1 -1
  39. package/lib.commonjs/quantumcoin.js +4 -26
  40. package/lib.commonjs/quantumcoin.js.map +1 -1
  41. package/lib.commonjs/transaction/address.d.ts +1 -1
  42. package/lib.commonjs/transaction/address.d.ts.map +1 -1
  43. package/lib.commonjs/transaction/address.js +9 -5
  44. package/lib.commonjs/transaction/address.js.map +1 -1
  45. package/lib.commonjs/wallet/hdwallet.d.ts.map +1 -1
  46. package/lib.commonjs/wallet/hdwallet.js +4 -5
  47. package/lib.commonjs/wallet/hdwallet.js.map +1 -1
  48. package/lib.commonjs/wallet/index.d.ts +2 -6
  49. package/lib.commonjs/wallet/index.d.ts.map +1 -1
  50. package/lib.commonjs/wallet/index.js +1 -14
  51. package/lib.commonjs/wallet/index.js.map +1 -1
  52. package/lib.commonjs/wallet/json-keystore.d.ts +3 -52
  53. package/lib.commonjs/wallet/json-keystore.d.ts.map +1 -1
  54. package/lib.commonjs/wallet/json-keystore.js +41 -246
  55. package/lib.commonjs/wallet/json-keystore.js.map +1 -1
  56. package/lib.commonjs/wallet/seedwallet.d.ts +4 -0
  57. package/lib.commonjs/wallet/seedwallet.d.ts.map +1 -0
  58. package/lib.commonjs/wallet/seedwallet.js +8 -0
  59. package/lib.commonjs/wallet/seedwallet.js.map +1 -0
  60. package/lib.commonjs/wallet/wallet.d.ts +5 -14
  61. package/lib.commonjs/wallet/wallet.d.ts.map +1 -1
  62. package/lib.commonjs/wallet/wallet.js +12 -51
  63. package/lib.commonjs/wallet/wallet.js.map +1 -1
  64. package/lib.esm/address/address.d.ts +1 -21
  65. package/lib.esm/address/address.d.ts.map +1 -1
  66. package/lib.esm/address/address.js +1 -28
  67. package/lib.esm/address/address.js.map +1 -1
  68. package/lib.esm/address/index.d.ts +1 -1
  69. package/lib.esm/address/index.d.ts.map +1 -1
  70. package/lib.esm/address/index.js +1 -1
  71. package/lib.esm/address/index.js.map +1 -1
  72. package/lib.esm/crypto/signature.d.ts +4 -17
  73. package/lib.esm/crypto/signature.d.ts.map +1 -1
  74. package/lib.esm/crypto/signature.js +45 -46
  75. package/lib.esm/crypto/signature.js.map +1 -1
  76. package/lib.esm/crypto/signing-key.d.ts +5 -64
  77. package/lib.esm/crypto/signing-key.d.ts.map +1 -1
  78. package/lib.esm/crypto/signing-key.js +26 -102
  79. package/lib.esm/crypto/signing-key.js.map +1 -1
  80. package/lib.esm/providers/default-provider.d.ts +0 -8
  81. package/lib.esm/providers/default-provider.d.ts.map +1 -1
  82. package/lib.esm/providers/default-provider.js +0 -108
  83. package/lib.esm/providers/default-provider.js.map +1 -1
  84. package/lib.esm/providers/index.d.ts +0 -9
  85. package/lib.esm/providers/index.d.ts.map +1 -1
  86. package/lib.esm/providers/index.js +0 -9
  87. package/lib.esm/providers/index.js.map +1 -1
  88. package/lib.esm/providers/network.js +3 -101
  89. package/lib.esm/providers/network.js.map +1 -1
  90. package/lib.esm/quantumcoin.d.ts +4 -4
  91. package/lib.esm/quantumcoin.d.ts.map +1 -1
  92. package/lib.esm/quantumcoin.js +3 -3
  93. package/lib.esm/quantumcoin.js.map +1 -1
  94. package/lib.esm/transaction/address.d.ts +1 -1
  95. package/lib.esm/transaction/address.d.ts.map +1 -1
  96. package/lib.esm/transaction/address.js +7 -4
  97. package/lib.esm/transaction/address.js.map +1 -1
  98. package/lib.esm/wallet/hdwallet.d.ts.map +1 -1
  99. package/lib.esm/wallet/hdwallet.js +4 -5
  100. package/lib.esm/wallet/hdwallet.js.map +1 -1
  101. package/lib.esm/wallet/index.d.ts +2 -6
  102. package/lib.esm/wallet/index.d.ts.map +1 -1
  103. package/lib.esm/wallet/index.js +1 -4
  104. package/lib.esm/wallet/index.js.map +1 -1
  105. package/lib.esm/wallet/json-keystore.d.ts +3 -52
  106. package/lib.esm/wallet/json-keystore.d.ts.map +1 -1
  107. package/lib.esm/wallet/json-keystore.js +32 -241
  108. package/lib.esm/wallet/json-keystore.js.map +1 -1
  109. package/lib.esm/wallet/seedwallet.d.ts +4 -0
  110. package/lib.esm/wallet/seedwallet.d.ts.map +1 -0
  111. package/lib.esm/wallet/seedwallet.js +4 -0
  112. package/lib.esm/wallet/seedwallet.js.map +1 -0
  113. package/lib.esm/wallet/wallet.d.ts +5 -14
  114. package/lib.esm/wallet/wallet.d.ts.map +1 -1
  115. package/lib.esm/wallet/wallet.js +12 -53
  116. package/lib.esm/wallet/wallet.js.map +1 -1
  117. package/package.json +5 -2
  118. package/src.ts/address/address.ts +2 -27
  119. package/src.ts/address/index.ts +1 -1
  120. package/src.ts/crypto/signature.ts +31 -45
  121. package/src.ts/crypto/signing-key.ts +31 -109
  122. package/src.ts/providers/default-provider.ts +0 -106
  123. package/src.ts/providers/index.ts +0 -10
  124. package/src.ts/providers/network.ts +3 -111
  125. package/src.ts/quantumcoin.ts +7 -17
  126. package/src.ts/transaction/address.ts +8 -5
  127. package/src.ts/wallet/index.ts +2 -17
  128. package/src.ts/wallet/json-keystore.ts +42 -325
  129. package/src.ts/wallet/wallet.ts +23 -47
  130. package/src.ts/providers/provider-alchemy.ts +0 -166
  131. package/src.ts/providers/provider-ankr.ts +0 -153
  132. package/src.ts/providers/provider-blockscout.ts +0 -167
  133. package/src.ts/providers/provider-chainstack.ts +0 -113
  134. package/src.ts/providers/provider-cloudflare.ts +0 -24
  135. package/src.ts/providers/provider-etherscan.ts +0 -671
  136. package/src.ts/providers/provider-infura.ts +0 -220
  137. package/src.ts/providers/provider-pocket.ts +0 -121
  138. package/src.ts/providers/provider-quicknode.ts +0 -177
  139. package/src.ts/wallet/hdwallet.ts +0 -586
  140. package/src.ts/wallet/json-crowdsale.ts +0 -74
  141. package/src.ts/wallet/mnemonic.ts +0 -203
@@ -6,10 +6,10 @@
6
6
  */
7
7
 
8
8
  import { accessListify } from "../transaction/index.js";
9
- import { getBigInt, assert, assertArgument } from "../utils/index.js";
9
+ import { getBigInt, assertArgument } from "../utils/index.js";
10
10
 
11
11
  import {
12
- EnsPlugin, FetchUrlFeeDataNetworkPlugin, GasCostPlugin
12
+ EnsPlugin, GasCostPlugin
13
13
  } from "./plugins-network.js";
14
14
 
15
15
  import type { BigNumberish } from "../utils/index.js";
@@ -288,65 +288,6 @@ type Options = {
288
288
  plugins?: Array<NetworkPlugin>;
289
289
  };
290
290
 
291
- // We don't want to bring in formatUnits because it is backed by
292
- // FixedNumber and we want to keep Networks tiny. The values
293
- // included by the Gas Stations are also IEEE 754 with lots of
294
- // rounding issues and exceed the strict checks formatUnits has.
295
- function parseUnits(_value: number | string, decimals: number): bigint {
296
- const value = String(_value);
297
- if (!value.match(/^[0-9.]+$/)) {
298
- throw new Error(`invalid gwei value: ${ _value }`);
299
- }
300
-
301
- // Break into [ whole, fraction ]
302
- const comps = value.split(".");
303
- if (comps.length === 1) { comps.push(""); }
304
-
305
- // More than 1 decimal point or too many fractional positions
306
- if (comps.length !== 2) {
307
- throw new Error(`invalid gwei value: ${ _value }`);
308
- }
309
-
310
- // Pad the fraction to 9 decimalplaces
311
- while (comps[1].length < decimals) { comps[1] += "0"; }
312
-
313
- // Too many decimals and some non-zero ending, take the ceiling
314
- if (comps[1].length > 9) {
315
- let frac = BigInt(comps[1].substring(0, 9));
316
- if (!comps[1].substring(9).match(/^0+$/)) { frac++; }
317
- comps[1] = frac.toString();
318
- }
319
-
320
- return BigInt(comps[0] + comps[1]);
321
- }
322
-
323
- // Used by Polygon to use a gas station for fee data
324
- function getGasStationPlugin(url: string) {
325
- return new FetchUrlFeeDataNetworkPlugin(url, async (fetchFeeData, provider, request) => {
326
-
327
- // Prevent Cloudflare from blocking our request in node.js
328
- request.setHeader("User-Agent", "ethers");
329
-
330
- let response;
331
- try {
332
- const [ _response, _feeData ] = await Promise.all([
333
- request.send(), fetchFeeData()
334
- ]);
335
- response = _response;
336
- const payload = response.bodyJson.standard;
337
- const feeData = {
338
- gasPrice: _feeData.gasPrice,
339
- maxFeePerGas: parseUnits(payload.maxFee, 9),
340
- maxPriorityFeePerGas: parseUnits(payload.maxPriorityFee, 9),
341
- };
342
- return feeData;
343
- } catch (error: any) {
344
- assert(false, `error encountered with polygon gas station (${ JSON.stringify(request.url) })`, "SERVER_ERROR", { request, response, error });
345
- }
346
- });
347
- }
348
-
349
- // See: https://chainlist.org
350
291
  let injected = false;
351
292
  function injectCommonNetworks(): void {
352
293
  if (injected) { return; }
@@ -382,54 +323,5 @@ function injectCommonNetworks(): void {
382
323
  }
383
324
  }
384
325
 
385
- registerEth("mainnet", 1, { ensNetwork: 1, altNames: [ "homestead" ] });
386
- registerEth("ropsten", 3, { ensNetwork: 3 });
387
- registerEth("rinkeby", 4, { ensNetwork: 4 });
388
- registerEth("goerli", 5, { ensNetwork: 5 });
389
- registerEth("kovan", 42, { ensNetwork: 42 });
390
- registerEth("sepolia", 11155111, { ensNetwork: 11155111 });
391
- registerEth("holesky", 17000, { ensNetwork: 17000 });
392
-
393
- registerEth("classic", 61, { });
394
- registerEth("classicKotti", 6, { });
395
-
396
- registerEth("arbitrum", 42161, {
397
- ensNetwork: 1,
398
- });
399
- registerEth("arbitrum-goerli", 421613, { });
400
- registerEth("arbitrum-sepolia", 421614, { });
401
-
402
- registerEth("base", 8453, { ensNetwork: 1 });
403
- registerEth("base-goerli", 84531, { });
404
- registerEth("base-sepolia", 84532, { });
405
-
406
- registerEth("bnb", 56, { ensNetwork: 1 });
407
- registerEth("bnbt", 97, { });
408
-
409
- registerEth("linea", 59144, { ensNetwork: 1 });
410
- registerEth("linea-goerli", 59140, { });
411
- registerEth("linea-sepolia", 59141, { });
412
-
413
- registerEth("matic", 137, {
414
- ensNetwork: 1,
415
- plugins: [
416
- getGasStationPlugin("https:/\/gasstation.polygon.technology/v2")
417
- ]
418
- });
419
- registerEth("matic-amoy", 80002, { });
420
- registerEth("matic-mumbai", 80001, {
421
- altNames: [ "maticMumbai", "maticmum" ], // @TODO: Future remove these alts
422
- plugins: [
423
- getGasStationPlugin("https:/\/gasstation-testnet.polygon.technology/v2")
424
- ]
425
- });
426
-
427
- registerEth("optimism", 10, {
428
- ensNetwork: 1,
429
- plugins: [ ]
430
- });
431
- registerEth("optimism-goerli", 420, { });
432
- registerEth("optimism-sepolia", 11155420, { });
433
-
434
- registerEth("xdai", 100, { ensNetwork: 1 });
326
+ registerEth("mainnet", 123123, { ensNetwork: 1, altNames: [ "quantumcoin" ] });
435
327
  }
@@ -16,7 +16,7 @@ export {
16
16
  } from "./abi/index.js";
17
17
 
18
18
  export {
19
- getAddress, getIcapAddress,
19
+ getAddress,
20
20
  getCreateAddress, getCreate2Address,
21
21
  isAddressable, isAddress, resolveAddress
22
22
  } from "./address/index.js";
@@ -70,16 +70,12 @@ export {
70
70
 
71
71
  BrowserProvider,
72
72
 
73
- AlchemyProvider, AnkrProvider, BlockscoutProvider, ChainstackProvider,
74
- CloudflareProvider, EtherscanProvider, InfuraProvider,
75
- InfuraWebSocketProvider, PocketProvider, QuickNodeProvider,
76
-
77
73
  IpcSocketProvider, SocketProvider, WebSocketProvider,
78
74
 
79
75
  EnsResolver,
80
76
  Network,
81
77
 
82
- EnsPlugin, EtherscanPlugin,
78
+ EnsPlugin,
83
79
  FeeDataNetworkPlugin, FetchUrlFeeDataNetworkPlugin,
84
80
  GasCostPlugin, NetworkPlugin, MulticoinProviderPlugin,
85
81
 
@@ -117,17 +113,11 @@ export {
117
113
  } from "./utils/index.js";
118
114
 
119
115
  export {
120
- Mnemonic,
121
- BaseWallet, HDNodeWallet, HDNodeVoidWallet,
116
+ BaseWallet,
122
117
  Wallet,
123
-
124
- defaultPath,
125
-
126
- getAccountPath, getIndexedAccountPath,
127
- isCrowdsaleJson, isKeystoreJson,
128
-
129
- decryptCrowdsaleJson, decryptKeystoreJsonSync, decryptKeystoreJson,
130
- encryptKeystoreJson, encryptKeystoreJsonSync,
118
+ isKeystoreJson,
119
+ decryptKeystoreJsonSync,
120
+ encryptKeystoreJsonSync,
131
121
  } from "./wallet/index.js";
132
122
 
133
123
  export {
@@ -215,7 +205,7 @@ export type {
215
205
  } from "./utils/index.js";
216
206
 
217
207
  export type {
218
- CrowdsaleAccount, KeystoreAccount, EncryptOptions
208
+ KeystoreAccount
219
209
  } from "./wallet/index.js";
220
210
 
221
211
  // dummy change; to pick-up ws security issue changes
@@ -1,8 +1,10 @@
1
- import { getAddress } from "../address/index.js";
2
- import { keccak256, SigningKey } from "../crypto/index.js";
1
+ //import { getAddress } from "../address/index.js";
2
+ // keccak256,
3
+ import {SigningKey } from "../crypto/index.js";
3
4
 
4
5
  import type { SignatureLike } from "../crypto/index.js";
5
- import type { BytesLike } from "../utils/index.js";
6
+ import {BytesLike, getBytes} from "../utils/index.js";
7
+ import qcsdk = require('quantum-coin-js-sdk');
6
8
 
7
9
  /**
8
10
  * Returns the address for the %%key%%.
@@ -12,11 +14,12 @@ import type { BytesLike } from "../utils/index.js";
12
14
  export function computeAddress(key: string | SigningKey): string {
13
15
  let pubkey: string;
14
16
  if (typeof(key) === "string") {
15
- pubkey = SigningKey.computePublicKey(key, false);
17
+ pubkey = SigningKey.computePublicKey(key);
16
18
  } else {
17
19
  pubkey = key.publicKey;
18
20
  }
19
- return getAddress(keccak256("0x" + pubkey.substring(4)).substring(26));
21
+ let pubKeyBytes: any = getBytes(pubkey);
22
+ return qcsdk.addressFromPublicKey(pubKeyBytes);
20
23
  }
21
24
 
22
25
  /**
@@ -19,29 +19,14 @@
19
19
 
20
20
  export { BaseWallet } from "./base-wallet.js";
21
21
 
22
- export {
23
- defaultPath,
24
-
25
- getAccountPath, getIndexedAccountPath,
26
-
27
- HDNodeWallet,
28
- HDNodeVoidWallet,
29
- } from "./hdwallet.js";
30
-
31
- export { isCrowdsaleJson, decryptCrowdsaleJson } from "./json-crowdsale.js";
32
-
33
22
  export {
34
23
  isKeystoreJson,
35
- decryptKeystoreJsonSync, decryptKeystoreJson,
36
- encryptKeystoreJson, encryptKeystoreJsonSync
24
+ decryptKeystoreJsonSync, encryptKeystoreJsonSync
37
25
  } from "./json-keystore.js";
38
26
 
39
- export { Mnemonic } from "./mnemonic.js";
40
-
41
27
  export { Wallet } from "./wallet.js";
42
28
 
43
29
 
44
- export type { CrowdsaleAccount } from "./json-crowdsale.js";
45
30
  export type {
46
- KeystoreAccount, EncryptOptions
31
+ KeystoreAccount
47
32
  } from "./json-keystore.js"
@@ -9,24 +9,31 @@
9
9
  * @_subsection: api/wallet:JSON Wallets [json-wallets]
10
10
  */
11
11
 
12
- import { CTR } from "aes-js";
12
+ //import { CTR } from "aes-js";
13
13
 
14
- import { getAddress } from "../address/index.js";
15
- import { keccak256, pbkdf2, randomBytes, scrypt, scryptSync } from "../crypto/index.js";
16
- import { computeAddress } from "../transaction/index.js";
14
+ //import { getAddress } from "../address/index.js";
15
+ //randomBytes, scrypt, scryptSync, uuidV4
16
+ //import { keccak256 } from "../crypto/index.js";
17
+ //import { computeAddress } from "../transaction/index.js";
18
+ //concat, assert, assertArgument,
17
19
  import {
18
- concat, getBytes, hexlify, uuidV4, assert, assertArgument
20
+ getBytes, hexlify, toUtf8String
19
21
  } from "../utils/index.js";
20
22
 
21
- import { getPassword, spelunk, zpad } from "./utils.js";
23
+ import {SigningKey} from "../crypto/signing-key"
22
24
 
23
- import type { ProgressCallback } from "../crypto/index.js";
24
- import type { BytesLike } from "../utils/index.js";
25
+ //zpad
26
+ //import { spelunk } from "./utils.js";
25
27
 
26
- import { version } from "../_version.js";
28
+ //import type { ProgressCallback } from "../crypto/index.js";
29
+ //import {Wallet} from "quantum-coin-js-sdk";
30
+ //import type { BytesLike } from "../utils/index.js";
31
+ import qcsdk = require('quantum-coin-js-sdk');
27
32
 
33
+ //import { version } from "../_version.js";
28
34
 
29
- const defaultPath = "m/44'/60'/0'/0/0";
35
+
36
+ //const defaultPath = "m/44'/60'/0'/0/0";
30
37
 
31
38
  /**
32
39
  * The contents of a JSON Keystore Wallet.
@@ -34,30 +41,8 @@ const defaultPath = "m/44'/60'/0'/0/0";
34
41
  export type KeystoreAccount = {
35
42
  address: string;
36
43
  privateKey: string;
37
- mnemonic?: {
38
- path?: string;
39
- locale?: string;
40
- entropy: string;
41
- }
42
44
  };
43
45
 
44
- /**
45
- * The parameters to use when encrypting a JSON Keystore Wallet.
46
- */
47
- export type EncryptOptions = {
48
- progressCallback?: ProgressCallback;
49
- iv?: BytesLike;
50
- entropy?: BytesLike;
51
- client?: string;
52
- salt?: BytesLike;
53
- uuid?: string;
54
- scrypt?: {
55
- N?: number;
56
- r?: number;
57
- p?: number;
58
- }
59
- }
60
-
61
46
  /**
62
47
  * Returns true if %%json%% is a valid JSON Keystore Wallet.
63
48
  */
@@ -70,150 +55,6 @@ export function isKeystoreJson(json: string): boolean {
70
55
  return false;
71
56
  }
72
57
 
73
- function decrypt(data: any, key: Uint8Array, ciphertext: Uint8Array): string {
74
- const cipher = spelunk<string>(data, "crypto.cipher:string");
75
- if (cipher === "aes-128-ctr") {
76
- const iv = spelunk<Uint8Array>(data, "crypto.cipherparams.iv:data!")
77
- const aesCtr = new CTR(key, iv);
78
- return hexlify(aesCtr.decrypt(ciphertext));
79
- }
80
-
81
- assert(false, "unsupported cipher", "UNSUPPORTED_OPERATION", {
82
- operation: "decrypt"
83
- });
84
- }
85
-
86
- function getAccount(data: any, _key: string): KeystoreAccount {
87
- const key = getBytes(_key);
88
- const ciphertext = spelunk<Uint8Array>(data, "crypto.ciphertext:data!");
89
-
90
- const computedMAC = hexlify(keccak256(concat([ key.slice(16, 32), ciphertext ]))).substring(2);
91
- assertArgument(computedMAC === spelunk<string>(data, "crypto.mac:string!").toLowerCase(),
92
- "incorrect password", "password", "[ REDACTED ]");
93
-
94
- const privateKey = decrypt(data, key.slice(0, 16), ciphertext);
95
-
96
- const address = computeAddress(privateKey);
97
- if (data.address) {
98
- let check = data.address.toLowerCase();
99
- if (!check.startsWith("0x")) { check = "0x" + check; }
100
-
101
- assertArgument(getAddress(check) === address, "keystore address/privateKey mismatch", "address", data.address);
102
- }
103
-
104
- const account: KeystoreAccount = { address, privateKey };
105
-
106
- // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
107
- const version = spelunk(data, "x-ethers.version:string");
108
- if (version === "0.1") {
109
- const mnemonicKey = key.slice(32, 64);
110
-
111
- const mnemonicCiphertext = spelunk<Uint8Array>(data, "x-ethers.mnemonicCiphertext:data!");
112
- const mnemonicIv = spelunk<Uint8Array>(data, "x-ethers.mnemonicCounter:data!");
113
-
114
- const mnemonicAesCtr = new CTR(mnemonicKey, mnemonicIv);
115
-
116
- account.mnemonic = {
117
- path: (spelunk<null | string>(data, "x-ethers.path:string") || defaultPath),
118
- locale: (spelunk<null | string>(data, "x-ethers.locale:string") || "en"),
119
- entropy: hexlify(getBytes(mnemonicAesCtr.decrypt(mnemonicCiphertext)))
120
- };
121
- }
122
-
123
- return account;
124
- }
125
-
126
- type ScryptParams = {
127
- name: "scrypt";
128
- salt: Uint8Array;
129
- N: number;
130
- r: number;
131
- p: number;
132
- dkLen: number;
133
- };
134
-
135
- type KdfParams = ScryptParams | {
136
- name: "pbkdf2";
137
- salt: Uint8Array;
138
- count: number;
139
- dkLen: number;
140
- algorithm: "sha256" | "sha512";
141
- };
142
-
143
- function getDecryptKdfParams<T>(data: any): KdfParams {
144
- const kdf = spelunk(data, "crypto.kdf:string");
145
- if (kdf && typeof(kdf) === "string") {
146
- if (kdf.toLowerCase() === "scrypt") {
147
- const salt = spelunk<Uint8Array>(data, "crypto.kdfparams.salt:data!");
148
- const N = spelunk<number>(data, "crypto.kdfparams.n:int!");
149
- const r = spelunk<number>(data, "crypto.kdfparams.r:int!");
150
- const p = spelunk<number>(data, "crypto.kdfparams.p:int!");
151
-
152
- // Make sure N is a power of 2
153
- assertArgument(N > 0 && (N & (N - 1)) === 0, "invalid kdf.N", "kdf.N", N);
154
- assertArgument(r > 0 && p > 0, "invalid kdf", "kdf", kdf);
155
-
156
- const dkLen = spelunk<number>(data, "crypto.kdfparams.dklen:int!");
157
- assertArgument(dkLen === 32, "invalid kdf.dklen", "kdf.dflen", dkLen);
158
-
159
- return { name: "scrypt", salt, N, r, p, dkLen: 64 };
160
-
161
- } else if (kdf.toLowerCase() === "pbkdf2") {
162
-
163
- const salt = spelunk<Uint8Array>(data, "crypto.kdfparams.salt:data!");
164
-
165
- const prf = spelunk<string>(data, "crypto.kdfparams.prf:string!");
166
- const algorithm = prf.split("-").pop();
167
- assertArgument(algorithm === "sha256" || algorithm === "sha512", "invalid kdf.pdf", "kdf.pdf", prf);
168
-
169
- const count = spelunk<number>(data, "crypto.kdfparams.c:int!");
170
-
171
- const dkLen = spelunk<number>(data, "crypto.kdfparams.dklen:int!");
172
- assertArgument(dkLen === 32, "invalid kdf.dklen", "kdf.dklen", dkLen);
173
-
174
- return { name: "pbkdf2", salt, count, dkLen, algorithm };
175
- }
176
- }
177
-
178
- assertArgument(false, "unsupported key-derivation function", "kdf", kdf);
179
- }
180
-
181
-
182
- /**
183
- * Returns the account details for the JSON Keystore Wallet %%json%%
184
- * using %%password%%.
185
- *
186
- * It is preferred to use the [async version](decryptKeystoreJson)
187
- * instead, which allows a [[ProgressCallback]] to keep the user informed
188
- * as to the decryption status.
189
- *
190
- * This method will block the event loop (freezing all UI) until decryption
191
- * is complete, which can take quite some time, depending on the wallet
192
- * paramters and platform.
193
- */
194
- export function decryptKeystoreJsonSync(json: string, _password: string | Uint8Array): KeystoreAccount {
195
- const data = JSON.parse(json);
196
-
197
- const password = getPassword(_password);
198
-
199
- const params = getDecryptKdfParams(data);
200
- if (params.name === "pbkdf2") {
201
- const { salt, count, dkLen, algorithm } = params;
202
- const key = pbkdf2(password, salt, count, dkLen, algorithm);
203
- return getAccount(data, key);
204
- }
205
-
206
- assert(params.name === "scrypt", "cannot be reached", "UNKNOWN_ERROR", { params })
207
-
208
- const { salt, N, r, p, dkLen } = params;
209
- const key = scryptSync(password, salt, N, r, p, dkLen);
210
- return getAccount(data, key);
211
- }
212
-
213
- function stall(duration: number): Promise<void> {
214
- return new Promise((resolve) => { setTimeout(() => { resolve(); }, duration); });
215
- }
216
-
217
58
  /**
218
59
  * Resolves to the decrypted JSON Keystore Wallet %%json%% using the
219
60
  * %%password%%.
@@ -221,152 +62,24 @@ function stall(duration: number): Promise<void> {
221
62
  * If provided, %%progress%% will be called periodically during the
222
63
  * decrpytion to provide feedback, and if the function returns
223
64
  * ``false`` will halt decryption.
224
- *
225
- * The %%progressCallback%% will **always** receive ``0`` before
226
- * decryption begins and ``1`` when complete.
227
65
  */
228
- export async function decryptKeystoreJson(json: string, _password: string | Uint8Array, progress?: ProgressCallback): Promise<KeystoreAccount> {
229
- const data = JSON.parse(json);
230
-
231
- const password = getPassword(_password);
232
-
233
- const params = getDecryptKdfParams(data);
234
- if (params.name === "pbkdf2") {
235
- if (progress) {
236
- progress(0);
237
- await stall(0);
238
- }
239
- const { salt, count, dkLen, algorithm } = params;
240
- const key = pbkdf2(password, salt, count, dkLen, algorithm);
241
- if (progress) {
242
- progress(1);
243
- await stall(0);
244
- }
245
- return getAccount(data, key);
246
- }
247
-
248
- assert(params.name === "scrypt", "cannot be reached", "UNKNOWN_ERROR", { params })
249
-
250
- const { salt, N, r, p, dkLen } = params;
251
- const key = await scrypt(password, salt, N, r, p, dkLen, progress);
252
- return getAccount(data, key);
253
- }
254
-
255
- function getEncryptKdfParams(options: EncryptOptions): ScryptParams {
256
- // Check/generate the salt
257
- const salt = (options.salt != null) ? getBytes(options.salt, "options.salt"): randomBytes(32);
258
-
259
- // Override the scrypt password-based key derivation function parameters
260
- let N = (1 << 17), r = 8, p = 1;
261
- if (options.scrypt) {
262
- if (options.scrypt.N) { N = options.scrypt.N; }
263
- if (options.scrypt.r) { r = options.scrypt.r; }
264
- if (options.scrypt.p) { p = options.scrypt.p; }
66
+ export function decryptKeystoreJsonSync(json: string, _password: string | Uint8Array): KeystoreAccount {
67
+ let pass: string;
68
+ if (typeof _password === 'string') {
69
+ pass = _password;
70
+ } else {
71
+ pass = toUtf8String(_password);
265
72
  }
266
- assertArgument(typeof(N) === "number" && N > 0 && Number.isSafeInteger(N) && (BigInt(N) & BigInt(N - 1)) === BigInt(0), "invalid scrypt N parameter", "options.N", N);
267
- assertArgument(typeof(r) === "number" && r > 0 && Number.isSafeInteger(r), "invalid scrypt r parameter", "options.r", r);
268
- assertArgument(typeof(p) === "number" && p > 0 && Number.isSafeInteger(p), "invalid scrypt p parameter", "options.p", p);
269
-
270
- return { name: "scrypt", dkLen: 32, salt, N, r, p };
271
- }
272
-
273
- function _encryptKeystore(key: Uint8Array, kdf: ScryptParams, account: KeystoreAccount, options: EncryptOptions): any {
274
73
 
275
- const privateKey = getBytes(account.privateKey, "privateKey");
74
+ let wal = qcsdk.deserializeEncryptedWallet(json, pass);
75
+ let privKey: any = wal.privateKey;
276
76
 
277
- // Override initialization vector
278
- const iv = (options.iv != null) ? getBytes(options.iv, "options.iv"): randomBytes(16);
279
- assertArgument(iv.length === 16, "invalid options.iv length", "options.iv", options.iv);
280
-
281
- // Override the uuid
282
- const uuidRandom = (options.uuid != null) ? getBytes(options.uuid, "options.uuid"): randomBytes(16);
283
- assertArgument(uuidRandom.length === 16, "invalid options.uuid length", "options.uuid", options.iv);
284
-
285
- // This will be used to encrypt the wallet (as per Web3 secret storage)
286
- // - 32 bytes As normal for the Web3 secret storage (derivedKey, macPrefix)
287
- // - 32 bytes AES key to encrypt mnemonic with (required here to be Ethers Wallet)
288
- const derivedKey = key.slice(0, 16);
289
- const macPrefix = key.slice(16, 32);
290
-
291
- // Encrypt the private key
292
- const aesCtr = new CTR(derivedKey, iv);
293
- const ciphertext = getBytes(aesCtr.encrypt(privateKey));
294
-
295
- // Compute the message authentication code, used to check the password
296
- const mac = keccak256(concat([ macPrefix, ciphertext ]))
297
-
298
- // See: https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition
299
- const data: { [key: string]: any } = {
300
- address: account.address.substring(2).toLowerCase(),
301
- id: uuidV4(uuidRandom),
302
- version: 3,
303
- Crypto: {
304
- cipher: "aes-128-ctr",
305
- cipherparams: {
306
- iv: hexlify(iv).substring(2),
307
- },
308
- ciphertext: hexlify(ciphertext).substring(2),
309
- kdf: "scrypt",
310
- kdfparams: {
311
- salt: hexlify(kdf.salt).substring(2),
312
- n: kdf.N,
313
- dklen: 32,
314
- p: kdf.p,
315
- r: kdf.r
316
- },
317
- mac: mac.substring(2)
318
- }
77
+ let ks: KeystoreAccount = {
78
+ address: wal.address,
79
+ privateKey: hexlify(privKey)
319
80
  };
320
81
 
321
- // If we have a mnemonic, encrypt it into the JSON wallet
322
- if (account.mnemonic) {
323
- const client = (options.client != null) ? options.client: `ethers/${ version }`;
324
-
325
- const path = account.mnemonic.path || defaultPath;
326
- const locale = account.mnemonic.locale || "en";
327
-
328
- const mnemonicKey = key.slice(32, 64);
329
-
330
- const entropy = getBytes(account.mnemonic.entropy, "account.mnemonic.entropy");
331
- const mnemonicIv = randomBytes(16);
332
- const mnemonicAesCtr = new CTR(mnemonicKey, mnemonicIv);
333
- const mnemonicCiphertext = getBytes(mnemonicAesCtr.encrypt(entropy));
334
-
335
- const now = new Date();
336
- const timestamp = (now.getUTCFullYear() + "-" +
337
- zpad(now.getUTCMonth() + 1, 2) + "-" +
338
- zpad(now.getUTCDate(), 2) + "T" +
339
- zpad(now.getUTCHours(), 2) + "-" +
340
- zpad(now.getUTCMinutes(), 2) + "-" +
341
- zpad(now.getUTCSeconds(), 2) + ".0Z");
342
- const gethFilename = ("UTC--" + timestamp + "--" + data.address);
343
-
344
- data["x-ethers"] = {
345
- client, gethFilename, path, locale,
346
- mnemonicCounter: hexlify(mnemonicIv).substring(2),
347
- mnemonicCiphertext: hexlify(mnemonicCiphertext).substring(2),
348
- version: "0.1"
349
- };
350
- }
351
-
352
- return JSON.stringify(data);
353
- }
354
-
355
- /**
356
- * Return the JSON Keystore Wallet for %%account%% encrypted with
357
- * %%password%%.
358
- *
359
- * The %%options%% can be used to tune the password-based key
360
- * derivation function parameters, explicitly set the random values
361
- * used. Any provided [[ProgressCallback]] is ignord.
362
- */
363
- export function encryptKeystoreJsonSync(account: KeystoreAccount, password: string | Uint8Array, options?: EncryptOptions): string {
364
- if (options == null) { options = { }; }
365
-
366
- const passwordBytes = getPassword(password);
367
- const kdf = getEncryptKdfParams(options);
368
- const key = scryptSync(passwordBytes, kdf.salt, kdf.N, kdf.r, kdf.p, 64);
369
- return _encryptKeystore(getBytes(key), kdf, account, options);
82
+ return ks;
370
83
  }
371
84
 
372
85
  /**
@@ -375,15 +88,19 @@ export function encryptKeystoreJsonSync(account: KeystoreAccount, password: stri
375
88
  *
376
89
  * The %%options%% can be used to tune the password-based key
377
90
  * derivation function parameters, explicitly set the random values
378
- * used and provide a [[ProgressCallback]] to receive periodic updates
379
- * on the completion status..
91
+ * used.
380
92
  */
381
- export async function encryptKeystoreJson(account: KeystoreAccount, password: string | Uint8Array, options?: EncryptOptions): Promise<string> {
382
- if (options == null) { options = { }; }
383
-
384
- const passwordBytes = getPassword(password);
385
- const kdf = getEncryptKdfParams(options);
386
- const key = await scrypt(passwordBytes, kdf.salt, kdf.N, kdf.r, kdf.p, 64, options.progressCallback);
387
- return _encryptKeystore(getBytes(key), kdf, account, options);
93
+ export function encryptKeystoreJsonSync(account: KeystoreAccount, password: Uint8Array | string): string {
94
+ const signingKey: SigningKey = new SigningKey(account.privateKey);
95
+ const privateKey: any = getBytes(signingKey.privateKey);
96
+ const publicKey: any = getBytes(signingKey.publicKey);
97
+ const wal = new qcsdk.Wallet(account.address, privateKey, publicKey);
98
+
99
+ if (typeof password === 'string') {
100
+ return qcsdk.serializeEncryptedWallet(wal, password);
101
+ } else {
102
+ let passPhrase = toUtf8String(password);
103
+ return qcsdk.serializeEncryptedWallet(wal, passPhrase);
104
+ }
388
105
  }
389
106