/bearnet-ts

Unofficial fernet version 03 implementation using XChaCha20Poly1305

Primary LanguageTypeScriptApache License 2.0Apache-2.0

Bearnet

Name is partially inspired by hairnet

Implementation of fernet, but using XChaCha20Poly1305 (following unofficial version 3).

Cryptography

This library fully relies on @noble/ciphers which is an unaudited library, use with caution.

Usage

Bearnet generated key

import { Bearnet } from 'bearnet'

const b = new Bearnet()

const token = b.encode('hello')
const msg = b.decode(token, { returnAsString: true })

assert(msg === 'hello')

Or with your own key

import { Bearnet } from 'bearnet'

const b = new Bearnet(new Uint8Array(32).fill(0))

const token = b.encode('hello')
const msg = b.decode(token, { returnAsString: true })

assert(msg === 'hello')

Separated encoding and decoding

import { Bearnet } from 'bearnet'

const b = new Bearnet(new Uint8Array(32).fill(0))

const token = b.encode('hello')

Key and Token transfer happen OOB

import { Bearnet } from 'bearnet'

const b = new Bearnet(new Uint8Array(32).fill(0))

const msg = b.decode(token, { returnAsString: true })

assert(msg === 'hello')