Skip to content

Commit 2a889fb

Browse files
committed
fix(rivetkit): fix crypto dep in drizzle
1 parent c636bc6 commit 2a889fb

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

rivetkit-typescript/packages/rivetkit/runtime/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { RemoteEngineControlClient } from "@/engine-client/mod";
99
import { ENGINE_ENDPOINT } from "@/common/engine";
1010
import type { Registry } from "@/registry";
1111
import type { RegistryActors, RegistryConfig } from "@/registry/config";
12-
import { getNodeFsSync } from "@/utils/node";
12+
import { getNodeFsSync, importNodeDependencies } from "@/utils/node";
1313
import pkg from "../package.json" with { type: "json" };
1414
import { logger } from "../src/registry/log";
1515

@@ -149,6 +149,7 @@ export class Runtime<A extends RegistryActors> {
149149

150150
if (this.#config.staticDir) {
151151
try {
152+
importNodeDependencies();
152153
const fsSync = getNodeFsSync();
153154
if (fsSync.existsSync(this.#config.staticDir)) {
154155
logLine("Static", `./${this.#config.staticDir}`);

rivetkit-typescript/packages/rivetkit/src/db/drizzle.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
SqliteDatabase,
1111
} from "@/common/database/config";
1212
import { toSqliteBindings } from "@/common/database/shared";
13-
import { getNodeCrypto } from "@/utils/node";
13+
import { sha256Hex } from "@/utils/crypto";
1414

1515
export type { SQLiteTable } from "drizzle-orm/sqlite-core";
1616
export {
@@ -243,10 +243,7 @@ async function runMigrations<TSchema extends DrizzleSchema>(
243243

244244
await db.execute(
245245
"INSERT INTO __drizzle_migrations (hash, created_at) VALUES (?, ?)",
246-
getNodeCrypto()
247-
.createHash("sha256")
248-
.update(migration)
249-
.digest("hex"),
246+
await sha256Hex(migration),
250247
entry.when,
251248
);
252249
}

rivetkit-typescript/packages/rivetkit/src/utils/crypto.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,17 @@ export function timingSafeEqual(
2222

2323
return result === 0;
2424
}
25+
26+
export async function sha256Hex(value: string): Promise<string> {
27+
if (!globalThis.crypto?.subtle) {
28+
throw new Error("Web Crypto API is required to compute SHA-256 hashes");
29+
}
30+
31+
const digest = await globalThis.crypto.subtle.digest(
32+
"SHA-256",
33+
new TextEncoder().encode(value),
34+
);
35+
return Array.from(new Uint8Array(digest), (byte) =>
36+
byte.toString(16).padStart(2, "0"),
37+
).join("");
38+
}

0 commit comments

Comments
 (0)