diff --git a/backend/src/activitypub/actors/index.ts b/backend/src/activitypub/actors/index.ts index 7156827..cd89ef5 100644 --- a/backend/src/activitypub/actors/index.ts +++ b/backend/src/activitypub/actors/index.ts @@ -3,6 +3,7 @@ import { generateUserKey } from 'wildebeest/backend/src/utils/key-ops' import { type APObject, sanitizeContent, getTextContent } from '../objects' import { addPeer } from 'wildebeest/backend/src/activitypub/peers' import { type Database } from 'wildebeest/backend/src/database' +import { Buffer } from 'buffer' const PERSON = 'Person' const isTesting = typeof jest !== 'undefined' @@ -158,7 +159,7 @@ export async function createPerson( // Since D1 and better-sqlite3 behaviors don't exactly match, presumable // because Buffer support is different in Node/Worker. We have to transform // the values depending on the platform. - if (isTesting) { + if (isTesting || db.client === 'neon') { privkey = Buffer.from(userKeyPair.wrappedPrivKey) salt = Buffer.from(userKeyPair.salt) } else { diff --git a/backend/src/database/d1.ts b/backend/src/database/d1.ts index a512d97..ba6af22 100644 --- a/backend/src/database/d1.ts +++ b/backend/src/database/d1.ts @@ -30,6 +30,7 @@ const qb: QueryBuilder = { export default function make({ DATABASE }: Pick): Database { const db = DATABASE as any db.qb = qb + db.client = 'd1' return db as Database } diff --git a/backend/src/database/index.ts b/backend/src/database/index.ts index 0e854fc..edcc402 100644 --- a/backend/src/database/index.ts +++ b/backend/src/database/index.ts @@ -15,6 +15,7 @@ export interface Database { batch(statements: PreparedStatement[]): Promise[]> exec(query: string): Promise> qb: QueryBuilder + client: string } export interface PreparedStatement { diff --git a/backend/src/database/neon.ts b/backend/src/database/neon.ts index 802c270..235ded5 100644 --- a/backend/src/database/neon.ts +++ b/backend/src/database/neon.ts @@ -41,6 +41,7 @@ export default async function make(env: Pick): Promise await client.connect() return { + client: 'neon', qb, prepare(query: string) { diff --git a/backend/src/mastodon/account.ts b/backend/src/mastodon/account.ts index 7c81612..170b675 100644 --- a/backend/src/mastodon/account.ts +++ b/backend/src/mastodon/account.ts @@ -89,5 +89,12 @@ SELECT export async function getSigningKey(instanceKey: string, db: Database, actor: Actor): Promise { const stmt = db.prepare('SELECT privkey, privkey_salt FROM actors WHERE id=?').bind(actor.id.toString()) const { privkey, privkey_salt } = (await stmt.first()) as any - return unwrapPrivateKey(instanceKey, new Uint8Array(privkey), new Uint8Array(privkey_salt)) + + if (privkey.buffer && privkey_salt.buffer) { + // neon.tech + return unwrapPrivateKey(instanceKey, new Uint8Array(privkey.buffer), new Uint8Array(privkey_salt.buffer)) + } else { + // D1 + return unwrapPrivateKey(instanceKey, new Uint8Array(privkey), new Uint8Array(privkey_salt)) + } } diff --git a/consumer/wrangler.toml b/consumer/wrangler.toml index 7a861f3..8d2045f 100644 --- a/consumer/wrangler.toml +++ b/consumer/wrangler.toml @@ -1,3 +1,4 @@ compatibility_date = "2023-01-09" main = "./src/index.ts" usage_model = "unbound" +node_compat = true diff --git a/wrangler.toml b/wrangler.toml index 6dd839d..ea7d914 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -3,6 +3,7 @@ name = "wildebeest" main = "src/index.ts" compatibility_date = "2022-12-05" +node_compat = true # Specify your account id here so that all commands run agains the correct account. # account_id = ""