edge-currency-plugins 1.1.4 → 1.2.0

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.
@@ -275,6 +275,8 @@ var _utils = require('./utils');
275
275
  options
276
276
  ) {
277
277
  const { spendTargets } = edgeSpendInfo
278
+ const { outputSort = 'bip69' } = _nullishCoalesce(edgeSpendInfo.otherParams, () => ( {}))
279
+
278
280
  if (_optionalChain([options, 'optionalAccess', _5 => _5.CPFP]) == null && spendTargets.length < 1) {
279
281
  throw new Error('Need to provide Spend Targets')
280
282
  }
@@ -397,7 +399,8 @@ var _utils = require('./utils');
397
399
  setRBF,
398
400
  freshChangeAddress,
399
401
  subtractFee,
400
- log
402
+ log,
403
+ outputSort
401
404
  })
402
405
  if (tx.changeUsed) {
403
406
  ourReceiveAddresses.push(freshChangeAddress)
@@ -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(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await 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 _biggystring = require('biggystring');
2
+ var _cleaners = require('cleaners');
2
3
 
3
4
 
4
5
 
@@ -1109,6 +1110,42 @@ const processTransactionResponse = (
1109
1110
  txResponse,
1110
1111
  pluginInfo: { coinInfo }
1111
1112
  } = args
1113
+ const inputs = txResponse.vin.map(vin => {
1114
+ const scriptPubkey =
1115
+ // Note: Blockbook has empirically not sent a hex value as the
1116
+ // scriptPubkey for vins. If we discover this to be changed for some
1117
+ // cases, we may want to use the `hex` field as an optimization.
1118
+ _cleaners.asMaybe.call(void 0,
1119
+ raw => _utils3.validScriptPubkeyFromAddress.call(void 0, raw),
1120
+ 'unknown'
1121
+ )({
1122
+ address: vin.addresses[0],
1123
+ coin: coinInfo.name
1124
+ })
1125
+ return {
1126
+ txId: vin.txid,
1127
+ outputIndex: vin.vout, // case for tx `fefac8c22ba1178df5d7c90b78cc1c203d1a9f5f5506f7b8f6f469fa821c2674` no `vout` for input
1128
+ n: vin.n,
1129
+ scriptPubkey,
1130
+ amount: vin.value
1131
+ }
1132
+ })
1133
+ const outputs = txResponse.vout.map(vout => {
1134
+ const scriptPubkey =
1135
+ _nullishCoalesce(vout.hex, () => (
1136
+ _cleaners.asMaybe.call(void 0,
1137
+ raw => _utils3.validScriptPubkeyFromAddress.call(void 0, raw),
1138
+ 'unknown'
1139
+ )({
1140
+ address: vout.addresses[0],
1141
+ coin: coinInfo.name
1142
+ })))
1143
+ return {
1144
+ n: vout.n,
1145
+ scriptPubkey,
1146
+ amount: vout.value
1147
+ }
1148
+ })
1112
1149
  return {
1113
1150
  txid: txResponse.txid,
1114
1151
  hex: txResponse.hex,
@@ -1116,26 +1153,8 @@ const processTransactionResponse = (
1116
1153
  blockHeight: txResponse.blockHeight > 0 ? txResponse.blockHeight : 0,
1117
1154
  date: txResponse.blockTime,
1118
1155
  fees: txResponse.fees,
1119
- inputs: txResponse.vin.map(input => ({
1120
- txId: input.txid,
1121
- outputIndex: input.vout, // case for tx `fefac8c22ba1178df5d7c90b78cc1c203d1a9f5f5506f7b8f6f469fa821c2674` no `vout` for input
1122
- n: input.n,
1123
- scriptPubkey: _utils3.validScriptPubkeyFromAddress.call(void 0, {
1124
- address: input.addresses[0],
1125
- coin: coinInfo.name
1126
- }),
1127
- amount: input.value
1128
- })),
1129
- outputs: txResponse.vout.map(output => ({
1130
- n: output.n,
1131
- scriptPubkey:
1132
- _nullishCoalesce(output.hex, () => (
1133
- _utils3.validScriptPubkeyFromAddress.call(void 0, {
1134
- address: output.addresses[0],
1135
- coin: coinInfo.name
1136
- }))),
1137
- amount: output.value
1138
- })),
1156
+ inputs,
1157
+ outputs,
1139
1158
  ourIns: [],
1140
1159
  ourOuts: [],
1141
1160
  ourAmount: '0'
@@ -233,6 +233,7 @@ var VerifyAddressEnum; (function (VerifyAddressEnum) {
233
233
 
234
234
 
235
235
 
236
+
236
237
 
237
238
 
238
239
  function bip43PurposeNumberToTypeEnum(
@@ -829,7 +830,7 @@ const wifToPrivateKeyInternal = (
829
830
  } exports.signMessageBase64 = signMessageBase64;
830
831
 
831
832
  function makeTx(args) {
832
- const { log } = args
833
+ const { log, outputSort } = args
833
834
  let sequence = 0xffffffff
834
835
  if (args.setRBF) {
835
836
  sequence -= 2
@@ -920,7 +921,7 @@ const wifToPrivateKeyInternal = (
920
921
  })
921
922
  }
922
923
 
923
- if (target.memo != null) {
924
+ if (target.memo != null && target.memo !== '') {
924
925
  const memoHex = Buffer.from(target.memo, 'utf8').toString('hex')
925
926
  // check if hex string is within 80 bytes
926
927
  const validatedMemo = _utils.validateMemo.call(void 0, memoHex)
@@ -962,7 +963,14 @@ const wifToPrivateKeyInternal = (
962
963
  }
963
964
 
964
965
  const sortedInputs = _bip69.sortInputs.call(void 0, result.inputs)
965
- const sortedOutputs = _bip69.sortOutputs.call(void 0, result.outputs)
966
+ const sortedOutputs = (() => {
967
+ switch (outputSort) {
968
+ case 'bip69':
969
+ return _bip69.sortOutputs.call(void 0, result.outputs)
970
+ case 'targets':
971
+ return result.outputs
972
+ }
973
+ })()
966
974
 
967
975
  const psbt = new bitcoin.Psbt()
968
976
  try {
@@ -133,6 +133,7 @@ export interface MakeTxArgs {
133
133
  freshChangeAddress: string;
134
134
  subtractFee?: boolean;
135
135
  log?: EdgeLog;
136
+ outputSort: 'bip69' | 'targets';
136
137
  }
137
138
  export interface MakeTxTarget {
138
139
  address?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
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",