Skip to content

Commit

Permalink
feat: modify software dlc handler to accept both tr and wpkh public k…
Browse files Browse the repository at this point in the history
…eys to create funding payment (#29)
  • Loading branch information
Polybius93 authored Sep 6, 2024
1 parent b958941 commit 3fdcbb6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "dlc-btc-lib",
"version": "2.2.5",
"version": "2.2.6",
"description": "This library provides a comprehensive set of interfaces and functions for minting dlcBTC tokens on supported blockchains.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
24 changes: 16 additions & 8 deletions src/dlc-handlers/software-wallet-dlc-handler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Transaction, p2wpkh } from '@scure/btc-signer';
import { Transaction, p2tr, p2wpkh } from '@scure/btc-signer';
import { P2Ret, P2TROut } from '@scure/btc-signer/payment';
import { Network } from 'bitcoinjs-lib';
import { bitcoin, regtest, testnet } from 'bitcoinjs-lib/src/networks.js';

import {
createTaprootMultisigPayment,
deriveUnhardenedPublicKey,
ecdsaPublicKeyToSchnorr,
getBalance,
getFeeRate,
getUnspendableKeyCommittedToUUID,
Expand All @@ -21,14 +22,16 @@ import { RawVault } from '../models/ethereum-models.js';
export class SoftwareWalletDLCHandler {
private fundingDerivedPublicKey: string;
private taprootDerivedPublicKey: string;
private fundingPaymentType: 'wpkh' | 'tr';
public payment: PaymentInformation | undefined;
private bitcoinNetwork: Network;
private bitcoinBlockchainAPI: string;
private bitcoinBlockchainFeeRecommendationAPI: string;

constructor(
nativeSegwitDerivedPublicKey: string,
fundingDerivedPublicKey: string,
taprootDerivedPublicKey: string,
fundingPaymentType: 'wpkh' | 'tr',
bitcoinNetwork: Network,
bitcoinBlockchainAPI?: string,
bitcoinBlockchainFeeRecommendationAPI?: string
Expand Down Expand Up @@ -59,12 +62,13 @@ export class SoftwareWalletDLCHandler {
default:
throw new Error('Invalid Bitcoin Network');
}
this.fundingPaymentType = fundingPaymentType;
this.bitcoinNetwork = bitcoinNetwork;
this.fundingDerivedPublicKey = nativeSegwitDerivedPublicKey;
this.fundingDerivedPublicKey = fundingDerivedPublicKey;
this.taprootDerivedPublicKey = taprootDerivedPublicKey;
}

private setPayment(fundingPayment: P2Ret, multisigPayment: P2TROut): void {
private setPayment(fundingPayment: P2Ret | P2TROut, multisigPayment: P2TROut): void {
this.payment = {
fundingPayment,
multisigPayment,
Expand Down Expand Up @@ -114,10 +118,14 @@ export class SoftwareWalletDLCHandler {
attestorGroupPublicKey: string
): Promise<PaymentInformation> {
try {
const fundingPayment = p2wpkh(
Buffer.from(this.fundingDerivedPublicKey, 'hex'),
this.bitcoinNetwork
);
const fundingPayment =
this.fundingPaymentType === 'wpkh'
? p2wpkh(Buffer.from(this.fundingDerivedPublicKey, 'hex'), this.bitcoinNetwork)
: p2tr(
ecdsaPublicKeyToSchnorr(Buffer.from(this.fundingDerivedPublicKey, 'hex')),
undefined,
this.bitcoinNetwork
);

const unspendablePublicKey = getUnspendableKeyCommittedToUUID(vaultUUID, this.bitcoinNetwork);
const unspendableDerivedPublicKey = deriveUnhardenedPublicKey(
Expand Down

0 comments on commit 3fdcbb6

Please sign in to comment.