bigblocks
Version:
Complete Bitcoin UI component library - authentication, social, wallet, market, inscriptions, and blockchain interactions for React
317 lines • 9.94 kB
TypeScript
import type { BapMasterBackup, BapMasterBackupLegacy, BapMemberBackup, DecryptedBackup, MasterBackupType42, OneSatBackup, WifBackup } from "bitcoin-backup";
import type React from "react";
import type { ButtonProps } from "../components/ui/button";
import type { WalletUserExtension } from "../components/wallet/types/extended-user";
export type { BapMasterBackup, BapMasterBackupLegacy, MasterBackupType42, BapMemberBackup, WifBackup, OneSatBackup, DecryptedBackup, WalletUserExtension, };
export declare function isBapMasterBackupLegacy(backup: BapMasterBackup): backup is BapMasterBackupLegacy;
export declare function isMasterBackupType42(backup: BapMasterBackup): backup is MasterBackupType42;
export type BackupTypeName = "BapMasterBackup" | "BapMemberBackup" | "OneSatBackup" | "WifBackup";
export interface BackupTypeConfig {
enabled: BackupTypeName[];
errorMessages?: {
unsupported?: string;
invalid?: string;
};
}
export interface BitcoinAuthConfig {
apiUrl?: string;
blockchainService?: BlockchainServiceConfig;
oauthProviders?: OAuthProvider[];
customOAuthProviders?: Array<{
id: string;
name: string;
icon: React.ReactNode;
authUrl?: string;
color?: string;
customAuth?: {
type: "popup" | "redirect" | "challenge";
handler: (config: Record<string, string | number | boolean>) => Promise<{
encryptedBackup?: string;
idKey?: string;
error?: string;
}>;
};
}>;
backupTypes?: BackupTypeConfig;
persistentStorage?: StorageAdapter;
sessionStorage?: StorageAdapter;
storageNamespace?: string;
theme?: ThemeConfig;
redirects?: RedirectConfig;
onSuccess?: (user: AuthUser) => void;
onError?: (error: AuthError) => void;
}
export interface BlockchainServiceConfig {
mode: "client" | "proxy";
client?: {
apiKeys?: {
whatsonchain?: string;
taal?: string;
gorillapool?: string;
mattercloud?: string;
custom?: Record<string, string>;
};
endpoints?: {
broadcast?: string;
utxos?: string;
balance?: string;
transactions?: string;
};
preferredService?: "whatsonchain" | "taal" | "gorillapool" | "mattercloud" | "custom";
};
proxy?: {
endpoint: string;
headers?: Record<string, string>;
timeout?: number;
};
network?: "main" | "test" | "stn";
retries?: number;
timeout?: number;
}
export type OAuthProvider = "google" | "github" | "twitter" | "handcash" | "yours" | string;
export interface StorageAdapter {
get: (key: string) => Promise<string | null>;
set: (key: string, value: string) => Promise<void>;
delete: (key: string) => Promise<void>;
clear?: () => Promise<void>;
}
export interface ThemeConfig {
mode?: "light" | "dark";
colors?: ColorPalette;
typography?: Typography;
spacing?: SpacingScale;
components?: ComponentStyles;
}
export interface RedirectConfig {
success?: string;
signup?: string;
signin?: string;
error?: string;
}
export interface AuthState {
user: AuthUser | null;
isAuthenticated: boolean;
isLoading: boolean;
error: AuthError | null;
currentStep: AuthStep;
mode: AuthMode;
hasLocalBackup: boolean;
backupStatus: BackupStatus;
hasWalletCapabilities: boolean;
linkedProviders: OAuthProvider[];
pendingOAuthProvider: OAuthProvider | null;
}
export type AuthStep = "initial" | "signin" | "signup" | "password" | "confirm-password" | "backup-display" | "backup-download" | "oauth-link" | "oauth-restore" | "import-backup" | "success";
export type AuthMode = "signin" | "signup" | "link" | "restore";
export interface AuthUser {
id: string;
address: string;
idKey: string;
profiles: ProfileInfo[];
activeProfileId: string;
ordinalsAddress?: string;
identityAddress?: string;
}
export interface ProfileInfo {
id: string;
address: string;
isPublished: boolean;
"@context"?: string;
"@type"?: "Person" | "Organization";
name?: string;
alternateName?: string;
description?: string;
url?: string;
email?: string;
image?: string;
logo?: string;
banner?: string;
givenName?: string;
familyName?: string;
legalName?: string;
location?: string;
homeLocation?: string;
streetAddress?: string;
addressLocality?: string;
addressRegion?: string;
postalCode?: string;
addressCountry?: string;
paymail?: string;
bitcoinAddress?: string;
}
export interface BackupStatus {
hasLocal: boolean;
hasCloud: boolean;
cloudProviders: OAuthProvider[];
lastUpdated?: Date;
}
export interface AuthActions {
signIn: (password: string) => Promise<void>;
signUp: (password: string) => Promise<void>;
signOut: () => Promise<void>;
generateBackup: () => BapMasterBackup;
importBackup: (file: File) => Promise<void>;
exportBackup: (password?: string) => Promise<void>;
validatePassword: (password: string) => Promise<boolean>;
getCurrentBackup: () => Promise<BapMasterBackup | null>;
linkOAuth: (provider: OAuthProvider) => Promise<void>;
unlinkOAuth: (provider: OAuthProvider) => Promise<void>;
restoreFromOAuth: (provider: OAuthProvider) => Promise<void>;
createProfile: () => Promise<ProfileInfo>;
switchProfile: (profileId: string) => void;
generateDeviceLink: () => Promise<string>;
importFromDeviceLink: (token: string) => Promise<void>;
getWalletExtension: () => Promise<WalletUserExtension | null>;
hasUnencryptedBackupInSession: () => Promise<boolean>;
hasEncryptedBackupStored: () => Promise<boolean>;
isSessionBackupImported: () => Promise<boolean>;
storeGeneratedBackupForSignup: (backup: BapMasterBackup) => Promise<void>;
setStep: (step: AuthStep) => void;
setMode: (mode: AuthMode) => void;
reset: () => void;
}
export interface AuthError {
code: AuthErrorCode;
message: string;
details?: Error | Record<string, unknown>;
}
export type AuthErrorCode = "INVALID_PASSWORD" | "BACKUP_NOT_FOUND" | "OAUTH_CONFLICT" | "NETWORK_ERROR" | "INVALID_BACKUP" | "UNSUPPORTED_BACKUP" | "ENCRYPTION_ERROR" | "STORAGE_ERROR" | "API_ERROR" | "AUTH_REQUIRED" | "PROFILE_NOT_FOUND" | "INVALID_TOKEN" | "UNKNOWN_ERROR";
export type AuthEvent = {
type: "AUTH_STARTED";
} | {
type: "AUTH_SUCCESS";
user: AuthUser;
} | {
type: "AUTH_FAILED";
error: AuthError;
} | {
type: "BACKUP_GENERATED";
backup: BapMasterBackup;
} | {
type: "BACKUP_IMPORTED";
} | {
type: "OAUTH_LINKED";
provider: OAuthProvider;
} | {
type: "OAUTH_UNLINKED";
provider: OAuthProvider;
} | {
type: "PROFILE_CREATED";
profile: ProfileInfo;
} | {
type: "PROFILE_SWITCHED";
profileId: string;
} | {
type: "STEP_CHANGED";
step: AuthStep;
} | {
type: "MODE_CHANGED";
mode: AuthMode;
};
export interface AuthButtonProps {
mode?: "signin" | "signup" | "signout";
className?: string;
style?: React.CSSProperties;
children?: React.ReactNode;
size?: "default" | "sm" | "lg" | "icon";
variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | "link";
color?: string;
confirmSignOut?: boolean;
confirmMessage?: string;
redirectTo?: string;
onSignOut?: () => void;
showClearInfo?: boolean;
}
export interface LoginFormProps {
mode?: "signin" | "signup" | "restore";
onSuccess?: (user: AuthUser) => void;
onError?: (error: AuthError) => void;
className?: string;
style?: React.CSSProperties;
cardProps?: {
size?: "1" | "2" | "3" | "4";
variant?: "classic" | "surface";
};
buttonProps?: {
size?: ButtonProps["size"];
variant?: ButtonProps["variant"];
};
enableProfileSync?: boolean;
maxDiscoveryAttempts?: number;
}
export interface ColorPalette {
primary: string;
secondary: string;
background: string;
surface: string;
error: string;
warning: string;
success: string;
text: {
primary: string;
secondary: string;
disabled: string;
};
border: string;
}
export interface Typography {
fontFamily: string;
fontSize: {
xs: string;
sm: string;
base: string;
lg: string;
xl: string;
"2xl": string;
};
fontWeight: {
normal: number;
medium: number;
semibold: number;
bold: number;
};
}
export interface SpacingScale {
xs: string;
sm: string;
md: string;
lg: string;
xl: string;
"2xl": string;
}
export interface ComponentStyles {
button?: {
borderRadius?: string;
padding?: string;
fontSize?: string;
fontWeight?: number;
};
input?: {
borderRadius?: string;
padding?: string;
fontSize?: string;
};
card?: {
borderRadius?: string;
padding?: string;
border?: string;
};
}
export declare enum ErrorType {
BACKEND_SETUP = "BACKEND_SETUP",
VALIDATION = "VALIDATION",
NETWORK = "NETWORK",
AUTHENTICATION = "AUTHENTICATION",
GENERAL = "GENERAL"
}
export interface BigBlocksError {
message: string;
type?: ErrorType;
code?: string;
metadata?: Record<string, unknown>;
}
export declare const BACKEND_ERRORS: {
readonly CONNECTION_FAILED: "Cannot connect to backend. Make sure your server is running and /api/auth/signin endpoint exists. See examples/backend-setup-guide.md for setup help.";
readonly ENDPOINT_NOT_FOUND: "Backend endpoint not found. You need to implement POST /api/auth/signin in your backend. See examples/backend-setup-guide.md for help.";
};
//# sourceMappingURL=types.d.ts.map