@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.
Files changed (35) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
  3. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +6 -2
  4. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  5. package/dist/cjs/src/overlay-tools/LookupResolver.js +3 -8
  6. package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
  7. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +44 -6
  8. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  9. package/dist/cjs/src/transaction/Transaction.js +1 -1
  10. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  11. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  12. package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
  13. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +6 -2
  14. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  15. package/dist/esm/src/overlay-tools/LookupResolver.js +3 -8
  16. package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
  17. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +21 -6
  18. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  19. package/dist/esm/src/transaction/Transaction.js +1 -1
  20. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  21. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  22. package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
  23. package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -1
  24. package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
  25. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
  26. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  27. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  28. package/dist/umd/bundle.js +1 -1
  29. package/package.json +1 -1
  30. package/src/auth/clients/AuthFetch.ts +0 -1
  31. package/src/auth/transports/SimplifiedFetchTransport.ts +8 -3
  32. package/src/overlay-tools/LookupResolver.ts +4 -9
  33. package/src/overlay-tools/SHIPBroadcaster.ts +20 -6
  34. package/src/overlay-tools/__tests/SHIPBroadcaster.test.ts +2 -1
  35. package/src/transaction/Transaction.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -240,7 +240,6 @@ export class AuthFetch {
240
240
  reject(e)
241
241
  }
242
242
  }) as Function)
243
-
244
243
  // Check if server requires payment to access the requested route
245
244
  if (response.status === 402) {
246
245
  // Create and attach a payment, then retry
@@ -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 && !response.headers.get('x-bsv-auth-request-id')) {
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
- payloadWriter.write(Utils.toArray(response.headers.get('x-bsv-auth-request-id'), 'base64'))
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 = String(Transaction.fromBEEF(output.beef).id('hex'))
211
-
212
- if (txId !== '') { // ✅ Ensures `txId` is always a non-empty string
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
- 'Content-Type': 'application/octet-stream',
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) {
@@ -253,7 +253,8 @@ describe('SHIPCast', () => {
253
253
  const testTx = {
254
254
  toBEEF: () => {
255
255
  throw new Error('Cannot serialize to BEEF')
256
- }
256
+ },
257
+ metadata: new Map()
257
258
  } as unknown as Transaction
258
259
 
259
260
  await expect(b.broadcast(testTx)).rejects.toThrow(
@@ -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