Skip to content

Commit 0122c79

Browse files
seefeldbclaude
andauthored
Fix TypeScript errors after Deno upgrade to 2.5.2 (#1856)
* Fix TypeScript errors after Deno upgrade to 2.5.2 Deno 2.5.2 has stricter type checking for WebCrypto and Web APIs. Uint8Array now has a buffer property typed as ArrayBufferLike (ArrayBuffer | SharedArrayBuffer), but WebCrypto APIs require the stricter BufferSource type with ArrayBuffer specifically. Added explicit type casts to satisfy the stricter type requirements: - crypto.subtle.sign/verify/digest/importKey now require BufferSource casts - WebAuthn credential creation requires BufferSource casts for challenge and user.id - Response constructor requires BodyInit cast for Uint8Array bodies 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * support multiple deno versions during transition --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent efd713d commit 0122c79

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
lines changed

packages/charm/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@commontools/charm",
33
"tasks": {
4-
"test": "deno test --allow-env --allow-ffi --allow-read"
4+
"test": "deno test --allow-env --allow-ffi --allow-read --allow-write"
55
},
66
"exports": {
77
".": "./src/index.ts",

packages/identity/src/ed25519/native.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class NativeEd25519Signer<ID extends DIDKey> implements Signer<ID> {
5959
await globalThis.crypto.subtle.sign(
6060
ED25519_ALG,
6161
this.#keypair.privateKey,
62-
payload,
62+
payload as BufferSource,
6363
),
6464
);
6565

@@ -76,15 +76,15 @@ export class NativeEd25519Signer<ID extends DIDKey> implements Signer<ID> {
7676
const rawPublic = await ed25519.getPublicKeyAsync(rawPrivateKey);
7777
const privateKey = await globalThis.crypto.subtle.importKey(
7878
"pkcs8",
79-
pkcs8Private,
79+
pkcs8Private as BufferSource,
8080
ED25519_ALG,
8181
false,
8282
["sign"],
8383
);
8484
// Set the public key to be extractable for DID generation.
8585
const publicKey = await globalThis.crypto.subtle.importKey(
8686
"raw",
87-
rawPublic,
87+
rawPublic as BufferSource,
8888
ED25519_ALG,
8989
true,
9090
[
@@ -135,8 +135,8 @@ export class NativeEd25519Verifier<ID extends DIDKey> implements Verifier<ID> {
135135
await globalThis.crypto.subtle.verify(
136136
ED25519_ALG,
137137
this.#publicKey,
138-
signature,
139-
payload,
138+
signature as BufferSource,
139+
payload as BufferSource,
140140
)
141141
) {
142142
return { ok: {} };
@@ -159,7 +159,7 @@ export class NativeEd25519Verifier<ID extends DIDKey> implements Verifier<ID> {
159159
// Set the public key to be extractable for DID generation.
160160
const publicKey = await globalThis.crypto.subtle.importKey(
161161
"raw",
162-
rawPublicKey,
162+
rawPublicKey as BufferSource,
163163
ED25519_ALG,
164164
true,
165165
[

packages/identity/src/pass-key.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ export class PassKey {
8484
};
8585

8686
const publicKey: PublicKeyCredentialCreationOptions = {
87-
challenge,
87+
challenge: challenge as BufferSource,
8888
rp: { id: RP_ID(), name: RP },
89-
user,
89+
user: {
90+
id: userId as BufferSource,
91+
name,
92+
displayName,
93+
},
9094
attestation: "none", // default
9195
authenticatorSelection: {
9296
// "Resident Keys" have been renamed to "Discoverable Keys",
@@ -130,7 +134,7 @@ export class PassKey {
130134
const credential = (await navigator.credentials.get({
131135
publicKey: {
132136
allowCredentials,
133-
challenge: random(32),
137+
challenge: random(32) as BufferSource,
134138
rpId: RP_ID(),
135139
userVerification: userVerification ?? "preferred",
136140
extensions: { prf: { eval: { first: PRF_SALT } } },

packages/identity/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ export function once(
2626
const HASH_ALG = "SHA-256";
2727
// Hash input via SHA-256.
2828
export async function hash(input: Uint8Array): Promise<Uint8Array> {
29-
return new Uint8Array(await globalThis.crypto.subtle.digest(HASH_ALG, input));
29+
return new Uint8Array(
30+
await globalThis.crypto.subtle.digest(HASH_ALG, input as BufferSource),
31+
);
3032
}

packages/static/etag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Returns a base64-encoded hash in quotes.
99
*/
1010
export async function generateETag(content: Uint8Array): Promise<string> {
11-
const hash = await crypto.subtle.digest("SHA-256", content);
11+
const hash = await crypto.subtle.digest("SHA-256", content as BufferSource);
1212
const base64 = btoa(String.fromCharCode(...new Uint8Array(hash)))
1313
.replace(/\+/g, "-")
1414
.replace(/\//g, "_")

packages/toolshed/routes/static/static.index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ router.get("/static/*", async (c) => {
4343
// Simple caching: always validate with ETag
4444
const cacheHeaders = createCacheHeaders(etag);
4545

46-
return new Response(buffer, {
46+
return new Response(buffer as BodyInit, {
4747
status: 200,
4848
headers: {
4949
"Content-Type": mimeType,

tasks/check.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
DENO_VERSION_REQUIRED="2.4.5"
4+
DENO_VERSIONS_ALLOWED=("2.5.2" "2.4.5")
55
# This is more portable than parsing `deno --version`
66
DENO_VERSION=$(echo "console.log(Deno.version.deno)" | deno run -)
7-
if [ "$DENO_VERSION" != "$DENO_VERSION_REQUIRED" ]; then
8-
echo "ERROR: Deno version is $DENO_VERSION, expected $DENO_VERSION_REQUIRED."
7+
if [[ ! " ${DENO_VERSIONS_ALLOWED[@]} " =~ " ${DENO_VERSION} " ]]; then
8+
echo "ERROR: Deno version is $DENO_VERSION, expected one of: ${DENO_VERSIONS_ALLOWED[*]}."
99
exit 1
1010
fi
1111

0 commit comments

Comments
 (0)