@bsv/sdk 2.0.8 → 2.0.10
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 +1 -1
- package/dist/cjs/src/auth/certificates/Certificate.js +1 -1
- package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/cjs/src/primitives/BigNumber.js +4 -5
- package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
- package/dist/cjs/src/primitives/index.js.map +1 -1
- package/dist/cjs/src/script/OP.js +22 -16
- package/dist/cjs/src/script/OP.js.map +1 -1
- package/dist/cjs/src/script/Spend.js +21 -78
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/src/transaction/Transaction.js +45 -0
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/certificates/Certificate.js +1 -1
- package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/esm/src/primitives/BigNumber.js +4 -5
- package/dist/esm/src/primitives/BigNumber.js.map +1 -1
- package/dist/esm/src/primitives/index.js.map +1 -1
- package/dist/esm/src/script/OP.js +22 -16
- package/dist/esm/src/script/OP.js.map +1 -1
- package/dist/esm/src/script/Spend.js +21 -78
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/src/transaction/Transaction.js +45 -0
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
- package/dist/types/src/primitives/index.d.ts +1 -1
- package/dist/types/src/primitives/index.d.ts.map +1 -1
- package/dist/types/src/script/OP.d.ts +9 -7
- package/dist/types/src/script/OP.d.ts.map +1 -1
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/src/transaction/Transaction.d.ts +9 -0
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +3 -3
- package/dist/umd/bundle.js.map +1 -1
- package/docs/reference/script.md +76 -0
- package/docs/reference/transaction.md +87 -7
- package/docs/reference/wallet.md +285 -1094
- package/package.json +1 -1
- package/src/auth/certificates/Certificate.ts +1 -1
- package/src/primitives/BigNumber.ts +4 -5
- package/src/primitives/__tests/BigNumber.constructor.test.ts +3 -3
- package/src/primitives/index.ts +1 -1
- package/src/script/OP.ts +21 -16
- package/src/script/Spend.ts +21 -28
- package/src/script/__tests/Chronicle.test.ts +39 -103
- package/src/script/__tests/ChronicleOpcodes.test.ts +548 -0
- package/src/transaction/Transaction.ts +46 -0
- package/src/transaction/__tests/Transaction.test.ts +170 -0
package/docs/reference/script.md
CHANGED
|
@@ -6,6 +6,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
6
6
|
|
|
7
7
|
| |
|
|
8
8
|
| --- |
|
|
9
|
+
| [FormatPreimageParams](#interface-formatpreimageparams) |
|
|
9
10
|
| [ScriptChunk](#interface-scriptchunk) |
|
|
10
11
|
| [ScriptTemplate](#interface-scripttemplate) |
|
|
11
12
|
| [ScriptTemplateUnlock](#interface-scripttemplateunlock) |
|
|
@@ -14,6 +15,28 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
14
15
|
|
|
15
16
|
---
|
|
16
17
|
|
|
18
|
+
### Interface: FormatPreimageParams
|
|
19
|
+
|
|
20
|
+
Parameters for formatting the transaction preimage
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
export interface FormatPreimageParams {
|
|
24
|
+
tx: Transaction;
|
|
25
|
+
inputIndex: number;
|
|
26
|
+
signatureScope: number;
|
|
27
|
+
sourceTXID: string;
|
|
28
|
+
sourceSatoshis: number;
|
|
29
|
+
lockingScript: Script;
|
|
30
|
+
otherInputs: Transaction["inputs"];
|
|
31
|
+
inputSequence?: number;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
See also: [Script](./script.md#class-script), [Transaction](./transaction.md#class-transaction)
|
|
36
|
+
|
|
37
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
38
|
+
|
|
39
|
+
---
|
|
17
40
|
### Interface: ScriptChunk
|
|
18
41
|
|
|
19
42
|
A representation of a chunk of a script, which includes an opcode. For push operations, the associated data to push onto the stack is also included.
|
|
@@ -942,6 +965,59 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
942
965
|
---
|
|
943
966
|
## Functions
|
|
944
967
|
|
|
968
|
+
| |
|
|
969
|
+
| --- |
|
|
970
|
+
| [computeSignatureScope](#function-computesignaturescope) |
|
|
971
|
+
| [formatPreimage](#function-formatpreimage) |
|
|
972
|
+
| [resolveSourceDetails](#function-resolvesourcedetails) |
|
|
973
|
+
|
|
974
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
975
|
+
|
|
976
|
+
---
|
|
977
|
+
|
|
978
|
+
### Function: computeSignatureScope
|
|
979
|
+
|
|
980
|
+
Computes the signature scope flags from the given signing parameters.
|
|
981
|
+
|
|
982
|
+
```ts
|
|
983
|
+
export function computeSignatureScope(signOutputs: "all" | "none" | "single", anyoneCanPay: boolean): number
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
987
|
+
|
|
988
|
+
---
|
|
989
|
+
### Function: formatPreimage
|
|
990
|
+
|
|
991
|
+
Formats the transaction preimage for signing.
|
|
992
|
+
|
|
993
|
+
```ts
|
|
994
|
+
export function formatPreimage(params: FormatPreimageParams): number[]
|
|
995
|
+
```
|
|
996
|
+
|
|
997
|
+
See also: [FormatPreimageParams](./script.md#interface-formatpreimageparams)
|
|
998
|
+
|
|
999
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
1000
|
+
|
|
1001
|
+
---
|
|
1002
|
+
### Function: resolveSourceDetails
|
|
1003
|
+
|
|
1004
|
+
Resolves and validates the source transaction details needed for signing.
|
|
1005
|
+
Returns the resolved sourceTXID, sourceSatoshis, lockingScript, and otherInputs.
|
|
1006
|
+
|
|
1007
|
+
```ts
|
|
1008
|
+
export function resolveSourceDetails(tx: Transaction, inputIndex: number, providedSourceSatoshis?: number, providedLockingScript?: Script): {
|
|
1009
|
+
sourceTXID: string;
|
|
1010
|
+
sourceSatoshis: number;
|
|
1011
|
+
lockingScript: Script;
|
|
1012
|
+
otherInputs: typeof tx.inputs;
|
|
1013
|
+
}
|
|
1014
|
+
```
|
|
1015
|
+
|
|
1016
|
+
See also: [Script](./script.md#class-script), [Transaction](./transaction.md#class-transaction)
|
|
1017
|
+
|
|
1018
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
1019
|
+
|
|
1020
|
+
---
|
|
945
1021
|
## Types
|
|
946
1022
|
|
|
947
1023
|
## Enums
|
|
@@ -6,14 +6,15 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
6
6
|
|
|
7
7
|
| | |
|
|
8
8
|
| --- | --- |
|
|
9
|
-
| [ArcConfig](#interface-arcconfig) | [
|
|
9
|
+
| [ArcConfig](#interface-arcconfig) | [HttpsModuleLike](#interface-httpsmodulelike) |
|
|
10
10
|
| [BroadcastFailure](#interface-broadcastfailure) | [HttpsNodejs](#interface-httpsnodejs) |
|
|
11
11
|
| [BroadcastResponse](#interface-broadcastresponse) | [MerklePathLeaf](#interface-merklepathleaf) |
|
|
12
12
|
| [Broadcaster](#interface-broadcaster) | [NodejsHttpClientRequest](#interface-nodejshttpclientrequest) |
|
|
13
|
-
| [ChainTracker](#interface-chaintracker) | [
|
|
14
|
-
| [FeeModel](#interface-feemodel) | [
|
|
15
|
-
| [FetchOptions](#interface-fetchoptions) | [
|
|
16
|
-
| [HttpClient](#interface-httpclient) |
|
|
13
|
+
| [ChainTracker](#interface-chaintracker) | [NodejsRequestLike](#interface-nodejsrequestlike) |
|
|
14
|
+
| [FeeModel](#interface-feemodel) | [TransactionInput](#interface-transactioninput) |
|
|
15
|
+
| [FetchOptions](#interface-fetchoptions) | [TransactionOutput](#interface-transactionoutput) |
|
|
16
|
+
| [HttpClient](#interface-httpclient) | [WhatsOnChainConfig](#interface-whatsonchainconfig) |
|
|
17
|
+
| [HttpClientRequestOptions](#interface-httpclientrequestoptions) | |
|
|
17
18
|
|
|
18
19
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
19
20
|
|
|
@@ -297,6 +298,21 @@ signal?: AbortSignal
|
|
|
297
298
|
|
|
298
299
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
299
300
|
|
|
301
|
+
---
|
|
302
|
+
### Interface: HttpsModuleLike
|
|
303
|
+
|
|
304
|
+
Common interface for Node.js https modules
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
export interface HttpsModuleLike {
|
|
308
|
+
request: (url: string, options: HttpClientRequestOptions, callback: (res: any) => void) => NodejsRequestLike;
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
See also: [HttpClientRequestOptions](./transaction.md#interface-httpclientrequestoptions), [NodejsRequestLike](./transaction.md#interface-nodejsrequestlike)
|
|
313
|
+
|
|
314
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
315
|
+
|
|
300
316
|
---
|
|
301
317
|
### Interface: HttpsNodejs
|
|
302
318
|
|
|
@@ -335,7 +351,22 @@ Nodejs result of the Node https.request call limited to options needed by ts-sdk
|
|
|
335
351
|
export interface NodejsHttpClientRequest {
|
|
336
352
|
write: (chunk: string) => void;
|
|
337
353
|
on: (event: string, callback: (data: any) => void) => void;
|
|
338
|
-
end: (
|
|
354
|
+
end: () => void;
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
### Interface: NodejsRequestLike
|
|
362
|
+
|
|
363
|
+
Common interface for Node.js https module request objects
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
export interface NodejsRequestLike {
|
|
367
|
+
write: (chunk: any) => void;
|
|
368
|
+
on: (event: string, callback: (data: any) => void) => void;
|
|
369
|
+
end: () => void;
|
|
339
370
|
}
|
|
340
371
|
```
|
|
341
372
|
|
|
@@ -1673,10 +1704,11 @@ export default class Transaction {
|
|
|
1673
1704
|
toAtomicBEEF(allowPartial?: boolean): number[]
|
|
1674
1705
|
toAtomicBEEFUint8Array(allowPartial?: boolean): Uint8Array
|
|
1675
1706
|
async completeWithWallet(wallet: WalletInterface, actionDescription?: DescriptionString5to50Bytes, originator?: string, options?: CreateActionOptions): Promise<void>
|
|
1707
|
+
preimage(inputIndex?: number, signatureScope?: number, subscript?: LockingScript): number[]
|
|
1676
1708
|
}
|
|
1677
1709
|
```
|
|
1678
1710
|
|
|
1679
|
-
See also: [BroadcastFailure](./transaction.md#interface-broadcastfailure), [BroadcastResponse](./transaction.md#interface-broadcastresponse), [Broadcaster](./transaction.md#interface-broadcaster), [ChainTracker](./transaction.md#interface-chaintracker), [CreateActionOptions](./wallet.md#interface-createactionoptions), [DescriptionString5to50Bytes](./wallet.md#type-descriptionstring5to50bytes), [FeeModel](./transaction.md#interface-feemodel), [LivePolicy](./transaction.md#class-livepolicy), [MerklePath](./transaction.md#class-merklepath), [Reader](./primitives.md#class-reader), [ReaderUint8Array](./primitives.md#class-readeruint8array), [TransactionInput](./transaction.md#interface-transactioninput), [TransactionOutput](./transaction.md#interface-transactionoutput), [WalletInterface](./wallet.md#interface-walletinterface), [Writer](./primitives.md#class-writer), [WriterUint8Array](./primitives.md#class-writeruint8array), [defaultBroadcaster](./transaction.md#function-defaultbroadcaster), [defaultChainTracker](./transaction.md#function-defaultchaintracker), [sign](./compat.md#variable-sign), [toHex](./primitives.md#variable-tohex), [toUint8Array](./primitives.md#variable-touint8array), [verify](./compat.md#variable-verify)
|
|
1711
|
+
See also: [BroadcastFailure](./transaction.md#interface-broadcastfailure), [BroadcastResponse](./transaction.md#interface-broadcastresponse), [Broadcaster](./transaction.md#interface-broadcaster), [ChainTracker](./transaction.md#interface-chaintracker), [CreateActionOptions](./wallet.md#interface-createactionoptions), [DescriptionString5to50Bytes](./wallet.md#type-descriptionstring5to50bytes), [FeeModel](./transaction.md#interface-feemodel), [LivePolicy](./transaction.md#class-livepolicy), [LockingScript](./script.md#class-lockingscript), [MerklePath](./transaction.md#class-merklepath), [Reader](./primitives.md#class-reader), [ReaderUint8Array](./primitives.md#class-readeruint8array), [TransactionInput](./transaction.md#interface-transactioninput), [TransactionOutput](./transaction.md#interface-transactionoutput), [WalletInterface](./wallet.md#interface-walletinterface), [Writer](./primitives.md#class-writer), [WriterUint8Array](./primitives.md#class-writeruint8array), [defaultBroadcaster](./transaction.md#function-defaultbroadcaster), [defaultChainTracker](./transaction.md#function-defaultchaintracker), [sign](./compat.md#variable-sign), [toHex](./primitives.md#variable-tohex), [toUint8Array](./primitives.md#variable-touint8array), [verify](./compat.md#variable-verify)
|
|
1680
1712
|
|
|
1681
1713
|
#### Method addInput
|
|
1682
1714
|
|
|
@@ -2033,6 +2065,28 @@ Argument Details
|
|
|
2033
2065
|
+ **bin**
|
|
2034
2066
|
+ binary transaction data
|
|
2035
2067
|
|
|
2068
|
+
#### Method preimage
|
|
2069
|
+
|
|
2070
|
+
Returns the formatted preimage of a transaction for the requested input index, signature scope (default SIGHASH_FORKID | SIGHASH_ALL), and optional subscript.
|
|
2071
|
+
|
|
2072
|
+
```ts
|
|
2073
|
+
preimage(inputIndex?: number, signatureScope?: number, subscript?: LockingScript): number[]
|
|
2074
|
+
```
|
|
2075
|
+
See also: [LockingScript](./script.md#class-lockingscript)
|
|
2076
|
+
|
|
2077
|
+
Returns
|
|
2078
|
+
|
|
2079
|
+
The formatted preimage
|
|
2080
|
+
|
|
2081
|
+
Argument Details
|
|
2082
|
+
|
|
2083
|
+
+ **inputIndex**
|
|
2084
|
+
+ The index of the input to generate the preimage for
|
|
2085
|
+
+ **signatureScope**
|
|
2086
|
+
+ The signature scope to use for the preimage
|
|
2087
|
+
+ **subscript**
|
|
2088
|
+
+ The subscript to use for the preimage (optional)
|
|
2089
|
+
|
|
2036
2090
|
#### Method sign
|
|
2037
2091
|
|
|
2038
2092
|
Signs a transaction, hydrating all its unlocking scripts based on the provided script templates where they are available.
|
|
@@ -2328,6 +2382,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
2328
2382
|
| [defaultBroadcaster](#function-defaultbroadcaster) |
|
|
2329
2383
|
| [defaultChainTracker](#function-defaultchaintracker) |
|
|
2330
2384
|
| [defaultHttpClient](#function-defaulthttpclient) |
|
|
2385
|
+
| [executeNodejsRequest](#function-executenodejsrequest) |
|
|
2331
2386
|
| [isBroadcastFailure](#function-isbroadcastfailure) |
|
|
2332
2387
|
| [isBroadcastResponse](#function-isbroadcastresponse) |
|
|
2333
2388
|
|
|
@@ -2371,6 +2426,31 @@ See also: [HttpClient](./transaction.md#interface-httpclient)
|
|
|
2371
2426
|
|
|
2372
2427
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
2373
2428
|
|
|
2429
|
+
---
|
|
2430
|
+
### Function: executeNodejsRequest
|
|
2431
|
+
|
|
2432
|
+
Shared implementation for handling Node.js HTTP requests.
|
|
2433
|
+
Used by both NodejsHttpClient and BinaryNodejsHttpClient.
|
|
2434
|
+
|
|
2435
|
+
```ts
|
|
2436
|
+
export function executeNodejsRequest(https: HttpsModuleLike, url: string, requestOptions: HttpClientRequestOptions, serializeData: (data: any) => any): Promise<HttpClientResponse>
|
|
2437
|
+
```
|
|
2438
|
+
|
|
2439
|
+
See also: [HttpClientRequestOptions](./transaction.md#interface-httpclientrequestoptions), [HttpClientResponse](./transaction.md#type-httpclientresponse), [HttpsModuleLike](./transaction.md#interface-httpsmodulelike)
|
|
2440
|
+
|
|
2441
|
+
Argument Details
|
|
2442
|
+
|
|
2443
|
+
+ **https**
|
|
2444
|
+
+ The Node.js https module (or compatible)
|
|
2445
|
+
+ **url**
|
|
2446
|
+
+ The URL to make the request to
|
|
2447
|
+
+ **requestOptions**
|
|
2448
|
+
+ The request configuration
|
|
2449
|
+
+ **serializeData**
|
|
2450
|
+
+ Function to serialize the request data for writing
|
|
2451
|
+
|
|
2452
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
|
|
2453
|
+
|
|
2374
2454
|
---
|
|
2375
2455
|
### Function: isBroadcastFailure
|
|
2376
2456
|
|