edge-currency-plugins 1.3.2 → 1.3.4

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.
@@ -18,6 +18,9 @@ var _utils = require('../utxobased/engine/utils');
18
18
 
19
19
 
20
20
 
21
+
22
+
23
+
21
24
  var _cleaners3 = require('../utxobased/keymanager/cleaners');
22
25
 
23
26
  var _utils3 = require('./utils');
@@ -38,6 +41,20 @@ var _utils3 = require('./utils');
38
41
  const asCurrencyNumbWalletInfo = _cleaners3.asNumbWalletInfo.call(void 0, pluginInfo)
39
42
 
40
43
  const fns = {
44
+ async checkPublicKey(publicKeyData) {
45
+ const publicKey = _cleaners.asMaybe.call(void 0, (0, _cleaners3.asPublicKey))(publicKeyData)
46
+
47
+ if (publicKey == null) return false
48
+
49
+ const privateKeyFormat = _cleaners3.inferPrivateKeyFormat.call(void 0, publicKey)
50
+ const supportedFormats = _cleaners3.getSupportedFormats.call(void 0, engineInfo, privateKeyFormat)
51
+
52
+ // Public must have an defined xpub for every supported format
53
+ return supportedFormats.every(
54
+ format => publicKey.publicKeys[format] != null
55
+ )
56
+ },
57
+
41
58
  async createPrivateKey(
42
59
  _walletType,
43
60
  opts
@@ -81,13 +81,13 @@ var _utils = require('./utils');
81
81
  const asMaybeCurrencyPrivateKey = _cleaners.asMaybe.call(void 0, asCurrencyPrivateKey)
82
82
  // This walletInfo is desensitized (numb) and should be passed around over the original walletInfo
83
83
  const walletInfo = _cleaners3.asNumbWalletInfo.call(void 0, pluginInfo)(sensitiveWalletInfo)
84
- const { primaryFormat, publicKey, walletFormats } = walletInfo.keys
84
+ const { privateKeyFormat, publicKey, walletFormats } = walletInfo.keys
85
85
 
86
86
  if (
87
87
  engineInfo.formats == null ||
88
- !engineInfo.formats.includes(primaryFormat)
88
+ !engineInfo.formats.includes(privateKeyFormat)
89
89
  ) {
90
- const message = `Wallet format is not supported: ${primaryFormat}`
90
+ const message = `Wallet format is not supported: ${privateKeyFormat}`
91
91
  log.error(message)
92
92
  throw new Error(message)
93
93
  }
@@ -194,7 +194,7 @@ var _utils = require('./utils');
194
194
  data: {
195
195
  walletInfo: {
196
196
  pluginType: currencyInfo.pluginId,
197
- primaryFormat,
197
+ privateKeyFormat,
198
198
  walletFormats
199
199
  },
200
200
  metadataState: metadata.state,
@@ -625,7 +625,7 @@ var _utils = require('./utils');
625
625
  id: walletInfo.id,
626
626
  type: walletInfo.type,
627
627
  keys: {
628
- primaryFormat: walletInfo.keys.primaryFormat,
628
+ privateKeyFormat: walletInfo.keys.privateKeyFormat,
629
629
  walletFormats: allFormats,
630
630
  publicKey: {
631
631
  publicKeys: {}
@@ -26,7 +26,7 @@ var _ProcessorTransaction = require('../db/Models/ProcessorTransaction');
26
26
 
27
27
 
28
28
  var _types5 = require('../db/types');
29
-
29
+ var _cleaners3 = require('../keymanager/cleaners');
30
30
 
31
31
 
32
32
 
@@ -54,8 +54,6 @@ var _makeServerStates = require('./makeServerStates');
54
54
 
55
55
 
56
56
 
57
-
58
-
59
57
  var _utils3 = require('./utils');
60
58
 
61
59
 
@@ -345,73 +343,58 @@ var _utils3 = require('./utils');
345
343
  branch = 0,
346
344
  forceIndex
347
345
  }) {
348
- const walletPurpose = _utils3.currencyFormatToPurposeType.call(void 0,
349
- walletInfo.keys.primaryFormat
350
- )
351
- if (walletPurpose === _keymanager.BIP43PurposeTypeEnum.Segwit) {
352
- const {
353
- address: publicAddress,
354
- nativeBalance = '0',
355
- legacyAddress
356
- } = await internalGetFreshAddress({
357
- ...commonArgs,
358
- format: _utils3.getCurrencyFormatFromPurposeType.call(void 0,
359
- _keymanager.BIP43PurposeTypeEnum.WrappedSegwit
360
- ),
361
- forceIndex,
362
- changeIndex: branch
363
- })
346
+ const { privateKeyFormat } = walletInfo.keys
347
+
348
+ // Airbitz wallets only use branch 0
349
+ if (privateKeyFormat === 'bip32') branch = 0
350
+
351
+ const {
352
+ address: publicAddress,
353
+ nativeBalance = '0',
354
+ legacyAddress
355
+ } = await internalGetFreshAddress({
356
+ ...commonArgs,
357
+ format: privateKeyFormat,
358
+ forceIndex,
359
+ changeIndex: branch
360
+ })
364
361
 
365
- const {
366
- address: segwitAddress,
367
- nativeBalance: segwitNativeBalance = '0'
368
- } = await internalGetFreshAddress({
369
- ...commonArgs,
370
- format: _utils3.getCurrencyFormatFromPurposeType.call(void 0, _keymanager.BIP43PurposeTypeEnum.Segwit),
371
- forceIndex,
372
- changeIndex: branch
373
- })
362
+ const freshAddress = {
363
+ publicAddress,
364
+ nativeBalance,
365
+ legacyAddress:
366
+ legacyAddress !== publicAddress ? legacyAddress : undefined,
367
+ // Legacy address is just a different encoding of the standard public address
368
+ // and therefore would have the same balance
369
+ legacyNativeBalance:
370
+ legacyAddress !== publicAddress ? nativeBalance : undefined
371
+ }
374
372
 
375
- return {
376
- nativeBalance,
377
- publicAddress,
378
- legacyNativeBalance:
379
- legacyAddress !== publicAddress ? nativeBalance : undefined,
380
- // Legacy address is just a different encoding of the standard public address
381
- // and therefore would have the same balance
382
- legacyAddress:
383
- legacyAddress !== publicAddress ? legacyAddress : undefined,
384
- segwitAddress,
385
- segwitNativeBalance
386
- }
387
- } else {
388
- // Airbitz wallets only use branch 0
389
- if (walletPurpose === _keymanager.BIP43PurposeTypeEnum.Airbitz) {
390
- branch = 0
391
- }
373
+ // Exclude the privateKeyFormat because it's covered by 'publicAddress'
374
+ const supportedFormats = _cleaners3.getSupportedFormats.call(void 0,
375
+ pluginInfo.engineInfo,
376
+ walletInfo.keys.privateKeyFormat
377
+ ).filter(format => format !== privateKeyFormat)
392
378
 
393
- const {
394
- address: publicAddress,
395
- nativeBalance = '0',
396
- legacyAddress
397
- } = await internalGetFreshAddress({
398
- ...commonArgs,
399
- format: _utils3.getCurrencyFormatFromPurposeType.call(void 0, walletPurpose),
400
- forceIndex,
401
- changeIndex: branch
402
- })
379
+ // Loop over all other supported formats for their equivalent address:
380
+ for (const format of supportedFormats) {
381
+ if (format === 'bip84') {
382
+ const {
383
+ address,
384
+ nativeBalance = '0'
385
+ } = await internalGetFreshAddress({
386
+ ...commonArgs,
387
+ format,
388
+ forceIndex,
389
+ changeIndex: branch
390
+ })
403
391
 
404
- return {
405
- nativeBalance,
406
- publicAddress,
407
- legacyNativeBalance:
408
- legacyAddress !== publicAddress ? nativeBalance : undefined,
409
- // Legacy address is just a different encoding of the standard public address
410
- // and therefore would have the same balance
411
- legacyAddress:
412
- legacyAddress !== publicAddress ? legacyAddress : undefined
392
+ freshAddress.segwitAddress = address
393
+ freshAddress.segwitNativeBalance = nativeBalance
413
394
  }
414
395
  }
396
+
397
+ return freshAddress
415
398
  },
416
399
 
417
400
  async deriveScriptAddress(script) {
@@ -420,7 +403,7 @@ var _utils3 = require('./utils');
420
403
  engineInfo: commonArgs.pluginInfo.engineInfo,
421
404
  processor: commonArgs.processor,
422
405
  taskCache: commonArgs.taskCache,
423
- format: walletInfo.keys.primaryFormat,
406
+ format: walletInfo.keys.privateKeyFormat,
424
407
  script
425
408
  })
426
409
  return {
@@ -235,11 +235,17 @@ var _keymanager = require('../keymanager/keymanager');
235
235
  const deriveXpubsFromKeys = (args
236
236
 
237
237
 
238
+
238
239
  ) => {
240
+ const { engineInfo, privateKey, coin } = args
239
241
  const xpubs = {}
240
- for (const format of _cleaners.getSupportedFormats.call(void 0, args.privateKey.format)) {
242
+ for (const format of _cleaners.getSupportedFormats.call(void 0,
243
+ engineInfo,
244
+ args.privateKey.format
245
+ )) {
241
246
  xpubs[format] = exports.deriveXpub.call(void 0, {
242
- ...args,
247
+ privateKey,
248
+ coin,
243
249
  type: exports.currencyFormatToPurposeType.call(void 0, format)
244
250
  })
245
251
  }
@@ -27,6 +27,7 @@ const currencyInfo = {
27
27
  ],
28
28
  enableCustomServers: false
29
29
  },
30
+ canReplaceByFee: true,
30
31
  customFeeTemplate: [
31
32
  {
32
33
  type: 'nativeAmount',
@@ -21,6 +21,7 @@ var _constants = require('../../constants');
21
21
  blockbookServers: ['wss://tbtc1.trezor.io', 'wss://tbtc2.trezor.io'],
22
22
  enableCustomServers: false
23
23
  },
24
+ canReplaceByFee: true,
24
25
  customFeeTemplate: [
25
26
  {
26
27
  type: 'nativeAmount',
@@ -25,6 +25,7 @@ var _constants = require('../../constants');
25
25
  ],
26
26
  enableCustomServers: false
27
27
  },
28
+ canReplaceByFee: true,
28
29
  customFeeTemplate: [
29
30
  {
30
31
  type: 'nativeAmount',
@@ -15,10 +15,12 @@ var _cleaners = require('cleaners');
15
15
 
16
16
 
17
17
 
18
+
18
19
  var _types3 = require('../../plugin/types');
19
20
  var _utils = require('../engine/utils');
20
21
 
21
22
  // Private key format are a strict subset of all currency formats
23
+
22
24
  const asPrivateKeyFormat = _cleaners.asValue.call(void 0, 'bip32', 'bip44', 'bip49')
23
25
  // Default to bip32 always for legacy reasons
24
26
  const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKeyFormat, 'bip32')
@@ -82,26 +84,44 @@ const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKe
82
84
  }); exports.asPublicKey = asPublicKey
83
85
 
84
86
  /**
85
- * This utility returns a wallet's supported formats as specified in the
86
- * key-formats specification.
87
+ * This utility returns a wallet's supported formats according to its
88
+ * private-key's format as specified in the key-formats specification.
87
89
  */
88
90
  const getSupportedFormats = (
89
- format
91
+ engineInfo,
92
+ privateKeyFormat
90
93
  ) => {
91
- switch (format) {
92
- case 'bip32':
93
- return ['bip32']
94
- case 'bip44':
95
- return ['bip44']
96
- case 'bip49':
97
- return ['bip49']
98
- case 'bip84':
99
- return ['bip84']
100
- default:
101
- throw new Error(`Unsupported format ${format}`)
102
- }
94
+ const formats = (() => {
95
+ switch (privateKeyFormat) {
96
+ case 'bip32':
97
+ return ['bip32']
98
+ case 'bip44':
99
+ return ['bip44']
100
+ case 'bip49':
101
+ return ['bip49', 'bip84']
102
+ }
103
+ })()
104
+ const engineInfoFormats = _nullishCoalesce(engineInfo.formats, () => ( ['bip44', 'bip32']))
105
+ return formats.filter(format => engineInfoFormats.includes(format))
103
106
  }; exports.getSupportedFormats = getSupportedFormats
104
107
 
108
+ /**
109
+ * Infers the private key format given a public key
110
+ */
111
+
112
+ const inferPrivateKeyFormat = (
113
+ publicKey
114
+ ) => {
115
+ const supportedFormats = []
116
+ for (const [format, xpub] of Object.entries(publicKey.publicKeys)) {
117
+ if (xpub != null) supportedFormats.push(format )
118
+ }
119
+ if (supportedFormats.includes('bip49')) return 'bip49'
120
+ if (supportedFormats.includes('bip44')) return 'bip44'
121
+ if (supportedFormats.includes('bip32')) return 'bip32'
122
+ return 'bip32'
123
+ }; exports.inferPrivateKeyFormat = inferPrivateKeyFormat
124
+
105
125
  /**
106
126
  * A cleaner that desensitizes the walletInfo object, excluding sensitive
107
127
  * keys (seed/mnemonic, sync key, data key, etc). By using this object type
@@ -113,8 +133,9 @@ const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKe
113
133
  * The `walletFormats` field is a list of formats from which to derive
114
134
  * extended-keys for the wallet.
115
135
  *
116
- * The `primaryFormat` field is the default format from which to derive
117
- * addresses from.
136
+ * The `privateKeyFormat` field is the format defined by the private key and is
137
+ * useful for determining the "kind of wallet", or more precisely how the public
138
+ * key (xpubs) formats were derived.
118
139
  */
119
140
 
120
141
 
@@ -130,7 +151,7 @@ const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKe
130
151
  pluginInfo
131
152
  ) => {
132
153
  return (walletInfo) => {
133
- const { engineInfo, coinInfo } = pluginInfo
154
+ const { coinInfo, engineInfo } = pluginInfo
134
155
  const { id, type } = walletInfo
135
156
 
136
157
  const asCurrencyPrivateKey = asPrivateKey(coinInfo.name, coinInfo.coinType)
@@ -152,21 +173,13 @@ const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKe
152
173
  throw new Error('Missing wallet public keys')
153
174
  }
154
175
 
155
- // Search the engineInfo's formats array for the first format that exists
156
- // in the publicKey data.
157
- // If there are no defined formats in the engineInfo, then fallback to the
158
- // first format in the publicKey after sorting alphabetically.
159
- const primaryFormat =
160
- _nullishCoalesce((engineInfo.formats != null && engineInfo.formats.length > 0
161
- ? engineInfo.formats.find(format => walletFormats.includes(format))
162
- : undefined), () => (
163
- walletFormats.sort((a, b) => (a === b ? 0 : a > b ? 1 : -1))[0]))
176
+ const privateKeyFormat = exports.inferPrivateKeyFormat.call(void 0, publicKey)
164
177
 
165
178
  return {
166
179
  id,
167
180
  type,
168
181
  keys: {
169
- primaryFormat,
182
+ privateKeyFormat,
170
183
  walletFormats,
171
184
  publicKey
172
185
  }
@@ -176,16 +189,17 @@ const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKe
176
189
  const privateKey = _cleaners.asMaybe.call(void 0, asCurrencyPrivateKey)(walletInfo.keys)
177
190
  if (privateKey != null) {
178
191
  const publicKey = _utils.deriveXpubsFromKeys.call(void 0, {
192
+ engineInfo,
179
193
  privateKey,
180
194
  coin: coinInfo.name
181
195
  })
182
- const walletFormats = exports.getSupportedFormats.call(void 0, privateKey.format)
196
+ const walletFormats = exports.getSupportedFormats.call(void 0, engineInfo, privateKey.format)
183
197
 
184
198
  return {
185
199
  id,
186
200
  type,
187
201
  keys: {
188
- primaryFormat: privateKey.format,
202
+ privateKeyFormat: privateKey.format,
189
203
  walletFormats,
190
204
  publicKey: { publicKeys: publicKey }
191
205
  }
@@ -49,6 +49,7 @@ export declare const deriveXprivFromKeys: (args: {
49
49
  coin: string;
50
50
  }) => CurrencyFormatKeys;
51
51
  export declare const deriveXpubsFromKeys: (args: {
52
+ engineInfo: EngineInfo;
52
53
  privateKey: PrivateKey;
53
54
  coin: string;
54
55
  }) => CurrencyFormatKeys;
@@ -1,5 +1,7 @@
1
1
  import { Cleaner } from 'cleaners';
2
- import { CurrencyFormat, PluginInfo } from '../../plugin/types';
2
+ import { CurrencyFormat, EngineInfo, PluginInfo } from '../../plugin/types';
3
+ declare type PrivateKeyFormat = ReturnType<typeof asPrivateKeyFormat>;
4
+ declare const asPrivateKeyFormat: Cleaner<"bip32" | "bip44" | "bip49">;
3
5
  /**
4
6
  * A cleaner for the private key format following the key-formats specification.
5
7
  *
@@ -7,7 +9,7 @@ import { CurrencyFormat, PluginInfo } from '../../plugin/types';
7
9
  */
8
10
  export interface PrivateKey {
9
11
  coinType: number;
10
- format: CurrencyFormat;
12
+ format: PrivateKeyFormat;
11
13
  imported?: boolean;
12
14
  seed: string;
13
15
  }
@@ -24,10 +26,14 @@ export interface PublicKey {
24
26
  }
25
27
  export declare const asPublicKey: Cleaner<PublicKey>;
26
28
  /**
27
- * This utility returns a wallet's supported formats as specified in the
28
- * key-formats specification.
29
+ * This utility returns a wallet's supported formats according to its
30
+ * private-key's format as specified in the key-formats specification.
29
31
  */
30
- export declare const getSupportedFormats: (format: CurrencyFormat) => CurrencyFormat[];
32
+ export declare const getSupportedFormats: (engineInfo: EngineInfo, privateKeyFormat: PrivateKeyFormat) => CurrencyFormat[];
33
+ /**
34
+ * Infers the private key format given a public key
35
+ */
36
+ export declare const inferPrivateKeyFormat: (publicKey: PublicKey) => PrivateKeyFormat;
31
37
  /**
32
38
  * A cleaner that desensitizes the walletInfo object, excluding sensitive
33
39
  * keys (seed/mnemonic, sync key, data key, etc). By using this object type
@@ -39,17 +45,19 @@ export declare const getSupportedFormats: (format: CurrencyFormat) => CurrencyFo
39
45
  * The `walletFormats` field is a list of formats from which to derive
40
46
  * extended-keys for the wallet.
41
47
  *
42
- * The `primaryFormat` field is the default format from which to derive
43
- * addresses from.
48
+ * The `privateKeyFormat` field is the format defined by the private key and is
49
+ * useful for determining the "kind of wallet", or more precisely how the public
50
+ * key (xpubs) formats were derived.
44
51
  */
45
52
  export interface NumbWalletInfo {
46
53
  id: string;
47
54
  type: string;
48
55
  keys: {
49
56
  imported?: boolean;
50
- primaryFormat: CurrencyFormat;
57
+ privateKeyFormat: PrivateKeyFormat;
51
58
  publicKey: PublicKey;
52
59
  walletFormats: CurrencyFormat[];
53
60
  };
54
61
  }
55
62
  export declare const asNumbWalletInfo: (pluginInfo: PluginInfo) => Cleaner<NumbWalletInfo>;
63
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Edge currency plugins to fetch and process wallet accounts, balances and transactions.",
5
5
  "repository": "https://github.com/EdgeApp/edge-currency-plugins",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "altcoin-js": "https://github.com/EdgeApp/altcoin-js.git#master",
37
37
  "async-mutex": "^0.2.6",
38
- "baselet": "^0.2.2",
38
+ "baselet": "^0.2.3",
39
39
  "biggystring": "^4.0.0",
40
40
  "bip32": "^2.0.5",
41
41
  "bip32grs": "^2.0.5",
@@ -48,9 +48,9 @@
48
48
  "bs58smartcheck": "^2.0.4",
49
49
  "cleaners": "^0.3.12",
50
50
  "disklet": "^0.4.5",
51
- "edge-core-js": "^0.19.33",
51
+ "edge-core-js": "^0.19.37",
52
52
  "edge-sync-client": "^0.2.7",
53
- "memlet": "^0.1.6",
53
+ "memlet": "^0.1.7",
54
54
  "uri-js": "^4.4.0",
55
55
  "url-parse": "^1.5.2",
56
56
  "wif-smart": "^2.0.0",