@ledgerhq/coin-casper 1.4.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/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +49 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/api/index.d.ts +11 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +129 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/types.d.ts +105 -0
- package/lib/api/types.d.ts.map +1 -0
- package/lib/api/types.js +3 -0
- package/lib/api/types.js.map +1 -0
- package/lib/bridge/bridgeHelpers/accountShape.d.ts +3 -0
- package/lib/bridge/bridgeHelpers/accountShape.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/accountShape.js +38 -0
- package/lib/bridge/bridgeHelpers/accountShape.js.map +1 -0
- package/lib/bridge/bridgeHelpers/addresses.d.ts +18 -0
- package/lib/bridge/bridgeHelpers/addresses.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/addresses.js +83 -0
- package/lib/bridge/bridgeHelpers/addresses.js.map +1 -0
- package/lib/bridge/bridgeHelpers/fee.d.ts +3 -0
- package/lib/bridge/bridgeHelpers/fee.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/fee.js +13 -0
- package/lib/bridge/bridgeHelpers/fee.js.map +1 -0
- package/lib/bridge/bridgeHelpers/transferId.d.ts +2 -0
- package/lib/bridge/bridgeHelpers/transferId.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/transferId.js +14 -0
- package/lib/bridge/bridgeHelpers/transferId.js.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.d.ts +9 -0
- package/lib/bridge/bridgeHelpers/txn.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.js +100 -0
- package/lib/bridge/bridgeHelpers/txn.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +4 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +15 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +27 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +4 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +19 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +18 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +26 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +23 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +4 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +75 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/index.d.ts +8 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +54 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +4 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +16 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +6 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +47 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/transaction.d.ts +14 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +53 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/common-logic/index.d.ts +2 -0
- package/lib/common-logic/index.d.ts.map +1 -0
- package/lib/common-logic/index.js +13 -0
- package/lib/common-logic/index.js.map +1 -0
- package/lib/common-logic/utils.d.ts +14 -0
- package/lib/common-logic/utils.d.ts.map +1 -0
- package/lib/common-logic/utils.js +53 -0
- package/lib/common-logic/utils.js.map +1 -0
- package/lib/common-logic/utils.unit.test.d.ts +2 -0
- package/lib/common-logic/utils.unit.test.d.ts.map +1 -0
- package/lib/common-logic/utils.unit.test.js +50 -0
- package/lib/common-logic/utils.unit.test.js.map +1 -0
- package/lib/consts.d.ts +10 -0
- package/lib/consts.d.ts.map +1 -0
- package/lib/consts.js +18 -0
- package/lib/consts.js.map +1 -0
- package/lib/errors.d.ts +10 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +8 -0
- package/lib/errors.js.map +1 -0
- package/lib/hw-signMessage.d.ts +23 -0
- package/lib/hw-signMessage.d.ts.map +1 -0
- package/lib/hw-signMessage.js +24 -0
- package/lib/hw-signMessage.js.map +1 -0
- package/lib/signer/getAddress.d.ts +6 -0
- package/lib/signer/getAddress.d.ts.map +1 -0
- package/lib/signer/getAddress.js +25 -0
- package/lib/signer/getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +3 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +8 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/test/bot-specs.d.ts +7 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +110 -0
- package/lib/test/bot-specs.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts +4 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib/test/bridgeDatasetTest.js +177 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +15 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +30 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +4 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +20 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/speculos-deviceActions.d.ts +4 -0
- package/lib/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib/test/speculos-deviceActions.js +53 -0
- package/lib/test/speculos-deviceActions.js.map +1 -0
- package/lib/types/common.d.ts +23 -0
- package/lib/types/common.d.ts.map +1 -0
- package/lib/types/common.js +3 -0
- package/lib/types/common.js.map +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +19 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/signer.d.ts +21 -0
- package/lib/types/signer.d.ts.map +1 -0
- package/lib/types/signer.js +3 -0
- package/lib/types/signer.js.map +1 -0
- package/lib-es/api/index.d.ts +11 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +118 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/types.d.ts +105 -0
- package/lib-es/api/types.d.ts.map +1 -0
- package/lib-es/api/types.js +2 -0
- package/lib-es/api/types.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.d.ts +3 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.js +31 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/addresses.d.ts +18 -0
- package/lib-es/bridge/bridgeHelpers/addresses.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/addresses.js +74 -0
- package/lib-es/bridge/bridgeHelpers/addresses.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/fee.d.ts +3 -0
- package/lib-es/bridge/bridgeHelpers/fee.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/fee.js +6 -0
- package/lib-es/bridge/bridgeHelpers/fee.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/transferId.d.ts +2 -0
- package/lib-es/bridge/bridgeHelpers/transferId.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/transferId.js +10 -0
- package/lib-es/bridge/bridgeHelpers/transferId.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.d.ts +9 -0
- package/lib-es/bridge/bridgeHelpers/txn.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.js +91 -0
- package/lib-es/bridge/bridgeHelpers/txn.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +4 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +11 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +23 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +4 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +12 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +18 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +24 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +16 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +68 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/index.d.ts +8 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +47 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +4 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +12 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +6 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +43 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +14 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +45 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/common-logic/index.d.ts +2 -0
- package/lib-es/common-logic/index.d.ts.map +1 -0
- package/lib-es/common-logic/index.js +2 -0
- package/lib-es/common-logic/index.js.map +1 -0
- package/lib-es/common-logic/utils.d.ts +14 -0
- package/lib-es/common-logic/utils.d.ts.map +1 -0
- package/lib-es/common-logic/utils.js +39 -0
- package/lib-es/common-logic/utils.js.map +1 -0
- package/lib-es/common-logic/utils.unit.test.d.ts +2 -0
- package/lib-es/common-logic/utils.unit.test.d.ts.map +1 -0
- package/lib-es/common-logic/utils.unit.test.js +48 -0
- package/lib-es/common-logic/utils.unit.test.js.map +1 -0
- package/lib-es/consts.d.ts +10 -0
- package/lib-es/consts.d.ts.map +1 -0
- package/lib-es/consts.js +15 -0
- package/lib-es/consts.js.map +1 -0
- package/lib-es/errors.d.ts +10 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +5 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/hw-signMessage.d.ts +23 -0
- package/lib-es/hw-signMessage.d.ts.map +1 -0
- package/lib-es/hw-signMessage.js +20 -0
- package/lib-es/hw-signMessage.js.map +1 -0
- package/lib-es/signer/getAddress.d.ts +6 -0
- package/lib-es/signer/getAddress.d.ts.map +1 -0
- package/lib-es/signer/getAddress.js +23 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +3 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +3 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +7 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +105 -0
- package/lib-es/test/bot-specs.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib-es/test/bridgeDatasetTest.js +171 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +15 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +24 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +4 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +4 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/test/speculos-deviceActions.d.ts +4 -0
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/test/speculos-deviceActions.js +50 -0
- package/lib-es/test/speculos-deviceActions.js.map +1 -0
- package/lib-es/types/common.d.ts +23 -0
- package/lib-es/types/common.d.ts.map +1 -0
- package/lib-es/types/common.js +2 -0
- package/lib-es/types/common.js.map +1 -0
- package/lib-es/types/index.d.ts +3 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +3 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/signer.d.ts +21 -0
- package/lib-es/types/signer.d.ts.map +1 -0
- package/lib-es/types/signer.js +2 -0
- package/lib-es/types/signer.js.map +1 -0
- package/package.json +127 -0
- package/src/api/index.ts +166 -0
- package/src/api/types.ts +113 -0
- package/src/bridge/bridgeHelpers/accountShape.ts +39 -0
- package/src/bridge/bridgeHelpers/addresses.ts +94 -0
- package/src/bridge/bridgeHelpers/fee.ts +6 -0
- package/src/bridge/bridgeHelpers/transferId.ts +9 -0
- package/src/bridge/bridgeHelpers/txn.ts +121 -0
- package/src/bridge/broadcast.ts +18 -0
- package/src/bridge/buildOptimisticOperation.ts +31 -0
- package/src/bridge/createTransaction.ts +15 -0
- package/src/bridge/deviceTransactionConfig.ts +46 -0
- package/src/bridge/estimateMaxSpendable.ts +26 -0
- package/src/bridge/getTransactionStatus.ts +96 -0
- package/src/bridge/index.ts +65 -0
- package/src/bridge/prepareTransaction.ts +19 -0
- package/src/bridge/signOperation.ts +73 -0
- package/src/bridge/transaction.ts +61 -0
- package/src/common-logic/index.ts +10 -0
- package/src/common-logic/utils.ts +53 -0
- package/src/common-logic/utils.unit.test.ts +75 -0
- package/src/consts.ts +18 -0
- package/src/errors.ts +5 -0
- package/src/hw-signMessage.ts +30 -0
- package/src/signer/getAddress.ts +31 -0
- package/src/signer/index.ts +3 -0
- package/src/test/bot-specs.ts +127 -0
- package/src/test/bridgeDatasetTest.ts +178 -0
- package/src/test/cli.ts +36 -0
- package/src/test/index.ts +3 -0
- package/src/test/speculos-deviceActions.ts +54 -0
- package/src/types/common.ts +38 -0
- package/src/types/index.ts +2 -0
- package/src/types/signer.ts +20 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { DeviceModelId } from "@ledgerhq/devices";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import expect from "expect";
|
|
5
|
+
import type { Transaction } from "../types";
|
|
6
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
7
|
+
import { genericTestDestination, pickSiblings, botTest } from "@ledgerhq/coin-framework/bot/specs";
|
|
8
|
+
import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
9
|
+
import { acceptTransaction } from "./speculos-deviceActions";
|
|
10
|
+
import { CASPER_MINIMUM_VALID_AMOUNT_MOTES, MayBlockAccountError } from "../consts";
|
|
11
|
+
import { getRandomTransferID } from "../common-logic";
|
|
12
|
+
|
|
13
|
+
const MIN_SAFE = new BigNumber(CASPER_MINIMUM_VALID_AMOUNT_MOTES * 2);
|
|
14
|
+
const maxAccount = 6;
|
|
15
|
+
|
|
16
|
+
const casperSpecs: AppSpec<Transaction> = {
|
|
17
|
+
name: "Casper",
|
|
18
|
+
currency: getCryptoCurrencyById("casper"),
|
|
19
|
+
appQuery: {
|
|
20
|
+
model: DeviceModelId.nanoSP,
|
|
21
|
+
appName: "Casper",
|
|
22
|
+
},
|
|
23
|
+
genericDeviceAction: acceptTransaction,
|
|
24
|
+
testTimeout: 6 * 60 * 1000,
|
|
25
|
+
minViableAmount: MIN_SAFE,
|
|
26
|
+
transactionCheck: ({ maxSpendable }) => {
|
|
27
|
+
invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
|
|
28
|
+
},
|
|
29
|
+
mutations: [
|
|
30
|
+
{
|
|
31
|
+
name: "Send ~50%",
|
|
32
|
+
feature: "send",
|
|
33
|
+
maxRun: 1,
|
|
34
|
+
testDestination: genericTestDestination,
|
|
35
|
+
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
36
|
+
invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
|
|
37
|
+
const sibling = pickSiblings(siblings, maxAccount);
|
|
38
|
+
const recipient = sibling.freshAddress;
|
|
39
|
+
const amount = maxSpendable.div(2).integerValue();
|
|
40
|
+
|
|
41
|
+
const transaction = bridge.createTransaction(account);
|
|
42
|
+
const updates: Array<Partial<Transaction>> = [
|
|
43
|
+
{
|
|
44
|
+
recipient,
|
|
45
|
+
},
|
|
46
|
+
{ amount },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
if (Math.random() < 0.5) {
|
|
50
|
+
updates.push({
|
|
51
|
+
transferId: getRandomTransferID(),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
transaction,
|
|
57
|
+
updates,
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
test: ({ accountBeforeTransaction, operation, account, transaction }) => {
|
|
62
|
+
botTest("account spendable balance decreased with operation", () =>
|
|
63
|
+
expect(account.spendableBalance).toEqual(
|
|
64
|
+
accountBeforeTransaction.spendableBalance.minus(operation.value),
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (transaction.transferId) {
|
|
69
|
+
botTest("operation transferId", () =>
|
|
70
|
+
expect(operation.extra).toMatchObject({
|
|
71
|
+
transferId: transaction.transferId,
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "Transfer Max",
|
|
79
|
+
feature: "sendMax",
|
|
80
|
+
maxRun: 1,
|
|
81
|
+
transaction: ({ account, siblings, bridge }) => {
|
|
82
|
+
const updates: Array<Partial<Transaction>> = [
|
|
83
|
+
{
|
|
84
|
+
recipient: pickSiblings(siblings, maxAccount).freshAddress,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
useAllAmount: true,
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
if (Math.random() < 0.5) {
|
|
92
|
+
updates.push({
|
|
93
|
+
transferId: getRandomTransferID(),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
transaction: bridge.createTransaction(account),
|
|
99
|
+
updates,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
expectStatusWarnings: _ => {
|
|
103
|
+
return {
|
|
104
|
+
amount: MayBlockAccountError,
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
testDestination: genericTestDestination,
|
|
108
|
+
test: ({ account, transaction, operation }) => {
|
|
109
|
+
botTest("account spendable balance is zero", () =>
|
|
110
|
+
expect(account.spendableBalance.toString()).toBe("0"),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
if (transaction.transferId) {
|
|
114
|
+
botTest("operation transferId", () =>
|
|
115
|
+
expect(operation.extra).toMatchObject({
|
|
116
|
+
transferId: transaction.transferId,
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export default {
|
|
126
|
+
casperSpecs,
|
|
127
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { CurrenciesData, DatasetTest } from "@ledgerhq/types-live";
|
|
2
|
+
import type { Transaction } from "../types";
|
|
3
|
+
import { fromTransactionRaw } from "../bridge/transaction";
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
import { AmountRequired, InvalidAddress, NotEnoughBalance } from "@ledgerhq/errors";
|
|
6
|
+
import { CasperInvalidTransferId, InvalidMinimumAmount, MayBlockAccount } from "../errors";
|
|
7
|
+
import { getEstimatedFees } from "../bridge/bridgeHelpers/fee";
|
|
8
|
+
|
|
9
|
+
const SEED_IDENTIFIER = "0202ba6dc98cbe677711a45bf028a03646f9e588996eb223fad2485e8bc391b01581";
|
|
10
|
+
const RECIPIENT_ADDRESS_SECP256k1 =
|
|
11
|
+
"0203A17118eC0e64c4e4FdbDbEe0eA14D118C9aAf08C6c81bbB776Cae607cEB84EcB";
|
|
12
|
+
const RECIPIENT_ADDRESS_EDSA25519 =
|
|
13
|
+
"0203A17118eC0e64c4e4FdbDbEe0eA14D118C9aAf08C6c81bbB776Cae607cEB84EcB";
|
|
14
|
+
|
|
15
|
+
const casper: CurrenciesData<Transaction> = {
|
|
16
|
+
scanAccounts: [
|
|
17
|
+
{
|
|
18
|
+
name: "casper seed 1",
|
|
19
|
+
apdus: `
|
|
20
|
+
=> 11010000142c000080fa010080000000800000000000000000
|
|
21
|
+
<= 038c8cb0f62b4efcd0c7868c2e749dda649affe30ff0f95fc91ce48ea67f077d1630323033384338636230663632623445466344304337383638633265373439446461363439614646453330664630663935666339314345343845413637463037374431369000
|
|
22
|
+
=> 11010000142c000080fa010080000000800000000001000000
|
|
23
|
+
<= 02ba6dc98cbe677711a45bf028a03646f9e588996eb223fad2485e8bc391b0158130323032624136444339386362453637373731316134356266303238413033363436463965353838393936654232323366616432343835653862633339316230313538319000
|
|
24
|
+
=> 11010000142c000080fa010080000000800000000002000000
|
|
25
|
+
<= 022aab9b6ed404f8cffe76ce493e1995d195b5f141ee7d5b7fb20fce60f2a4969130323032324141423942364544343034663843464645373663653439334531393935643139354235463134314565374435423766623230464345363066324134393639319000
|
|
26
|
+
`,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
accounts: [
|
|
30
|
+
{
|
|
31
|
+
raw: {
|
|
32
|
+
id: `js:2:casper:${SEED_IDENTIFIER}:casper_wallet`,
|
|
33
|
+
seedIdentifier: SEED_IDENTIFIER,
|
|
34
|
+
name: "Casper 1",
|
|
35
|
+
derivationMode: "casper_wallet" as const,
|
|
36
|
+
index: 0,
|
|
37
|
+
freshAddress: SEED_IDENTIFIER,
|
|
38
|
+
freshAddressPath: "44'/506'/0'/0/1",
|
|
39
|
+
blockHeight: 0,
|
|
40
|
+
operations: [],
|
|
41
|
+
pendingOperations: [],
|
|
42
|
+
currencyId: "casper",
|
|
43
|
+
lastSyncDate: "",
|
|
44
|
+
balance: "1000",
|
|
45
|
+
},
|
|
46
|
+
transactions: [
|
|
47
|
+
{
|
|
48
|
+
name: "not a valid address",
|
|
49
|
+
transaction: fromTransactionRaw({
|
|
50
|
+
family: "casper",
|
|
51
|
+
recipient: "novalidaddress",
|
|
52
|
+
fees: getEstimatedFees().toString(),
|
|
53
|
+
amount: "1000",
|
|
54
|
+
}),
|
|
55
|
+
expectedStatus: {
|
|
56
|
+
errors: {
|
|
57
|
+
recipient: new InvalidAddress(),
|
|
58
|
+
},
|
|
59
|
+
warnings: {},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "not enough balance",
|
|
64
|
+
transaction: fromTransactionRaw({
|
|
65
|
+
family: "casper",
|
|
66
|
+
recipient: RECIPIENT_ADDRESS_SECP256k1,
|
|
67
|
+
fees: getEstimatedFees().toString(),
|
|
68
|
+
amount: (300 * 1e9).toString(),
|
|
69
|
+
}),
|
|
70
|
+
expectedStatus: {
|
|
71
|
+
errors: {
|
|
72
|
+
amount: new NotEnoughBalance(),
|
|
73
|
+
},
|
|
74
|
+
warnings: {},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "amount required",
|
|
79
|
+
transaction: fromTransactionRaw({
|
|
80
|
+
family: "casper",
|
|
81
|
+
recipient: RECIPIENT_ADDRESS_SECP256k1,
|
|
82
|
+
amount: "0",
|
|
83
|
+
fees: getEstimatedFees().toString(),
|
|
84
|
+
}),
|
|
85
|
+
expectedStatus: {
|
|
86
|
+
errors: {
|
|
87
|
+
amount: new AmountRequired(),
|
|
88
|
+
},
|
|
89
|
+
warnings: {},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "minimum amount required",
|
|
94
|
+
transaction: fromTransactionRaw({
|
|
95
|
+
family: "casper",
|
|
96
|
+
fees: getEstimatedFees().toString(),
|
|
97
|
+
recipient: RECIPIENT_ADDRESS_SECP256k1,
|
|
98
|
+
amount: "1",
|
|
99
|
+
}),
|
|
100
|
+
|
|
101
|
+
expectedStatus: {
|
|
102
|
+
errors: {
|
|
103
|
+
amount: new InvalidMinimumAmount(),
|
|
104
|
+
},
|
|
105
|
+
warnings: {},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "sufficient amount - recipient address secp256k1",
|
|
110
|
+
transaction: fromTransactionRaw({
|
|
111
|
+
family: "casper",
|
|
112
|
+
recipient: RECIPIENT_ADDRESS_SECP256k1,
|
|
113
|
+
amount: "3",
|
|
114
|
+
fees: getEstimatedFees().toString(),
|
|
115
|
+
}),
|
|
116
|
+
expectedStatus: {
|
|
117
|
+
amount: new BigNumber("3"),
|
|
118
|
+
errors: {},
|
|
119
|
+
warnings: {},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "sufficient amount - recipient address ed25519",
|
|
124
|
+
transaction: fromTransactionRaw({
|
|
125
|
+
family: "casper",
|
|
126
|
+
recipient: RECIPIENT_ADDRESS_EDSA25519,
|
|
127
|
+
amount: "3",
|
|
128
|
+
fees: getEstimatedFees().toString(),
|
|
129
|
+
}),
|
|
130
|
+
expectedStatus: {
|
|
131
|
+
amount: new BigNumber("3"),
|
|
132
|
+
errors: {},
|
|
133
|
+
warnings: {},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "invalid transferID",
|
|
138
|
+
transaction: fromTransactionRaw({
|
|
139
|
+
family: "casper",
|
|
140
|
+
recipient: RECIPIENT_ADDRESS_SECP256k1,
|
|
141
|
+
fees: getEstimatedFees().toString(),
|
|
142
|
+
amount: "3",
|
|
143
|
+
transferId: "afdsaf1",
|
|
144
|
+
}),
|
|
145
|
+
expectedStatus: {
|
|
146
|
+
amount: new BigNumber("3"),
|
|
147
|
+
errors: {
|
|
148
|
+
sender: new CasperInvalidTransferId(),
|
|
149
|
+
},
|
|
150
|
+
warnings: {},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
name: "may block account warning",
|
|
155
|
+
transaction: fromTransactionRaw({
|
|
156
|
+
family: "casper",
|
|
157
|
+
recipient: RECIPIENT_ADDRESS_SECP256k1,
|
|
158
|
+
fees: getEstimatedFees().toString(),
|
|
159
|
+
amount: (999 * 1e9).toString(),
|
|
160
|
+
}),
|
|
161
|
+
expectedStatus: {
|
|
162
|
+
errors: {},
|
|
163
|
+
warnings: {
|
|
164
|
+
amount: new MayBlockAccount(),
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const dataset: DatasetTest<Transaction> = {
|
|
174
|
+
implementations: ["js"],
|
|
175
|
+
currencies: {
|
|
176
|
+
casper,
|
|
177
|
+
},
|
|
178
|
+
};
|
package/src/test/cli.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Account, AccountLike, AccountLikeArray } from "@ledgerhq/types-live";
|
|
2
|
+
import invariant from "invariant";
|
|
3
|
+
import flatMap from "lodash/flatMap";
|
|
4
|
+
import type { Transaction } from "../types";
|
|
5
|
+
|
|
6
|
+
function inferAccounts(account: Account): AccountLikeArray {
|
|
7
|
+
invariant(account.currency.family === "casper", "casper family");
|
|
8
|
+
|
|
9
|
+
const accounts: Account[] = [account];
|
|
10
|
+
return accounts;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function inferTransactions(
|
|
14
|
+
transactions: Array<{
|
|
15
|
+
account: AccountLike;
|
|
16
|
+
transaction: Transaction;
|
|
17
|
+
mainAccount: Account;
|
|
18
|
+
}>,
|
|
19
|
+
): Transaction[] {
|
|
20
|
+
return flatMap(transactions, ({ transaction }) => {
|
|
21
|
+
invariant(transaction.family === "casper", "casper family");
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
...transaction,
|
|
25
|
+
family: "casper",
|
|
26
|
+
} as Transaction;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function makeCliTools() {
|
|
31
|
+
return {
|
|
32
|
+
options: [],
|
|
33
|
+
inferAccounts,
|
|
34
|
+
inferTransactions,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { deviceActionFlow, SpeculosButton } from "@ledgerhq/coin-framework/bot/specs";
|
|
2
|
+
import { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
|
|
3
|
+
import { casperGetCLPublicKey } from "../bridge/bridgeHelpers/addresses";
|
|
4
|
+
import type { Transaction } from "../types";
|
|
5
|
+
|
|
6
|
+
export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
7
|
+
steps: [
|
|
8
|
+
{
|
|
9
|
+
title: "Please",
|
|
10
|
+
button: SpeculosButton.RIGHT,
|
|
11
|
+
expectedValue: () => "review",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
title: "Txn hash",
|
|
15
|
+
button: SpeculosButton.RIGHT,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
title: "Type",
|
|
19
|
+
button: SpeculosButton.RIGHT,
|
|
20
|
+
expectedValue: () => "Token transfer",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
title: "Chain ID",
|
|
24
|
+
button: SpeculosButton.RIGHT,
|
|
25
|
+
expectedValue: () => "casper",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: "Account",
|
|
29
|
+
button: SpeculosButton.RIGHT,
|
|
30
|
+
expectedValue: ({ account }) => casperGetCLPublicKey(account.freshAddress).toHex(true),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
title: "Fee",
|
|
34
|
+
button: SpeculosButton.RIGHT,
|
|
35
|
+
expectedValue: ({ transaction }) =>
|
|
36
|
+
`${transaction.fees.toNumber().toLocaleString("en-US").replace(/,/g, " ")} motes`,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: "Target",
|
|
40
|
+
button: SpeculosButton.RIGHT,
|
|
41
|
+
expectedValue: ({ transaction }) => casperGetCLPublicKey(transaction.recipient).toHex(true),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
title: "Amount",
|
|
45
|
+
button: SpeculosButton.RIGHT,
|
|
46
|
+
expectedValue: ({ status }) =>
|
|
47
|
+
`${status.amount.toNumber().toLocaleString("en-US").replace(/,/g, " ")} motes`,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
title: "APPROVE",
|
|
51
|
+
button: SpeculosButton.BOTH,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Account,
|
|
3
|
+
Operation,
|
|
4
|
+
TransactionCommon,
|
|
5
|
+
TransactionCommonRaw,
|
|
6
|
+
TransactionStatusCommon,
|
|
7
|
+
TransactionStatusCommonRaw,
|
|
8
|
+
} from "@ledgerhq/types-live";
|
|
9
|
+
import BigNumber from "bignumber.js";
|
|
10
|
+
import { ExtraDeviceTransactionField } from "../bridge/deviceTransactionConfig";
|
|
11
|
+
|
|
12
|
+
type FamilyType = "casper";
|
|
13
|
+
|
|
14
|
+
export type CasperAccount = Account;
|
|
15
|
+
|
|
16
|
+
export type Transaction = TransactionCommon & {
|
|
17
|
+
family: FamilyType;
|
|
18
|
+
fees: BigNumber;
|
|
19
|
+
transferId?: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type CasperOperation = Operation<CasperOperationExtra>;
|
|
23
|
+
|
|
24
|
+
interface CasperOperationExtra {
|
|
25
|
+
transferId?: string | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type TransactionRaw = TransactionCommonRaw & {
|
|
29
|
+
family: FamilyType;
|
|
30
|
+
transferId?: string | undefined;
|
|
31
|
+
fees: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type TransactionStatus = TransactionStatusCommon;
|
|
35
|
+
|
|
36
|
+
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
|
37
|
+
|
|
38
|
+
export type { ExtraDeviceTransactionField };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type CasperSignature = {
|
|
2
|
+
errorMessage: string;
|
|
3
|
+
returnCode: number;
|
|
4
|
+
signatureRS: Buffer;
|
|
5
|
+
signatureRSV: Buffer;
|
|
6
|
+
signature_compact: Uint8Array;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type CasperGetAddrResponse = {
|
|
10
|
+
errorMessage: string;
|
|
11
|
+
returnCode: number;
|
|
12
|
+
publicKey: Buffer;
|
|
13
|
+
Address: any;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export interface CasperSigner {
|
|
17
|
+
showAddressAndPubKey(path: string): Promise<CasperGetAddrResponse>;
|
|
18
|
+
getAddressAndPubKey(path: string): Promise<CasperGetAddrResponse>;
|
|
19
|
+
sign(path: string, message: Buffer): Promise<CasperSignature>;
|
|
20
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"declarationMap": true,
|
|
6
|
+
"downlevelIteration": true,
|
|
7
|
+
"lib": ["es2020", "dom"],
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"outDir": "lib",
|
|
10
|
+
"exactOptionalPropertyTypes": true,
|
|
11
|
+
"module": "esnext",
|
|
12
|
+
"moduleResolution": "bundler"
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*", "deviceTransactionConfig.ts", "transaction.ts"]
|
|
15
|
+
}
|