pribado-seed-proxy-sdk 2.0.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.
@@ -0,0 +1,489 @@
1
+ /**
2
+ * Pribado Seed Proxy SDK
3
+ *
4
+ * Types and Interfaces for Oasis Sapphire integration
5
+ *
6
+ * @author Ralph Lawrence Pecayo
7
+ */
8
+ /** Oasis Sapphire Mainnet Chain ID */
9
+ declare const SAPPHIRE_MAINNET_CHAIN_ID = 23294;
10
+ /** KeyBridgeV9 Contract Address on Sapphire Mainnet - Supports Seed Phrases AND Private Keys */
11
+ declare const CONTRACT_ADDRESS = "0xabE5D482AceFED95E0D37dA89bC63F941f02f9A0";
12
+ /** Key Types */
13
+ declare const KEY_TYPE_SEED = 0;
14
+ declare const KEY_TYPE_PRIVATE_KEY = 1;
15
+ type KeyType = 'seed' | 'privateKey';
16
+ interface SeedProxyConfig {
17
+ /** Base URL of the Seed Proxy API (e.g., 'https://your-instance.com' or 'http://localhost:3000') */
18
+ baseUrl: string;
19
+ /** API key for authentication (optional for some endpoints) */
20
+ apiKey?: string;
21
+ /** Storage type preference: 'sapphire' (on-chain TEE) or 'l2s' (off-chain encrypted) */
22
+ defaultStorage?: 'sapphire' | 'l2s';
23
+ /** Request timeout in milliseconds (default: 30000) */
24
+ timeout?: number;
25
+ }
26
+ interface VaultInfo {
27
+ /** Unique vault identifier */
28
+ id: string;
29
+ /** Vault index (positive for Sapphire, negative for L2S) */
30
+ index: number;
31
+ /** Human-readable label */
32
+ label: string;
33
+ /** Unix timestamp (ms) when created */
34
+ createdAt: number;
35
+ /** Unix timestamp (ms) when last used */
36
+ lastUsed: number;
37
+ /** Number of message signatures */
38
+ signatureCount: number;
39
+ /** Number of logins */
40
+ loginCount: number;
41
+ /** Whether vault is active */
42
+ isActive: boolean;
43
+ /** Storage type */
44
+ type: 'sapphire' | 'l2s';
45
+ /** Key type: 'seed' for seed phrase, 'privateKey' for Ethereum private key */
46
+ keyType?: KeyType;
47
+ }
48
+ interface RegisterVaultParams {
49
+ /**
50
+ * The secret to encrypt - can be either:
51
+ * - Seed phrase (12 or 24 words)
52
+ * - Private key (0x + 64 hex chars)
53
+ */
54
+ secret: string;
55
+ /** @deprecated Use 'secret' instead. Alias for seed phrase. */
56
+ seedPhrase?: string;
57
+ /** Password for encryption */
58
+ password: string;
59
+ /** Human-readable label for the vault */
60
+ label?: string;
61
+ /** Owner's wallet address */
62
+ ownerAddress: string;
63
+ /** Storage type: 'sapphire' or 'l2s' */
64
+ storageType?: 'sapphire' | 'l2s';
65
+ /**
66
+ * Key type: auto-detected if not provided
67
+ * - 'seed' for seed phrase
68
+ * - 'privateKey' for Ethereum private key
69
+ */
70
+ keyType?: KeyType;
71
+ }
72
+ interface RegisterVaultResult {
73
+ /** Success status */
74
+ success: boolean;
75
+ /** The proxy key ID (priv_xxx or priv_secret_xxx) */
76
+ proxyKeyId: string;
77
+ /** Vault index */
78
+ vaultIndex?: number;
79
+ /** Transaction hash (for Sapphire only) */
80
+ txHash?: string;
81
+ /** Error message if failed */
82
+ error?: string;
83
+ }
84
+ interface AuthenticateParams {
85
+ /** The proxy key ID */
86
+ proxyKeyId: string;
87
+ /** Password for decryption */
88
+ password: string;
89
+ }
90
+ interface AuthenticateResult {
91
+ /** Success status */
92
+ success: boolean;
93
+ /** The recovered seed phrase (only on success) */
94
+ seedPhrase?: string;
95
+ /** New rotated proxy key ID */
96
+ newProxyKeyId?: string;
97
+ /** Error message if failed */
98
+ error?: string;
99
+ }
100
+ interface SignMessageParams {
101
+ /** The proxy key ID */
102
+ proxyKeyId: string;
103
+ /** Password for authentication */
104
+ password: string;
105
+ /** Message to sign (string or hex) */
106
+ message: string;
107
+ }
108
+ interface SignMessageResult {
109
+ /** Success status */
110
+ success: boolean;
111
+ /** The signature (0x-prefixed hex) */
112
+ signature?: string;
113
+ /** Signature components */
114
+ v?: number;
115
+ r?: string;
116
+ s?: string;
117
+ /** New rotated proxy key ID (CRITICAL: User must save this) */
118
+ newProxyKeyId?: string;
119
+ /** The address that signed the message */
120
+ signerAddress?: string;
121
+ /** Error message if failed */
122
+ error?: string;
123
+ }
124
+ interface SignTransactionParams {
125
+ /** The proxy key ID */
126
+ proxyKeyId: string;
127
+ /** Password for authentication */
128
+ password: string;
129
+ /** Transaction object */
130
+ transaction: {
131
+ to: string;
132
+ value?: string;
133
+ data?: string;
134
+ nonce?: number;
135
+ gasLimit?: string;
136
+ gasPrice?: string;
137
+ maxFeePerGas?: string;
138
+ maxPriorityFeePerGas?: string;
139
+ chainId?: number;
140
+ };
141
+ }
142
+ interface SignTransactionResult {
143
+ /** Success status */
144
+ success: boolean;
145
+ /** Signed transaction (serialized, ready to broadcast) */
146
+ signedTransaction?: string;
147
+ /** Signature */
148
+ signature?: string;
149
+ /** Error message if failed */
150
+ error?: string;
151
+ }
152
+ interface VerifyKeyParams {
153
+ /** The proxy key ID to verify */
154
+ proxyKeyId: string;
155
+ }
156
+ interface VerifyKeyResult {
157
+ /** Whether the key exists */
158
+ exists: boolean;
159
+ /** Whether the key is valid */
160
+ valid: boolean;
161
+ /** Whether the key is active (not revoked) */
162
+ isActive: boolean;
163
+ /** Vault index */
164
+ vaultIndex?: number;
165
+ /** Key type */
166
+ type?: 'sapphire' | 'l2s';
167
+ /** Error message if any */
168
+ error?: string;
169
+ }
170
+ interface RotateKeyParams {
171
+ /** Current proxy key ID */
172
+ proxyKeyId: string;
173
+ /** Password for authentication */
174
+ password: string;
175
+ }
176
+ interface RotateKeyResult {
177
+ /** Success status */
178
+ success: boolean;
179
+ /** New proxy key ID */
180
+ newProxyKeyId?: string;
181
+ /** Error message if failed */
182
+ error?: string;
183
+ }
184
+ interface RevokeKeyParams {
185
+ /** The proxy key ID to revoke */
186
+ proxyKeyId: string;
187
+ /** Password for authentication */
188
+ password: string;
189
+ }
190
+ interface RevokeKeyResult {
191
+ /** Success status */
192
+ success: boolean;
193
+ /** Transaction hash (for Sapphire) */
194
+ txHash?: string;
195
+ /** Error message if failed */
196
+ error?: string;
197
+ }
198
+ interface ApiResponse<T = unknown> {
199
+ success: boolean;
200
+ data?: T;
201
+ error?: string;
202
+ message?: string;
203
+ }
204
+ declare enum SeedProxyErrorCode {
205
+ INVALID_CONFIG = "INVALID_CONFIG",
206
+ MISSING_API_KEY = "MISSING_API_KEY",
207
+ INVALID_PASSWORD = "INVALID_PASSWORD",
208
+ INVALID_KEY = "INVALID_KEY",
209
+ KEY_NOT_FOUND = "KEY_NOT_FOUND",
210
+ KEY_INACTIVE = "KEY_INACTIVE",
211
+ AUTHENTICATION_FAILED = "AUTHENTICATION_FAILED",
212
+ INVALID_SEED_PHRASE = "INVALID_SEED_PHRASE",
213
+ INVALID_PRIVATE_KEY = "INVALID_PRIVATE_KEY",
214
+ INVALID_ADDRESS = "INVALID_ADDRESS",
215
+ INVALID_TRANSACTION = "INVALID_TRANSACTION",
216
+ REGISTRATION_FAILED = "REGISTRATION_FAILED",
217
+ SIGNING_FAILED = "SIGNING_FAILED",
218
+ ROTATION_FAILED = "ROTATION_FAILED",
219
+ REVOCATION_FAILED = "REVOCATION_FAILED",
220
+ NETWORK_ERROR = "NETWORK_ERROR",
221
+ TIMEOUT = "TIMEOUT",
222
+ RATE_LIMITED = "RATE_LIMITED",
223
+ GAS_LIMIT_EXCEEDED = "GAS_LIMIT_EXCEEDED"
224
+ }
225
+ declare class SeedProxyError extends Error {
226
+ code: SeedProxyErrorCode;
227
+ cause?: Error | undefined;
228
+ constructor(message: string, code: SeedProxyErrorCode, cause?: Error | undefined);
229
+ }
230
+
231
+ /**
232
+ * Pribado Seed Proxy SDK
233
+ *
234
+ * Main Client Class - HTTP-based integration for secure seed management
235
+ *
236
+ * @author Ralph Lawrence Pecayo
237
+ * @license MIT
238
+ */
239
+
240
+ declare class SeedProxyClient {
241
+ private config;
242
+ private abortController;
243
+ constructor(config: SeedProxyConfig);
244
+ /**
245
+ * Register a new seed phrase vault
246
+ *
247
+ * The seed phrase is encrypted client-side before being sent to the server.
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * const result = await client.registerVault({
252
+ * seedPhrase: 'word1 word2 ... word12',
253
+ * password: 'secure-password',
254
+ * label: 'My Main Wallet',
255
+ * ownerAddress: '0x...',
256
+ * storageType: 'l2s' // or 'sapphire'
257
+ * });
258
+ *
259
+ * console.log('Proxy Key:', result.proxyKeyId);
260
+ * // Save this key securely - it's needed for authentication
261
+ * ```
262
+ */
263
+ registerVault(params: RegisterVaultParams): Promise<RegisterVaultResult>;
264
+ /**
265
+ * Authenticate using a proxy key to recover the seed phrase
266
+ *
267
+ * This also rotates the key for security (one-time use).
268
+ *
269
+ * @example
270
+ * ```typescript
271
+ * const result = await client.authenticate({
272
+ * proxyKeyId: 'priv_abc123...',
273
+ * password: 'your-password'
274
+ * });
275
+ *
276
+ * if (result.success) {
277
+ * console.log('Seed:', result.seedPhrase);
278
+ * console.log('New Key:', result.newProxyKeyId);
279
+ * // Store the new key for next login
280
+ * }
281
+ * ```
282
+ */
283
+ authenticate(params: AuthenticateParams): Promise<AuthenticateResult>;
284
+ /**
285
+ * Verify if a proxy key exists and is active
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * const result = await client.verifyKey({ proxyKeyId: 'priv_abc123...' });
290
+ *
291
+ * if (result.valid && result.isActive) {
292
+ * console.log('Key is valid and can be used');
293
+ * }
294
+ * ```
295
+ */
296
+ verifyKey(params: VerifyKeyParams): Promise<VerifyKeyResult>;
297
+ /**
298
+ * Rotate a proxy key (invalidates old key, generates new one)
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * const result = await client.rotateKey({
303
+ * proxyKeyId: 'priv_old...',
304
+ * password: 'your-password'
305
+ * });
306
+ *
307
+ * console.log('New key:', result.newProxyKeyId);
308
+ * ```
309
+ */
310
+ rotateKey(params: RotateKeyParams): Promise<RotateKeyResult>;
311
+ /**
312
+ * Permanently revoke a proxy key
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * const result = await client.revokeKey({
317
+ * proxyKeyId: 'priv_abc123...',
318
+ * password: 'your-password'
319
+ * });
320
+ * ```
321
+ */
322
+ revokeKey(params: RevokeKeyParams): Promise<RevokeKeyResult>;
323
+ /**
324
+ * List all vaults for an owner address
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * const vaults = await client.listVaults('0x...');
329
+ *
330
+ * for (const vault of vaults) {
331
+ * console.log(vault.label, vault.type, vault.isActive);
332
+ * }
333
+ * ```
334
+ */
335
+ listVaults(ownerAddress: string): Promise<VaultInfo[]>;
336
+ /**
337
+ * Sign a message using the seed stored in a vault
338
+ *
339
+ * This decrypts the seed temporarily to sign, then clears it from memory.
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * const result = await client.signMessage({
344
+ * proxyKeyId: 'priv_abc123...',
345
+ * password: 'your-password',
346
+ * message: 'Hello, World!'
347
+ * });
348
+ *
349
+ * console.log('Signature:', result.signature);
350
+ * ```
351
+ */
352
+ signMessage(params: SignMessageParams): Promise<SignMessageResult>;
353
+ /**
354
+ * Sign a transaction using the seed stored in a vault
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * const result = await client.signTransaction({
359
+ * proxyKeyId: 'priv_abc123...',
360
+ * password: 'your-password',
361
+ * transaction: {
362
+ * to: '0x...',
363
+ * value: '1000000000000000000', // 1 ETH in wei
364
+ * chainId: 1
365
+ * }
366
+ * });
367
+ *
368
+ * // Broadcast the signed transaction
369
+ * const txHash = await provider.sendTransaction(result.signedTransaction);
370
+ * ```
371
+ */
372
+ signTransaction(params: SignTransactionParams): Promise<SignTransactionResult>;
373
+ /**
374
+ * Get the configured base URL
375
+ */
376
+ getBaseUrl(): string;
377
+ /**
378
+ * Get the default storage type
379
+ */
380
+ getDefaultStorage(): 'sapphire' | 'l2s';
381
+ /**
382
+ * Cancel any pending requests
383
+ */
384
+ cancelPendingRequests(): void;
385
+ private request;
386
+ }
387
+ /**
388
+ * Create a new Seed Proxy client instance
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * import { createSeedProxyClient } from '@pribado/seed-proxy-sdk';
393
+ *
394
+ * const client = createSeedProxyClient({
395
+ * baseUrl: 'https://your-pribado-instance.com',
396
+ * defaultStorage: 'l2s'
397
+ * });
398
+ * ```
399
+ */
400
+ declare function createSeedProxyClient(config: SeedProxyConfig): SeedProxyClient;
401
+
402
+ /**
403
+ * Pribado Seed Proxy SDK
404
+ *
405
+ * Cryptographic utilities for client-side encryption
406
+ *
407
+ * @author Ralph Lawrence Pecayo
408
+ */
409
+ /**
410
+ * Validate a BIP39 seed phrase
411
+ */
412
+ declare function validateSeedPhrase(phrase: string): boolean;
413
+ /**
414
+ * Validate an Ethereum private key
415
+ */
416
+ declare function validatePrivateKey(key: string): boolean;
417
+ /**
418
+ * Validate an Ethereum address
419
+ */
420
+ declare function validateAddress(address: string): boolean;
421
+ /**
422
+ * Generate a random proxy key ID
423
+ */
424
+ declare function generateProxyKeyId(isL2S?: boolean): string;
425
+ /**
426
+ * Hash a proxy key ID for storage/lookup
427
+ */
428
+ declare function hashProxyKey(proxyKeyId: string): string;
429
+ /**
430
+ * Parse a proxy key to bytes32 format
431
+ */
432
+ declare function parseProxyKey(proxyKeyId: string): string;
433
+ /**
434
+ * Encrypt a seed phrase with password (client-side, before sending to server)
435
+ *
436
+ * @param seedPhrase - The seed phrase to encrypt
437
+ * @param password - User's password
438
+ * @returns Encrypted blob (base64 encoded)
439
+ */
440
+ declare function encryptSeedPhrase(seedPhrase: string, password: string): Promise<string>;
441
+ /**
442
+ * Decrypt an encrypted seed phrase (client-side)
443
+ *
444
+ * @param encryptedBlob - Base64 encoded encrypted data
445
+ * @param password - User's password
446
+ * @returns Decrypted seed phrase
447
+ */
448
+ declare function decryptSeedPhrase(encryptedBlob: string, password: string): Promise<string>;
449
+ /**
450
+ * Encode a seed phrase into 12 bytes32 words for Sapphire contract
451
+ */
452
+ declare function encodeSeedWords(seedPhrase: string): {
453
+ words: string[];
454
+ count: number;
455
+ };
456
+ /**
457
+ * Decode bytes32 words back to seed phrase
458
+ */
459
+ declare function decodeSeedWords(words: string[], count: number): string;
460
+ /**
461
+ * Hash owner address to bytes32
462
+ */
463
+ declare function hashOwner(address: string): string;
464
+ /**
465
+ * Convert label string to bytes32
466
+ */
467
+ declare function labelToBytes32(label: string): string;
468
+ /**
469
+ * Convert bytes32 to label string
470
+ */
471
+ declare function bytes32ToLabel(bytes32: string): string;
472
+ /**
473
+ * Derive wallet address from seed phrase
474
+ */
475
+ declare function deriveAddress(seedPhrase: string): string;
476
+
477
+ /**
478
+ * Pribado Seed Proxy SDK
479
+ *
480
+ * Secure encrypted endpoints for Web3 wallets
481
+ *
482
+ * @packageDocumentation
483
+ * @author Ralph Lawrence Pecayo
484
+ * @license MIT
485
+ */
486
+
487
+ declare const VERSION = "2.0.0";
488
+
489
+ export { type ApiResponse, type AuthenticateParams, type AuthenticateResult, CONTRACT_ADDRESS, KEY_TYPE_PRIVATE_KEY, KEY_TYPE_SEED, type KeyType, type RegisterVaultParams, type RegisterVaultResult, type RevokeKeyParams, type RevokeKeyResult, type RotateKeyParams, type RotateKeyResult, SAPPHIRE_MAINNET_CHAIN_ID, SeedProxyClient, type SeedProxyConfig, SeedProxyError, SeedProxyErrorCode, type SignMessageParams, type SignMessageResult, type SignTransactionParams, type SignTransactionResult, VERSION, type VaultInfo, type VerifyKeyParams, type VerifyKeyResult, bytes32ToLabel, createSeedProxyClient, decodeSeedWords, decryptSeedPhrase, createSeedProxyClient as default, deriveAddress, encodeSeedWords, encryptSeedPhrase, generateProxyKeyId, hashOwner, hashProxyKey, labelToBytes32, parseProxyKey, validateAddress, validatePrivateKey, validateSeedPhrase };