edge-currency-plugins 2.1.1 → 2.2.1

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 (37) hide show
  1. package/lib/common/plugin/makeCurrencyTools.js +0 -5
  2. package/lib/common/upgradeMemos.js +47 -0
  3. package/lib/common/utxobased/db/Models/ProcessorTransaction.js +7 -4
  4. package/lib/common/utxobased/engine/makeUtxoEngine.js +18 -18
  5. package/lib/common/utxobased/engine/utils.js +0 -13
  6. package/lib/common/utxobased/info/badcoin.js +6 -2
  7. package/lib/common/utxobased/info/bitcoin.js +6 -2
  8. package/lib/common/utxobased/info/bitcoincash.js +6 -2
  9. package/lib/common/utxobased/info/bitcoincashtestnet.js +6 -2
  10. package/lib/common/utxobased/info/bitcoingold.js +6 -2
  11. package/lib/common/utxobased/info/bitcoingoldtestnet.js +6 -2
  12. package/lib/common/utxobased/info/bitcoinsv.js +7 -3
  13. package/lib/common/utxobased/info/bitcointestnet.js +6 -2
  14. package/lib/common/utxobased/info/commonInfo.js +16 -0
  15. package/lib/common/utxobased/info/dash.js +7 -2
  16. package/lib/common/utxobased/info/digibyte.js +6 -2
  17. package/lib/common/utxobased/info/dogecoin.js +6 -2
  18. package/lib/common/utxobased/info/eboost.js +6 -2
  19. package/lib/common/utxobased/info/feathercoin.js +6 -2
  20. package/lib/common/utxobased/info/groestlcoin.js +6 -2
  21. package/lib/common/utxobased/info/litecoin.js +6 -2
  22. package/lib/common/utxobased/info/qtum.js +6 -2
  23. package/lib/common/utxobased/info/ravencoin.js +6 -2
  24. package/lib/common/utxobased/info/smartcash.js +6 -2
  25. package/lib/common/utxobased/info/ufo.js +6 -2
  26. package/lib/common/utxobased/info/vertcoin.js +6 -2
  27. package/lib/common/utxobased/info/zcoin.js +6 -2
  28. package/lib/common/utxobased/keymanager/keymanager.js +14 -18
  29. package/lib/common/validateMemos.js +107 -0
  30. package/lib/src/common/upgradeMemos.d.ts +6 -0
  31. package/lib/src/common/utxobased/engine/utils.d.ts +1 -2
  32. package/lib/src/common/utxobased/info/commonInfo.d.ts +2 -0
  33. package/lib/src/common/utxobased/keymanager/keymanager.d.ts +2 -2
  34. package/lib/src/common/validateMemos.d.ts +6 -0
  35. package/lib/src/util/cleaners.d.ts +6 -0
  36. package/lib/util/cleaners.js +18 -0
  37. package/package.json +2 -2
@@ -9,7 +9,6 @@ var _cleaners = require('cleaners');
9
9
 
10
10
 
11
11
 
12
-
13
12
  var _urijs = require('uri-js'); var uri = _interopRequireWildcard(_urijs);
14
13
  var _urlparse = require('url-parse'); var _urlparse2 = _interopRequireDefault(_urlparse);
15
14
 
@@ -98,10 +97,6 @@ var _utils3 = require('./utils');
98
97
  return wasCurrencyPrivateKey(privateKey)
99
98
  },
100
99
 
101
- async validateMemo(memo) {
102
- return _utils.validateMemo.call(void 0, memo)
103
- },
104
-
105
100
  async derivePublicKey(
106
101
  unsafeWalletInfo
107
102
  ) {
@@ -0,0 +1,47 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _validateMemos = require('./validateMemos');
4
+
5
+ /**
6
+ * Upgrades the memo fields inside an EdgeSpendTarget,
7
+ * since we need to be runtime-compatible with legacy core versions.
8
+ */
9
+ function upgradeMemos(
10
+ spendInfo,
11
+ currencyInfo
12
+ ) {
13
+ const { memoType } = currencyInfo
14
+
15
+ const legacyMemos = []
16
+
17
+ // If this chain supports legacy memos, grab those:
18
+ if (memoType === 'hex' || memoType === 'number' || memoType === 'text') {
19
+ for (const target of spendInfo.spendTargets) {
20
+ if (target.memo != null) {
21
+ legacyMemos.push({
22
+ type: memoType,
23
+ value: target.memo
24
+ })
25
+ } else if (target.uniqueIdentifier != null) {
26
+ legacyMemos.push({
27
+ type: memoType,
28
+ value: target.uniqueIdentifier
29
+ })
30
+ } else if (typeof _optionalChain([target, 'access', _ => _.otherParams, 'optionalAccess', _2 => _2.uniqueIdentifier]) === 'string') {
31
+ legacyMemos.push({
32
+ type: memoType,
33
+ value: target.otherParams.uniqueIdentifier
34
+ })
35
+ }
36
+ }
37
+ }
38
+
39
+ // If we don't have modern memos, use the legacy ones:
40
+ const out = {
41
+ ...spendInfo,
42
+ memos: _nullishCoalesce(spendInfo.memos, () => ( legacyMemos))
43
+ }
44
+
45
+ _validateMemos.validateMemos.call(void 0, out, currencyInfo)
46
+ return out
47
+ } exports.upgradeMemos = upgradeMemos;
@@ -1,4 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _altcoinjs = require('altcoin-js');
2
+ var _biggystring = require('biggystring');
2
3
  var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
3
4
 
4
5
 
@@ -95,16 +96,18 @@ var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
95
96
  } catch (e) {}
96
97
 
