import {
MnemonicIdentity,
MultisigTapscript,
CLTVMultisigTapscript,
VtxoScript,
networks,
} from '@arkade-os/sdk';
const buyer = MnemonicIdentity.fromMnemonic('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', { isMainnet: false });
const seller = MnemonicIdentity.fromMnemonic('zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong', { isMainnet: false });
const arbiter = MnemonicIdentity.fromMnemonic('legal winner thank year wave sausage worth useful legal winner thank yellow', { isMainnet: false });
const buyerPubkey = await buyer.xOnlyPublicKey();
const sellerPubkey = await seller.xOnlyPublicKey();
const arbiterPubkey = await arbiter.xOnlyPublicKey();
// Store refundAt with the contract: another value gives another address
const refundAt = BigInt(Math.floor(Date.now() / 1000)) + 30n * 86400n;
const releaseLeaf = MultisigTapscript.encode({
pubkeys: [buyerPubkey, sellerPubkey, serverPubkey],
}).script;
const arbiterLeaf = MultisigTapscript.encode({
pubkeys: [arbiterPubkey, serverPubkey],
}).script;
const refundLeaf = CLTVMultisigTapscript.encode({
pubkeys: [buyerPubkey, serverPubkey],
absoluteTimelock: refundAt,
}).script;
const exitLeaf = CSVMultisigTapscript.encode({
pubkeys: [buyerPubkey, sellerPubkey],
timelock: exitTimelock,
}).script;
const escrow = new VtxoScript([releaseLeaf, arbiterLeaf, refundLeaf, exitLeaf]);
console.log('Escrow address:', escrow.address(networks.mutinynet.hrp, serverPubkey).encode());