@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
package/src/logic.ts
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CARDANO_COIN_TYPE,
|
|
3
|
+
CARDANO_PURPOSE,
|
|
4
|
+
MEMO_LABEL,
|
|
5
|
+
STAKING_ADDRESS_INDEX,
|
|
6
|
+
TTL_GAP,
|
|
7
|
+
} from "./constants";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
utils as TyphonUtils,
|
|
11
|
+
types as TyphonTypes,
|
|
12
|
+
address as TyphonAddress,
|
|
13
|
+
} from "@stricahq/typhonjs";
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
CardanoAccount,
|
|
17
|
+
BipPath,
|
|
18
|
+
PaymentChain,
|
|
19
|
+
PaymentCredential,
|
|
20
|
+
StakeChain,
|
|
21
|
+
StakeCredential,
|
|
22
|
+
Token,
|
|
23
|
+
} from "./types";
|
|
24
|
+
import { Bip32PublicKey } from "@stricahq/bip32ed25519";
|
|
25
|
+
import BigNumber from "bignumber.js";
|
|
26
|
+
import { getNetworkParameters } from "./networks";
|
|
27
|
+
import groupBy from "lodash/groupBy";
|
|
28
|
+
import { APITransaction } from "./api/api-types";
|
|
29
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
30
|
+
import ShelleyTypeAddress from "@stricahq/typhonjs/dist/address/ShelleyTypeAddress";
|
|
31
|
+
import type { OperationType } from "@ledgerhq/types-live";
|
|
32
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
33
|
+
import bech32 from "bech32";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* returns BipPath object with account, chain and index field for cardano
|
|
37
|
+
*
|
|
38
|
+
* @param {string} path
|
|
39
|
+
*/
|
|
40
|
+
export function getBipPathFromString(path: string): BipPath {
|
|
41
|
+
const regEx = new RegExp(`^${CARDANO_PURPOSE}'/${CARDANO_COIN_TYPE}'/(\\d*)'/([012])/(\\d*)`);
|
|
42
|
+
const result = path.match(regEx);
|
|
43
|
+
if (result == null) {
|
|
44
|
+
throw new Error("Invalid derivation path");
|
|
45
|
+
}
|
|
46
|
+
return getBipPath({
|
|
47
|
+
account: parseInt(result[1]),
|
|
48
|
+
chain: parseInt(result[2]),
|
|
49
|
+
index: parseInt(result[3]),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @returns true if the account can stake, false otherwise
|
|
56
|
+
*/
|
|
57
|
+
export function canStake(account: CardanoAccount): boolean {
|
|
58
|
+
return account.balance.gt(0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @returns true if account is staked, false otherwise
|
|
64
|
+
*/
|
|
65
|
+
export function isAlreadyStaking(account: CardanoAccount): boolean {
|
|
66
|
+
return !!account.cardanoResources?.delegation?.poolId;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* returns complete bipPath with purpose, coin, account, chain and index for cardano
|
|
71
|
+
*/
|
|
72
|
+
export function getBipPath({
|
|
73
|
+
account,
|
|
74
|
+
chain,
|
|
75
|
+
index,
|
|
76
|
+
}: {
|
|
77
|
+
account: number;
|
|
78
|
+
chain: PaymentChain | StakeChain;
|
|
79
|
+
index: number;
|
|
80
|
+
}): BipPath {
|
|
81
|
+
return {
|
|
82
|
+
purpose: CARDANO_PURPOSE,
|
|
83
|
+
coin: CARDANO_COIN_TYPE,
|
|
84
|
+
account,
|
|
85
|
+
chain,
|
|
86
|
+
index,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* returns bipPathString from account, chain and index for cardano
|
|
92
|
+
*/
|
|
93
|
+
export function getBipPathString({
|
|
94
|
+
account,
|
|
95
|
+
chain,
|
|
96
|
+
index,
|
|
97
|
+
}: {
|
|
98
|
+
account: number;
|
|
99
|
+
chain: number;
|
|
100
|
+
index: number;
|
|
101
|
+
}): string {
|
|
102
|
+
return `${CARDANO_PURPOSE}'/${CARDANO_COIN_TYPE}'/${account}'/${chain}/${index}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function getExtendedPublicKeyFromHex(keyHex: string): Bip32PublicKey {
|
|
106
|
+
return Bip32PublicKey.fromBytes(Buffer.from(keyHex, "hex"));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function getCredentialKey(
|
|
110
|
+
accountKey: Bip32PublicKey,
|
|
111
|
+
path: BipPath,
|
|
112
|
+
): { key: string; path: BipPath } {
|
|
113
|
+
const keyBytes = accountKey.derive(path.chain).derive(path.index).toPublicKey().hash();
|
|
114
|
+
const pubKeyHex = keyBytes.toString("hex");
|
|
115
|
+
return {
|
|
116
|
+
key: pubKeyHex,
|
|
117
|
+
path,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* returns cardano base address by paymentKey and stakeKey
|
|
123
|
+
*/
|
|
124
|
+
export function getBaseAddress({
|
|
125
|
+
networkId,
|
|
126
|
+
paymentCred,
|
|
127
|
+
stakeCred,
|
|
128
|
+
}: {
|
|
129
|
+
networkId: number;
|
|
130
|
+
paymentCred: PaymentCredential;
|
|
131
|
+
stakeCred: StakeCredential;
|
|
132
|
+
}): TyphonAddress.BaseAddress {
|
|
133
|
+
const paymentCredential: TyphonTypes.HashCredential = {
|
|
134
|
+
hash: paymentCred.key,
|
|
135
|
+
type: TyphonTypes.HashType.ADDRESS,
|
|
136
|
+
bipPath: paymentCred.path,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const stakeCredential: TyphonTypes.HashCredential = {
|
|
140
|
+
hash: stakeCred.key,
|
|
141
|
+
type: TyphonTypes.HashType.ADDRESS,
|
|
142
|
+
bipPath: stakeCred.path,
|
|
143
|
+
};
|
|
144
|
+
return new TyphonAddress.BaseAddress(networkId, paymentCredential, stakeCredential);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Returns true if address is a valid
|
|
149
|
+
*
|
|
150
|
+
* @param {string} address
|
|
151
|
+
*/
|
|
152
|
+
export const isValidAddress = (address: string, networkId: number): boolean => {
|
|
153
|
+
if (!address) return false;
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
const cardanoAddress = TyphonUtils.getAddressFromBech32(address);
|
|
157
|
+
if (cardanoAddress instanceof ShelleyTypeAddress) {
|
|
158
|
+
const addressNetworkId = Number(cardanoAddress.getHex().toLowerCase().charAt(1));
|
|
159
|
+
if (addressNetworkId !== networkId) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
} catch (error) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export const getAbsoluteSlot = function (networkName: string, time: Date): number {
|
|
170
|
+
const networkParams = getNetworkParameters(networkName);
|
|
171
|
+
const byronChainEndSlots = networkParams.shelleyStartEpoch * networkParams.byronSlotsPerEpoch;
|
|
172
|
+
const byronChainEndTime = byronChainEndSlots * networkParams.byronSlotDuration;
|
|
173
|
+
|
|
174
|
+
const shelleyChainTime = time.getTime() - networkParams.chainStartTime - byronChainEndTime;
|
|
175
|
+
const shelleyChainSlots = Math.floor(shelleyChainTime / networkParams.shelleySlotDuration);
|
|
176
|
+
return byronChainEndSlots + shelleyChainSlots;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Returns the time to live for transaction
|
|
181
|
+
*
|
|
182
|
+
* @returns {number}
|
|
183
|
+
*/
|
|
184
|
+
export function getTTL(networkName: string): number {
|
|
185
|
+
return getAbsoluteSlot(networkName, new Date()) + TTL_GAP;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function getEpoch(networkName: string, time: Date): number {
|
|
189
|
+
const networkParams = getNetworkParameters(networkName);
|
|
190
|
+
const chainTime = time.getTime() - networkParams.chainStartTime;
|
|
191
|
+
const epoch = Math.floor(
|
|
192
|
+
chainTime / (networkParams.shelleySlotsPerEpoch * networkParams.shelleySlotDuration),
|
|
193
|
+
);
|
|
194
|
+
return epoch;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function mergeTokens(tokens: Array<TyphonTypes.Token>): Array<TyphonTypes.Token> {
|
|
198
|
+
return Object.values(groupBy(tokens, t => `${t.policyId}${t.assetName}`)).map(similarTokens => ({
|
|
199
|
+
policyId: similarTokens[0].policyId,
|
|
200
|
+
assetName: similarTokens[0].assetName,
|
|
201
|
+
amount: similarTokens.reduce((total, token) => total.plus(token.amount), new BigNumber(0)),
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @param { Array<TyphonTypes.Token> } b
|
|
207
|
+
* @param { Array<TyphonTypes.Token> } a
|
|
208
|
+
* @returns a - b
|
|
209
|
+
*/
|
|
210
|
+
export function getTokenDiff(
|
|
211
|
+
a: Array<TyphonTypes.Token>,
|
|
212
|
+
b: Array<TyphonTypes.Token>,
|
|
213
|
+
): Array<TyphonTypes.Token> {
|
|
214
|
+
return mergeTokens(a.concat(b.map(t => ({ ...t, amount: t.amount.negated() })))).filter(
|
|
215
|
+
t => !t.amount.eq(0),
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function getAccountStakeCredential(xpub: string, index: number): StakeCredential {
|
|
220
|
+
const accountXPubKey = getExtendedPublicKeyFromHex(xpub);
|
|
221
|
+
const keyPath = getCredentialKey(
|
|
222
|
+
accountXPubKey,
|
|
223
|
+
getBipPath({
|
|
224
|
+
account: index,
|
|
225
|
+
chain: StakeChain.stake,
|
|
226
|
+
index: STAKING_ADDRESS_INDEX,
|
|
227
|
+
}),
|
|
228
|
+
);
|
|
229
|
+
return {
|
|
230
|
+
key: keyPath.key,
|
|
231
|
+
path: keyPath.path,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function getOperationType({
|
|
236
|
+
valueChange,
|
|
237
|
+
fees,
|
|
238
|
+
}: {
|
|
239
|
+
valueChange: BigNumber;
|
|
240
|
+
fees: BigNumber;
|
|
241
|
+
}): OperationType {
|
|
242
|
+
return valueChange.isNegative()
|
|
243
|
+
? valueChange.absoluteValue().eq(fees)
|
|
244
|
+
? "FEES"
|
|
245
|
+
: "OUT"
|
|
246
|
+
: valueChange.isPositive()
|
|
247
|
+
? "IN"
|
|
248
|
+
: "NONE";
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function isTestnet(currency: CryptoCurrency): boolean {
|
|
252
|
+
return getCryptoCurrencyById(currency.id).isTestnetFor ? true : false;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function getAccountChange(
|
|
256
|
+
t: APITransaction,
|
|
257
|
+
accountCredentialsMap: Record<string, PaymentCredential>,
|
|
258
|
+
): { ada: BigNumber; tokens: Array<Token> } {
|
|
259
|
+
let accountInputAda = new BigNumber(0);
|
|
260
|
+
const accountInputTokens: Array<Token> = [];
|
|
261
|
+
t.inputs.forEach(i => {
|
|
262
|
+
if (accountCredentialsMap[i.paymentKey]) {
|
|
263
|
+
accountInputAda = accountInputAda.plus(i.value);
|
|
264
|
+
accountInputTokens.push(
|
|
265
|
+
...i.tokens.map(t => ({
|
|
266
|
+
assetName: t.assetName,
|
|
267
|
+
policyId: t.policyId,
|
|
268
|
+
amount: new BigNumber(t.value),
|
|
269
|
+
})),
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
let accountOutputAda = new BigNumber(0);
|
|
275
|
+
const accountOutputTokens: Array<Token> = [];
|
|
276
|
+
t.outputs.forEach(o => {
|
|
277
|
+
if (accountCredentialsMap[o.paymentKey]) {
|
|
278
|
+
accountOutputAda = accountOutputAda.plus(o.value);
|
|
279
|
+
accountOutputTokens.push(
|
|
280
|
+
...o.tokens.map(t => ({
|
|
281
|
+
assetName: t.assetName,
|
|
282
|
+
policyId: t.policyId,
|
|
283
|
+
amount: new BigNumber(t.value),
|
|
284
|
+
})),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
return {
|
|
290
|
+
ada: accountOutputAda.minus(accountInputAda),
|
|
291
|
+
tokens: getTokenDiff(accountOutputTokens, accountInputTokens),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function getMemoFromTx(tx: APITransaction): string | undefined {
|
|
296
|
+
let memo;
|
|
297
|
+
const metadataValue = tx.metadata?.data.find(m => m.label === MEMO_LABEL.toString());
|
|
298
|
+
if (metadataValue) {
|
|
299
|
+
try {
|
|
300
|
+
const parsedValue = JSON.parse(metadataValue.value);
|
|
301
|
+
if (parsedValue.msg && Array.isArray(parsedValue.msg) && parsedValue.msg.length) {
|
|
302
|
+
memo = parsedValue.msg.join(", ");
|
|
303
|
+
}
|
|
304
|
+
// eslint-disable-next-line no-empty
|
|
305
|
+
} catch (e) {}
|
|
306
|
+
}
|
|
307
|
+
return memo;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function isHexString(value: string): boolean {
|
|
311
|
+
const regExp = /^[0-9a-fA-F]+$/;
|
|
312
|
+
return regExp.test(value);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export function decodeTokenName(assetName: string): string {
|
|
316
|
+
if (assetName.length > 0) {
|
|
317
|
+
const bytes = [...Buffer.from(assetName, "hex")];
|
|
318
|
+
if (bytes.filter(byte => byte <= 32 || byte >= 127).length === 0) {
|
|
319
|
+
return String.fromCharCode(...bytes);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return assetName;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export function getBech32PoolId(poolId: string, networkName: string): string {
|
|
326
|
+
const networkParams = getNetworkParameters(networkName);
|
|
327
|
+
const words = bech32.toWords(Buffer.from(poolId, "hex"));
|
|
328
|
+
const encoded = bech32.encode(networkParams.poolIdPrefix, words, 1000);
|
|
329
|
+
return encoded;
|
|
330
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { canStake, isAlreadyStaking } from "./logic";
|
|
3
|
+
import { CardanoAccount } from "./types";
|
|
4
|
+
|
|
5
|
+
describe("canStake", () => {
|
|
6
|
+
it("should return false when acc has no funds", () => {
|
|
7
|
+
const accWithNoFunds = {
|
|
8
|
+
balance: new BigNumber(0),
|
|
9
|
+
} as CardanoAccount;
|
|
10
|
+
expect(canStake(accWithNoFunds)).toEqual(false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should return true when acc has funds", () => {
|
|
14
|
+
const accWithFunds = {
|
|
15
|
+
balance: new BigNumber(1),
|
|
16
|
+
} as CardanoAccount;
|
|
17
|
+
expect(canStake(accWithFunds)).toEqual(true);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("isAlreadyStaking", () => {
|
|
22
|
+
it("should return false when acc isn't delegating", () => {
|
|
23
|
+
const noResourcesAcc = {} as CardanoAccount;
|
|
24
|
+
expect(isAlreadyStaking(noResourcesAcc)).toEqual(false);
|
|
25
|
+
const noDelegationAcc = {
|
|
26
|
+
cardanoResources: {},
|
|
27
|
+
} as CardanoAccount;
|
|
28
|
+
expect(isAlreadyStaking(noDelegationAcc)).toEqual(false);
|
|
29
|
+
const noPoolIdAcc = { cardanoResources: { delegation: {} } } as CardanoAccount;
|
|
30
|
+
expect(isAlreadyStaking(noPoolIdAcc)).toEqual(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should return true when acc is delegating", () => {
|
|
34
|
+
const noResourcesAcc = {
|
|
35
|
+
cardanoResources: { delegation: { poolId: "itspoolid" } },
|
|
36
|
+
} as CardanoAccount;
|
|
37
|
+
expect(isAlreadyStaking(noResourcesAcc)).toEqual(true);
|
|
38
|
+
});
|
|
39
|
+
});
|
package/src/networks.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CardanoLikeNetworkParameters } from "./types";
|
|
2
|
+
|
|
3
|
+
export const getNetworkParameters = (networkName: string): CardanoLikeNetworkParameters => {
|
|
4
|
+
if (networkName === "cardano") {
|
|
5
|
+
return {
|
|
6
|
+
identifier: "cardano",
|
|
7
|
+
networkId: 1,
|
|
8
|
+
chainStartTime: 1506203091000,
|
|
9
|
+
byronSlotDuration: 20000,
|
|
10
|
+
byronSlotsPerEpoch: 21600,
|
|
11
|
+
shelleyStartEpoch: 208,
|
|
12
|
+
shelleySlotDuration: 1000,
|
|
13
|
+
shelleySlotsPerEpoch: 432000,
|
|
14
|
+
addressPrefix: "addr",
|
|
15
|
+
poolIdPrefix: "pool",
|
|
16
|
+
};
|
|
17
|
+
} else if (networkName === "cardano_testnet") {
|
|
18
|
+
return {
|
|
19
|
+
identifier: "cardano_testnet",
|
|
20
|
+
networkId: 0,
|
|
21
|
+
chainStartTime: 1563999616000,
|
|
22
|
+
byronSlotDuration: 20000,
|
|
23
|
+
byronSlotsPerEpoch: 21600,
|
|
24
|
+
shelleyStartEpoch: 74,
|
|
25
|
+
shelleySlotDuration: 1000,
|
|
26
|
+
shelleySlotsPerEpoch: 432000,
|
|
27
|
+
addressPrefix: "addr_test",
|
|
28
|
+
poolIdPrefix: "pool",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
throw new Error("No network parameters set for " + networkName);
|
|
33
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code reference taken from src/families/ethereum/postSyncPatch.ts
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { AccountLike, Operation } from "@ledgerhq/types-live";
|
|
6
|
+
import { CardanoAccount } from "./types";
|
|
7
|
+
|
|
8
|
+
// we need to preserve ADA pendingOperations because there is no mempool to do this
|
|
9
|
+
// we assume we need to preserve until:
|
|
10
|
+
// - that txid appears in operations
|
|
11
|
+
const postSyncPatchGen = <T extends AccountLike>(
|
|
12
|
+
initial: T,
|
|
13
|
+
synced: T,
|
|
14
|
+
parentPendingOperation?: Operation[],
|
|
15
|
+
): T => {
|
|
16
|
+
const pendingOperations = initial.pendingOperations || [];
|
|
17
|
+
if (pendingOperations.length === 0) return synced;
|
|
18
|
+
const { operations } = synced;
|
|
19
|
+
synced.pendingOperations = pendingOperations.filter(
|
|
20
|
+
op =>
|
|
21
|
+
(!parentPendingOperation || // a child pending parent need to disappear if parent ada op disappear
|
|
22
|
+
parentPendingOperation.some(o => o.hash === op.hash)) &&
|
|
23
|
+
!operations.some(o => o.hash === op.hash), // after retain logic, we need operation to appear
|
|
24
|
+
);
|
|
25
|
+
return synced;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const postSyncPatch = (initial: CardanoAccount, synced: CardanoAccount): CardanoAccount => {
|
|
29
|
+
const acc = postSyncPatchGen(initial, synced);
|
|
30
|
+
const { subAccounts, pendingOperations } = acc;
|
|
31
|
+
const initialSubAccounts = initial.subAccounts;
|
|
32
|
+
|
|
33
|
+
if (subAccounts && initialSubAccounts) {
|
|
34
|
+
acc.subAccounts = subAccounts.map(subAccount => {
|
|
35
|
+
const initialSubAccount = initialSubAccounts.find(a => a.id === subAccount.id);
|
|
36
|
+
if (!initialSubAccount) return subAccount;
|
|
37
|
+
return postSyncPatchGen(initialSubAccount, subAccount, pendingOperations);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return acc;
|
|
42
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { types as TyphonTypes, address as TyphonAddress } from "@stricahq/typhonjs";
|
|
3
|
+
import { defaultUpdateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
4
|
+
|
|
5
|
+
import { CardanoAccount, Transaction } from "./types";
|
|
6
|
+
import { buildTransaction } from "./buildTransaction";
|
|
7
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Prepare transaction before checking status
|
|
11
|
+
*
|
|
12
|
+
* @param {Account} account
|
|
13
|
+
* @param {Transaction} transaction
|
|
14
|
+
*/
|
|
15
|
+
export const prepareTransaction: AccountBridge<
|
|
16
|
+
Transaction,
|
|
17
|
+
CardanoAccount
|
|
18
|
+
>["prepareTransaction"] = async (account, transaction) => {
|
|
19
|
+
let patch = {};
|
|
20
|
+
try {
|
|
21
|
+
const cardanoTransaction = await buildTransaction(account, transaction);
|
|
22
|
+
const transactionFees = cardanoTransaction.getFee();
|
|
23
|
+
const transactionAmount = transaction.subAccountId
|
|
24
|
+
? transaction.amount
|
|
25
|
+
: cardanoTransaction
|
|
26
|
+
.getOutputs()
|
|
27
|
+
.filter(
|
|
28
|
+
o =>
|
|
29
|
+
!(o.address instanceof TyphonAddress.BaseAddress) ||
|
|
30
|
+
!(o.address.paymentCredential.type === TyphonTypes.HashType.ADDRESS) ||
|
|
31
|
+
o.address.paymentCredential.bipPath === undefined,
|
|
32
|
+
)
|
|
33
|
+
.reduce((total, o) => total.plus(o.amount), new BigNumber(0));
|
|
34
|
+
|
|
35
|
+
patch = { fees: transactionFees, amount: transactionAmount };
|
|
36
|
+
} catch (error) {
|
|
37
|
+
patch = { fees: new BigNumber(0), amount: transaction.amount };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return defaultUpdateTransaction(transaction, patch);
|
|
41
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type {
|
|
3
|
+
BipPath,
|
|
4
|
+
BipPathRaw,
|
|
5
|
+
CardanoDelegation,
|
|
6
|
+
CardanoDelegationRaw,
|
|
7
|
+
CardanoAccount,
|
|
8
|
+
CardanoAccountRaw,
|
|
9
|
+
CardanoOutput,
|
|
10
|
+
CardanoOutputRaw,
|
|
11
|
+
CardanoResources,
|
|
12
|
+
CardanoResourcesRaw,
|
|
13
|
+
PaymentCredential,
|
|
14
|
+
PaymentCredentialRaw,
|
|
15
|
+
ProtocolParams,
|
|
16
|
+
ProtocolParamsRaw,
|
|
17
|
+
Token,
|
|
18
|
+
TokenRaw,
|
|
19
|
+
} from "./types";
|
|
20
|
+
import { Account, AccountRaw } from "@ledgerhq/types-live";
|
|
21
|
+
|
|
22
|
+
function toTokenRaw({ assetName, policyId, amount }: Token): TokenRaw {
|
|
23
|
+
return {
|
|
24
|
+
assetName,
|
|
25
|
+
policyId,
|
|
26
|
+
amount: amount.toString(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function fromTokenRaw({ assetName, policyId, amount }: TokenRaw): Token {
|
|
31
|
+
return {
|
|
32
|
+
assetName,
|
|
33
|
+
policyId,
|
|
34
|
+
amount: new BigNumber(amount),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function toBipPathRaw({ purpose, coin, account, chain, index }: BipPath): BipPathRaw {
|
|
39
|
+
return {
|
|
40
|
+
purpose,
|
|
41
|
+
coin,
|
|
42
|
+
account,
|
|
43
|
+
chain,
|
|
44
|
+
index,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function fromBipPathRaw({ purpose, coin, account, chain, index }: BipPathRaw): BipPath {
|
|
49
|
+
return {
|
|
50
|
+
purpose,
|
|
51
|
+
coin,
|
|
52
|
+
account,
|
|
53
|
+
chain,
|
|
54
|
+
index,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function toPaymentCredentialRaw(r: PaymentCredential): PaymentCredentialRaw {
|
|
59
|
+
return {
|
|
60
|
+
isUsed: r.isUsed,
|
|
61
|
+
key: r.key,
|
|
62
|
+
path: toBipPathRaw(r.path),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function fromPaymentCredentialRaw(r: PaymentCredentialRaw): PaymentCredential {
|
|
67
|
+
return {
|
|
68
|
+
isUsed: r.isUsed,
|
|
69
|
+
key: r.key,
|
|
70
|
+
path: fromBipPathRaw(r.path),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function toCardanoOutputRaw({
|
|
75
|
+
hash,
|
|
76
|
+
index,
|
|
77
|
+
address,
|
|
78
|
+
amount,
|
|
79
|
+
tokens,
|
|
80
|
+
paymentCredential,
|
|
81
|
+
}: CardanoOutput): CardanoOutputRaw {
|
|
82
|
+
return {
|
|
83
|
+
hash,
|
|
84
|
+
index,
|
|
85
|
+
address,
|
|
86
|
+
amount: amount.toString(),
|
|
87
|
+
tokens: tokens.map(toTokenRaw),
|
|
88
|
+
paymentCredential,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function fromCardanoOutputRaw({
|
|
93
|
+
hash,
|
|
94
|
+
index,
|
|
95
|
+
address,
|
|
96
|
+
amount,
|
|
97
|
+
tokens,
|
|
98
|
+
paymentCredential,
|
|
99
|
+
}: CardanoOutputRaw): CardanoOutput {
|
|
100
|
+
return {
|
|
101
|
+
hash,
|
|
102
|
+
index,
|
|
103
|
+
address,
|
|
104
|
+
amount: new BigNumber(amount),
|
|
105
|
+
tokens: tokens.map(fromTokenRaw),
|
|
106
|
+
paymentCredential,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function toProtocolParamsRaw({
|
|
111
|
+
minFeeA,
|
|
112
|
+
minFeeB,
|
|
113
|
+
stakeKeyDeposit,
|
|
114
|
+
lovelacePerUtxoWord,
|
|
115
|
+
collateralPercent,
|
|
116
|
+
priceSteps,
|
|
117
|
+
priceMem,
|
|
118
|
+
languageView,
|
|
119
|
+
}: ProtocolParams): ProtocolParamsRaw {
|
|
120
|
+
return {
|
|
121
|
+
minFeeA,
|
|
122
|
+
minFeeB,
|
|
123
|
+
stakeKeyDeposit,
|
|
124
|
+
lovelacePerUtxoWord,
|
|
125
|
+
collateralPercent,
|
|
126
|
+
priceSteps,
|
|
127
|
+
priceMem,
|
|
128
|
+
languageView,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function fromProtocolParamsRaw({
|
|
133
|
+
minFeeA,
|
|
134
|
+
minFeeB,
|
|
135
|
+
stakeKeyDeposit,
|
|
136
|
+
lovelacePerUtxoWord,
|
|
137
|
+
collateralPercent,
|
|
138
|
+
priceSteps,
|
|
139
|
+
priceMem,
|
|
140
|
+
languageView,
|
|
141
|
+
}: ProtocolParamsRaw): ProtocolParams {
|
|
142
|
+
return {
|
|
143
|
+
minFeeA,
|
|
144
|
+
minFeeB,
|
|
145
|
+
stakeKeyDeposit,
|
|
146
|
+
lovelacePerUtxoWord,
|
|
147
|
+
collateralPercent,
|
|
148
|
+
priceSteps,
|
|
149
|
+
priceMem,
|
|
150
|
+
languageView,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function toDelegationRaw({
|
|
155
|
+
status,
|
|
156
|
+
poolId,
|
|
157
|
+
ticker,
|
|
158
|
+
name,
|
|
159
|
+
rewards,
|
|
160
|
+
}: CardanoDelegation): CardanoDelegationRaw {
|
|
161
|
+
return {
|
|
162
|
+
status,
|
|
163
|
+
poolId,
|
|
164
|
+
ticker,
|
|
165
|
+
name,
|
|
166
|
+
rewards: rewards.toString(),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function fromDelegationRaw({
|
|
171
|
+
status,
|
|
172
|
+
poolId,
|
|
173
|
+
ticker,
|
|
174
|
+
name,
|
|
175
|
+
rewards,
|
|
176
|
+
}: CardanoDelegationRaw): CardanoDelegation {
|
|
177
|
+
return {
|
|
178
|
+
status,
|
|
179
|
+
poolId,
|
|
180
|
+
ticker,
|
|
181
|
+
name,
|
|
182
|
+
rewards: new BigNumber(rewards),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function toCardanoResourceRaw(r: CardanoResources): CardanoResourcesRaw {
|
|
187
|
+
return {
|
|
188
|
+
internalCredentials: r.internalCredentials.map(toPaymentCredentialRaw),
|
|
189
|
+
externalCredentials: r.externalCredentials.map(toPaymentCredentialRaw),
|
|
190
|
+
delegation: r.delegation ? toDelegationRaw(r.delegation) : undefined,
|
|
191
|
+
utxos: r.utxos.map(toCardanoOutputRaw),
|
|
192
|
+
protocolParams: toProtocolParamsRaw(r.protocolParams),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function fromCardanoResourceRaw(r: CardanoResourcesRaw): CardanoResources {
|
|
197
|
+
return {
|
|
198
|
+
internalCredentials: r.internalCredentials.map(fromPaymentCredentialRaw),
|
|
199
|
+
externalCredentials: r.externalCredentials.map(fromPaymentCredentialRaw),
|
|
200
|
+
delegation: r.delegation ? fromDelegationRaw(r.delegation) : undefined,
|
|
201
|
+
utxos: r.utxos.map(fromCardanoOutputRaw),
|
|
202
|
+
protocolParams: fromProtocolParamsRaw(r.protocolParams),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function assignToAccountRaw(account: Account, accountRaw: AccountRaw): void {
|
|
207
|
+
const cardanoAccount = account as CardanoAccount;
|
|
208
|
+
if (cardanoAccount.cardanoResources) {
|
|
209
|
+
(accountRaw as CardanoAccountRaw).cardanoResources = toCardanoResourceRaw(
|
|
210
|
+
cardanoAccount.cardanoResources,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function assignFromAccountRaw(accountRaw: AccountRaw, account: Account) {
|
|
216
|
+
const cardanoResourcesRaw = (accountRaw as CardanoAccountRaw).cardanoResources;
|
|
217
|
+
if (cardanoResourcesRaw)
|
|
218
|
+
(account as CardanoAccount).cardanoResources = fromCardanoResourceRaw(cardanoResourcesRaw);
|
|
219
|
+
}
|