@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,115 @@
|
|
|
1
|
+
import { ProtocolParams } from "../types";
|
|
2
|
+
|
|
3
|
+
type APIToken = { assetName: string; policyId: string; value: string };
|
|
4
|
+
|
|
5
|
+
type APIMetadata = { label: string; value: string };
|
|
6
|
+
|
|
7
|
+
export enum HashType {
|
|
8
|
+
ADDRESS = "ADDRESS",
|
|
9
|
+
SCRIPT = "SCRIPT",
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type StakeCredential = {
|
|
13
|
+
key: string;
|
|
14
|
+
type: HashType;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type StakeKeyRegistrationCertificate = {
|
|
18
|
+
index: number;
|
|
19
|
+
stakeCredential: StakeCredential;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type StakeKeyDeRegistrationCertificate = {
|
|
23
|
+
index: number;
|
|
24
|
+
stakeCredential: StakeCredential;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type StakeDelegationCertificate = {
|
|
28
|
+
index: number;
|
|
29
|
+
poolKeyHash: string;
|
|
30
|
+
stakeCredential: StakeCredential;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type TransactionCertificate =
|
|
34
|
+
| StakeKeyRegistrationCertificate
|
|
35
|
+
| StakeKeyDeRegistrationCertificate
|
|
36
|
+
| StakeDelegationCertificate;
|
|
37
|
+
|
|
38
|
+
export type TransactionCertificates = {
|
|
39
|
+
stakeRegistrations: Array<StakeKeyRegistrationCertificate>;
|
|
40
|
+
stakeDeRegistrations: Array<StakeKeyDeRegistrationCertificate>;
|
|
41
|
+
stakeDelegations: Array<StakeDelegationCertificate>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type APITransaction = {
|
|
45
|
+
fees: string;
|
|
46
|
+
hash: string;
|
|
47
|
+
timestamp: string;
|
|
48
|
+
blockHeight: number;
|
|
49
|
+
inputs: Array<{
|
|
50
|
+
txId: string;
|
|
51
|
+
index: number;
|
|
52
|
+
address: string;
|
|
53
|
+
value: string;
|
|
54
|
+
paymentKey: string;
|
|
55
|
+
tokens: Array<APIToken>;
|
|
56
|
+
}>;
|
|
57
|
+
certificate: TransactionCertificates;
|
|
58
|
+
outputs: Array<{
|
|
59
|
+
address: string;
|
|
60
|
+
value: string;
|
|
61
|
+
paymentKey: string;
|
|
62
|
+
tokens: Array<APIToken>;
|
|
63
|
+
}>;
|
|
64
|
+
metadata?: {
|
|
65
|
+
hash: string;
|
|
66
|
+
data: Array<APIMetadata>;
|
|
67
|
+
};
|
|
68
|
+
withdrawals?: Array<{
|
|
69
|
+
stakeCredential: StakeCredential;
|
|
70
|
+
amount: string;
|
|
71
|
+
}>;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type APINetworkInfo = {
|
|
75
|
+
protocolParams: ProtocolParams;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type APIDelegation = {
|
|
79
|
+
status: boolean;
|
|
80
|
+
stakeCredential: {
|
|
81
|
+
key: string;
|
|
82
|
+
type: string;
|
|
83
|
+
};
|
|
84
|
+
stake: string;
|
|
85
|
+
rewardsAvailable: string;
|
|
86
|
+
rewardsWithdrawn: string;
|
|
87
|
+
poolInfo: {
|
|
88
|
+
poolId: string;
|
|
89
|
+
name: string;
|
|
90
|
+
ticker: string;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type StakePool = {
|
|
95
|
+
poolId: string;
|
|
96
|
+
name: string | undefined;
|
|
97
|
+
ticker: string | undefined;
|
|
98
|
+
website: string | undefined;
|
|
99
|
+
margin: string;
|
|
100
|
+
cost: string;
|
|
101
|
+
pledge: string;
|
|
102
|
+
retiredEpoch: number | undefined;
|
|
103
|
+
liveStake: string;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type APIGetPoolList = {
|
|
107
|
+
pageNo: number;
|
|
108
|
+
limit: number;
|
|
109
|
+
count: number;
|
|
110
|
+
pools: Array<StakePool>;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type APIGetPoolsDetail = {
|
|
114
|
+
pools: Array<StakePool>;
|
|
115
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import network from "@ledgerhq/live-network/network";
|
|
4
|
+
import { CARDANO_API_ENDPOINT, CARDANO_TESTNET_API_ENDPOINT } from "../constants";
|
|
5
|
+
import { isTestnet } from "../logic";
|
|
6
|
+
import { CardanoDelegation } from "../types";
|
|
7
|
+
import { APIDelegation } from "./api-types";
|
|
8
|
+
|
|
9
|
+
async function fetchDelegationInfo(
|
|
10
|
+
currency: CryptoCurrency,
|
|
11
|
+
stakeKey: string,
|
|
12
|
+
): Promise<APIDelegation> {
|
|
13
|
+
const res = await network({
|
|
14
|
+
method: "GET",
|
|
15
|
+
url: isTestnet(currency)
|
|
16
|
+
? `${CARDANO_TESTNET_API_ENDPOINT}/v1/delegation`
|
|
17
|
+
: `${CARDANO_API_ENDPOINT}/v1/delegation`,
|
|
18
|
+
params: {
|
|
19
|
+
stakeKey,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
return res && res.data && (res.data.delegation as APIDelegation);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function getDelegationInfo(
|
|
26
|
+
currency: CryptoCurrency,
|
|
27
|
+
stakeKey: string,
|
|
28
|
+
): Promise<CardanoDelegation | undefined> {
|
|
29
|
+
const res = await fetchDelegationInfo(currency, stakeKey);
|
|
30
|
+
return (
|
|
31
|
+
res && {
|
|
32
|
+
status: res.status,
|
|
33
|
+
poolId: res.poolInfo?.poolId,
|
|
34
|
+
ticker: res.poolInfo?.ticker,
|
|
35
|
+
name: res.poolInfo?.name,
|
|
36
|
+
rewards: new BigNumber(res.rewardsAvailable),
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import network from "@ledgerhq/live-network/network";
|
|
2
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import { CARDANO_API_ENDPOINT, CARDANO_TESTNET_API_ENDPOINT } from "../constants";
|
|
4
|
+
import { getEpoch, isTestnet } from "../logic";
|
|
5
|
+
import { CardanoAccount } from "../types";
|
|
6
|
+
import { APINetworkInfo } from "./api-types";
|
|
7
|
+
|
|
8
|
+
async function fetchNetworkInfo(currency: CryptoCurrency): Promise<APINetworkInfo> {
|
|
9
|
+
const res = await network({
|
|
10
|
+
method: "GET",
|
|
11
|
+
url: isTestnet(currency)
|
|
12
|
+
? `${CARDANO_TESTNET_API_ENDPOINT}/v1/network/info`
|
|
13
|
+
: `${CARDANO_API_ENDPOINT}/v1/network/info`,
|
|
14
|
+
});
|
|
15
|
+
return res && (res.data as APINetworkInfo);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function getNetworkInfo(
|
|
19
|
+
a: CardanoAccount | undefined,
|
|
20
|
+
currency: CryptoCurrency,
|
|
21
|
+
): Promise<APINetworkInfo> {
|
|
22
|
+
if (a && a.cardanoResources) {
|
|
23
|
+
const currencyId = a.currency.id;
|
|
24
|
+
const currentEpoch = getEpoch(currencyId, new Date());
|
|
25
|
+
const lastSyncedEpoch = getEpoch(currencyId, a.lastSyncDate);
|
|
26
|
+
|
|
27
|
+
if (currentEpoch === lastSyncedEpoch) {
|
|
28
|
+
return {
|
|
29
|
+
protocolParams: a.cardanoResources.protocolParams,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return fetchNetworkInfo(currency);
|
|
34
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { APIGetPoolList, APIGetPoolsDetail } from "./api-types";
|
|
2
|
+
import { isTestnet } from "../logic";
|
|
3
|
+
import { CARDANO_API_ENDPOINT, CARDANO_TESTNET_API_ENDPOINT } from "../constants";
|
|
4
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
5
|
+
import network from "@ledgerhq/live-network/network";
|
|
6
|
+
|
|
7
|
+
export async function fetchPoolList(
|
|
8
|
+
currency: CryptoCurrency,
|
|
9
|
+
search: string,
|
|
10
|
+
pageNo: number,
|
|
11
|
+
limit: number,
|
|
12
|
+
): Promise<APIGetPoolList> {
|
|
13
|
+
const res = await network({
|
|
14
|
+
method: "GET",
|
|
15
|
+
url: isTestnet(currency)
|
|
16
|
+
? `${CARDANO_TESTNET_API_ENDPOINT}/v1/pool/list`
|
|
17
|
+
: `${CARDANO_API_ENDPOINT}/v1/pool/list`,
|
|
18
|
+
params: { search, pageNo, limit },
|
|
19
|
+
});
|
|
20
|
+
return res && (res.data as APIGetPoolList);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function fetchPoolDetails(
|
|
24
|
+
currency: CryptoCurrency,
|
|
25
|
+
poolIds: Array<string>,
|
|
26
|
+
): Promise<APIGetPoolsDetail> {
|
|
27
|
+
const res = await network({
|
|
28
|
+
method: "GET",
|
|
29
|
+
url: isTestnet(currency)
|
|
30
|
+
? `${CARDANO_TESTNET_API_ENDPOINT}/v1/pool/detail`
|
|
31
|
+
: `${CARDANO_API_ENDPOINT}/v1/pool/detail`,
|
|
32
|
+
params: { poolIds },
|
|
33
|
+
});
|
|
34
|
+
return res && (res.data as APIGetPoolsDetail);
|
|
35
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import network from "@ledgerhq/live-network/network";
|
|
2
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import { Bip32PublicKey } from "@stricahq/bip32ed25519";
|
|
4
|
+
import chunk from "lodash/chunk";
|
|
5
|
+
import range from "lodash/range";
|
|
6
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
7
|
+
import { CARDANO_API_ENDPOINT, CARDANO_TESTNET_API_ENDPOINT } from "../constants";
|
|
8
|
+
import { getBipPath, getCredentialKey, getExtendedPublicKeyFromHex, isTestnet } from "../logic";
|
|
9
|
+
import { CardanoAccount, PaymentChain, PaymentCredential } from "../types";
|
|
10
|
+
import * as ApiTypes from "./api-types";
|
|
11
|
+
import { APITransaction } from "./api-types";
|
|
12
|
+
|
|
13
|
+
async function fetchTransactions(
|
|
14
|
+
paymentKeys: Array<string>,
|
|
15
|
+
pageNo: number,
|
|
16
|
+
blockHeight: number,
|
|
17
|
+
currency: CryptoCurrency,
|
|
18
|
+
): Promise<{
|
|
19
|
+
pageNo: number;
|
|
20
|
+
limit: number;
|
|
21
|
+
blockHeight: number;
|
|
22
|
+
transactions: Array<APITransaction>;
|
|
23
|
+
}> {
|
|
24
|
+
const res = await network({
|
|
25
|
+
method: "POST",
|
|
26
|
+
url: isTestnet(currency)
|
|
27
|
+
? `${CARDANO_TESTNET_API_ENDPOINT}/v1/transaction`
|
|
28
|
+
: `${CARDANO_API_ENDPOINT}/v1/transaction`,
|
|
29
|
+
data: {
|
|
30
|
+
paymentKeys,
|
|
31
|
+
pageNo,
|
|
32
|
+
blockHeight,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
return res.data;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function getAllTransactionsByKeys(
|
|
39
|
+
paymentKeys: Array<string>,
|
|
40
|
+
blockHeight: number,
|
|
41
|
+
currency: CryptoCurrency,
|
|
42
|
+
): Promise<{
|
|
43
|
+
transactions: Array<ApiTypes.APITransaction>;
|
|
44
|
+
blockHeight: number;
|
|
45
|
+
}> {
|
|
46
|
+
const transactions: Array<ApiTypes.APITransaction> = [];
|
|
47
|
+
let latestBlockHeight = 0;
|
|
48
|
+
let isAllTrxFetched = false;
|
|
49
|
+
let pageNo = 1;
|
|
50
|
+
|
|
51
|
+
while (!isAllTrxFetched) {
|
|
52
|
+
const res = await fetchTransactions(paymentKeys, pageNo, blockHeight, currency);
|
|
53
|
+
transactions.push(...res.transactions);
|
|
54
|
+
latestBlockHeight = Math.max(res.blockHeight, latestBlockHeight);
|
|
55
|
+
isAllTrxFetched = res.transactions.length < res.limit;
|
|
56
|
+
pageNo += 1;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
transactions,
|
|
60
|
+
blockHeight: latestBlockHeight,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function getSyncedTransactionsByChain(
|
|
65
|
+
accountPubKey: Bip32PublicKey,
|
|
66
|
+
accountIndex: number,
|
|
67
|
+
chainType: PaymentChain,
|
|
68
|
+
blockHeight: number,
|
|
69
|
+
initialPaymentCredentials: Array<PaymentCredential>,
|
|
70
|
+
currency: CryptoCurrency,
|
|
71
|
+
): Promise<{
|
|
72
|
+
transactions: Array<ApiTypes.APITransaction>;
|
|
73
|
+
latestBlockHeight: number;
|
|
74
|
+
paymentCredentials: Array<PaymentCredential>;
|
|
75
|
+
}> {
|
|
76
|
+
const keyChainRange = getEnv("KEYCHAIN_OBSERVABLE_RANGE") || 20;
|
|
77
|
+
|
|
78
|
+
// credentialsMap for efficient use
|
|
79
|
+
const initialPaymentCredentialMap: Record<string, PaymentCredential> = {};
|
|
80
|
+
let maxUsedKeyIndex = -1;
|
|
81
|
+
initialPaymentCredentials.forEach(cred => {
|
|
82
|
+
initialPaymentCredentialMap[cred.key] = cred;
|
|
83
|
+
if (cred.isUsed) maxUsedKeyIndex = cred.path.index;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const transactions: Array<ApiTypes.APITransaction> = [];
|
|
87
|
+
let latestBlockHeight = 0;
|
|
88
|
+
|
|
89
|
+
// fetch transactions for existing keys
|
|
90
|
+
const trxsRes = await Promise.all(
|
|
91
|
+
chunk(Object.keys(initialPaymentCredentialMap), keyChainRange).map(keys =>
|
|
92
|
+
getAllTransactionsByKeys(keys, blockHeight, currency),
|
|
93
|
+
),
|
|
94
|
+
);
|
|
95
|
+
trxsRes.forEach(txRes => {
|
|
96
|
+
transactions.push(...txRes.transactions);
|
|
97
|
+
latestBlockHeight = Math.max(latestBlockHeight, txRes.blockHeight);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// fetch transactions for new avaialble keys
|
|
101
|
+
let newPaymentCredentialsMap: Record<string, PaymentCredential> = {};
|
|
102
|
+
let lastSyncedKeyIndex = initialPaymentCredentials.length
|
|
103
|
+
? initialPaymentCredentials[initialPaymentCredentials.length - 1].path.index
|
|
104
|
+
: -1;
|
|
105
|
+
let syncToKeyIndex = maxUsedKeyIndex + keyChainRange;
|
|
106
|
+
while (syncToKeyIndex !== lastSyncedKeyIndex) {
|
|
107
|
+
const currentPaymentKeysMap: Record<string, PaymentCredential> = {};
|
|
108
|
+
range(lastSyncedKeyIndex + 1, syncToKeyIndex + 1, 1).forEach(keyIndex => {
|
|
109
|
+
const keyPath = getCredentialKey(
|
|
110
|
+
accountPubKey,
|
|
111
|
+
getBipPath({
|
|
112
|
+
account: accountIndex,
|
|
113
|
+
chain: chainType,
|
|
114
|
+
index: keyIndex,
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
currentPaymentKeysMap[keyPath.key] = {
|
|
118
|
+
isUsed: false,
|
|
119
|
+
key: keyPath.key,
|
|
120
|
+
path: keyPath.path,
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
const trxRes = await getAllTransactionsByKeys(
|
|
124
|
+
Object.keys(currentPaymentKeysMap),
|
|
125
|
+
blockHeight,
|
|
126
|
+
currency,
|
|
127
|
+
);
|
|
128
|
+
transactions.push(...trxRes.transactions);
|
|
129
|
+
|
|
130
|
+
lastSyncedKeyIndex = syncToKeyIndex;
|
|
131
|
+
latestBlockHeight = Math.max(latestBlockHeight, trxRes.blockHeight);
|
|
132
|
+
newPaymentCredentialsMap = Object.assign({}, newPaymentCredentialsMap, currentPaymentKeysMap);
|
|
133
|
+
maxUsedKeyIndex = trxRes.transactions.reduce(
|
|
134
|
+
(maxIndexA, { inputs, outputs }) =>
|
|
135
|
+
[...inputs, ...outputs].reduce(
|
|
136
|
+
(maxIndexB, io) =>
|
|
137
|
+
Math.max(newPaymentCredentialsMap[io.paymentKey]?.path.index || -1, maxIndexB),
|
|
138
|
+
maxIndexA,
|
|
139
|
+
),
|
|
140
|
+
maxUsedKeyIndex,
|
|
141
|
+
);
|
|
142
|
+
syncToKeyIndex = maxUsedKeyIndex + keyChainRange;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const availablePaymentCredentialsMap = {
|
|
146
|
+
...initialPaymentCredentialMap,
|
|
147
|
+
...newPaymentCredentialsMap,
|
|
148
|
+
};
|
|
149
|
+
transactions.forEach(trx => {
|
|
150
|
+
[...trx.inputs, ...trx.outputs].forEach(io => {
|
|
151
|
+
if (availablePaymentCredentialsMap[io.paymentKey]) {
|
|
152
|
+
availablePaymentCredentialsMap[io.paymentKey].isUsed = true;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
transactions,
|
|
159
|
+
latestBlockHeight,
|
|
160
|
+
paymentCredentials: Object.values(availablePaymentCredentialsMap).sort(
|
|
161
|
+
(aCred, bCred) => aCred.path.index - bCred.path.index,
|
|
162
|
+
),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function getTransactions(
|
|
167
|
+
xpub: string,
|
|
168
|
+
accountIndex: number,
|
|
169
|
+
initialAccount: CardanoAccount | undefined,
|
|
170
|
+
blockHeight: number,
|
|
171
|
+
currency: CryptoCurrency,
|
|
172
|
+
): Promise<{
|
|
173
|
+
transactions: Array<ApiTypes.APITransaction>;
|
|
174
|
+
blockHeight: number;
|
|
175
|
+
externalCredentials: Array<PaymentCredential>;
|
|
176
|
+
internalCredentials: Array<PaymentCredential>;
|
|
177
|
+
}> {
|
|
178
|
+
const accountPubKey = getExtendedPublicKeyFromHex(xpub);
|
|
179
|
+
const oldExternalCredentials = initialAccount?.cardanoResources?.externalCredentials || [];
|
|
180
|
+
const oldInternalCredentials = initialAccount?.cardanoResources?.internalCredentials || [];
|
|
181
|
+
|
|
182
|
+
const [
|
|
183
|
+
{
|
|
184
|
+
transactions: externalKeyTransactions,
|
|
185
|
+
latestBlockHeight: aBlockHeight,
|
|
186
|
+
paymentCredentials: externalCredentials,
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
transactions: internalKeyTransactions,
|
|
190
|
+
latestBlockHeight: bBlockHeight,
|
|
191
|
+
paymentCredentials: internalCredentials,
|
|
192
|
+
},
|
|
193
|
+
] = await Promise.all([
|
|
194
|
+
getSyncedTransactionsByChain(
|
|
195
|
+
accountPubKey,
|
|
196
|
+
accountIndex,
|
|
197
|
+
PaymentChain.external,
|
|
198
|
+
blockHeight,
|
|
199
|
+
oldExternalCredentials,
|
|
200
|
+
currency,
|
|
201
|
+
),
|
|
202
|
+
getSyncedTransactionsByChain(
|
|
203
|
+
accountPubKey,
|
|
204
|
+
accountIndex,
|
|
205
|
+
PaymentChain.internal,
|
|
206
|
+
blockHeight,
|
|
207
|
+
oldInternalCredentials,
|
|
208
|
+
currency,
|
|
209
|
+
),
|
|
210
|
+
]);
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
transactions: [...externalKeyTransactions, ...internalKeyTransactions],
|
|
214
|
+
blockHeight: Math.max(aBlockHeight, bBlockHeight),
|
|
215
|
+
externalCredentials,
|
|
216
|
+
internalCredentials,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import network from "@ledgerhq/live-network/network";
|
|
2
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import { CARDANO_API_ENDPOINT, CARDANO_TESTNET_API_ENDPOINT } from "../constants";
|
|
4
|
+
import { isTestnet } from "../logic";
|
|
5
|
+
import { APITransaction } from "./api-types";
|
|
6
|
+
|
|
7
|
+
export async function submitTransaction({
|
|
8
|
+
transaction,
|
|
9
|
+
currency,
|
|
10
|
+
}: {
|
|
11
|
+
transaction: string;
|
|
12
|
+
currency: CryptoCurrency;
|
|
13
|
+
}): Promise<APITransaction> {
|
|
14
|
+
const res = await network({
|
|
15
|
+
method: "POST",
|
|
16
|
+
url: isTestnet(currency)
|
|
17
|
+
? `${CARDANO_TESTNET_API_ENDPOINT}/v1/transaction/submit`
|
|
18
|
+
: `${CARDANO_API_ENDPOINT}/v1/transaction/submit`,
|
|
19
|
+
data: {
|
|
20
|
+
transaction: transaction,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return res.data.transaction;
|
|
24
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultUpdateTransaction,
|
|
3
|
+
makeAccountBridgeReceive,
|
|
4
|
+
makeScanAccounts,
|
|
5
|
+
makeSync,
|
|
6
|
+
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
7
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
8
|
+
import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
9
|
+
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
10
|
+
import type { CardanoAccount, Transaction, TransactionStatus } from "../types";
|
|
11
|
+
import { assignToAccountRaw, assignFromAccountRaw } from "../serialization";
|
|
12
|
+
import { estimateMaxSpendable } from "../estimateMaxSpendable";
|
|
13
|
+
import { getTransactionStatus } from "../getTransactionStatus";
|
|
14
|
+
import { prepareTransaction } from "../prepareTransaction";
|
|
15
|
+
import { createTransaction } from "../createTransaction";
|
|
16
|
+
import { makeGetAccountShape } from "../synchronisation";
|
|
17
|
+
import { buildSignOperation } from "../signOperation";
|
|
18
|
+
import { postSyncPatch } from "../postSyncPatch";
|
|
19
|
+
import { CardanoSigner } from "../signer";
|
|
20
|
+
import { broadcast } from "../broadcast";
|
|
21
|
+
import resolver from "../hw-getAddress";
|
|
22
|
+
|
|
23
|
+
export function buildCurrencyBridge(signerContext: SignerContext<CardanoSigner>): CurrencyBridge {
|
|
24
|
+
const getAddress = resolver(signerContext);
|
|
25
|
+
const scanAccounts = makeScanAccounts({
|
|
26
|
+
getAccountShape: makeGetAccountShape(signerContext),
|
|
27
|
+
getAddressFn: getAddressWrapper(getAddress),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
scanAccounts,
|
|
32
|
+
preload: async () => ({}),
|
|
33
|
+
hydrate: () => {},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function buildAccountBridge(
|
|
38
|
+
signerContext: SignerContext<CardanoSigner>,
|
|
39
|
+
): AccountBridge<Transaction, CardanoAccount, TransactionStatus> {
|
|
40
|
+
const sync = makeSync({
|
|
41
|
+
getAccountShape: makeGetAccountShape(signerContext),
|
|
42
|
+
postSync: postSyncPatch,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const getAddress = resolver(signerContext);
|
|
46
|
+
|
|
47
|
+
const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
estimateMaxSpendable,
|
|
51
|
+
createTransaction,
|
|
52
|
+
updateTransaction: defaultUpdateTransaction,
|
|
53
|
+
getTransactionStatus,
|
|
54
|
+
prepareTransaction,
|
|
55
|
+
sync,
|
|
56
|
+
receive,
|
|
57
|
+
signOperation: buildSignOperation(signerContext),
|
|
58
|
+
broadcast,
|
|
59
|
+
assignToAccountRaw,
|
|
60
|
+
assignFromAccountRaw,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createBridges(signerContext: SignerContext<CardanoSigner>) {
|
|
65
|
+
return {
|
|
66
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
67
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { cardanoRawAccount1 } from "./datasets/rawAccount.1";
|
|
3
|
+
import { cardanoScanAccounts } from "./datasets/scanAccounts";
|
|
4
|
+
import { CardanoInvalidPoolId, CardanoMinAmountError } from "./errors";
|
|
5
|
+
import { fromTransactionRaw } from "./transaction";
|
|
6
|
+
import type { Transaction } from "./types";
|
|
7
|
+
import type { DatasetTest } from "@ledgerhq/types-live";
|
|
8
|
+
|
|
9
|
+
export const dataset: DatasetTest<Transaction> = {
|
|
10
|
+
implementations: ["js"],
|
|
11
|
+
currencies: {
|
|
12
|
+
cardano_testnet: {
|
|
13
|
+
scanAccounts: cardanoScanAccounts,
|
|
14
|
+
accounts: [
|
|
15
|
+
{
|
|
16
|
+
raw: cardanoRawAccount1,
|
|
17
|
+
transactions: [
|
|
18
|
+
{
|
|
19
|
+
name: "amount less then minimum",
|
|
20
|
+
transaction: fromTransactionRaw({
|
|
21
|
+
family: "cardano",
|
|
22
|
+
recipient:
|
|
23
|
+
"addr_test1qpl90kc2jl5kr9tev0s7vays9yhwcdnq8nlylyk4dqsdq3g466elxnxwrzwq72pvp5akenj30t5s9et7frfvrxxx8xcsxrzs87",
|
|
24
|
+
amount: "0.1",
|
|
25
|
+
mode: "send",
|
|
26
|
+
poolId: undefined,
|
|
27
|
+
}),
|
|
28
|
+
expectedStatus: {
|
|
29
|
+
amount: new BigNumber("0.1"),
|
|
30
|
+
errors: {
|
|
31
|
+
amount: new CardanoMinAmountError(),
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
/* // FIXME broken test
|
|
36
|
+
{
|
|
37
|
+
name: "token amount more than balance",
|
|
38
|
+
transaction: fromTransactionRaw({
|
|
39
|
+
family: "cardano",
|
|
40
|
+
recipient:
|
|
41
|
+
"addr_test1qpl90kc2jl5kr9tev0s7vays9yhwcdnq8nlylyk4dqsdq3g466elxnxwrzwq72pvp5akenj30t5s9et7frfvrxxx8xcsxrzs87",
|
|
42
|
+
amount: "101",
|
|
43
|
+
subAccountId:
|
|
44
|
+
"js:2:cardano_testnet:806499588e0c4a58f4119f7e6e096bf42c3f774a528d2acec9e82ceebf87d1ceb3d4f3622dd2c77c65cc89c123f79337db22cf8a69f122e36dab1bf5083bf82d:cardano+cardano_testnet%2Fnative%2F47be64fcc8a7fe5321b976282ce4e43e4d29015f6613cfabcea28eab54657374",
|
|
45
|
+
mode: "send",
|
|
46
|
+
poolId: undefined,
|
|
47
|
+
}),
|
|
48
|
+
expectedStatus: {
|
|
49
|
+
amount: new BigNumber("101"),
|
|
50
|
+
errors: {
|
|
51
|
+
amount: new NotEnoughBalance(),
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "send max token",
|
|
57
|
+
transaction: fromTransactionRaw({
|
|
58
|
+
family: "cardano",
|
|
59
|
+
recipient:
|
|
60
|
+
"addr_test1qpl90kc2jl5kr9tev0s7vays9yhwcdnq8nlylyk4dqsdq3g466elxnxwrzwq72pvp5akenj30t5s9et7frfvrxxx8xcsxrzs87",
|
|
61
|
+
amount: "0",
|
|
62
|
+
subAccountId:
|
|
63
|
+
"js:2:cardano_testnet:806499588e0c4a58f4119f7e6e096bf42c3f774a528d2acec9e82ceebf87d1ceb3d4f3622dd2c77c65cc89c123f79337db22cf8a69f122e36dab1bf5083bf82d:cardano+cardano_testnet%2Fnative%2F47be64fcc8a7fe5321b976282ce4e43e4d29015f6613cfabcea28eab54657374",
|
|
64
|
+
mode: "send",
|
|
65
|
+
useAllAmount: true,
|
|
66
|
+
poolId: undefined,
|
|
67
|
+
}),
|
|
68
|
+
expectedStatus: {
|
|
69
|
+
amount: new BigNumber("100"),
|
|
70
|
+
totalSpent: new BigNumber("100"),
|
|
71
|
+
errors: {},
|
|
72
|
+
warnings: {},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
*/
|
|
76
|
+
{
|
|
77
|
+
name: "delegate to invalid poolId",
|
|
78
|
+
transaction: fromTransactionRaw({
|
|
79
|
+
family: "cardano",
|
|
80
|
+
recipient: "",
|
|
81
|
+
amount: "0",
|
|
82
|
+
mode: "delegate",
|
|
83
|
+
poolId: "efae72c07a26e4542ba55ef59d35ad45ffaaac312865e3a758ede",
|
|
84
|
+
}),
|
|
85
|
+
expectedStatus: {
|
|
86
|
+
errors: {
|
|
87
|
+
poolId: new CardanoInvalidPoolId(),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "delegate valid poolId",
|
|
93
|
+
transaction: fromTransactionRaw({
|
|
94
|
+
family: "cardano",
|
|
95
|
+
recipient: "",
|
|
96
|
+
amount: "0",
|
|
97
|
+
mode: "delegate",
|
|
98
|
+
poolId: "efae72c07a26e4542ba55ef59d35ad45ffaaac312865e3a758ede997",
|
|
99
|
+
}),
|
|
100
|
+
expectedStatus: {},
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
describe("Cardano bridge", () => {
|
|
110
|
+
test.todo(
|
|
111
|
+
"This is an empty test to make jest command pass. Remove it once there is a real test.",
|
|
112
|
+
);
|
|
113
|
+
});
|
package/src/broadcast.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
3
|
+
import { submitTransaction } from "./api/submitTransaction";
|
|
4
|
+
import { Transaction } from "./types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Broadcast the signed transaction
|
|
8
|
+
* @param {signature: string, operation: string} signedOperation
|
|
9
|
+
*/
|
|
10
|
+
export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
|
|
11
|
+
signedOperation,
|
|
12
|
+
account,
|
|
13
|
+
}) => {
|
|
14
|
+
const signedTx = signedOperation.signature;
|
|
15
|
+
const pendingTransaction = await submitTransaction({
|
|
16
|
+
transaction: signedTx,
|
|
17
|
+
currency: account.currency,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return patchOperationWithHash(signedOperation.operation, pendingTransaction.hash);
|
|
21
|
+
};
|