@burstjs/util
Useful utilities and tools for building Burstcoin applications
Installation
@burstjs/http
can be used with NodeJS or Web. Two formats are available
Using with NodeJS and/or modern web frameworks
Install using npm:
npm install @burstjs/util
or using yarn:
yarn add @burstjs/util
Example
import {convertNumberToNQTString} from '@burstjs/util'
const value = convertNumberToNQTString(1000)
console.log(value)
<script>
Using in classic Each package is available as bundled standalone library using IIFE.
This way burstJS can be used also within <script>
-Tags.
This might be useful for Wordpress and/or other PHP applications.
Just import the package using the HTML <script>
tag.
<script src='https://cdn.jsdelivr.net/npm/@burstjs/util/dist/util.crypto.min.js'></script>
Example
const value = b$util.convertNumberToNQTString(1000)
console.log(value)
See more here:
@burstjs/util Online Documentation
API Reference
Modules
- util
A Value Object to facilitate Burst Timestamp conversions.
- util
Enum to determine the representation format of [BurstValue] string
- util
-
A Value Object to facilitate BURST and Planck conversions/calculations.
Note: This class uses a big number representation (ES5 compatible) under the hood, so number limits and numeric calculations are much more precise than JS number type
- util
Symbol/Character for BURST unit
- util
Symbol/Character for Planck (the smallest possible unit in Burstcoin)
- util
The smallest possible fee
- util
One Burst expressed in Planck
- util ⇒
Converts BURST-XXXX-XXXX-XXXX-XXXXX into numeric Id
-
util ⇒
string
Converts/Decodes a Base64 encoded string to string. UTF-8 is supported Inverse function [[convertStringToBase64String]]
util ⇒Converts a Burst/Block Time (seconds since genesis block) into Date
util ⇒Converts a Burst/Block Time (seconds since genesis block) into Unix Epoch Time (milliseconds since 01.01.1970)
-
util ⇒
string
Converts byte array to hexadecimal string Inverse operation of [[convertHexStringToByteArray]]
-
util ⇒
string
Converts a byte array into string Inverse function [[convertStringToByteArray]]
util ⇒Converts a Date into Burst/Block Time (seconds since genesis block)
- util ⇒
Arbitrary length decimal to hexadecimal conversion
- util ⇒
-
Toggles the endianess of a hex string.
0xBEEF
>0xEFBE
If string is little Endianess it turns into Big Endianess, and vice versaThis method is mainly used for Smart Contract messaging and data inspection
-
util ⇒
Array.<number>
Converts an hexadecimal string to byte array
- util ⇒
Arbitrary length hexadecimal to decimal conversion https://stackoverflow.com/questions/21667377/javascript-hexadecimal-string-to-decimal-string
-
util ⇒
string
Converts a Hexadecimally encoded string into String Inverse function [[convertStringToHexString]]
util ⇒Helper method to convert a Planck Value (BURST * 1E-8) String to BURST number
util ⇒- util ⇒
Encode a numeric id into BURST-XXXX-XXXX-XXXX-XXXXX
-
util ⇒
string
Converts/Encodes a String into Base64 (URI) encoded string. UTF-8 is supported. Inverse function [[convertBase64StringToString]]
-
util ⇒
Array.<number>
Converts a string into byte array Inverse function [[convertByteArrayToString]]
-
util ⇒
string
Converts/Encode a String into Hexadecimally encoded Inverse function [[convertHexStringToString]]
- util ⇒
-
Creates a deeplink according the CIP22 spec
burst.[domain]://v1?action=[action]&payload=[encodedData]
Deeplinks are a way to call/open applications and do certain actions within it, e.g. Phoenix wallet can redirect to the "Send Burst" screen a fill out the form according the passed payload.
- util
-
util ⇒
boolean
-
util ⇒
boolean
Check for valid Burst address (format: BURST-XXXX-XXXX-XXXX-XXXXX, XXXX-XXXX-XXXX-XXXXX)
- util ⇒
-
Parses a deeplink according the CIP22 spec
burst.[domain]://v1?action=[action]&payload=[encodedData]
- util
util ⇒Sums various NQT values and returns in Burst
Constants
- MandatoryPattern
Original work Copyright (c) 2019 Burst Apps Team
Functions
util
A Value Object to facilitate Burst Timestamp conversions.
util
Enum to determine the representation format of [BurstValue] string
util
A Value Object to facilitate BURST and Planck conversions/calculations.
Note: This class uses a big number representation (ES5 compatible) under the hood, so number limits and numeric calculations are much more precise than JS number type
util
Symbol/Character for BURST unit
util
Symbol/Character for Planck (the smallest possible unit in Burstcoin)
util
The smallest possible fee
util
One Burst expressed in Planck
util ⇒
Converts BURST-XXXX-XXXX-XXXX-XXXXX into numeric Id
Returns:
The numeric id, or undefined if address is invalid
Param | Description |
---|---|
address | The BURST address |
string
util ⇒ Converts/Decodes a Base64 encoded string to string. UTF-8 is supported Inverse function [[convertStringToBase64String]]
Returns: string
-
The orginal string
Param | Description |
---|---|
b64 | The string to be decoded (either URI encoded or not) |
util ⇒
Deprecated
Converts a Burst/Block Time (seconds since genesis block) into Date
Returns:
Date
Param | Description |
---|---|
burstTimestamp | The numeric Id |
util ⇒
Deprecated
Converts a Burst/Block Time (seconds since genesis block) into Unix Epoch Time (milliseconds since 01.01.1970)
Returns:
Unix Epoch Time (milliseconds since 01.01.1970)
Param | Description |
---|---|
burstTimestamp | The numeric Id |
string
util ⇒ Converts byte array to hexadecimal string Inverse operation of [[convertHexStringToByteArray]]
Returns: string
-
A hex string representing the byte array input
Param | Description |
---|---|
bytes | The (unsigned) byte array to be converted |
uppercase | If true, converts hex string with uppercase characters (Default: false) |
string
util ⇒ Converts a byte array into string Inverse function [[convertStringToByteArray]]
Returns: string
-
The converted string
Param | Description |
---|---|
byteArray | The byte array to be converted |
startIndex | The starting index of array to be converted (Default: 0) |
length | The number of bytes to be considered, iff startIndex is given. If null the byte array's length is considered |
util ⇒
Deprecated
Converts a Date into Burst/Block Time (seconds since genesis block)
Returns:
The Burst Timestamp
Param | Description |
---|---|
date | The date to be converted |
util ⇒
Arbitrary length decimal to hexadecimal conversion
Returns:
A hexadecimal string
Note:: Negative numbers are expressed as Two's Complement (https://en.wikipedia.org/wiki/Two%27s_complement) Credits to AJ ONeal for the two's complements stuff https://coolaj86.com/articles/convert-decimal-to-hex-with-js-bigints/
Param | Description |
---|---|
decimal | A decimal string or BigNumber representation |
padding | If set the hex string will be padded to given number, 8 or 16 or more |
util ⇒
Toggles the endianess of a hex string.
0xBEEF
> 0xEFBE
If string is little Endianess it turns into Big Endianess, and vice versa
This method is mainly used for Smart Contract messaging and data inspection
Returns:
The converted string as hex string
Param | Description |
---|---|
hexString | The hex string to be converted |
Array.<number>
util ⇒ Converts an hexadecimal string to byte array
Returns: Array.<number>
-
An byte array representing the hexadecimal input
Param | Description |
---|---|
hex | The hexadecimal string to be converted |
util ⇒
Arbitrary length hexadecimal to decimal conversion https://stackoverflow.com/questions/21667377/javascript-hexadecimal-string-to-decimal-string
Returns:
A decimal string
Param | Description |
---|---|
hexStr | A hexadecimal string |
string
util ⇒ Converts a Hexadecimally encoded string into String Inverse function [[convertStringToHexString]]
Returns: string
-
The string represented by the Hex String
Param | Description |
---|---|
hex | The Hex string to be converted |
util ⇒
Deprecated
Helper method to convert a Planck Value (BURST * 1E-8) String to BURST number
Returns:
A number expressed in Burst (not NQT)
Throws:
-
exception if argument is invalid
Param | Description |
---|---|
amount | The amount in Planck (aka NQT) |
util ⇒
Deprecated
Returns:
a NQT number string
Param | Description |
---|---|
n | the number |
util ⇒
Encode a numeric id into BURST-XXXX-XXXX-XXXX-XXXXX
Returns:
the BURST address in Reed-Solomon encoding, or undefined if passed null, undefined
Param | Description |
---|---|
numericId | The numeric Id |
string
util ⇒ Converts/Encodes a String into Base64 (URI) encoded string. UTF-8 is supported. Inverse function [[convertBase64StringToString]]
Returns: string
-
The Base64 String representing the input string. The string is already URI encoded, i.e. can be used directly in browsers
Param | Description |
---|---|
str | The string to be converted |
isURICompatible | Determine whether the resulting string shall be URI compatible, or not. Default is |
Array.<number>
util ⇒ Converts a string into byte array Inverse function [[convertByteArrayToString]]
Returns: Array.<number>
-
A byte array representing the string input
Param | Description |
---|---|
str | The string to be converted |
string
util ⇒ Converts/Encode a String into Hexadecimally encoded Inverse function [[convertHexStringToString]]
Returns: string
-
The Hex String representing the input string
Param | Description |
---|---|
str | The Hex string to be converted |
util ⇒
Creates a deeplink according the CIP22 spec
burst.[domain]://v1?action=[action]&payload=[encodedData]
Deeplinks are a way to call/open applications and do certain actions within it, e.g. Phoenix wallet can redirect to the "Send Burst" screen a fill out the form according the passed payload.
Returns:
The Deeplink
See:
[[parseDeeplink]] as inverse function
Param | Type | Description |
---|---|---|
args | CreateDeeplinkArgs |
The arguments for the deeplink |
util
boolean
util ⇒ Returns: boolean
-
true, if is a valid address, else false
Internal: Check for valid Burst address (format: BURST-XXXX-XXXX-XXXX-XXXXX, XXXX-XXXX-XXXX-XXXXX)
Param | Type | Description |
---|---|---|
address | string |
The address |
boolean
util ⇒ Check for valid Burst address (format: BURST-XXXX-XXXX-XXXX-XXXXX, XXXX-XXXX-XXXX-XXXXX)
Returns: boolean
-
true, if is a valid address, else false
Param | Type | Description |
---|---|---|
address | string |
The address |
util ⇒
Parses a deeplink according the CIP22 spec
burst.[domain]://v1?action=[action]&payload=[encodedData]
Returns:
The parsed deeplink parts.
Throws:
-
Error if parsing fails
See:
[[createDeeplink]] as inverse function
Param | Type | Description |
---|---|---|
deeplink | string |
The deeplink to be parsed |
util
util ⇒
Deprecated
Sums various NQT values and returns in Burst
Returns:
The sum of all amounts in BURST
Param | Description |
---|---|
nqts | Variable amount list with NQT string |
MandatoryPattern
Original work Copyright (c) 2019 Burst Apps Team
twosComplementBinary(bn)
Kind: global function
Internal:
Param |
---|
bn |
encodePayload()
Kind: global function
Internal: