JSPM

hypercore-id-encoding

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 38111
  • Score
    100M100P100Q152095F
  • License MIT

Convert Hypercore keys to/from z-base32 or hex

Package Exports

  • hypercore-id-encoding
  • hypercore-id-encoding/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hypercore-id-encoding) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hypercore-id-encoding

Encodes Hypercore keys into z-base32 ids, and decodes both hex/z-base32 strings.

npm install hypercore-id-encoding

Usage

const { encode, decode } = require('hypercore-id-encoding')

const id = encode(core.key) // (z-base32 String)
const hexEncoded = core.key.toString('hex')

const core = new Hypercore(ram, decode(id)) 
const core2 = new Hypercore(ram, decode(hexEncoded)) // Will also work with hex

API

const id = encode(hypercoreKey)

Encodes a 32-byte Hypercore key into a z-base32 id.

hypercoreKey must be a Buffer or an ArrayBuffer.

const buf = decode(hypercoreId)

Decodes an id into a Hypercore key.

hypercoreId must be a String.

If hypercoreId is a 52-character String, it will be decoded as z-base32.

If hypercoreId is a 64-character String, it will be decoded as hex.

License

MIT