edge-currency-plugins 1.3.6 → 2.0.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.
- package/lib/common/plugin/makeCurrencyTools.js +8 -4
- package/lib/common/utxobased/engine/makeUtxoEngine.js +88 -66
- package/lib/common/utxobased/engine/makeUtxoEngineState.js +1 -1
- package/lib/common/utxobased/engine/types.js +7 -0
- package/lib/common/utxobased/engine/utils.js +10 -28
- package/lib/common/utxobased/keymanager/cleaners.js +11 -4
- package/lib/src/common/utxobased/engine/makeServerStates.d.ts +2 -2
- package/lib/src/common/utxobased/engine/makeUtxoEngine.d.ts +1 -1
- package/lib/src/common/utxobased/engine/makeUtxoEngineState.d.ts +3 -3
- package/lib/src/common/utxobased/engine/types.d.ts +4 -0
- package/lib/src/common/utxobased/engine/utils.d.ts +0 -6
- package/lib/src/common/utxobased/keymanager/cleaners.d.ts +11 -4
- package/package.json +2 -2
|
@@ -38,7 +38,7 @@ var _utils3 = require('./utils');
|
|
|
38
38
|
|
|
39
39
|
const asCurrencyPrivateKey = _cleaners3.asPrivateKey.call(void 0, coinInfo.name, coinInfo.coinType)
|
|
40
40
|
const wasCurrencyPrivateKey = _cleaners.uncleaner.call(void 0, asCurrencyPrivateKey)
|
|
41
|
-
const
|
|
41
|
+
const asCurrencySafeWalletInfo = _cleaners3.asSafeWalletInfo.call(void 0, pluginInfo)
|
|
42
42
|
|
|
43
43
|
const fns = {
|
|
44
44
|
async checkPublicKey(publicKeyData) {
|
|
@@ -102,9 +102,13 @@ var _utils3 = require('./utils');
|
|
|
102
102
|
return _utils.validateMemo.call(void 0, memo)
|
|
103
103
|
},
|
|
104
104
|
|
|
105
|
-
async derivePublicKey(
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
async derivePublicKey(
|
|
106
|
+
unsafeWalletInfo
|
|
107
|
+
) {
|
|
108
|
+
// Use the safety cleaner to derive the public keys from the
|
|
109
|
+
// unsafeWalletInfo which contains the private key.
|
|
110
|
+
const safeWalletInfo = asCurrencySafeWalletInfo(unsafeWalletInfo)
|
|
111
|
+
return safeWalletInfo.keys.publicKey
|
|
108
112
|
},
|
|
109
113
|
|
|
110
114
|
async parseUri(uri) {
|
|
@@ -14,7 +14,8 @@ var _disklet = require('disklet');
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
var _edgecorejs = require('edge-core-js');
|
|
18
19
|
|
|
19
20
|
var _filterUndefined = require('../../../util/filterUndefined');
|
|
20
21
|
var _unixTime = require('../../../util/unixTime');
|
|
@@ -42,7 +43,11 @@ var _keymanager = require('../keymanager/keymanager');
|
|
|
42
43
|
var _makeUtxoEngineState = require('./makeUtxoEngineState');
|
|
43
44
|
var _makeUtxoWalletTools = require('./makeUtxoWalletTools');
|
|
44
45
|
var _paymentRequest = require('./paymentRequest');
|
|
45
|
-
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
var _types5 = require('./types');
|
|
46
51
|
var _getOwnUtxosFromTx = require('./util/getOwnUtxosFromTx');
|
|
47
52
|
var _utils = require('./utils');
|
|
48
53
|
|
|
@@ -53,7 +58,6 @@ var _utils = require('./utils');
|
|
|
53
58
|
pluginInfo,
|
|
54
59
|
pluginDisklet,
|
|
55
60
|
// Rename to make it explicit that this is sensitive memory
|
|
56
|
-
walletInfo: sensitiveWalletInfo,
|
|
57
61
|
options,
|
|
58
62
|
io,
|
|
59
63
|
pluginState
|
|
@@ -65,7 +69,7 @@ var _utils = require('./utils');
|
|
|
65
69
|
log
|
|
66
70
|
} = options
|
|
67
71
|
const { currencyInfo, engineInfo, coinInfo } = pluginInfo
|
|
68
|
-
const userSettings =
|
|
72
|
+
const userSettings = _types5.asUtxoUserSettings.call(void 0, options.userSettings)
|
|
69
73
|
|
|
70
74
|
// We should move the active server list to the engine state,
|
|
71
75
|
// since multiple accounts can be logged in at once,
|
|
@@ -77,10 +81,12 @@ var _utils = require('./utils');
|
|
|
77
81
|
})
|
|
78
82
|
|
|
79
83
|
const asCurrencyPrivateKey = _cleaners3.asPrivateKey.call(void 0, coinInfo.name, coinInfo.coinType)
|
|
80
|
-
// Private key may be missing for
|
|
84
|
+
// Private key may be missing for read-only wallets
|
|
81
85
|
const asMaybeCurrencyPrivateKey = _cleaners.asMaybe.call(void 0, asCurrencyPrivateKey)
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
|
|
87
|
+
// This walletInfo will not contain private keys and should only contain the
|
|
88
|
+
// public keys and so can be passed around the plugin safely.
|
|
89
|
+
const walletInfo = _cleaners3.asSafeWalletInfo.call(void 0, pluginInfo)(config.walletInfo)
|
|
84
90
|
const { privateKeyFormat, publicKey, walletFormats } = walletInfo.keys
|
|
85
91
|
|
|
86
92
|
if (
|
|
@@ -120,7 +126,7 @@ var _utils = require('./utils');
|
|
|
120
126
|
pluginState
|
|
121
127
|
})
|
|
122
128
|
|
|
123
|
-
const
|
|
129
|
+
const engine = {
|
|
124
130
|
async startEngine() {
|
|
125
131
|
emitter.emit(
|
|
126
132
|
_makeEngineEmitter.EngineEvent.WALLET_BALANCE_CHANGED,
|
|
@@ -180,7 +186,7 @@ var _utils = require('./utils');
|
|
|
180
186
|
},
|
|
181
187
|
|
|
182
188
|
async changeUserSettings(userSettings) {
|
|
183
|
-
await pluginState.updateServers(
|
|
189
|
+
await pluginState.updateServers(_types5.asUtxoUserSettings.call(void 0, userSettings))
|
|
184
190
|
},
|
|
185
191
|
|
|
186
192
|
async disableTokens(_tokens) {
|
|
@@ -208,8 +214,8 @@ var _utils = require('./utils');
|
|
|
208
214
|
return await Promise.resolve(undefined)
|
|
209
215
|
},
|
|
210
216
|
|
|
211
|
-
getDisplayPrivateSeed() {
|
|
212
|
-
const privateKey = asMaybeCurrencyPrivateKey(
|
|
217
|
+
getDisplayPrivateSeed(privateKeys) {
|
|
218
|
+
const privateKey = asMaybeCurrencyPrivateKey(privateKeys)
|
|
213
219
|
if (privateKey == null) return null
|
|
214
220
|
return privateKey.format === 'bip32'
|
|
215
221
|
? Buffer.from(privateKey.seed, 'base64').toString('hex')
|
|
@@ -279,11 +285,10 @@ var _utils = require('./utils');
|
|
|
279
285
|
return addressData.used
|
|
280
286
|
},
|
|
281
287
|
|
|
282
|
-
async makeSpend(
|
|
283
|
-
edgeSpendInfo,
|
|
284
|
-
options
|
|
285
|
-
) {
|
|
288
|
+
async makeSpend(edgeSpendInfo) {
|
|
286
289
|
const { spendTargets } = edgeSpendInfo
|
|
290
|
+
const txOptions =
|
|
291
|
+
_optionalChain([edgeSpendInfo, 'access', _5 => _5.otherParams, 'optionalAccess', _6 => _6.txOptions])
|
|
287
292
|
const { outputSort = 'bip69', utxoSourceAddress, forceChangeAddress } =
|
|
288
293
|
_nullishCoalesce(edgeSpendInfo.otherParams, () => ( {}))
|
|
289
294
|
|
|
@@ -292,7 +297,7 @@ var _utils = require('./utils');
|
|
|
292
297
|
utxoScriptPubkey = walletTools.addressToScriptPubkey(utxoSourceAddress)
|
|
293
298
|
}
|
|
294
299
|
|
|
295
|
-
if (_optionalChain([
|
|
300
|
+
if (_optionalChain([txOptions, 'optionalAccess', _7 => _7.CPFP]) == null && spendTargets.length < 1) {
|
|
296
301
|
throw new Error('Need to provide Spend Targets')
|
|
297
302
|
}
|
|
298
303
|
// Calculate the total amount to send
|
|
@@ -301,7 +306,7 @@ var _utils = require('./utils');
|
|
|
301
306
|
'0'
|
|
302
307
|
)
|
|
303
308
|
const utxos =
|
|
304
|
-
await _asyncNullishCoalesce(await _asyncOptionalChain([
|
|
309
|
+
await _asyncNullishCoalesce(await _asyncOptionalChain([txOptions, 'optionalAccess', async _8 => _8.utxos]), async () => (
|
|
305
310
|
_filterUndefined.filterUndefined.call(void 0,
|
|
306
311
|
(await processor.fetchUtxos({
|
|
307
312
|
scriptPubkey: utxoScriptPubkey,
|
|
@@ -313,7 +318,7 @@ var _utils = require('./utils');
|
|
|
313
318
|
bs.gt(totalAmountToSend, `${_utils.sumUtxos.call(void 0, utxos)}`) ||
|
|
314
319
|
utxos.length === 0
|
|
315
320
|
) {
|
|
316
|
-
throw new (0,
|
|
321
|
+
throw new (0, _edgecorejs.InsufficientFundsError)(currencyInfo.currencyCode)
|
|
317
322
|
}
|
|
318
323
|
|
|
319
324
|
let targets = []
|
|
@@ -327,7 +332,7 @@ var _utils = require('./utils');
|
|
|
327
332
|
}
|
|
328
333
|
|
|
329
334
|
// if script exists construct address from script
|
|
330
|
-
if (_optionalChain([target, 'access',
|
|
335
|
+
if (_optionalChain([target, 'access', _9 => _9.otherParams, 'optionalAccess', _10 => _10.script]) != null) {
|
|
331
336
|
const { script } = target.otherParams
|
|
332
337
|
if (script.type === 'replayProtection') {
|
|
333
338
|
// construct a replay protection p2sh address
|
|
@@ -373,7 +378,7 @@ var _utils = require('./utils');
|
|
|
373
378
|
freshAddress.segwitAddress)), () => (
|
|
374
379
|
freshAddress.publicAddress))
|
|
375
380
|
|
|
376
|
-
const setRBF = _nullishCoalesce(_optionalChain([
|
|
381
|
+
const setRBF = _nullishCoalesce(_optionalChain([txOptions, 'optionalAccess', _11 => _11.setRBF]), () => ( false))
|
|
377
382
|
const rbfTxid = edgeSpendInfo.rbfTxid
|
|
378
383
|
let maxUtxo
|
|
379
384
|
let feeRate = parseInt(await fees.getRate(edgeSpendInfo))
|
|
@@ -395,9 +400,9 @@ var _utils = require('./utils');
|
|
|
395
400
|
)
|
|
396
401
|
}
|
|
397
402
|
}
|
|
398
|
-
if (_optionalChain([
|
|
403
|
+
if (_optionalChain([txOptions, 'optionalAccess', _12 => _12.CPFP]) != null) {
|
|
399
404
|
const [childTx] = await processor.fetchTransactions({
|
|
400
|
-
txId: _optionalChain([
|
|
405
|
+
txId: _optionalChain([txOptions, 'optionalAccess', _13 => _13.CPFP])
|
|
401
406
|
})
|
|
402
407
|
if (childTx == null) throw new Error('transaction not found')
|
|
403
408
|
const utxos = []
|
|
@@ -411,7 +416,7 @@ var _utils = require('./utils');
|
|
|
411
416
|
}
|
|
412
417
|
log.warn(`spend: Using fee rate ${feeRate} sat/B`)
|
|
413
418
|
const subtractFee =
|
|
414
|
-
_optionalChain([
|
|
419
|
+
_optionalChain([txOptions, 'optionalAccess', _14 => _14.subtractFee]) != null ? txOptions.subtractFee : false
|
|
415
420
|
const tx = _keymanager.makeTx.call(void 0, {
|
|
416
421
|
utxos,
|
|
417
422
|
forceUseUtxo: maxUtxo != null ? [maxUtxo] : [],
|
|
@@ -480,7 +485,7 @@ var _utils = require('./utils');
|
|
|
480
485
|
|
|
481
486
|
async resyncBlockchain() {
|
|
482
487
|
// Stops the engine
|
|
483
|
-
await
|
|
488
|
+
await engine.killEngine()
|
|
484
489
|
|
|
485
490
|
// Clear cache and state
|
|
486
491
|
await processor.clearAll()
|
|
@@ -492,7 +497,7 @@ var _utils = require('./utils');
|
|
|
492
497
|
await pluginState.refreshServers()
|
|
493
498
|
|
|
494
499
|
// Restart the engine
|
|
495
|
-
await
|
|
500
|
+
await engine.startEngine()
|
|
496
501
|
},
|
|
497
502
|
|
|
498
503
|
async saveTx(edgeTx) {
|
|
@@ -507,7 +512,7 @@ var _utils = require('./utils');
|
|
|
507
512
|
})
|
|
508
513
|
await processor.saveTransaction({
|
|
509
514
|
tx,
|
|
510
|
-
scriptPubkeys: _optionalChain([edgeTx, 'access',
|
|
515
|
+
scriptPubkeys: _optionalChain([edgeTx, 'access', _15 => _15.otherParams, 'optionalAccess', _16 => _16.ourScriptPubkeys])
|
|
511
516
|
})
|
|
512
517
|
|
|
513
518
|
/*
|
|
@@ -517,7 +522,44 @@ var _utils = require('./utils');
|
|
|
517
522
|
await engineState.processUtxos(ownUtxos)
|
|
518
523
|
},
|
|
519
524
|
|
|
520
|
-
async
|
|
525
|
+
async signMessage(
|
|
526
|
+
message,
|
|
527
|
+
privateKeys,
|
|
528
|
+
opts
|
|
529
|
+
) {
|
|
530
|
+
const otherParams = _types5.asUtxoSignMessageOtherParams.call(void 0, opts)
|
|
531
|
+
const { publicAddress } = otherParams
|
|
532
|
+
if (publicAddress == null)
|
|
533
|
+
throw new Error('Missing publicAddress in EdgeSignMessageOptions')
|
|
534
|
+
const scriptPubkey = walletTools.addressToScriptPubkey(publicAddress)
|
|
535
|
+
const processorAddress = await processor.fetchAddress(scriptPubkey)
|
|
536
|
+
if (_optionalChain([processorAddress, 'optionalAccess', _17 => _17.path]) == null) {
|
|
537
|
+
throw new Error('Missing address to sign with')
|
|
538
|
+
}
|
|
539
|
+
const privateKey = asMaybeCurrencyPrivateKey(privateKeys)
|
|
540
|
+
|
|
541
|
+
if (privateKey == null)
|
|
542
|
+
throw new Error('Cannot sign a message for a read-only wallet')
|
|
543
|
+
|
|
544
|
+
// Derive the xprivs on the fly, since we do not persist them
|
|
545
|
+
const xprivKeys = await _utils.fetchOrDeriveXprivFromKeys.call(void 0, {
|
|
546
|
+
privateKey,
|
|
547
|
+
walletLocalEncryptedDisklet,
|
|
548
|
+
coin: coinInfo.name
|
|
549
|
+
})
|
|
550
|
+
|
|
551
|
+
const signature = await walletTools.signMessageBase64({
|
|
552
|
+
path: _optionalChain([processorAddress, 'optionalAccess', _18 => _18.path]),
|
|
553
|
+
message,
|
|
554
|
+
xprivKeys
|
|
555
|
+
})
|
|
556
|
+
return signature
|
|
557
|
+
},
|
|
558
|
+
|
|
559
|
+
async signTx(
|
|
560
|
+
transaction,
|
|
561
|
+
privateKeys
|
|
562
|
+
) {
|
|
521
563
|
const otherParams = transaction.otherParams
|
|
522
564
|
if (otherParams == null) throw new Error('Invalid transaction data')
|
|
523
565
|
|
|
@@ -525,7 +567,7 @@ var _utils = require('./utils');
|
|
|
525
567
|
if (psbt == null || edgeSpendInfo == null)
|
|
526
568
|
throw new Error('Invalid transaction data')
|
|
527
569
|
|
|
528
|
-
const privateKey = asMaybeCurrencyPrivateKey(
|
|
570
|
+
const privateKey = asMaybeCurrencyPrivateKey(privateKeys)
|
|
529
571
|
|
|
530
572
|
if (privateKey == null)
|
|
531
573
|
throw new Error('Cannot sign a transaction for a read-only wallet')
|
|
@@ -550,15 +592,21 @@ var _utils = require('./utils');
|
|
|
550
592
|
return await Promise.all(
|
|
551
593
|
psbt.inputs.map(async ({ hash, index }) => {
|
|
552
594
|
const txid = Buffer.from(hash).reverse().toString('hex')
|
|
595
|
+
const utxoId = `${txid}_${index}`
|
|
553
596
|
|
|
554
597
|
const [utxo] = await processor.fetchUtxos({
|
|
555
|
-
utxoIds: [
|
|
598
|
+
utxoIds: [utxoId]
|
|
556
599
|
})
|
|
557
600
|
if (utxo == null) throw new Error('Invalid UTXO')
|
|
558
601
|
|
|
559
602
|
const address = await processor.fetchAddress(utxo.scriptPubkey)
|
|
560
|
-
if (
|
|
561
|
-
throw new Error(
|
|
603
|
+
if (address == null) {
|
|
604
|
+
throw new Error(`Address for UTXO ${utxoId} not found`)
|
|
605
|
+
}
|
|
606
|
+
if (address.path == null)
|
|
607
|
+
throw new Error(
|
|
608
|
+
`Invalid scriptPubkey ${address.scriptPubkey}; Missing path`
|
|
609
|
+
)
|
|
562
610
|
|
|
563
611
|
const privateKey = walletTools.getPrivateKey({
|
|
564
612
|
path: address.path,
|
|
@@ -581,7 +629,7 @@ var _utils = require('./utils');
|
|
|
581
629
|
transaction.signedTx = signedTx.hex
|
|
582
630
|
|
|
583
631
|
const { paymentProtocolInfo } =
|
|
584
|
-
_nullishCoalesce(_optionalChain([transaction, 'access',
|
|
632
|
+
_nullishCoalesce(_optionalChain([transaction, 'access', _19 => _19.otherParams, 'optionalAccess', _20 => _20.edgeSpendInfo, 'optionalAccess', _21 => _21.otherParams]), () => ( {}))
|
|
585
633
|
if (paymentProtocolInfo != null) {
|
|
586
634
|
const payment = _paymentRequest.createPayment.call(void 0,
|
|
587
635
|
transaction.signedTx,
|
|
@@ -666,12 +714,15 @@ var _utils = require('./utils');
|
|
|
666
714
|
}
|
|
667
715
|
const destAddress = await this.getFreshAddress({})
|
|
668
716
|
const nativeAmount = tmpMetadata.state.balance
|
|
669
|
-
const
|
|
717
|
+
const txOptions = { utxos: tmpUtxos, subtractFee: true }
|
|
670
718
|
spendInfo.spendTargets = [
|
|
671
719
|
{ publicAddress: destAddress.publicAddress, nativeAmount }
|
|
672
720
|
]
|
|
673
|
-
|
|
674
|
-
|
|
721
|
+
spendInfo.otherParams = {
|
|
722
|
+
...spendInfo.otherParams,
|
|
723
|
+
txOptions
|
|
724
|
+
}
|
|
725
|
+
const tx = await this.makeSpend(spendInfo)
|
|
675
726
|
success(tx)
|
|
676
727
|
} catch (e) {
|
|
677
728
|
failure(e)
|
|
@@ -705,37 +756,8 @@ var _utils = require('./utils');
|
|
|
705
756
|
return await end
|
|
706
757
|
},
|
|
707
758
|
|
|
708
|
-
otherMethods: {
|
|
709
|
-
signMessageBase64: async (
|
|
710
|
-
message,
|
|
711
|
-
address
|
|
712
|
-
) => {
|
|
713
|
-
const scriptPubkey = walletTools.addressToScriptPubkey(address)
|
|
714
|
-
const processorAddress = await processor.fetchAddress(scriptPubkey)
|
|
715
|
-
if (_optionalChain([processorAddress, 'optionalAccess', _19 => _19.path]) == null) {
|
|
716
|
-
throw new Error('Missing address to sign with')
|
|
717
|
-
}
|
|
718
|
-
const privateKey = asMaybeCurrencyPrivateKey(sensitiveWalletInfo.keys)
|
|
719
|
-
|
|
720
|
-
if (privateKey == null)
|
|
721
|
-
throw new Error('Cannot sign a message for a read-only wallet')
|
|
722
|
-
|
|
723
|
-
// Derive the xprivs on the fly, since we do not persist them
|
|
724
|
-
const xprivKeys = await _utils.fetchOrDeriveXprivFromKeys.call(void 0, {
|
|
725
|
-
privateKey,
|
|
726
|
-
walletLocalEncryptedDisklet,
|
|
727
|
-
coin: coinInfo.name
|
|
728
|
-
})
|
|
729
|
-
|
|
730
|
-
const signature = await walletTools.signMessageBase64({
|
|
731
|
-
path: _optionalChain([processorAddress, 'optionalAccess', _20 => _20.path]),
|
|
732
|
-
message,
|
|
733
|
-
xprivKeys
|
|
734
|
-
})
|
|
735
|
-
return signature
|
|
736
|
-
}
|
|
737
|
-
}
|
|
759
|
+
otherMethods: {}
|
|
738
760
|
}
|
|
739
761
|
|
|
740
|
-
return
|
|
762
|
+
return engine
|
|
741
763
|
} exports.makeUtxoEngine = makeUtxoEngine;
|
|
@@ -291,7 +291,7 @@ var _utils3 = require('./utils');
|
|
|
291
291
|
})
|
|
292
292
|
if (processorAddress == null) {
|
|
293
293
|
throw new Error(
|
|
294
|
-
|
|
294
|
+
`Missing processor address ${format} ${branch} ${addressIndex} during initialization`
|
|
295
295
|
)
|
|
296
296
|
}
|
|
297
297
|
const { address } = walletTools.scriptPubkeyToAddress({
|
|
@@ -52,14 +52,6 @@ var _keymanager = require('../keymanager/keymanager');
|
|
|
52
52
|
return result
|
|
53
53
|
}; exports.validateMemo = validateMemo
|
|
54
54
|
|
|
55
|
-
const getAddressTypeFromKeys = (
|
|
56
|
-
privateKey
|
|
57
|
-
) => {
|
|
58
|
-
return exports.getAddressTypeFromPurposeType.call(void 0,
|
|
59
|
-
exports.currencyFormatToPurposeType.call(void 0, privateKey.format)
|
|
60
|
-
)
|
|
61
|
-
}; exports.getAddressTypeFromKeys = getAddressTypeFromKeys
|
|
62
|
-
|
|
63
55
|
const getAddressTypeFromPurposeType = (
|
|
64
56
|
purpose
|
|
65
57
|
) => {
|
|
@@ -239,32 +231,22 @@ var _keymanager = require('../keymanager/keymanager');
|
|
|
239
231
|
) => {
|
|
240
232
|
const { engineInfo, privateKey, coin } = args
|
|
241
233
|
const xpubs = {}
|
|
242
|
-
for (const format of _cleaners.getSupportedFormats.call(void 0,
|
|
243
|
-
|
|
244
|
-
args.privateKey.format
|
|
245
|
-
)) {
|
|
246
|
-
xpubs[format] = exports.deriveXpub.call(void 0, {
|
|
247
|
-
privateKey,
|
|
234
|
+
for (const format of _cleaners.getSupportedFormats.call(void 0, engineInfo, privateKey.format)) {
|
|
235
|
+
const xpriv = exports.deriveXprivFromKeys.call(void 0, {
|
|
248
236
|
coin,
|
|
249
|
-
|
|
237
|
+
privateKey
|
|
238
|
+
})[format]
|
|
239
|
+
if (xpriv == null)
|
|
240
|
+
throw new Error('Cannot derive xpub: no private key exists')
|
|
241
|
+
xpubs[format] = _keymanager.xprivToXPub.call(void 0, {
|
|
242
|
+
coin,
|
|
243
|
+
type: exports.currencyFormatToPurposeType.call(void 0, format),
|
|
244
|
+
xpriv
|
|
250
245
|
})
|
|
251
246
|
}
|
|
252
247
|
return xpubs
|
|
253
248
|
}; exports.deriveXpubsFromKeys = deriveXpubsFromKeys
|
|
254
249
|
|
|
255
|
-
const deriveXpub = (args
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
) => {
|
|
260
|
-
const xpriv = exports.deriveXprivFromKeys.call(void 0, args)[
|
|
261
|
-
exports.getCurrencyFormatFromPurposeType.call(void 0, args.type)
|
|
262
|
-
]
|
|
263
|
-
if (xpriv == null)
|
|
264
|
-
throw new Error('Cannot derive xpub: no private key exists')
|
|
265
|
-
return _keymanager.xprivToXPub.call(void 0, { ...args, xpriv })
|
|
266
|
-
}; exports.deriveXpub = deriveXpub
|
|
267
|
-
|
|
268
250
|
const parsePathname = (args
|
|
269
251
|
|
|
270
252
|
|
|
@@ -27,6 +27,10 @@ const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKe
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* A cleaner for the private key format following the key-formats specification.
|
|
30
|
+
* It _includes_ the private key.
|
|
31
|
+
*
|
|
32
|
+
* **It is not considered safe memory, and it should be deallocated
|
|
33
|
+
* (thrown away) after use**.
|
|
30
34
|
*
|
|
31
35
|
* (spec: https://github.com/EdgeApp/edge-core-js/blob/master/docs/key-formats.md)
|
|
32
36
|
*/
|
|
@@ -123,9 +127,12 @@ const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKe
|
|
|
123
127
|
}; exports.inferPrivateKeyFormat = inferPrivateKeyFormat
|
|
124
128
|
|
|
125
129
|
/**
|
|
126
|
-
* A cleaner that desensitizes
|
|
130
|
+
* A cleaner that desensitizes an unsafeWalletInfo object, excluding sensitive
|
|
127
131
|
* keys (seed/mnemonic, sync key, data key, etc). By using this object type
|
|
128
|
-
* internally within the plugin, we can minimize risk of leaking sensitive data
|
|
132
|
+
* internally within the plugin, we can minimize risk of leaking sensitive data
|
|
133
|
+
* when deriving public keys from walletInfo which only contains private keys.
|
|
134
|
+
* It may also be used on a safeWalletInfo object which only contains the
|
|
135
|
+
* wallet's public keys.
|
|
129
136
|
*
|
|
130
137
|
* It also includes internal derived data (publicKey, format, walletFormats, etc).
|
|
131
138
|
* This derived data is to be used internally within the plugin and saved to disk (publicKey).
|
|
@@ -147,7 +154,7 @@ const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKe
|
|
|
147
154
|
|
|
148
155
|
|
|
149
156
|
|
|
150
|
-
const
|
|
157
|
+
const asSafeWalletInfo = (
|
|
151
158
|
pluginInfo
|
|
152
159
|
) => {
|
|
153
160
|
return (walletInfo) => {
|
|
@@ -209,4 +216,4 @@ const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKe
|
|
|
209
216
|
// If we get here, nothing matched:
|
|
210
217
|
throw new Error('Either a public or private key are required')
|
|
211
218
|
}
|
|
212
|
-
}; exports.
|
|
219
|
+
}; exports.asSafeWalletInfo = asSafeWalletInfo
|
|
@@ -2,7 +2,7 @@ import { EdgeLog, EdgeTransaction } from 'edge-core-js/types';
|
|
|
2
2
|
import { EngineEmitter } from '../../plugin/makeEngineEmitter';
|
|
3
3
|
import { PluginState } from '../../plugin/pluginState';
|
|
4
4
|
import { PluginInfo } from '../../plugin/types';
|
|
5
|
-
import {
|
|
5
|
+
import { SafeWalletInfo } from '../keymanager/cleaners';
|
|
6
6
|
import { BlockBook } from '../network/BlockBook';
|
|
7
7
|
import Deferred from '../network/Deferred';
|
|
8
8
|
import { WsTask } from '../network/Socket';
|
|
@@ -18,7 +18,7 @@ interface ServerStateConfig {
|
|
|
18
18
|
log: EdgeLog;
|
|
19
19
|
pluginInfo: PluginInfo;
|
|
20
20
|
pluginState: PluginState;
|
|
21
|
-
walletInfo:
|
|
21
|
+
walletInfo: SafeWalletInfo;
|
|
22
22
|
}
|
|
23
23
|
export interface ServerStates {
|
|
24
24
|
setPickNextTaskCB: (callback: (uri: string) => Promise<boolean | WsTask<any> | undefined>) => void;
|
|
@@ -4,7 +4,7 @@ import { PluginState } from '../../plugin/pluginState';
|
|
|
4
4
|
import { ChangePath, CurrencyFormat, EngineConfig, PluginInfo } from '../../plugin/types';
|
|
5
5
|
import { Processor } from '../db/makeProcessor';
|
|
6
6
|
import { IAddress, IProcessorTransaction, IUTXO } from '../db/types';
|
|
7
|
-
import {
|
|
7
|
+
import { SafeWalletInfo } from '../keymanager/cleaners';
|
|
8
8
|
import { BlockbookAccountUtxo } from '../network/BlockBookAPI';
|
|
9
9
|
import { WsTask } from '../network/Socket';
|
|
10
10
|
import AwaitLock from './await-lock';
|
|
@@ -29,13 +29,13 @@ export interface UtxoEngineState {
|
|
|
29
29
|
}
|
|
30
30
|
export interface UtxoEngineStateConfig extends EngineConfig {
|
|
31
31
|
walletTools: UTXOPluginWalletTools;
|
|
32
|
-
walletInfo:
|
|
32
|
+
walletInfo: SafeWalletInfo;
|
|
33
33
|
processor: Processor;
|
|
34
34
|
}
|
|
35
35
|
export declare function makeUtxoEngineState(config: UtxoEngineStateConfig): UtxoEngineState;
|
|
36
36
|
interface CommonArgs {
|
|
37
37
|
pluginInfo: PluginInfo;
|
|
38
|
-
walletInfo:
|
|
38
|
+
walletInfo: SafeWalletInfo;
|
|
39
39
|
walletTools: UTXOPluginWalletTools;
|
|
40
40
|
processor: Processor;
|
|
41
41
|
emitter: EngineEmitter;
|
|
@@ -15,3 +15,7 @@ export interface UtxoTxOtherParams {
|
|
|
15
15
|
edgeSpendInfo?: EdgeSpendInfo;
|
|
16
16
|
ourScriptPubkeys: string[];
|
|
17
17
|
}
|
|
18
|
+
export declare type UtxoSignMessageOtherParams = ReturnType<typeof asUtxoSignMessageOtherParams>;
|
|
19
|
+
export declare const asUtxoSignMessageOtherParams: import("cleaners").ObjectCleaner<{
|
|
20
|
+
publicAddress: string;
|
|
21
|
+
}>;
|
|
@@ -7,7 +7,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
9
|
export declare const validateMemo: (memo: string) => EdgeMemoRules;
|
|
10
|
-
export declare const getAddressTypeFromKeys: (privateKey: PrivateKey) => AddressTypeEnum;
|
|
11
10
|
export declare const getAddressTypeFromPurposeType: (purpose: BIP43PurposeTypeEnum) => AddressTypeEnum;
|
|
12
11
|
export declare const getScriptTypeFromPurposeType: (purpose: BIP43PurposeTypeEnum) => ScriptTypeEnum;
|
|
13
12
|
export declare const validScriptPubkeyFromAddress: (args: {
|
|
@@ -53,11 +52,6 @@ export declare const deriveXpubsFromKeys: (args: {
|
|
|
53
52
|
privateKey: PrivateKey;
|
|
54
53
|
coin: string;
|
|
55
54
|
}) => CurrencyFormatKeys;
|
|
56
|
-
export declare const deriveXpub: (args: {
|
|
57
|
-
privateKey: PrivateKey;
|
|
58
|
-
coin: string;
|
|
59
|
-
type: BIP43PurposeTypeEnum;
|
|
60
|
-
}) => string;
|
|
61
55
|
export declare const parsePathname: (args: {
|
|
62
56
|
pathname: string;
|
|
63
57
|
coin: string;
|
|
@@ -4,6 +4,10 @@ declare type PrivateKeyFormat = ReturnType<typeof asPrivateKeyFormat>;
|
|
|
4
4
|
declare const asPrivateKeyFormat: Cleaner<"bip32" | "bip44" | "bip49">;
|
|
5
5
|
/**
|
|
6
6
|
* A cleaner for the private key format following the key-formats specification.
|
|
7
|
+
* It _includes_ the private key.
|
|
8
|
+
*
|
|
9
|
+
* **It is not considered safe memory, and it should be deallocated
|
|
10
|
+
* (thrown away) after use**.
|
|
7
11
|
*
|
|
8
12
|
* (spec: https://github.com/EdgeApp/edge-core-js/blob/master/docs/key-formats.md)
|
|
9
13
|
*/
|
|
@@ -35,9 +39,12 @@ export declare const getSupportedFormats: (engineInfo: EngineInfo, privateKeyFor
|
|
|
35
39
|
*/
|
|
36
40
|
export declare const inferPrivateKeyFormat: (publicKey: PublicKey) => PrivateKeyFormat;
|
|
37
41
|
/**
|
|
38
|
-
* A cleaner that desensitizes
|
|
42
|
+
* A cleaner that desensitizes an unsafeWalletInfo object, excluding sensitive
|
|
39
43
|
* keys (seed/mnemonic, sync key, data key, etc). By using this object type
|
|
40
|
-
* internally within the plugin, we can minimize risk of leaking sensitive data
|
|
44
|
+
* internally within the plugin, we can minimize risk of leaking sensitive data
|
|
45
|
+
* when deriving public keys from walletInfo which only contains private keys.
|
|
46
|
+
* It may also be used on a safeWalletInfo object which only contains the
|
|
47
|
+
* wallet's public keys.
|
|
41
48
|
*
|
|
42
49
|
* It also includes internal derived data (publicKey, format, walletFormats, etc).
|
|
43
50
|
* This derived data is to be used internally within the plugin and saved to disk (publicKey).
|
|
@@ -49,7 +56,7 @@ export declare const inferPrivateKeyFormat: (publicKey: PublicKey) => PrivateKey
|
|
|
49
56
|
* useful for determining the "kind of wallet", or more precisely how the public
|
|
50
57
|
* key (xpubs) formats were derived.
|
|
51
58
|
*/
|
|
52
|
-
export interface
|
|
59
|
+
export interface SafeWalletInfo {
|
|
53
60
|
id: string;
|
|
54
61
|
type: string;
|
|
55
62
|
keys: {
|
|
@@ -59,5 +66,5 @@ export interface NumbWalletInfo {
|
|
|
59
66
|
walletFormats: CurrencyFormat[];
|
|
60
67
|
};
|
|
61
68
|
}
|
|
62
|
-
export declare const
|
|
69
|
+
export declare const asSafeWalletInfo: (pluginInfo: PluginInfo) => Cleaner<SafeWalletInfo>;
|
|
63
70
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-currency-plugins",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"bs58smartcheck": "^2.0.4",
|
|
49
49
|
"cleaners": "^0.3.12",
|
|
50
50
|
"disklet": "^0.4.5",
|
|
51
|
-
"edge-core-js": "^0.19.
|
|
51
|
+
"edge-core-js": "^0.19.48",
|
|
52
52
|
"edge-sync-client": "^0.2.7",
|
|
53
53
|
"memlet": "^0.1.7",
|
|
54
54
|
"uri-js": "^4.4.0",
|