@ledgerhq/coin-stacks 0.1.1-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 +31 -0
- package/CHANGELOG.md +11 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/bridge/broadcast.d.ts +4 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +28 -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 +34 -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 +18 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +22 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +34 -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 +46 -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 +60 -0
- package/lib/bridge/getTransactionStatus.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 +56 -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 +56 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +5 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +85 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/synchronization.d.ts +5 -0
- package/lib/bridge/synchronization.d.ts.map +1 -0
- package/lib/bridge/synchronization.js +62 -0
- package/lib/bridge/synchronization.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 +46 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/bridge/utils/addresses.d.ts +13 -0
- package/lib/bridge/utils/addresses.d.ts.map +1 -0
- package/lib/bridge/utils/addresses.js +15 -0
- package/lib/bridge/utils/addresses.js.map +1 -0
- package/lib/bridge/utils/misc.d.ts +15 -0
- package/lib/bridge/utils/misc.d.ts.map +1 -0
- package/lib/bridge/utils/misc.js +186 -0
- package/lib/bridge/utils/misc.js.map +1 -0
- package/lib/bridge/utils/misc.unit.test.d.ts +2 -0
- package/lib/bridge/utils/misc.unit.test.d.ts.map +1 -0
- package/lib/bridge/utils/misc.unit.test.js +230 -0
- package/lib/bridge/utils/misc.unit.test.js.map +1 -0
- package/lib/config.d.ts +14 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +16 -0
- package/lib/config.js.map +1 -0
- package/lib/errors.d.ts +4 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +6 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/network/api.d.ts +11 -0
- package/lib/network/api.d.ts.map +1 -0
- package/lib/network/api.js +139 -0
- package/lib/network/api.js.map +1 -0
- package/lib/network/api.types.d.ts +168 -0
- package/lib/network/api.types.d.ts.map +1 -0
- package/lib/network/api.types.js +9 -0
- package/lib/network/api.types.js.map +1 -0
- package/lib/network/index.d.ts +3 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +19 -0
- package/lib/network/index.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 +31 -0
- package/lib/signer/getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +4 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +23 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/signer/signMessage.d.ts +12 -0
- package/lib/signer/signMessage.d.ts.map +1 -0
- package/lib/signer/signMessage.js +31 -0
- package/lib/signer/signMessage.js.map +1 -0
- package/lib/test/bot-deviceActions.d.ts +4 -0
- package/lib/test/bot-deviceActions.d.ts.map +1 -0
- package/lib/test/bot-deviceActions.js +48 -0
- package/lib/test/bot-deviceActions.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 +73 -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 +129 -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 +27 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +6 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +26 -0
- package/lib/test/index.js.map +1 -0
- package/lib/types/bridge.d.ts +35 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.js +3 -0
- package/lib/types/bridge.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 +14 -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/utils.d.ts +8 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +26 -0
- package/lib/utils.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 +21 -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 +27 -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 +11 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +22 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +32 -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 +39 -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 +53 -0
- package/lib-es/bridge/getTransactionStatus.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 +48 -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 +49 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +5 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +78 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/synchronization.d.ts +5 -0
- package/lib-es/bridge/synchronization.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.js +55 -0
- package/lib-es/bridge/synchronization.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 +38 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/bridge/utils/addresses.d.ts +13 -0
- package/lib-es/bridge/utils/addresses.d.ts.map +1 -0
- package/lib-es/bridge/utils/addresses.js +11 -0
- package/lib-es/bridge/utils/addresses.js.map +1 -0
- package/lib-es/bridge/utils/misc.d.ts +15 -0
- package/lib-es/bridge/utils/misc.d.ts.map +1 -0
- package/lib-es/bridge/utils/misc.js +176 -0
- package/lib-es/bridge/utils/misc.js.map +1 -0
- package/lib-es/bridge/utils/misc.unit.test.d.ts +2 -0
- package/lib-es/bridge/utils/misc.unit.test.d.ts.map +1 -0
- package/lib-es/bridge/utils/misc.unit.test.js +228 -0
- package/lib-es/bridge/utils/misc.unit.test.js.map +1 -0
- package/lib-es/config.d.ts +14 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +11 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/errors.d.ts +4 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +3 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/index.d.ts +4 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +3 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/network/api.d.ts +11 -0
- package/lib-es/network/api.d.ts.map +1 -0
- package/lib-es/network/api.js +124 -0
- package/lib-es/network/api.js.map +1 -0
- package/lib-es/network/api.types.d.ts +168 -0
- package/lib-es/network/api.types.d.ts.map +1 -0
- package/lib-es/network/api.types.js +6 -0
- package/lib-es/network/api.types.js.map +1 -0
- package/lib-es/network/index.d.ts +3 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +3 -0
- package/lib-es/network/index.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 +29 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +4 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +4 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/signer/signMessage.d.ts +12 -0
- package/lib-es/signer/signMessage.d.ts.map +1 -0
- package/lib-es/signer/signMessage.js +27 -0
- package/lib-es/signer/signMessage.js.map +1 -0
- package/lib-es/test/bot-deviceActions.d.ts +4 -0
- package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
- package/lib-es/test/bot-deviceActions.js +45 -0
- package/lib-es/test/bot-deviceActions.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 +68 -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 +126 -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 +21 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +6 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +6 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/types/bridge.d.ts +35 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.js +2 -0
- package/lib-es/types/bridge.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 +14 -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/lib-es/utils.d.ts +8 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +17 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +136 -0
- package/src/bridge/broadcast.ts +18 -0
- package/src/bridge/buildOptimisticOperation.ts +34 -0
- package/src/bridge/createTransaction.ts +13 -0
- package/src/bridge/deviceTransactionConfig.ts +57 -0
- package/src/bridge/estimateMaxSpendable.ts +50 -0
- package/src/bridge/getTransactionStatus.ts +56 -0
- package/src/bridge/index.ts +64 -0
- package/src/bridge/prepareTransaction.ts +60 -0
- package/src/bridge/signOperation.ts +91 -0
- package/src/bridge/synchronization.ts +55 -0
- package/src/bridge/transaction.ts +75 -0
- package/src/bridge/utils/addresses.ts +23 -0
- package/src/bridge/utils/misc.ts +274 -0
- package/src/bridge/utils/misc.unit.test.ts +237 -0
- package/src/config.ts +26 -0
- package/src/errors.ts +3 -0
- package/src/index.ts +4 -0
- package/src/network/api.ts +173 -0
- package/src/network/api.types.ts +180 -0
- package/src/network/index.ts +2 -0
- package/src/signer/getAddress.ts +27 -0
- package/src/signer/index.ts +4 -0
- package/src/signer/signMessage.ts +26 -0
- package/src/test/bot-deviceActions.ts +47 -0
- package/src/test/bot-specs.ts +82 -0
- package/src/test/bridgeDatasetTest.ts +134 -0
- package/src/test/cli.ts +38 -0
- package/src/test/index.ts +5 -0
- package/src/types/bridge.ts +49 -0
- package/src/types/index.ts +2 -0
- package/src/types/signer.ts +16 -0
- package/src/utils.ts +24 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
|
|
2
|
+
import type { Transaction } from "../types";
|
|
3
|
+
import { deviceActionFlow, SpeculosButton } from "@ledgerhq/coin-framework/bot/specs";
|
|
4
|
+
|
|
5
|
+
export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
6
|
+
steps: [
|
|
7
|
+
{
|
|
8
|
+
title: "Please",
|
|
9
|
+
button: SpeculosButton.RIGHT,
|
|
10
|
+
expectedValue: () => "review",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
title: "Origin",
|
|
14
|
+
button: SpeculosButton.RIGHT,
|
|
15
|
+
expectedValue: ({ account }) => account.freshAddress,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
title: "Nonce",
|
|
19
|
+
button: SpeculosButton.RIGHT,
|
|
20
|
+
expectedValue: ({ transaction }) => (transaction.nonce ? transaction.nonce.toFixed() : "0"),
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
title: "Fee (uSTX)",
|
|
24
|
+
button: SpeculosButton.RIGHT,
|
|
25
|
+
expectedValue: ({ transaction }) => (transaction.fee ? transaction.fee.toFixed() : "0"),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: "Amount uSTX",
|
|
29
|
+
button: SpeculosButton.RIGHT,
|
|
30
|
+
expectedValue: ({ status }) => status.amount.toFixed(),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
title: "To",
|
|
34
|
+
button: SpeculosButton.RIGHT,
|
|
35
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
title: "Memo",
|
|
39
|
+
button: SpeculosButton.RIGHT,
|
|
40
|
+
expectedValue: ({ transaction }) => transaction.memo || "",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
title: "APPROVE",
|
|
44
|
+
button: SpeculosButton.BOTH,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { DeviceModelId } from "@ledgerhq/devices";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import expect from "expect";
|
|
5
|
+
|
|
6
|
+
import type { Transaction } from "../types";
|
|
7
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
8
|
+
import { botTest, pickSiblings } from "@ledgerhq/coin-framework/bot/specs";
|
|
9
|
+
import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
10
|
+
import { acceptTransaction } from "./bot-deviceActions";
|
|
11
|
+
|
|
12
|
+
const MIN_SAFE = new BigNumber(10000);
|
|
13
|
+
const stacksSpecs: AppSpec<Transaction> = {
|
|
14
|
+
name: "Stacks",
|
|
15
|
+
currency: getCryptoCurrencyById("stacks"),
|
|
16
|
+
appQuery: {
|
|
17
|
+
model: DeviceModelId.nanoSP,
|
|
18
|
+
appName: "Stacks",
|
|
19
|
+
},
|
|
20
|
+
genericDeviceAction: acceptTransaction,
|
|
21
|
+
// FIXME Stacks operations can take much longer to be confirmed
|
|
22
|
+
// Need an evolution of the bot to tolerate unconfirmed ops and just warn maybe instead of error
|
|
23
|
+
testTimeout: 25 * 60 * 1000,
|
|
24
|
+
transactionCheck: ({ maxSpendable }) => {
|
|
25
|
+
invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
|
|
26
|
+
},
|
|
27
|
+
mutations: [
|
|
28
|
+
{
|
|
29
|
+
name: "Send 50%~",
|
|
30
|
+
maxRun: 1,
|
|
31
|
+
transaction: ({ account, siblings, bridge }) => {
|
|
32
|
+
const sibling = pickSiblings(siblings, 2);
|
|
33
|
+
const recipient = sibling.freshAddress;
|
|
34
|
+
|
|
35
|
+
let amount = account.spendableBalance.div(1.9 + 0.2 * Math.random()).integerValue();
|
|
36
|
+
|
|
37
|
+
if (!sibling.used && amount.lt(MIN_SAFE)) {
|
|
38
|
+
invariant(account.spendableBalance.gt(MIN_SAFE), "send is too low to activate account");
|
|
39
|
+
amount = MIN_SAFE;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const transaction = bridge.createTransaction(account);
|
|
43
|
+
const updates = [{ recipient }, { amount }];
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
transaction,
|
|
47
|
+
updates,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
test: ({ account, accountBeforeTransaction, operation }) => {
|
|
51
|
+
botTest("account balance decreased with operation value", () =>
|
|
52
|
+
expect(account.balance.toFixed()).toBe(
|
|
53
|
+
accountBeforeTransaction.balance.minus(operation.value).toFixed(),
|
|
54
|
+
),
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "Transfer Max",
|
|
60
|
+
maxRun: 1,
|
|
61
|
+
transaction: ({ account, siblings, bridge }) => {
|
|
62
|
+
const sibling = pickSiblings(siblings, 2);
|
|
63
|
+
const recipient = sibling.freshAddress;
|
|
64
|
+
|
|
65
|
+
const transaction = bridge.createTransaction(account);
|
|
66
|
+
const updates = [{ recipient }, { useAllAmount: true }];
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
transaction,
|
|
70
|
+
updates,
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
test: ({ account }) => {
|
|
74
|
+
botTest("account balance is 0", () => expect(account.balance.toFixed()).toBe("0"));
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export default {
|
|
81
|
+
stacksSpecs,
|
|
82
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { CurrenciesData } from "@ledgerhq/types-live";
|
|
2
|
+
import { AnchorMode } from "@stacks/transactions";
|
|
3
|
+
import type { DatasetTest } from "@ledgerhq/types-live";
|
|
4
|
+
import type { Transaction } from "../types";
|
|
5
|
+
import { fromTransactionRaw } from "../bridge/transaction";
|
|
6
|
+
import { BigNumber } from "bignumber.js";
|
|
7
|
+
import {
|
|
8
|
+
AmountRequired,
|
|
9
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
10
|
+
NotEnoughBalance,
|
|
11
|
+
} from "@ledgerhq/errors";
|
|
12
|
+
|
|
13
|
+
const SEED_IDENTIFIER = "SP3KS7VMY2ZNE6SB88PHR4SKRK2EEPHS8N8MCCBR9";
|
|
14
|
+
const SEED_IDENTIFIER_PUBKEY = "022a460decc9dba8c452927fecb33d7ae25a8d79dc5442b84feaf8f3aa0e2b575d";
|
|
15
|
+
const ACCOUNT_1 = "SP2DV2RVZP1A69Q6VAG5PHEQ6ZHQHZPCV84TMYNGN";
|
|
16
|
+
|
|
17
|
+
const stacks: CurrenciesData<Transaction> = {
|
|
18
|
+
FIXME_ignoreAccountFields: [],
|
|
19
|
+
IgnorePrepareTransactionFields: ["fee"],
|
|
20
|
+
scanAccounts: [
|
|
21
|
+
{
|
|
22
|
+
name: "stacks seed 1",
|
|
23
|
+
apdus: `
|
|
24
|
+
=> 09010016142c0000807d160080000000800000000000000000
|
|
25
|
+
<= 022a460decc9dba8c452927fecb33d7ae25a8d79dc5442b84feaf8f3aa0e2b575d5350334b5337564d59325a4e45365342383850485234534b524b324545504853384e384d43434252399000
|
|
26
|
+
=> 09010016142c0000807d160080000000800000000001000000
|
|
27
|
+
<= 03a2d4bbb54c2f44c3a205b15ca7d2049a2bb66e50e100304f932b3b99ed3a99cb5350324136463652374632395a3338533259434a4d37484a44564532345332564757543542545a50419000
|
|
28
|
+
=> 09010016142c0000807d160080010000800000000000000000
|
|
29
|
+
<= 034bbb21911e9d4502ac170162c5c05cbba65cbb79e5b46adf95152af2d0e78a4553503244563252565a503141363951365641473550484551365a4851485a5043563834544d594e474e9000
|
|
30
|
+
=> 09010016142c0000807d160080020000800000000000000000
|
|
31
|
+
<= 020637c4d824458f6a11551f51df9e5be9e96c2e3a2e5bdb25d2916cc1dd5ba2d753504e5a4e434333433244525450574a4a384e534d484d575744304643415459413843565a3834459000
|
|
32
|
+
=> 09010016142c0000807d160080030000800000000000000000
|
|
33
|
+
<= 02e57bb8c28c4c768cf65f8e28935482e40afbb33168d26810199f39a719cc05f0535031564d30584546574251345a543838384654333447333047474635324459395951575a434151309000
|
|
34
|
+
=> 09010016142c0000807d160080040000800000000000000000
|
|
35
|
+
<= 0264b6d44f720fa50055dc294276bf15ce22e4f3dec48510b317ab8c07419c1b7753503248574a58594e4747594354535952545036323636424a483858565a4759504d455248514538529000
|
|
36
|
+
`,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
accounts: [
|
|
40
|
+
{
|
|
41
|
+
raw: {
|
|
42
|
+
id: `js:2:stacks:${SEED_IDENTIFIER_PUBKEY}:`,
|
|
43
|
+
seedIdentifier: SEED_IDENTIFIER,
|
|
44
|
+
name: "Stacks 1",
|
|
45
|
+
derivationMode: "",
|
|
46
|
+
index: 0,
|
|
47
|
+
freshAddress: SEED_IDENTIFIER,
|
|
48
|
+
freshAddressPath: "",
|
|
49
|
+
blockHeight: 0,
|
|
50
|
+
operations: [],
|
|
51
|
+
xpub: SEED_IDENTIFIER_PUBKEY,
|
|
52
|
+
pendingOperations: [],
|
|
53
|
+
currencyId: "stacks",
|
|
54
|
+
lastSyncDate: "",
|
|
55
|
+
balance: "1000",
|
|
56
|
+
},
|
|
57
|
+
transactions: [
|
|
58
|
+
{
|
|
59
|
+
name: "Source and destination are the equal",
|
|
60
|
+
transaction: fromTransactionRaw({
|
|
61
|
+
family: "stacks",
|
|
62
|
+
nonce: "1",
|
|
63
|
+
network: "mainnet",
|
|
64
|
+
anchorMode: AnchorMode.Any,
|
|
65
|
+
recipient: SEED_IDENTIFIER,
|
|
66
|
+
amount: "1",
|
|
67
|
+
}),
|
|
68
|
+
expectedStatus: {
|
|
69
|
+
errors: {
|
|
70
|
+
recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
|
|
71
|
+
},
|
|
72
|
+
warnings: {},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "Not enough balance",
|
|
77
|
+
transaction: fromTransactionRaw({
|
|
78
|
+
family: "stacks",
|
|
79
|
+
nonce: "1",
|
|
80
|
+
network: "mainnet",
|
|
81
|
+
anchorMode: AnchorMode.Any,
|
|
82
|
+
recipient: ACCOUNT_1,
|
|
83
|
+
amount: "10000000000",
|
|
84
|
+
}),
|
|
85
|
+
expectedStatus: {
|
|
86
|
+
errors: {
|
|
87
|
+
amount: new NotEnoughBalance(),
|
|
88
|
+
},
|
|
89
|
+
warnings: {},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "Amount Required",
|
|
94
|
+
transaction: fromTransactionRaw({
|
|
95
|
+
family: "stacks",
|
|
96
|
+
nonce: "1",
|
|
97
|
+
network: "mainnet",
|
|
98
|
+
anchorMode: AnchorMode.Any,
|
|
99
|
+
recipient: ACCOUNT_1,
|
|
100
|
+
amount: "0",
|
|
101
|
+
}),
|
|
102
|
+
expectedStatus: {
|
|
103
|
+
errors: {
|
|
104
|
+
amount: new AmountRequired(),
|
|
105
|
+
},
|
|
106
|
+
warnings: {},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "New account and sufficient amount",
|
|
111
|
+
transaction: fromTransactionRaw({
|
|
112
|
+
family: "stacks",
|
|
113
|
+
nonce: "1",
|
|
114
|
+
network: "mainnet",
|
|
115
|
+
anchorMode: AnchorMode.Any,
|
|
116
|
+
recipient: ACCOUNT_1,
|
|
117
|
+
amount: "1",
|
|
118
|
+
}),
|
|
119
|
+
expectedStatus: {
|
|
120
|
+
amount: new BigNumber("1"),
|
|
121
|
+
errors: {},
|
|
122
|
+
warnings: {},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
export const dataset: DatasetTest<Transaction> = {
|
|
130
|
+
implementations: ["js"],
|
|
131
|
+
currencies: {
|
|
132
|
+
stacks,
|
|
133
|
+
},
|
|
134
|
+
};
|
package/src/test/cli.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import flatMap from "lodash/flatMap";
|
|
3
|
+
|
|
4
|
+
import type { Account, AccountLike, AccountLikeArray } from "@ledgerhq/types-live";
|
|
5
|
+
|
|
6
|
+
import type { Transaction } from "../types";
|
|
7
|
+
|
|
8
|
+
function inferAccounts(account: Account): AccountLikeArray {
|
|
9
|
+
invariant(account.currency.family === "stacks", "stacks family");
|
|
10
|
+
|
|
11
|
+
const accounts: Account[] = [account];
|
|
12
|
+
return accounts;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function inferTransactions(
|
|
16
|
+
transactions: Array<{
|
|
17
|
+
account: AccountLike;
|
|
18
|
+
transaction: Transaction;
|
|
19
|
+
mainAccount: Account;
|
|
20
|
+
}>,
|
|
21
|
+
): Transaction[] {
|
|
22
|
+
return flatMap(transactions, ({ transaction }) => {
|
|
23
|
+
invariant(transaction.family === "stacks", "stacks family");
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
...transaction,
|
|
27
|
+
family: "stacks",
|
|
28
|
+
} as Transaction;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default function makeCliTools() {
|
|
33
|
+
return {
|
|
34
|
+
options: [],
|
|
35
|
+
inferAccounts,
|
|
36
|
+
inferTransactions,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AnchorMode } from "@stacks/transactions";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Operation,
|
|
6
|
+
TransactionCommon,
|
|
7
|
+
TransactionCommonRaw,
|
|
8
|
+
TransactionStatusCommon,
|
|
9
|
+
TransactionStatusCommonRaw,
|
|
10
|
+
} from "@ledgerhq/types-live";
|
|
11
|
+
|
|
12
|
+
import { StacksNetwork } from "../network/api.types";
|
|
13
|
+
|
|
14
|
+
type FamilyType = "stacks";
|
|
15
|
+
|
|
16
|
+
export type NetworkInfo = {
|
|
17
|
+
family: FamilyType;
|
|
18
|
+
};
|
|
19
|
+
export type NetworkInfoRaw = {
|
|
20
|
+
family: FamilyType;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type Transaction = TransactionCommon & {
|
|
24
|
+
family: FamilyType;
|
|
25
|
+
fee?: BigNumber;
|
|
26
|
+
nonce?: BigNumber;
|
|
27
|
+
memo?: string;
|
|
28
|
+
network: keyof typeof StacksNetwork;
|
|
29
|
+
anchorMode: AnchorMode;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type TransactionRaw = TransactionCommonRaw & {
|
|
33
|
+
family: FamilyType;
|
|
34
|
+
fee?: string;
|
|
35
|
+
nonce?: string;
|
|
36
|
+
memo?: string;
|
|
37
|
+
network: string;
|
|
38
|
+
anchorMode: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type TransactionStatus = TransactionStatusCommon;
|
|
42
|
+
|
|
43
|
+
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
|
44
|
+
|
|
45
|
+
export type StacksOperation = Operation<StacksOperationExtra>;
|
|
46
|
+
|
|
47
|
+
export type StacksOperationExtra = {
|
|
48
|
+
memo?: string | undefined;
|
|
49
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AddressVersion } from "@stacks/transactions";
|
|
2
|
+
import { ResponseAddress } from "@zondax/ledger-stacks";
|
|
3
|
+
|
|
4
|
+
export type StacksAddress = {
|
|
5
|
+
publicKey: string;
|
|
6
|
+
address: string;
|
|
7
|
+
chainCode?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type StacksSignature = string; // `0x${string}`
|
|
11
|
+
|
|
12
|
+
export interface StacksSigner {
|
|
13
|
+
showAddressAndPubKey(path: string, version: AddressVersion): Promise<ResponseAddress>;
|
|
14
|
+
getAddressAndPubKey(path: string, version: AddressVersion): Promise<ResponseAddress>;
|
|
15
|
+
sign(path: string, message: Buffer): Promise<any>;
|
|
16
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ResponseAddress } from "@zondax/ledger-stacks";
|
|
2
|
+
|
|
3
|
+
// NOTE: inlined now, this shared utils code will be moved to coin-framework in a future PR
|
|
4
|
+
const validHexRegExp = new RegExp(/^(0x)?[a-fA-F0-9]+$/);
|
|
5
|
+
const validBase64RegExp = new RegExp(
|
|
6
|
+
/^(?:[A-Za-z\d+/]{4})*(?:[A-Za-z\d+/]{3}=|[A-Za-z\d+/]{2}==)?$/,
|
|
7
|
+
);
|
|
8
|
+
export const isValidHex = (msg: string) => validHexRegExp.test(msg) && msg.length % 2 === 0;
|
|
9
|
+
export const isValidBase64 = (msg: string) => validBase64RegExp.test(msg);
|
|
10
|
+
|
|
11
|
+
export const isNoErrorReturnCode = (code: number) => code === 0x9000;
|
|
12
|
+
|
|
13
|
+
export const getPath = (path: string) => (path && path.substr(0, 2) !== "m/" ? `m/${path}` : path);
|
|
14
|
+
|
|
15
|
+
export const throwIfError = (r: ResponseAddress) => {
|
|
16
|
+
if (!isNoErrorReturnCode(r.returnCode)) throw new Error(`${r.returnCode} - ${r.errorMessage}`);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const getBufferFromString = (message: string): Buffer =>
|
|
20
|
+
isValidHex(message)
|
|
21
|
+
? Buffer.from(message, "hex")
|
|
22
|
+
: isValidBase64(message)
|
|
23
|
+
? Buffer.from(message, "base64")
|
|
24
|
+
: Buffer.from(message);
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"declarationMap": true,
|
|
6
|
+
"noImplicitAny": false,
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"downlevelIteration": true,
|
|
9
|
+
"lib": ["es2020", "dom"],
|
|
10
|
+
"outDir": "lib",
|
|
11
|
+
"typeRoots": ["./types", "./node_modules/@types"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*"]
|
|
14
|
+
}
|