@bsv/sdk 1.4.9 → 1.4.11

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/docs/README.md CHANGED
@@ -7,13 +7,15 @@ The documentation is split into various pages, each covering a set of related fu
7
7
  - [Transaction](./transaction.md) — Covers transaction construction, signing, broadcasters, fee models, merkle proofs, and SPV structures like BUMP
8
8
  - [Messages](./messages.md) — Covers generalizable message signing, verification, encryption and decryption
9
9
  - [TOTP](./totp.md) - Covers Time-based One Time Password, useful for validating counterparties across unsecured mediums.
10
- - [Wallet](./wallet-substrates.md) - Covers the Wallet Substrates for communication between applications and wallets using a standard interface.
10
+ - [Wallet](./wallet.md) - Covers the Wallet interface for communication between applications and wallets using a standard interface.
11
+ - [Wallet Substrates](./wallet-substrates.md) - Covers the Wallet Substrates which facilitate communication between apps and wallets.
11
12
  - [Overlay Tools](./overlay-tools.md) - Covers the use of Overlays for broadcast of transactions based on topics, as well as distributed lookup of tokens.
12
13
  - [Auth](./auth.md) - Mutual Authentication and Service Monetization Framework
14
+ - [Storage](./storage.md) — Covers a UHRP client for storing and retrieving data from distributed data storage services by hash.
13
15
  - [Compat](./compat.md) — Covers deprecated functionality for legacy systems like BIP32 and ECIES
14
16
 
15
17
  ## Swagger
16
18
 
17
19
  [BRC-100](https://brc.dev/100) defines a Unified, Vendor-Neutral, Unchanging, and Open BSV Blockchain Standard Wallet-to-Application Interface which is implemented in this library within the WalletClient class. The API is laid out here as a swagger openapi document to offer a fast-track to understanding the interface which is implemented across multiple substrates. The JSON api is generally considered a developer friendly introduction to the WalletClient, where an binary equivalent ABI may be preferred for production use cases.
18
20
 
19
- - [Wallet JSON API Swagger](./swagger)
21
+ - [Wallet JSON API Swagger](./swagger)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -349,22 +349,30 @@ 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
- if (k.startsWith('x-bsv-') || k === 'content-type' || k === 'authorization') {
359
+ if (k.startsWith('x-bsv-') || k === 'authorization') {
359
360
  if (k.startsWith('x-bsv-auth')) {
360
361
  throw new Error('No BSV auth headers allowed here!')
361
362
  }
362
363
  includedHeaders.push([k, v])
364
+ } else if (k.startsWith('content-type')) {
365
+ // Normalize the Content-Type header by removing any parameters (e.g., "; charset=utf-8")
366
+ v = v.split(';')[0].trim()
367
+ includedHeaders.push([k, v])
363
368
  } else {
364
369
  throw new Error('Unsupported header in the simplified fetch implementation. Only content-type, authorization, and x-bsv-* headers are supported.')
365
370
  }
366
371
  }
367
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
+
368
376
  // nHeaders
369
377
  writer.writeVarIntNum(includedHeaders.length)
370
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)