edge-currency-plugins 1.1.1 → 1.1.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.
@@ -9,6 +9,7 @@ var _cleaners = require('cleaners');
9
9
 
10
10
 
11
11
 
12
+
12
13
  var _urijs = require('uri-js'); var uri = _interopRequireWildcard(_urijs);
13
14
  var _urlparse = require('url-parse'); var _urlparse2 = _interopRequireDefault(_urlparse);
14
15
 
@@ -80,6 +81,10 @@ var _utils3 = require('./utils');
80
81
  return wasCurrencyPrivateKey(privateKey)
81
82
  },
82
83
 
84
+ async validateMemo(memo) {
85
+ return _utils.validateMemo.call(void 0, memo)
86
+ },
87
+
83
88
  async derivePublicKey(walletInfo) {
84
89
  const numbWalletInfo = asCurrencyNumbWalletInfo(walletInfo)
85
90
  return numbWalletInfo.keys.publicKey
@@ -66,7 +66,9 @@ var _utils = require('./utils');
66
66
  // each with a different list of custom servers.
67
67
  // The Edge UI only allows for one active login, though,
68
68
  // so this is OK for now:
69
- await pluginState.updateServers(userSettings)
69
+ pluginState.updateServers(userSettings).catch(err => {
70
+ log.error(err)
71
+ })
70
72
 
71
73
  const asCurrencyPrivateKey = _cleaners3.asPrivateKey.call(void 0, coinInfo.name, coinInfo.coinType)
72
74
  // Private key may be missing for watch-only wallets
@@ -295,7 +297,10 @@ var _utils = require('./utils');
295
297
  let targets = []
296
298
  const ourReceiveAddresses = []
297
299
  for (const target of spendTargets) {
298
- if (target.publicAddress == null || target.nativeAmount == null) {
300
+ if (
301
+ target.memo == null &&
302
+ (target.publicAddress == null || target.nativeAmount == null)
303
+ ) {
299
304
  throw new Error('Invalid spend target')
300
305
  }
301
306
 
@@ -309,19 +314,29 @@ var _utils = require('./utils');
309
314
  )
310
315
  targets.push({
311
316
  address: publicAddress,
312
- value: parseInt(target.nativeAmount)
317
+ value:
318
+ target.nativeAmount == null
319
+ ? undefined
320
+ : parseInt(target.nativeAmount),
321
+ memo: target.memo
313
322
  })
314
323
  }
315
324
  } else {
316
- const scriptPubkey = walletTools.addressToScriptPubkey(
317
- target.publicAddress
318
- )
319
- if (processor.fetchAddress(scriptPubkey) != null) {
320
- ourReceiveAddresses.push(target.publicAddress)
325
+ if (target.publicAddress != null) {
326
+ const scriptPubkey = walletTools.addressToScriptPubkey(
327
+ target.publicAddress
328
+ )
329
+ if (processor.fetchAddress(scriptPubkey) != null) {
330
+ ourReceiveAddresses.push(target.publicAddress)
331
+ }
321
332
  }
322
333
  targets.push({
323
334
  address: target.publicAddress,
324
- value: parseInt(target.nativeAmount)
335
+ value:
336
+ target.nativeAmount == null
337
+ ? undefined
338
+ : parseInt(target.nativeAmount),
339
+ memo: target.memo
325
340
  })
326
341
  }
327
342
  }
@@ -372,7 +387,7 @@ var _utils = require('./utils');
372
387
  log.warn(`spend: Using fee rate ${feeRate} sat/B`)
373
388
  const subtractFee =
374
389
  _optionalChain([options, 'optionalAccess', _12 => _12.subtractFee]) != null ? options.subtractFee : false
