@bsv/sdk 1.2.1 → 1.2.2
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.
- package/dist/cjs/package.json +2 -2
- package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +3 -2
- package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +3 -2
- package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/compat.md +166 -135
- package/docs/messages.md +63 -55
- package/docs/overlay-tools.md +131 -101
- package/docs/primitives.md +4095 -3812
- package/docs/script.md +506 -467
- package/docs/totp.md +8 -0
- package/docs/transaction.md +822 -735
- package/docs/wallet.md +1025 -849
- package/package.json +2 -2
- package/src/overlay-tools/SHIPBroadcaster.ts +3 -2
- package/src/overlay-tools/__tests/SHIPBroadcaster.test.ts +4 -4
package/docs/script.md
CHANGED
|
@@ -39,6 +39,8 @@ export default interface ScriptTemplate {
|
|
|
39
39
|
}
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
See also: [LockingScript](#class-lockingscript), [Transaction](#class-transaction), [UnlockingScript](#class-unlockingscript), [sign](#variable-sign)
|
|
43
|
+
|
|
42
44
|
<details>
|
|
43
45
|
|
|
44
46
|
<summary>Interface ScriptTemplate Details</summary>
|
|
@@ -50,6 +52,7 @@ Creates a locking script with the given parameters.
|
|
|
50
52
|
```ts
|
|
51
53
|
lock: (...params: any) => LockingScript | Promise<LockingScript>
|
|
52
54
|
```
|
|
55
|
+
See also: [LockingScript](#class-lockingscript)
|
|
53
56
|
|
|
54
57
|
#### Property unlock
|
|
55
58
|
|
|
@@ -65,6 +68,7 @@ unlock: (...params: any) => {
|
|
|
65
68
|
estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>;
|
|
66
69
|
}
|
|
67
70
|
```
|
|
71
|
+
See also: [Transaction](#class-transaction), [UnlockingScript](#class-unlockingscript), [sign](#variable-sign)
|
|
68
72
|
|
|
69
73
|
</details>
|
|
70
74
|
|
|
@@ -87,362 +91,491 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
87
91
|
|
|
88
92
|
---
|
|
89
93
|
|
|
90
|
-
### Class:
|
|
94
|
+
### Class: LockingScript
|
|
91
95
|
|
|
92
|
-
The
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
The LockingScript class represents a locking script in a Bitcoin SV transaction.
|
|
97
|
+
It extends the Script class and is used specifically for output scripts that lock funds.
|
|
98
|
+
|
|
99
|
+
Inherits all properties and methods from the Script class.
|
|
95
100
|
|
|
96
101
|
```ts
|
|
97
|
-
export default class Script {
|
|
98
|
-
chunks: ScriptChunk[];
|
|
99
|
-
static fromASM(asm: string): Script
|
|
100
|
-
static fromHex(hex: string): Script
|
|
101
|
-
static fromBinary(bin: number[]): Script
|
|
102
|
-
constructor(chunks: ScriptChunk[] = [])
|
|
103
|
-
toASM(): string
|
|
104
|
-
toHex(): string
|
|
105
|
-
toBinary(): number[]
|
|
106
|
-
writeScript(script: Script): Script
|
|
107
|
-
writeOpCode(op: number): Script
|
|
108
|
-
setChunkOpCode(i: number, op: number): Script
|
|
109
|
-
writeBn(bn: BigNumber): Script
|
|
110
|
-
writeBin(bin: number[]): Script
|
|
111
|
-
writeNumber(num: number): Script
|
|
112
|
-
removeCodeseparators(): Script
|
|
113
|
-
findAndDelete(script: Script): Script
|
|
114
|
-
isPushOnly(): boolean
|
|
102
|
+
export default class LockingScript extends Script {
|
|
115
103
|
isLockingScript(): boolean
|
|
116
104
|
isUnlockingScript(): boolean
|
|
117
105
|
}
|
|
118
106
|
```
|
|
119
107
|
|
|
108
|
+
See also: [Script](#class-script)
|
|
109
|
+
|
|
120
110
|
<details>
|
|
121
111
|
|
|
122
|
-
<summary>Class
|
|
112
|
+
<summary>Class LockingScript Details</summary>
|
|
123
113
|
|
|
124
|
-
####
|
|
114
|
+
#### Method isLockingScript
|
|
125
115
|
|
|
126
116
|
```ts
|
|
127
|
-
|
|
117
|
+
isLockingScript(): boolean
|
|
128
118
|
```
|
|
129
119
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
+ **chunks**
|
|
133
|
-
+ =[] - An array of script chunks to directly initialize the script.
|
|
120
|
+
Returns
|
|
134
121
|
|
|
135
|
-
|
|
122
|
+
Always returns true for a LockingScript instance.
|
|
136
123
|
|
|
137
|
-
|
|
124
|
+
#### Method isUnlockingScript
|
|
138
125
|
|
|
139
126
|
```ts
|
|
140
|
-
|
|
127
|
+
isUnlockingScript(): boolean
|
|
141
128
|
```
|
|
142
129
|
|
|
143
130
|
Returns
|
|
144
131
|
|
|
145
|
-
|
|
132
|
+
Always returns false for a LockingScript instance.
|
|
146
133
|
|
|
147
|
-
|
|
134
|
+
</details>
|
|
148
135
|
|
|
149
|
-
|
|
150
|
-
+ The script containing the item to delete from the current script.
|
|
136
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
151
137
|
|
|
152
|
-
|
|
138
|
+
---
|
|
139
|
+
### Class: P2PKH
|
|
153
140
|
|
|
154
|
-
|
|
155
|
-
static fromASM(asm: string): Script
|
|
156
|
-
```
|
|
141
|
+
P2PKH (Pay To Public Key Hash) class implementing ScriptTemplate.
|
|
157
142
|
|
|
158
|
-
|
|
143
|
+
This class provides methods to create Pay To Public Key Hash locking and unlocking scripts, including the unlocking of P2PKH UTXOs with the private key.
|
|
159
144
|
|
|
160
|
-
|
|
145
|
+
```ts
|
|
146
|
+
export default class P2PKH implements ScriptTemplate {
|
|
147
|
+
lock(pubkeyhash: string | number[]): LockingScript
|
|
148
|
+
unlock(privateKey: PrivateKey, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay: boolean = false, sourceSatoshis?: number, lockingScript?: Script): {
|
|
149
|
+
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
150
|
+
estimateLength: () => Promise<108>;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
161
154
|
|
|
162
|
-
|
|
155
|
+
See also: [LockingScript](#class-lockingscript), [PrivateKey](#class-privatekey), [Script](#class-script), [ScriptTemplate](#interface-scripttemplate), [Transaction](#class-transaction), [UnlockingScript](#class-unlockingscript), [sign](#variable-sign)
|
|
163
156
|
|
|
164
|
-
|
|
165
|
-
+ The script in ASM string format.
|
|
157
|
+
<details>
|
|
166
158
|
|
|
167
|
-
|
|
159
|
+
<summary>Class P2PKH Details</summary>
|
|
168
160
|
|
|
169
|
-
|
|
170
|
-
const script = Script.fromASM("OP_DUP OP_HASH160 abcd... OP_EQUALVERIFY OP_CHECKSIG")
|
|
171
|
-
```
|
|
161
|
+
#### Method lock
|
|
172
162
|
|
|
173
|
-
|
|
163
|
+
Creates a P2PKH locking script for a given public key hash or address string
|
|
174
164
|
|
|
175
165
|
```ts
|
|
176
|
-
|
|
166
|
+
lock(pubkeyhash: string | number[]): LockingScript
|
|
177
167
|
```
|
|
168
|
+
See also: [LockingScript](#class-lockingscript)
|
|
178
169
|
|
|
179
170
|
Returns
|
|
180
171
|
|
|
181
|
-
A
|
|
172
|
+
- A P2PKH locking script.
|
|
182
173
|
|
|
183
174
|
Argument Details
|
|
184
175
|
|
|
185
|
-
+ **
|
|
186
|
-
+
|
|
176
|
+
+ **pubkeyhash**
|
|
177
|
+
+ or address - An array or address representing the public key hash.
|
|
187
178
|
|
|
188
|
-
|
|
179
|
+
#### Method unlock
|
|
189
180
|
|
|
190
|
-
|
|
191
|
-
const script = Script.fromBinary([0x76, 0xa9, ...])
|
|
192
|
-
```
|
|
181
|
+
Creates a function that generates a P2PKH unlocking script along with its signature and length estimation.
|
|
193
182
|
|
|
194
|
-
|
|
183
|
+
The returned object contains:
|
|
184
|
+
1. `sign` - A function that, when invoked with a transaction and an input index,
|
|
185
|
+
produces an unlocking script suitable for a P2PKH locked output.
|
|
186
|
+
2. `estimateLength` - A function that returns the estimated length of the unlocking script in bytes.
|
|
195
187
|
|
|
196
188
|
```ts
|
|
197
|
-
|
|
189
|
+
unlock(privateKey: PrivateKey, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay: boolean = false, sourceSatoshis?: number, lockingScript?: Script): {
|
|
190
|
+
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
191
|
+
estimateLength: () => Promise<108>;
|
|
192
|
+
}
|
|
198
193
|
```
|
|
194
|
+
See also: [PrivateKey](#class-privatekey), [Script](#class-script), [Transaction](#class-transaction), [UnlockingScript](#class-unlockingscript), [sign](#variable-sign)
|
|
199
195
|
|
|
200
196
|
Returns
|
|
201
197
|
|
|
202
|
-
|
|
198
|
+
- An object containing the `sign` and `estimateLength` functions.
|
|
203
199
|
|
|
204
200
|
Argument Details
|
|
205
201
|
|
|
206
|
-
+ **
|
|
207
|
-
+ The
|
|
202
|
+
+ **privateKey**
|
|
203
|
+
+ The private key used for signing the transaction.
|
|
204
|
+
+ **signOutputs**
|
|
205
|
+
+ The signature scope for outputs.
|
|
206
|
+
+ **anyoneCanPay**
|
|
207
|
+
+ Flag indicating if the signature allows for other inputs to be added later.
|
|
208
|
+
+ **sourceSatoshis**
|
|
209
|
+
+ Optional. The amount being unlocked. Otherwise the input.sourceTransaction is required.
|
|
210
|
+
+ **lockingScript**
|
|
211
|
+
+ Optional. The lockinScript. Otherwise the input.sourceTransaction is required.
|
|
208
212
|
|
|
209
|
-
|
|
213
|
+
</details>
|
|
210
214
|
|
|
211
|
-
|
|
212
|
-
const script = Script.fromHex("76a9...");
|
|
213
|
-
```
|
|
215
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
214
216
|
|
|
215
|
-
|
|
217
|
+
---
|
|
218
|
+
### Class: PushDrop
|
|
216
219
|
|
|
217
220
|
```ts
|
|
218
|
-
|
|
221
|
+
export default class PushDrop implements ScriptTemplate {
|
|
222
|
+
wallet: Wallet;
|
|
223
|
+
static decode(script: LockingScript): {
|
|
224
|
+
lockingPublicKey: PublicKey;
|
|
225
|
+
fields: number[][];
|
|
226
|
+
}
|
|
227
|
+
constructor(wallet: Wallet)
|
|
228
|
+
async lock(fields: number[][], protocolID: [
|
|
229
|
+
0 | 1 | 2,
|
|
230
|
+
string
|
|
231
|
+
], keyID: string, counterparty: string, forSelf = false, includeSignature = true, lockPosition: "before" | "after" = "before"): Promise<LockingScript>
|
|
232
|
+
unlock(protocolID: [
|
|
233
|
+
0 | 1 | 2,
|
|
234
|
+
string
|
|
235
|
+
], keyID: string, counterparty: string, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay = false, sourceSatoshis?: number, lockingScript?: LockingScript): {
|
|
236
|
+
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
237
|
+
estimateLength: () => Promise<73>;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
219
240
|
```
|
|
220
241
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
True if the script is a locking script, otherwise false.
|
|
224
|
-
|
|
225
|
-
#### Method isPushOnly
|
|
242
|
+
See also: [LockingScript](#class-lockingscript), [PublicKey](#class-publickey), [ScriptTemplate](#interface-scripttemplate), [Transaction](#class-transaction), [UnlockingScript](#class-unlockingscript), [Wallet](#interface-wallet), [sign](#variable-sign)
|
|
226
243
|
|
|
227
|
-
|
|
228
|
-
isPushOnly(): boolean
|
|
229
|
-
```
|
|
244
|
+
<details>
|
|
230
245
|
|
|
231
|
-
|
|
246
|
+
<summary>Class PushDrop Details</summary>
|
|
232
247
|
|
|
233
|
-
|
|
248
|
+
#### Constructor
|
|
234
249
|
|
|
235
|
-
|
|
250
|
+
Constructs a new instance of the PushDrop class.
|
|
236
251
|
|
|
237
252
|
```ts
|
|
238
|
-
|
|
253
|
+
constructor(wallet: Wallet)
|
|
239
254
|
```
|
|
255
|
+
See also: [Wallet](#interface-wallet)
|
|
240
256
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
True if the script is an unlocking script, otherwise false.
|
|
244
|
-
|
|
245
|
-
#### Method removeCodeseparators
|
|
246
|
-
|
|
247
|
-
```ts
|
|
248
|
-
removeCodeseparators(): Script
|
|
249
|
-
```
|
|
257
|
+
Argument Details
|
|
250
258
|
|
|
251
|
-
|
|
259
|
+
+ **wallet**
|
|
260
|
+
+ The wallet interface used for creating signatures and accessing public keys.
|
|
252
261
|
|
|
253
|
-
|
|
262
|
+
#### Method decode
|
|
254
263
|
|
|
255
|
-
|
|
264
|
+
Decodes a PushDrop script back into its token fields and the locking public key. If a signature was present, it will be the last field returned.
|
|
265
|
+
Warning: Only works with a P2PK lock at the beginning of the script.
|
|
256
266
|
|
|
257
267
|
```ts
|
|
258
|
-
|
|
268
|
+
static decode(script: LockingScript): {
|
|
269
|
+
lockingPublicKey: PublicKey;
|
|
270
|
+
fields: number[][];
|
|
271
|
+
}
|
|
259
272
|
```
|
|
273
|
+
See also: [LockingScript](#class-lockingscript), [PublicKey](#class-publickey)
|
|
260
274
|
|
|
261
275
|
Returns
|
|
262
276
|
|
|
263
|
-
|
|
277
|
+
An object containing PushDrop token fields and the locking public key. If a signature was included, it will be the last field.
|
|
264
278
|
|
|
265
279
|
Argument Details
|
|
266
280
|
|
|
267
|
-
+ **
|
|
268
|
-
+
|
|
269
|
-
+ **op**
|
|
270
|
-
+ The opcode to set.
|
|
271
|
-
|
|
272
|
-
#### Method toASM
|
|
273
|
-
|
|
274
|
-
```ts
|
|
275
|
-
toASM(): string
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
Returns
|
|
281
|
+
+ **script**
|
|
282
|
+
+ PushDrop script to decode back into token fields
|
|
279
283
|
|
|
280
|
-
|
|
284
|
+
#### Method lock
|
|
281
285
|
|
|
282
|
-
|
|
286
|
+
Creates a PushDrop locking script with arbitrary data fields and a public key lock.
|
|
283
287
|
|
|
284
288
|
```ts
|
|
285
|
-
|
|
289
|
+
async lock(fields: number[][], protocolID: [
|
|
290
|
+
0 | 1 | 2,
|
|
291
|
+
string
|
|
292
|
+
], keyID: string, counterparty: string, forSelf = false, includeSignature = true, lockPosition: "before" | "after" = "before"): Promise<LockingScript>
|
|
286
293
|
```
|
|
294
|
+
See also: [LockingScript](#class-lockingscript)
|
|
287
295
|
|
|
288
296
|
Returns
|
|
289
297
|
|
|
290
|
-
The
|
|
291
|
-
|
|
292
|
-
#### Method toHex
|
|
298
|
+
The generated PushDrop locking script.
|
|
293
299
|
|
|
294
|
-
|
|
295
|
-
toHex(): string
|
|
296
|
-
```
|
|
300
|
+
Argument Details
|
|
297
301
|
|
|
298
|
-
|
|
302
|
+
+ **fields**
|
|
303
|
+
+ The token fields to include in the locking script.
|
|
304
|
+
+ **protocolID**
|
|
305
|
+
+ The protocol ID to use.
|
|
306
|
+
+ **keyID**
|
|
307
|
+
+ The key ID to use.
|
|
308
|
+
+ **counterparty**
|
|
309
|
+
+ The counterparty involved in the transaction, "self" or "anyone".
|
|
310
|
+
+ **forSelf**
|
|
311
|
+
+ Flag indicating if the lock is for the creator (default no).
|
|
312
|
+
+ **includeSignature**
|
|
313
|
+
+ Flag indicating if a signature should be included in the script (default yes).
|
|
299
314
|
|
|
300
|
-
|
|
315
|
+
#### Method unlock
|
|
301
316
|
|
|
302
|
-
|
|
317
|
+
Creates an unlocking script for spending a PushDrop token output.
|
|
303
318
|
|
|
304
319
|
```ts
|
|
305
|
-
|
|
320
|
+
unlock(protocolID: [
|
|
321
|
+
0 | 1 | 2,
|
|
322
|
+
string
|
|
323
|
+
], keyID: string, counterparty: string, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay = false, sourceSatoshis?: number, lockingScript?: LockingScript): {
|
|
324
|
+
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
325
|
+
estimateLength: () => Promise<73>;
|
|
326
|
+
}
|
|
306
327
|
```
|
|
328
|
+
See also: [LockingScript](#class-lockingscript), [Transaction](#class-transaction), [UnlockingScript](#class-unlockingscript), [sign](#variable-sign)
|
|
307
329
|
|
|
308
330
|
Returns
|
|
309
331
|
|
|
310
|
-
|
|
332
|
+
An object containing functions to sign the transaction and estimate the script length.
|
|
311
333
|
|
|
312
334
|
Argument Details
|
|
313
335
|
|
|
314
|
-
+ **
|
|
315
|
-
+ The
|
|
316
|
-
|
|
317
|
-
|
|
336
|
+
+ **protocolID**
|
|
337
|
+
+ The protocol ID to use.
|
|
338
|
+
+ **keyID**
|
|
339
|
+
+ The key ID to use.
|
|
340
|
+
+ **counterparty**
|
|
341
|
+
+ The counterparty involved in the transaction, "self" or "anyone".
|
|
342
|
+
+ **sourceTXID**
|
|
343
|
+
+ The TXID of the source transaction.
|
|
344
|
+
+ **sourceSatoshis**
|
|
345
|
+
+ The number of satoshis in the source output.
|
|
346
|
+
+ **lockingScript**
|
|
347
|
+
+ The locking script of the source output.
|
|
348
|
+
+ **signOutputs**
|
|
349
|
+
+ Specifies which outputs to sign.
|
|
350
|
+
+ **anyoneCanPay**
|
|
351
|
+
+ Specifies if the anyone-can-pay flag is set.
|
|
318
352
|
|
|
319
|
-
|
|
353
|
+
</details>
|
|
320
354
|
|
|
321
|
-
|
|
355
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
### Class: RPuzzle
|
|
359
|
+
|
|
360
|
+
RPuzzle class implementing ScriptTemplate.
|
|
361
|
+
|
|
362
|
+
This class provides methods to create R Puzzle and R Puzzle Hash locking and unlocking scripts, including the unlocking of UTXOs with the correct K value.
|
|
322
363
|
|
|
323
364
|
```ts
|
|
324
|
-
|
|
365
|
+
export default class RPuzzle implements ScriptTemplate {
|
|
366
|
+
type: "raw" | "SHA1" | "SHA256" | "HASH256" | "RIPEMD160" | "HASH160" = "raw";
|
|
367
|
+
constructor(type: "raw" | "SHA1" | "SHA256" | "HASH256" | "RIPEMD160" | "HASH160" = "raw")
|
|
368
|
+
lock(value: number[]): LockingScript
|
|
369
|
+
unlock(k: BigNumber, privateKey: PrivateKey, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay: boolean = false): {
|
|
370
|
+
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
371
|
+
estimateLength: () => Promise<108>;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
325
374
|
```
|
|
326
375
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
This script instance for chaining.
|
|
376
|
+
See also: [BigNumber](#class-bignumber), [LockingScript](#class-lockingscript), [PrivateKey](#class-privatekey), [ScriptTemplate](#interface-scripttemplate), [Transaction](#class-transaction), [UnlockingScript](#class-unlockingscript), [sign](#variable-sign)
|
|
330
377
|
|
|
331
|
-
|
|
378
|
+
<details>
|
|
332
379
|
|
|
333
|
-
|
|
334
|
-
+ The BigNumber to append.
|
|
380
|
+
<summary>Class RPuzzle Details</summary>
|
|
335
381
|
|
|
336
|
-
####
|
|
382
|
+
#### Constructor
|
|
337
383
|
|
|
338
384
|
```ts
|
|
339
|
-
|
|
385
|
+
constructor(type: "raw" | "SHA1" | "SHA256" | "HASH256" | "RIPEMD160" | "HASH160" = "raw")
|
|
340
386
|
```
|
|
341
387
|
|
|
342
|
-
Returns
|
|
343
|
-
|
|
344
|
-
This script instance for chaining.
|
|
345
|
-
|
|
346
388
|
Argument Details
|
|
347
389
|
|
|
348
|
-
+ **
|
|
349
|
-
+
|
|
390
|
+
+ **type**
|
|
391
|
+
+ Denotes the type of puzzle to create
|
|
350
392
|
|
|
351
|
-
#### Method
|
|
393
|
+
#### Method lock
|
|
394
|
+
|
|
395
|
+
Creates an R puzzle locking script for a given R value or R value hash.
|
|
352
396
|
|
|
353
397
|
```ts
|
|
354
|
-
|
|
398
|
+
lock(value: number[]): LockingScript
|
|
355
399
|
```
|
|
400
|
+
See also: [LockingScript](#class-lockingscript)
|
|
356
401
|
|
|
357
402
|
Returns
|
|
358
403
|
|
|
359
|
-
|
|
404
|
+
- An R puzzle locking script.
|
|
360
405
|
|
|
361
406
|
Argument Details
|
|
362
407
|
|
|
363
|
-
+ **
|
|
364
|
-
+
|
|
408
|
+
+ **value**
|
|
409
|
+
+ An array representing the R value or its hash.
|
|
365
410
|
|
|
366
|
-
#### Method
|
|
411
|
+
#### Method unlock
|
|
412
|
+
|
|
413
|
+
Creates a function that generates an R puzzle unlocking script along with its signature and length estimation.
|
|
414
|
+
|
|
415
|
+
The returned object contains:
|
|
416
|
+
1. `sign` - A function that, when invoked with a transaction and an input index,
|
|
417
|
+
produces an unlocking script suitable for an R puzzle locked output.
|
|
418
|
+
2. `estimateLength` - A function that returns the estimated length of the unlocking script in bytes.
|
|
367
419
|
|
|
368
420
|
```ts
|
|
369
|
-
|
|
421
|
+
unlock(k: BigNumber, privateKey: PrivateKey, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay: boolean = false): {
|
|
422
|
+
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
423
|
+
estimateLength: () => Promise<108>;
|
|
424
|
+
}
|
|
370
425
|
```
|
|
426
|
+
See also: [BigNumber](#class-bignumber), [PrivateKey](#class-privatekey), [Transaction](#class-transaction), [UnlockingScript](#class-unlockingscript), [sign](#variable-sign)
|
|
371
427
|
|
|
372
428
|
Returns
|
|
373
429
|
|
|
374
|
-
|
|
430
|
+
- An object containing the `sign` and `estimateLength` functions.
|
|
375
431
|
|
|
376
432
|
Argument Details
|
|
377
433
|
|
|
378
|
-
+ **
|
|
379
|
-
+ The
|
|
434
|
+
+ **k**
|
|
435
|
+
+ — The K-value used to unlock the R-puzzle.
|
|
436
|
+
+ **privateKey**
|
|
437
|
+
+ The private key used for signing the transaction. If not provided, a random key will be generated.
|
|
438
|
+
+ **signOutputs**
|
|
439
|
+
+ The signature scope for outputs.
|
|
440
|
+
+ **anyoneCanPay**
|
|
441
|
+
+ Flag indicating if the signature allows for other inputs to be added later.
|
|
380
442
|
|
|
381
443
|
</details>
|
|
382
444
|
|
|
383
445
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
384
446
|
|
|
385
447
|
---
|
|
386
|
-
### Class:
|
|
387
|
-
|
|
388
|
-
The LockingScript class represents a locking script in a Bitcoin SV transaction.
|
|
389
|
-
It extends the Script class and is used specifically for output scripts that lock funds.
|
|
448
|
+
### Class: Script
|
|
390
449
|
|
|
391
|
-
|
|
450
|
+
The Script class represents a script in a Bitcoin SV transaction,
|
|
451
|
+
encapsulating the functionality to construct, parse, and serialize
|
|
452
|
+
scripts used in both locking (output) and unlocking (input) scripts.
|
|
392
453
|
|
|
393
454
|
```ts
|
|
394
|
-
export default class
|
|
455
|
+
export default class Script {
|
|
456
|
+
chunks: ScriptChunk[];
|
|
457
|
+
static fromASM(asm: string): Script
|
|
458
|
+
static fromHex(hex: string): Script
|
|
459
|
+
static fromBinary(bin: number[]): Script
|
|
460
|
+
constructor(chunks: ScriptChunk[] = [])
|
|
461
|
+
toASM(): string
|
|
462
|
+
toHex(): string
|
|
463
|
+
toBinary(): number[]
|
|
464
|
+
writeScript(script: Script): Script
|
|
465
|
+
writeOpCode(op: number): Script
|
|
466
|
+
setChunkOpCode(i: number, op: number): Script
|
|
467
|
+
writeBn(bn: BigNumber): Script
|
|
468
|
+
writeBin(bin: number[]): Script
|
|
469
|
+
writeNumber(num: number): Script
|
|
470
|
+
removeCodeseparators(): Script
|
|
471
|
+
findAndDelete(script: Script): Script
|
|
472
|
+
isPushOnly(): boolean
|
|
395
473
|
isLockingScript(): boolean
|
|
396
474
|
isUnlockingScript(): boolean
|
|
397
475
|
}
|
|
398
476
|
```
|
|
399
477
|
|
|
478
|
+
See also: [BigNumber](#class-bignumber), [ScriptChunk](#interface-scriptchunk), [toHex](#variable-tohex)
|
|
479
|
+
|
|
400
480
|
<details>
|
|
401
481
|
|
|
402
|
-
<summary>Class
|
|
482
|
+
<summary>Class Script Details</summary>
|
|
403
483
|
|
|
404
|
-
####
|
|
484
|
+
#### Constructor
|
|
405
485
|
|
|
406
486
|
```ts
|
|
407
|
-
|
|
487
|
+
constructor(chunks: ScriptChunk[] = [])
|
|
488
|
+
```
|
|
489
|
+
See also: [ScriptChunk](#interface-scriptchunk)
|
|
490
|
+
|
|
491
|
+
Argument Details
|
|
492
|
+
|
|
493
|
+
+ **chunks**
|
|
494
|
+
+ =[] - An array of script chunks to directly initialize the script.
|
|
495
|
+
|
|
496
|
+
#### Method findAndDelete
|
|
497
|
+
|
|
498
|
+
Deletes the given item wherever it appears in the current script.
|
|
499
|
+
|
|
500
|
+
```ts
|
|
501
|
+
findAndDelete(script: Script): Script
|
|
408
502
|
```
|
|
503
|
+
See also: [Script](#class-script)
|
|
409
504
|
|
|
410
505
|
Returns
|
|
411
506
|
|
|
412
|
-
|
|
507
|
+
This script instance for chaining.
|
|
413
508
|
|
|
414
|
-
|
|
509
|
+
Argument Details
|
|
510
|
+
|
|
511
|
+
+ **script**
|
|
512
|
+
+ The script containing the item to delete from the current script.
|
|
513
|
+
|
|
514
|
+
#### Method fromASM
|
|
415
515
|
|
|
416
516
|
```ts
|
|
417
|
-
|
|
517
|
+
static fromASM(asm: string): Script
|
|
418
518
|
```
|
|
519
|
+
See also: [Script](#class-script)
|
|
419
520
|
|
|
420
521
|
Returns
|
|
421
522
|
|
|
422
|
-
|
|
523
|
+
A new Script instance.
|
|
423
524
|
|
|
424
|
-
|
|
525
|
+
Argument Details
|
|
425
526
|
|
|
426
|
-
|
|
527
|
+
+ **asm**
|
|
528
|
+
+ The script in ASM string format.
|
|
427
529
|
|
|
428
|
-
|
|
429
|
-
### Class: UnlockingScript
|
|
530
|
+
Example
|
|
430
531
|
|
|
431
|
-
|
|
432
|
-
|
|
532
|
+
```ts
|
|
533
|
+
const script = Script.fromASM("OP_DUP OP_HASH160 abcd... OP_EQUALVERIFY OP_CHECKSIG")
|
|
534
|
+
```
|
|
433
535
|
|
|
434
|
-
|
|
536
|
+
#### Method fromBinary
|
|
435
537
|
|
|
436
538
|
```ts
|
|
437
|
-
|
|
438
|
-
isLockingScript(): boolean
|
|
439
|
-
isUnlockingScript(): boolean
|
|
440
|
-
}
|
|
539
|
+
static fromBinary(bin: number[]): Script
|
|
441
540
|
```
|
|
541
|
+
See also: [Script](#class-script)
|
|
442
542
|
|
|
443
|
-
|
|
543
|
+
Returns
|
|
444
544
|
|
|
445
|
-
|
|
545
|
+
A new Script instance.
|
|
546
|
+
|
|
547
|
+
Argument Details
|
|
548
|
+
|
|
549
|
+
+ **bin**
|
|
550
|
+
+ The script in binary array format.
|
|
551
|
+
|
|
552
|
+
Example
|
|
553
|
+
|
|
554
|
+
```ts
|
|
555
|
+
const script = Script.fromBinary([0x76, 0xa9, ...])
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
#### Method fromHex
|
|
559
|
+
|
|
560
|
+
```ts
|
|
561
|
+
static fromHex(hex: string): Script
|
|
562
|
+
```
|
|
563
|
+
See also: [Script](#class-script)
|
|
564
|
+
|
|
565
|
+
Returns
|
|
566
|
+
|
|
567
|
+
A new Script instance.
|
|
568
|
+
|
|
569
|
+
Argument Details
|
|
570
|
+
|
|
571
|
+
+ **hex**
|
|
572
|
+
+ The script in hexadecimal format.
|
|
573
|
+
|
|
574
|
+
Example
|
|
575
|
+
|
|
576
|
+
```ts
|
|
577
|
+
const script = Script.fromHex("76a9...");
|
|
578
|
+
```
|
|
446
579
|
|
|
447
580
|
#### Method isLockingScript
|
|
448
581
|
|
|
@@ -452,7 +585,17 @@ isLockingScript(): boolean
|
|
|
452
585
|
|
|
453
586
|
Returns
|
|
454
587
|
|
|
455
|
-
|
|
588
|
+
True if the script is a locking script, otherwise false.
|
|
589
|
+
|
|
590
|
+
#### Method isPushOnly
|
|
591
|
+
|
|
592
|
+
```ts
|
|
593
|
+
isPushOnly(): boolean
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
Returns
|
|
597
|
+
|
|
598
|
+
True if the script is push-only, otherwise false.
|
|
456
599
|
|
|
457
600
|
#### Method isUnlockingScript
|
|
458
601
|
|
|
@@ -462,35 +605,178 @@ isUnlockingScript(): boolean
|
|
|
462
605
|
|
|
463
606
|
Returns
|
|
464
607
|
|
|
465
|
-
|
|
608
|
+
True if the script is an unlocking script, otherwise false.
|
|
466
609
|
|
|
467
|
-
|
|
610
|
+
#### Method removeCodeseparators
|
|
468
611
|
|
|
469
|
-
|
|
612
|
+
```ts
|
|
613
|
+
removeCodeseparators(): Script
|
|
614
|
+
```
|
|
615
|
+
See also: [Script](#class-script)
|
|
470
616
|
|
|
471
|
-
|
|
472
|
-
### Class: Spend
|
|
617
|
+
Returns
|
|
473
618
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
619
|
+
This script instance for chaining.
|
|
620
|
+
|
|
621
|
+
#### Method setChunkOpCode
|
|
477
622
|
|
|
478
623
|
```ts
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
624
|
+
setChunkOpCode(i: number, op: number): Script
|
|
625
|
+
```
|
|
626
|
+
See also: [Script](#class-script)
|
|
627
|
+
|
|
628
|
+
Returns
|
|
629
|
+
|
|
630
|
+
This script instance for chaining.
|
|
631
|
+
|
|
632
|
+
Argument Details
|
|
633
|
+
|
|
634
|
+
+ **i**
|
|
635
|
+
+ The index of the chunk.
|
|
636
|
+
+ **op**
|
|
637
|
+
+ The opcode to set.
|
|
638
|
+
|
|
639
|
+
#### Method toASM
|
|
640
|
+
|
|
641
|
+
```ts
|
|
642
|
+
toASM(): string
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
Returns
|
|
646
|
+
|
|
647
|
+
The script in ASM string format.
|
|
648
|
+
|
|
649
|
+
#### Method toBinary
|
|
650
|
+
|
|
651
|
+
```ts
|
|
652
|
+
toBinary(): number[]
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
Returns
|
|
656
|
+
|
|
657
|
+
The script in binary array format.
|
|
658
|
+
|
|
659
|
+
#### Method toHex
|
|
660
|
+
|
|
661
|
+
```ts
|
|
662
|
+
toHex(): string
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
Returns
|
|
666
|
+
|
|
667
|
+
The script in hexadecimal format.
|
|
668
|
+
|
|
669
|
+
#### Method writeBin
|
|
670
|
+
|
|
671
|
+
```ts
|
|
672
|
+
writeBin(bin: number[]): Script
|
|
673
|
+
```
|
|
674
|
+
See also: [Script](#class-script)
|
|
675
|
+
|
|
676
|
+
Returns
|
|
677
|
+
|
|
678
|
+
This script instance for chaining.
|
|
679
|
+
|
|
680
|
+
Argument Details
|
|
681
|
+
|
|
682
|
+
+ **bin**
|
|
683
|
+
+ The binary data to append.
|
|
684
|
+
|
|
685
|
+
Throws
|
|
686
|
+
|
|
687
|
+
Throws an error if the data is too large to be pushed.
|
|
688
|
+
|
|
689
|
+
#### Method writeBn
|
|
690
|
+
|
|
691
|
+
```ts
|
|
692
|
+
writeBn(bn: BigNumber): Script
|
|
693
|
+
```
|
|
694
|
+
See also: [BigNumber](#class-bignumber), [Script](#class-script)
|
|
695
|
+
|
|
696
|
+
Returns
|
|
697
|
+
|
|
698
|
+
This script instance for chaining.
|
|
699
|
+
|
|
700
|
+
Argument Details
|
|
701
|
+
|
|
702
|
+
+ **bn**
|
|
703
|
+
+ The BigNumber to append.
|
|
704
|
+
|
|
705
|
+
#### Method writeNumber
|
|
706
|
+
|
|
707
|
+
```ts
|
|
708
|
+
writeNumber(num: number): Script
|
|
709
|
+
```
|
|
710
|
+
See also: [Script](#class-script)
|
|
711
|
+
|
|
712
|
+
Returns
|
|
713
|
+
|
|
714
|
+
This script instance for chaining.
|
|
715
|
+
|
|
716
|
+
Argument Details
|
|
717
|
+
|
|
718
|
+
+ **num**
|
|
719
|
+
+ The number to append.
|
|
720
|
+
|
|
721
|
+
#### Method writeOpCode
|
|
722
|
+
|
|
723
|
+
```ts
|
|
724
|
+
writeOpCode(op: number): Script
|
|
725
|
+
```
|
|
726
|
+
See also: [Script](#class-script)
|
|
727
|
+
|
|
728
|
+
Returns
|
|
729
|
+
|
|
730
|
+
This script instance for chaining.
|
|
731
|
+
|
|
732
|
+
Argument Details
|
|
733
|
+
|
|
734
|
+
+ **op**
|
|
735
|
+
+ The opcode to append.
|
|
736
|
+
|
|
737
|
+
#### Method writeScript
|
|
738
|
+
|
|
739
|
+
```ts
|
|
740
|
+
writeScript(script: Script): Script
|
|
741
|
+
```
|
|
742
|
+
See also: [Script](#class-script)
|
|
743
|
+
|
|
744
|
+
Returns
|
|
745
|
+
|
|
746
|
+
This script instance for chaining.
|
|
747
|
+
|
|
748
|
+
Argument Details
|
|
749
|
+
|
|
750
|
+
+ **script**
|
|
751
|
+
+ The script to append.
|
|
752
|
+
|
|
753
|
+
</details>
|
|
754
|
+
|
|
755
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
756
|
+
|
|
757
|
+
---
|
|
758
|
+
### Class: Spend
|
|
759
|
+
|
|
760
|
+
The Spend class represents a spend action within a Bitcoin SV transaction.
|
|
761
|
+
It encapsulates all the necessary data required for spending a UTXO (Unspent Transaction Output)
|
|
762
|
+
and includes details about the source transaction, output, and the spending transaction itself.
|
|
763
|
+
|
|
764
|
+
```ts
|
|
765
|
+
export default class Spend {
|
|
766
|
+
sourceTXID: string;
|
|
767
|
+
sourceOutputIndex: number;
|
|
768
|
+
sourceSatoshis: number;
|
|
769
|
+
lockingScript: LockingScript;
|
|
770
|
+
transactionVersion: number;
|
|
771
|
+
otherInputs: TransactionInput[];
|
|
772
|
+
outputs: TransactionOutput[];
|
|
773
|
+
inputIndex: number;
|
|
774
|
+
unlockingScript: UnlockingScript;
|
|
775
|
+
inputSequence: number;
|
|
776
|
+
lockTime: number;
|
|
777
|
+
context: "UnlockingScript" | "LockingScript";
|
|
778
|
+
programCounter: number;
|
|
779
|
+
lastCodeSeparator: number | null;
|
|
494
780
|
stack: number[][];
|
|
495
781
|
altStack: number[][];
|
|
496
782
|
ifStack: boolean[];
|
|
@@ -513,6 +799,8 @@ export default class Spend {
|
|
|
513
799
|
}
|
|
514
800
|
```
|
|
515
801
|
|
|
802
|
+
See also: [LockingScript](#class-lockingscript), [TransactionInput](#interface-transactioninput), [TransactionOutput](#interface-transactionoutput), [UnlockingScript](#class-unlockingscript)
|
|
803
|
+
|
|
516
804
|
<details>
|
|
517
805
|
|
|
518
806
|
<summary>Class Spend Details</summary>
|
|
@@ -534,6 +822,7 @@ constructor(params: {
|
|
|
534
822
|
lockTime: number;
|
|
535
823
|
})
|
|
536
824
|
```
|
|
825
|
+
See also: [LockingScript](#class-lockingscript), [TransactionInput](#interface-transactioninput), [TransactionOutput](#interface-transactionoutput), [UnlockingScript](#class-unlockingscript)
|
|
537
826
|
|
|
538
827
|
Argument Details
|
|
539
828
|
|
|
@@ -604,295 +893,45 @@ if (spend.validate()) {
|
|
|
604
893
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
605
894
|
|
|
606
895
|
---
|
|
607
|
-
### Class:
|
|
608
|
-
|
|
609
|
-
P2PKH (Pay To Public Key Hash) class implementing ScriptTemplate.
|
|
610
|
-
|
|
611
|
-
This class provides methods to create Pay To Public Key Hash locking and unlocking scripts, including the unlocking of P2PKH UTXOs with the private key.
|
|
612
|
-
|
|
613
|
-
```ts
|
|
614
|
-
export default class P2PKH implements ScriptTemplate {
|
|
615
|
-
lock(pubkeyhash: string | number[]): LockingScript
|
|
616
|
-
unlock(privateKey: PrivateKey, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay: boolean = false, sourceSatoshis?: number, lockingScript?: Script): {
|
|
617
|
-
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
618
|
-
estimateLength: () => Promise<108>;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
```
|
|
622
|
-
|
|
623
|
-
<details>
|
|
624
|
-
|
|
625
|
-
<summary>Class P2PKH Details</summary>
|
|
626
|
-
|
|
627
|
-
#### Method lock
|
|
628
|
-
|
|
629
|
-
Creates a P2PKH locking script for a given public key hash or address string
|
|
630
|
-
|
|
631
|
-
```ts
|
|
632
|
-
lock(pubkeyhash: string | number[]): LockingScript
|
|
633
|
-
```
|
|
634
|
-
|
|
635
|
-
Returns
|
|
636
|
-
|
|
637
|
-
- A P2PKH locking script.
|
|
638
|
-
|
|
639
|
-
Argument Details
|
|
640
|
-
|
|
641
|
-
+ **pubkeyhash**
|
|
642
|
-
+ or address - An array or address representing the public key hash.
|
|
643
|
-
|
|
644
|
-
#### Method unlock
|
|
645
|
-
|
|
646
|
-
Creates a function that generates a P2PKH unlocking script along with its signature and length estimation.
|
|
647
|
-
|
|
648
|
-
The returned object contains:
|
|
649
|
-
1. `sign` - A function that, when invoked with a transaction and an input index,
|
|
650
|
-
produces an unlocking script suitable for a P2PKH locked output.
|
|
651
|
-
2. `estimateLength` - A function that returns the estimated length of the unlocking script in bytes.
|
|
652
|
-
|
|
653
|
-
```ts
|
|
654
|
-
unlock(privateKey: PrivateKey, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay: boolean = false, sourceSatoshis?: number, lockingScript?: Script): {
|
|
655
|
-
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
656
|
-
estimateLength: () => Promise<108>;
|
|
657
|
-
}
|
|
658
|
-
```
|
|
659
|
-
|
|
660
|
-
Returns
|
|
661
|
-
|
|
662
|
-
- An object containing the `sign` and `estimateLength` functions.
|
|
663
|
-
|
|
664
|
-
Argument Details
|
|
665
|
-
|
|
666
|
-
+ **privateKey**
|
|
667
|
-
+ The private key used for signing the transaction.
|
|
668
|
-
+ **signOutputs**
|
|
669
|
-
+ The signature scope for outputs.
|
|
670
|
-
+ **anyoneCanPay**
|
|
671
|
-
+ Flag indicating if the signature allows for other inputs to be added later.
|
|
672
|
-
+ **sourceSatoshis**
|
|
673
|
-
+ Optional. The amount being unlocked. Otherwise the input.sourceTransaction is required.
|
|
674
|
-
+ **lockingScript**
|
|
675
|
-
+ Optional. The lockinScript. Otherwise the input.sourceTransaction is required.
|
|
676
|
-
|
|
677
|
-
</details>
|
|
678
|
-
|
|
679
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
680
|
-
|
|
681
|
-
---
|
|
682
|
-
### Class: RPuzzle
|
|
896
|
+
### Class: UnlockingScript
|
|
683
897
|
|
|
684
|
-
|
|
898
|
+
The UnlockingScript class represents an unlocking script in a Bitcoin SV transaction.
|
|
899
|
+
It extends the Script class and is used specifically for input scripts that unlock funds.
|
|
685
900
|
|
|
686
|
-
|
|
901
|
+
Inherits all properties and methods from the Script class.
|
|
687
902
|
|
|
688
903
|
```ts
|
|
689
|
-
export default class
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
lock(value: number[]): LockingScript
|
|
693
|
-
unlock(k: BigNumber, privateKey: PrivateKey, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay: boolean = false): {
|
|
694
|
-
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
695
|
-
estimateLength: () => Promise<108>;
|
|
696
|
-
}
|
|
904
|
+
export default class UnlockingScript extends Script {
|
|
905
|
+
isLockingScript(): boolean
|
|
906
|
+
isUnlockingScript(): boolean
|
|
697
907
|
}
|
|
698
908
|
```
|
|
699
909
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
<summary>Class RPuzzle Details</summary>
|
|
703
|
-
|
|
704
|
-
#### Constructor
|
|
705
|
-
|
|
706
|
-
```ts
|
|
707
|
-
constructor(type: "raw" | "SHA1" | "SHA256" | "HASH256" | "RIPEMD160" | "HASH160" = "raw")
|
|
708
|
-
```
|
|
709
|
-
|
|
710
|
-
Argument Details
|
|
711
|
-
|
|
712
|
-
+ **type**
|
|
713
|
-
+ Denotes the type of puzzle to create
|
|
714
|
-
|
|
715
|
-
#### Method lock
|
|
716
|
-
|
|
717
|
-
Creates an R puzzle locking script for a given R value or R value hash.
|
|
718
|
-
|
|
719
|
-
```ts
|
|
720
|
-
lock(value: number[]): LockingScript
|
|
721
|
-
```
|
|
722
|
-
|
|
723
|
-
Returns
|
|
724
|
-
|
|
725
|
-
- An R puzzle locking script.
|
|
726
|
-
|
|
727
|
-
Argument Details
|
|
728
|
-
|
|
729
|
-
+ **value**
|
|
730
|
-
+ An array representing the R value or its hash.
|
|
731
|
-
|
|
732
|
-
#### Method unlock
|
|
733
|
-
|
|
734
|
-
Creates a function that generates an R puzzle unlocking script along with its signature and length estimation.
|
|
735
|
-
|
|
736
|
-
The returned object contains:
|
|
737
|
-
1. `sign` - A function that, when invoked with a transaction and an input index,
|
|
738
|
-
produces an unlocking script suitable for an R puzzle locked output.
|
|
739
|
-
2. `estimateLength` - A function that returns the estimated length of the unlocking script in bytes.
|
|
740
|
-
|
|
741
|
-
```ts
|
|
742
|
-
unlock(k: BigNumber, privateKey: PrivateKey, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay: boolean = false): {
|
|
743
|
-
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
744
|
-
estimateLength: () => Promise<108>;
|
|
745
|
-
}
|
|
746
|
-
```
|
|
747
|
-
|
|
748
|
-
Returns
|
|
749
|
-
|
|
750
|
-
- An object containing the `sign` and `estimateLength` functions.
|
|
751
|
-
|
|
752
|
-
Argument Details
|
|
753
|
-
|
|
754
|
-
+ **k**
|
|
755
|
-
+ — The K-value used to unlock the R-puzzle.
|
|
756
|
-
+ **privateKey**
|
|
757
|
-
+ The private key used for signing the transaction. If not provided, a random key will be generated.
|
|
758
|
-
+ **signOutputs**
|
|
759
|
-
+ The signature scope for outputs.
|
|
760
|
-
+ **anyoneCanPay**
|
|
761
|
-
+ Flag indicating if the signature allows for other inputs to be added later.
|
|
762
|
-
|
|
763
|
-
</details>
|
|
764
|
-
|
|
765
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
766
|
-
|
|
767
|
-
---
|
|
768
|
-
### Class: PushDrop
|
|
769
|
-
|
|
770
|
-
```ts
|
|
771
|
-
export default class PushDrop implements ScriptTemplate {
|
|
772
|
-
wallet: Wallet;
|
|
773
|
-
static decode(script: LockingScript): {
|
|
774
|
-
lockingPublicKey: PublicKey;
|
|
775
|
-
fields: number[][];
|
|
776
|
-
}
|
|
777
|
-
constructor(wallet: Wallet)
|
|
778
|
-
async lock(fields: number[][], protocolID: [
|
|
779
|
-
0 | 1 | 2,
|
|
780
|
-
string
|
|
781
|
-
], keyID: string, counterparty: string, forSelf = false, includeSignature = true, lockPosition: "before" | "after" = "before"): Promise<LockingScript>
|
|
782
|
-
unlock(protocolID: [
|
|
783
|
-
0 | 1 | 2,
|
|
784
|
-
string
|
|
785
|
-
], keyID: string, counterparty: string, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay = false, sourceSatoshis?: number, lockingScript?: LockingScript): {
|
|
786
|
-
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
787
|
-
estimateLength: () => Promise<73>;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
```
|
|
910
|
+
See also: [Script](#class-script)
|
|
791
911
|
|
|
792
912
|
<details>
|
|
793
913
|
|
|
794
|
-
<summary>Class
|
|
795
|
-
|
|
796
|
-
#### Constructor
|
|
797
|
-
|
|
798
|
-
Constructs a new instance of the PushDrop class.
|
|
799
|
-
|
|
800
|
-
```ts
|
|
801
|
-
constructor(wallet: Wallet)
|
|
802
|
-
```
|
|
803
|
-
|
|
804
|
-
Argument Details
|
|
805
|
-
|
|
806
|
-
+ **wallet**
|
|
807
|
-
+ The wallet interface used for creating signatures and accessing public keys.
|
|
808
|
-
|
|
809
|
-
#### Method decode
|
|
810
|
-
|
|
811
|
-
Decodes a PushDrop script back into its token fields and the locking public key. If a signature was present, it will be the last field returned.
|
|
812
|
-
Warning: Only works with a P2PK lock at the beginning of the script.
|
|
813
|
-
|
|
814
|
-
```ts
|
|
815
|
-
static decode(script: LockingScript): {
|
|
816
|
-
lockingPublicKey: PublicKey;
|
|
817
|
-
fields: number[][];
|
|
818
|
-
}
|
|
819
|
-
```
|
|
820
|
-
|
|
821
|
-
Returns
|
|
822
|
-
|
|
823
|
-
An object containing PushDrop token fields and the locking public key. If a signature was included, it will be the last field.
|
|
824
|
-
|
|
825
|
-
Argument Details
|
|
826
|
-
|
|
827
|
-
+ **script**
|
|
828
|
-
+ PushDrop script to decode back into token fields
|
|
829
|
-
|
|
830
|
-
#### Method lock
|
|
914
|
+
<summary>Class UnlockingScript Details</summary>
|
|
831
915
|
|
|
832
|
-
|
|
916
|
+
#### Method isLockingScript
|
|
833
917
|
|
|
834
918
|
```ts
|
|
835
|
-
|
|
836
|
-
0 | 1 | 2,
|
|
837
|
-
string
|
|
838
|
-
], keyID: string, counterparty: string, forSelf = false, includeSignature = true, lockPosition: "before" | "after" = "before"): Promise<LockingScript>
|
|
919
|
+
isLockingScript(): boolean
|
|
839
920
|
```
|
|
840
921
|
|
|
841
922
|
Returns
|
|
842
923
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
Argument Details
|
|
846
|
-
|
|
847
|
-
+ **fields**
|
|
848
|
-
+ The token fields to include in the locking script.
|
|
849
|
-
+ **protocolID**
|
|
850
|
-
+ The protocol ID to use.
|
|
851
|
-
+ **keyID**
|
|
852
|
-
+ The key ID to use.
|
|
853
|
-
+ **counterparty**
|
|
854
|
-
+ The counterparty involved in the transaction, "self" or "anyone".
|
|
855
|
-
+ **forSelf**
|
|
856
|
-
+ Flag indicating if the lock is for the creator (default no).
|
|
857
|
-
+ **includeSignature**
|
|
858
|
-
+ Flag indicating if a signature should be included in the script (default yes).
|
|
859
|
-
|
|
860
|
-
#### Method unlock
|
|
924
|
+
Always returns false for an UnlockingScript instance.
|
|
861
925
|
|
|
862
|
-
|
|
926
|
+
#### Method isUnlockingScript
|
|
863
927
|
|
|
864
928
|
```ts
|
|
865
|
-
|
|
866
|
-
0 | 1 | 2,
|
|
867
|
-
string
|
|
868
|
-
], keyID: string, counterparty: string, signOutputs: "all" | "none" | "single" = "all", anyoneCanPay = false, sourceSatoshis?: number, lockingScript?: LockingScript): {
|
|
869
|
-
sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
|
|
870
|
-
estimateLength: () => Promise<73>;
|
|
871
|
-
}
|
|
929
|
+
isUnlockingScript(): boolean
|
|
872
930
|
```
|
|
873
931
|
|
|
874
932
|
Returns
|
|
875
933
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
Argument Details
|
|
879
|
-
|
|
880
|
-
+ **protocolID**
|
|
881
|
-
+ The protocol ID to use.
|
|
882
|
-
+ **keyID**
|
|
883
|
-
+ The key ID to use.
|
|
884
|
-
+ **counterparty**
|
|
885
|
-
+ The counterparty involved in the transaction, "self" or "anyone".
|
|
886
|
-
+ **sourceTXID**
|
|
887
|
-
+ The TXID of the source transaction.
|
|
888
|
-
+ **sourceSatoshis**
|
|
889
|
-
+ The number of satoshis in the source output.
|
|
890
|
-
+ **lockingScript**
|
|
891
|
-
+ The locking script of the source output.
|
|
892
|
-
+ **signOutputs**
|
|
893
|
-
+ Specifies which outputs to sign.
|
|
894
|
-
+ **anyoneCanPay**
|
|
895
|
-
+ Specifies if the anyone-can-pay flag is set.
|
|
934
|
+
Always returns true for an UnlockingScript instance.
|
|
896
935
|
|
|
897
936
|
</details>
|
|
898
937
|
|