@ledgerhq/coin-tezos 6.6.0-nightly.1 → 6.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +30 -4
- package/CHANGELOG.md +17 -8
- package/jest.integ.config.js +0 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +40 -188
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +10 -79
- package/lib/api/index.test.js.map +1 -1
- package/lib/api/types.d.ts +5 -7
- package/lib/api/types.d.ts.map +1 -1
- package/lib/bridge/broadcast.d.ts +4 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +11 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/broadcast.test.d.ts +2 -0
- package/lib/bridge/broadcast.test.d.ts.map +1 -0
- package/lib/bridge/broadcast.test.js +36 -0
- package/lib/bridge/broadcast.test.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 +28 -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 +24 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +30 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getFeesForTransaction.d.ts +21 -0
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib/bridge/getFeesForTransaction.js +39 -0
- package/lib/bridge/getFeesForTransaction.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 +108 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.test.js +107 -0
- package/lib/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib/bridge/index.d.ts +10 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +59 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/logic.d.ts +10 -0
- package/lib/bridge/logic.d.ts.map +1 -0
- package/lib/bridge/logic.js +155 -0
- package/lib/bridge/logic.js.map +1 -0
- package/lib/bridge/preload.d.ts +9 -0
- package/lib/bridge/preload.d.ts.map +1 -0
- package/lib/bridge/preload.js +23 -0
- package/lib/bridge/preload.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +5 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.integ.test.d.ts +2 -0
- package/lib/bridge/prepareTransaction.integ.test.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.integ.test.js +34 -0
- package/lib/bridge/prepareTransaction.integ.test.js.map +1 -0
- package/lib/bridge/prepareTransaction.js +57 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.test.js +178 -0
- package/lib/bridge/prepareTransaction.test.js.map +1 -0
- package/lib/bridge/serialization.d.ts +7 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +26 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +16 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +88 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/signOperation.test.d.ts +2 -0
- package/lib/bridge/signOperation.test.d.ts.map +1 -0
- package/lib/bridge/signOperation.test.js +283 -0
- package/lib/bridge/signOperation.test.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.integ.test.d.ts +2 -0
- package/lib/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib/bridge/synchronization.integ.test.js +32 -0
- package/lib/bridge/synchronization.integ.test.js.map +1 -0
- package/lib/bridge/synchronization.js +100 -0
- package/lib/bridge/synchronization.js.map +1 -0
- package/lib/{transaction.d.ts → bridge/transaction.d.ts} +1 -1
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/{transaction.js → bridge/transaction.js} +3 -3
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/config.d.ts +3 -4
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +0 -7
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +0 -1
- package/lib/logic/craftTransaction.test.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.integ.test.js +2 -8
- package/lib/logic/estimateFees.integ.test.js.map +1 -1
- package/lib/logic/estimateFees.js +45 -119
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.js +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/index.d.ts +0 -2
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +1 -5
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +10 -56
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +10 -14
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/types/bridge.d.ts +0 -3
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/bridge.fixture.d.ts.map +1 -1
- package/lib/types/bridge.fixture.js +0 -1
- package/lib/types/bridge.fixture.js.map +1 -1
- package/lib/types/bridge.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +41 -189
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +10 -79
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/api/types.d.ts +5 -7
- package/lib-es/api/types.d.ts.map +1 -1
- 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 +7 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/broadcast.test.d.ts +2 -0
- package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.test.js +31 -0
- package/lib-es/bridge/broadcast.test.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 +21 -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 +17 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +23 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts +21 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.js +33 -0
- package/lib-es/bridge/getFeesForTransaction.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 +101 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.js +102 -0
- package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib-es/bridge/index.d.ts +10 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +53 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/logic.d.ts +10 -0
- package/lib-es/bridge/logic.d.ts.map +1 -0
- package/lib-es/bridge/logic.js +145 -0
- package/lib-es/bridge/logic.js.map +1 -0
- package/lib-es/bridge/preload.d.ts +9 -0
- package/lib-es/bridge/preload.d.ts.map +1 -0
- package/lib-es/bridge/preload.js +17 -0
- package/lib-es/bridge/preload.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +5 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts +2 -0
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.integ.test.js +29 -0
- package/lib-es/bridge/prepareTransaction.integ.test.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +50 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.test.js +173 -0
- package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
- package/lib-es/bridge/serialization.d.ts +7 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +20 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +16 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +83 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/signOperation.test.d.ts +2 -0
- package/lib-es/bridge/signOperation.test.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.test.js +255 -0
- package/lib-es/bridge/signOperation.test.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.integ.test.d.ts +2 -0
- package/lib-es/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.integ.test.js +27 -0
- package/lib-es/bridge/synchronization.integ.test.js.map +1 -0
- package/lib-es/bridge/synchronization.js +70 -0
- package/lib-es/bridge/synchronization.js.map +1 -0
- package/lib-es/{transaction.d.ts → bridge/transaction.d.ts} +1 -1
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/{transaction.js → bridge/transaction.js} +3 -3
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/config.d.ts +3 -4
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/index.d.ts +1 -1
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +1 -1
- package/lib-es/index.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +0 -7
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +0 -1
- package/lib-es/logic/craftTransaction.test.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.integ.test.js +2 -8
- package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
- package/lib-es/logic/estimateFees.js +45 -119
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.js +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/index.d.ts +0 -2
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +0 -2
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +10 -56
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +10 -14
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/types/bridge.d.ts +0 -3
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/bridge.fixture.d.ts.map +1 -1
- package/lib-es/types/bridge.fixture.js +0 -1
- package/lib-es/types/bridge.fixture.js.map +1 -1
- package/lib-es/types/bridge.js.map +1 -1
- package/package.json +14 -11
- package/src/api/index.test.ts +15 -87
- package/src/api/index.ts +55 -204
- package/src/api/types.ts +6 -11
- package/src/bridge/broadcast.test.ts +36 -0
- package/src/bridge/broadcast.ts +13 -0
- package/src/bridge/buildOptimisticOperation.ts +28 -0
- package/src/bridge/createTransaction.ts +19 -0
- package/src/bridge/estimateMaxSpendable.ts +37 -0
- package/src/bridge/getFeesForTransaction.ts +49 -0
- package/src/bridge/getTransactionStatus.test.ts +124 -0
- package/src/bridge/getTransactionStatus.ts +123 -0
- package/src/bridge/index.ts +74 -0
- package/src/bridge/logic.ts +171 -0
- package/src/bridge/preload.ts +18 -0
- package/src/bridge/prepareTransaction.integ.test.ts +35 -0
- package/src/bridge/prepareTransaction.test.ts +205 -0
- package/src/bridge/prepareTransaction.ts +69 -0
- package/src/bridge/serialization.ts +27 -0
- package/src/bridge/signOperation.test.ts +284 -0
- package/src/bridge/signOperation.ts +130 -0
- package/src/bridge/synchronization.integ.test.ts +33 -0
- package/src/bridge/synchronization.ts +100 -0
- package/src/{transaction.ts → bridge/transaction.ts} +4 -4
- package/src/config.ts +2 -9
- package/src/index.ts +2 -1
- package/src/logic/craftTransaction.test.ts +0 -1
- package/src/logic/craftTransaction.ts +0 -8
- package/src/logic/estimateFees.integ.test.ts +2 -8
- package/src/logic/estimateFees.ts +49 -140
- package/src/logic/getBalance.ts +1 -1
- package/src/logic/index.ts +0 -2
- package/src/logic/listOperations.test.ts +54 -64
- package/src/logic/listOperations.ts +9 -57
- package/src/types/bridge.fixture.ts +0 -1
- package/src/types/bridge.ts +1 -6
- package/lib/logic/getStakes.d.ts +0 -3
- package/lib/logic/getStakes.d.ts.map +0 -1
- package/lib/logic/getStakes.js +0 -26
- package/lib/logic/getStakes.js.map +0 -1
- package/lib/logic/getStakes.test.d.ts +0 -2
- package/lib/logic/getStakes.test.d.ts.map +0 -1
- package/lib/logic/getStakes.test.js +0 -133
- package/lib/logic/getStakes.test.js.map +0 -1
- package/lib/logic/validateIntent.d.ts +0 -3
- package/lib/logic/validateIntent.d.ts.map +0 -1
- package/lib/logic/validateIntent.js +0 -179
- package/lib/logic/validateIntent.js.map +0 -1
- package/lib/logic/validateIntent.test.d.ts +0 -2
- package/lib/logic/validateIntent.test.d.ts.map +0 -1
- package/lib/logic/validateIntent.test.js +0 -249
- package/lib/logic/validateIntent.test.js.map +0 -1
- package/lib/transaction.d.ts.map +0 -1
- package/lib/transaction.js.map +0 -1
- package/lib/utils.d.ts +0 -48
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -112
- package/lib/utils.js.map +0 -1
- package/lib-es/logic/getStakes.d.ts +0 -3
- package/lib-es/logic/getStakes.d.ts.map +0 -1
- package/lib-es/logic/getStakes.js +0 -20
- package/lib-es/logic/getStakes.js.map +0 -1
- package/lib-es/logic/getStakes.test.d.ts +0 -2
- package/lib-es/logic/getStakes.test.d.ts.map +0 -1
- package/lib-es/logic/getStakes.test.js +0 -128
- package/lib-es/logic/getStakes.test.js.map +0 -1
- package/lib-es/logic/validateIntent.d.ts +0 -3
- package/lib-es/logic/validateIntent.d.ts.map +0 -1
- package/lib-es/logic/validateIntent.js +0 -173
- package/lib-es/logic/validateIntent.js.map +0 -1
- package/lib-es/logic/validateIntent.test.d.ts +0 -2
- package/lib-es/logic/validateIntent.test.d.ts.map +0 -1
- package/lib-es/logic/validateIntent.test.js +0 -221
- package/lib-es/logic/validateIntent.test.js.map +0 -1
- package/lib-es/transaction.d.ts.map +0 -1
- package/lib-es/transaction.js.map +0 -1
- package/lib-es/utils.d.ts +0 -48
- package/lib-es/utils.d.ts.map +0 -1
- package/lib-es/utils.js +0 -105
- package/lib-es/utils.js.map +0 -1
- package/src/logic/getStakes.test.ts +0 -145
- package/src/logic/getStakes.ts +0 -20
- package/src/logic/validateIntent.test.ts +0 -262
- package/src/logic/validateIntent.ts +0 -207
- package/src/utils.ts +0 -115
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-tezos",
|
|
3
|
-
"version": "6.6.0
|
|
3
|
+
"version": "6.6.0",
|
|
4
4
|
"description": "Tezos Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"default": "./lib-es/test/bot-specs.js"
|
|
57
57
|
},
|
|
58
58
|
"./transaction": {
|
|
59
|
-
"require": "./lib/transaction.js",
|
|
60
|
-
"default": "./lib-es/transaction.js"
|
|
59
|
+
"require": "./lib/bridge/transaction.js",
|
|
60
|
+
"default": "./lib-es/bridge/transaction.js"
|
|
61
61
|
},
|
|
62
62
|
"./*": {
|
|
63
63
|
"require": "./lib/*.js",
|
|
@@ -72,20 +72,24 @@
|
|
|
72
72
|
"@taquito/taquito": "^23.0.0-RC.0",
|
|
73
73
|
"@taquito/utils": "^23.0.0-RC.0",
|
|
74
74
|
"bignumber.js": "^9.1.2",
|
|
75
|
+
"@noble/hashes": "1.8.0",
|
|
76
|
+
"bs58check": "^3.0.1",
|
|
75
77
|
"invariant": "^2.2.4",
|
|
76
78
|
"lodash": "^4.17.21",
|
|
77
79
|
"rxjs": "^7.8.1",
|
|
78
|
-
"@ledgerhq/coin-framework": "^6.6.0
|
|
79
|
-
"@ledgerhq/cryptoassets": "^13.30.0
|
|
80
|
-
"@ledgerhq/devices": "8.6.
|
|
81
|
-
"@ledgerhq/errors": "^6.26.0
|
|
82
|
-
"@ledgerhq/live-network": "^2.0.
|
|
80
|
+
"@ledgerhq/coin-framework": "^6.6.0",
|
|
81
|
+
"@ledgerhq/cryptoassets": "^13.30.0",
|
|
82
|
+
"@ledgerhq/devices": "8.6.1",
|
|
83
|
+
"@ledgerhq/errors": "^6.26.0",
|
|
84
|
+
"@ledgerhq/live-network": "^2.0.19",
|
|
83
85
|
"@ledgerhq/logs": "^6.13.0",
|
|
84
|
-
"@ledgerhq/types-
|
|
86
|
+
"@ledgerhq/types-cryptoassets": "^7.28.0",
|
|
87
|
+
"@ledgerhq/types-live": "^6.86.0"
|
|
85
88
|
},
|
|
86
89
|
"devDependencies": {
|
|
87
90
|
"@faker-js/faker": "^8.4.1",
|
|
88
91
|
"@taquito/local-forging": "^23.0.0-RC.0",
|
|
92
|
+
"@types/bs58check": "^2.1.2",
|
|
89
93
|
"@types/invariant": "^2.2.37",
|
|
90
94
|
"@types/jest": "^29.5.12",
|
|
91
95
|
"@types/lodash": "^4.17.4",
|
|
@@ -93,8 +97,7 @@
|
|
|
93
97
|
"msw": "^2.7.3",
|
|
94
98
|
"ts-jest": "^29.1.4",
|
|
95
99
|
"typescript": "^5.4.5",
|
|
96
|
-
"@ledgerhq/disable-network-setup": "^0.0.0"
|
|
97
|
-
"@ledgerhq/types-cryptoassets": "^7.28.0-nightly.0"
|
|
100
|
+
"@ledgerhq/disable-network-setup": "^0.0.0"
|
|
98
101
|
},
|
|
99
102
|
"overrides": {
|
|
100
103
|
"@taquito/ledger-signer": {
|
package/src/api/index.test.ts
CHANGED
|
@@ -24,18 +24,11 @@ jest.mock("../logic", () => ({
|
|
|
24
24
|
rawEncode: () => Promise.resolve("tz1heMGVHQnx7ALDcDKqez8fan64Eyicw4DJ"),
|
|
25
25
|
}));
|
|
26
26
|
|
|
27
|
-
jest
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
publicKey: "edpktest",
|
|
33
|
-
counter: 0,
|
|
34
|
-
delegationLevel: 0,
|
|
35
|
-
delegationTime: "2021-01-01T00:00:00Z",
|
|
36
|
-
numTransactions: 0,
|
|
37
|
-
firstActivityTime: "2021-01-01T00:00:00Z",
|
|
38
|
-
} as APIAccount);
|
|
27
|
+
jest
|
|
28
|
+
.spyOn(networkApi, "getAccountByAddress")
|
|
29
|
+
.mockImplementation((_adress: string) =>
|
|
30
|
+
Promise.resolve({ type: "user", balance: 1000 } as APIAccount),
|
|
31
|
+
);
|
|
39
32
|
|
|
40
33
|
const api = createApi({
|
|
41
34
|
baker: {
|
|
@@ -101,27 +94,12 @@ describe("Testing craftTransaction function", () => {
|
|
|
101
94
|
beforeEach(() => jest.clearAllMocks());
|
|
102
95
|
|
|
103
96
|
it("should use estimated fees when user does not provide them for crafting a transaction ", async () => {
|
|
104
|
-
logicEstimateFees.mockResolvedValue({
|
|
105
|
-
|
|
106
|
-
gasLimit: DEFAULT_GAS_LIMIT,
|
|
107
|
-
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
108
|
-
});
|
|
109
|
-
await api.craftTransaction({
|
|
110
|
-
type: "send",
|
|
111
|
-
sender: "tz1test",
|
|
112
|
-
recipient: "tz1recipient",
|
|
113
|
-
amount: 1000n,
|
|
114
|
-
} as TezosTransactionIntent);
|
|
97
|
+
logicEstimateFees.mockResolvedValue({ estimatedFees: DEFAULT_ESTIMATED_FEES });
|
|
98
|
+
await api.craftTransaction({ type: "send", sender: {} } as TezosTransactionIntent);
|
|
115
99
|
expect(logicEstimateFees).toHaveBeenCalledTimes(1);
|
|
116
100
|
expect(logicCraftTransactionMock).toHaveBeenCalledWith(
|
|
117
|
-
expect.
|
|
118
|
-
expect.objectContaining({
|
|
119
|
-
fee: expect.objectContaining({
|
|
120
|
-
fees: DEFAULT_ESTIMATED_FEES.toString(),
|
|
121
|
-
gasLimit: DEFAULT_GAS_LIMIT.toString(),
|
|
122
|
-
storageLimit: DEFAULT_STORAGE_LIMIT.toString(),
|
|
123
|
-
}),
|
|
124
|
-
}),
|
|
101
|
+
expect.any(Object),
|
|
102
|
+
expect.objectContaining({ fee: { fees: DEFAULT_ESTIMATED_FEES.toString() } }),
|
|
125
103
|
);
|
|
126
104
|
});
|
|
127
105
|
|
|
@@ -132,22 +110,10 @@ describe("Testing craftTransaction function", () => {
|
|
|
132
110
|
estimatedFees: DEFAULT_ESTIMATED_FEES,
|
|
133
111
|
gasLimit: DEFAULT_GAS_LIMIT,
|
|
134
112
|
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
135
|
-
parameters: {
|
|
136
|
-
gasLimit: DEFAULT_GAS_LIMIT,
|
|
137
|
-
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
138
|
-
},
|
|
139
113
|
});
|
|
140
|
-
await api.craftTransaction(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
sender: "tz1test",
|
|
144
|
-
recipient: "tz1recipient",
|
|
145
|
-
amount: 1000n,
|
|
146
|
-
} as TezosTransactionIntent,
|
|
147
|
-
{
|
|
148
|
-
value: customFees,
|
|
149
|
-
},
|
|
150
|
-
);
|
|
114
|
+
await api.craftTransaction({ type: "send", sender: {} } as TezosTransactionIntent, {
|
|
115
|
+
value: customFees,
|
|
116
|
+
});
|
|
151
117
|
expect(logicEstimateFees).toHaveBeenCalledTimes(1);
|
|
152
118
|
expect(logicCraftTransactionMock).toHaveBeenCalledWith(
|
|
153
119
|
expect.any(Object),
|
|
@@ -172,12 +138,7 @@ describe("Testing estimateFees function", () => {
|
|
|
172
138
|
gasLimit: DEFAULT_GAS_LIMIT,
|
|
173
139
|
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
174
140
|
});
|
|
175
|
-
const result = await api.estimateFees({
|
|
176
|
-
type: "send",
|
|
177
|
-
sender: "tz1test",
|
|
178
|
-
recipient: "tz1recipient",
|
|
179
|
-
amount: 1000n,
|
|
180
|
-
} as TezosTransactionIntent);
|
|
141
|
+
const result = await api.estimateFees({ type: "send", sender: {} } as TezosTransactionIntent);
|
|
181
142
|
expect(result).toEqual({
|
|
182
143
|
value: DEFAULT_ESTIMATED_FEES,
|
|
183
144
|
parameters: {
|
|
@@ -188,42 +149,9 @@ describe("Testing estimateFees function", () => {
|
|
|
188
149
|
});
|
|
189
150
|
|
|
190
151
|
it("should throw taquito errors", async () => {
|
|
191
|
-
logicEstimateFees.mockResolvedValue({
|
|
192
|
-
estimatedFees: DEFAULT_ESTIMATED_FEES,
|
|
193
|
-
gasLimit: DEFAULT_GAS_LIMIT,
|
|
194
|
-
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
195
|
-
taquitoError: "test",
|
|
196
|
-
});
|
|
152
|
+
logicEstimateFees.mockResolvedValue({ taquitoError: "test" });
|
|
197
153
|
await expect(
|
|
198
|
-
api.estimateFees({
|
|
199
|
-
type: "send",
|
|
200
|
-
sender: "tz1test",
|
|
201
|
-
recipient: "tz1recipient",
|
|
202
|
-
amount: 1000n,
|
|
203
|
-
} as TezosTransactionIntent),
|
|
154
|
+
api.estimateFees({ type: "send", sender: {} } as TezosTransactionIntent),
|
|
204
155
|
).rejects.toThrow("Fees estimation failed: test");
|
|
205
156
|
});
|
|
206
|
-
|
|
207
|
-
it("should not throw for delegate.unchanged errors", async () => {
|
|
208
|
-
logicEstimateFees.mockResolvedValue({
|
|
209
|
-
estimatedFees: DEFAULT_ESTIMATED_FEES,
|
|
210
|
-
gasLimit: DEFAULT_GAS_LIMIT,
|
|
211
|
-
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
212
|
-
taquitoError: "proto.022-PsRiotum.delegate.unchanged",
|
|
213
|
-
});
|
|
214
|
-
const result = await api.estimateFees({
|
|
215
|
-
type: "delegate",
|
|
216
|
-
sender: "tz1test",
|
|
217
|
-
recipient: "tz1validator",
|
|
218
|
-
amount: 0n,
|
|
219
|
-
} as TezosTransactionIntent);
|
|
220
|
-
|
|
221
|
-
expect(result).toEqual({
|
|
222
|
-
value: DEFAULT_ESTIMATED_FEES,
|
|
223
|
-
parameters: {
|
|
224
|
-
gasLimit: DEFAULT_GAS_LIMIT,
|
|
225
|
-
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
226
|
-
},
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
157
|
});
|
package/src/api/index.ts
CHANGED
|
@@ -21,20 +21,11 @@ import {
|
|
|
21
21
|
lastBlock,
|
|
22
22
|
listOperations,
|
|
23
23
|
rawEncode,
|
|
24
|
-
validateIntent,
|
|
25
|
-
getStakes,
|
|
26
24
|
} from "../logic";
|
|
27
25
|
import api from "../network/tzkt";
|
|
28
26
|
import type { TezosApi, TezosFeeEstimation } from "./types";
|
|
29
|
-
import
|
|
30
|
-
import {
|
|
31
|
-
import { validatePublicKey, ValidationResult, getPkhfromPk } from "@taquito/utils";
|
|
32
|
-
import { getRevealFee } from "@taquito/taquito";
|
|
33
|
-
import {
|
|
34
|
-
DUST_MARGIN_MUTEZ,
|
|
35
|
-
mapIntentTypeToTezosMode,
|
|
36
|
-
normalizePublicKeyForAddress,
|
|
37
|
-
} from "../utils";
|
|
27
|
+
import { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
28
|
+
import { TezosOperationMode } from "../types";
|
|
38
29
|
|
|
39
30
|
export function createApi(config: TezosConfig): TezosApi {
|
|
40
31
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
@@ -47,54 +38,31 @@ export function createApi(config: TezosConfig): TezosApi {
|
|
|
47
38
|
getBalance: balance,
|
|
48
39
|
lastBlock,
|
|
49
40
|
listOperations: operations,
|
|
50
|
-
getStakes,
|
|
51
|
-
validateIntent,
|
|
52
|
-
// required by signer to compute next valid sequence/counter
|
|
53
|
-
getSequence: async (address: string) => {
|
|
54
|
-
const accountInfo = await api.getAccountByAddress(address);
|
|
55
|
-
return accountInfo.type === "user" ? accountInfo.counter + 1 : 0;
|
|
56
|
-
},
|
|
57
41
|
getBlock(_height): Promise<Block> {
|
|
58
42
|
throw new Error("getBlock is not supported");
|
|
59
43
|
},
|
|
60
44
|
getBlockInfo(_height: number): Promise<BlockInfo> {
|
|
61
45
|
throw new Error("getBlockInfo is not supported");
|
|
62
46
|
},
|
|
47
|
+
getStakes(_address: string, _cursor?: Cursor): Promise<Page<Stake>> {
|
|
48
|
+
throw new Error("getStakes is not supported");
|
|
49
|
+
},
|
|
63
50
|
getRewards(_address: string, _cursor?: Cursor): Promise<Page<Reward>> {
|
|
64
51
|
throw new Error("getRewards is not supported");
|
|
65
52
|
},
|
|
66
53
|
};
|
|
67
54
|
}
|
|
68
55
|
|
|
69
|
-
function isTezosTransactionType(
|
|
70
|
-
|
|
71
|
-
): type is "send" | "delegate" | "undelegate" | "stake" | "unstake" {
|
|
72
|
-
return ["send", "delegate", "undelegate", "stake", "unstake"].includes(type);
|
|
56
|
+
function isTezosTransactionType(type: string): type is "send" | "delegate" | "undelegate" {
|
|
57
|
+
return ["send", "delegate", "undelegate"].includes(type);
|
|
73
58
|
}
|
|
74
59
|
|
|
75
60
|
async function balance(address: string): Promise<Balance[]> {
|
|
76
61
|
const value = await getBalance(address);
|
|
77
|
-
const accountInfo = await api.getAccountByAddress(address);
|
|
78
|
-
// tzkt returns `type: "empty"` for untouched accounts; legacy logic returns -1 in that case
|
|
79
|
-
// the generic bridge expects non-negative balances
|
|
80
|
-
const normalized = value < 0n ? 0n : value;
|
|
81
|
-
// include stake information so ui can reflect delegation on account page
|
|
82
|
-
const stake: Stake | undefined =
|
|
83
|
-
accountInfo.type === "user" && accountInfo.delegate?.address
|
|
84
|
-
? {
|
|
85
|
-
uid: address,
|
|
86
|
-
address,
|
|
87
|
-
delegate: accountInfo.delegate.address,
|
|
88
|
-
state: "active",
|
|
89
|
-
asset: { type: "native" },
|
|
90
|
-
amount: BigInt(accountInfo.balance ?? 0),
|
|
91
|
-
}
|
|
92
|
-
: undefined;
|
|
93
62
|
return [
|
|
94
63
|
{
|
|
95
|
-
value
|
|
64
|
+
value,
|
|
96
65
|
asset: { type: "native" },
|
|
97
|
-
stake,
|
|
98
66
|
},
|
|
99
67
|
];
|
|
100
68
|
}
|
|
@@ -107,180 +75,64 @@ async function craft(
|
|
|
107
75
|
throw new IncorrectTypeError(transactionIntent.type);
|
|
108
76
|
}
|
|
109
77
|
|
|
110
|
-
//
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// Map generic staking intents to tezos modes
|
|
119
|
-
const mappedType = mapIntentTypeToTezosMode(transactionIntent.type);
|
|
120
|
-
|
|
121
|
-
// Guard: send max is incompatible with delegated accounts
|
|
122
|
-
let amountToUse = transactionIntent.amount;
|
|
123
|
-
if (mappedType === "send" && transactionIntent.useAllAmount) {
|
|
124
|
-
const senderInfo = await api.getAccountByAddress(transactionIntent.sender);
|
|
125
|
-
if (senderInfo.type === "user" && senderInfo.delegate?.address) {
|
|
126
|
-
throw new RecommendUndelegation();
|
|
127
|
-
}
|
|
128
|
-
if (senderInfo.type === "user") {
|
|
129
|
-
// Use the amount calculated by the estimation which includes proper buffers and adjustments
|
|
130
|
-
if (estimation.parameters?.amount !== undefined) {
|
|
131
|
-
amountToUse = estimation.parameters.amount;
|
|
132
|
-
} else {
|
|
133
|
-
// Fallback to the original calculation if estimation doesn't provide amount
|
|
134
|
-
const bal = BigInt(senderInfo.balance);
|
|
135
|
-
const feeBI = BigInt(fee.fees || "0");
|
|
136
|
-
const dustMargin = BigInt(DUST_MARGIN_MUTEZ);
|
|
137
|
-
const totalToDeduct = feeBI + dustMargin;
|
|
138
|
-
amountToUse = bal > totalToDeduct ? bal - totalToDeduct : 0n;
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
amountToUse = 0n;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
78
|
+
// note that an estimation is always necessary to get gasLimit and storageLimit, if even using custom fees
|
|
79
|
+
const fee = await estimate(transactionIntent).then(fees => ({
|
|
80
|
+
fees: (customFees?.value ?? fees.value).toString(),
|
|
81
|
+
gasLimit: fees.parameters?.gasLimit?.toString(),
|
|
82
|
+
storageLimit: fees.parameters?.storageLimit?.toString(),
|
|
83
|
+
}));
|
|
144
84
|
|
|
145
|
-
const
|
|
146
|
-
address: transactionIntent.sender,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
txFee = totalFee;
|
|
155
|
-
} else if (estimation.parameters?.txFee !== undefined) {
|
|
156
|
-
txFee = Number(estimation.parameters.txFee);
|
|
157
|
-
} else {
|
|
158
|
-
txFee = needsReveal ? Math.max(totalFee - getRevealFee(transactionIntent.sender), 0) : totalFee;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const txForCraft = {
|
|
162
|
-
type: mappedType,
|
|
163
|
-
recipient: transactionIntent.recipient,
|
|
164
|
-
amount: amountToUse,
|
|
165
|
-
fee: { ...fee, fees: txFee.toString() },
|
|
166
|
-
};
|
|
167
|
-
const publicKeyForCraft =
|
|
168
|
-
needsReveal && transactionIntent.senderPublicKey
|
|
169
|
-
? (() => {
|
|
170
|
-
// Accept either base58 or hex from device, and map curve using sender address
|
|
171
|
-
let pk = transactionIntent.senderPublicKey;
|
|
172
|
-
if (validatePublicKey(pk) !== ValidationResult.VALID) {
|
|
173
|
-
pk = normalizePublicKeyForAddress(pk, transactionIntent.sender) || pk;
|
|
174
|
-
}
|
|
175
|
-
// Verify the public key matches the sender address to avoid inconsistent_hash
|
|
176
|
-
let isPublicKeyValid = false;
|
|
177
|
-
try {
|
|
178
|
-
const derived = getPkhfromPk(pk);
|
|
179
|
-
isPublicKeyValid = derived === transactionIntent.sender;
|
|
180
|
-
} catch {
|
|
181
|
-
// getPkhfromPk failed = will fallback to basic validation below
|
|
182
|
-
isPublicKeyValid = false;
|
|
183
|
-
}
|
|
85
|
+
const { contents } = await craftTransaction(
|
|
86
|
+
{ address: transactionIntent.sender },
|
|
87
|
+
{
|
|
88
|
+
type: transactionIntent.type,
|
|
89
|
+
recipient: transactionIntent.recipient,
|
|
90
|
+
amount: transactionIntent.amount,
|
|
91
|
+
fee,
|
|
92
|
+
},
|
|
93
|
+
);
|
|
184
94
|
|
|
185
|
-
if (!isPublicKeyValid) {
|
|
186
|
-
// If derivation failed/doesn't match, check if the key is atleast valid format
|
|
187
|
-
if (validatePublicKey(pk) !== ValidationResult.VALID) {
|
|
188
|
-
throw new Error("Unable to normalize sender public key");
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return { publicKey: pk, publicKeyHash: transactionIntent.sender };
|
|
192
|
-
})()
|
|
193
|
-
: undefined;
|
|
194
|
-
const { contents } = await craftTransaction(accountForCraft, txForCraft, publicKeyForCraft);
|
|
195
95
|
const tx = await rawEncode(contents);
|
|
96
|
+
|
|
196
97
|
return { transaction: tx };
|
|
197
98
|
}
|
|
198
99
|
|
|
199
100
|
async function estimate(transactionIntent: TransactionIntent): Promise<TezosFeeEstimation> {
|
|
200
|
-
// avoid taquito error when estimating a 0-amount transfer during input
|
|
201
|
-
if (
|
|
202
|
-
transactionIntent.type === "send" &&
|
|
203
|
-
transactionIntent.amount === 0n &&
|
|
204
|
-
!transactionIntent.useAllAmount
|
|
205
|
-
) {
|
|
206
|
-
return {
|
|
207
|
-
value: BigInt(DUST_MARGIN_MUTEZ),
|
|
208
|
-
parameters: {
|
|
209
|
-
gasLimit: 10000n,
|
|
210
|
-
storageLimit: 300n,
|
|
211
|
-
amount: 0n,
|
|
212
|
-
txFee: BigInt(DUST_MARGIN_MUTEZ),
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
101
|
const senderAccountInfo = await api.getAccountByAddress(transactionIntent.sender);
|
|
217
|
-
// If the sender is not a user account, return default estimation values
|
|
218
|
-
if (senderAccountInfo.type !== "user") {
|
|
219
|
-
return {
|
|
220
|
-
value: BigInt(DUST_MARGIN_MUTEZ),
|
|
221
|
-
parameters: {
|
|
222
|
-
gasLimit: 10000n,
|
|
223
|
-
storageLimit: 300n,
|
|
224
|
-
amount: 0n,
|
|
225
|
-
txFee: BigInt(DUST_MARGIN_MUTEZ),
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
102
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
!estimation.taquitoError.includes("delegate.unchanged") &&
|
|
252
|
-
!estimation.taquitoError.includes("subtraction_underflow") &&
|
|
253
|
-
!estimation.taquitoError.includes("balance_too_low")
|
|
254
|
-
) {
|
|
255
|
-
throw new Error(`Fees estimation failed: ${estimation.taquitoError}`);
|
|
256
|
-
}
|
|
103
|
+
const {
|
|
104
|
+
estimatedFees: value,
|
|
105
|
+
gasLimit,
|
|
106
|
+
storageLimit,
|
|
107
|
+
taquitoError,
|
|
108
|
+
} = await estimateFees({
|
|
109
|
+
account: {
|
|
110
|
+
address: transactionIntent.sender,
|
|
111
|
+
revealed: senderAccountInfo.type === "user" && senderAccountInfo.revealed,
|
|
112
|
+
balance: BigInt(senderAccountInfo.type === "user" ? senderAccountInfo.balance : 0),
|
|
113
|
+
// NOTE: previously we checked for .sender.xpub
|
|
114
|
+
xpub:
|
|
115
|
+
transactionIntent.senderPublicKey ??
|
|
116
|
+
(senderAccountInfo.type === "user" ? senderAccountInfo.publicKey : undefined),
|
|
117
|
+
},
|
|
118
|
+
transaction: {
|
|
119
|
+
mode: transactionIntent.type as TezosOperationMode,
|
|
120
|
+
recipient: transactionIntent.recipient,
|
|
121
|
+
amount: transactionIntent.amount,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
257
124
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
parameters: {
|
|
261
|
-
gasLimit: estimation.gasLimit,
|
|
262
|
-
storageLimit: estimation.storageLimit,
|
|
263
|
-
amount: estimation.amount,
|
|
264
|
-
txFee: estimation.fees,
|
|
265
|
-
},
|
|
266
|
-
};
|
|
267
|
-
} catch (error: any) {
|
|
268
|
-
// Handle PublicKeyNotFoundError
|
|
269
|
-
if (error?.message?.includes("Public key not found")) {
|
|
270
|
-
return {
|
|
271
|
-
value: 1000n, // Safe default with reveal fees (500 + 374 reveal + buffer)
|
|
272
|
-
parameters: {
|
|
273
|
-
gasLimit: 10000n,
|
|
274
|
-
storageLimit: 300n,
|
|
275
|
-
amount: 0n,
|
|
276
|
-
txFee: 1000n,
|
|
277
|
-
},
|
|
278
|
-
};
|
|
279
|
-
} else {
|
|
280
|
-
// Re-throw other errors
|
|
281
|
-
throw error;
|
|
282
|
-
}
|
|
125
|
+
if (taquitoError !== undefined) {
|
|
126
|
+
throw new Error(`Fees estimation failed: ${taquitoError}`);
|
|
283
127
|
}
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
value,
|
|
131
|
+
parameters: {
|
|
132
|
+
gasLimit,
|
|
133
|
+
storageLimit,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
284
136
|
}
|
|
285
137
|
|
|
286
138
|
async function operations(
|
|
@@ -293,6 +145,5 @@ async function operations(
|
|
|
293
145
|
sort: pagination.order === "asc" ? "Ascending" : "Descending",
|
|
294
146
|
minHeight: pagination.minHeight,
|
|
295
147
|
});
|
|
296
|
-
|
|
297
148
|
return [operations, newNextCursor || ""];
|
|
298
149
|
}
|
package/src/api/types.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AlpacaApi, FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
2
2
|
|
|
3
|
-
export type TezosFeeParameters = {
|
|
4
|
-
|
|
5
|
-
storageLimit: bigint;
|
|
6
|
-
amount?: bigint;
|
|
7
|
-
txFee?: bigint;
|
|
8
|
-
};
|
|
9
|
-
export type TezosFeeEstimation = FeeEstimation & {
|
|
10
|
-
parameters?: TezosFeeParameters & Record<string, unknown>;
|
|
11
|
-
};
|
|
3
|
+
export type TezosFeeParameters = { gasLimit: bigint; storageLimit: bigint };
|
|
4
|
+
export type TezosFeeEstimation = FeeEstimation;
|
|
12
5
|
|
|
13
6
|
export type TezosSender = { address: string; xpub?: string };
|
|
14
7
|
export type TezosTransactionIntent = TransactionIntent;
|
|
15
8
|
|
|
16
|
-
export type TezosApi =
|
|
9
|
+
export type TezosApi = AlpacaApi & {
|
|
10
|
+
estimateFees: (transactionIntent: TezosTransactionIntent) => Promise<TezosFeeEstimation>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SignedOperation } from "@ledgerhq/types-live";
|
|
2
|
+
import { createFixtureOperation } from "../types/bridge.fixture";
|
|
3
|
+
import config, { type TezosCoinConfig } from "../config";
|
|
4
|
+
import { broadcast } from "./broadcast";
|
|
5
|
+
import { mockConfig } from "../test/config";
|
|
6
|
+
|
|
7
|
+
const mockInjectOperation = jest.fn();
|
|
8
|
+
jest.mock("@taquito/taquito", () => ({
|
|
9
|
+
TezosToolkit: jest.fn().mockReturnValue({
|
|
10
|
+
rpc: {
|
|
11
|
+
injectOperation: () => mockInjectOperation(),
|
|
12
|
+
},
|
|
13
|
+
}),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
describe("broadcast", () => {
|
|
17
|
+
beforeAll(() => {
|
|
18
|
+
config.setCoinConfig((): TezosCoinConfig => mockConfig as TezosCoinConfig);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("calls 'injectOperation' from TezosToolkit and returns its hash computation", async () => {
|
|
22
|
+
// GIVEN
|
|
23
|
+
const signedOperation: SignedOperation = {
|
|
24
|
+
operation: createFixtureOperation(),
|
|
25
|
+
signature: "SIGNATURE",
|
|
26
|
+
};
|
|
27
|
+
mockInjectOperation.mockResolvedValue("SIGN_HASH");
|
|
28
|
+
|
|
29
|
+
// WHEN
|
|
30
|
+
const op = await broadcast({ signedOperation, account: {} as any });
|
|
31
|
+
|
|
32
|
+
// THEN
|
|
33
|
+
expect(mockInjectOperation).toHaveBeenCalledTimes(1);
|
|
34
|
+
expect(op.hash).toEqual("SIGN_HASH");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
2
|
+
import { AccountBridge, SignedOperation } from "@ledgerhq/types-live";
|
|
3
|
+
import { Transaction } from "../types";
|
|
4
|
+
import { broadcast as logicBroadcast } from "../logic";
|
|
5
|
+
|
|
6
|
+
export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
|
|
7
|
+
signedOperation: { operation, signature },
|
|
8
|
+
}: {
|
|
9
|
+
signedOperation: SignedOperation;
|
|
10
|
+
}) => {
|
|
11
|
+
const hash = await logicBroadcast(signature);
|
|
12
|
+
return patchOperationWithHash(operation, hash);
|
|
13
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { OperationType } from "@ledgerhq/types-live";
|
|
2
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
3
|
+
import { TezosAccount, TezosOperation, Transaction } from "../types";
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
|
|
6
|
+
export const buildOptimisticOperation = (
|
|
7
|
+
account: TezosAccount,
|
|
8
|
+
transaction: Transaction,
|
|
9
|
+
operationType: OperationType,
|
|
10
|
+
): TezosOperation => {
|
|
11
|
+
const txHash = ""; // resolved at broadcast time
|
|
12
|
+
const { id: accountId } = account;
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
id: encodeOperationId(accountId, txHash, operationType),
|
|
16
|
+
hash: txHash,
|
|
17
|
+
type: operationType,
|
|
18
|
+
value: transaction.amount,
|
|
19
|
+
fee: transaction.fees || new BigNumber(0),
|
|
20
|
+
extra: {},
|
|
21
|
+
blockHash: null,
|
|
22
|
+
blockHeight: null,
|
|
23
|
+
senders: [account.freshAddress],
|
|
24
|
+
recipients: [transaction.recipient],
|
|
25
|
+
accountId,
|
|
26
|
+
date: new Date(),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
+
import { Transaction } from "../types";
|
|
4
|
+
|
|
5
|
+
export const createTransaction: AccountBridge<Transaction>["createTransaction"] = () => {
|
|
6
|
+
return {
|
|
7
|
+
family: "tezos",
|
|
8
|
+
mode: "send",
|
|
9
|
+
amount: new BigNumber(0),
|
|
10
|
+
fees: null,
|
|
11
|
+
gasLimit: null,
|
|
12
|
+
storageLimit: null,
|
|
13
|
+
recipient: "",
|
|
14
|
+
networkInfo: null,
|
|
15
|
+
useAllAmount: false,
|
|
16
|
+
taquitoError: null,
|
|
17
|
+
estimatedFees: null,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Account, AccountBridge, AccountLike } from "@ledgerhq/types-live";
|
|
3
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
4
|
+
import { TezosAccount, Transaction } from "../types";
|
|
5
|
+
import { prepareTransaction } from "./prepareTransaction";
|
|
6
|
+
import { createTransaction } from "./createTransaction";
|
|
7
|
+
import getEstimatedFees from "./getFeesForTransaction";
|
|
8
|
+
|
|
9
|
+
const TEZOS_BURN_ADDRESS = "tz1burnburnburnburnburnburnburjAYjjX";
|
|
10
|
+
|
|
11
|
+
export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"] = async ({
|
|
12
|
+
account,
|
|
13
|
+
parentAccount,
|
|
14
|
+
transaction,
|
|
15
|
+
}: {
|
|
16
|
+
account: AccountLike;
|
|
17
|
+
parentAccount: Account | undefined;
|
|
18
|
+
transaction: Transaction;
|
|
19
|
+
}): Promise<BigNumber> => {
|
|
20
|
+
const mainAccount = getMainAccount(account, parentAccount) as TezosAccount;
|
|
21
|
+
const tx = await prepareTransaction(mainAccount, {
|
|
22
|
+
...createTransaction(account),
|
|
23
|
+
...transaction,
|
|
24
|
+
// estimate using a burn address that exists so we don't enter into NotEnoughBalanceBecauseDestinationNotCreated
|
|
25
|
+
recipient: transaction?.recipient || TEZOS_BURN_ADDRESS,
|
|
26
|
+
useAllAmount: true,
|
|
27
|
+
});
|
|
28
|
+
const estimation = await getEstimatedFees({
|
|
29
|
+
account: mainAccount,
|
|
30
|
+
transaction: tx,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// As we use `useAllAmount`, we know we will receive an amount value.
|
|
34
|
+
return estimation.amount!;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default estimateMaxSpendable;
|