Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 163 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"varuint-bitcoin": "^2.0.0"
},
"devDependencies": {
"bitcoinjs-lib": ".",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.9.1",
"@types/bs58": "^4.0.0",
Expand All @@ -88,7 +87,9 @@
"bip39": "^3.1.0",
"bip65": "^1.0.1",
"bip68": "^1.0.3",
"bitcoinjs-lib": ".",
"bs58": "^6.0.0",
"c8": "^10.1.2",
"dhttp": "^3.0.0",
"ecpair": "^3.0.0-rc.0",
"eslint": "^9.9.0",
Expand All @@ -98,16 +99,16 @@
"hoodwink": "^2.0.0",
"minimaldata": "^1.0.2",
"mocha": "^10.6.0",
"c8": "^10.1.2",
"prettier": "^3.0.0",
"proxyquire": "^2.0.1",
"randombytes": "^2.1.0",
"regtest-client": "0.2.0",
"rimraf": "^2.6.3",
"tiny-secp256k1": "^2.2.0",
"ts-node": "^10.9.2",
"tsx": "^4.17.0",
"typedoc": "^0.26.6",
"typescript": "^5.0.4"
"typescript": "^5.9.3"
},
"license": "MIT"
}
5 changes: 3 additions & 2 deletions test/bip371.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { toXOnly } from 'bitcoinjs-lib';
import { toXOnly } from '../ts_src/psbt/bip371';
import * as assert from 'assert';

describe('toXOnly', () => {
it('should return the input if the pubKey length is 32', () => {
const pubKey = new Uint8Array(32).fill(1); // Example 32-byte public key
const result = toXOnly(pubKey);
assert.strictEqual(result, pubKey); // Expect the same array (reference equality)
assert.deepStrictEqual(result, pubKey); // Expect the same content
assert.notStrictEqual(result, pubKey); // Expect a new instance (copy)
});

it('should return the sliced key if the pubKey length is greater than 32', () => {
Expand Down
14 changes: 8 additions & 6 deletions ts_src/psbt/bip371.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import { signatureBlocksAction } from './psbtutils.js';
* @returns The X-only public key.
*/
export const toXOnly = (pubKey: Uint8Array) =>
pubKey.length === 32 ? pubKey : pubKey.slice(1, 33);
pubKey.length === 32
? new Uint8Array(pubKey.buffer, pubKey.byteOffset, pubKey.byteLength)
: new Uint8Array(pubKey.slice(1, 33));

/**
* Default tapscript finalizer. It searches for the `tapLeafHashToFinalize` if provided.
Expand Down Expand Up @@ -209,8 +211,8 @@ export function tweakInternalPubKey(
if (!outputKey)
throw new Error(
`Cannot tweak tap internal key for input #${inputIndex}. Public key: ${
// tapInternalKey && tapInternalKey.toString('hex')
tapInternalKey && tools.toHex(tapInternalKey)
// tapInternalKey && tapInternalKey.toString('hex')
tapInternalKey && tools.toHex(tapInternalKey)
}`,
);
return outputKey.x;
Expand Down Expand Up @@ -417,7 +419,7 @@ function checkMixedTaprootAndNonTaprootInputFields(
if (isBadTaprootUpdate || isBadNonTaprootUpdate || hasMixedFields)
throw new Error(
`Invalid arguments for Psbt.${action}. ` +
`Cannot use both taproot and non-taproot fields.`,
`Cannot use both taproot and non-taproot fields.`,
);
}

Expand Down Expand Up @@ -445,7 +447,7 @@ function checkMixedTaprootAndNonTaprootOutputFields(
if (isBadTaprootUpdate || isBadNonTaprootUpdate || hasMixedFields)
throw new Error(
`Invalid arguments for Psbt.${action}. ` +
`Cannot use both taproot and non-taproot fields.`,
`Cannot use both taproot and non-taproot fields.`,
);
}

Expand Down Expand Up @@ -596,7 +598,7 @@ function canFinalizeLeaf(
return (
whiteListedHash &&
tapScriptSig!.find(tss => tools.compare(tss.leafHash, leafHash) === 0) !==
undefined
undefined
);
}

Expand Down