@bsv/sdk 1.6.1 → 1.6.3
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/clients/AuthFetch.js.map +1 -1
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +6 -2
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/cjs/src/overlay-tools/LookupResolver.js +3 -8
- package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +44 -6
- package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
- package/dist/cjs/src/transaction/Transaction.js +1 -1
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +6 -2
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/esm/src/overlay-tools/LookupResolver.js +3 -8
- package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +21 -6
- package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
- package/dist/esm/src/transaction/Transaction.js +1 -1
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
- package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -1
- package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
- package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/package.json +1 -1
- package/src/auth/clients/AuthFetch.ts +0 -1
- package/src/auth/transports/SimplifiedFetchTransport.ts +8 -3
- package/src/overlay-tools/LookupResolver.ts +4 -9
- package/src/overlay-tools/SHIPBroadcaster.ts +20 -6
- package/src/overlay-tools/__tests/SHIPBroadcaster.test.ts +2 -1
- package/src/transaction/Transaction.ts +1 -1
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ export class SimplifiedFetchTransport implements Transport {
|
|
|
17
17
|
fetchClient: typeof fetch
|
|
18
18
|
baseUrl: string
|
|
19
19
|
|
|
20
|
+
|
|
20
21
|
/**
|
|
21
22
|
* Constructs a new instance of SimplifiedFetchTransport.
|
|
22
23
|
* @param baseUrl - The base URL for all HTTP requests made by this transport.
|
|
@@ -53,11 +54,11 @@ export class SimplifiedFetchTransport implements Transport {
|
|
|
53
54
|
body: JSON.stringify(message)
|
|
54
55
|
})
|
|
55
56
|
|
|
57
|
+
// For initialRequest message, mark connection as established and start pool.
|
|
56
58
|
if (message.messageType !== "initialRequest") {
|
|
57
59
|
resolve()
|
|
58
60
|
}
|
|
59
61
|
const response = await responsePromise
|
|
60
|
-
|
|
61
62
|
// Handle the response if data is received and callback is set
|
|
62
63
|
if (response.ok && this.onDataCallback) {
|
|
63
64
|
const responseMessage = await response.json()
|
|
@@ -126,7 +127,8 @@ export class SimplifiedFetchTransport implements Transport {
|
|
|
126
127
|
})
|
|
127
128
|
|
|
128
129
|
// Check for an acceptable status
|
|
129
|
-
if (response.status === 500 &&
|
|
130
|
+
if (response.status === 500 && (response.headers.get('x-bsv-auth-request-id') == null &&
|
|
131
|
+
response.headers.get('x-bsv-auth-requested-certificates') == null)) {
|
|
130
132
|
// Try parsing JSON error
|
|
131
133
|
const errorInfo = await response.json()
|
|
132
134
|
// Otherwise just throw whatever we got
|
|
@@ -135,7 +137,10 @@ export class SimplifiedFetchTransport implements Transport {
|
|
|
135
137
|
|
|
136
138
|
const parsedBody = await response.arrayBuffer()
|
|
137
139
|
const payloadWriter = new Utils.Writer()
|
|
138
|
-
|
|
140
|
+
if(response.headers.get('x-bsv-auth-request-id') != null)
|
|
141
|
+
{
|
|
142
|
+
payloadWriter.write(Utils.toArray(response.headers.get('x-bsv-auth-request-id'), 'base64'));
|
|
143
|
+
}
|
|
139
144
|
payloadWriter.writeVarIntNum(response.status)
|
|
140
145
|
|
|
141
146
|
// PARSE RESPONSE HEADERS FROM SERVER --------------------------------
|
|
@@ -198,7 +198,7 @@ export default class LookupResolver {
|
|
|
198
198
|
|
|
199
199
|
// Process the successful responses
|
|
200
200
|
// Aggregate outputs from all successful responses
|
|
201
|
-
const outputs = new Map<string, { beef: number[], outputIndex: number }>()
|
|
201
|
+
const outputs = new Map<string, { beef: number[], context?: number[], outputIndex: number }>()
|
|
202
202
|
|
|
203
203
|
for (const response of successfulResponses) {
|
|
204
204
|
if (response.type !== 'output-list') {
|
|
@@ -207,14 +207,9 @@ export default class LookupResolver {
|
|
|
207
207
|
try {
|
|
208
208
|
for (const output of response.outputs) {
|
|
209
209
|
try {
|
|
210
|
-
const txId: string =
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const key = `${String(txId)}.${String(output.outputIndex)}`
|
|
214
|
-
outputs.set(key, output)
|
|
215
|
-
} else {
|
|
216
|
-
console.warn('Invalid transaction ID:', txId)
|
|
217
|
-
}
|
|
210
|
+
const txId: string = Transaction.fromBEEF(output.beef).id('hex') // !! This is STUPIDLY inefficient.
|
|
211
|
+
const key = `${txId}.${output.outputIndex}`
|
|
212
|
+
outputs.set(key, output)
|
|
218
213
|
} catch {
|
|
219
214
|
continue
|
|
220
215
|
}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
BroadcastFailure,
|
|
5
5
|
Broadcaster
|
|
6
6
|
} from '../transaction/index.js'
|
|
7
|
+
import * as Utils from '../primitives/utils.js'
|
|
7
8
|
import LookupResolver from './LookupResolver.js'
|
|
8
9
|
import OverlayAdminTokenTemplate from './OverlayAdminTokenTemplate.js'
|
|
9
10
|
|
|
@@ -92,13 +93,25 @@ export class HTTPSOverlayBroadcastFacilitator implements OverlayBroadcastFacilit
|
|
|
92
93
|
'HTTPS facilitator can only use URLs that start with "https:"'
|
|
93
94
|
)
|
|
94
95
|
}
|
|
96
|
+
const headers = {
|
|
97
|
+
'Content-Type': 'application/octet-stream',
|
|
98
|
+
'X-Topics': JSON.stringify(taggedBEEF.topics)
|
|
99
|
+
}
|
|
100
|
+
let body
|
|
101
|
+
if (Array.isArray(taggedBEEF.offChainValues)) {
|
|
102
|
+
headers['x-includes-off-chain-values'] = 'true'
|
|
103
|
+
const w = new Utils.Writer()
|
|
104
|
+
w.writeVarIntNum(taggedBEEF.beef.length)
|
|
105
|
+
w.write(taggedBEEF.beef)
|
|
106
|
+
w.write(taggedBEEF.offChainValues)
|
|
107
|
+
body = new Uint8Array(w.toArray())
|
|
108
|
+
} else {
|
|
109
|
+
body = new Uint8Array(taggedBEEF.beef)
|
|
110
|
+
}
|
|
95
111
|
const response = await fetch(`${url}/submit`, {
|
|
96
112
|
method: 'POST',
|
|
97
|
-
headers
|
|
98
|
-
|
|
99
|
-
'X-Topics': JSON.stringify(taggedBEEF.topics)
|
|
100
|
-
},
|
|
101
|
-
body: new Uint8Array(taggedBEEF.beef)
|
|
113
|
+
headers,
|
|
114
|
+
body
|
|
102
115
|
})
|
|
103
116
|
if (response.ok) {
|
|
104
117
|
return await response.json()
|
|
@@ -154,8 +167,8 @@ export default class TopicBroadcaster implements Broadcaster {
|
|
|
154
167
|
async broadcast (
|
|
155
168
|
tx: Transaction
|
|
156
169
|
): Promise<BroadcastResponse | BroadcastFailure> {
|
|
157
|
-
console.log(tx)
|
|
158
170
|
let beef: number[]
|
|
171
|
+
const offChainValues = tx.metadata.get('OffChainValues') as number[]
|
|
159
172
|
try {
|
|
160
173
|
beef = tx.toBEEF()
|
|
161
174
|
} catch (error) {
|
|
@@ -176,6 +189,7 @@ export default class TopicBroadcaster implements Broadcaster {
|
|
|
176
189
|
try {
|
|
177
190
|
const steak = await this.facilitator.send(host, {
|
|
178
191
|
beef,
|
|
192
|
+
offChainValues,
|
|
179
193
|
topics: [...topics]
|
|
180
194
|
})
|
|
181
195
|
if (steak == null || Object.keys(steak).length === 0) {
|
|
@@ -318,7 +318,7 @@ export default class Transaction {
|
|
|
318
318
|
inputs: TransactionInput[] = [],
|
|
319
319
|
outputs: TransactionOutput[] = [],
|
|
320
320
|
lockTime: number = 0,
|
|
321
|
-
metadata: Record<string, any> =
|
|
321
|
+
metadata: Record<string, any> = new Map(),
|
|
322
322
|
merklePath?: MerklePath
|
|
323
323
|
) {
|
|
324
324
|
this.version = version
|