Class: BCURDecoder

bcur.BCURDecoder()

Decoder class for BC UR data.

Decodes a hex string from a collection of UR parts.

Designed for use by a calling application which is typically in a loop parsing an animated sequence of QR codes.

Constructor

new BCURDecoder()

Source:
Example
import {BCURDecoder} from "unchained-wallets";
const decoder = new BCURDecoder();

// Read data until the decoder is complete...
while (!decoder.isComplete()) {

  // Progress can be fed back to the calling application for visualization in its UI
  console.log(decoder.progress());  // {totalParts: 10, partsReceived; 3}

  // Application-defined function to obtain a single UR part string.
  const part = scanQRCode();
  decoder.receivePart(part);
}

// Check for an error
if (decoder.isSuccess()) {

  // Data can be passed back to the calling application
  console.log(decoder.data()); // "deadbeef"
  
} else {

  // Errors can be passed back to the calling application
  console.log(decoder.errorMessage());
}

Methods

data() → {string}

Returns the decoded data as a hex string.

Source:
Returns:

decoded data in hex or null if not successful

Type
string

errorMessage() → {string}

Returns the error message.

Source:
Returns:

the error message

Type
string

isComplete() → {bool}

Is this decoder complete?

Will return true if there was an error.

Source:
Returns:

Completion status

Type
bool

isSuccess() → {bool}

Was this decoder successful?

Will return false if completed because of an error.

Source:
Returns:

Success status

Type
bool

progress() → {object}

Returns the current progress of this decoder.

Source:
Returns:

An object with keys totalParts and partsReceived.

Type
object
Example
import {BCURDecoder} from "unchained-wallets";
const decoder = BCURDecoder();
console.log(decoder.progress())
// { totalParts: 0, partsReceived: 0 }

decoder.receivePart(part);
...
decoder.receivePart(part);
...
decoder.receivePart(part);
...
console.log(decoder.progress())
// { totalParts: 10, partsReceived: 3 }

receivePart(part) → {null}

Receive a new UR part.

It's OK to call this method multiple times for the same UR part.

Parameters:
Name Type Description
part string

the UR part, typically the contents of a QR code

Source:
Returns:

Nothing is returned.

Type
null

reset() → {null}

Reset this decoder.

Clears any error message and received parts and returns counts to zero.

Source:
Returns:

Nothing is returned.

Type
null