Skip to content

Commit

Permalink
Fix LEAF_VERSION_TAPSCRIPT
Browse files Browse the repository at this point in the history
  • Loading branch information
opcatdev committed Jan 11, 2025
1 parent e39a107 commit d02dca8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cat-protocol/cat-sdk",
"version": "1.0.14",
"version": "1.0.15",
"description": "CAT protocol SDK.",
"author": "catprotocol.org",
"main": "./dist/cjs/index.js",
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/src/lib/covenant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ByteString, FixedArray, hash160, SmartContract, UTXO } from 'scrypt-ts'
import { Tap } from '@cmdcode/tapscript' // Requires node >= 19
import { btc } from './btc'
import { btc, LEAF_VERSION_TAPSCRIPT } from './btc'
import { SupportedNetwork, TAPROOT_ONLY_SCRIPT_SPENT_KEY } from './constants'
import { TapLeafSmartContract } from './tapLeafSmartContract'
import { Optional, p2trLockingScriptToAddr } from './utils'
Expand Down Expand Up @@ -51,13 +51,15 @@ export abstract class Covenant<StateT = undefined> {
}
const [tpubkey] = Tap.getPubKey(TAPROOT_ONLY_SCRIPT_SPENT_KEY, {
tree: tapTree,
version: LEAF_VERSION_TAPSCRIPT
})

for (const cK of subContracts.map(c => c.alias || 'default')) {
const taprootContract = tapLeafContracts[cK]
const [, cblock] = Tap.getPubKey(TAPROOT_ONLY_SCRIPT_SPENT_KEY, {
target: taprootContract.tapScript,
tree: tapTree,
version: LEAF_VERSION_TAPSCRIPT
})
taprootContract.tpubkey = tpubkey
taprootContract.cblock = cblock
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/lib/tapLeafSmartContract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { hash160, int2ByteString, SmartContract } from 'scrypt-ts'
import { Tap } from '@cmdcode/tapscript' // Requires node >= 19
import { bitcoinjs, btc } from './btc'
import { bitcoinjs, btc, LEAF_VERSION_TAPSCRIPT } from './btc'
import { TAPROOT_ONLY_SCRIPT_SPENT_KEY } from './constants'
import { unlockingScriptToWitness } from './txTools'
import { ABICoder, Arguments } from 'scryptlib/dist/abi'
Expand All @@ -20,6 +20,7 @@ export class TapLeafSmartContract {
const tapScript = Tap.encodeScript(contractScript.toBuffer())
const [tpubkey, cblock] = Tap.getPubKey(TAPROOT_ONLY_SCRIPT_SPENT_KEY, {
target: tapScript,
version: LEAF_VERSION_TAPSCRIPT
})
this.contract = contract
this.contractScriptHash = hash160(
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tap } from "@cmdcode/tapscript";
import { TxOutpoint } from "../contracts/utils/txUtil";
import { bitcoinjs, btc } from "./btc";
import { LEAF_VERSION_TAPSCRIPT, bitcoinjs, btc } from "./btc";
import { SupportedNetwork, TAPROOT_ONLY_SCRIPT_SPENT_KEY } from "./constants";
import * as btcSigner from '@scure/btc-signer';
import { Network, networks, payments, Psbt, TxInput } from "bitcoinjs-lib";
Expand Down Expand Up @@ -37,6 +37,7 @@ export function scriptToP2tr(script: Buffer): {
const tapScript = Tap.encodeScript(script)
const [tpubkey, cblock] = Tap.getPubKey(TAPROOT_ONLY_SCRIPT_SPENT_KEY, {
target: tapScript,
version: LEAF_VERSION_TAPSCRIPT
})
return {
p2trLockingScript: xPubkeyToP2trLockingScript(tpubkey).toHex(),
Expand Down

0 comments on commit d02dca8

Please sign in to comment.