@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 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/test/cli.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,iBAAS,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAKzD;AAED,iBAAS,iBAAiB,CACxB,YAAY,EAAE,KAAK,CAAC;IAClB,OAAO,EAAE,WAAW,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC,GACD,WAAW,EAAE,CASf;AAED,MAAM,CAAC,OAAO,UAAU,YAAY;;;;EAMnC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import flatMap from "lodash/flatMap";
|
|
3
|
+
function inferAccounts(account) {
|
|
4
|
+
invariant(account.currency.family === "stacks", "stacks family");
|
|
5
|
+
const accounts = [account];
|
|
6
|
+
return accounts;
|
|
7
|
+
}
|
|
8
|
+
function inferTransactions(transactions) {
|
|
9
|
+
return flatMap(transactions, ({ transaction }) => {
|
|
10
|
+
invariant(transaction.family === "stacks", "stacks family");
|
|
11
|
+
return Object.assign(Object.assign({}, transaction), { family: "stacks" });
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export default function makeCliTools() {
|
|
15
|
+
return {
|
|
16
|
+
options: [],
|
|
17
|
+
inferAccounts,
|
|
18
|
+
inferTransactions,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/test/cli.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAMrC,SAAS,aAAa,CAAC,OAAgB;IACrC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE,eAAe,CAAC,CAAC;IAEjE,MAAM,QAAQ,GAAc,CAAC,OAAO,CAAC,CAAC;IACtC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,iBAAiB,CACxB,YAIE;IAEF,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE;QAC/C,SAAS,CAAC,WAAW,CAAC,MAAM,KAAK,QAAQ,EAAE,eAAe,CAAC,CAAC;QAE5D,OAAO,gCACF,WAAW,KACd,MAAM,EAAE,QAAQ,GACF,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,YAAY;IAClC,OAAO;QACL,OAAO,EAAE,EAAE;QACX,aAAa;QACb,iBAAiB;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AnchorMode } from "@stacks/transactions";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import { Operation, TransactionCommon, TransactionCommonRaw, TransactionStatusCommon, TransactionStatusCommonRaw } from "@ledgerhq/types-live";
|
|
4
|
+
import { StacksNetwork } from "../network/api.types";
|
|
5
|
+
type FamilyType = "stacks";
|
|
6
|
+
export type NetworkInfo = {
|
|
7
|
+
family: FamilyType;
|
|
8
|
+
};
|
|
9
|
+
export type NetworkInfoRaw = {
|
|
10
|
+
family: FamilyType;
|
|
11
|
+
};
|
|
12
|
+
export type Transaction = TransactionCommon & {
|
|
13
|
+
family: FamilyType;
|
|
14
|
+
fee?: BigNumber;
|
|
15
|
+
nonce?: BigNumber;
|
|
16
|
+
memo?: string;
|
|
17
|
+
network: keyof typeof StacksNetwork;
|
|
18
|
+
anchorMode: AnchorMode;
|
|
19
|
+
};
|
|
20
|
+
export type TransactionRaw = TransactionCommonRaw & {
|
|
21
|
+
family: FamilyType;
|
|
22
|
+
fee?: string;
|
|
23
|
+
nonce?: string;
|
|
24
|
+
memo?: string;
|
|
25
|
+
network: string;
|
|
26
|
+
anchorMode: number;
|
|
27
|
+
};
|
|
28
|
+
export type TransactionStatus = TransactionStatusCommon;
|
|
29
|
+
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
|
30
|
+
export type StacksOperation = Operation<StacksOperationExtra>;
|
|
31
|
+
export type StacksOperationExtra = {
|
|
32
|
+
memo?: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/types/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC3B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,KAAK,UAAU,GAAG,QAAQ,CAAC;AAE3B,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,UAAU,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,UAAU,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,iBAAiB,GAAG;IAC5C,MAAM,EAAE,UAAU,CAAC;IACnB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,OAAO,aAAa,CAAC;IACpC,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAAG;IAClD,MAAM,EAAE,UAAU,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAExD,MAAM,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAE9D,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAC;AAE9D,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/types/bridge.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AddressVersion } from "@stacks/transactions";
|
|
2
|
+
import { ResponseAddress } from "@zondax/ledger-stacks";
|
|
3
|
+
export type StacksAddress = {
|
|
4
|
+
publicKey: string;
|
|
5
|
+
address: string;
|
|
6
|
+
chainCode?: string;
|
|
7
|
+
};
|
|
8
|
+
export type StacksSignature = string;
|
|
9
|
+
export interface StacksSigner {
|
|
10
|
+
showAddressAndPubKey(path: string, version: AddressVersion): Promise<ResponseAddress>;
|
|
11
|
+
getAddressAndPubKey(path: string, version: AddressVersion): Promise<ResponseAddress>;
|
|
12
|
+
sign(path: string, message: Buffer): Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/types/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACtF,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACrF,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/types/signer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ResponseAddress } from "@zondax/ledger-stacks";
|
|
2
|
+
export declare const isValidHex: (msg: string) => boolean;
|
|
3
|
+
export declare const isValidBase64: (msg: string) => boolean;
|
|
4
|
+
export declare const isNoErrorReturnCode: (code: number) => code is 36864;
|
|
5
|
+
export declare const getPath: (path: string) => string;
|
|
6
|
+
export declare const throwIfError: (r: ResponseAddress) => void;
|
|
7
|
+
export declare const getBufferFromString: (message: string) => Buffer;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAOxD,eAAO,MAAM,UAAU,QAAS,MAAM,YAAqD,CAAC;AAC5F,eAAO,MAAM,aAAa,QAAS,MAAM,YAAgC,CAAC;AAE1E,eAAO,MAAM,mBAAmB,SAAU,MAAM,kBAAoB,CAAC;AAErE,eAAO,MAAM,OAAO,SAAU,MAAM,WAA8D,CAAC;AAEnG,eAAO,MAAM,YAAY,MAAO,eAAe,SAE9C,CAAC;AAEF,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,MAK1B,CAAC"}
|
package/lib-es/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// NOTE: inlined now, this shared utils code will be moved to coin-framework in a future PR
|
|
2
|
+
const validHexRegExp = new RegExp(/^(0x)?[a-fA-F0-9]+$/);
|
|
3
|
+
const validBase64RegExp = new RegExp(/^(?:[A-Za-z\d+/]{4})*(?:[A-Za-z\d+/]{3}=|[A-Za-z\d+/]{2}==)?$/);
|
|
4
|
+
export const isValidHex = (msg) => validHexRegExp.test(msg) && msg.length % 2 === 0;
|
|
5
|
+
export const isValidBase64 = (msg) => validBase64RegExp.test(msg);
|
|
6
|
+
export const isNoErrorReturnCode = (code) => code === 0x9000;
|
|
7
|
+
export const getPath = (path) => (path && path.substr(0, 2) !== "m/" ? `m/${path}` : path);
|
|
8
|
+
export const throwIfError = (r) => {
|
|
9
|
+
if (!isNoErrorReturnCode(r.returnCode))
|
|
10
|
+
throw new Error(`${r.returnCode} - ${r.errorMessage}`);
|
|
11
|
+
};
|
|
12
|
+
export const getBufferFromString = (message) => isValidHex(message)
|
|
13
|
+
? Buffer.from(message, "hex")
|
|
14
|
+
: isValidBase64(message)
|
|
15
|
+
? Buffer.from(message, "base64")
|
|
16
|
+
: Buffer.from(message);
|
|
17
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,2FAA2F;AAC3F,MAAM,cAAc,GAAG,IAAI,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACzD,MAAM,iBAAiB,GAAG,IAAI,MAAM,CAClC,+DAA+D,CAChE,CAAC;AACF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC;AAC5F,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE1E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,KAAK,MAAM,CAAC;AAErE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEnG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAkB,EAAE,EAAE;IACjD,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,UAAU,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,UAAU,MAAM,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;AACjG,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAU,EAAE,CAC7D,UAAU,CAAC,OAAO,CAAC;IACjB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC;IAC7B,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC;QACtB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ledgerhq/coin-stacks",
|
|
3
|
+
"version": "0.1.1-next.0",
|
|
4
|
+
"description": "Ledger Stacks Coin integration",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Ledger",
|
|
7
|
+
"LedgerWallet",
|
|
8
|
+
"stacks",
|
|
9
|
+
"stx",
|
|
10
|
+
"Bitcoin layer2",
|
|
11
|
+
"Hardware Wallet"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/LedgerHQ/ledger-live/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-stacks",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"typesVersions": {
|
|
25
|
+
"*": {
|
|
26
|
+
"lib/*": [
|
|
27
|
+
"lib/*"
|
|
28
|
+
],
|
|
29
|
+
"lib-es/*": [
|
|
30
|
+
"lib-es/*"
|
|
31
|
+
],
|
|
32
|
+
"deviceTransactionConfig": [
|
|
33
|
+
"lib/bridge/deviceTransactionConfig"
|
|
34
|
+
],
|
|
35
|
+
"specs": [
|
|
36
|
+
"lib/test/bot-specs"
|
|
37
|
+
],
|
|
38
|
+
"transaction": [
|
|
39
|
+
"lib/bridge/transaction"
|
|
40
|
+
],
|
|
41
|
+
"*": [
|
|
42
|
+
"lib/*"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"exports": {
|
|
47
|
+
"./lib/*": "./lib/*.js",
|
|
48
|
+
"./lib-es/*": "./lib-es/*.js",
|
|
49
|
+
"./api": {
|
|
50
|
+
"require": "./lib/api/index.js",
|
|
51
|
+
"default": "./lib-es/api/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./deviceTransactionConfig": {
|
|
54
|
+
"require": "./lib/bridge/deviceTransactionConfig.js",
|
|
55
|
+
"default": "./lib-es/bridge/deviceTransactionConfig.js"
|
|
56
|
+
},
|
|
57
|
+
"./signer": {
|
|
58
|
+
"require": "./lib/signer/index.js",
|
|
59
|
+
"default": "./lib-es/signer/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./hw-signMessage": {
|
|
62
|
+
"require": "./lib/signer/signMessage.js",
|
|
63
|
+
"default": "./lib-es/signer/signMessage.js"
|
|
64
|
+
},
|
|
65
|
+
"./specs": {
|
|
66
|
+
"require": "./lib/test/bot-specs.js",
|
|
67
|
+
"default": "./lib-es/test/bot-specs.js"
|
|
68
|
+
},
|
|
69
|
+
"./transaction": {
|
|
70
|
+
"require": "./lib/bridge/transaction.js",
|
|
71
|
+
"default": "./lib-es/bridge/transaction.js"
|
|
72
|
+
},
|
|
73
|
+
"./types": {
|
|
74
|
+
"require": "./lib/types/index.js",
|
|
75
|
+
"default": "./lib-es/types/index.js"
|
|
76
|
+
},
|
|
77
|
+
"./*": {
|
|
78
|
+
"require": "./lib/*.js",
|
|
79
|
+
"default": "./lib-es/*.js"
|
|
80
|
+
},
|
|
81
|
+
".": {
|
|
82
|
+
"require": "./lib/index.js",
|
|
83
|
+
"default": "./lib-es/index.js"
|
|
84
|
+
},
|
|
85
|
+
"./package.json": "./package.json"
|
|
86
|
+
},
|
|
87
|
+
"license": "Apache-2.0",
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"axios": "1.7.7",
|
|
90
|
+
"bignumber.js": "^9.1.2",
|
|
91
|
+
"c32check": "1.1.3",
|
|
92
|
+
"invariant": "^2.2.4",
|
|
93
|
+
"lodash": "^4.17.21",
|
|
94
|
+
"ripple-address-codec": "^5.0.0",
|
|
95
|
+
"ripple-binary-codec": "^1.3.0",
|
|
96
|
+
"rxjs": "^7.8.1",
|
|
97
|
+
"@stacks/network": "6.10.0",
|
|
98
|
+
"@stacks/transactions": "6.11.0",
|
|
99
|
+
"@zondax/ledger-stacks": "^1.0.2",
|
|
100
|
+
"@ledgerhq/coin-framework": "^0.19.1-next.0",
|
|
101
|
+
"@ledgerhq/cryptoassets": "^13.7.0",
|
|
102
|
+
"@ledgerhq/devices": "8.4.4",
|
|
103
|
+
"@ledgerhq/errors": "^6.19.1",
|
|
104
|
+
"@ledgerhq/live-env": "^2.4.1",
|
|
105
|
+
"@ledgerhq/live-network": "^2.0.3",
|
|
106
|
+
"@ledgerhq/logs": "^6.12.0",
|
|
107
|
+
"@ledgerhq/types-cryptoassets": "^7.17.0",
|
|
108
|
+
"@ledgerhq/types-live": "^6.53.1-next.0"
|
|
109
|
+
},
|
|
110
|
+
"devDependencies": {
|
|
111
|
+
"@faker-js/faker": "^8.4.1",
|
|
112
|
+
"@types/invariant": "^2.2.37",
|
|
113
|
+
"@types/jest": "^29.5.12",
|
|
114
|
+
"@types/lodash": "^4.14.191",
|
|
115
|
+
"dotenv": "^16.4.5",
|
|
116
|
+
"expect": "^27.4.6",
|
|
117
|
+
"jest": "^29.7.0",
|
|
118
|
+
"ripple-keypairs": "^2.0.0",
|
|
119
|
+
"ts-jest": "^29.1.1",
|
|
120
|
+
"typescript": "^5.4.5"
|
|
121
|
+
},
|
|
122
|
+
"scripts": {
|
|
123
|
+
"clean": "rimraf lib lib-es",
|
|
124
|
+
"build": "tsc && tsc -m ES6 --outDir lib-es",
|
|
125
|
+
"coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-stacks.json",
|
|
126
|
+
"prewatch": "pnpm build",
|
|
127
|
+
"watch": "tsc --watch",
|
|
128
|
+
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
129
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
130
|
+
"lint:fix": "pnpm lint --fix",
|
|
131
|
+
"test": "jest",
|
|
132
|
+
"test-integ": "DOTENV_CONFIG_PATH=.env.integ.test jest --config=jest.integ.config.js",
|
|
133
|
+
"typecheck": "tsc --noEmit",
|
|
134
|
+
"unimported": "unimported"
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
2
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
+
import invariant from "invariant";
|
|
4
|
+
import { broadcastTx } from "../network/api";
|
|
5
|
+
import { StacksOperation, Transaction } from "../types";
|
|
6
|
+
import { getTxToBroadcast } from "./utils/misc";
|
|
7
|
+
|
|
8
|
+
export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
|
|
9
|
+
signedOperation: { operation, signature, rawData },
|
|
10
|
+
}) => {
|
|
11
|
+
invariant(operation as StacksOperation, "StacksOperation expected");
|
|
12
|
+
const tx = await getTxToBroadcast(operation as StacksOperation, signature, rawData ?? {});
|
|
13
|
+
|
|
14
|
+
const hash = await broadcastTx(tx);
|
|
15
|
+
const result = patchOperationWithHash(operation, hash);
|
|
16
|
+
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
2
|
+
import { Account, OperationType } from "@ledgerhq/types-live";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { StacksOperation, Transaction } from "../types";
|
|
5
|
+
import { getAddress } from "./utils/misc";
|
|
6
|
+
|
|
7
|
+
export const buildOptimisticOperation = (
|
|
8
|
+
account: Account,
|
|
9
|
+
transaction: Transaction,
|
|
10
|
+
operatioinType: OperationType = "OUT",
|
|
11
|
+
): StacksOperation => {
|
|
12
|
+
const hash = "";
|
|
13
|
+
|
|
14
|
+
const { id: accountId } = account;
|
|
15
|
+
const { address } = getAddress(account);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
id: encodeOperationId(accountId, hash, operatioinType),
|
|
19
|
+
hash,
|
|
20
|
+
type: "OUT",
|
|
21
|
+
senders: [address],
|
|
22
|
+
recipients: [transaction.recipient],
|
|
23
|
+
accountId,
|
|
24
|
+
value: transaction.amount.plus(transaction.fee || 0),
|
|
25
|
+
fee: transaction.fee || new BigNumber(0),
|
|
26
|
+
blockHash: null,
|
|
27
|
+
blockHeight: null,
|
|
28
|
+
date: new Date(),
|
|
29
|
+
transactionSequenceNumber: transaction.nonce?.toNumber() || 0,
|
|
30
|
+
extra: {
|
|
31
|
+
memo: transaction.memo,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { AnchorMode } from "@stacks/transactions";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { Transaction } from "../types";
|
|
5
|
+
|
|
6
|
+
export const createTransaction: AccountBridge<Transaction>["createTransaction"] = () => ({
|
|
7
|
+
family: "stacks",
|
|
8
|
+
recipient: "",
|
|
9
|
+
amount: new BigNumber(0),
|
|
10
|
+
network: "mainnet",
|
|
11
|
+
anchorMode: AnchorMode.Any,
|
|
12
|
+
useAllAmount: false,
|
|
13
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { CommonDeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
|
|
2
|
+
import type { Account, AccountLike } from "@ledgerhq/types-live";
|
|
3
|
+
import { BigNumber } from "bignumber.js";
|
|
4
|
+
import type { Transaction, TransactionStatus } from "../types";
|
|
5
|
+
|
|
6
|
+
export type ExtraDeviceTransactionField =
|
|
7
|
+
| {
|
|
8
|
+
type: "stacks.memo";
|
|
9
|
+
label: string;
|
|
10
|
+
value: string;
|
|
11
|
+
}
|
|
12
|
+
| {
|
|
13
|
+
type: "stacks.extendedAmount";
|
|
14
|
+
label: string;
|
|
15
|
+
value: BigNumber;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type DeviceTransactionField = CommonDeviceTransactionField | ExtraDeviceTransactionField;
|
|
19
|
+
|
|
20
|
+
function getDeviceTransactionConfig(input: {
|
|
21
|
+
account: AccountLike;
|
|
22
|
+
parentAccount: Account | null | undefined;
|
|
23
|
+
transaction: Transaction;
|
|
24
|
+
status: TransactionStatus;
|
|
25
|
+
}): Array<DeviceTransactionField> {
|
|
26
|
+
const fields: Array<DeviceTransactionField> = [];
|
|
27
|
+
|
|
28
|
+
fields.push({
|
|
29
|
+
type: "stacks.extendedAmount",
|
|
30
|
+
label: "Amount",
|
|
31
|
+
value: input.transaction.amount,
|
|
32
|
+
});
|
|
33
|
+
fields.push({
|
|
34
|
+
type: "stacks.extendedAmount",
|
|
35
|
+
label: "Fees",
|
|
36
|
+
value: input.transaction.fee ? input.transaction.fee : new BigNumber(0),
|
|
37
|
+
});
|
|
38
|
+
fields.push({
|
|
39
|
+
type: "address",
|
|
40
|
+
label: "Recipient",
|
|
41
|
+
address: input.transaction.recipient,
|
|
42
|
+
});
|
|
43
|
+
fields.push({
|
|
44
|
+
type: "text",
|
|
45
|
+
label: "Nonce",
|
|
46
|
+
value: input.transaction.nonce ? input.transaction.nonce.toFixed() : "0",
|
|
47
|
+
});
|
|
48
|
+
fields.push({
|
|
49
|
+
type: "stacks.memo",
|
|
50
|
+
label: "Memo",
|
|
51
|
+
value: input.transaction.memo || "",
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return fields;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default getDeviceTransactionConfig;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
2
|
+
import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets/abandonseed";
|
|
3
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
4
|
+
import { StacksMainnet } from "@stacks/network";
|
|
5
|
+
import {
|
|
6
|
+
UnsignedTokenTransferOptions,
|
|
7
|
+
estimateTransaction,
|
|
8
|
+
makeUnsignedSTXTokenTransfer,
|
|
9
|
+
} from "@stacks/transactions";
|
|
10
|
+
import BigNumber from "bignumber.js";
|
|
11
|
+
import invariant from "invariant";
|
|
12
|
+
import { StacksNetwork } from "../network/api.types";
|
|
13
|
+
import { Transaction } from "../types";
|
|
14
|
+
import { createTransaction } from "./createTransaction";
|
|
15
|
+
|
|
16
|
+
export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"] = async ({
|
|
17
|
+
account,
|
|
18
|
+
parentAccount,
|
|
19
|
+
transaction,
|
|
20
|
+
}) => {
|
|
21
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
22
|
+
const { spendableBalance, xpub } = mainAccount;
|
|
23
|
+
invariant(xpub, "xpub is required");
|
|
24
|
+
|
|
25
|
+
const dummyTx = {
|
|
26
|
+
...createTransaction(account),
|
|
27
|
+
...transaction,
|
|
28
|
+
recipient: getAbandonSeedAddress(mainAccount.currency.id),
|
|
29
|
+
useAllAmount: true,
|
|
30
|
+
};
|
|
31
|
+
// Compute fees
|
|
32
|
+
const { recipient, anchorMode, memo, amount } = dummyTx;
|
|
33
|
+
const network = StacksNetwork[dummyTx.network] || new StacksMainnet();
|
|
34
|
+
|
|
35
|
+
const options: UnsignedTokenTransferOptions = {
|
|
36
|
+
recipient,
|
|
37
|
+
anchorMode,
|
|
38
|
+
memo,
|
|
39
|
+
network,
|
|
40
|
+
publicKey: xpub,
|
|
41
|
+
amount: amount.toFixed(),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const tx = await makeUnsignedSTXTokenTransfer(options);
|
|
45
|
+
|
|
46
|
+
const [feeEst] = await estimateTransaction(tx.payload);
|
|
47
|
+
|
|
48
|
+
const diff = spendableBalance.minus(new BigNumber(feeEst.fee));
|
|
49
|
+
return diff.gte(0) ? diff : new BigNumber(0);
|
|
50
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AmountRequired,
|
|
3
|
+
FeeNotLoaded,
|
|
4
|
+
InvalidAddress,
|
|
5
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
6
|
+
NotEnoughBalance,
|
|
7
|
+
RecipientRequired,
|
|
8
|
+
} from "@ledgerhq/errors";
|
|
9
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
10
|
+
import BigNumber from "bignumber.js";
|
|
11
|
+
import { StacksMemoTooLong } from "../errors";
|
|
12
|
+
import { Transaction, TransactionStatus } from "../types";
|
|
13
|
+
import { validateAddress } from "./utils/addresses";
|
|
14
|
+
import { getAddress } from "./utils/misc";
|
|
15
|
+
|
|
16
|
+
export const getTransactionStatus: AccountBridge<Transaction>["getTransactionStatus"] = async (
|
|
17
|
+
account,
|
|
18
|
+
transaction,
|
|
19
|
+
) => {
|
|
20
|
+
const errors: TransactionStatus["errors"] = {};
|
|
21
|
+
const warnings: TransactionStatus["warnings"] = {};
|
|
22
|
+
|
|
23
|
+
const { spendableBalance } = account;
|
|
24
|
+
const { address } = getAddress(account);
|
|
25
|
+
const { memo, recipient, useAllAmount, fee } = transaction;
|
|
26
|
+
let { amount } = transaction;
|
|
27
|
+
|
|
28
|
+
if (!recipient) {
|
|
29
|
+
errors.recipient = new RecipientRequired();
|
|
30
|
+
} else if (!validateAddress(recipient).isValid) {
|
|
31
|
+
errors.recipient = new InvalidAddress("", {
|
|
32
|
+
currencyName: account.currency.name,
|
|
33
|
+
});
|
|
34
|
+
} else if (address === recipient) {
|
|
35
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
36
|
+
} else if (!fee || fee.eq(0)) {
|
|
37
|
+
errors.gas = new FeeNotLoaded();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const estimatedFees = fee || new BigNumber(0);
|
|
41
|
+
|
|
42
|
+
const totalSpent = useAllAmount ? spendableBalance : amount.plus(estimatedFees);
|
|
43
|
+
amount = useAllAmount ? spendableBalance.minus(estimatedFees) : amount;
|
|
44
|
+
|
|
45
|
+
if (amount.lte(0)) errors.amount = new AmountRequired();
|
|
46
|
+
if (totalSpent.gt(spendableBalance)) errors.amount = new NotEnoughBalance();
|
|
47
|
+
if (memo && memo.length > 34) errors.transaction = new StacksMemoTooLong();
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
errors,
|
|
51
|
+
warnings,
|
|
52
|
+
estimatedFees,
|
|
53
|
+
amount,
|
|
54
|
+
totalSpent,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
makeAccountBridgeReceive,
|
|
3
|
+
makeScanAccounts,
|
|
4
|
+
makeSync,
|
|
5
|
+
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
6
|
+
import resolver from "../signer/index";
|
|
7
|
+
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
8
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
9
|
+
import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
10
|
+
import { defaultUpdateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
11
|
+
import type { Transaction, TransactionStatus, StacksSigner } from "../types";
|
|
12
|
+
import { getTransactionStatus } from "./getTransactionStatus";
|
|
13
|
+
import { estimateMaxSpendable } from "./estimateMaxSpendable";
|
|
14
|
+
import { prepareTransaction } from "./prepareTransaction";
|
|
15
|
+
import { createTransaction } from "./createTransaction";
|
|
16
|
+
import { getAccountShape } from "./synchronization";
|
|
17
|
+
import { buildSignOperation } from "./signOperation";
|
|
18
|
+
import { broadcast } from "./broadcast";
|
|
19
|
+
|
|
20
|
+
function buildCurrencyBridge(signerContext: SignerContext<StacksSigner>): CurrencyBridge {
|
|
21
|
+
const getAddress = resolver(signerContext);
|
|
22
|
+
|
|
23
|
+
const scanAccounts = makeScanAccounts({
|
|
24
|
+
getAccountShape,
|
|
25
|
+
getAddressFn: getAddressWrapper(getAddress),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
preload: () => Promise.resolve({}),
|
|
30
|
+
hydrate: () => {},
|
|
31
|
+
scanAccounts,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const sync = makeSync({ getAccountShape });
|
|
36
|
+
|
|
37
|
+
function buildAccountBridge(
|
|
38
|
+
signerContext: SignerContext<StacksSigner>,
|
|
39
|
+
): AccountBridge<Transaction, Account, TransactionStatus> {
|
|
40
|
+
const getAddress = resolver(signerContext);
|
|
41
|
+
const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
|
|
42
|
+
|
|
43
|
+
const signOperation = buildSignOperation(signerContext);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
estimateMaxSpendable,
|
|
47
|
+
createTransaction,
|
|
48
|
+
updateTransaction: defaultUpdateTransaction,
|
|
49
|
+
getTransactionStatus,
|
|
50
|
+
prepareTransaction,
|
|
51
|
+
sync,
|
|
52
|
+
receive,
|
|
53
|
+
signOperation,
|
|
54
|
+
broadcast,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createBridges(signerContext: SignerContext<StacksSigner>) {
|
|
59
|
+
return {
|
|
60
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
61
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export { prepareTransaction, estimateMaxSpendable };
|