Skip to content

Commit e0c3ede

Browse files
authored
Merge pull request #2191 from Heracles4179/master
export toXOnly
2 parents 2a8f83f + a037cc2 commit e0c3ede

File tree

9 files changed

+45
-4
lines changed

9 files changed

+45
-4
lines changed

src/cjs/index.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4747
exports.initEccLib =
4848
exports.Transaction =
4949
exports.opcodes =
50+
exports.toXOnly =
5051
exports.Psbt =
5152
exports.Block =
5253
exports.script =
@@ -79,6 +80,12 @@ Object.defineProperty(exports, 'Psbt', {
7980
return psbt_js_1.Psbt;
8081
},
8182
});
83+
Object.defineProperty(exports, 'toXOnly', {
84+
enumerable: true,
85+
get: function () {
86+
return psbt_js_1.toXOnly;
87+
},
88+
});
8289
/** @hidden */
8390
var ops_js_1 = require('./ops.cjs');
8491
Object.defineProperty(exports, 'opcodes', {

src/cjs/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export { address, crypto, networks, payments, script };
77
export { Block } from './block.js';
88
/** @hidden */
99
export { TaggedHashPrefix } from './crypto.js';
10-
export { Psbt, PsbtTxInput, PsbtTxOutput, Signer, SignerAsync, HDSigner, HDSignerAsync, } from './psbt.js';
10+
export { Psbt, PsbtTxInput, PsbtTxOutput, Signer, SignerAsync, HDSigner, HDSignerAsync, toXOnly, } from './psbt.js';
1111
/** @hidden */
1212
export { OPS as opcodes } from './ops.js';
1313
export { Transaction } from './transaction.js';

src/cjs/psbt.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var __importStar =
4444
return result;
4545
};
4646
Object.defineProperty(exports, '__esModule', { value: true });
47-
exports.Psbt = void 0;
47+
exports.Psbt = exports.toXOnly = void 0;
4848
const bip174_1 = require('bip174');
4949
const varuint = __importStar(require('varuint-bitcoin'));
5050
const bip174_2 = require('bip174');
@@ -56,6 +56,12 @@ const bip341_js_1 = require('./payments/bip341.cjs');
5656
const bscript = __importStar(require('./script.cjs'));
5757
const transaction_js_1 = require('./transaction.cjs');
5858
const bip371_js_1 = require('./psbt/bip371.cjs');
59+
Object.defineProperty(exports, 'toXOnly', {
60+
enumerable: true,
61+
get: function () {
62+
return bip371_js_1.toXOnly;
63+
},
64+
});
5965
const psbtutils_js_1 = require('./psbt/psbtutils.cjs');
6066
const tools = __importStar(require('uint8array-tools'));
6167
/**

src/cjs/psbt.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Psbt as PsbtBase } from 'bip174';
22
import { KeyValue, PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, PsbtOutput, PsbtOutputUpdate } from 'bip174';
33
import { Network } from './networks.js';
44
import { Transaction } from './transaction.js';
5+
import { toXOnly } from './psbt/bip371.js';
6+
export { toXOnly };
57
export interface TransactionInput {
68
hash: string | Uint8Array;
79
index: number;
@@ -202,4 +204,3 @@ tapLeafHashToFinalize?: Uint8Array) => {
202204
finalScriptWitness: Uint8Array | undefined;
203205
};
204206
type AllScriptType = 'witnesspubkeyhash' | 'pubkeyhash' | 'multisig' | 'pubkey' | 'nonstandard' | 'p2sh-witnesspubkeyhash' | 'p2sh-pubkeyhash' | 'p2sh-multisig' | 'p2sh-pubkey' | 'p2sh-nonstandard' | 'p2wsh-pubkeyhash' | 'p2wsh-multisig' | 'p2wsh-pubkey' | 'p2wsh-nonstandard' | 'p2sh-p2wsh-pubkeyhash' | 'p2sh-p2wsh-multisig' | 'p2sh-p2wsh-pubkey' | 'p2sh-p2wsh-nonstandard';
205-
export {};

src/esm/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as payments from './payments/index.js';
55
import * as script from './script.js';
66
export { address, crypto, networks, payments, script };
77
export { Block } from './block.js';
8-
export { Psbt } from './psbt.js';
8+
export { Psbt, toXOnly } from './psbt.js';
99
/** @hidden */
1010
export { OPS as opcodes } from './ops.js';
1111
export { Transaction } from './transaction.js';

src/esm/psbt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
isP2TR,
3131
} from './psbt/psbtutils.js';
3232
import * as tools from 'uint8array-tools';
33+
export { toXOnly };
3334
/**
3435
* These are the default arguments for a Psbt instance.
3536
*/

test/bip371.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { toXOnly } from 'bitcoinjs-lib';
2+
import * as assert from 'assert';
3+
4+
describe('toXOnly', () => {
5+
it('should return the input if the pubKey length is 32', () => {
6+
const pubKey = new Uint8Array(32).fill(1); // Example 32-byte public key
7+
const result = toXOnly(pubKey);
8+
assert.strictEqual(result, pubKey); // Expect the same array (reference equality)
9+
});
10+
11+
it('should return the sliced key if the pubKey length is greater than 32', () => {
12+
const pubKey = new Uint8Array(33).fill(1);
13+
pubKey[0] = 0; // Add a leading byte
14+
const result = toXOnly(pubKey);
15+
assert.deepStrictEqual(result, pubKey.slice(1, 33)); // Expect the sliced array
16+
});
17+
18+
it('should return the key if the pubKey length is less than 32', () => {
19+
const pubKey = new Uint8Array(31).fill(1); // Example invalid public key
20+
const result = toXOnly(pubKey);
21+
assert.deepStrictEqual(result, pubKey.slice(1, 33)); // Expect the sliced array
22+
});
23+
});

ts_src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export {
1717
SignerAsync,
1818
HDSigner,
1919
HDSignerAsync,
20+
toXOnly,
2021
} from './psbt.js';
2122
/** @hidden */
2223
export { OPS as opcodes } from './ops.js';

ts_src/psbt.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import {
4646
} from './psbt/psbtutils.js';
4747
import * as tools from 'uint8array-tools';
4848

49+
export { toXOnly };
50+
4951
export interface TransactionInput {
5052
hash: string | Uint8Array;
5153
index: number;

0 commit comments

Comments
 (0)