@onekeyfe/hd-transport 1.2.8 → 1.2.10-alpha.2

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.
Files changed (38) hide show
  1. package/__tests__/babylon-context-hash.test.js +44 -0
  2. package/__tests__/protocol-v2-file-write-pipeline.test.js +478 -0
  3. package/__tests__/protocol-v2.test.js +3 -3
  4. package/__tests__/static-protobuf.test.js +436 -0
  5. package/__tests__/transport-log.test.js +176 -0
  6. package/dist/constants.d.ts +1 -0
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/index.d.ts +158 -3
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +109280 -98
  11. package/dist/protocols/index.d.ts.map +1 -1
  12. package/dist/protocols/v2/session.d.ts +7 -1
  13. package/dist/protocols/v2/session.d.ts.map +1 -1
  14. package/dist/serialization/protobuf/messages.d.ts +1 -1
  15. package/dist/serialization/protobuf/messages.d.ts.map +1 -1
  16. package/dist/types/messages.d.ts +72 -0
  17. package/dist/types/messages.d.ts.map +1 -1
  18. package/dist/types/transport.d.ts +6 -0
  19. package/dist/types/transport.d.ts.map +1 -1
  20. package/dist/utils/transportLog.d.ts.map +1 -1
  21. package/jest.config.js +3 -0
  22. package/messages-protocol-v2.json +152 -0
  23. package/package.json +6 -4
  24. package/scripts/protobuf-build.sh +37 -0
  25. package/scripts/protobuf-static-csp.js +103 -0
  26. package/scripts/protobuf-static.js +85 -0
  27. package/scripts/protobuf-types.js +1 -0
  28. package/src/constants.ts +10 -1
  29. package/src/index.ts +1 -0
  30. package/src/protocols/index.ts +10 -23
  31. package/src/protocols/v2/session.ts +326 -96
  32. package/src/serialization/protobuf/generated/codecs.d.ts +3 -0
  33. package/src/serialization/protobuf/generated/codecs.js +108990 -0
  34. package/src/serialization/protobuf/legacy-protocol-info.json +16 -0
  35. package/src/serialization/protobuf/messages.ts +12 -6
  36. package/src/types/messages.ts +97 -0
  37. package/src/types/transport.ts +25 -0
  38. package/src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AM,UAAU,CAAC;AA8E7C,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAKxF;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;EAO9B;AAID,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,WAE3D"}
1
+ {"version":3,"file":"transportLog.d.ts","sourceRoot":"","sources":["../../src/utils/transportLog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA6F7C,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAKxF;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;EAO9B;AAID,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,WAE3D"}
package/jest.config.js CHANGED
@@ -3,5 +3,8 @@ module.exports = {
3
3
  testEnvironment: 'node',
4
4
  modulePathIgnorePatterns: ['node_modules', '<rootDir>/lib', '<rootDir>/libDev'],
5
5
  collectCoverage: true,
6
+ // Generated codecs and compiled dependencies are already executable JavaScript.
7
+ transformIgnorePatterns: ['/node_modules/', '/serialization/protobuf/generated/', '/dist/'],
8
+ coveragePathIgnorePatterns: ['/node_modules/', '/serialization/protobuf/generated/', '/dist/'],
6
9
  // collectCoverageFrom: ['src/**/*.ts'],
7
10
  };
@@ -11034,6 +11034,149 @@
11034
11034
  }
11035
11035
  }
11036
11036
  },
