Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rivetkit-typescript/packages/rivetkit/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RemoteEngineControlClient } from "@/engine-client/mod";
import { ENGINE_ENDPOINT } from "@/common/engine";
import type { Registry } from "@/registry";
import type { RegistryActors, RegistryConfig } from "@/registry/config";
import { getNodeFsSync } from "@/utils/node";
import { getNodeFsSync, importNodeDependencies } from "@/utils/node";
import pkg from "../package.json" with { type: "json" };
import { logger } from "../src/registry/log";

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

if (this.#config.staticDir) {
try {
importNodeDependencies();
const fsSync = getNodeFsSync();
if (fsSync.existsSync(this.#config.staticDir)) {
logLine("Static", `./${this.#config.staticDir}`);
Expand Down
7 changes: 2 additions & 5 deletions rivetkit-typescript/packages/rivetkit/src/db/drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
SqliteDatabase,
} from "@/common/database/config";
import { toSqliteBindings } from "@/common/database/shared";
import { getNodeCrypto } from "@/utils/node";
import { sha256Hex } from "@/utils/crypto";

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

await db.execute(
"INSERT INTO __drizzle_migrations (hash, created_at) VALUES (?, ?)",
getNodeCrypto()
.createHash("sha256")
.update(migration)
.digest("hex"),
await sha256Hex(migration),
entry.when,
);
}
Expand Down
14 changes: 14 additions & 0 deletions rivetkit-typescript/packages/rivetkit/src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ export function timingSafeEqual(

return result === 0;
}

export async function sha256Hex(value: string): Promise<string> {
if (!globalThis.crypto?.subtle) {
throw new Error("Web Crypto API is required to compute SHA-256 hashes");
}

const digest = await globalThis.crypto.subtle.digest(
"SHA-256",
new TextEncoder().encode(value),
);
return Array.from(new Uint8Array(digest), (byte) =>
byte.toString(16).padStart(2, "0"),
).join("");
}
Loading