import {
MnemonicIdentity,
MultisigTapscript,
CLTVMultisigTapscript,
VtxoScript,
networks,
} from '@arkade-os/sdk';
const alice = MnemonicIdentity.fromMnemonic('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', { isMainnet: false });
const bob = MnemonicIdentity.fromMnemonic('zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong', { isMainnet: false });
const alicePubkey = await alice.xOnlyPublicKey();
const bobPubkey = await bob.xOnlyPublicKey();
// Store refundAt with the contract: another value gives another address
const refundAt = BigInt(Math.floor(Date.now() / 1000)) + 7n * 86400n;
const updateLeaf = MultisigTapscript.encode({
pubkeys: [alicePubkey, bobPubkey, serverPubkey],
}).script;
const refundLeaf = CLTVMultisigTapscript.encode({
pubkeys: [alicePubkey, serverPubkey],
absoluteTimelock: refundAt,
}).script;
const exitUpdateLeaf = CSVMultisigTapscript.encode({
pubkeys: [alicePubkey, bobPubkey],
timelock: exitTimelock,
}).script;
const exitRefundLeaf = CSVMultisigTapscript.encode({
pubkeys: [alicePubkey],
timelock: { ...exitTimelock, value: exitTimelock.value * 2n },
}).script;
const channel = new VtxoScript([updateLeaf, refundLeaf, exitUpdateLeaf, exitRefundLeaf]);
console.log('Channel address:', channel.address(networks.mutinynet.hrp, serverPubkey).encode());