11037
+ "ZcashAddressType": {
11038
+ "values": {
11039
+ "UNIFIED_ORCHARD_P2PKH": 0,
11040
+ "TRANSPARENT_P2PKH": 1,
11041
+ "UNIFIED_ORCHARD": 2
11042
+ }
11043
+ },
11044
+ "ZcashAddressScope": {
11045
+ "values": {
11046
+ "EXTERNAL": 0,
11047
+ "INTERNAL": 1
11048
+ }
11049
+ },
11050
+ "ZcashGetAddress": {
11051
+ "fields": {
11052
+ "address_n": {
11053
+ "rule": "repeated",
11054
+ "type": "uint32",
11055
+ "id": 1,
11056
+ "options": {
11057
+ "packed": false
11058
+ }
11059
+ },
11060
+ "show_display": {
11061
+ "type": "bool",
11062
+ "id": 2
11063
+ },
11064
+ "include_seed_fingerprint": {
11065
+ "type": "bool",
11066
+ "id": 3
11067
+ },
11068
+ "diversifier_index": {
11069
+ "type": "uint32",
11070
+ "id": 5,
11071
+ "options": {
11072
+ "default": 0
11073
+ }
11074
+ },
11075
+ "address_type": {
11076
+ "type": "ZcashAddressType",
11077
+ "id": 6,
11078
+ "options": {
11079
+ "default": "UNIFIED_ORCHARD_P2PKH"
11080
+ }
11081
+ },
11082
+ "scope": {
11083
+ "type": "ZcashAddressScope",
11084
+ "id": 7,
11085
+ "options": {
11086
+ "default": "EXTERNAL"
11087
+ }
11088
+ }
11089
+ }
11090
+ },
11091
+ "ZcashAddress": {
11092
+ "fields": {
11093
+ "address": {
11094
+ "rule": "required",
11095
+ "type": "string",
11096
+ "id": 1
11097
+ },
11098
+ "seed_fingerprint": {
11099
+ "type": "bytes",
11100
+ "id": 3
11101
+ }
11102
+ }
11103
+ },
11104
+ "ZcashGetFullViewingKey": {
11105
+ "fields": {
11106
+ "address_n": {
11107
+ "rule": "repeated",
11108
+ "type": "uint32",
11109
+ "id": 1,
11110
+ "options": {
11111
+ "packed": false
11112
+ }
11113
+ }
11114
+ }
11115
+ },
11116
+ "ZcashFullViewingKey": {
11117
+ "fields": {
11118
+ "ufvk": {
11119
+ "rule": "required",
11120
+ "type": "string",
11121
+ "id": 1
11122
+ }
11123
+ }
11124
+ },
11125
+ "ZcashSignPczt": {
11126
+ "fields": {
11127
+ "pczt_length": {
11128
+ "rule": "required",
11129
+ "type": "uint32",
11130
+ "id": 1
11131
+ },
11132
+ "pczt_initial_chunk": {
11133
+ "rule": "required",
11134
+ "type": "bytes",
11135
+ "id": 2
11136
+ }
11137
+ }
11138
+ },
11139
+ "ZcashPcztChunkRequest": {
11140
+ "fields": {
11141
+ "chunk_length": {
11142
+ "rule": "required",
11143
+ "type": "uint32",
11144
+ "id": 1
11145
+ }
11146
+ }
11147
+ },
11148
+ "ZcashPcztChunkAck": {
11149
+ "fields": {
11150
+ "data_chunk": {
11151
+ "rule": "required",
11152
+ "type": "bytes",
11153
+ "id": 1
11154
+ }
11155
+ }
11156
+ },
11157
+ "ZcashSignedPczt": {
11158
+ "fields": {
11159
+ "pczt_length": {
11160
+ "rule": "required",
11161
+ "type": "uint32",
11162
+ "id": 1
11163
+ },
11164
+ "pczt_initial_chunk": {
11165
+ "rule": "required",
11166
+ "type": "bytes",
11167
+ "id": 2
11168
+ }
11169
+ }
11170
+ },
11171
+ "ZcashSignedPcztChunkRequest": {
11172
+ "fields": {
11173
+ "chunk_length": {
11174
+ "rule": "required",
11175
+ "type": "uint32",
11176
+ "id": 1
11177
+ }
11178
+ }
11179
+ },
11037
11180
  "wire_in": {
11038
11181
  "type": "bool",
11039
11182
  "id": 50002,
@@ -11459,6 +11602,15 @@
11459
11602
  "MessageType_NeoAddress": 12302,
11460
11603
  "MessageType_NeoSignTx": 12303,
11461
11604
  "MessageType_NeoSignedTx": 12304,
11605
+ "MessageType_ZcashGetAddress": 12400,
11606
+ "MessageType_ZcashAddress": 12401,
11607
+ "MessageType_ZcashSignPczt": 12402,
11608
+ "MessageType_ZcashSignedPczt": 12403,
11609
+ "MessageType_ZcashPcztChunkRequest": 12404,
11610
+ "MessageType_ZcashPcztChunkAck": 12405,
11611
+ "MessageType_ZcashSignedPcztChunkRequest": 12406,
11612
+ "MessageType_ZcashGetFullViewingKey": 12407,
11613
+ "MessageType_ZcashFullViewingKey": 12408,
11462
11614
  "MessageType_DeviceFactoryInfoSet": 60000,
11463
11615
  "MessageType_DeviceFactoryInfoGet": 60001,
11464
11616
  "MessageType_DeviceFactoryInfo": 60002,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport",
3
- "version": "1.2.8",
3
+ "version": "1.2.10-alpha.2",
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",
@@ -12,8 +12,10 @@
12
12
  },
