import type { Base58, Hash, KeyScope, Keyring, Keyset, SyncState, UnixTimestamp, UserWithSecrets } from '@localfirst/crdx'; import type { Device, DeviceWithSecrets, FirstUseDevice, FirstUseDeviceWithSecrets } from 'device/index.js'; import type { ProofOfInvitation } from 'invitation/index.js'; import type { ServerWithSecrets } from 'server/index.js'; import type { Member, Team } from 'team/index.js'; import type { ConnectionErrorPayload } from './errors.js'; import type { ConnectionMessage } from './message.js'; export type ConnectionEvents = { /** state change in the connection */ change: (summary: string) => void; /** message received from peer */ message: (message: unknown) => void; /** Our peer has detected an error and reported it to us, e.g. we tried to join with an invalid invitation. */ remoteError: (error: ConnectionErrorPayload) => void; /** We've detected an error locally, e.g. a peer tries to join with an invalid invitation. */ localError: (error: ConnectionErrorPayload) => void; /** We're connected to a peer and have been mutually authenticated. */ connected: () => void; /** * We've successfully joined a team using an invitation. This event provides the team graph and * the user's info (including keys). (When we're joining as a new device for an existing user, * this is how we get the user's keys.) This event gives the application a chance to persist the * team graph and the user's info. */ joined: ({ team, user }: { team: Team; user: UserWithSecrets; teamKeyring: Keyring; }) => void; /** The team graph has been updated. This event gives the application a chance to persist the changes. */ updated: () => void; /** The auth connection disconnects from a peer after entering an error state. */ disconnected: (event: ConnectionMessage) => void; }; export type MemberIdentityClaim = { deviceId: string; }; export type InviteeMemberIdentityClaim = { proofOfInvitation: ProofOfInvitation; userName: string; userKeys: Keyset; device: Device; }; export type InviteeDeviceIdentityClaim = { proofOfInvitation: ProofOfInvitation; userName: string; device: FirstUseDevice; }; export type IdentityClaim = MemberIdentityClaim | InviteeMemberIdentityClaim | InviteeDeviceIdentityClaim; export type MemberContext = { user: UserWithSecrets; device: DeviceWithSecrets; team: Team; }; export type InviteeMemberContext = { user: UserWithSecrets; device: DeviceWithSecrets; invitationSeed: string; }; export type InviteeDeviceContext = { userName: string; device: FirstUseDeviceWithSecrets; invitationSeed: string; }; export type InviteeContext = InviteeMemberContext | InviteeDeviceContext; export type ServerContext = { server: ServerWithSecrets; team: Team; }; export type Context = MemberContext | InviteeContext | ServerContext; export type Challenge = KeyScope & { nonce: Base58; timestamp: UnixTimestamp; }; export type ConnectionContext = { device: DeviceWithSecrets | FirstUseDeviceWithSecrets; ourIdentityClaim?: IdentityClaim; theirIdentityClaim?: IdentityClaim; challenge?: Challenge; theirDevice?: Device | FirstUseDevice; peer?: Member; seed?: Uint8Array; theirEncryptedSeed?: Uint8Array; sessionKey?: Uint8Array; theirHead?: Hash; syncState?: SyncState; error?: ErrorPayload; } & Partial & Partial & Partial & Partial; export type ErrorPayload = { message: string; details?: any; }; type C = Context | ConnectionContext; export declare const isMemberContext: (c: C) => c is MemberContext; export declare const isInviteeContext: (c: C) => c is InviteeContext; export declare const isInviteeMemberContext: (c: C) => c is InviteeMemberContext; export declare const isInviteeDeviceContext: (c: C) => c is InviteeDeviceContext; export declare const isServerContext: (c: C) => c is ServerContext; export declare const isMemberClaim: (claim: IdentityClaim) => claim is MemberIdentityClaim; export declare const isInviteeMemberClaim: (claim: IdentityClaim) => claim is InviteeMemberIdentityClaim; export declare const isInviteeDeviceClaim: (claim: IdentityClaim) => claim is InviteeDeviceIdentityClaim; export declare const isInviteeClaim: (claim: IdentityClaim) => claim is InviteeDeviceIdentityClaim; export {}; //# sourceMappingURL=types.d.ts.map