w3pk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +673 -0
- package/README.md +461 -0
- package/dist/index.d.mts +171 -0
- package/dist/index.d.ts +171 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +36 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types used across the SDK
|
|
3
|
+
*/
|
|
4
|
+
interface UserInfo {
|
|
5
|
+
id: string;
|
|
6
|
+
username: string;
|
|
7
|
+
ethereumAddress: string;
|
|
8
|
+
}
|
|
9
|
+
interface WalletInfo {
|
|
10
|
+
address: string;
|
|
11
|
+
mnemonic: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Custom error classes for better error handling
|
|
16
|
+
*/
|
|
17
|
+
declare class Web3PasskeyError extends Error {
|
|
18
|
+
code: string;
|
|
19
|
+
originalError?: unknown | undefined;
|
|
20
|
+
constructor(message: string, code: string, originalError?: unknown | undefined);
|
|
21
|
+
}
|
|
22
|
+
declare class AuthenticationError extends Web3PasskeyError {
|
|
23
|
+
constructor(message: string, originalError?: unknown);
|
|
24
|
+
}
|
|
25
|
+
declare class RegistrationError extends Web3PasskeyError {
|
|
26
|
+
constructor(message: string, originalError?: unknown);
|
|
27
|
+
}
|
|
28
|
+
declare class WalletError extends Web3PasskeyError {
|
|
29
|
+
constructor(message: string, originalError?: unknown);
|
|
30
|
+
}
|
|
31
|
+
declare class CryptoError extends Web3PasskeyError {
|
|
32
|
+
constructor(message: string, originalError?: unknown);
|
|
33
|
+
}
|
|
34
|
+
declare class StorageError extends Web3PasskeyError {
|
|
35
|
+
constructor(message: string, originalError?: unknown);
|
|
36
|
+
}
|
|
37
|
+
declare class ApiError extends Web3PasskeyError {
|
|
38
|
+
statusCode?: number | undefined;
|
|
39
|
+
constructor(message: string, statusCode?: number | undefined, originalError?: unknown);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* SDK Configuration
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
interface Web3PasskeyConfig {
|
|
47
|
+
/**
|
|
48
|
+
* Base URL of the WebAuthn API
|
|
49
|
+
* @example 'https://webauthn.w3hc.org'
|
|
50
|
+
*/
|
|
51
|
+
apiBaseUrl: string;
|
|
52
|
+
/**
|
|
53
|
+
* Timeout for API requests in milliseconds
|
|
54
|
+
* @default 30000
|
|
55
|
+
*/
|
|
56
|
+
timeout?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Enable debug logging
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
debug?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Custom error handler
|
|
64
|
+
*/
|
|
65
|
+
onError?: (error: Web3PasskeyError) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Auth state change callback
|
|
68
|
+
*/
|
|
69
|
+
onAuthStateChanged?: (isAuthenticated: boolean, user?: UserInfo) => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Authentication-related types
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
interface AuthResult {
|
|
77
|
+
verified: boolean;
|
|
78
|
+
user?: {
|
|
79
|
+
id: string;
|
|
80
|
+
username: string;
|
|
81
|
+
ethereumAddress: string;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Main Web3Passkey SDK class
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
declare class Web3Passkey {
|
|
90
|
+
private config;
|
|
91
|
+
private apiClient;
|
|
92
|
+
private walletStorage;
|
|
93
|
+
private walletSigner;
|
|
94
|
+
private currentUser;
|
|
95
|
+
private isAuthenticatedState;
|
|
96
|
+
private isBrowser;
|
|
97
|
+
constructor(config: Web3PasskeyConfig);
|
|
98
|
+
private loadAuthState;
|
|
99
|
+
private saveAuthState;
|
|
100
|
+
private clearAuthState;
|
|
101
|
+
private notifyAuthStateChange;
|
|
102
|
+
/**
|
|
103
|
+
* Generate a new BIP39 wallet
|
|
104
|
+
* @returns Wallet info with mnemonic (user MUST backup)
|
|
105
|
+
*/
|
|
106
|
+
generateWallet(): Promise<WalletInfo>;
|
|
107
|
+
/**
|
|
108
|
+
* Check if wallet exists for current user
|
|
109
|
+
*/
|
|
110
|
+
hasWallet(): Promise<boolean>;
|
|
111
|
+
/**
|
|
112
|
+
* Register a new user with WebAuthn
|
|
113
|
+
* @param username Username for the account
|
|
114
|
+
* @param ethereumAddress Ethereum address from generated wallet
|
|
115
|
+
* @param mnemonic BIP39 mnemonic to encrypt and store
|
|
116
|
+
* @param credentialId WebAuthn credential ID (from registration response)
|
|
117
|
+
* @param challenge Challenge used in registration
|
|
118
|
+
*/
|
|
119
|
+
register(options: {
|
|
120
|
+
username: string;
|
|
121
|
+
ethereumAddress: string;
|
|
122
|
+
mnemonic: string;
|
|
123
|
+
credentialId: string;
|
|
124
|
+
challenge: string;
|
|
125
|
+
}): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Authenticate with Ethereum address
|
|
128
|
+
*/
|
|
129
|
+
authenticate(ethereumAddress: string): Promise<AuthResult>;
|
|
130
|
+
/**
|
|
131
|
+
* Authenticate without username (usernameless flow)
|
|
132
|
+
*/
|
|
133
|
+
authenticateUsernameless(): Promise<AuthResult>;
|
|
134
|
+
/**
|
|
135
|
+
* Logout current user
|
|
136
|
+
*/
|
|
137
|
+
logout(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Sign a message with encrypted wallet
|
|
140
|
+
* Requires fresh WebAuthn authentication
|
|
141
|
+
* @param message Message to sign
|
|
142
|
+
* @param credentialId WebAuthn credential ID (from fresh auth)
|
|
143
|
+
* @param challenge Challenge from fresh auth
|
|
144
|
+
*/
|
|
145
|
+
signMessage(message: string, credentialId: string, challenge: string): Promise<string>;
|
|
146
|
+
/**
|
|
147
|
+
* Check if user is authenticated
|
|
148
|
+
*/
|
|
149
|
+
get isAuthenticated(): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Get current user info
|
|
152
|
+
*/
|
|
153
|
+
get user(): UserInfo | null;
|
|
154
|
+
/**
|
|
155
|
+
* Get SDK version
|
|
156
|
+
*/
|
|
157
|
+
get version(): string;
|
|
158
|
+
/**
|
|
159
|
+
* Check if running in browser environment
|
|
160
|
+
*/
|
|
161
|
+
get isBrowserEnvironment(): boolean;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* w3pk - Web3 Passkey SDK
|
|
166
|
+
* WebAuthn SDK for passwordless authentication and encrypted wallet management
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
declare function createWeb3Passkey(config: Web3PasskeyConfig): Web3Passkey;
|
|
170
|
+
|
|
171
|
+
export { ApiError, type AuthResult, AuthenticationError, CryptoError, RegistrationError, StorageError, type UserInfo, WalletError, type WalletInfo, Web3Passkey, type Web3PasskeyConfig, Web3PasskeyError, createWeb3Passkey, createWeb3Passkey as default };
|