berendsliedrecht / bearnet-ts

Unofficial fernet version 03 implementation using XChaCha20Poly1305

Home Page:https://www.npmjs.com/package/bearnet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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')

About

Unofficial fernet version 03 implementation using XChaCha20Poly1305

https://www.npmjs.com/package/bearnet

License:Apache License 2.0


Languages

Language:TypeScript 100.0%