@onekeyfe/hd-transport 1.2.0-alpha.20 → 1.2.0-alpha.22

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 (35) hide show
  1. package/__tests__/messages.test.js +32 -7
  2. package/__tests__/protocol-v2-link-manager.test.js +27 -34
  3. package/__tests__/protocol-v2.test.js +242 -56
  4. package/dist/constants.d.ts +1 -0
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/index.d.ts +101 -19
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +166 -106
  9. package/dist/protocols/index.d.ts +5 -2
  10. package/dist/protocols/index.d.ts.map +1 -1
  11. package/dist/protocols/v2/decode.d.ts +11 -1
  12. package/dist/protocols/v2/decode.d.ts.map +1 -1
  13. package/dist/protocols/v2/errors.d.ts +8 -0
  14. package/dist/protocols/v2/errors.d.ts.map +1 -0
  15. package/dist/protocols/v2/frame-assembler.d.ts.map +1 -1
  16. package/dist/protocols/v2/index.d.ts +1 -0
  17. package/dist/protocols/v2/index.d.ts.map +1 -1
  18. package/dist/protocols/v2/link-manager.d.ts +0 -1
  19. package/dist/protocols/v2/link-manager.d.ts.map +1 -1
  20. package/dist/protocols/v2/session.d.ts +4 -5
  21. package/dist/protocols/v2/session.d.ts.map +1 -1
  22. package/dist/types/messages.d.ts +34 -5
  23. package/dist/types/messages.d.ts.map +1 -1
  24. package/messages-protocol-v2.json +77 -4
  25. package/package.json +2 -2
  26. package/scripts/protobuf-types.js +7 -1
  27. package/src/constants.ts +8 -0
  28. package/src/protocols/index.ts +18 -4
  29. package/src/protocols/v2/decode.ts +49 -19
  30. package/src/protocols/v2/errors.ts +23 -0
  31. package/src/protocols/v2/frame-assembler.ts +6 -4
  32. package/src/protocols/v2/index.ts +1 -0
  33. package/src/protocols/v2/link-manager.ts +0 -2
  34. package/src/protocols/v2/session.ts +124 -122
  35. package/src/types/messages.ts +46 -6
package/dist/index.js CHANGED
@@ -277,6 +277,7 @@ const PROTOCOL_V2_CHANNEL_USB = 0;
277
277
  const PROTOCOL_V2_CHANNEL_BLE_UART = 1;
278
278
  const PROTOCOL_V2_CHANNEL_SOCKET = 2;
279
279
  const PROTOCOL_V2_PACKET_SRC_COMMAND = 0;
280
+ const PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS = 5 * 60 * 1000;
280
281
 