97
98
  return {
98
- walletId,
99
- currencyCode: currencyInfo.currencyCode,
100
- txid: tx.txid,
101
99
  blockHeight: tx.blockHeight,
102
100
  confirmations: tx.confirmations,
101
+ currencyCode: currencyInfo.currencyCode,
103
102
  date: tx.date,
103
+ isSend: _biggystring.lt.call(void 0, tx.ourAmount, '0'),
104
+ memos: [],
104
105
  nativeAmount: tx.ourAmount,
105
106
  networkFee: tx.fees,
106
- signedTx: tx.hex,
107
107
  ourReceiveAddresses,
108
+ signedTx: tx.hex,
109
+ txid: tx.txid,
110
+ walletId,
108
111
  ...feeRes
109
112
  }
110
113
  }; exports.toEdgeTransaction = toEdgeTransaction
@@ -24,6 +24,7 @@ var _makeFees = require('../../fees/makeFees');
24
24
  var _makeEngineEmitter = require('../../plugin/makeEngineEmitter');
25
25
  var _makeMetadata = require('../../plugin/makeMetadata');
26
26
 
27
+ var _upgradeMemos = require('../../upgradeMemos');
27
28
  var _makeProcessor = require('../db/makeProcessor');
28
29
 
29
30
 
@@ -292,7 +293,8 @@ var _utils = require('./utils');
292
293
  },
293
294
 
294
295
  async makeSpend(edgeSpendInfo) {
295
- const { spendTargets } = edgeSpendInfo
296
+ edgeSpendInfo = _upgradeMemos.upgradeMemos.call(void 0, edgeSpendInfo, currencyInfo)
297
+ const { memos = [], spendTargets } = edgeSpendInfo
296
298
  const txOptions =
297
299
  _optionalChain([edgeSpendInfo, 'access', _5 => _5.otherParams, 'optionalAccess', _6 => _6.txOptions])
298
300
  const { outputSort = 'bip69', utxoSourceAddress, forceChangeAddress } =
@@ -330,10 +332,7 @@ var _utils = require('./utils');
330
332
  let targets = []
331
333
  const ourReceiveAddresses = []
332
334
  for (const target of spendTargets) {
333
- if (
334
- target.memo == null &&
335
- (target.publicAddress == null || target.nativeAmount == null)
336
- ) {
335
+ if (target.publicAddress == null || target.nativeAmount == null) {
337
336
  throw new Error('Invalid spend target')
338
337
  }
339
338
 
@@ -350,8 +349,7 @@ var _utils = require('./utils');
350
349
  value:
351
350
  target.nativeAmount == null
352
351
  ? undefined
353
- : parseInt(target.nativeAmount),
354
- memo: target.memo
352
+ : parseInt(target.nativeAmount)
355
353
  })
356
354
  }
357
355
  } else {
@@ -368,13 +366,12 @@ var _utils = require('./utils');
368
366
  value:
369
367
  target.nativeAmount == null
370
368
  ? undefined
371
- : parseInt(target.nativeAmount),
372
- memo: target.memo
369
+ : parseInt(target.nativeAmount)
373
370
  })
374
371
  }
375
372
  }
376
373
 
377
- if (targets.length < 1) {
374
+ if (targets.length + memos.length < 1) {
378
375
  throw new Error('Need to provide Spend Targets')
379
376
  }
380
377
 
@@ -427,6 +424,7 @@ var _utils = require('./utils');
427
424
  utxos,
428
425
  forceUseUtxo: maxUtxo != null ? [maxUtxo] : [],
429
426
  targets,
427
+ memos,
430
428
  feeRate,
431
429
  coin: coinInfo.name,
432
430
  currencyCode: currencyInfo.currencyCode,
@@ -471,19 +469,21 @@ var _utils = require('./utils');
471
469
  }
472
470
 
473
471
  const transaction = {
474
- walletId: walletInfo.id,
475
- ourReceiveAddresses,
476
- otherParams,
472
+ blockHeight: 0,
477
473
  currencyCode: currencyInfo.currencyCode,
478
- txid: '',
479
474
  date: _unixTime.unixTime.call(void 0, ),
480
- blockHeight: 0,
481
- nativeAmount,
482
- networkFee,
483
475
  feeRateUsed: {
484
476
  satPerVByte: feeRate
485
477
  },
486
- signedTx: ''
478
+ isSend: true,
479
+ memos,
480
+ nativeAmount,
481
+ networkFee,
482
+ otherParams,
483
+ ourReceiveAddresses,
484
+ signedTx: '',
485
+ txid: '',
486
+ walletId: walletInfo.id
487
487
  }
488
488
 
489
489
  return transaction
@@ -39,19 +39,6 @@ var _keymanager = require('../keymanager/keymanager');
39
39
  }
40
40
  }; exports.getCurrencyFormatFromPurposeType = getCurrencyFormatFromPurposeType
41
41
 
42
- // Expect memo to be a hex string
43
- const validateMemo = (memo) => {
44
- const result = {
45
- passed: true,
46
- tooLarge: false
47
- }
48
- if (Math.ceil(memo.length / 2) > 80) {
49
- result.passed = false
50
- result.tooLarge = true
51
- }
52
- return result
53
- }; exports.validateMemo = validateMemo
54
-
55
42
  const getAddressTypeFromPurposeType = (
56
43
  purpose
57
44
  ) => {
@@ -1,6 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
+ var _commonInfo = require('./commonInfo');
4
5
 
5
6
  const currencyInfo = {
6
7
  pluginId: 'badcoin',
@@ -26,12 +27,15 @@ const currencyInfo = {
26
27
  displayMultiplier: '0'
27
28
  }
28
29
  ],
29
- metaTokens: [],
30
+ ..._commonInfo.memoInfo,
30
31
 
31
32
  // Explorers:
32
33
  addressExplorer: 'https://www.blockingbad.com/address/%s',
33
34
  blockExplorer: 'https://www.blockingbad.com/block/%s',
34
- transactionExplorer: 'https://www.blockingbad.com/tx/%s'
35
+ transactionExplorer: 'https://www.blockingbad.com/tx/%s',
36
+
37
+ // Deprecated:
38
+ metaTokens: []
35
39
  }
