Interface CompilerConfiguration<CompilationContext, CompilerKeyOperations, CompilerSigningSerializationOperations, CompilerAddressDataOperations, CompilerWalletDataOperations, CompilerCurrentBlockHeightOperations, CompilerCurrentBlockTimeOperations>

The full context required to compile a given CashAssembly Template script – everything required for the compiler to understand the CompilationData and generate the compiled bytecode (targeting a specific AuthenticationVirtualMachine).

Remarks

A CompilerConfiguration must include a subset of the script's AuthenticationTemplate – all the variables and scripts referenced (including children of children) by the script in question.

The context must also include an object mapping of opcode identifiers to the bytecode they generate.

If keys are used, an implementation of sha256 and secp256k1 is required. If the script requires evaluations during compilation, the evaluating AuthenticationVirtualMachine must also be included.

Type Parameters

  • CompilationContext = unknown

    additional data available to compiler operations, e.g. transaction signing serialization components

  • CompilerKeyOperations extends string | false = CompilerOperationsKeysCommon

    a list of valid compiler operations for Key and HdKey variables, e.g. 'public_key' | 'signature', or false if only a single compiler operation is used for all instances

  • CompilerSigningSerializationOperations extends string | false = CompilerOperationsSigningSerializationCommon

    a list of valid compiler operations for Key and HdKey variables, e.g. "version" | "transaction_outpoints" | ..., or false if only a single compiler operation is used for all signing_serialization instances

  • CompilerAddressDataOperations extends string | false = false

    a list of valid compiler operations for AddressData variables or false if only a single compiler operation is used for all AddressData instances (default: false)

  • CompilerWalletDataOperations extends string | false = false

    a list of valid compiler operations for WalletData variables or false if only a single compiler operation is used for all WalletData instances (default: false)

  • CompilerCurrentBlockHeightOperations extends string | false = false

    a list of valid compiler operations for current_block_height variables or false if only a single compiler operation is used for all instances (default: false)

  • CompilerCurrentBlockTimeOperations extends string | false = false

    a list of valid compiler operations for current_block_time variables or false if only a single compiler operation is used for all instances (default: false)

Hierarchy

  • CompilerConfiguration

Properties

createAuthenticationProgram?: ((evaluationBytecode: Uint8Array) => any)

Type declaration

    • (evaluationBytecode: Uint8Array): any
    • A method that accepts the compiled bytecode contents of a CashAssembly evaluation and produces the equivalent AuthenticationProgram to be evaluated by the VM. This method is used internally to compute CashAssembly evaluations. See createAuthenticationProgramEvaluationCommon for details.

      Parameters

      • evaluationBytecode: Uint8Array

      Returns any

entityOwnership?: {
    [variableId: string]: string;
}

An object mapping template variable identifiers to the entity identifiers responsible for them. This is required for HdKey support, as each entity uses a single HD private key (provided in hdKeys.hdPrivateKeys) or HD public key (provided in hdKeys.hdPublicKeys) per compilation, and each HdKey variable is derived from this key.

To avoid compilation errors, this object must contain all HdKey variables referenced by the script being compiled (including in child scripts). To enable support for error handling like extractMissingVariables, it's recommended that all variables be provided here.

Type declaration

  • [variableId: string]: string
lockingScriptTypes?: {
    [lockingScriptId: string]: "p2sh20" | "p2sh32" | "standard";
}

An object mapping the script identifiers of locking scripts to their locking script type, either standard or p2sh20.

This is used to transform compilation results into the proper structure for P2SH20 locking and unlocking scripts.

When compiling locking scripts of type p2sh20, the result will be placed in a P2SH20 "redeemScript" format: OP_HASH160 <$(<result> OP_HASH160)> OP_EQUAL

When compiling unlocking scripts that unlock locking scripts of type p2sh20, the result will be transformed into the P2SH20 unlocking format: result <locking_script> (where locking_script is the compiled bytecode of the locking script, without the "redeemScript" transformation.)

By default, all scripts are assumed to have the type standard.

Type declaration

  • [lockingScriptId: string]: "p2sh20" | "p2sh32" | "standard"
opcodes?: {
    [opcodeIdentifier: string]: Uint8Array;
}

An object mapping opcode identifiers to the bytecode they generate.

Type declaration

  • [opcodeIdentifier: string]: Uint8Array
