Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions packages/ordinalsplus/src/transactions/reveal-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export async function createRevealTransaction(params: RevealTransactionParams):
'Missing commit address, script, or inscription data in prepared inscription for reveal'
);
}
const commitScript = preparedInscription.commitAddress.script;
const commitAddress = preparedInscription.commitAddress.address;
const inscriptionObject = preparedInscription.inscription;
const pubKey = preparedInscription.revealPublicKey;
Expand All @@ -166,7 +165,6 @@ export async function createRevealTransaction(params: RevealTransactionParams):
ORDINAL_CUSTOM_SCRIPTS
);

console.log(`[DEBUG-REVEAL-FIX] Using PRE-CALCULATED commit script for witness: ${Buffer.from(commitScript).toString('hex')}`);
console.log(`[DEBUG-REVEAL-FIX] Expected Commit Address from prep: ${commitAddress}`);
console.log(`[DEBUG-REVEAL-FIX] Reveal Payment Script (for input): ${revealPayment.script ? Buffer.from(revealPayment.script).toString('hex') : 'undefined'}`);
// Log the entire revealPayment object to inspect its structure for tapleaf info
Expand All @@ -177,9 +175,9 @@ export async function createRevealTransaction(params: RevealTransactionParams):
...revealPayment,
txid: selectedUTXO.txid,
index: selectedUTXO.vout,
witnessUtxo: {
script: commitScript,
amount: inputAmount
witnessUtxo: {
script: revealPayment.script,
amount: inputAmount
},
// Removed incorrect redeemScript property.
// We need to inspect revealPayment object structure to find where
Expand All @@ -195,7 +193,6 @@ export async function createRevealTransaction(params: RevealTransactionParams):

// DEBUG-COMMIT-REVEAL logging
console.log(`[DEBUG-COMMIT-REVEAL] Reveal Address used for output: ${outputAddress}`);
console.log(`[DEBUG-COMMIT-REVEAL] Commit Script used for witness: ${Buffer.from(commitScript).toString('hex')}`);
console.log(`[DEBUG-COMMIT-REVEAL] Using Reveal Public Key for signing: ${Buffer.from(pubKey).toString('hex')}`);

// Add progress event for adding input
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { describe, test, expect } from 'bun:test';
import * as btc from '@scure/btc-signer';
import { KeyPairGenerator } from '../../src/key-management/key-pair-generator';
import { createTextInscription } from '../../src/inscription';
import { prepareCommitTransaction } from '../../src/transactions/commit-transaction';
import { signTransaction } from '../../src/transactions/transaction-signing';
import { createRevealTransaction } from '../../src/transactions/reveal-transaction';
import { Utxo } from '../../src/types';

// Integration test that builds a commit and reveal transaction pair
// ensuring both transactions are fully signed and ready for broadcast.

describe('Commit & Reveal Integration', () => {
test('should create broadcastable commit and reveal transactions', async () => {
// Generate funding key pair for P2WPKH input
const fundingKey = KeyPairGenerator.generateSecp256k1KeyPair({ includeAddress: true, network: 'testnet' });
const fundingAddress = fundingKey.address!;
const fundingPayment = btc.p2wpkh(fundingKey.publicKeyCompressed, btc.TEST_NETWORK);

// Mock UTXO used to fund the commit transaction
const utxo: Utxo = {
txid: 'aa'.repeat(32),
vout: 0,
value: 20_000,
scriptPubKey: Buffer.from(fundingPayment.script).toString('hex'),
script: { type: 'p2wpkh', address: fundingAddress }
};

// Prepare inscription and commit transaction
const inscription = createTextInscription('Integration commit-reveal', 'testnet');
const commitRes = await prepareCommitTransaction({
inscription,
utxos: [utxo],
changeAddress: fundingAddress,
feeRate: 1,
network: 'testnet'
});

// Sign the commit transaction so it would be valid for broadcast
const signedCommit = await signTransaction(commitRes.commitPsbt, {
privateKey: fundingKey.privateKey,
transactionType: 'COMMIT'
});

expect(signedCommit.tx.isFinal).toBe(true);
expect(signedCommit.hex.length).toBeGreaterThan(0);

// Build UTXO from commit output for the reveal transaction
const commitOutput = signedCommit.tx.getOutput(0);
const commitUtxo: Utxo = {
txid: signedCommit.tx.id,
vout: 0,
value: Number(commitOutput.amount),
script: { type: 'p2tr', address: inscription.commitAddress.address }
};

// Create and sign the reveal transaction using the inscription key
// Mock network calls used by system health check
(globalThis as any).fetch = async () => ({ ok: true });
const revealRes = await createRevealTransaction({
selectedUTXO: commitUtxo,
preparedInscription: inscription,
feeRate: 1,
network: btc.TEST_NETWORK,
privateKey: inscription.revealPrivateKey!,
commitTransactionId: signedCommit.tx.id
});

expect(revealRes.tx.isFinal).toBe(true);
expect(revealRes.hex.length).toBeGreaterThan(0);

// Verify reveal spends the exact script produced in the commit output
const commitScriptHex = Buffer.from(commitOutput.script).toString('hex');
const revealInput = revealRes.tx.getInput(0);
const revealScriptHex = Buffer.from(revealInput.witnessUtxo!.script).toString('hex');
expect(revealScriptHex).toBe(commitScriptHex);
});
});