@bsv/sdk 1.3.32 → 1.3.34
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 +1 -1
- package/dist/cjs/src/auth/certificates/MasterCertificate.js +25 -15
- package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +6 -2
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/cjs/src/overlay-tools/LookupResolver.js +22 -23
- package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +17 -15
- package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
- package/dist/cjs/src/overlay-tools/index.js +8 -2
- package/dist/cjs/src/overlay-tools/index.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js +25 -15
- package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js +6 -2
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/esm/src/overlay-tools/LookupResolver.js +22 -22
- package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +17 -14
- package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
- package/dist/esm/src/overlay-tools/index.js +4 -0
- package/dist/esm/src/overlay-tools/index.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts +10 -4
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +3 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
- package/dist/types/src/overlay-tools/LookupResolver.d.ts +12 -1
- package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
- package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts +13 -4
- package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
- package/dist/types/src/overlay-tools/index.d.ts +2 -0
- package/dist/types/src/overlay-tools/index.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/auth.md +25 -9
- package/docs/overlay-tools.md +58 -14
- package/package.json +1 -1
- package/src/auth/certificates/MasterCertificate.ts +37 -13
- package/src/auth/certificates/VerifiableCertificate.ts +8 -2
- package/src/overlay-tools/LookupResolver.ts +30 -30
- package/src/overlay-tools/SHIPBroadcaster.ts +25 -21
- package/src/overlay-tools/__tests/LookupResolver.test.ts +3 -3
- package/src/overlay-tools/__tests/SHIPBroadcaster.test.ts +3 -3
- package/src/overlay-tools/index.ts +5 -0
|
@@ -50,10 +50,17 @@ export type STEAK = Record<string, AdmittanceInstructions>
|
|
|
50
50
|
|
|
51
51
|
/** Configuration options for the SHIP broadcaster. */
|
|
52
52
|
export interface SHIPBroadcasterConfig {
|
|
53
|
+
/**
|
|
54
|
+
* The network preset to use, unless other options override it.
|
|
55
|
+
* - mainnet: use mainnet resolver and HTTPS facilitator
|
|
56
|
+
* - testnet: use testnet resolver and HTTPS facilitator
|
|
57
|
+
* - local: directly send to localhost:8080 and a facilitator that permits plain HTTP
|
|
58
|
+
*/
|
|
59
|
+
networkPreset?: 'mainnet' | 'testnet' | 'local'
|
|
53
60
|
/** The facilitator used to make requests to Overlay Services hosts. */
|
|
54
61
|
facilitator?: OverlayBroadcastFacilitator
|
|
55
62
|
/** The resolver used to locate suitable hosts with SHIP */
|
|
56
|
-
resolver
|
|
63
|
+
resolver?: LookupResolver
|
|
57
64
|
/** Determines which topics (all, any, or a specific list) must be present within all STEAKs received from every host for the broadcast to be considered a success. By default, all hosts must acknowledge all topics. */
|
|
58
65
|
requireAcknowledgmentFromAllHostsForTopics?: 'all' | 'any' | string[]
|
|
59
66
|
/** Determines which topics (all, any, or a specific list) must be present within STEAK received from at least one host for the broadcast to be considered a success. */
|
|
@@ -71,13 +78,15 @@ const MAX_SHIP_QUERY_TIMEOUT = 1000
|
|
|
71
78
|
|
|
72
79
|
export class HTTPSOverlayBroadcastFacilitator implements OverlayBroadcastFacilitator {
|
|
73
80
|
httpClient: typeof fetch
|
|
81
|
+
allowHTTP: boolean
|
|
74
82
|
|
|
75
|
-
constructor (httpClient = fetch) {
|
|
83
|
+
constructor (httpClient = fetch, allowHTTP: boolean = false) {
|
|
76
84
|
this.httpClient = httpClient
|
|
85
|
+
this.allowHTTP = false
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
async send (url: string, taggedBEEF: TaggedBEEF): Promise<STEAK> {
|
|
80
|
-
if (!url.startsWith('https:')) {
|
|
89
|
+
if (!url.startsWith('https:') && !this.allowHTTP) {
|
|
81
90
|
throw new Error(
|
|
82
91
|
'HTTPS facilitator can only use URLs that start with "https:"'
|
|
83
92
|
)
|
|
@@ -99,15 +108,16 @@ export class HTTPSOverlayBroadcastFacilitator implements OverlayBroadcastFacilit
|
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
/**
|
|
102
|
-
*
|
|
111
|
+
* Broadcasts transactions to one or more overlay topics.
|
|
103
112
|
*/
|
|
104
|
-
export default class
|
|
113
|
+
export default class TopicBroadcaster implements Broadcaster {
|
|
105
114
|
private readonly topics: string[]
|
|
106
115
|
private readonly facilitator: OverlayBroadcastFacilitator
|
|
107
116
|
private readonly resolver: LookupResolver
|
|
108
117
|
private readonly requireAcknowledgmentFromAllHostsForTopics: | 'all' | 'any' | string[]
|
|
109
118
|
private readonly requireAcknowledgmentFromAnyHostForTopics: | 'all' | 'any' | string[]
|
|
110
119
|
private readonly requireAcknowledgmentFromSpecificHostsForTopics: Record<string, 'all' | 'any' | string[]>
|
|
120
|
+
private readonly networkPreset: 'mainnet' | 'testnet' | 'local'
|
|
111
121
|
|
|
112
122
|
/**
|
|
113
123
|
* Constructs an instance of the SHIP broadcaster.
|
|
@@ -115,7 +125,7 @@ export default class SHIPBroadcaster implements Broadcaster {
|
|
|
115
125
|
* @param {string[]} topics - The list of SHIP topic names where transactions are to be sent.
|
|
116
126
|
* @param {SHIPBroadcasterConfig} config - Configuration options for the SHIP broadcaster.
|
|
117
127
|
*/
|
|
118
|
-
constructor (topics: string[], config
|
|
128
|
+
constructor (topics: string[], config: SHIPBroadcasterConfig = {}) {
|
|
119
129
|
if (topics.length === 0) {
|
|
120
130
|
throw new Error('At least one topic is required for broadcast.')
|
|
121
131
|
}
|
|
@@ -123,21 +133,15 @@ export default class SHIPBroadcaster implements Broadcaster {
|
|
|
123
133
|
throw new Error('Every topic must start with "tm_".')
|
|
124
134
|
}
|
|
125
135
|
this.topics = topics
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
requireAcknowledgmentFromAllHostsForTopics,
|
|
130
|
-
requireAcknowledgmentFromAnyHostForTopics,
|
|
131
|
-
requireAcknowledgmentFromSpecificHostsForTopics
|
|
132
|
-
} = config ?? {}
|
|
133
|
-
this.facilitator = facilitator ?? new HTTPSOverlayBroadcastFacilitator()
|
|
134
|
-
this.resolver = resolver ?? new LookupResolver()
|
|
136
|
+
this.networkPreset = config.networkPreset ?? 'mainnet'
|
|
137
|
+
this.facilitator = config.facilitator ?? new HTTPSOverlayBroadcastFacilitator(undefined, this.networkPreset === 'local')
|
|
138
|
+
this.resolver = config.resolver ?? new LookupResolver({ networkPreset: this.networkPreset })
|
|
135
139
|
this.requireAcknowledgmentFromAllHostsForTopics =
|
|
136
|
-
requireAcknowledgmentFromAllHostsForTopics ?? []
|
|
140
|
+
config.requireAcknowledgmentFromAllHostsForTopics ?? []
|
|
137
141
|
this.requireAcknowledgmentFromAnyHostForTopics =
|
|
138
|
-
requireAcknowledgmentFromAnyHostForTopics ?? 'all'
|
|
142
|
+
config.requireAcknowledgmentFromAnyHostForTopics ?? 'all'
|
|
139
143
|
this.requireAcknowledgmentFromSpecificHostsForTopics =
|
|
140
|
-
requireAcknowledgmentFromSpecificHostsForTopics ?? {}
|
|
144
|
+
config.requireAcknowledgmentFromSpecificHostsForTopics ?? {}
|
|
141
145
|
}
|
|
142
146
|
|
|
143
147
|
/**
|
|
@@ -157,12 +161,12 @@ export default class SHIPBroadcaster implements Broadcaster {
|
|
|
157
161
|
'Transactions sent via SHIP to Overlay Services must be serializable to BEEF format.'
|
|
158
162
|
)
|
|
159
163
|
}
|
|
160
|
-
const interestedHosts = await this.findInterestedHosts()
|
|
164
|
+
const interestedHosts = this.networkPreset === 'local' ? ['http://localhost:8080'] : await this.findInterestedHosts()
|
|
161
165
|
if (Object.keys(interestedHosts).length === 0) {
|
|
162
166
|
return {
|
|
163
167
|
status: 'error',
|
|
164
168
|
code: 'ERR_NO_HOSTS_INTERESTED',
|
|
165
|
-
description:
|
|
169
|
+
description: `No ${this.networkPreset} hosts are interested in receiving this transaction.`
|
|
166
170
|
}
|
|
167
171
|
}
|
|
168
172
|
const hostPromises = Object.entries(interestedHosts).map(
|
|
@@ -190,7 +194,7 @@ export default class SHIPBroadcaster implements Broadcaster {
|
|
|
190
194
|
return {
|
|
191
195
|
status: 'error',
|
|
192
196
|
code: 'ERR_ALL_HOSTS_REJECTED',
|
|
193
|
-
description:
|
|
197
|
+
description: `All ${this.networkPreset} topical hosts have rejected the transaction.`
|
|
194
198
|
}
|
|
195
199
|
}
|
|
196
200
|
|
|
@@ -861,7 +861,7 @@ describe('LookupResolver', () => {
|
|
|
861
861
|
query: { test: 1 }
|
|
862
862
|
})
|
|
863
863
|
).rejects.toThrow(
|
|
864
|
-
'No competent hosts found by the SLAP trackers for lookup service: ls_foo'
|
|
864
|
+
'No competent mainnet hosts found by the SLAP trackers for lookup service: ls_foo'
|
|
865
865
|
)
|
|
866
866
|
|
|
867
867
|
expect(mockFacilitator.lookup.mock.calls).toEqual([
|
|
@@ -1054,7 +1054,7 @@ describe('LookupResolver', () => {
|
|
|
1054
1054
|
query: { test: 1 }
|
|
1055
1055
|
})
|
|
1056
1056
|
).rejects.toThrow(
|
|
1057
|
-
'No competent hosts found by the SLAP trackers for lookup service: ls_foo'
|
|
1057
|
+
'No competent mainnet hosts found by the SLAP trackers for lookup service: ls_foo'
|
|
1058
1058
|
)
|
|
1059
1059
|
|
|
1060
1060
|
expect(mockFacilitator.lookup.mock.calls).toEqual([
|
|
@@ -1628,7 +1628,7 @@ describe('LookupResolver', () => {
|
|
|
1628
1628
|
query: { test: 1 }
|
|
1629
1629
|
})
|
|
1630
1630
|
).rejects.toThrow(
|
|
1631
|
-
'No competent hosts found by the SLAP trackers for lookup service: ls_foo'
|
|
1631
|
+
'No competent mainnet hosts found by the SLAP trackers for lookup service: ls_foo'
|
|
1632
1632
|
)
|
|
1633
1633
|
|
|
1634
1634
|
expect(mockFacilitator.lookup.mock.calls.length).toBe(2)
|
|
@@ -279,7 +279,7 @@ describe('SHIPCast', () => {
|
|
|
279
279
|
expect(result).toEqual({
|
|
280
280
|
status: 'error',
|
|
281
281
|
code: 'ERR_NO_HOSTS_INTERESTED',
|
|
282
|
-
description: 'No hosts are interested in receiving this transaction.'
|
|
282
|
+
description: 'No mainnet hosts are interested in receiving this transaction.'
|
|
283
283
|
})
|
|
284
284
|
|
|
285
285
|
expect(mockResolver.query).toHaveBeenCalledWith(
|
|
@@ -343,7 +343,7 @@ describe('SHIPCast', () => {
|
|
|
343
343
|
expect(result).toEqual({
|
|
344
344
|
status: 'error',
|
|
345
345
|
code: 'ERR_ALL_HOSTS_REJECTED',
|
|
346
|
-
description: 'All
|
|
346
|
+
description: 'All mainnet topical hosts have rejected the transaction.'
|
|
347
347
|
})
|
|
348
348
|
|
|
349
349
|
expect(mockFacilitator.send).toHaveBeenCalled()
|
|
@@ -1081,7 +1081,7 @@ describe('SHIPCast', () => {
|
|
|
1081
1081
|
expect(response).toEqual({
|
|
1082
1082
|
status: 'error',
|
|
1083
1083
|
code: 'ERR_ALL_HOSTS_REJECTED',
|
|
1084
|
-
description: 'All
|
|
1084
|
+
description: 'All mainnet topical hosts have rejected the transaction.'
|
|
1085
1085
|
})
|
|
1086
1086
|
})
|
|
1087
1087
|
describe('SHIPCast private methods', () => {
|
|
@@ -2,4 +2,9 @@ export * from './LookupResolver.js'
|
|
|
2
2
|
export * from './SHIPBroadcaster.js'
|
|
3
3
|
export { default as OverlayAdminTokenTemplate } from './OverlayAdminTokenTemplate.js'
|
|
4
4
|
export { default as LookupResolver } from './LookupResolver.js'
|
|
5
|
+
|
|
6
|
+
// For intuitive clarity, we name this the Topic Broadcaster.
|
|
7
|
+
export { default as TopicBroadcaster } from './SHIPBroadcaster.js'
|
|
8
|
+
// Historically, it was also known by two other names:
|
|
5
9
|
export { default as SHIPBroadcaster } from './SHIPBroadcaster.js'
|
|
10
|
+
export { default as SHIPCast } from './SHIPBroadcaster.js'
|