@bsv/sdk 1.4.10 → 1.4.12
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/clients/AuthFetch.js +6 -3
- package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +8 -13
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/cjs/src/registry/RegistryClient.js +5 -5
- package/dist/cjs/src/registry/RegistryClient.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/clients/AuthFetch.js +6 -3
- package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +8 -13
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/esm/src/registry/RegistryClient.js +5 -5
- package/dist/esm/src/registry/RegistryClient.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
- package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -1
- package/dist/types/src/registry/RegistryClient.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/package.json +1 -1
- package/src/auth/clients/AuthFetch.ts +9 -5
- package/src/auth/transports/SimplifiedFetchTransport.ts +8 -13
- package/src/registry/RegistryClient.ts +6 -6
package/package.json
CHANGED
|
@@ -349,10 +349,11 @@ export class AuthFetch {
|
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
// Construct headers to send / sign:
|
|
352
|
-
//
|
|
353
|
-
// - x-bsv
|
|
354
|
-
// -
|
|
355
|
-
|
|
352
|
+
// Ensures clients only provided supported HTTP request headers
|
|
353
|
+
// - Include custom headers prefixed with x-bsv (excluding those starting with x-bsv-auth)
|
|
354
|
+
// - Include a normalized version of the content-type header
|
|
355
|
+
// - Include the authorization header
|
|
356
|
+
const includedHeaders: Array<[string, string]> = []
|
|
356
357
|
for (let [k, v] of Object.entries(headers)) {
|
|
357
358
|
k = k.toLowerCase() // We will always sign lower-case header keys
|
|
358
359
|
if (k.startsWith('x-bsv-') || k === 'authorization') {
|
|
@@ -362,13 +363,16 @@ export class AuthFetch {
|
|
|
362
363
|
includedHeaders.push([k, v])
|
|
363
364
|
} else if (k.startsWith('content-type')) {
|
|
364
365
|
// Normalize the Content-Type header by removing any parameters (e.g., "; charset=utf-8")
|
|
365
|
-
v =
|
|
366
|
+
v = v.split(';')[0].trim()
|
|
366
367
|
includedHeaders.push([k, v])
|
|
367
368
|
} else {
|
|
368
369
|
throw new Error('Unsupported header in the simplified fetch implementation. Only content-type, authorization, and x-bsv-* headers are supported.')
|
|
369
370
|
}
|
|
370
371
|
}
|
|
371
372
|
|
|
373
|
+
// Sort the headers by key to ensure a consistent order for signing and verification.
|
|
374
|
+
includedHeaders.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
|
|
375
|
+
|
|
372
376
|
// nHeaders
|
|
373
377
|
writer.writeVarIntNum(includedHeaders.length)
|
|
374
378
|
for (let i = 0; i < includedHeaders.length; i++) {
|
|
@@ -152,25 +152,20 @@ export class SimplifiedFetchTransport implements Transport {
|
|
|
152
152
|
payloadWriter.write(Utils.toArray(response.headers.get('x-bsv-auth-request-id'), 'base64'))
|
|
153
153
|
payloadWriter.writeVarIntNum(response.status)
|
|
154
154
|
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
// - x-bsv
|
|
158
|
-
// - authorization header
|
|
155
|
+
// PARSE RESPONSE HEADERS FROM SERVER --------------------------------
|
|
156
|
+
// Parse response headers from the server and include only the signed headers:
|
|
157
|
+
// - Include custom headers prefixed with x-bsv (excluding those starting with x-bsv-auth)
|
|
158
|
+
// - Include the authorization header
|
|
159
159
|
const includedHeaders: [string, string][] = []
|
|
160
|
-
// Collect headers into a raw array for sorting
|
|
161
|
-
const headersArray: [string, string][] = []
|
|
162
160
|
response.headers.forEach((value, key) => {
|
|
163
161
|
const lowerKey = key.toLowerCase()
|
|
164
|
-
if (lowerKey.startsWith('x-bsv-') || lowerKey === 'authorization') {
|
|
165
|
-
|
|
166
|
-
headersArray.push([lowerKey, value])
|
|
167
|
-
}
|
|
162
|
+
if ((lowerKey.startsWith('x-bsv-') || lowerKey === 'authorization') && !lowerKey.startsWith('x-bsv-auth')) {
|
|
163
|
+
includedHeaders.push([lowerKey, value])
|
|
168
164
|
}
|
|
169
165
|
})
|
|
170
166
|
|
|
171
|
-
// Sort headers
|
|
172
|
-
|
|
173
|
-
includedHeaders.push(...headersArray)
|
|
167
|
+
// Sort the headers by key to ensure a consistent order for signing and verification.
|
|
168
|
+
includedHeaders.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
|
|
174
169
|
|
|
175
170
|
// nHeaders
|
|
176
171
|
payloadWriter.writeVarIntNum(includedHeaders.length)
|
|
@@ -199,6 +199,12 @@ export class RegistryClient {
|
|
|
199
199
|
throw new Error('Invalid registry record. Missing txid, outputIndex, or lockingScript.')
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
// Check if the registry record belongs to the current user
|
|
203
|
+
const currentIdentityKey = (await this.wallet.getPublicKey({ identityKey: true })).publicKey
|
|
204
|
+
if (registryRecord.registryOperator !== currentIdentityKey) {
|
|
205
|
+
throw new Error('This registry token does not belong to the current wallet.')
|
|
206
|
+
}
|
|
207
|
+
|
|
202
208
|
// Create a descriptive label for the item we’re revoking
|
|
203
209
|
const itemIdentifier =
|
|
204
210
|
registryRecord.definitionType === 'basket'
|
|
@@ -421,12 +427,6 @@ export class RegistryClient {
|
|
|
421
427
|
throw new Error(`Unsupported definition type: ${definitionType as string}`)
|
|
422
428
|
}
|
|
423
429
|
|
|
424
|
-
// Enforce that the pushdrop belongs to the CURRENT identity key
|
|
425
|
-
const currentIdentityKey = (await this.wallet.getPublicKey({ identityKey: true })).publicKey
|
|
426
|
-
if (registryOperator !== currentIdentityKey) {
|
|
427
|
-
throw new Error('This registry token does not belong to the current wallet.')
|
|
428
|
-
}
|
|
429
|
-
|
|
430
430
|
// Return the typed data plus the operator key
|
|
431
431
|
return { ...parsedData, registryOperator }
|
|
432
432
|
}
|