coinlib library

A dart library for Peercoin using secp256k1 with corss-platform support

Classes

Address
Base class for all addresses. Encoded addresses for sub-classes are provided via the toString() method.
Base58Address
Base class for all addresses that use base58: P2PKHAddress and P2SHAddress.
Bech32
Encapsules 5-bit words that can be bech32 encoded and decoded. The 5-bit words may need to be further converted into the required data.
Bech32Address
Base class for addresses that use bech32: P2WPKHAddress and P2WSHAddress. Unknown witness programs are encoded via UnknownWitnessAddress.
BytesReader
Reads serialized data from a Uint8List. Throws an OutOfData exception if there is not enough data to read. If there is an error, the offset may be different than before.
BytesWriter
Writes serialized data to a Uint8List. Throws an OutOfData exception if there is not enough space in the bytes to write to.
CoinSelection
Represents a selection of inputs to fund a transaction. If the inputs provide sufficient value to cover the ouputs and fee for a transaction that isn't too large, ready shall be true and it is possible to obtain a signable transaction.
CoinUnit
Objects of this class represent a coin denomination with a given number of decimals. Use coin for whole coins with 6 decimal places and sats for the smallest unit with no decimal places.
ECDSAInputSignature
Encapsulates an ECDSA signature and hashType for inclusion in an Input.
ECDSARecoverableSignature
An ECDSARecoverableSignature is similar to an ECDSASignature but contains an additional byte that encodes a "recid" and compression flag that allows for the public key to be recovered from the message hash and signature.
ECDSASignature
ECPrivateKey
Represents an ECC private key for use with the secp256k1 curve
ECPublicKey
Represents an ECC public key on the secp256k1 curve that has an associated private key
HDKey
HDPrivateKey
Represents a private key with a chain code that can derive BIP32 keys.
HDPublicKey
Input
The base class for all inputs, providing the Input.match factory constructor to determine the appropriate subclass from a RawInput
InputCandidate
A candidate input to spend a UTXO with the UTXO value
InputSignature
The base for input signatures that carry a hashType.
LegacyInput
Inputs that are not witness inputs: P2PKHInput and P2SHMultisigInput.
LegacySignatureHasher
Produces signature hashes for legacy non-witness inputs.
LegacyWitnessInput
Represents v0 witness program inputs
MagicHash
MeasureWriter
Measures the serialized size of data written to it without writing to a Uint8List
MessageSignature
Encapsulates a signature for messages that are encoded to base-64. The base-64 representation can be obtained via toString().
MultisigProgram
Network
NUMSPublicKey
A "nothing up my sleeve" ECPublicKey that is created from a point with no known private key and tweaked with a scalar value named rTweak. The key is reproduceable from this scalar using fromRTweak(). Any of these keys have no known associted private key. Sharing the rTweak allows others to verify this. These keys can be used as Taproot internal keys where no key-path spending is desired.
OutPoint
Reference to an Output by transaction hash and index
Output
A transaction output that carries a value and program specifying how the value can be spent.
P2PKH
Pay-to-Public-Key-Hash program taking a 20-byte public key hash that can satisfy this script with a signature.
P2PKHAddress
P2PKHInput
An input for a Pay-to-Public-Key-Hash output (P2PKH). This contains the public key that should match the hash in the associated output. It is either signed or unsigned. The sign method can be used to sign the input with the corresponding ECPrivateKey or a signature can be added without checks using addSignature.
P2SH
Pay-to-Script-Hash program taking a 20-byte script hash for a redeem script.
P2SHAddress
P2SHMultisigInput
An input for a Pay-to-Script-Hash output (P2SH) with a multisig redeemScript and any number of required signatures. It can be signed with one of the associated ECPrivateKey objects using sign or an existing signature can be inserted with insertSignature.
P2TR
Pay-to-Taproot program taking a 32-byte Taproot tweaked key.
P2TRAddress
P2Witness
Arbitrary witness program
P2WPKH
Pay-to-Witness-Public-Key-Hash program taking a 20-byte public key hash that can satisfy this script with a signature provided as witness data.
P2WPKHAddress
P2WPKHInput
An input for a Pay-to-Witness-Public-Key-Hash output (P2WPKH). This contains the public key that should match the hash in the associated output. It is either signed or unsigned. The sign method can be used to sign the input with the corresponding ECPrivateKey or a signature can be added without checks using addSignature. Signature and public key data is stored in the witness data.
P2WSH
Pay-to-Witness-Script-Hash program taking a 32-byte script hash for a witness script whereby the witness script and other push data is to be provided as witness data.
P2WSHAddress
PKHInput
A mixin for Public Key Hash input types, providing the ECPublicKey and ECDSAInputSignature required in these inputs.
Program
An interface for programs that wrap a Script with associated functionality. This is seperated from the Script class to present high-level abstractions.
RawInput
A transaction input without any associated witness data that acts as the base for all other inputs as all inputs include a outpoint, script and sequence number.
RawProgram
A program that is not recognised and merely wraps a Script.
SchnorrInputSignature
Encapsulates a Schnorr signature and hashType for inclusion in a Taproot input.
SchnorrSignature
Script
ScriptOp
Represents a single operation or script pushdata
ScriptOpCode
Represents a ScriptOp that is an op code
ScriptPushData
Represents a ScriptOp that is a pushdata
ScriptPushDataMatcher
Provides comparison with ScriptPushData of a particular size.
SigHashType
Encapsulates the signature hash type to be used for an input signature. Signatures may sign different output and inputs to allow for transaction modifications. To sign an entire transaction the all constructor should be used.
TapBranch
Takes two child nodes within the MAST tree.
TapLeaf
A leaf in the MAST tree representing the Tapscript script.
TapNode
A node in the MAST tree, either a TapBranch or TapLeaf.
Taproot
This class encapsulates the construction of Taproot tweaked keys given an internal key and MAST consisting of Tapscript leaves constructed with TapBranch and TapLeaf objects.
TaprootInput
Represents v1 Taproot program inputs
TaprootKeyInput
A TaprootInput which spends using the key-path
TaprootScriptInput
A TaprootInput which spends using the script-path for 0xc0 version Tapscripts. There is no signing logic and sign() is not implemented. Subclasses should handle signing. createScriptSignature can be used to create signatures as necessary. Insertion of signatures and other data can be done manually via updateStack. These signatures must be handled by the consumer and will not be filtered upon a transaction update.
TaprootSignatureHasher
Produces signature hashes for taproot inputs
Transaction
Allows construction and signing of Peercoin transactions including those with witness data.
UnknownWitnessAddress
This address type is for all bech32 addresses that do not match known witness versions.
WIF
Encapsulates a ECPrivateKey and version that can be encoded or decoded in the Wallet Import Format (WIF). toString can be used to obtain the encoded WIF string.
WitnessInput
The base-class for all witness inputs
WitnessSignatureHasher
Produces signature hashes for non-taproot witness inputs

