@swapkit/wallet-keystore 1.0.0-rc.2 → 1.0.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "author": "swapkit-oss-team",
3
3
  "dependencies": {
4
+ "crypto-js": "4.2.0",
4
5
  "blakejs": "1.2.1",
5
6
  "uuid": "9.0.0",
6
- "@swapkit/types": "1.0.0-rc.0"
7
+ "@swapkit/types": "1.0.0-rc.6"
7
8
  },
8
9
  "description": "SwapKit Lib keystore",
9
10
  "devDependencies": {
11
+ "@rollup/plugin-node-resolve": "15.2.3",
10
12
  "@scure/bip39": "1.2.1",
11
13
  "@types/long": "4.0.2",
12
14
  "@types/uniqid": "5.3.2",
@@ -17,10 +19,10 @@
17
19
  "vite": "4.4.9",
18
20
  "vitest": "0.34.4",
19
21
  "@internal/config": "0.0.0-internal.0",
20
- "@swapkit/helpers": "1.0.0-rc.0",
21
- "@swapkit/toolbox-cosmos": "1.0.0-rc.1",
22
- "@swapkit/toolbox-evm": "1.0.0-rc.1",
23
- "@swapkit/toolbox-utxo": "1.0.0-rc.0"
22
+ "@swapkit/helpers": "1.0.0-rc.15",
23
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.17",
24
+ "@swapkit/toolbox-evm": "1.0.0-rc.16",
25
+ "@swapkit/toolbox-utxo": "1.0.0-rc.16"
24
26
  },
25
27
  "eslintConfig": {
26
28
  "extends": "../../../internal/eslint-config"
@@ -45,10 +47,10 @@
45
47
  "@scure/bip39": "1.2.1",
46
48
  "ethers": "^6.7.1",
47
49
  "bitcoinjs-lib": "^5.2.0",
48
- "@swapkit/helpers": "1.0.0-rc.0",
49
- "@swapkit/toolbox-cosmos": "1.0.0-rc.1",
50
- "@swapkit/toolbox-evm": "1.0.0-rc.1",
51
- "@swapkit/toolbox-utxo": "1.0.0-rc.0"
50
+ "@swapkit/helpers": "1.0.0-rc.15",
51
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.17",
52
+ "@swapkit/toolbox-evm": "1.0.0-rc.16",
53
+ "@swapkit/toolbox-utxo": "1.0.0-rc.16"
52
54
  },
