@bsv/sdk 1.3.14 → 1.3.16

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 (30) hide show
  1. package/dist/cjs/package.json +4 -2
  2. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +43 -70
  3. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  4. package/dist/cjs/src/script/ScriptTemplateUnlock.js +3 -0
  5. package/dist/cjs/src/script/ScriptTemplateUnlock.js.map +1 -0
  6. package/dist/cjs/src/script/index.js.map +1 -1
  7. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  8. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +43 -69
  9. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  10. package/dist/esm/src/script/ScriptTemplateUnlock.js +2 -0
  11. package/dist/esm/src/script/ScriptTemplateUnlock.js.map +1 -0
  12. package/dist/esm/src/script/index.js.map +1 -1
  13. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  14. package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts +1 -1
  15. package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -1
  16. package/dist/types/src/script/ScriptTemplate.d.ts +6 -10
  17. package/dist/types/src/script/ScriptTemplate.d.ts.map +1 -1
  18. package/dist/types/src/script/ScriptTemplateUnlock.d.ts +7 -0
  19. package/dist/types/src/script/ScriptTemplateUnlock.d.ts.map +1 -0
  20. package/dist/types/src/script/index.d.ts +1 -0
  21. package/dist/types/src/script/index.d.ts.map +1 -1
  22. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  23. package/dist/umd/bundle.js +1 -1
  24. package/docs/auth.md +1 -1
  25. package/docs/script.md +19 -10
  26. package/package.json +4 -2
  27. package/src/auth/transports/SimplifiedFetchTransport.ts +73 -144
  28. package/src/script/ScriptTemplate.ts +6 -10
  29. package/src/script/ScriptTemplateUnlock.ts +7 -0
  30. package/src/script/index.ts +1 -0
package/docs/auth.md CHANGED
@@ -1064,7 +1064,7 @@ Argument Details
1064
1064
 
1065
1065
  #### Method onData
1066
1066
 
1067
- Registers a callback to handle incoming messages.
1067
+ Registers a callback to handle incoming messages.
1068
1068
  This must be called before sending any messages to ensure responses can be processed.
1069
1069
 
1070
1070
  ```ts
package/docs/script.md CHANGED
@@ -8,6 +8,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
8
8
  | --- |
9
9
  | [ScriptChunk](#interface-scriptchunk) |
10
10
  | [ScriptTemplate](#interface-scripttemplate) |
11
+ | [ScriptTemplateUnlock](#interface-scripttemplateunlock) |
11
12
 
12
13
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
13
14
 
@@ -31,15 +32,12 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
31
32
 
32
33
  ```ts
33
34
  export default interface ScriptTemplate {
34
- lock: (...params: unknown[]) => LockingScript | Promise<LockingScript>;
35
- unlock: (...params: unknown[]) => {
36
- sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
37
- estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>;
38
- };
35
+ lock: (...params: any[]) => LockingScript | Promise<LockingScript>;
36
+ unlock: (...params: any[]) => ScriptTemplateUnlock;
39
37
  }
40
38
  ```
41
39
 
42
- See also: [LockingScript](./script.md#class-lockingscript), [Transaction](./transaction.md#class-transaction), [UnlockingScript](./script.md#class-unlockingscript), [sign](./compat.md#variable-sign)
40
+ See also: [LockingScript](./script.md#class-lockingscript), [ScriptTemplateUnlock](./script.md#interface-scripttemplateunlock)
43
41
 
44
42
  <details>
45
43
 
@@ -50,7 +48,7 @@ See also: [LockingScript](./script.md#class-lockingscript), [Transaction](./tran
50
48
  Creates a locking script with the given parameters.
51
49
 
52
50
  ```ts
53
- lock: (...params: unknown[]) => LockingScript | Promise<LockingScript>
51
+ lock: (...params: any[]) => LockingScript | Promise<LockingScript>
54
52
  ```
55
53
  See also: [LockingScript](./script.md#class-lockingscript)
56
54
 
@@ -63,14 +61,25 @@ This method returns an object containing two functions:
63
61
  2. `estimateLength` - A function that returns the estimated length of the unlocking script in bytes.
64
62
 
65
63
  ```ts
