edge-currency-plugins 1.1.2 → 1.1.3

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
@@ -297,7 +297,10 @@ var _utils = require('./utils');
297
297
  let targets = []
298
298
  const ourReceiveAddresses = []
299
299
  for (const target of spendTargets) {
300
- if (target.publicAddress == null || target.nativeAmount == null) {
300
+ if (
301
+ target.memo == null &&
302
+ (target.publicAddress == null || target.nativeAmount == null)
303
+ ) {
301
304
  throw new Error('Invalid spend target')
302
305
  }
303
306
 
@@ -311,19 +314,29 @@ var _utils = require('./utils');
311
314
  )
312
315
  targets.push({
313
316
  address: publicAddress,
314
- value: parseInt(target.nativeAmount)
317
+ value:
318
+ target.nativeAmount == null
319
+ ? undefined
320
+ : parseInt(target.nativeAmount),
321
+ memo: target.memo
315
322
  })
316
323
  }
317
324
  } else {
318
- const scriptPubkey = walletTools.addressToScriptPubkey(
319
- target.publicAddress
320
- )
321
- if (processor.fetchAddress(scriptPubkey) != null) {
322
- 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
+ }
323
332
  }
324
333
  targets.push({
325
334
  address: target.publicAddress,
326
- value: parseInt(target.nativeAmount)
335
+ value:
336
+ target.nativeAmount == null
337
+ ? undefined
338
+ : parseInt(target.nativeAmount),
339
+ memo: target.memo
327
340
  })
328
341
  }
329
342
  }
@@ -374,7 +387,7 @@ var _utils = require('./utils');
374
387
  log.warn(`spend: Using fee rate ${feeRate} sat/B`)
375
388
  const subtractFee =
376
389
  _optionalChain([options, 'optionalAccess', _12 => _12.subtractFee]) != null ? options.subtractFee : false
377
- const tx = await _keymanager.makeTx.call(void 0, {
390
+ const tx = _keymanager.makeTx.call(void 0, {
378
391
  utxos,
379
392
  forceUseUtxo: maxUtxo != null ? [maxUtxo] : [],
380
393
  targets,
@@ -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
 
@@ -230,6 +231,7 @@ var VerifyAddressEnum; (function (VerifyAddressEnum) {
230
231
 
231
232
 
232
233
 
234
+
233
235
 
234
236
 
235
237
  function bip43PurposeNumberToTypeEnum(
@@ -825,7 +827,7 @@ const wifToPrivateKeyInternal = (
825
827
  .toString('base64')
826
828
  } exports.signMessageBase64 = signMessageBase64;
827
829
 
828
- async function makeTx(args) {
830
+ function makeTx(args) {
829
831
  let sequence = 0xffffffff
830
832
  if (args.setRBF) {
831
833
  sequence -= 2
@@ -903,16 +905,36 @@ const wifToPrivateKeyInternal = (
903
905
  if (!forceUsage) mappedUtxos.push(input)
904
906
  }
905
907
 
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
908
+ const targets = []
909
+ for (const target of args.targets) {
910
+ if (target.address != null && target.value != null) {
911
+ const script = exports.addressToScriptPubkey.call(void 0, {
912
+ address: target.address,
913
+ coin: coin.name
914
+ })
915
+ targets.push({
916
+ script,
917
+ value: target.value
918
+ })
914
919
  }
915
- })
920
+
921
+ if (target.memo != null) {
922
+ const memoHex = Buffer.from(target.memo, 'utf8').toString('hex')
923
+ // check if hex string is within 80 bytes
924
+ const validatedMemo = _utils.validateMemo.call(void 0, memoHex)
925
+ if (!validatedMemo.passed) {
926
+ throw new Error('Memo size exceeds 80 bytes')
927
+ }
928
+ const script = bitcoin.script
929
+ .compile([bitcoin.opcodes.OP_RETURN, Buffer.from(target.memo, 'utf8')])
930
+ .toString('hex')
931
+ targets.push({
932
+ script,
933
+ value: 0
934
+ })
935
+ }
936
+ }
937
+
916
938
  const changeScript = exports.addressToScriptPubkey.call(void 0, {
917
939
  address: args.freshChangeAddress,
918
940
  coin: coin.name
@@ -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;
@@ -133,8 +133,9 @@ export interface MakeTxArgs {
133
133
  subtractFee?: boolean;
134
134
  }
135
135
  export interface MakeTxTarget {
136
- address: string;
137
- value: number;
136
+ address?: string;
137
+ value?: number;
138
+ memo?: string | null;
138
139
  }
139
140
  interface MakeTxReturn extends Required<utxopicker.UtxoPickerResult> {
140
141
  hex: string;
@@ -194,6 +195,6 @@ export declare function privateKeyToWIF(args: PrivateKeyToWIFArgs): string;
194
195
  export declare const wifToPrivateKey: (args: WIFToPrivateKeyArgs) => string;
195
196
  export declare function privateKeyToPubkey(privateKey: string): string;
196
197
  export declare function signMessageBase64(message: string, privateKey: string): string;
197
- export declare function makeTx(args: MakeTxArgs): Promise<MakeTxReturn>;
198
+ export declare function makeTx(args: MakeTxArgs): MakeTxReturn;
198
199
  export declare function signTx(args: SignTxArgs): Promise<SignTxReturn>;
199
200
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
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",