@omegajs/id-encoding
v1.0.0
Published
Transforms Scroll keys between z-base32 and hexadecimal formats, enabling seamless conversion and compatibility.
Downloads
4
Readme
Scroll ID Encoding
@omegajs/id-encoding
Transforms Scroll keys between z-base32 and hexadecimal formats, enabling seamless conversion and compatibility.
Install Via L1FE's NPM
npm config set registry https://npm.l1fe.tech
npm install @omegajs/id-encoding
Install Via L1FE's Git Repository
git clone https://lab.l1fe.tech/omega/id-encoding.git
cd id-encoding
npm install
Usage
const { encode, decode, normalize } = require('@omegajs/id-encoding')
const id = encode(scroll.key) // (z-base32 String)
const hexEncoded = scroll.key.toString('hex')
const scroll = new Scroll(ram, decode(id))
const scroll2 = new Scroll(ram, decode(hexEncoded)) // Will also work with hex
const id2 = normalize(id)
const id3 = normalize(hexEncoded)
API
const id = encode(scrollKey)
Encodes a 32-byte Scroll key into a z-base32 id.
scrollKey
must be a Buffer or an ArrayBuffer.
const buf = decode(scrollId)
Decodes an id into a Scroll key.
If scrollId
is a 52-character String, it will be decoded as z-base32.
If scrollId
is a 64-character String, it will be decoded as hex.
If scrollId
is already a Buffer and is a valid id, it will be returned as-is.
const id = normalize(any)
Decodes and encodes the input any
to always return a z-base32 id.
isValid(any)
Returns a boolean indicating whether the key is a valid Scroll key (meaning that it can be decoded/normalised).
License
Apache-2.0