Options
All
  • Public
  • Public/Protected
  • All
Menu

bitcoin-ts

Index

Enumerations

Interfaces

Type aliases

Variables

Functions

Object literals

Type aliases

AuthenticationInstruction

AuthenticationInstruction<Opcodes>: AuthenticationInstructionPush<Opcodes> | AuthenticationInstructionOperation<Opcodes>

A properly-formed instruction used by an AuthenticationVirtualMachine.

Type parameters

  • Opcodes

AuthenticationInstructions

AuthenticationInstructions<Opcodes>: Array<AuthenticationInstruction<Opcodes>>

Type parameters

  • Opcodes

Operation

Operation<ProgramState>: function

Operations define the behavior of an opcode in an InstructionSet.

Operations should be written as efficiently as possible, and may safely mutate the ProgramState. If needed, the AuthenticationVirtualMachine will clone the ProgramState before providing it to an operation.

Type parameters

  • ProgramState

Type declaration

    • (state: ProgramState): ProgramState
    • Parameters

      • state: ProgramState

      Returns ProgramState

ParsedAuthenticationInstruction

ParsedAuthenticationInstruction<Opcodes>: AuthenticationInstruction<Opcodes> | ParsedAuthenticationInstructionMalformed<Opcodes>

A potentially-malformed AuthenticationInstruction. If malformed is true, this could be either ParsedAuthenticationInstructionPushMalformedLength or ParsedAuthenticationInstructionPushMalformedData

If the final instruction is a push operation which requires more bytes than are available in the remaining portion of a serialized script, that instruction will have a malformed property with a value of true. .

Type parameters

  • Opcodes

ParsedAuthenticationInstructionMalformed

ParsedAuthenticationInstructionMalformed<Opcodes>: ParsedAuthenticationInstructionPushMalformedLength<Opcodes> | ParsedAuthenticationInstructionPushMalformedData<Opcodes>

Type parameters

  • Opcodes

ParsedAuthenticationInstructions

ParsedAuthenticationInstructions<Opcodes>: Array<AuthenticationInstruction<Opcodes> | ParsedAuthenticationInstruction<Opcodes>>

An array of authentication instructions which may end with a malformed instruction.

Implementation note: this type can be improved by only marking the final element as potentially malformed. This is waiting on: https://github.com/Microsoft/TypeScript/issues/1360

The following type can be used when it doesn't produce the error, A rest element must be last in a tuple type. [1256]:

export type ParsedAuthenticationInstructions<Opcodes = number> = [
  ...AuthenticationInstruction<Opcodes>,
  ParsedAuthenticationInstruction<Opcodes>
];

Type parameters

  • Opcodes

RecoveryId

RecoveryId: 0 | 1 | 2 | 3

TestState

TestState<ProgramState>: function

Type parameters

  • ProgramState

Type declaration

    • (state: ProgramState): boolean
    • Parameters

      • state: ProgramState

      Returns boolean

Variables

Const instructionSetBCHCurrentStrict

instructionSetBCHCurrentStrict: BCH_2019_05_STRICT = InstructionSetBCH.BCH_2019_05_STRICT

Const pushByteOpcodes

pushByteOpcodes: ReadonlyArray<OpcodesCommon> = [OpcodesCommon.OP_PUSHBYTES_1,OpcodesCommon.OP_PUSHBYTES_2,OpcodesCommon.OP_PUSHBYTES_3,OpcodesCommon.OP_PUSHBYTES_4,OpcodesCommon.OP_PUSHBYTES_5,OpcodesCommon.OP_PUSHBYTES_6,OpcodesCommon.OP_PUSHBYTES_7,OpcodesCommon.OP_PUSHBYTES_8,OpcodesCommon.OP_PUSHBYTES_9,OpcodesCommon.OP_PUSHBYTES_10,OpcodesCommon.OP_PUSHBYTES_11,OpcodesCommon.OP_PUSHBYTES_12,OpcodesCommon.OP_PUSHBYTES_13,OpcodesCommon.OP_PUSHBYTES_14,OpcodesCommon.OP_PUSHBYTES_15,OpcodesCommon.OP_PUSHBYTES_16,OpcodesCommon.OP_PUSHBYTES_17,OpcodesCommon.OP_PUSHBYTES_18,OpcodesCommon.OP_PUSHBYTES_19,OpcodesCommon.OP_PUSHBYTES_20,OpcodesCommon.OP_PUSHBYTES_21,OpcodesCommon.OP_PUSHBYTES_22,OpcodesCommon.OP_PUSHBYTES_23,OpcodesCommon.OP_PUSHBYTES_24,OpcodesCommon.OP_PUSHBYTES_25,OpcodesCommon.OP_PUSHBYTES_26,OpcodesCommon.OP_PUSHBYTES_27,OpcodesCommon.OP_PUSHBYTES_28,OpcodesCommon.OP_PUSHBYTES_29,OpcodesCommon.OP_PUSHBYTES_30,OpcodesCommon.OP_PUSHBYTES_31,OpcodesCommon.OP_PUSHBYTES_32,OpcodesCommon.OP_PUSHBYTES_33,OpcodesCommon.OP_PUSHBYTES_34,OpcodesCommon.OP_PUSHBYTES_35,OpcodesCommon.OP_PUSHBYTES_36,OpcodesCommon.OP_PUSHBYTES_37,OpcodesCommon.OP_PUSHBYTES_38,OpcodesCommon.OP_PUSHBYTES_39,OpcodesCommon.OP_PUSHBYTES_40,OpcodesCommon.OP_PUSHBYTES_41,OpcodesCommon.OP_PUSHBYTES_42,OpcodesCommon.OP_PUSHBYTES_43,OpcodesCommon.OP_PUSHBYTES_44,OpcodesCommon.OP_PUSHBYTES_45,OpcodesCommon.OP_PUSHBYTES_46,OpcodesCommon.OP_PUSHBYTES_47,OpcodesCommon.OP_PUSHBYTES_48,OpcodesCommon.OP_PUSHBYTES_49,OpcodesCommon.OP_PUSHBYTES_50,OpcodesCommon.OP_PUSHBYTES_51,OpcodesCommon.OP_PUSHBYTES_52,OpcodesCommon.OP_PUSHBYTES_53,OpcodesCommon.OP_PUSHBYTES_54,OpcodesCommon.OP_PUSHBYTES_55,OpcodesCommon.OP_PUSHBYTES_56,OpcodesCommon.OP_PUSHBYTES_57,OpcodesCommon.OP_PUSHBYTES_58,OpcodesCommon.OP_PUSHBYTES_59,OpcodesCommon.OP_PUSHBYTES_60,OpcodesCommon.OP_PUSHBYTES_61,OpcodesCommon.OP_PUSHBYTES_62,OpcodesCommon.OP_PUSHBYTES_63,OpcodesCommon.OP_PUSHBYTES_64,OpcodesCommon.OP_PUSHBYTES_65,OpcodesCommon.OP_PUSHBYTES_66,OpcodesCommon.OP_PUSHBYTES_67,OpcodesCommon.OP_PUSHBYTES_68,OpcodesCommon.OP_PUSHBYTES_69,OpcodesCommon.OP_PUSHBYTES_70,OpcodesCommon.OP_PUSHBYTES_71,OpcodesCommon.OP_PUSHBYTES_72,OpcodesCommon.OP_PUSHBYTES_73,OpcodesCommon.OP_PUSHBYTES_74,OpcodesCommon.OP_PUSHBYTES_75]

