- DefaultBroadcastDelegate
- DefaultSigningDelegate
- LedgerSigningDelegate
- ab2hexstring
- ab2str
- calInputCoins
- calculateRandomNumberHash
- calculateSwapID
- checkCoins
- checkNumber
- checkOutputs
- ensureHex
- hexXor
- hexstring2ab
- hexstring2str
- int2hex
- isHex
- num2VarInt
- num2hexstring
- reverseArray
- reverseHex
- sha256
- sha256ripemd160
- sha3
- str2ab
- str2hexstring
- convertObjectToSignBytes
- encodeArrayBinary
- encodeBinary
- encodeBinaryByteArray
- encodeBool
- encodeNumber
- encodeObjectBinary
- encodeString
- encodeTime
- marshalBinary
- marshalBinaryBare
js amino UnmarshalBinaryBare Functions
js amino UnmarshalBinaryLengthPrefixed Functions
- checkAddress
- decodeAddress
- encodeAddress
- generateKeyStore
- generateMnemonic
- generatePrivateKey
- generatePubKey
- generateRandomArray
- generateSignature
- getAddressFromPrivateKey
- getAddressFromPublicKey
- getPrivateKeyFromKeyStore
- getPrivateKeyFromMnemonic
- getPublicKey
- getPublicKeyFromPrivateKey
- verifySignature
▸ DefaultBroadcastDelegate(this: BncClient, signedTx: Transaction): Promise‹object›
The default broadcast delegate which immediately broadcasts a transaction.
Parameters:
| Name | Type | Description |
|---|---|---|
this |
BncClient | - |
signedTx |
Transaction | the signed transaction |
Returns: Promise‹object›
▸ DefaultSigningDelegate(this: BncClient, tx: Transaction, signMsg?: any): Promise‹Transaction›
The default signing delegate which uses the local private key.
Parameters:
| Name | Type | Description |
|---|---|---|
this |
BncClient | - |
tx |
Transaction | the transaction |
signMsg? |
any | the canonical sign bytes for the msg |
Returns: Promise‹Transaction›
▸ LedgerSigningDelegate(ledgerApp: LedgerApp, preSignCb: function, postSignCb: function, errCb: function, hdPath: number[]): typeof DefaultSigningDelegate
The Ledger signing delegate.
Parameters:
▪ ledgerApp: LedgerApp
▪ preSignCb: function
▸ (preSignCb: Buffer): void
Parameters:
| Name | Type |
|---|---|
preSignCb |
Buffer |
▪ postSignCb: function
▸ (pubKeyResp: PublicKey, sigResp: SignedSignature): void
Parameters:
| Name | Type |
|---|---|
pubKeyResp |
PublicKey |
sigResp |
SignedSignature |
▪ errCb: function
▸ (error: any): void
Parameters:
| Name | Type |
|---|---|
error |
any |
▪ hdPath: number[]
Returns: typeof DefaultSigningDelegate
▸ ab2hexstring(arr: any): string
Parameters:
| Name | Type |
|---|---|
arr |
any |
Returns: string
HEX string
▸ ab2str(buf: Uint8Array): void
Parameters:
| Name | Type |
|---|---|
buf |
Uint8Array |
Returns: void
ASCII string
▸ calInputCoins(inputs: Array‹object›, coins: Coin[]): void
sum corresponding input coin
Parameters:
| Name | Type | Description |
|---|---|---|
inputs |
Array‹object› | - |
coins |
Coin[] |
Returns: void
▸ calculateRandomNumberHash(randomNumber: string, timestamp: number): string
Computes sha256 of random number and timestamp
Parameters:
| Name | Type |
|---|---|
randomNumber |
string |
timestamp |
number |
Returns: string
sha256 result
▸ calculateSwapID(randomNumberHash: string, sender: string, senderOtherChain: string): string
Computes swapID
Parameters:
| Name | Type |
|---|---|
randomNumberHash |
string |
sender |
string |
senderOtherChain |
string |
Returns: string
sha256 result
▸ checkCoins(coins: Coin[]): void
basic validation of coins
Parameters:
| Name | Type | Description |
|---|---|---|
coins |
Coin[] |
Returns: void
▸ checkNumber(value: BigSource, name: string): void
validate the input number.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
value |
BigSource | - | |
name |
string | "input number" | - |
Returns: void
▸ checkOutputs(outputs: Transfer[]): void
validate the input number.
Parameters:
| Name | Type | Description |
|---|---|---|
outputs |
Transfer[] |
Returns: void
▸ ensureHex(str: string): void
Throws an error if input is not hexstring.
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string |
Returns: void
▸ hexXor(str1: string, str2: string): string
XORs two hexstrings
Parameters:
| Name | Type | Description |
|---|---|---|
str1 |
string | HEX string |
str2 |
string | HEX string |
Returns: string
XOR output as a HEX string
▸ hexstring2ab(str: string): Uint8Array‹›
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | HEX string |
Returns: Uint8Array‹›
▸ hexstring2str(hexstring: string): void
Parameters:
| Name | Type | Description |
|---|---|---|
hexstring |
string | HEX string |
Returns: void
ASCII string
▸ int2hex(num: number): string
convert an integer to big endian hex and add leading zeros
Parameters:
| Name | Type |
|---|---|
num |
number |
Returns: string
▸ isHex(str: string): boolean
Checks if input is a hexstring. Empty string is considered a hexstring.
example
isHex('0101') = true
isHex('') = true
isHex('0x01') = false
Parameters:
| Name | Type |
|---|---|
str |
string |
Returns: boolean
▸ num2VarInt(num: number): string
Converts a number to a variable length Int. Used for array length header
Parameters:
| Name | Type | Description |
|---|---|---|
num |
number | The number |
Returns: string
hexstring of the variable Int.
▸ num2hexstring(num: number, size: number, littleEndian: boolean): string
Converts a number to a big endian hexstring of a suitable size, optionally little endian
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
num |
number | - | - |
size |
number | 1 | The required size in bytes, eg 1 for Uint8, 2 for Uint16. Defaults to 1. |
littleEndian |
boolean | false | Encode the hex in little endian form |
Returns: string
▸ reverseArray(arr: any[]): Uint8Array‹›
Reverses an array. Accepts arrayBuffer.
Parameters:
| Name | Type |
|---|---|
arr |
any[] |
Returns: Uint8Array‹›
▸ reverseHex(hex: string): string
Reverses a HEX string, treating 2 chars as a byte.
example
reverseHex('abcdef') = 'efcdab'
Parameters:
| Name | Type | Description |
|---|---|---|
hex |
string | HEX string |
Returns: string
HEX string reversed in 2s.
▸ sha256(hex: string): string
Computes a single SHA256 digest.
Parameters:
| Name | Type | Description |
|---|---|---|
hex |
string | message to hash |
Returns: string
hash output
▸ sha256ripemd160(hex: string): string
Computes a SHA256 followed by a RIPEMD160.
Parameters:
| Name | Type | Description |
|---|---|---|
hex |
string | message to hash |
Returns: string
hash output
▸ sha3(hex: string): string
Computes a single SHA3 (Keccak) digest.
Parameters:
| Name | Type | Description |
|---|---|---|
hex |
string | message to hash |
Returns: string
hash output
▸ str2ab(str: string): Uint8Array‹›
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | ASCII string |
Returns: Uint8Array‹›
▸ str2hexstring(str: string): string
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | ASCII string |
Returns: string
HEX string
▸ convertObjectToSignBytes(obj: any): Buffer‹›
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
any | -- {object} |
Returns: Buffer‹›
bytes {Buffer}
▸ encodeArrayBinary(fieldNum: number | undefined, arr: any[], isByteLenPrefix?: undefined | false | true): Buffer‹›
Parameters:
| Name | Type | Description |
|---|---|---|
fieldNum |
number | undefined | object field index |
arr |
any[] | - |
isByteLenPrefix? |
undefined | false | true | - |
Returns: Buffer‹›
bytes of array
▸ encodeBinary(val: any, fieldNum?: undefined | number, isByteLenPrefix?: undefined | false | true): any
This is the main entrypoint for encoding all types in binary form.
Parameters:
| Name | Type |
|---|---|
val |
any |
fieldNum? |
undefined | number |
isByteLenPrefix? |
undefined | false | true |
Returns: any
binary of object.
▸ encodeBinaryByteArray(bytes: Buffer): Buffer‹›
prefixed with bytes length
Parameters:
| Name | Type |
|---|---|
bytes |
Buffer |
Returns: Buffer‹›
with bytes length prefixed
▸ encodeBool(b: boolean): any
encode bool
Parameters:
| Name | Type | Description |
|---|---|---|
b |
boolean |
Returns: any
▸ encodeNumber(num: number): any
encode number
Parameters:
| Name | Type | Description |
|---|---|---|
num |
number |
Returns: any
▸ encodeObjectBinary(obj: any, isByteLenPrefix?: undefined | false | true): Buffer‹›
Parameters:
| Name | Type |
|---|---|
obj |
any |
isByteLenPrefix? |
undefined | false | true |
Returns: Buffer‹›
with bytes length prefixed
▸ encodeString(str: string): Buffer‹›
encode string
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string |
Returns: Buffer‹›
▸ encodeTime(value: string | Date): Buffer‹›
encode time
Parameters:
| Name | Type | Description |
|---|---|---|
value |
string | Date |
Returns: Buffer‹›
▸ marshalBinary(obj: any): any
js amino MarshalBinary
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
any |
Returns: any
▸ marshalBinaryBare(obj: any): any
js amino MarshalBinaryBare
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
any |
Returns: any
js amino UnmarshalBinaryBare Functions
▸ unMarshalBinaryBare(bytes: Buffer, type: any): any
Parameters:
| Name | Type |
|---|---|
bytes |
Buffer |
type |
any |
Returns: any
js amino UnmarshalBinaryLengthPrefixed Functions
▸ unMarshalBinaryLengthPrefixed(bytes: Buffer, type: any): any
Parameters:
| Name | Type |
|---|---|
bytes |
Buffer |
type |
any |
Returns: any
▸ checkAddress(address: string, hrp: string): boolean
Checks whether an address is valid.
Parameters:
| Name | Type | Description |
|---|---|---|
address |
string | the bech32 address to decode |
hrp |
string | the prefix to check for the bech32 address |
Returns: boolean
▸ decodeAddress(value: string): Buffer
Decodes an address in bech32 format.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
string | the bech32 address to decode |
Returns: Buffer
▸ encodeAddress(value: string | Buffer, prefix: string, type: BufferEncoding): string
Encodes an address from input data bytes.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
value |
string | Buffer | - | the public key to encode |
prefix |
string | "tbnb" | the address prefix |
type |
BufferEncoding | "hex" | the output type (default: hex) |
Returns: string
▸ generateKeyStore(privateKeyHex: string, password: string): KeyStore
Generates a keystore object (web3 secret storage format) given a private key to store and a password.
Parameters:
| Name | Type | Description |
|---|---|---|
privateKeyHex |
string | the private key hexstring. |
password |
string | the password. |
Returns: KeyStore
the keystore object.
▸ generateMnemonic(): string
Generates mnemonic phrase words using random entropy.
Returns: string
▸ generatePrivateKey(len: number): string
Generates 32 bytes of random entropy
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
len |
number | PRIVKEY_LEN | output length (default: 32 bytes) |
Returns: string
entropy bytes hexstring
▸ generatePubKey(privateKey: Buffer): BasePoint
PubKey performs the point-scalar multiplication from the privKey on the generator point to get the pubkey.
Parameters:
| Name | Type |
|---|---|
privateKey |
Buffer |
Returns: BasePoint
PubKey
▸ generateRandomArray(length: number): ArrayBuffer
Generates an arrayBuffer filled with random bits.
Parameters:
| Name | Type | Description |
|---|---|---|
length |
number | Length of buffer. |
Returns: ArrayBuffer
▸ generateSignature(signBytesHex: string, privateKey: string | Buffer): Buffer
Generates a signature (64 byte <r,s>) for a transaction based on given private key.
Parameters:
| Name | Type | Description |
|---|---|---|
signBytesHex |
string | Unsigned transaction sign bytes hexstring. |
privateKey |
string | Buffer | The private key. |
Returns: Buffer
Signature. Does not include tx.
▸ getAddressFromPrivateKey(privateKeyHex: string, prefix?: undefined | string): string
Gets an address from a private key.
Parameters:
| Name | Type | Description |
|---|---|---|
privateKeyHex |
string | the private key hexstring |
prefix? |
undefined | string | the address prefix |
Returns: string
▸ getAddressFromPublicKey(publicKeyHex: string, prefix?: undefined | string): string
Gets an address from a public key hex.
Parameters:
| Name | Type | Description |
|---|---|---|
publicKeyHex |
string | the public key hexstring |
prefix? |
undefined | string | the address prefix |
Returns: string
▸ getPrivateKeyFromKeyStore(keystore: string, password: string): string
Gets a private key from a keystore given its password.
Parameters:
| Name | Type | Description |
|---|---|---|
keystore |
string | the keystore in json format |
password |
string | the password. |
Returns: string
▸ getPrivateKeyFromMnemonic(mnemonic: string, derive: boolean, index: number, password: string): string
Get a private key from mnemonic words.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
mnemonic |
string | - | the mnemonic phrase words |
derive |
boolean | true | derive a private key using the default HD path (default: true) |
index |
number | 0 | the bip44 address index (default: 0) |
password |
string | "" | according to bip39 |
Returns: string
hexstring
▸ getPublicKey(publicKey: string): BasePoint‹›
Parameters:
| Name | Type | Description |
|---|---|---|
publicKey |
string | Encoded public key |
Returns: BasePoint‹›
public key hexstring
▸ getPublicKeyFromPrivateKey(privateKeyHex: string): string
Calculates the public key from a given private key.
Parameters:
| Name | Type | Description |
|---|---|---|
privateKeyHex |
string | the private key hexstring |
Returns: string
public key hexstring
▸ verifySignature(sigHex: string, signBytesHex: string, publicKeyHex: string): boolean
Verifies a signature (64 byte <r,s>) given the sign bytes and public key.
Parameters:
| Name | Type | Description |
|---|---|---|
sigHex |
string | The signature hexstring. |
signBytesHex |
string | Unsigned transaction sign bytes hexstring. |
publicKeyHex |
string | The public key. |
Returns: boolean