Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface AuthenticationVirtualMachine<AuthenticationProgram, ProgramState>

A set of pure-functions allowing authentication programs to be evaluated and inspected.

Type parameters

  • AuthenticationProgram

  • ProgramState

Hierarchy

  • AuthenticationVirtualMachine

Index

Properties

debug

debug: (program: Readonly<AuthenticationProgram>) => ProgramState[]

Debug a program by fully evaluating it, cloning and adding each intermediate ProgramState to the returned array. The first ProgramState in the returned array is the initial program state, and the last ProgramState in the returned array is the result of the evaluation.

Note, If the virtual machine is multi-phasic (as is the case with all bitcoin forks), the initial program state at the start of of each phase will appear in the debug trace. For example, all inputs in all bitcoin forks use at least two phases 1) the unlocking phase 2) the locking phase. Inputs which match the P2SH format perform a third P2SH phase. Other virtual machines may include different phases (e.g. the SegWit phase in BTC). For each phase performed, the count of program states in the final debug trace will increase by one, even if the phase includes no instructions.

remarks

Even for simple virtual machines, this method includes one final program state in addition to the output which would otherwise be produced by stateDebug. This occurs because the evaluate method of the instruction set must return one final program state after stateContinue has produced a false. Often, this is cloned from the previous program state, but it is also possible that this final state will include changes produced by the remaining portion of the instruction set's evaluate method (e.g. P2SH evaluation). In any case, this final program state is not a "duplicate": it is the finalized result of the complete virtual machine evaluation.

param

the AuthenticationProgram to debug

Type declaration

    • (program: Readonly<AuthenticationProgram>): ProgramState[]
    • Parameters

      • program: Readonly<AuthenticationProgram>

      Returns ProgramState[]

evaluate

evaluate: (program: Readonly<AuthenticationProgram>) => ProgramState

Fully evaluate a program, returning the resulting ProgramState.

param

the AuthenticationProgram to evaluate

Type declaration

    • (program: Readonly<AuthenticationProgram>): ProgramState
    • Parameters

      • program: Readonly<AuthenticationProgram>

      Returns ProgramState

stateContinue

stateContinue: (state: Readonly<ProgramState>) => boolean

Test the ProgramState to determine if execution should continue.

Type declaration

    • (state: Readonly<ProgramState>): boolean
    • Parameters

      • state: Readonly<ProgramState>

      Returns boolean

stateDebug

stateDebug: (state: Readonly<ProgramState>) => ProgramState[]

Return an array of program states by fully evaluating state, cloning and adding each intermediate state to the returned array. The first ProgramState in the returned array is the initial program state, and the last ProgramState in the returned array is the first program state which returns false when provided to stateContinue.

Note, this method is typically an implementation detail of the virtual machine and cannot produce a final result. In most cases, debug is the proper method to debug a program.

Type declaration

    • (state: Readonly<ProgramState>): ProgramState[]
    • Parameters

      • state: Readonly<ProgramState>

      Returns ProgramState[]

stateEvaluate

stateEvaluate: (state: Readonly<ProgramState>) => ProgramState

Return a new program state by cloning and fully evaluating state.

To evaluate a state, the state is cloned and provided to stateStepMutate until a final result is obtained (a ProgramState which returns false when provided to stateContinue).

Note, this method is typically an implementation detail of the virtual machine and cannot produce a final result. In most cases, evaluate is the proper method to evaluate a program.

param

the program state to evaluate

Type declaration

    • (state: Readonly<ProgramState>): ProgramState
    • Parameters

      • state: Readonly<ProgramState>

      Returns ProgramState

stateStep

stateStep: (state: Readonly<ProgramState>) => ProgramState

Clones and return a new program state advanced by one step.

param

the program state to advance

Type declaration

    • (state: Readonly<ProgramState>): ProgramState
    • Parameters

      • state: Readonly<ProgramState>

      Returns ProgramState

stateStepMutate

stateStepMutate: (state: ProgramState) => ProgramState

A faster, less-safe version of step which directly modifies the provided program state.

param

the program state to mutate

Type declaration

    • (state: ProgramState): ProgramState
    • Parameters

      • state: ProgramState

      Returns ProgramState

verify

verify: (state: ProgramState) => true | string

Verify a program state has completed evaluation successfully.

remarks

This method verifies a final ProgramState as emitted by the evaluate or debug methods. When manually using the stateStep or stateStepMutate methods, ensure the ProgramState has finished evaluation using the stateContinue method.

param

the program state to verify

Type declaration

    • (state: ProgramState): true | string
    • Parameters

      • state: ProgramState

      Returns true | string

Generated using TypeDoc