Const pushNumberOpcodes

pushNumberOpcodes: ReadonlyArray<OpcodesCommon> = [OpcodesCommon.OP_1NEGATE,OpcodesCommon.OP_1,OpcodesCommon.OP_2,OpcodesCommon.OP_3,OpcodesCommon.OP_4,OpcodesCommon.OP_5,OpcodesCommon.OP_6,OpcodesCommon.OP_7,OpcodesCommon.OP_8,OpcodesCommon.OP_9,OpcodesCommon.OP_10,OpcodesCommon.OP_11,OpcodesCommon.OP_12,OpcodesCommon.OP_13,OpcodesCommon.OP_14,OpcodesCommon.OP_15,OpcodesCommon.OP_16]

Functions

Const applyError

Const arithmeticOperations

  • arithmeticOperations<Opcodes, State, Errors>(flags: object): object

Const authenticationInstructionIsMalformed

Const authenticationInstructionsAreMalformed

Const authenticationInstructionsAreNotMalformed

Const base64ToBin

  • base64ToBin(base64Text: string): Uint8Array

Const bigIntToBinUint64LE

  • bigIntToBinUint64LE(value: bigint): Uint8Array
  • Return a BigInt as Uint64LE Uint8Array.

    Note: For valid results, value must be within the range representable by the specified number of bytes.

    Parameters

    • value: bigint

      the number to convert into a little-endian Uint8Array

    Returns Uint8Array

Const bigIntToBinUintLE

  • bigIntToBinUintLE(value: bigint, bytes: number): Uint8Array
  • Return a BigInt as little-endian Uint8Array.

    Note: For valid results, value must be between 0 and 0xffff ffff ffff ffff.

    Parameters

    • value: bigint

      the number to convert into a little-endian Uint8Array

    • bytes: number

      the byte length of the Uint8Array to return

    Returns Uint8Array

Const bigIntToBitcoinVarInt

  • bigIntToBitcoinVarInt(value: bigint): Uint8Array
  • Encode a BigInt as a Bitcoin VarInt (Variable-length integer).

    Note: the maximum value of a Bitcoin VarInt is 0xffff ffff ffff ffff. This method will produce invalid results for larger values.

    Parameters

    • value: bigint

      the BigInt to encode (no larger than 0xffff ffff ffff ffff)

    Returns Uint8Array

Const bigIntToScriptNumber

  • bigIntToScriptNumber(integer: bigint): Uint8Array
  • Convert a BigInt into the "Script Number" format. See parseBytesAsScriptNumber for more information.

    Parameters

    • integer: bigint

      the BigInt to encode as a Script Number

    Returns Uint8Array

Const binToBase64

  • binToBase64(bytes: Uint8Array): string

Const binToBigIntUint64LE

  • binToBigIntUint64LE(bin: Uint8Array): bigint
  • Decode an 8-byte Uint64LE Uint8Array into a BigInt.

    Parameters

    • bin: Uint8Array

      the Uint8Array to decode

    Returns bigint

Const binToBigIntUintLE

  • binToBigIntUintLE(bin: Uint8Array, bytes: number): bigint
  • Decode a little-endian Uint8Array into a BigInt.

    Parameters

    • bin: Uint8Array

      the Uint8Array to decode

    • bytes: number

    Returns bigint

Const binToHex

  • binToHex(bytes: Uint8Array): string
  • Encode a Uint8Array into a hexadecimal-encoded string.

    E.g.: binToHex(new Uint8Array([42, 100, 255])) => '2a64ff'

    Parameters

    • bytes: Uint8Array

      a Uint8Array to encode

    Returns string

Const binToNumberUint16LE

  • binToNumberUint16LE(bin: Uint8Array): number
  • Decode a 2-byte Uint16LE Uint8Array into a number.

    Parameters

    • bin: Uint8Array

      the Uint8Array to decode

    Returns number

Const binToNumberUint32LE

  • binToNumberUint32LE(bin: Uint8Array): number
  • Decode a 4-byte Uint32LE Uint8Array into a number.

    Parameters

    • bin: Uint8Array

      the Uint8Array to decode

    Returns number

Const binToNumberUintLE

  • binToNumberUintLE(bin: Uint8Array, bytes: number): number
  • Decode a little-endian Uint8Array into a number.

    Parameters

    • bin: Uint8Array

      the Uint8Array to decode

    • bytes: number

      the number of bytes to read

    Returns number

Const binToUtf8

  • binToUtf8(bytes: Uint8Array): string

Const bitcoinCashOperations

  • bitcoinCashOperations<Opcodes, State>(sha256: Sha256, secp256k1: Secp256k1, flags: object): object

Const bitwiseOperation

  • bitwiseOperation<State>(combine: function): (Anonymous function)

Const bitwiseOperations

  • bitwiseOperations<Opcodes, State, Errors>(): object

Const booleanToScriptNumber

  • booleanToScriptNumber(value: boolean): Uint8Array
  • Convert a boolean into Script Number format (the type used to express boolean values emitted by several operations).

    Parameters

    • value: boolean

      the boolean value to convert

    Returns Uint8Array

