lopata 0.4.0 → 0.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lopata",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -77,8 +77,8 @@ function isPkcs1RsaKey(data: Uint8Array): boolean {
77
77
  if (data.length < 10 || data[0] !== 0x30) return false
78
78
  let offset = 1
79
79
  // Skip outer SEQUENCE length
80
- if (data[offset] & 0x80) {
81
- offset += 1 + (data[offset] & 0x7f)
80
+ if (data[offset]! & 0x80) {
81
+ offset += 1 + (data[offset]! & 0x7f)
82
82
  } else {
83
83
  offset += 1
84
84
  }
@@ -138,7 +138,7 @@ function wrapPkcs1InPkcs8(pkcs1Key: Uint8Array): Uint8Array {
138
138
  return derWrap(0x30, inner)
139
139
  }
140
140
 
141
- function toUint8Array(data: BufferSource): Uint8Array {
141
+ function toUint8Array(data: ArrayBuffer | ArrayBufferView): Uint8Array {
142
142
  if (data instanceof Uint8Array) return data
143
143
  if (ArrayBuffer.isView(data)) return new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
144
144
  return new Uint8Array(data)
@@ -166,19 +166,13 @@ export function patchGlobalCrypto(): void {
166
166
  // Patch importKey to accept PKCS#1 RSA keys with "pkcs8" format (matching workerd behavior).
167
167
  // Workerd is lenient and auto-wraps PKCS#1 in PKCS#8; Bun/Node native crypto rejects it.
168
168
  const origImportKey = subtle.importKey.bind(subtle)
169
- subtle.importKey = function(
170
- format: KeyFormat,
171
- keyData: BufferSource | JsonWebKey,
172
- algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm,
173
- extractable: boolean,
174
- keyUsages: readonly KeyUsage[],
175
- ): Promise<CryptoKey> {
176
- if (format === 'pkcs8' && !(keyData as JsonWebKey).kty) {
177
- const bytes = toUint8Array(keyData as BufferSource)
169
+ subtle.importKey = ((format: string, keyData: unknown, algorithm: unknown, extractable: boolean, keyUsages: readonly string[]) => {
170
+ if (format === 'pkcs8' && typeof keyData === 'object' && keyData !== null && !('kty' in keyData)) {
171
+ const bytes = toUint8Array(keyData as ArrayBuffer | ArrayBufferView)
178
172
  if (isPkcs1RsaKey(bytes)) {
179
- return origImportKey('pkcs8', wrapPkcs1InPkcs8(bytes), algorithm, extractable, keyUsages)
173
+ return (origImportKey as any)('pkcs8', wrapPkcs1InPkcs8(bytes), algorithm, extractable, [...keyUsages])
180
174
  }
181
175
  }
182
- return origImportKey(format, keyData as BufferSource, algorithm, extractable, keyUsages)
183
- }
176
+ return (origImportKey as any)(format, keyData, algorithm, extractable, [...keyUsages])
177
+ }) as typeof subtle.importKey
184
178
  }