@bsv/sdk 2.0.13 → 2.0.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 (127) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/package.json +14 -14
  3. package/dist/cjs/src/identity/IdentityClient.js +3 -3
  4. package/dist/cjs/src/identity/IdentityClient.js.map +1 -1
  5. package/dist/cjs/src/identity/types/index.js +1 -1
  6. package/dist/cjs/src/identity/types/index.js.map +1 -1
  7. package/dist/cjs/src/primitives/Hash.js +1 -1
  8. package/dist/cjs/src/primitives/Hash.js.map +1 -1
  9. package/dist/cjs/src/primitives/TransactionSignature.js +10 -3
  10. package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -1
  11. package/dist/cjs/src/script/Script.js +60 -13
  12. package/dist/cjs/src/script/Script.js.map +1 -1
  13. package/dist/cjs/src/script/Spend.js +434 -59
  14. package/dist/cjs/src/script/Spend.js.map +1 -1
  15. package/dist/cjs/src/storage/StorageUploader.js +315 -96
  16. package/dist/cjs/src/storage/StorageUploader.js.map +1 -1
  17. package/dist/cjs/src/storage/index.js +3 -1
  18. package/dist/cjs/src/storage/index.js.map +1 -1
  19. package/dist/cjs/src/transaction/http/BinaryFetchClient.js +6 -2
  20. package/dist/cjs/src/transaction/http/BinaryFetchClient.js.map +1 -1
  21. package/dist/cjs/src/transaction/http/DefaultHttpClient.js +8 -4
  22. package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
  23. package/dist/cjs/src/wallet/WERR_REVIEW_ACTIONS.js +2 -2
  24. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  25. package/dist/esm/src/identity/IdentityClient.js +3 -3
  26. package/dist/esm/src/identity/IdentityClient.js.map +1 -1
  27. package/dist/esm/src/identity/types/index.js +1 -1
  28. package/dist/esm/src/identity/types/index.js.map +1 -1
  29. package/dist/esm/src/primitives/Hash.js +1 -1
  30. package/dist/esm/src/primitives/Hash.js.map +1 -1
  31. package/dist/esm/src/primitives/TransactionSignature.js +10 -3
  32. package/dist/esm/src/primitives/TransactionSignature.js.map +1 -1
  33. package/dist/esm/src/script/Script.js +60 -13
  34. package/dist/esm/src/script/Script.js.map +1 -1
  35. package/dist/esm/src/script/Spend.js +438 -59
  36. package/dist/esm/src/script/Spend.js.map +1 -1
  37. package/dist/esm/src/storage/StorageUploader.js +319 -95
  38. package/dist/esm/src/storage/StorageUploader.js.map +1 -1
  39. package/dist/esm/src/storage/index.js +1 -1
  40. package/dist/esm/src/storage/index.js.map +1 -1
  41. package/dist/esm/src/transaction/http/BinaryFetchClient.js +6 -2
  42. package/dist/esm/src/transaction/http/BinaryFetchClient.js.map +1 -1
  43. package/dist/esm/src/transaction/http/DefaultHttpClient.js +8 -4
  44. package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
  45. package/dist/esm/src/wallet/WERR_REVIEW_ACTIONS.js +2 -2
  46. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  47. package/dist/types/src/primitives/TransactionSignature.d.ts +1 -0
  48. package/dist/types/src/primitives/TransactionSignature.d.ts.map +1 -1
  49. package/dist/types/src/script/Script.d.ts +1 -0
  50. package/dist/types/src/script/Script.d.ts.map +1 -1
  51. package/dist/types/src/script/ScriptChunk.d.ts +1 -0
  52. package/dist/types/src/script/ScriptChunk.d.ts.map +1 -1
  53. package/dist/types/src/script/Spend.d.ts +29 -0
  54. package/dist/types/src/script/Spend.d.ts.map +1 -1
  55. package/dist/types/src/storage/StorageUploader.d.ts +94 -55
  56. package/dist/types/src/storage/StorageUploader.d.ts.map +1 -1
  57. package/dist/types/src/storage/index.d.ts +1 -1
  58. package/dist/types/src/storage/index.d.ts.map +1 -1
  59. package/dist/types/src/transaction/http/BinaryFetchClient.d.ts.map +1 -1
  60. package/dist/types/src/transaction/http/DefaultHttpClient.d.ts +2 -2
  61. package/dist/types/src/transaction/http/DefaultHttpClient.d.ts.map +1 -1
  62. package/dist/types/src/wallet/WERR_REVIEW_ACTIONS.d.ts +2 -2
  63. package/dist/types/src/wallet/Wallet.interfaces.d.ts +2 -2
  64. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  65. package/dist/umd/bundle.js +4 -5
  66. package/docs/index.md +3 -1
  67. package/docs/reference/identity.md +1 -1
  68. package/docs/reference/primitives.md +1 -0
  69. package/docs/reference/script.md +7 -0
  70. package/docs/reference/storage.md +214 -85
  71. package/docs/reference/transaction.md +4 -4
  72. package/docs/reference/wallet.md +4 -4
  73. package/package.json +14 -14
  74. package/src/identity/IdentityClient.ts +3 -3
  75. package/src/identity/__tests/IdentityClient.additional.test.ts +3 -3
  76. package/src/identity/types/index.ts +1 -1
  77. package/src/primitives/Hash.ts +1 -1
  78. package/src/primitives/TransactionSignature.ts +11 -3
  79. package/src/script/Script.ts +59 -13
  80. package/src/script/ScriptChunk.ts +1 -0
  81. package/src/script/Spend.ts +483 -61
  82. package/src/script/__tests/NormativeVectors.test.ts +465 -0
  83. package/src/script/__tests/fixtures/SOURCES.md +25 -0
  84. package/src/script/__tests/fixtures/bitcoin-sv/script_tests.json +2591 -0
  85. package/src/script/__tests/fixtures/bitcoin-sv/sighash.json +1003 -0
  86. package/src/script/__tests/fixtures/bitcoin-sv/tx_invalid.json +285 -0
  87. package/src/script/__tests/fixtures/bitcoin-sv/tx_valid.json +367 -0
  88. package/src/script/__tests/fixtures/teranode/script_tests.json +2432 -0
  89. package/src/script/__tests/fixtures/teranode/sighash.json +1003 -0
  90. package/src/script/__tests/fixtures/teranode/tx_invalid.json +285 -0
  91. package/src/script/__tests/fixtures/teranode/tx_valid.json +367 -0
  92. package/src/storage/StorageUploader.ts +427 -105
  93. package/src/storage/__tests/StorageUploader.test.ts +881 -64
  94. package/src/storage/index.ts +1 -1
  95. package/src/transaction/broadcasters/__tests/ARC.test.ts +26 -4
  96. package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +26 -4
  97. package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +32 -10
  98. package/src/transaction/http/BinaryFetchClient.ts +5 -2
  99. package/src/transaction/http/DefaultHttpClient.ts +7 -4
  100. package/src/transaction/http/__tests/DefaultHttpClient.additional.test.ts +19 -1
  101. package/src/wallet/WERR_REVIEW_ACTIONS.ts +2 -2
  102. package/src/wallet/Wallet.interfaces.ts +2 -2
  103. package/dist/cjs/src/auth/clients/__tests__/AuthFetch.additional.test.js +0 -827
  104. package/dist/cjs/src/auth/clients/__tests__/AuthFetch.additional.test.js.map +0 -1
  105. package/dist/cjs/src/auth/clients/__tests__/AuthFetch.test.js +0 -266
  106. package/dist/cjs/src/auth/clients/__tests__/AuthFetch.test.js.map +0 -1
  107. package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js +0 -654
  108. package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js.map +0 -1
  109. package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.test.js +0 -144
  110. package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.test.js.map +0 -1
  111. package/dist/esm/src/auth/clients/__tests__/AuthFetch.additional.test.js +0 -825
  112. package/dist/esm/src/auth/clients/__tests__/AuthFetch.additional.test.js.map +0 -1
  113. package/dist/esm/src/auth/clients/__tests__/AuthFetch.test.js +0 -264
  114. package/dist/esm/src/auth/clients/__tests__/AuthFetch.test.js.map +0 -1
  115. package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js +0 -619
  116. package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js.map +0 -1
  117. package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.test.js +0 -109
  118. package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.test.js.map +0 -1
  119. package/dist/types/src/auth/clients/__tests__/AuthFetch.additional.test.d.ts +0 -21
  120. package/dist/types/src/auth/clients/__tests__/AuthFetch.additional.test.d.ts.map +0 -1
  121. package/dist/types/src/auth/clients/__tests__/AuthFetch.test.d.ts +0 -2
  122. package/dist/types/src/auth/clients/__tests__/AuthFetch.test.d.ts.map +0 -1
  123. package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.d.ts +0 -2
  124. package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.d.ts.map +0 -1
  125. package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.test.d.ts +0 -2
  126. package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.test.d.ts.map +0 -1
  127. package/dist/umd/bundle.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  export * as StorageUtils from './StorageUtils.js'
