@bsv/sdk 1.4.10 → 1.4.12

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.4.10",
3
+ "version": "1.4.12",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -349,10 +349,11 @@ export class AuthFetch {
349
349
  }
350
350
 
351
351
  // Construct headers to send / sign:
352
- // - Custom headers prefixed with x-bsv are included
353
- // - x-bsv-auth headers are not allowed
354
- // - content-type and authorization are signed by client
355
- const includedHeaders: [string, string][] = []
352
+ // Ensures clients only provided supported HTTP request headers
353
+ // - Include custom headers prefixed with x-bsv (excluding those starting with x-bsv-auth)
354
+ // - Include a normalized version of the content-type header
355
+ // - Include the authorization header
356
+ const includedHeaders: Array<[string, string]> = []
356
357
  for (let [k, v] of Object.entries(headers)) {
357
358
  k = k.toLowerCase() // We will always sign lower-case header keys
358
359
  if (k.startsWith('x-bsv-') || k === 'authorization') {
@@ -362,13 +363,16 @@ export class AuthFetch {
362
363
  includedHeaders.push([k, v])
363
364
  } else if (k.startsWith('content-type')) {
364
365
  // Normalize the Content-Type header by removing any parameters (e.g., "; charset=utf-8")
365
- v = (v as string).split(';')[0].trim()
366
+ v = v.split(';')[0].trim()
366
367
  includedHeaders.push([k, v])
367
368
  } else {
368
369
  throw new Error('Unsupported header in the simplified fetch implementation. Only content-type, authorization, and x-bsv-* headers are supported.')
369
370
  }
370
371
  }
371
372
 
373
+ // Sort the headers by key to ensure a consistent order for signing and verification.
374
+ includedHeaders.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
375
+
372
376
  // nHeaders
373
377
  writer.writeVarIntNum(includedHeaders.length)
374
378
  for (let i = 0; i < includedHeaders.length; i++) {
@@ -152,25 +152,20 @@ export class SimplifiedFetchTransport implements Transport {
152
152
  payloadWriter.write(Utils.toArray(response.headers.get('x-bsv-auth-request-id'), 'base64'))
153
153
  payloadWriter.writeVarIntNum(response.status)
154
154
 
155
- // Filter out headers the server signed:
156
- // - Custom headers prefixed with x-bsv are included, except auth
157
- // - x-bsv-auth headers are not allowed
158
- // - authorization header is signed by the server
155
+ // PARSE RESPONSE HEADERS FROM SERVER --------------------------------
156
+ // Parse response headers from the server and include only the signed headers:
157
+ // - Include custom headers prefixed with x-bsv (excluding those starting with x-bsv-auth)
158
+ // - Include the authorization header
159
159
  const includedHeaders: [string, string][] = []
160
- // Collect headers into a raw array for sorting
161
- const headersArray: [string, string][] = []
162
160
  response.headers.forEach((value, key) => {
163
161
  const lowerKey = key.toLowerCase()
164
- if (lowerKey.startsWith('x-bsv-') || lowerKey === 'authorization') {
165
- if (!lowerKey.startsWith('x-bsv-auth')) {
166
- headersArray.push([lowerKey, value])
167
- }
162
+ if ((lowerKey.startsWith('x-bsv-') || lowerKey === 'authorization') && !lowerKey.startsWith('x-bsv-auth')) {
163
+ includedHeaders.push([lowerKey, value])
168
164
  }
169
165
  })
170
166
 
171
- // Sort headers explicitly to match server-side order
172
- headersArray.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
173
- includedHeaders.push(...headersArray)
167
+ // Sort the headers by key to ensure a consistent order for signing and verification.
168
+ includedHeaders.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
174
169
 
175
170
  // nHeaders
176
171
  payloadWriter.writeVarIntNum(includedHeaders.length)
@@ -199,6 +199,12 @@ export class RegistryClient {
199
199
  throw new Error('Invalid registry record. Missing txid, outputIndex, or lockingScript.')
200
200
  }
201
201
 
202
+ // Check if the registry record belongs to the current user
203
+ const currentIdentityKey = (await this.wallet.getPublicKey({ identityKey: true })).publicKey
204
+ if (registryRecord.registryOperator !== currentIdentityKey) {
205
+ throw new Error('This registry token does not belong to the current wallet.')
206
+ }
207
+
202
208
  // Create a descriptive label for the item we’re revoking
203
209
  const itemIdentifier =
204
210
  registryRecord.definitionType === 'basket'
@@ -421,12 +427,6 @@ export class RegistryClient {
421
427
  throw new Error(`Unsupported definition type: ${definitionType as string}`)
422
428
  }
423
429
 
424
- // Enforce that the pushdrop belongs to the CURRENT identity key
425
- const currentIdentityKey = (await this.wallet.getPublicKey({ identityKey: true })).publicKey
426
- if (registryOperator !== currentIdentityKey) {
427
- throw new Error('This registry token does not belong to the current wallet.')
428
- }
429
-
430
430
  // Return the typed data plus the operator key
431
431
  return { ...parsedData, registryOperator }
432
432
  }