Interface CompilationData<CompilationContext>

Data required at compilation time to generate the bytecode for a particular CashAssembly Template script.

Type Parameters

Hierarchy

  • CompilationData

Properties

bytecode?: {
    [fullIdentifier: string]: Uint8Array;
}

A map of full identifiers to pre-computed bytecode for this compilation.

This is always used to provide bytecode for AddressData and WalletData, and it can also be used to provide public keys and signatures that have been pre-computed by other entities (e.g. when computing these would require access to private keys held by another entities).

The provided fullIdentifier should match the complete identifier for each item, e.g. some_wallet_data, variable_id.public_key, or variable_id.signature.all_outputs.

To provide AddressData or WalletData from advanced user interfaces, consider parsing input with compileCashAssembly.

Remarks

It is security-critical that only identifiers provided by the entities expected to provide them are included here. For example:

  1. When generating a lockingBytecode for a 2-of-2 wallet, a malicious entity could provide a pre-computed value for us.public_key that is equal to them.public_key such that the resulting lockingBytecode is entirely controlled by that entity.

  2. When generating an unlockingBytecode that includes a data signature, if a malicious entity can provide a pre-computed value for identifiers present in the message, the malicious entity can trick the compiling entity into signing an unintended message, e.g. creating a false attestation or releasing funds from an unrelated wallet. (This can be partially mitigated by avoiding key reuse.)

To safely include identifiers from external entities, the compilation must first be evaluated only with trusted information (variables owned by or previously validated by the compiling entity). On unsuccessful compilations, missing variables can be extracted with extractMissingVariables, and each missing variable should be filled only by bytecode values provided by entities from which they were expected.

Type declaration

  • [fullIdentifier: string]: Uint8Array
compilationContext?: CompilationContext

The CompilationContext expected by this particular compiler for any operations used in the compilation.

currentBlockHeight?: number

The current block height at address creation time.

currentBlockTime?: number

The current MTP block time as a UNIX timestamp at address creation time.

Note, this is never a current timestamp, but rather the median timestamp of the last 11 blocks. It is therefore approximately one hour in the past.

Every block has a precise MTP block time, much like a block height. See BIP113 for details.

hdKeys?: {
    addressIndex?: number;
    hdPrivateKeys?: {
        [entityId: string]: string;
    };
    hdPublicKeys?: {
        [entityId: string]: string;
    };
}

An object describing the settings used for HdKey variables in this compilation.

Type declaration

  • Optional addressIndex?: number

    The current address index to be used for this compilation. The addressIndex gets added to each HdKeys addressOffset to calculate the dynamic index (i) used in each privateDerivationPath or publicDerivationPath.

    This is required for any compiler operation that requires derivation. Typically, the value is incremented by one for each address in a wallet.

  • Optional hdPrivateKeys?: {
        [entityId: string]: string;
    }

    A map of entity IDs to master HD private keys. These master HD private keys are used to derive each HdKey variable assigned to that entity (as specified in entityOwnership) according to its privateDerivationPath.

    HD private keys may be encoded for either mainnet or testnet (the network information is ignored).

    If both an HD private key (in hdPrivateKeys) and HD public key (in hdPublicKeys) are provided for the same entity in the same compilation (not recommended), only the HD private key is used.

    • [entityId: string]: string
  • Optional hdPublicKeys?: {
        [entityId: string]: string;
    }

    A map of entity IDs to HD public keys. These HD public keys are used to derive public keys for each HdKey variable assigned to that entity (as specified in entityOwnership) according to its publicDerivationPath.

    HD public keys may be encoded for either mainnet or testnet (the network information is ignored).

    If both an HD private key (in hdPrivateKeys) and HD public key (in hdPublicKeys) are provided for the same entity in the same compilation (not recommended), the HD private key is used.

    • [entityId: string]: string
keys?: {
    privateKeys?: {
        [variableId: string]: Uint8Array;
    };
}

An object describing the settings used for Key variables in this compilation.

Type declaration

  • Optional privateKeys?: {
        [variableId: string]: Uint8Array;
    }

    A map of Key variable IDs to their private keys for this compilation.

    • [variableId: string]: Uint8Array

Generated using TypeDoc