UNPKG

@covenance/dlc

Version:

Crypto and Bitcoin functions for Covenance DLC implementation

72 lines 3.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.signCetWithAdaptorSig = signCetWithAdaptorSig; exports.verifyCetAdaptorSig = verifyCetAdaptorSig; exports.verifyCetSignature = verifyCetSignature; exports.sigToTaprootBuf = sigToTaprootBuf; const sighash_1 = require("./sighash"); const counterparty_1 = require("../crypto/counterparty"); const general_1 = require("../crypto/general"); const utils_1 = require("../utils"); /** * Creates an adaptor signature for a CET * @param counterpartyPrivKey - The private key of the counterparty creating the signature * @param oracleSigPoint - The oracle's signature point for the event outcome * @param cet - The CET transaction to sign * @param inputIndex - The index of the input to sign in the CET * @param tapleafHash - The hash of the tapleaf * @returns The adaptor signature for the CET */ async function signCetWithAdaptorSig(counterpartyPrivKey, oracleSigPoint, cet, inputIndex, tapleafHash) { // Get the sighash for the CET const cetSighash = (0, sighash_1.sighashForAdaptorSig)(cet, inputIndex, tapleafHash); // Create the adaptor signature using the sighash as the message return (0, counterparty_1.createAdaptorSig)(counterpartyPrivKey, oracleSigPoint, cetSighash); } /** * Verifies an adaptor signature for a CET * @param signature - The adaptor signature to verify * @param counterpartyPubKey - The counterparty's public key * @param oracleSigPoint - The oracle's signature point for the event outcome * @param cet - The CET transaction that was signed * @param inputIndex - The index of the input that was signed * @param tapleafHash - The hash of the tapleaf * @returns True if the signature is valid, false otherwise */ async function verifyCetAdaptorSig(signature, counterpartyPubKey, oracleSigPoint, cet, inputIndex, tapleafHash) { // Get the sighash for the CET const cetSighash = (0, sighash_1.sighashForAdaptorSig)(cet, inputIndex, tapleafHash); // Verify the signature using the sighash as the message return (0, counterparty_1.verifyAdaptorSig)(signature, counterpartyPubKey, cetSighash, oracleSigPoint); } /** * Verifies a completed signature for a CET * @param signature - The completed signature to verify * @param counterpartyPubKey - The counterparty's public key * @param cet - The CET transaction that was signed * @param inputIndex - The index of the input that was signed * @param tapleafHash - The hash of the tapleaf * @returns True if the signature is valid, false otherwise */ async function verifyCetSignature(signature, counterpartyPubKey, cet, inputIndex, tapleafHash) { // Get the sighash for the CET const cetSighash = (0, sighash_1.sighashForAdaptorSig)(cet, inputIndex, tapleafHash); // Verify the signature using the sighash as the message return (0, general_1.verifySig)(signature, counterpartyPubKey, cetSighash); } /** * Taproot/SegWit-v1 Schnorr signature serializer * @param signature - The signature to serialize * @param sighash - The sighash to serialize * @returns The serialized signature */ function sigToTaprootBuf({ R, s }, sighash = 0x00) { const addFlag = sighash !== 0x00; const out = new Uint8Array(addFlag ? 65 : 64); (0, utils_1.be32)(out, 0, R.x); (0, utils_1.be32)(out, 32, s); if (addFlag) out[64] = sighash; return out; } //# sourceMappingURL=signature.js.map