@ledgerhq/coin-multiversx 0.2.0-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/.eslintrc.js +23 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +31 -0
- package/CHANGELOG.md +400 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/api/apiCalls.d.ts +22 -0
- package/lib/api/apiCalls.d.ts.map +1 -0
- package/lib/api/apiCalls.js +153 -0
- package/lib/api/apiCalls.js.map +1 -0
- package/lib/api/dtos/multiversx-account.d.ts +9 -0
- package/lib/api/dtos/multiversx-account.d.ts.map +1 -0
- package/lib/api/dtos/multiversx-account.js +17 -0
- package/lib/api/dtos/multiversx-account.js.map +1 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +16 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/sdk.d.ts +29 -0
- package/lib/api/sdk.d.ts.map +1 -0
- package/lib/api/sdk.js +281 -0
- package/lib/api/sdk.js.map +1 -0
- package/lib/bridge/js.d.ts +11 -0
- package/lib/bridge/js.d.ts.map +1 -0
- package/lib/bridge/js.js +62 -0
- package/lib/bridge/js.js.map +1 -0
- package/lib/bridge.integration.test.d.ts +4 -0
- package/lib/bridge.integration.test.d.ts.map +1 -0
- package/lib/bridge.integration.test.js +142 -0
- package/lib/bridge.integration.test.js.map +1 -0
- package/lib/broadcast.d.ts +9 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +16 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/buildOptimisticOperation.d.ts +4 -0
- package/lib/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/buildOptimisticOperation.js +100 -0
- package/lib/buildOptimisticOperation.js.map +1 -0
- package/lib/buildOptimisticOperation.test.d.ts +2 -0
- package/lib/buildOptimisticOperation.test.d.ts.map +1 -0
- package/lib/buildOptimisticOperation.test.js +78 -0
- package/lib/buildOptimisticOperation.test.js.map +1 -0
- package/lib/buildSubAccounts.d.ts +11 -0
- package/lib/buildSubAccounts.d.ts.map +1 -0
- package/lib/buildSubAccounts.js +117 -0
- package/lib/buildSubAccounts.js.map +1 -0
- package/lib/buildTransaction.d.ts +19 -0
- package/lib/buildTransaction.d.ts.map +1 -0
- package/lib/buildTransaction.js +49 -0
- package/lib/buildTransaction.js.map +1 -0
- package/lib/buildTransaction.unit.test.d.ts +2 -0
- package/lib/buildTransaction.unit.test.d.ts.map +1 -0
- package/lib/buildTransaction.unit.test.js +47 -0
- package/lib/buildTransaction.unit.test.js.map +1 -0
- package/lib/cli-transaction.d.ts +16 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +35 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/config.d.ts +14 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +16 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +21 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +27 -0
- package/lib/constants.js.map +1 -0
- package/lib/createTransaction.d.ts +9 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +26 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/datasets/multiversx1.d.ts +3 -0
- package/lib/datasets/multiversx1.d.ts.map +1 -0
- package/lib/datasets/multiversx1.js +21 -0
- package/lib/datasets/multiversx1.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +10 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +60 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/encode.d.ts +11 -0
- package/lib/encode.d.ts.map +1 -0
- package/lib/encode.js +39 -0
- package/lib/encode.js.map +1 -0
- package/lib/errors.d.ts +16 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +10 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +10 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +35 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/formatters.d.ts +11 -0
- package/lib/formatters.d.ts.map +1 -0
- package/lib/formatters.js +65 -0
- package/lib/formatters.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +5 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +107 -0
- package/lib/getTransactionStatus.js.map +1 -0
- package/lib/helpers/denominate.d.ts +9 -0
- package/lib/helpers/denominate.d.ts.map +1 -0
- package/lib/helpers/denominate.js +75 -0
- package/lib/helpers/denominate.js.map +1 -0
- package/lib/helpers/handleTransactionStatus.d.ts +7 -0
- package/lib/helpers/handleTransactionStatus.d.ts.map +1 -0
- package/lib/helpers/handleTransactionStatus.js +18 -0
- package/lib/helpers/handleTransactionStatus.js.map +1 -0
- package/lib/helpers/hasMinimumDelegableBalance.d.ts +3 -0
- package/lib/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
- package/lib/helpers/hasMinimumDelegableBalance.js +7 -0
- package/lib/helpers/hasMinimumDelegableBalance.js.map +1 -0
- package/lib/helpers/randomizeProviders.d.ts +7 -0
- package/lib/helpers/randomizeProviders.d.ts.map +1 -0
- package/lib/helpers/randomizeProviders.js +12 -0
- package/lib/helpers/randomizeProviders.js.map +1 -0
- package/lib/hw-getAddress.d.ts +6 -0
- package/lib/hw-getAddress.d.ts.map +1 -0
- package/lib/hw-getAddress.js +14 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/logic.d.ts +15 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +77 -0
- package/lib/logic.js.map +1 -0
- package/lib/preload.d.ts +11 -0
- package/lib/preload.d.ts.map +1 -0
- package/lib/preload.js +94 -0
- package/lib/preload.js.map +1 -0
- package/lib/prepareTransaction.d.ts +10 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +72 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/reconciliation.d.ts +3 -0
- package/lib/reconciliation.d.ts.map +1 -0
- package/lib/reconciliation.js +56 -0
- package/lib/reconciliation.js.map +1 -0
- package/lib/serialization.d.ts +9 -0
- package/lib/serialization.d.ts.map +1 -0
- package/lib/serialization.js +65 -0
- package/lib/serialization.js.map +1 -0
- package/lib/signOperation.d.ts +10 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +65 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +16 -0
- package/lib/signer.d.ts.map +1 -0
- package/lib/signer.js +3 -0
- package/lib/signer.js.map +1 -0
- package/lib/specs.d.ts +7 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +286 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +16 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +250 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronisation.d.ts +5 -0
- package/lib/synchronisation.d.ts.map +1 -0
- package/lib/synchronisation.js +69 -0
- package/lib/synchronisation.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +62 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types.d.ts +188 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +17 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/binary.utils.d.ts +5 -0
- package/lib/utils/binary.utils.d.ts.map +1 -0
- package/lib/utils/binary.utils.js +16 -0
- package/lib/utils/binary.utils.js.map +1 -0
- package/lib-es/api/apiCalls.d.ts +22 -0
- package/lib-es/api/apiCalls.d.ts.map +1 -0
- package/lib-es/api/apiCalls.js +147 -0
- package/lib-es/api/apiCalls.js.map +1 -0
- package/lib-es/api/dtos/multiversx-account.d.ts +9 -0
- package/lib-es/api/dtos/multiversx-account.d.ts.map +1 -0
- package/lib-es/api/dtos/multiversx-account.js +13 -0
- package/lib-es/api/dtos/multiversx-account.js.map +1 -0
- package/lib-es/api/index.d.ts +2 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +2 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/sdk.d.ts +29 -0
- package/lib-es/api/sdk.d.ts.map +1 -0
- package/lib-es/api/sdk.js +264 -0
- package/lib-es/api/sdk.js.map +1 -0
- package/lib-es/bridge/js.d.ts +11 -0
- package/lib-es/bridge/js.d.ts.map +1 -0
- package/lib-es/bridge/js.js +53 -0
- package/lib-es/bridge/js.js.map +1 -0
- package/lib-es/bridge.integration.test.d.ts +4 -0
- package/lib-es/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/bridge.integration.test.js +139 -0
- package/lib-es/bridge.integration.test.js.map +1 -0
- package/lib-es/broadcast.d.ts +9 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +12 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/buildOptimisticOperation.d.ts +4 -0
- package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/buildOptimisticOperation.js +93 -0
- package/lib-es/buildOptimisticOperation.js.map +1 -0
- package/lib-es/buildOptimisticOperation.test.d.ts +2 -0
- package/lib-es/buildOptimisticOperation.test.d.ts.map +1 -0
- package/lib-es/buildOptimisticOperation.test.js +73 -0
- package/lib-es/buildOptimisticOperation.test.js.map +1 -0
- package/lib-es/buildSubAccounts.d.ts +11 -0
- package/lib-es/buildSubAccounts.d.ts.map +1 -0
- package/lib-es/buildSubAccounts.js +112 -0
- package/lib-es/buildSubAccounts.js.map +1 -0
- package/lib-es/buildTransaction.d.ts +19 -0
- package/lib-es/buildTransaction.d.ts.map +1 -0
- package/lib-es/buildTransaction.js +44 -0
- package/lib-es/buildTransaction.js.map +1 -0
- package/lib-es/buildTransaction.unit.test.d.ts +2 -0
- package/lib-es/buildTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/buildTransaction.unit.test.js +42 -0
- package/lib-es/buildTransaction.unit.test.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +16 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +29 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/config.d.ts +14 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +11 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +21 -0
- package/lib-es/constants.d.ts.map +1 -0
- package/lib-es/constants.js +21 -0
- package/lib-es/constants.js.map +1 -0
- package/lib-es/createTransaction.d.ts +9 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +19 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/datasets/multiversx1.d.ts +3 -0
- package/lib-es/datasets/multiversx1.d.ts.map +1 -0
- package/lib-es/datasets/multiversx1.js +18 -0
- package/lib-es/datasets/multiversx1.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +10 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +55 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/encode.d.ts +11 -0
- package/lib-es/encode.d.ts.map +1 -0
- package/lib-es/encode.js +35 -0
- package/lib-es/encode.js.map +1 -0
- package/lib-es/errors.d.ts +16 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +7 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +10 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +31 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/formatters.d.ts +11 -0
- package/lib-es/formatters.d.ts.map +1 -0
- package/lib-es/formatters.js +60 -0
- package/lib-es/formatters.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +5 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +100 -0
- package/lib-es/getTransactionStatus.js.map +1 -0
- package/lib-es/helpers/denominate.d.ts +9 -0
- package/lib-es/helpers/denominate.d.ts.map +1 -0
- package/lib-es/helpers/denominate.js +71 -0
- package/lib-es/helpers/denominate.js.map +1 -0
- package/lib-es/helpers/handleTransactionStatus.d.ts +7 -0
- package/lib-es/helpers/handleTransactionStatus.d.ts.map +1 -0
- package/lib-es/helpers/handleTransactionStatus.js +14 -0
- package/lib-es/helpers/handleTransactionStatus.js.map +1 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.d.ts +3 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.js +3 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.js.map +1 -0
- package/lib-es/helpers/randomizeProviders.d.ts +7 -0
- package/lib-es/helpers/randomizeProviders.d.ts.map +1 -0
- package/lib-es/helpers/randomizeProviders.js +8 -0
- package/lib-es/helpers/randomizeProviders.js.map +1 -0
- package/lib-es/hw-getAddress.d.ts +6 -0
- package/lib-es/hw-getAddress.d.ts.map +1 -0
- package/lib-es/hw-getAddress.js +12 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/logic.d.ts +15 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +65 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/preload.d.ts +11 -0
- package/lib-es/preload.d.ts.map +1 -0
- package/lib-es/preload.js +85 -0
- package/lib-es/preload.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +10 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +68 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/reconciliation.d.ts +3 -0
- package/lib-es/reconciliation.d.ts.map +1 -0
- package/lib-es/reconciliation.js +52 -0
- package/lib-es/reconciliation.js.map +1 -0
- package/lib-es/serialization.d.ts +9 -0
- package/lib-es/serialization.d.ts.map +1 -0
- package/lib-es/serialization.js +53 -0
- package/lib-es/serialization.js.map +1 -0
- package/lib-es/signOperation.d.ts +10 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +61 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +16 -0
- package/lib-es/signer.d.ts.map +1 -0
- package/lib-es/signer.js +2 -0
- package/lib-es/signer.js.map +1 -0
- package/lib-es/specs.d.ts +7 -0
- package/lib-es/specs.d.ts.map +1 -0
- package/lib-es/specs.js +281 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +16 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +244 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronisation.d.ts +5 -0
- package/lib-es/synchronisation.d.ts.map +1 -0
- package/lib-es/synchronisation.js +62 -0
- package/lib-es/synchronisation.js.map +1 -0
- package/lib-es/transaction.d.ts +15 -0
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/transaction.js +56 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types.d.ts +188 -0
- package/lib-es/types.d.ts.map +1 -0
- package/lib-es/types.js +12 -0
- package/lib-es/types.js.map +1 -0
- package/lib-es/utils/binary.utils.d.ts +5 -0
- package/lib-es/utils/binary.utils.d.ts.map +1 -0
- package/lib-es/utils/binary.utils.js +12 -0
- package/lib-es/utils/binary.utils.js.map +1 -0
- package/package.json +86 -0
- package/src/__snapshots__/bridge.integration.test.ts.snap +181 -0
- package/src/api/apiCalls.ts +243 -0
- package/src/api/dtos/multiversx-account.ts +20 -0
- package/src/api/index.ts +13 -0
- package/src/api/sdk.ts +368 -0
- package/src/bridge/js.ts +77 -0
- package/src/bridge.integration.test.ts +147 -0
- package/src/broadcast.ts +16 -0
- package/src/buildOptimisticOperation.test.ts +88 -0
- package/src/buildOptimisticOperation.ts +120 -0
- package/src/buildSubAccounts.ts +153 -0
- package/src/buildTransaction.ts +67 -0
- package/src/buildTransaction.unit.test.ts +49 -0
- package/src/cli-transaction.ts +41 -0
- package/src/config.ts +26 -0
- package/src/constants.ts +24 -0
- package/src/createTransaction.ts +21 -0
- package/src/datasets/multiversx1.ts +19 -0
- package/src/deviceTransactionConfig.ts +74 -0
- package/src/encode.ts +46 -0
- package/src/errors.ts +19 -0
- package/src/estimateMaxSpendable.ts +43 -0
- package/src/formatters.ts +76 -0
- package/src/getTransactionStatus.ts +151 -0
- package/src/helpers/denominate.ts +95 -0
- package/src/helpers/handleTransactionStatus.ts +26 -0
- package/src/helpers/hasMinimumDelegableBalance.ts +6 -0
- package/src/helpers/randomizeProviders.ts +20 -0
- package/src/hw-getAddress.ts +19 -0
- package/src/logic.ts +83 -0
- package/src/preload.ts +95 -0
- package/src/prepareTransaction.ts +78 -0
- package/src/reconciliation.ts +64 -0
- package/src/serialization.ts +72 -0
- package/src/signOperation.ts +99 -0
- package/src/signer.ts +21 -0
- package/src/specs.ts +387 -0
- package/src/speculos-deviceActions.ts +269 -0
- package/src/synchronisation.ts +74 -0
- package/src/transaction.ts +76 -0
- package/src/types.ts +235 -0
- package/src/utils/binary.utils.ts +13 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TransactionStatus } from "../types";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Declare the type for the return payload of the transaction status handler.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface handleTransactionStatusType {
|
|
8
|
+
warning: Error | false;
|
|
9
|
+
error: Error | false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Return an object, of the function, with the error and warning keys, as boolean values.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const handleTransactionStatus = (status: TransactionStatus): handleTransactionStatusType => {
|
|
17
|
+
const [[warning], [error]] = [
|
|
18
|
+
Object.keys(status.warnings || {}),
|
|
19
|
+
Object.keys(status.errors || {}),
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
warning: status.warnings[warning],
|
|
24
|
+
error: status.errors[error],
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MultiversXProvider } from "../types";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Declare the type for the extended validator object that has the sort key attached.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface SortedValidatorType {
|
|
8
|
+
provider: MultiversXProvider;
|
|
9
|
+
sort: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Map through the providers, assign a random number, sort by that, then return the original providers' list.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const randomizeProviders = (providers: MultiversXProvider[]) =>
|
|
17
|
+
providers
|
|
18
|
+
.map(provider => ({ provider, sort: Math.random() }))
|
|
19
|
+
.sort((alpha: SortedValidatorType, beta: SortedValidatorType) => alpha.sort - beta.sort)
|
|
20
|
+
.map((item: SortedValidatorType) => item.provider);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
2
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
|
|
4
|
+
import { MultiversXSigner } from "./signer";
|
|
5
|
+
|
|
6
|
+
const resolver = (signerContext: SignerContext<MultiversXSigner>): GetAddressFn => {
|
|
7
|
+
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
|
|
8
|
+
const { address, publicKey } = await signerContext(deviceId, signer =>
|
|
9
|
+
signer.getAddress(path, verify || false),
|
|
10
|
+
);
|
|
11
|
+
return {
|
|
12
|
+
address: address,
|
|
13
|
+
publicKey: publicKey,
|
|
14
|
+
path,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default resolver;
|
package/src/logic.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { decode, fromWords } from "bech32";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
4
|
+
import type { Transaction, MultiversXTransactionMode, MultiversXDelegation } from "./types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The human-readable-part of the bech32 addresses.
|
|
8
|
+
*/
|
|
9
|
+
const HRP = "erd";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The length (in bytes) of a public key (from which a bech32 address can be obtained).
|
|
13
|
+
*/
|
|
14
|
+
const PUBKEY_LENGTH = 32;
|
|
15
|
+
|
|
16
|
+
function fromBech32(value: string): string {
|
|
17
|
+
let decoded;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
decoded = decode(value);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
throw new Error("Erd address can't be created");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const prefix = decoded.prefix;
|
|
26
|
+
if (prefix != HRP) {
|
|
27
|
+
throw new Error("Bad HRP");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const pubkey = Buffer.from(fromWords(decoded.words));
|
|
31
|
+
if (pubkey.length != PUBKEY_LENGTH) {
|
|
32
|
+
throw new Error("Erd address can't be created");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns true if address is a valid bech32
|
|
40
|
+
*
|
|
41
|
+
* @param {string} address
|
|
42
|
+
*/
|
|
43
|
+
export const isValidAddress = (address: string): boolean => {
|
|
44
|
+
try {
|
|
45
|
+
fromBech32(address);
|
|
46
|
+
return true;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const isSelfTransaction = (a: Account, t: Transaction): boolean => {
|
|
53
|
+
return t.recipient === a.freshAddress;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// For some transaction modes the amount doesn't belong to the account's balance
|
|
57
|
+
export const isAmountSpentFromBalance = (mode: MultiversXTransactionMode) => {
|
|
58
|
+
return ["send", "delegate"].includes(mode);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const computeDelegationBalance = (delegations: MultiversXDelegation[]): BigNumber => {
|
|
62
|
+
let totalDelegationBalance = new BigNumber(0);
|
|
63
|
+
|
|
64
|
+
for (const delegation of delegations) {
|
|
65
|
+
let delegationBalance = new BigNumber(delegation.userActiveStake).plus(
|
|
66
|
+
new BigNumber(delegation.claimableRewards),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
for (const undelegation of delegation.userUndelegatedList) {
|
|
70
|
+
delegationBalance = delegationBalance.plus(new BigNumber(undelegation.amount));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
totalDelegationBalance = totalDelegationBalance.plus(delegationBalance);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return totalDelegationBalance;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const addPrefixToken = (tokenId: string) => `multiversx/esdt/${tokenId}`;
|
|
80
|
+
|
|
81
|
+
export const extractTokenId = (tokenId: string) => {
|
|
82
|
+
return tokenId.split("/")[2];
|
|
83
|
+
};
|
package/src/preload.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Observable, Subject } from "rxjs";
|
|
2
|
+
import { log } from "@ledgerhq/logs";
|
|
3
|
+
import type { MultiversXPreloadData, MultiversXProvider } from "./types";
|
|
4
|
+
import { getProviders } from "./api";
|
|
5
|
+
const PRELOAD_MAX_AGE = 30 * 60 * 1000; // 30 minutes
|
|
6
|
+
|
|
7
|
+
let currentPreloadedData: MultiversXPreloadData = {
|
|
8
|
+
validators: [],
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function fromHydrateValidator(validatorRaw: Record<string, any>): MultiversXProvider {
|
|
12
|
+
return {
|
|
13
|
+
contract: validatorRaw.contract,
|
|
14
|
+
owner: validatorRaw.owner,
|
|
15
|
+
serviceFee: validatorRaw.serviceFee,
|
|
16
|
+
maxDelegationCap: validatorRaw.maxDelegationCap,
|
|
17
|
+
initialOwnerFunds: validatorRaw.initialOwnerFunds,
|
|
18
|
+
totalActiveStake: validatorRaw.totalActiveStake,
|
|
19
|
+
totalUnstaked: validatorRaw.totalUnstaked,
|
|
20
|
+
maxDelegateAmountAllowed: validatorRaw.maxDelegateAmountAllowed,
|
|
21
|
+
apr: validatorRaw.apr,
|
|
22
|
+
explorerURL: validatorRaw.explorerURL,
|
|
23
|
+
address: validatorRaw.address,
|
|
24
|
+
aprValue: Number(validatorRaw.aprValue),
|
|
25
|
+
automaticActivation: !!validatorRaw.automaticActivation,
|
|
26
|
+
changeableServiceFee: !!validatorRaw.changeableServiceFee,
|
|
27
|
+
checkCapOnRedelegate: !!validatorRaw.checkCapOnRedelegate,
|
|
28
|
+
createdNonce: Number(validatorRaw.createdNonce),
|
|
29
|
+
featured: !!validatorRaw.featured,
|
|
30
|
+
numNodes: Number(validatorRaw.numNodes),
|
|
31
|
+
numUsers: Number(validatorRaw.numUsers),
|
|
32
|
+
ownerBelowRequiredBalanceThreshold: !!validatorRaw.ownerBelowRequiredBalanceThreshold,
|
|
33
|
+
unBondPeriod: Number(validatorRaw.unBondPeriod),
|
|
34
|
+
withDelegationCap: !!validatorRaw.withDelegationCap,
|
|
35
|
+
disabled: !!validatorRaw.disabled,
|
|
36
|
+
identity: {
|
|
37
|
+
key: validatorRaw.identity.key,
|
|
38
|
+
name: validatorRaw.identity.name,
|
|
39
|
+
avatar: validatorRaw.identity.avatar,
|
|
40
|
+
description: validatorRaw.identity.description,
|
|
41
|
+
location: validatorRaw.identity.location === null ? null : validatorRaw.location,
|
|
42
|
+
twitter: validatorRaw.identity.twitter,
|
|
43
|
+
url: validatorRaw.identity.url,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function fromHydratePreloadData(data: any): MultiversXPreloadData {
|
|
49
|
+
let validators = [];
|
|
50
|
+
|
|
51
|
+
if (typeof data === "object" && data) {
|
|
52
|
+
if (Array.isArray(data.validators)) {
|
|
53
|
+
validators = data.validators.map(fromHydrateValidator);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
validators,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const updates = new Subject<MultiversXPreloadData>();
|
|
63
|
+
export function getCurrentMultiversXPreloadData(): MultiversXPreloadData {
|
|
64
|
+
return currentPreloadedData;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function setMultiversXPreloadData(data: MultiversXPreloadData) {
|
|
68
|
+
if (data === currentPreloadedData) return;
|
|
69
|
+
currentPreloadedData = data;
|
|
70
|
+
updates.next(data);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getMultiversXPreloadDataUpdates(): Observable<MultiversXPreloadData> {
|
|
74
|
+
return updates.asObservable();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const getPreloadStrategy = () => {
|
|
78
|
+
return {
|
|
79
|
+
preloadMaxAge: PRELOAD_MAX_AGE,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const preload = async (): Promise<MultiversXPreloadData> => {
|
|
84
|
+
log("multiversx/preload", "preloading multiversx data...");
|
|
85
|
+
const validators = (await getProviders()) || [];
|
|
86
|
+
return {
|
|
87
|
+
validators,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const hydrate = (data: unknown) => {
|
|
92
|
+
const hydrated = fromHydratePreloadData(data);
|
|
93
|
+
log("multiversx/preload", `hydrated ${hydrated.validators.length} multiversx validators`);
|
|
94
|
+
setMultiversXPreloadData(hydrated);
|
|
95
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type { Transaction } from "./types";
|
|
3
|
+
import { getFees } from "./api";
|
|
4
|
+
import { GAS } from "./constants";
|
|
5
|
+
import { MultiversXEncodeTransaction } from "./encode";
|
|
6
|
+
import { isAmountSpentFromBalance } from "./logic";
|
|
7
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Prepare t before checking status
|
|
11
|
+
*
|
|
12
|
+
* @param {MultiversXAccount} account
|
|
13
|
+
* @param {Transaction} transaction
|
|
14
|
+
*/
|
|
15
|
+
export const prepareTransaction: AccountBridge<Transaction>["prepareTransaction"] = async (
|
|
16
|
+
account,
|
|
17
|
+
transaction,
|
|
18
|
+
) => {
|
|
19
|
+
// What's the point of this extra variable ?
|
|
20
|
+
const preparedTx = transaction;
|
|
21
|
+
|
|
22
|
+
const tokenAccount =
|
|
23
|
+
(transaction.subAccountId &&
|
|
24
|
+
account.subAccounts &&
|
|
25
|
+
account.subAccounts.find(ta => ta.id === transaction.subAccountId)) ||
|
|
26
|
+
null;
|
|
27
|
+
|
|
28
|
+
if (tokenAccount) {
|
|
29
|
+
preparedTx.data = MultiversXEncodeTransaction.ESDTTransfer(transaction, tokenAccount);
|
|
30
|
+
preparedTx.gasLimit = GAS.ESDT_TRANSFER;
|
|
31
|
+
} else {
|
|
32
|
+
switch (transaction.mode) {
|
|
33
|
+
case "delegate":
|
|
34
|
+
preparedTx.gasLimit = GAS.DELEGATE;
|
|
35
|
+
preparedTx.data = MultiversXEncodeTransaction.delegate();
|
|
36
|
+
break;
|
|
37
|
+
case "claimRewards":
|
|
38
|
+
preparedTx.gasLimit = GAS.CLAIM;
|
|
39
|
+
preparedTx.data = MultiversXEncodeTransaction.claimRewards();
|
|
40
|
+
break;
|
|
41
|
+
case "withdraw":
|
|
42
|
+
preparedTx.gasLimit = GAS.DELEGATE;
|
|
43
|
+
preparedTx.data = MultiversXEncodeTransaction.withdraw();
|
|
44
|
+
break;
|
|
45
|
+
case "reDelegateRewards":
|
|
46
|
+
preparedTx.gasLimit = GAS.DELEGATE;
|
|
47
|
+
preparedTx.data = MultiversXEncodeTransaction.reDelegateRewards();
|
|
48
|
+
break;
|
|
49
|
+
case "unDelegate":
|
|
50
|
+
preparedTx.gasLimit = GAS.DELEGATE;
|
|
51
|
+
preparedTx.data = MultiversXEncodeTransaction.unDelegate(transaction);
|
|
52
|
+
break;
|
|
53
|
+
case "send":
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error("Unsupported transaction mode: " + transaction.mode);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (transaction.useAllAmount) {
|
|
61
|
+
// Set the max amount
|
|
62
|
+
preparedTx.amount = tokenAccount ? tokenAccount.balance : account.spendableBalance;
|
|
63
|
+
|
|
64
|
+
// Compute estimated fees for that amount
|
|
65
|
+
preparedTx.fees = await getFees(preparedTx);
|
|
66
|
+
|
|
67
|
+
// Adjust max amount according to computed fees
|
|
68
|
+
if (!tokenAccount && isAmountSpentFromBalance(transaction.mode)) {
|
|
69
|
+
preparedTx.amount = preparedTx.amount.gt(preparedTx.fees)
|
|
70
|
+
? preparedTx.amount.minus(preparedTx.fees)
|
|
71
|
+
: new BigNumber(0);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
preparedTx.fees = await getFees(preparedTx);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return preparedTx;
|
|
78
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { log } from "@ledgerhq/logs";
|
|
2
|
+
import { Account, SubAccount, TokenAccount } from "@ledgerhq/types-live";
|
|
3
|
+
|
|
4
|
+
export function reconciliateSubAccounts(
|
|
5
|
+
tokenAccounts: TokenAccount[],
|
|
6
|
+
initialAccount: Account | undefined,
|
|
7
|
+
): TokenAccount[] {
|
|
8
|
+
let subAccounts;
|
|
9
|
+
|
|
10
|
+
if (initialAccount) {
|
|
11
|
+
const initialSubAccounts: SubAccount[] | undefined = initialAccount.subAccounts;
|
|
12
|
+
let anySubAccountHaveChanged = false;
|
|
13
|
+
const stats: string[] = [];
|
|
14
|
+
|
|
15
|
+
if (initialSubAccounts && tokenAccounts.length !== initialSubAccounts.length) {
|
|
16
|
+
stats.push("length differ");
|
|
17
|
+
anySubAccountHaveChanged = true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
subAccounts = tokenAccounts.map((ta: TokenAccount) => {
|
|
21
|
+
const existingTokenAccount = initialSubAccounts?.find(a => a.id === ta.id);
|
|
22
|
+
|
|
23
|
+
if (existingTokenAccount) {
|
|
24
|
+
let sameProperties = true;
|
|
25
|
+
|
|
26
|
+
if (existingTokenAccount !== ta) {
|
|
27
|
+
for (const property in existingTokenAccount) {
|
|
28
|
+
if ((existingTokenAccount as any)[property] !== (ta as any)[property]) {
|
|
29
|
+
sameProperties = false;
|
|
30
|
+
stats.push(`field ${property} changed for ${ta.id}`);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (sameProperties) {
|
|
37
|
+
return existingTokenAccount;
|
|
38
|
+
} else {
|
|
39
|
+
anySubAccountHaveChanged = true;
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
anySubAccountHaveChanged = true;
|
|
43
|
+
stats.push(`new token account ${ta.id}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return ta;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!anySubAccountHaveChanged && initialSubAccounts) {
|
|
50
|
+
// eslint-disable-next-line prettier/prettier
|
|
51
|
+
log(
|
|
52
|
+
"multiversx",
|
|
53
|
+
`incremental sync: ${String(initialSubAccounts.length)} sub accounts have not changed`,
|
|
54
|
+
);
|
|
55
|
+
subAccounts = initialSubAccounts;
|
|
56
|
+
} else {
|
|
57
|
+
log("multiversx", "incremental sync: sub accounts changed: " + stats.join(", "));
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
subAccounts = tokenAccounts.map((a: TokenAccount) => a);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return subAccounts;
|
|
64
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import {
|
|
3
|
+
type MultiversXResourcesRaw,
|
|
4
|
+
type MultiversXResources,
|
|
5
|
+
type MultiversXAccountRaw,
|
|
6
|
+
type MultiversXAccount,
|
|
7
|
+
type MultiversXOperationExtraRaw,
|
|
8
|
+
type MultiversXOperationExtra,
|
|
9
|
+
isMultiversXOperationExtraRaw,
|
|
10
|
+
isMultiversXOperationExtra,
|
|
11
|
+
} from "./types";
|
|
12
|
+
import type { Account, AccountRaw, OperationExtra, OperationExtraRaw } from "@ledgerhq/types-live";
|
|
13
|
+
|
|
14
|
+
export function toMultiversXResourcesRaw(r: MultiversXResources): MultiversXResourcesRaw {
|
|
15
|
+
const { nonce, delegations, isGuarded } = r;
|
|
16
|
+
return {
|
|
17
|
+
nonce,
|
|
18
|
+
delegations,
|
|
19
|
+
isGuarded,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function fromMultiversXResourcesRaw(r: MultiversXResourcesRaw): MultiversXResources {
|
|
24
|
+
const { nonce, delegations, isGuarded } = r;
|
|
25
|
+
return {
|
|
26
|
+
nonce,
|
|
27
|
+
delegations,
|
|
28
|
+
isGuarded,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function assignToAccountRaw(account: Account, accountRaw: AccountRaw) {
|
|
33
|
+
const multiversxAccount = account as MultiversXAccount;
|
|
34
|
+
if (multiversxAccount.multiversxResources) {
|
|
35
|
+
(accountRaw as MultiversXAccountRaw).multiversxResources = toMultiversXResourcesRaw(
|
|
36
|
+
multiversxAccount.multiversxResources,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function assignFromAccountRaw(accountRaw: AccountRaw, account: Account) {
|
|
42
|
+
const multiversxResourcesRaw = (accountRaw as MultiversXAccountRaw).multiversxResources;
|
|
43
|
+
if (multiversxResourcesRaw)
|
|
44
|
+
(account as MultiversXAccount).multiversxResources =
|
|
45
|
+
fromMultiversXResourcesRaw(multiversxResourcesRaw);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function fromOperationExtraRaw(extraRaw: OperationExtraRaw) {
|
|
49
|
+
const extra: MultiversXOperationExtra = {};
|
|
50
|
+
if (!isMultiversXOperationExtraRaw(extraRaw)) {
|
|
51
|
+
// All fields might be undefined
|
|
52
|
+
return extra;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (extraRaw.amount) {
|
|
56
|
+
extra.amount = new BigNumber(extraRaw.amount);
|
|
57
|
+
}
|
|
58
|
+
return extra;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function toOperationExtraRaw(extra: OperationExtra) {
|
|
62
|
+
const extraRaw: MultiversXOperationExtraRaw = {};
|
|
63
|
+
if (!isMultiversXOperationExtra(extra)) {
|
|
64
|
+
// All fields might be undefined
|
|
65
|
+
return extraRaw;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (extra.amount) {
|
|
69
|
+
extraRaw.amount = extra.amount.toString();
|
|
70
|
+
}
|
|
71
|
+
return extraRaw;
|
|
72
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
3
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
4
|
+
import { buildOptimisticOperation } from "./buildOptimisticOperation";
|
|
5
|
+
import { buildTransactionToSign } from "./buildTransaction";
|
|
6
|
+
import type { MultiversXAccount, Transaction } from "./types";
|
|
7
|
+
import { decodeTokenAccountId } from "@ledgerhq/coin-framework/account";
|
|
8
|
+
import { extractTokenId } from "./logic";
|
|
9
|
+
import { CHAIN_ID } from "./constants";
|
|
10
|
+
import { MultiversXSigner } from "./signer";
|
|
11
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Sign Transaction with Ledger hardware
|
|
15
|
+
*/
|
|
16
|
+
export const buildSignOperation =
|
|
17
|
+
(
|
|
18
|
+
signerContext: SignerContext<MultiversXSigner>,
|
|
19
|
+
): AccountBridge<Transaction, MultiversXAccount>["signOperation"] =>
|
|
20
|
+
({ account, transaction, deviceId }) =>
|
|
21
|
+
new Observable(o => {
|
|
22
|
+
let cancelled = false;
|
|
23
|
+
|
|
24
|
+
async function main() {
|
|
25
|
+
if (!transaction.fees) {
|
|
26
|
+
throw new FeeNotLoaded();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Collect data for an ESDT transfer
|
|
30
|
+
const { subAccounts } = account;
|
|
31
|
+
const { subAccountId } = transaction;
|
|
32
|
+
const tokenAccount = !subAccountId
|
|
33
|
+
? null
|
|
34
|
+
: subAccounts && subAccounts.find(ta => ta.id === subAccountId);
|
|
35
|
+
|
|
36
|
+
await signerContext(deviceId, signer => signer.setAddress(account.freshAddressPath));
|
|
37
|
+
|
|
38
|
+
if (tokenAccount) {
|
|
39
|
+
const { token } = decodeTokenAccountId(tokenAccount.id);
|
|
40
|
+
if (token == null) {
|
|
41
|
+
throw new Error("Invalid token");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await signerContext(deviceId, signer =>
|
|
45
|
+
signer.provideESDTInfo(
|
|
46
|
+
token.ticker,
|
|
47
|
+
extractTokenId(token.id),
|
|
48
|
+
token.units[0].magnitude,
|
|
49
|
+
CHAIN_ID,
|
|
50
|
+
token.ledgerSignature,
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const unsignedTx: string = await buildTransactionToSign(account, transaction);
|
|
56
|
+
|
|
57
|
+
o.next({
|
|
58
|
+
type: "device-signature-requested",
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const { signature } = await signerContext(deviceId, signer =>
|
|
62
|
+
signer.sign(account.freshAddressPath, unsignedTx),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
if (cancelled) return;
|
|
66
|
+
|
|
67
|
+
o.next({
|
|
68
|
+
type: "device-signature-granted",
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
if (!signature) {
|
|
72
|
+
throw new Error("No signature");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const parsedUnsignedTx = JSON.parse(unsignedTx);
|
|
76
|
+
|
|
77
|
+
const operation = buildOptimisticOperation(account, transaction, parsedUnsignedTx);
|
|
78
|
+
|
|
79
|
+
o.next({
|
|
80
|
+
type: "signed",
|
|
81
|
+
signedOperation: {
|
|
82
|
+
operation,
|
|
83
|
+
signature: signature.toString("hex"),
|
|
84
|
+
rawData: parsedUnsignedTx,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
main().then(
|
|
90
|
+
() => o.complete(),
|
|
91
|
+
e => o.error(e),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return () => {
|
|
95
|
+
cancelled = true;
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
export default buildSignOperation;
|
package/src/signer.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type MultiversXAddress = {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
address: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type MultiversXSignature = {
|
|
7
|
+
signature: null | Buffer;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export interface MultiversXSigner {
|
|
11
|
+
getAddress(path: string, boolDisplay?: boolean): Promise<MultiversXAddress>;
|
|
12
|
+
setAddress(path: string, boolDisplay?: boolean): Promise<void>;
|
|
13
|
+
sign(path: string, message: string): Promise<MultiversXSignature>;
|
|
14
|
+
provideESDTInfo(
|
|
15
|
+
ticker?: string,
|
|
16
|
+
id?: string,
|
|
17
|
+
decimals?: number,
|
|
18
|
+
chainId?: string,
|
|
19
|
+
signature?: string,
|
|
20
|
+
): Promise<any>;
|
|
21
|
+
}
|