Const checkLimitsCommon

Const cloneAuthenticationProgramStateCommon

  • cloneAuthenticationProgramStateCommon<Opcodes, State, Errors>(state: State): object | object

Const cloneStack

  • cloneStack(stack: ReadonlyArray<Readonly<Uint8Array>>): Uint8Array[]

Const combineOperations

  • combineOperations<State>(firstOperation: Operation<State>, secondOperation: Operation<State>): (Anonymous function)

Const commonOperations

Const conditionalFlowControlOperations

  • conditionalFlowControlOperations<Opcodes, State, Errors>(): object

Const conditionallyEvaluate

Const createAuthenticationProgramExternalStateCommon

Const createAuthenticationProgramExternalStateCommonEmpty

  • createAuthenticationProgramExternalStateCommonEmpty(): object

Const createAuthenticationProgramInternalStateCommon

Const createAuthenticationProgramStateCommon

Const createAuthenticationProgramStateCommonEmpty

Const createAuthenticationVirtualMachine

Const createInstructionSetBCH

Const createTestAuthenticationProgramBCH

  • createTestAuthenticationProgramBCH(unlockingBytecode: Uint8Array, lockingBytecode: Uint8Array, sha256: Sha256, satoshis?: bigint): object

Const cryptoOperations

Const decodeBitcoinSignature

  • decodeBitcoinSignature(encodedSignature: Uint8Array): object
  • Split a bitcoin-encoded signature into a signature and signing serialization type.

    While a bitcoin-encoded signature only includes a single byte to encode the signing serialization type, a 3-byte forkId can be appended to the signing serialization to provide replay-protection between different forks. (See Bitcoin Cash's Replay Protected Sighash spec for details.)

    Parameters

    • encodedSignature: Uint8Array

    Returns object

Const deserializeTransaction

  • TODO: document return type (note outpointTransactionHash is little-endian – most UIs display big-endian transaction hashes)

    Note: this method throws runtime errors when attempting to decode improperly encoded transactions.

    Parameters

    • bin: Uint8Array

      the raw transaction to decode

    Returns Transaction

Const disabledOperation

  • disabledOperation<State, Errors>(): (Anonymous function)

Const disabledOperations

  • disabledOperations<State, Errors>(): object

Const disassembleAuthenticationInstruction

Const disassembleParsedAuthenticationInstruction

Const disassembleParsedAuthenticationInstructionMalformed

Const disassembleParsedAuthenticationInstructions

Const disassembleScript

  • disassembleScript<Opcode>(opcodes: object, script: Uint8Array): string
  • Disassemble a serialized script into a lossless ASM representation.

    TODO: a similar method which re-formats ASM strings, converting HexLiterals to Script Numbers or UTF8Literals.

    Type parameters

    • Opcode

    Parameters

    • opcodes: object

      the set to use when determining the name of opcodes, e.g. OpcodesBCH

      • [opcode: number]: string
    • script: Uint8Array

      the serialized script to disassemble

    Returns string

Const disassembleScriptBCH

  • disassembleScriptBCH(script: Uint8Array): string

Const disassembleScriptBTC

  • disassembleScriptBTC(script: Uint8Array): string

Const encodeDataPush

  • encodeDataPush(data: Uint8Array): Uint8Array
  • Returns the minimal bytecode required to push the provided data to the stack.

    Parameters

    • data: Uint8Array

      the Uint8Array to push to the stack

    Returns Uint8Array

Const flattenBinArray

  • flattenBinArray(array: ReadonlyArray<Uint8Array>): Uint8Array
  • Reduce an array of Uint8Arrays into a single Uint8Array.

    Parameters

    • array: ReadonlyArray<Uint8Array>

      the array of Uint8Arrays to flatten

    Returns Uint8Array

Const generateBytecodeMap

  • generateBytecodeMap(opcodes: object): object
  • Create an object where each key is an opcode identifier and each value is the bytecode value (Uint8Array) it represents.

    Parameters

    • opcodes: object

      An opcode enum, e.g. OpcodesBCH

    Returns object

    • [opcode: string]: Uint8Array

Const generateSigningSerializationBCH

  • generateSigningSerializationBCH(version: number, hashTransactionOutpoints: function, hashTransactionSequenceNumbers: function, outpointTransactionHash: Uint8Array, outpointIndex: number, coveredScript: Uint8Array, outputValue: bigint, sequenceNumber: number, hashCorrespondingOutput: function, hashTransactionOutputs: function, locktime: number, signingSerializationType: Uint8Array, forkId?: Uint8Array): Uint8Array
  • Serialize the signature-protected properties of a transaction following the algorithm required by the signingSerializationType of a signature.

    Parameters

    • version: number

      the version number of the transaction

    • hashTransactionOutpoints: function

      a function returning the 32-byte double SHA256 hash of the serialization of all input outpoints (A.K.A. hashPrevouts) – used if ANYONECANPAY is not set

        • (): Uint8Array
        • Returns Uint8Array

    • hashTransactionSequenceNumbers: function

      a function returning the double SHA256 hash of the serialization of all input sequence numbers. (A.K.A. hashSequence) – used if none of ANYONECANPAY, SINGLE, or NONE are set.

        • (): Uint8Array
        • Returns Uint8Array

    • outpointTransactionHash: Uint8Array

      the big-endian (standard) transaction hash of the outpoint being spent.

    • outpointIndex: number

      the index of the outpoint being spent in outpointTransactionHash

    • coveredScript: Uint8Array

      the script currently being executed, beginning at the lastCodeSeparator.

    • outputValue: bigint

      the value of the outpoint in satoshis

    • sequenceNumber: number

      the sequence number of the input (A.K.A. nSequence)

    • hashCorrespondingOutput: function

      The double SHA256 of the serialization of the output at the same index as this input (A.K.A. hashOutputs with SIGHASH_SINGLE) – only used if SINGLE is set

        • (): Uint8Array
        • Returns Uint8Array

    • hashTransactionOutputs: function

      the double SHA256 of the serialization of output amounts and locking bytecode values (A.K.A. hashOutputs with SIGHASH_ALL) – only used if ALL is set

        • (): Uint8Array
        • Returns Uint8Array

    • locktime: number

      the locktime of the transaction

    • signingSerializationType: Uint8Array

      the signing serialization type of the signature (A.K.A. sighash type)

    • Default value forkId: Uint8Array = new Uint8Array([0, 0, 0])

      while a bitcoin-encoded signature only includes a single byte to encode the signing serialization type, a 3-byte forkId can be appended to provide replay-protection between different forks. (See Bitcoin Cash's Replay Protected Sighash spec for details.)

    Returns Uint8Array

Const getBitcoinIdentifier

  • getBitcoinIdentifier(data: Uint8Array, sha256: Sha256): Uint8Array
  • Derive a standard identifier from a serialized data structure.

    Parameters

    • data: Uint8Array

      the serialized raw data being identified

    • sha256: Sha256

      an implementation of sha256

    Returns Uint8Array

    an identifier in little-endian byte order

Const getBitcoinTransactionId

  • getBitcoinTransactionId(transaction: Uint8Array, sha256: Sha256): string
  • Derive a standard transaction identifier from a serialized transaction.

    Parameters

    • transaction: Uint8Array

      the serialized transaction

    • sha256: Sha256

      an implementation of sha256

    Returns string

    a Transaction ID in little-endian byte order

Const getEmbeddedRipemd160Binary

  • getEmbeddedRipemd160Binary(): ArrayBuffer | SharedArrayBuffer

Const getEmbeddedSecp256k1Binary

  • getEmbeddedSecp256k1Binary(): ArrayBuffer | SharedArrayBuffer

Const getEmbeddedSha1Binary

  • getEmbeddedSha1Binary(): ArrayBuffer

Const getEmbeddedSha256Binary

  • getEmbeddedSha256Binary(): ArrayBuffer | SharedArrayBuffer

Const getEmbeddedSha512Binary

  • getEmbeddedSha512Binary(): ArrayBuffer | SharedArrayBuffer

Const getFlagsForInstructionSetBCH

Const getOutpointsHash

  • getOutpointsHash(inputs: ReadonlyArray<Input>, sha256: Sha256): Uint8Array
  • Get the hash of all outpoints in a series of inputs. (For use in hashTransactionOutpoints.)

    Parameters

    • inputs: ReadonlyArray<Input>

      the series of inputs from which to extract the outpoints

    • sha256: Sha256

      an implementation of sha256

    Returns Uint8Array

Const getOutputHash

  • Get the hash of a output. (For use in hashCorrespondingOutput.)

    Parameters

    • output: Output

      the output to hash

    • sha256: Sha256

      an implementation of sha256

    Returns Uint8Array

Const getOutputsHash

  • getOutputsHash(outputs: ReadonlyArray<Output>, sha256: Sha256): Uint8Array
  • Get the hash of a series of outputs. (Primarily for use in hashTransactionOutputs)

    Parameters

    • outputs: ReadonlyArray<Output>

      the series of outputs to serialize and hash

    • sha256: Sha256

      an implementation of sha256

    Returns Uint8Array

Const getSequenceNumbersHash

  • getSequenceNumbersHash(inputs: ReadonlyArray<Input>, sha256: Sha256): Uint8Array
  • Get the hash of a series of input sequence numbers. (Primarily for use in hashTransactionSequenceNumbers)

    Parameters

    • inputs: ReadonlyArray<Input>

      the series of inputs from which to extract the sequence numbers

    • sha256: Sha256

      an implementation of sha256

    Returns Uint8Array

Const hexToBin

  • hexToBin(wellFormedHex: string): Uint8Array
  • Decode a hexadecimal-encoded string into a Uint8Array.

    E.g.: hexToBin('2a64ff') => new Uint8Array([42, 100, 255])

    Note, this method always completes. If wellFormedHex is not divisible by 2, the final byte will be parsed as if it were prepended with a 0 (e.g. aaa is interpreted as aa0a). If wellFormedHex is potentially malformed, check it with isHex before calling this method.

    Parameters

    • wellFormedHex: string

      a string of valid, hexadecimal-encoded data

    Returns Uint8Array

Const incrementOperationCount

Const instantiateRipemd160

  • An ultimately-portable (but slower) version of instantiateRipemd160Bytes which does not require the consumer to provide the ripemd160 binary buffer.

    Returns Promise<Ripemd160>

Const instantiateRipemd160Bytes

  • instantiateRipemd160Bytes(webassemblyBytes: ArrayBuffer): Promise<Ripemd160>
  • The most performant way to instantiate ripemd160 functionality. To avoid using Node.js or DOM-specific APIs, you can use instantiateRipemd160.

    Parameters

    • webassemblyBytes: ArrayBuffer

      A buffer containing the ripemd160 binary.

    Returns Promise<Ripemd160>

Const instantiateRustWasm

  • instantiateRustWasm(webassemblyBytes: ArrayBuffer, expectedImportModuleName: string, hashExportName: string, initExportName: string, updateExportName: string, finalExportName: string): Promise<HashFunction>
  • Note, most of this method is translated and boiled-down from the wasm-pack workflow. Significant changes to wasm-bindgen or wasm-pack build will likely require modifications to this method.

    Parameters

    • webassemblyBytes: ArrayBuffer
    • expectedImportModuleName: string
    • hashExportName: string
    • initExportName: string
    • updateExportName: string
    • finalExportName: string

    Returns Promise<HashFunction>

Const instantiateSecp256k1

  • instantiateSecp256k1(randomSeed?: Uint8Array): Promise<Secp256k1>
  • Create and wrap a Secp256k1 WebAssembly instance to expose a set of purely-functional Secp256k1 methods. For slightly faster initialization, use instantiateSecp256k1Bytes.

    TODO: cache resulting instance to return in all future calls

    Parameters

    • Optional randomSeed: Uint8Array

      a 32-byte random seed used to randomize the secp256k1 context after creation. See the description in instantiateSecp256k1Bytes for details.

    Returns Promise<Secp256k1>

Const instantiateSecp256k1Bytes

  • instantiateSecp256k1Bytes(webassemblyBytes: ArrayBuffer, randomSeed?: Uint8Array): Promise<Secp256k1>
  • This method is like instantiateSecp256k1, but requires the consumer to Window.fetch or fs.readFile the secp256k1.wasm binary and provide it to this method as webassemblyBytes. This skips a base64 decoding of an embedded binary.

    Randomizing the Context with randomSeed

    This method also accepts an optional, 32-byte randomSeed, which is passed to the contextRandomize method in the underlying WebAssembly.

    The value of this precaution is debatable, especially in the context of javascript and WebAssembly.

    In the secp256k1 C library, context randomization is an additional layer of security from side-channel attacks which attempt to extract private key information by analyzing things like a CPU's emitted radio frequencies or power usage.

    In this library, these attacks seem even less likely, since the "platform" on which this code will be executed (e.g. V8) is likely to obscure any such signals.

    Still, out of an abundance of caution (and because no one has produced a definitive proof indicating that this is not helpful), this library exposes the ability to randomize the context like the C library. Depending on the intended application, consumers can decide whether or not to randomize.

    Parameters

    • webassemblyBytes: ArrayBuffer

      an ArrayBuffer containing the bytes from bitcoin-ts' secp256k1.wasm binary. Providing this buffer manually may be faster than the internal base64 decode which happens in instantiateSecp256k1.

    • Optional randomSeed: Uint8Array

      a 32-byte random seed used to randomize the secp256k1 context after creation. See above for details.

    Returns Promise<Secp256k1>

Const instantiateSecp256k1Wasm

Const instantiateSecp256k1WasmBytes

  • instantiateSecp256k1WasmBytes(webassemblyBytes: ArrayBuffer): Promise<Secp256k1Wasm>
  • The most performant way to instantiate secp256k1 functionality. To avoid using Node.js or DOM-specific APIs, you can use instantiateSecp256k1.

    Note, most of this method is translated and boiled-down from Emscripten's preamble.js. Significant changes to the WASM build or breaking updates to Emscripten will likely require modifications to this method.

    Parameters

    • webassemblyBytes: ArrayBuffer

      A buffer containing the secp256k1 binary.

    Returns Promise<Secp256k1Wasm>

Const instantiateSha1

  • instantiateSha1(): Promise<Sha1>
  • An ultimately-portable (but slower) version of instantiateSha1Bytes which does not require the consumer to provide the sha1 binary buffer.

    Returns Promise<Sha1>

Const instantiateSha1Bytes

  • instantiateSha1Bytes(webassemblyBytes: ArrayBuffer): Promise<Sha1>
  • The most performant way to instantiate sha1 functionality. To avoid using Node.js or DOM-specific APIs, you can use instantiateSha1.

    Parameters

    • webassemblyBytes: ArrayBuffer

      A buffer containing the sha1 binary.

    Returns Promise<Sha1>

Const instantiateSha256

  • instantiateSha256(): Promise<Sha256>
  • An ultimately-portable (but possibly slower) version of instantiateSha256Bytes which does not require the consumer to provide the sha256 binary buffer.

    TODO: cache resulting instance to return in all future calls

    Returns Promise<Sha256>

Const instantiateSha256Bytes

  • instantiateSha256Bytes(webassemblyBytes: ArrayBuffer): Promise<Sha256>
  • The most performant way to instantiate sha256 functionality. To avoid using Node.js or DOM-specific APIs, you can use instantiateSha256.

    Parameters

    • webassemblyBytes: ArrayBuffer

      A buffer containing the sha256 binary.

    Returns Promise<Sha256>

Const instantiateSha512

  • instantiateSha512(): Promise<Sha512>
  • An ultimately-portable (but slower) version of instantiateSha512Bytes which does not require the consumer to provide the sha512 binary buffer.

    Returns Promise<Sha512>

Const instantiateSha512Bytes

  • instantiateSha512Bytes(webassemblyBytes: ArrayBuffer): Promise<Sha512>
  • The most performant way to instantiate sha512 functionality. To avoid using Node.js or DOM-specific APIs, you can use instantiateSha512.

    Parameters

    • webassemblyBytes: ArrayBuffer

      A buffer containing the sha512 binary.

    Returns Promise<Sha512>

Const instantiateVirtualMachineBCH

Const isDefinedSigningSerializationType

  • isDefinedSigningSerializationType(byte: number): boolean

Const isHex

  • isHex(maybeHex: string): boolean
  • For use before hexToBin. Returns true if the provided string is divisible by 2 and only uses hex characters.

    Parameters

    • maybeHex: string

      a string to test

    Returns boolean

Const isLegacySigningSerialization

  • isLegacySigningSerialization(signingSerializationType: number): boolean

Const isMinimalDataPush

  • isMinimalDataPush(opcode: number, data: Uint8Array): boolean
  • Returns true if the provided data is minimally-encoded by the provided opcode.

    Parameters

    • opcode: number

      the opcode used to push data

    • data: Uint8Array

      the contents of the push

    Returns boolean

Const isPayToScriptHash

Const isScriptNumberError

Const isValidCompressedPublicKeyEncoding

  • isValidCompressedPublicKeyEncoding(publicKey: Uint8Array): boolean

Const isValidPublicKeyEncoding

  • isValidPublicKeyEncoding(publicKey: Uint8Array): boolean

Const isValidSignatureEncodingBCHRaw

  • isValidSignatureEncodingBCHRaw(signature: Uint8Array): boolean
  • Validate the encoding of a raw signature – a signature without a signing serialization type byte (A.K.A. "sighash" byte).

    Parameters

    • signature: Uint8Array

      the raw signature

    Returns boolean

Const isValidSignatureEncodingBCHTransaction

  • isValidSignatureEncodingBCHTransaction(transactionSignature: Uint8Array): boolean
  • Validate the encoding of a transaction signature, including a signing serialization type byte (A.K.A. "sighash" byte).

    Parameters

    • transactionSignature: Uint8Array

      the full transaction signature

    Returns boolean

Const isValidSignatureEncodingDER

  • isValidSignatureEncodingDER(signature: Uint8Array): boolean

Const isValidUncompressedPublicKeyEncoding

  • isValidUncompressedPublicKeyEncoding(publicKey: Uint8Array): boolean

Const isWitnessProgram

  • isWitnessProgram(bytecode: Uint8Array): boolean

Const lengthBytesForPushOpcode

  • lengthBytesForPushOpcode(opcode: number): number

Const mapOverOperations

Const nonOperations

  • nonOperations<State>(flags: object): object

Const numberToBinUint16LE

  • numberToBinUint16LE(value: number): Uint8Array
  • Encode a number as a 2-byte Uint16LE Uint8Array.

    Note: For valid results, value must be between 0 and 0xffff.

    Parameters

    • value: number

      the number to convert into a Uint16LE Uint8Array

    Returns Uint8Array

Const numberToBinUint32LE

  • numberToBinUint32LE(value: number): Uint8Array
  • Encode a number as a 4-byte Uint32LE Uint8Array.

    Note: For valid results, value must be between 0 and 0xffffffff.

    Parameters

    • value: number

      the number to convert into a Uint32LE Uint8Array

    Returns Uint8Array

Const numberToBinUintLE

  • numberToBinUintLE(value: number, bytes: number): Uint8Array
  • Encode a number as a little-endian Uint8Array.

    Note: For valid results, value must be within the range representable by the specified number of bytes. For values exceeding Number.MAX_SAFE_INTEGER, use bigIntToBinUintLE.

    Parameters

    • value: number

      the number to convert into a Uint32LE Uint8Array

    • bytes: number

      the number of bytes to read

    Returns Uint8Array

Const numberToLittleEndianBin

  • numberToLittleEndianBin(value: number, length: Bytes): Uint8Array

Const op0NotEqual

  • op0NotEqual<State, Errors>(flags: object): (Anonymous function)

Const op1Add

  • op1Add<State, Errors>(flags: object): (Anonymous function)

Const op1Sub

  • op1Sub<State, Errors>(flags: object): (Anonymous function)

Const op2Drop

  • op2Drop<State>(): (Anonymous function)

Const op2Dup

  • op2Dup<State>(): (Anonymous function)

Const op2Over

  • op2Over<State>(): (Anonymous function)

Const op2Rot

  • op2Rot<State>(): (Anonymous function)

Const op2Swap

  • op2Swap<State>(): (Anonymous function)

Const op3Dup

  • op3Dup<State>(): (Anonymous function)

Const opAbs

  • opAbs<State, Errors>(flags: object): (Anonymous function)

Const opAdd

  • opAdd<State, Errors>(flags: object): (Anonymous function)

Const opAnd

  • opAnd<State>(): (Anonymous function)

Const opBin2Num

  • opBin2Num<State>(): (Anonymous function)

Const opBoolAnd

  • opBoolAnd<State, Errors>(flags: object): (Anonymous function)

Const opBoolOr

  • opBoolOr<State, Errors>(flags: object): (Anonymous function)

Const opCat

  • opCat<State>(): (Anonymous function)

Const opCheckDataSig

  • opCheckDataSig<State, Errors>(sha256: Sha256, secp256k1: Secp256k1): (Anonymous function)

Const opCheckDataSigVerify

  • opCheckDataSigVerify<State, Errors>(sha256: Sha256, secp256k1: Secp256k1): (Anonymous function)

Const opCheckLockTimeVerify

  • opCheckLockTimeVerify<State, Errors>(flags: object): (Anonymous function)

Const opCheckMultiSig

  • opCheckMultiSig<Opcodes, State, Errors>(sha256: Sha256, secp256k1: Secp256k1, flags: object): (Anonymous function)

Const opCheckMultiSigVerify

Const opCheckSequenceVerify

  • opCheckSequenceVerify<State, Errors>(flags: object): (Anonymous function)

Const opCheckSig

Const opCheckSigVerify

Const opCodeSeparator

  • opCodeSeparator<Opcodes, State>(): Operation<State>

Const opDepth

  • opDepth<State>(): (Anonymous function)

Const opDiv

  • opDiv<State>(flags: object): (Anonymous function)

Const opDrop

  • opDrop<State>(): (Anonymous function)

Const opDup

  • opDup<State>(): (Anonymous function)

Const opElse

Const opEndIf

Const opEqual

Const opEqualVerify

  • opEqualVerify<State, Errors>(): Operation<State>

Const opFromAltStack

  • opFromAltStack<State, Errors>(): (Anonymous function)

Const opGreaterThan

  • opGreaterThan<State, Errors>(flags: object): (Anonymous function)

Const opGreaterThanOrEqual

  • opGreaterThanOrEqual<State, Errors>(flags: object): (Anonymous function)

Const opHash160

Const opHash256

Const opIf

Const opIfDup

  • opIfDup<State>(): (Anonymous function)

Const opLessThan

  • opLessThan<State, Errors>(flags: object): (Anonymous function)

Const opLessThanOrEqual

  • opLessThanOrEqual<State, Errors>(flags: object): (Anonymous function)

Const opMax

  • opMax<State, Errors>(flags: object): (Anonymous function)

Const opMin

  • opMin<State, Errors>(flags: object): (Anonymous function)

Const opMod

  • opMod<State>(flags: object): (Anonymous function)

Const opNegate

  • opNegate<State, Errors>(flags: object): (Anonymous function)

Const opNip

  • opNip<State>(): (Anonymous function)

Const opNop

  • opNop<State>(flags: object): (Anonymous function)

Const opNot

  • opNot<State, Errors>(flags: object): (Anonymous function)

Const opNotIf

  • opNotIf<State, Errors>(flags: object): Operation<State>

Const opNum2Bin

  • opNum2Bin<State>(): (Anonymous function)

Const opNumEqual

  • opNumEqual<State, Errors>(flags: object): (Anonymous function)

Const opNumEqualVerify

  • opNumEqualVerify<State, Errors>(flags: object): (Anonymous function)

Const opNumNotEqual

  • opNumNotEqual<State, Errors>(flags: object): (Anonymous function)

Const opOr

  • opOr<State>(): (Anonymous function)

Const opOver

  • opOver<State>(): (Anonymous function)

Const opPick

  • opPick<State, Errors>(flags: object): (Anonymous function)

Const opReturn

  • opReturn<State, Errors>(): (Anonymous function)

Const opRipemd160

Const opRoll

  • opRoll<State, Errors>(flags: object): (Anonymous function)

Const opRot

  • opRot<State>(): (Anonymous function)

Const opSha1

Const opSha256

Const opSize

  • opSize<State>(): (Anonymous function)

Const opSplit

  • opSplit<State>(flags: object): (Anonymous function)

Const opSub

  • opSub<State, Errors>(flags: object): (Anonymous function)

Const opSwap

  • opSwap<State>(): (Anonymous function)

Const opToAltStack

  • opToAltStack<State>(): (Anonymous function)

Const opTuck

  • opTuck<State>(): (Anonymous function)

Const opVerify

  • opVerify<State, Errors>(): Operation<State>

Const opWithin

  • opWithin<State, Errors>(flags: object): (Anonymous function)

Const opXor

  • opXor<State>(): (Anonymous function)

Const padMinimallyEncodedScriptNumber

  • padMinimallyEncodedScriptNumber(scriptNumber: Uint8Array, length: number): Uint8Array

Const parseBytesAsScriptNumber

  • parseBytesAsScriptNumber(bytes: Uint8Array, requireMinimalEncoding?: boolean, maximumScriptNumberByteLength?: number): bigint | ScriptNumberError
  • This method attempts to parse a "Script Number", a format with which numeric values are represented on the stack. (The Satoshi implementation calls this CScriptNum.)

    If bytes is a valid Script Number, this method returns the represented number in BigInt format. If bytes is not valid, a ScriptNumberError is returned.

    All common operations accepting numeric parameters or pushing numeric values to the stack currently use the Script Number format. The binary format of numbers wouldn't be important if they could only be operated on by arithmetic operators, but since the results of these operations may become input to other operations (e.g. hashing), the specific representation is consensus- critical.

    Parsing of Script Numbers is limited to 4 bytes (with the exception of OP_CHECKLOCKTIMEVERIFY and OP_CHECKSEQUENCEVERIFY, which read up to 5-bytes). The bytes are read as a signed integer (for 32-bits: inclusive range from -2^31 + 1 to 2^31 - 1) in little-endian byte order. Script Numbers must further be encoded as minimally as possible (no zero-padding). See code/tests for details.

    Notes

    Operators may push numeric results to the stack which exceed the current 4-byte length limit of Script Numbers. While these stack elements would otherwise be valid Script Numbers, because of the 4-byte length limit, they can only be used as non-numeric values in later operations.

    Most other implementations currently parse Script Numbers into 64-bit integers to operate on them (rather than integers of arbitrary size like BigInt). Currently, no operators are at risk of overflowing 64-bit integers given 32-bit integer inputs, but future operators may require additional refactoring in those implementations.

    Parameters

    • bytes: Uint8Array

      a Uint8Array from the stack

    • Default value requireMinimalEncoding: boolean = true

      if true, this method returns an error when parsing non-minimally encoded Script Numbers

    • Default value maximumScriptNumberByteLength: number = 4

      the maximum valid number of bytes

    Returns bigint | ScriptNumberError

Const parseScript

Const pushNumberOperations

  • pushNumberOperations<Opcodes, ProgramState>(): object

Const pushOperation

Const pushOperations

Const pushToStack

  • pushToStack<State>(state: State, ...data: Uint8Array[]): State

Const range

  • range(length: number, begin?: number): number[]
  • Returns an array of incrementing values starting at begin and incrementing by one for length.

    E.g.: range(3) => [0, 1, 2] and range(3, 1) => [1, 2, 3]

    Parameters

    • length: number

      the number of elements in the array

    • Default value begin: number = 0

      the index at which the range starts (default: 0)

    Returns number[]

Const readAuthenticationInstruction

  • readAuthenticationInstruction<Opcodes>(script: Uint8Array, index: number): object
  • Parse one instruction from the provided script.

    Returns an object with an instruction referencing a ParsedAuthenticationInstruction, and a nextIndex indicating the next index from which to read. If the next index is greater than or equal to the length of the script, the script has been fully parsed.

    The final ParsedAuthenticationInstruction from a serialized script may be malformed if 1) the final operation is a push and 2) too few bytes remain for the push operation to complete.

    Type parameters

    • Opcodes

    Parameters

    • script: Uint8Array

      the script from which to read the next instruction

    • index: number

      the offset from which to begin reading

    Returns object

