@bsv/sdk 2.0.14 → 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.
- package/dist/cjs/package.json +14 -14
- package/dist/cjs/src/primitives/Hash.js +1 -1
- package/dist/cjs/src/primitives/Hash.js.map +1 -1
- package/dist/cjs/src/primitives/TransactionSignature.js +10 -3
- package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -1
- package/dist/cjs/src/script/Script.js +60 -13
- package/dist/cjs/src/script/Script.js.map +1 -1
- package/dist/cjs/src/script/Spend.js +434 -59
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/src/transaction/http/BinaryFetchClient.js +6 -2
- package/dist/cjs/src/transaction/http/BinaryFetchClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/DefaultHttpClient.js +8 -4
- package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/primitives/Hash.js +1 -1
- package/dist/esm/src/primitives/Hash.js.map +1 -1
- package/dist/esm/src/primitives/TransactionSignature.js +10 -3
- package/dist/esm/src/primitives/TransactionSignature.js.map +1 -1
- package/dist/esm/src/script/Script.js +60 -13
- package/dist/esm/src/script/Script.js.map +1 -1
- package/dist/esm/src/script/Spend.js +438 -59
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/src/transaction/http/BinaryFetchClient.js +6 -2
- package/dist/esm/src/transaction/http/BinaryFetchClient.js.map +1 -1
- package/dist/esm/src/transaction/http/DefaultHttpClient.js +8 -4
- package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/primitives/TransactionSignature.d.ts +1 -0
- package/dist/types/src/primitives/TransactionSignature.d.ts.map +1 -1
- package/dist/types/src/script/Script.d.ts +1 -0
- package/dist/types/src/script/Script.d.ts.map +1 -1
- package/dist/types/src/script/ScriptChunk.d.ts +1 -0
- package/dist/types/src/script/ScriptChunk.d.ts.map +1 -1
- package/dist/types/src/script/Spend.d.ts +29 -0
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/src/transaction/http/BinaryFetchClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/DefaultHttpClient.d.ts +2 -2
- package/dist/types/src/transaction/http/DefaultHttpClient.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +3 -4
- package/docs/reference/primitives.md +1 -0
- package/docs/reference/script.md +7 -0
- package/docs/reference/transaction.md +2 -2
- package/package.json +14 -14
- package/src/primitives/Hash.ts +1 -1
- package/src/primitives/TransactionSignature.ts +11 -3
- package/src/script/Script.ts +59 -13
- package/src/script/ScriptChunk.ts +1 -0
- package/src/script/Spend.ts +483 -61
- package/src/script/__tests/NormativeVectors.test.ts +465 -0
- package/src/script/__tests/fixtures/SOURCES.md +25 -0
- package/src/script/__tests/fixtures/bitcoin-sv/script_tests.json +2591 -0
- package/src/script/__tests/fixtures/bitcoin-sv/sighash.json +1003 -0
- package/src/script/__tests/fixtures/bitcoin-sv/tx_invalid.json +285 -0
- package/src/script/__tests/fixtures/bitcoin-sv/tx_valid.json +367 -0
- package/src/script/__tests/fixtures/teranode/script_tests.json +2432 -0
- package/src/script/__tests/fixtures/teranode/sighash.json +1003 -0
- package/src/script/__tests/fixtures/teranode/tx_invalid.json +285 -0
- package/src/script/__tests/fixtures/teranode/tx_valid.json +367 -0
- package/src/transaction/broadcasters/__tests/ARC.test.ts +26 -4
- package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +26 -4
- package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +32 -10
- package/src/transaction/http/BinaryFetchClient.ts +5 -2
- package/src/transaction/http/DefaultHttpClient.ts +7 -4
- package/src/transaction/http/__tests/DefaultHttpClient.additional.test.ts +19 -1
- package/dist/cjs/src/auth/clients/__tests__/AuthFetch.additional.test.js +0 -827
- package/dist/cjs/src/auth/clients/__tests__/AuthFetch.additional.test.js.map +0 -1
- package/dist/cjs/src/auth/clients/__tests__/AuthFetch.test.js +0 -266
- package/dist/cjs/src/auth/clients/__tests__/AuthFetch.test.js.map +0 -1
- package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js +0 -654
- package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js.map +0 -1
- package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.test.js +0 -144
- package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.test.js.map +0 -1
- package/dist/esm/src/auth/clients/__tests__/AuthFetch.additional.test.js +0 -825
- package/dist/esm/src/auth/clients/__tests__/AuthFetch.additional.test.js.map +0 -1
- package/dist/esm/src/auth/clients/__tests__/AuthFetch.test.js +0 -264
- package/dist/esm/src/auth/clients/__tests__/AuthFetch.test.js.map +0 -1
- package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js +0 -619
- package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js.map +0 -1
- package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.test.js +0 -109
- package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.test.js.map +0 -1
- package/dist/types/src/auth/clients/__tests__/AuthFetch.additional.test.d.ts +0 -21
- package/dist/types/src/auth/clients/__tests__/AuthFetch.additional.test.d.ts.map +0 -1
- package/dist/types/src/auth/clients/__tests__/AuthFetch.test.d.ts +0 -2
- package/dist/types/src/auth/clients/__tests__/AuthFetch.test.d.ts.map +0 -1
- package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.d.ts +0 -2
- package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.d.ts.map +0 -1
- package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.test.d.ts +0 -2
- package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.test.d.ts.map +0 -1
- package/dist/umd/bundle.js.map +0 -1
|
@@ -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
|
-
*
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
|
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
|
|