edge-currency-plugins 1.1.2 → 1.1.5
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.
- package/lib/common/plugin/makeCurrencyTools.js +5 -0
- package/lib/common/utxobased/engine/makeUtxoEngine.js +24 -10
- package/lib/common/utxobased/engine/makeUtxoEngineState.js +3 -18
- package/lib/common/utxobased/engine/utils.js +13 -0
- package/lib/common/utxobased/keymanager/keymanager.js +42 -13
- package/lib/src/common/utxobased/engine/utils.d.ts +2 -1
- package/lib/src/common/utxobased/keymanager/keymanager.d.ts +6 -3
- package/package.json +1 -1
|
@@ -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 (
|
|
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:
|
|
317
|
+
value:
|
|
318
|
+
target.nativeAmount == null
|
|
319
|
+
? undefined
|
|
320
|
+
: parseInt(target.nativeAmount),
|
|
321
|
+
memo: target.memo
|
|
315
322
|
})
|
|
316
323
|
}
|
|
317
324
|
} else {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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:
|
|
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 =
|
|
390
|
+
const tx = _keymanager.makeTx.call(void 0, {
|
|
378
391
|
utxos,
|
|
379
392
|
forceUseUtxo: maxUtxo != null ? [maxUtxo] : [],
|
|
380
393
|
targets,
|
|
@@ -383,7 +396,8 @@ var _utils = require('./utils');
|
|
|
383
396
|
currencyCode: currencyInfo.currencyCode,
|
|
384
397
|
setRBF,
|
|
385
398
|
freshChangeAddress,
|
|
386
|
-
subtractFee
|
|
399
|
+
subtractFee,
|
|
400
|
+
log
|
|
387
401
|
})
|
|
388
402
|
if (tx.changeUsed) {
|
|
389
403
|
ourReceiveAddresses.push(freshChangeAddress)
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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 =
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
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 && target.memo !== '') {
|
|
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
|
-
|
|
945
|
-
|
|
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',
|
|
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
|
|
|
@@ -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
|
|
137
|
-
value
|
|
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):
|
|
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.
|
|
3
|
+
"version": "1.1.5",
|
|
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",
|