-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwithDraw.ts
25 lines (22 loc) · 938 Bytes
/
withDraw.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import dotenv from 'dotenv';
import * as bitcoin from 'bitcoinjs-lib';
import * as ecc from 'tiny-secp256k1';
import ECPairFactory from 'ecpair';
import { BitcoinHtlc } from '../../../packages/bitcoin/src/BitcoinHtlc';
import { BITCOIN } from './config';
dotenv.config();
async function withDraw(hash: string, contractAddress: string, witnessScript: string, proof: string) {
const { WIF } = BITCOIN;
const ECPair = ECPairFactory(ecc);
const Bob = ECPair.fromWIF(WIF.TO, bitcoin.networks.testnet);
const swap = new BitcoinHtlc(bitcoin.networks.testnet);
return await swap.withdraw(hash, contractAddress, witnessScript, Bob, proof);
}
async function start() {
const hash = '************************';
const contractAddress = '************************';
const witnessScript = '************************';
const proof = '************************';
await withDraw(hash, contractAddress, witnessScript, proof);
}
start();