Files
2026-07-13 13:34:48 +08:00

24 lines
766 B
TypeScript

import * as uuid from 'uuid'
import * as chat from '../src'
import { signJwt } from '../src/jwt'
import * as config from './config'
const encryptionKey = config.get('ENCRYPTION_KEY')
export const halfId = () => {
const id = uuid.v4()
return id.slice(0, id.length / 2)
}
export const getUserFid = (): string => `test-user-${halfId()}`
export const getConversationFid = (): string => `test-conversation-${halfId()}`
export const getUserKey = (userId: string): Promise<string> => signJwt({ id: userId }, encryptionKey)
export const waitFor = <S extends keyof chat.Signals>(
listener: chat.SignalListener,
signal: S
): Promise<chat.Signals[S]> =>
new Promise((resolve, reject) => {
listener.once(signal, resolve)
listener.once('error', reject)
})