@ledgerhq/coin-framework 0.0.2-next.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/account/accountId.d.ts +16 -0
- package/lib/account/accountId.d.ts.map +1 -0
- package/lib/account/accountId.js +85 -0
- package/lib/account/accountId.js.map +1 -0
- package/lib/account/accountName.d.ts +14 -0
- package/lib/account/accountName.d.ts.map +1 -0
- package/lib/account/accountName.js +17 -0
- package/lib/account/accountName.js.map +1 -0
- package/lib/account/addAccounts.d.ts +35 -0
- package/lib/account/addAccounts.d.ts.map +1 -0
- package/lib/account/addAccounts.js +209 -0
- package/lib/account/addAccounts.js.map +1 -0
- package/lib/account/balanceHistoryCache.d.ts +25 -0
- package/lib/account/balanceHistoryCache.d.ts.map +1 -0
- package/lib/account/balanceHistoryCache.js +115 -0
- package/lib/account/balanceHistoryCache.js.map +1 -0
- package/lib/account/groupOperations.d.ts +17 -0
- package/lib/account/groupOperations.d.ts.map +1 -0
- package/lib/account/groupOperations.js +127 -0
- package/lib/account/groupOperations.js.map +1 -0
- package/lib/account/helpers.d.ts +44 -0
- package/lib/account/helpers.d.ts.map +1 -0
- package/lib/account/helpers.js +333 -0
- package/lib/account/helpers.js.map +1 -0
- package/lib/account/helpers.test.d.ts +2 -0
- package/lib/account/helpers.test.d.ts.map +1 -0
- package/lib/account/helpers.test.js +366 -0
- package/lib/account/helpers.test.js.map +1 -0
- package/lib/account/index.d.ts +11 -0
- package/lib/account/index.d.ts.map +1 -0
- package/lib/account/index.js +27 -0
- package/lib/account/index.js.map +1 -0
- package/lib/account/ordering.d.ts +10 -0
- package/lib/account/ordering.d.ts.map +1 -0
- package/lib/account/ordering.js +110 -0
- package/lib/account/ordering.js.map +1 -0
- package/lib/account/pending.d.ts +33 -0
- package/lib/account/pending.d.ts.map +1 -0
- package/lib/account/pending.js +64 -0
- package/lib/account/pending.js.map +1 -0
- package/lib/account/serialization.d.ts +6 -0
- package/lib/account/serialization.d.ts.map +1 -0
- package/lib/account/serialization.js +118 -0
- package/lib/account/serialization.js.map +1 -0
- package/lib/account/support.d.ts +9 -0
- package/lib/account/support.d.ts.map +1 -0
- package/lib/account/support.js +72 -0
- package/lib/account/support.js.map +1 -0
- package/lib/account.test.d.ts +2 -0
- package/lib/account.test.d.ts.map +1 -0
- package/lib/account.test.js +257 -0
- package/lib/account.test.js.map +1 -0
- package/lib/bot/bot-test-context.d.ts +3 -0
- package/lib/bot/bot-test-context.d.ts.map +1 -0
- package/lib/bot/bot-test-context.js +26 -0
- package/lib/bot/bot-test-context.js.map +1 -0
- package/lib/bot/bot-test-context.test.d.ts +2 -0
- package/lib/bot/bot-test-context.test.d.ts.map +1 -0
- package/lib/bot/bot-test-context.test.js +41 -0
- package/lib/bot/bot-test-context.test.js.map +1 -0
- package/lib/bot/formatters.d.ts +2 -0
- package/lib/bot/formatters.d.ts.map +1 -0
- package/lib/bot/formatters.js +31 -0
- package/lib/bot/formatters.js.map +1 -0
- package/lib/bot/specs.d.ts +50 -0
- package/lib/bot/specs.d.ts.map +1 -0
- package/lib/bot/specs.js +204 -0
- package/lib/bot/specs.js.map +1 -0
- package/lib/bot/types.d.ts +178 -0
- package/lib/bot/types.d.ts.map +1 -0
- package/lib/bot/types.js +3 -0
- package/lib/bot/types.js.map +1 -0
- package/lib/bridge/getAddressWrapper.d.ts +6 -0
- package/lib/bridge/getAddressWrapper.d.ts.map +1 -0
- package/lib/bridge/getAddressWrapper.js +27 -0
- package/lib/bridge/getAddressWrapper.js.map +1 -0
- package/lib/bridge/jsHelpers.d.ts +63 -0
- package/lib/bridge/jsHelpers.d.ts.map +1 -0
- package/lib/bridge/jsHelpers.js +574 -0
- package/lib/bridge/jsHelpers.js.map +1 -0
- package/lib/cache.d.ts +10 -0
- package/lib/cache.d.ts.map +1 -0
- package/lib/cache.js +100 -0
- package/lib/cache.js.map +1 -0
- package/lib/cross.d.ts +42 -0
- package/lib/cross.d.ts.map +1 -0
- package/lib/cross.js +254 -0
- package/lib/cross.js.map +1 -0
- package/lib/cross.test.d.ts +2 -0
- package/lib/cross.test.d.ts.map +1 -0
- package/lib/cross.test.js +99 -0
- package/lib/cross.test.js.map +1 -0
- package/lib/currencies/BigNumberToLocaleString.d.ts +8 -0
- package/lib/currencies/BigNumberToLocaleString.d.ts.map +1 -0
- package/lib/currencies/BigNumberToLocaleString.js +65 -0
- package/lib/currencies/BigNumberToLocaleString.js.map +1 -0
- package/lib/currencies/BigNumberToLocaleString.test.d.ts +2 -0
- package/lib/currencies/BigNumberToLocaleString.test.d.ts.map +1 -0
- package/lib/currencies/BigNumberToLocaleString.test.js +108 -0
- package/lib/currencies/BigNumberToLocaleString.test.js.map +1 -0
- package/lib/currencies/CurrencyURIScheme.d.ts +13 -0
- package/lib/currencies/CurrencyURIScheme.d.ts.map +1 -0
- package/lib/currencies/CurrencyURIScheme.js +124 -0
- package/lib/currencies/CurrencyURIScheme.js.map +1 -0
- package/lib/currencies/chopCurrencyUnitDecimals.d.ts +3 -0
- package/lib/currencies/chopCurrencyUnitDecimals.d.ts.map +1 -0
- package/lib/currencies/chopCurrencyUnitDecimals.js +29 -0
- package/lib/currencies/chopCurrencyUnitDecimals.js.map +1 -0
- package/lib/currencies/formatCurrencyUnit.d.ts +33 -0
- package/lib/currencies/formatCurrencyUnit.d.ts.map +1 -0
- package/lib/currencies/formatCurrencyUnit.js +126 -0
- package/lib/currencies/formatCurrencyUnit.js.map +1 -0
- package/lib/currencies/formatShort.d.ts +8 -0
- package/lib/currencies/formatShort.d.ts.map +1 -0
- package/lib/currencies/formatShort.js +27 -0
- package/lib/currencies/formatShort.js.map +1 -0
- package/lib/currencies/index.d.ts +13 -0
- package/lib/currencies/index.d.ts.map +1 -0
- package/lib/currencies/index.js +65 -0
- package/lib/currencies/index.js.map +1 -0
- package/lib/currencies/localeUtility.d.ts +8 -0
- package/lib/currencies/localeUtility.d.ts.map +1 -0
- package/lib/currencies/localeUtility.js +49 -0
- package/lib/currencies/localeUtility.js.map +1 -0
- package/lib/currencies/parseCurrencyUnit.d.ts +4 -0
- package/lib/currencies/parseCurrencyUnit.d.ts.map +1 -0
- package/lib/currencies/parseCurrencyUnit.js +18 -0
- package/lib/currencies/parseCurrencyUnit.js.map +1 -0
- package/lib/currencies/sanitizeValueString.d.ts +6 -0
- package/lib/currencies/sanitizeValueString.d.ts.map +1 -0
- package/lib/currencies/sanitizeValueString.js +56 -0
- package/lib/currencies/sanitizeValueString.js.map +1 -0
- package/lib/currencies/support.d.ts +8 -0
- package/lib/currencies/support.d.ts.map +1 -0
- package/lib/currencies/support.js +101 -0
- package/lib/currencies/support.js.map +1 -0
- package/lib/currencies/valueFromUnit.d.ts +9 -0
- package/lib/currencies/valueFromUnit.d.ts.map +1 -0
- package/lib/currencies/valueFromUnit.js +14 -0
- package/lib/currencies/valueFromUnit.js.map +1 -0
- package/lib/derivation.d.ts +232 -0
- package/lib/derivation.d.ts.map +1 -0
- package/lib/derivation.js +501 -0
- package/lib/derivation.js.map +1 -0
- package/lib/env.d.ts +30 -0
- package/lib/env.d.ts.map +1 -0
- package/lib/env.js +783 -0
- package/lib/env.js.map +1 -0
- package/lib/errors.d.ts +7 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +7 -0
- package/lib/errors.js.map +1 -0
- package/lib/errors.test.d.ts +2 -0
- package/lib/errors.test.d.ts.map +1 -0
- package/lib/errors.test.js +20 -0
- package/lib/errors.test.js.map +1 -0
- package/lib/mocks/account.d.ts +25 -0
- package/lib/mocks/account.d.ts.map +1 -0
- package/lib/mocks/account.js +368 -0
- package/lib/mocks/account.js.map +1 -0
- package/lib/mocks/fixtures/nfts.d.ts +27 -0
- package/lib/mocks/fixtures/nfts.d.ts.map +1 -0
- package/lib/mocks/fixtures/nfts.js +398 -0
- package/lib/mocks/fixtures/nfts.js.map +1 -0
- package/lib/mocks/fixtures/nfts.test.d.ts +2 -0
- package/lib/mocks/fixtures/nfts.test.d.ts.map +1 -0
- package/lib/mocks/fixtures/nfts.test.js +20 -0
- package/lib/mocks/fixtures/nfts.test.js.map +1 -0
- package/lib/mocks/helpers.d.ts +15 -0
- package/lib/mocks/helpers.d.ts.map +1 -0
- package/lib/mocks/helpers.js +32 -0
- package/lib/mocks/helpers.js.map +1 -0
- package/lib/network.d.ts +5 -0
- package/lib/network.d.ts.map +1 -0
- package/lib/network.js +125 -0
- package/lib/network.js.map +1 -0
- package/lib/nft/nftId.d.ts +8 -0
- package/lib/nft/nftId.d.ts.map +1 -0
- package/lib/nft/nftId.js +34 -0
- package/lib/nft/nftId.js.map +1 -0
- package/lib/operation.d.ts +24 -0
- package/lib/operation.d.ts.map +1 -0
- package/lib/operation.js +183 -0
- package/lib/operation.js.map +1 -0
- package/lib/promise.d.ts +21 -0
- package/lib/promise.d.ts.map +1 -0
- package/lib/promise.js +187 -0
- package/lib/promise.js.map +1 -0
- package/lib/promise.test.d.ts +2 -0
- package/lib/promise.test.d.ts.map +1 -0
- package/lib/promise.test.js +72 -0
- package/lib/promise.test.js.map +1 -0
- package/lib/rangeDates.d.ts +29 -0
- package/lib/rangeDates.d.ts.map +1 -0
- package/lib/rangeDates.js +94 -0
- package/lib/rangeDates.js.map +1 -0
- package/lib/rangeDates.test.d.ts +2 -0
- package/lib/rangeDates.test.d.ts.map +1 -0
- package/lib/rangeDates.test.js +51 -0
- package/lib/rangeDates.test.js.map +1 -0
- package/lib/test-helpers/staticTime.d.ts +2 -0
- package/lib/test-helpers/staticTime.d.ts.map +1 -0
- package/lib/test-helpers/staticTime.js +10 -0
- package/lib/test-helpers/staticTime.js.map +1 -0
- package/lib/transaction/common.d.ts +26 -0
- package/lib/transaction/common.d.ts.map +1 -0
- package/lib/transaction/common.js +123 -0
- package/lib/transaction/common.js.map +1 -0
- package/lib-es/account/accountId.d.ts +16 -0
- package/lib-es/account/accountId.d.ts.map +1 -0
- package/lib-es/account/accountId.js +74 -0
- package/lib-es/account/accountId.js.map +1 -0
- package/lib-es/account/accountName.d.ts +14 -0
- package/lib-es/account/accountName.d.ts.map +1 -0
- package/lib-es/account/accountName.js +12 -0
- package/lib-es/account/accountName.js.map +1 -0
- package/lib-es/account/addAccounts.d.ts +35 -0
- package/lib-es/account/addAccounts.d.ts.map +1 -0
- package/lib-es/account/addAccounts.js +200 -0
- package/lib-es/account/addAccounts.js.map +1 -0
- package/lib-es/account/balanceHistoryCache.d.ts +25 -0
- package/lib-es/account/balanceHistoryCache.d.ts.map +1 -0
- package/lib-es/account/balanceHistoryCache.js +109 -0
- package/lib-es/account/balanceHistoryCache.js.map +1 -0
- package/lib-es/account/groupOperations.d.ts +17 -0
- package/lib-es/account/groupOperations.d.ts.map +1 -0
- package/lib-es/account/groupOperations.js +122 -0
- package/lib-es/account/groupOperations.js.map +1 -0
- package/lib-es/account/helpers.d.ts +44 -0
- package/lib-es/account/helpers.d.ts.map +1 -0
- package/lib-es/account/helpers.js +303 -0
- package/lib-es/account/helpers.js.map +1 -0
- package/lib-es/account/helpers.test.d.ts +2 -0
- package/lib-es/account/helpers.test.d.ts.map +1 -0
- package/lib-es/account/helpers.test.js +361 -0
- package/lib-es/account/helpers.test.js.map +1 -0
- package/lib-es/account/index.d.ts +11 -0
- package/lib-es/account/index.d.ts.map +1 -0
- package/lib-es/account/index.js +11 -0
- package/lib-es/account/index.js.map +1 -0
- package/lib-es/account/ordering.d.ts +10 -0
- package/lib-es/account/ordering.d.ts.map +1 -0
- package/lib-es/account/ordering.js +103 -0
- package/lib-es/account/ordering.js.map +1 -0
- package/lib-es/account/pending.d.ts +33 -0
- package/lib-es/account/pending.d.ts.map +1 -0
- package/lib-es/account/pending.js +59 -0
- package/lib-es/account/pending.js.map +1 -0
- package/lib-es/account/serialization.d.ts +6 -0
- package/lib-es/account/serialization.d.ts.map +1 -0
- package/lib-es/account/serialization.js +112 -0
- package/lib-es/account/serialization.js.map +1 -0
- package/lib-es/account/support.d.ts +9 -0
- package/lib-es/account/support.d.ts.map +1 -0
- package/lib-es/account/support.js +64 -0
- package/lib-es/account/support.js.map +1 -0
- package/lib-es/account.test.d.ts +2 -0
- package/lib-es/account.test.d.ts.map +1 -0
- package/lib-es/account.test.js +252 -0
- package/lib-es/account.test.js.map +1 -0
- package/lib-es/bot/bot-test-context.d.ts +3 -0
- package/lib-es/bot/bot-test-context.d.ts.map +1 -0
- package/lib-es/bot/bot-test-context.js +21 -0
- package/lib-es/bot/bot-test-context.js.map +1 -0
- package/lib-es/bot/bot-test-context.test.d.ts +2 -0
- package/lib-es/bot/bot-test-context.test.d.ts.map +1 -0
- package/lib-es/bot/bot-test-context.test.js +39 -0
- package/lib-es/bot/bot-test-context.test.js.map +1 -0
- package/lib-es/bot/formatters.d.ts +2 -0
- package/lib-es/bot/formatters.d.ts.map +1 -0
- package/lib-es/bot/formatters.js +27 -0
- package/lib-es/bot/formatters.js.map +1 -0
- package/lib-es/bot/specs.d.ts +50 -0
- package/lib-es/bot/specs.d.ts.map +1 -0
- package/lib-es/bot/specs.js +193 -0
- package/lib-es/bot/specs.js.map +1 -0
- package/lib-es/bot/types.d.ts +178 -0
- package/lib-es/bot/types.d.ts.map +1 -0
- package/lib-es/bot/types.js +2 -0
- package/lib-es/bot/types.js.map +1 -0
- package/lib-es/bridge/getAddressWrapper.d.ts +6 -0
- package/lib-es/bridge/getAddressWrapper.d.ts.map +1 -0
- package/lib-es/bridge/getAddressWrapper.js +25 -0
- package/lib-es/bridge/getAddressWrapper.js.map +1 -0
- package/lib-es/bridge/jsHelpers.d.ts +63 -0
- package/lib-es/bridge/jsHelpers.d.ts.map +1 -0
- package/lib-es/bridge/jsHelpers.js +562 -0
- package/lib-es/bridge/jsHelpers.js.map +1 -0
- package/lib-es/cache.d.ts +10 -0
- package/lib-es/cache.d.ts.map +1 -0
- package/lib-es/cache.js +93 -0
- package/lib-es/cache.js.map +1 -0
- package/lib-es/cross.d.ts +42 -0
- package/lib-es/cross.d.ts.map +1 -0
- package/lib-es/cross.js +244 -0
- package/lib-es/cross.js.map +1 -0
- package/lib-es/cross.test.d.ts +2 -0
- package/lib-es/cross.test.d.ts.map +1 -0
- package/lib-es/cross.test.js +97 -0
- package/lib-es/cross.test.js.map +1 -0
- package/lib-es/currencies/BigNumberToLocaleString.d.ts +8 -0
- package/lib-es/currencies/BigNumberToLocaleString.d.ts.map +1 -0
- package/lib-es/currencies/BigNumberToLocaleString.js +61 -0
- package/lib-es/currencies/BigNumberToLocaleString.js.map +1 -0
- package/lib-es/currencies/BigNumberToLocaleString.test.d.ts +2 -0
- package/lib-es/currencies/BigNumberToLocaleString.test.d.ts.map +1 -0
- package/lib-es/currencies/BigNumberToLocaleString.test.js +106 -0
- package/lib-es/currencies/BigNumberToLocaleString.test.js.map +1 -0
- package/lib-es/currencies/CurrencyURIScheme.d.ts +13 -0
- package/lib-es/currencies/CurrencyURIScheme.d.ts.map +1 -0
- package/lib-es/currencies/CurrencyURIScheme.js +116 -0
- package/lib-es/currencies/CurrencyURIScheme.js.map +1 -0
- package/lib-es/currencies/chopCurrencyUnitDecimals.d.ts +3 -0
- package/lib-es/currencies/chopCurrencyUnitDecimals.d.ts.map +1 -0
- package/lib-es/currencies/chopCurrencyUnitDecimals.js +25 -0
- package/lib-es/currencies/chopCurrencyUnitDecimals.js.map +1 -0
- package/lib-es/currencies/formatCurrencyUnit.d.ts +33 -0
- package/lib-es/currencies/formatCurrencyUnit.d.ts.map +1 -0
- package/lib-es/currencies/formatCurrencyUnit.js +121 -0
- package/lib-es/currencies/formatCurrencyUnit.js.map +1 -0
- package/lib-es/currencies/formatShort.d.ts +8 -0
- package/lib-es/currencies/formatShort.d.ts.map +1 -0
- package/lib-es/currencies/formatShort.js +20 -0
- package/lib-es/currencies/formatShort.js.map +1 -0
- package/lib-es/currencies/index.d.ts +13 -0
- package/lib-es/currencies/index.d.ts.map +1 -0
- package/lib-es/currencies/index.js +16 -0
- package/lib-es/currencies/index.js.map +1 -0
- package/lib-es/currencies/localeUtility.d.ts +8 -0
- package/lib-es/currencies/localeUtility.d.ts.map +1 -0
- package/lib-es/currencies/localeUtility.js +43 -0
- package/lib-es/currencies/localeUtility.js.map +1 -0
- package/lib-es/currencies/parseCurrencyUnit.d.ts +4 -0
- package/lib-es/currencies/parseCurrencyUnit.d.ts.map +1 -0
- package/lib-es/currencies/parseCurrencyUnit.js +14 -0
- package/lib-es/currencies/parseCurrencyUnit.js.map +1 -0
- package/lib-es/currencies/sanitizeValueString.d.ts +6 -0
- package/lib-es/currencies/sanitizeValueString.d.ts.map +1 -0
- package/lib-es/currencies/sanitizeValueString.js +52 -0
- package/lib-es/currencies/sanitizeValueString.js.map +1 -0
- package/lib-es/currencies/support.d.ts +8 -0
- package/lib-es/currencies/support.d.ts.map +1 -0
- package/lib-es/currencies/support.js +92 -0
- package/lib-es/currencies/support.js.map +1 -0
- package/lib-es/currencies/valueFromUnit.d.ts +9 -0
- package/lib-es/currencies/valueFromUnit.d.ts.map +1 -0
- package/lib-es/currencies/valueFromUnit.js +10 -0
- package/lib-es/currencies/valueFromUnit.js.map +1 -0
- package/lib-es/derivation.d.ts +232 -0
- package/lib-es/derivation.d.ts.map +1 -0
- package/lib-es/derivation.js +473 -0
- package/lib-es/derivation.js.map +1 -0
- package/lib-es/env.d.ts +30 -0
- package/lib-es/env.d.ts.map +1 -0
- package/lib-es/env.js +768 -0
- package/lib-es/env.js.map +1 -0
- package/lib-es/errors.d.ts +7 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +4 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/errors.test.d.ts +2 -0
- package/lib-es/errors.test.d.ts.map +1 -0
- package/lib-es/errors.test.js +18 -0
- package/lib-es/errors.test.js.map +1 -0
- package/lib-es/mocks/account.d.ts +25 -0
- package/lib-es/mocks/account.d.ts.map +1 -0
- package/lib-es/mocks/account.js +358 -0
- package/lib-es/mocks/account.js.map +1 -0
- package/lib-es/mocks/fixtures/nfts.d.ts +27 -0
- package/lib-es/mocks/fixtures/nfts.d.ts.map +1 -0
- package/lib-es/mocks/fixtures/nfts.js +390 -0
- package/lib-es/mocks/fixtures/nfts.js.map +1 -0
- package/lib-es/mocks/fixtures/nfts.test.d.ts +2 -0
- package/lib-es/mocks/fixtures/nfts.test.d.ts.map +1 -0
- package/lib-es/mocks/fixtures/nfts.test.js +18 -0
- package/lib-es/mocks/fixtures/nfts.test.js.map +1 -0
- package/lib-es/mocks/helpers.d.ts +15 -0
- package/lib-es/mocks/helpers.d.ts.map +1 -0
- package/lib-es/mocks/helpers.js +26 -0
- package/lib-es/mocks/helpers.js.map +1 -0
- package/lib-es/network.d.ts +5 -0
- package/lib-es/network.d.ts.map +1 -0
- package/lib-es/network.js +118 -0
- package/lib-es/network.js.map +1 -0
- package/lib-es/nft/nftId.d.ts +8 -0
- package/lib-es/nft/nftId.d.ts.map +1 -0
- package/lib-es/nft/nftId.js +29 -0
- package/lib-es/nft/nftId.js.map +1 -0
- package/lib-es/operation.d.ts +24 -0
- package/lib-es/operation.d.ts.map +1 -0
- package/lib-es/operation.js +168 -0
- package/lib-es/operation.js.map +1 -0
- package/lib-es/promise.d.ts +21 -0
- package/lib-es/promise.d.ts.map +1 -0
- package/lib-es/promise.js +179 -0
- package/lib-es/promise.js.map +1 -0
- package/lib-es/promise.test.d.ts +2 -0
- package/lib-es/promise.test.d.ts.map +1 -0
- package/lib-es/promise.test.js +70 -0
- package/lib-es/promise.test.js.map +1 -0
- package/lib-es/rangeDates.d.ts +29 -0
- package/lib-es/rangeDates.d.ts.map +1 -0
- package/lib-es/rangeDates.js +84 -0
- package/lib-es/rangeDates.js.map +1 -0
- package/lib-es/rangeDates.test.d.ts +2 -0
- package/lib-es/rangeDates.test.d.ts.map +1 -0
- package/lib-es/rangeDates.test.js +49 -0
- package/lib-es/rangeDates.test.js.map +1 -0
- package/lib-es/test-helpers/staticTime.d.ts +2 -0
- package/lib-es/test-helpers/staticTime.d.ts.map +1 -0
- package/lib-es/test-helpers/staticTime.js +5 -0
- package/lib-es/test-helpers/staticTime.js.map +1 -0
- package/lib-es/transaction/common.d.ts +26 -0
- package/lib-es/transaction/common.d.ts.map +1 -0
- package/lib-es/transaction/common.js +115 -0
- package/lib-es/transaction/common.js.map +1 -0
- package/package.json +113 -0
- package/src/__snapshots__/account.test.ts.snap +2065 -0
- package/src/__snapshots__/cross.test.ts.snap +57 -0
- package/src/account/accountId.ts +93 -0
- package/src/account/accountName.ts +25 -0
- package/src/account/addAccounts.ts +236 -0
- package/src/account/balanceHistoryCache.ts +146 -0
- package/src/account/groupOperations.ts +164 -0
- package/src/account/helpers.test.ts +441 -0
- package/src/account/helpers.ts +380 -0
- package/src/account/index.ts +10 -0
- package/src/account/ordering.ts +109 -0
- package/src/account/pending.ts +66 -0
- package/src/account/serialization.ts +189 -0
- package/src/account/support.ts +96 -0
- package/src/account.test.ts +237 -0
- package/src/bot/bot-test-context.test.ts +37 -0
- package/src/bot/bot-test-context.ts +24 -0
- package/src/bot/formatters.ts +22 -0
- package/src/bot/specs.ts +275 -0
- package/src/bot/types.ts +224 -0
- package/src/bridge/getAddressWrapper.ts +40 -0
- package/src/bridge/jsHelpers.ts +645 -0
- package/src/cache.ts +65 -0
- package/src/cross.test.ts +112 -0
- package/src/cross.ts +366 -0
- package/src/currencies/BigNumberToLocaleString.test.ts +155 -0
- package/src/currencies/BigNumberToLocaleString.ts +80 -0
- package/src/currencies/CurrencyURIScheme.ts +114 -0
- package/src/currencies/chopCurrencyUnitDecimals.ts +34 -0
- package/src/currencies/formatCurrencyUnit.ts +167 -0
- package/src/currencies/formatShort.ts +24 -0
- package/src/currencies/index.ts +78 -0
- package/src/currencies/localeUtility.ts +50 -0
- package/src/currencies/parseCurrencyUnit.ts +16 -0
- package/src/currencies/sanitizeValueString.ts +58 -0
- package/src/currencies/support.ts +107 -0
- package/src/currencies/valueFromUnit.ts +10 -0
- package/src/derivation.ts +595 -0
- package/src/env.ts +790 -0
- package/src/errors.test.ts +21 -0
- package/src/errors.ts +9 -0
- package/src/mocks/account.ts +476 -0
- package/src/mocks/fixtures/nfts.test.ts +25 -0
- package/src/mocks/fixtures/nfts.ts +432 -0
- package/src/mocks/helpers.ts +38 -0
- package/src/network.ts +135 -0
- package/src/nft/nftId.ts +26 -0
- package/src/operation.ts +212 -0
- package/src/promise.test.ts +20 -0
- package/src/promise.ts +101 -0
- package/src/rangeDates.test.ts +66 -0
- package/src/rangeDates.ts +96 -0
- package/src/test-helpers/staticTime.ts +4 -0
- package/src/transaction/common.ts +157 -0
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
import isEqual from "lodash/isEqual";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import { Observable, Observer, from } from "rxjs";
|
|
4
|
+
import { log } from "@ledgerhq/logs";
|
|
5
|
+
import { WrongDeviceForAccount } from "@ledgerhq/errors";
|
|
6
|
+
import Transport from "@ledgerhq/hw-transport";
|
|
7
|
+
import {
|
|
8
|
+
getSeedIdentifierDerivation,
|
|
9
|
+
getDerivationModesForCurrency,
|
|
10
|
+
getDerivationScheme,
|
|
11
|
+
runDerivationScheme,
|
|
12
|
+
isIterableDerivationMode,
|
|
13
|
+
derivationModeSupportsIndex,
|
|
14
|
+
getMandatoryEmptyAccountSkip,
|
|
15
|
+
getDerivationModeStartsAt,
|
|
16
|
+
DerivationMode,
|
|
17
|
+
} from "../derivation";
|
|
18
|
+
import {
|
|
19
|
+
getAccountPlaceholderName,
|
|
20
|
+
getNewAccountPlaceholderName,
|
|
21
|
+
shouldRetainPendingOperation,
|
|
22
|
+
isAccountEmpty,
|
|
23
|
+
shouldShowNewAccount,
|
|
24
|
+
clearAccount,
|
|
25
|
+
emptyHistoryCache,
|
|
26
|
+
generateHistoryFromOperations,
|
|
27
|
+
recalculateAccountBalanceHistories,
|
|
28
|
+
encodeAccountId,
|
|
29
|
+
} from "../account";
|
|
30
|
+
import { FreshAddressIndexInvalid, UnsupportedDerivation } from "../errors";
|
|
31
|
+
import getAddressWrapper, { Resolver } from "./getAddressWrapper";
|
|
32
|
+
import type { Result } from "../derivation";
|
|
33
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
34
|
+
import type {
|
|
35
|
+
Account,
|
|
36
|
+
AccountBridge,
|
|
37
|
+
Address,
|
|
38
|
+
CurrencyBridge,
|
|
39
|
+
Operation,
|
|
40
|
+
ProtoNFT,
|
|
41
|
+
ScanAccountEvent,
|
|
42
|
+
SyncConfig,
|
|
43
|
+
} from "@ledgerhq/types-live";
|
|
44
|
+
|
|
45
|
+
// Customize the way to iterate on the keychain derivation
|
|
46
|
+
type IterateResult = ({
|
|
47
|
+
transport,
|
|
48
|
+
index,
|
|
49
|
+
derivationsCache,
|
|
50
|
+
derivationScheme,
|
|
51
|
+
derivationMode,
|
|
52
|
+
currency,
|
|
53
|
+
}: {
|
|
54
|
+
transport: Transport;
|
|
55
|
+
index: number;
|
|
56
|
+
derivationsCache: Record<string, Result>;
|
|
57
|
+
derivationScheme: string;
|
|
58
|
+
derivationMode: DerivationMode;
|
|
59
|
+
currency: CryptoCurrency;
|
|
60
|
+
}) => Promise<Result | null>;
|
|
61
|
+
|
|
62
|
+
export type IterateResultBuilder = ({
|
|
63
|
+
result, // derivation on the "root" of the derivation
|
|
64
|
+
derivationMode, // identify the current derivation scheme
|
|
65
|
+
derivationScheme,
|
|
66
|
+
}: {
|
|
67
|
+
result: Result;
|
|
68
|
+
derivationMode: DerivationMode;
|
|
69
|
+
derivationScheme: string;
|
|
70
|
+
}) => Promise<IterateResult>;
|
|
71
|
+
|
|
72
|
+
export type AccountShapeInfo = {
|
|
73
|
+
currency: CryptoCurrency;
|
|
74
|
+
address: string;
|
|
75
|
+
index: number;
|
|
76
|
+
initialAccount?: Account;
|
|
77
|
+
derivationPath: string;
|
|
78
|
+
derivationMode: DerivationMode;
|
|
79
|
+
transport?: Transport;
|
|
80
|
+
rest?: any;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type GetAccountShape = (
|
|
84
|
+
arg0: AccountShapeInfo,
|
|
85
|
+
arg1: SyncConfig
|
|
86
|
+
) => Promise<Partial<Account>>;
|
|
87
|
+
type AccountUpdater = (arg0: Account) => Account;
|
|
88
|
+
|
|
89
|
+
// compare that two dates are roughly the same date in order to update the case it would have drastically changed
|
|
90
|
+
const sameDate = (a: Date, b: Date) =>
|
|
91
|
+
Math.abs(a.getTime() - b.getTime()) < 1000 * 60 * 30;
|
|
92
|
+
|
|
93
|
+
// an operation is relatively immutable, however we saw that sometimes it can temporarily change due to reorg,..
|
|
94
|
+
export const sameOp = (a: Operation, b: Operation): boolean =>
|
|
95
|
+
a === b ||
|
|
96
|
+
(a.id === b.id && // hash, accountId, type are in id
|
|
97
|
+
(a.fee ? a.fee.isEqualTo(b.fee) : a.fee === b.fee) &&
|
|
98
|
+
(a.value ? a.value.isEqualTo(b.value) : a.value === b.value) &&
|
|
99
|
+
a.nftOperations?.length === b.nftOperations?.length &&
|
|
100
|
+
sameDate(a.date, b.date) &&
|
|
101
|
+
a.blockHeight === b.blockHeight &&
|
|
102
|
+
isEqual(a.senders, b.senders) &&
|
|
103
|
+
isEqual(a.recipients, b.recipients));
|
|
104
|
+
// efficiently prepend newFetched operations to existing operations
|
|
105
|
+
export function mergeOps( // existing operations. sorted (newer to older). deduped.
|
|
106
|
+
existing: Operation[], // new fetched operations. not sorted. not deduped. time is allowed to overlap inside existing.
|
|
107
|
+
newFetched: Operation[]
|
|
108
|
+
): // return a list of operations, deduped and sorted from newer to older
|
|
109
|
+
Operation[] {
|
|
110
|
+
// there is new fetched
|
|
111
|
+
if (newFetched.length === 0) return existing;
|
|
112
|
+
// efficient lookup map of id.
|
|
113
|
+
const existingIds: Record<string, Operation> = {};
|
|
114
|
+
|
|
115
|
+
for (const o of existing) {
|
|
116
|
+
existingIds[o.id] = o;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// only keep the newFetched that are not in existing. this array will be mutated
|
|
120
|
+
let newOps = newFetched
|
|
121
|
+
.filter((o) => !existingIds[o.id] || !sameOp(existingIds[o.id], o))
|
|
122
|
+
.sort((a, b) => b.date.valueOf() - a.date.valueOf());
|
|
123
|
+
|
|
124
|
+
// Deduplicate new ops to guarantee operations don't have dups
|
|
125
|
+
const newOpsIds: Record<string, Operation> = {};
|
|
126
|
+
newOps.forEach((op) => {
|
|
127
|
+
newOpsIds[op.id] = op;
|
|
128
|
+
});
|
|
129
|
+
newOps = Object.values(newOpsIds);
|
|
130
|
+
|
|
131
|
+
// return existing when there is no real new operations
|
|
132
|
+
if (newOps.length === 0) return existing;
|
|
133
|
+
// edge case, existing can be empty. return the sorted list.
|
|
134
|
+
if (existing.length === 0) return newOps;
|
|
135
|
+
// building up merging the ops
|
|
136
|
+
const all: Operation[] = [];
|
|
137
|
+
|
|
138
|
+
for (const o of existing) {
|
|
139
|
+
// prepend all the new ops that have higher date
|
|
140
|
+
while (newOps.length > 0 && newOps[0].date >= o.date) {
|
|
141
|
+
all.push(newOps.shift() as Operation);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!newOpsIds[o.id]) {
|
|
145
|
+
all.push(o);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return all;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const mergeNfts = (
|
|
153
|
+
oldNfts: ProtoNFT[],
|
|
154
|
+
newNfts: ProtoNFT[]
|
|
155
|
+
): ProtoNFT[] => {
|
|
156
|
+
// Getting a map of id => NFT
|
|
157
|
+
const newNftsPerId: Record<string, ProtoNFT> = {};
|
|
158
|
+
newNfts.forEach((n) => {
|
|
159
|
+
newNftsPerId[n.id] = n;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// copying the argument to avoid mutating it
|
|
163
|
+
const nfts = oldNfts.slice();
|
|
164
|
+
for (let i = 0; i < nfts.length; i++) {
|
|
165
|
+
const nft = nfts[i];
|
|
166
|
+
|
|
167
|
+
// The NFTs are the same, do don't anything
|
|
168
|
+
if (!newNftsPerId[nft.id]) {
|
|
169
|
+
nfts.splice(i, 1);
|
|
170
|
+
i--;
|
|
171
|
+
} else if (!isEqual(nft, newNftsPerId[nft.id])) {
|
|
172
|
+
// Use the new NFT instead
|
|
173
|
+
nfts[i] = newNftsPerId[nft.id];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Delete it from the newNfts to keep only the un-added ones at the end
|
|
177
|
+
delete newNftsPerId[nft.id];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Prepending newNfts to respect nfts's newest to oldest order
|
|
181
|
+
return Object.values(newNftsPerId).concat(nfts);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export const makeSync =
|
|
185
|
+
({
|
|
186
|
+
getAccountShape,
|
|
187
|
+
postSync = (_, a) => a,
|
|
188
|
+
shouldMergeOps = true,
|
|
189
|
+
}: {
|
|
190
|
+
getAccountShape: GetAccountShape;
|
|
191
|
+
postSync?: (initial: Account, synced: Account) => Account;
|
|
192
|
+
shouldMergeOps?: boolean;
|
|
193
|
+
}): AccountBridge<any>["sync"] =>
|
|
194
|
+
(initial, syncConfig): Observable<AccountUpdater> =>
|
|
195
|
+
Observable.create((o: Observer<(acc: Account) => Account>) => {
|
|
196
|
+
async function main() {
|
|
197
|
+
const accountId = encodeAccountId({
|
|
198
|
+
type: "js",
|
|
199
|
+
version: "2",
|
|
200
|
+
currencyId: initial.currency.id,
|
|
201
|
+
xpubOrAddress: initial.xpub || initial.freshAddress,
|
|
202
|
+
derivationMode: initial.derivationMode,
|
|
203
|
+
});
|
|
204
|
+
const needClear = initial.id !== accountId;
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
const freshAddressPath = getSeedIdentifierDerivation(
|
|
208
|
+
initial.currency,
|
|
209
|
+
initial.derivationMode as DerivationMode
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const shape = await getAccountShape(
|
|
213
|
+
{
|
|
214
|
+
currency: initial.currency,
|
|
215
|
+
index: initial.index,
|
|
216
|
+
address: initial.freshAddress,
|
|
217
|
+
derivationPath: freshAddressPath,
|
|
218
|
+
derivationMode: initial.derivationMode as DerivationMode,
|
|
219
|
+
initialAccount: needClear ? clearAccount(initial) : initial,
|
|
220
|
+
},
|
|
221
|
+
syncConfig
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const updater = (acc: Account): Account => {
|
|
225
|
+
let a = acc; // a is a immutable version of Account, based on acc
|
|
226
|
+
|
|
227
|
+
if (needClear) {
|
|
228
|
+
a = clearAccount(acc);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// FIXME reconsider doing mergeOps here. work is redundant for impl like eth
|
|
232
|
+
const operations = shouldMergeOps
|
|
233
|
+
? mergeOps(a.operations, shape.operations || [])
|
|
234
|
+
: shape.operations || [];
|
|
235
|
+
|
|
236
|
+
a = postSync(a, {
|
|
237
|
+
...a,
|
|
238
|
+
id: accountId,
|
|
239
|
+
spendableBalance: shape.balance || a.balance,
|
|
240
|
+
operationsCount: shape.operationsCount || operations.length,
|
|
241
|
+
lastSyncDate: new Date(),
|
|
242
|
+
creationDate:
|
|
243
|
+
operations.length > 0
|
|
244
|
+
? operations[operations.length - 1].date
|
|
245
|
+
: new Date(),
|
|
246
|
+
...shape,
|
|
247
|
+
operations,
|
|
248
|
+
pendingOperations: a.pendingOperations.filter((op) =>
|
|
249
|
+
shouldRetainPendingOperation(a, op)
|
|
250
|
+
),
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
a = recalculateAccountBalanceHistories(a, acc);
|
|
254
|
+
|
|
255
|
+
if (!a.used) {
|
|
256
|
+
a.used = !isAccountEmpty(a);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return a;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
o.next(updater);
|
|
263
|
+
o.complete();
|
|
264
|
+
} catch (e) {
|
|
265
|
+
o.error(e);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
main();
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// Use for withDevice
|
|
273
|
+
export type DeviceCommunication = (
|
|
274
|
+
deviceId: string
|
|
275
|
+
) => <T>(job: (transport: Transport) => Observable<T>) => Observable<T>;
|
|
276
|
+
|
|
277
|
+
const defaultIterateResultBuilder = (getAddressFn: Resolver) => () =>
|
|
278
|
+
Promise.resolve(
|
|
279
|
+
async ({
|
|
280
|
+
transport,
|
|
281
|
+
index,
|
|
282
|
+
derivationsCache,
|
|
283
|
+
derivationScheme,
|
|
284
|
+
derivationMode,
|
|
285
|
+
currency,
|
|
286
|
+
}: {
|
|
287
|
+
transport: Transport;
|
|
288
|
+
index: number | string;
|
|
289
|
+
derivationsCache: Record<string, Result>;
|
|
290
|
+
derivationScheme: string;
|
|
291
|
+
derivationMode: DerivationMode;
|
|
292
|
+
currency: CryptoCurrency;
|
|
293
|
+
}): Promise<Result | null> => {
|
|
294
|
+
const freshAddressPath = runDerivationScheme(derivationScheme, currency, {
|
|
295
|
+
account: index,
|
|
296
|
+
});
|
|
297
|
+
let res = derivationsCache[freshAddressPath];
|
|
298
|
+
if (!res) {
|
|
299
|
+
res = await getAddressWrapper(getAddressFn!)(transport, {
|
|
300
|
+
currency,
|
|
301
|
+
path: freshAddressPath,
|
|
302
|
+
derivationMode,
|
|
303
|
+
});
|
|
304
|
+
derivationsCache[freshAddressPath] = res;
|
|
305
|
+
}
|
|
306
|
+
return res as Result;
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
export const makeScanAccounts =
|
|
311
|
+
({
|
|
312
|
+
getAccountShape,
|
|
313
|
+
deviceCommunication,
|
|
314
|
+
buildIterateResult,
|
|
315
|
+
getAddressFn,
|
|
316
|
+
}: {
|
|
317
|
+
getAccountShape: GetAccountShape;
|
|
318
|
+
deviceCommunication: DeviceCommunication;
|
|
319
|
+
buildIterateResult?: IterateResultBuilder;
|
|
320
|
+
getAddressFn: Resolver;
|
|
321
|
+
}): CurrencyBridge["scanAccounts"] =>
|
|
322
|
+
({ currency, deviceId, syncConfig }): Observable<ScanAccountEvent> =>
|
|
323
|
+
deviceCommunication(deviceId)((transport) =>
|
|
324
|
+
Observable.create(
|
|
325
|
+
(o: Observer<{ type: "discovered"; account: Account }>) => {
|
|
326
|
+
let finished = false;
|
|
327
|
+
|
|
328
|
+
const unsubscribe = () => {
|
|
329
|
+
finished = true;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
const derivationsCache: Record<string, Result> = {};
|
|
333
|
+
|
|
334
|
+
async function stepAccount(
|
|
335
|
+
index: number,
|
|
336
|
+
res: Result,
|
|
337
|
+
derivationMode: DerivationMode,
|
|
338
|
+
seedIdentifier: string,
|
|
339
|
+
transport: Transport
|
|
340
|
+
): Promise<Account | null | undefined> {
|
|
341
|
+
if (finished) return;
|
|
342
|
+
|
|
343
|
+
const { address, path: freshAddressPath, ...rest } = res;
|
|
344
|
+
|
|
345
|
+
const accountShape: Partial<Account> = await getAccountShape(
|
|
346
|
+
{
|
|
347
|
+
transport,
|
|
348
|
+
currency,
|
|
349
|
+
index,
|
|
350
|
+
address,
|
|
351
|
+
derivationPath: freshAddressPath,
|
|
352
|
+
derivationMode,
|
|
353
|
+
rest,
|
|
354
|
+
},
|
|
355
|
+
syncConfig
|
|
356
|
+
);
|
|
357
|
+
if (finished) return;
|
|
358
|
+
|
|
359
|
+
const freshAddress = address;
|
|
360
|
+
const operations = accountShape.operations || [];
|
|
361
|
+
const operationsCount =
|
|
362
|
+
accountShape.operationsCount || operations.length;
|
|
363
|
+
const creationDate =
|
|
364
|
+
operations.length > 0
|
|
365
|
+
? operations[operations.length - 1].date
|
|
366
|
+
: new Date();
|
|
367
|
+
const balance = accountShape.balance || new BigNumber(0);
|
|
368
|
+
const spendableBalance =
|
|
369
|
+
accountShape.spendableBalance || new BigNumber(0);
|
|
370
|
+
if (!accountShape.id)
|
|
371
|
+
throw new Error("account ID must be provided");
|
|
372
|
+
if (balance.isNaN()) throw new Error("invalid balance NaN");
|
|
373
|
+
const initialAccount: Account = {
|
|
374
|
+
type: "Account",
|
|
375
|
+
id: accountShape.id,
|
|
376
|
+
seedIdentifier,
|
|
377
|
+
freshAddress,
|
|
378
|
+
freshAddressPath,
|
|
379
|
+
freshAddresses: [
|
|
380
|
+
{
|
|
381
|
+
address: freshAddress,
|
|
382
|
+
derivationPath: freshAddressPath,
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
derivationMode,
|
|
386
|
+
name: "",
|
|
387
|
+
starred: false,
|
|
388
|
+
used: false,
|
|
389
|
+
index,
|
|
390
|
+
currency,
|
|
391
|
+
operationsCount,
|
|
392
|
+
operations: [],
|
|
393
|
+
swapHistory: [],
|
|
394
|
+
pendingOperations: [],
|
|
395
|
+
unit: currency.units[0],
|
|
396
|
+
lastSyncDate: new Date(),
|
|
397
|
+
creationDate,
|
|
398
|
+
// overrides
|
|
399
|
+
balance,
|
|
400
|
+
spendableBalance,
|
|
401
|
+
blockHeight: 0,
|
|
402
|
+
balanceHistoryCache: emptyHistoryCache,
|
|
403
|
+
};
|
|
404
|
+
const account = { ...initialAccount, ...accountShape };
|
|
405
|
+
|
|
406
|
+
if (account.balanceHistoryCache === emptyHistoryCache) {
|
|
407
|
+
account.balanceHistoryCache =
|
|
408
|
+
generateHistoryFromOperations(account);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (!account.used) {
|
|
412
|
+
account.used = !isAccountEmpty(account);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Bitcoin needs to compute the freshAddressPath itself,
|
|
416
|
+
// so we update it afterwards
|
|
417
|
+
if (account?.freshAddressPath) {
|
|
418
|
+
res.address = account.freshAddress;
|
|
419
|
+
derivationsCache[account.freshAddressPath] = res;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
log("scanAccounts", "derivationsCache", res);
|
|
423
|
+
|
|
424
|
+
log(
|
|
425
|
+
"scanAccounts",
|
|
426
|
+
`scanning ${currency.id} at ${freshAddressPath}: ${
|
|
427
|
+
res.address
|
|
428
|
+
} resulted of ${
|
|
429
|
+
account
|
|
430
|
+
? `Account with ${account.operations.length} txs`
|
|
431
|
+
: "no account"
|
|
432
|
+
}`
|
|
433
|
+
);
|
|
434
|
+
if (!account) return;
|
|
435
|
+
account.name = !account.used
|
|
436
|
+
? getNewAccountPlaceholderName({
|
|
437
|
+
currency,
|
|
438
|
+
index,
|
|
439
|
+
derivationMode,
|
|
440
|
+
})
|
|
441
|
+
: getAccountPlaceholderName({
|
|
442
|
+
currency,
|
|
443
|
+
index,
|
|
444
|
+
derivationMode,
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
const showNewAccount = shouldShowNewAccount(
|
|
448
|
+
currency,
|
|
449
|
+
derivationMode
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
if (account.used || showNewAccount) {
|
|
453
|
+
log(
|
|
454
|
+
"debug",
|
|
455
|
+
`Emit 'discovered' event for a new account found. AccountUsed: ${account.used} - showNewAccount: ${showNewAccount}`
|
|
456
|
+
);
|
|
457
|
+
o.next({
|
|
458
|
+
type: "discovered",
|
|
459
|
+
account,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return account;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (buildIterateResult === undefined) {
|
|
467
|
+
buildIterateResult = defaultIterateResultBuilder(getAddressFn);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
async function main() {
|
|
471
|
+
try {
|
|
472
|
+
const derivationModes = getDerivationModesForCurrency(currency);
|
|
473
|
+
|
|
474
|
+
for (const derivationMode of derivationModes) {
|
|
475
|
+
if (finished) break;
|
|
476
|
+
const path = getSeedIdentifierDerivation(
|
|
477
|
+
currency,
|
|
478
|
+
derivationMode
|
|
479
|
+
);
|
|
480
|
+
log(
|
|
481
|
+
"scanAccounts",
|
|
482
|
+
`scanning ${currency.id} on derivationMode=${derivationMode}`
|
|
483
|
+
);
|
|
484
|
+
let result: Result = derivationsCache[path];
|
|
485
|
+
|
|
486
|
+
if (!result) {
|
|
487
|
+
try {
|
|
488
|
+
result = await getAddressFn(transport, {
|
|
489
|
+
currency,
|
|
490
|
+
path,
|
|
491
|
+
derivationMode,
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
derivationsCache[path] = result;
|
|
495
|
+
} catch (e) {
|
|
496
|
+
if (e instanceof UnsupportedDerivation) {
|
|
497
|
+
log(
|
|
498
|
+
"scanAccounts",
|
|
499
|
+
"ignore derivationMode=" + derivationMode
|
|
500
|
+
);
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
throw e;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (!result) continue;
|
|
508
|
+
const seedIdentifier = result.publicKey;
|
|
509
|
+
let emptyCount = 0;
|
|
510
|
+
const mandatoryEmptyAccountSkip =
|
|
511
|
+
getMandatoryEmptyAccountSkip(derivationMode);
|
|
512
|
+
const derivationScheme = getDerivationScheme({
|
|
513
|
+
derivationMode,
|
|
514
|
+
currency,
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
const stopAt = isIterableDerivationMode(derivationMode)
|
|
518
|
+
? 255
|
|
519
|
+
: 1;
|
|
520
|
+
const startsAt = getDerivationModeStartsAt(derivationMode);
|
|
521
|
+
|
|
522
|
+
log(
|
|
523
|
+
"debug",
|
|
524
|
+
`start scanning account process. MandatoryEmptyAccountSkip ${mandatoryEmptyAccountSkip} / StartsAt: ${startsAt} - StopAt: ${stopAt}`
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
const iterateResult = await buildIterateResult!({
|
|
528
|
+
result,
|
|
529
|
+
derivationMode,
|
|
530
|
+
derivationScheme,
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
for (let index = startsAt; index < stopAt; index++) {
|
|
534
|
+
log("debug", `start to scan a new account. Index: ${index}`);
|
|
535
|
+
|
|
536
|
+
if (finished) {
|
|
537
|
+
log(
|
|
538
|
+
"debug",
|
|
539
|
+
`new account scanning process has been finished`
|
|
540
|
+
);
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (!derivationModeSupportsIndex(derivationMode, index))
|
|
545
|
+
continue;
|
|
546
|
+
|
|
547
|
+
const res = await iterateResult({
|
|
548
|
+
transport,
|
|
549
|
+
index,
|
|
550
|
+
derivationsCache,
|
|
551
|
+
derivationMode,
|
|
552
|
+
derivationScheme,
|
|
553
|
+
currency,
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
if (!res) break;
|
|
557
|
+
|
|
558
|
+
const account = await stepAccount(
|
|
559
|
+
index,
|
|
560
|
+
res,
|
|
561
|
+
derivationMode,
|
|
562
|
+
seedIdentifier,
|
|
563
|
+
transport
|
|
564
|
+
);
|
|
565
|
+
|
|
566
|
+
if (account && !account.used) {
|
|
567
|
+
if (emptyCount >= mandatoryEmptyAccountSkip) break;
|
|
568
|
+
emptyCount++;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
o.complete();
|
|
574
|
+
} catch (e) {
|
|
575
|
+
o.error(e);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
main();
|
|
580
|
+
return unsubscribe;
|
|
581
|
+
}
|
|
582
|
+
)
|
|
583
|
+
);
|
|
584
|
+
export function makeAccountBridgeReceive(
|
|
585
|
+
getAddressFn: Resolver,
|
|
586
|
+
deviceCommunication: DeviceCommunication,
|
|
587
|
+
{
|
|
588
|
+
injectGetAddressParams,
|
|
589
|
+
}: {
|
|
590
|
+
injectGetAddressParams?: (account: Account) => any;
|
|
591
|
+
} = {}
|
|
592
|
+
): (
|
|
593
|
+
account: Account,
|
|
594
|
+
option: {
|
|
595
|
+
verify?: boolean;
|
|
596
|
+
deviceId: string;
|
|
597
|
+
subAccountId?: string;
|
|
598
|
+
freshAddressIndex?: number;
|
|
599
|
+
}
|
|
600
|
+
) => Observable<{
|
|
601
|
+
address: string;
|
|
602
|
+
path: string;
|
|
603
|
+
}> {
|
|
604
|
+
return (account, { verify, deviceId, freshAddressIndex }) => {
|
|
605
|
+
let freshAddress: Address | undefined;
|
|
606
|
+
|
|
607
|
+
if (freshAddressIndex !== undefined && freshAddressIndex !== null) {
|
|
608
|
+
freshAddress = account.freshAddresses[freshAddressIndex];
|
|
609
|
+
|
|
610
|
+
if (freshAddress === undefined) {
|
|
611
|
+
throw new FreshAddressIndexInvalid();
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const arg = {
|
|
616
|
+
verify,
|
|
617
|
+
currency: account.currency,
|
|
618
|
+
derivationMode: account.derivationMode,
|
|
619
|
+
path: freshAddress
|
|
620
|
+
? freshAddress.derivationPath
|
|
621
|
+
: account.freshAddressPath,
|
|
622
|
+
...(injectGetAddressParams && injectGetAddressParams(account)),
|
|
623
|
+
};
|
|
624
|
+
return deviceCommunication(deviceId)((transport: Transport) =>
|
|
625
|
+
from(
|
|
626
|
+
getAddressFn(transport, arg).then((r) => {
|
|
627
|
+
const accountAddress = freshAddress
|
|
628
|
+
? freshAddress.address
|
|
629
|
+
: account.freshAddress;
|
|
630
|
+
|
|
631
|
+
if (r.address !== accountAddress) {
|
|
632
|
+
throw new WrongDeviceForAccount(
|
|
633
|
+
`WrongDeviceForAccount ${account.name}`,
|
|
634
|
+
{
|
|
635
|
+
accountName: account.name,
|
|
636
|
+
}
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
return r;
|
|
641
|
+
})
|
|
642
|
+
)
|
|
643
|
+
);
|
|
644
|
+
};
|
|
645
|
+
}
|
package/src/cache.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import LRU from "lru-cache";
|
|
2
|
+
export type CacheRes<A extends Array<any>, T> = {
|
|
3
|
+
(...args: A): Promise<T>;
|
|
4
|
+
force: (...args: A) => Promise<T>;
|
|
5
|
+
hydrate: (arg0: string, arg1: T) => void;
|
|
6
|
+
clear: (arg0: string) => void;
|
|
7
|
+
reset: () => void;
|
|
8
|
+
};
|
|
9
|
+
export const makeLRUCache = <A extends Array<any>, T>(
|
|
10
|
+
f: (...args: A) => Promise<T>,
|
|
11
|
+
keyExtractor: (...args: A) => string = () => "",
|
|
12
|
+
lruOpts: LRU.Options<string, any> = {
|
|
13
|
+
max: 100,
|
|
14
|
+
ttl: 5 * 60 * 1000,
|
|
15
|
+
}
|
|
16
|
+
): CacheRes<A, T> => {
|
|
17
|
+
// LRU-Cache is written in JS and do not enforce in its code the type checking.
|
|
18
|
+
// Regarding its [documentation](https://github.com/isaacs/node-lru-cache/#ttl), `max` or `ttlAutopurge` must be set.
|
|
19
|
+
// As the code in live use sometimes `max` property with `ttl`, we check it's defined in `lruOpts` to add or not `ttlAutopurge`.
|
|
20
|
+
// eslint-disable-next-line
|
|
21
|
+
// @ts-ignore: TS-2339
|
|
22
|
+
lruOpts = lruOpts.max
|
|
23
|
+
? lruOpts
|
|
24
|
+
: {
|
|
25
|
+
...lruOpts,
|
|
26
|
+
ttlAutopurge: true,
|
|
27
|
+
};
|
|
28
|
+
const cache = new LRU(lruOpts);
|
|
29
|
+
|
|
30
|
+
const result = (...args: A) => {
|
|
31
|
+
const key = keyExtractor(...args);
|
|
32
|
+
let promise = cache.get(key);
|
|
33
|
+
if (promise) return promise;
|
|
34
|
+
promise = f(...args).catch((e) => {
|
|
35
|
+
cache.del(key);
|
|
36
|
+
throw e;
|
|
37
|
+
});
|
|
38
|
+
cache.set(key, promise);
|
|
39
|
+
return promise;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
result.force = (...args: A) => {
|
|
43
|
+
const key = keyExtractor(...args);
|
|
44
|
+
const promise = f(...args).catch((e) => {
|
|
45
|
+
cache.del(key);
|
|
46
|
+
throw e;
|
|
47
|
+
});
|
|
48
|
+
cache.set(key, promise);
|
|
49
|
+
return promise;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
result.hydrate = (key: string, value: T) => {
|
|
53
|
+
cache.set(key, Promise.resolve(value));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
result.clear = (key: string) => {
|
|
57
|
+
cache.del(key);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
result.reset = () => {
|
|
61
|
+
cache.reset();
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return result;
|
|
65
|
+
};
|