@oh-my-pi/pi-wire 18.14.2 → 18.16.0
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/CHANGELOG.md +6 -0
- package/dist/types/index.d.ts +13 -0
- package/package.json +1 -1
- package/src/index.ts +24 -0
package/CHANGELOG.md
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -430,6 +430,19 @@ export declare const COLLAB_PROTO = 3;
|
|
|
430
430
|
export declare const INTENT_FIELD = "i";
|
|
431
431
|
/** Plaintext envelope prefix: `[4B uint32 BE peerId][sealed payload]`. */
|
|
432
432
|
export declare const ENVELOPE_HEADER_LENGTH = 4;
|
|
433
|
+
/**
|
|
434
|
+
* Prefix `sealed` with its envelope header. Host→relay: peerId 0 broadcasts to
|
|
435
|
+
* all guests, peerId N targets guest N. Guest→relay: always 0; the relay
|
|
436
|
+
* rewrites it to the sender's id.
|
|
437
|
+
*/
|
|
438
|
+
export declare function packEnvelope(peerId: number, sealed: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
439
|
+
/** Split an envelope into its peerId and sealed payload; `null` when shorter than the header. */
|
|
440
|
+
export declare function unpackEnvelope(data: Uint8Array): {
|
|
441
|
+
peerId: number;
|
|
442
|
+
payload: Uint8Array;
|
|
443
|
+
} | null;
|
|
444
|
+
/** Rewrite the peerId in place without copying the payload. */
|
|
445
|
+
export declare function rewriteEnvelopePeer(data: Uint8Array, peerId: number): void;
|
|
433
446
|
export declare const ROOM_ID_BYTES = 16;
|
|
434
447
|
/** AES-256-GCM room key; the seal key for every collab frame. */
|
|
435
448
|
export declare const ROOM_KEY_BYTES = 32;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -410,6 +410,30 @@ export const INTENT_FIELD = "i";
|
|
|
410
410
|
/** Plaintext envelope prefix: `[4B uint32 BE peerId][sealed payload]`. */
|
|
411
411
|
export const ENVELOPE_HEADER_LENGTH = 4;
|
|
412
412
|
|
|
413
|
+
/**
|
|
414
|
+
* Prefix `sealed` with its envelope header. Host→relay: peerId 0 broadcasts to
|
|
415
|
+
* all guests, peerId N targets guest N. Guest→relay: always 0; the relay
|
|
416
|
+
* rewrites it to the sender's id.
|
|
417
|
+
*/
|
|
418
|
+
export function packEnvelope(peerId: number, sealed: Uint8Array): Uint8Array<ArrayBuffer> {
|
|
419
|
+
const out = new Uint8Array(ENVELOPE_HEADER_LENGTH + sealed.byteLength);
|
|
420
|
+
new DataView(out.buffer).setUint32(0, peerId, false);
|
|
421
|
+
out.set(sealed, ENVELOPE_HEADER_LENGTH);
|
|
422
|
+
return out;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Split an envelope into its peerId and sealed payload; `null` when shorter than the header. */
|
|
426
|
+
export function unpackEnvelope(data: Uint8Array): { peerId: number; payload: Uint8Array } | null {
|
|
427
|
+
if (data.byteLength < ENVELOPE_HEADER_LENGTH) return null;
|
|
428
|
+
const peerId = new DataView(data.buffer, data.byteOffset, ENVELOPE_HEADER_LENGTH).getUint32(0, false);
|
|
429
|
+
return { peerId, payload: data.subarray(ENVELOPE_HEADER_LENGTH) };
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** Rewrite the peerId in place without copying the payload. */
|
|
433
|
+
export function rewriteEnvelopePeer(data: Uint8Array, peerId: number): void {
|
|
434
|
+
new DataView(data.buffer, data.byteOffset, ENVELOPE_HEADER_LENGTH).setUint32(0, peerId, false);
|
|
435
|
+
}
|
|
436
|
+
|
|
413
437
|
export const ROOM_ID_BYTES = 16;
|
|
414
438
|
|
|
415
439
|
/** AES-256-GCM room key; the seal key for every collab frame. */
|