Skip to content

Commit ddc1e8d

Browse files
committed
feat: pass the ECC library as an optional parameter to p2tr
1 parent 4573e6c commit ddc1e8d

File tree

9 files changed

+523
-535
lines changed

9 files changed

+523
-535
lines changed

src/payments/index.d.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { p2pkh } from './p2pkh';
88
import { p2sh } from './p2sh';
99
import { p2wpkh } from './p2wpkh';
1010
import { p2wsh } from './p2wsh';
11+
import { p2tr } from './p2tr';
1112
export interface Payment {
1213
name?: string;
1314
network?: Network;
@@ -28,24 +29,13 @@ export interface Payment {
2829
scriptLeaf?: TaprootLeaf;
2930
witness?: Buffer[];
3031
}
31-
export declare type PaymentCreator = (a: Payment, opts?: PaymentOpts) => Payment;
32+
export declare type PaymentCreator = (a: Payment, opts?: PaymentOpts, eccLib?: TinySecp256k1Interface) => Payment;
3233
export declare type PaymentFunction = () => Payment;
3334
export interface PaymentOpts {
3435
validate?: boolean;
3536
allowIncomplete?: boolean;
3637
}
37-
export interface PaymentAPI {
38-
embed: PaymentCreator;
39-
p2ms: PaymentCreator;
40-
p2pk: PaymentCreator;
41-
p2pkh: PaymentCreator;
42-
p2sh: PaymentCreator;
43-
p2wpkh: PaymentCreator;
44-
p2wsh: PaymentCreator;
45-
p2tr: PaymentCreator;
46-
}
4738
export declare type StackElement = Buffer | number;
4839
export declare type Stack = StackElement[];
4940
export declare type StackFunction = () => Stack;
50-
export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh, PaymentFactory };
51-
export default function PaymentFactory(ecc: TinySecp256k1Interface): PaymentAPI;
41+
export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh, p2tr };

src/payments/index.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
Object.defineProperty(exports, '__esModule', { value: true });
3-
exports.PaymentFactory = exports.p2wsh = exports.p2wpkh = exports.p2sh = exports.p2pkh = exports.p2pk = exports.p2ms = exports.embed = void 0;
3+
exports.p2tr = exports.p2wsh = exports.p2wpkh = exports.p2sh = exports.p2pkh = exports.p2pk = exports.p2ms = exports.embed = void 0;
44
const embed_1 = require('./embed');
55
Object.defineProperty(exports, 'embed', {
66
enumerable: true,
@@ -51,21 +51,11 @@ Object.defineProperty(exports, 'p2wsh', {
5151
},
5252
});
5353
const p2tr_1 = require('./p2tr');
54-
const testecc_1 = require('./testecc');
55-
function PaymentFactory(ecc) {
56-
(0, testecc_1.testEcc)(ecc);
57-
return {
58-
embed: embed_1.p2data,
59-
p2ms: p2ms_1.p2ms,
60-
p2pk: p2pk_1.p2pk,
61-
p2pkh: p2pkh_1.p2pkh,
62-
p2sh: p2sh_1.p2sh,
63-
p2wpkh: p2wpkh_1.p2wpkh,
64-
p2wsh: p2wsh_1.p2wsh,
65-
p2tr: (0, p2tr_1.p2tr)(ecc),
66-
};
67-
}
68-
exports.default = PaymentFactory;
69-
exports.PaymentFactory = PaymentFactory;
54+
Object.defineProperty(exports, 'p2tr', {
55+
enumerable: true,
56+
get: function() {
57+
return p2tr_1.p2tr;
58+
},
59+
});
7060
// TODO
7161
// witness commitment

src/payments/p2tr.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { TinySecp256k1Interface } from '../types';
2-
import { PaymentCreator } from './index';
3-
export declare function p2tr(ecc: TinySecp256k1Interface): PaymentCreator;
2+
import { Payment, PaymentOpts } from './index';
3+
export declare function p2tr(a: Payment, opts?: PaymentOpts, eccLib?: TinySecp256k1Interface): Payment;

0 commit comments

Comments
 (0)