BC-UR
This repository is an implementation of the BC-UR encoding, following the C++ implementation and trying to provide a similar API for Javascript/Typescript usage.
Installing
To install, run:
yarn add @ngraveio/bc-ur
Quick Start
Encode a message
import {UR, UREncoder} from '@ngraveio/bc-ur'
const message = {any: 'property'}
const messageBuffer = Buffer.from(JSON.stringify(message))
const ur = UR.fromBuffer(messageBuffer)
const maxFragmentLength = 200
const firstSeqNum = 0
const encoder = new UREncoder(ur, maxFragmentLength, firstSeqNum)
while(!stop) {
let part = encoder.nextPart()
displayPart(part)
}
Decode a message
import {URDecoder} from '@ngraveio/bc-ur'
const decoder = new URDecoder()
do {
const part = scanQRCode()
decoder.receivePart(part)
} while (!decoder.isComplete())
if (decoder.isSuccess()) {
const ur = decoder.resultUR()
const decoded = ur.decodeCBOR()
const originalMessage = JSON.parse(decoded.toString())
}
else {
const error = decoder.resultError()
console.log('Error found while decoding', error)
handleError(error)
}