Pure functions reference¶
Base function primitives implemented in functional programming paradigm.
Mnemonic(BIP39)¶
-
generateEntropy
(A)¶ Generate 128-256 bits entropy bytes string
- Arguments
strength – (optional) entropy bits strength, by default is 256 bit.
hex – (optional) return HEX encoded string result flag, by default is
true
.sec256k1Order – (optional) if
true
ECDSA_SEC256K1_ORDER, by default istrue
.
- Returns
HEX encoded or bytes entropy string.
-
entropyToMnemonic
(e, A)¶ Convert entropy to mnemonic words string.
- Parameters
- e
random entropy HEX encoded or bytes string.
- Arguments
wordList – (optional) word list, by default is BIP39_WORDLIST
- Returns
mnemonic words string.
-
mnemonicToEntropy
(m, A)¶ Converting mnemonic words to entropy.
- Parameters
m: mnemonic words string (space separated)
- Arguments
wordList – (optional) word list, by default is BIP39_WORDLIST
checkSum – (optional) boolean, by default is``false``.
hex – (optional) return HEX encoded string result flag, by default is
false
.
- Returns
HEX encoded or bytes string.
-
mnemonicToSeed
(m, A)¶ Converting mnemonic words string to seed for uses in key derivation (BIP-0032).
- Parameters
- m
mnemonic words string (space separated)
- Arguments
passphrase – (optional) passphrase to get ability use 2FA approach for creating seed, by default is empty string.
checkSum – (optional) boolean, by default is
false
.hex – (optional) return HEX encoded string result flag, by default is
true
.
- Returns
HEX encoded or bytes string.
Private keys¶
-
createPrivateKey
(A)¶ Create private key
- Arguments
compressed – (optional) flag of private key compressed format, by default is
true
testnet – (optional) flag for testnet network, by default is
false
.wif – (optional) If set to
true
return key in WIF format, by default istrue
.hex – (optional) If set to
true
return key in HEX format, by default isfalse
.
- Returns
Private key in wif format (default), hex encoded byte string in case of hex flag or raw bytes string in case wif and hex flags set to
false
.
-
privateKeyToWif
(h, A)¶ Encode private key in HEX or RAW bytes format to WIF format.
- Parameters
- h
private key 32 byte string or HEX encoded string.
- Arguments
compressed – (optional) flag of public key compressed format, by default is
true
.testnet – (optional) flag for testnet network, by default is
false
.
- Returns
Private key in WIF format.
-
wifToPrivateKey
(h, A)¶ Decode WIF private key to bytes string or HEX encoded string
- Parameters
- h
private key in WIF format string.
- Arguments
hex – (optional) if set to
true
return key in HEX format, by default istrue
.
- Returns
Private key HEX encoded string or raw bytes string.
-
isWifValid
(wif)¶ Check is private key in WIF format string is valid.
- Parameters
- wif
private key in WIF format string.
- Returns
boolean.
Public keys¶
Warning
Using uncompressed public keys is deprecated in a new SEGWIT address format. To avoid potential future funds loss, users MUST NOT use uncompressed keys in version 0 witness programs. Use uncompressed keys only for backward compatibilitylegacy in legacy address format (PUBKEY, P2PKH).
-
privateToPublicKey
(privateKey, A)¶ Get public key from private key using ECDSA secp256k1
- Parameters
- privateKey
private key in WIF, HEX or bytes.
- Arguments
compressed – (optional) flag of public key compressed format, by default is
true
. In case private_key in WIF format, this flag is set in accordance with the key format specified in WIF string.hex – (optional) if set to
true
return key in HEX format, by default istrue
.
- Returns
33/65 bytes public key in HEX or bytes string.
-
isPublicKeyValid
(key)¶ Check public key is valid.
- Parameters
- key
public key in HEX or bytes string format.
- Returns
boolean.
Extended keys(BIP32)¶
-
createMasterXPrivateKey
(seed, A)¶ Create extended private key from seed
- Parameters
- seed
seed HEX or bytes string.
- Arguments
testnet – (optional) flag for testnet network, by default is
false
.base58 – (optional) return result as base58 encoded string, by default is
true
.
- Returns
extended private key in base58 string format.
-
xPrivateToXPublicKey
(xKey, A)¶ Get extended public key from extended private key using ECDSA secp256k1
- Parameters
- xKey
extended private key in base58, HEX or bytes string.
- Arguments
base58 – (optional) return result as base58 encoded string, by default is
true
.
- Returns
extended private key in base58 string format.
-
deriveXKey
(xKey, path, A)¶ Child Key derivation for extended private/public keys
- Parameters
- xKey
extended private/public in base58, HEX or bytes string format.
- path
list of derivation path levels. For hardened derivation use HARDENED_KEY flag.
- Arguments
base58 – (optional) return result as base58 encoded string, by default is
true
.subPath – (optional) boolean, by default is
false
.
- Returns
extended child private/public key in base58, HEX or bytes string format.
-
publicFromXPublicKey
(xPub, A)¶ Get public key from extended public key
- Parameters
- xPub
extended public in base58, HEX or bytes string format.
- Arguments
hex – (optional) return result as HEX encoded string, by default is
true
.
- Returns
public key in HEX or bytes string format.
-
privateFromXPrivateKey
(xPriv, A)¶ Get private key from extended private key
- Parameters
- xPriv
extended private in base58, HEX or bytes string format.
- Arguments
wif – (optional) return result as WIF format, by default is
true
.
- Returns
private key in HEX or bytes string format.
Addresses¶
-
hashToAddress
(ha, A)¶ Get address from public key/script hash. In case PUBKEY, P2PKH, P2PKH public key/script hash is SHA256+RIPEMD160,P2WSH script hash is SHA256.
- Parameters
- ha
public key hash or script hash in HEX or bytes string format.
- Arguments
testnet – (optional) flag for testnet network, by default is
false
.scriptHash – (optional) flag for script hash (P2SH address), by default is
false
.witnessVersion – (optional) witness program version, by default is 0, for legacy address format use null.
- Returns
address in base58 or bech32 format.
-
addressToHash
(a, A)¶ Get address hash from base58 or bech32 address format.
- Parameters
- a
address in base58 or bech32 format.
- Arguments
hex – (optional) If set to
true
return key in HEX format, by default isfalse
.
- Returns
script in HEX or bytes string.
-
publicKeyToAddress
(pubkey, A)¶ Get address from public key/script hash. In case PUBKEY, P2PKH, P2PKH public key/script hash is SHA256+RIPEMD160, P2WSH script hash is SHA256.
- Parameters
- pubkey
public key HEX or bytes string format.
- Arguments
testnet – (optional) flag for testnet network, by default is
false
.p2sh_p2wpkh – (optional) flag for P2WPKH inside P2SH address, by default is
false
.witnessVersion – (optional) witness program version, by default is 0, for legacy address format use null.
- Returns
address in base58 or bech32 format.
-
addressType
(a, A)¶ Get address type.
- Parameters
- a
address in base58 or bech32 format.
- Arguments
num – (optional) If set to
true
return type in numeric format, by default isfalse
.
- Returns
address type in string or numeric format.
-
addressToScript
(a, A)¶ Get public key script from address.
- Parameters
- a
address in base58 or bech32 format.
- Arguments
hex – (optional) If set to
true
return key in HEX format, by default isfalse
.
- Returns
public key script in HEX or bytes string.
-
isAddressValid
(address, A)¶ Check is address valid.
- Parameters
- address
address in base58 or bech32 format.
- Arguments
testnet – (optional) flag for testnet network, by default is
false
.
- Returns
boolean.
Script¶
-
decodeScript
(s, A)¶ Decode script to ASM format or to human readable OPCODES string.
- Parameters
- s
script in bytes string or HEX encoded string format.
- Arguments
asm – (optional) If set to
true
decode to ASM format, by default isfalse
.
- Returns
script in ASM format string or OPCODES string.
-
parseScript
(s, A)¶ Parse script and return script type, script address and required signatures count.
- Parameters
- s
script in bytes string or HEX encoded string format.
- Arguments
segwit – (optional) If set to
true
recognize P2WPKH and P2WSH sripts, by default istrue
.
- Returns
object:
nType - numeric script type
type - script type
addressHash - address hash in case address recognized
script - script if no address recognized
reqSigs - required signatures count
-
deleteFromScript
(script, subScript, A)¶ Delete OP_CODE or subscript from script.
- Parameters
- script
target script in bytes or HEX encoded string.
- subScript
sub_script which is necessary to remove from target script in bytes or HEX encoded string.
- Arguments
hex – (optional) return HEX encoded string result flag, by default is
false
.
- Returns
script in bytes or HEX encoded string corresponding to the format of target script.
-
scriptToHash
(s, A)¶ Encode script to hash HASH160 or SHA256 in dependency of the witness.
- Parameters
- s
script in bytes or HEX encoded string.
- Arguments
witness – (optional) If set to
true
return SHA256 hash for P2WSH, by default isfalse
.hex – (optional) return HEX encoded string result flag, by default is
true
.
- Returns
hash HASH160 or SHA256 of script in bytes or HEX encoded.
Signatures¶
-
verifySignature
(s, p, m)¶ Verify signature for message and given public key
- Parameters
- s
signature in bytes or HEX encoded string.
- p
public key in bytes or HEX encoded string.
- m
message in bytes or HEX encoded string.
- Returns
boolean.
-
signBitcoinMessage
(m, privateKey, A)¶ Sign message
- Parameters
- m
message in bytes or HEX encoded string.
- privateKey
private key (bytes, hex encoded string or WIF format)
- Arguments
base64 – (optional) If set to
true
return key signature BASE64 format, by default istrue
.
- Returns
DER or BASE64 encoded signature in bytes.
-
isValidSignatureEncoding
(s)¶ Check is valid signature encoded in DER format
- Parameters
- s
signature in bytes or HEX encoded string.
- Returns
boolean.
Hash encoding¶
-
rh2s
(s)¶ Encode raw transaction hash to HEX string with bytes order change
- Parameters
- raw_hash
transaction hash in bytes string.
- Returns
HEX encoded string.
-
s2rh
(s)¶ Decode HEX transaction hash to bytes with byte order change
- Parameters
- hash_string
HEX encoded string.
- Returns
bytes string.
Tools¶
-
encodeBase58
(m, A)¶ Encode to a base58-encoded string
- Parameters
- m
string to encode
- Arguments
encoding – (optional), by default ‘hex|utf8’.
checksum – (optional) boolean, by default is
false
.
- Returns
base58 string format.
-
decodeBase58
(m, A)¶ Decode a base58-encoding string
- Parameters
- m
string to decode
- Arguments
hex – (optional) return result as HEX encoded string, by default is
true
.checksum – (optional) boolean, by default is
false
.
- Returns
HEX or bytes string format.
-
intToBytes
(x, n, byte_order)¶ Convert integer to bytes.
- Parameters
- x
integer.
- n
bytes count.
- byte_order
(optional) byte order ‘big’ or ‘little’, by default is ‘little’.
- Returns
bytes.
-
intToVarInt
(i)¶ Convert integer to variable integer
- Parameters
- i
integer.
- Returns
bytes.
-
varIntToInt
(s, bn)¶ Convert variable integer to integer
- Parameters
- s
bytes variable integer.
- bn
(optional) BigNum flag, by default is
false
- Returns
integer.
-
varIntLen
(b)¶ Get variable integer length in bytes from integer value
- Parameters
- b
integer
- Returns
integer.
-
bytesToString
(bytes)¶ Convert bytes to string.
- Parameters
- bytes
bytes
- Returns
string.
-
stringToBytes
(str)¶ Convert string to bytes.
- Parameters
- str
string
- Returns
bytes.
-
hexToBytes
(hex)¶ Convert HEX string to bytes.
- Parameters
- hex
HEX string
- Returns
bytes.