@bsv/sdk 1.2.4 → 1.2.5
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/transaction/broadcasters/ARC.js +57 -17
- package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -1
- package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js +2 -2
- package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/transaction/broadcasters/ARC.js +57 -17
- package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -1
- package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +2 -2
- package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/transaction/broadcasters/ARC.d.ts +12 -1
- package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -1
- package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts +2 -1
- package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/transaction.md +22 -2
- package/docs/wallet.md +11 -11
- package/package.json +1 -1
- package/src/transaction/broadcasters/ARC.ts +72 -27
- package/src/transaction/broadcasters/DefaultBroadcaster.ts +4 -4
package/docs/transaction.md
CHANGED
|
@@ -498,6 +498,7 @@ export default class ARC implements Broadcaster {
|
|
|
498
498
|
constructor(URL: string, apiKey?: string);
|
|
499
499
|
constructor(URL: string, config?: string | ArcConfig)
|
|
500
500
|
async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>
|
|
501
|
+
async broadcastMany(txs: Transaction[]): Promise<Array<object>>
|
|
501
502
|
}
|
|
502
503
|
```
|
|
503
504
|
|
|
@@ -556,6 +557,25 @@ Argument Details
|
|
|
556
557
|
+ **tx**
|
|
557
558
|
+ The transaction to be broadcasted.
|
|
558
559
|
|
|
560
|
+
#### Method broadcastMany
|
|
561
|
+
|
|
562
|
+
Broadcasts multiple transactions via ARC.
|
|
563
|
+
Handles mixed responses where some transactions succeed and others fail.
|
|
564
|
+
|
|
565
|
+
```ts
|
|
566
|
+
async broadcastMany(txs: Transaction[]): Promise<Array<object>>
|
|
567
|
+
```
|
|
568
|
+
See also: [Transaction](#class-transaction)
|
|
569
|
+
|
|
570
|
+
Returns
|
|
571
|
+
|
|
572
|
+
A promise that resolves to an array of objects.
|
|
573
|
+
|
|
574
|
+
Argument Details
|
|
575
|
+
|
|
576
|
+
+ **txs**
|
|
577
|
+
+ Array of transactions to be broadcasted.
|
|
578
|
+
|
|
559
579
|
</details>
|
|
560
580
|
|
|
561
581
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
@@ -2038,10 +2058,10 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
2038
2058
|
### Function: defaultBroadcaster
|
|
2039
2059
|
|
|
2040
2060
|
```ts
|
|
2041
|
-
export function defaultBroadcaster(): Broadcaster
|
|
2061
|
+
export function defaultBroadcaster(isTestnet: boolean = false, config: ArcConfig = {}): Broadcaster
|
|
2042
2062
|
```
|
|
2043
2063
|
|
|
2044
|
-
See also: [Broadcaster](#interface-broadcaster)
|
|
2064
|
+
See also: [ArcConfig](#interface-arcconfig), [Broadcaster](#interface-broadcaster)
|
|
2045
2065
|
|
|
2046
2066
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
2047
2067
|
|
package/docs/wallet.md
CHANGED
|
@@ -111,8 +111,8 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
111
111
|
export interface CreateActionArgs {
|
|
112
112
|
description: DescriptionString5to50Bytes;
|
|
113
113
|
inputBEEF?: BEEF;
|
|
114
|
-
inputs?:
|
|
115
|
-
outputs?:
|
|
114
|
+
inputs?: CreateActionInput[];
|
|
115
|
+
outputs?: CreateActionOutput[];
|
|
116
116
|
lockTime?: PositiveIntegerOrZero;
|
|
117
117
|
version?: PositiveIntegerOrZero;
|
|
118
118
|
labels?: LabelStringUnder300Bytes[];
|
|
@@ -188,7 +188,7 @@ export interface CreateActionResult {
|
|
|
188
188
|
txid?: TXIDHexString;
|
|
189
189
|
tx?: AtomicBEEF;
|
|
190
190
|
noSendChange?: OutpointString[];
|
|
191
|
-
sendWithResults?:
|
|
191
|
+
sendWithResults?: SendWithResult[];
|
|
192
192
|
signableTransaction?: SignableTransaction;
|
|
193
193
|
}
|
|
194
194
|
```
|
|
@@ -262,7 +262,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
262
262
|
```ts
|
|
263
263
|
export interface DiscoverCertificatesResult {
|
|
264
264
|
totalCertificates: PositiveIntegerOrZero;
|
|
265
|
-
certificates:
|
|
265
|
+
certificates: IdentityCertificate[];
|
|
266
266
|
}
|
|
267
267
|
```
|
|
268
268
|
|
|
@@ -325,7 +325,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
325
325
|
```ts
|
|
326
326
|
export interface InternalizeActionArgs {
|
|
327
327
|
tx: AtomicBEEF;
|
|
328
|
-
outputs:
|
|
328
|
+
outputs: InternalizeOutput[];
|
|
329
329
|
description: DescriptionString5to50Bytes;
|
|
330
330
|
labels?: LabelStringUnder300Bytes[];
|
|
331
331
|
seekPermission?: BooleanDefaultTrue;
|
|
@@ -426,7 +426,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
426
426
|
```ts
|
|
427
427
|
export interface ListActionsResult {
|
|
428
428
|
totalActions: PositiveIntegerOrZero;
|
|
429
|
-
actions:
|
|
429
|
+
actions: WalletAction[];
|
|
430
430
|
}
|
|
431
431
|
```
|
|
432
432
|
|
|
@@ -458,7 +458,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
458
458
|
```ts
|
|
459
459
|
export interface ListCertificatesResult {
|
|
460
460
|
totalCertificates: PositiveIntegerOrZero;
|
|
461
|
-
certificates:
|
|
461
|
+
certificates: WalletCertificate[];
|
|
462
462
|
}
|
|
463
463
|
```
|
|
464
464
|
|
|
@@ -495,7 +495,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
495
495
|
export interface ListOutputsResult {
|
|
496
496
|
totalOutputs: PositiveIntegerOrZero;
|
|
497
497
|
BEEF?: BEEF;
|
|
498
|
-
outputs:
|
|
498
|
+
outputs: WalletOutput[];
|
|
499
499
|
}
|
|
500
500
|
```
|
|
501
501
|
|
|
@@ -657,7 +657,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
657
657
|
export interface SignActionResult {
|
|
658
658
|
txid?: TXIDHexString;
|
|
659
659
|
tx?: AtomicBEEF;
|
|
660
|
-
sendWithResults?:
|
|
660
|
+
sendWithResults?: SendWithResult[];
|
|
661
661
|
}
|
|
662
662
|
```
|
|
663
663
|
|
|
@@ -1116,8 +1116,8 @@ export interface WalletAction {
|
|
|
1116
1116
|
labels?: LabelStringUnder300Bytes[];
|
|
1117
1117
|
version: PositiveIntegerOrZero;
|
|
1118
1118
|
lockTime: PositiveIntegerOrZero;
|
|
1119
|
-
inputs?:
|
|
1120
|
-
outputs?:
|
|
1119
|
+
inputs?: WalletActionInput[];
|
|
1120
|
+
outputs?: WalletActionOutput[];
|
|
1121
1121
|
}
|
|
1122
1122
|
```
|
|
1123
1123
|
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@ export interface ArcConfig {
|
|
|
21
21
|
headers?: Record<string, string>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function defaultDeploymentId
|
|
24
|
+
function defaultDeploymentId() {
|
|
25
25
|
return `ts-sdk-${toHex(Random(16))}`
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -43,16 +43,16 @@ export default class ARC implements Broadcaster {
|
|
|
43
43
|
* @param {string} URL - The URL endpoint for the ARC API.
|
|
44
44
|
* @param {ArcConfig} config - Configuration options for the ARC broadcaster.
|
|
45
45
|
*/
|
|
46
|
-
constructor
|
|
46
|
+
constructor(URL: string, config?: ArcConfig)
|
|
47
47
|
/**
|
|
48
48
|
* Constructs an instance of the ARC broadcaster.
|
|
49
49
|
*
|
|
50
50
|
* @param {string} URL - The URL endpoint for the ARC API.
|
|
51
51
|
* @param {string} apiKey - The API key used for authorization with the ARC API.
|
|
52
52
|
*/
|
|
53
|
-
constructor
|
|
53
|
+
constructor(URL: string, apiKey?: string)
|
|
54
54
|
|
|
55
|
-
constructor
|
|
55
|
+
constructor(URL: string, config?: string | ArcConfig) {
|
|
56
56
|
this.URL = URL
|
|
57
57
|
if (typeof config === 'string') {
|
|
58
58
|
this.apiKey = config
|
|
@@ -71,13 +71,43 @@ export default class ARC implements Broadcaster {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Constructs a dictionary of the default & supplied request headers.
|
|
76
|
+
*/
|
|
77
|
+
private requestHeaders() {
|
|
78
|
+
const headers: Record<string, string> = {
|
|
79
|
+
'Content-Type': 'application/json',
|
|
80
|
+
'XDeployment-ID': this.deploymentId
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (this.apiKey) {
|
|
84
|
+
headers.Authorization = `Bearer ${this.apiKey}`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (this.callbackUrl) {
|
|
88
|
+
headers['X-CallbackUrl'] = this.callbackUrl
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (this.callbackToken) {
|
|
92
|
+
headers['X-CallbackToken'] = this.callbackToken
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (this.headers) {
|
|
96
|
+
for (const key in this.headers) {
|
|
97
|
+
headers[key] = this.headers[key]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return headers
|
|
102
|
+
}
|
|
103
|
+
|
|
74
104
|
/**
|
|
75
105
|
* Broadcasts a transaction via ARC.
|
|
76
106
|
*
|
|
77
107
|
* @param {Transaction} tx - The transaction to be broadcasted.
|
|
78
108
|
* @returns {Promise<BroadcastResponse | BroadcastFailure>} A promise that resolves to either a success or failure response.
|
|
79
109
|
*/
|
|
80
|
-
async broadcast
|
|
110
|
+
async broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure> {
|
|
81
111
|
let rawTx
|
|
82
112
|
try {
|
|
83
113
|
rawTx = tx.toHexEF()
|
|
@@ -99,7 +129,7 @@ export default class ARC implements Broadcaster {
|
|
|
99
129
|
const response = await this.httpClient.request<ArcResponse>(`${this.URL}/v1/tx`, requestOptions)
|
|
100
130
|
if (response.ok) {
|
|
101
131
|
const { txid, extraInfo, txStatus, competingTxs } = response.data
|
|
102
|
-
let broadcastRes
|
|
132
|
+
let broadcastRes: BroadcastResponse = {
|
|
103
133
|
status: 'success',
|
|
104
134
|
txid,
|
|
105
135
|
message: `${txStatus} ${extraInfo}`
|
|
@@ -143,31 +173,46 @@ export default class ARC implements Broadcaster {
|
|
|
143
173
|
}
|
|
144
174
|
}
|
|
145
175
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Broadcasts multiple transactions via ARC.
|
|
178
|
+
* Handles mixed responses where some transactions succeed and others fail.
|
|
179
|
+
*
|
|
180
|
+
* @param {Transaction[]} txs - Array of transactions to be broadcasted.
|
|
181
|
+
* @returns {Promise<Array<object>>} A promise that resolves to an array of objects.
|
|
182
|
+
*/
|
|
183
|
+
async broadcastMany(txs: Transaction[]): Promise<Array<object>> {
|
|
184
|
+
const rawTxs = txs.map(tx => {
|
|
185
|
+
try {
|
|
186
|
+
return { rawTx: tx.toHexEF() };
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (error.message === 'All inputs must have source transactions when serializing to EF format') {
|
|
189
|
+
return { rawTx: tx.toHex() };
|
|
190
|
+
}
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
155
194
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
195
|
+
const requestOptions: HttpClientRequestOptions = {
|
|
196
|
+
method: 'POST',
|
|
197
|
+
headers: this.requestHeaders(),
|
|
198
|
+
data: rawTxs
|
|
199
|
+
};
|
|
159
200
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
201
|
+
try {
|
|
202
|
+
const response = await this.httpClient.request<Array<object>>(
|
|
203
|
+
`${this.URL}/v1/txs`,
|
|
204
|
+
requestOptions
|
|
205
|
+
);
|
|
163
206
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
207
|
+
return response.data
|
|
208
|
+
} catch (error) {
|
|
209
|
+
const errorResponse: BroadcastFailure = {
|
|
210
|
+
status: 'error',
|
|
211
|
+
code: '500',
|
|
212
|
+
description: error.message || 'Internal Server Error'
|
|
213
|
+
};
|
|
214
|
+
return txs.map(() => errorResponse);
|
|
168
215
|
}
|
|
169
|
-
|
|
170
|
-
return headers
|
|
171
216
|
}
|
|
172
217
|
}
|
|
173
218
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Broadcaster } from '../Broadcaster.js'
|
|
2
|
-
import ARC from './ARC.js'
|
|
2
|
+
import ARC, { ArcConfig } from './ARC.js'
|
|
3
3
|
|
|
4
|
-
export function defaultBroadcaster (): Broadcaster {
|
|
5
|
-
return new ARC('https://arc.taal.com')
|
|
6
|
-
}
|
|
4
|
+
export function defaultBroadcaster (isTestnet: boolean = false, config: ArcConfig = {}): Broadcaster {
|
|
5
|
+
return new ARC(isTestnet ? 'https://arc-test.taal.com' : 'https://arc.taal.com', config)
|
|
6
|
+
}
|