Table of Contents

Class ArkadeTweak

Namespace
NArk.Arkade.Crypto
Assembly
NArk.Arkade.dll

Computes the BIP-340 tagged hashes tagged_hash("ArkScriptHash", script) and tagged_hash("ArkWitnessHash", witness), plus the resulting "emulator-tweaked" public key emulator_pubkey + tagged_hash · G that ArkadeScript leaves bind signing authority to a specific script body.

public static class ArkadeTweak
Inheritance
ArkadeTweak
Inherited Members

Remarks

The emulator service signs an input only after validating that the script attached to that input hashes to the tweak it computed for the signing key — i.e. the tweak commits the signature path to the exact bytes of the script. Reference: https://github.com/arkade-os/emulator — section on tweaked signing keys.

Tag strings are the literal ASCII ScriptTagName and WitnessTagName. Both producer and verifier MUST use the same tag — divergence here would silently lock funds to a key the emulator won't sign for.

Fields

ScriptTagName

The BIP-340 tag bound into every Arkade script hash.

public const string ScriptTagName = "ArkScriptHash"

Field Value

string

WitnessTagName

The BIP-340 tag bound into every Arkade witness hash.

public const string WitnessTagName = "ArkWitnessHash"

Field Value

string

Methods

ComputeScriptHash(ReadOnlySpan<byte>)

Computes SHA256(SHA256(tag) || SHA256(tag) || script) for the ScriptTagName tag — the 32-byte scalar used to tweak the emulator's public key.

public static byte[] ComputeScriptHash(ReadOnlySpan<byte> script)

Parameters

script ReadOnlySpan<byte>

Returns

byte[]

ComputeWitnessHash(ReadOnlySpan<byte>)

Computes SHA256(SHA256(tag) || SHA256(tag) || witness) for the WitnessTagName tag — the hash pushed by OP_INSPECTINPUTARKADEWITNESSHASH. Returns 32 zero bytes for an empty witness, matching the ts-sdk / emulator reference.

public static byte[] ComputeWitnessHash(ReadOnlySpan<byte> witness)

Parameters

witness ReadOnlySpan<byte>

Returns

byte[]

Tweak(ECPubKey, ReadOnlySpan<byte>)

Convenience overload that accepts the emulator's compressed public key (as returned by GET /v1/info's signerPubkey) and tweaks its x-only form. The key's parity is dropped before tweaking, matching the ts-sdk / emulator reference.

public static TaprootPubKey Tweak(ECPubKey emulatorPubKey, ReadOnlySpan<byte> script)

Parameters

emulatorPubKey ECPubKey
script ReadOnlySpan<byte>

Returns

TaprootPubKey

Tweak(TaprootPubKey, ReadOnlySpan<byte>)

Tweaks emulatorPubKey with tagged_hash("ArkScriptHash", script) and returns the resulting x-only public key. This is the key the emulator will sign with for any input whose attached ArkadeScript matches script.

public static TaprootPubKey Tweak(TaprootPubKey emulatorPubKey, ReadOnlySpan<byte> script)

Parameters

emulatorPubKey TaprootPubKey
script ReadOnlySpan<byte>

Returns

TaprootPubKey

Exceptions

ArgumentException

The tagged hash is not a valid scalar (≥ secp256k1 group order or zero), or the addition produced the point at infinity. Both cases are vanishingly improbable for honestly-generated scripts but MUST be rejected — a silent fall-through would let a caller construct a commitment to a script the emulator cannot honour.