13
13
  "scripts": {
14
14
  "dev": "rimraf dist && rollup -c ../../build/rollup.config.js -w",
15
- "build": "rimraf dist && rollup -c ../../build/rollup.config.js",
15
+ "build": "node scripts/protobuf-static.js --check && rimraf dist && rollup -c ../../build/rollup.config.js",
16
16
  "test": "jest",
17
+ "test:static-csp": "node --disallow-code-generation-from-strings scripts/protobuf-static-csp.js",
18
+ "check:static": "node scripts/protobuf-static.js --check",
17
19
  "lint": "eslint .",
18
20
  "lint:fix": "eslint . --fix",
19
21
  "update:protobuf": "./scripts/protobuf-build.sh"
@@ -26,7 +28,7 @@
26
28
  "dependencies": {
27
29
  "bytebuffer": "^5.0.1",
28
30
  "long": "^4.0.0",
29
- "protobufjs": "^6.11.2"
31
+ "protobufjs": "6.11.6"
30
32
  },
31
- "gitHead": "9f016278a7f395bf66b8502815dc63191e162fd3"
33
+ "gitHead": "2bcc72a43379abb005405f18f914330f3f2dbfd7"
32
34
  }
@@ -7,6 +7,11 @@ PACKAGE_ROOT="$PARENT_PATH/.."
7
7
  REPO_ROOT="$PARENT_PATH/../../.."
8
8
  CORE_MESSAGES_DIR="$REPO_ROOT/packages/core/src/data/messages"
9
9
 
10
+ if [[ "${1:-}" == "--static-only" ]]; then
11
+ node "$PARENT_PATH/protobuf-static.js"
12
+ exit 0
13
+ fi
14
+
10
15
  SRC="../../submodules/firmware/common/protob"
11
16
  DIST="."
12
17
  LANG="typescript"
@@ -54,6 +59,36 @@ grep -hv -e '^import ' -e '^syntax' -e '^package' -e 'option java_' "$SRC_PATH"/
54
59
  | sed 's/^option /\/\/ option /' \
55
60
  | grep -v ' reserved ' >> "$V1_TMP_PROTO"
56
61
 
