From ab877609621798faa9d25306bbea888579a85f74 Mon Sep 17 00:00:00 2001 From: Polybius93 Date: Mon, 2 Dec 2024 16:53:43 +0100 Subject: [PATCH 1/4] feat: add nested segwit case for fee address validation test --- tests/unit/bitcoin-functions.test.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/unit/bitcoin-functions.test.ts b/tests/unit/bitcoin-functions.test.ts index 5ddc1ea..290fa9b 100644 --- a/tests/unit/bitcoin-functions.test.ts +++ b/tests/unit/bitcoin-functions.test.ts @@ -13,7 +13,6 @@ import { getScriptMatchingOutputFromTransaction, getUnspendableKeyCommittedToUUID, } from '../../src/functions/bitcoin/bitcoin-functions'; -import { shiftValue, unshiftValue } from '../../src/utilities'; import { TEST_TESTNET_ATTESTOR_EXTENDED_GROUP_PUBLIC_KEY_1, TEST_TESTNET_ATTESTOR_UNHARDENED_DERIVED_PUBLIC_KEY_1, @@ -83,6 +82,11 @@ describe('Bitcoin Functions', () => { expect(getFeeRecipientAddress(address, network)).toBe(address); }); + it('accepts nested segwit (p2sh) address', () => { + const address = '3KF9nXowQ4asSGxRRzeiTpDjMuwM2nypAN'; + expect(getFeeRecipientAddress(address, network)).toBe(address); + }); + it('converts public key to native segwit address', () => { const publicKey = '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'; const expectedAddress = 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4'; @@ -103,6 +107,11 @@ describe('Bitcoin Functions', () => { expect(getFeeRecipientAddress(address, network)).toBe(address); }); + it('accepts nested segwit (p2sh) address', () => { + const address = '2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc'; + expect(getFeeRecipientAddress(address, network)).toBe(address); + }); + it('converts public key to native segwit address', () => { const publicKey = '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'; const expectedAddress = 'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx'; @@ -123,6 +132,11 @@ describe('Bitcoin Functions', () => { expect(getFeeRecipientAddress(address, network)).toBe(address); }); + it('accepts nested segwit (p2sh) address', () => { + const address = '2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc'; + expect(getFeeRecipientAddress(address, network)).toBe(address); + }); + it('converts public key to native segwit address', () => { const publicKey = '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'; const expectedAddress = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080'; From 46e74cdd2578ae3ebd7674ea7b239bff89220331 Mon Sep 17 00:00:00 2001 From: Polybius93 Date: Mon, 2 Dec 2024 17:30:39 +0100 Subject: [PATCH 2/4] chore: update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fc9d05c..2538b60 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "dlc-btc-lib", - "version": "2.4.19", + "version": "2.4.2", "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", From e54f3713791ba4cc448564c7ec3ed4d5aff3d98b Mon Sep 17 00:00:00 2001 From: Polybius93 Date: Tue, 3 Dec 2024 10:43:51 +0100 Subject: [PATCH 3/4] feat: add ecc lib init, modify taproot adresses in tests --- src/functions/bitcoin/bitcoin-functions.ts | 3 ++- tests/unit/bitcoin-functions.test.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/functions/bitcoin/bitcoin-functions.ts b/src/functions/bitcoin/bitcoin-functions.ts index 1dfbbea..beeb01a 100644 --- a/src/functions/bitcoin/bitcoin-functions.ts +++ b/src/functions/bitcoin/bitcoin-functions.ts @@ -12,7 +12,7 @@ import { import { P2Ret, P2TROut } from '@scure/btc-signer/payment'; import { TransactionInput } from '@scure/btc-signer/psbt'; import { BIP32Factory, BIP32Interface } from 'bip32'; -import { Network, address } from 'bitcoinjs-lib'; +import { Network, address, initEccLib } from 'bitcoinjs-lib'; import { bitcoin, regtest, testnet } from 'bitcoinjs-lib/src/networks.js'; import { Decimal } from 'decimal.js'; import * as ellipticCurveCryptography from 'tiny-secp256k1'; @@ -37,6 +37,7 @@ const TAPROOT_UNSPENDABLE_KEY_HEX = const ECDSA_PUBLIC_KEY_LENGTH = 33; const bip32 = BIP32Factory(ellipticCurveCryptography); +initEccLib(ellipticCurveCryptography); export function getFeeAmount(bitcoinAmount: number, feeBasisPoints: number): number { const feePercentage = new Decimal(feeBasisPoints).dividedBy(10000); diff --git a/tests/unit/bitcoin-functions.test.ts b/tests/unit/bitcoin-functions.test.ts index 290fa9b..606ec28 100644 --- a/tests/unit/bitcoin-functions.test.ts +++ b/tests/unit/bitcoin-functions.test.ts @@ -78,7 +78,7 @@ describe('Bitcoin Functions', () => { }); it('accepts taproot (p2tr) address', () => { - const address = 'bc1qw02rsw9afgp4dsd5n87z5s6rqnf455yhhsnz9f'; + const address = 'bc1pgj9ef0lhysgd2v042jta4mv8qmc70yappkv7vpl76dhfvrdfvusqqe4qj3'; expect(getFeeRecipientAddress(address, network)).toBe(address); }); @@ -103,7 +103,7 @@ describe('Bitcoin Functions', () => { }); it('accepts taproot (p2tr) address', () => { - const address = 'tb1qqhy33peyp82mf82fktdtphfmnhtxyhtp6x9hrc'; + const address = 'tb1pa8hxt6r2gkc8d5thzfrw7gyrqlv354rdy4k05ylkvf6nadnhg8xsygyusf'; expect(getFeeRecipientAddress(address, network)).toBe(address); }); @@ -128,7 +128,7 @@ describe('Bitcoin Functions', () => { }); it('accepts taproot (p2tr) address', () => { - const address = 'bcrt1qqhy33peyp82mf82fktdtphfmnhtxyhtpc0u653'; + const address = 'bcrt1pa8hxt6r2gkc8d5thzfrw7gyrqlv354rdy4k05ylkvf6nadnhg8xsf3w69n'; expect(getFeeRecipientAddress(address, network)).toBe(address); }); From 87446c1cabdf9e5a2993969fc16cc9f316004ba4 Mon Sep 17 00:00:00 2001 From: Polybius93 Date: Wed, 4 Dec 2024 15:10:54 +0100 Subject: [PATCH 4/4] fix: modify package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2538b60..4666518 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "dlc-btc-lib", - "version": "2.4.2", + "version": "2.4.20", "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",