-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.d.ts
More file actions
282 lines (237 loc) · 10.3 KB
/
index.d.ts
File metadata and controls
282 lines (237 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
export const version: string;
export const testnet: boolean;
export const feePerKb: number;
export module classes {
export class BufferReader {
constructor(buffer: ByteArray, pos?: number);
read(length: number): ByteArray;
close(): void;
checkRemaining(length: number): void;
}
export class BufferWriter {
constructor();
write(buffer: ByteArray): BufferWriter;
toBuffer(): ByteArray;
}
export class PrivateKey {
constructor(number: ByteArray, testnet: boolean, compressed: boolean, validate?: boolean);
readonly compressed: boolean;
readonly testnet: boolean;
readonly number: ByteArray;
static from(privateKey: PrivateKey | string | Object ): PrivateKey;
static fromString(wif: string): PrivateKey;
static fromRandom(testnet?: boolean): PrivateKey;
toAddress(): Address;
toPublicKey(): PublicKey;
toString(): string;
}
export class PublicKey {
constructor(point: Point, testnet: boolean, compressed: boolean, validate?: boolean);
readonly compressed: boolean;
readonly testnet: boolean;
readonly point: Point;
static from(x: PublicKey | PrivateKey | string | Object): PublicKey;
static fromString(pubkey: string): PublicKey;
static fromPrivateKey(privateKey: PrivateKey): PublicKey;
toAddress(): Address;
toString(): string;
toBuffer(): ByteArray;
}
export class Address {
constructor(pubkeyhash: ByteArray, testnet: boolean, validate?: boolean);
readonly testnet: boolean;
readonly pubkeyhash: ByteArray;
static from(x: Address | PublicKey | string | Object): Address;
static fromString(s: string): Address;
static fromPublicKey(publicKey: PublicKey): Address;
toString(): string;
toScript(): P2PKHLockScript;
}
type scriptTemplates = {
P2PKHLockScript: P2PKHLockScript
}
export class Script {
constructor(buffer?: ByteArray, validate?: boolean);
readonly buffer: ByteArray;
readonly length: number;
readonly chunks: Chunk[];
static slice(start: number, end: number): ByteArray;
static fromString(s: string): Script;
static fromHex(s: string): Script;
static fromASM(s: string): Script;
static fromBuffer(buffer: ByteArray): Script;
static from(script: Script | ByteArray | string | Object): Script;
static templates: scriptTemplates;
toString(): string;
toASM(): string;
toHex(): string;
toBuffer(): ByteArray;
}
export namespace Transaction {
export class Output {
constructor(script: Script | ByteArray | string, satoshis: number, tx?: Transaction);
readonly txid: string;
readonly vout: number;
readonly satoshis: number;
readonly script: Script | P2PKHLockScript;
readonly tx: Transaction;
}
export class Input {
constructor(txid: string, vout: number, script?: Script, sequence?: number, output?: Output);
readonly script: Script;
readonly vout: number;
readonly sequence: number;
readonly txid: string;
}
}
export class Transaction {
constructor();
readonly hash: string;
readonly fee: number;
readonly version: number;
readonly inputs: Transaction.Input[];
readonly outputs: Transaction.Output[];
readonly changeOutput: Transaction.Output | null;
locktime: number;
to(address: Address | PublicKey | string | Object, satoshis: number): Transaction;
input(input: Transaction.Input | {
txid: string | undefined,
vout: number | undefined,
script: Script | P2PKHLockScript,
sequence: number,
output: Transaction.Output }): Transaction;
output(output: Transaction.Output | { script: Script; satoshis: number }): Transaction;
change(address: Address | PublicKey | string | Object): Transaction;
sign(privateKey: PrivateKey | string): Transaction;
verify(): Transaction;
finalize(): Transaction;
_calculateChange(): void;
setFeePerKb(satoshis: number): Transaction;
static fromString(hex: string): Transaction;
static fromHex(hex: string): Transaction;
static fromBuffer(buffer: ByteArray): Transaction;
static from(output: Transaction.Output | Transaction.Output[]): Transaction;
toString(): string;
toHex(): string;
toBuffer(): ByteArray;
}
}
declare interface P2PKHLockScript extends Script {
matches(buffer: ByteArray): boolean;
fromAddress(address: Address | PublicKey | string | Object): P2PKHLockScript;
toAddress(): Address;
}
export class functions {
static areBuffersEqual(a: ByteArray, b: ByteArray): boolean;
static calculatePublicKeyHash(publicKey: Point): ByteArray;
static calculatePublicKey (privateKey: ByteArray): Point;
static calculateTxid(buffer: ByteArray): string;
static createP2PKHLockScript(pubkeyhash: ByteArray): ByteArray;
static createP2PKHUnlockScript(signature: ByteArray, pubkey: ByteArray): ByteArray;
static decodeAddress(address: string): {testnet: boolean, pubkeyhash: ByteArray};
static decodeASM(script: string): ByteArray;
static decodeBase58Check(s: string): {version: number, payload: ByteArray};
static decodeBase58(s: string): ByteArray;
static decodeBase64(b64: string): ByteArray;
static decodeDER(buffer: ByteArray): Signature;
static decodeHex(hex: string): ByteArray;
static decodePublicKey(buffer: ByteArray): Point;
static decodeScriptChunks(script: ByteArray): Chunk[];
static decodeTx(buffer: ByteArray): tx;
static decodeWIF(privkey: string): {number: ByteArray, testnet: boolean, compressed: boolean};
static ecdsaSign(hash32: ByteArray, privateKey: ByteArray, publicKey: Point): Signature | null;
static ecdsaSignAsync(hash32: ByteArray, privateKey: ByteArray, publicKey: Point): Promise<Signature>;
static ecdsaSignWithK(hash32: ByteArray, k: ByteArray, privateKey: ByteArray, publicKey: Point): Signature | null;
static ecdsaVerify(signature: Signature, hash32: ByteArray, publicKey: Point): boolean;
static encodeAddress(pubkeyhash: ByteArray, testnet: boolean): string;
static encodeBase58(payload: ByteArray): string;
static encodeDER(signature: ByteArray): ByteArray;
static encodeHex(buffer: ByteArray): string;
static encodePublicKey(publicKey: Point, compress: boolean): ByteArray;
static encodePushData (buffer: ByteArray): ByteArray;
static encodeTx(tx: Transaction): ByteArray;
static encodeWIF(payload: ByteArray, testnet: boolean, compressed?: boolean): string;
static evalScript(unlockScript: ByteArray, lockScript: ByteArray, tx: Transaction, vin: number, parentSatoshis: number, opts?: { async?: boolean, trace?: boolean}): evalResult;
static extractP2PKHLockScriptPubkeyhash (script: ByteArray): ByteArray;
static generatePrivateKey(): ByteArray;
static generateRandomData(size: number): ByteArray;
static isBuffer(a: any): boolean;
static isHex(s: string): boolean;
static isP2PKHLockScript(script: ByteArray): boolean;
static preimage(tx: Transaction, vin: number, parentScript: ByteArray, parentSatoshis: number, sighashFlags: number, async?: boolean): ByteArray;
static preimageAsync(tx: Transaction, vin: number, parentScript: ByteArray, parentSatoshis: number, sighashFlags: number): Promise<ByteArray>;
static readBlockHeader(reader: classes.BufferReader): BlockHeader;
static readDER(reader: classes.BufferReader): {r: ByteArray, s: ByteArray};
static readTx(reader: classes.BufferReader): tx;
static readU32LE(reader: classes.BufferReader): number;
static readU64LE(reader: classes.BufferReader): number;
static readVarint(reader: classes.BufferReader): number;
static ripemd160(data: ByteArray): ByteArray;
static ripemd160Async(data: ByteArray): Promise<ByteArray>;
static sha1(data: ByteArray): ByteArray;
static sha1Async(data: ByteArray): Promise<ByteArray>;
static sha256(data: ByteArray): ByteArray;
static sha256d(data: ByteArray): ByteArray;
static sha256ripemd160(data: ByteArray): ByteArray;
static sighash(tx: Transaction, vin: number, parentScript: ByteArray, parentSatoshis: number, sighashFlags: number, async?: boolean): ByteArray;
static sighashAsync(tx: Transaction, vin: number, parentScript: ByteArray, parentSatoshis: number, sighashFlags: number): Promise<ByteArray>;
static verifyPoint(publicKey: Point): Point;
static verifyPrivateKey (privateKey: ByteArray): ByteArray;
static verifyScript(unlockScript: ByteArray, lockScript: ByteArray, tx: Transaction, vin: number, parentSatoshis: number, async?: boolean): Error | boolean;
static verifyScriptAsync(unlockScript: ByteArray, lockScript: ByteArray, tx: Transaction, vin: number, parentSatoshis: number): Promise<Error | boolean>;
static verifyTxSignature(tx: Transaction, vin: number, signature: ByteArray, pubkey: Point, parentScript: ByteArray, parentSatoshis: number): boolean;
static verifyTx(tx: Transaction, parents: ParentTx[], minFeePerKb: number): void;
static writeDER(writer: classes.BufferWriter, signature: Signature): void;
static writePushData(writer: classes.BufferWriter, buffer: ByteArray): classes.BufferWriter;
static writeTx(writer: classes.BufferWriter, tx: Transaction): void;
static writeU32LE(writer: classes.BufferWriter, n: number): classes.BufferWriter;
static writeU64LE(writer: classes.BufferWriter, n: number): classes.BufferWriter;
static writeVarint(writer: classes.BufferWriter, n: number): classes.BufferWriter;
}
export class PrivateKey extends classes.PrivateKey {}
export class PublicKey extends classes.PublicKey {}
export class Address extends classes.Address {}
export class Script extends classes.Script {}
export class Transaction extends classes.Transaction {}
export type BufferReader = classes.BufferReader;
export type BufferWriter = classes.BufferWriter;
export interface ByteArray extends Iterable<number> {
length: number;
}
export type Point = {
x: ByteArray;
y: ByteArray;
}
export type Chunk = {
opcode: number;
buf?: ByteArray;
}
type Signature = {
r: ByteArray;
s: ByteArray;
}
type BlockHeader = {
version: number;
prevBlock: ByteArray;
merkleRoot: ByteArray;
timestamp: number;
bits: number;
nonce: number;
}
type tx = {
version: number;
inputs: classes.Transaction.Input[];
outputs: classes.Transaction.Output[];
locktime: number;
}
type evalResult = {
success: boolean;
error: Error | null;
chunks: Chunk[];
stack: string;
stackTrace: string;
}
type ParentTx = {
script: ByteArray;
satoshis: number;
}