fix byte array for neon

pull/358/head
Sven Sauleau 2023-03-01 12:24:25 +00:00
rodzic cb2a69c62d
commit ba4daecf17
7 zmienionych plików z 15 dodań i 2 usunięć

Wyświetl plik

@ -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 {

Wyświetl plik

@ -30,6 +30,7 @@ const qb: QueryBuilder = {
export default function make({ DATABASE }: Pick<Env, 'DATABASE'>): Database {
const db = DATABASE as any
db.qb = qb
db.client = 'd1'
return db as Database
}

Wyświetl plik

@ -15,6 +15,7 @@ export interface Database {
batch<T = unknown>(statements: PreparedStatement[]): Promise<Result<T>[]>
exec<T = unknown>(query: string): Promise<Result<T>>
qb: QueryBuilder
client: string
}
export interface PreparedStatement {

Wyświetl plik

@ -41,6 +41,7 @@ export default async function make(env: Pick<Env, 'NEON_DATABASE_URL'>): Promise
await client.connect()
return {
client: 'neon',
qb,
prepare(query: string) {

Wyświetl plik

@ -89,5 +89,12 @@ SELECT
export async function getSigningKey(instanceKey: string, db: Database, actor: Actor): Promise<CryptoKey> {
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))
}
}

Wyświetl plik

@ -1,3 +1,4 @@
compatibility_date = "2023-01-09"
main = "./src/index.ts"
usage_model = "unbound"
node_compat = true

Wyświetl plik

@ -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 = "<your account id>"