36
40
 
37
41
  const engineInfo = {
@@ -2,6 +2,7 @@
2
2
 
3
3
  var _constants = require('../../constants');
4
4
 
5
+ var _commonInfo = require('./commonInfo');
5
6
 
6
7
  const currencyInfo = {
7
8
  pluginId: 'bitcoin',
@@ -36,7 +37,7 @@ const currencyInfo = {
36
37
  displayMultiplier: '0'
37
38
  }
38
39
  ],
39
- metaTokens: [],
40
+ ..._commonInfo.memoInfo,
40
41
 
41
42
  // Explorers:
42
43
  blockExplorer: 'https://blockchair.com/bitcoin/block/%s',
@@ -45,7 +46,10 @@ const currencyInfo = {
45
46
 
46
47
  // Images:
47
48
  symbolImage: `${_constants.IMAGE_SERVER_URL}/bitcoin-logo-solo-64.png`,
48
- symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/bitcoin-logo-solo-64.png`
49
+ symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/bitcoin-logo-solo-64.png`,
50
+
51
+ // Deprecated:
52
+ metaTokens: []
49
53
  }
50
54
 
51
55
  const engineInfo = {
@@ -4,6 +4,7 @@ var _cleaners = require('cleaners');
4
4
 
5
5
  var _constants = require('../../constants');
6
6
 
7
+ var _commonInfo = require('./commonInfo');
7
8
  var _bitcoincashScriptTemplates = require('./scriptTemplates/bitcoincashScriptTemplates');
8
9
 
9
10
  const currencyInfo = {
@@ -37,7 +38,7 @@ const currencyInfo = {
37
38
  displayMultiplier: '0'
38
39
  }
39
40
  ],
40
- metaTokens: [],
41
+ ..._commonInfo.memoInfo,
41
42
 
42
43
  // Explorers:
43
44
  blockExplorer: 'https://blockchair.com/bitcoin-cash/block/%s',
@@ -47,7 +48,10 @@ const currencyInfo = {
47
48
 
48
49
  // Images:
49
50
  symbolImage: `${_constants.IMAGE_SERVER_URL}/bitcoincash-logo-solo-64.png`,
50
- symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/bitcoincash-logo-solo-64.png`
51
+ symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/bitcoincash-logo-solo-64.png`,
52
+
53
+ // Deprecated:
54
+ metaTokens: []
51
55
  }
52
56
 
53
57
  const engineInfo = {
@@ -3,6 +3,7 @@
3
3
 
4
4
  var _constants = require('../../constants');
5
5
 
6
+ var _commonInfo = require('./commonInfo');
6
7
  var _bitcoincashScriptTemplates = require('./scriptTemplates/bitcoincashScriptTemplates');
7
8
 
8
9
  const currencyInfo = {
@@ -22,7 +23,7 @@ const currencyInfo = {
22
23
  blockbookServers: [],
23
24
  enableCustomServers: false
24
25
  },
25
- metaTokens: [],
26
+ ..._commonInfo.memoInfo,
26
27
 
27
28
  // Explorers:
28
29
  blockExplorer: 'https://blockchair.com/bitcoin-cash/block/%s',
@@ -32,7 +33,10 @@ const currencyInfo = {
32
33
 
33
34
  // Images:
34
35
  symbolImage: `${_constants.IMAGE_SERVER_URL}/bitcoincash-logo-solo-64.png`,
35
- symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/bitcoincash-logo-solo-64.png`
36
+ symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/bitcoincash-logo-solo-64.png`,
37
+
38
+ // Deprecated:
39
+ metaTokens: []
36
40
  }
37
41
 
38
42
  const engineInfo = {
@@ -2,6 +2,7 @@
2
2
 
3
3
 
4
4
 
5
+ var _commonInfo = require('./commonInfo');
5
6
 
6
7
  const currencyInfo = {
7
8
  pluginId: 'bitcoingold',
@@ -34,12 +35,15 @@ const currencyInfo = {
34
35
  displayMultiplier: '0'
35
36
  }
36
37
  ],
37
- metaTokens: [],
38
+ ..._commonInfo.memoInfo,
38
39
 
39
40
  // Explorers:
40
41
  addressExplorer: 'https://explorer.bitcoingold.org/insight/address/%s',
41
42
  blockExplorer: 'https://explorer.bitcoingold.org/insight/block/%s',
42
- transactionExplorer: 'https://explorer.bitcoingold.org/insight/tx/%s'
43
+ transactionExplorer: 'https://explorer.bitcoingold.org/insight/tx/%s',
44
+
45
+ // Deprecated:
46
+ metaTokens: []
43
47
  }
44
48
 
45
49
  const engineInfo = {
@@ -2,6 +2,7 @@
2
2
 
3
3
 
4
4
 
5
+ var _commonInfo = require('./commonInfo');
5
6
 
6
7
  const currencyInfo = {
7
8
  pluginId: 'bitcoingoldtestnet',
@@ -20,12 +21,15 @@ const currencyInfo = {
20
21
  blockbookServers: [],
21
22
  enableCustomServers: false
22
23
  },
23
- metaTokens: [],
24
+ ..._commonInfo.memoInfo,
24
25
 
25
26
  // Explorers:
26
27
  addressExplorer: 'https://explorer.bitcoingold.org/insight/address/%s',
27
28
  blockExplorer: 'https://explorer.bitcoingold.org/insight/block/%s',
28
- transactionExplorer: 'https://explorer.bitcoingold.org/insight/tx/%s'
29
+ transactionExplorer: 'https://explorer.bitcoingold.org/insight/tx/%s',
30
+
31
+ // Deprecated:
32
+ metaTokens: []
29
33
  }
30
34
 
31
35
  const engineInfo = {
@@ -9,6 +9,7 @@ var _constants = require('../../constants');
9
9
 
10
10
 
11
11
  var _keymanager = require('../keymanager/keymanager');
12
+ var _commonInfo = require('./commonInfo');
12
13
 
13
14
  const currencyInfo = {
14
15
  pluginId: 'bitcoinsv',
@@ -35,7 +36,7 @@ const currencyInfo = {
35
36
  displayMultiplier: '0'
36
37
  }
37
38
  ],
38
- metaTokens: [],
39
+ ..._commonInfo.memoInfo,
39
40
 
40
41
  // Explorers:
41
42
  blockExplorer: 'https://whatsonchain.com/block/%s',
@@ -44,7 +45,10 @@ const currencyInfo = {
44
45
 
45
46
  // Images:
46
47
  symbolImage: `${_constants.IMAGE_SERVER_URL}/bitcoinsv-logo-solo-64.png`,
47
- symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/bitcoinsv-logo-solo-64.png`
48
+ symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/bitcoinsv-logo-solo-64.png`,
49
+
50
+ // Deprecated:
51
+ metaTokens: []
48
52
  }
49
53
 
50
54
  const engineInfo = {
@@ -69,7 +73,7 @@ const engineInfo = {
69
73
  /*
70
74
  This is to support cashaddr and 1-addresses coming from the network.
71
75
  We always convert to a 1-address for internal use.
72
- We send 1-address to the network because all servers should support legacy
76
+ We send 1-address to the network because all servers should support legacy
73
77
  address (this is the uncleaner).
74
78
  */
75
79
  asBlockbookAddress: _cleaners.asCodec.call(void 0,
@@ -2,6 +2,7 @@
2
2
 
3
3
  var _constants = require('../../constants');
4
4
 
5
+ var _commonInfo = require('./commonInfo');
5
6
 
6
7
  const currencyInfo = {
7
8
  pluginId: 'bitcointestnet',
@@ -30,7 +31,7 @@ var _constants = require('../../constants');
30
31
  displayMultiplier: '0'
31
32
  }
32
33
  ],
33
- metaTokens: [],
34
+ ..._commonInfo.memoInfo,
34
35
 
35
36
  // Explorers:
36
37
  blockExplorer: 'https://blockchair.com/bitcoin/testnet/block/%s',
@@ -39,7 +40,10 @@ var _constants = require('../../constants');
39
40
 
40
41
  // Images:
41
42
  symbolImage: `${_constants.IMAGE_SERVER_URL}/bitcoin-logo-solo-64.png`,
42
- symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/bitcoin-logo-solo-64.png`
43
+ symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/bitcoin-logo-solo-64.png`,
44
+
45
+ // Deprecated:
46
+ metaTokens: []
43
47
  }; exports.currencyInfo = currencyInfo
44
48
 
45
49
  const engineInfo = {
@@ -0,0 +1,16 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ const memoInfo = {
4
+ memoOptions: [
5
+ {
6
+ type: 'hex',
7
+ hidden: true,
8
+ maxBytes: 80,
9
+ memoName: 'OP_RETURN'
10
+ }
11
+ ],
12
+
13
+ // Deprecated:
14
+ memoMaxLength: 80,
15
+ memoType: 'text'
16
+ }; exports.memoInfo = memoInfo
@@ -3,6 +3,7 @@
3
3
 
4
4
 
5
5
 
6
+ var _commonInfo = require('./commonInfo');
6
7
 
7
8
  const currencyInfo = {
8
9
  pluginId: 'dash',
@@ -34,12 +35,16 @@ const currencyInfo = {
34
35
  displayMultiplier: '0'
35
36
  }
36
37
  ],
37
- metaTokens: [],
38
+ ..._commonInfo.memoInfo,
38
39
 
39
40
  // Explorers:
40
41
  addressExplorer: 'https://blockchair.com/dash/address/%s?from=edgeapp',
41
42
  blockExplorer: 'https://blockchair.com/dash/block/%s?from=edgeapp',
42
- transactionExplorer: 'https://blockchair.com/dash/transaction/%s?from=edgeapp'
43
+ transactionExplorer:
44
+ 'https://blockchair.com/dash/transaction/%s?from=edgeapp',
45
+
46
+ // Deprecated:
47
+ metaTokens: []
43
48
  }
44
49
 
45
50
  const engineInfo = {
@@ -1,6 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
+ var _commonInfo = require('./commonInfo');
4
5
 
5
6
  const currencyInfo = {
6
7
  pluginId: 'digibyte',
@@ -26,12 +27,15 @@ const currencyInfo = {
26
27
  displayMultiplier: '0'
27
28
  }
28
29
  ],
29
- metaTokens: [],
30
+ ..._commonInfo.memoInfo,
30
31
 
31
32
  // Explorers:
32
33
  addressExplorer: 'https://digiexplorer.info/address/%s',
33
34
  blockExplorer: 'https://digiexplorer.info/block/%s',
34
- transactionExplorer: 'https://digiexplorer.info/tx/%s'
35
+ transactionExplorer: 'https://digiexplorer.info/tx/%s',
36
+
37
+ // Deprecated:
38
+ metaTokens: []
35
39
  }
36
40
 
37
41
  const engineInfo = {
@@ -1,6 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
+ var _commonInfo = require('./commonInfo');
4
5
  var _dogeUtxoPicker = require('./utxoPickers/dogeUtxoPicker');
5
6
 
6
7
  const currencyInfo = {
@@ -30,13 +31,16 @@ const currencyInfo = {
30
31
  displayMultiplier: '0'
31
32
  }
32
33
  ],
33
- metaTokens: [],
34
+ ..._commonInfo.memoInfo,
34
35
 
35
36
  // Explorers:
36
37
  addressExplorer: 'https://blockchair.com/dogecoin/address/%s?from=edgeapp',
37
38
  blockExplorer: 'https://blockchair.com/dogecoin/block/%s?from=edgeapp',
38
39
  transactionExplorer:
39
- 'https://blockchair.com/dogecoin/transaction/%s?from=edgeapp'
40
+ 'https://blockchair.com/dogecoin/transaction/%s?from=edgeapp',
41
+
42
+ // Deprecated:
43
+ metaTokens: []
40
44
  }
41
45
 
42
46
  const engineInfo = {
@@ -1,6 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
+ var _commonInfo = require('./commonInfo');
4
5
 
5
6
  const currencyInfo = {
6
7
  pluginId: 'eboost',
@@ -26,12 +27,15 @@ const currencyInfo = {
26
27
  displayMultiplier: '0'
27
28
  }
28
29
  ],
29
- metaTokens: [],
30
+ ..._commonInfo.memoInfo,
30
31
 
31
32
  // Explorers:
32
33
  addressExplorer: 'https://www.blockexperts.com/ebst/address/%s',
33
34
  blockExplorer: 'https://www.blockexperts.com/ebst/hash/%s',
34
- transactionExplorer: 'https://www.blockexperts.com/ebst/tx/%s'
35
+ transactionExplorer: 'https://www.blockexperts.com/ebst/tx/%s',
36
+
37
+ // Deprecated:
38
+ metaTokens: []
35
39
  }
36
40
 
37
41
  const engineInfo = {
@@ -2,6 +2,7 @@
2
2
 
3
3
  var _constants = require('../../constants');
4
4
 
5
+ var _commonInfo = require('./commonInfo');
5
6
 
6
7
  const currencyInfo = {
7
8
  pluginId: 'feathercoin',
@@ -27,7 +28,7 @@ var _constants = require('../../constants');
27
28
  displayMultiplier: '0'
28
29
  }
29
30
  ],
30
- metaTokens: [],
31
+ ..._commonInfo.memoInfo,
31
32
 
32
33
  // Explorers:
33
34
  addressExplorer: 'https://fsight.chain.tips/address/%s',
@@ -36,7 +37,10 @@ var _constants = require('../../constants');
36
37
 
37
38
  // Images:
38
39
  symbolImage: `${_constants.IMAGE_SERVER_URL}/feathercoin-logo-solo-64.png`,
39
- symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/feathercoin-logo-solo-64.png`
40
+ symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/feathercoin-logo-solo-64.png`,
41
+
42
+ // Deprecated:
43
+ metaTokens: []
40
44
  }; exports.currencyInfo = currencyInfo
41
45
 
42
46
  const engineInfo = {
@@ -5,6 +5,7 @@ var _bs58grscheck = require('bs58grscheck'); var base58grs = _interopRequireWild
5
5
  var _wifgrs = require('wifgrs'); var wifgrs = _interopRequireWildcard(_wifgrs);
6
6
 
7
7
 
8
+ var _commonInfo = require('./commonInfo');
8
9
 
9
10
  const currencyInfo = {
10
11
  pluginId: 'groestlcoin',
@@ -30,14 +31,17 @@ const currencyInfo = {
30
31
  displayMultiplier: '0'
31
32
  }
32
33
  ],
33
- metaTokens: [],
34
+ ..._commonInfo.memoInfo,
34
35
 
35
36
  // Explorers:
36
37
  addressExplorer:
37
38
  'https://blockchair.com/groestlcoin/address/%s?from=edgeapp?from=edgeapp',
38
39
  blockExplorer: 'https://blockchair.com/groestlcoin/block/%s?from=edgeapp',
39
40
  transactionExplorer:
40
- 'https://blockchair.com/groestlcoin/transaction/%s?from=edgeapp'
41
+ 'https://blockchair.com/groestlcoin/transaction/%s?from=edgeapp',
42
+
43
+ // Deprecated:
44
+ metaTokens: []
41
45
  }
42
46
 
43
47
  const engineInfo = {
@@ -2,6 +2,7 @@
2
2
 
3
3
  var _constants = require('../../constants');
4
4
 
5
+ var _commonInfo = require('./commonInfo');
5
6
 
6
7
  const currencyInfo = {
7
8
  pluginId: 'litecoin',
@@ -34,7 +35,7 @@ var _constants = require('../../constants');
34
35
  displayMultiplier: '0'
35
36
  }
36
37
  ],
37
- metaTokens: [],
38
+ ..._commonInfo.memoInfo,
38
39
 
39
40
  // Explorers:
40
41
  blockExplorer: 'https://blockchair.com/litecoin/block/%s',
@@ -43,7 +44,10 @@ var _constants = require('../../constants');
43
44
 
44
45
  // Images:
45
46
  symbolImage: `${_constants.IMAGE_SERVER_URL}/litecoin-logo-solo-64.png`,
46
- symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/litecoin-logo-solo-64.png`
47
+ symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/litecoin-logo-solo-64.png`,
48
+
49
+ // Deprecated:
50
+ metaTokens: []
47
51
  }; exports.currencyInfo = currencyInfo
48
52
 
49
53
  const engineInfo = {
@@ -1,6 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
+ var _commonInfo = require('./commonInfo');
4
5
 
5
6
  const currencyInfo = {
6
7
  pluginId: 'qtum',
@@ -23,12 +24,15 @@ const currencyInfo = {
23
24
  displayMultiplier: '0'
24
25
  }
25
26
  ],
26
- metaTokens: [],
27
+ ..._commonInfo.memoInfo,
27
28
 
28
29
  // Explorers:
29
30
  addressExplorer: 'https://explorer.qtum.org/address/%s',
30
31
  blockExplorer: 'https://explorer.qtum.org/block/%s',
31
- transactionExplorer: 'https://explorer.qtum.org/tx/%s'
32
+ transactionExplorer: 'https://explorer.qtum.org/tx/%s',
33
+
34
+ // Deprecated:
35
+ metaTokens: []
32
36
  }
33
37
 
34
38
  const engineInfo = {
@@ -1,6 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
+ var _commonInfo = require('./commonInfo');
4
5
 
5
6
  const currencyInfo = {
6
7
  pluginId: 'ravencoin',
@@ -23,12 +24,15 @@ const currencyInfo = {
23
24
  displayMultiplier: '0'
24
25
  }
25
26
  ],
26
- metaTokens: [],
27
+ ..._commonInfo.memoInfo,
27
28
 
28
29
  // Explorers:
29
30
  addressExplorer: 'https://ravencoin.network/address/%s',
30
31
  blockExplorer: 'https://ravencoin.network/block/%s',
31
- transactionExplorer: 'https://ravencoin.network/tx/%s'
32
+ transactionExplorer: 'https://ravencoin.network/tx/%s',
33
+
34
+ // Deprecated:
35
+ metaTokens: []
32
36
  }
33
37
 
34
38
  const engineInfo = {
@@ -4,6 +4,7 @@ var _bs58smartcheck = require('bs58smartcheck'); var base58smart = _interopRequi
4
4
  var _wifsmart = require('wif-smart'); var wifsmart = _interopRequireWildcard(_wifsmart);
5
5
 
6
6
 
7
+ var _commonInfo = require('./commonInfo');
7
8
 
8
9
  const currencyInfo = {
9
10
  pluginId: 'smartcash',
@@ -29,12 +30,15 @@ const currencyInfo = {
29
30
  displayMultiplier: '0'
30
31
  }
31
32
  ],
32
- metaTokens: [],
33
+ ..._commonInfo.memoInfo,
33
34
 
34
35
  // Explorers:
35
36
  addressExplorer: 'https://insight.smartcash.cc/address/%s',
36
37
  blockExplorer: 'https://insight.smartcash.cc/block/%s',
37
- transactionExplorer: 'https://insight.smartcash.cc/tx/%s'
38
+ transactionExplorer: 'https://insight.smartcash.cc/tx/%s',
39
+
40
+ // Deprecated:
41
+ metaTokens: []
38
42
  }
39
43
 
40
44
  const engineInfo = {
@@ -1,6 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
+ var _commonInfo = require('./commonInfo');
4
5
 
5
6
  const currencyInfo = {
6
7
  pluginId: 'ufo',
@@ -26,12 +27,15 @@ const currencyInfo = {
26
27
  displayMultiplier: '0'
27
28
  }
28
29
  ],
29
- metaTokens: [],
30
+ ..._commonInfo.memoInfo,
30
31
 
31
32
  // Explorers:
32
33
  addressExplorer: 'https://explorer.ufobject.com/address/%s',
33
34
  blockExplorer: 'https://explorer.ufobject.com/block/%s',
34
- transactionExplorer: 'https://explorer.ufobject.com/tx/%s'
35
+ transactionExplorer: 'https://explorer.ufobject.com/tx/%s',
36
+
37
+ // Deprecated:
38
+ metaTokens: []
35
39
  }
36
40
 
37
41
  const engineInfo = {
@@ -1,6 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
+ var _commonInfo = require('./commonInfo');
4
5
 
5
6
  const currencyInfo = {
6
7
  pluginId: 'vertcoin',
@@ -32,12 +33,15 @@ const currencyInfo = {
32
33
  displayMultiplier: '0'
33
34
  }
34
35
  ],
35
- metaTokens: [],
36
+ ..._commonInfo.memoInfo,
36
37
 
37
38
  // Explorers:
38
39
  addressExplorer: 'https://insight.vertcoin.org/address/%s',
39
40
  blockExplorer: 'https://insight.vertcoin.org/block/%s',
40
- transactionExplorer: 'https://insight.vertcoin.org/tx/%s'
41
+ transactionExplorer: 'https://insight.vertcoin.org/tx/%s',
42
+
43
+ // Deprecated:
44
+ metaTokens: []
41
45
  }
42
46
 
43
47
  const engineInfo = {
@@ -2,6 +2,7 @@
2
2
 
3
3
  var _constants = require('../../constants');
4
4
 
5
+ var _commonInfo = require('./commonInfo');
5
6
 
6
7
  const currencyInfo = {
7
8
  pluginId: 'zcoin',
@@ -27,7 +28,7 @@ var _constants = require('../../constants');
27
28
  displayMultiplier: '0'
28
29
  }
29
30
  ],
30
- metaTokens: [],
31
+ ..._commonInfo.memoInfo,
31
32
 
32
33
  // Explorers:
33
34
  addressExplorer: 'https://insight.zcoin.io/address/%s',
@@ -36,7 +37,10 @@ var _constants = require('../../constants');
36
37
 
37
38
  // Images:
38
39
  symbolImage: `${_constants.IMAGE_SERVER_URL}/zcoin-logo-solo-64.png`,
39
- symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/zcoin-logo-solo-64.png`
40
+ symbolImageDarkMono: `${_constants.IMAGE_SERVER_URL}/zcoin-logo-solo-64.png`,
41
+
42
+ // Deprecated:
43
+ metaTokens: []
40
44
  }; exports.currencyInfo = currencyInfo
41
45
 
42
46
  const engineInfo = {
@@ -19,7 +19,6 @@ var _indexAtProtected = require('../../../util/indexAtProtected');
19
19
  var _undefinedIfEmptyString = require('../../../util/undefinedIfEmptyString');
20
20
 
21
21
 
22
- var _utils = require('../engine/utils');
23
22
 
24
23
  var _bip69 = require('./bip69');
25
24
 
@@ -926,7 +925,7 @@ const wifToPrivateKeyEncodingInternal = (
926
925
  } exports.signMessageBase64 = signMessageBase64;
927
926
 
928
927
  function makeTx(args) {
929
- const { log, outputSort } = args
928
+ const { log, outputSort, memos } = args
930
929
  let sequence = 0xffffffff
931
930
  if (args.setRBF) {
932
931
  sequence -= 2
@@ -1016,22 +1015,19 @@ const wifToPrivateKeyEncodingInternal = (
1016
1015
  value: target.value
1017
1016
  })
1018
1017
  }
1019
-
1020
- if (target.memo != null && target.memo !== '') {
1021
- const memoHex = Buffer.from(target.memo, 'utf8').toString('hex')
1022
- // check if hex string is within 80 bytes
1023
- const validatedMemo = _utils.validateMemo.call(void 0, memoHex)
1024
- if (!validatedMemo.passed) {
1025
- throw new Error('Memo size exceeds 80 bytes')
1026
- }
1027
- const script = _altcoinjs.script
1028
- .compile([_altcoinjs.opcodes.OP_RETURN, Buffer.from(target.memo, 'utf8')])
1029
- .toString('hex')
1030
- targets.push({
1031
- script,
1032
- value: 0
1033
- })
1034
- }
1018
+ }
1019
+ for (const memo of memos) {
1020
+ const memoData =
1021
+ memo.type === 'text'
1022
+ ? Buffer.from(memo.value, 'utf8')
1023
+ : Buffer.from(memo.value, 'hex')
1024
+ const script = _altcoinjs.script
1025
+ .compile([_altcoinjs.opcodes.OP_RETURN, memoData])
1026
+ .toString('hex')
1027
+ targets.push({
1028
+ script,
1029
+ value: 0
1030
+ })
1035
1031
  }
1036
1032
 
1037
1033
  const changeScript = exports.addressToScriptPubkey.call(void 0, {
@@ -0,0 +1,107 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _biggystring = require('biggystring');
2
+ var _cleaners = require('cleaners');
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+ var _cleaners3 = require('../util/cleaners');
11
+
12
+ /**
13
+ * Validates the memos on an spend request.
14
+ * Throws an error if any of the memos are wrong.
15
+ */
16
+ function validateMemos(
17
+ spendInfo,
18
+ currencyInfo
19
+ ) {
20
+ const { memos = [] } = spendInfo
21
+ const {
22
+ displayName,
23
+ memoMaxLength,
24
+ memoMaxValue,
25
+ memoOptions = [],
26
+ multipleMemos = false,
27
+ memoType
28
+ } = currencyInfo
29
+
30
+ // Not all coins keep the legacy memo type in the modern list,
31
+ // but we still need to validate the legacy type if present:
32
+ const allOptions = [...memoOptions]
33
+ if (memoType === 'text') {
34
+ allOptions.push({ type: 'text', maxLength: memoMaxLength })
35
+ }
36
+ if (memoType === 'number') {
37
+ allOptions.push({ type: 'number', maxValue: memoMaxValue })
38
+ }
39
+ if (memoType === 'hex') {
40
+ allOptions.push({
41
+ type: 'hex',
42
+ maxBytes: memoMaxLength == null ? undefined : memoMaxLength / 2
43
+ })
44
+ }
45
+
46
+ // What we should call a "memo" in our error messages:
47
+ const { memoName = 'memo' } = _nullishCoalesce(memoOptions[0], () => ( {}))
48
+
49
+ // Now validate our memos:
50
+ for (const memo of memos) {
51
+ const options = allOptions.filter(option => memo.type === option.type)
52
+ if (options.length < 1) {
53
+ throw new Error(`${displayName} ${memoName}: cannot be type ${memo.type}`)
54
+ }
55
+ const problem = options
56
+ .map(option => getMemoError(memo, option))
57
+ .find(problem => problem != null)
58
+ if (problem != null) {
59
+ throw new Error(`${displayName} {memoName}: ${problem}`)
60
+ }
61
+ }
62
+
63
+ // Validate the number of memos:
64
+ if (!multipleMemos && memos.length > 1) {
65
+ throw new Error(`${displayName} only supports one ${memoName}`)
66
+ }
67
+ } exports.validateMemos = validateMemos;
68
+
69
+ /**
70
+ * Checks a memo against a memo option.
71
+ * Returns `undefined` if valid, or an error string if invalid.
72
+ */
73
+ function getMemoError(
74
+ memo,
75
+ option
76
+ ) {
77
+ if (
78
+ option.type === 'text' &&
79
+ option.maxLength != null &&
80
+ memo.value.length > option.maxLength
81
+ ) {
82
+ return `cannot be longer than ${option.maxLength}`
83
+ }
84
+
85
+ if (option.type === 'number') {
86
+ const value = _cleaners.asMaybe.call(void 0, (0, _cleaners3.asIntegerString))(memo.value)
87
+ if (value == null) {
88
+ return `is not a valid number`
89
+ }
90
+ if (option.maxValue != null && _biggystring.gt.call(void 0, value, option.maxValue)) {
91
+ return `cannot be greater than ${option.maxValue}`
92
+ }
93
+ }
94
+
95
+ if (option.type === 'hex') {
96
+ const value = _cleaners.asMaybe.call(void 0, (0, _cleaners3.asBase16))(memo.value)
97
+ if (value == null) {
98
+ return `is not valid hexadecimal`
99
+ }
100
+ if (option.maxBytes != null && value.length > option.maxBytes) {
101
+ return `cannot be longer than ${option.maxBytes} bytes`
102
+ }
103
+ if (option.minBytes != null && value.length < option.minBytes) {
104
+ return `cannot be shorter than ${option.minBytes} bytes`
105
+ }
106
+ }
107
+ }
@@ -0,0 +1,6 @@
1
+ import { EdgeCurrencyInfo, EdgeSpendInfo } from 'edge-core-js/types';
2
+ /**
3
+ * Upgrades the memo fields inside an EdgeSpendTarget,
4
+ * since we need to be runtime-compatible with legacy core versions.
5
+ */
6
+ export declare function upgradeMemos(spendInfo: EdgeSpendInfo, currencyInfo: EdgeCurrencyInfo): EdgeSpendInfo;
@@ -1,12 +1,11 @@
1
1
  import { Disklet } from 'disklet';
2
- import { EdgeMemoRules, EdgeParsedUri } from 'edge-core-js/types';
2
+ import { EdgeParsedUri } from 'edge-core-js/types';
3
3
  import { ChangePath, CurrencyFormat, EngineInfo } from '../../plugin/types';
4
4
  import { IUTXO } from '../db/types';
5
5
  import { ScriptTemplates } from '../info/scriptTemplates/types';
6
6
  import { PrivateKey } from '../keymanager/cleaners';
7
7
  import { AddressTypeEnum, BIP43PurposeTypeEnum, ScriptTypeEnum } from '../keymanager/keymanager';
8
8
  export declare const getCurrencyFormatFromPurposeType: (purpose: BIP43PurposeTypeEnum) => CurrencyFormat;
9
- export declare const validateMemo: (memo: string) => EdgeMemoRules;
10
9
  export declare const getAddressTypeFromPurposeType: (purpose: BIP43PurposeTypeEnum) => AddressTypeEnum;
11
10
  export declare const getScriptTypeFromPurposeType: (purpose: BIP43PurposeTypeEnum) => ScriptTypeEnum;
12
11
  export declare const validScriptPubkeyFromAddress: (args: {
@@ -0,0 +1,2 @@
1
+ import { EdgeCurrencyInfo } from 'edge-core-js/types';
2
+ export declare const memoInfo: Partial<EdgeCurrencyInfo>;
@@ -1,4 +1,4 @@
1
- import { EdgeLog } from 'edge-core-js/types';
1
+ import { EdgeLog, EdgeMemo } from 'edge-core-js/types';
2
2
  import { ChangePath } from '../../plugin/types';
3
3
  import { IUTXO } from '../db/types';
4
4
  import { ScriptTemplate, ScriptTemplates } from '../info/scriptTemplates/types';
@@ -134,6 +134,7 @@ export interface MakeTxArgs {
134
134
  forceUseUtxo: IUTXO[];
135
135
  utxos: IUTXO[];
136
136
  targets: MakeTxTarget[];
137
+ memos: EdgeMemo[];
137
138
  feeRate: number;
138
139
  setRBF: boolean;
139
140
  coin: string;
@@ -146,7 +147,6 @@ export interface MakeTxArgs {
146
147
  export interface MakeTxTarget {
147
148
  address?: string;
148
149
  value?: number;
149
- memo?: string | null;
150
150
  }
151
151
  interface MakeTxReturn extends Required<utxopicker.UtxoPickerResult> {
152
152
  hex: string;
@@ -0,0 +1,6 @@
1
+ import { EdgeCurrencyInfo, EdgeSpendInfo } from 'edge-core-js/types';
2
+ /**
3
+ * Validates the memos on an spend request.
4
+ * Throws an error if any of the memos are wrong.
5
+ */
6
+ export declare function validateMemos(spendInfo: EdgeSpendInfo, currencyInfo: EdgeCurrencyInfo): void;
@@ -0,0 +1,6 @@
1
+ import { Cleaner } from 'cleaners';
2
+ /**
3
+ * A string of hex-encoded binary data.
4
+ */
5
+ export declare const asBase16: Cleaner<Uint8Array>;
6
+ export declare function asIntegerString(raw: unknown): string;
@@ -0,0 +1,18 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _cleaners = require('cleaners');
2
+ var _rfc4648 = require('rfc4648');
3
+
4
+ /**
5
+ * A string of hex-encoded binary data.
6
+ */
7
+ const asBase16 = _cleaners.asCodec.call(void 0,
8
+ raw => _rfc4648.base16.parse(_cleaners.asString.call(void 0, raw)),
9
+ clean => _rfc4648.base16.stringify(clean).toLowerCase()
10
+ ); exports.asBase16 = asBase16
11
+
12
+ function asIntegerString(raw) {
13
+ const clean = _cleaners.asString.call(void 0, raw)
14
+ if (!/^\d+$/.test(clean)) {
15
+ throw new Error('Expected an integer string')
16
+ }
17
+ return clean
18
+ } exports.asIntegerString = asIntegerString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "2.1.1",
3
+ "version": "2.2.1",
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",
@@ -79,7 +79,7 @@
79
79
  "base-x": "^4.0.0",
80
80
  "chai": "^4.2.0",
81
81
  "chai-as-promised": "^7.1.1",
82
- "edge-core-js": "^0.19.48",
82
+ "edge-core-js": "^1.6.0",
83
83
  "eslint": "^7.14.0",
84
84
  "eslint-config-standard-kit": "0.15.1",
85
85
  "eslint-plugin-import": "^2.22.1",