Skip to content

Commit 6cfbf65

Browse files
committed
refactor: use injectable ecc lib
1 parent 4d2af06 commit 6cfbf65

File tree

16 files changed

+926
-612
lines changed

16 files changed

+926
-612
lines changed

src/payments/index.d.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/// <reference types="node" />
22
import { Network } from '../networks';
3-
import { TaprootLeaf } from '../types';
3+
import { TaprootLeaf, TinySecp256k1Interface } from '../types';
44
import { p2data as embed } from './embed';
55
import { p2ms } from './p2ms';
66
import { p2pk } from './p2pk';
77
import { p2pkh } from './p2pkh';
88
import { p2sh } from './p2sh';
99
import { p2wpkh } from './p2wpkh';
1010
import { p2wsh } from './p2wsh';
11-
import { p2tr } from './p2tr';
1211
export interface Payment {
1312
name?: string;
1413
network?: Network;
@@ -35,7 +34,18 @@ export interface PaymentOpts {
3534
validate?: boolean;
3635
allowIncomplete?: boolean;
3736
}
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+
}
3847
export declare type StackElement = Buffer | number;
3948
export declare type Stack = StackElement[];
4049
export declare type StackFunction = () => Stack;
41-
export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh, p2tr };
50+
export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh, PaymentFactory };
51+
export default function PaymentFactory(ecc: TinySecp256k1Interface): PaymentAPI;

src/payments/index.js

Lines changed: 17 additions & 7 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.p2tr = exports.p2wsh = exports.p2wpkh = exports.p2sh = exports.p2pkh = exports.p2pk = exports.p2ms = exports.embed = void 0;
3+
exports.PaymentFactory = 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,11 +51,21 @@ Object.defineProperty(exports, 'p2wsh', {
5151
},
5252
});
5353
const p2tr_1 = require('./p2tr');
54-
Object.defineProperty(exports, 'p2tr', {
55-
enumerable: true,
56-
get: function() {
57-
return p2tr_1.p2tr;
58-
},
59-
});
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;
6070
// TODO
6171
// witness commitment

src/payments/p2tr.d.ts

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

0 commit comments

Comments
 (0)