375
- const tx = await _keymanager.makeTx.call(void 0, {
390
+ const tx = _keymanager.makeTx.call(void 0, {
376
391
  utxos,
377
392
  forceUseUtxo: maxUtxo != null ? [maxUtxo] : [],
378
393
  targets,
@@ -381,7 +396,8 @@ var _utils = require('./utils');
381
396
  currencyCode: currencyInfo.currencyCode,
382
397
  setRBF,
383
398
  freshChangeAddress,
384
- subtractFee
399
+ subtractFee,
400
+ log
385
401
  })
386
402
  if (tx.changeUsed) {
387
403
  ourReceiveAddresses.push(freshChangeAddress)
@@ -407,7 +423,7 @@ var _utils = require('./utils');
407
423
  nativeAmount = bs.sub(nativeAmount, networkFee)
408
424
 
409
425
  const otherParams = {
410
- txJson: { hex: tx.hex },
426
+ unsignedTx: tx.hex,
411
427
  psbt: {
412
428
  base64: tx.psbtBase64,
413
429
  inputs: tx.inputs,
@@ -1244,25 +1244,10 @@ const processProcessorUtxos = async (
1244
1244
  oldBalance = _biggystring.add.call(void 0, utxo.value, oldBalance)
1245
1245
  }
1246
1246
 
1247
- // If the UTXO isn't present in the update UTXO set, then it is spent.
1247
+ // If the UTXO isn't present in the update UTXO set, then it is spent or dropped.
1248
+ // Remove it from the database if so
1248
1249
  if (updatedUtxos[utxo.id] == null) {
1249
- if (utxo.blockHeight > 0) {
1250
- // Delete the UTXO from the database if it's spent and confirmed
1251
- utxoIdsToRemove.push(utxo.id)
1252
- } else {
1253
- // Otherwise just mark it as spent.
1254
- updatedUtxos[utxo.id] = { ...utxo, spent: true }
1255
- }
1256
- } else {
1257
- /*
1258
- If the UTXO is present in the updated UTXO set, enforce that the UTXO
1259
- remains spent in the new UTXO set. This means, we will never mark a UTXO
1260
- as unspent again. UTXOs only become unspent again if the tx is dropped
1261
- which shall be affected by another routine.
1262
- */
1263
- // TODO: To fix this logic for dropped-tx, add a condition which uses the
1264
- // network's block-height to determine whether to set it back as unspend
1265
- updatedUtxos[utxo.id].spent = utxo.spent || updatedUtxos[utxo.id].spent
1250
+ utxoIdsToRemove.push(utxo.id)
1266
1251
  }
1267
1252
  }
1268
1253
 
@@ -35,6 +35,19 @@ var _keymanager = require('../keymanager/keymanager');
35
35
  }
36
36
  }; exports.getCurrencyFormatFromPurposeType = getCurrencyFormatFromPurposeType
37
37
 
38
+ // Expect memo to be a hex string
39
+ const validateMemo = (memo) => {
40
+ const result = {
41
+ passed: true,
42
+ tooLarge: false
43
+ }
44
+ if (Math.ceil(memo.length / 2) > 80) {
45
+ result.passed = false
46
+ result.tooLarge = true
47
+ }
48
+ return result
49
+ }; exports.validateMemo = validateMemo
50
+
38
51
  const getAddressTypeFromKeys = (
39
52
  privateKey
40
53
  ) => {
@@ -10,6 +10,7 @@ var _indexAtProtected = require('../../../util/indexAtProtected');
10
10
  var _undefinedIfEmptyString = require('../../../util/undefinedIfEmptyString');
11
11
 
12
12
 
13
+ var _utils = require('../engine/utils');
13
14
 
14
15
  var _bip69 = require('./bip69');
15
16
 
@@ -229,6 +230,8 @@ var VerifyAddressEnum; (function (VerifyAddressEnum) {
229
230
 
230
231
 
231
232
 
233
+
234
+
232
235
 
233
236
 
234
237
 
@@ -825,7 +828,8 @@ const wifToPrivateKeyInternal = (
825
828
  .toString('base64')
826
829
  } exports.signMessageBase64 = signMessageBase64;
827
830
 
828
- async function makeTx(args) {
831
+ function makeTx(args) {
832
+ const { log } = args
829
833
  let sequence = 0xffffffff
830
834
  if (args.setRBF) {
831
835
  sequence -= 2
@@ -903,16 +907,36 @@ const wifToPrivateKeyInternal = (
903
907
  if (!forceUsage) mappedUtxos.push(input)
904
908
  }
905
909
 
906
- const targets = args.targets.map(target => {
907
- const script = exports.addressToScriptPubkey.call(void 0, {
908
- address: target.address,
909
- coin: coin.name
910
- })
911
- return {
912
- script,
913
- value: target.value
910
+ const targets = []
911
+ for (const target of args.targets) {
912
+ if (target.address != null && target.value != null) {
913
+ const script = exports.addressToScriptPubkey.call(void 0, {
914
+ address: target.address,
915
+ coin: coin.name
916
+ })
917
+ targets.push({
918
+ script,
919
+ value: target.value
920
+ })
914
921
  }
915
- })
922
+
923
+ if (target.memo != null) {
924
+ const memoHex = Buffer.from(target.memo, 'utf8').toString('hex')
925
+ // check if hex string is within 80 bytes
926
+ const validatedMemo = _utils.validateMemo.call(void 0, memoHex)
927
+ if (!validatedMemo.passed) {
928
+ throw new Error('Memo size exceeds 80 bytes')
929
+ }
930
+ const script = bitcoin.script
931
+ .compile([bitcoin.opcodes.OP_RETURN, Buffer.from(target.memo, 'utf8')])
932
+ .toString('hex')
933
+ targets.push({
934
+ script,
935
+ value: 0
936
+ })
937
+ }
938
+ }
939
+
916
940
  const changeScript = exports.addressToScriptPubkey.call(void 0, {
917
941
  address: args.freshChangeAddress,
918
942
  coin: coin.name
@@ -941,8 +965,13 @@ const wifToPrivateKeyInternal = (
941
965
  const sortedOutputs = _bip69.sortOutputs.call(void 0, result.outputs)
942
966
 
943
967
  const psbt = new bitcoin.Psbt()
944
- psbt.addInputs(sortedInputs)
945
- psbt.addOutputs(sortedOutputs)
968
+ try {
969
+ psbt.addInputs(sortedInputs)
970
+ psbt.addOutputs(sortedOutputs)
971
+ } catch (error) {
972
+ _optionalChain([log, 'optionalAccess', _16 => _16.error, 'call', _17 => _17(`Failed makeTx: ${String(error)}`)])
973
+ throw error
974
+ }
946
975
 
947
976
  return {
948
977
  inputs: sortedInputs,
@@ -950,7 +979,7 @@ const wifToPrivateKeyInternal = (
950
979
  changeUsed: result.changeUsed,
951
980
  fee: result.fee,
952
981
  psbtBase64: psbt.toBase64(),
953
- hex: _optionalChain([psbt, 'access', _16 => _16.data, 'optionalAccess', _17 => _17.globalMap, 'optionalAccess', _18 => _18.unsignedTx, 'optionalAccess', _19 => _19.toBuffer, 'call', _20 => _20(), 'optionalAccess', _21 => _21.toString, 'call', _22 => _22('hex')])
982
+ hex: _optionalChain([psbt, 'access', _18 => _18.data, 'optionalAccess', _19 => _19.globalMap, 'optionalAccess', _20 => _20.unsignedTx, 'optionalAccess', _21 => _21.toBuffer, 'call', _22 => _22(), 'optionalAccess', _23 => _23.toString, 'call', _24 => _24('hex')])
954
983
  }
955
984
  } exports.makeTx = makeTx;
956
985
 
@@ -6,9 +6,7 @@ export declare const asUtxoUserSettings: import("cleaners").ObjectCleaner<{
6
6
  }>;
7
7
  export declare type UtxoUserSettings = ReturnType<typeof asUtxoUserSettings>;
8
8
  export interface UtxoTxOtherParams {
9
- txJson?: {
10
- hex?: string;
11
- };
9
+ unsignedTx: string;
12
10
  psbt?: {
13
11
  base64: string;
14
12
  inputs: Input[];
@@ -1,11 +1,12 @@
1
1
  import { Disklet } from 'disklet';
2
- import { EdgeParsedUri } from 'edge-core-js/types';
2
+ import { EdgeMemoRules, EdgeParsedUri } from 'edge-core-js/types';
3
3
  import { CurrencyFormat } 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;
9
10
  export declare const getAddressTypeFromKeys: (privateKey: PrivateKey) => AddressTypeEnum;
10
11
  export declare const getAddressTypeFromPurposeType: (purpose: BIP43PurposeTypeEnum) => AddressTypeEnum;
11
12
  export declare const getScriptTypeFromPurposeType: (purpose: BIP43PurposeTypeEnum, redeemScript?: string | undefined, scriptTemplates?: ScriptTemplates | undefined) => ScriptTypeEnum;
@@ -1,3 +1,4 @@
1
+ import { EdgeLog } from 'edge-core-js/types';
1
2
  import { AddressPath } from '../../plugin/types';
2
3
  import { IUTXO } from '../db/types';
3
4
  import { ScriptTemplate } from '../info/scriptTemplates/types';
@@ -131,10 +132,12 @@ export interface MakeTxArgs {
131
132
  currencyCode: string;
132
133
  freshChangeAddress: string;
133
134
  subtractFee?: boolean;
135
+ log?: EdgeLog;
134
136
  }
135
137
  export interface MakeTxTarget {
136
- address: string;
137
- value: number;
138
+ address?: string;
139
+ value?: number;
140
+ memo?: string | null;
138
141
  }
139
142
  interface MakeTxReturn extends Required<utxopicker.UtxoPickerResult> {
140
143
  hex: string;
@@ -194,6 +197,6 @@ export declare function privateKeyToWIF(args: PrivateKeyToWIFArgs): string;
194
197
  export declare const wifToPrivateKey: (args: WIFToPrivateKeyArgs) => string;
195
198
  export declare function privateKeyToPubkey(privateKey: string): string;
196
199
  export declare function signMessageBase64(message: string, privateKey: string): string;
197
- export declare function makeTx(args: MakeTxArgs): Promise<MakeTxReturn>;
200
+ export declare function makeTx(args: MakeTxArgs): MakeTxReturn;
198
201
  export declare function signTx(args: SignTxArgs): Promise<SignTxReturn>;
199
202
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "1.1.1",
3
+ "version": "1.1.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",
@@ -49,6 +49,7 @@
49
49
  "cleaners": "^0.3.12",
50
50
  "disklet": "^0.4.5",
51
51
  "edge-core-js": "^0.19.20",
52
+ "edge-sync-client": "^0.2.7",
52
53
  "memlet": "^0.1.6",
53
54
  "uri-js": "^4.4.0",
54
55
  "url-parse": "^1.5.2",
package/CHANGELOG.md DELETED
@@ -1,39 +0,0 @@
1
- # edge-currency-plugins
2
-
3
- ## v1.1.1 (2022-07-12)
4
-
5
- - Fix: Add feathercoin blockbook server
6
- - Fix: Engine crashs on fetching server list network failure
7
- - Fix: Spend issues caused by not saving UTXOs locally without needing a network event
8
-
9
- ## v1.1.0 (2022-06-29)
10
-
11
- - Change: Computes the sat/vByte used for a given transaction, and adds feeRateUsed object to the EdgeTransaction output.
12
-
13
- ## v1.0.0 (2022-06-22)
14
-
15
- - Fix: Fix a logic error in UtxoEngineState.processUtxos
16
- - Change: Disable BCH to BSV splitting for now
17
- - Change: Add detailed logs for Socket errors caused by cleaner
18
-
19
- ## v1.0.0-rc.6 (2022-06-21)
20
-
21
- - Fix: Fee rounding errors for some spending cases (particularly sweek keys for segwit wallets)
22
- - Change: Use WhatsOnChain.com as the block explorer URLs for BSV
23
-
24
- ## v1.0.0-rc.5 (2022-06-21)
25
-
26
- - Fix: Insufficient funds error for edge case (max spend on a zero-balance wallet)
27
-
28
- ## v1.0.0-rc.4 (2022-06-20)
29
-
30
- - Fix: Avoid redundant ADDRESSES_CHECKED events after initial sync
31
-
32
- ## v1.0.0-rc.3 (2022-06-20)
33
-
34
- - Fix: Balance bug after sending transactions
35
-
36
- ## v1.0.0-rc.2 (2022-06-17)
37
-
38
- - Fix: Improve connection states and fix reconnection bugs caused when connections are unreliable
39
- - Fix: Improve BSV address format support for addresses coming from networks