@onekeyfe/hd-transport 1.2.0-alpha.12 → 1.2.0-alpha.121
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/__tests__/messages.test.js +165 -13
- package/__tests__/protocol-v2-ble-frame-writer.test.js +119 -0
- package/__tests__/protocol-v2-link-manager.test.js +120 -9
- package/__tests__/protocol-v2-usb-transport-base.test.js +36 -2
- package/__tests__/protocol-v2.test.js +566 -69
- package/__tests__/transport-log.test.js +79 -0
- package/dist/constants.d.ts +3 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +696 -221
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +662 -130
- package/dist/protocols/index.d.ts +24 -1
- package/dist/protocols/index.d.ts.map +1 -1
- package/dist/protocols/v2/ble-frame-writer.d.ts +15 -0
- package/dist/protocols/v2/ble-frame-writer.d.ts.map +1 -0
- package/dist/protocols/v2/decode.d.ts +11 -0
- package/dist/protocols/v2/decode.d.ts.map +1 -1
- package/dist/protocols/v2/errors.d.ts +8 -0
- package/dist/protocols/v2/errors.d.ts.map +1 -0
- package/dist/protocols/v2/frame-assembler.d.ts.map +1 -1
- package/dist/protocols/v2/index.d.ts +2 -0
- package/dist/protocols/v2/index.d.ts.map +1 -1
- package/dist/protocols/v2/link-manager.d.ts +4 -0
- package/dist/protocols/v2/link-manager.d.ts.map +1 -1
- package/dist/protocols/v2/session.d.ts +11 -4
- package/dist/protocols/v2/session.d.ts.map +1 -1
- package/dist/protocols/v2/usb-transport-base.d.ts +1 -0
- package/dist/protocols/v2/usb-transport-base.d.ts.map +1 -1
- package/dist/serialization/protobuf/decode.d.ts.map +1 -1
- package/dist/serialization/protobuf/encode.d.ts.map +1 -1
- package/dist/types/messages.d.ts +345 -158
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/transport.d.ts +21 -3
- package/dist/types/transport.d.ts.map +1 -1
- package/dist/utils/transportLog.d.ts +9 -0
- package/dist/utils/transportLog.d.ts.map +1 -0
- package/messages-protocol-v2.json +1057 -577
- package/package.json +3 -3
- package/scripts/protobuf-build.sh +85 -217
- package/scripts/protobuf-patches/index.js +1 -0
- package/scripts/protobuf-types.js +19 -1
- package/src/constants.ts +30 -16
- package/src/index.ts +5 -1
- package/src/protocols/index.ts +127 -4
- package/src/protocols/v2/ble-frame-writer.ts +77 -0
- package/src/protocols/v2/crc8.ts +1 -1
- package/src/protocols/v2/decode.ts +49 -12
- package/src/protocols/v2/encode.ts +1 -1
- package/src/protocols/v2/errors.ts +25 -0
- package/src/protocols/v2/frame-assembler.ts +6 -4
- package/src/protocols/v2/index.ts +2 -0
- package/src/protocols/v2/link-manager.ts +54 -5
- package/src/protocols/v2/session.ts +166 -59
- package/src/protocols/v2/usb-transport-base.ts +29 -10
- package/src/serialization/protobuf/decode.ts +4 -1
- package/src/serialization/protobuf/encode.ts +5 -1
- package/src/types/messages.ts +421 -201
- package/src/types/transport.ts +30 -3
- package/src/utils/transportLog.ts +102 -0
package/dist/index.js
CHANGED
|
@@ -140,7 +140,7 @@ function messageToJSON(Message, fields) {
|
|
|
140
140
|
res[key] = field.resolvedType.valuesById[value];
|
|
141
141
|
}
|
|
142
142
|
else if (field.resolvedType.fields) {
|
|
143
|
-
res[key] = messageToJSON(value, field.resolvedType.fields);
|
|
143
|
+
res[key] = value == null ? null : messageToJSON(value, field.resolvedType.fields);
|
|
144
144
|
}
|
|
145
145
|
else {
|
|
146
146
|
throw new Error(`case not handled: ${key}`);
|
|
@@ -200,7 +200,10 @@ function patch(Message, payload) {
|
|
|
200
200
|
}
|
|
201
201
|
if (field.repeated) {
|
|
202
202
|
const RefMessage = Message.lookupTypeOrEnum(field.type);
|
|
203
|
-
patched[key] =
|
|
203
|
+
patched[key] =
|
|
204
|
+
RefMessage instanceof protobuf.Enum
|
|
205
|
+
? value.map((v) => transform(field.type, v))
|
|
206
|
+
: value.map((v) => patch(RefMessage, v));
|
|
204
207
|
}
|
|
205
208
|
else if (typeof value === 'object' && value !== null) {
|
|
206
209
|
const RefMessage = Message.lookupType(field.type);
|
|
@@ -267,9 +270,10 @@ const PROTOCOL_V1_CHUNK_PAYLOAD_SIZE = 63;
|
|
|
267
270
|
const PROTOCOL_V1_USB_PACKET_SIZE = PROTOCOL_V1_CHUNK_PAYLOAD_SIZE + 1;
|
|
268
271
|
const PROTOCOL_V1_MESSAGE_HEADER_SIZE = 2 + 4;
|
|
269
272
|
const PROTOCOL_V1_ENVELOPE_HEADER_SIZE = 1 + 1 + PROTOCOL_V1_MESSAGE_HEADER_SIZE;
|
|
270
|
-
const PROTOCOL_V2_FRAME_MAX_BYTES =
|
|
273
|
+
const PROTOCOL_V2_FRAME_MAX_BYTES = 4200;
|
|
271
274
|
const PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE = 4000;
|
|
272
275
|
const PROTOCOL_V2_BLE_FILE_CHUNK_SIZE = 1800;
|
|
276
|
+
const PROTOCOL_V2_BLE_FIRMWARE_FILE_CHUNK_SIZE = 1960;
|
|
273
277
|
const PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE = 900;
|
|
274
278
|
const PROTOCOL_V2_BLE_FRAME_MAX_BYTES = 2048;
|
|
275
279
|
const PROTOCOL_V2_FILE_CHUNK_SIZE = PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
@@ -277,6 +281,7 @@ const PROTOCOL_V2_CHANNEL_USB = 0;
|
|
|
277
281
|
const PROTOCOL_V2_CHANNEL_BLE_UART = 1;
|
|
278
282
|
const PROTOCOL_V2_CHANNEL_SOCKET = 2;
|
|
279
283
|
const PROTOCOL_V2_PACKET_SRC_COMMAND = 0;
|
|
284
|
+
const PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS = 5 * 60 * 1000;
|
|
280
285
|
|
|
281
286
|
function encodeEnvelope(data, options) {
|
|
282
287
|
const { addTrezorHeaders, chunked, messageTypeId } = options;
|
|
@@ -425,7 +430,7 @@ function encodeFrame(payload, packetSrc, router, seq) {
|
|
|
425
430
|
const payloadLen = payload ? payload.length : 0;
|
|
426
431
|
const frameLen = payloadLen + PROTO_HEAD_CRC_SIZE;
|
|
427
432
|
if (frameLen > PROTOCOL_V2_FRAME_MAX_BYTES) {
|
|
428
|
-
throw new Error(`Protocol V2 frame too large: ${frameLen}`);
|
|
433
|
+
throw new Error(`Protocol V2 frame too large: ${frameLen} > ${PROTOCOL_V2_FRAME_MAX_BYTES}`);
|
|
429
434
|
}
|
|
430
435
|
const frame = new Uint8Array(frameLen);
|
|
431
436
|
frame[0] = PROTO_HEAD_SOF;
|
|
@@ -450,7 +455,7 @@ function encodeProtobufFrame(messageTypeId, pbPayload, packetSrc, router, seq) {
|
|
|
450
455
|
return encodeFrame(payload, packetSrc, router, seq);
|
|
451
456
|
}
|
|
452
457
|
|
|
453
|
-
function
|
|
458
|
+
function inspectFrameHeader(data) {
|
|
454
459
|
if (data.length < PROTO_HEAD_CRC_SIZE) {
|
|
455
460
|
throw new Error(`Protocol V2 frame too short: ${data.length} bytes`);
|
|
456
461
|
}
|
|
@@ -458,8 +463,8 @@ function validateFrame(data) {
|
|
|
458
463
|
throw new Error(`Invalid SOF byte: expected 0x5A, got 0x${data[0].toString(16).padStart(2, '0')}`);
|
|
459
464
|
}
|
|
460
465
|
const frameLen = data[1] + data[2] * 256;
|
|
461
|
-
if (data.length
|
|
462
|
-
throw new Error(`
|
|
466
|
+
if (data.length !== frameLen) {
|
|
467
|
+
throw new Error(`Protocol V2 frame length mismatch: expected ${frameLen} bytes, got ${data.length}`);
|
|
463
468
|
}
|
|
464
469
|
const expectedHeaderCrc = crc8(data, 3);
|
|
465
470
|
if (data[3] !== expectedHeaderCrc) {
|
|
@@ -473,30 +478,54 @@ function validateFrame(data) {
|
|
|
473
478
|
.toString(16)
|
|
474
479
|
.padStart(2, '0')}, got 0x${data[frameLen - 1].toString(16).padStart(2, '0')}`);
|
|
475
480
|
}
|
|
476
|
-
|
|
481
|
+
const dataType = data[5] & 0x03;
|
|
482
|
+
const packetSrc = (data[5] >> 2) & 0x0f;
|
|
483
|
+
const seq = data[6];
|
|
484
|
+
if (seq === 0) {
|
|
485
|
+
throw new Error('Invalid Protocol V2 sequence: 0 is reserved');
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
frameLen,
|
|
489
|
+
router: data[4],
|
|
490
|
+
packetSrc,
|
|
491
|
+
dataType,
|
|
492
|
+
seq,
|
|
493
|
+
};
|
|
477
494
|
}
|
|
478
495
|
function isAckFrame(data) {
|
|
479
496
|
if (data.length < 6 || (data[5] & 0x03) !== PROTO_DATA_TYPE_ACK) {
|
|
480
497
|
return false;
|
|
481
498
|
}
|
|
482
|
-
const
|
|
483
|
-
if (frameLen !== PROTO_HEAD_CRC_SIZE) {
|
|
484
|
-
throw new Error(`Invalid Protocol V2 ACK frame length: ${frameLen}`);
|
|
499
|
+
const header = inspectFrameHeader(data);
|
|
500
|
+
if (header.frameLen !== PROTO_HEAD_CRC_SIZE) {
|
|
501
|
+
throw new Error(`Invalid Protocol V2 ACK frame length: ${header.frameLen}`);
|
|
485
502
|
}
|
|
486
503
|
return true;
|
|
487
504
|
}
|
|
488
505
|
function decodeFrame(data) {
|
|
489
|
-
const frameLen =
|
|
490
|
-
|
|
506
|
+
const { frameLen, router, packetSrc, dataType, seq } = inspectFrameHeader(data);
|
|
507
|
+
if (dataType !== PROTO_DATA_TYPE_PACKET) {
|
|
508
|
+
throw new Error(`Invalid Protocol V2 data type: expected packet, got ${dataType}`);
|
|
509
|
+
}
|
|
491
510
|
const payloadData = data.slice(7, frameLen - 1);
|
|
492
511
|
if (payloadData.length < 2) {
|
|
493
512
|
throw new Error(`Protocol V2 payload too short (need >=2 bytes for messageTypeId)`);
|
|
494
513
|
}
|
|
495
514
|
const messageTypeId = payloadData[0] + payloadData[1] * 256;
|
|
496
515
|
const pbPayload = payloadData.slice(2);
|
|
497
|
-
return { messageTypeId, pbPayload, seq };
|
|
516
|
+
return { messageTypeId, pbPayload, seq, router, packetSrc, dataType };
|
|
498
517
|
}
|
|
499
518
|
|
|
519
|
+
class ProtocolV2LinkError extends Error {
|
|
520
|
+
constructor(code, message, cause) {
|
|
521
|
+
super(message);
|
|
522
|
+
this.name = 'ProtocolV2LinkError';
|
|
523
|
+
this.code = code;
|
|
524
|
+
this.cause = cause;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
const isProtocolV2LinkError = (error) => error instanceof ProtocolV2LinkError;
|
|
528
|
+
|
|
500
529
|
function concatUint8Arrays(arrays) {
|
|
501
530
|
const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
502
531
|
const result = new Uint8Array(totalLength);
|
|
@@ -540,23 +569,23 @@ class ProtocolV2FrameAssembler {
|
|
|
540
569
|
return undefined;
|
|
541
570
|
if (this.buffer[0] !== PROTO_HEAD_SOF) {
|
|
542
571
|
this.reset();
|
|
543
|
-
throw new
|
|
572
|
+
throw new ProtocolV2LinkError('frame', 'Invalid Protocol V2 SOF');
|
|
544
573
|
}
|
|
545
574
|
const expectedLen = this.buffer[1] + this.buffer[2] * 256;
|
|
546
575
|
if (expectedLen < PROTO_HEAD_CRC_SIZE) {
|
|
547
576
|
this.reset();
|
|
548
|
-
throw new
|
|
577
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 frame length too small: ${expectedLen}`);
|
|
549
578
|
}
|
|
550
579
|
if (expectedLen > this.maxFrameBytes) {
|
|
551
580
|
this.reset();
|
|
552
|
-
throw new
|
|
581
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 frame too large: ${expectedLen}`);
|
|
553
582
|
}
|
|
554
583
|
if (this.buffer.length < PROTO_PRE_HEAD_SIZE)
|
|
555
584
|
return undefined;
|
|
556
585
|
const expectedHeaderCrc = crc8(this.buffer, 3);
|
|
557
586
|
if (this.buffer[3] !== expectedHeaderCrc) {
|
|
558
587
|
this.reset();
|
|
559
|
-
throw new
|
|
588
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 header CRC mismatch: expected 0x${expectedHeaderCrc
|
|
560
589
|
.toString(16)
|
|
561
590
|
.padStart(2, '0')}`);
|
|
562
591
|
}
|
|
@@ -568,6 +597,51 @@ class ProtocolV2FrameAssembler {
|
|
|
568
597
|
}
|
|
569
598
|
}
|
|
570
599
|
|
|
600
|
+
const defaultWait = (timeoutMs) => new Promise(resolve => {
|
|
601
|
+
setTimeout(resolve, timeoutMs);
|
|
602
|
+
});
|
|
603
|
+
function writeProtocolV2BleFrame({ frame, packetCapacity, writePacket, assertActive, signal, abortMessage = 'Protocol V2 BLE write aborted', initialDelayMs = 0, burstSize, burstPauseMs = 0, flushDelayMs = 0, wait = defaultWait, }) {
|
|
604
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
605
|
+
if (!Number.isInteger(packetCapacity) || packetCapacity <= 0) {
|
|
606
|
+
throw new Error('Protocol V2 BLE packet capacity must be a positive integer');
|
|
607
|
+
}
|
|
608
|
+
if (burstSize !== undefined && (!Number.isInteger(burstSize) || burstSize <= 0)) {
|
|
609
|
+
throw new Error('Protocol V2 BLE burst size must be a positive integer');
|
|
610
|
+
}
|
|
611
|
+
const assertWritable = () => {
|
|
612
|
+
assertActive === null || assertActive === void 0 ? void 0 : assertActive();
|
|
613
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
614
|
+
throw new Error(abortMessage);
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
if (frame.length > 0 && initialDelayMs > 0) {
|
|
618
|
+
assertWritable();
|
|
619
|
+
yield wait(initialDelayMs);
|
|
620
|
+
assertWritable();
|
|
621
|
+
}
|
|
622
|
+
let packetsWritten = 0;
|
|
623
|
+
for (let offset = 0; offset < frame.length; offset += packetCapacity) {
|
|
624
|
+
assertWritable();
|
|
625
|
+
const packet = frame.slice(offset, offset + packetCapacity);
|
|
626
|
+
yield writePacket(packet, packetsWritten);
|
|
627
|
+
packetsWritten += 1;
|
|
628
|
+
assertWritable();
|
|
629
|
+
const hasMorePackets = offset + packetCapacity < frame.length;
|
|
630
|
+
if (hasMorePackets &&
|
|
631
|
+
burstSize !== undefined &&
|
|
632
|
+
packetsWritten % burstSize === 0 &&
|
|
633
|
+
burstPauseMs > 0) {
|
|
634
|
+
yield wait(burstPauseMs);
|
|
635
|
+
assertWritable();
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (burstSize !== undefined && packetsWritten > burstSize && flushDelayMs > 0) {
|
|
639
|
+
yield wait(flushDelayMs);
|
|
640
|
+
assertWritable();
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
|
|
571
645
|
var protocolV2Codec = /*#__PURE__*/Object.freeze({
|
|
572
646
|
__proto__: null,
|
|
573
647
|
PROTO_HEAD_SOF: PROTO_HEAD_SOF,
|
|
@@ -582,13 +656,92 @@ var protocolV2Codec = /*#__PURE__*/Object.freeze({
|
|
|
582
656
|
nextProtoSeq: nextProtoSeq,
|
|
583
657
|
encodeFrame: encodeFrame,
|
|
584
658
|
encodeProtobufFrame: encodeProtobufFrame,
|
|
659
|
+
inspectFrameHeader: inspectFrameHeader,
|
|
585
660
|
isAckFrame: isAckFrame,
|
|
586
661
|
decodeFrame: decodeFrame,
|
|
662
|
+
ProtocolV2LinkError: ProtocolV2LinkError,
|
|
663
|
+
isProtocolV2LinkError: isProtocolV2LinkError,
|
|
587
664
|
concatUint8Arrays: concatUint8Arrays,
|
|
588
|
-
ProtocolV2FrameAssembler: ProtocolV2FrameAssembler
|
|
665
|
+
ProtocolV2FrameAssembler: ProtocolV2FrameAssembler,
|
|
666
|
+
writeProtocolV2BleFrame: writeProtocolV2BleFrame
|
|
589
667
|
});
|
|
590
668
|
|
|
591
669
|
const PROTOCOL_V2_SYS_MESSAGE_THRESHOLD = 60000;
|
|
670
|
+
const LEGACY_PROTOCOL_V2_PROTOCOL_INFO = protobuf.Type.fromJSON('LegacyProtocolInfo', {
|
|
671
|
+
fields: {
|
|
672
|
+
version: {
|
|
673
|
+
rule: 'required',
|
|
674
|
+
type: 'uint32',
|
|
675
|
+
id: 1,
|
|
676
|
+
},
|
|
677
|
+
supported_messages: {
|
|
678
|
+
rule: 'repeated',
|
|
679
|
+
type: 'uint32',
|
|
680
|
+
id: 2,
|
|
681
|
+
options: {
|
|
682
|
+
packed: false,
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
protobuf_definition: {
|
|
686
|
+
type: 'string',
|
|
687
|
+
id: 3,
|
|
688
|
+
},
|
|
689
|
+
},
|
|
690
|
+
});
|
|
691
|
+
const decodeLegacyProtocolV2ProtocolInfo = (pbPayload) => {
|
|
692
|
+
var _a;
|
|
693
|
+
const byteBuffer = ByteBuffer__default["default"].wrap(Buffer.from(pbPayload));
|
|
694
|
+
const legacy = decode(LEGACY_PROTOCOL_V2_PROTOCOL_INFO, byteBuffer);
|
|
695
|
+
return {
|
|
696
|
+
version: legacy.version,
|
|
697
|
+
build_fingerprint: '',
|
|
698
|
+
supported_messages: (_a = legacy.supported_messages) !== null && _a !== void 0 ? _a : [],
|
|
699
|
+
protobuf_definition: null,
|
|
700
|
+
};
|
|
701
|
+
};
|
|
702
|
+
const isLegacyProtocolV2ProtocolInfoWireLayout = (pbPayload) => {
|
|
703
|
+
const reader = protobuf.Reader.create(pbPayload);
|
|
704
|
+
let hasVersion = false;
|
|
705
|
+
try {
|
|
706
|
+
while (reader.pos < reader.len) {
|
|
707
|
+
const tag = reader.uint32();
|
|
708
|
+
const fieldNumber = tag >>> 3;
|
|
709
|
+
const wireType = tag & 0x07;
|
|
710
|
+
if (fieldNumber === 1) {
|
|
711
|
+
if (wireType !== 0)
|
|
712
|
+
return false;
|
|
713
|
+
hasVersion = true;
|
|
714
|
+
}
|
|
715
|
+
else if (fieldNumber === 2) {
|
|
716
|
+
if (wireType !== 0)
|
|
717
|
+
return false;
|
|
718
|
+
}
|
|
719
|
+
else if (fieldNumber === 3) {
|
|
720
|
+
if (wireType !== 2)
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
else {
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
reader.skipType(wireType);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
catch (_a) {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
return hasVersion;
|
|
733
|
+
};
|
|
734
|
+
const tryDecodeLegacyProtocolV2ProtocolInfo = (messageName, pbPayload) => {
|
|
735
|
+
if (messageName !== 'ProtocolInfo' || !isLegacyProtocolV2ProtocolInfoWireLayout(pbPayload)) {
|
|
736
|
+
return undefined;
|
|
737
|
+
}
|
|
738
|
+
try {
|
|
739
|
+
return decodeLegacyProtocolV2ProtocolInfo(pbPayload);
|
|
740
|
+
}
|
|
741
|
+
catch (_a) {
|
|
742
|
+
return undefined;
|
|
743
|
+
}
|
|
744
|
+
};
|
|
592
745
|
const resolveProtocolV2EncodeSchema = (name, schemas) => {
|
|
593
746
|
try {
|
|
594
747
|
schemas.protocolV2.lookupType(name);
|
|
@@ -634,6 +787,21 @@ const ProtocolV1 = {
|
|
|
634
787
|
};
|
|
635
788
|
const ProtocolV2 = {
|
|
636
789
|
isAckFrame,
|
|
790
|
+
inspectFrameHeader,
|
|
791
|
+
inspectFrame(schemas, frame) {
|
|
792
|
+
const { messageTypeId, pbPayload, seq, router, packetSrc, dataType } = decodeFrame(frame);
|
|
793
|
+
const { messageName } = createProtocolV2MessageFromType(messageTypeId, schemas);
|
|
794
|
+
return {
|
|
795
|
+
messageName,
|
|
796
|
+
messageTypeId,
|
|
797
|
+
pbPayload,
|
|
798
|
+
seq,
|
|
799
|
+
router,
|
|
800
|
+
packetSrc,
|
|
801
|
+
dataType,
|
|
802
|
+
type: messageName,
|
|
803
|
+
};
|
|
804
|
+
},
|
|
637
805
|
encodeFrame(schemas, name, data, options = {}) {
|
|
638
806
|
const encodeMessages = resolveProtocolV2EncodeSchema(name, schemas);
|
|
639
807
|
const { Message, messageTypeId } = createMessageFromName(encodeMessages, name);
|
|
@@ -644,10 +812,31 @@ const ProtocolV2 = {
|
|
|
644
812
|
return encodeProtobufFrame(messageTypeId, pbBytes, options.packetSrc, options.router, options.seq);
|
|
645
813
|
},
|
|
646
814
|
decodeFrame(schemas, frame) {
|
|
647
|
-
const { messageTypeId, pbPayload, seq } =
|
|
648
|
-
const { Message
|
|
815
|
+
const { messageTypeId, pbPayload, seq, messageName } = this.inspectFrame(schemas, frame);
|
|
816
|
+
const { Message } = createProtocolV2MessageFromType(messageTypeId, schemas);
|
|
649
817
|
const rxByteBuffer = ByteBuffer__default["default"].wrap(Buffer.from(pbPayload));
|
|
650
|
-
|
|
818
|
+
let message;
|
|
819
|
+
try {
|
|
820
|
+
message = decode(Message, rxByteBuffer);
|
|
821
|
+
}
|
|
822
|
+
catch (cause) {
|
|
823
|
+
const legacyProtocolInfo = tryDecodeLegacyProtocolV2ProtocolInfo(messageName, pbPayload);
|
|
824
|
+
if (legacyProtocolInfo) {
|
|
825
|
+
return {
|
|
826
|
+
message: legacyProtocolInfo,
|
|
827
|
+
messageName,
|
|
828
|
+
messageTypeId,
|
|
829
|
+
pbPayload,
|
|
830
|
+
seq,
|
|
831
|
+
type: messageName,
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
const error = new Error(`Protocol V2 protobuf decode failed for "${messageName}" ` +
|
|
835
|
+
`(${messageTypeId}, ${pbPayload.length}-byte payload); ` +
|
|
836
|
+
'the payload is malformed or incompatible with the active SDK schema.');
|
|
837
|
+
error.cause = cause;
|
|
838
|
+
throw error;
|
|
839
|
+
}
|
|
651
840
|
return {
|
|
652
841
|
message,
|
|
653
842
|
messageName,
|
|
@@ -796,14 +985,27 @@ function bytesToHex(bytes) {
|
|
|
796
985
|
.map(b => b.toString(16).padStart(2, '0'))
|
|
797
986
|
.join('');
|
|
798
987
|
}
|
|
799
|
-
const
|
|
988
|
+
const REDUCED_DEBUG_PROTOCOL_V2_CALLS = new Set([
|
|
800
989
|
...LogBlockCommand,
|
|
801
990
|
'FilesystemFileRead',
|
|
802
991
|
'FileRead',
|
|
803
992
|
'EmmcFileRead',
|
|
804
993
|
]);
|
|
805
994
|
function shouldReduceProtocolV2Debug(name) {
|
|
806
|
-
return
|
|
995
|
+
return REDUCED_DEBUG_PROTOCOL_V2_CALLS.has(name);
|
|
996
|
+
}
|
|
997
|
+
const HIGH_THROUGHPUT_PROTOCOL_V2_CALLS = new Set([
|
|
998
|
+
'FilesystemFileWrite',
|
|
999
|
+
'FileWrite',
|
|
1000
|
+
'EmmcFileWrite',
|
|
1001
|
+
'FirmwareUpload',
|
|
1002
|
+
'ResourceAck',
|
|
1003
|
+
'FilesystemFileRead',
|
|
1004
|
+
'FileRead',
|
|
1005
|
+
'EmmcFileRead',
|
|
1006
|
+
]);
|
|
1007
|
+
function isProtocolV2HighThroughputCall(name) {
|
|
1008
|
+
return HIGH_THROUGHPUT_PROTOCOL_V2_CALLS.has(name);
|
|
807
1009
|
}
|
|
808
1010
|
const COMMON_TERMINAL_RESPONSE_TYPES = new Set([
|
|
809
1011
|
'Failure',
|
|
@@ -830,11 +1032,12 @@ function getErrorMessage(error) {
|
|
|
830
1032
|
}
|
|
831
1033
|
return String(error);
|
|
832
1034
|
}
|
|
833
|
-
function withProtocolTimeout(promise, timeoutMs, createTimeoutError, onTimeout) {
|
|
1035
|
+
function withProtocolTimeout(promise, timeoutMs, createTimeoutError, onTimeout, abortSignal) {
|
|
834
1036
|
return __awaiter(this, void 0, void 0, function* () {
|
|
835
1037
|
if (!timeoutMs)
|
|
836
1038
|
return promise;
|
|
837
1039
|
let timer;
|
|
1040
|
+
let abortHandler;
|
|
838
1041
|
try {
|
|
839
1042
|
return yield Promise.race([
|
|
840
1043
|
promise,
|
|
@@ -844,15 +1047,32 @@ function withProtocolTimeout(promise, timeoutMs, createTimeoutError, onTimeout)
|
|
|
844
1047
|
reject(createTimeoutError());
|
|
845
1048
|
}, timeoutMs);
|
|
846
1049
|
}),
|
|
1050
|
+
...(abortSignal
|
|
1051
|
+
? [
|
|
1052
|
+
new Promise((_, reject) => {
|
|
1053
|
+
abortHandler = () => {
|
|
1054
|
+
reject(new Error('Protocol V2 operation aborted'));
|
|
1055
|
+
};
|
|
1056
|
+
if (abortSignal.aborted) {
|
|
1057
|
+
abortHandler();
|
|
1058
|
+
}
|
|
1059
|
+
else {
|
|
1060
|
+
abortSignal.addEventListener('abort', abortHandler, { once: true });
|
|
1061
|
+
}
|
|
1062
|
+
}),
|
|
1063
|
+
]
|
|
1064
|
+
: []),
|
|
847
1065
|
]);
|
|
848
1066
|
}
|
|
849
1067
|
finally {
|
|
850
1068
|
if (timer)
|
|
851
1069
|
clearTimeout(timer);
|
|
1070
|
+
if (abortHandler) {
|
|
1071
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', abortHandler);
|
|
1072
|
+
}
|
|
852
1073
|
}
|
|
853
1074
|
});
|
|
854
1075
|
}
|
|
855
|
-
const PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS = 0;
|
|
856
1076
|
class ProtocolV2Session {
|
|
857
1077
|
constructor(options) {
|
|
858
1078
|
var _a;
|
|
@@ -867,16 +1087,18 @@ class ProtocolV2Session {
|
|
|
867
1087
|
return result;
|
|
868
1088
|
}
|
|
869
1089
|
executeCall(name, data, callOptions) {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
};
|
|
879
|
-
|
|
1090
|
+
const { schemas, router, packetSrc = PROTOCOL_V2_PACKET_SRC_COMMAND, maxFrameBytes, prepareCall, writeFrame, readFrame, logger, logPrefix = 'ProtocolV2', createTimeoutError, generation = 0, } = this.options;
|
|
1091
|
+
const timeoutMs = callOptions.timeoutMs && callOptions.timeoutMs > 0
|
|
1092
|
+
? callOptions.timeoutMs
|
|
1093
|
+
: PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS;
|
|
1094
|
+
const abortController = new AbortController();
|
|
1095
|
+
const shouldReduceDebug = shouldReduceProtocolV2Debug(name);
|
|
1096
|
+
const baseCallContext = Object.assign(Object.assign({ messageName: name, timeoutMs, highThroughput: isProtocolV2HighThroughputCall(name) }, (callOptions.writeWithResponse === undefined
|
|
1097
|
+
? {}
|
|
1098
|
+
: { writeWithResponse: callOptions.writeWithResponse })), { generation, signal: abortController.signal });
|
|
1099
|
+
const runCall = () => __awaiter(this, void 0, void 0, function* () {
|
|
1100
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1101
|
+
yield (prepareCall === null || prepareCall === void 0 ? void 0 : prepareCall(baseCallContext));
|
|
880
1102
|
const protoSeq = this.sequenceCursor.next();
|
|
881
1103
|
const frame = ProtocolV2.encodeFrame(schemas, name, data, {
|
|
882
1104
|
packetSrc,
|
|
@@ -886,40 +1108,79 @@ class ProtocolV2Session {
|
|
|
886
1108
|
if (maxFrameBytes !== undefined && frame.length > maxFrameBytes) {
|
|
887
1109
|
throw new Error(`Protocol V2 frame too large for transport: ${frame.length} > ${maxFrameBytes}`);
|
|
888
1110
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
1111
|
+
const writeStartedAt = Date.now();
|
|
1112
|
+
yield writeFrame(frame, baseCallContext);
|
|
1113
|
+
try {
|
|
1114
|
+
(_a = callOptions.onWriteCompleted) === null || _a === void 0 ? void 0 : _a.call(callOptions, {
|
|
1115
|
+
elapsedMs: Math.max(Date.now() - writeStartedAt, 0),
|
|
1116
|
+
frameBytes: frame.byteLength,
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
catch (error) {
|
|
1120
|
+
(_b = logger === null || logger === void 0 ? void 0 : logger.error) === null || _b === void 0 ? void 0 : _b.call(logger, `${logPrefix} write metrics callback failed: ${String(error)}`);
|
|
1121
|
+
}
|
|
1122
|
+
if (callOptions.returnAfterWrite) {
|
|
1123
|
+
return { type: 'WriteCompleted', message: {} };
|
|
1124
|
+
}
|
|
1125
|
+
while (!abortController.signal.aborted) {
|
|
1126
|
+
const rxFrame = yield readFrame(baseCallContext);
|
|
1127
|
+
if (abortController.signal.aborted)
|
|
1128
|
+
break;
|
|
1129
|
+
let header;
|
|
1130
|
+
try {
|
|
1131
|
+
header = ProtocolV2.inspectFrameHeader(rxFrame);
|
|
1132
|
+
}
|
|
1133
|
+
catch (cause) {
|
|
1134
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 frame validation failed: ${getErrorMessage(cause)}`, cause);
|
|
1135
|
+
}
|
|
1136
|
+
if (header.router !== router) {
|
|
1137
|
+
throw new ProtocolV2LinkError('router', `Protocol V2 router mismatch: expected ${router}, got ${header.router}`);
|
|
1138
|
+
}
|
|
1139
|
+
if (header.packetSrc !== packetSrc) {
|
|
1140
|
+
throw new ProtocolV2LinkError('packet-source', `Protocol V2 packet source mismatch: expected ${packetSrc}, got ${header.packetSrc}`);
|
|
1141
|
+
}
|
|
1142
|
+
let isAck;
|
|
1143
|
+
try {
|
|
1144
|
+
isAck = ProtocolV2.isAckFrame(rxFrame);
|
|
1145
|
+
}
|
|
1146
|
+
catch (cause) {
|
|
1147
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 ACK validation failed: ${getErrorMessage(cause)}`, cause);
|
|
1148
|
+
}
|
|
1149
|
+
if (isAck) {
|
|
1150
|
+
if (header.seq !== protoSeq) {
|
|
1151
|
+
throw new ProtocolV2LinkError('ack-sequence', `Protocol V2 ACK sequence mismatch: expected ${protoSeq}, got ${header.seq}`);
|
|
897
1152
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
1153
|
+
}
|
|
1154
|
+
else {
|
|
1155
|
+
let decoded;
|
|
1156
|
+
try {
|
|
1157
|
+
decoded = ProtocolV2.decodeFrame(schemas, rxFrame);
|
|
1158
|
+
}
|
|
1159
|
+
catch (cause) {
|
|
1160
|
+
throw new ProtocolV2LinkError('frame', `Protocol V2 frame decode failed: ${getErrorMessage(cause)}`, cause);
|
|
1161
|
+
}
|
|
1162
|
+
if (this.lastResponseSequence === decoded.seq) {
|
|
1163
|
+
throw new ProtocolV2LinkError('response-sequence', `Protocol V2 duplicate response sequence: ${decoded.seq}`);
|
|
1164
|
+
}
|
|
1165
|
+
this.lastResponseSequence = decoded.seq;
|
|
1166
|
+
const response = call(decoded);
|
|
1167
|
+
if ((_c = callOptions.intermediateTypes) === null || _c === void 0 ? void 0 : _c.includes(response.type)) {
|
|
1168
|
+
(_d = callOptions.onIntermediateResponse) === null || _d === void 0 ? void 0 : _d.call(callOptions, response);
|
|
1169
|
+
}
|
|
1170
|
+
else if (isExpectedTerminalResponse(response, callOptions.expectedTypes)) {
|
|
1171
|
+
return response;
|
|
1172
|
+
}
|
|
1173
|
+
else if (!shouldReduceDebug) {
|
|
1174
|
+
(_e = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _e === void 0 ? void 0 : _e.call(logger, `[${logPrefix}] skip unexpected response for ${name}: expected=${(_f = callOptions.expectedTypes) === null || _f === void 0 ? void 0 : _f.join('|')} got=${response.type}`);
|
|
911
1175
|
}
|
|
912
1176
|
}
|
|
913
|
-
|
|
914
|
-
});
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
}, () => {
|
|
921
|
-
cancellation.cancelled = true;
|
|
922
|
-
});
|
|
1177
|
+
}
|
|
1178
|
+
throw new Error(`Protocol V2 read loop cancelled after timeout for ${name}`);
|
|
1179
|
+
});
|
|
1180
|
+
return withProtocolTimeout(runCall(), timeoutMs, () => createTimeoutError
|
|
1181
|
+
? createTimeoutError(name, timeoutMs)
|
|
1182
|
+
: new Error(`Protocol V2 response timeout after ${timeoutMs}ms for ${name}`), () => {
|
|
1183
|
+
abortController.abort();
|
|
923
1184
|
});
|
|
924
1185
|
}
|
|
925
1186
|
}
|
|
@@ -929,7 +1190,10 @@ function probeProtocolV2({ call, timeoutMs, logger, logPrefix = 'ProtocolV2', on
|
|
|
929
1190
|
let probeError;
|
|
930
1191
|
try {
|
|
931
1192
|
yield (onBeforeProbe === null || onBeforeProbe === void 0 ? void 0 : onBeforeProbe());
|
|
932
|
-
const response = yield call('Ping', { message: 'protocol-v2-probe' }, {
|
|
1193
|
+
const response = yield call('Ping', { message: 'protocol-v2-probe' }, {
|
|
1194
|
+
timeoutMs,
|
|
1195
|
+
expectedTypes: ['Success'],
|
|
1196
|
+
});
|
|
933
1197
|
if (response.type === 'Success') {
|
|
934
1198
|
return true;
|
|
935
1199
|
}
|
|
@@ -949,12 +1213,19 @@ class ProtocolV2LinkManager {
|
|
|
949
1213
|
this.links = new Map();
|
|
950
1214
|
this.sequences = new Map();
|
|
951
1215
|
this.callQueues = new Map();
|
|
1216
|
+
this.generations = new Map();
|
|
1217
|
+
this.invalidationReasons = new Map();
|
|
1218
|
+
this.invalidations = new Map();
|
|
952
1219
|
this.options = options;
|
|
953
1220
|
}
|
|
954
1221
|
call(key, createAdapter, name, data, options) {
|
|
955
|
-
var _a;
|
|
956
|
-
const
|
|
957
|
-
const
|
|
1222
|
+
var _a, _b;
|
|
1223
|
+
const generation = (_a = this.generations.get(key)) !== null && _a !== void 0 ? _a : 0;
|
|
1224
|
+
const run = () => {
|
|
1225
|
+
this.assertCallGeneration(key, generation);
|
|
1226
|
+
return this.executeCall(key, createAdapter, name, data, options);
|
|
1227
|
+
};
|
|
1228
|
+
const previous = (_b = this.callQueues.get(key)) !== null && _b !== void 0 ? _b : Promise.resolve();
|
|
958
1229
|
const result = previous.then(run, run);
|
|
959
1230
|
const queue = result.catch(() => undefined);
|
|
960
1231
|
this.callQueues.set(key, queue);
|
|
@@ -964,20 +1235,44 @@ class ProtocolV2LinkManager {
|
|
|
964
1235
|
return result;
|
|
965
1236
|
}
|
|
966
1237
|
invalidateLink(key, reason) {
|
|
967
|
-
var _a
|
|
1238
|
+
var _a;
|
|
968
1239
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1240
|
+
const generation = ((_a = this.generations.get(key)) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
1241
|
+
this.generations.set(key, generation);
|
|
1242
|
+
this.invalidationReasons.set(key, { generation, reason });
|
|
1243
|
+
const pendingInvalidation = this.invalidations.get(key);
|
|
969
1244
|
const link = this.links.get(key);
|
|
970
|
-
if (!link)
|
|
1245
|
+
if (!link) {
|
|
1246
|
+
yield pendingInvalidation;
|
|
971
1247
|
return;
|
|
1248
|
+
}
|
|
972
1249
|
this.links.delete(key);
|
|
973
1250
|
link.state.invalidatedReason = reason;
|
|
974
|
-
|
|
975
|
-
|
|
1251
|
+
const invalidation = (() => __awaiter(this, void 0, void 0, function* () {
|
|
1252
|
+
var _b, _c;
|
|
1253
|
+
yield (pendingInvalidation === null || pendingInvalidation === void 0 ? void 0 : pendingInvalidation.catch(() => undefined));
|
|
1254
|
+
yield link.adapter.reset(reason);
|
|
1255
|
+
yield ((_c = (_b = this.options).onLinkInvalidated) === null || _c === void 0 ? void 0 : _c.call(_b, key, reason));
|
|
1256
|
+
}))();
|
|
1257
|
+
this.invalidations.set(key, invalidation);
|
|
1258
|
+
try {
|
|
1259
|
+
yield invalidation;
|
|
1260
|
+
}
|
|
1261
|
+
finally {
|
|
1262
|
+
if (this.invalidations.get(key) === invalidation) {
|
|
1263
|
+
this.invalidations.delete(key);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
976
1266
|
});
|
|
977
1267
|
}
|
|
978
1268
|
invalidateAllLinks(reason) {
|
|
979
1269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
980
|
-
|
|
1270
|
+
const keys = new Set([
|
|
1271
|
+
...this.links.keys(),
|
|
1272
|
+
...this.callQueues.keys(),
|
|
1273
|
+
...this.invalidations.keys(),
|
|
1274
|
+
]);
|
|
1275
|
+
yield Promise.all(Array.from(keys, key => this.invalidateLink(key, reason)));
|
|
981
1276
|
});
|
|
982
1277
|
}
|
|
983
1278
|
dispose(reason) {
|
|
@@ -985,6 +1280,7 @@ class ProtocolV2LinkManager {
|
|
|
985
1280
|
yield this.invalidateAllLinks(reason);
|
|
986
1281
|
this.sequences.clear();
|
|
987
1282
|
this.callQueues.clear();
|
|
1283
|
+
this.invalidations.clear();
|
|
988
1284
|
});
|
|
989
1285
|
}
|
|
990
1286
|
getOrCreateLink(key, createAdapter) {
|
|
@@ -1052,6 +1348,17 @@ class ProtocolV2LinkManager {
|
|
|
1052
1348
|
this.callQueues.delete(key);
|
|
1053
1349
|
}
|
|
1054
1350
|
}
|
|
1351
|
+
assertCallGeneration(key, generation) {
|
|
1352
|
+
var _a;
|
|
1353
|
+
const currentGeneration = (_a = this.generations.get(key)) !== null && _a !== void 0 ? _a : 0;
|
|
1354
|
+
if (currentGeneration === generation)
|
|
1355
|
+
return;
|
|
1356
|
+
const invalidation = this.invalidationReasons.get(key);
|
|
1357
|
+
const reason = (invalidation === null || invalidation === void 0 ? void 0 : invalidation.generation) === currentGeneration
|
|
1358
|
+
? invalidation.reason
|
|
1359
|
+
: 'Protocol V2 link generation changed';
|
|
1360
|
+
throw new ProtocolV2LinkError('generation', reason);
|
|
1361
|
+
}
|
|
1055
1362
|
}
|
|
1056
1363
|
|
|
1057
1364
|
class ProtocolV2UsbTransportBase {
|
|
@@ -1062,7 +1369,7 @@ class ProtocolV2UsbTransportBase {
|
|
|
1062
1369
|
this.protocolV2UsbOptions = options;
|
|
1063
1370
|
this.protocolV2UsbLinks = new ProtocolV2LinkManager({
|
|
1064
1371
|
getSchemas: () => this.getProtocolV2UsbSchemas(),
|
|
1065
|
-
classifyError: ()
|
|
1372
|
+
classifyError: error => (isProtocolV2LinkError(error) ? 'link-fatal' : 'recoverable'),
|
|
1066
1373
|
onLinkInvalidated: (key, reason) => __awaiter(this, void 0, void 0, function* () {
|
|
1067
1374
|
var _a;
|
|
1068
1375
|
(_a = this.protocolV2UsbAssemblers.get(key)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
@@ -1112,10 +1419,10 @@ class ProtocolV2UsbTransportBase {
|
|
|
1112
1419
|
}
|
|
1113
1420
|
const assertCurrentGeneration = () => {
|
|
1114
1421
|
if (cancellation.reason) {
|
|
1115
|
-
throw new
|
|
1422
|
+
throw new ProtocolV2LinkError('generation', cancellation.reason);
|
|
1116
1423
|
}
|
|
1117
1424
|
if (this.protocolV2UsbGenerations.get(key) !== generation) {
|
|
1118
|
-
throw new
|
|
1425
|
+
throw new ProtocolV2LinkError('generation', 'Protocol V2 USB connection generation changed');
|
|
1119
1426
|
}
|
|
1120
1427
|
};
|
|
1121
1428
|
return {
|
|
@@ -1124,11 +1431,15 @@ class ProtocolV2UsbTransportBase {
|
|
|
1124
1431
|
generation,
|
|
1125
1432
|
prepareCall: () => {
|
|
1126
1433
|
assertCurrentGeneration();
|
|
1127
|
-
this.getProtocolV2UsbAssembler(key).reset();
|
|
1128
1434
|
},
|
|
1129
1435
|
writeFrame: (frame, context) => __awaiter(this, void 0, void 0, function* () {
|
|
1130
1436
|
assertCurrentGeneration();
|
|
1131
|
-
|
|
1437
|
+
try {
|
|
1438
|
+
yield this.writeProtocolV2UsbPacket(key, frame, context);
|
|
1439
|
+
}
|
|
1440
|
+
catch (error) {
|
|
1441
|
+
throw this.createProtocolV2UsbIoError('write', error);
|
|
1442
|
+
}
|
|
1132
1443
|
assertCurrentGeneration();
|
|
1133
1444
|
}),
|
|
1134
1445
|
readFrame: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1136,13 +1447,15 @@ class ProtocolV2UsbTransportBase {
|
|
|
1136
1447
|
const assembler = this.getProtocolV2UsbAssembler(key);
|
|
1137
1448
|
let frame = assembler.push(new Uint8Array(0));
|
|
1138
1449
|
while (!frame) {
|
|
1139
|
-
const packetRead = this.readProtocolV2UsbPacket(key, context)
|
|
1140
|
-
packet
|
|
1141
|
-
|
|
1450
|
+
const packetRead = this.readProtocolV2UsbPacket(key, context)
|
|
1451
|
+
.then(packet => ({ packet }))
|
|
1452
|
+
.catch(error => {
|
|
1453
|
+
throw this.createProtocolV2UsbIoError('read', error);
|
|
1454
|
+
});
|
|
1142
1455
|
const cancelled = cancellation.promise.then(reason => ({ reason }));
|
|
1143
1456
|
const result = yield Promise.race([packetRead, cancelled]);
|
|
1144
1457
|
if ('reason' in result) {
|
|
1145
|
-
throw new
|
|
1458
|
+
throw new ProtocolV2LinkError('generation', result.reason);
|
|
1146
1459
|
}
|
|
1147
1460
|
assertCurrentGeneration();
|
|
1148
1461
|
frame = assembler.push(result.packet);
|
|
@@ -1183,8 +1496,17 @@ class ProtocolV2UsbTransportBase {
|
|
|
1183
1496
|
};
|
|
1184
1497
|
return cancellation;
|
|
1185
1498
|
}
|
|
1499
|
+
createProtocolV2UsbIoError(operation, error) {
|
|
1500
|
+
if (isProtocolV2LinkError(error))
|
|
1501
|
+
return error;
|
|
1502
|
+
return new ProtocolV2LinkError('io', `Protocol V2 USB ${operation} failed: ${getErrorMessage(error) || 'unknown error'}`, error);
|
|
1503
|
+
}
|
|
1186
1504
|
}
|
|
1187
1505
|
|
|
1506
|
+
const TRANSPORT_EVENT = {
|
|
1507
|
+
DEVICE_DISCONNECT: 'transport-device-disconnect',
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1188
1510
|
exports.AptosTransactionType = void 0;
|
|
1189
1511
|
(function (AptosTransactionType) {
|
|
1190
1512
|
AptosTransactionType[AptosTransactionType["STANDARD"] = 0] = "STANDARD";
|
|
@@ -1431,6 +1753,24 @@ exports.EthereumDataType = void 0;
|
|
|
1431
1753
|
EthereumDataType[EthereumDataType["ARRAY"] = 7] = "ARRAY";
|
|
1432
1754
|
EthereumDataType[EthereumDataType["STRUCT"] = 8] = "STRUCT";
|
|
1433
1755
|
})(exports.EthereumDataType || (exports.EthereumDataType = {}));
|
|
1756
|
+
exports.Enum_KaspaInputScriptType = void 0;
|
|
1757
|
+
(function (Enum_KaspaInputScriptType) {
|
|
1758
|
+
Enum_KaspaInputScriptType[Enum_KaspaInputScriptType["KASPA_SPEND_P2PK_SCHNORR"] = 0] = "KASPA_SPEND_P2PK_SCHNORR";
|
|
1759
|
+
Enum_KaspaInputScriptType[Enum_KaspaInputScriptType["KASPA_SPEND_P2PK_ECDSA"] = 1] = "KASPA_SPEND_P2PK_ECDSA";
|
|
1760
|
+
})(exports.Enum_KaspaInputScriptType || (exports.Enum_KaspaInputScriptType = {}));
|
|
1761
|
+
exports.Enum_KaspaOutputScriptType = void 0;
|
|
1762
|
+
(function (Enum_KaspaOutputScriptType) {
|
|
1763
|
+
Enum_KaspaOutputScriptType[Enum_KaspaOutputScriptType["KASPA_PAYTOADDRESS"] = 0] = "KASPA_PAYTOADDRESS";
|
|
1764
|
+
Enum_KaspaOutputScriptType[Enum_KaspaOutputScriptType["KASPA_PAYTOCHANGE"] = 1] = "KASPA_PAYTOCHANGE";
|
|
1765
|
+
})(exports.Enum_KaspaOutputScriptType || (exports.Enum_KaspaOutputScriptType = {}));
|
|
1766
|
+
exports.Enum_KaspaRequestType = void 0;
|
|
1767
|
+
(function (Enum_KaspaRequestType) {
|
|
1768
|
+
Enum_KaspaRequestType[Enum_KaspaRequestType["KASPA_TX_INPUT"] = 0] = "KASPA_TX_INPUT";
|
|
1769
|
+
Enum_KaspaRequestType[Enum_KaspaRequestType["KASPA_TX_OUTPUT"] = 1] = "KASPA_TX_OUTPUT";
|
|
1770
|
+
Enum_KaspaRequestType[Enum_KaspaRequestType["KASPA_TX_PAYLOAD"] = 2] = "KASPA_TX_PAYLOAD";
|
|
1771
|
+
Enum_KaspaRequestType[Enum_KaspaRequestType["KASPA_TX_FINISHED"] = 3] = "KASPA_TX_FINISHED";
|
|
1772
|
+
Enum_KaspaRequestType[Enum_KaspaRequestType["KASPA_TX_PREV_META"] = 4] = "KASPA_TX_PREV_META";
|
|
1773
|
+
})(exports.Enum_KaspaRequestType || (exports.Enum_KaspaRequestType = {}));
|
|
1434
1774
|
exports.Enum_BackupType = void 0;
|
|
1435
1775
|
(function (Enum_BackupType) {
|
|
1436
1776
|
Enum_BackupType[Enum_BackupType["Bip39"] = 0] = "Bip39";
|
|
@@ -1624,11 +1964,6 @@ exports.CommandFlags = void 0;
|
|
|
1624
1964
|
CommandFlags[CommandFlags["Default"] = 0] = "Default";
|
|
1625
1965
|
CommandFlags[CommandFlags["Factory_Only"] = 1] = "Factory_Only";
|
|
1626
1966
|
})(exports.CommandFlags || (exports.CommandFlags = {}));
|
|
1627
|
-
exports.WallpaperTarget = void 0;
|
|
1628
|
-
(function (WallpaperTarget) {
|
|
1629
|
-
WallpaperTarget[WallpaperTarget["Home"] = 0] = "Home";
|
|
1630
|
-
WallpaperTarget[WallpaperTarget["Lock"] = 1] = "Lock";
|
|
1631
|
-
})(exports.WallpaperTarget || (exports.WallpaperTarget = {}));
|
|
1632
1967
|
exports.MoneroNetworkType = void 0;
|
|
1633
1968
|
(function (MoneroNetworkType) {
|
|
1634
1969
|
MoneroNetworkType[MoneroNetworkType["MAINNET"] = 0] = "MAINNET";
|
|
@@ -1636,19 +1971,18 @@ exports.MoneroNetworkType = void 0;
|
|
|
1636
1971
|
MoneroNetworkType[MoneroNetworkType["STAGENET"] = 2] = "STAGENET";
|
|
1637
1972
|
MoneroNetworkType[MoneroNetworkType["FAKECHAIN"] = 3] = "FAKECHAIN";
|
|
1638
1973
|
})(exports.MoneroNetworkType || (exports.MoneroNetworkType = {}));
|
|
1639
|
-
exports.
|
|
1640
|
-
(function (
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
})(exports.ViewSignLayout || (exports.ViewSignLayout = {}));
|
|
1974
|
+
exports.UiAnimationType = void 0;
|
|
1975
|
+
(function (UiAnimationType) {
|
|
1976
|
+
UiAnimationType[UiAnimationType["Unknown"] = 0] = "Unknown";
|
|
1977
|
+
UiAnimationType[UiAnimationType["Signing"] = 1] = "Signing";
|
|
1978
|
+
})(exports.UiAnimationType || (exports.UiAnimationType = {}));
|
|
1979
|
+
exports.UiAnimationCommand = void 0;
|
|
1980
|
+
(function (UiAnimationCommand) {
|
|
1981
|
+
UiAnimationCommand[UiAnimationCommand["CommandUnknown"] = 0] = "CommandUnknown";
|
|
1982
|
+
UiAnimationCommand[UiAnimationCommand["Start"] = 1] = "Start";
|
|
1983
|
+
UiAnimationCommand[UiAnimationCommand["Stop"] = 2] = "Stop";
|
|
1984
|
+
UiAnimationCommand[UiAnimationCommand["Refresh"] = 3] = "Refresh";
|
|
1985
|
+
})(exports.UiAnimationCommand || (exports.UiAnimationCommand = {}));
|
|
1652
1986
|
exports.DeviceErrorCode = void 0;
|
|
1653
1987
|
(function (DeviceErrorCode) {
|
|
1654
1988
|
DeviceErrorCode[DeviceErrorCode["DeviceError_None"] = 0] = "DeviceError_None";
|
|
@@ -1675,6 +2009,11 @@ exports.DeviceSettingsPage = void 0;
|
|
|
1675
2009
|
DeviceSettingsPage[DeviceSettingsPage["DevicePassphrase"] = 2] = "DevicePassphrase";
|
|
1676
2010
|
DeviceSettingsPage[DeviceSettingsPage["DeviceAirgap"] = 3] = "DeviceAirgap";
|
|
1677
2011
|
})(exports.DeviceSettingsPage || (exports.DeviceSettingsPage = {}));
|
|
2012
|
+
exports.DeviceFactoryAck = void 0;
|
|
2013
|
+
(function (DeviceFactoryAck) {
|
|
2014
|
+
DeviceFactoryAck[DeviceFactoryAck["FACTORY_ACK_SUCCESS"] = 0] = "FACTORY_ACK_SUCCESS";
|
|
2015
|
+
DeviceFactoryAck[DeviceFactoryAck["FACTORY_ACK_FAIL"] = 1] = "FACTORY_ACK_FAIL";
|
|
2016
|
+
})(exports.DeviceFactoryAck || (exports.DeviceFactoryAck = {}));
|
|
1678
2017
|
exports.DeviceFirmwareTargetType = void 0;
|
|
1679
2018
|
(function (DeviceFirmwareTargetType) {
|
|
1680
2019
|
DeviceFirmwareTargetType[DeviceFirmwareTargetType["FW_MGMT_TARGET_INVALID"] = 0] = "FW_MGMT_TARGET_INVALID";
|
|
@@ -1703,11 +2042,6 @@ exports.DeviceFirmwareUpdateTaskStatus = void 0;
|
|
|
1703
2042
|
DeviceFirmwareUpdateTaskStatus[DeviceFirmwareUpdateTaskStatus["FW_MGMT_UPDATER_TASK_STATUS_FAILED_BUSY"] = 9] = "FW_MGMT_UPDATER_TASK_STATUS_FAILED_BUSY";
|
|
1704
2043
|
DeviceFirmwareUpdateTaskStatus[DeviceFirmwareUpdateTaskStatus["FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS"] = 10] = "FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS";
|
|
1705
2044
|
})(exports.DeviceFirmwareUpdateTaskStatus || (exports.DeviceFirmwareUpdateTaskStatus = {}));
|
|
1706
|
-
exports.DeviceFactoryAck = void 0;
|
|
1707
|
-
(function (DeviceFactoryAck) {
|
|
1708
|
-
DeviceFactoryAck[DeviceFactoryAck["FACTORY_ACK_SUCCESS"] = 0] = "FACTORY_ACK_SUCCESS";
|
|
1709
|
-
DeviceFactoryAck[DeviceFactoryAck["FACTORY_ACK_FAIL"] = 1] = "FACTORY_ACK_FAIL";
|
|
1710
|
-
})(exports.DeviceFactoryAck || (exports.DeviceFactoryAck = {}));
|
|
1711
2045
|
exports.DeviceType = void 0;
|
|
1712
2046
|
(function (DeviceType) {
|
|
1713
2047
|
DeviceType[DeviceType["CLASSIC1"] = 0] = "CLASSIC1";
|
|
@@ -1730,22 +2064,116 @@ exports.DeviceSEState = void 0;
|
|
|
1730
2064
|
DeviceSEState[DeviceSEState["APP_FACTORY"] = 51] = "APP_FACTORY";
|
|
1731
2065
|
DeviceSEState[DeviceSEState["APP"] = 85] = "APP";
|
|
1732
2066
|
})(exports.DeviceSEState || (exports.DeviceSEState = {}));
|
|
1733
|
-
exports.
|
|
1734
|
-
(function (
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
2067
|
+
exports.DeviceSessionErrorCode = void 0;
|
|
2068
|
+
(function (DeviceSessionErrorCode) {
|
|
2069
|
+
DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_None"] = 0] = "DeviceSessionError_None";
|
|
2070
|
+
DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_UserCancelled"] = 1] = "DeviceSessionError_UserCancelled";
|
|
2071
|
+
DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_InvalidSession"] = 2] = "DeviceSessionError_InvalidSession";
|
|
2072
|
+
DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_AttachPinUnavailable"] = 3] = "DeviceSessionError_AttachPinUnavailable";
|
|
2073
|
+
DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_PassphraseDisabled"] = 4] = "DeviceSessionError_PassphraseDisabled";
|
|
2074
|
+
DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_Busy"] = 5] = "DeviceSessionError_Busy";
|
|
2075
|
+
})(exports.DeviceSessionErrorCode || (exports.DeviceSessionErrorCode = {}));
|
|
2076
|
+
exports.DeviceSessionSeedDomain = void 0;
|
|
2077
|
+
(function (DeviceSessionSeedDomain) {
|
|
2078
|
+
DeviceSessionSeedDomain[DeviceSessionSeedDomain["SeedDomain_Standard"] = 1] = "SeedDomain_Standard";
|
|
2079
|
+
DeviceSessionSeedDomain[DeviceSessionSeedDomain["SeedDomain_Cardano"] = 2] = "SeedDomain_Cardano";
|
|
2080
|
+
})(exports.DeviceSessionSeedDomain || (exports.DeviceSessionSeedDomain = {}));
|
|
2081
|
+
exports.DeviceSessionPinType = void 0;
|
|
2082
|
+
(function (DeviceSessionPinType) {
|
|
2083
|
+
DeviceSessionPinType[DeviceSessionPinType["Any"] = 1] = "Any";
|
|
2084
|
+
DeviceSessionPinType[DeviceSessionPinType["Main"] = 2] = "Main";
|
|
2085
|
+
DeviceSessionPinType[DeviceSessionPinType["AttachToPin"] = 3] = "AttachToPin";
|
|
2086
|
+
})(exports.DeviceSessionPinType || (exports.DeviceSessionPinType = {}));
|
|
2087
|
+
exports.DeviceSessionAskPin_FailureSubCodes = void 0;
|
|
2088
|
+
(function (DeviceSessionAskPin_FailureSubCodes) {
|
|
2089
|
+
DeviceSessionAskPin_FailureSubCodes[DeviceSessionAskPin_FailureSubCodes["UserCancel"] = 1] = "UserCancel";
|
|
2090
|
+
})(exports.DeviceSessionAskPin_FailureSubCodes || (exports.DeviceSessionAskPin_FailureSubCodes = {}));
|
|
2091
|
+
exports.OnboardingStep = void 0;
|
|
2092
|
+
(function (OnboardingStep) {
|
|
2093
|
+
OnboardingStep[OnboardingStep["ONBOARDING_STEP_UNKNOWN"] = 0] = "ONBOARDING_STEP_UNKNOWN";
|
|
2094
|
+
OnboardingStep[OnboardingStep["ONBOARDING_STEP_CHECKING"] = 1] = "ONBOARDING_STEP_CHECKING";
|
|
2095
|
+
OnboardingStep[OnboardingStep["ONBOARDING_STEP_PERSONALIZATION"] = 2] = "ONBOARDING_STEP_PERSONALIZATION";
|
|
2096
|
+
OnboardingStep[OnboardingStep["ONBOARDING_STEP_PIN"] = 3] = "ONBOARDING_STEP_PIN";
|
|
2097
|
+
OnboardingStep[OnboardingStep["ONBOARDING_STEP_SETUP"] = 4] = "ONBOARDING_STEP_SETUP";
|
|
2098
|
+
OnboardingStep[OnboardingStep["ONBOARDING_STEP_DONE"] = 5] = "ONBOARDING_STEP_DONE";
|
|
2099
|
+
})(exports.OnboardingStep || (exports.OnboardingStep = {}));
|
|
2100
|
+
exports.OnboardingPhase = void 0;
|
|
2101
|
+
(function (OnboardingPhase) {
|
|
2102
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_UNKNOWN"] = 0] = "ONBOARDING_PHASE_UNKNOWN";
|
|
2103
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_SAFETY_CHECK"] = 1] = "ONBOARDING_PHASE_SAFETY_CHECK";
|
|
2104
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_PIN_SETUP"] = 2] = "ONBOARDING_PHASE_PIN_SETUP";
|
|
2105
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_FINGERPRINT_SETUP"] = 3] = "ONBOARDING_PHASE_FINGERPRINT_SETUP";
|
|
2106
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_SETUP_CHOICE"] = 4] = "ONBOARDING_PHASE_SETUP_CHOICE";
|
|
2107
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_WALLET_CREATE_START"] = 5] = "ONBOARDING_PHASE_WALLET_CREATE_START";
|
|
2108
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_RECOVERY_PHRASE_VIEW"] = 6] = "ONBOARDING_PHASE_RECOVERY_PHRASE_VIEW";
|
|
2109
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_RECOVERY_PHRASE_CONFIRM"] = 7] = "ONBOARDING_PHASE_RECOVERY_PHRASE_CONFIRM";
|
|
2110
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_RESTORE_METHOD_CHOICE"] = 8] = "ONBOARDING_PHASE_RESTORE_METHOD_CHOICE";
|
|
2111
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_RECOVERY_PHRASE_RESTORE"] = 9] = "ONBOARDING_PHASE_RECOVERY_PHRASE_RESTORE";
|
|
2112
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_SEEDCARD_RESTORE"] = 10] = "ONBOARDING_PHASE_SEEDCARD_RESTORE";
|
|
2113
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_WALLET_READY"] = 11] = "ONBOARDING_PHASE_WALLET_READY";
|
|
2114
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_SEEDCARD_BACKUP_PROMPT"] = 12] = "ONBOARDING_PHASE_SEEDCARD_BACKUP_PROMPT";
|
|
2115
|
+
OnboardingPhase[OnboardingPhase["ONBOARDING_PHASE_SEEDCARD_BACKUP"] = 13] = "ONBOARDING_PHASE_SEEDCARD_BACKUP";
|
|
2116
|
+
})(exports.OnboardingPhase || (exports.OnboardingPhase = {}));
|
|
2117
|
+
exports.OnboardingSetupKind = void 0;
|
|
2118
|
+
(function (OnboardingSetupKind) {
|
|
2119
|
+
OnboardingSetupKind[OnboardingSetupKind["ONBOARDING_SETUP_KIND_UNKNOWN"] = 0] = "ONBOARDING_SETUP_KIND_UNKNOWN";
|
|
2120
|
+
OnboardingSetupKind[OnboardingSetupKind["ONBOARDING_SETUP_KIND_CHOICE"] = 1] = "ONBOARDING_SETUP_KIND_CHOICE";
|
|
2121
|
+
OnboardingSetupKind[OnboardingSetupKind["ONBOARDING_SETUP_KIND_CREATE"] = 2] = "ONBOARDING_SETUP_KIND_CREATE";
|
|
2122
|
+
OnboardingSetupKind[OnboardingSetupKind["ONBOARDING_SETUP_KIND_RESTORE"] = 3] = "ONBOARDING_SETUP_KIND_RESTORE";
|
|
2123
|
+
})(exports.OnboardingSetupKind || (exports.OnboardingSetupKind = {}));
|
|
2124
|
+
exports.OnboardingSetupMethod = void 0;
|
|
2125
|
+
(function (OnboardingSetupMethod) {
|
|
2126
|
+
OnboardingSetupMethod[OnboardingSetupMethod["ONBOARDING_SETUP_METHOD_UNKNOWN"] = 0] = "ONBOARDING_SETUP_METHOD_UNKNOWN";
|
|
2127
|
+
OnboardingSetupMethod[OnboardingSetupMethod["ONBOARDING_SETUP_METHOD_RECOVERY_PHRASE"] = 1] = "ONBOARDING_SETUP_METHOD_RECOVERY_PHRASE";
|
|
2128
|
+
OnboardingSetupMethod[OnboardingSetupMethod["ONBOARDING_SETUP_METHOD_SEEDCARD"] = 2] = "ONBOARDING_SETUP_METHOD_SEEDCARD";
|
|
2129
|
+
})(exports.OnboardingSetupMethod || (exports.OnboardingSetupMethod = {}));
|
|
2130
|
+
exports.ViewTipType = void 0;
|
|
2131
|
+
(function (ViewTipType) {
|
|
2132
|
+
ViewTipType[ViewTipType["Default"] = 0] = "Default";
|
|
2133
|
+
ViewTipType[ViewTipType["Highlight"] = 1] = "Highlight";
|
|
2134
|
+
ViewTipType[ViewTipType["Recommend"] = 2] = "Recommend";
|
|
2135
|
+
ViewTipType[ViewTipType["Warning"] = 3] = "Warning";
|
|
2136
|
+
ViewTipType[ViewTipType["Danger"] = 4] = "Danger";
|
|
2137
|
+
})(exports.ViewTipType || (exports.ViewTipType = {}));
|
|
2138
|
+
exports.ViewSignLayout = void 0;
|
|
2139
|
+
(function (ViewSignLayout) {
|
|
2140
|
+
ViewSignLayout[ViewSignLayout["LayoutDefault"] = 0] = "LayoutDefault";
|
|
2141
|
+
ViewSignLayout[ViewSignLayout["LayoutSafeTxCreate"] = 1] = "LayoutSafeTxCreate";
|
|
2142
|
+
ViewSignLayout[ViewSignLayout["LayoutFinalConfirm"] = 2] = "LayoutFinalConfirm";
|
|
2143
|
+
ViewSignLayout[ViewSignLayout["Layout7702"] = 3] = "Layout7702";
|
|
2144
|
+
ViewSignLayout[ViewSignLayout["LayoutFlat"] = 4] = "LayoutFlat";
|
|
2145
|
+
ViewSignLayout[ViewSignLayout["LayoutEthApprove"] = 5] = "LayoutEthApprove";
|
|
2146
|
+
})(exports.ViewSignLayout || (exports.ViewSignLayout = {}));
|
|
2147
|
+
exports.ProtocolV2FailureType = void 0;
|
|
2148
|
+
(function (ProtocolV2FailureType) {
|
|
2149
|
+
ProtocolV2FailureType[ProtocolV2FailureType["Failure_InvalidMessage"] = 1] = "Failure_InvalidMessage";
|
|
2150
|
+
ProtocolV2FailureType[ProtocolV2FailureType["Failure_UndefinedError"] = 2] = "Failure_UndefinedError";
|
|
2151
|
+
ProtocolV2FailureType[ProtocolV2FailureType["Failure_UsageError"] = 3] = "Failure_UsageError";
|
|
2152
|
+
ProtocolV2FailureType[ProtocolV2FailureType["Failure_DataError"] = 4] = "Failure_DataError";
|
|
2153
|
+
ProtocolV2FailureType[ProtocolV2FailureType["Failure_ProcessError"] = 5] = "Failure_ProcessError";
|
|
2154
|
+
})(exports.ProtocolV2FailureType || (exports.ProtocolV2FailureType = {}));
|
|
2155
|
+
exports.Enum_ProtocolV2Capability = void 0;
|
|
2156
|
+
(function (Enum_ProtocolV2Capability) {
|
|
2157
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Bitcoin"] = 1] = "Capability_Bitcoin";
|
|
2158
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Bitcoin_like"] = 2] = "Capability_Bitcoin_like";
|
|
2159
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Binance"] = 3] = "Capability_Binance";
|
|
2160
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Cardano"] = 4] = "Capability_Cardano";
|
|
2161
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Crypto"] = 5] = "Capability_Crypto";
|
|
2162
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_EOS"] = 6] = "Capability_EOS";
|
|
2163
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Ethereum"] = 7] = "Capability_Ethereum";
|
|
2164
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Lisk"] = 8] = "Capability_Lisk";
|
|
2165
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Monero"] = 9] = "Capability_Monero";
|
|
2166
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_NEM"] = 10] = "Capability_NEM";
|
|
2167
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Ripple"] = 11] = "Capability_Ripple";
|
|
2168
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Stellar"] = 12] = "Capability_Stellar";
|
|
2169
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Tezos"] = 13] = "Capability_Tezos";
|
|
2170
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_U2F"] = 14] = "Capability_U2F";
|
|
2171
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_Shamir"] = 15] = "Capability_Shamir";
|
|
2172
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_ShamirGroups"] = 16] = "Capability_ShamirGroups";
|
|
2173
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_PassphraseEntry"] = 17] = "Capability_PassphraseEntry";
|
|
2174
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_AttachToPin"] = 18] = "Capability_AttachToPin";
|
|
2175
|
+
Enum_ProtocolV2Capability[Enum_ProtocolV2Capability["Capability_EthereumTypedData"] = 1000] = "Capability_EthereumTypedData";
|
|
2176
|
+
})(exports.Enum_ProtocolV2Capability || (exports.Enum_ProtocolV2Capability = {}));
|
|
1749
2177
|
|
|
1750
2178
|
var messages = /*#__PURE__*/Object.freeze({
|
|
1751
2179
|
__proto__: null,
|
|
@@ -1778,6 +2206,9 @@ var messages = /*#__PURE__*/Object.freeze({
|
|
|
1778
2206
|
get EthereumGnosisSafeTxOperation () { return exports.EthereumGnosisSafeTxOperation; },
|
|
1779
2207
|
get EthereumDataTypeOneKey () { return exports.EthereumDataTypeOneKey; },
|
|
1780
2208
|
get EthereumDataType () { return exports.EthereumDataType; },
|
|
2209
|
+
get Enum_KaspaInputScriptType () { return exports.Enum_KaspaInputScriptType; },
|
|
2210
|
+
get Enum_KaspaOutputScriptType () { return exports.Enum_KaspaOutputScriptType; },
|
|
2211
|
+
get Enum_KaspaRequestType () { return exports.Enum_KaspaRequestType; },
|
|
1781
2212
|
get Enum_BackupType () { return exports.Enum_BackupType; },
|
|
1782
2213
|
get Enum_SafetyCheckLevel () { return exports.Enum_SafetyCheckLevel; },
|
|
1783
2214
|
get OneKeyDeviceType () { return exports.OneKeyDeviceType; },
|
|
@@ -1809,22 +2240,114 @@ var messages = /*#__PURE__*/Object.freeze({
|
|
|
1809
2240
|
get TronResourceCode () { return exports.TronResourceCode; },
|
|
1810
2241
|
get TronMessageType () { return exports.TronMessageType; },
|
|
1811
2242
|
get CommandFlags () { return exports.CommandFlags; },
|
|
1812
|
-
get WallpaperTarget () { return exports.WallpaperTarget; },
|
|
1813
2243
|
get MoneroNetworkType () { return exports.MoneroNetworkType; },
|
|
1814
|
-
get
|
|
1815
|
-
get
|
|
2244
|
+
get UiAnimationType () { return exports.UiAnimationType; },
|
|
2245
|
+
get UiAnimationCommand () { return exports.UiAnimationCommand; },
|
|
1816
2246
|
get DeviceErrorCode () { return exports.DeviceErrorCode; },
|
|
1817
2247
|
get DeviceRebootType () { return exports.DeviceRebootType; },
|
|
1818
2248
|
get DeviceSettingsPage () { return exports.DeviceSettingsPage; },
|
|
2249
|
+
get DeviceFactoryAck () { return exports.DeviceFactoryAck; },
|
|
1819
2250
|
get DeviceFirmwareTargetType () { return exports.DeviceFirmwareTargetType; },
|
|
1820
2251
|
get DeviceFirmwareUpdateTaskStatus () { return exports.DeviceFirmwareUpdateTaskStatus; },
|
|
1821
|
-
get DeviceFactoryAck () { return exports.DeviceFactoryAck; },
|
|
1822
2252
|
get DeviceType () { return exports.DeviceType; },
|
|
1823
2253
|
get DeviceSeType () { return exports.DeviceSeType; },
|
|
1824
2254
|
get DeviceSEState () { return exports.DeviceSEState; },
|
|
1825
|
-
get
|
|
2255
|
+
get DeviceSessionErrorCode () { return exports.DeviceSessionErrorCode; },
|
|
2256
|
+
get DeviceSessionSeedDomain () { return exports.DeviceSessionSeedDomain; },
|
|
2257
|
+
get DeviceSessionPinType () { return exports.DeviceSessionPinType; },
|
|
2258
|
+
get DeviceSessionAskPin_FailureSubCodes () { return exports.DeviceSessionAskPin_FailureSubCodes; },
|
|
2259
|
+
get OnboardingStep () { return exports.OnboardingStep; },
|
|
2260
|
+
get OnboardingPhase () { return exports.OnboardingPhase; },
|
|
2261
|
+
get OnboardingSetupKind () { return exports.OnboardingSetupKind; },
|
|
2262
|
+
get OnboardingSetupMethod () { return exports.OnboardingSetupMethod; },
|
|
2263
|
+
get ViewTipType () { return exports.ViewTipType; },
|
|
2264
|
+
get ViewSignLayout () { return exports.ViewSignLayout; },
|
|
2265
|
+
get ProtocolV2FailureType () { return exports.ProtocolV2FailureType; },
|
|
2266
|
+
get Enum_ProtocolV2Capability () { return exports.Enum_ProtocolV2Capability; }
|
|
1826
2267
|
});
|
|
1827
2268
|
|
|
2269
|
+
const REDACTED = '[REDACTED]';
|
|
2270
|
+
const SENSITIVE_LOG_KEYS = new Set([
|
|
2271
|
+
'accesstoken',
|
|
2272
|
+
'address',
|
|
2273
|
+
'apikey',
|
|
2274
|
+
'connectid',
|
|
2275
|
+
'devicestate',
|
|
2276
|
+
'deviceid',
|
|
2277
|
+
'entropy',
|
|
2278
|
+
'expectedpassphrasestate',
|
|
2279
|
+
'mnemonic',
|
|
2280
|
+
'passphrase',
|
|
2281
|
+
'passphrasestate',
|
|
2282
|
+
'password',
|
|
2283
|
+
'pin',
|
|
2284
|
+
'privatekey',
|
|
2285
|
+
'publickey',
|
|
2286
|
+
'seed',
|
|
2287
|
+
'serialnumber',
|
|
2288
|
+
'session',
|
|
2289
|
+
'sessionid',
|
|
2290
|
+
'signature',
|
|
2291
|
+
'token',
|
|
2292
|
+
'uuid',
|
|
2293
|
+
'walletsessionid',
|
|
2294
|
+
'xprv',
|
|
2295
|
+
'xpub',
|
|
2296
|
+
]);
|
|
2297
|
+
const normalizeLogKey = (key) => key.replace(/[_-]/g, '').toLowerCase();
|
|
2298
|
+
const isSensitiveLogKey = (key) => {
|
|
2299
|
+
const normalizedKey = normalizeLogKey(key);
|
|
2300
|
+
return (SENSITIVE_LOG_KEYS.has(normalizedKey) ||
|
|
2301
|
+
normalizedKey.endsWith('address') ||
|
|
2302
|
+
normalizedKey.endsWith('privatekey') ||
|
|
2303
|
+
normalizedKey.endsWith('publickey') ||
|
|
2304
|
+
normalizedKey.endsWith('signature'));
|
|
2305
|
+
};
|
|
2306
|
+
const isSigningMessage = (messageName) => Boolean(messageName && /(?:sign|txack|transaction)/i.test(messageName));
|
|
2307
|
+
const redactLogValue = (value, seen) => {
|
|
2308
|
+
if (ArrayBuffer.isView(value)) {
|
|
2309
|
+
return `[BINARY:${value.byteLength}]`;
|
|
2310
|
+
}
|
|
2311
|
+
if (value instanceof ArrayBuffer) {
|
|
2312
|
+
return `[BINARY:${value.byteLength}]`;
|
|
2313
|
+
}
|
|
2314
|
+
if (Array.isArray(value)) {
|
|
2315
|
+
return value.map(item => redactLogValue(item, seen));
|
|
2316
|
+
}
|
|
2317
|
+
if (!value || typeof value !== 'object') {
|
|
2318
|
+
return value;
|
|
2319
|
+
}
|
|
2320
|
+
if (seen.has(value)) {
|
|
2321
|
+
return '[CIRCULAR]';
|
|
2322
|
+
}
|
|
2323
|
+
seen.add(value);
|
|
2324
|
+
const redacted = Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
2325
|
+
key,
|
|
2326
|
+
isSensitiveLogKey(key) && item !== null && item !== undefined
|
|
2327
|
+
? REDACTED
|
|
2328
|
+
: redactLogValue(item, seen),
|
|
2329
|
+
]));
|
|
2330
|
+
seen.delete(value);
|
|
2331
|
+
return redacted;
|
|
2332
|
+
};
|
|
2333
|
+
function getSafeTransportLogPayload(value, messageName) {
|
|
2334
|
+
if (isSigningMessage(messageName)) {
|
|
2335
|
+
return REDACTED;
|
|
2336
|
+
}
|
|
2337
|
+
return redactLogValue(value, new WeakSet());
|
|
2338
|
+
}
|
|
2339
|
+
function createTransportCallLog(name, protocol, data) {
|
|
2340
|
+
return {
|
|
2341
|
+
name,
|
|
2342
|
+
protocol,
|
|
2343
|
+
request: getSafeTransportLogPayload(data, name),
|
|
2344
|
+
};
|
|
2345
|
+
}
|
|
2346
|
+
const HIGH_VOLUME_CALLS = new Set(['FileWrite', 'FilesystemFileWrite', 'EmmcFileWrite']);
|
|
2347
|
+
function shouldSuppressHighVolumeCallLog(name) {
|
|
2348
|
+
return HIGH_VOLUME_CALLS.has(name);
|
|
2349
|
+
}
|
|
2350
|
+
|
|
1828
2351
|
protobuf__namespace.util.Long = Long__default["default"];
|
|
1829
2352
|
protobuf__namespace.configure();
|
|
1830
2353
|
var index = {
|
|
@@ -1861,29 +2384,38 @@ exports.PROTOCOL_V1_REPORT_ID = PROTOCOL_V1_REPORT_ID;
|
|
|
1861
2384
|
exports.PROTOCOL_V1_USB_PACKET_SIZE = PROTOCOL_V1_USB_PACKET_SIZE;
|
|
1862
2385
|
exports.PROTOCOL_V2_BLE_FILE_CHUNK_SIZE = PROTOCOL_V2_BLE_FILE_CHUNK_SIZE;
|
|
1863
2386
|
exports.PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE = PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE;
|
|
2387
|
+
exports.PROTOCOL_V2_BLE_FIRMWARE_FILE_CHUNK_SIZE = PROTOCOL_V2_BLE_FIRMWARE_FILE_CHUNK_SIZE;
|
|
1864
2388
|
exports.PROTOCOL_V2_BLE_FRAME_MAX_BYTES = PROTOCOL_V2_BLE_FRAME_MAX_BYTES;
|
|
1865
2389
|
exports.PROTOCOL_V2_CHANNEL_BLE_UART = PROTOCOL_V2_CHANNEL_BLE_UART;
|
|
1866
2390
|
exports.PROTOCOL_V2_CHANNEL_SOCKET = PROTOCOL_V2_CHANNEL_SOCKET;
|
|
1867
2391
|
exports.PROTOCOL_V2_CHANNEL_USB = PROTOCOL_V2_CHANNEL_USB;
|
|
2392
|
+
exports.PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS = PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS;
|
|
1868
2393
|
exports.PROTOCOL_V2_FILE_CHUNK_SIZE = PROTOCOL_V2_FILE_CHUNK_SIZE;
|
|
1869
2394
|
exports.PROTOCOL_V2_FRAME_MAX_BYTES = PROTOCOL_V2_FRAME_MAX_BYTES;
|
|
1870
2395
|
exports.PROTOCOL_V2_PACKET_SRC_COMMAND = PROTOCOL_V2_PACKET_SRC_COMMAND;
|
|
1871
2396
|
exports.PROTOCOL_V2_SYS_MESSAGE_THRESHOLD = PROTOCOL_V2_SYS_MESSAGE_THRESHOLD;
|
|
1872
2397
|
exports.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE = PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
1873
|
-
exports.PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS = PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS;
|
|
1874
2398
|
exports.ProtocolV1 = ProtocolV1;
|
|
1875
2399
|
exports.ProtocolV2 = ProtocolV2;
|
|
1876
2400
|
exports.ProtocolV2FrameAssembler = ProtocolV2FrameAssembler;
|
|
2401
|
+
exports.ProtocolV2LinkError = ProtocolV2LinkError;
|
|
1877
2402
|
exports.ProtocolV2LinkManager = ProtocolV2LinkManager;
|
|
1878
2403
|
exports.ProtocolV2SequenceCursor = ProtocolV2SequenceCursor;
|
|
1879
2404
|
exports.ProtocolV2Session = ProtocolV2Session;
|
|
1880
2405
|
exports.ProtocolV2UsbTransportBase = ProtocolV2UsbTransportBase;
|
|
2406
|
+
exports.TRANSPORT_EVENT = TRANSPORT_EVENT;
|
|
1881
2407
|
exports.bytesToHex = bytesToHex;
|
|
1882
2408
|
exports.concatUint8Arrays = concatUint8Arrays;
|
|
2409
|
+
exports.createTransportCallLog = createTransportCallLog;
|
|
1883
2410
|
exports["default"] = index;
|
|
1884
2411
|
exports.getErrorMessage = getErrorMessage;
|
|
2412
|
+
exports.getSafeTransportLogPayload = getSafeTransportLogPayload;
|
|
1885
2413
|
exports.hexToBytes = hexToBytes;
|
|
2414
|
+
exports.isProtocolV2HighThroughputCall = isProtocolV2HighThroughputCall;
|
|
2415
|
+
exports.isProtocolV2LinkError = isProtocolV2LinkError;
|
|
1886
2416
|
exports.probeProtocolV2 = probeProtocolV2;
|
|
1887
2417
|
exports.protocolV1 = index$1;
|
|
1888
2418
|
exports.protocolV2 = protocolV2Codec;
|
|
2419
|
+
exports.shouldSuppressHighVolumeCallLog = shouldSuppressHighVolumeCallLog;
|
|
1889
2420
|
exports.withProtocolTimeout = withProtocolTimeout;
|
|
2421
|
+
exports.writeProtocolV2BleFrame = writeProtocolV2BleFrame;
|