@ledgerhq/coin-ton 0.3.12-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 +19 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +12 -0
- package/lib/__tests__/fixtures/api.fixtures.d.ts +4 -0
- package/lib/__tests__/fixtures/api.fixtures.d.ts.map +1 -0
- package/lib/__tests__/fixtures/api.fixtures.js +33 -0
- package/lib/__tests__/fixtures/api.fixtures.js.map +1 -0
- package/lib/__tests__/fixtures/common.fixtures.d.ts +29 -0
- package/lib/__tests__/fixtures/common.fixtures.d.ts.map +1 -0
- package/lib/__tests__/fixtures/common.fixtures.js +124 -0
- package/lib/__tests__/fixtures/common.fixtures.js.map +1 -0
- package/lib/__tests__/integration/bridge.integration.test.d.ts +14 -0
- package/lib/__tests__/integration/bridge.integration.test.d.ts.map +1 -0
- package/lib/__tests__/integration/bridge.integration.test.js +136 -0
- package/lib/__tests__/integration/bridge.integration.test.js.map +1 -0
- package/lib/__tests__/unit/api.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/api.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/api.unit.test.js +77 -0
- package/lib/__tests__/unit/api.unit.test.js.map +1 -0
- package/lib/__tests__/unit/broadcast.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/broadcast.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/broadcast.unit.test.js +40 -0
- package/lib/__tests__/unit/broadcast.unit.test.js.map +1 -0
- package/lib/__tests__/unit/createTransaction.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/createTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/createTransaction.unit.test.js +34 -0
- package/lib/__tests__/unit/createTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js +74 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js +31 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js +96 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.js +67 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.js.map +1 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.js +42 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/unit/signOperation.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/signOperation.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/signOperation.unit.test.js +83 -0
- package/lib/__tests__/unit/signOperation.unit.test.js.map +1 -0
- package/lib/__tests__/unit/txn.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/txn.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/txn.unit.test.js +116 -0
- package/lib/__tests__/unit/txn.unit.test.js.map +1 -0
- package/lib/__tests__/unit/utils.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/utils.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/utils.unit.test.js +97 -0
- package/lib/__tests__/unit/utils.unit.test.js.map +1 -0
- package/lib/bridge/bridgeHelpers/api.d.ts +10 -0
- package/lib/bridge/bridgeHelpers/api.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/api.js +104 -0
- package/lib/bridge/bridgeHelpers/api.js.map +1 -0
- package/lib/bridge/bridgeHelpers/api.types.d.ts +164 -0
- package/lib/bridge/bridgeHelpers/api.types.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/api.types.js +3 -0
- package/lib/bridge/bridgeHelpers/api.types.js.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.d.ts +5 -0
- package/lib/bridge/bridgeHelpers/txn.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.js +166 -0
- package/lib/bridge/bridgeHelpers/txn.js.map +1 -0
- package/lib/bridge/js.d.ts +12 -0
- package/lib/bridge/js.d.ts.map +1 -0
- package/lib/bridge/js.js +65 -0
- package/lib/bridge/js.js.map +1 -0
- package/lib/broadcast.d.ts +5 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +19 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/cli-transaction.d.ts +12 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +21 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/config.d.ts +9 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +16 -0
- package/lib/config.js.map +1 -0
- package/lib/createTransaction.d.ts +5 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +16 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +11 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +37 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/errors.d.ts +4 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +9 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +5 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +32 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +5 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +97 -0
- package/lib/getTransactionStatus.js.map +1 -0
- package/lib/hw-getAddress.d.ts +6 -0
- package/lib/hw-getAddress.d.ts.map +1 -0
- package/lib/hw-getAddress.js +31 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/hw-signMessage.d.ts +12 -0
- package/lib/hw-signMessage.d.ts.map +1 -0
- package/lib/hw-signMessage.js +33 -0
- package/lib/hw-signMessage.js.map +1 -0
- package/lib/prepareTransaction.d.ts +5 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +29 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/signOperation.d.ts +11 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +96 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +27 -0
- package/lib/signer.d.ts.map +1 -0
- package/lib/signer.js +3 -0
- package/lib/signer.js.map +1 -0
- package/lib/specs.d.ts +8 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +106 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +4 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +34 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronisation.d.ts +5 -0
- package/lib/synchronisation.d.ts.map +1 -0
- package/lib/synchronisation.js +95 -0
- package/lib/synchronisation.js.map +1 -0
- package/lib/transaction.d.ts +14 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +41 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types.d.ts +65 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +11 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +125 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/__tests__/fixtures/api.fixtures.d.ts +4 -0
- package/lib-es/__tests__/fixtures/api.fixtures.d.ts.map +1 -0
- package/lib-es/__tests__/fixtures/api.fixtures.js +30 -0
- package/lib-es/__tests__/fixtures/api.fixtures.js.map +1 -0
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts +29 -0
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +1 -0
- package/lib-es/__tests__/fixtures/common.fixtures.js +118 -0
- package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -0
- package/lib-es/__tests__/integration/bridge.integration.test.d.ts +14 -0
- package/lib-es/__tests__/integration/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/__tests__/integration/bridge.integration.test.js +130 -0
- package/lib-es/__tests__/integration/bridge.integration.test.js.map +1 -0
- package/lib-es/__tests__/unit/api.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/api.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/api.unit.test.js +52 -0
- package/lib-es/__tests__/unit/api.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.js +35 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.js +29 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js +69 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js +26 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js +91 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.js +62 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js +37 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.js +78 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/txn.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/txn.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/txn.unit.test.js +111 -0
- package/lib-es/__tests__/unit/txn.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/utils.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/utils.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/utils.unit.test.js +95 -0
- package/lib-es/__tests__/unit/utils.unit.test.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.d.ts +10 -0
- package/lib-es/bridge/bridgeHelpers/api.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.js +93 -0
- package/lib-es/bridge/bridgeHelpers/api.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.types.d.ts +164 -0
- package/lib-es/bridge/bridgeHelpers/api.types.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.types.js +2 -0
- package/lib-es/bridge/bridgeHelpers/api.types.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.d.ts +5 -0
- package/lib-es/bridge/bridgeHelpers/txn.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.js +158 -0
- package/lib-es/bridge/bridgeHelpers/txn.js.map +1 -0
- package/lib-es/bridge/js.d.ts +12 -0
- package/lib-es/bridge/js.d.ts.map +1 -0
- package/lib-es/bridge/js.js +56 -0
- package/lib-es/bridge/js.js.map +1 -0
- package/lib-es/broadcast.d.ts +5 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +17 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +12 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +15 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/config.d.ts +9 -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/createTransaction.d.ts +5 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +14 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +11 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +35 -0
- package/lib-es/deviceTransactionConfig.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 +6 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +30 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +5 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +93 -0
- package/lib-es/getTransactionStatus.js.map +1 -0
- package/lib-es/hw-getAddress.d.ts +6 -0
- package/lib-es/hw-getAddress.d.ts.map +1 -0
- package/lib-es/hw-getAddress.js +29 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/hw-signMessage.d.ts +12 -0
- package/lib-es/hw-signMessage.d.ts.map +1 -0
- package/lib-es/hw-signMessage.js +29 -0
- package/lib-es/hw-signMessage.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +5 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +27 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/signOperation.d.ts +11 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +91 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +27 -0
- package/lib-es/signer.d.ts.map +1 -0
- package/lib-es/signer.js +2 -0
- package/lib-es/signer.js.map +1 -0
- package/lib-es/specs.d.ts +8 -0
- package/lib-es/specs.d.ts.map +1 -0
- package/lib-es/specs.js +99 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +4 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +31 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronisation.d.ts +5 -0
- package/lib-es/synchronisation.d.ts.map +1 -0
- package/lib-es/synchronisation.js +88 -0
- package/lib-es/synchronisation.js.map +1 -0
- package/lib-es/transaction.d.ts +14 -0
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/transaction.js +33 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types.d.ts +65 -0
- package/lib-es/types.d.ts.map +1 -0
- package/lib-es/types.js +2 -0
- package/lib-es/types.js.map +1 -0
- package/lib-es/utils.d.ts +11 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +112 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +86 -0
- package/src/__tests__/fixtures/api.fixtures.ts +39 -0
- package/src/__tests__/fixtures/common.fixtures.ts +139 -0
- package/src/__tests__/integration/bridge.integration.test.ts +135 -0
- package/src/__tests__/unit/api.unit.test.ts +60 -0
- package/src/__tests__/unit/broadcast.unit.test.ts +36 -0
- package/src/__tests__/unit/createTransaction.unit.test.ts +20 -0
- package/src/__tests__/unit/deviceTransactionConfig.unit.test.ts +69 -0
- package/src/__tests__/unit/estimateMaxSpendable.unit.test.ts +19 -0
- package/src/__tests__/unit/getTransactionStatus.unit.test.ts +119 -0
- package/src/__tests__/unit/hw-getAddress.unit.test.ts +58 -0
- package/src/__tests__/unit/prepareTransaction.unit.test.ts +52 -0
- package/src/__tests__/unit/signOperation.unit.test.ts +90 -0
- package/src/__tests__/unit/txn.unit.test.ts +121 -0
- package/src/__tests__/unit/utils.unit.test.ts +126 -0
- package/src/bridge/bridgeHelpers/api.ts +104 -0
- package/src/bridge/bridgeHelpers/api.types.ts +178 -0
- package/src/bridge/bridgeHelpers/txn.ts +166 -0
- package/src/bridge/js.ts +65 -0
- package/src/broadcast.ts +13 -0
- package/src/cli-transaction.ts +30 -0
- package/src/config.ts +21 -0
- package/src/createTransaction.ts +17 -0
- package/src/deviceTransactionConfig.ts +48 -0
- package/src/errors.ts +6 -0
- package/src/estimateMaxSpendable.ts +40 -0
- package/src/getTransactionStatus.ts +130 -0
- package/src/hw-getAddress.ts +28 -0
- package/src/hw-signMessage.ts +31 -0
- package/src/prepareTransaction.ts +27 -0
- package/src/signOperation.ts +115 -0
- package/src/signer.ts +32 -0
- package/src/specs.ts +122 -0
- package/src/speculos-deviceActions.ts +38 -0
- package/src/synchronisation.ts +91 -0
- package/src/transaction.ts +61 -0
- package/src/types.ts +82 -0
- package/src/utils.ts +120 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SpeculosButton, deviceActionFlow, formatDeviceAmount, } from "@ledgerhq/coin-framework/bot/specs";
|
|
2
|
+
export const acceptTransaction = deviceActionFlow({
|
|
3
|
+
steps: [
|
|
4
|
+
{
|
|
5
|
+
title: "Review",
|
|
6
|
+
button: SpeculosButton.RIGHT,
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
title: "To",
|
|
10
|
+
button: SpeculosButton.RIGHT,
|
|
11
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
title: "Amount",
|
|
15
|
+
button: SpeculosButton.RIGHT,
|
|
16
|
+
expectedValue: ({ account, transaction }) => transaction.useAllAmount
|
|
17
|
+
? "ALL YOUR TONs"
|
|
18
|
+
: formatDeviceAmount(account.currency, transaction.amount),
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: "Comment",
|
|
22
|
+
button: SpeculosButton.RIGHT,
|
|
23
|
+
expectedValue: ({ transaction }) => transaction.comment.text,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
title: "Approve",
|
|
27
|
+
button: SpeculosButton.BOTH,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=speculos-deviceActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speculos-deviceActions.js","sourceRoot":"","sources":["../src/speculos-deviceActions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,oCAAoC,CAAC;AAI5C,MAAM,CAAC,MAAM,iBAAiB,GAAkD,gBAAgB,CAAC;IAC/F,KAAK,EAAE;QACL;YACE,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,cAAc,CAAC,KAAK;SAC7B;QACD;YACE,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS;SAC1D;QACD;YACE,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAC1C,WAAW,CAAC,YAAY;gBACtB,CAAC,CAAC,eAAe;gBACjB,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC;SAC/D;QACD;YACE,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI;SAC7D;QACD;YACE,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,cAAc,CAAC,IAAI;SAC5B;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
2
|
+
import { Account } from "@ledgerhq/types-live";
|
|
3
|
+
export declare const getAccountShape: GetAccountShape<Account>;
|
|
4
|
+
export declare const sync: (initialAccount: Account, syncConfig: import("@ledgerhq/types-live").SyncConfig) => import("rxjs").Observable<(arg0: Account) => Account>;
|
|
5
|
+
//# sourceMappingURL=synchronisation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synchronisation.d.ts","sourceRoot":"","sources":["../src/synchronisation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAsB,MAAM,2CAA2C,CAAC;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAQ/C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,OAAO,CAiDpD,CAAC;AA8BF,eAAO,MAAM,IAAI,2IAA0C,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { decodeAccountId, encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
11
|
+
import { makeSync, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
12
|
+
import { log } from "@ledgerhq/logs";
|
|
13
|
+
import BigNumber from "bignumber.js";
|
|
14
|
+
import flatMap from "lodash/flatMap";
|
|
15
|
+
import { fetchAccountInfo, fetchLastBlockNumber } from "./bridge/bridgeHelpers/api";
|
|
16
|
+
import { getTransactions, mapTxToOps } from "./bridge/bridgeHelpers/txn";
|
|
17
|
+
export const getAccountShape = (info) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
19
|
+
const { address, rest, currency, derivationMode, initialAccount } = info;
|
|
20
|
+
const publicKey = reconciliatePubkey(rest === null || rest === void 0 ? void 0 : rest.publicKey, initialAccount);
|
|
21
|
+
const blockHeight = yield fetchLastBlockNumber();
|
|
22
|
+
const accountId = encodeAccountId({
|
|
23
|
+
type: "js",
|
|
24
|
+
version: "2",
|
|
25
|
+
currencyId: currency.id,
|
|
26
|
+
xpubOrAddress: publicKey,
|
|
27
|
+
derivationMode,
|
|
28
|
+
});
|
|
29
|
+
log("debug", `Generation account shape for ${address}`);
|
|
30
|
+
const newTxs = { transactions: [], address_book: {} };
|
|
31
|
+
const oldOps = ((_a = initialAccount === null || initialAccount === void 0 ? void 0 : initialAccount.operations) !== null && _a !== void 0 ? _a : []);
|
|
32
|
+
const { last_transaction_lt, balance } = yield fetchAccountInfo(address);
|
|
33
|
+
// if last_transaction_lt is empty, then there are no transactions in account
|
|
34
|
+
if (last_transaction_lt != null) {
|
|
35
|
+
if (oldOps.length === 0) {
|
|
36
|
+
const [tmpTxs] = yield Promise.all([getTransactions(address)]);
|
|
37
|
+
newTxs.transactions.push(...tmpTxs.transactions);
|
|
38
|
+
newTxs.address_book = Object.assign(Object.assign({}, newTxs.address_book), tmpTxs.address_book);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// if they are the same, we have no new ops
|
|
42
|
+
if (oldOps[0].extra.lt !== last_transaction_lt) {
|
|
43
|
+
const [tmpTxs] = yield Promise.all([getTransactions(address, oldOps[0].extra.lt)]);
|
|
44
|
+
newTxs.transactions.push(...tmpTxs.transactions);
|
|
45
|
+
newTxs.address_book = Object.assign(Object.assign({}, newTxs.address_book), tmpTxs.address_book);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const newOps = flatMap(newTxs.transactions, mapTxToOps(accountId, address, newTxs.address_book));
|
|
50
|
+
const operations = mergeOps(oldOps, newOps);
|
|
51
|
+
const toReturn = {
|
|
52
|
+
id: accountId,
|
|
53
|
+
balance: new BigNumber(balance),
|
|
54
|
+
spendableBalance: new BigNumber(balance),
|
|
55
|
+
operations,
|
|
56
|
+
operationsCount: operations.length,
|
|
57
|
+
blockHeight,
|
|
58
|
+
xpub: publicKey,
|
|
59
|
+
lastSyncDate: new Date(),
|
|
60
|
+
};
|
|
61
|
+
return toReturn;
|
|
62
|
+
});
|
|
63
|
+
const postSync = (initial, synced) => {
|
|
64
|
+
const initialPendingOperations = initial.pendingOperations || [];
|
|
65
|
+
const { operations } = synced;
|
|
66
|
+
const pendingOperations = initialPendingOperations.filter(op => !operations.some(o => o.id === op.id));
|
|
67
|
+
// Set of hashes from the pending operations of the main account
|
|
68
|
+
const coinPendingOperationsHashes = new Set();
|
|
69
|
+
for (const op of pendingOperations) {
|
|
70
|
+
coinPendingOperationsHashes.add(op.hash);
|
|
71
|
+
}
|
|
72
|
+
return Object.assign(Object.assign({}, synced), { pendingOperations });
|
|
73
|
+
};
|
|
74
|
+
function reconciliatePubkey(publicKey, initialAccount) {
|
|
75
|
+
var _a;
|
|
76
|
+
if ((publicKey === null || publicKey === void 0 ? void 0 : publicKey.length) === 64)
|
|
77
|
+
return publicKey;
|
|
78
|
+
if (initialAccount) {
|
|
79
|
+
if (((_a = initialAccount.xpub) === null || _a === void 0 ? void 0 : _a.length) === 64)
|
|
80
|
+
return initialAccount.xpub;
|
|
81
|
+
const { xpubOrAddress } = decodeAccountId(initialAccount.id);
|
|
82
|
+
if (xpubOrAddress.length === 64)
|
|
83
|
+
return xpubOrAddress;
|
|
84
|
+
}
|
|
85
|
+
throw Error("[ton] pubkey was not properly restored");
|
|
86
|
+
}
|
|
87
|
+
export const sync = makeSync({ getAccountShape, postSync });
|
|
88
|
+
//# sourceMappingURL=synchronisation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synchronisation.js","sourceRoot":"","sources":["../src/synchronisation.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAC1F,OAAO,EAAmB,QAAQ,EAA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AQ,CAAC,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
2
|
+
import type { Transaction, TransactionRaw } from "./types";
|
|
3
|
+
export declare const formatTransaction: ({ recipient, useAllAmount, amount }: Transaction, account: Account) => string;
|
|
4
|
+
export declare const fromTransactionRaw: (tr: TransactionRaw) => Transaction;
|
|
5
|
+
declare const _default: {
|
|
6
|
+
formatTransaction: ({ recipient, useAllAmount, amount }: Transaction, account: Account) => string;
|
|
7
|
+
fromTransactionRaw: (tr: TransactionRaw) => Transaction;
|
|
8
|
+
toTransactionRaw: (transaction: Transaction) => TransactionRaw;
|
|
9
|
+
fromTransactionStatusRaw: (ts: import("@ledgerhq/types-live").TransactionStatusCommonRaw) => import("@ledgerhq/types-live").TransactionStatusCommon;
|
|
10
|
+
toTransactionStatusRaw: (ts: import("@ledgerhq/types-live").TransactionStatusCommon) => import("@ledgerhq/types-live").TransactionStatusCommonRaw;
|
|
11
|
+
formatTransactionStatus: (t: import("@ledgerhq/types-live").TransactionCommon, { errors, warnings, estimatedFees, amount, totalSpent }: import("@ledgerhq/types-live").TransactionStatusCommon, mainAccount: Account) => string;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
14
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE3D,eAAO,MAAM,iBAAiB,wCACS,WAAW,WACvC,OAAO,KACf,MAYa,CAAC;AAEjB,eAAO,MAAM,kBAAkB,OAAQ,cAAc,KAAG,WASvD,CAAC;;;;;;;;;AAcF,wBAOE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
|
|
2
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
3
|
+
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
4
|
+
import { fromTransactionCommonRaw, fromTransactionStatusRawCommon as fromTransactionStatusRaw, toTransactionCommonRaw, toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization";
|
|
5
|
+
import BigNumber from "bignumber.js";
|
|
6
|
+
export const formatTransaction = ({ recipient, useAllAmount, amount }, account) => `
|
|
7
|
+
SEND ${useAllAmount
|
|
8
|
+
? "MAX"
|
|
9
|
+
: amount.isZero()
|
|
10
|
+
? ""
|
|
11
|
+
: " " +
|
|
12
|
+
formatCurrencyUnit(getAccountCurrency(account).units[0], amount, {
|
|
13
|
+
showCode: true,
|
|
14
|
+
disableRounding: true,
|
|
15
|
+
})}
|
|
16
|
+
TO ${recipient}`;
|
|
17
|
+
export const fromTransactionRaw = (tr) => {
|
|
18
|
+
const common = fromTransactionCommonRaw(tr);
|
|
19
|
+
return Object.assign(Object.assign({}, common), { family: tr.family, fees: new BigNumber(tr.fees), comment: tr.comment });
|
|
20
|
+
};
|
|
21
|
+
const toTransactionRaw = (transaction) => {
|
|
22
|
+
const common = toTransactionCommonRaw(transaction);
|
|
23
|
+
return Object.assign(Object.assign({}, common), { family: transaction.family, amount: transaction.amount.toFixed(), fees: transaction.fees.toFixed(), comment: transaction.comment });
|
|
24
|
+
};
|
|
25
|
+
export default {
|
|
26
|
+
formatTransaction,
|
|
27
|
+
fromTransactionRaw,
|
|
28
|
+
toTransactionRaw,
|
|
29
|
+
fromTransactionStatusRaw,
|
|
30
|
+
toTransactionStatusRaw,
|
|
31
|
+
formatTransactionStatus,
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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AAM,EAAE,WAAW,CAAC,MAAM,EAC1B,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE,EACpC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,EAChC,OAAO,EAAE,WAAW,CAAC,OAAO,IAC5B;AACJ,CAAC,CAAC;AAEF,eAAe;IACb,iBAAiB;IACjB,kBAAkB;IAClB,gBAAgB;IAChB,wBAAwB;IACxB,sBAAsB;IACtB,uBAAuB;CACxB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Operation, TransactionCommon, TransactionCommonRaw, TransactionStatusCommon, TransactionStatusCommonRaw } from "@ledgerhq/types-live";
|
|
2
|
+
import { Address, SendMode, StateInit } from "@ton/core";
|
|
3
|
+
import { Cell } from "@ton/ton";
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
type FamilyType = "ton";
|
|
6
|
+
export interface TonComment {
|
|
7
|
+
isEncrypted: boolean;
|
|
8
|
+
text: string;
|
|
9
|
+
}
|
|
10
|
+
export type Transaction = TransactionCommon & {
|
|
11
|
+
family: FamilyType;
|
|
12
|
+
fees: BigNumber;
|
|
13
|
+
comment: TonComment;
|
|
14
|
+
};
|
|
15
|
+
export type TransactionRaw = TransactionCommonRaw & {
|
|
16
|
+
family: FamilyType;
|
|
17
|
+
fees: string;
|
|
18
|
+
comment: TonComment;
|
|
19
|
+
};
|
|
20
|
+
export type TransactionStatus = TransactionStatusCommon;
|
|
21
|
+
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
|
22
|
+
export type TonOperation = Operation<TonOperationExtra>;
|
|
23
|
+
export type TonPayloadJettonTransfer = {
|
|
24
|
+
type: "jetton-transfer";
|
|
25
|
+
queryId: bigint | null;
|
|
26
|
+
amount: bigint;
|
|
27
|
+
destination: Address;
|
|
28
|
+
responseDestination: Address;
|
|
29
|
+
customPayload: TonCell | null;
|
|
30
|
+
forwardAmount: bigint;
|
|
31
|
+
forwardPayload: TonCell | null;
|
|
32
|
+
};
|
|
33
|
+
export type TonPayloadNftTransfer = {
|
|
34
|
+
type: "nft-transfer";
|
|
35
|
+
queryId: bigint | null;
|
|
36
|
+
newOwner: Address;
|
|
37
|
+
responseDestination: Address;
|
|
38
|
+
customPayload: TonCell | null;
|
|
39
|
+
forwardAmount: bigint;
|
|
40
|
+
forwardPayload: TonCell | null;
|
|
41
|
+
};
|
|
42
|
+
export type TonPayloadComment = {
|
|
43
|
+
type: "comment";
|
|
44
|
+
text: string;
|
|
45
|
+
};
|
|
46
|
+
export type TonPayloadFormat = TonPayloadComment | TonPayloadJettonTransfer | TonPayloadNftTransfer;
|
|
47
|
+
export interface TonTransaction {
|
|
48
|
+
to: Address;
|
|
49
|
+
sendMode: SendMode;
|
|
50
|
+
seqno: number;
|
|
51
|
+
timeout: number;
|
|
52
|
+
bounce: boolean;
|
|
53
|
+
amount: bigint;
|
|
54
|
+
stateInit?: StateInit;
|
|
55
|
+
payload?: TonPayloadFormat;
|
|
56
|
+
}
|
|
57
|
+
export interface TonCell extends Cell {
|
|
58
|
+
}
|
|
59
|
+
export type TonOperationExtra = {
|
|
60
|
+
comment: TonComment;
|
|
61
|
+
lt: string;
|
|
62
|
+
explorerHash: string;
|
|
63
|
+
};
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,KAAK,UAAU,GAAG,KAAK,CAAC;AAIxB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,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAAG,wBAAwB,GAAG,qBAAqB,CAAC;AAEpG,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B;AAED,MAAM,WAAW,OAAQ,SAAQ,IAAI;CAAG;AAExC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,UAAU,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
package/lib-es/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Account } from "@ledgerhq/types-live";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import { TonComment, TonTransaction, Transaction } from "./types";
|
|
4
|
+
export declare const isAddressValid: (recipient: string) => boolean;
|
|
5
|
+
export declare const addressesAreEqual: (addr1: string, addr2: string) => boolean;
|
|
6
|
+
export declare const buildTonTransaction: (transaction: Transaction, seqno: number) => TonTransaction;
|
|
7
|
+
export declare const commentIsValid: (msg: TonComment) => boolean;
|
|
8
|
+
export declare const getTransferExpirationTime: () => number;
|
|
9
|
+
export declare const getTonEstimatedFees: (account: Account, needsInit: boolean, tx: TonTransaction) => Promise<BigNumber>;
|
|
10
|
+
export declare const getLedgerTonPath: (path: string) => number[];
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAElE,eAAO,MAAM,cAAc,cAAe,MAAM,YAS/C,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,MAAM,SAAS,MAAM,YAU7D,CAAC;AAEF,eAAO,MAAM,mBAAmB,gBAAiB,WAAW,SAAS,MAAM,KAAG,cA+B7E,CAAC;AAGF,eAAO,MAAM,cAAc,QAAS,UAAU,YACiC,CAAC;AAGhF,eAAO,MAAM,yBAAyB,cAA2C,CAAC;AAElF,eAAO,MAAM,mBAAmB,YACrB,OAAO,aACL,OAAO,MACd,cAAc,uBA8BnB,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAU,MAAM,KAAG,MAAM,EAcrD,CAAC"}
|
package/lib-es/utils.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { decodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
11
|
+
import { SendMode, Address as TonAddress, WalletContractV4, comment, internal } from "@ton/ton";
|
|
12
|
+
import BigNumber from "bignumber.js";
|
|
13
|
+
import { estimateFee } from "./bridge/bridgeHelpers/api";
|
|
14
|
+
export const isAddressValid = (recipient) => {
|
|
15
|
+
try {
|
|
16
|
+
return Boolean((TonAddress.isRaw(recipient) || TonAddress.isFriendly(recipient)) &&
|
|
17
|
+
TonAddress.parse(recipient));
|
|
18
|
+
}
|
|
19
|
+
catch (_a) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export const addressesAreEqual = (addr1, addr2) => {
|
|
24
|
+
try {
|
|
25
|
+
return (isAddressValid(addr1) &&
|
|
26
|
+
isAddressValid(addr2) &&
|
|
27
|
+
TonAddress.parse(addr1).equals(TonAddress.parse(addr2)));
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export const buildTonTransaction = (transaction, seqno) => {
|
|
34
|
+
const { useAllAmount, amount, comment, recipient } = transaction;
|
|
35
|
+
let recipientParsed = recipient;
|
|
36
|
+
// if recipient is not valid calculate fees with empty address
|
|
37
|
+
// we handle invalid addresses in account bridge
|
|
38
|
+
try {
|
|
39
|
+
TonAddress.parse(recipientParsed);
|
|
40
|
+
}
|
|
41
|
+
catch (_a) {
|
|
42
|
+
recipientParsed = new TonAddress(0, Buffer.alloc(32)).toRawString();
|
|
43
|
+
}
|
|
44
|
+
const finalAmount = useAllAmount ? BigInt(0) : BigInt(amount.toFixed());
|
|
45
|
+
const tonTransaction = {
|
|
46
|
+
to: TonAddress.parse(recipientParsed),
|
|
47
|
+
seqno,
|
|
48
|
+
amount: finalAmount,
|
|
49
|
+
bounce: TonAddress.isFriendly(recipientParsed)
|
|
50
|
+
? TonAddress.parseFriendly(recipientParsed).isBounceable
|
|
51
|
+
: true,
|
|
52
|
+
timeout: getTransferExpirationTime(),
|
|
53
|
+
sendMode: useAllAmount
|
|
54
|
+
? SendMode.CARRY_ALL_REMAINING_BALANCE
|
|
55
|
+
: SendMode.IGNORE_ERRORS + SendMode.PAY_GAS_SEPARATELY,
|
|
56
|
+
};
|
|
57
|
+
if (comment.text.length) {
|
|
58
|
+
tonTransaction.payload = { type: "comment", text: comment.text };
|
|
59
|
+
}
|
|
60
|
+
return tonTransaction;
|
|
61
|
+
};
|
|
62
|
+
// max length is 120 and only ascii allowed
|
|
63
|
+
export const commentIsValid = (msg) => !msg.isEncrypted && msg.text.length <= 120 && /^[\x20-\x7F]*$/.test(msg.text);
|
|
64
|
+
// 1 minute
|
|
65
|
+
export const getTransferExpirationTime = () => Math.floor(Date.now() / 1000 + 60);
|
|
66
|
+
export const getTonEstimatedFees = (account, needsInit, tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const { xpubOrAddress: pubKey } = decodeAccountId(account.id);
|
|
69
|
+
if (pubKey.length !== 64)
|
|
70
|
+
throw Error("[ton] pubKey can't be found");
|
|
71
|
+
if (tx.payload && ((_a = tx.payload) === null || _a === void 0 ? void 0 : _a.type) !== "comment") {
|
|
72
|
+
throw Error("[ton] payload kind not expected");
|
|
73
|
+
}
|
|
74
|
+
const contract = WalletContractV4.create({ workchain: 0, publicKey: Buffer.from(pubKey, "hex") });
|
|
75
|
+
const transfer = contract.createTransfer({
|
|
76
|
+
seqno: tx.seqno,
|
|
77
|
+
secretKey: Buffer.alloc(64), // secretKey set to 0, signature is not verified
|
|
78
|
+
messages: [
|
|
79
|
+
internal({
|
|
80
|
+
bounce: tx.bounce,
|
|
81
|
+
to: tx.to,
|
|
82
|
+
value: tx.amount,
|
|
83
|
+
body: ((_b = tx.payload) === null || _b === void 0 ? void 0 : _b.text) ? comment(tx.payload.text) : undefined,
|
|
84
|
+
}),
|
|
85
|
+
],
|
|
86
|
+
sendMode: tx.sendMode,
|
|
87
|
+
});
|
|
88
|
+
const initCode = needsInit ? contract.init.code.toBoc().toString("base64") : undefined;
|
|
89
|
+
const initData = needsInit ? contract.init.data.toBoc().toString("base64") : undefined;
|
|
90
|
+
const fee = yield estimateFee(account.freshAddress, transfer.toBoc().toString("base64"), initCode, initData);
|
|
91
|
+
return BigNumber(fee.fwd_fee + fee.gas_fee + fee.in_fwd_fee + fee.storage_fee);
|
|
92
|
+
});
|
|
93
|
+
export const getLedgerTonPath = (path) => {
|
|
94
|
+
const numPath = [];
|
|
95
|
+
if (!path)
|
|
96
|
+
throw Error("[ton] Path is empty");
|
|
97
|
+
if (path.startsWith("m/"))
|
|
98
|
+
path = path.slice(2);
|
|
99
|
+
const pathEntries = path.split("/");
|
|
100
|
+
if (pathEntries.length !== 6)
|
|
101
|
+
throw Error(`[ton] Path length is not right ${path}`);
|
|
102
|
+
for (const entry of pathEntries) {
|
|
103
|
+
if (!entry.endsWith("'"))
|
|
104
|
+
throw Error(`[ton] Path entry is not hardened ${path}`);
|
|
105
|
+
const num = parseInt(entry.slice(0, entry.length - 1));
|
|
106
|
+
if (!Number.isInteger(num) || num < 0 || num >= 0x80000000)
|
|
107
|
+
throw Error(`[ton] Path entry is not right ${path}`);
|
|
108
|
+
numPath.push(num);
|
|
109
|
+
}
|
|
110
|
+
return numPath;
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAEzE,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,UAAU,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAChG,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAGzD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAiB,EAAE,EAAE;IAClD,IAAI,CAAC;QACH,OAAO,OAAO,CACZ,CAAC,UAAU,CAAC,KAAK,CAA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|
|
1
|
+
{
|
|
2
|
+
"name": "@ledgerhq/coin-ton",
|
|
3
|
+
"version": "0.3.12-next.0",
|
|
4
|
+
"description": "Ton Coin integration",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Ledger",
|
|
7
|
+
"LedgerWallet",
|
|
8
|
+
"ton",
|
|
9
|
+
"Ton",
|
|
10
|
+
"Hardware Wallet"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/LedgerHQ/ledger-live/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-ton",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
"*": {
|
|
25
|
+
"lib/*": [
|
|
26
|
+
"lib/*"
|
|
27
|
+
],
|
|
28
|
+
"lib-es/*": [
|
|
29
|
+
"lib-es/*"
|
|
30
|
+
],
|
|
31
|
+
"*": [
|
|
32
|
+
"lib/*"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"exports": {
|
|
37
|
+
"./lib/*": "./lib/*.js",
|
|
38
|
+
"./lib-es/*": "./lib-es/*.js",
|
|
39
|
+
"./*": {
|
|
40
|
+
"require": "./lib/*.js",
|
|
41
|
+
"default": "./lib-es/*.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"license": "Apache-2.0",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@ton/core": "^0.56.1",
|
|
48
|
+
"@ton/ton": "^13.11.1",
|
|
49
|
+
"@ton/crypto": "3.2.0",
|
|
50
|
+
"bignumber.js": "^9.1.2",
|
|
51
|
+
"expect": "^27.4.6",
|
|
52
|
+
"invariant": "^2.2.2",
|
|
53
|
+
"lodash": "^4.17.21",
|
|
54
|
+
"msw": "^2.0.11",
|
|
55
|
+
"rxjs": "^7.8.1",
|
|
56
|
+
"@ledgerhq/coin-framework": "^0.17.0-next.0",
|
|
57
|
+
"@ledgerhq/cryptoassets": "^13.3.0-next.0",
|
|
58
|
+
"@ledgerhq/devices": "^8.4.2",
|
|
59
|
+
"@ledgerhq/errors": "^6.18.0",
|
|
60
|
+
"@ledgerhq/live-env": "^2.2.0-next.0",
|
|
61
|
+
"@ledgerhq/live-network": "^1.4.0-next.0",
|
|
62
|
+
"@ledgerhq/logs": "^6.12.0",
|
|
63
|
+
"@ledgerhq/types-cryptoassets": "^7.15.0-next.0",
|
|
64
|
+
"@ledgerhq/types-live": "^6.50.0-next.0"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/invariant": "^2.2.2",
|
|
68
|
+
"@types/jest": "^29.5.10",
|
|
69
|
+
"@types/lodash": "^4.14.191",
|
|
70
|
+
"jest": "^29.7.0",
|
|
71
|
+
"ts-jest": "^29.1.1"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"clean": "rimraf lib lib-es",
|
|
75
|
+
"coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-ton.json",
|
|
76
|
+
"build": "tsc && tsc -m ES6 --outDir lib-es",
|
|
77
|
+
"prewatch": "pnpm build",
|
|
78
|
+
"watch": "tsc --watch",
|
|
79
|
+
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
80
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
81
|
+
"lint:fix": "pnpm lint --fix",
|
|
82
|
+
"prettier": "prettier --write 'src/**/*.?s'",
|
|
83
|
+
"test": "jest",
|
|
84
|
+
"unimported": "unimported"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { HttpResponse, http } from "msw";
|
|
2
|
+
import { setupServer } from "msw/node";
|
|
3
|
+
import {
|
|
4
|
+
lastBlockNumber,
|
|
5
|
+
tonAccount,
|
|
6
|
+
tonEstimateFee,
|
|
7
|
+
tonTransactionResponse,
|
|
8
|
+
tonWallet,
|
|
9
|
+
} from "./common.fixtures";
|
|
10
|
+
|
|
11
|
+
// Define the mock base URL for the TON API
|
|
12
|
+
export const API_TON_ENDPOINT = "https://ton.coin.ledger.com/api/v3";
|
|
13
|
+
|
|
14
|
+
// Create request handlers for the mock server
|
|
15
|
+
const handlers = [
|
|
16
|
+
// Handle GET request for masterchainInfo endpoint
|
|
17
|
+
http.get(`${API_TON_ENDPOINT}/masterchainInfo`, () => {
|
|
18
|
+
return HttpResponse.json(lastBlockNumber);
|
|
19
|
+
}),
|
|
20
|
+
// Handle GET request for transactions endpoint
|
|
21
|
+
http.get(`${API_TON_ENDPOINT}/transactions`, () => {
|
|
22
|
+
return HttpResponse.json(tonTransactionResponse);
|
|
23
|
+
}),
|
|
24
|
+
// Handle GET request for account endpoint
|
|
25
|
+
http.get(`${API_TON_ENDPOINT}/account`, () => {
|
|
26
|
+
return HttpResponse.json(tonAccount);
|
|
27
|
+
}),
|
|
28
|
+
// Handle GET request for wallet endpoint
|
|
29
|
+
http.get(`${API_TON_ENDPOINT}/wallet`, () => {
|
|
30
|
+
return HttpResponse.json(tonWallet);
|
|
31
|
+
}),
|
|
32
|
+
// Handle POST request for estimate fee endpoint
|
|
33
|
+
http.post(`${API_TON_ENDPOINT}/estimateFee`, () => HttpResponse.json(tonEstimateFee)),
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
// Set up the mock server with the defined handlers
|
|
37
|
+
const mockServer = setupServer(...handlers);
|
|
38
|
+
|
|
39
|
+
export default mockServer;
|