kopia lustrzana https://github.com/cloudflare/wildebeest
Merge pull request #358 from cloudflare/sven/fix-arraybuffer
fix byte array for neonsven/consumer-test
commit
74ed95b09b
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
compatibility_date = "2023-01-09"
|
||||
main = "./src/index.ts"
|
||||
usage_model = "unbound"
|
||||
node_compat = true
|
||||
|
|
|
@ -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>"
|
||||
|
|
Ładowanie…
Reference in New Issue