281
282
  function encodeEnvelope(data, options) {
282
283
  const { addTrezorHeaders, chunked, messageTypeId } = options;
@@ -450,7 +451,7 @@ function encodeProtobufFrame(messageTypeId, pbPayload, packetSrc, router, seq) {
450
451
  return encodeFrame(payload, packetSrc, router, seq);
451
452
  }
452
453
 
453
- function validateFrame(data) {
454
+ function inspectFrameHeader(data) {
454
455
  if (data.length < PROTO_HEAD_CRC_SIZE) {
455
456
  throw new Error(`Protocol V2 frame too short: ${data.length} bytes`);
456
457
  }
@@ -458,8 +459,8 @@ function validateFrame(data) {
458
459
  throw new Error(`Invalid SOF byte: expected 0x5A, got 0x${data[0].toString(16).padStart(2, '0')}`);
459
460
  }
460
461
  const frameLen = data[1] + data[2] * 256;
461
- if (data.length < frameLen) {
462
- throw new Error(`Frame truncated: expected ${frameLen} bytes, got ${data.length}`);
462
+ if (data.length !== frameLen) {
463
+ throw new Error(`Protocol V2 frame length mismatch: expected ${frameLen} bytes, got ${data.length}`);
463
464
  }
464
465
  const expectedHeaderCrc = crc8(data, 3);
465
466
  if (data[3] !== expectedHeaderCrc) {
@@ -473,35 +474,53 @@ function validateFrame(data) {
473
474
  .toString(16)
474
475
  .padStart(2, '0')}, got 0x${data[frameLen - 1].toString(16).padStart(2, '0')}`);
475
476
  }
476
- return frameLen;
477
+ const dataType = data[5] & 0x03;
478
+ const packetSrc = (data[5] >> 2) & 0x0f;
479
+ const seq = data[6];
480
+ if (seq === 0) {
481
+ throw new Error('Invalid Protocol V2 sequence: 0 is reserved');
482
+ }
483
+ return {
484
+ frameLen,
485
+ router: data[4],
486
+ packetSrc,
487
+ dataType,
488
+ seq,
489
+ };
477
490
  }
478
491
  function isAckFrame(data) {
479
492
  if (data.length < 6 || (data[5] & 0x03) !== PROTO_DATA_TYPE_ACK) {
480
493
  return false;
481
494
  }
482
- const frameLen = validateFrame(data);
483
- if (frameLen !== PROTO_HEAD_CRC_SIZE) {
484
- throw new Error(`Invalid Protocol V2 ACK frame length: ${frameLen}`);
495
+ const header = inspectFrameHeader(data);
496
+ if (header.frameLen !== PROTO_HEAD_CRC_SIZE) {
497
+ throw new Error(`Invalid Protocol V2 ACK frame length: ${header.frameLen}`);
485
498
  }
486
499
  return true;
487
500
  }
488
- function getAckSequence(data) {
489
- if (!isAckFrame(data)) {
490
- return undefined;
491
- }
492
- return data[6];
493
- }
494
501
  function decodeFrame(data) {
495
- const frameLen = validateFrame(data);
496
- const seq = data[6];
502
+ const { frameLen, router, packetSrc, dataType, seq } = inspectFrameHeader(data);
503
+ if (dataType !== PROTO_DATA_TYPE_PACKET) {
504
+ throw new Error(`Invalid Protocol V2 data type: expected packet, got ${dataType}`);
505
+ }
497
506
  const payloadData = data.slice(7, frameLen - 1);
498
507
  if (payloadData.length < 2) {
499
508
  throw new Error(`Protocol V2 payload too short (need >=2 bytes for messageTypeId)`);
500
509
  }
501
510
  const messageTypeId = payloadData[0] + payloadData[1] * 256;
502
511
  const pbPayload = payloadData.slice(2);
503
- return { messageTypeId, pbPayload, seq };
512
+ return { messageTypeId, pbPayload, seq, router, packetSrc, dataType };
513
+ }
514
+
515
+ class ProtocolV2LinkError extends Error {
516
+ constructor(code, message, cause) {
517
+ super(message);
518
+ this.name = 'ProtocolV2LinkError';
519
+ this.code = code;
520
+ this.cause = cause;
521
+ }
504
522
  }
523
+ const isProtocolV2LinkError = (error) => error instanceof ProtocolV2LinkError;
505
524
 
506
525
  function concatUint8Arrays(arrays) {
507
526
  const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
@@ -546,23 +565,23 @@ class ProtocolV2FrameAssembler {
546
565
  return undefined;
547
566
  if (this.buffer[0] !== PROTO_HEAD_SOF) {
548
567
  this.reset();
549
- throw new Error('Invalid Protocol V2 SOF');
568
+ throw new ProtocolV2LinkError('frame', 'Invalid Protocol V2 SOF');
550
569
  }
551
570
  const expectedLen = this.buffer[1] + this.buffer[2] * 256;
552
571
  if (expectedLen < PROTO_HEAD_CRC_SIZE) {
553
572
  this.reset();
554
- throw new Error(`Protocol V2 frame length too small: ${expectedLen}`);
573
+ throw new ProtocolV2LinkError('frame', `Protocol V2 frame length too small: ${expectedLen}`);
555
574
  }
556
575
  if (expectedLen > this.maxFrameBytes) {
557
576
  this.reset();
558
- throw new Error(`Protocol V2 frame too large: ${expectedLen}`);
577
+ throw new ProtocolV2LinkError('frame', `Protocol V2 frame too large: ${expectedLen}`);
559
578
  }
560
579
  if (this.buffer.length < PROTO_PRE_HEAD_SIZE)
561
580
  return undefined;
562
581
  const expectedHeaderCrc = crc8(this.buffer, 3);
563
582
  if (this.buffer[3] !== expectedHeaderCrc) {
564
583
  this.reset();
565
- throw new Error(`Protocol V2 header CRC mismatch: expected 0x${expectedHeaderCrc
584
+ throw new ProtocolV2LinkError('frame', `Protocol V2 header CRC mismatch: expected 0x${expectedHeaderCrc
566
585
  .toString(16)
567
586
  .padStart(2, '0')}`);
568
587
  }
@@ -588,9 +607,11 @@ var protocolV2Codec = /*#__PURE__*/Object.freeze({
588
607
  nextProtoSeq: nextProtoSeq,
589
608
  encodeFrame: encodeFrame,
590
609
  encodeProtobufFrame: encodeProtobufFrame,
610
+ inspectFrameHeader: inspectFrameHeader,
591
611
  isAckFrame: isAckFrame,
592
- getAckSequence: getAckSequence,
593
612
  decodeFrame: decodeFrame,
613
+ ProtocolV2LinkError: ProtocolV2LinkError,
614
+ isProtocolV2LinkError: isProtocolV2LinkError,
594
615
  concatUint8Arrays: concatUint8Arrays,
595
616
  ProtocolV2FrameAssembler: ProtocolV2FrameAssembler
596
617
  });
@@ -641,15 +662,18 @@ const ProtocolV1 = {
641
662
  };
642
663
  const ProtocolV2 = {
643
664
  isAckFrame,
644
- getAckSequence,
665
+ inspectFrameHeader,
645
666
  inspectFrame(schemas, frame) {
646
- const { messageTypeId, pbPayload, seq } = decodeFrame(frame);
667
+ const { messageTypeId, pbPayload, seq, router, packetSrc, dataType } = decodeFrame(frame);
647
668
  const { messageName } = createProtocolV2MessageFromType(messageTypeId, schemas);
648
669
  return {
649
670
  messageName,
650
671
  messageTypeId,
651
672
  pbPayload,
652
673
  seq,
674
+ router,
675
+ packetSrc,
676
+ dataType,
653
677
  type: messageName,
654
678
  };
655
679
  },
@@ -666,7 +690,17 @@ const ProtocolV2 = {
666
690
  const { messageTypeId, pbPayload, seq, messageName } = this.inspectFrame(schemas, frame);
667
691
  const { Message } = createProtocolV2MessageFromType(messageTypeId, schemas);
668
692
  const rxByteBuffer = ByteBuffer__default["default"].wrap(Buffer.from(pbPayload));
669
- const message = decode(Message, rxByteBuffer);
693
+ let message;
694
+ try {
695
+ message = decode(Message, rxByteBuffer);
696
+ }
697
+ catch (cause) {
698
+ const error = new Error(`Protocol V2 protobuf decode failed for "${messageName}" ` +
699
+ `(${messageTypeId}, ${pbPayload.length}-byte payload); ` +
700
+ 'the payload is malformed or incompatible with the active SDK schema.');
701
+ error.cause = cause;
702
+ throw error;
703
+ }
670
704
  return {
671
705
  message,
672
706
  messageName,
@@ -849,11 +883,12 @@ function getErrorMessage(error) {
849
883
  }
850
884
  return String(error);
851
885
  }
852
- function withProtocolTimeout(promise, timeoutMs, createTimeoutError, onTimeout) {
886
+ function withProtocolTimeout(promise, timeoutMs, createTimeoutError, onTimeout, abortSignal) {
853
887
  return __awaiter(this, void 0, void 0, function* () {
854
888
  if (!timeoutMs)
855
889
  return promise;
856
890
  let timer;
891
+ let abortHandler;
857
892
  try {
858
893
  return yield Promise.race([
859
894
  promise,
@@ -863,16 +898,32 @@ function withProtocolTimeout(promise, timeoutMs, createTimeoutError, onTimeout)
863
898
  reject(createTimeoutError());
864
899
  }, timeoutMs);
865
900
  }),
901
+ ...(abortSignal
902
+ ? [
903
+ new Promise((_, reject) => {
904
+ abortHandler = () => {
905
+ reject(new Error('Protocol V2 operation aborted'));
906
+ };
907
+ if (abortSignal.aborted) {
908
+ abortHandler();
909
+ }
910
+ else {
911
+ abortSignal.addEventListener('abort', abortHandler, { once: true });
912
+ }
913
+ }),
914
+ ]
915
+ : []),
866
916
  ]);
867
917
  }
868
918
  finally {
869
919
  if (timer)
870
920
  clearTimeout(timer);
921
+ if (abortHandler) {
922
+ abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', abortHandler);
923
+ }
871
924
  }
872
925
  });
873
926
  }
874
- const PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS = 30000;
875
- const PROTOCOL_V2_DELIVERY_WATCHDOG_TIMEOUT_MS = 5000;
876
927
  class ProtocolV2Session {
877
928
  constructor(options) {
878
929
  var _a;
@@ -887,16 +938,22 @@ class ProtocolV2Session {
887
938
  return result;
888
939
  }
889
940
  executeCall(name, data, callOptions) {
890
- return __awaiter(this, void 0, void 0, function* () {
891
- const { schemas, router, packetSrc = PROTOCOL_V2_PACKET_SRC_COMMAND, maxFrameBytes, prepareCall, writeFrame, readFrame, logger, logPrefix = 'ProtocolV2', createTimeoutError, generation = 0, writeTimeoutMs = PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS, deliveryTimeoutMs = PROTOCOL_V2_DELIVERY_WATCHDOG_TIMEOUT_MS, } = this.options;
892
- const shouldReduceDebug = shouldReduceProtocolV2Debug(name);
893
- const callContext = {
894
- messageName: name,
895
- timeoutMs: callOptions.timeoutMs,
896
- highVolume: shouldReduceDebug,
897
- generation,
898
- };
899
- yield (prepareCall === null || prepareCall === void 0 ? void 0 : prepareCall(callContext));
941
+ const { schemas, router, packetSrc = PROTOCOL_V2_PACKET_SRC_COMMAND, maxFrameBytes, prepareCall, writeFrame, readFrame, logger, logPrefix = 'ProtocolV2', createTimeoutError, generation = 0, } = this.options;
942
+ const timeoutMs = callOptions.timeoutMs && callOptions.timeoutMs > 0
943
+ ? callOptions.timeoutMs
944
+ : PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS;
945
+ const abortController = new AbortController();
946
+ const shouldReduceDebug = shouldReduceProtocolV2Debug(name);
947
+ const baseCallContext = {
948
+ messageName: name,
949
+ timeoutMs,
950
+ highVolume: shouldReduceDebug,
951
+ generation,
952
+ signal: abortController.signal,
953
+ };
954
+ const runCall = () => __awaiter(this, void 0, void 0, function* () {
955
+ var _a, _b, _c, _d;
956
+ yield (prepareCall === null || prepareCall === void 0 ? void 0 : prepareCall(baseCallContext));
900
957
  const protoSeq = this.sequenceCursor.next();
901
958
  const frame = ProtocolV2.encodeFrame(schemas, name, data, {
902
959
  packetSrc,
@@ -906,76 +963,66 @@ class ProtocolV2Session {
906
963
  if (maxFrameBytes !== undefined && frame.length > maxFrameBytes) {
907
964
  throw new Error(`Protocol V2 frame too large for transport: ${frame.length} > ${maxFrameBytes}`);
908
965
  }
909
- yield withProtocolTimeout(writeFrame(frame, callContext), writeTimeoutMs, () => new Error(`Protocol V2 write timeout after ${writeTimeoutMs}ms for ${name}`));
910
- const cancellation = { cancelled: false };
911
- let resolveDelivery = () => undefined;
912
- let deliveryConfirmed = false;
913
- const deliveryPromise = new Promise(resolve => {
914
- resolveDelivery = () => {
915
- if (deliveryConfirmed)
916
- return;
917
- deliveryConfirmed = true;
918
- resolve();
919
- };
920
- });
921
- const readResponse = () => __awaiter(this, void 0, void 0, function* () {
922
- var _a, _b, _c, _d;
923
- while (!cancellation.cancelled) {
924
- const rxFrame = yield readFrame(callContext);
925
- if (cancellation.cancelled) {
926
- break;
966
+ yield writeFrame(frame, baseCallContext);
967
+ while (!abortController.signal.aborted) {
968
+ const rxFrame = yield readFrame(baseCallContext);
969
+ if (abortController.signal.aborted)
970
+ break;
971
+ let header;
972
+ try {
973
+ header = ProtocolV2.inspectFrameHeader(rxFrame);
974
+ }
975
+ catch (cause) {
976
+ throw new ProtocolV2LinkError('frame', `Protocol V2 frame validation failed: ${getErrorMessage(cause)}`, cause);
977
+ }
978
+ if (header.router !== router) {
979
+ throw new ProtocolV2LinkError('router', `Protocol V2 router mismatch: expected ${router}, got ${header.router}`);
980
+ }
981
+ if (header.packetSrc !== packetSrc) {
982
+ throw new ProtocolV2LinkError('packet-source', `Protocol V2 packet source mismatch: expected ${packetSrc}, got ${header.packetSrc}`);
983
+ }
984
+ let isAck;
985
+ try {
986
+ isAck = ProtocolV2.isAckFrame(rxFrame);
987
+ }
988
+ catch (cause) {
989
+ throw new ProtocolV2LinkError('frame', `Protocol V2 ACK validation failed: ${getErrorMessage(cause)}`, cause);
990
+ }
991
+ if (isAck) {
992
+ if (header.seq !== protoSeq) {
993
+ throw new ProtocolV2LinkError('ack-sequence', `Protocol V2 ACK sequence mismatch: expected ${protoSeq}, got ${header.seq}`);
927
994
  }
928
- const ackSequence = ProtocolV2.getAckSequence(rxFrame);
929
- if (ackSequence !== undefined) {
930
- if (ackSequence === protoSeq) {
931
- resolveDelivery();
932
- }
995
+ }
996
+ else {
997
+ let decoded;
998
+ try {
999
+ decoded = ProtocolV2.decodeFrame(schemas, rxFrame);
933
1000
  }
934
- else {
935
- resolveDelivery();
936
- const decoded = ProtocolV2.decodeFrame(schemas, rxFrame);
937
- const response = call(decoded);
938
- if ((_a = callOptions.intermediateTypes) === null || _a === void 0 ? void 0 : _a.includes(response.type)) {
939
- (_b = callOptions.onIntermediateResponse) === null || _b === void 0 ? void 0 : _b.call(callOptions, response);
940
- }
941
- else if (isExpectedTerminalResponse(response, callOptions.expectedTypes)) {
942
- return response;
943
- }
944
- else if (!shouldReduceDebug) {
945
- (_c = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _c === void 0 ? void 0 : _c.call(logger, `[${logPrefix}] skip unexpected response for ${name}: expected=${(_d = callOptions.expectedTypes) === null || _d === void 0 ? void 0 : _d.join('|')} got=${response.type}`);
946
- }
1001
+ catch (cause) {
1002
+ throw new ProtocolV2LinkError('frame', `Protocol V2 frame decode failed: ${getErrorMessage(cause)}`, cause);
1003
+ }
1004
+ if (this.lastResponseSequence === decoded.seq) {
1005
+ throw new ProtocolV2LinkError('response-sequence', `Protocol V2 duplicate response sequence: ${decoded.seq}`);
1006
+ }
1007
+ this.lastResponseSequence = decoded.seq;
1008
+ const response = call(decoded);
1009
+ if ((_a = callOptions.intermediateTypes) === null || _a === void 0 ? void 0 : _a.includes(response.type)) {
1010
+ (_b = callOptions.onIntermediateResponse) === null || _b === void 0 ? void 0 : _b.call(callOptions, response);
1011
+ }
1012
+ else if (isExpectedTerminalResponse(response, callOptions.expectedTypes)) {
1013
+ return response;
1014
+ }
1015
+ else if (!shouldReduceDebug) {
1016
+ (_c = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _c === void 0 ? void 0 : _c.call(logger, `[${logPrefix}] skip unexpected response for ${name}: expected=${(_d = callOptions.expectedTypes) === null || _d === void 0 ? void 0 : _d.join('|')} got=${response.type}`);
947
1017
  }
948
1018
  }
949
- throw new Error(`Protocol V2 read loop cancelled after timeout for ${name}`);
950
- });
951
- const responsePromise = withProtocolTimeout(readResponse(), callOptions.timeoutMs, () => {
952
- var _a;
953
- return createTimeoutError
954
- ? createTimeoutError(name, (_a = callOptions.timeoutMs) !== null && _a !== void 0 ? _a : 0)
955
- : new Error(`Protocol V2 response timeout after ${callOptions.timeoutMs}ms for ${name}`);
956
- }, () => {
957
- cancellation.cancelled = true;
958
- });
959
- const deliverySignal = Promise.race([deliveryPromise, responsePromise.then(() => undefined)]);
960
- const deliveryWatchdog = withProtocolTimeout(deliverySignal, deliveryTimeoutMs, () => new Error(`Protocol V2 delivery timeout after ${deliveryTimeoutMs}ms for ${name}`), () => {
961
- cancellation.cancelled = true;
962
- });
963
- try {
964
- const firstResult = yield Promise.race([
965
- deliveryWatchdog.then(() => ({ kind: 'delivered' })),
966
- responsePromise.then(response => ({ kind: 'response', response })),
967
- ]);
968
- if (firstResult.kind === 'response') {
969
- return firstResult.response;
970
- }
971
- return yield responsePromise;
972
- }
973
- catch (error) {
974
- cancellation.cancelled = true;
975
- deliveryWatchdog.catch(() => undefined);
976
- responsePromise.catch(() => undefined);
977
- throw error;
978
1019
  }
1020
+ throw new Error(`Protocol V2 read loop cancelled after timeout for ${name}`);
1021
+ });
1022
+ return withProtocolTimeout(runCall(), timeoutMs, () => createTimeoutError
1023
+ ? createTimeoutError(name, timeoutMs)
1024
+ : new Error(`Protocol V2 response timeout after ${timeoutMs}ms for ${name}`), () => {
1025
+ abortController.abort();
979
1026
  });
980
1027
  }
981
1028
  }
@@ -985,7 +1032,10 @@ function probeProtocolV2({ call, timeoutMs, logger, logPrefix = 'ProtocolV2', on
985
1032
  let probeError;
986
1033
  try {
987
1034
  yield (onBeforeProbe === null || onBeforeProbe === void 0 ? void 0 : onBeforeProbe());
988
- const response = yield call('Ping', { message: 'protocol-v2-probe' }, { timeoutMs, expectedTypes: ['Success'] });
1035
+ const response = yield call('Ping', { message: 'protocol-v2-probe' }, {
1036
+ timeoutMs,
1037
+ expectedTypes: ['Success'],
1038
+ });
989
1039
  if (response.type === 'Success') {
990
1040
  return true;
991
1041
  }
@@ -1084,7 +1134,6 @@ class ProtocolV2LinkManager {
1084
1134
  logger: adapter.logger,
1085
1135
  logPrefix: adapter.logPrefix,
1086
1136
  createTimeoutError: adapter.createTimeoutError,
1087
- writeTimeoutMs: adapter.writeTimeoutMs,
1088
1137
  });
1089
1138
  const link = { adapter, session, state };
1090
1139
  this.links.set(key, link);
@@ -1809,6 +1858,15 @@ exports.DeviceSEState = void 0;
1809
1858
  DeviceSEState[DeviceSEState["APP_FACTORY"] = 51] = "APP_FACTORY";
1810
1859
  DeviceSEState[DeviceSEState["APP"] = 85] = "APP";
1811
1860
  })(exports.DeviceSEState || (exports.DeviceSEState = {}));
1861
+ exports.DeviceSessionErrorCode = void 0;
1862
+ (function (DeviceSessionErrorCode) {
1863
+ DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_None"] = 0] = "DeviceSessionError_None";
1864
+ DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_UserCancelled"] = 1] = "DeviceSessionError_UserCancelled";
1865
+ DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_InvalidSession"] = 2] = "DeviceSessionError_InvalidSession";
1866
+ DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_AttachPinUnavailable"] = 3] = "DeviceSessionError_AttachPinUnavailable";
1867
+ DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_PassphraseDisabled"] = 4] = "DeviceSessionError_PassphraseDisabled";
1868
+ DeviceSessionErrorCode[DeviceSessionErrorCode["DeviceSessionError_Busy"] = 5] = "DeviceSessionError_Busy";
1869
+ })(exports.DeviceSessionErrorCode || (exports.DeviceSessionErrorCode = {}));
1812
1870
  exports.DeviceSessionAskPin_FailureSubCodes = void 0;
1813
1871
  (function (DeviceSessionAskPin_FailureSubCodes) {
1814
1872
  DeviceSessionAskPin_FailureSubCodes[DeviceSessionAskPin_FailureSubCodes["UserCancel"] = 1] = "UserCancel";
@@ -1961,6 +2019,7 @@ var messages = /*#__PURE__*/Object.freeze({
1961
2019
  get DeviceType () { return exports.DeviceType; },
1962
2020
  get DeviceSeType () { return exports.DeviceSeType; },
1963
2021
  get DeviceSEState () { return exports.DeviceSEState; },
2022
+ get DeviceSessionErrorCode () { return exports.DeviceSessionErrorCode; },
1964
2023
  get DeviceSessionAskPin_FailureSubCodes () { return exports.DeviceSessionAskPin_FailureSubCodes; },
1965
2024
  get DevOnboardingStep () { return exports.DevOnboardingStep; },
1966
2025
  get DevOnboardingPhase () { return exports.DevOnboardingPhase; },
@@ -2010,16 +2069,16 @@ exports.PROTOCOL_V2_BLE_FRAME_MAX_BYTES = PROTOCOL_V2_BLE_FRAME_MAX_BYTES;
2010
2069
  exports.PROTOCOL_V2_CHANNEL_BLE_UART = PROTOCOL_V2_CHANNEL_BLE_UART;
2011
2070
  exports.PROTOCOL_V2_CHANNEL_SOCKET = PROTOCOL_V2_CHANNEL_SOCKET;
2012
2071
  exports.PROTOCOL_V2_CHANNEL_USB = PROTOCOL_V2_CHANNEL_USB;
2013
- exports.PROTOCOL_V2_DELIVERY_WATCHDOG_TIMEOUT_MS = PROTOCOL_V2_DELIVERY_WATCHDOG_TIMEOUT_MS;
2072
+ exports.PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS = PROTOCOL_V2_DEFAULT_RESPONSE_TIMEOUT_MS;
2014
2073
  exports.PROTOCOL_V2_FILE_CHUNK_SIZE = PROTOCOL_V2_FILE_CHUNK_SIZE;
2015
2074
  exports.PROTOCOL_V2_FRAME_MAX_BYTES = PROTOCOL_V2_FRAME_MAX_BYTES;
2016
2075
  exports.PROTOCOL_V2_PACKET_SRC_COMMAND = PROTOCOL_V2_PACKET_SRC_COMMAND;
2017
2076
  exports.PROTOCOL_V2_SYS_MESSAGE_THRESHOLD = PROTOCOL_V2_SYS_MESSAGE_THRESHOLD;
2018
2077
  exports.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE = PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
2019
- exports.PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS = PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS;
2020
2078
  exports.ProtocolV1 = ProtocolV1;
2021
2079
  exports.ProtocolV2 = ProtocolV2;
2022
2080
  exports.ProtocolV2FrameAssembler = ProtocolV2FrameAssembler;
2081
+ exports.ProtocolV2LinkError = ProtocolV2LinkError;
2023
2082
  exports.ProtocolV2LinkManager = ProtocolV2LinkManager;
2024
2083
  exports.ProtocolV2SequenceCursor = ProtocolV2SequenceCursor;
2025
2084
  exports.ProtocolV2Session = ProtocolV2Session;
@@ -2029,6 +2088,7 @@ exports.concatUint8Arrays = concatUint8Arrays;
2029
2088
  exports["default"] = index;
2030
2089
  exports.getErrorMessage = getErrorMessage;
2031
2090
  exports.hexToBytes = hexToBytes;
2091
+ exports.isProtocolV2LinkError = isProtocolV2LinkError;
2032
2092
  exports.probeProtocolV2 = probeProtocolV2;
2033
2093
  exports.protocolV1 = index$1;
2034
2094
  exports.protocolV2 = protocolV2Codec;
@@ -2,7 +2,7 @@
2
2
  import ByteBuffer from 'bytebuffer';
3
3
  import { encodeEnvelopeMessage } from './v1/packets';
4
4
  import { decodeMessage as decodeV1Message } from './v1/receive';
5
- import { getAckSequence, isAckFrame } from './v2';
5
+ import { inspectFrameHeader, isAckFrame } from './v2';
6
6
  import type { Root } from 'protobufjs/light';
7
7
  export declare const PROTOCOL_V2_SYS_MESSAGE_THRESHOLD = 60000;
8
8
  type ProtocolV2Schemas = {
@@ -27,12 +27,15 @@ export declare const ProtocolV1: {
27
27
  };
28
28
  export declare const ProtocolV2: {
29
29
  isAckFrame: typeof isAckFrame;
30
- getAckSequence: typeof getAckSequence;
30
+ inspectFrameHeader: typeof inspectFrameHeader;
31
31
  inspectFrame(schemas: ProtocolV2Schemas, frame: Uint8Array): {
32
32
  messageName: string;
33
33
  messageTypeId: number;
34
34
  pbPayload: Uint8Array;
35
35
  seq: number;
36
+ router: number;
37
+ packetSrc: number;
38
+ dataType: number;
36
39
  type: string;
37
40
  };
38
41
  encodeFrame(schemas: ProtocolV2Schemas, name: string, data: Record<string, unknown>, options?: ProtocolV2FrameOptions): Uint8Array;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocols/index.ts"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,qBAAqB,EAA+C,MAAM,cAAc,CAAC;AAElG,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAIhE,OAAO,EAGL,cAAc,EACd,UAAU,EACX,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,eAAO,MAAM,iCAAiC,QAAQ,CAAC;AAEvD,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,IAA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,EAAE,OAAO,CAAC,YACpB,sBAAsB;yBAkBZ,iBAAiB,SAAS,UAAU;;;;;;;;;;CA0B1D,CAAC"}
@@ -2,8 +2,18 @@ export interface ProtoV2Frame {
2
2
  messageTypeId: number;
3
3
  pbPayload: Uint8Array;
4
4
  seq: number;
5
+ router: number;
6
+ packetSrc: number;
7
+ dataType: number;
5
8
  }
9
+ export type ProtoV2FrameHeader = {
10
+ frameLen: number;
11
+ router: number;
12
+ packetSrc: number;
13
+ dataType: number;
14
+ seq: number;
15
+ };
16
+ export declare function inspectFrameHeader(data: Uint8Array): ProtoV2FrameHeader;
6
17
  export declare function isAckFrame(data: Uint8Array): boolean;
7
- export declare function getAckSequence(data: Uint8Array): number | undefined;
8
18
  export declare function decodeFrame(data: Uint8Array): ProtoV2Frame;
9
19
  //# sourceMappingURL=decode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/decode.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAE3B,aAAa,EAAE,MAAM,CAAC;IAEtB,SAAS,EAAE,UAAU,CAAC;IAEtB,GAAG,EAAE,MAAM,CAAC;CACb;AAwCD,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAWpD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAKnE;AAYD,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,CAe1D"}
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/decode.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,YAAY;IAE3B,aAAa,EAAE,MAAM,CAAC;IAEtB,SAAS,EAAE,UAAU,CAAC;IAEtB,GAAG,EAAE,MAAM,CAAC;IAEZ,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,MAAM,CAAC;IAElB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,kBAAkB,CAqDvE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAWpD;AAYD,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,CAgB1D"}
@@ -0,0 +1,8 @@
1
+ export type ProtocolV2LinkErrorCode = 'response-timeout' | 'router' | 'packet-source' | 'ack-sequence' | 'response-sequence' | 'frame';
2
+ export declare class ProtocolV2LinkError extends Error {
3
+ readonly code: ProtocolV2LinkErrorCode;
4
+ readonly cause?: unknown;
5
+ constructor(code: ProtocolV2LinkErrorCode, message: string, cause?: unknown);
6
+ }
7
+ export declare const isProtocolV2LinkError: (error: unknown) => error is ProtocolV2LinkError;
8
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAC/B,kBAAkB,GAClB,QAAQ,GACR,eAAe,GACf,cAAc,GACd,mBAAmB,GACnB,OAAO,CAAC;AAEZ,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IAEvC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEb,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAM5E;AAED,eAAO,MAAM,qBAAqB,UAAW,OAAO,iCACd,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"frame-assembler.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/frame-assembler.ts"],"names":[],"mappings":"AAIA,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,CASlE;AAED,qBAAa,wBAAwB;IACnC,OAAO,CAAC,MAAM,CAAqB;IAEnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,aAAa,SAA8B;IAIvD,KAAK;IAIL,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS;IAU/C,KAAK,CAAC,KAAK,GAAE,UAA8B,GAAG,UAAU,EAAE;IAW1D,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,YAAY;CA0CrB"}
1
+ {"version":3,"file":"frame-assembler.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/frame-assembler.ts"],"names":[],"mappings":"AAKA,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,CASlE;AAED,qBAAa,wBAAwB;IACnC,OAAO,CAAC,MAAM,CAAqB;IAEnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,aAAa,SAA8B;IAIvD,KAAK;IAIL,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS;IAU/C,KAAK,CAAC,KAAK,GAAE,UAA8B,GAAG,UAAU,EAAE;IAW1D,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,YAAY;CA2CrB"}
@@ -2,5 +2,6 @@ export * from './constants';
2
2
  export * from './crc8';
3
3
  export * from './encode';
4
4
  export * from './decode';
5
+ export * from './errors';
5
6
  export * from './frame-assembler';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC"}
@@ -12,7 +12,6 @@ export interface ProtocolV2LinkAdapter {
12
12
  logger?: ProtocolV2SessionOptions['logger'];
13
13
  logPrefix?: string;
14
14
  createTimeoutError?: ProtocolV2SessionOptions['createTimeoutError'];
15
- writeTimeoutMs?: number;
16
15
  }
17
16
  export type ProtocolV2LinkManagerOptions<Key> = {
18
17
  getSchemas: () => ProtocolV2Schemas;
@@ -1 +1 @@
1
- {"version":3,"file":"link-manager.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/link-manager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,KAAK,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAEpG,MAAM,MAAM,iCAAiC,GAAG,YAAY,GAAG,aAAa,CAAC;AAE7E,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAClE,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7E,SAAS,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/D,KAAK,CAAC,MAAM,EAAE,MA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AK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACxE,CAAC;AAUF,qBAAa,qBAAqB,CAAC,GAAG;IACpC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkC;IAExD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4C;IAEtE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAE/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;gBAEhD,OAAO,EAAE,4BAA4B,CAAC,GAAG,CAAC;IAItD,IAAI,CACF,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,MAAM,qBAAqB,EAC1C,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IAevB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvD,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM5C,OAAO,CAAC,eAAe;YA+CT,WAAW;IAkBzB,OAAO,CAAC,qBAAqB;CAK9B"}
@@ -2,6 +2,7 @@ import { ProtocolV2FrameAssembler, concatUint8Arrays } from './frame-assembler';
2
2
  import { ProtocolV2SequenceCursor } from './sequence-cursor';
3
3
  import type { Root } from 'protobufjs/light';
4
4
  import type { MessageFromOneKey } from '../../types';
5
+ export * from './errors';
5
6
  export type ProtocolV2Schemas = {
6
7
  protocolV1: Root;
7
8
  protocolV2: Root;
@@ -11,6 +12,7 @@ export type ProtocolV2CallContext = {
11
12
  timeoutMs?: number;
12
13
  highVolume: boolean;
13
14
  generation: number;
15
+ signal: AbortSignal;
14
16
  };
15
17
  type ProtocolLogger = {
16
18
  debug?: (...args: any[]) => void;
@@ -29,8 +31,6 @@ export type ProtocolV2SessionOptions = {
29
31
  createTimeoutError?: (name: string, timeoutMs: number) => Error;
30
32
  sequenceCursor?: ProtocolV2SequenceCursor;
31
33
  generation?: number;
32
- writeTimeoutMs?: number;
33
- deliveryTimeoutMs?: number;
34
34
  };
35
35
  export type ProtocolV2CallOptions = {
36
36
  timeoutMs?: number;
@@ -43,13 +43,12 @@ export { ProtocolV2SequenceCursor };
43
43
  export declare function hexToBytes(hex: string): Uint8Array;
44
44
  export declare function bytesToHex(bytes: Uint8Array): string;
45
45
  export declare function getErrorMessage(error: unknown): string;
46
- export declare function withProtocolTimeout<T>(promise: Promise<T>, timeoutMs: number | undefined, createTimeoutError: () => Error, onTimeout?: () => void): Promise<T>;
47
- export declare const PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS = 30000;
48
- export declare const PROTOCOL_V2_DELIVERY_WATCHDOG_TIMEOUT_MS = 5000;
46
+ export declare function withProtocolTimeout<T>(promise: Promise<T>, timeoutMs: number | undefined, createTimeoutError: () => Error, onTimeout?: () => void, abortSignal?: AbortSignal): Promise<T>;
49
47
  export declare class ProtocolV2Session {
50
48
  private readonly options;
51
49
  private readonly sequenceCursor;
52
50
  private pendingCall;
51
+ private lastResponseSequence?;
53
52
  constructor(options: ProtocolV2SessionOptions);
54
53
  call(name: string, data: Record<string, unknown>, callOptions?: ProtocolV2CallOptions): Promise<MessageFromOneKey>;
55
54
  private executeCall;
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAK7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAA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