@bsv/sdk 1.4.12 → 1.4.15

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.
Files changed (34) hide show
  1. package/dist/cjs/package.json +3 -1
  2. package/dist/cjs/src/auth/clients/AuthFetch.js +2 -0
  3. package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
  4. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +2 -15
  5. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  6. package/dist/cjs/src/primitives/index.js +3 -1
  7. package/dist/cjs/src/primitives/index.js.map +1 -1
  8. package/dist/cjs/src/transaction/Transaction.js +2 -2
  9. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  10. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  11. package/dist/esm/src/auth/clients/AuthFetch.js +2 -0
  12. package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
  13. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +2 -15
  14. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  15. package/dist/esm/src/primitives/index.js +1 -0
  16. package/dist/esm/src/primitives/index.js.map +1 -1
  17. package/dist/esm/src/transaction/Transaction.js +2 -2
  18. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  19. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  20. package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
  21. package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -1
  22. package/dist/types/src/primitives/index.d.ts +1 -0
  23. package/dist/types/src/primitives/index.d.ts.map +1 -1
  24. package/dist/types/src/transaction/Transaction.d.ts +1 -1
  25. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  26. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  27. package/dist/umd/bundle.js +1 -1
  28. package/package.json +3 -1
  29. package/src/auth/clients/AuthFetch.ts +2 -0
  30. package/src/auth/transports/SimplifiedFetchTransport.ts +2 -16
  31. package/src/primitives/__tests/ECDH.test.ts +2 -2
  32. package/src/primitives/index.ts +1 -0
  33. package/src/transaction/Transaction.ts +2 -2
  34. package/src/transaction/__tests/Transaction.test.ts +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.4.12",
3
+ "version": "1.4.15",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -230,7 +230,9 @@
230
230
  "homepage": "https://github.com/bitcoin-sv/ts-sdk#readme",
231
231
  "devDependencies": {
232
232
  "@eslint/js": "^9.19.0",
233
+ "@jest/globals": "^29.7.0",
233
234
  "@types/jest": "^29.5.14",
235
+ "@types/node": "^22.13.14",
234
236
  "eslint": "^8.57.1",
235
237
  "globals": "^15.14.0",
236
238
  "jest": "^29.7.0",
@@ -222,11 +222,13 @@ export class AuthFetch {
222
222
  config.retryCounter ??= 3
223
223
  const response = await this.fetch(url, config)
224
224
  resolve(response)
225
+ return
225
226
  }
226
227
  if (error.message.includes('HTTP server failed to authenticate')) {
227
228
  try {
228
229
  const response = await this.handleFetchAndValidate(url, config, peerToUse)
229
230
  resolve(response)
231
+ return
230
232
  } catch (fetchError) {
231
233
  reject(fetchError)
232
234
  }
@@ -126,23 +126,9 @@ export class SimplifiedFetchTransport implements Transport {
126
126
  })
127
127
 
128
128
  // Check for an acceptable status
129
- if (!SUCCESS_STATUS_CODES.includes(response.status)) {
129
+ if (response.status === 500 && !response.headers.get('x-bsv-auth-request-id')) {
130
130
  // Try parsing JSON error
131
- let errorInfo;
132
- try {
133
- errorInfo = await response.json();
134
- } catch {
135
- // Fallback to text if JSON parse fails
136
- const text = await response.text().catch(() => '');
137
- throw new Error(`HTTP ${response.status} - ${text || 'Unknown error'}`);
138
- }
139
-
140
- // If we find a known { status: 'error', code, description } structure
141
- if (errorInfo?.status === 'error' && typeof errorInfo.description === 'string') {
142
- const msg = `HTTP ${response.status} - ${errorInfo.description}`;
143
- throw new Error(errorInfo.code ? `${msg} (code: ${errorInfo.code})` : msg);
144
- }
145
-
131
+ const errorInfo = await response.json()
146
132
  // Otherwise just throw whatever we got
147
133
  throw new Error(`HTTP ${response.status} - ${JSON.stringify(errorInfo)}`);
148
134
  }
@@ -12,12 +12,12 @@ describe('ECDH', function () {
12
12
  expect(sh1.toString()).toEqual(sh2.toString())
13
13
  sh1 = s1.deriveSharedSecret(
14
14
  PublicKey.fromString(
15
- Buffer.from(s2.toPublicKey().toDER()).toString('hex')
15
+ s2.toPublicKey().toDER('hex') as string
16
16
  )
17
17
  )
18
18
  sh2 = s2.deriveSharedSecret(
19
19
  PublicKey.fromString(
20
- Buffer.from(s1.toPublicKey().toDER()).toString('hex')
20
+ s1.toPublicKey().toDER('hex') as string
21
21
  )
22
22
  )
23
23
 
@@ -5,6 +5,7 @@ export { default as PublicKey } from './PublicKey.js'
5
5
  export { default as Signature } from './Signature.js'
6
6
  export { default as PrivateKey, KeyShares } from './PrivateKey.js'
7
7
  export { default as SymmetricKey } from './SymmetricKey.js'
8
+ export { default as DRBG } from './DRBG.js'
8
9
  export * as ECDSA from './ECDSA.js'
9
10
  export * as Utils from './utils.js'
10
11
  export * as Hash from './Hash.js'
@@ -403,7 +403,7 @@ export default class Transaction {
403
403
 
404
404
  /**
405
405
  * Computes fees prior to signing.
406
- * If no fee model is provided, uses a SatoshisPerKilobyte fee model that pays 10 sat/kb.
406
+ * If no fee model is provided, uses a SatoshisPerKilobyte fee model that pays 1 sat/kb.
407
407
  * If fee is a number, the transaction uses that value as fee.
408
408
  *
409
409
  * @param modelOrFee - The initialized fee model to use or fixed fee for the transaction
@@ -412,7 +412,7 @@ export default class Transaction {
412
412
  *
413
413
  */
414
414
  async fee (
415
- modelOrFee: FeeModel | number = new SatoshisPerKilobyte(10),
415
+ modelOrFee: FeeModel | number = new SatoshisPerKilobyte(1),
416
416
  changeDistribution: 'equal' | 'random' = 'equal'
417
417
  ): Promise<void> {
418
418
  this.cachedHash = undefined
@@ -348,9 +348,9 @@ describe('Transaction', () => {
348
348
  expect(spendTx.outputs[1].satoshis).not.toBeDefined()
349
349
  await spendTx.fee()
350
350
  // Transaction size is 225 bytes for one-input two-output P2PKH.
351
- // Default fee rate is 10 sat/kb = 2.25 sats (round up to 3).
352
- // 4000 sats in - 1000 sats out - 3 sats fee = expected 2997 sats change.
353
- expect(spendTx.outputs[1].satoshis).toEqual(2997)
351
+ // Default fee rate is 1 sat/kb = 0.225 sats (round up to 1).
352
+ // 4000 sats in - 1000 sats out - 3 sats fee = expected 2999 sats change.
353
+ expect(spendTx.outputs[1].satoshis).toEqual(2999)
354
354
  })
355
355
  it('Computes fees with a custom fee model', async () => {
356
356
  const privateKey = new PrivateKey(1)