operations?: {
    addressData?: CompilerAddressDataOperations extends string ? { [ operationId in string]?: CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>> } : CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>>;
    currentBlockHeight?: CompilerCurrentBlockHeightOperations extends string ? { [ operationId in string]?: CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>> } : CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>>;
    currentBlockTime?: CompilerCurrentBlockTimeOperations extends string ? { [ operationId in string]?: CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>> } : CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>>;
    hdKey?: CompilerKeyOperations extends string ? { [ operationId in string]?: CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>> } : CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>>;
    key?: CompilerKeyOperations extends string ? { [ operationId in string]?: CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>> } : CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>>;
    signingSerialization?: CompilerSigningSerializationOperations extends string ? { [ operationId in string]?: CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>> } : CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>>;
    walletData?: CompilerWalletDataOperations extends string ? { [ operationId in string]?: CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>> } : CompilerOperation<CompilationContext, false, CompilationData<CompilationContext>, CompilerConfiguration<CompilationContext, CompilerOperationsKeysCommon, CompilerOperationsSigningSerializationCommon, false, false, false, false>>;
}

An object specifying the operations made available by this compiler configuration for each variable type. For example, keys typically support public key derivation (.public_key) and several signature types.

Compiler operations can be specified as a single operation for all instances of a variable type (as is the default for AddressData or WalletData), or they can be specified as an object, where each key is a valid operation name (as is the default for Key and HdKey).

Type declaration

ripemd160?: {
    hash: ((input: Uint8Array) => Uint8Array);
}

An implementation of ripemd160 is required for any scripts that include HdKeys. This can be instantiated with instantiateRipemd160.

Type declaration

  • hash: ((input: Uint8Array) => Uint8Array)
      • (input: Uint8Array): Uint8Array
      • Returns the ripemd160 hash of the provided input.

        To incrementally construct a ripemd160 hash (e.g. for streaming), use init, update, and final.

        Parameters

        • input: Uint8Array

          a Uint8Array to be hashed using ripemd160

        Returns Uint8Array

scenarios?: {
    [scriptId: string]: AuthenticationTemplateScenario;
}

An object mapping scenario identifiers to the AuthenticationTemplateScenarios they represent.

Type declaration

scripts: {
    [scriptId: string]: string;
}

An object mapping script identifiers to the text of script in CashAssembly.

To avoid compilation errors, this object must contain all scripts referenced by the script being compiled (including children of children).

Type declaration

  • [scriptId: string]: string
secp256k1?: {
    addTweakPrivateKey: ((privateKey: Uint8Array, tweakValue: Uint8Array) => string | Uint8Array);
    addTweakPublicKeyCompressed: ((publicKey: Uint8Array, tweakValue: Uint8Array) => string | Uint8Array);
    derivePublicKeyCompressed: ((privateKey: Uint8Array) => string | Uint8Array);
    signMessageHashDER: ((privateKey: Uint8Array, messageHash: Uint8Array) => string | Uint8Array);
    signMessageHashSchnorr: ((privateKey: Uint8Array, messageHash: Uint8Array) => string | Uint8Array);
}

An implementation of secp256k1 is required for any scripts that include signatures. This can be instantiated with instantiateSecp256k1.