Const readBitcoinVarInt

  • readBitcoinVarInt(bin: Uint8Array, offset: number): object
  • Read a Bitcoin VarInt (Variable-length integer) from a Uint8Array, returning the nextOffset after the VarInt and the value as a BigInt.

    Parameters

    • bin: Uint8Array

      the Uint8Array from which to read the VarInt

    • offset: number

      the offset at which the input begins

    Returns object

Const readLittleEndianNumber

  • readLittleEndianNumber(script: Uint8Array, index: number, length: Bytes): number
  • Note: this implementation assumes script is defined and long enough to read the specified number of bytes. If necessary, validation should be done before calling this method.

    Parameters

    • script: Uint8Array

      the Uint8Array from which to read

    • index: number

      the index from which to begin reading

    • length: Bytes

      the number of bytes to read

    Returns number

Const readLocktime

  • readLocktime<State, Errors>(state: State, operation: function, flags: object): State

Const readTransactionInput

  • readTransactionInput(bin: Uint8Array, offset: number): object
  • Parameters

    • bin: Uint8Array

      the raw transaction from which to read the input

    • offset: number

      the offset at which the input begins

    Returns object

Const readTransactionOutput

  • readTransactionOutput(bin: Uint8Array, offset: number): object
  • Parameters

    • bin: Uint8Array

      the raw transaction from which to read the output

    • offset: number

      the offset at which the output begins

    Returns object