2
2
 
3
- export { StorageUploader } from './StorageUploader.js'
3
+ export { StorageUploader, DEFAULT_UHRP_SERVERS, RenewResiliencyError } from './StorageUploader.js'
4
4
 
5
5
  export { StorageDownloader } from './StorageDownloader.js'
@@ -36,13 +36,33 @@ describe('ARC Broadcaster', () => {
36
36
  transaction = new Transaction()
37
37
  })
38
38
 
39
+ async function withoutGlobalFetch<T> (callback: () => Promise<T>): Promise<T> {
40
+ const originalFetchDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'fetch')
41
+ Object.defineProperty(globalThis, 'fetch', {
42
+ configurable: true,
43
+ writable: true,
44
+ value: undefined
45
+ })
46
+ try {
47
+ return await callback()
48
+ } finally {
49
+ if (originalFetchDescriptor !== undefined) {
50
+ Object.defineProperty(globalThis, 'fetch', originalFetchDescriptor)
51
+ } else {
52
+ delete (globalThis as { fetch?: unknown }).fetch
53
+ }
54
+ }
55
+ }
56
+
39
57
  it('should broadcast successfully using window.fetch', async () => {
40
58
  // Mocking window.fetch
41
59
  const mockFetch = mockedFetch(successResponse)
42
60
  global.window = { fetch: mockFetch } as unknown as Window & typeof globalThis
43
61
 
44
- const broadcaster = new ARC(URL)
45
- const response = await broadcaster.broadcast(transaction)
62
+ const response = await withoutGlobalFetch(async () => {
63
+ const broadcaster = new ARC(URL)
64
+ return await broadcaster.broadcast(transaction)
65
+ })
46
66
 
47
67
  expect(mockFetch).toHaveBeenCalled()
48
68
  expect(response).toEqual({
@@ -59,8 +79,10 @@ describe('ARC Broadcaster', () => {
59
79
  delete (globalThis as { window?: unknown }).window // ✅ Explicit property check
60
80
  }
61
81
 
62
- const broadcaster = new ARC(URL)
63
- const response = await broadcaster.broadcast(transaction)
82
+ const response = await withoutGlobalFetch(async () => {
83
+ const broadcaster = new ARC(URL)
84
+ return await broadcaster.broadcast(transaction)
85
+ })
64
86
 
65
87
  expect(response).toEqual({
66
88
  status: 'success',
@@ -30,13 +30,33 @@ describe('WhatsOnChainBroadcaster', () => {
30
30
  transaction = new Transaction()
31
31
  })
32
32
 
33
+ async function withoutGlobalFetch<T> (callback: () => Promise<T>): Promise<T> {
34
+ const originalFetchDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'fetch')
35
+ Object.defineProperty(globalThis, 'fetch', {
36
+ configurable: true,
37
+ writable: true,
38
+ value: undefined
39
+ })
40
+ try {
41
+ return await callback()
42
+ } finally {
43
+ if (originalFetchDescriptor !== undefined) {
44
+ Object.defineProperty(globalThis, 'fetch', originalFetchDescriptor)
45
+ } else {
46
+ delete (globalThis as { fetch?: unknown }).fetch
47
+ }
48
+ }
49
+ }
50
+
33
51
  it('should broadcast successfully using window.fetch', async () => {
34
52
  // Mocking window.fetch
35
53
  const mockFetch = mockedFetch(successResponse)
36
54
  global.window = { fetch: mockFetch } as any
37
55
 
38
- const broadcaster = new WhatsOnChainBroadcaster(network)
39
- const response = await broadcaster.broadcast(transaction)
56
+ const response = await withoutGlobalFetch(async () => {
57
+ const broadcaster = new WhatsOnChainBroadcaster(network)
58
+ return await broadcaster.broadcast(transaction)
59
+ })
40
60
 
41
61
  expect(mockFetch).toHaveBeenCalled()
42
62
  expect(response).toEqual({
@@ -51,8 +71,10 @@ describe('WhatsOnChainBroadcaster', () => {
51
71
  mockedHttps(successResponse)
52
72
  global.window = {} as any
53
73
 
54
- const broadcaster = new WhatsOnChainBroadcaster(network)
55
- const response = await broadcaster.broadcast(transaction)
74
+ const response = await withoutGlobalFetch(async () => {
75
+ const broadcaster = new WhatsOnChainBroadcaster(network)
76
+ return await broadcaster.broadcast(transaction)
77
+ })
56
78
 
57
79
  expect(response).toEqual({
58
80
  status: 'success',
@@ -14,16 +14,36 @@ describe('WhatsOnChain ChainTracker', () => {
14
14
  }
15
15
  }
16
16
 
17
+ async function withoutGlobalFetch<T> (callback: () => Promise<T>): Promise<T> {
18
+ const originalFetchDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'fetch')
19
+ Object.defineProperty(globalThis, 'fetch', {
20
+ configurable: true,
21
+ writable: true,
22
+ value: undefined
23
+ })
24
+ try {
25
+ return await callback()
26
+ } finally {
27
+ if (originalFetchDescriptor !== undefined) {
28
+ Object.defineProperty(globalThis, 'fetch', originalFetchDescriptor)
29
+ } else {
30
+ delete (globalThis as { fetch?: unknown }).fetch
31
+ }
32
+ }
33
+ }
34
+
17
35
  it('should verify merkleroot successfully using window.fetch', async () => {
18
36
  // Mocking window.fetch
19
37
  const mockFetch = mockedFetch(successResponse)
20
38
  global.window = { fetch: mockFetch } as any
21
39
 
22
- const chainTracker = new WhatsOnChain(network)
23
- const response = await chainTracker.isValidRootForHeight(
24
- merkleroot,
25
- height
26
- )
40
+ const response = await withoutGlobalFetch(async () => {
41
+ const chainTracker = new WhatsOnChain(network)
42
+ return await chainTracker.isValidRootForHeight(
43
+ merkleroot,
44
+ height
45
+ )
46
+ })
27
47
 
28
48
  expect(mockFetch).toHaveBeenCalled()
29
49
  expect(response).toEqual(true)
@@ -34,11 +54,13 @@ describe('WhatsOnChain ChainTracker', () => {
34
54
  mockedHttps(successResponse)
35
55
  if (typeof global.window !== 'undefined') global.window = {} as any
36
56
 
37
- const chainTracker = new WhatsOnChain(network)
38
- const response = await chainTracker.isValidRootForHeight(
39
- merkleroot,
40
- height
41
- )
57
+ const response = await withoutGlobalFetch(async () => {
58
+ const chainTracker = new WhatsOnChain(network)
59
+ return await chainTracker.isValidRootForHeight(
60
+ merkleroot,
61
+ height
62
+ )
63
+ })
42
64
 
43
65
  expect(response).toEqual(true)
44
66
  })
@@ -99,10 +99,13 @@ export function binaryHttpClient(): HttpClient {
99
99
  }
100
100
 
101
101
  if (typeof window !== 'undefined' && typeof window.fetch === 'function') {
102
- // Use fetch in a browser environment
102
+ // Browser tab/page context
103
103
  return new BinaryFetchClient(window.fetch.bind(window))
104
+ } else if (typeof globalThis.fetch === 'function') {
105
+ // Service workers, Deno, Node 18+ (any environment with global fetch)
106
+ return new BinaryFetchClient(globalThis.fetch.bind(globalThis))
104
107
  } else if (typeof require !== 'undefined') {
105
- // Use Node https module
108
+ // Older Node.js — use https module
106
109
  // eslint-disable-next-line
107
110
  try {
108
111
  // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -4,8 +4,8 @@ import { FetchHttpClient } from './FetchHttpClient.js'
4
4
 
5
5
  /**
6
6
  * Returns a default HttpClient implementation based on the environment that it is run on.
7
- * This method will attempt to use `window.fetch` if available (in browser environments).
8
- * If running in a Node environment, it falls back to using the Node `https` module
7
+ * This method will attempt to use `window.fetch` if available (in browser environments),
8
+ * then `globalThis.fetch` (service workers, Deno, Node 18+), then the Node `https` module.
9
9
  */
10
10
  export function defaultHttpClient(): HttpClient {
11
11
  const noHttpClient: HttpClient = {
@@ -15,10 +15,13 @@ export function defaultHttpClient(): HttpClient {
15
15
  }
16
16
 
17
17
  if (typeof window !== 'undefined' && typeof window.fetch === 'function') {
18
- // Use fetch in a browser environment
18
+ // Browser tab/page context
19
19
  return new FetchHttpClient(window.fetch.bind(window))
20
+ } else if (typeof globalThis.fetch === 'function') {
21
+ // Service workers, Deno, Node 18+ (any environment with global fetch)
22
+ return new FetchHttpClient(globalThis.fetch.bind(globalThis))
20
23
  } else if (typeof require !== 'undefined') {
21
- // Use Node https module
24
+ // Older Node.js — use https module
22
25
  // eslint-disable-next-line
23
26
  try {
24
27
  // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -7,10 +7,17 @@
7
7
  // allowing us to control whether `https` throws on require.
8
8
 
9
9
  describe('defaultHttpClient — noHttpClient fallback paths', () => {
10
+ let savedFetch: typeof globalThis.fetch | undefined
11
+
12
+ beforeEach(() => {
13
+ savedFetch = globalThis.fetch
14
+ })
15
+
10
16
  afterEach(() => {
11
17
  if ('window' in globalThis) {
12
18
  delete (globalThis as { window?: unknown }).window
13
19
  }
20
+ globalThis.fetch = savedFetch as typeof globalThis.fetch
14
21
  jest.resetModules()
15
22
  })
16
23
 
@@ -25,10 +32,11 @@ describe('defaultHttpClient — noHttpClient fallback paths', () => {
25
32
  throw new Error('https module not available')
26
33
  })
27
34
 
28
- // window must be absent so the fetch branch is skipped
35
+ // window and globalThis.fetch must be absent so the fetch branches are skipped
29
36
  if ('window' in globalThis) {
30
37
  delete (globalThis as { window?: unknown }).window
31
38
  }
39
+ delete (globalThis as { fetch?: unknown }).fetch
32
40
 
33
41
  let defaultHttpClient: any
34
42
 
@@ -61,6 +69,7 @@ describe('defaultHttpClient — noHttpClient fallback paths', () => {
61
69
  if ('window' in globalThis) {
62
70
  delete (globalThis as { window?: unknown }).window
63
71
  }
72
+ delete (globalThis as { fetch?: unknown }).fetch
64
73
 
65
74
  let client: any
66
75
 
@@ -111,10 +120,17 @@ describe('defaultHttpClient — noHttpClient fallback paths', () => {
111
120
  // --------------------------------------------------------------------------
112
121
 
113
122
  describe('binaryHttpClient — noHttpClient fallback paths', () => {
123
+ let savedFetch: typeof globalThis.fetch | undefined
124
+
125
+ beforeEach(() => {
126
+ savedFetch = globalThis.fetch
127
+ })
128
+
114
129
  afterEach(() => {
115
130
  if ('window' in globalThis) {
116
131
  delete (globalThis as { window?: unknown }).window
117
132
  }
133
+ globalThis.fetch = savedFetch as typeof globalThis.fetch
118
134
  jest.resetModules()
119
135
  })
120
136
 
@@ -126,6 +142,7 @@ describe('binaryHttpClient — noHttpClient fallback paths', () => {
126
142
  if ('window' in globalThis) {
127
143
  delete (globalThis as { window?: unknown }).window
128
144
  }
145
+ delete (globalThis as { fetch?: unknown }).fetch
129
146
 
130
147
  let binaryHttpClient: any
131
148
 
@@ -153,6 +170,7 @@ describe('binaryHttpClient — noHttpClient fallback paths', () => {
153
170
  if ('window' in globalThis) {
154
171
  delete (globalThis as { window?: unknown }).window
155
172
  }
173
+ delete (globalThis as { fetch?: unknown }).fetch
156
174
 
157
175
  let client: any
158
176
 
@@ -2,7 +2,7 @@ import { AtomicBEEF, OutpointString, ReviewActionResult, SendWithResult, TXIDHex
2
2
 
3
3
  /**
4
4
  * When a `createAction` or `signAction` is completed in undelayed mode (`acceptDelayedBroadcast`: false),
5
- * any unsucccessful result will return the results by way of this exception to ensure attention is
5
+ * any unsuccessful result will return the results by way of this exception to ensure attention is
6
6
  * paid to processing errors.
7
7
  */
8
8
  export class WERR_REVIEW_ACTIONS extends Error {
@@ -10,7 +10,7 @@ export class WERR_REVIEW_ACTIONS extends Error {
10
10
  isError: boolean = true
11
11
 
12
12
  /**
13
- * All parameters correspond to their comparable `createAction` or `signSction` results
13
+ * All parameters correspond to their comparable `createAction` or `signAction` results
14
14
  * with the exception of `reviewActionResults`;
15
15
  * which contains more details, particularly for double spend results.
16
16
  */
@@ -305,10 +305,10 @@ export interface SendWithResult {
305
305
 
306
306
  /**
307
307
  * Indicates status of a new Action following a `createAction` or `signAction` in immediate mode:
308
- * When `acceptDelayedBroadcast` is falses.
308
+ * When `acceptDelayedBroadcast` is false.
309
309
  *
310
310
  * 'success': The action has been broadcast and accepted by the bitcoin processing network.
311
- * 'doulbeSpend': The action has been confirmed to double spend one or more inputs, and by the "first-seen-rule" is the loosing transaction.
311
+ * 'doubleSpend': The action has been confirmed to double spend one or more inputs, and by the "first-seen-rule" is the losing transaction.
312
312
  * 'invalidTx': The action was rejected by the processing network as an invalid bitcoin transaction.
313
313
  * 'serviceError': The broadcast services are currently unable to reach the bitcoin network. The action is now queued for delayed retries.
314
314
  */