Constructor
new BCURDecoder()
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.
Returns:
decoded data in hex or null
if not successful
- Type
- string
errorMessage() → {string}
Returns the error message.
Returns:
the error message
- Type
- string
isComplete() → {bool}
Is this decoder complete?
Will return true
if there was an error.
Returns:
Completion status
- Type
- bool
isSuccess() → {bool}
Was this decoder successful?
Will return false
if completed because of an error.
Returns:
Success status
- Type
- bool
progress() → {object}
Returns the current progress of this decoder.
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 |
Returns:
Nothing is returned.
- Type
- null
reset() → {null}
Reset this decoder.
Clears any error message and received parts and returns counts to zero.
Returns:
Nothing is returned.
- Type
- null