@bsv/sdk 1.3.26 → 1.3.28

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/auth.md CHANGED
@@ -1139,10 +1139,10 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
1139
1139
  Creates a nonce derived from a wallet
1140
1140
 
1141
1141
  ```ts
1142
- export async function createNonce(wallet: WalletInterface, counterparty: WalletCounterparty = "self"): Promise<string>
1142
+ export async function createNonce(wallet: WalletInterface, counterparty: WalletCounterparty = "self"): Promise<Base64String>
1143
1143
  ```
1144
1144
 
1145
- See also: [WalletCounterparty](./wallet.md#type-walletcounterparty), [WalletInterface](./wallet.md#interface-walletinterface)
1145
+ See also: [Base64String](./wallet.md#type-base64string), [WalletCounterparty](./wallet.md#type-walletcounterparty), [WalletInterface](./wallet.md#interface-walletinterface)
1146
1146
 
1147
1147
  Returns
1148
1148
 
@@ -1161,10 +1161,10 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
1161
1161
  Verifies a nonce derived from a wallet
1162
1162
 
1163
1163
  ```ts
1164
- export async function verifyNonce(nonce: string, wallet: WalletInterface, counterparty: WalletCounterparty = "self"): Promise<boolean>
1164
+ export async function verifyNonce(nonce: Base64String, wallet: WalletInterface, counterparty: WalletCounterparty = "self"): Promise<boolean>
1165
1165
  ```
1166
1166
 
1167
- See also: [WalletCounterparty](./wallet.md#type-walletcounterparty), [WalletInterface](./wallet.md#interface-walletinterface)
1167
+ See also: [Base64String](./wallet.md#type-base64string), [WalletCounterparty](./wallet.md#type-walletcounterparty), [WalletInterface](./wallet.md#interface-walletinterface)
1168
1168
 
1169
1169
  Returns
1170
1170
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.3.26",
3
+ "version": "1.3.28",
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
@@ -392,7 +405,7 @@ export class AuthFetch {
392
405
  }
393
406
 
394
407
  const derivationPrefix = originalResponse.headers.get('x-bsv-payment-derivation-prefix')
395
- if (!derivationPrefix) {
408
+ if (typeof derivationPrefix !== 'string' || derivationPrefix.length < 1) {
396
409
  throw new Error('Missing x-bsv-payment-derivation-prefix response header.')
397
410
  }
398
411
 
@@ -413,8 +426,12 @@ export class AuthFetch {
413
426
  outputs: [{
414
427
  satoshis: satoshisRequired,
415
428
  lockingScript,
429
+ customInstructions: JSON.stringify({ derivationPrefix, derivationSuffix, payee: serverIdentityKey }),
416
430
  outputDescription: 'HTTP request payment'
417
- }]
431
+ }],
432
+ options: {
433
+ randomizeOutputs: false
434
+ }
418
435
  })
419
436
 
420
437
  // Attach the payment to the request headers
@@ -431,11 +448,16 @@ export class AuthFetch {
431
448
  }
432
449
 
433
450
  private async normalizeBodyToNumberArray(body: BodyInit | null | undefined): Promise<number[]> {
434
- // 1. Null / undefined
451
+ // 0. Null / undefined
435
452
  if (body == null) {
436
453
  return []
437
454
  }
438
455
 
456
+ // 1. object
457
+ if (typeof body === 'object') {
458
+ return Utils.toArray(JSON.stringify(body, 'utf8'))
459
+ }
460
+
439
461
  // 2. number[]
440
462
  if (Array.isArray(body) && body.every((item) => typeof item === 'number')) {
441
463
  return body // Return the array as is