Const reservedOperation

  • reservedOperation<State, Errors>(): (Anonymous function)

Const serializeAuthenticationInstruction

Const serializeAuthenticationInstructions

Const serializeInput

  • serializeInput(input: Input): Uint8Array

Const serializeInputs

  • serializeInputs(inputs: ReadonlyArray<Input>): Uint8Array
  • Serialize a set of inputs for inclusion in a serialized transaction.

    Format: <BitcoinVarInt: input count>

    Parameters

    • inputs: ReadonlyArray<Input>

      the set of inputs to serialize

    Returns Uint8Array

Const serializeOutput

  • serializeOutput(output: Output): Uint8Array

Const serializeOutputs

  • serializeOutputs(outputs: ReadonlyArray<Output>): Uint8Array
  • Serialize a set of outputs for inclusion in a serialized transaction.

    Format: <BitcoinVarInt: output count>

    Parameters

    • outputs: ReadonlyArray<Output>

      the set of outputs to serialize

    Returns Uint8Array

Const serializeParsedAuthenticationInstruction

Const serializeParsedAuthenticationInstructionMalformed

Const serializeParsedAuthenticationInstructions

Const serializeTransaction

Const spliceOperations

  • spliceOperations<State, Errors>(): object

Const splitEvery

  • splitEvery(input: string, chunkLength: number): string[]
  • Split a string into an array of chunkLength strings. The final string may have a length between 1 and chunkLength.

    E.g.: splitEvery('abcde', 2) => ['ab', 'cd', 'e']

    Parameters

    • input: string
    • chunkLength: number

    Returns string[]

