@freesignal/protocol 0.5.4 → 0.5.6
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/dist/types.d.ts +1 -2
- package/dist/types.js +5 -6
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -92,7 +92,7 @@ export interface SignedDatagram extends Datagram {
|
|
|
92
92
|
signature: string;
|
|
93
93
|
}
|
|
94
94
|
export declare class DatagramHeader implements Encodable {
|
|
95
|
-
|
|
95
|
+
static readonly headerLength: number;
|
|
96
96
|
readonly id: string;
|
|
97
97
|
readonly version: number;
|
|
98
98
|
readonly sender: string;
|
|
@@ -113,7 +113,6 @@ export declare class Datagram implements Encodable, DatagramHeader {
|
|
|
113
113
|
private _createdAt;
|
|
114
114
|
private _payload?;
|
|
115
115
|
private _signature?;
|
|
116
|
-
private static headerOffset;
|
|
117
116
|
constructor(sender: Uint8Array | string, receiver: Uint8Array | string, protocol: Protocols, payload?: Uint8Array | Encodable);
|
|
118
117
|
get id(): string;
|
|
119
118
|
get version(): number;
|
package/dist/types.js
CHANGED
|
@@ -247,10 +247,10 @@ class DatagramHeader {
|
|
|
247
247
|
this.id = crypto_1.default.UUID.stringify(data.subarray(2, 18));
|
|
248
248
|
this.createdAt = (0, utils_1.bytesToNumber)(data.subarray(18, 26));
|
|
249
249
|
this.sender = (0, utils_1.decodeBase64)(data.subarray(26, 26 + crypto_1.default.EdDSA.publicKeyLength));
|
|
250
|
-
this.receiver = (0, utils_1.decodeBase64)(data.subarray(26 + crypto_1.default.EdDSA.publicKeyLength, DatagramHeader.
|
|
250
|
+
this.receiver = (0, utils_1.decodeBase64)(data.subarray(26 + crypto_1.default.EdDSA.publicKeyLength, DatagramHeader.headerLength));
|
|
251
251
|
}
|
|
252
252
|
toBytes() {
|
|
253
|
-
return (0, utils_1.concatBytes)((0, utils_1.numberToBytes)(this.version, 1), Protocols.encode(this.protocol, 1), crypto_1.default.UUID.parse(this.
|
|
253
|
+
return (0, utils_1.concatBytes)((0, utils_1.numberToBytes)(this.version, 1), Protocols.encode(this.protocol, 1), crypto_1.default.UUID.parse(this.id), (0, utils_1.numberToBytes)(this.createdAt, 8), (0, utils_1.encodeBase64)(this.sender), (0, utils_1.encodeBase64)(this.receiver));
|
|
254
254
|
}
|
|
255
255
|
static from(data) {
|
|
256
256
|
if (typeof data === 'string')
|
|
@@ -259,7 +259,7 @@ class DatagramHeader {
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
exports.DatagramHeader = DatagramHeader;
|
|
262
|
-
DatagramHeader.
|
|
262
|
+
DatagramHeader.headerLength = 26 + crypto_1.default.EdDSA.publicKeyLength * 2;
|
|
263
263
|
class Datagram {
|
|
264
264
|
constructor(sender, receiver, protocol, payload) {
|
|
265
265
|
this._id = crypto_1.default.UUID.generate().toString();
|
|
@@ -295,7 +295,7 @@ class Datagram {
|
|
|
295
295
|
return data.subarray(0, data.length - (this._signature ? crypto_1.default.EdDSA.signatureLength : 0));
|
|
296
296
|
}
|
|
297
297
|
get header() {
|
|
298
|
-
return this.toBytes().slice(0,
|
|
298
|
+
return this.toBytes().slice(0, DatagramHeader.headerLength);
|
|
299
299
|
}
|
|
300
300
|
toBytes() {
|
|
301
301
|
var _a, _b, _c;
|
|
@@ -335,7 +335,7 @@ class Datagram {
|
|
|
335
335
|
if (typeof data === 'string')
|
|
336
336
|
data = (0, utils_1.encodeBase64)(data);
|
|
337
337
|
if (data instanceof Uint8Array) {
|
|
338
|
-
const datagram = new Datagram((0, utils_1.decodeBase64)(data.subarray(26, 26 + crypto_1.default.EdDSA.publicKeyLength)), (0, utils_1.decodeBase64)(data.subarray(26 + crypto_1.default.EdDSA.publicKeyLength,
|
|
338
|
+
const datagram = new Datagram((0, utils_1.decodeBase64)(data.subarray(26, 26 + crypto_1.default.EdDSA.publicKeyLength)), (0, utils_1.decodeBase64)(data.subarray(26 + crypto_1.default.EdDSA.publicKeyLength, DatagramHeader.headerLength)), Protocols.decode(data.subarray(1, 2)), data.subarray(DatagramHeader.headerLength, data.length - (data[0] & 128 ? crypto_1.default.EdDSA.signatureLength : 0)));
|
|
339
339
|
datagram._version = data[0] & 127;
|
|
340
340
|
datagram._id = crypto_1.default.UUID.stringify(data.subarray(2, 18));
|
|
341
341
|
datagram._createdAt = (0, utils_1.bytesToNumber)(data.subarray(18, 26));
|
|
@@ -357,7 +357,6 @@ class Datagram {
|
|
|
357
357
|
}
|
|
358
358
|
exports.Datagram = Datagram;
|
|
359
359
|
Datagram.version = 1;
|
|
360
|
-
Datagram.headerOffset = 26 + crypto_1.default.EdDSA.publicKeyLength * 2;
|
|
361
360
|
class EncryptionHeader {
|
|
362
361
|
constructor(keys, nonce) {
|
|
363
362
|
this.nonce = nonce;
|