0.2.0 • Published 12 months ago
@screamingvoid/codecs v0.2.0
@screamingvoid/codecs
Shared binary encodings and codecs for Void project.
Usage
import { ID } from "@screamingvoid/codecs"
const id = Buffer.allocUnsafe(32).fill(13)
// Passing base32 string to encode() returns same string
const base32 = ID.encode(id)
const base32 = ID.encode(id.toString("hex"))
// Passing 32 byte buffer to decode() returns same buffer
const buffer = ID.decode(base32)
const buffer = ID.decode(id.toString("hex"))
import { Cipher } from "@screamingvoid/codecs"
// Nonce is always expected to be 192 bits (24 bytes)
const nonce = Buffer.allocUnsafe(24)
random(nonce)
// Cipher can be any length buffer
const cipher = encrypt("Hello, World!", nonce, secret)
const buffer = Cipher.encode({ cipher, nonce })
const { cipher, nonce } = Cipher.decode(buffer)
import { ErrorCodec, makeError } from "@screamingvoid/codecs"
const buffer = ErrorCodec.encode(new Error("Something"))
const { message, code, stack } = ErrorCodec.decode(buffer)
const error = makeError({ message, code, stack })
License
Apache-2.0