Const stackItemIsTruthy

  • stackItemIsTruthy(item: Uint8Array): boolean
  • Returns true if the provided stack item is "truthy" in the sense required by several operations (anything but zero and "negative zero").

    The Satoshi implementation calls this method CastToBool.

    Parameters

    • item: Uint8Array

      the stack item to check for truthiness

    Returns boolean

Const stackOperations

  • stackOperations<State, Errors>(flags: object): object

Const stringify

  • stringify(object: object, spacing?: number): string
  • Parameters

    • object: object
    • Default value spacing: number = 2

    Returns string

Const swapEndianness

  • swapEndianness(wellFormedHex: string): string
  • Decode a hexadecimal-encoded string into bytes, reverse it, then re-encode.

    Parameters

    • wellFormedHex: string

      a string of valid, hexadecimal-encoded data. See hexToBin for more information.

    Returns string

Const timeOperations

  • timeOperations<Opcodes, State, Errors>(flags: object): object

Const unconditionalFlowControlOperations

  • unconditionalFlowControlOperations<Opcodes, State, Errors>(flags: object): object

Const undefinedOperation

  • undefinedOperation<State, Errors>(): object

Const useFourStackItems

  • useFourStackItems<State, Errors>(state: State, operation: function): State
  • Type parameters

    Parameters

    • state: State
    • operation: function
        • (nextState: State, valueTop: Uint8Array, valueTwo: Uint8Array, valueThree: Uint8Array, valueFour: Uint8Array): State
        • Parameters

          • nextState: State
          • valueTop: Uint8Array
          • valueTwo: Uint8Array
          • valueThree: Uint8Array
          • valueFour: Uint8Array

          Returns State

    Returns State

