0.2.0 • Published 12 months ago

@screamingvoid/codecs v0.2.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
12 months ago

@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

0.2.0

12 months ago

0.1.3

12 months ago

0.1.2

12 months ago

0.1.1

12 months ago

0.1.0

12 months ago