@scure/btc-signer 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +19 -3
  2. package/lib/_type_test.d.ts +2 -0
  3. package/lib/_type_test.d.ts.map +1 -0
  4. package/lib/_type_test.js +59 -0
  5. package/lib/_type_test.js.map +1 -0
  6. package/lib/esm/_type_test.js +57 -0
  7. package/lib/esm/_type_test.js.map +1 -0
  8. package/lib/esm/index.js +13 -3007
  9. package/lib/esm/index.js.map +1 -1
  10. package/lib/esm/payment.js +681 -0
  11. package/lib/esm/payment.js.map +1 -0
  12. package/lib/esm/psbt.js +441 -0
  13. package/lib/esm/psbt.js.map +1 -0
  14. package/lib/esm/script.js +347 -0
  15. package/lib/esm/script.js.map +1 -0
  16. package/lib/esm/transaction.js +1013 -0
  17. package/lib/esm/transaction.js.map +1 -0
  18. package/lib/esm/utils.js +115 -0
  19. package/lib/esm/utils.js.map +1 -0
  20. package/lib/esm/utxo.js +491 -0
  21. package/lib/esm/utxo.js.map +1 -0
  22. package/lib/index.d.ts +18 -1439
  23. package/lib/index.d.ts.map +1 -1
  24. package/lib/index.js +53 -3042
  25. package/lib/index.js.map +1 -0
  26. package/lib/payment.d.ts +167 -0
  27. package/lib/payment.d.ts.map +1 -0
  28. package/lib/payment.js +704 -0
  29. package/lib/payment.js.map +1 -0
  30. package/lib/psbt.d.ts +834 -0
  31. package/lib/psbt.d.ts.map +1 -0
  32. package/lib/psbt.js +446 -0
  33. package/lib/psbt.js.map +1 -0
  34. package/lib/script.d.ts +154 -0
  35. package/lib/script.d.ts.map +1 -0
  36. package/lib/script.js +353 -0
  37. package/lib/script.js.map +1 -0
  38. package/lib/transaction.d.ts +223 -0
  39. package/lib/transaction.d.ts.map +1 -0
  40. package/lib/transaction.js +1022 -0
  41. package/lib/transaction.js.map +1 -0
  42. package/lib/utils.d.ts +30 -0
  43. package/lib/utils.d.ts.map +1 -0
  44. package/lib/utils.js +128 -0
  45. package/lib/utils.js.map +1 -0
  46. package/lib/utxo.d.ts +251 -0
  47. package/lib/utxo.d.ts.map +1 -0
  48. package/lib/utxo.js +501 -0
  49. package/lib/utxo.js.map +1 -0
  50. package/package.json +40 -10
  51. package/src/_type_test.ts +69 -0
  52. package/src/index.ts +28 -0
  53. package/src/package.json +3 -0
  54. package/src/payment.ts +749 -0
  55. package/src/psbt.ts +512 -0
  56. package/src/script.ts +236 -0
  57. package/src/transaction.ts +1065 -0
  58. package/src/utils.ts +118 -0
  59. package/src/utxo.ts +517 -0
  60. package/index.ts +0 -3067
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0EAA0E;AAC1E,yCAAmG;AACnG,kBAAkB;AAClB,2CAGsB;AAFpB,kGAAA,IAAI,OAAA;AAAE,mGAAA,KAAK,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,mGAAA,KAAK,OAAA;AAAE,oGAAA,MAAM,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,qGAAA,OAAO,OAAA;AAAE,qGAAA,OAAO,OAAA;AAAE,qGAAA,OAAO,OAAA;AACvE,sGAAA,QAAQ,OAAA,CAAC,sBAAsB;AAEjC,kBAAkB;AAClB,yCAGqB;AAFnB,+FAAA,EAAE,OAAA;AAAE,kGAAA,KAAK,OAAA;AAAE,wGAAA,WAAW,OAAA;AACtB,mGAAA,MAAM,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAc,mHAAA,sBAAsB,OAAA;AAEvD,mDAA+C;AAAtC,6GAAA,WAAW,OAAA;AACpB,qCAAqD;AAA5C,uGAAA,YAAY,OAAA;AAAE,qGAAA,UAAU,OAAA;AACjC,uCAA4E;AAAnE,mGAAA,OAAO,OAAA;AAAE,wGAAA,YAAY,OAAA;AAAE,mHAAA,uBAAuB,OAAA;AAE1C,QAAA,KAAK,GAAG,EAAE,OAAO,EAAP,kBAAO,EAAE,WAAW,EAAX,sBAAW,EAAE,YAAY,EAAZ,uBAAY,EAAE,UAAU,EAAV,qBAAU,EAAE,qBAAqB,EAArB,gCAAqB,EAAE,CAAC;AAE/F,QAAQ;AACR,kBAAkB;AAClB,2CAIsB,CAAC,SAAS;AAH9B,qGAAA,OAAO,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,iGAAA,GAAG,OAAA;AAExB,+GAAA,iBAAiB,OAAA;AAAE,uGAAA,SAAS,OAAA;AAAE,0GAAA,YAAY,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,0GAAA,YAAY,OAAA;AAE1E,qCAA4D,CAAC,SAAS;AAA7D,qGAAA,UAAU,OAAA;AAAE,8GAAA,mBAAmB,OAAA;AACxC,mDAA8F,CAAC,SAAS;AAA/F,yGAAA,OAAO,OAAA;AAAE,2GAAA,SAAS,OAAA;AAAE,yGAAA,OAAO,OAAA;AAAE,6GAAA,WAAW,OAAA;AAAE,kHAAA,gBAAgB,OAAA;AACnE,qCAAgD;AAAvC,kGAAA,OAAO,OAAA;AAAE,qGAAA,UAAU,OAAA"}
@@ -0,0 +1,167 @@
1
+ import { Coder } from '@scure/base';
2
+ import * as P from 'micro-packed';
3
+ import { TransactionInput } from './psbt.js';
4
+ import { ScriptType } from './script.js';
5
+ import { Bytes } from './utils.js';
6
+ export type P2Ret = {
7
+ type: string;
8
+ script: Bytes;
9
+ address?: string;
10
+ redeemScript?: Bytes;
11
+ witnessScript?: Bytes;
12
+ };
13
+ type OutPKType = {
14
+ type: 'pk';
15
+ pubkey: Bytes;
16
+ };
17
+ export type OptScript = ScriptType | undefined;
18
+ type OutPKHType = {
19
+ type: 'pkh';
20
+ hash: Bytes;
21
+ };
22
+ type OutSHType = {
23
+ type: 'sh';
24
+ hash: Bytes;
25
+ };
26
+ type OutWSHType = {
27
+ type: 'wsh';
28
+ hash: Bytes;
29
+ };
30
+ type OutWPKHType = {
31
+ type: 'wpkh';
32
+ hash: Bytes;
33
+ };
34
+ type OutMSType = {
35
+ type: 'ms';
36
+ pubkeys: Bytes[];
37
+ m: number;
38
+ };
39
+ type OutTRType = {
40
+ type: 'tr';
41
+ pubkey: Bytes;
42
+ };
43
+ type OutTRNSType = {
44
+ type: 'tr_ns';
45
+ pubkeys: Bytes[];
46
+ };
47
+ type OutTRMSType = {
48
+ type: 'tr_ms';
49
+ pubkeys: Bytes[];
50
+ m: number;
51
+ };
52
+ type OutUnknownType = {
53
+ type: 'unknown';
54
+ script: Bytes;
55
+ };
56
+ type FinalizeSignature = [{
57
+ pubKey: Bytes;
58
+ leafHash: Bytes;
59
+ }, Bytes];
60
+ type CustomScriptOut = {
61
+ type: string;
62
+ } & Record<string, any>;
63
+ export type CustomScript = Coder<OptScript, CustomScriptOut | undefined> & {
64
+ finalizeTaproot?: (script: Bytes, parsed: CustomScriptOut, signatures: FinalizeSignature[]) => Bytes[] | undefined;
65
+ };
66
+ export declare const OutScript: P.CoderType<NonNullable<OutPKType | OutPKHType | OutSHType | OutWSHType | OutWPKHType | OutMSType | OutTRType | OutTRNSType | OutTRMSType | OutUnknownType | undefined>>;
67
+ export type OutScriptType = typeof OutScript;
68
+ export declare function checkScript(script?: Bytes, redeemScript?: Bytes, witnessScript?: Bytes): void;
69
+ export declare const p2pk: (pubkey: Bytes, network?: {
70
+ bech32: string;
71
+ pubKeyHash: number;
72
+ scriptHash: number;
73
+ wif: number;
74
+ }) => P2Ret;
75
+ export declare const p2pkh: (publicKey: Bytes, network?: {
76
+ bech32: string;
77
+ pubKeyHash: number;
78
+ scriptHash: number;
79
+ wif: number;
80
+ }) => P2Ret;
81
+ export declare const p2sh: (child: P2Ret, network?: {
82
+ bech32: string;
83
+ pubKeyHash: number;
84
+ scriptHash: number;
85
+ wif: number;
86
+ }) => P2Ret;
87
+ export declare const p2wsh: (child: P2Ret, network?: {
88
+ bech32: string;
89
+ pubKeyHash: number;
90
+ scriptHash: number;
91
+ wif: number;
92
+ }) => P2Ret;
93
+ export declare const p2wpkh: (publicKey: Bytes, network?: {
94
+ bech32: string;
95
+ pubKeyHash: number;
96
+ scriptHash: number;
97
+ wif: number;
98
+ }) => P2Ret;
99
+ export declare const p2ms: (m: number, pubkeys: Bytes[], allowSamePubkeys?: boolean) => P2Ret;
100
+ export type P2TROut = P2Ret & {
101
+ tweakedPubkey: Uint8Array;
102
+ tapInternalKey: Uint8Array;
103
+ tapMerkleRoot?: Uint8Array;
104
+ tapLeafScript?: TransactionInput['tapLeafScript'];
105
+ leaves?: TaprootLeaf[];
106
+ };
107
+ export type TaprootNode = {
108
+ script: Bytes | string;
109
+ leafVersion?: number;
110
+ weight?: number;
111
+ } & Partial<P2TROut>;
112
+ export type TaprootScriptTree = TaprootNode | TaprootScriptTree[];
113
+ export type TaprootScriptList = TaprootNode[];
114
+ export declare function taprootListToTree(taprootList: TaprootScriptList): TaprootScriptTree;
115
+ type TaprootLeaf = {
116
+ type: 'leaf';
117
+ version?: number;
118
+ script: Bytes;
119
+ hash: Bytes;
120
+ path: Bytes[];
121
+ };
122
+ export declare const TAP_LEAF_VERSION = 192;
123
+ export declare const tapLeafHash: (script: Bytes, version?: number) => Uint8Array;
124
+ export declare function p2tr(internalPubKey?: Bytes | string, tree?: TaprootScriptTree, network?: {
125
+ bech32: string;
126
+ pubKeyHash: number;
127
+ scriptHash: number;
128
+ wif: number;
129
+ }, allowUnknownOutputs?: boolean, customScripts?: CustomScript[]): P2TROut;
130
+ export declare function combinations<T>(m: number, list: T[]): T[][];
131
+ /**
132
+ * M-of-N multi-leaf wallet via p2tr_ns. If m == n, single script is emitted.
133
+ * Takes O(n^2) if m != n. 99-of-100 is ok, 5-of-100 is not.
134
+ * `2-of-[A,B,C] => [A,B] | [A,C] | [B,C]`
135
+ */
136
+ export declare const p2tr_ns: (m: number, pubkeys: Bytes[], allowSamePubkeys?: boolean) => P2Ret[];
137
+ export declare const p2tr_pk: (pubkey: Bytes) => P2Ret;
138
+ export declare function p2tr_ms(m: number, pubkeys: Bytes[], allowSamePubkeys?: boolean): {
139
+ type: string;
140
+ script: Uint8Array;
141
+ };
142
+ export declare function getAddress(type: 'pkh' | 'wpkh' | 'tr', privKey: Bytes, network?: {
143
+ bech32: string;
144
+ pubKeyHash: number;
145
+ scriptHash: number;
146
+ wif: number;
147
+ }): string | undefined;
148
+ export declare const _sortPubkeys: (pubkeys: Bytes[]) => Uint8Array[];
149
+ export declare function multisig(m: number, pubkeys: Bytes[], sorted?: boolean, witness?: boolean): P2Ret;
150
+ export declare function sortedMultisig(m: number, pubkeys: Bytes[], witness?: boolean): P2Ret;
151
+ export declare function WIF(network?: {
152
+ bech32: string;
153
+ pubKeyHash: number;
154
+ scriptHash: number;
155
+ wif: number;
156
+ }): Coder<Bytes, string>;
157
+ export declare function Address(network?: {
158
+ bech32: string;
159
+ pubKeyHash: number;
160
+ scriptHash: number;
161
+ wif: number;
162
+ }): {
163
+ encode(from: P.UnwrapCoder<OutScriptType>): string;
164
+ decode(address: string): P.UnwrapCoder<OutScriptType>;
165
+ };
166
+ export {};
167
+ //# sourceMappingURL=payment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../src/payment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAA2C,MAAM,aAAa,CAAC;AAC7E,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAuB,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAW,UAAU,EAAoB,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,KAAK,EAAW,MAAM,YAAY,CAAC;AAQ5C,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB,CAAC;AAGF,KAAK,SAAS,G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