@onekeyfe/hd-transport 1.2.0-alpha.8 → 1.2.0-alpha.9
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 +62 -0
- package/__tests__/protocol-v2-link-manager.test.js +326 -0
- package/__tests__/protocol-v2-usb-transport-base.test.js +296 -0
- package/__tests__/protocol-v2.test.js +112 -4
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +164 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +352 -29
- package/dist/protocols/index.d.ts +2 -0
- package/dist/protocols/index.d.ts.map +1 -1
- package/dist/protocols/v2/constants.d.ts +1 -0
- package/dist/protocols/v2/constants.d.ts.map +1 -1
- package/dist/protocols/v2/decode.d.ts +1 -0
- package/dist/protocols/v2/decode.d.ts.map +1 -1
- package/dist/protocols/v2/link-manager.d.ts +35 -0
- package/dist/protocols/v2/link-manager.d.ts.map +1 -0
- package/dist/protocols/v2/sequence-cursor.d.ts +5 -0
- package/dist/protocols/v2/sequence-cursor.d.ts.map +1 -0
- package/dist/protocols/v2/session.d.ts +15 -3
- package/dist/protocols/v2/session.d.ts.map +1 -1
- package/dist/protocols/v2/usb-transport-base.d.ts +31 -0
- package/dist/protocols/v2/usb-transport-base.d.ts.map +1 -0
- package/dist/types/messages.d.ts +51 -1
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/transport.d.ts +1 -1
- package/dist/types/transport.d.ts.map +1 -1
- package/messages-protocol-v2.json +134 -3
- package/package.json +2 -2
- package/scripts/protobuf-build.sh +46 -0
- package/src/constants.ts +6 -0
- package/src/index.ts +8 -0
- package/src/protocols/index.ts +3 -1
- package/src/protocols/v2/constants.ts +1 -0
- package/src/protocols/v2/decode.ts +36 -17
- package/src/protocols/v2/link-manager.ts +160 -0
- package/src/protocols/v2/sequence-cursor.ts +10 -0
- package/src/protocols/v2/session.ts +76 -40
- package/src/protocols/v2/usb-transport-base.ts +194 -0
- package/src/types/messages.ts +65 -1
- package/src/types/transport.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -270,6 +270,8 @@ const PROTOCOL_V1_ENVELOPE_HEADER_SIZE = 1 + 1 + PROTOCOL_V1_MESSAGE_HEADER_SIZE
|
|
|
270
270
|
const PROTOCOL_V2_FRAME_MAX_BYTES = 4608;
|
|
271
271
|
const PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE = 4000;
|
|
272
272
|
const PROTOCOL_V2_BLE_FILE_CHUNK_SIZE = 1800;
|
|
273
|
+
const PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE = 900;
|
|
274
|
+
const PROTOCOL_V2_BLE_FRAME_MAX_BYTES = 2048;
|
|
273
275
|
const PROTOCOL_V2_FILE_CHUNK_SIZE = PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
274
276
|
const PROTOCOL_V2_CHANNEL_USB = 0;
|
|
275
277
|
const PROTOCOL_V2_CHANNEL_BLE_UART = 1;
|
|
@@ -381,6 +383,7 @@ const PROTO_HEAD_CRC_SIZE = 8;
|
|
|
381
383
|
const CRC8_INIT = 0x30;
|
|
382
384
|
const PACKET_SIZE = 4096;
|
|
383
385
|
const PROTO_DATA_TYPE_PACKET = 0;
|
|
386
|
+
const PROTO_DATA_TYPE_ACK = 1;
|
|
384
387
|
|
|
385
388
|
const CRC8_TABLE = new Uint8Array([
|
|
386
389
|
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41,
|
|
@@ -462,7 +465,7 @@ function encodeProtobufFrame(messageTypeId, pbPayload, packetSrc, router, debugO
|
|
|
462
465
|
return encodeFrame(payload, packetSrc, router, Object.assign(Object.assign({}, debugOptions), { messageTypeId, pbPayloadLength: pbPayload.length }), seq);
|
|
463
466
|
}
|
|
464
467
|
|
|
465
|
-
function
|
|
468
|
+
function validateFrame(data) {
|
|
466
469
|
if (data.length < PROTO_HEAD_CRC_SIZE) {
|
|
467
470
|
throw new Error(`Protocol V2 frame too short: ${data.length} bytes`);
|
|
468
471
|
}
|
|
@@ -485,6 +488,22 @@ function decodeFrame(data, debugOptions) {
|
|
|
485
488
|
.toString(16)
|
|
486
489
|
.padStart(2, '0')}, got 0x${data[frameLen - 1].toString(16).padStart(2, '0')}`);
|
|
487
490
|
}
|
|
491
|
+
return frameLen;
|
|
492
|
+
}
|
|
493
|
+
function isAckFrame(data) {
|
|
494
|
+
if (data.length < 6 || (data[5] & 0x03) !== PROTO_DATA_TYPE_ACK) {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
const frameLen = validateFrame(data);
|
|
498
|
+
if (frameLen !== PROTO_HEAD_CRC_SIZE) {
|
|
499
|
+
throw new Error(`Invalid Protocol V2 ACK frame length: ${frameLen}`);
|
|
500
|
+
}
|
|
501
|
+
return true;
|
|
502
|
+
}
|
|
503
|
+
function decodeFrame(data, debugOptions) {
|
|
504
|
+
const frameLen = validateFrame(data);
|
|
505
|
+
const expectedHeaderCrc = data[3];
|
|
506
|
+
const expectedFrameCrc = data[frameLen - 1];
|
|
488
507
|
const seq = data[6];
|
|
489
508
|
const payloadData = data.slice(7, frameLen - 1);
|
|
490
509
|
if (payloadData.length < 2) {
|
|
@@ -587,12 +606,14 @@ var protocolV2Codec = /*#__PURE__*/Object.freeze({
|
|
|
587
606
|
CRC8_INIT: CRC8_INIT,
|
|
588
607
|
PACKET_SIZE: PACKET_SIZE,
|
|
589
608
|
PROTO_DATA_TYPE_PACKET: PROTO_DATA_TYPE_PACKET,
|
|
609
|
+
PROTO_DATA_TYPE_ACK: PROTO_DATA_TYPE_ACK,
|
|
590
610
|
CRC8_TABLE: CRC8_TABLE,
|
|
591
611
|
crc8: crc8,
|
|
592
612
|
logProtocolV2Debug: logProtocolV2Debug,
|
|
593
613
|
nextProtoSeq: nextProtoSeq,
|
|
594
614
|
encodeFrame: encodeFrame,
|
|
595
615
|
encodeProtobufFrame: encodeProtobufFrame,
|
|
616
|
+
isAckFrame: isAckFrame,
|
|
596
617
|
decodeFrame: decodeFrame,
|
|
597
618
|
concatUint8Arrays: concatUint8Arrays,
|
|
598
619
|
ProtocolV2FrameAssembler: ProtocolV2FrameAssembler
|
|
@@ -643,6 +664,7 @@ const ProtocolV1 = {
|
|
|
643
664
|
decodeMessage: decodeMessage,
|
|
644
665
|
};
|
|
645
666
|
const ProtocolV2 = {
|
|
667
|
+
isAckFrame,
|
|
646
668
|
encodeFrame(schemas, name, data, options = {}) {
|
|
647
669
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
648
670
|
const encodeMessages = resolveProtocolV2EncodeSchema(name, schemas);
|
|
@@ -705,6 +727,16 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
705
727
|
decodeMessage: decodeMessage
|
|
706
728
|
});
|
|
707
729
|
|
|
730
|
+
class ProtocolV2SequenceCursor {
|
|
731
|
+
constructor() {
|
|
732
|
+
this.current = 0;
|
|
733
|
+
}
|
|
734
|
+
next() {
|
|
735
|
+
this.current = nextProtoSeq(this.current);
|
|
736
|
+
return this.current;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
708
740
|
const ERROR = 'Wrong result type.';
|
|
709
741
|
function info(res) {
|
|
710
742
|
if (typeof res !== 'object' || res == null) {
|
|
@@ -959,9 +991,10 @@ function withProtocolTimeout(promise, timeoutMs, createTimeoutError, onTimeout)
|
|
|
959
991
|
const PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS = 0;
|
|
960
992
|
class ProtocolV2Session {
|
|
961
993
|
constructor(options) {
|
|
994
|
+
var _a;
|
|
962
995
|
this.pendingCall = Promise.resolve();
|
|
963
|
-
this.protoSeq = 0;
|
|
964
996
|
this.options = options;
|
|
997
|
+
this.sequenceCursor = (_a = options.sequenceCursor) !== null && _a !== void 0 ? _a : new ProtocolV2SequenceCursor();
|
|
965
998
|
}
|
|
966
999
|
call(name, data, callOptions = {}) {
|
|
967
1000
|
const run = () => this.executeCall(name, data, callOptions);
|
|
@@ -972,55 +1005,73 @@ class ProtocolV2Session {
|
|
|
972
1005
|
executeCall(name, data, callOptions) {
|
|
973
1006
|
var _a, _b;
|
|
974
1007
|
return __awaiter(this, void 0, void 0, function* () {
|
|
975
|
-
const { schemas, router, packetSrc = PROTOCOL_V2_PACKET_SRC_COMMAND, writeFrame, readFrame, logger, logPrefix = 'ProtocolV2', createTimeoutError, } = this.options;
|
|
1008
|
+
const { schemas, router, packetSrc = PROTOCOL_V2_PACKET_SRC_COMMAND, maxFrameBytes, prepareCall, writeFrame, readFrame, logger, logPrefix = 'ProtocolV2', createTimeoutError, generation = 0, } = this.options;
|
|
976
1009
|
const shouldReduceDebug = shouldReduceProtocolV2Debug(name);
|
|
977
|
-
|
|
1010
|
+
const callContext = {
|
|
1011
|
+
messageName: name,
|
|
1012
|
+
timeoutMs: callOptions.timeoutMs,
|
|
1013
|
+
highVolume: shouldReduceDebug,
|
|
1014
|
+
generation,
|
|
1015
|
+
};
|
|
1016
|
+
yield (prepareCall === null || prepareCall === void 0 ? void 0 : prepareCall(callContext));
|
|
1017
|
+
const protoSeq = this.sequenceCursor.next();
|
|
978
1018
|
const frame = ProtocolV2.encodeFrame(schemas, name, data, {
|
|
979
1019
|
packetSrc,
|
|
980
1020
|
router,
|
|
981
|
-
seq:
|
|
1021
|
+
seq: protoSeq,
|
|
982
1022
|
logger: shouldReduceDebug ? undefined : logger,
|
|
983
1023
|
logPrefix,
|
|
984
1024
|
context: `tx:${name}`,
|
|
985
1025
|
});
|
|
986
1026
|
const expectedSeq = frame[6];
|
|
1027
|
+
if (maxFrameBytes !== undefined && frame.length > maxFrameBytes) {
|
|
1028
|
+
throw new Error(`Protocol V2 frame too large for transport: ${frame.length} > ${maxFrameBytes}`);
|
|
1029
|
+
}
|
|
987
1030
|
if (!shouldReduceDebug) {
|
|
988
1031
|
(_a = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _a === void 0 ? void 0 : _a.call(logger, `[${logPrefix}] TX payload name=${name}`, sanitizeProtocolV2DebugPayload(data));
|
|
989
1032
|
(_b = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _b === void 0 ? void 0 : _b.call(logger, `[${logPrefix}] TX frame name=${name} len=${frame.length} router=${frame[4]} attr=${frame[5]} seq=${expectedSeq} headerHex=${frameHeaderDebugHex(frame)}`);
|
|
990
1033
|
}
|
|
991
|
-
yield withProtocolTimeout(writeFrame(frame), PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS, () => new Error(`Protocol V2 write timeout after ${PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS}ms for ${name}`));
|
|
1034
|
+
yield withProtocolTimeout(writeFrame(frame, callContext), PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS, () => new Error(`Protocol V2 write timeout after ${PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS}ms for ${name}`));
|
|
992
1035
|
const cancellation = { cancelled: false };
|
|
993
1036
|
const readResponse = () => __awaiter(this, void 0, void 0, function* () {
|
|
994
|
-
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
1037
|
+
var _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
995
1038
|
while (!cancellation.cancelled) {
|
|
996
|
-
const rxFrame = yield readFrame();
|
|
1039
|
+
const rxFrame = yield readFrame(callContext);
|
|
997
1040
|
if (cancellation.cancelled) {
|
|
998
1041
|
break;
|
|
999
1042
|
}
|
|
1000
1043
|
if (!shouldReduceDebug) {
|
|
1001
1044
|
(_c = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _c === void 0 ? void 0 : _c.call(logger, `[${logPrefix}] RX frame len=${rxFrame.length} router=${rxFrame[4]} attr=${rxFrame[5]} seq=${rxFrame[6]} headerHex=${frameHeaderDebugHex(rxFrame)}`);
|
|
1002
1045
|
}
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
if (!shouldReduceDebug && decoded.seq !== expectedSeq) {
|
|
1009
|
-
(_d = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _d === void 0 ? void 0 : _d.call(logger, `[${logPrefix}] seq differs for ${name}: tx=${expectedSeq}, rx=${decoded.seq}`);
|
|
1010
|
-
}
|
|
1011
|
-
if (!shouldReduceDebug) {
|
|
1012
|
-
(_e = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _e === void 0 ? void 0 : _e.call(logger, `[${logPrefix}] TX name=${name} seq=${expectedSeq} | RX seq=${decoded.seq} messageTypeId=${decoded.messageTypeId} pbPayload=${decoded.pbPayload.length}B`);
|
|
1013
|
-
(_f = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _f === void 0 ? void 0 : _f.call(logger, `[${logPrefix}] RX payload type=${decoded.type} messageTypeId=${decoded.messageTypeId}`, sanitizeProtocolV2DebugPayload(decoded.message));
|
|
1014
|
-
}
|
|
1015
|
-
const response = call(decoded);
|
|
1016
|
-
if ((_g = callOptions.intermediateTypes) === null || _g === void 0 ? void 0 : _g.includes(response.type)) {
|
|
1017
|
-
(_h = callOptions.onIntermediateResponse) === null || _h === void 0 ? void 0 : _h.call(callOptions, response);
|
|
1046
|
+
const isAck = ProtocolV2.isAckFrame(rxFrame);
|
|
1047
|
+
if (isAck) {
|
|
1048
|
+
if (!shouldReduceDebug) {
|
|
1049
|
+
(_d = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _d === void 0 ? void 0 : _d.call(logger, `[${logPrefix}] skip Proto Link ACK seq=${rxFrame[6]}`);
|
|
1050
|
+
}
|
|
1018
1051
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1052
|
+
if (!isAck) {
|
|
1053
|
+
const decoded = ProtocolV2.decodeFrame(schemas, rxFrame, {
|
|
1054
|
+
logger: shouldReduceDebug ? undefined : logger,
|
|
1055
|
+
logPrefix,
|
|
1056
|
+
context: `rx:${name}`,
|
|
1057
|
+
});
|
|
1058
|
+
if (!shouldReduceDebug && decoded.seq !== expectedSeq) {
|
|
1059
|
+
(_e = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _e === void 0 ? void 0 : _e.call(logger, `[${logPrefix}] seq differs for ${name}: tx=${expectedSeq}, rx=${decoded.seq}`);
|
|
1060
|
+
}
|
|
1061
|
+
if (!shouldReduceDebug) {
|
|
1062
|
+
(_f = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _f === void 0 ? void 0 : _f.call(logger, `[${logPrefix}] TX name=${name} seq=${expectedSeq} | RX seq=${decoded.seq} messageTypeId=${decoded.messageTypeId} pbPayload=${decoded.pbPayload.length}B`);
|
|
1063
|
+
(_g = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _g === void 0 ? void 0 : _g.call(logger, `[${logPrefix}] RX payload type=${decoded.type} messageTypeId=${decoded.messageTypeId}`, sanitizeProtocolV2DebugPayload(decoded.message));
|
|
1064
|
+
}
|
|
1065
|
+
const response = call(decoded);
|
|
1066
|
+
if ((_h = callOptions.intermediateTypes) === null || _h === void 0 ? void 0 : _h.includes(response.type)) {
|
|
1067
|
+
(_j = callOptions.onIntermediateResponse) === null || _j === void 0 ? void 0 : _j.call(callOptions, response);
|
|
1068
|
+
}
|
|
1069
|
+
else if (isExpectedTerminalResponse(response, callOptions.expectedTypes)) {
|
|
1070
|
+
return response;
|
|
1071
|
+
}
|
|
1072
|
+
else if (!shouldReduceDebug) {
|
|
1073
|
+
(_k = logger === null || logger === void 0 ? void 0 : logger.debug) === null || _k === void 0 ? void 0 : _k.call(logger, `[${logPrefix}] skip unexpected response for ${name}: expected=${(_l = callOptions.expectedTypes) === null || _l === void 0 ? void 0 : _l.join('|')} got=${response.type}`);
|
|
1074
|
+
}
|
|
1024
1075
|
}
|
|
1025
1076
|
}
|
|
1026
1077
|
throw new Error(`Protocol V2 read loop cancelled after timeout for ${name}`);
|
|
@@ -1057,6 +1108,247 @@ function probeProtocolV2({ call, timeoutMs, logger, logPrefix = 'ProtocolV2', on
|
|
|
1057
1108
|
});
|
|
1058
1109
|
}
|
|
1059
1110
|
|
|
1111
|
+
class ProtocolV2LinkManager {
|
|
1112
|
+
constructor(options) {
|
|
1113
|
+
this.links = new Map();
|
|
1114
|
+
this.sequences = new Map();
|
|
1115
|
+
this.callQueues = new Map();
|
|
1116
|
+
this.options = options;
|
|
1117
|
+
}
|
|
1118
|
+
call(key, createAdapter, name, data, options) {
|
|
1119
|
+
var _a;
|
|
1120
|
+
const run = () => this.executeCall(key, createAdapter, name, data, options);
|
|
1121
|
+
const previous = (_a = this.callQueues.get(key)) !== null && _a !== void 0 ? _a : Promise.resolve();
|
|
1122
|
+
const result = previous.then(run, run);
|
|
1123
|
+
const queue = result.catch(() => undefined);
|
|
1124
|
+
this.callQueues.set(key, queue);
|
|
1125
|
+
result
|
|
1126
|
+
.then(() => this.clearSettledCallQueue(key, queue), () => this.clearSettledCallQueue(key, queue))
|
|
1127
|
+
.catch(() => undefined);
|
|
1128
|
+
return result;
|
|
1129
|
+
}
|
|
1130
|
+
invalidateLink(key, reason) {
|
|
1131
|
+
var _a, _b;
|
|
1132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1133
|
+
const link = this.links.get(key);
|
|
1134
|
+
if (!link)
|
|
1135
|
+
return;
|
|
1136
|
+
this.links.delete(key);
|
|
1137
|
+
link.state.invalidatedReason = reason;
|
|
1138
|
+
yield link.adapter.reset(reason);
|
|
1139
|
+
yield ((_b = (_a = this.options).onLinkInvalidated) === null || _b === void 0 ? void 0 : _b.call(_a, key, reason));
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
invalidateAllLinks(reason) {
|
|
1143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1144
|
+
yield Promise.all(Array.from(this.links.keys(), key => this.invalidateLink(key, reason)));
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
dispose(reason) {
|
|
1148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1149
|
+
yield this.invalidateAllLinks(reason);
|
|
1150
|
+
this.sequences.clear();
|
|
1151
|
+
this.callQueues.clear();
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
getOrCreateLink(key, createAdapter) {
|
|
1155
|
+
const existing = this.links.get(key);
|
|
1156
|
+
if (existing)
|
|
1157
|
+
return existing;
|
|
1158
|
+
const adapter = createAdapter();
|
|
1159
|
+
const state = {};
|
|
1160
|
+
const assertLinkActive = () => {
|
|
1161
|
+
if (state.invalidatedReason) {
|
|
1162
|
+
throw new Error(state.invalidatedReason);
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
let sequenceCursor = this.sequences.get(key);
|
|
1166
|
+
if (!sequenceCursor) {
|
|
1167
|
+
sequenceCursor = new ProtocolV2SequenceCursor();
|
|
1168
|
+
this.sequences.set(key, sequenceCursor);
|
|
1169
|
+
}
|
|
1170
|
+
const session = new ProtocolV2Session({
|
|
1171
|
+
schemas: this.options.getSchemas(),
|
|
1172
|
+
router: adapter.router,
|
|
1173
|
+
maxFrameBytes: adapter.maxFrameBytes,
|
|
1174
|
+
generation: adapter.generation,
|
|
1175
|
+
sequenceCursor,
|
|
1176
|
+
prepareCall: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
1177
|
+
assertLinkActive();
|
|
1178
|
+
yield adapter.prepareCall(context);
|
|
1179
|
+
assertLinkActive();
|
|
1180
|
+
}),
|
|
1181
|
+
writeFrame: (frame, context) => __awaiter(this, void 0, void 0, function* () {
|
|
1182
|
+
assertLinkActive();
|
|
1183
|
+
yield adapter.writeFrame(frame, context);
|
|
1184
|
+
assertLinkActive();
|
|
1185
|
+
}),
|
|
1186
|
+
readFrame: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
1187
|
+
assertLinkActive();
|
|
1188
|
+
const frame = yield adapter.readFrame(context);
|
|
1189
|
+
assertLinkActive();
|
|
1190
|
+
return frame;
|
|
1191
|
+
}),
|
|
1192
|
+
logger: adapter.logger,
|
|
1193
|
+
logPrefix: adapter.logPrefix,
|
|
1194
|
+
createTimeoutError: adapter.createTimeoutError,
|
|
1195
|
+
});
|
|
1196
|
+
const link = { adapter, session, state };
|
|
1197
|
+
this.links.set(key, link);
|
|
1198
|
+
return link;
|
|
1199
|
+
}
|
|
1200
|
+
executeCall(key, createAdapter, name, data, options) {
|
|
1201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1202
|
+
try {
|
|
1203
|
+
return yield this.getOrCreateLink(key, createAdapter).session.call(name, data, options);
|
|
1204
|
+
}
|
|
1205
|
+
catch (error) {
|
|
1206
|
+
if (this.options.classifyError(error) === 'link-fatal') {
|
|
1207
|
+
const errorMessage = getErrorMessage(error) || 'unknown error';
|
|
1208
|
+
yield this.invalidateLink(key, `Protocol V2 link-fatal error: ${errorMessage}`);
|
|
1209
|
+
}
|
|
1210
|
+
throw error;
|
|
1211
|
+
}
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
clearSettledCallQueue(key, queue) {
|
|
1215
|
+
if (this.callQueues.get(key) === queue) {
|
|
1216
|
+
this.callQueues.delete(key);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
class ProtocolV2UsbTransportBase {
|
|
1222
|
+
constructor(options) {
|
|
1223
|
+
this.protocolV2UsbAssemblers = new Map();
|
|
1224
|
+
this.protocolV2UsbGenerations = new Map();
|
|
1225
|
+
this.protocolV2UsbCancellations = new Map();
|
|
1226
|
+
this.protocolV2UsbOptions = options;
|
|
1227
|
+
this.protocolV2UsbLinks = new ProtocolV2LinkManager({
|
|
1228
|
+
getSchemas: () => this.getProtocolV2UsbSchemas(),
|
|
1229
|
+
classifyError: () => 'link-fatal',
|
|
1230
|
+
onLinkInvalidated: (key, reason) => __awaiter(this, void 0, void 0, function* () {
|
|
1231
|
+
var _a;
|
|
1232
|
+
(_a = this.protocolV2UsbAssemblers.get(key)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
1233
|
+
yield this.resetProtocolV2UsbNativeLink(key, reason);
|
|
1234
|
+
yield this.onProtocolV2UsbLinkInvalidated(key, reason);
|
|
1235
|
+
}),
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
onProtocolV2UsbLinkInvalidated(_key, _reason) {
|
|
1239
|
+
}
|
|
1240
|
+
rotateProtocolV2UsbGeneration(key, reason) {
|
|
1241
|
+
var _a;
|
|
1242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1243
|
+
yield this.protocolV2UsbLinks.invalidateLink(key, reason);
|
|
1244
|
+
const generation = ((_a = this.protocolV2UsbGenerations.get(key)) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
1245
|
+
this.protocolV2UsbGenerations.set(key, generation);
|
|
1246
|
+
this.protocolV2UsbCancellations.set(key, this.createProtocolV2UsbCancellation(generation));
|
|
1247
|
+
this.protocolV2UsbAssemblers.set(key, new ProtocolV2FrameAssembler(this.protocolV2UsbOptions.maxFrameBytes));
|
|
1248
|
+
return generation;
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
callProtocolV2Usb(key, name, data, options) {
|
|
1252
|
+
return this.protocolV2UsbLinks.call(key, () => this.createProtocolV2UsbAdapter(key), name, data, options);
|
|
1253
|
+
}
|
|
1254
|
+
invalidateProtocolV2UsbLink(key, reason) {
|
|
1255
|
+
return this.protocolV2UsbLinks.invalidateLink(key, reason);
|
|
1256
|
+
}
|
|
1257
|
+
invalidateAllProtocolV2UsbLinks(reason) {
|
|
1258
|
+
return this.protocolV2UsbLinks.invalidateAllLinks(reason);
|
|
1259
|
+
}
|
|
1260
|
+
disposeProtocolV2UsbLinks(reason) {
|
|
1261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1262
|
+
yield this.protocolV2UsbLinks.dispose(reason);
|
|
1263
|
+
this.protocolV2UsbAssemblers.clear();
|
|
1264
|
+
this.protocolV2UsbGenerations.clear();
|
|
1265
|
+
this.protocolV2UsbCancellations.clear();
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
createProtocolV2UsbAdapter(key) {
|
|
1269
|
+
const generation = this.protocolV2UsbGenerations.get(key);
|
|
1270
|
+
if (generation === undefined) {
|
|
1271
|
+
throw new Error('Protocol V2 USB generation has not been initialized');
|
|
1272
|
+
}
|
|
1273
|
+
const cancellation = this.protocolV2UsbCancellations.get(key);
|
|
1274
|
+
if (!cancellation || cancellation.generation !== generation) {
|
|
1275
|
+
throw new Error('Protocol V2 USB cancellation state has not been initialized');
|
|
1276
|
+
}
|
|
1277
|
+
const assertCurrentGeneration = () => {
|
|
1278
|
+
if (cancellation.reason) {
|
|
1279
|
+
throw new Error(cancellation.reason);
|
|
1280
|
+
}
|
|
1281
|
+
if (this.protocolV2UsbGenerations.get(key) !== generation) {
|
|
1282
|
+
throw new Error('Protocol V2 USB connection generation changed');
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
return {
|
|
1286
|
+
router: this.protocolV2UsbOptions.router,
|
|
1287
|
+
maxFrameBytes: this.protocolV2UsbOptions.maxFrameBytes,
|
|
1288
|
+
generation,
|
|
1289
|
+
prepareCall: () => {
|
|
1290
|
+
assertCurrentGeneration();
|
|
1291
|
+
this.getProtocolV2UsbAssembler(key).reset();
|
|
1292
|
+
},
|
|
1293
|
+
writeFrame: (frame, context) => __awaiter(this, void 0, void 0, function* () {
|
|
1294
|
+
assertCurrentGeneration();
|
|
1295
|
+
yield this.writeProtocolV2UsbPacket(key, frame, context);
|
|
1296
|
+
assertCurrentGeneration();
|
|
1297
|
+
}),
|
|
1298
|
+
readFrame: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
1299
|
+
assertCurrentGeneration();
|
|
1300
|
+
const assembler = this.getProtocolV2UsbAssembler(key);
|
|
1301
|
+
let frame = assembler.push(new Uint8Array(0));
|
|
1302
|
+
while (!frame) {
|
|
1303
|
+
const packetRead = this.readProtocolV2UsbPacket(key, context).then(packet => ({
|
|
1304
|
+
packet,
|
|
1305
|
+
}));
|
|
1306
|
+
const cancelled = cancellation.promise.then(reason => ({ reason }));
|
|
1307
|
+
const result = yield Promise.race([packetRead, cancelled]);
|
|
1308
|
+
if ('reason' in result) {
|
|
1309
|
+
throw new Error(result.reason);
|
|
1310
|
+
}
|
|
1311
|
+
assertCurrentGeneration();
|
|
1312
|
+
frame = assembler.push(result.packet);
|
|
1313
|
+
}
|
|
1314
|
+
assertCurrentGeneration();
|
|
1315
|
+
return frame;
|
|
1316
|
+
}),
|
|
1317
|
+
reset: (reason) => {
|
|
1318
|
+
var _a;
|
|
1319
|
+
cancellation.cancel(reason);
|
|
1320
|
+
(_a = this.protocolV2UsbAssemblers.get(key)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
1321
|
+
},
|
|
1322
|
+
logger: this.getProtocolV2UsbLogger(),
|
|
1323
|
+
logPrefix: this.protocolV2UsbOptions.logPrefix,
|
|
1324
|
+
createTimeoutError: (messageName, timeoutMs) => this.createProtocolV2UsbTimeoutError(messageName, timeoutMs),
|
|
1325
|
+
};
|
|
1326
|
+
}
|
|
1327
|
+
getProtocolV2UsbAssembler(key) {
|
|
1328
|
+
const assembler = this.protocolV2UsbAssemblers.get(key);
|
|
1329
|
+
if (!assembler) {
|
|
1330
|
+
throw new Error('Protocol V2 USB assembler has not been initialized');
|
|
1331
|
+
}
|
|
1332
|
+
return assembler;
|
|
1333
|
+
}
|
|
1334
|
+
createProtocolV2UsbCancellation(generation) {
|
|
1335
|
+
let resolveCancellation = () => undefined;
|
|
1336
|
+
const cancellation = {
|
|
1337
|
+
generation,
|
|
1338
|
+
promise: new Promise(resolve => {
|
|
1339
|
+
resolveCancellation = resolve;
|
|
1340
|
+
}),
|
|
1341
|
+
cancel: reason => {
|
|
1342
|
+
if (cancellation.reason)
|
|
1343
|
+
return;
|
|
1344
|
+
cancellation.reason = reason;
|
|
1345
|
+
resolveCancellation(reason);
|
|
1346
|
+
},
|
|
1347
|
+
};
|
|
1348
|
+
return cancellation;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1060
1352
|
exports.AptosTransactionType = void 0;
|
|
1061
1353
|
(function (AptosTransactionType) {
|
|
1062
1354
|
AptosTransactionType[AptosTransactionType["STANDARD"] = 0] = "STANDARD";
|
|
@@ -1516,6 +1808,11 @@ exports.ViewTipType = void 0;
|
|
|
1516
1808
|
ViewTipType[ViewTipType["Warning"] = 3] = "Warning";
|
|
1517
1809
|
ViewTipType[ViewTipType["Danger"] = 4] = "Danger";
|
|
1518
1810
|
})(exports.ViewTipType || (exports.ViewTipType = {}));
|
|
1811
|
+
exports.ViewSignLayout = void 0;
|
|
1812
|
+
(function (ViewSignLayout) {
|
|
1813
|
+
ViewSignLayout[ViewSignLayout["LayoutDefault"] = 0] = "LayoutDefault";
|
|
1814
|
+
ViewSignLayout[ViewSignLayout["LayoutSafeTxCreate"] = 1] = "LayoutSafeTxCreate";
|
|
1815
|
+
})(exports.ViewSignLayout || (exports.ViewSignLayout = {}));
|
|
1519
1816
|
exports.DeviceRebootType = void 0;
|
|
1520
1817
|
(function (DeviceRebootType) {
|
|
1521
1818
|
DeviceRebootType[DeviceRebootType["Normal"] = 0] = "Normal";
|
|
@@ -1577,6 +1874,22 @@ exports.DeviceSEState = void 0;
|
|
|
1577
1874
|
DeviceSEState[DeviceSEState["APP_FACTORY"] = 51] = "APP_FACTORY";
|
|
1578
1875
|
DeviceSEState[DeviceSEState["APP"] = 85] = "APP";
|
|
1579
1876
|
})(exports.DeviceSEState || (exports.DeviceSEState = {}));
|
|
1877
|
+
exports.DevOnboardingStage = void 0;
|
|
1878
|
+
(function (DevOnboardingStage) {
|
|
1879
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_UNKNOWN"] = 0] = "DEV_ONBOARDING_STAGE_UNKNOWN";
|
|
1880
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_SAFETY_CHECK"] = 1] = "DEV_ONBOARDING_STAGE_SAFETY_CHECK";
|
|
1881
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_PERSONALIZATION"] = 2] = "DEV_ONBOARDING_STAGE_PERSONALIZATION";
|
|
1882
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_SELECT_SETUP_METHOD"] = 3] = "DEV_ONBOARDING_STAGE_SELECT_SETUP_METHOD";
|
|
1883
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_NEW_DEVICE"] = 4] = "DEV_ONBOARDING_STAGE_NEW_DEVICE";
|
|
1884
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_SELECT_RESTORE_METHOD"] = 5] = "DEV_ONBOARDING_STAGE_SELECT_RESTORE_METHOD";
|
|
1885
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_RESTORE_MNEMONIC"] = 6] = "DEV_ONBOARDING_STAGE_RESTORE_MNEMONIC";
|
|
1886
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_RESTORE_SEEDCARD"] = 7] = "DEV_ONBOARDING_STAGE_RESTORE_SEEDCARD";
|
|
1887
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_WALLET_READY"] = 8] = "DEV_ONBOARDING_STAGE_WALLET_READY";
|
|
1888
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_SEEDCARD_BACKUP_PROMPT"] = 9] = "DEV_ONBOARDING_STAGE_SEEDCARD_BACKUP_PROMPT";
|
|
1889
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_SELECT_SEEDCARD_BACKUP_METHOD"] = 10] = "DEV_ONBOARDING_STAGE_SELECT_SEEDCARD_BACKUP_METHOD";
|
|
1890
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_SEEDCARD_BACKUP"] = 11] = "DEV_ONBOARDING_STAGE_SEEDCARD_BACKUP";
|
|
1891
|
+
DevOnboardingStage[DevOnboardingStage["DEV_ONBOARDING_STAGE_DONE"] = 12] = "DEV_ONBOARDING_STAGE_DONE";
|
|
1892
|
+
})(exports.DevOnboardingStage || (exports.DevOnboardingStage = {}));
|
|
1580
1893
|
|
|
1581
1894
|
var messages = /*#__PURE__*/Object.freeze({
|
|
1582
1895
|
__proto__: null,
|
|
@@ -1643,13 +1956,15 @@ var messages = /*#__PURE__*/Object.freeze({
|
|
|
1643
1956
|
get WallpaperTarget () { return exports.WallpaperTarget; },
|
|
1644
1957
|
get MoneroNetworkType () { return exports.MoneroNetworkType; },
|
|
1645
1958
|
get ViewTipType () { return exports.ViewTipType; },
|
|
1959
|
+
get ViewSignLayout () { return exports.ViewSignLayout; },
|
|
1646
1960
|
get DeviceRebootType () { return exports.DeviceRebootType; },
|
|
1647
1961
|
get DeviceFirmwareTargetType () { return exports.DeviceFirmwareTargetType; },
|
|
1648
1962
|
get DeviceFirmwareUpdateTaskStatus () { return exports.DeviceFirmwareUpdateTaskStatus; },
|
|
1649
1963
|
get DeviceFactoryAck () { return exports.DeviceFactoryAck; },
|
|
1650
1964
|
get DeviceType () { return exports.DeviceType; },
|
|
1651
1965
|
get DeviceSeType () { return exports.DeviceSeType; },
|
|
1652
|
-
get DeviceSEState () { return exports.DeviceSEState; }
|
|
1966
|
+
get DeviceSEState () { return exports.DeviceSEState; },
|
|
1967
|
+
get DevOnboardingStage () { return exports.DevOnboardingStage; }
|
|
1653
1968
|
});
|
|
1654
1969
|
|
|
1655
1970
|
protobuf__namespace.util.Long = Long__default["default"];
|
|
@@ -1662,7 +1977,10 @@ var index = {
|
|
|
1662
1977
|
ProtocolV2,
|
|
1663
1978
|
PROTOCOL_V2_SYS_MESSAGE_THRESHOLD,
|
|
1664
1979
|
ProtocolV2FrameAssembler,
|
|
1980
|
+
ProtocolV2LinkManager,
|
|
1981
|
+
ProtocolV2SequenceCursor,
|
|
1665
1982
|
ProtocolV2Session,
|
|
1983
|
+
ProtocolV2UsbTransportBase,
|
|
1666
1984
|
bytesToHex,
|
|
1667
1985
|
concatUint8Arrays,
|
|
1668
1986
|
createMessageFromName,
|
|
@@ -1684,6 +2002,8 @@ exports.PROTOCOL_V1_MESSAGE_HEADER_SIZE = PROTOCOL_V1_MESSAGE_HEADER_SIZE;
|
|
|
1684
2002
|
exports.PROTOCOL_V1_REPORT_ID = PROTOCOL_V1_REPORT_ID;
|
|
1685
2003
|
exports.PROTOCOL_V1_USB_PACKET_SIZE = PROTOCOL_V1_USB_PACKET_SIZE;
|
|
1686
2004
|
exports.PROTOCOL_V2_BLE_FILE_CHUNK_SIZE = PROTOCOL_V2_BLE_FILE_CHUNK_SIZE;
|
|
2005
|
+
exports.PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE = PROTOCOL_V2_BLE_FILE_READ_CHUNK_SIZE;
|
|
2006
|
+
exports.PROTOCOL_V2_BLE_FRAME_MAX_BYTES = PROTOCOL_V2_BLE_FRAME_MAX_BYTES;
|
|
1687
2007
|
exports.PROTOCOL_V2_CHANNEL_BLE_UART = PROTOCOL_V2_CHANNEL_BLE_UART;
|
|
1688
2008
|
exports.PROTOCOL_V2_CHANNEL_SOCKET = PROTOCOL_V2_CHANNEL_SOCKET;
|
|
1689
2009
|
exports.PROTOCOL_V2_CHANNEL_USB = PROTOCOL_V2_CHANNEL_USB;
|
|
@@ -1696,7 +2016,10 @@ exports.PROTOCOL_V2_WRITE_WATCHDOG_TIMEOUT_MS = PROTOCOL_V2_WRITE_WATCHDOG_TIMEO
|
|
|
1696
2016
|
exports.ProtocolV1 = ProtocolV1;
|
|
1697
2017
|
exports.ProtocolV2 = ProtocolV2;
|
|
1698
2018
|
exports.ProtocolV2FrameAssembler = ProtocolV2FrameAssembler;
|
|
2019
|
+
exports.ProtocolV2LinkManager = ProtocolV2LinkManager;
|
|
2020
|
+
exports.ProtocolV2SequenceCursor = ProtocolV2SequenceCursor;
|
|
1699
2021
|
exports.ProtocolV2Session = ProtocolV2Session;
|
|
2022
|
+
exports.ProtocolV2UsbTransportBase = ProtocolV2UsbTransportBase;
|
|
1700
2023
|
exports.bytesToHex = bytesToHex;
|
|
1701
2024
|
exports.concatUint8Arrays = concatUint8Arrays;
|
|
1702
2025
|
exports["default"] = index;
|
|
@@ -2,6 +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 { isAckFrame } from './v2';
|
|
5
6
|
import type { Root } from 'protobufjs/light';
|
|
6
7
|
import type { ProtocolV2DebugLogger } from './v2';
|
|
7
8
|
export declare const PROTOCOL_V2_SYS_MESSAGE_THRESHOLD = 60000;
|
|
@@ -29,6 +30,7 @@ export declare const ProtocolV1: {
|
|
|
29
30
|
decodeMessage: typeof decodeV1Message;
|
|
30
31
|
};
|
|
31
32
|
export declare const ProtocolV2: {
|
|
33
|
+
isAckFrame: typeof isAckFrame;
|
|
32
34
|
encodeFrame(schemas: ProtocolV2Schemas, name: string, data: Record<string, unknown>, options?: ProtocolV2FrameOptions): Uint8Array;
|
|
33
35
|
decodeFrame(schemas: ProtocolV2Schemas, frame: Uint8Array, options?: Pick<ProtocolV2FrameOptions, 'logger' | 'logPrefix' | 'context'>): {
|
|
34
36
|
message: {
|
|
@@ -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;
|
|
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,EAAqD,UAAU,EAAE,MAAM,MAAM,CAAC;AAErF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,MAAM,CAAC;AAElD,eAAO,MAAM,iCAAiC,QAAQ,CAAC;AAEvD,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAsCF,eAAO,MAAM,UAAU;;;;;;;;;;CAOtB,CAAC;AAEF,eAAO,MAAM,UAAU;;yBAIV,iBAAiB,QACpB,MAAM,QACN,OAAO,MAAM,EAAE,OAAO,CAAC,YACpB,sBAAsB;yBAkCtB,iBAAiB,SACnB,UAAU,YACR,KAAK,sBAAsB,EAAE,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;;;;;;;;;;CA4B5E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,KAAO,CAAC;AACnC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,eAAO,MAAM,SAAS,KAAO,CAAC;AAC9B,eAAO,MAAM,WAAW,OAAO,CAAC;AAChC,eAAO,MAAM,sBAAsB,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,KAAO,CAAC;AACnC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,eAAO,MAAM,SAAS,KAAO,CAAC;AAC9B,eAAO,MAAM,WAAW,OAAO,CAAC;AAChC,eAAO,MAAM,sBAAsB,IAAI,CAAC;AACxC,eAAO,MAAM,mBAAmB,IAAI,CAAC"}
|
|
@@ -4,5 +4,6 @@ export interface ProtoV2Frame {
|
|
|
4
4
|
pbPayload: Uint8Array;
|
|
5
5
|
seq: number;
|
|
6
6
|
}
|
|
7
|
+
export declare function isAckFrame(data: Uint8Array): boolean;
|
|
7
8
|
export declare function decodeFrame(data: Uint8Array, debugOptions?: ProtocolV2FrameDebugOptions): ProtoV2Frame;
|
|
8
9
|
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/decode.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,WAAW,YAAY;IAE3B,aAAa,EAAE,MAAM,CAAC;IAEtB,SAAS,EAAE,UAAU,CAAC;IAEtB,GAAG,EAAE,MAAM,CAAC;CACb;AAYD,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,YAAY,CAAC,EAAE,2BAA2B,GACzC,YAAY,CA+
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/decode.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAE3D,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;AAYD,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,YAAY,CAAC,EAAE,2BAA2B,GACzC,YAAY,CA+Bd"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { MessageFromOneKey, TransportCallOptions } from '../../types';
|
|
2
|
+
import type { ProtocolV2CallContext, ProtocolV2Schemas, ProtocolV2SessionOptions } from './session';
|
|
3
|
+
export type ProtocolV2LinkErrorClassification = 'link-fatal' | 'recoverable';
|
|
4
|
+
export interface ProtocolV2LinkAdapter {
|
|
5
|
+
router: number;
|
|
6
|
+
maxFrameBytes?: number;
|
|
7
|
+
generation: number;
|
|
8
|
+
prepareCall(context: ProtocolV2CallContext): Promise<void> | void;
|
|
9
|
+
writeFrame(frame: Uint8Array, context: ProtocolV2CallContext): Promise<void>;
|
|
10
|
+
readFrame(context: ProtocolV2CallContext): Promise<Uint8Array>;
|
|
11
|
+
reset(reason: string): Promise<void> | void;
|
|
12
|
+
logger?: ProtocolV2SessionOptions['logger'];
|
|
13
|
+
logPrefix?: string;
|
|
14
|
+
createTimeoutError?: ProtocolV2SessionOptions['createTimeoutError'];
|
|
15
|
+
}
|
|
16
|
+
export type ProtocolV2LinkManagerOptions<Key> = {
|
|
17
|
+
getSchemas: () => ProtocolV2Schemas;
|
|
18
|
+
classifyError: (error: unknown) => ProtocolV2LinkErrorClassification;
|
|
19
|
+
onLinkInvalidated?: (key: Key, reason: string) => Promise<void> | void;
|
|
20
|
+
};
|
|
21
|
+
export declare class ProtocolV2LinkManager<Key> {
|
|
22
|
+
private readonly links;
|
|
23
|
+
private readonly sequences;
|
|
24
|
+
private readonly callQueues;
|
|
25
|
+
private readonly options;
|
|
26
|
+
constructor(options: ProtocolV2LinkManagerOptions<Key>);
|
|
27
|
+
call(key: Key, createAdapter: () => ProtocolV2LinkAdapter, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<MessageFromOneKey>;
|
|
28
|
+
invalidateLink(key: Key, reason: string): Promise<void>;
|
|
29
|
+
invalidateAllLinks(reason: string): Promise<void>;
|
|
30
|
+
dispose(reason: string): Promise<void>;
|
|
31
|
+
private getOrCreateLink;
|
|
32
|
+
private executeCall;
|
|
33
|
+
private clearSettledCallQueue;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=link-manager.d.ts.map
|
|
@@ -0,0 +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,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC5C,MAAM,CAAC,EAAE,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,wBAAwB,CAAC,oBAAoB,CAAC,CAAC;CACrE;AAED,MAAM,MAAM,4BAA4B,CAAC,GAAG,IAAI;IAC9C,UAAU,EAAE,MAAM,iBAAiB,CAAC;IACpC,aAAa,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,iCAAiC,CAAC;IACrE,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,KAAK,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence-cursor.d.ts","sourceRoot":"","sources":["../../../src/protocols/v2/sequence-cursor.ts"],"names":[],"mappings":"AAEA,qBAAa,wBAAwB;IACnC,OAAO,CAAC,OAAO,CAAK;IAEpB,IAAI,IAAI,MAAM;CAIf"}
|