Const useOneScriptNumber

  • useOneScriptNumber<State, Errors>(state: State, operation: function, requireMinimalEncoding: boolean, maximumScriptNumberByteLength?: number): State
  • Type parameters

    Parameters

    • state: State
    • operation: function
        • (nextState: State, value: bigint): State
        • Parameters

          • nextState: State
          • value: bigint

          Returns State

    • requireMinimalEncoding: boolean
    • Default value maximumScriptNumberByteLength: number = 4

    Returns State

Const useOneStackItem

  • useOneStackItem<State, Errors>(state: State, operation: function): State
  • Pop one stack item off of state.stack and provide that item to operation.

    Type parameters

    Parameters

    • state: State
    • operation: function
        • (nextState: State, value: Uint8Array): State
        • Parameters

          • nextState: State
          • value: Uint8Array

          Returns State

    Returns State

Const useSixStackItems

  • useSixStackItems<State, Errors>(state: State, operation: function): State
  • Type parameters

    Parameters

    • state: State
    • operation: function
        • (nextState: State, valueTop: Uint8Array, valueTwo: Uint8Array, valueThree: Uint8Array, valueFour: Uint8Array, valueFive: Uint8Array, valueSix: Uint8Array): State
        • Parameters

          • nextState: State
          • valueTop: Uint8Array
          • valueTwo: Uint8Array
          • valueThree: Uint8Array
          • valueFour: Uint8Array
          • valueFive: Uint8Array
          • valueSix: Uint8Array

          Returns State

    Returns State