Enums

Bech32Type

Mixins

Writable
Classes that use this mixin are serializable to a Writer via write and return cached bytes via toBytes. These classes should be immutable as the bytes are written to only once.
Writer
Methods to handle the writing of data

Properties

alphabet String
final
scriptOpCodeToName Map<int, String>
final
scriptOpNameToCode Map<String, int>
final

Functions

base58Decode(String b58) Uint8List
Decodes a checksumed base58 string. This will throw a InvalidBase58 exception if the base58 encoding is invalid, or InvalidBase58Checksum if the checksum is wrong.
base58Encode(Uint8List data) String
Encodes a checksumed base58 string
bytesEqual(Uint8List a, Uint8List b) bool
Determines if two Uint8List lists are equal
bytesToHex(Uint8List bytes) String
checkBytes(Uint8List bytes, int length, {String name = "Bytes"}) Uint8List
Throws an ArgumentError if the bytes are not of the required length and returns the bytes.
compareBytes(Uint8List a, Uint8List b) int
Compares two Uint8List bytes from the left-most to right-most byte. If all bytes are the same apart from one list being longer, the shortest list comes first.
convertBits(List<int> data, int from, int to, bool pad) List<int>?
Converts data from "from" bits to "to" bits with optional padding (pad). Returns the new data or null if conversion was not possible. Used to convert to and from the 5-bit words for bech32.
copyCheckBytes(Uint8List bytes, int length, {String name = "Bytes"}) Uint8List
Throws an ArgumentError if the bytes are not of the required length and returns a copy of the bytes.
generateRandomBytes(int size) Uint8List
Generates random bytes using a CSPRNG Tested with the ent command
getTaggedHasher(String tag) Uint8List Function(Uint8List msg)
hash160(Uint8List msg) Uint8List
hexToBytes(String hex) Uint8List
hmacSha512(Uint8List key, Uint8List msg) Uint8List
hrpValid(String hrp) bool
Returns true if a bech32 hrp uses valid characters.
insertRandom<T>(List<T> list, T element) List<T>
loadCoinlib() Future<void>
sha256DoubleHash(Uint8List msg) Uint8List
sha256Hash(Uint8List msg) Uint8List