@onekeyfe/hd-transport 1.1.28 → 1.2.0-alpha.1
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/README.md +2 -4
- package/__tests__/build-receive.test.js +6 -8
- package/__tests__/decode-features.test.js +3 -2
- package/__tests__/messages.test.js +8 -0
- package/__tests__/protocol-v2.test.js +754 -0
- package/dist/constants.d.ts +14 -5
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +905 -41
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +811 -84
- package/dist/protocols/index.d.ts +45 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/v1/decode.d.ts +11 -0
- package/dist/protocols/v1/decode.d.ts.map +1 -0
- package/dist/protocols/v1/encode.d.ts +11 -0
- package/dist/protocols/v1/encode.d.ts.map +1 -0
- package/dist/protocols/v1/index.d.ts +5 -0
- package/dist/protocols/v1/index.d.ts.map +1 -0
- package/dist/protocols/v1/packets.d.ts +7 -0
- package/dist/protocols/v1/packets.d.ts.map +1 -0
- package/dist/{serialization → protocols/v1}/receive.d.ts +1 -1
- package/dist/protocols/v1/receive.d.ts.map +1 -0
- package/dist/protocols/v2/constants.d.ts +7 -0
- package/dist/protocols/v2/constants.d.ts.map +1 -0
- package/dist/protocols/v2/crc8.d.ts +3 -0
- package/dist/protocols/v2/crc8.d.ts.map +1 -0
- package/dist/protocols/v2/debug.d.ts +13 -0
- package/dist/protocols/v2/debug.d.ts.map +1 -0
- package/dist/protocols/v2/decode.d.ts +8 -0
- package/dist/protocols/v2/decode.d.ts.map +1 -0
- package/dist/protocols/v2/encode.d.ts +5 -0
- package/dist/protocols/v2/encode.d.ts.map +1 -0
- package/dist/protocols/v2/frame-assembler.d.ts +12 -0
- package/dist/protocols/v2/frame-assembler.d.ts.map +1 -0
- package/dist/protocols/v2/index.d.ts +7 -0
- package/dist/protocols/v2/index.d.ts.map +1 -0
- package/dist/protocols/v2/session.d.ts +50 -0
- package/dist/protocols/v2/session.d.ts.map +1 -0
- package/dist/serialization/index.d.ts +6 -3
- package/dist/serialization/index.d.ts.map +1 -1
- package/dist/serialization/protobuf/decode.d.ts.map +1 -1
- package/dist/serialization/protobuf/messages.d.ts +1 -1
- package/dist/serialization/protobuf/messages.d.ts.map +1 -1
- package/dist/types/messages.d.ts +441 -11
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/transport.d.ts +14 -2
- package/dist/types/transport.d.ts.map +1 -1
- package/dist/utils/logBlockCommand.d.ts.map +1 -1
- package/messages-protocol-v2.json +13375 -0
- package/package.json +3 -3
- package/scripts/protobuf-build.sh +314 -20
- package/scripts/protobuf-patches/TxInputType.js +1 -0
- package/scripts/protobuf-patches/index.js +2 -0
- package/scripts/protobuf-types.js +224 -18
- package/src/constants.ts +42 -6
- package/src/index.ts +39 -11
- package/src/protocols/index.ts +144 -0
- package/src/{serialization/protocol → protocols/v1}/decode.ts +4 -4
- package/src/{serialization/protocol → protocols/v1}/encode.ts +18 -13
- package/src/protocols/v1/index.ts +4 -0
- package/src/protocols/v1/packets.ts +53 -0
- package/src/{serialization → protocols/v1}/receive.ts +5 -5
- package/src/protocols/v2/constants.ts +6 -0
- package/src/protocols/v2/crc8.ts +34 -0
- package/src/protocols/v2/debug.ts +26 -0
- package/src/protocols/v2/decode.ts +92 -0
- package/src/protocols/v2/encode.ts +116 -0
- package/src/protocols/v2/frame-assembler.ts +98 -0
- package/src/protocols/v2/index.ts +6 -0
- package/src/protocols/v2/session.ts +429 -0
- package/src/serialization/index.ts +6 -5
- package/src/serialization/protobuf/decode.ts +7 -0
- package/src/serialization/protobuf/messages.ts +8 -4
- package/src/types/messages.ts +579 -13
- package/src/types/transport.ts +26 -2
- package/src/utils/logBlockCommand.ts +9 -1
- package/dist/serialization/protocol/decode.d.ts +0 -11
- package/dist/serialization/protocol/decode.d.ts.map +0 -1
- package/dist/serialization/protocol/encode.d.ts +0 -11
- package/dist/serialization/protocol/encode.d.ts.map +0 -1
- package/dist/serialization/protocol/index.d.ts +0 -3
- package/dist/serialization/protocol/index.d.ts.map +0 -1
- package/dist/serialization/receive.d.ts.map +0 -1
- package/dist/serialization/send.d.ts +0 -7
- package/dist/serialization/send.d.ts.map +0 -1
- package/src/serialization/protocol/index.ts +0 -2
- package/src/serialization/send.ts +0 -58
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.0-alpha.1",
|
|
4
4
|
"description": "Transport layer abstractions and utilities for OneKey hardware SDK.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"test": "jest",
|
|
17
17
|
"lint": "eslint .",
|
|
18
18
|
"lint:fix": "eslint . --fix",
|
|
19
|
-
"update
|
|
19
|
+
"update-protobuf": "./scripts/protobuf-build.sh"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/bytebuffer": "^5.0.42",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"long": "^4.0.0",
|
|
29
29
|
"protobufjs": "^6.11.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "4f4aae3a47be7bd54b4db4a10c400056784e01bd"
|
|
32
32
|
}
|
|
@@ -5,10 +5,14 @@ set -euxo pipefail
|
|
|
5
5
|
echo $#
|
|
6
6
|
|
|
7
7
|
PARENT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
|
8
|
+
PACKAGE_ROOT="$PARENT_PATH/.."
|
|
8
9
|
|
|
9
10
|
SRC="../../submodules/firmware/common/protob"
|
|
10
11
|
DIST="."
|
|
11
12
|
LANG="typescript"
|
|
13
|
+
# Absolute paths — resolved relative to this script's directory
|
|
14
|
+
REPO_ROOT="$PARENT_PATH/../../.."
|
|
15
|
+
CORE_MESSAGES_DIR="$REPO_ROOT/packages/core/src/data/messages"
|
|
12
16
|
|
|
13
17
|
if [[ $# -ne 0 && $# -ne 3 ]]
|
|
14
18
|
then
|
|
@@ -29,30 +33,320 @@ if [[ "$LANG" != "typescript" && "$LANG" != "flow" ]];
|
|
|
29
33
|
exit 1
|
|
30
34
|
fi
|
|
31
35
|
|
|
36
|
+
if [[ "$SRC" = /* ]]; then
|
|
37
|
+
SRC_PATH="$SRC"
|
|
38
|
+
else
|
|
39
|
+
SRC_PATH="$PACKAGE_ROOT/$SRC"
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
if [[ "$DIST" = /* ]]; then
|
|
43
|
+
DIST_PATH="$DIST"
|
|
44
|
+
else
|
|
45
|
+
DIST_PATH="$PACKAGE_ROOT/$DIST"
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# Remove temp proto files on any exit, including failure paths
|
|
49
|
+
trap 'rm -f "$DIST_PATH/messages-tmp.proto" "$PARENT_PATH/messages-protocol-v2-tmp.proto"' EXIT
|
|
32
50
|
|
|
33
|
-
# BUILD combined messages.proto file from protobuf files
|
|
34
|
-
# this code was copied from ./submodules/firmware/protob Makekile
|
|
35
|
-
# clear protobuf syntax and remove unknown values to be able to work with proto2js
|
|
36
|
-
echo 'syntax = "proto2";' > $DIST/messages.proto
|
|
37
|
-
echo 'import "google/protobuf/descriptor.proto";' >> $DIST/messages.proto
|
|
38
|
-
echo "Build proto file from $SRC"
|
|
39
|
-
grep -hv -e '^import ' -e '^syntax' -e '^package' -e 'option java_' $SRC/messages*.proto \
|
|
40
|
-
| sed 's/ hw\.trezor\.messages\.common\./ /' \
|
|
41
|
-
| sed 's/ common\./ /' \
|
|
42
|
-
| sed 's/ ethereum_definitions\./ /' \
|
|
43
|
-
| sed 's/ management\./ /' \
|
|
44
|
-
| sed 's/^option /\/\/ option /' \
|
|
45
|
-
| grep -v ' reserved '>> $DIST/messages.proto
|
|
46
51
|
|
|
47
|
-
#
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
# ============================================================
|
|
53
|
+
# BUILD Pro1 messages.json (requires firmware submodule)
|
|
54
|
+
# ============================================================
|
|
55
|
+
# Combines all messages*.proto files from firmware submodule into
|
|
56
|
+
# messages.json, then copies to core package.
|
|
57
|
+
if [ -d "$SRC_PATH" ] && ls "$SRC_PATH"/messages*.proto 1>/dev/null 2>&1; then
|
|
58
|
+
echo "=== Building Pro1 (legacy) protobuf messages ==="
|
|
59
|
+
TMP_PROTO="$DIST_PATH/messages-tmp.proto"
|
|
60
|
+
echo 'syntax = "proto2";' > "$TMP_PROTO"
|
|
61
|
+
echo 'import "google/protobuf/descriptor.proto";' >> "$TMP_PROTO"
|
|
62
|
+
echo "Build proto file from $SRC_PATH"
|
|
63
|
+
grep -hv -e '^import ' -e '^syntax' -e '^package' -e 'option java_' "$SRC_PATH"/messages*.proto \
|
|
64
|
+
| sed 's/ hw\.trezor\.messages\.common\./ /' \
|
|
65
|
+
| sed 's/ common\./ /' \
|
|
66
|
+
| sed 's/ ethereum_definitions\./ /' \
|
|
67
|
+
| sed 's/ management\./ /' \
|
|
68
|
+
| sed 's/^option /\/\/ option /' \
|
|
69
|
+
| grep -v ' reserved '>> "$TMP_PROTO"
|
|
70
|
+
|
|
71
|
+
npx pbjs -t json -p "$DIST_PATH" -o "$DIST_PATH/messages.json" --keep-case "$TMP_PROTO"
|
|
72
|
+
rm "$TMP_PROTO"
|
|
73
|
+
|
|
74
|
+
# Copy to core package
|
|
75
|
+
cp "$DIST_PATH/messages.json" "$CORE_MESSAGES_DIR/messages.json"
|
|
76
|
+
echo "Pro1 messages.json copied to core"
|
|
77
|
+
|
|
78
|
+
yarn --cwd "$PACKAGE_ROOT" prettier --write "$DIST_PATH/messages.json"
|
|
79
|
+
yarn --cwd "$PACKAGE_ROOT" prettier --write "$CORE_MESSAGES_DIR/messages.json"
|
|
80
|
+
# Type generation (protobuf-types.js) runs once at the end of the Protocol V2
|
|
81
|
+
# section below, after both schemas are available.
|
|
82
|
+
else
|
|
83
|
+
# Intentional asymmetry with the Protocol V2 section below: the legacy firmware
|
|
84
|
+
# submodule is optional (the committed messages.json stays in use when it is
|
|
85
|
+
# absent), while firmware-pro2 is the only source of the Protocol V2 schema,
|
|
86
|
+
# so its absence is a hard error (exit 1).
|
|
87
|
+
echo "⚠️ firmware submodule not found at $SRC_PATH"
|
|
88
|
+
echo " Skipping Pro1 protobuf build. To enable:"
|
|
89
|
+
echo " git submodule update --init submodules/firmware"
|
|
90
|
+
fi
|
|
50
91
|
|
|
51
|
-
echo "generating type definitions for: $LANG"
|
|
52
92
|
|
|
93
|
+
# ============================================================
|
|
94
|
+
# BUILD Protocol V2 messages-protocol-v2.json
|
|
95
|
+
# ============================================================
|
|
96
|
+
# Source of truth: submodules/firmware-pro2/sys/protobuf/onekey_protocol/.
|
|
97
|
+
# Protocol V2 keeps chain/app protocols under legacy/ and system protocols under latest/.
|
|
98
|
+
# The SDK flattens them into one protobuf schema for transport runtime, but it must keep
|
|
99
|
+
# firmware message names and enum values intact. SDK-facing aliases belong in core/API code,
|
|
100
|
+
# not in the protobuf schema.
|
|
101
|
+
# ============================================================
|
|
53
102
|
cd "$PARENT_PATH"
|
|
54
103
|
|
|
55
|
-
|
|
104
|
+
SRC_PRO2_LEGACY="$REPO_ROOT/submodules/firmware-pro2/sys/protobuf/onekey_protocol/legacy"
|
|
105
|
+
SRC_PRO2_LATEST="$REPO_ROOT/submodules/firmware-pro2/sys/protobuf/onekey_protocol/latest"
|
|
106
|
+
|
|
107
|
+
if [ -d "$SRC_PRO2_LATEST" ] && ls "$SRC_PRO2_LATEST"/messages*.proto 1>/dev/null 2>&1; then
|
|
108
|
+
echo "=== Building Protocol V2 messages from firmware-pro2 legacy + latest protobuf schema ==="
|
|
109
|
+
TMP_PROTO="$PARENT_PATH/messages-protocol-v2-tmp.proto"
|
|
110
|
+
|
|
111
|
+
{
|
|
112
|
+
echo 'syntax = "proto2";'
|
|
113
|
+
echo 'import "google/protobuf/descriptor.proto";'
|
|
114
|
+
echo ''
|
|
115
|
+
|
|
116
|
+
# Pro2 firmware keeps chain/app protocols under legacy/, and Protocol V2
|
|
117
|
+
# device/filesystem/firmware protocols under latest/. Build one flat
|
|
118
|
+
# schema so Protocol V2 framing can also encode legacy public-chain calls.
|
|
119
|
+
grep -hv \
|
|
120
|
+
-e '^import ' -e '^syntax' -e '^package' -e 'option java_' \
|
|
121
|
+
"$SRC_PRO2_LEGACY"/messages*.proto \
|
|
122
|
+
| sed 's/ hw\.onekey\.messages\.[a-zA-Z_]*\./ /g' \
|
|
123
|
+
| sed 's/ crypto\./ /g' \
|
|
124
|
+
| sed 's/ ethereum_definitions\./ /g' \
|
|
125
|
+
| sed 's/ management\./ /g' \
|
|
126
|
+
| sed 's/^option /\/\/ option /' \
|
|
127
|
+
| grep -v ' reserved '
|
|
128
|
+
|
|
129
|
+
if ! grep -q '^message TonSignData ' "$SRC_PRO2_LEGACY"/messages*.proto; then
|
|
130
|
+
echo ''
|
|
131
|
+
echo '// --- TON signData (kept until firmware-pro2 legacy proto exports it) ---'
|
|
132
|
+
echo 'message TonSignData {'
|
|
133
|
+
echo ' repeated uint32 address_n = 1;'
|
|
134
|
+
echo ' required TonSignDataType type = 2;'
|
|
135
|
+
echo ' required bytes payload = 3;'
|
|
136
|
+
echo ' optional string schema = 4;'
|
|
137
|
+
echo ' required string appdomain = 5;'
|
|
138
|
+
echo ' required uint64 timestamp = 6;'
|
|
139
|
+
echo ' optional string from_address = 7;'
|
|
140
|
+
echo ' optional TonWalletVersion wallet_version = 8 [default=V4R2];'
|
|
141
|
+
echo ' optional uint32 wallet_id = 9 [default=698983191];'
|
|
142
|
+
echo ' optional TonWorkChain workchain = 10 [default=BASECHAIN];'
|
|
143
|
+
echo ' optional bool is_bounceable = 11 [default=false];'
|
|
144
|
+
echo ' optional bool is_testnet_only = 12 [default=false];'
|
|
145
|
+
echo ''
|
|
146
|
+
echo ' enum TonSignDataType {'
|
|
147
|
+
echo ' TEXT = 0;'
|
|
148
|
+
echo ' BINARY = 1;'
|
|
149
|
+
echo ' CELL = 2;'
|
|
150
|
+
echo ' }'
|
|
151
|
+
echo '}'
|
|
152
|
+
echo ''
|
|
153
|
+
echo 'message TonSignedData {'
|
|
154
|
+
echo ' optional bytes signature = 1;'
|
|
155
|
+
echo ' optional bytes digest = 2;'
|
|
156
|
+
echo '}'
|
|
157
|
+
fi
|
|
158
|
+
|
|
159
|
+
echo ''
|
|
160
|
+
echo '// --- Protocol V2 system messages ---'
|
|
161
|
+
grep -hv \
|
|
162
|
+
-e '^import ' -e '^syntax' -e '^package' -e 'option java_' \
|
|
163
|
+
-e '^option ' \
|
|
164
|
+
"$SRC_PRO2_LATEST"/messages*.proto \
|
|
165
|
+
| grep -v ' reserved '
|
|
166
|
+
|
|
167
|
+
if ! grep -q '^message GetOnboardingStatus ' "$SRC_PRO2_LATEST"/messages*.proto; then
|
|
168
|
+
echo ''
|
|
169
|
+
echo '// --- Onboarding status (kept until firmware-pro2 latest proto exports it) ---'
|
|
170
|
+
echo 'enum OnboardingStep {'
|
|
171
|
+
echo ' ONBOARDING_STEP_UNKNOWN = 0;'
|
|
172
|
+
echo ' ONBOARDING_STEP_DEVICE_VERIFICATION = 1;'
|
|
173
|
+
echo ' ONBOARDING_STEP_PERSONALIZATION = 2;'
|
|
174
|
+
echo ' ONBOARDING_STEP_SETUP = 3;'
|
|
175
|
+
echo ' ONBOARDING_STEP_FIRMWARE = 4;'
|
|
176
|
+
echo '}'
|
|
177
|
+
echo ''
|
|
178
|
+
echo 'message GetOnboardingStatus {'
|
|
179
|
+
echo '}'
|
|
180
|
+
echo ''
|
|
181
|
+
echo 'message OnboardingStatus {'
|
|
182
|
+
echo ' message Setup {'
|
|
183
|
+
echo ' message NewDevice {'
|
|
184
|
+
echo ' optional bool seedcard_backup = 1;'
|
|
185
|
+
echo ' }'
|
|
186
|
+
echo ' message Restore {'
|
|
187
|
+
echo ' optional bool mnemonic = 1;'
|
|
188
|
+
echo ' optional bool seedcard = 2;'
|
|
189
|
+
echo ' }'
|
|
190
|
+
echo ' optional NewDevice new_device = 1;'
|
|
191
|
+
echo ' optional Restore restore = 2;'
|
|
192
|
+
echo ' }'
|
|
193
|
+
echo ' required OnboardingStep step = 1;'
|
|
194
|
+
echo ' optional Setup setup = 2;'
|
|
195
|
+
echo ' optional uint32 detail_code = 3;'
|
|
196
|
+
echo ' optional string detail_str = 4;'
|
|
197
|
+
echo '}'
|
|
198
|
+
fi
|
|
199
|
+
} > "$TMP_PROTO"
|
|
200
|
+
|
|
201
|
+
if ! grep -q 'MessageType_TonSignData' "$TMP_PROTO"; then
|
|
202
|
+
node - "$TMP_PROTO" <<'NODE'
|
|
203
|
+
const fs = require('fs');
|
|
204
|
+
|
|
205
|
+
const protoPath = process.argv[2];
|
|
206
|
+
const proto = fs.readFileSync(protoPath, 'utf8');
|
|
207
|
+
const updated = proto.replace(
|
|
208
|
+
/( MessageType_TonTxAck\s*=\s*11907[^\n]*;\n)/,
|
|
209
|
+
`$1 MessageType_TonSignData = 11908 [(wire_in) = true];\n MessageType_TonSignedData = 11909 [(wire_out) = true];\n`
|
|
210
|
+
);
|
|
56
211
|
|
|
57
|
-
|
|
58
|
-
|
|
212
|
+
if (updated === proto) {
|
|
213
|
+
throw new Error('Unable to insert TON signData MessageType entries into Pro2 schema');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
fs.writeFileSync(protoPath, updated);
|
|
217
|
+
NODE
|
|
218
|
+
fi
|
|
219
|
+
|
|
220
|
+
if ! grep -q 'MessageType_GetOnboardingStatus' "$TMP_PROTO"; then
|
|
221
|
+
node - "$TMP_PROTO" <<'NODE'
|
|
222
|
+
const fs = require('fs');
|
|
223
|
+
|
|
224
|
+
const protoPath = process.argv[2];
|
|
225
|
+
const proto = fs.readFileSync(protoPath, 'utf8');
|
|
226
|
+
const updated = proto.replace(
|
|
227
|
+
/( MessageType_DeviceInfo\s*=\s*60601[^\n]*;\n)/,
|
|
228
|
+
`$1 MessageType_GetOnboardingStatus = 60602;\n MessageType_OnboardingStatus = 60603;\n`
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
if (updated === proto) {
|
|
232
|
+
throw new Error('Unable to insert onboarding MessageType entries into Pro2 schema');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
fs.writeFileSync(protoPath, updated);
|
|
236
|
+
NODE
|
|
237
|
+
fi
|
|
238
|
+
|
|
239
|
+
node - "$TMP_PROTO" <<'NODE'
|
|
240
|
+
const fs = require('fs');
|
|
241
|
+
|
|
242
|
+
const protoPath = process.argv[2];
|
|
243
|
+
const proto = fs.readFileSync(protoPath, 'utf8');
|
|
244
|
+
const messageNames = new Set(
|
|
245
|
+
Array.from(proto.matchAll(/^\s*message\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{/gm)).map(
|
|
246
|
+
match => match[1]
|
|
247
|
+
)
|
|
248
|
+
);
|
|
249
|
+
const messageTypeNames = new Set(
|
|
250
|
+
Array.from(proto.matchAll(/^\s*MessageType_([A-Za-z_][A-Za-z0-9_]*)\s*=/gm)).map(
|
|
251
|
+
match => match[1]
|
|
252
|
+
)
|
|
253
|
+
);
|
|
254
|
+
const requiredMessages = [
|
|
255
|
+
'Ping',
|
|
256
|
+
'Success',
|
|
257
|
+
'Failure',
|
|
258
|
+
'DevReboot',
|
|
259
|
+
'DevGetDeviceInfo',
|
|
260
|
+
'DeviceInfo',
|
|
261
|
+
'DevFirmwareUpdate',
|
|
262
|
+
'DevFirmwareInstallProgress',
|
|
263
|
+
'DevGetFirmwareUpdateStatus',
|
|
264
|
+
'DevFirmwareUpdateStatus',
|
|
265
|
+
'FilesystemFixPermission',
|
|
266
|
+
'FilesystemPathInfo',
|
|
267
|
+
'FilesystemPathInfoQuery',
|
|
268
|
+
'FilesystemFile',
|
|
269
|
+
'FilesystemFileRead',
|
|
270
|
+
'FilesystemFileWrite',
|
|
271
|
+
'FilesystemFileDelete',
|
|
272
|
+
'FilesystemDir',
|
|
273
|
+
'FilesystemDirList',
|
|
274
|
+
'FilesystemDirMake',
|
|
275
|
+
'FilesystemDirRemove',
|
|
276
|
+
'FilesystemFormat',
|
|
277
|
+
'TonSignData',
|
|
278
|
+
'TonSignedData',
|
|
279
|
+
'GetOnboardingStatus',
|
|
280
|
+
'OnboardingStatus',
|
|
281
|
+
];
|
|
282
|
+
const missingMessages = requiredMessages.filter(name => !messageNames.has(name));
|
|
283
|
+
const missingMessageTypes = requiredMessages.filter(name => !messageTypeNames.has(name));
|
|
284
|
+
|
|
285
|
+
if (missingMessages.length > 0 || missingMessageTypes.length > 0) {
|
|
286
|
+
throw new Error(
|
|
287
|
+
`Protocol V2 schema missing required entries: messages=[${missingMessages.join(
|
|
288
|
+
', '
|
|
289
|
+
)}], messageTypes=[${missingMessageTypes.join(
|
|
290
|
+
', '
|
|
291
|
+
)}]. Make sure submodules/firmware-pro2 is checked out on branch dev_romloader_split ` +
|
|
292
|
+
'(origin/dev_romloader_split), which contains the Filesystem*/DevFirmwareUpdate/DevReboot messages.'
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Provisional wire IDs injected by this script for messages the firmware proto does
|
|
297
|
+
// not export yet (pending firmware confirmation, see
|
|
298
|
+
// docs/protocol-v2-deviceinfo-field-gaps.md). If the firmware submodule starts
|
|
299
|
+
// exporting these MessageType entries itself, the injection above is skipped and the
|
|
300
|
+
// firmware-assigned IDs flow into TMP_PROTO — assert they still match the IDs the SDK
|
|
301
|
+
// was built against, and fail loudly on any drift.
|
|
302
|
+
const expectedInjectedIds = {
|
|
303
|
+
TonSignData: 11908,
|
|
304
|
+
TonSignedData: 11909,
|
|
305
|
+
GetOnboardingStatus: 60602,
|
|
306
|
+
OnboardingStatus: 60603,
|
|
307
|
+
};
|
|
308
|
+
const actualIds = {};
|
|
309
|
+
for (const match of proto.matchAll(/^\s*MessageType_([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(\d+)/gm)) {
|
|
310
|
+
actualIds[match[1]] = Number(match[2]);
|
|
311
|
+
}
|
|
312
|
+
const idMismatches = Object.entries(expectedInjectedIds)
|
|
313
|
+
.filter(([name, id]) => name in actualIds && actualIds[name] !== id)
|
|
314
|
+
.map(([name, id]) => `${name}: expected ${id}, firmware proto has ${actualIds[name]}`);
|
|
315
|
+
|
|
316
|
+
if (idMismatches.length > 0) {
|
|
317
|
+
throw new Error(
|
|
318
|
+
`Protocol V2 injected MessageType wire IDs conflict with the firmware proto: ${idMismatches.join(
|
|
319
|
+
'; '
|
|
320
|
+
)}. Update the injected IDs in protobuf-build.sh and the registry section in ` +
|
|
321
|
+
'docs/protocol-v2-deviceinfo-field-gaps.md.'
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
NODE
|
|
325
|
+
|
|
326
|
+
npx pbjs -t json \
|
|
327
|
+
-p "$PARENT_PATH" \
|
|
328
|
+
-o "$PARENT_PATH/../messages-protocol-v2.json" \
|
|
329
|
+
--keep-case \
|
|
330
|
+
"$(basename "$TMP_PROTO")"
|
|
331
|
+
|
|
332
|
+
rm -f "$TMP_PROTO"
|
|
333
|
+
|
|
334
|
+
cp "$PARENT_PATH/../messages-protocol-v2.json" "$CORE_MESSAGES_DIR/messages-protocol-v2.json"
|
|
335
|
+
echo "Protocol V2 messages-protocol-v2.json generated from firmware-pro2 legacy + latest schema and copied to core"
|
|
336
|
+
|
|
337
|
+
yarn --cwd "$PACKAGE_ROOT" prettier --write "$PARENT_PATH/../messages-protocol-v2.json"
|
|
338
|
+
yarn --cwd "$PACKAGE_ROOT" prettier --write "$CORE_MESSAGES_DIR/messages-protocol-v2.json"
|
|
339
|
+
|
|
340
|
+
echo "generating type definitions for: $LANG"
|
|
341
|
+
node ./protobuf-types.js $LANG
|
|
342
|
+
yarn --cwd "$PACKAGE_ROOT" prettier --write "$PACKAGE_ROOT/src/types/messages.ts"
|
|
343
|
+
echo "=== Protocol V2 messages build complete ==="
|
|
344
|
+
else
|
|
345
|
+
# Unlike the optional Pro1 (legacy) section above, the firmware-pro2 submodule is
|
|
346
|
+
# the only source of the Protocol V2 schema, so a missing checkout is a hard error.
|
|
347
|
+
echo "firmware-pro2 latest protobuf schema not found at $SRC_PRO2_LATEST"
|
|
348
|
+
echo "The Protocol V2 schema requires firmware-pro2 on branch dev_romloader_split."
|
|
349
|
+
echo "Run: git submodule update --init submodules/firmware-pro2"
|
|
350
|
+
echo "Then: git -C submodules/firmware-pro2 fetch origin dev_romloader_split && git -C submodules/firmware-pro2 checkout origin/dev_romloader_split"
|
|
351
|
+
exit 1
|
|
352
|
+
fi
|
|
@@ -29,6 +29,7 @@ type CommonTxInputType = {|
|
|
|
29
29
|
witness?: string, // used by EXTERNAL, depending on script_pubkey
|
|
30
30
|
ownership_proof?: string, // used by EXTERNAL, depending on script_pubkey
|
|
31
31
|
commitment_data?: string, // used by EXTERNAL, depending on ownership_proof
|
|
32
|
+
coinjoin_flags?: number, // Protocol V2 only (CoinJoin)
|
|
32
33
|
|};
|
|
33
34
|
|
|
34
35
|
export type TxInputType =
|
|
@@ -116,6 +116,7 @@ const TYPE_PATCH = {
|
|
|
116
116
|
'Features.onekey_se03_state': 'string | null',
|
|
117
117
|
'Features.onekey_se04_state': 'string | null',
|
|
118
118
|
'HDNodePathType.node': 'HDNodeType | string',
|
|
119
|
+
'FilesystemFile.data': 'Buffer | ArrayBuffer | Uint8Array | string',
|
|
119
120
|
'FirmwareUpload.payload': 'Buffer | ArrayBuffer',
|
|
120
121
|
'EthereumGetAddress.encoded_network': 'ArrayBuffer',
|
|
121
122
|
'EthereumDefinitions.encoded_network': 'ArrayBuffer',
|
|
@@ -207,6 +208,7 @@ const TYPE_PATCH = {
|
|
|
207
208
|
'TonSignMessage.fwd_fee': UINT_TYPE,
|
|
208
209
|
'TonSignMessage.expire_at': UINT_TYPE,
|
|
209
210
|
'TonSignMessage.ext_ton_amount': UINT_TYPE,
|
|
211
|
+
'TonSignData.timestamp': UINT_TYPE,
|
|
210
212
|
'TonSignProof.expire_at': UINT_TYPE,
|
|
211
213
|
};
|
|
212
214
|
|