import { CompilationData } from '../template/compiler-types' ; import { CompilationError , ResolvedScript , } from '../template/language/language-types' ; /**
 * The partial transaction context which is shared between all of the inputs in
 * a transaction.
 */ export interface TransactionContextSharedCommon { /**
     * A time or block height at which the transaction is considered valid (and
     * can be added to the block chain). This allows signers to create time-locked
     * transactions which may only become valid in the future.
     */ readonly locktime : number ; /**
     * A.K.A. the serialization for `hashPrevouts`
     *
     * The signing serialization of all input outpoints. (See BIP143 or Bitcoin
     * Cash's Replay Protected Sighash spec for details.)
     */ readonly transactionOutpoints : Uint8Array ; readonly transactionOutputs : Uint8Array ; readonly transactionSequenceNumbers : Uint8Array ; readonly version : number ; } /**
 * The complete transaction context in which a single transaction input exists.
 */ export interface TransactionContextCommon extends TransactionContextSharedCommon { readonly correspondingOutput ? : Uint8Array ; /**
     * The index (within the previous transaction) of the outpoint being spent by
     * this input.
     */ readonly outpointIndex : number ; /**
     * The hash/ID of the transaction from which the outpoint being spent by this
     * input originated.
     */ readonly outpointTransactionHash : Uint8Array ; /**
     * The 8-byte `Uint64LE`-encoded value of the outpoint in satoshis (see
     * `bigIntToBinUint64LE`).
     */ readonly outputValue : Uint8Array ; /**
     * The `sequenceNumber` associated with the input being validated. See
     * `Input.sequenceNumber` for details.
     */ readonly sequenceNumber : number ; } /**
 * Data type representing a Transaction Input.
 */ export interface Input < Bytecode = Uint8Array , HashRepresentation = Uint8Array > { remarks outpointIndex : number ; remarks outpointTransactionHash : HashRepresentation ; remarks sequenceNumber : number ; /**
     * The bytecode used to unlock a transaction output. To spend an output,
     * unlocking bytecode must be included in a transaction input which – when
     * evaluated in the authentication virtual machine with the locking bytecode –
     * completes in valid state.
     *
     * A.K.A. `scriptSig` or "unlocking script"
     */ unlockingBytecode : Bytecode ; } typeParam typeParam export interface Output < Bytecode = Uint8Array , Amount = Uint8Array > { /**
     * The bytecode used to encumber this transaction output. To spend the output,
     * unlocking bytecode must be included in a transaction input which – when
     * evaluated before the locking bytecode – completes in a valid state.
     *
     * A.K.A. `scriptPubKey` or "locking script"
     */ readonly lockingBytecode : Bytecode ; /**
     * The 8-byte `Uint64LE`-encoded value of the output in satoshis, the smallest
     * unit of bitcoin.
     *
     * There are 100 satoshis in a bit, and 100,000,000 satoshis in a bitcoin.
     *
     * This value could be defined using a `number`, as `Number.MAX_SAFE_INTEGER`
     * (`9007199254740991`) is about 4 times larger than the maximum number of
     * satoshis which should ever exist. I.e. even if all satoshis were
     * consolidated into a single output, the transaction spending this output
     * could still be defined with a numeric `satoshis` value.
     *
     * However, because the encoded output format for version 1 and 2 transactions
     * (used in both transaction encoding and signing serialization) uses a 64-bit
     * unsigned, little-endian integer to serialize `satoshis`, this property is
     * encoded in the same format, allowing it to cover the full possible range.
     *
     * This is useful for encoding values using schemes for fractional satoshis
     * (for which no finalized specification yet exists) or for encoding
     * intentionally excessive values. For example, `invalidSatoshis`
     * (`0xffffffffffffffff` - the maximum uint64 value) is a clearly impossible
     * `satoshis` value for version 1 and 2 transactions. As such, this value can
     * safely by used by transaction signing and verification implementations to
     * ensure that an otherwise properly-signed transaction can never be included
     * n the blockchain, e.g. for transaction size estimation or off-chain Bitauth
     * signatures.
     *
     * To convert this value to and from a `BigInt` use `bigIntToBinUint64LE` and
     * `binToBigIntUint64LE`, respectively.
     */ readonly satoshis : Amount ; } /**
 * The maximum uint64 value – an impossibly large, intentionally invalid value
 * for `satoshis`. See `Transaction.satoshis` for details.
 */ export const invalidSatoshis = Uint8Array . from ( [ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ] ) ; /**
 * Data type representing a transaction.
 */ export interface Transaction < InputType = Input , OutputType = Output > { /**
     * An array of inputs included in this transaction.
     *
     * Input order is critical to signing serializations, and reordering inputs
     * may invalidate transactions.
     */ inputs : InputType [ ] ; remarks locktime : number ; /**
     * An array of outputs included in this transaction.
     *
     * Output order is critical to signing serializations, and reordering outputs
     * may invalidate transactions.
     */ outputs : OutputType [ ] ; /**
     * The version of this transaction – a positive integer from `0` to a maximum
     * of `4294967295`. Since BIP68, most transactions use a version of `2`.
     */ version : number ; } export interface CompilationDirectiveLocking < CompilerType , CompilationDataType > { /**
     * The `Compiler` with which to generate bytecode.
     */ compiler : CompilerType ; /**
     * The `CompilationData` required to compile the specified script.
     */ data ? : CompilationDataType ; /**
     * The script ID to compile.
     */ script : string ; } export interface CompilationDirectiveUnlocking < CompilerType , CompilationDataType > extends CompilationDirectiveLocking < CompilerType , CompilationDataType > { /**
     * The `satoshis` value of the `Output` being spent by this input. Required
     * for use in signing serializations.
     */ satoshis : Output [ 'satoshis' ] ; } export interface CompilationDirectiveUnlockingEstimate < CompilerType , CompilationDataType > extends CompilationDirectiveUnlocking < CompilerType , CompilationDataType > { /**
     * The scenario ID which can be used to estimate the final size of this
     * unlocking script. This is required when using fee estimation.
     */ estimate : string ; } /**
 * An input which may optionally use a `CompilationDirectiveUnlocking` as its
 * `unlockingBytecode` property. During compilation, the final `lockingBytecode`
 * will be generated from this directive.
 *
 * If `RequireEstimate` is `true`, all input directives must include an
 * `estimate` scenario ID. See `estimateTransaction` for details.
 */ export type InputTemplate < CompilerType , RequireEstimate = false , CompilationDataType = CompilationData < never > > = Input < ( RequireEstimate extends true ? CompilationDirectiveUnlockingEstimate < CompilerType , CompilationDataType > : CompilationDirectiveUnlocking < CompilerType , CompilationDataType > ) | Uint8Array > ; /**
 * An output which may optionally use a `CompilationDirectiveLocking` as its
 * `lockingBytecode` property. During compilation, the final `lockingBytecode`
 * will be generated from this directive.
 *
 * If `EnableFeeEstimation` is `true`, the `satoshis` value may also be
 * `undefined` (as estimated transactions always set output values to
 * `invalidSatoshis`).
 */ export type OutputTemplate < CompilerType , EnableFeeEstimation = false , CompilationDataType = CompilationData < never > > = Output < CompilationDirectiveLocking < CompilerType , CompilationDataType > | Uint8Array , EnableFeeEstimation extends true ? Uint8Array | undefined : Uint8Array > ; /**
 * A `Transaction` which may optionally use compilation directives in place of
 * `lockingBytecode` and `unlockingBytecode` instances. During transaction
 * generation, these directives will be generated from these directives.
 *
 *  If `EnableFeeEstimation` is `true`, all input directives must include an
 * `estimate` scenario ID, and the `satoshis` value of each output may also be
 * `undefined` (as estimated transactions always set output values to
 * `invalidSatoshis`).
 */ export type TransactionTemplate < CompilerType , EnableFeeEstimation = false , CompilationDataType = CompilationData < never > > = Transaction < InputTemplate < CompilerType , EnableFeeEstimation , CompilationDataType > , OutputTemplate < CompilerType , EnableFeeEstimation , CompilationDataType > > ; /**
 * A transaction template where all output amounts are provided (i.e. the values
 * of each "change" output has been decided). To estimate the final transaction
 * size given a transaction template (and from it, the required transaction
 * fee), see `estimateTransaction`.
 */ export type TransactionTemplateFixed < CompilerType > = TransactionTemplate < CompilerType > ; /**
 * A transaction template which enables fee estimation. The template must
 * include an `inputSatoshis` value (the total satoshi value of all
 * transaction inputs); all unlocking compilation directives must provide an
 * `estimate` scenario ID which is used to estimate the size of the resulting
 * unlocking bytecode; and the `satoshis` value of outputs is optional (all
 * satoshi values will be set to `impossibleSatoshis` in the estimated
 * transaction).
 */ export type TransactionTemplateEstimated < CompilerType > = TransactionTemplate < CompilerType , true > & { /**
     * The total satoshi value of all transaction inputs. This is required when
     * using fee estimation, and is used to calculate the appropriate value of
     * change outputs (outputs with `satoshis` set to `undefined`).
     */ inputSatoshis : number ; } ; /**
 * An error resulting from unsuccessful bytecode generation. Includes the
 * generation type (`locking` or `unlocking`), and the output or input index
 */ export interface BytecodeGenerationErrorBase { /**
     * The type of bytecode that was being generated when this error occurred.
     */ type : 'locking' | 'unlocking' ; /**
     * The input or output index for which this bytecode was being generated. (To )
     */ index : number ; /**
     * The stage of generation at which this error occurred – the `outputs` stage
     * must complete before the `inputs` can begin.
     */ /**
     * If the error occurred after the `parse` stage, the resolved script is
     * provided for analysis or processing (e.g. `getResolvedBytecode`).
     */ resolved ? : ResolvedScript ; /**
     * The compilation errors which occurred while generating this bytecode.
     */ errors : CompilationError [ ] ; } export interface BytecodeGenerationErrorLocking extends BytecodeGenerationErrorBase { type : 'locking' ; } export interface BytecodeGenerationErrorUnlocking extends BytecodeGenerationErrorBase { type : 'unlocking' ; } export interface BytecodeGenerationCompletionBase { /**
     * If `output`, this bytecode was generated for the output at `index` (a
     * `lockingBytecode`). If `input`, the bytecode was generated for the input at
     * `index` (an `unlockingBytecode`).
     */ type : 'output' | 'input' ; /**
     * The index of the input or output for which this bytecode was generated.
     */ index : number ; } export interface BytecodeGenerationCompletionInput extends BytecodeGenerationCompletionBase { type : 'input' ; /**
     * The successfully generated Input.
     */ input : Input ; } export interface BytecodeGenerationCompletionOutput extends BytecodeGenerationCompletionBase { type : 'output' ; /**
     * The successfully generated Output.
     */ output : Output ; } /**
 * A successfully generated `lockingBytecode` (for an output) or
 * `unlockingBytecode` (for an input). Because this bytecode generation was
 * successful, the associated compilation directive in the transaction template
 * can be replaced with this result for subsequent compilations. For example, if
 * most inputs were successfully compiled, but some inputs require keys held by
 * another entity, the transaction template can be updated such that only the
 * final inputs contain compilation directives.
 */ export type BytecodeGenerationCompletion = BytecodeGenerationCompletionOutput | BytecodeGenerationCompletionInput ; export interface TransactionGenerationSuccess { success : true ; transaction : Transaction ; } export type TransactionGenerationError = { success : false ; completions : BytecodeGenerationCompletionOutput [ ] ; errors : BytecodeGenerationErrorLocking [ ] ; /**
     * Error(s) occurred at the `output` stage of compilation, so the `input`
     * stage never began.
     */ stage : 'outputs' ; } | { success : false ; completions : BytecodeGenerationCompletionInput [ ] ; errors : BytecodeGenerationErrorUnlocking [ ] ; /**
     * Error(s) occurred at the `input` stage of compilation, meaning the
     * `output` stage completed successfully.
     */ stage : 'inputs' ; } ; export type TransactionGenerationAttempt = TransactionGenerationSuccess | TransactionGenerationError ;