edge-currency-plugins 1.0.0-rc.1
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/LICENSE +21 -0
- package/README.md +3 -0
- package/lib/bch.js +15 -0
- package/lib/bsv.js +15 -0
- package/lib/btc.js +15 -0
- package/lib/common/constants.js +11 -0
- package/lib/common/fees/calcMinerFeePerByte.js +62 -0
- package/lib/common/fees/makeFees.js +182 -0
- package/lib/common/fees/processInfoServerFees.js +30 -0
- package/lib/common/fees/processMempoolSpaceFees.js +38 -0
- package/lib/common/plugin/makeCurrencyPlugin.js +66 -0
- package/lib/common/plugin/makeCurrencyTools.js +211 -0
- package/lib/common/plugin/makeEngineEmitter.js +102 -0
- package/lib/common/plugin/makeMetadata.js +99 -0
- package/lib/common/plugin/pluginState.js +253 -0
- package/lib/common/plugin/serverScores.js +328 -0
- package/lib/common/plugin/types.js +173 -0
- package/lib/common/plugin/utils.js +18 -0
- package/lib/common/utxobased/db/Models/ProcessorTransaction.js +122 -0
- package/lib/common/utxobased/db/Models/baselet.js +81 -0
- package/lib/common/utxobased/db/makeBaselets.js +123 -0
- package/lib/common/utxobased/db/makeMutex.js +17 -0
- package/lib/common/utxobased/db/makeProcessor.js +554 -0
- package/lib/common/utxobased/db/types.js +67 -0
- package/lib/common/utxobased/engine/await-lock.js +65 -0
- package/lib/common/utxobased/engine/constants.js +7 -0
- package/lib/common/utxobased/engine/makeServerStates.js +394 -0
- package/lib/common/utxobased/engine/makeUtxoEngine.js +690 -0
- package/lib/common/utxobased/engine/makeUtxoEngineState.js +1443 -0
- package/lib/common/utxobased/engine/makeUtxoWalletTools.js +216 -0
- package/lib/common/utxobased/engine/paymentRequest.js +102 -0
- package/lib/common/utxobased/engine/types.js +21 -0
- package/lib/common/utxobased/engine/util/defaultValidateConfirmations.js +19 -0
- package/lib/common/utxobased/engine/util/getOwnUtxosFromTx.js +54 -0
- package/lib/common/utxobased/engine/utils.js +239 -0
- package/lib/common/utxobased/info/all.js +67 -0
- package/lib/common/utxobased/info/badcoin.js +73 -0
- package/lib/common/utxobased/info/bitcoin.js +91 -0
- package/lib/common/utxobased/info/bitcoincash.js +93 -0
- package/lib/common/utxobased/info/bitcoincashtestnet.js +72 -0
- package/lib/common/utxobased/info/bitcoingold.js +85 -0
- package/lib/common/utxobased/info/bitcoingoldtestnet.js +71 -0
- package/lib/common/utxobased/info/bitcoinsv.js +76 -0
- package/lib/common/utxobased/info/bitcointestnet.js +81 -0
- package/lib/common/utxobased/info/dash.js +76 -0
- package/lib/common/utxobased/info/digibyte.js +76 -0
- package/lib/common/utxobased/info/dogecoin.js +76 -0
- package/lib/common/utxobased/info/eboost.js +70 -0
- package/lib/common/utxobased/info/feathercoin.js +76 -0
- package/lib/common/utxobased/info/groestlcoin.js +88 -0
- package/lib/common/utxobased/info/litecoin.js +82 -0
- package/lib/common/utxobased/info/qtum.js +67 -0
- package/lib/common/utxobased/info/ravencoin.js +70 -0
- package/lib/common/utxobased/info/scriptTemplates/bitcoincashScriptTemplates.js +56 -0
- package/lib/common/utxobased/info/scriptTemplates/types.js +14 -0
- package/lib/common/utxobased/info/smartcash.js +78 -0
- package/lib/common/utxobased/info/ufo.js +75 -0
- package/lib/common/utxobased/info/utxoPickers/dogeUtxoPicker.js +34 -0
- package/lib/common/utxobased/info/vertcoin.js +82 -0
- package/lib/common/utxobased/info/zcoin.js +72 -0
- package/lib/common/utxobased/keymanager/base.js +60 -0
- package/lib/common/utxobased/keymanager/bip69.js +31 -0
- package/lib/common/utxobased/keymanager/bitcoincashUtils/base32.js +88 -0
- package/lib/common/utxobased/keymanager/bitcoincashUtils/bn.js +210 -0
- package/lib/common/utxobased/keymanager/bitcoincashUtils/cashAddress.js +282 -0
- package/lib/common/utxobased/keymanager/cleaners.js +198 -0
- package/lib/common/utxobased/keymanager/coinmapper.js +12 -0
- package/lib/common/utxobased/keymanager/declarations/base58grscheck.d.js +1 -0
- package/lib/common/utxobased/keymanager/declarations/blake-hash.d.js +1 -0
- package/lib/common/utxobased/keymanager/declarations/bn.d.js +1 -0
- package/lib/common/utxobased/keymanager/declarations/bs58smartcheck.d.js +1 -0
- package/lib/common/utxobased/keymanager/declarations/wif-smart.d.js +1 -0
- package/lib/common/utxobased/keymanager/declarations/wifgrs.d.js +1 -0
- package/lib/common/utxobased/keymanager/keymanager.js +1214 -0
- package/lib/common/utxobased/keymanager/utxopicker/accumulative.js +52 -0
- package/lib/common/utxobased/keymanager/utxopicker/forceUseUtxo.js +59 -0
- package/lib/common/utxobased/keymanager/utxopicker/subtractFee.js +17 -0
- package/lib/common/utxobased/keymanager/utxopicker/types.js +42 -0
- package/lib/common/utxobased/keymanager/utxopicker/utils.js +159 -0
- package/lib/common/utxobased/keymanager/utxopicker.js +17 -0
- package/lib/common/utxobased/network/BlockBook.js +200 -0
- package/lib/common/utxobased/network/BlockBookAPI.js +335 -0
- package/lib/common/utxobased/network/Deferred.js +29 -0
- package/lib/common/utxobased/network/MakeSocketEmitter.js +35 -0
- package/lib/common/utxobased/network/Socket.js +362 -0
- package/lib/common/utxobased/network/nodejsWS.js +59 -0
- package/lib/common/utxobased/network/socketQueue.js +60 -0
- package/lib/common/utxobased/network/types.js +19 -0
- package/lib/common/utxobased/network/windowWS.js +54 -0
- package/lib/firo.js +15 -0
- package/lib/ftc.js +15 -0
- package/lib/index.js +19 -0
- package/lib/ltc.js +15 -0
- package/lib/src/bch.d.ts +3 -0
- package/lib/src/bsv.d.ts +3 -0
- package/lib/src/btc.d.ts +3 -0
- package/lib/src/common/constants.d.ts +9 -0
- package/lib/src/common/fees/calcMinerFeePerByte.d.ts +13 -0
- package/lib/src/common/fees/makeFees.d.ts +20 -0
- package/lib/src/common/fees/processInfoServerFees.d.ts +7 -0
- package/lib/src/common/fees/processMempoolSpaceFees.d.ts +13 -0
- package/lib/src/common/plugin/makeCurrencyPlugin.d.ts +3 -0
- package/lib/src/common/plugin/makeCurrencyTools.d.ts +8 -0
- package/lib/src/common/plugin/makeEngineEmitter.d.ts +23 -0
- package/lib/src/common/plugin/makeMetadata.d.ts +14 -0
- package/lib/src/common/plugin/pluginState.d.ts +34 -0
- package/lib/src/common/plugin/serverScores.d.ts +61 -0
- package/lib/src/common/plugin/types.d.ts +135 -0
- package/lib/src/common/plugin/utils.d.ts +6 -0
- package/lib/src/common/utxobased/db/Models/ProcessorTransaction.d.ts +16 -0
- package/lib/src/common/utxobased/db/Models/baselet.d.ts +28 -0
- package/lib/src/common/utxobased/db/makeBaselets.d.ts +33 -0
- package/lib/src/common/utxobased/db/makeMutex.d.ts +3 -0
- package/lib/src/common/utxobased/db/makeProcessor.d.ts +42 -0
- package/lib/src/common/utxobased/db/types.d.ts +47 -0
- package/lib/src/common/utxobased/engine/await-lock.d.ts +29 -0
- package/lib/src/common/utxobased/engine/constants.d.ts +4 -0
- package/lib/src/common/utxobased/engine/makeServerStates.d.ts +37 -0
- package/lib/src/common/utxobased/engine/makeUtxoEngine.d.ts +3 -0
- package/lib/src/common/utxobased/engine/makeUtxoEngineState.d.ts +108 -0
- package/lib/src/common/utxobased/engine/makeUtxoWalletTools.d.ts +52 -0
- package/lib/src/common/utxobased/engine/paymentRequest.d.ts +18 -0
- package/lib/src/common/utxobased/engine/types.d.ts +19 -0
- package/lib/src/common/utxobased/engine/util/defaultValidateConfirmations.d.ts +3 -0
- package/lib/src/common/utxobased/engine/util/getOwnUtxosFromTx.d.ts +4 -0
- package/lib/src/common/utxobased/engine/utils.d.ts +43 -0
- package/lib/src/common/utxobased/info/all.d.ts +22 -0
- package/lib/src/common/utxobased/info/badcoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoincash.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoincashtestnet.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoingold.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoingoldtestnet.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoinsv.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcointestnet.d.ts +6 -0
- package/lib/src/common/utxobased/info/dash.d.ts +3 -0
- package/lib/src/common/utxobased/info/digibyte.d.ts +3 -0
- package/lib/src/common/utxobased/info/dogecoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/eboost.d.ts +3 -0
- package/lib/src/common/utxobased/info/feathercoin.d.ts +6 -0
- package/lib/src/common/utxobased/info/groestlcoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/litecoin.d.ts +6 -0
- package/lib/src/common/utxobased/info/qtum.d.ts +3 -0
- package/lib/src/common/utxobased/info/ravencoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/scriptTemplates/bitcoincashScriptTemplates.d.ts +2 -0
- package/lib/src/common/utxobased/info/scriptTemplates/types.d.ts +9 -0
- package/lib/src/common/utxobased/info/smartcash.d.ts +3 -0
- package/lib/src/common/utxobased/info/ufo.d.ts +3 -0
- package/lib/src/common/utxobased/info/utxoPickers/dogeUtxoPicker.d.ts +2 -0
- package/lib/src/common/utxobased/info/vertcoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/zcoin.d.ts +6 -0
- package/lib/src/common/utxobased/keymanager/base.d.ts +9 -0
- package/lib/src/common/utxobased/keymanager/bip69.d.ts +19 -0
- package/lib/src/common/utxobased/keymanager/bitcoincashUtils/base32.d.ts +19 -0
- package/lib/src/common/utxobased/keymanager/bitcoincashUtils/bn.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/bitcoincashUtils/cashAddress.d.ts +12 -0
- package/lib/src/common/utxobased/keymanager/cleaners.d.ts +55 -0
- package/lib/src/common/utxobased/keymanager/coinmapper.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/keymanager.d.ts +198 -0
- package/lib/src/common/utxobased/keymanager/utxopicker/accumulative.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/utxopicker/forceUseUtxo.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/utxopicker/subtractFee.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/utxopicker/types.d.ts +36 -0
- package/lib/src/common/utxobased/keymanager/utxopicker/utils.d.ts +15 -0
- package/lib/src/common/utxobased/keymanager/utxopicker.d.ts +8 -0
- package/lib/src/common/utxobased/network/BlockBook.d.ts +33 -0
- package/lib/src/common/utxobased/network/BlockBookAPI.d.ts +163 -0
- package/lib/src/common/utxobased/network/Deferred.d.ts +8 -0
- package/lib/src/common/utxobased/network/MakeSocketEmitter.d.ts +13 -0
- package/lib/src/common/utxobased/network/Socket.d.ts +41 -0
- package/lib/src/common/utxobased/network/nodejsWS.d.ts +2 -0
- package/lib/src/common/utxobased/network/socketQueue.d.ts +8 -0
- package/lib/src/common/utxobased/network/types.d.ts +17 -0
- package/lib/src/common/utxobased/network/windowWS.d.ts +2 -0
- package/lib/src/firo.d.ts +3 -0
- package/lib/src/ftc.d.ts +3 -0
- package/lib/src/index.d.ts +4 -0
- package/lib/src/ltc.d.ts +3 -0
- package/lib/src/tbch.d.ts +3 -0
- package/lib/src/tbtc.d.ts +3 -0
- package/lib/src/tbtg.d.ts +3 -0
- package/lib/src/types.d.ts +6 -0
- package/lib/src/util/delay.d.ts +1 -0
- package/lib/src/util/filterUndefined.d.ts +1 -0
- package/lib/src/util/indexAtProtected.d.ts +5 -0
- package/lib/src/util/typeUtil.d.ts +8 -0
- package/lib/src/util/undefinedIfEmptyString.d.ts +1 -0
- package/lib/src/util/unixTime.d.ts +1 -0
- package/lib/tbch.js +15 -0
- package/lib/tbtc.js +15 -0
- package/lib/tbtg.js +15 -0
- package/lib/test/common/fees/calcMinerFeePerByte.spec.d.ts +1 -0
- package/lib/test/common/fees/fees.spec.d.ts +1 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/common.d.ts +29 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/bitcoin.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/bitcoincash.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/bitcoinsv.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/digibyte.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/feathercoin.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/groestlcoin.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/litecoin.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/smartcash.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/zcoin.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/index.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.spec.d.ts +1 -0
- package/lib/test/common/plugin/makeMetadata.spec.d.ts +1 -0
- package/lib/test/common/plugin/serverScores.spec.d.ts +1 -0
- package/lib/test/common/utxobased/addressFormat/addressFormatIndex/addressFormat.spec.d.ts +1 -0
- package/lib/test/common/utxobased/db/Processor.spec.d.ts +1 -0
- package/lib/test/common/utxobased/engine/PaymentRequest.spec.d.ts +1 -0
- package/lib/test/common/utxobased/engine/UtxoWalletTools.spec.d.ts +1 -0
- package/lib/test/common/utxobased/engine/engine.fixtures/bitcoinTestnet/tests.d.ts +70 -0
- package/lib/test/common/utxobased/engine/engine.fixtures/index.d.ts +65 -0
- package/lib/test/common/utxobased/engine/engine.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/altcointestfixtures.d.ts +54 -0
- package/lib/test/common/utxobased/keymanager/coins/bitcoincashtransactiontest.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/bitcointransactiontest.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/cashaddr.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/checkdatasig.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/groestlcointransactiontest.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/keymanagertest.spec.d.ts +1 -0
- package/lib/test/common/utxobased/network/BlockBook.spec.d.ts +1 -0
- package/lib/test/util/objectKeys.d.ts +8 -0
- package/lib/test/util/testLog.d.ts +3 -0
- package/lib/test/utils.d.ts +10 -0
- package/lib/types.js +7 -0
- package/lib/util/delay.js +4 -0
- package/lib/util/filterUndefined.js +4 -0
- package/lib/util/indexAtProtected.js +9 -0
- package/lib/util/typeUtil.js +9 -0
- package/lib/util/undefinedIfEmptyString.js +2 -0
- package/lib/util/unixTime.js +2 -0
- package/package.json +101 -0
|
@@ -0,0 +1,210 @@
|
|
|
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(); } }'use strict'
|
|
2
|
+
|
|
3
|
+
var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
|
|
4
|
+
var _buffer = require('buffer');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const reversebuf = function (buf) {
|
|
12
|
+
const buf2 = _buffer.Buffer.alloc(buf.length)
|
|
13
|
+
for (let i = 0; i < buf.length; i++) {
|
|
14
|
+
buf2[i] = buf[buf.length - 1 - i]
|
|
15
|
+
}
|
|
16
|
+
return buf2
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_bnjs2.default.Zero = new (0, _bnjs2.default)(0)
|
|
20
|
+
_bnjs2.default.One = new (0, _bnjs2.default)(1)
|
|
21
|
+
_bnjs2.default.Minus1 = new (0, _bnjs2.default)(-1)
|
|
22
|
+
|
|
23
|
+
_bnjs2.default.fromNumber = function (n) {
|
|
24
|
+
if (typeof n !== 'number') {
|
|
25
|
+
throw new Error(`InvalidArgument: ${JSON.stringify(n)} not a number`)
|
|
26
|
+
}
|
|
27
|
+
return new (0, _bnjs2.default)(n)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
_bnjs2.default.fromString = function (str, base) {
|
|
31
|
+
if (typeof str !== 'string') {
|
|
32
|
+
throw new Error(`InvalidArgument: ${JSON.stringify(str)} not a string`)
|
|
33
|
+
}
|
|
34
|
+
return new (0, _bnjs2.default)(str, base)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_bnjs2.default.fromBuffer = function (buf, opts) {
|
|
38
|
+
if (opts.endian === 'little') {
|
|
39
|
+
buf = reversebuf(buf)
|
|
40
|
+
}
|
|
41
|
+
const hex = buf.toString('hex')
|
|
42
|
+
const bn = new (0, _bnjs2.default)(hex, 16)
|
|
43
|
+
return bn
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Instantiate a BigNumber from a "signed magnitude buffer"
|
|
48
|
+
* (a buffer where the most significant bit represents the sign (0 = positive, -1 = negative))
|
|
49
|
+
*/
|
|
50
|
+
_bnjs2.default.fromSM = function (buf, opts) {
|
|
51
|
+
let ret
|
|
52
|
+
if (buf.length === 0) {
|
|
53
|
+
return _bnjs2.default.fromBuffer(_buffer.Buffer.from([0]))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const endian = _nullishCoalesce(opts.endian, () => ( 'big'))
|
|
57
|
+
if (endian === 'little') {
|
|
58
|
+
buf = reversebuf(buf)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if ((buf[0] & 0x80) !== 0) {
|
|
62
|
+
buf[0] = buf[0] & 0x7f
|
|
63
|
+
ret = _bnjs2.default.fromBuffer(buf)
|
|
64
|
+
ret.neg().copy(ret)
|
|
65
|
+
} else {
|
|
66
|
+
ret = _bnjs2.default.fromBuffer(buf)
|
|
67
|
+
}
|
|
68
|
+
return ret
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_bnjs2.default.prototype.toNumber = function () {
|
|
72
|
+
return parseInt(this.toString(10), 10)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_bnjs2.default.prototype.toBuffer = function (opts) {
|
|
76
|
+
let buf, hex
|
|
77
|
+
if (opts.size != null && opts.size > 0) {
|
|
78
|
+
hex = this.toString(16, 2)
|
|
79
|
+
const natlen = hex.length / 2
|
|
80
|
+
buf = _buffer.Buffer.from(hex, 'hex')
|
|
81
|
+
|
|
82
|
+
if (natlen > opts.size) {
|
|
83
|
+
buf = _bnjs2.default.trim(buf, natlen)
|
|
84
|
+
} else if (natlen < opts.size) {
|
|
85
|
+
buf = _bnjs2.default.pad(buf, natlen, opts.size)
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
hex = this.toString(16, 2)
|
|
89
|
+
buf = _buffer.Buffer.from(hex, 'hex')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (opts.endian === 'little') {
|
|
93
|
+
buf = reversebuf(buf)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return buf
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_bnjs2.default.prototype.toSMBigEndian = function () {
|
|
100
|
+
let buf
|
|
101
|
+
if (this.cmp(_bnjs2.default.Zero) === -1) {
|
|
102
|
+
buf = this.neg().toBuffer()
|
|
103
|
+
if ((buf[0] & 0x80) !== 0) {
|
|
104
|
+
buf = _buffer.Buffer.concat([_buffer.Buffer.from([0x80]), buf])
|
|
105
|
+
} else {
|
|
106
|
+
buf[0] = buf[0] | 0x80
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
buf = this.toBuffer()
|
|
110
|
+
if ((buf[0] & 0x80) !== 0) {
|
|
111
|
+
buf = _buffer.Buffer.concat([_buffer.Buffer.from([0x00]), buf])
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (buf.length === 1 && buf[0] === 0) {
|
|
116
|
+
buf = _buffer.Buffer.from([])
|
|
117
|
+
}
|
|
118
|
+
return buf
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_bnjs2.default.prototype.toSM = function (opts) {
|
|
122
|
+
const endian = _nullishCoalesce(opts.endian, () => ( 'big'))
|
|
123
|
+
let buf = this.toSMBigEndian()
|
|
124
|
+
|
|
125
|
+
if (endian === 'little') {
|
|
126
|
+
buf = reversebuf(buf)
|
|
127
|
+
}
|
|
128
|
+
return buf
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Create a BN from a "ScriptNum":
|
|
133
|
+
* This is analogous to the constructor for CScriptNum in bitcoind. Many ops in
|
|
134
|
+
* bitcoind's script interpreter use CScriptNum, which is not really a proper
|
|
135
|
+
* bignum. Instead, an error is thrown if trying to input a number bigger than
|
|
136
|
+
* 4 bytes. We copy that behavior here. A third argument, `size`, is provided to
|
|
137
|
+
* extend the hard limit of 4 bytes, as some usages require more than 4 bytes.
|
|
138
|
+
*/
|
|
139
|
+
_bnjs2.default.fromScriptNumBuffer = function (
|
|
140
|
+
buf,
|
|
141
|
+
fRequireMinimal,
|
|
142
|
+
size
|
|
143
|
+
) {
|
|
144
|
+
const nMaxNumSize = _nullishCoalesce(size, () => ( 4))
|
|
145
|
+
if (buf.length > nMaxNumSize) {
|
|
146
|
+
throw new Error('InvalidArgument: script number overflow')
|
|
147
|
+
}
|
|
148
|
+
if (fRequireMinimal && buf.length > 0) {
|
|
149
|
+
// Check that the number is encoded with the minimum possible
|
|
150
|
+
// number of bytes.
|
|
151
|
+
//
|
|
152
|
+
// If the most-significant-byte - excluding the sign bit - is zero
|
|
153
|
+
// then we're not minimal. Note how this test also rejects the
|
|
154
|
+
// negative-zero encoding, 0x80.
|
|
155
|
+
if ((buf[buf.length - 1] & 0x7f) === 0) {
|
|
156
|
+
// One exception: if there's more than one byte and the most
|
|
157
|
+
// significant bit of the second-most-significant-byte is set
|
|
158
|
+
// it would conflict with the sign bit. An example of this case
|
|
159
|
+
// is +-255, which encode to 0xff00 and 0xff80 respectively.
|
|
160
|
+
// (big-endian).
|
|
161
|
+
if (buf.length <= 1 || (buf[buf.length - 2] & 0x80) === 0) {
|
|
162
|
+
throw new Error('non-minimally encoded script number')
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return _bnjs2.default.fromSM(buf, {
|
|
167
|
+
endian: 'little'
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The corollary to the above, with the notable exception that we do not throw
|
|
173
|
+
* an error if the output is larger than four bytes. (Which can happen if
|
|
174
|
+
* performing a numerical operation that results in an overflow to more than 4
|
|
175
|
+
* bytes).
|
|
176
|
+
*/
|
|
177
|
+
_bnjs2.default.prototype.toScriptNumBuffer = function () {
|
|
178
|
+
return this.toSM({
|
|
179
|
+
endian: 'little'
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
_bnjs2.default.prototype.gt = function (b) {
|
|
184
|
+
return this.cmp(b) > 0
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
_bnjs2.default.prototype.gte = function (b) {
|
|
188
|
+
return this.cmp(b) >= 0
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
_bnjs2.default.prototype.lt = function (b) {
|
|
192
|
+
return this.cmp(b) < 0
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
_bnjs2.default.trim = function (buf, natlen) {
|
|
196
|
+
return buf.slice(natlen - buf.length, buf.length)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
_bnjs2.default.pad = function (buf, natlen, size) {
|
|
200
|
+
const rbuf = _buffer.Buffer.alloc(size)
|
|
201
|
+
for (let i = 0; i < buf.length; i++) {
|
|
202
|
+
rbuf[rbuf.length - 1 - i] = buf[buf.length - 1 - i]
|
|
203
|
+
}
|
|
204
|
+
for (let i = 0; i < size - natlen; i++) {
|
|
205
|
+
rbuf[i] = 0
|
|
206
|
+
}
|
|
207
|
+
return rbuf
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
exports. default = _bnjs2.default
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// @flow
|
|
2
|
+
|
|
3
|
+
// import bcoin from 'bcoin'
|
|
4
|
+
var _buffer = require('buffer');
|
|
5
|
+
|
|
6
|
+
var _base32 = require('./base32');
|
|
7
|
+
var _bn = require('./bn'); var _bn2 = _interopRequireDefault(_bn);
|
|
8
|
+
|
|
9
|
+
var CashaddrTypeEnum; (function (CashaddrTypeEnum) {
|
|
10
|
+
const pubkeyhash = 'pubkeyhash'; CashaddrTypeEnum["pubkeyhash"] = pubkeyhash;
|
|
11
|
+
const scripthash = 'scripthash'; CashaddrTypeEnum["scripthash"] = scripthash;
|
|
12
|
+
})(CashaddrTypeEnum || (exports.CashaddrTypeEnum = CashaddrTypeEnum = {}));
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const GENERATOR = [
|
|
20
|
+
0x98f2bc8e61,
|
|
21
|
+
0x79b76d99e2,
|
|
22
|
+
0xf33e5fb3c4,
|
|
23
|
+
0xae2eabe2a8,
|
|
24
|
+
0x1e4f43e470
|
|
25
|
+
].map(x => new (0, _bn2.default)(x))
|
|
26
|
+
|
|
27
|
+
// returns a BN object, which is not typed yet. Logs as <BN: dc0f07f285>
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
const polymod = (data) => {
|
|
30
|
+
let checksum = new (0, _bn2.default)(1)
|
|
31
|
+
const C = new (0, _bn2.default)(0x07ffffffff)
|
|
32
|
+
for (let j = 0; j < data.length; j++) {
|
|
33
|
+
const value = data[j]
|
|
34
|
+
const topBits = checksum.shrn(35)
|
|
35
|
+
checksum = checksum.and(C)
|
|
36
|
+
checksum = checksum.shln(5).xor(new (0, _bn2.default)(value))
|
|
37
|
+
for (let i = 0; i < GENERATOR.length; ++i) {
|
|
38
|
+
const D = topBits.shrn(i).and(_bn2.default.One)
|
|
39
|
+
if (D.eqn(1) === true) {
|
|
40
|
+
checksum = checksum.xor(GENERATOR[i])
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return checksum.xor(_bn2.default.One)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const convertBits = (
|
|
48
|
+
data,
|
|
49
|
+
from,
|
|
50
|
+
to,
|
|
51
|
+
strict
|
|
52
|
+
) => {
|
|
53
|
+
if (strict == null) {
|
|
54
|
+
strict = false
|
|
55
|
+
}
|
|
56
|
+
let accumulator = 0
|
|
57
|
+
let bits = 0
|
|
58
|
+
const result = []
|
|
59
|
+
const mask = (1 << to) - 1
|
|
60
|
+
for (let i = 0; i < data.length; i++) {
|
|
61
|
+
const value = data[i]
|
|
62
|
+
if (value < 0 || value >> from !== 0) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`InvalidArgument in function convertBits: ${JSON.stringify(value)}`
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
accumulator = (accumulator << from) | value
|
|
69
|
+
bits += from
|
|
70
|
+
while (bits >= to) {
|
|
71
|
+
bits -= to
|
|
72
|
+
result.push((accumulator >> bits) & mask)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
76
|
+
isNaN(to) ||
|
|
77
|
+
to == null ||
|
|
78
|
+
isNaN(accumulator) ||
|
|
79
|
+
isNaN(bits) ||
|
|
80
|
+
isNaN(mask) ||
|
|
81
|
+
mask == null
|
|
82
|
+
) {
|
|
83
|
+
throw Error(`InvalidArgument in function convertBits: ${to}`)
|
|
84
|
+
}
|
|
85
|
+
if (!strict) {
|
|
86
|
+
if (bits > 0) {
|
|
87
|
+
result.push((accumulator << (to - bits)) & mask)
|
|
88
|
+
}
|
|
89
|
+
} else if (bits >= from || ((accumulator << (to - bits)) & mask) !== 0) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
'InvalidState: Conversion requires padding but strict mode was used'
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
return result
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const prefixToArray = (prefix) => {
|
|
98
|
+
const result = []
|
|
99
|
+
for (let i = 0; i < prefix.length; i++) {
|
|
100
|
+
result.push(prefix.charCodeAt(i) & 31)
|
|
101
|
+
}
|
|
102
|
+
return result
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const hashToCashAddress = (
|
|
106
|
+
scriptHash,
|
|
107
|
+
type,
|
|
108
|
+
cashAddrPrefix,
|
|
109
|
+
includePrefix = false
|
|
110
|
+
) => {
|
|
111
|
+
// Not any, but a BN object
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
113
|
+
function checksumToArray(checksum) {
|
|
114
|
+
const result = []
|
|
115
|
+
const N31 = new (0, _bn2.default)(31)
|
|
116
|
+
for (let i = 0; i < 8; ++i) {
|
|
117
|
+
result.push(checksum.and(N31).toNumber())
|
|
118
|
+
checksum = checksum.shrn(5)
|
|
119
|
+
}
|
|
120
|
+
return result.reverse()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getTypeBits(type) {
|
|
124
|
+
switch (type) {
|
|
125
|
+
case CashaddrTypeEnum.pubkeyhash:
|
|
126
|
+
return 0
|
|
127
|
+
case CashaddrTypeEnum.scripthash:
|
|
128
|
+
return 8
|
|
129
|
+
default:
|
|
130
|
+
throw new Error('Invalid type:' + type)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getHashSizeBits(hash) {
|
|
135
|
+
switch (hash.length * 8) {
|
|
136
|
+
case 160:
|
|
137
|
+
return 0
|
|
138
|
+
case 192:
|
|
139
|
+
return 1
|
|
140
|
+
case 224:
|
|
141
|
+
return 2
|
|
142
|
+
case 256:
|
|
143
|
+
return 3
|
|
144
|
+
case 320:
|
|
145
|
+
return 4
|
|
146
|
+
case 384:
|
|
147
|
+
return 5
|
|
148
|
+
case 448:
|
|
149
|
+
return 6
|
|
150
|
+
case 512:
|
|
151
|
+
return 7
|
|
152
|
+
default:
|
|
153
|
+
throw new Error('Invalid hash size:' + hash.length.toString())
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const hashBuffer = _buffer.Buffer.from(scriptHash, 'hex')
|
|
158
|
+
const eight0 = [0, 0, 0, 0, 0, 0, 0, 0]
|
|
159
|
+
const prefixData = prefixToArray(cashAddrPrefix).concat([0])
|
|
160
|
+
const versionByte = getTypeBits(type) + getHashSizeBits(hashBuffer)
|
|
161
|
+
const arr = Array.prototype.slice.call(hashBuffer, 0)
|
|
162
|
+
const payloadData = convertBits([versionByte].concat(arr), 8, 5)
|
|
163
|
+
const checksumData = prefixData.concat(payloadData).concat(eight0)
|
|
164
|
+
const payload = payloadData.concat(checksumToArray(polymod(checksumData)))
|
|
165
|
+
return includePrefix
|
|
166
|
+
? cashAddrPrefix + ':' + _base32.encode.call(void 0, payload)
|
|
167
|
+
: _base32.encode.call(void 0, payload)
|
|
168
|
+
}; exports.hashToCashAddress = hashToCashAddress
|
|
169
|
+
|
|
170
|
+
const cashAddressToHash = (
|
|
171
|
+
address,
|
|
172
|
+
cashAddrPrefixes
|
|
173
|
+
) => {
|
|
174
|
+
function getHashSize(versionByte) {
|
|
175
|
+
switch (versionByte & 7) {
|
|
176
|
+
case 0:
|
|
177
|
+
return 160
|
|
178
|
+
case 1:
|
|
179
|
+
return 192
|
|
180
|
+
case 2:
|
|
181
|
+
return 224
|
|
182
|
+
case 3:
|
|
183
|
+
return 256
|
|
184
|
+
case 4:
|
|
185
|
+
return 320
|
|
186
|
+
case 5:
|
|
187
|
+
return 384
|
|
188
|
+
case 6:
|
|
189
|
+
return 448
|
|
190
|
+
case 7:
|
|
191
|
+
return 512
|
|
192
|
+
default:
|
|
193
|
+
return 0
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function hasSingleCase(string) {
|
|
198
|
+
const lowerCase = string.toLowerCase()
|
|
199
|
+
const upperCase = string.toUpperCase()
|
|
200
|
+
const hasSingleCase = string === lowerCase || string === upperCase
|
|
201
|
+
return hasSingleCase
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// not any, but a bignum payload
|
|
205
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
206
|
+
function validChecksum(prefix, payload) {
|
|
207
|
+
const prefixData = prefixToArray(prefix).concat([0])
|
|
208
|
+
return polymod(prefixData.concat(payload)).eqn(0)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!hasSingleCase(address)) {
|
|
212
|
+
throw new Error(`InvalidArgument: ${address} has Mixed case`)
|
|
213
|
+
}
|
|
214
|
+
address = address.toLowerCase()
|
|
215
|
+
|
|
216
|
+
const pieces = address.split(':')
|
|
217
|
+
if (pieces.length > 2) {
|
|
218
|
+
throw new Error(`InvalidArgument: ${address} has invalid format`)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let prefix, encodedPayload
|
|
222
|
+
|
|
223
|
+
if (pieces.length === 2) {
|
|
224
|
+
prefix = pieces[0]
|
|
225
|
+
encodedPayload = pieces[1]
|
|
226
|
+
} else {
|
|
227
|
+
prefix = null
|
|
228
|
+
encodedPayload = pieces[0]
|
|
229
|
+
}
|
|
230
|
+
const payload = _base32.decode.call(void 0, encodedPayload.toLowerCase())
|
|
231
|
+
if (prefix != null) {
|
|
232
|
+
if (!validChecksum(prefix, payload)) {
|
|
233
|
+
throw new Error(`InvalidArgument: ${address} has invalid checksum`)
|
|
234
|
+
}
|
|
235
|
+
} else {
|
|
236
|
+
// Loop over all of the currency's cashaddr prefixes to see if any of them
|
|
237
|
+
// validate the checksum for the payload. If we find one, then we'll use
|
|
238
|
+
// it as the selected prefix. Otherwise, we'll throw an error.
|
|
239
|
+
for (let i = 0; i < cashAddrPrefixes.length; ++i) {
|
|
240
|
+
const candidatePrefix = cashAddrPrefixes[i]
|
|
241
|
+
if (validChecksum(candidatePrefix, payload)) {
|
|
242
|
+
prefix = candidatePrefix
|
|
243
|
+
break
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (prefix == null) {
|
|
247
|
+
throw new Error(`InvalidArgument: ${address} has invalid checksum`)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const convertedBits = convertBits(payload.slice(0, -8), 5, 8, true)
|
|
252
|
+
const versionByte = convertedBits.shift()
|
|
253
|
+
const hash = convertedBits
|
|
254
|
+
|
|
255
|
+
if (versionByte == null) {
|
|
256
|
+
throw new Error('cashaddress converter produced bad version byte')
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (getHashSize(versionByte) !== hash.length * 8) {
|
|
260
|
+
throw new Error(`InvalidArgument: ${address} has invalid hash size`)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function getType(versionByte) {
|
|
264
|
+
switch (versionByte & 120) {
|
|
265
|
+
case 0:
|
|
266
|
+
return CashaddrTypeEnum.pubkeyhash
|
|
267
|
+
case 8:
|
|
268
|
+
return CashaddrTypeEnum.scripthash
|
|
269
|
+
default:
|
|
270
|
+
throw new Error(
|
|
271
|
+
'Invalid address type in version byte: ' + versionByte.toString()
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const type = getType(versionByte)
|
|
277
|
+
const info = {
|
|
278
|
+
scriptHash: _buffer.Buffer.from(hash),
|
|
279
|
+
type: type
|
|
280
|
+
}
|
|
281
|
+
return info
|
|
282
|
+
}; exports.cashAddressToHash = cashAddressToHash
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _cleaners = require('cleaners');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _types3 = require('../../plugin/types');
|
|
19
|
+
var _utils = require('../engine/utils');
|
|
20
|
+
|
|
21
|
+
// Private key format are a strict subset of all currency formats
|
|
22
|
+
const asPrivateKeyFormat = _cleaners.asValue.call(void 0, 'bip32', 'bip44', 'bip49')
|
|
23
|
+
// Default to bip32 always for legacy reasons
|
|
24
|
+
const asOptionalPrivateKeyFormat = _cleaners.asOptional.call(void 0, asPrivateKeyFormat, 'bip32')
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A cleaner for the private key format following the key-formats specification.
|
|
28
|
+
*
|
|
29
|
+
* (spec: https://github.com/EdgeApp/edge-core-js/blob/master/docs/key-formats.md)
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function asPrivateKey(
|
|
38
|
+
coinName,
|
|
39
|
+
coinType = 0
|
|
40
|
+
) {
|
|
41
|
+
return _cleaners.asCodec.call(void 0,
|
|
42
|
+
raw => {
|
|
43
|
+
if (raw == null || typeof raw !== 'object') {
|
|
44
|
+
throw new TypeError('Private keys must be objects')
|
|
45
|
+
}
|
|
46
|
+
return _cleaners.asObject.call(void 0, {
|
|
47
|
+
coinType: _cleaners.asOptional.call(void 0, _cleaners.asNumber, coinType),
|
|
48
|
+
format: asOptionalPrivateKeyFormat,
|
|
49
|
+
imported: _cleaners.asOptional.call(void 0, _cleaners.asBoolean),
|
|
50
|
+
seed: _cleaners.asString
|
|
51
|
+
})({ ...raw, seed: raw[`${coinName}Key`] })
|
|
52
|
+
},
|
|
53
|
+
clean => {
|
|
54
|
+
const { coinType, format, imported, seed } = clean
|
|
55
|
+
return {
|
|
56
|
+
coinType,
|
|
57
|
+
format,
|
|
58
|
+
imported,
|
|
59
|
+
[`${coinName}Key`]: seed
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
} exports.asPrivateKey = asPrivateKey;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A cleaner for the public key format following the key-formats specification.
|
|
67
|
+
*
|
|
68
|
+
* (spec: https://github.com/EdgeApp/edge-core-js/blob/master/docs/key-formats.md)
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
const asPublicKey = _cleaners.asObject.call(void 0, {
|
|
76
|
+
publicKeys: _cleaners.asObject.call(void 0, {
|
|
77
|
+
bip32: _cleaners.asOptional.call(void 0, _cleaners.asString),
|
|
78
|
+
bip44: _cleaners.asOptional.call(void 0, _cleaners.asString),
|
|
79
|
+
bip49: _cleaners.asOptional.call(void 0, _cleaners.asString),
|
|
80
|
+
bip84: _cleaners.asOptional.call(void 0, _cleaners.asString)
|
|
81
|
+
})
|
|
82
|
+
}); exports.asPublicKey = asPublicKey
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* This utility returns a wallet's supported formats as specified in the
|
|
86
|
+
* key-formats specification.
|
|
87
|
+
*/
|
|
88
|
+
const getSupportedFormats = (
|
|
89
|
+
format
|
|
90
|
+
) => {
|
|
91
|
+
switch (format) {
|
|
92
|
+
case 'bip32':
|
|
93
|
+
return ['bip32']
|
|
94
|
+
case 'bip44':
|
|
95
|
+
return ['bip44']
|
|
96
|
+
case 'bip49':
|
|
97
|
+
return ['bip49']
|
|
98
|
+
case 'bip84':
|
|
99
|
+
return ['bip84']
|
|
100
|
+
default:
|
|
101
|
+
throw new Error(`Unsupported format ${format}`)
|
|
102
|
+
}
|
|
103
|
+
}; exports.getSupportedFormats = getSupportedFormats
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A cleaner that desensitizes the walletInfo object, excluding sensitive
|
|
107
|
+
* keys (seed/mnemonic, sync key, data key, etc). By using this object type
|
|
108
|
+
* internally within the plugin, we can minimize risk of leaking sensitive data.
|
|
109
|
+
*
|
|
110
|
+
* It also includes internal derived data (publicKey, format, walletFormats, etc).
|
|
111
|
+
* This derived data is to be used internally within the plugin and saved to disk (publicKey).
|
|
112
|
+
*
|
|
113
|
+
* The `walletFormats` field is a list of formats from which to derive
|
|
114
|
+
* extended-keys for the wallet.
|
|
115
|
+
*
|
|
116
|
+
* The `primaryFormat` field is the default format from which to derive
|
|
117
|
+
* addresses from.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
const asNumbWalletInfo = (
|
|
130
|
+
pluginInfo
|
|
131
|
+
) => {
|
|
132
|
+
return (walletInfo) => {
|
|
133
|
+
const { engineInfo, coinInfo } = pluginInfo
|
|
134
|
+
const { id, type } = walletInfo
|
|
135
|
+
|
|
136
|
+
const asCurrencyPrivateKey = asPrivateKey(coinInfo.name, coinInfo.coinType)
|
|
137
|
+
|
|
138
|
+
const publicKey = _cleaners.asMaybe.call(void 0, (0, exports.asPublicKey))(walletInfo.keys)
|
|
139
|
+
if (publicKey != null) {
|
|
140
|
+
const walletFormats = Object.entries(publicKey.publicKeys)
|
|
141
|
+
// Filter out undefined values in the entries because cleaners allow
|
|
142
|
+
// undefined values for optional fields.
|
|
143
|
+
.filter(([, value]) => value != null)
|
|
144
|
+
// Map to the entry's key as a currency format
|
|
145
|
+
.map(([format]) => _cleaners.asMaybe.call(void 0, (0, _types3.asCurrencyFormat))(format))
|
|
146
|
+
// Filter out any formats that didn't pass the cleaner assertion
|
|
147
|
+
.filter(
|
|
148
|
+
(format) => format != null
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
if (walletFormats.length === 0) {
|
|
152
|
+
throw new Error('Missing wallet public keys')
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Search the engineInfo's formats array for the first format that exists
|
|
156
|
+
// in the publicKey data.
|
|
157
|
+
// If there are no defined formats in the engineInfo, then fallback to the
|
|
158
|
+
// first format in the publicKey after sorting alphabetically.
|
|
159
|
+
const primaryFormat =
|
|
160
|
+
_nullishCoalesce((engineInfo.formats != null && engineInfo.formats.length > 0
|
|
161
|
+
? engineInfo.formats.find(format => walletFormats.includes(format))
|
|
162
|
+
: undefined), () => (
|
|
163
|
+
walletFormats.sort((a, b) => (a === b ? 0 : a > b ? 1 : -1))[0]))
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
id,
|
|
167
|
+
type,
|
|
168
|
+
keys: {
|
|
169
|
+
primaryFormat,
|
|
170
|
+
walletFormats,
|
|
171
|
+
publicKey
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const privateKey = _cleaners.asMaybe.call(void 0, asCurrencyPrivateKey)(walletInfo.keys)
|
|
177
|
+
if (privateKey != null) {
|
|
178
|
+
const publicKey = _utils.deriveXpubsFromKeys.call(void 0, {
|
|
179
|
+
privateKey,
|
|
180
|
+
coin: coinInfo.name
|
|
181
|
+
})
|
|
182
|
+
const walletFormats = exports.getSupportedFormats.call(void 0, privateKey.format)
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
id,
|
|
186
|
+
type,
|
|
187
|
+
keys: {
|
|
188
|
+
primaryFormat: privateKey.format,
|
|
189
|
+
walletFormats,
|
|
190
|
+
publicKey: { publicKeys: publicKey }
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// If we get here, nothing matched:
|
|
196
|
+
throw new Error('Either a public or private key are required')
|
|
197
|
+
}
|
|
198
|
+
}; exports.asNumbWalletInfo = asNumbWalletInfo
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _all = require('../info/all');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function getCoinFromString(coinName) {
|
|
5
|
+
const pluginInfo = _all.all.find(
|
|
6
|
+
pluginInfo => pluginInfo.coinInfo.name === coinName
|
|
7
|
+
)
|
|
8
|
+
if (pluginInfo == null) {
|
|
9
|
+
throw new Error('Could not find coin info ' + coinName)
|
|
10
|
+
}
|
|
11
|
+
return pluginInfo.coinInfo
|
|
12
|
+
} exports.getCoinFromString = getCoinFromString;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|