62
+ # Classic 1s exposes these messages before the shared firmware submodule includes them.
63
+ # Wire contract: https://onekeygroup.slack.com/archives/C0A7BUG1DT6/p1791598732003599
64
+ node - "$V1_TMP_PROTO" <<'NODE'
65
+ const fs = require('fs');
66
+ const protoPath = process.argv[2];
67
+ let proto = fs.readFileSync(protoPath, 'utf8');
68
+ proto = proto.replace('enum MessageType {', `enum MessageType {
69
+ MessageType_BabylonDeriveContextHash = 10054 [(bitcoin_only) = true, (wire_in) = true];
70
+ MessageType_BabylonDerivedContextHash = 10055 [(bitcoin_only) = true, (wire_out) = true];`);
71
+ proto += `
72
+ enum CanonicalBitcoinNetwork {
73
+ BITCOIN_MAINNET = 0;
74
+ BITCOIN_TESTNET = 1;
75
+ BITCOIN_SIGNET = 2;
76
+ BITCOIN_REGTEST = 3;
77
+ }
78
+ message BabylonDeriveContextHash {
79
+ repeated uint32 address_n = 1;
80
+ required InputScriptType script_type = 2;
81
+ required bytes app_name = 3;
82
+ required bytes context = 4;
83
+ required CanonicalBitcoinNetwork network = 5;
84
+ }
85
+ message BabylonDerivedContextHash {
86
+ required bytes secret = 1;
87
+ }
88
+ `;
89
+ fs.writeFileSync(protoPath, proto);
90
+ NODE
91
+
57
92
  npx pbjs -t json -p "$DIST_PATH" -o "$DIST_PATH/messages.json" --keep-case "$V1_TMP_PROTO"
58
93
  cp "$DIST_PATH/messages.json" "$CORE_MESSAGES_DIR/messages.json"
59
94
 
@@ -136,3 +171,5 @@ yarn --cwd "$PACKAGE_ROOT" prettier --write "$CORE_MESSAGES_DIR/messages.json"
136
171
  yarn --cwd "$PACKAGE_ROOT" prettier --write "$PACKAGE_ROOT/messages-protocol-v2.json"
137
172
  yarn --cwd "$PACKAGE_ROOT" prettier --write "$CORE_MESSAGES_DIR/messages-protocol-v2.json"
138
173
  yarn --cwd "$PACKAGE_ROOT" prettier --write "$PACKAGE_ROOT/src/types/messages.ts"