Const useThreeScriptNumbers

  • useThreeScriptNumbers<State, Errors>(state: State, operation: function, requireMinimalEncoding: boolean, maximumScriptNumberByteLength?: number): State
  • Type parameters

    Parameters

    • state: State
    • operation: function
        • (nextState: State, firstValue: bigint, secondValue: bigint, thirdValue: bigint): State
        • Parameters

          • nextState: State
          • firstValue: bigint
          • secondValue: bigint
          • thirdValue: bigint

          Returns State

    • requireMinimalEncoding: boolean
    • Default value maximumScriptNumberByteLength: number = 4

    Returns State

Const useThreeStackItems

  • useThreeStackItems<State, Errors>(state: State, operation: function): State
  • Type parameters

    Parameters

    • state: State
    • operation: function
        • (nextState: State, valueTop: Uint8Array, valueTwo: Uint8Array, valueThree: Uint8Array): State
        • Parameters

          • nextState: State
          • valueTop: Uint8Array
          • valueTwo: Uint8Array
          • valueThree: Uint8Array

          Returns State

    Returns State

Const useTwoScriptNumbers

  • useTwoScriptNumbers<State, Errors>(state: State, operation: function, requireMinimalEncoding: boolean, maximumScriptNumberByteLength?: number): State
  • Type parameters

    Parameters

    • state: State
    • operation: function
        • (nextState: State, firstValue: bigint, secondValue: bigint): State
        • Parameters

          • nextState: State
          • firstValue: bigint
          • secondValue: bigint

          Returns State

    • requireMinimalEncoding: boolean
    • Default value maximumScriptNumberByteLength: number = 4

    Returns State

Const useTwoStackItems

  • useTwoStackItems<State, Errors>(state: State, operation: function): State

Const utf8ToBin

  • utf8ToBin(utf8: string): Uint8Array

Const writeLittleEndianNumber

  • writeLittleEndianNumber(script: Uint8Array, index: number, length: Bytes, value: number): Uint8Array
  • Note: this implementation assumes script is defined and long enough to write the specified number of bytes. It also assumes the provided number is representable in length bytes.

    If necessary, validation should be done before calling this method.

    Parameters

    • script: Uint8Array

      the Uint8Array to which the number should be written

    • index: number

      the index at which to begin reading

    • length: Bytes

      the number of bytes to use

    • value: number

      the number to write at script[index]

    Returns Uint8Array

Object literals

Const OpcodeDescriptionsBCH

OpcodeDescriptionsBCH: object

A map of descriptions for each Bitcoin Cash opcode.

Generated using TypeDoc