53
55
  "publishConfig": {
54
56
  "access": "public"
@@ -57,7 +59,7 @@
57
59
  "repository": "https://github.com/thorswap/SwapKit.git",
58
60
  "type": "module",
59
61
  "types": "./dist/index.d.ts",
60
- "version": "1.0.0-rc.2",
62
+ "version": "1.0.0-rc.21",
61
63
  "scripts": {
62
64
  "build": "vite build",
63
65
  "clean": "rm -rf dist vite.config.ts.* .turbo node_modules",
package/src/helpers.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { entropyToMnemonic, generateMnemonic } from '@scure/bip39';
1
+ import { generateMnemonic } from '@scure/bip39';
2
2
  import { wordlist } from '@scure/bip39/wordlists/english';
3
3
  import { blake2bFinal, blake2bInit, blake2bUpdate } from 'blakejs';
4
4
  import crypto from 'crypto';
@@ -38,6 +38,7 @@ export type Keystore = {
38
38
  */
39
39
  const toHexByte = (byte: number) => (byte < 0x10 ? `0${byte.toString(16)}` : byte.toString(16));
40
40
  const toHex = (buffer: Buffer | Uint8Array) => Array.from(buffer).map(toHexByte).join('');
41
+ const _isNode = () => typeof window === 'undefined';
41
42
 
42
43
  /**
43
44
  * Gets data's 256 bit blake hash.
@@ -61,7 +62,7 @@ const pbkdf2Async = async (
61
62
  digest: string,
62
63
  ) => {
63
64
  return new Promise<Buffer>((resolve, reject) => {
64
- crypto.pbkdf2(passphrase, salt, iterations, keylen, digest, (err, drived) => {
65
+ crypto.pbkdf2(passphrase, salt, iterations, keylen, digest, (err: any, drived: any) => {
65
66
  if (err) {
66
67
  reject(err);
67
68
  } else {
@@ -71,10 +72,6 @@ const pbkdf2Async = async (
71
72
  });
72
73
  };
73
74
 
74
- const _isNode = () => {
75
- return typeof window === 'undefined';
76
- };
77
-
78
75
  export const encryptToKeyStore = async (phrase: string, password: string) => {
79
76
  const ID = _isNode() ? require('uuid').v4() : uuidv4();
80
77
  const salt = crypto.randomBytes(32);
@@ -124,11 +121,7 @@ export const encryptToKeyStore = async (phrase: string, password: string) => {
124
121
 
125
122
  export const generatePhrase = (size = 12) => {
126
123
  const entropy = size === 12 ? 128 : 256;
127
- if (_isNode()) {
128
- return entropyToMnemonic(crypto.randomBytes(entropy / 8), wordlist);
129
- } else {
130
- return generateMnemonic(wordlist, entropy);
131
- }
124
+ return generateMnemonic(wordlist, entropy);
132
125
  };
133
126
 
134
127
  export const decryptFromKeystore = async (keystore: Keystore, password: string) => {
package/src/keystore.ts CHANGED
@@ -10,7 +10,7 @@ import type { Psbt } from 'bitcoinjs-lib';
10
10
 
11
11
  type KeystoreOptions = {
12
12
  ethplorerApiKey?: string;
13
- utxoApiKey?: string;
13
+ blockchairApiKey?: string;
14
14
  covalentApiKey?: string;
15
15
  stagenet?: boolean;
16
16
  };
@@ -30,7 +30,7 @@ const getWalletMethodsForChain = async ({
30
30
  phrase,
31
31
  ethplorerApiKey,
32
32
  covalentApiKey,
33
- utxoApiKey,
33
+ blockchairApiKey,
34
34
  index,
35
35
  stagenet,
36
36
  }: Params) => {
@@ -72,9 +72,8 @@ const getWalletMethodsForChain = async ({
72
72
  }
73
73
 
74
74
  case Chain.BitcoinCash: {
75
- if (!utxoApiKey) throw new Error('UTXO API key not found');
76
75
  const { BCHToolbox } = await import('@swapkit/toolbox-utxo');
77
- const toolbox = BCHToolbox({ rpcUrl, apiKey: utxoApiKey, apiClient: api });
76
+ const toolbox = BCHToolbox({ rpcUrl, apiKey: blockchairApiKey, apiClient: api });
78
77
  const keys = await toolbox.createKeysForPath({ phrase, derivationPath });
79
78
  const address = toolbox.getAddressFromKeys(keys);
80
79
 
@@ -106,7 +105,7 @@ const getWalletMethodsForChain = async ({
106
105
  case Chain.Bitcoin:
107
106
  case Chain.Dogecoin:
108
107
  case Chain.Litecoin: {
109
- const params = { rpcUrl, apiKey: utxoApiKey, apiClient: api };
108
+ const params = { rpcUrl, apiKey: blockchairApiKey, apiClient: api };
110
109
 
111
110
  const { BTCToolbox, LTCToolbox, DOGEToolbox } = await import('@swapkit/toolbox-utxo');
112
111
 
@@ -179,6 +178,27 @@ const getWalletMethodsForChain = async ({
179
178
  };
180
179
  }
181
180
 
181
+ case Chain.Kujira: {
182
+ const { KujiraToolbox } = await import('@swapkit/toolbox-cosmos');
183
+ const toolbox = KujiraToolbox({ server: api });
184
+ const signer = await toolbox.getSigner(phrase);
185
+ const address = await toolbox.getAddressFromMnemonic(phrase);
186
+
187
+ const transfer = ({ assetValue, recipient, memo }: TransferParams) =>
188
+ toolbox.transfer({
189
+ from: address,
190
+ recipient,
191
+ signer,
192
+ assetValue,
193
+ memo,
194
+ });
195
+
196
+ return {
197
+ address,
198
+ walletMethods: { ...toolbox, transfer, getAddress: () => address },
199
+ };
200
+ }
201
+
182
202
  case Chain.Maya:
183
203
  case Chain.THORChain: {
184
204
  const { MayaToolbox, ThorchainToolbox } = await import('@swapkit/toolbox-cosmos');
@@ -215,7 +235,7 @@ const connectKeystore =
215
235
  addChain,
216
236
  apis,
217
237
  rpcUrls,
218
- config: { covalentApiKey, ethplorerApiKey, utxoApiKey, stagenet },
238
+ config: { covalentApiKey, ethplorerApiKey, blockchairApiKey, utxoApiKey, stagenet },
219
239
  }: ConnectWalletParams) =>
220
240
  async (chains: Chain[], phrase: string, index: number = 0) => {
221
241
  const promises = chains.map(async (chain) => {
@@ -227,7 +247,7 @@ const connectKeystore =
227
247
  covalentApiKey,
228
248
  ethplorerApiKey,
229
249
  phrase,
230
- utxoApiKey,
250
+ blockchairApiKey: blockchairApiKey || utxoApiKey,
231
251
  stagenet,
232
252
  });
233
253