@bsv/sdk 1.3.26 → 1.3.27

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.3.26",
3
+ "version": "1.3.27",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -329,6 +329,19 @@ export class AuthFetch {
329
329
  writer.write(headerValueAsArray)
330
330
  }
331
331
 
332
+ // If method typically carries a body and body is undefined, default it
333
+ // This prevents signature verification errors due to mismatch default body types with express
334
+ const methodsThatTypicallyHaveBody = ['POST', 'PUT', 'PATCH', 'DELETE']
335
+ if (methodsThatTypicallyHaveBody.includes(method.toUpperCase()) && body === undefined) {
336
+ // Check if content-type is application/json
337
+ const contentTypeHeader = includedHeaders.find(([k]) => k === 'content-type')
338
+ if (contentTypeHeader && contentTypeHeader[1].includes('application/json')) {
339
+ body = '{}'
340
+ } else {
341
+ body = ''
342
+ }
343
+ }
344
+
332
345
  // Handle body
333
346
  if (body) {
334
347
  const reqBody = await this.normalizeBodyToNumberArray(body) // Use the utility function
@@ -431,11 +444,16 @@ export class AuthFetch {
431
444
  }
432
445
 
433
446
  private async normalizeBodyToNumberArray(body: BodyInit | null | undefined): Promise<number[]> {
434
- // 1. Null / undefined
447
+ // 0. Null / undefined
435
448
  if (body == null) {
436
449
  return []
437
450
  }
438
451
 
452
+ // 1. object
453
+ if (typeof body === 'object') {
454
+ return Utils.toArray(JSON.stringify(body, 'utf8'))
455
+ }
456
+
439
457
  // 2. number[]
440
458
  if (Array.isArray(body) && body.every((item) => typeof item === 'number')) {
441
459
  return body // Return the array as is