@hyperfrontend/network-protocol/node/packetpacket
Node.js-side packet types, builders, and validators.
A packet is either a plaintext UnencryptedPacket<T> (origin, target, and a Data<T> envelope) or the sealed WirePacket bytes that carry it. This entry point exposes createPacketBase and createUnencryptedPacket, the validators isValidOrigin, isValidTarget, isValidUnencryptedPacket, and isValidWirePacket, and the operation and drop types (PacketSealer, PacketOpener, PacketDrop, PacketDropHandler, PacketDropStage) that a session protocol and a channel's onDrop handler share. Origins and targets are UUID v4 strings. The /node/v3 and /node/v4 protocols convert between the two shapes; /browser/packet exports the same code, so packets cross runtime boundaries cleanly.
API Reference§
ƒ Functions
Parameters
Returns
PacketBaseExample
Creating a packet base
const base = createPacketBase(
'550e8400-e29b-41d4-a716-446655440000',
'6ba7b810-9dad-11d1-80b4-00c04fd430c8'
)
// => { origin: '550e8400-...', target: '6ba7b810-...' }createUnencryptedPacket<T>(origin: string, target: string, data: Data<T>): UnencryptedPacket<T>
Parameters
Returns
UnencryptedPacket<T>Example
Creating an unencrypted packet
const packet = createUnencryptedPacket(originId, targetId, await createData(pid, 1, { action: 'ping' }))
// => { origin, target, data: { pid, id, sequence, message, schema, schemaHash } }Parameters
| Name | Type | Description |
|---|---|---|
§origin | unknown | The value to validate as a packet origin |
Returns
booleanExample
Validating packet origins
isValidOrigin('550e8400-e29b-41d4-a716-446655440000')
// => true
isValidOrigin('not-a-uuid')
// => falseParameters
| Name | Type | Description |
|---|---|---|
§target | unknown | The value to validate as a packet target |
Returns
booleanExample
Validating packet targets
isValidTarget('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
// => true
isValidTarget('invalid')
// => falseParameters
| Name | Type | Description |
|---|---|---|
§packet | unknown | The value to check |
Returns
unknownUnencryptedPacketExample
Validating a packet before sealing
isValidUnencryptedPacket({ origin, target, data: { pid, id, sequence: 1, message: { action: 'ping' }, schema, schemaHash } })
// => trueParameters
| Name | Type | Description |
|---|---|---|
§packet | unknown | The value to check |
Returns
unknownUint8Array with at least one byteExample
Validating wire packets
isValidWirePacket(new Uint8Array([1, 2, 3]))
// => true
isValidWirePacket({ data: 'not binary' })
// => false◈ Interfaces
Properties
Properties
readonly direction:"inbound" | "outbound"outbound) or arriving (inbound)◆ Types
type Packet = UnencryptedPacket<T> | WirePackettype PacketDropHandler = (drop: PacketDrop) => voidtype PacketDropStage = "seal" | "open"type PacketOpener = (packet: WirePacket) => Promise<UnencryptedPacket<T>>type PacketSealer = (packet: UnencryptedPacket<T>) => Promise<WirePacket>type WirePacket = Uint8Array