174
+
175
+ node "$PARENT_PATH/protobuf-static.js"
@@ -0,0 +1,103 @@
1
+ // Run after lerna run build, with --disallow-code-generation-from-strings.
2
+ const assert = require('assert');
3
+ const path = require('path');
4
+ const vm = require('vm');
5
+ const { readFileSync } = require('fs');
6
+ const { build } = require('tsup');
7
+ const protobuf = require('protobufjs/light');
8
+ const { default: transport } = require('../dist');
9
+
10
+ const v1 = require('../../core/src/data/messages/messages.json');
11
+ const legacy = require('../../core/src/data/messages/messages_legacy_v1.json');
12
+ const v2 = require('../messages-protocol-v2.json');
13
+
14
+ const schemas = [v1, legacy, v2];
15
+ function collectTypes(namespace) {
16
+ return [
17
+ ...(namespace instanceof protobuf.Type ? [namespace] : []),
18
+ ...(namespace.nestedArray || []).flatMap(collectTypes),
19
+ ];
20
+ }
21
+ let blocked = 0;
22
+ const dynamic = () => {
23
+ blocked += 1;
24
+ throw new Error('Unexpected dynamic protobuf setup');
25
+ };
26
+ protobuf.Type.prototype.setup = dynamic;
27
+ protobuf.Type.generateConstructor = dynamic;
28
+ let count = 0;
29
+ for (const schema of schemas) {
30
+ const root = transport.parseConfigure(schema);
31
+ for (const type of collectTypes(root)) {
32
+ // Missing required fields can throw; no constructor or codec may fall back to codegen.
33
+ for (const operation of [
34
+ () => type.fromObject({}),
35
+ () => type.encode(type.create()).finish(),
36
+ () => type.decode(new Uint8Array()),
37
+ () => type.verify({}),
38
+ () => type.toObject(type.create()),
39
+ ]) {
40
+ try {
41
+ operation();
42
+ } catch (error) {
43
+ if (error instanceof EvalError) throw error;
44
+ }
45
+ count += 1;
46
+ }
47
+ }
48
+ }
49
+ assert.strictEqual(blocked, 0);
50
+ console.log(`CSP static protobuf: ${count} operations, no dynamic setup`);
51
+
52
+ async function checkBrowser() {
53
+ const outDir = path.resolve(__dirname, '../../../node_modules/.cache/protobuf-static/browser');
54
+ await build({
55
+ entry: { browser: path.resolve(__dirname, '../dist/index.js') },
56
+ outDir,
57
+ format: ['iife'],
58
+ globalName: 'transport',
59
+ platform: 'browser',
60
+ noExternal: [/.*/],
61
+ splitting: false,
62
+ silent: true,
63
+ config: false,
64
+ });
65
+ const code = readFileSync(path.join(outDir, 'browser.global.js'), 'utf8');
66
+ const context = vm.createContext(
67
+ { schemas },
68
+ { codeGeneration: { strings: false, wasm: false } }
69
+ );
70
+ vm.runInContext(code, context);
71
+ const operations = vm.runInContext(
72
+ `
73
+ let count = 0;
74
+ function visit(namespace) {
75
+ if (namespace.fields) {
76
+ if (!Object.hasOwn(namespace, 'encode')) throw Error('Missing static codec');
77
+ for (const operation of [
78
+ () => namespace.fromObject({}),
79
+ () => namespace.encode(namespace.create()).finish(),
80
+ () => namespace.decode(new Uint8Array()),
81
+ () => namespace.verify({}),
82
+ () => namespace.toObject(namespace.create())
83
+ ]) {
84
+ try { operation(); } catch (error) {
85
+ if (error instanceof EvalError) throw error;
86
+ }
87
+ count += 1;
88
+ }
89
+ }
90
+ for (const child of namespace.nestedArray || []) visit(child);
91
+ }
92
+ for (const schema of schemas) visit(transport.default.parseConfigure(schema));
93
+ count;
94
+ `,
95
+ context
96
+ );
97
+ assert.strictEqual(operations, count);
98
+ console.log(`Browser CSP: ${operations} operations, ${code.length} bytes before minification`);
99
+ }
100
+ checkBrowser().catch(error => {
101
+ console.error(error.message);
102
+ process.exitCode = 1;
103
+ });
@@ -0,0 +1,85 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const protobuf = require('protobufjs/light');
4
+ const Long = require('long');
5
+
6
+ protobuf.util.Long = Long;
7
+ protobuf.configure();
8
+
9
+ const packageRoot = path.resolve(__dirname, '..');
10
+ const outputDirectory = path.join(packageRoot, 'src/serialization/protobuf/generated');
11
+ const schemaPaths = [
12
+ '../core/src/data/messages/messages.json',
13
+ '../core/src/data/messages/messages_legacy_v1.json',
14
+ 'messages-protocol-v2.json',
15
+ 'src/serialization/protobuf/legacy-protocol-info.json',
16
+ ];
17
+ const methods = ['encode', 'decode', 'verify', 'fromObject', 'toObject'];
18
+ const factories = new Map();
19
+ const registrations = [];
20
+
21
+ function collectTypes(namespace) {
22
+ return [
23
+ ...(namespace instanceof protobuf.Type ? [namespace] : []),
24
+ ...(namespace.nestedArray || []).flatMap(collectTypes),
25
+ ];
26
+ }
27
+
28
+ for (const schemaPath of schemaPaths) {
29
+ const schema = JSON.parse(fs.readFileSync(path.join(packageRoot, schemaPath), 'utf8'));
30
+ const root = protobuf.Root.fromJSON(schema);
31
+ // Capture before resolution, which can normalize field options in place.
32
+ const signature = JSON.stringify(root.toJSON());
33
+ const registrationsForSchema = [];
34
+ for (const type of collectTypes(root)) {
35
+ type.setup();
36
+ const source = [
37
+ `type.ctor = ${type.ctor.toString()};`,
38
+ 'const types = type.fieldsArray.map(field => field.resolvedType);',
39
+ ...methods.map(method => `type.${method} = ${type[method].toString()};`),
40
+ ].join('\n');
41
+ if (!factories.has(source)) factories.set(source, factories.size);
42
+ registrationsForSchema.push([type.fullName, factories.get(source)]);
43
+ }
44
+ registrations.push({ signature, types: registrationsForSchema });
45
+ }
46
+
47
+ // Keep the exact generated algorithms, including legacy conversion quirks.
48
+ const source = [
49
+ '// @generated by scripts/protobuf-static.js. DO NOT EDIT.',
50
+ `const { Reader, Writer, util } = require('protobufjs/minimal');`,
51
+ 'const factories = [',
52
+ ...Array.from(factories.keys(), body => `function(type) {\n${body}\n},`),
53
+ '];',
54
+ `const schemas = ${JSON.stringify(registrations)};`,
55
+ 'exports.installStaticCodecs = function(root) {',
56
+ ' const signature = JSON.stringify(root.toJSON());',
57
+ ' const schema = schemas.find(candidate => candidate.signature === signature);',
58
+ ' if (!schema) return false;',
59
+ ' for (const [name, factory] of schema.types) factories[factory](root.lookupType(name));',
60
+ ' return true;',
61
+ '};',
62
+ '',
63
+ ].join('\n');
64
+ const declaration = [
65
+ '// @generated by scripts/protobuf-static.js. DO NOT EDIT.',
66
+ "import type { Root } from 'protobufjs/light';",
67
+ 'export declare function installStaticCodecs(root: Root): boolean;',
68
+ '',
69
+ ].join('\n');
70
+
71
+ for (const [name, content] of [
72
+ ['codecs.js', source],
73
+ ['codecs.d.ts', declaration],
74
+ ]) {
75
+ const destination = path.join(outputDirectory, name);
76
+ if (process.argv.includes('--check')) {
77
+ if (!fs.existsSync(destination) || fs.readFileSync(destination, 'utf8') !== content) {
78
+ throw new Error(`Static protobuf is stale: run yarn update-protobuf:static (${name})`);
79
+ }
80
+ } else {
81
+ fs.mkdirSync(outputDirectory, { recursive: true });
82
+ fs.writeFileSync(destination, content);
83
+ }
84
+ }
85
+ console.log(`Static protobuf: ${registrations.length} schemas, ${factories.size} shared codecs`);
@@ -55,6 +55,7 @@ const hasParsedType = name => types.some(t => t && t.name === name);
55
55
  // enums used as keys (string), used as values (number) by default
