Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 1001 Bytes

README.md

File metadata and controls

34 lines (24 loc) · 1001 Bytes

Browser Network Crypto

Browser-compatible cryptographic helpers for Browser Network. It uses audited Noble primitives: secp256k1 signatures/ECDH, HKDF, and XChaCha20-Poly1305.

Installation

npm install @browser-network/crypto

For a script tag, load the UMD bundle. It exposes window.Bnc:

<script src="https://unpkg.com/@browser-network/crypto/umd/crypto.min.js"></script>

Usage

import * as Bnc from '@browser-network/crypto'

const secret = Bnc.generateSecret() // hexadecimal secp256k1 private key
const publicKey = Bnc.derivePubKey(secret)

const value = { message: 'hello' }
const signature = await Bnc.sign(secret, value)
const valid = await Bnc.verifySignature(value, signature, publicKey)

sign() uses canonical key-sorted JSON serialization. encrypt() and decrypt() authenticate ciphertext; decryption rejects altered or malformed input. A secret is an identity private key: never send it to peers, the Switchboard, or application servers.