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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Edge (formerly Airbitz)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/lib/bch.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }
|
|
2
|
+
|
|
3
|
+
var _makeCurrencyPlugin = require('./common/plugin/makeCurrencyPlugin');
|
|
4
|
+
var _bitcoincash = require('./common/utxobased/info/bitcoincash');
|
|
5
|
+
|
|
6
|
+
const plugin = (options) =>
|
|
7
|
+
_makeCurrencyPlugin.makeCurrencyPlugin.call(void 0, options, _bitcoincash.info)
|
|
8
|
+
|
|
9
|
+
if (typeof window !== 'undefined') {
|
|
10
|
+
_optionalChain([window, 'access', _ => _.addEdgeCorePlugins, 'optionalCall', _2 => _2({
|
|
11
|
+
[_bitcoincash.info.currencyInfo.pluginId]: plugin
|
|
12
|
+
})])
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports. default = plugin
|
package/lib/bsv.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }
|
|
2
|
+
|
|
3
|
+
var _makeCurrencyPlugin = require('./common/plugin/makeCurrencyPlugin');
|
|
4
|
+
var _bitcoinsv = require('./common/utxobased/info/bitcoinsv');
|
|
5
|
+
|
|
6
|
+
const plugin = (options) =>
|
|
7
|
+
_makeCurrencyPlugin.makeCurrencyPlugin.call(void 0, options, _bitcoinsv.info)
|
|
8
|
+
|
|
9
|
+
if (typeof window !== 'undefined') {
|
|
10
|
+
_optionalChain([window, 'access', _ => _.addEdgeCorePlugins, 'optionalCall', _2 => _2({
|
|
11
|
+
[_bitcoinsv.info.currencyInfo.pluginId]: plugin
|
|
12
|
+
})])
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports. default = plugin
|
package/lib/btc.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }
|
|
2
|
+
|
|
3
|
+
var _makeCurrencyPlugin = require('./common/plugin/makeCurrencyPlugin');
|
|
4
|
+
var _bitcoin = require('./common/utxobased/info/bitcoin');
|
|
5
|
+
|
|
6
|
+
const plugin = (options) =>
|
|
7
|
+
_makeCurrencyPlugin.makeCurrencyPlugin.call(void 0, options, _bitcoin.info)
|
|
8
|
+
|
|
9
|
+
if (typeof window !== 'undefined') {
|
|
10
|
+
_optionalChain([window, 'access', _ => _.addEdgeCorePlugins, 'optionalCall', _2 => _2({
|
|
11
|
+
[_bitcoin.info.currencyInfo.pluginId]: plugin
|
|
12
|
+
})])
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports. default = plugin
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); const IMAGE_SERVER_URL = 'https://content.edge.app'; exports.IMAGE_SERVER_URL = IMAGE_SERVER_URL
|
|
2
|
+
const INFO_SERVER_URI = 'https://info1.edgesecure.co:8444/v1'; exports.INFO_SERVER_URI = INFO_SERVER_URI
|
|
3
|
+
|
|
4
|
+
// Fees
|
|
5
|
+
const FEES_PATH = 'fees.json'; exports.FEES_PATH = FEES_PATH
|
|
6
|
+
const MAX_FEE = 999999999.0; exports.MAX_FEE = MAX_FEE
|
|
7
|
+
const LOW_FEE = 2; exports.LOW_FEE = LOW_FEE
|
|
8
|
+
const MAX_HIGH_DELAY = 200; exports.MAX_HIGH_DELAY = MAX_HIGH_DELAY
|
|
9
|
+
const MAX_STANDARD_DELAY = 6; exports.MAX_STANDARD_DELAY = MAX_STANDARD_DELAY
|
|
10
|
+
const MIN_STANDARD_DELAY = 2; exports.MIN_STANDARD_DELAY = MIN_STANDARD_DELAY
|
|
11
|
+
const MIN_LOW_DELAY = 1; exports.MIN_LOW_DELAY = MIN_LOW_DELAY
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _biggystring = require('biggystring'); var bs = _interopRequireWildcard(_biggystring);
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Calculate the sat/byte mining fee given an amount to spend and a SimpleFeeSettings object
|
|
10
|
+
* @param nativeAmount
|
|
11
|
+
* @param fees
|
|
12
|
+
* @param networkFeeOption
|
|
13
|
+
* @param customNetworkFee
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
const calcMinerFeePerByte = (
|
|
17
|
+
nativeAmount,
|
|
18
|
+
fees,
|
|
19
|
+
networkFeeOption,
|
|
20
|
+
customNetworkFee
|
|
21
|
+
) => {
|
|
22
|
+
switch (networkFeeOption) {
|
|
23
|
+
case 'low':
|
|
24
|
+
return fees.lowFee
|
|
25
|
+
|
|
26
|
+
case 'standard': {
|
|
27
|
+
if (bs.gte(nativeAmount, fees.standardFeeHighAmount)) {
|
|
28
|
+
return fees.standardFeeHigh
|
|
29
|
+
}
|
|
30
|
+
if (bs.lte(nativeAmount, fees.standardFeeLowAmount)) {
|
|
31
|
+
return fees.standardFeeLow
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Scale the fee by the amount the user is sending scaled between standardFeeLowAmount and standardFeeHighAmount
|
|
35
|
+
const lowHighAmountDiff = bs.sub(
|
|
36
|
+
fees.standardFeeHighAmount,
|
|
37
|
+
fees.standardFeeLowAmount
|
|
38
|
+
)
|
|
39
|
+
const lowHighFeeDiff = bs.sub(fees.standardFeeHigh, fees.standardFeeLow)
|
|
40
|
+
|
|
41
|
+
// How much above the lowFeeAmount is the user sending
|
|
42
|
+
const amountDiffFromLow = bs.sub(nativeAmount, fees.standardFeeLowAmount)
|
|
43
|
+
|
|
44
|
+
// Add this much to the low fee = (amountDiffFromLow * lowHighFeeDiff) / lowHighAmountDiff)
|
|
45
|
+
const temp1 = bs.mul(amountDiffFromLow, lowHighFeeDiff)
|
|
46
|
+
const addFeeToLow = bs.div(temp1, lowHighAmountDiff)
|
|
47
|
+
return bs.add(fees.standardFeeLow, addFeeToLow)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
case 'high':
|
|
51
|
+
return fees.highFee
|
|
52
|
+
|
|
53
|
+
case 'custom':
|
|
54
|
+
if (customNetworkFee == null || customNetworkFee === '0') {
|
|
55
|
+
throw new Error(`Invalid custom network fee: ${customNetworkFee}`)
|
|
56
|
+
}
|
|
57
|
+
return customNetworkFee
|
|
58
|
+
|
|
59
|
+
default:
|
|
60
|
+
throw new Error(`Invalid networkFeeOption: ${networkFeeOption}`)
|
|
61
|
+
}
|
|
62
|
+
}; exports.calcMinerFeePerByte = calcMinerFeePerByte
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return 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'); var bs = _interopRequireWildcard(_biggystring);
|
|
2
|
+
var _cleaners = require('cleaners');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _memlet = require('memlet');
|
|
11
|
+
|
|
12
|
+
var _constants = require('../constants');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _types3 = require('../plugin/types');
|
|
18
|
+
var _calcMinerFeePerByte = require('./calcMinerFeePerByte');
|
|
19
|
+
var _processInfoServerFees = require('./processInfoServerFees');
|
|
20
|
+
var _processMempoolSpaceFees = require('./processMempoolSpaceFees');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const makeFees = async (config) => {
|
|
41
|
+
const { disklet, pluginInfo, ...common } = config
|
|
42
|
+
const { currencyInfo, engineInfo } = pluginInfo
|
|
43
|
+
|
|
44
|
+
const memlet = _memlet.makeMemlet.call(void 0, disklet)
|
|
45
|
+
const fees = await fetchCachedFees(
|
|
46
|
+
memlet,
|
|
47
|
+
engineInfo.simpleFeeSettings
|
|
48
|
+
)
|
|
49
|
+
// The last time the fees were updated
|
|
50
|
+
let timestamp = 0
|
|
51
|
+
let vendorIntervalId
|
|
52
|
+
|
|
53
|
+
const updateVendorFees = async () => {
|
|
54
|
+
if (Date.now() - timestamp <= engineInfo.feeUpdateInterval) return
|
|
55
|
+
|
|
56
|
+
const vendorFees = await fetchFeesFromVendor({
|
|
57
|
+
...common,
|
|
58
|
+
mempoolSpaceFeeInfoServer: engineInfo.mempoolSpaceFeeInfoServer
|
|
59
|
+
})
|
|
60
|
+
Object.assign(fees, _nullishCoalesce(vendorFees, () => ( {})))
|
|
61
|
+
timestamp = Date.now()
|
|
62
|
+
|
|
63
|
+
await cacheFees(memlet, fees)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
async start() {
|
|
68
|
+
const edgeFees = await fetchFees({
|
|
69
|
+
...common,
|
|
70
|
+
uri: `${_constants.INFO_SERVER_URI}/networkFees/${currencyInfo.currencyCode}`,
|
|
71
|
+
processor: _processInfoServerFees.processInfoServerFees
|
|
72
|
+
})
|
|
73
|
+
Object.assign(fees, edgeFees)
|
|
74
|
+
await updateVendorFees()
|
|
75
|
+
vendorIntervalId = setInterval(
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
77
|
+
updateVendorFees,
|
|
78
|
+
engineInfo.feeUpdateInterval
|
|
79
|
+
)
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
stop() {
|
|
83
|
+
clearInterval(vendorIntervalId)
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
async clearCache() {
|
|
87
|
+
await memlet.delete(_constants.FEES_PATH)
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
async getRate(edgeSpendInfo) {
|
|
91
|
+
const {
|
|
92
|
+
spendTargets,
|
|
93
|
+
networkFeeOption = 'standard',
|
|
94
|
+
customNetworkFee = {},
|
|
95
|
+
otherParams = {}
|
|
96
|
+
} = edgeSpendInfo
|
|
97
|
+
|
|
98
|
+
const requiredFeeRate =
|
|
99
|
+
_optionalChain([otherParams, 'access', _ => _.paymentProtocolInfo, 'optionalAccess', _2 => _2.merchant, 'optionalAccess', _3 => _3.requiredFeeRate])
|
|
100
|
+
if (requiredFeeRate != null) {
|
|
101
|
+
const rate = bs.add(bs.mul(`${requiredFeeRate}`, '1.5'), '1')
|
|
102
|
+
return bs.toFixed(rate, 0, 0)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const customFeeTemplate = (_nullishCoalesce(currencyInfo.customFeeTemplate, () => ( [])))[0]
|
|
106
|
+
if (customFeeTemplate == null) throw new Error('No custom fee template')
|
|
107
|
+
|
|
108
|
+
const rate = _calcMinerFeePerByte.calcMinerFeePerByte.call(void 0,
|
|
109
|
+
sumSpendTargets(spendTargets),
|
|
110
|
+
fees,
|
|
111
|
+
networkFeeOption,
|
|
112
|
+
customNetworkFee[customFeeTemplate.key]
|
|
113
|
+
)
|
|
114
|
+
return rate
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
get fees() {
|
|
118
|
+
return fees
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}; exports.makeFees = makeFees
|
|
122
|
+
|
|
123
|
+
const fetchCachedFees = async (
|
|
124
|
+
memlet,
|
|
125
|
+
fallback
|
|
126
|
+
) => {
|
|
127
|
+
const data = await memlet.getJson(_constants.FEES_PATH).catch(() => undefined)
|
|
128
|
+
const feeSettings = _cleaners.asMaybe.call(void 0, _types3.asSimpleFeeSettings, fallback)(data)
|
|
129
|
+
return feeSettings
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const cacheFees = async (
|
|
133
|
+
memlet,
|
|
134
|
+
fees
|
|
135
|
+
) => await memlet.setJson(_constants.FEES_PATH, fees)
|
|
136
|
+
|
|
137
|
+
const sumSpendTargets = (spendTargets) =>
|
|
138
|
+
spendTargets.reduce((amount, { nativeAmount }) => {
|
|
139
|
+
if (nativeAmount == null)
|
|
140
|
+
throw new Error(`Invalid spend target amount: ${nativeAmount}`)
|
|
141
|
+
return bs.add(amount, nativeAmount)
|
|
142
|
+
}, '0')
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
const fetchFees = async ( args) => {
|
|
149
|
+
const { uri, processor, io, log } = args
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
const response = await io.fetch(uri)
|
|
153
|
+
if (!response.ok) throw new Error(`Error fetching fees from ${uri}`)
|
|
154
|
+
|
|
155
|
+
const fees = await response.json()
|
|
156
|
+
return processor(fees)
|
|
157
|
+
} catch (err) {
|
|
158
|
+
log(err.message)
|
|
159
|
+
return null
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
const fetchFeesFromVendor = async (
|
|
168
|
+
args
|
|
169
|
+
) => {
|
|
170
|
+
if (args.mempoolSpaceFeeInfoServer != null) {
|
|
171
|
+
const mempoolFees = await fetchFees({
|
|
172
|
+
...args,
|
|
173
|
+
uri: args.mempoolSpaceFeeInfoServer,
|
|
174
|
+
processor: _processMempoolSpaceFees.processMempoolSpaceFees
|
|
175
|
+
})
|
|
176
|
+
if (mempoolFees != null) {
|
|
177
|
+
return mempoolFees
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return {}
|
|
182
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _cleaners = require('cleaners');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const asInfoServerFees = _cleaners.asObject({
|
|
6
|
+
lowFee: _cleaners.asString,
|
|
7
|
+
standardFeeLow: _cleaners.asString,
|
|
8
|
+
standardFeeHigh: _cleaners.asString,
|
|
9
|
+
highFee: _cleaners.asString,
|
|
10
|
+
|
|
11
|
+
// The amount of satoshis which will be charged the standardFeeLow
|
|
12
|
+
standardFeeLowAmount: _cleaners.asString,
|
|
13
|
+
// The amount of satoshis which will be charged the standardFeeHigh
|
|
14
|
+
standardFeeHighAmount: _cleaners.asString
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Processes the fee object from Edge Info Server
|
|
19
|
+
* @param fees
|
|
20
|
+
* @returns {SimpleFeeSettings}
|
|
21
|
+
*/
|
|
22
|
+
const processInfoServerFees = (
|
|
23
|
+
fees
|
|
24
|
+
) => {
|
|
25
|
+
try {
|
|
26
|
+
return asInfoServerFees(fees)
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
}; exports.processInfoServerFees = processInfoServerFees
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _biggystring = require('biggystring'); var bs = _interopRequireWildcard(_biggystring);
|
|
2
|
+
var _cleaners = require('cleaners');
|
|
3
|
+
|
|
4
|
+
var _constants = require('../constants');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const asMempoolSpaceFees = _cleaners.asObject.call(void 0, {
|
|
8
|
+
fastestFee: _cleaners.asNumber,
|
|
9
|
+
halfHourFee: _cleaners.asNumber,
|
|
10
|
+
hourFee: _cleaners.asNumber
|
|
11
|
+
}); exports.asMempoolSpaceFees = asMempoolSpaceFees
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the FeeRates object from MempoolSpace
|
|
15
|
+
* Sets the minimum of LOW_FEE on all fee levels
|
|
16
|
+
* @param fees
|
|
17
|
+
* @returns Partial<FeeRates>
|
|
18
|
+
*/
|
|
19
|
+
const processMempoolSpaceFees = (fees) => {
|
|
20
|
+
let mempoolFees
|
|
21
|
+
try {
|
|
22
|
+
mempoolFees = exports.asMempoolSpaceFees.call(void 0, fees)
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const standardFeeLow = mempoolFees.hourFee.toString()
|
|
28
|
+
const lowFee = bs.div(standardFeeLow, '2')
|
|
29
|
+
const standardFeeHigh = mempoolFees.halfHourFee.toString()
|
|
30
|
+
const highFee = mempoolFees.fastestFee.toString()
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
lowFee: bs.max(lowFee, _constants.LOW_FEE.toString()),
|
|
34
|
+
standardFeeLow: bs.max(standardFeeLow, _constants.LOW_FEE.toString()),
|
|
35
|
+
standardFeeHigh: bs.max(standardFeeHigh, _constants.LOW_FEE.toString()),
|
|
36
|
+
highFee: bs.max(highFee, _constants.LOW_FEE.toString())
|
|
37
|
+
}
|
|
38
|
+
}; exports.processMempoolSpaceFees = processMempoolSpaceFees
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _makeUtxoEngine = require('../utxobased/engine/makeUtxoEngine');
|
|
11
|
+
var _types3 = require('../utxobased/engine/types');
|
|
12
|
+
var _makeCurrencyTools = require('./makeCurrencyTools');
|
|
13
|
+
var _makeEngineEmitter = require('./makeEngineEmitter');
|
|
14
|
+
var _pluginState = require('./pluginState');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
function makeCurrencyPlugin(
|
|
18
|
+
pluginOptions,
|
|
19
|
+
pluginInfo
|
|
20
|
+
) {
|
|
21
|
+
const { currencyInfo } = pluginInfo
|
|
22
|
+
const { io, log, pluginDisklet } = pluginOptions
|
|
23
|
+
const currencyTools = _makeCurrencyTools.makeCurrencyTools.call(void 0, io, pluginInfo)
|
|
24
|
+
const { defaultSettings, pluginId, currencyCode } = currencyInfo
|
|
25
|
+
const state = _pluginState.makePluginState.call(void 0, {
|
|
26
|
+
io,
|
|
27
|
+
currencyCode,
|
|
28
|
+
pluginId,
|
|
29
|
+
pluginDisklet,
|
|
30
|
+
log,
|
|
31
|
+
defaultSettings: _types3.asUtxoUserSettings.call(void 0, defaultSettings)
|
|
32
|
+
})
|
|
33
|
+
return {
|
|
34
|
+
currencyInfo,
|
|
35
|
+
|
|
36
|
+
async makeCurrencyEngine(
|
|
37
|
+
walletInfo,
|
|
38
|
+
engineOptions
|
|
39
|
+
) {
|
|
40
|
+
const emitter = _makeEngineEmitter.makeEngineEmitter.call(void 0, engineOptions.callbacks)
|
|
41
|
+
const engineConfig = {
|
|
42
|
+
walletInfo,
|
|
43
|
+
pluginInfo,
|
|
44
|
+
pluginDisklet,
|
|
45
|
+
currencyTools,
|
|
46
|
+
io,
|
|
47
|
+
options: {
|
|
48
|
+
...pluginOptions,
|
|
49
|
+
...engineOptions,
|
|
50
|
+
emitter
|
|
51
|
+
},
|
|
52
|
+
pluginState: state
|
|
53
|
+
}
|
|
54
|
+
const engine = await _makeUtxoEngine.makeUtxoEngine.call(void 0, engineConfig)
|
|
55
|
+
|
|
56
|
+
return engine
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
async makeCurrencyTools() {
|
|
60
|
+
state.load().catch(e => {
|
|
61
|
+
throw e
|
|
62
|
+
})
|
|
63
|
+
return currencyTools
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} exports.makeCurrencyPlugin = makeCurrencyPlugin;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return 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'); var bn = _interopRequireWildcard(_biggystring);
|
|
2
|
+
var _bip39 = require('bip39'); var bip39 = _interopRequireWildcard(_bip39);
|
|
3
|
+
var _cleaners = require('cleaners');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _urijs = require('uri-js'); var uri = _interopRequireWildcard(_urijs);
|
|
13
|
+
var _urlparse = require('url-parse'); var _urlparse2 = _interopRequireDefault(_urlparse);
|
|
14
|
+
|
|
15
|
+
var _utils = require('../utxobased/engine/utils');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _cleaners3 = require('../utxobased/keymanager/cleaners');
|
|
21
|
+
|
|
22
|
+
var _utils3 = require('./utils');
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The core currency plugin.
|
|
26
|
+
* Provides information about the currency,
|
|
27
|
+
* as well as generic (non-wallet) functionality.
|
|
28
|
+
*/
|
|
29
|
+
function makeCurrencyTools(
|
|
30
|
+
io,
|
|
31
|
+
pluginInfo
|
|
32
|
+
) {
|
|
33
|
+
const { currencyInfo, engineInfo, coinInfo } = pluginInfo
|
|
34
|
+
|
|
35
|
+
const asCurrencyPrivateKey = _cleaners3.asPrivateKey.call(void 0, coinInfo.name, coinInfo.coinType)
|
|
36
|
+
const wasCurrencyPrivateKey = _cleaners.uncleaner.call(void 0, asCurrencyPrivateKey)
|
|
37
|
+
const asCurrencyNumbWalletInfo = _cleaners3.asNumbWalletInfo.call(void 0, pluginInfo)
|
|
38
|
+
|
|
39
|
+
const fns = {
|
|
40
|
+
async createPrivateKey(
|
|
41
|
+
_walletType,
|
|
42
|
+
opts
|
|
43
|
+
) {
|
|
44
|
+
const mnemonic = bip39.entropyToMnemonic(Buffer.from(io.random(32)))
|
|
45
|
+
|
|
46
|
+
const privateKey = {
|
|
47
|
+
imported: false,
|
|
48
|
+
seed: mnemonic,
|
|
49
|
+
format: _nullishCoalesce(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _ => _.format]), () => ( _optionalChain([engineInfo, 'access', _2 => _2.formats, 'optionalAccess', _3 => _3[0]]))), () => ( 'bip44')),
|
|
50
|
+
coinType: _nullishCoalesce(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _4 => _4.coinType]), () => ( coinInfo.coinType)), () => ( 0))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return wasCurrencyPrivateKey(privateKey)
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async importPrivateKey(
|
|
57
|
+
entropy,
|
|
58
|
+
opts
|
|
59
|
+
) {
|
|
60
|
+
const isMnemonic = bip39.validateMnemonic(entropy)
|
|
61
|
+
|
|
62
|
+
// Handle error case(s) if not a valid form of entropy
|
|
63
|
+
if (!isMnemonic) {
|
|
64
|
+
// An Airbitz seed is a 256 bit base64 encoded string. Convert the string
|
|
65
|
+
// to a buffer and then count the bytes (32 bytes is 256 bits).
|
|
66
|
+
const isAirbitzSeed = Buffer.from(entropy, 'base64').length === 32
|
|
67
|
+
if (isAirbitzSeed) {
|
|
68
|
+
throw new Error('Import for Airbitz seeds is unsupported.')
|
|
69
|
+
}
|
|
70
|
+
throw new Error('Invalid mnemonic')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const privateKey = {
|
|
74
|
+
imported: true,
|
|
75
|
+
seed: entropy,
|
|
76
|
+
format: _nullishCoalesce(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _5 => _5.format]), () => ( _optionalChain([engineInfo, 'access', _6 => _6.formats, 'optionalAccess', _7 => _7[0]]))), () => ( 'bip44')),
|
|
77
|
+
coinType: _nullishCoalesce(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _8 => _8.coinType]), () => ( coinInfo.coinType)), () => ( 0))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return wasCurrencyPrivateKey(privateKey)
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
async derivePublicKey(walletInfo) {
|
|
84
|
+
const numbWalletInfo = asCurrencyNumbWalletInfo(walletInfo)
|
|
85
|
+
return numbWalletInfo.keys.publicKey
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
async parseUri(uri) {
|
|
89
|
+
const isGateway = uri
|
|
90
|
+
.toLocaleLowerCase()
|
|
91
|
+
.startsWith(`${coinInfo.name}://`)
|
|
92
|
+
if (isGateway) uri = uri.replace('//', '')
|
|
93
|
+
|
|
94
|
+
const uriObj = _urlparse2.default.call(void 0, uri, {}, true)
|
|
95
|
+
const protocol = uriObj.protocol.replace(':', '').toLowerCase()
|
|
96
|
+
|
|
97
|
+
// If the currency URI belongs to the wrong network then error
|
|
98
|
+
if (
|
|
99
|
+
protocol !== '' &&
|
|
100
|
+
protocol !== currencyInfo.pluginId &&
|
|
101
|
+
protocol !== engineInfo.uriPrefix &&
|
|
102
|
+
protocol !== 'pay'
|
|
103
|
+
) {
|
|
104
|
+
throw new Error('InvalidUriError')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Get all possible query params
|
|
108
|
+
const { pathname, query } = uriObj
|
|
109
|
+
// If we don't have a pathname or a paymentProtocolURL uri then we bail
|
|
110
|
+
if (pathname === '' && query.r == null) throw new Error('InvalidUriError')
|
|
111
|
+
|
|
112
|
+
// Create the returned object
|
|
113
|
+
const parsedUri = {}
|
|
114
|
+
// Parse the pathname and add it to the result object
|
|
115
|
+
if (pathname !== '') {
|
|
116
|
+
const parsedPath = _utils.parsePathname.call(void 0, {
|
|
117
|
+
pathname: uriObj.pathname,
|
|
118
|
+
coin: coinInfo.name
|
|
119
|
+
})
|
|
120
|
+
if (parsedPath == null) throw new Error('InvalidUriError')
|
|
121
|
+
|
|
122
|
+
Object.assign(parsedUri, parsedPath)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Assign the query params to the parsedUri object
|
|
126
|
+
const metadata = {}
|
|
127
|
+
if (query.label != null) metadata.name = query.label
|
|
128
|
+
if (query.message != null) metadata.notes = query.message
|
|
129
|
+
if (query.category != null) metadata.category = query.category
|
|
130
|
+
if (query.r != null) parsedUri.paymentProtocolUrl = query.r
|
|
131
|
+
if (isGateway) metadata.gateway = true
|
|
132
|
+
Object.assign(parsedUri, { metadata })
|
|
133
|
+
|
|
134
|
+
// Get amount in native denomination if exists
|
|
135
|
+
const denomination = currencyInfo.denominations.find(
|
|
136
|
+
({ name }) => name === currencyInfo.currencyCode
|
|
137
|
+
)
|
|
138
|
+
if (denomination != null && query.amount != null) {
|
|
139
|
+
const { multiplier = '1' } = denomination
|
|
140
|
+
const t = bn.mul(query.amount, multiplier.toString())
|
|
141
|
+
parsedUri.currencyCode = currencyInfo.currencyCode
|
|
142
|
+
parsedUri.nativeAmount = bn.toFixed(t, 0, 0)
|
|
143
|
+
}
|
|
144
|
+
return parsedUri
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
async encodeUri(
|
|
148
|
+
obj,
|
|
149
|
+
_customTokens
|
|
150
|
+
) {
|
|
151
|
+
const { publicAddress } = obj
|
|
152
|
+
if (publicAddress === '') {
|
|
153
|
+
throw new Error('InvalidPublicAddressError')
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// TODO: validate network address
|
|
157
|
+
|
|
158
|
+
const query = []
|
|
159
|
+
|
|
160
|
+
if (obj.nativeAmount != null) {
|
|
161
|
+
const currencyCode = _nullishCoalesce(obj.currencyCode, () => ( currencyInfo.currencyCode))
|
|
162
|
+
const denomination = currencyInfo.denominations.find(
|
|
163
|
+
({ name }) => name === currencyCode
|
|
164
|
+
)
|
|
165
|
+
if (denomination == null) {
|
|
166
|
+
throw new Error('InvalidDenominationError')
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const amount = bn.div(obj.nativeAmount, denomination.multiplier, 8)
|
|
170
|
+
query.push(`amount=${amount}`)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (obj.label != null) {
|
|
174
|
+
query.push(`label=${obj.label}`)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (obj.message != null) {
|
|
178
|
+
query.push(`message=${obj.message}`)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const metadata = obj.metadata
|
|
182
|
+
if (metadata != null) {
|
|
183
|
+
if (metadata.name != null) {
|
|
184
|
+
query.push(`label=${metadata.name}`)
|
|
185
|
+
}
|
|
186
|
+
if (metadata.notes != null) {
|
|
187
|
+
query.push(`message=${metadata.notes}`)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return query.length > 0
|
|
192
|
+
? uri.serialize({
|
|
193
|
+
scheme: _nullishCoalesce(engineInfo.uriPrefix, () => ( currencyInfo.pluginId)),
|
|
194
|
+
path: publicAddress,
|
|
195
|
+
query: query.join('&')
|
|
196
|
+
})
|
|
197
|
+
: publicAddress
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
getSplittableTypes(walletInfo) {
|
|
201
|
+
const { keys: { format = 'bip32' } = {} } = walletInfo
|
|
202
|
+
const forks = _nullishCoalesce(engineInfo.forks, () => ( []))
|
|
203
|
+
|
|
204
|
+
return forks
|
|
205
|
+
.filter(network => _utils3.getFormatsForNetwork.call(void 0, network).includes(format))
|
|
206
|
+
.map(network => `wallet:${network}`)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return fns
|
|
211
|
+
} exports.makeCurrencyTools = makeCurrencyTools;
|