@ledgerhq/coin-cardano 0.1.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 +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +35 -0
- package/CHANGELOG.md +19 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/account.d.ts +7 -0
- package/lib/account.d.ts.map +1 -0
- package/lib/account.js +41 -0
- package/lib/account.js.map +1 -0
- package/lib/address.unit.test.d.ts +2 -0
- package/lib/address.unit.test.d.ts.map +1 -0
- package/lib/address.unit.test.js +21 -0
- package/lib/address.unit.test.js.map +1 -0
- package/lib/api/api-types.d.ts +106 -0
- package/lib/api/api-types.d.ts.map +1 -0
- package/lib/api/api-types.js +9 -0
- package/lib/api/api-types.js.map +1 -0
- package/lib/api/getDelegationInfo.d.ts +4 -0
- package/lib/api/getDelegationInfo.d.ts.map +1 -0
- package/lib/api/getDelegationInfo.js +48 -0
- package/lib/api/getDelegationInfo.js.map +1 -0
- package/lib/api/getNetworkInfo.d.ts +5 -0
- package/lib/api/getNetworkInfo.d.ts.map +1 -0
- package/lib/api/getNetworkInfo.js +46 -0
- package/lib/api/getNetworkInfo.js.map +1 -0
- package/lib/api/getPools.d.ts +5 -0
- package/lib/api/getPools.d.ts.map +1 -0
- package/lib/api/getPools.js +45 -0
- package/lib/api/getPools.js.map +1 -0
- package/lib/api/getTransactions.d.ts +10 -0
- package/lib/api/getTransactions.d.ts.map +1 -0
- package/lib/api/getTransactions.js +139 -0
- package/lib/api/getTransactions.js.map +1 -0
- package/lib/api/submitTransaction.d.ts +7 -0
- package/lib/api/submitTransaction.d.ts.map +1 -0
- package/lib/api/submitTransaction.js +34 -0
- package/lib/api/submitTransaction.js.map +1 -0
- package/lib/bridge/index.d.ts +11 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +70 -0
- package/lib/bridge/index.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 +113 -0
- package/lib/bridge.integration.test.js.map +1 -0
- package/lib/broadcast.d.ts +8 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +28 -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 +125 -0
- package/lib/buildOptimisticOperation.js.map +1 -0
- package/lib/buildSubAccounts.d.ts +26 -0
- package/lib/buildSubAccounts.d.ts.map +1 -0
- package/lib/buildSubAccounts.js +124 -0
- package/lib/buildSubAccounts.js.map +1 -0
- package/lib/buildTransaction.d.ts +11 -0
- package/lib/buildTransaction.d.ts.map +1 -0
- package/lib/buildTransaction.js +342 -0
- package/lib/buildTransaction.js.map +1 -0
- package/lib/cli-transaction.d.ts +18 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +66 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/constants.d.ts +8 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +12 -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 +23 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/datasets/rawAccount.1.d.ts +3 -0
- package/lib/datasets/rawAccount.1.d.ts.map +1 -0
- package/lib/datasets/rawAccount.1.js +20 -0
- package/lib/datasets/rawAccount.1.js.map +1 -0
- package/lib/datasets/scanAccounts.d.ts +5 -0
- package/lib/datasets/scanAccounts.d.ts.map +1 -0
- package/lib/datasets/scanAccounts.js +27 -0
- package/lib/datasets/scanAccounts.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +11 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +106 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/errors.d.ts +22 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +18 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +9 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +53 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +4 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +214 -0
- package/lib/getTransactionStatus.js.map +1 -0
- package/lib/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib/getTransactionStatus.unit.test.js +54 -0
- package/lib/getTransactionStatus.unit.test.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 +37 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/logic.d.ts +88 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +264 -0
- package/lib/logic.js.map +1 -0
- package/lib/logic.unit.test.d.ts +2 -0
- package/lib/logic.unit.test.d.ts.map +1 -0
- package/lib/logic.unit.test.js +40 -0
- package/lib/logic.unit.test.js.map +1 -0
- package/lib/networks.d.ts +3 -0
- package/lib/networks.d.ts.map +1 -0
- package/lib/networks.js +36 -0
- package/lib/networks.js.map +1 -0
- package/lib/postSyncPatch.d.ts +6 -0
- package/lib/postSyncPatch.d.ts.map +1 -0
- package/lib/postSyncPatch.js +35 -0
- package/lib/postSyncPatch.js.map +1 -0
- package/lib/prepareTransaction.d.ts +10 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +44 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/serialization.d.ts +7 -0
- package/lib/serialization.d.ts.map +1 -0
- package/lib/serialization.js +146 -0
- package/lib/serialization.js.map +1 -0
- package/lib/signOperation.d.ts +9 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +71 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +92 -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 +218 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +4 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +128 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronisation.d.ts +6 -0
- package/lib/synchronisation.d.ts.map +1 -0
- package/lib/synchronisation.js +237 -0
- package/lib/synchronisation.js.map +1 -0
- package/lib/synchronisation.unit.test.d.ts +2 -0
- package/lib/synchronisation.unit.test.d.ts.map +1 -0
- package/lib/synchronisation.unit.test.js +129 -0
- package/lib/synchronisation.unit.test.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +43 -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 +18 -0
- package/lib/types.js.map +1 -0
- package/lib/typhonSerializer.d.ts +17 -0
- package/lib/typhonSerializer.d.ts.map +1 -0
- package/lib/typhonSerializer.js +213 -0
- package/lib/typhonSerializer.js.map +1 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +8 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/account.d.ts +7 -0
- package/lib-es/account.d.ts.map +1 -0
- package/lib-es/account.js +34 -0
- package/lib-es/account.js.map +1 -0
- package/lib-es/address.unit.test.d.ts +2 -0
- package/lib-es/address.unit.test.d.ts.map +1 -0
- package/lib-es/address.unit.test.js +19 -0
- package/lib-es/address.unit.test.js.map +1 -0
- package/lib-es/api/api-types.d.ts +106 -0
- package/lib-es/api/api-types.d.ts.map +1 -0
- package/lib-es/api/api-types.js +6 -0
- package/lib-es/api/api-types.js.map +1 -0
- package/lib-es/api/getDelegationInfo.d.ts +4 -0
- package/lib-es/api/getDelegationInfo.d.ts.map +1 -0
- package/lib-es/api/getDelegationInfo.js +41 -0
- package/lib-es/api/getDelegationInfo.js.map +1 -0
- package/lib-es/api/getNetworkInfo.d.ts +5 -0
- package/lib-es/api/getNetworkInfo.d.ts.map +1 -0
- package/lib-es/api/getNetworkInfo.js +39 -0
- package/lib-es/api/getNetworkInfo.js.map +1 -0
- package/lib-es/api/getPools.d.ts +5 -0
- package/lib-es/api/getPools.d.ts.map +1 -0
- package/lib-es/api/getPools.js +37 -0
- package/lib-es/api/getPools.js.map +1 -0
- package/lib-es/api/getTransactions.d.ts +10 -0
- package/lib-es/api/getTransactions.d.ts.map +1 -0
- package/lib-es/api/getTransactions.js +132 -0
- package/lib-es/api/getTransactions.js.map +1 -0
- package/lib-es/api/submitTransaction.d.ts +7 -0
- package/lib-es/api/submitTransaction.d.ts.map +1 -0
- package/lib-es/api/submitTransaction.js +27 -0
- package/lib-es/api/submitTransaction.js.map +1 -0
- package/lib-es/bridge/index.d.ts +11 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +61 -0
- package/lib-es/bridge/index.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 +107 -0
- package/lib-es/bridge.integration.test.js.map +1 -0
- package/lib-es/broadcast.d.ts +8 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +24 -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 +118 -0
- package/lib-es/buildOptimisticOperation.js.map +1 -0
- package/lib-es/buildSubAccounts.d.ts +26 -0
- package/lib-es/buildSubAccounts.d.ts.map +1 -0
- package/lib-es/buildSubAccounts.js +114 -0
- package/lib-es/buildSubAccounts.js.map +1 -0
- package/lib-es/buildTransaction.d.ts +11 -0
- package/lib-es/buildTransaction.d.ts.map +1 -0
- package/lib-es/buildTransaction.js +335 -0
- package/lib-es/buildTransaction.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +18 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +60 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/constants.d.ts +8 -0
- package/lib-es/constants.d.ts.map +1 -0
- package/lib-es/constants.js +9 -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 +16 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/datasets/rawAccount.1.d.ts +3 -0
- package/lib-es/datasets/rawAccount.1.d.ts.map +1 -0
- package/lib-es/datasets/rawAccount.1.js +17 -0
- package/lib-es/datasets/rawAccount.1.js.map +1 -0
- package/lib-es/datasets/scanAccounts.d.ts +5 -0
- package/lib-es/datasets/scanAccounts.d.ts.map +1 -0
- package/lib-es/datasets/scanAccounts.js +24 -0
- package/lib-es/datasets/scanAccounts.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +11 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +101 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/errors.d.ts +22 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +15 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +9 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +49 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +4 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +210 -0
- package/lib-es/getTransactionStatus.js.map +1 -0
- package/lib-es/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib-es/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.unit.test.js +49 -0
- package/lib-es/getTransactionStatus.unit.test.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 +35 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/logic.d.ts +88 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +236 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/logic.unit.test.d.ts +2 -0
- package/lib-es/logic.unit.test.d.ts.map +1 -0
- package/lib-es/logic.unit.test.js +35 -0
- package/lib-es/logic.unit.test.js.map +1 -0
- package/lib-es/networks.d.ts +3 -0
- package/lib-es/networks.d.ts.map +1 -0
- package/lib-es/networks.js +32 -0
- package/lib-es/networks.js.map +1 -0
- package/lib-es/postSyncPatch.d.ts +6 -0
- package/lib-es/postSyncPatch.d.ts.map +1 -0
- package/lib-es/postSyncPatch.js +31 -0
- package/lib-es/postSyncPatch.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 +40 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/serialization.d.ts +7 -0
- package/lib-es/serialization.d.ts.map +1 -0
- package/lib-es/serialization.js +139 -0
- package/lib-es/serialization.js.map +1 -0
- package/lib-es/signOperation.d.ts +9 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +64 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +92 -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 +213 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +4 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +125 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronisation.d.ts +6 -0
- package/lib-es/synchronisation.d.ts.map +1 -0
- package/lib-es/synchronisation.js +230 -0
- package/lib-es/synchronisation.js.map +1 -0
- package/lib-es/synchronisation.unit.test.d.ts +2 -0
- package/lib-es/synchronisation.unit.test.d.ts.map +1 -0
- package/lib-es/synchronisation.unit.test.js +124 -0
- package/lib-es/synchronisation.unit.test.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 +37 -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 +15 -0
- package/lib-es/types.js.map +1 -0
- package/lib-es/typhonSerializer.d.ts +17 -0
- package/lib-es/typhonSerializer.d.ts.map +1 -0
- package/lib-es/typhonSerializer.js +207 -0
- package/lib-es/typhonSerializer.js.map +1 -0
- package/lib-es/utils.d.ts +2 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +5 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +91 -0
- package/src/account.ts +39 -0
- package/src/address.unit.test.ts +32 -0
- package/src/api/api-types.ts +115 -0
- package/src/api/getDelegationInfo.ts +39 -0
- package/src/api/getNetworkInfo.ts +34 -0
- package/src/api/getPools.ts +35 -0
- package/src/api/getTransactions.ts +218 -0
- package/src/api/submitTransaction.ts +24 -0
- package/src/bridge/index.ts +69 -0
- package/src/bridge.integration.test.ts +113 -0
- package/src/broadcast.ts +21 -0
- package/src/buildOptimisticOperation.ts +181 -0
- package/src/buildSubAccounts.ts +170 -0
- package/src/buildTransaction.ts +435 -0
- package/src/cli-transaction.ts +82 -0
- package/src/constants.ts +10 -0
- package/src/createTransaction.ts +18 -0
- package/src/datasets/rawAccount.1.ts +19 -0
- package/src/datasets/scanAccounts.ts +23 -0
- package/src/deviceTransactionConfig.ts +128 -0
- package/src/errors.ts +18 -0
- package/src/estimateMaxSpendable.ts +61 -0
- package/src/getTransactionStatus.ts +251 -0
- package/src/getTransactionStatus.unit.test.ts +45 -0
- package/src/hw-getAddress.ts +37 -0
- package/src/logic.ts +330 -0
- package/src/logic.unit.test.ts +39 -0
- package/src/networks.ts +33 -0
- package/src/postSyncPatch.ts +42 -0
- package/src/prepareTransaction.ts +41 -0
- package/src/serialization.ts +219 -0
- package/src/signOperation.ts +82 -0
- package/src/signer.ts +98 -0
- package/src/specs.ts +253 -0
- package/src/speculos-deviceActions.ts +132 -0
- package/src/synchronisation.ts +347 -0
- package/src/synchronisation.unit.test.ts +137 -0
- package/src/transaction.ts +66 -0
- package/src/types.ts +227 -0
- package/src/typhonSerializer.ts +259 -0
- package/src/utils.ts +4 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { getAccountCurrency, getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
3
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
4
|
+
import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
|
|
5
|
+
import { Account, AccountLike } from "@ledgerhq/types-live";
|
|
6
|
+
import { decodeTokenAssetId, decodeTokenCurrencyId } from "./buildSubAccounts";
|
|
7
|
+
import { CardanoAccount, Transaction, TransactionStatus } from "./types";
|
|
8
|
+
import { utils as TyphonUtils } from "@stricahq/typhonjs";
|
|
9
|
+
import {
|
|
10
|
+
decodeTokenName,
|
|
11
|
+
getAccountStakeCredential,
|
|
12
|
+
getBech32PoolId,
|
|
13
|
+
getBipPathString,
|
|
14
|
+
} from "./logic";
|
|
15
|
+
|
|
16
|
+
function getDeviceTransactionConfig({
|
|
17
|
+
account,
|
|
18
|
+
transaction,
|
|
19
|
+
parentAccount,
|
|
20
|
+
}: {
|
|
21
|
+
account: AccountLike;
|
|
22
|
+
parentAccount: Account | null | undefined;
|
|
23
|
+
transaction: Transaction;
|
|
24
|
+
status: TransactionStatus;
|
|
25
|
+
}): Array<DeviceTransactionField> {
|
|
26
|
+
const { mode } = transaction;
|
|
27
|
+
const fields: DeviceTransactionField[] = [];
|
|
28
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
29
|
+
const cardanoResources = (mainAccount as CardanoAccount).cardanoResources;
|
|
30
|
+
|
|
31
|
+
const { fees } = transaction;
|
|
32
|
+
if (fees) {
|
|
33
|
+
fields.push({
|
|
34
|
+
type: "text",
|
|
35
|
+
label: "Transaction Fee",
|
|
36
|
+
value: formatCurrencyUnit(getAccountCurrency(account).units[0], fees, {
|
|
37
|
+
showCode: true,
|
|
38
|
+
disableRounding: true,
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (mode === "send") {
|
|
44
|
+
if (account.type === "TokenAccount") {
|
|
45
|
+
const { assetId } = decodeTokenCurrencyId(account.token.id);
|
|
46
|
+
const { policyId, assetName } = decodeTokenAssetId(assetId);
|
|
47
|
+
const transactionAmount = transaction.useAllAmount ? account.balance : transaction.amount;
|
|
48
|
+
|
|
49
|
+
const tokensToSend = [
|
|
50
|
+
{
|
|
51
|
+
policyId,
|
|
52
|
+
assetName,
|
|
53
|
+
amount: transactionAmount,
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const requiredMinAdaForTokens = TyphonUtils.calculateMinUtxoAmount(
|
|
58
|
+
tokensToSend,
|
|
59
|
+
new BigNumber(cardanoResources.protocolParams.lovelacePerUtxoWord),
|
|
60
|
+
);
|
|
61
|
+
fields.push({
|
|
62
|
+
type: "text",
|
|
63
|
+
label: "ADA",
|
|
64
|
+
value: formatCurrencyUnit(
|
|
65
|
+
getAccountCurrency(mainAccount).units[0],
|
|
66
|
+
requiredMinAdaForTokens,
|
|
67
|
+
{
|
|
68
|
+
showCode: true,
|
|
69
|
+
disableRounding: true,
|
|
70
|
+
},
|
|
71
|
+
),
|
|
72
|
+
});
|
|
73
|
+
fields.push({
|
|
74
|
+
type: "text",
|
|
75
|
+
label: "Token Name",
|
|
76
|
+
value: decodeTokenName(assetName),
|
|
77
|
+
});
|
|
78
|
+
fields.push({
|
|
79
|
+
type: "text",
|
|
80
|
+
label: "Amount",
|
|
81
|
+
value: formatCurrencyUnit(getAccountCurrency(account).units[0], transactionAmount, {
|
|
82
|
+
showCode: true,
|
|
83
|
+
disableRounding: true,
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
} else if (account.type === "Account") {
|
|
87
|
+
fields.push({
|
|
88
|
+
type: "text",
|
|
89
|
+
label: "Amount",
|
|
90
|
+
value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
|
|
91
|
+
showCode: true,
|
|
92
|
+
disableRounding: true,
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
} else if (mode === "delegate" && account.type === "Account") {
|
|
97
|
+
const stakeCredential = getAccountStakeCredential(account.xpub as string, account.index);
|
|
98
|
+
fields.push({
|
|
99
|
+
type: "text",
|
|
100
|
+
label: "Staking key",
|
|
101
|
+
value: getBipPathString({
|
|
102
|
+
account: stakeCredential.path.account,
|
|
103
|
+
chain: stakeCredential.path.chain,
|
|
104
|
+
index: stakeCredential.path.index,
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
107
|
+
fields.push({
|
|
108
|
+
type: "text",
|
|
109
|
+
label: "Delegate stake to",
|
|
110
|
+
value: getBech32PoolId(transaction.poolId as string, account.currency.id),
|
|
111
|
+
});
|
|
112
|
+
} else if (mode === "undelegate" && account.type === "Account") {
|
|
113
|
+
const stakeCredential = getAccountStakeCredential(account.xpub as string, account.index);
|
|
114
|
+
fields.push({
|
|
115
|
+
type: "text",
|
|
116
|
+
label: "Staking key",
|
|
117
|
+
value: getBipPathString({
|
|
118
|
+
account: stakeCredential.path.account,
|
|
119
|
+
chain: stakeCredential.path.chain,
|
|
120
|
+
index: stakeCredential.path.index,
|
|
121
|
+
}),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return fields;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export default getDeviceTransactionConfig;
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createCustomErrorClass } from "@ledgerhq/errors";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cardano error thrown when transaction amount is less then minUtxo
|
|
5
|
+
*/
|
|
6
|
+
export const CardanoMinAmountError = createCustomErrorClass("CardanoMinAmountError");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Cardano error thrown when user don't have enough fund for deposit
|
|
10
|
+
*/
|
|
11
|
+
export const CardanoStakeKeyDepositError = createCustomErrorClass("CardanoStakeKeyDepositError");
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Cardano error thrown when not enough funds to perform transaction
|
|
15
|
+
*/
|
|
16
|
+
export const CardanoNotEnoughFunds = createCustomErrorClass("CardanoNotEnoughFunds");
|
|
17
|
+
|
|
18
|
+
export const CardanoInvalidPoolId = createCustomErrorClass("CardanoInvalidPoolId");
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
address as TyphonAddress,
|
|
3
|
+
types as TyphonTypes,
|
|
4
|
+
Transaction as TyphonTransaction,
|
|
5
|
+
} from "@stricahq/typhonjs";
|
|
6
|
+
import { log } from "@ledgerhq/logs";
|
|
7
|
+
import { BigNumber } from "bignumber.js";
|
|
8
|
+
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
9
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
10
|
+
import type { CardanoAccount, Transaction } from "./types";
|
|
11
|
+
import { createTransaction } from "./createTransaction";
|
|
12
|
+
import { buildTransaction } from "./buildTransaction";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns the maximum possible amount for transaction
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} param - the account, parentAccount and transaction
|
|
18
|
+
*/
|
|
19
|
+
export const estimateMaxSpendable: AccountBridge<
|
|
20
|
+
Transaction,
|
|
21
|
+
CardanoAccount
|
|
22
|
+
>["estimateMaxSpendable"] = async ({ account, parentAccount, transaction }) => {
|
|
23
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
24
|
+
|
|
25
|
+
if (mainAccount.cardanoResources.utxos.length === 0) {
|
|
26
|
+
return new BigNumber(0);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (account.type === "TokenAccount") {
|
|
30
|
+
return account.balance;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const dummyRecipient =
|
|
34
|
+
"addr1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv2t5am";
|
|
35
|
+
const t: Transaction = {
|
|
36
|
+
...createTransaction(account),
|
|
37
|
+
...transaction,
|
|
38
|
+
recipient: dummyRecipient,
|
|
39
|
+
// amount field will not be used to build a transaction when useAllAmount is true
|
|
40
|
+
amount: new BigNumber(0),
|
|
41
|
+
useAllAmount: true,
|
|
42
|
+
};
|
|
43
|
+
let typhonTransaction: TyphonTransaction;
|
|
44
|
+
try {
|
|
45
|
+
typhonTransaction = await buildTransaction(mainAccount, t);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
log("cardano-error", "Failed to estimate max spendable: " + String(error));
|
|
48
|
+
return new BigNumber(0);
|
|
49
|
+
}
|
|
50
|
+
const transactionAmount = typhonTransaction
|
|
51
|
+
.getOutputs()
|
|
52
|
+
.filter(
|
|
53
|
+
o =>
|
|
54
|
+
!(o.address instanceof TyphonAddress.BaseAddress) ||
|
|
55
|
+
!(o.address.paymentCredential.type === TyphonTypes.HashType.ADDRESS) ||
|
|
56
|
+
o.address.paymentCredential.bipPath === undefined,
|
|
57
|
+
)
|
|
58
|
+
.reduce((total, o) => total.plus(o.amount), new BigNumber(0));
|
|
59
|
+
|
|
60
|
+
return transactionAmount;
|
|
61
|
+
};
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccountAwaitingSendPendingOperations,
|
|
3
|
+
RecipientRequired,
|
|
4
|
+
FeeNotLoaded,
|
|
5
|
+
InvalidAddress,
|
|
6
|
+
AmountRequired,
|
|
7
|
+
NotEnoughBalance,
|
|
8
|
+
} from "@ledgerhq/errors";
|
|
9
|
+
import { BigNumber } from "bignumber.js";
|
|
10
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
11
|
+
import { utils as TyphonUtils } from "@stricahq/typhonjs";
|
|
12
|
+
import { decodeTokenAssetId, decodeTokenCurrencyId } from "./buildSubAccounts";
|
|
13
|
+
import { estimateMaxSpendable } from "./estimateMaxSpendable";
|
|
14
|
+
import { buildTransaction } from "./buildTransaction";
|
|
15
|
+
import { isHexString, isValidAddress } from "./logic";
|
|
16
|
+
import { getNetworkParameters } from "./networks";
|
|
17
|
+
import {
|
|
18
|
+
CardanoInvalidPoolId,
|
|
19
|
+
CardanoStakeKeyDepositError,
|
|
20
|
+
CardanoMinAmountError,
|
|
21
|
+
CardanoNotEnoughFunds,
|
|
22
|
+
} from "./errors";
|
|
23
|
+
import type {
|
|
24
|
+
CardanoAccount,
|
|
25
|
+
CardanoResources,
|
|
26
|
+
Token,
|
|
27
|
+
Transaction,
|
|
28
|
+
TransactionStatus,
|
|
29
|
+
} from "./types";
|
|
30
|
+
|
|
31
|
+
export const getTransactionStatus: AccountBridge<
|
|
32
|
+
Transaction,
|
|
33
|
+
CardanoAccount,
|
|
34
|
+
TransactionStatus
|
|
35
|
+
>["getTransactionStatus"] = async (account, transaction) => {
|
|
36
|
+
if (account.pendingOperations.length > 0) {
|
|
37
|
+
throw new AccountAwaitingSendPendingOperations();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (account.cardanoResources.utxos.length === 0) {
|
|
41
|
+
const errors = {
|
|
42
|
+
amount: new CardanoNotEnoughFunds(),
|
|
43
|
+
};
|
|
44
|
+
return Promise.resolve({
|
|
45
|
+
errors,
|
|
46
|
+
warnings: {},
|
|
47
|
+
estimatedFees: new BigNumber(0),
|
|
48
|
+
amount: new BigNumber(transaction.amount),
|
|
49
|
+
totalSpent: new BigNumber(transaction.amount),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (transaction.mode === "send") {
|
|
54
|
+
return getSendTransactionStatus(account, transaction);
|
|
55
|
+
} else if (transaction.mode === "delegate") {
|
|
56
|
+
return getDelegateTransactionStatus(account, transaction);
|
|
57
|
+
} else if (transaction.mode === "undelegate") {
|
|
58
|
+
return getUndelegateTransactionStatus(account, transaction);
|
|
59
|
+
} else {
|
|
60
|
+
throw new Error("Invalid transaction mode");
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
async function getSendTransactionStatus(
|
|
65
|
+
account: CardanoAccount,
|
|
66
|
+
transaction: Transaction,
|
|
67
|
+
): Promise<TransactionStatus> {
|
|
68
|
+
const errors: Record<string, Error> = {};
|
|
69
|
+
const warnings: Record<string, Error> = {};
|
|
70
|
+
const useAllAmount = !!transaction.useAllAmount;
|
|
71
|
+
|
|
72
|
+
const cardanoResources = account.cardanoResources;
|
|
73
|
+
const networkParams = getNetworkParameters(account.currency.id);
|
|
74
|
+
|
|
75
|
+
const estimatedFees = transaction.fees || new BigNumber(0);
|
|
76
|
+
let amount = transaction.amount;
|
|
77
|
+
let totalSpent = estimatedFees;
|
|
78
|
+
|
|
79
|
+
const tokenAccount =
|
|
80
|
+
transaction.subAccountId && account.subAccounts
|
|
81
|
+
? account.subAccounts.find(a => {
|
|
82
|
+
return a.id === transaction.subAccountId;
|
|
83
|
+
})
|
|
84
|
+
: undefined;
|
|
85
|
+
|
|
86
|
+
let tokensToSend: Array<Token> = [];
|
|
87
|
+
if (transaction.subAccountId) {
|
|
88
|
+
// Token transaction
|
|
89
|
+
if (!tokenAccount || tokenAccount.type !== "TokenAccount") {
|
|
90
|
+
throw new Error("TokenAccount not found");
|
|
91
|
+
}
|
|
92
|
+
const { assetId } = decodeTokenCurrencyId(tokenAccount.token.id);
|
|
93
|
+
const { policyId, assetName } = decodeTokenAssetId(assetId);
|
|
94
|
+
amount = transaction.useAllAmount ? tokenAccount.balance : transaction.amount;
|
|
95
|
+
totalSpent = amount;
|
|
96
|
+
tokensToSend = [
|
|
97
|
+
{
|
|
98
|
+
policyId,
|
|
99
|
+
assetName,
|
|
100
|
+
amount,
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
} else {
|
|
104
|
+
// ADA transaction
|
|
105
|
+
amount = transaction.useAllAmount
|
|
106
|
+
? await estimateMaxSpendable({ account: account, transaction: transaction })
|
|
107
|
+
: amount;
|
|
108
|
+
totalSpent = amount.plus(estimatedFees);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const minTransactionAmount = TyphonUtils.calculateMinUtxoAmount(
|
|
112
|
+
tokensToSend,
|
|
113
|
+
new BigNumber(cardanoResources.protocolParams.lovelacePerUtxoWord),
|
|
114
|
+
false,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
if (!transaction.fees) {
|
|
118
|
+
errors.fees = new FeeNotLoaded();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!transaction.recipient) {
|
|
122
|
+
errors.recipient = new RecipientRequired();
|
|
123
|
+
} else if (!isValidAddress(transaction.recipient, networkParams.networkId)) {
|
|
124
|
+
errors.recipient = new InvalidAddress("", {
|
|
125
|
+
currencyName: account.currency.name,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!amount.gt(0)) {
|
|
130
|
+
errors.amount = useAllAmount ? new CardanoNotEnoughFunds() : new AmountRequired();
|
|
131
|
+
} else if (!transaction.subAccountId && amount.lt(minTransactionAmount)) {
|
|
132
|
+
errors.amount = new CardanoMinAmountError("", {
|
|
133
|
+
amount: minTransactionAmount.div(1e6).toString(),
|
|
134
|
+
});
|
|
135
|
+
} else if (tokenAccount ? totalSpent.gt(tokenAccount.balance) : totalSpent.gt(account.balance)) {
|
|
136
|
+
errors.amount = new NotEnoughBalance();
|
|
137
|
+
} else {
|
|
138
|
+
try {
|
|
139
|
+
await buildTransaction(account, transaction);
|
|
140
|
+
} catch (e: any) {
|
|
141
|
+
if (
|
|
142
|
+
e.message.toLowerCase() === "not enough ada" ||
|
|
143
|
+
e.message.toLowerCase() === "not enough tokens"
|
|
144
|
+
) {
|
|
145
|
+
errors.amount = new CardanoNotEnoughFunds();
|
|
146
|
+
} else {
|
|
147
|
+
throw e;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return Promise.resolve({
|
|
153
|
+
errors,
|
|
154
|
+
warnings,
|
|
155
|
+
estimatedFees,
|
|
156
|
+
amount,
|
|
157
|
+
totalSpent,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function getDelegateTransactionStatus(
|
|
162
|
+
account: CardanoAccount,
|
|
163
|
+
transaction: Transaction,
|
|
164
|
+
): Promise<TransactionStatus> {
|
|
165
|
+
const errors: Record<string, Error> = {};
|
|
166
|
+
const warnings: Record<string, Error> = {};
|
|
167
|
+
|
|
168
|
+
if (!transaction.fees) {
|
|
169
|
+
errors.fees = new FeeNotLoaded();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const estimatedFees = transaction.fees || new BigNumber(0);
|
|
173
|
+
|
|
174
|
+
if (!transaction.poolId || !isHexString(transaction.poolId) || transaction.poolId.length !== 56) {
|
|
175
|
+
errors.poolId = new CardanoInvalidPoolId();
|
|
176
|
+
} else {
|
|
177
|
+
try {
|
|
178
|
+
await buildTransaction(account, transaction);
|
|
179
|
+
} catch (e: any) {
|
|
180
|
+
if (
|
|
181
|
+
e.message.toLowerCase() === "not enough ada" ||
|
|
182
|
+
e.message.toLowerCase() === "not enough tokens"
|
|
183
|
+
) {
|
|
184
|
+
errors.amount = new CardanoNotEnoughFunds();
|
|
185
|
+
} else {
|
|
186
|
+
throw e;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const stakeKeyRegisterDeposit = new BigNumber(
|
|
192
|
+
account.cardanoResources.protocolParams.stakeKeyDeposit,
|
|
193
|
+
);
|
|
194
|
+
if (
|
|
195
|
+
!account.cardanoResources.delegation?.status &&
|
|
196
|
+
account.spendableBalance.isLessThan(stakeKeyRegisterDeposit)
|
|
197
|
+
) {
|
|
198
|
+
errors.amount = new CardanoStakeKeyDepositError("", {
|
|
199
|
+
depositAmount: stakeKeyRegisterDeposit.div(1e6).toString(),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return Promise.resolve({
|
|
204
|
+
errors,
|
|
205
|
+
warnings,
|
|
206
|
+
estimatedFees,
|
|
207
|
+
amount: new BigNumber(0),
|
|
208
|
+
totalSpent: estimatedFees,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function getUndelegateTransactionStatus(
|
|
213
|
+
account: CardanoAccount,
|
|
214
|
+
transaction: Transaction,
|
|
215
|
+
): Promise<TransactionStatus> {
|
|
216
|
+
const errors: Record<string, Error> = {};
|
|
217
|
+
const warnings: Record<string, Error> = {};
|
|
218
|
+
|
|
219
|
+
const cardanoResources = account.cardanoResources as CardanoResources;
|
|
220
|
+
|
|
221
|
+
const estimatedFees = transaction.fees || new BigNumber(0);
|
|
222
|
+
|
|
223
|
+
if (!cardanoResources.delegation?.status) {
|
|
224
|
+
throw new Error("StakeKey is not registered");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (account.balance.eq(0)) {
|
|
228
|
+
throw new CardanoNotEnoughFunds();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
await buildTransaction(account, transaction);
|
|
233
|
+
} catch (e: any) {
|
|
234
|
+
if (
|
|
235
|
+
e.message.toLowerCase() === "not enough ada" ||
|
|
236
|
+
e.message.toLowerCase() === "not enough tokens"
|
|
237
|
+
) {
|
|
238
|
+
errors.amount = new CardanoNotEnoughFunds();
|
|
239
|
+
} else {
|
|
240
|
+
throw e;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return Promise.resolve({
|
|
245
|
+
errors,
|
|
246
|
+
warnings,
|
|
247
|
+
estimatedFees,
|
|
248
|
+
amount: new BigNumber(0),
|
|
249
|
+
totalSpent: estimatedFees,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { getTransactionStatus } from "./getTransactionStatus";
|
|
3
|
+
import { CardanoAccount, Transaction } from "./types";
|
|
4
|
+
|
|
5
|
+
describe("getTransactionStatus", () => {
|
|
6
|
+
it("should return not enough funds error when there are no utxos", async () => {
|
|
7
|
+
const initialAccount = {
|
|
8
|
+
pendingOperations: [],
|
|
9
|
+
cardanoResources: {
|
|
10
|
+
utxos: [],
|
|
11
|
+
},
|
|
12
|
+
} as unknown as CardanoAccount;
|
|
13
|
+
|
|
14
|
+
const sendTx: Transaction = {
|
|
15
|
+
amount: new BigNumber(1000000),
|
|
16
|
+
recipient:
|
|
17
|
+
"addr1qxqm3nxwzf70ke9jqa2zrtrevjznpv6yykptxnv34perjc8a7zgxmpv5pgk4hhhe0m9kfnlsf5pt7d2ahkxaul2zygrq3nura9",
|
|
18
|
+
mode: "send",
|
|
19
|
+
family: "cardano",
|
|
20
|
+
poolId: undefined,
|
|
21
|
+
};
|
|
22
|
+
const sendTxRes = await getTransactionStatus(initialAccount, sendTx);
|
|
23
|
+
expect(sendTxRes.errors.amount.name).toBe("CardanoNotEnoughFunds");
|
|
24
|
+
|
|
25
|
+
const delegateTx: Transaction = {
|
|
26
|
+
amount: new BigNumber(0),
|
|
27
|
+
recipient: "",
|
|
28
|
+
mode: "delegate",
|
|
29
|
+
family: "cardano",
|
|
30
|
+
poolId: "d0f48f07e4e5eb8040a988085f7ea3bd32d71a2e2998d53e9bbc959a",
|
|
31
|
+
};
|
|
32
|
+
const delegateTxRes = await getTransactionStatus(initialAccount, delegateTx);
|
|
33
|
+
expect(delegateTxRes.errors.amount.name).toBe("CardanoNotEnoughFunds");
|
|
34
|
+
|
|
35
|
+
const undelegateTx: Transaction = {
|
|
36
|
+
amount: new BigNumber(0),
|
|
37
|
+
recipient: "",
|
|
38
|
+
mode: "undelegate",
|
|
39
|
+
family: "cardano",
|
|
40
|
+
poolId: undefined,
|
|
41
|
+
};
|
|
42
|
+
const undelegateTxRes = await getTransactionStatus(initialAccount, undelegateTx);
|
|
43
|
+
expect(undelegateTxRes.errors.amount.name).toBe("CardanoNotEnoughFunds");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { utils as TyphonUtils } from "@stricahq/typhonjs";
|
|
2
|
+
import { address as TyphonAddress } from "@stricahq/typhonjs";
|
|
3
|
+
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
4
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
5
|
+
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
|
|
6
|
+
import { getBipPathFromString, getBipPathString } from "./logic";
|
|
7
|
+
import { StakeChain } from "./types";
|
|
8
|
+
import { STAKING_ADDRESS_INDEX } from "./constants";
|
|
9
|
+
import { getNetworkParameters } from "./networks";
|
|
10
|
+
import { CardanoSigner } from "./signer";
|
|
11
|
+
|
|
12
|
+
const resolver = (signerContext: SignerContext<CardanoSigner>): GetAddressFn => {
|
|
13
|
+
return async (deviceId: string, { path, verify, currency }: GetAddressOptions) => {
|
|
14
|
+
const spendingPath = getBipPathFromString(path);
|
|
15
|
+
const stakingPathString = getBipPathString({
|
|
16
|
+
account: spendingPath.account,
|
|
17
|
+
chain: StakeChain.stake,
|
|
18
|
+
index: STAKING_ADDRESS_INDEX,
|
|
19
|
+
});
|
|
20
|
+
const networkParams = getNetworkParameters(currency.id);
|
|
21
|
+
|
|
22
|
+
const r = await signerContext(deviceId, signer =>
|
|
23
|
+
signer.getAddress({ path, stakingPathString, networkParams, verify }),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const address = TyphonUtils.getAddressFromHex(r.addressHex) as TyphonAddress.BaseAddress;
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
address: address.getBech32(),
|
|
30
|
+
// Here, we use publicKey hash, as cardano app doesn't export the public key
|
|
31
|
+
publicKey: address.paymentCredential.hash,
|
|
32
|
+
path,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default resolver;
|