66
- unlock: (...params: unknown[]) => {
64
+ unlock: (...params: any[]) => ScriptTemplateUnlock
65
+ ```
66
+ See also: [ScriptTemplateUnlock](./script.md#interface-scripttemplateunlock)
67
+
68
+ </details>
69
+
70
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
71
+
72
+ ---
73
+ ### Interface: ScriptTemplateUnlock
74
+
75
+ ```ts
76
+ export default interface ScriptTemplateUnlock {
67
77
  sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>;
68
78
  estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>;
69
79
  }
70
80
  ```
71
- See also: [Transaction](./transaction.md#class-transaction), [UnlockingScript](./script.md#class-unlockingscript), [sign](./compat.md#variable-sign)
72
81
 
73
- </details>
82
+ See also: [Transaction](./transaction.md#class-transaction), [UnlockingScript](./script.md#class-unlockingscript), [sign](./compat.md#variable-sign)
74
83
 
75
84
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
76
85
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.3.14",
3
+ "version": "1.3.16",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -239,7 +239,9 @@
239
239
  "project": "tsconfig.eslint.json",
240
240
  "ignore": [
241
241
  "dist",
242
- "src/transaction/Transaction.ts"
242
+ "src/script/ScriptTemplate.ts",
243
+ "src/transaction/Transaction.ts",
244
+ "src/auth/transports/SimplifiedFetchTransport.ts"
243
245
  ]
244
246
  }
245
247
  }
@@ -1,18 +1,12 @@
1
1
  // @ts-nocheck
2
- import { AuthMessage, RequestedCertificateSet, Transport } from '../types.js'
2
+ // @ts-ignore
3
+ import { AuthMessage, RequestedCertificateSet, Transport } from "../types.js"
3
4
  import { Utils } from '../../../mod.js'
4
5
 
5
- // Define the expected shape of error responses
6
- interface ErrorInfo {
7
- status: string
8
- description: string
9
- code?: string
10
- }
11
-
12
6
  const SUCCESS_STATUS_CODES = [200, 402]
13
7
 
14
8
  // Only bind window.fetch in the browser
15
- const defaultFetch = typeof window !== 'undefined' ? fetch.bind(window) : fetch
9
+ const defaultFetch = typeof window !== 'undefined' ? fetch.bind(window) : fetch;
16
10
 
17
11
  /**
18
12
  * Implements an HTTP-specific transport for handling Peer mutual authentication messages.
@@ -38,32 +32,27 @@ export class SimplifiedFetchTransport implements Transport {
38
32
  * Handles both general and authenticated message types. For general messages,
39
33
  * the payload is deserialized and sent as an HTTP request. For other message types,
40
34
  * the message is sent as a POST request to the `/auth` endpoint.
41
- *
35
+ *
42
36
  * @param message - The AuthMessage to send.
43
37
  * @returns A promise that resolves when the message is successfully sent.
44
- *
38
+ *
45
39
  * @throws Will throw an error if no listener has been registered via `onData`.
46
40
  */
47
41
  async send(message: AuthMessage): Promise<void> {
48
- if (this.onDataCallback == null) {
49
- throw new Error(
50
- 'Listen before you start speaking. God gave you two ears and one mouth for a reason.'
51
- )
42
+ if (!this.onDataCallback) {
43
+ throw new Error('Listen before you start speaking. God gave you two ears and one mouth for a reason.')
52
44
  }
53
45
 
54
46
  if (message.messageType !== 'general') {
55
- const response = await this.fetchClient(
56
- `${this.baseUrl}/.well-known/auth`,
57
- {
58
- method: 'POST',
59
- headers: {
60
- 'Content-Type': 'application/json'
61
- },
62
- body: JSON.stringify(message)
63
- }
64
- )
47
+ const response = await this.fetchClient(`${this.baseUrl}/.well-known/auth`, {
48
+ method: 'POST',
49
+ headers: {
50
+ 'Content-Type': 'application/json'
51
+ },
52
+ body: JSON.stringify(message)
53
+ })
65
54
  // Handle the response if data is received and callback is set
66
- if (response.ok && typeof this.onDataCallback === 'function') { // ✅ Explicitly check if it's a function
55
+ if (response.ok && this.onDataCallback) {
67
56
  const responseMessage = await response.json()
68
57
  if (responseMessage?.status !== 'certificate received') {
69
58
  this.onDataCallback(responseMessage as AuthMessage)
@@ -74,77 +63,49 @@ export class SimplifiedFetchTransport implements Transport {
74
63
  }
75
64
  } else {
76
65
  // Parse message payload
77
- const httpRequest = this.deserializeRequestPayload(message.payload ?? [])
66
+ const httpRequest = this.deserializeRequestPayload(message.payload)
78
67
 
79
68
  // Send the byte array as the HTTP payload
80
69
  const url = `${this.baseUrl}${httpRequest.urlPostfix}`
81
- const httpRequestWithAuthHeaders: {
82
- method: string // ✅ Add method property
83
- headers: Record<string, string>
84
- body?: string | Record<string, unknown> | Uint8Array
85
- } = {
86
- method: httpRequest.method, // ✅ Copy method from httpRequest
87
- headers: httpRequest.headers,
88
- body: Array.isArray(httpRequest.body)
89
- ? JSON.stringify(httpRequest.body)
90
- : httpRequest.body
91
- }
92
-
70
+ let httpRequestWithAuthHeaders: any = httpRequest
93
71
  if (typeof httpRequest.headers !== 'object') {
94
72
  httpRequestWithAuthHeaders.headers = {}
95
73
  }
96
74
 
97
75
  // Append auth headers in request to server
98
- httpRequestWithAuthHeaders.headers['x-bsv-auth-version'] =
99
- message.version
100
- httpRequestWithAuthHeaders.headers['x-bsv-auth-identity-key'] =
101
- message.identityKey
102
- httpRequestWithAuthHeaders.headers['x-bsv-auth-nonce'] = message.nonce ?? ''
103
- httpRequestWithAuthHeaders.headers['x-bsv-auth-your-nonce'] = message.yourNonce ?? ''
104
-
105
- httpRequestWithAuthHeaders.headers['x-bsv-auth-signature'] = Utils.toHex(
106
- message.signature ?? []
107
- )
108
- httpRequestWithAuthHeaders.headers['x-bsv-auth-request-id'] =
109
- httpRequest.requestId
76
+ httpRequestWithAuthHeaders.headers['x-bsv-auth-version'] = message.version
77
+ httpRequestWithAuthHeaders.headers['x-bsv-auth-identity-key'] = message.identityKey
78
+ httpRequestWithAuthHeaders.headers['x-bsv-auth-nonce'] = message.nonce
79
+ httpRequestWithAuthHeaders.headers['x-bsv-auth-your-nonce'] = message.yourNonce
80
+ httpRequestWithAuthHeaders.headers['x-bsv-auth-signature'] = Utils.toHex(message.signature)
81
+ httpRequestWithAuthHeaders.headers['x-bsv-auth-request-id'] = httpRequest.requestId
110
82
 
111
83
  // Ensure Content-Type is set for requests with a body
112
- if (httpRequestWithAuthHeaders.body !== null && httpRequestWithAuthHeaders.body !== undefined) {
113
- const headers = httpRequestWithAuthHeaders.headers
114
- if (headers['content-type'] === undefined || headers['content-type'] === null || headers['content-type'].trim() === '') {
115
- throw new Error(
116
- 'Content-Type header is required for requests with a body.'
117
- )
84
+ if (httpRequestWithAuthHeaders.body) {
85
+ const headers = httpRequestWithAuthHeaders.headers;
86
+ if (!headers['content-type']) {
87
+ throw new Error('Content-Type header is required for requests with a body.');
118
88
  }
119
89
 
120
- const contentType = headers['content-type']
90
+ const contentType = headers['content-type'];
121
91
 
122
92
  // Transform body based on Content-Type
123
- if (typeof httpRequestWithAuthHeaders.body !== 'undefined') {
124
- if (contentType.includes('application/json') ||
125
- contentType.includes('application/x-www-form-urlencoded') ||
126
- contentType.includes('text/plain')) {
127
- // Convert byte array or object to UTF-8 string
128
- if (httpRequestWithAuthHeaders.body instanceof Uint8Array) {
129
- httpRequestWithAuthHeaders.body = Utils.toUTF8(
130
- Array.from(httpRequestWithAuthHeaders.body) // Convert Uint8Array to number[]
131
- )
132
- } else if (typeof httpRequestWithAuthHeaders.body === 'object') {
133
- httpRequestWithAuthHeaders.body = JSON.stringify(httpRequestWithAuthHeaders.body)
134
- }
135
- } else {
136
- // For all other content types, ensure it's Uint8Array
137
- if (!(httpRequestWithAuthHeaders.body instanceof Uint8Array)) {
138
- httpRequestWithAuthHeaders.body = new Uint8Array(
139
- typeof httpRequestWithAuthHeaders.body === 'string'
140
- ? Utils.toArray(httpRequestWithAuthHeaders.body, 'utf8') // Convert string to byte array
141
- : []
142
- )
143
- }
144
- }
93
+ if (contentType.includes('application/json')) {
94
+ // Convert byte array to JSON string
95
+ httpRequestWithAuthHeaders.body = Utils.toUTF8(httpRequestWithAuthHeaders.body);
96
+ } else if (contentType.includes('application/x-www-form-urlencoded')) {
97
+ // Convert byte array to URL-encoded string
98
+ httpRequestWithAuthHeaders.body = Utils.toUTF8(httpRequestWithAuthHeaders.body);
99
+ } else if (contentType.includes('text/plain')) {
100
+ // Convert byte array to plain UTF-8 string
101
+ httpRequestWithAuthHeaders.body = Utils.toUTF8(httpRequestWithAuthHeaders.body);
102
+ } else {
103
+ // For all other content types, treat as binary data
104
+ httpRequestWithAuthHeaders.body = new Uint8Array(httpRequestWithAuthHeaders.body);
145
105
  }
146
106
  }
147
107
 
108
+
148
109
  // Send the actual fetch request to the server
149
110
  const response = await this.fetchClient(url, {
150
111
  method: httpRequestWithAuthHeaders.method,
@@ -154,50 +115,38 @@ export class SimplifiedFetchTransport implements Transport {
154
115
 
155
116
  // Check for an acceptable status
156
117
  if (!SUCCESS_STATUS_CODES.includes(response.status)) {
157
- let errorInfo: ErrorInfo | null = null // Explicitly initialize
158
-
118
+ // Try parsing JSON error
119
+ let errorInfo;
159
120
  try {
160
- errorInfo = await response.json() as ErrorInfo // Cast response to expected type
121
+ errorInfo = await response.json();
161
122
  } catch {
162
123
  // Fallback to text if JSON parse fails
163
- const text = await response.text().catch(() => '')
164
- throw new Error(
165
- `HTTP ${response.status} - ${text.trim() !== '' ? text : 'Unknown error'}`
166
- )
124
+ const text = await response.text().catch(() => '');
125
+ throw new Error(`HTTP ${response.status} - ${text || 'Unknown error'}`);
167
126
  }
168
127
 
169
128
  // If we find a known { status: 'error', code, description } structure
170
- if (
171
- errorInfo !== null && // Explicitly check for null
172
- errorInfo.status === 'error' &&
173
- typeof errorInfo.description === 'string'
174
- ) {
175
- const msg = `HTTP ${response.status} - ${errorInfo.description}`
176
- throw new Error(
177
- typeof errorInfo.code === 'string' ? `${msg} (code: ${errorInfo.code})` : msg
178
- )
129
+ if (errorInfo?.status === 'error' && typeof errorInfo.description === 'string') {
130
+ const msg = `HTTP ${response.status} - ${errorInfo.description}`;
131
+ throw new Error(errorInfo.code ? `${msg} (code: ${errorInfo.code})` : msg);
179
132
  }
180
133
 
181
134
  // Otherwise just throw whatever we got
182
- throw new Error(
183
- `HTTP ${response.status} - ${JSON.stringify(errorInfo)}`
184
- )
135
+ throw new Error(`HTTP ${response.status} - ${JSON.stringify(errorInfo)}`);
185
136
  }
186
137
 
187
138
  const parsedBody = await response.arrayBuffer()
188
139
  const payloadWriter = new Utils.Writer()
189
- payloadWriter.write(
190
- Utils.toArray(response.headers.get('x-bsv-auth-request-id'), 'base64')
191
- )
140
+ payloadWriter.write(Utils.toArray(response.headers.get('x-bsv-auth-request-id'), 'base64'))
192
141
  payloadWriter.writeVarIntNum(response.status)
193
142
 
194
143
  // Filter out headers the server signed:
195
144
  // - Custom headers prefixed with x-bsv are included, except auth
196
145
  // - x-bsv-auth headers are not allowed
197
146
  // - authorization header is signed by the server
198
- const includedHeaders: Array<[string, string]> = []
147
+ const includedHeaders: [string, string][] = []
199
148
  // Collect headers into a raw array for sorting
200
- const headersArray: Array<[string, string]> = []
149
+ const headersArray: [string, string][] = []
201
150
  response.headers.forEach((value, key) => {
202
151
  const lowerKey = key.toLowerCase()
203
152
  if (lowerKey.startsWith('x-bsv-') || lowerKey === 'authorization') {
@@ -227,7 +176,7 @@ export class SimplifiedFetchTransport implements Transport {
227
176
  }
228
177
 
229
178
  // Handle body
230
- if (parsedBody !== null && parsedBody !== undefined) { // ✅ Explicitly check for null/undefined
179
+ if (parsedBody) {
231
180
  const bodyAsArray = Array.from(new Uint8Array(parsedBody))
232
181
  payloadWriter.writeVarIntNum(bodyAsArray.length)
233
182
  payloadWriter.write(bodyAsArray)
@@ -237,27 +186,18 @@ export class SimplifiedFetchTransport implements Transport {
237
186
 
238
187
  // Build the correct AuthMessage for the response
239
188
  const responseMessage: AuthMessage = {
240
- version: response.headers.get('x-bsv-auth-version') ?? '', // Ensure string
241
- messageType:
242
- response.headers.get('x-bsv-auth-message-type') ===
243
- 'certificateRequest'
244
- ? 'certificateRequest'
245
- : 'general',
246
- identityKey: response.headers.get('x-bsv-auth-identity-key') ?? '',
247
- nonce: response.headers.get('x-bsv-auth-nonce') ?? undefined,
248
- yourNonce: response.headers.get('x-bsv-auth-your-nonce') ?? undefined,
249
- requestedCertificates: JSON.parse(
250
- response.headers.get('x-bsv-auth-requested-certificates') ?? '[]'
251
- ) as RequestedCertificateSet,
189
+ version: response.headers.get('x-bsv-auth-version'),
190
+ messageType: response.headers.get('x-bsv-auth-message-type') === 'certificateRequest' ? 'certificateRequest' : 'general',
191
+ identityKey: response.headers.get('x-bsv-auth-identity-key'),
192
+ nonce: response.headers.get('x-bsv-auth-nonce'),
193
+ yourNonce: response.headers.get('x-bsv-auth-your-nonce'),
194
+ requestedCertificates: JSON.parse(response.headers.get('x-bsv-auth-requested-certificates')) as RequestedCertificateSet,
252
195
  payload: payloadWriter.toArray(),
253
- signature: Utils.toArray(
254
- response.headers.get('x-bsv-auth-signature') ?? '',
255
- 'hex'
256
- )
196
+ signature: Utils.toArray(response.headers.get('x-bsv-auth-signature'), 'hex'),
257
197
  }
258
198
 
259
199
  // If the server didn't provide the correct authentication headers, throw an error
260
- if (responseMessage.version === undefined || responseMessage.version === null || responseMessage.version.trim() === '') {
200
+ if (!responseMessage.version) {
261
201
  throw new Error('HTTP server failed to authenticate')
262
202
  }
263
203
 
@@ -267,41 +207,30 @@ export class SimplifiedFetchTransport implements Transport {
267
207
  }
268
208
 
269
209
  /**
270
- * Registers a callback to handle incoming messages.
210
+ * Registers a callback to handle incoming messages.
271
211
  * This must be called before sending any messages to ensure responses can be processed.
272
- *
212
+ *
273
213
  * @param callback - A function to invoke when an incoming AuthMessage is received.
274
214
  * @returns A promise that resolves once the callback is set.
275
215
  */
276
- async onData(
277
- callback: (message: AuthMessage) => Promise<void>
278
- ): Promise<void> {
279
- this.onDataCallback = (m) => { // ✅ Removed `async` here
280
- void (async () => { // ✅ Wraps the async function inside a void IIFE
281
- try {
282
- await callback(m) // ✅ Ensures proper `await`
283
- } catch (error) {
284
- console.error(
285
- 'Error handling AuthMessage:',
286
- error instanceof Error ? error.message : String(error)
287
- )
288
- }
289
- })()
216
+ async onData(callback: (message: AuthMessage) => Promise<void>): Promise<void> {
217
+ this.onDataCallback = (m) => {
218
+ callback(m)
290
219
  }
291
220
  }
292
221
 
293
222
  /**
294
223
  * Deserializes a request payload from a byte array into an HTTP request-like structure.
295
- *
224
+ *
296
225
  * @param payload - The serialized payload to deserialize.
297
226
  * @returns An object representing the deserialized request, including the method,
298
227
  * URL postfix (path and query string), headers, body, and request ID.
299
228
  */
300
229
  deserializeRequestPayload(payload: number[]): {
301
- method: string
302
- urlPostfix: string
303
- headers: Record<string, string>
304
- body: number[]
230
+ method: string,
231
+ urlPostfix: string,
232
+ headers: Record<string, string>,
233
+ body: number[],
305
234
  requestId: string
306
235
  } {
307
236
  // Create a reader
@@ -361,4 +290,4 @@ export class SimplifiedFetchTransport implements Transport {
361
290
  requestId
362
291
  }
363
292
  }
364
- }
293
+ }
@@ -1,6 +1,5 @@
1
1
  import LockingScript from './LockingScript.js'
2
- import UnlockingScript from './UnlockingScript.js'
3
- import Transaction from '../transaction/Transaction.js'
2
+ import ScriptTemplateUnlock from './ScriptTemplateUnlock.js'
4
3
 
5
4
  /**
6
5
  * @interface
@@ -12,10 +11,10 @@ export default interface ScriptTemplate {
12
11
  /**
13
12
  * Creates a locking script with the given parameters.
14
13
  *
15
- * @param {...any} params - The parameters required to create the locking script.
14
+ * @param {...any[]} params - The parameters required to create the locking script.
16
15
  * @returns {LockingScript} - An instance of LockingScript, or a Promise for one.
17
16
  */
18
- lock: (...params: unknown[]) => LockingScript | Promise<LockingScript>
17
+ lock: (...params: any[]) => LockingScript | Promise<LockingScript>
19
18
 
20
19
  /**
21
20
  * Creates a function that generates an unlocking script along with its signature and length estimation.
@@ -24,11 +23,8 @@ export default interface ScriptTemplate {
24
23
  * 1. `sign` - A function that, when called with a transaction and an input index, returns an UnlockingScript instance.
25
24
  * 2. `estimateLength` - A function that returns the estimated length of the unlocking script in bytes.
26
25
  *
27
- * @param {...any} params - The parameters required to create the unlocking script.
28
- * @returns {Object} - An object containing the `sign` and `estimateLength` functions.
26
+ * @param {...any[]} params - The parameters required to create the unlocking script.
27
+ * @returns {ScriptTemplateUnlock} - An object containing the `sign` and `estimateLength` functions.
29
28
  */
30
- unlock: (...params: unknown[]) => {
31
- sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>
32
- estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>
33
- }
29
+ unlock: (...params: any[]) => ScriptTemplateUnlock
34
30
  }
@@ -0,0 +1,7 @@
1
+ import UnlockingScript from './UnlockingScript.js'
2
+ import Transaction from '../transaction/Transaction.js'
3
+
4
+ export default interface ScriptTemplateUnlock {
5
+ sign: (tx: Transaction, inputIndex: number) => Promise<UnlockingScript>
6
+ estimateLength: (tx: Transaction, inputIndex: number) => Promise<number>
7
+ }
@@ -3,5 +3,6 @@ export { default as Script } from './Script.js'
3
3
  export { default as LockingScript } from './LockingScript.js'
4
4
  export { default as UnlockingScript } from './UnlockingScript.js'
5
5
  export { default as Spend } from './Spend.js'
6
+ export type { default as ScriptTemplateUnlock } from './ScriptTemplateUnlock.js'
6
7
  export type { default as ScriptTemplate } from './ScriptTemplate.js'
7
8
  export * from './templates/index.js'