@ledgerhq/coin-canton 0.9.0-nightly.1 → 0.9.0-nightly.20251030160608
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 +2 -1
- package/CHANGELOG.md +26 -9
- package/README.md +75 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +1 -1
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/bridge/deviceTransactionConfig.js +1 -1
- package/lib/bridge/deviceTransactionConfig.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts +2 -2
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +2 -3
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts +5 -3
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +27 -10
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/index.d.ts +2 -2
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +3 -3
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/onboard.d.ts.map +1 -1
- package/lib/bridge/onboard.js +48 -22
- package/lib/bridge/onboard.js.map +1 -1
- package/lib/bridge/prepareTransaction.js +1 -1
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/serialization.d.ts +4 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +36 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +11 -4
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/sync.d.ts.map +1 -1
- package/lib/bridge/sync.js +14 -6
- package/lib/bridge/sync.js.map +1 -1
- package/lib/bridge/transaction.js +1 -1
- package/lib/bridge/transaction.js.map +1 -1
- package/lib/common-logic/account/getBalance.d.ts +5 -1
- package/lib/common-logic/account/getBalance.d.ts.map +1 -1
- package/lib/common-logic/account/getBalance.js +2 -0
- package/lib/common-logic/account/getBalance.js.map +1 -1
- package/lib/common-logic/index.d.ts +1 -0
- package/lib/common-logic/index.d.ts.map +1 -1
- package/lib/common-logic/index.js +3 -1
- package/lib/common-logic/index.js.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.js +1 -1
- package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib/common-logic/transaction/estimateFees.js +1 -1
- package/lib/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib/common-logic/transaction/sign.d.ts +8 -0
- package/lib/common-logic/transaction/sign.d.ts.map +1 -0
- package/lib/common-logic/transaction/sign.js +45 -0
- package/lib/common-logic/transaction/sign.js.map +1 -0
- package/lib/common-logic/transaction/split.d.ts +9 -0
- package/lib/common-logic/transaction/split.d.ts.map +1 -0
- package/lib/common-logic/transaction/split.js +119 -0
- package/lib/common-logic/transaction/split.js.map +1 -0
- package/lib/common-logic/utils.js +2 -2
- package/lib/common-logic/utils.js.map +1 -1
- package/lib/network/gateway.d.ts +6 -1
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.js +6 -9
- package/lib/network/gateway.js.map +1 -1
- package/lib/test/cantonTestUtils.d.ts +4 -9
- package/lib/test/cantonTestUtils.d.ts.map +1 -1
- package/lib/test/cantonTestUtils.js +736 -27
- package/lib/test/cantonTestUtils.js.map +1 -1
- package/lib/test/fixtures.d.ts +5 -0
- package/lib/test/fixtures.d.ts.map +1 -0
- package/lib/test/fixtures.js +57 -0
- package/lib/test/fixtures.js.map +1 -0
- package/lib/types/bridge.d.ts +14 -2
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/errors.d.ts +6 -0
- package/lib/types/errors.d.ts.map +1 -1
- package/lib/types/errors.js +3 -1
- package/lib/types/errors.js.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/signer.d.ts +15 -2
- package/lib/types/signer.d.ts.map +1 -1
- package/lib/types/transaction-proto.json +1238 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +1 -1
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/bridge/deviceTransactionConfig.js +1 -1
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts +2 -2
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +2 -3
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts +5 -3
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +27 -10
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/index.d.ts +2 -2
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +3 -3
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/onboard.d.ts.map +1 -1
- package/lib-es/bridge/onboard.js +49 -23
- package/lib-es/bridge/onboard.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +1 -1
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/serialization.d.ts +4 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +32 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +11 -4
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/sync.d.ts.map +1 -1
- package/lib-es/bridge/sync.js +14 -6
- package/lib-es/bridge/sync.js.map +1 -1
- package/lib-es/bridge/transaction.js +1 -1
- package/lib-es/bridge/transaction.js.map +1 -1
- package/lib-es/common-logic/account/getBalance.d.ts +5 -1
- package/lib-es/common-logic/account/getBalance.d.ts.map +1 -1
- package/lib-es/common-logic/account/getBalance.js +2 -0
- package/lib-es/common-logic/account/getBalance.js.map +1 -1
- package/lib-es/common-logic/index.d.ts +1 -0
- package/lib-es/common-logic/index.d.ts.map +1 -1
- package/lib-es/common-logic/index.js +1 -0
- package/lib-es/common-logic/index.js.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.js +1 -1
- package/lib-es/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib-es/common-logic/transaction/sign.d.ts +8 -0
- package/lib-es/common-logic/transaction/sign.d.ts.map +1 -0
- package/lib-es/common-logic/transaction/sign.js +42 -0
- package/lib-es/common-logic/transaction/sign.js.map +1 -0
- package/lib-es/common-logic/transaction/split.d.ts +9 -0
- package/lib-es/common-logic/transaction/split.d.ts.map +1 -0
- package/lib-es/common-logic/transaction/split.js +83 -0
- package/lib-es/common-logic/transaction/split.js.map +1 -0
- package/lib-es/common-logic/utils.js +2 -2
- package/lib-es/common-logic/utils.js.map +1 -1
- package/lib-es/network/gateway.d.ts +6 -1
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.js +5 -10
- package/lib-es/network/gateway.js.map +1 -1
- package/lib-es/test/cantonTestUtils.d.ts +4 -9
- package/lib-es/test/cantonTestUtils.d.ts.map +1 -1
- package/lib-es/test/cantonTestUtils.js +697 -21
- package/lib-es/test/cantonTestUtils.js.map +1 -1
- package/lib-es/test/fixtures.d.ts +5 -0
- package/lib-es/test/fixtures.d.ts.map +1 -0
- package/lib-es/test/fixtures.js +49 -0
- package/lib-es/test/fixtures.js.map +1 -0
- package/lib-es/types/bridge.d.ts +14 -2
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/errors.d.ts +6 -0
- package/lib-es/types/errors.d.ts.map +1 -1
- package/lib-es/types/errors.js +2 -0
- package/lib-es/types/errors.js.map +1 -1
- package/lib-es/types/index.d.ts +1 -0
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js +1 -0
- package/lib-es/types/index.js.map +1 -1
- package/lib-es/types/signer.d.ts +15 -2
- package/lib-es/types/signer.d.ts.map +1 -1
- package/lib-es/types/transaction-proto.json +1238 -0
- package/package.json +13 -10
- package/scripts/generate.js +261 -0
- package/src/bridge/deviceTransactionConfig.test.ts +14 -10
- package/src/bridge/deviceTransactionConfig.ts +2 -2
- package/src/bridge/estimateMaxSpendable.ts +6 -8
- package/src/bridge/getTransactionStatus.test.ts +103 -165
- package/src/bridge/getTransactionStatus.ts +43 -11
- package/src/bridge/index.ts +6 -5
- package/src/bridge/onboard.integ.test.ts +8 -51
- package/src/bridge/onboard.ts +58 -33
- package/src/bridge/prepareTransaction.ts +1 -1
- package/src/bridge/serialization.ts +44 -0
- package/src/bridge/signOperation.test.ts +123 -0
- package/src/bridge/signOperation.ts +13 -6
- package/src/bridge/sync.integ.test.ts +157 -132
- package/src/bridge/sync.test.ts +5 -1
- package/src/bridge/sync.ts +18 -7
- package/src/bridge/transaction.ts +1 -1
- package/src/common-logic/account/getBalance.ts +12 -2
- package/src/common-logic/account/getBalance.unit.test.ts +7 -1
- package/src/common-logic/index.ts +1 -0
- package/src/common-logic/transaction/craftTransaction.ts +1 -1
- package/src/common-logic/transaction/estimateFees.test.ts +10 -0
- package/src/common-logic/transaction/estimateFees.ts +1 -1
- package/src/common-logic/transaction/sign.test.ts +389 -0
- package/src/common-logic/transaction/sign.ts +59 -0
- package/src/common-logic/transaction/split.test.ts +50 -0
- package/src/common-logic/transaction/split.ts +101 -0
- package/src/common-logic/utils.test.ts +22 -30
- package/src/common-logic/utils.ts +2 -2
- package/src/network/gateway.integ.test.ts +5 -6
- package/src/network/gateway.ts +13 -10
- package/src/test/cantonTestUtils.ts +789 -24
- package/src/test/fixtures.ts +53 -0
- package/src/test/prepare-transfer-serialized.json +26 -0
- package/src/test/prepare-transfer.json +3298 -0
- package/src/types/bridge.ts +15 -2
- package/src/types/errors.ts +3 -0
- package/src/types/index.ts +1 -0
- package/src/types/signer.ts +21 -3
- package/src/types/transaction-proto.json +1238 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-canton",
|
|
3
|
-
"version": "0.9.0-nightly.
|
|
3
|
+
"version": "0.9.0-nightly.20251030160608",
|
|
4
4
|
"description": "Canton coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -100,15 +100,16 @@
|
|
|
100
100
|
"dependencies": {
|
|
101
101
|
"bignumber.js": "^9.1.2",
|
|
102
102
|
"invariant": "^2.2.4",
|
|
103
|
+
"protobufjs": "7.5.4",
|
|
103
104
|
"rxjs": "^7.8.1",
|
|
104
|
-
"@ledgerhq/coin-framework": "^6.8.0-nightly.
|
|
105
|
-
"@ledgerhq/cryptoassets": "^13.
|
|
106
|
-
"@ledgerhq/devices": "8.
|
|
107
|
-
"@ledgerhq/errors": "^6.27.0-nightly.
|
|
108
|
-
"@ledgerhq/live-env": "^2.
|
|
109
|
-
"@ledgerhq/live-network": "^2.0.
|
|
105
|
+
"@ledgerhq/coin-framework": "^6.8.0-nightly.20251030160608",
|
|
106
|
+
"@ledgerhq/cryptoassets": "^13.32.0-nightly.20251030160608",
|
|
107
|
+
"@ledgerhq/devices": "8.7.0-nightly.20251030160608",
|
|
108
|
+
"@ledgerhq/errors": "^6.27.0-nightly.20251030160608",
|
|
109
|
+
"@ledgerhq/live-env": "^2.20.0-nightly.20251030160608",
|
|
110
|
+
"@ledgerhq/live-network": "^2.1.0-nightly.20251030160608",
|
|
110
111
|
"@ledgerhq/logs": "^6.13.0",
|
|
111
|
-
"@ledgerhq/types-live": "^6.88.0-nightly.
|
|
112
|
+
"@ledgerhq/types-live": "^6.88.0-nightly.20251030160608"
|
|
112
113
|
},
|
|
113
114
|
"devDependencies": {
|
|
114
115
|
"@types/invariant": "^2.2.37",
|
|
@@ -116,13 +117,15 @@
|
|
|
116
117
|
"dotenv": "^16.4.5",
|
|
117
118
|
"expect": "^27.4.6",
|
|
118
119
|
"jest": "^29.7.0",
|
|
120
|
+
"protobufjs-cli": "1.1.2",
|
|
119
121
|
"ts-jest": "^29.1.1",
|
|
120
122
|
"typescript": "^5.4.5",
|
|
121
|
-
"@ledgerhq/
|
|
122
|
-
"@ledgerhq/
|
|
123
|
+
"@ledgerhq/disable-network-setup": "^0.1.0-nightly.20251030160608",
|
|
124
|
+
"@ledgerhq/types-cryptoassets": "^7.30.0-nightly.20251030160608"
|
|
123
125
|
},
|
|
124
126
|
"scripts": {
|
|
125
127
|
"clean": "rimraf lib lib-es",
|
|
128
|
+
"generate-proto": "node scripts/generate.js",
|
|
126
129
|
"build": "tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es",
|
|
127
130
|
"coverage": "jest --coverage",
|
|
128
131
|
"prewatch": "pnpm build",
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint @typescript-eslint/no-var-requires: off */
|
|
3
|
+
/* eslint no-console: off */
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { execSync } from "node:child_process";
|
|
7
|
+
import https from "node:https";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
13
|
+
const outputFile = path.join(__dirname, "../src/types/transaction-proto.json");
|
|
14
|
+
const tempDir = path.join(__dirname, "temp-proto");
|
|
15
|
+
|
|
16
|
+
const APP_CANTON_REPO = "LedgerHQ/app-canton";
|
|
17
|
+
const APP_CANTON_BRANCH = "develop";
|
|
18
|
+
const APP_CANTON_BASE_URL = `https://raw.githubusercontent.com/${APP_CANTON_REPO}/${APP_CANTON_BRANCH}`;
|
|
19
|
+
|
|
20
|
+
const DAML_REPO = "digital-asset/daml";
|
|
21
|
+
const DAML_BRANCH = "main";
|
|
22
|
+
const DAML_BASE_URL = `https://raw.githubusercontent.com/${DAML_REPO}/${DAML_BRANCH}`;
|
|
23
|
+
|
|
24
|
+
const RESERVED_WORDS = [
|
|
25
|
+
{ pattern: /\bbool bool\b/g, replacement: "bool bool_" },
|
|
26
|
+
{ pattern: /\bEnum enum\b/g, replacement: "Enum enum_" },
|
|
27
|
+
{ pattern: /\bstring constructor = (\d+);/g, replacement: "string constructor_ = $1;" },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
function handleFileFinish(file, resolve) {
|
|
31
|
+
file.close();
|
|
32
|
+
resolve();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function handleFileError(filePath, reject) {
|
|
36
|
+
return err => {
|
|
37
|
+
fs.unlink(filePath, () => {
|
|
38
|
+
/* empty function */
|
|
39
|
+
});
|
|
40
|
+
reject(err);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function handleHttpResponse(url, file, filePath, resolve, reject) {
|
|
45
|
+
return response => {
|
|
46
|
+
if (response.statusCode !== 200) {
|
|
47
|
+
reject(new Error(`Failed to download ${url}: ${response.statusCode}`));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
response.pipe(file);
|
|
52
|
+
|
|
53
|
+
file.on("finish", () => handleFileFinish(file, resolve));
|
|
54
|
+
file.on("error", handleFileError(filePath, reject));
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function downloadFile(url, filePath) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const file = fs.createWriteStream(filePath);
|
|
61
|
+
|
|
62
|
+
https.get(url, handleHttpResponse(url, file, filePath, resolve, reject)).on("error", err => {
|
|
63
|
+
reject(err instanceof Error ? err : new Error(err));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const PROTO_FILES = [
|
|
69
|
+
{
|
|
70
|
+
repoPath: "proto/device.proto",
|
|
71
|
+
localPath: "device.proto",
|
|
72
|
+
source: "app-canton",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
repoPath: "proto/com/daml/ledger/api/v2/value.proto",
|
|
76
|
+
localPath: "com/daml/ledger/api/v2/value.proto",
|
|
77
|
+
source: "app-canton",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
repoPath: "proto/com/daml/ledger/api/v2/value_cb.proto",
|
|
81
|
+
localPath: "com/daml/ledger/api/v2/value_cb.proto",
|
|
82
|
+
source: "app-canton",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
repoPath:
|
|
86
|
+
"sdk/canton/community/ledger-api/src/main/protobuf/com/daml/ledger/api/v2/interactive/interactive_submission_common_data.proto",
|
|
87
|
+
localPath: "com/daml/ledger/api/v2/interactive/interactive_submission_common_data.proto",
|
|
88
|
+
source: "daml",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
repoPath:
|
|
92
|
+
"sdk/canton/community/ledger-api/src/main/protobuf/com/daml/ledger/api/v2/interactive/transaction/v1/interactive_submission_data.proto",
|
|
93
|
+
localPath:
|
|
94
|
+
"com/daml/ledger/api/v2/interactive/transaction/v1/interactive_submission_data.proto",
|
|
95
|
+
source: "daml",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
repoPath: "proto/interactive_submission_data_cb.proto",
|
|
99
|
+
localPath:
|
|
100
|
+
"com/daml/ledger/api/v2/interactive/transaction/v1/interactive_submission_data_cb.proto",
|
|
101
|
+
source: "app-canton",
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
repoPath: "proto/google/protobuf/any.proto",
|
|
105
|
+
localPath: "google/protobuf/any.proto",
|
|
106
|
+
source: "app-canton",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
repoPath: "proto/google/protobuf/duration.proto",
|
|
110
|
+
localPath: "google/protobuf/duration.proto",
|
|
111
|
+
source: "app-canton",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
repoPath: "proto/google/protobuf/empty.proto",
|
|
115
|
+
localPath: "google/protobuf/empty.proto",
|
|
116
|
+
source: "app-canton",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
repoPath: "proto/google/protobuf/timestamp.proto",
|
|
120
|
+
localPath: "google/protobuf/timestamp.proto",
|
|
121
|
+
source: "app-canton",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
repoPath: "proto/google/rpc/error_details.proto",
|
|
125
|
+
localPath: "google/rpc/error_details.proto",
|
|
126
|
+
source: "app-canton",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
repoPath: "proto/google/rpc/status.proto",
|
|
130
|
+
localPath: "google/rpc/status.proto",
|
|
131
|
+
source: "app-canton",
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
function ensureDirectoryExists(dirPath) {
|
|
136
|
+
if (!fs.existsSync(dirPath)) {
|
|
137
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function getDownloadUrl(protoFile) {
|
|
142
|
+
const baseUrl = protoFile.source === "daml" ? DAML_BASE_URL : APP_CANTON_BASE_URL;
|
|
143
|
+
return `${baseUrl}/${protoFile.repoPath}`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function downloadProtoFile(protoFile) {
|
|
147
|
+
const url = getDownloadUrl(protoFile);
|
|
148
|
+
const localPath = path.join(tempDir, protoFile.localPath);
|
|
149
|
+
|
|
150
|
+
ensureDirectoryExists(path.dirname(localPath));
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
await downloadFile(url, localPath);
|
|
154
|
+
console.log(`Downloaded: ${protoFile.localPath}`);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error(`Failed to download ${protoFile.localPath}:`, error.message);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function downloadProtoFiles() {
|
|
162
|
+
console.log("Downloading proto files from...");
|
|
163
|
+
|
|
164
|
+
if (!fs.existsSync(tempDir)) {
|
|
165
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
for (const protoFile of PROTO_FILES) {
|
|
169
|
+
await downloadProtoFile(protoFile);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
console.log("All proto files downloaded successfully!");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Replace reserved words to make sure only C allowed names are used
|
|
176
|
+
// see https://github.com/LedgerHQ/app-canton/blob/develop/proto/proto_gen.sh#L257
|
|
177
|
+
function replaceReservedWords(filePath) {
|
|
178
|
+
if (!fs.existsSync(filePath)) return;
|
|
179
|
+
|
|
180
|
+
let content = fs.readFileSync(filePath, "utf8");
|
|
181
|
+
|
|
182
|
+
for (const { pattern, replacement } of RESERVED_WORDS) {
|
|
183
|
+
content = content.replace(pattern, replacement);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
fs.writeFileSync(filePath, content);
|
|
187
|
+
console.log(`Updated field names in ${path.basename(filePath)}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Clean up temp directory
|
|
191
|
+
function cleanup() {
|
|
192
|
+
if (fs.existsSync(tempDir)) {
|
|
193
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
194
|
+
console.log("Cleaned up temporary files");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function processProtoFiles() {
|
|
199
|
+
// Replace field names in proto files
|
|
200
|
+
replaceReservedWords(path.join(tempDir, "com/daml/ledger/api/v2/value.proto"));
|
|
201
|
+
replaceReservedWords(path.join(tempDir, "com/daml/ledger/api/v2/value_cb.proto"));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function generateProtobufBindings() {
|
|
205
|
+
// Sanitize paths to prevent command injection
|
|
206
|
+
const sanitizedTempDir = path.resolve(tempDir);
|
|
207
|
+
const sanitizedOutputFile = path.resolve(outputFile);
|
|
208
|
+
const deviceProtoPath = path.join(sanitizedTempDir, "device.proto");
|
|
209
|
+
|
|
210
|
+
// Validate that paths exist and are within expected directories
|
|
211
|
+
if (!fs.existsSync(deviceProtoPath)) {
|
|
212
|
+
throw new Error(`Device proto file not found: ${deviceProtoPath}`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!sanitizedTempDir.startsWith(path.resolve(__dirname))) {
|
|
216
|
+
throw new Error("Invalid temp directory path");
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (!sanitizedOutputFile.startsWith(path.resolve(__dirname, ".."))) {
|
|
220
|
+
throw new Error("Invalid output file path");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Use npx from the same Node.js installation directory to avoid PATH manipulation
|
|
224
|
+
const npxPath = path.join(process.execPath, "..", "npx");
|
|
225
|
+
const absoluteNpxPath = path.resolve(npxPath);
|
|
226
|
+
|
|
227
|
+
execSync(
|
|
228
|
+
absoluteNpxPath,
|
|
229
|
+
[
|
|
230
|
+
"pbjs",
|
|
231
|
+
"-t",
|
|
232
|
+
"json",
|
|
233
|
+
"-w",
|
|
234
|
+
"es6",
|
|
235
|
+
"--path",
|
|
236
|
+
sanitizedTempDir,
|
|
237
|
+
"-o",
|
|
238
|
+
sanitizedOutputFile,
|
|
239
|
+
deviceProtoPath,
|
|
240
|
+
],
|
|
241
|
+
{
|
|
242
|
+
stdio: "inherit",
|
|
243
|
+
cwd: __dirname,
|
|
244
|
+
},
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
console.log("Generating protobuf bindings...");
|
|
250
|
+
|
|
251
|
+
await downloadProtoFiles();
|
|
252
|
+
processProtoFiles();
|
|
253
|
+
generateProtobufBindings();
|
|
254
|
+
|
|
255
|
+
console.log("Protobuf bindings generated successfully!");
|
|
256
|
+
} catch (error) {
|
|
257
|
+
console.error("Error generating protobuf bindings:", error.message);
|
|
258
|
+
process.exit(1);
|
|
259
|
+
} finally {
|
|
260
|
+
cleanup();
|
|
261
|
+
}
|
|
@@ -2,21 +2,25 @@ import getDeviceTransactionConfig from "./deviceTransactionConfig";
|
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
|
|
4
4
|
describe("getDeviceTransactionConfig", () => {
|
|
5
|
-
it("should return amount field when it's more than 0", () => {
|
|
5
|
+
it("should return amount field when it's more than 0", async () => {
|
|
6
6
|
expect(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
(
|
|
8
|
+
await getDeviceTransactionConfig({
|
|
9
|
+
transaction: {},
|
|
10
|
+
status: { amount: new BigNumber(1), estimatedFees: new BigNumber(0) },
|
|
11
|
+
} as any)
|
|
12
|
+
)[0],
|
|
11
13
|
).toEqual({ type: "amount", label: "Amount" });
|
|
12
14
|
});
|
|
13
15
|
|
|
14
|
-
it("should return fee field when it's more than 0", () => {
|
|
16
|
+
it("should return fee field when it's more than 0", async () => {
|
|
15
17
|
expect(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
(
|
|
19
|
+
await getDeviceTransactionConfig({
|
|
20
|
+
transaction: {},
|
|
21
|
+
status: { amount: new BigNumber(0), estimatedFees: new BigNumber(1) },
|
|
22
|
+
} as any)
|
|
23
|
+
)[0],
|
|
20
24
|
).toEqual({ type: "fees", label: "Fees" });
|
|
21
25
|
});
|
|
22
26
|
});
|
|
@@ -3,7 +3,7 @@ import type { Transaction, TransactionStatus } from "../types";
|
|
|
3
3
|
import type { CommonDeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
|
|
4
4
|
|
|
5
5
|
// This method adds additional fields that need to be reviewed when signing a transaction on the device.
|
|
6
|
-
function getDeviceTransactionConfig({
|
|
6
|
+
async function getDeviceTransactionConfig({
|
|
7
7
|
transaction: {},
|
|
8
8
|
status: { amount, estimatedFees },
|
|
9
9
|
}: {
|
|
@@ -11,7 +11,7 @@ function getDeviceTransactionConfig({
|
|
|
11
11
|
parentAccount: Account | null | undefined;
|
|
12
12
|
transaction: Transaction;
|
|
13
13
|
status: TransactionStatus;
|
|
14
|
-
}): Array<CommonDeviceTransactionField
|
|
14
|
+
}): Promise<Array<CommonDeviceTransactionField>> {
|
|
15
15
|
const fields: Array<CommonDeviceTransactionField> = [];
|
|
16
16
|
|
|
17
17
|
if (!amount.isZero()) {
|
|
@@ -5,19 +5,17 @@ import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets/abandonseed";
|
|
|
5
5
|
import { getTransactionStatus } from "./getTransactionStatus";
|
|
6
6
|
import { prepareTransaction } from "./prepareTransaction";
|
|
7
7
|
import { createTransaction } from "./createTransaction";
|
|
8
|
-
import { Transaction } from "../types";
|
|
8
|
+
import { Transaction, CantonAccount } from "../types";
|
|
9
9
|
|
|
10
|
-
export const estimateMaxSpendable: AccountBridge<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}) => {
|
|
10
|
+
export const estimateMaxSpendable: AccountBridge<
|
|
11
|
+
Transaction,
|
|
12
|
+
CantonAccount
|
|
13
|
+
>["estimateMaxSpendable"] = async ({ account, parentAccount, transaction }) => {
|
|
15
14
|
const mainAccount = getMainAccount(account, parentAccount);
|
|
16
15
|
const newTransaction = await prepareTransaction(mainAccount, {
|
|
17
16
|
...createTransaction(account),
|
|
18
17
|
...transaction,
|
|
19
|
-
|
|
20
|
-
recipient: transaction?.recipient || getAbandonSeedAddress("boilerplate"),
|
|
18
|
+
recipient: transaction?.recipient || getAbandonSeedAddress("canton_network"),
|
|
21
19
|
amount: new BigNumber(0),
|
|
22
20
|
});
|
|
23
21
|
const status = await getTransactionStatus(mainAccount, newTransaction);
|