56
56
  const ENUM_KEYS = [
57
57
  'InputScriptType',
58
+ 'CanonicalBitcoinNetwork',
58
59
  'OutputScriptType',
59
60
  'RequestType',
60
61
  'KaspaInputScriptType',
package/src/constants.ts CHANGED
@@ -30,8 +30,9 @@ export const PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE = 4000;
30
30
  export const PROTOCOL_V2_BLE_FILE_CHUNK_SIZE = 1800;
31
31
 
32
32
  /**
33
- * FirmwareUpdateV4 chunk size for its fixed BLE staging paths.
33
+ * FirmwareUpdateV4 chunk size for its fixed BLE staging paths when writes are serial.
34
34
  * The longest current path still leaves 28 bytes below the 2048-byte BLE frame limit.
35
+ * Pipelined writes use PROTOCOL_V2_BLE_FILE_CHUNK_SIZE so two frames fit the UART FIFO.
35
36
  */
36
37
  export const PROTOCOL_V2_BLE_FIRMWARE_FILE_CHUNK_SIZE = 1960;
37
38
 
@@ -41,6 +42,14 @@ export const PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE = 900;
41
42
  /** Pro2 BLE/UART RX FIFO must hold a complete Proto Link frame. */
42
43
  export const PROTOCOL_V2_BLE_FRAME_MAX_BYTES = 2048;
43
44
 
45
+ /**
46
+ * FilesystemFileWrite frames kept in flight by a file write pipeline. The main MCU copies a
47
+ * complete frame out of its UART FIFO before handling it, but a frame waiting to be parsed and
48
+ * the next one being received can both be resident: two full frames must fit (4096-byte FIFO).
49
+ * With 1800-byte chunks two frames take about 3.75 KB.
50
+ */
51
+ export const PROTOCOL_V2_FILE_WRITE_PIPELINE_WINDOW = 2;
52
+
44
53
  /** @deprecated Use the transport-specific WebUSB or BLE file chunk constant. */
45
54
  export const PROTOCOL_V2_FILE_CHUNK_SIZE = PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
46
55
 
package/src/index.ts CHANGED
@@ -37,6 +37,7 @@ export type {
37
37
  MessageFromOneKey,
38
38
  TransportCallOptions,
39
39
  TransportWriteMetrics,
40
+ ProtocolV2FileWritePipeline,
40
41
  LowlevelTransportSharedPlugin,
41
42
  LowLevelDevice,
42
43
  OneKeyDeviceInfoBase,
@@ -1,10 +1,14 @@
1
1
  import ByteBuffer from 'bytebuffer';
2
- import { Reader, Type } from 'protobufjs/light';
2
+ import { Reader } from 'protobufjs/minimal';
3
3
 
4
4
  import { encodeEnvelopeMessage, encodeMessageChunks, encodeTransportPackets } from './v1/packets';
5
5
  import { decodeFirstChunk } from './v1/decode';
6
6
  import { decodeMessage as decodeV1Message } from './v1/receive';
7
- import { createMessageFromName, createMessageFromType } from '../serialization/protobuf/messages';
7
+ import {
8
+ createMessageFromName,
9
+ createMessageFromType,
10
+ parseConfigure,
11
+ } from '../serialization/protobuf/messages';
8
12
  import { encode as encodeProtobuf } from '../serialization/protobuf/encode';
9
13
  import { decode as decodeProtobuf } from '../serialization/protobuf/decode';
10
14
  import {
@@ -14,6 +18,8 @@ import {
14
18
  isAckFrame,
15
19
  } from './v2';
16
20
 
21
+ import legacyProtocolInfo from '../serialization/protobuf/legacy-protocol-info.json';
22
+
17
23
  import type { Root } from 'protobufjs/light';
18
24
 
19
25
  export const PROTOCOL_V2_SYS_MESSAGE_THRESHOLD = 60000;
@@ -30,27 +36,8 @@ type ProtocolV2FrameOptions = {
30
36
  seq?: number;
31
37
  };
32
38
 
33
- const LEGACY_PROTOCOL_V2_PROTOCOL_INFO = Type.fromJSON('LegacyProtocolInfo', {
34
- fields: {
35
- version: {
36
- rule: 'required',
37
- type: 'uint32',
38
- id: 1,
39
- },
40
- supported_messages: {
41
- rule: 'repeated',
42
- type: 'uint32',
43
- id: 2,
44
- options: {
45
- packed: false,
46
- },
47
- },
48
- protobuf_definition: {
49
- type: 'string',
50
- id: 3,
51
- },
52
- },
53
- });
39
+ const LEGACY_PROTOCOL_V2_PROTOCOL_INFO =
40
+ parseConfigure(legacyProtocolInfo).lookupType('LegacyProtocolInfo');
54
41
 
55
42
  const decodeLegacyProtocolV2ProtocolInfo = (pbPayload: Uint8Array) => {
56
43
  const byteBuffer = ByteBuffer.wrap(Buffer.from(pbPayload) as unknown as ArrayBuffer);