@bsv/sdk 1.6.1 → 1.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -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