Type declaration

  • addTweakPrivateKey: ((privateKey: Uint8Array, tweakValue: Uint8Array) => string | Uint8Array)
      • (privateKey: Uint8Array, tweakValue: Uint8Array): string | Uint8Array
      • Tweak a privateKey by adding tweakValue to it.

        Returns an error message if the private key is invalid or if the addition fails.

        Parameters

        • privateKey: Uint8Array

          a valid secp256k1 private key

        • tweakValue: Uint8Array

          256 bit value to tweak by (BE)

        Returns string | Uint8Array

  • addTweakPublicKeyCompressed: ((publicKey: Uint8Array, tweakValue: Uint8Array) => string | Uint8Array)
      • (publicKey: Uint8Array, tweakValue: Uint8Array): string | Uint8Array
      • Tweak a publicKey by adding tweakValue times the generator to it.

        Returns an error message if the provided public key could not be parsed or is not valid, or if the addition failed.

        The returned public key will be in compressed format.

        Parameters

        • publicKey: Uint8Array

          a public key.

        • tweakValue: Uint8Array

          256 bit value to tweak by (BE)

        Returns string | Uint8Array

  • derivePublicKeyCompressed: ((privateKey: Uint8Array) => string | Uint8Array)
      • (privateKey: Uint8Array): string | Uint8Array
      • Derive a compressed public key from a valid secp256k1 private key.

        Returns an error message if the provided private key is too large (see validatePrivateKey).

        Parameters

        • privateKey: Uint8Array

          a valid secp256k1, 32-byte private key

        Returns string | Uint8Array

  • signMessageHashDER: ((privateKey: Uint8Array, messageHash: Uint8Array) => string | Uint8Array)
      • (privateKey: Uint8Array, messageHash: Uint8Array): string | Uint8Array
      • Create an ECDSA signature in DER format. The created signature is always in lower-S form and follows RFC 6979.

        Returns an error message if the provided private key is too large (see validatePrivateKey).

        Parameters

        • privateKey: Uint8Array

          a valid secp256k1, 32-byte private key

        • messageHash: Uint8Array

          the 32-byte message hash to be signed

        Returns string | Uint8Array

  • signMessageHashSchnorr: ((privateKey: Uint8Array, messageHash: Uint8Array) => string | Uint8Array)
      • (privateKey: Uint8Array, messageHash: Uint8Array): string | Uint8Array
      • Create a Secp256k1 EC-Schnorr-SHA256 signature (Bitcoin Cash construction).

        Signatures are 64-bytes, non-malleable, and support both batch validation and multiparty signing. Nonces are generated using RFC6979, where the Section 3.6, 16-byte ASCII "additional data" is set to Schnorr+SHA256 . This avoids leaking a private key by inadvertently creating both an ECDSA signature and a Schnorr signature using the same nonce.

        Returns an error message if the provided private key is too large (see validatePrivateKey).

        Parameters

        • privateKey: Uint8Array

          a valid secp256k1, 32-byte private key

        • messageHash: Uint8Array

          the 32-byte message hash to be signed

        Returns string | Uint8Array

sha256?: {
    hash: ((input: Uint8Array) => Uint8Array);
}

An implementation of sha256 is required for any scripts that include signatures. This can be instantiated with instantiateSha256.

Type declaration

  • hash: ((input: Uint8Array) => Uint8Array)
      • (input: Uint8Array): Uint8Array
      • Returns the sha256 hash of the provided input.

        To incrementally construct a sha256 hash (e.g. for streaming), use init, update, and final.

        Parameters

        • input: Uint8Array

          a Uint8Array to be hashed using sha256

        Returns Uint8Array

sha512?: {
    hash: ((input: Uint8Array) => Uint8Array);
}

An implementation of sha512 is required for any scripts that include HdKeys. This can be instantiated with instantiateSha512.

Type declaration

  • hash: ((input: Uint8Array) => Uint8Array)
      • (input: Uint8Array): Uint8Array
      • Returns the sha512 hash of the provided input.

        To incrementally construct a sha512 hash (e.g. for streaming), use init, update, and final.

        Parameters

        • input: Uint8Array

          a Uint8Array to be hashed using sha512

        Returns Uint8Array

sourceScriptIds?: string[]

Only for use when recursively calling compileScript (e.g. in compiler operations).

The "breadcrumb" path of script IDs currently being compiled, including the current script. (E.g. ["grandparentId", "parentId", "scriptId"])

CashAssembly identifier resolution must be acyclic. To prevent an infinite loop, IdentifierResolutionFunctions must abort resolution if they encounter their own id while resolving another identifier. Likewise, child scripts being resolved by a parent script may not reference any script that is already in the process of being resolved.

unlockingScriptTimeLockTypes?: {
    [unlockingScriptId: string]: "height" | "timestamp";
}

An object mapping the identifiers of unlocking scripts to their timeLockType.

The timestamp type indicates that the transaction's locktime is provided as a UNIX timestamp (the locktime value is greater than or equal to 500000000).

The height type indicates that the transaction's locktime is provided as a block height (the locktime value is less than 500000000).

See AuthenticationTemplateScript.timeLockType for details.

Type declaration

  • [unlockingScriptId: string]: "height" | "timestamp"
unlockingScripts?: {
    [unlockingScriptId: string]: string;
}

An object mapping the identifiers of unlocking scripts to the identifiers of the locking scripts they unlock. This is used to identify the coveredBytecode used in signing serializations, and it is required for all signature operations and many signing serialization operations.

Type declaration

  • [unlockingScriptId: string]: string
variables?: {
    [variableId: string]: AuthenticationTemplateVariable;
}

An object mapping template variable identifiers to the AuthenticationTemplateVariable describing them.

To avoid compilation errors, this object must contain all variables referenced by the script being compiled (including in child scripts).

Type declaration

vm?: AuthenticationVirtualMachine<any, any, any>

The AuthenticationVirtualMachine on which CashAssembly evaluation results will be computed.

Generated using TypeDoc