Function encodeDataPush

  • Returns the minimal bytecode required to push the provided data to the stack.


    • data: Uint8Array

      the Uint8Array to push to the stack

    Returns Uint8Array


    This method conservatively encodes a Uint8Array as a data push. For VM Numbers that can be pushed using a single opcode (-1 through 16), the equivalent bytecode value is returned. Other data values will be prefixed with the proper opcode and push length bytes (if necessary) to create the minimal push instruction.

    Note, while some single-byte VM Number pushes will be minimally-encoded by this method, all larger inputs will be encoded as-is (it cannot be assumed that inputs are intended to be used as VM Numbers). To encode the push of a VM Number, minimally-encode the number before passing it to this method, e.g.: encodeDataPush(bigIntToVmNumber(decodeVmNumber(nonMinimalNumber))).

    The maximum bytecode length that can be encoded for a push in the Bitcoin system is 4294967295 (~4GB). This method assumes a smaller input – if bytecode has the potential to be longer, it should be checked (and the error handled) prior to calling this method.

Generated using TypeDoc