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.
- package/README.md +397 -0
- package/dist/index.d.mts +489 -0
- package/dist/index.d.ts +489 -0
- package/dist/index.js +829 -0
- package/dist/index.mjs +780 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
# Pribado Seed Proxy SDK
|
|
2
|
+
|
|
3
|
+
**Zero-Knowledge Key Bridge SDK**
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://www.npmjs.com/package/pribado-seed-proxy-sdk)
|
|
7
|
+
|
|
8
|
+
> Securely manage Web3 seed phrases and private keys with client-side encryption and Oasis Sapphire TEEs.
|
|
9
|
+
|
|
10
|
+
The Pribado Seed Proxy SDK allows any wallet or application to create secure, encrypted endpoints for seed phrase and private key management. Your secrets are encrypted client-side and stored securely on Oasis Sapphire TEE or off-chain (L2S), accessible only with your password.
|
|
11
|
+
|
|
12
|
+
**V2.0.0:** Now supports both **Seed Phrases** and **Private Keys**!
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Why Seed Proxy?
|
|
17
|
+
|
|
18
|
+
**The Problem:**
|
|
19
|
+
- Seed phrases stored in plain text in wallet extensions
|
|
20
|
+
- Private keys vulnerable to malware and phishing
|
|
21
|
+
- One compromised device = all funds lost
|
|
22
|
+
|
|
23
|
+
**The Solution:**
|
|
24
|
+
- Keys encrypted client-side before storage
|
|
25
|
+
- Signing happens inside hardware TEE (Trusted Execution Environment)
|
|
26
|
+
- Real key NEVER leaves the secure enclave
|
|
27
|
+
- Proxy key ID can be safely used in applications
|
|
28
|
+
- **Auto-rotation** - Keys rotate after each use for maximum security
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **Client-Side Encryption** - Secrets are encrypted in the browser before transmission
|
|
35
|
+
- **Dual Support** - Store seed phrases (12/24 words) OR private keys (0x...)
|
|
36
|
+
- **Auto Key Rotation** - Proxy keys automatically rotate after each use
|
|
37
|
+
- **Multi-Storage** - Choose between Oasis Sapphire (TEE) or L2S (off-chain encrypted)
|
|
38
|
+
- **Easy Integration** - Simple HTTP-based API for any platform
|
|
39
|
+
- **Zero-Knowledge** - Server never sees your unencrypted secrets
|
|
40
|
+
- **L2S: No Gas Fees** - Off-chain storage for cost-sensitive applications
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install pribado-seed-proxy-sdk
|
|
48
|
+
# or
|
|
49
|
+
yarn add pribado-seed-proxy-sdk
|
|
50
|
+
# or
|
|
51
|
+
pnpm add pribado-seed-proxy-sdk
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Quick Start
|
|
57
|
+
|
|
58
|
+
### Register a Seed Phrase
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { createSeedProxyClient } from 'pribado-seed-proxy-sdk';
|
|
62
|
+
|
|
63
|
+
const client = createSeedProxyClient({
|
|
64
|
+
baseUrl: 'https://your-pribado-instance.com',
|
|
65
|
+
defaultStorage: 'l2s'
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const result = await client.registerVault({
|
|
69
|
+
secret: 'word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12',
|
|
70
|
+
password: 'your-secure-password',
|
|
71
|
+
label: 'My Main Wallet',
|
|
72
|
+
ownerAddress: '0x...'
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
console.log('Save this proxy key:', result.proxyKeyId);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Register a Private Key
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const result = await client.registerVault({
|
|
82
|
+
secret: '0xa8b294d1c5977795c9be902d5a57210c458fbf42d7a091aa70a1a28c12747335',
|
|
83
|
+
password: 'your-secure-password',
|
|
84
|
+
label: 'Trading Bot Key',
|
|
85
|
+
ownerAddress: '0x...',
|
|
86
|
+
storageType: 'sapphire' // TEE storage for maximum security
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
console.log('Proxy key:', result.proxyKeyId);
|
|
90
|
+
// Key type is auto-detected as 'privateKey'
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## How It Works
|
|
96
|
+
|
|
97
|
+
### Architecture
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
101
|
+
│ YOUR DEVICE │
|
|
102
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
103
|
+
│ ┌─────────────┐ ┌──────────────────┐ ┌──────────────┐ │
|
|
104
|
+
│ │ Wallet │────▶│ Pribado SDK │────▶│ Proxy Key │ │
|
|
105
|
+
│ │ │ │ │ │ priv_xxx │ │
|
|
106
|
+
│ └─────────────┘ └────────┬─────────┘ └──────────────┘ │
|
|
107
|
+
└───────────────────────────────┼─────────────────────────────────┘
|
|
108
|
+
│
|
|
109
|
+
▼
|
|
110
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
111
|
+
│ OASIS SAPPHIRE (TEE) │
|
|
112
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
113
|
+
│ ┌──────────────────────────────────────────────────────────┐ │
|
|
114
|
+
│ │ Your encrypted key stored here │ │
|
|
115
|
+
│ │ Signing happens INSIDE the hardware enclave │ │
|
|
116
|
+
│ │ Real key NEVER exposed to anyone │ │
|
|
117
|
+
│ └──────────────────────────────────────────────────────────┘ │
|
|
118
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Usage
|
|
124
|
+
|
|
125
|
+
### Register a Vault
|
|
126
|
+
|
|
127
|
+
Store your seed phrase securely:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const result = await client.registerVault({
|
|
131
|
+
seedPhrase: 'your twelve word seed phrase here ...',
|
|
132
|
+
password: 'minimum-6-chars',
|
|
133
|
+
label: 'Wallet Name',
|
|
134
|
+
ownerAddress: '0xYourWalletAddress',
|
|
135
|
+
storageType: 'l2s' // 'l2s' (off-chain) or 'sapphire' (on-chain TEE)
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (result.success) {
|
|
139
|
+
// IMPORTANT: Store this proxy key securely!
|
|
140
|
+
// You'll need it + password to access your seed
|
|
141
|
+
console.log('Proxy Key:', result.proxyKeyId);
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Authenticate (Login)
|
|
146
|
+
|
|
147
|
+
Recover your seed phrase and get a new rotation key:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
const result = await client.authenticate({
|
|
151
|
+
proxyKeyId: 'priv_secret...',
|
|
152
|
+
password: 'your-password'
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
if (result.success) {
|
|
156
|
+
// Your decrypted seed phrase
|
|
157
|
+
console.log('Seed:', result.seedPhrase);
|
|
158
|
+
|
|
159
|
+
// IMPORTANT: Store the new key for next login!
|
|
160
|
+
// The old key is now invalid
|
|
161
|
+
console.log('New Key:', result.newProxyKeyId);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Verify a Key
|
|
166
|
+
|
|
167
|
+
Check if a proxy key is valid before using:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const result = await client.verifyKey({
|
|
171
|
+
proxyKeyId: 'priv_...'
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
if (result.valid && result.isActive) {
|
|
175
|
+
console.log('Key is valid and ready to use');
|
|
176
|
+
} else if (!result.isActive) {
|
|
177
|
+
console.log('Key has been revoked or already used');
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Sign a Message
|
|
182
|
+
|
|
183
|
+
Sign messages using your stored seed:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const result = await client.signMessage({
|
|
187
|
+
proxyKeyId: 'priv_...',
|
|
188
|
+
password: 'your-password',
|
|
189
|
+
message: 'Hello, Web3!'
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
console.log('Signature:', result.signature);
|
|
193
|
+
// 0x1234...
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Sign a Transaction
|
|
197
|
+
|
|
198
|
+
Sign transactions without exposing your seed:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { SAPPHIRE_MAINNET_CHAIN_ID } from '@pribado/seed-proxy-sdk';
|
|
202
|
+
|
|
203
|
+
const result = await client.signTransaction({
|
|
204
|
+
proxyKeyId: 'priv_...',
|
|
205
|
+
password: 'your-password',
|
|
206
|
+
transaction: {
|
|
207
|
+
to: '0xRecipient...',
|
|
208
|
+
value: '1000000000000000000', // 1 ROSE in wei
|
|
209
|
+
chainId: SAPPHIRE_MAINNET_CHAIN_ID // 23294 (use 23295 for Testnet)
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Broadcast the signed transaction
|
|
214
|
+
const txHash = await provider.sendTransaction(result.signedTransaction);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### List All Vaults
|
|
218
|
+
|
|
219
|
+
Get all vaults for an owner address:
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
const vaults = await client.listVaults('0xOwnerAddress');
|
|
223
|
+
|
|
224
|
+
for (const vault of vaults) {
|
|
225
|
+
console.log(`${vault.label}: ${vault.type}, Active: ${vault.isActive}`);
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Rotate Key Manually
|
|
230
|
+
|
|
231
|
+
Rotate a key without authentication:
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
const result = await client.rotateKey({
|
|
235
|
+
proxyKeyId: 'priv_old...',
|
|
236
|
+
password: 'your-password'
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
console.log('New Key:', result.newProxyKeyId);
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Revoke a Key
|
|
243
|
+
|
|
244
|
+
Permanently disable a proxy key:
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
const result = await client.revokeKey({
|
|
248
|
+
proxyKeyId: 'priv_...',
|
|
249
|
+
password: 'your-password'
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
if (result.success) {
|
|
253
|
+
console.log('Key has been revoked');
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Storage Types
|
|
260
|
+
|
|
261
|
+
### L2S (Layer 2 Storage)
|
|
262
|
+
- **Off-chain** encrypted storage
|
|
263
|
+
- **No gas fees** for registration or rotation
|
|
264
|
+
- **Fast** operations
|
|
265
|
+
- **Proxy key format:** `priv_secret...`
|
|
266
|
+
- Best for: High-frequency use, cost-sensitive applications
|
|
267
|
+
|
|
268
|
+
### Sapphire (TEE)
|
|
269
|
+
- **On-chain** storage on Oasis Sapphire
|
|
270
|
+
- **Hardware-level** security via Trusted Execution Environment
|
|
271
|
+
- **Decentralized** and tamper-proof
|
|
272
|
+
- **Proxy key format:** `priv_...`
|
|
273
|
+
- Best for: Maximum security, regulatory compliance
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## Oasis Sapphire Network
|
|
278
|
+
|
|
279
|
+
**Live Contract:** [`0x9B4aA4B40995bD93256E26706A12535851C4FD95`](https://explorer.oasis.io/mainnet/sapphire/address/0x9B4aA4B40995bD93256E26706A12535851C4FD95)
|
|
280
|
+
|
|
281
|
+
| Network | Chain ID | RPC URL |
|
|
282
|
+
|---------|----------|---------|
|
|
283
|
+
| Mainnet | 23294 | https://sapphire.oasis.io |
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import { SAPPHIRE_MAINNET_CHAIN_ID } from '@pribado/seed-proxy-sdk';
|
|
287
|
+
// SAPPHIRE_MAINNET_CHAIN_ID = 23294
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## Security Best Practices
|
|
293
|
+
|
|
294
|
+
1. **Never share your proxy key** - Treat it like a password
|
|
295
|
+
2. **Use strong passwords** - Minimum 8 characters, mix of letters/numbers/symbols
|
|
296
|
+
3. **Store new keys immediately** - Keys rotate after each use
|
|
297
|
+
4. **Revoke compromised keys** - If you suspect a breach, revoke immediately
|
|
298
|
+
5. **Use HTTPS** - Always connect to the API over HTTPS
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Error Handling
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
import { SeedProxyError, SeedProxyErrorCode } from '@pribado/seed-proxy-sdk';
|
|
306
|
+
|
|
307
|
+
try {
|
|
308
|
+
await client.authenticate({ ... });
|
|
309
|
+
} catch (error) {
|
|
310
|
+
if (error instanceof SeedProxyError) {
|
|
311
|
+
switch (error.code) {
|
|
312
|
+
case SeedProxyErrorCode.INVALID_PASSWORD:
|
|
313
|
+
console.log('Wrong password');
|
|
314
|
+
break;
|
|
315
|
+
case SeedProxyErrorCode.KEY_NOT_FOUND:
|
|
316
|
+
console.log('Key does not exist');
|
|
317
|
+
break;
|
|
318
|
+
case SeedProxyErrorCode.KEY_INACTIVE:
|
|
319
|
+
console.log('Key has been revoked');
|
|
320
|
+
break;
|
|
321
|
+
default:
|
|
322
|
+
console.log('Error:', error.message);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## API Reference
|
|
331
|
+
|
|
332
|
+
### `createSeedProxyClient(config)`
|
|
333
|
+
|
|
334
|
+
Create a new client instance.
|
|
335
|
+
|
|
336
|
+
| Parameter | Type | Required | Description |
|
|
337
|
+
|-----------|------|----------|-------------|
|
|
338
|
+
| `baseUrl` | string | Yes | Base URL of the Pribado API |
|
|
339
|
+
| `apiKey` | string | No | API key for authentication |
|
|
340
|
+
| `defaultStorage` | 'sapphire' \| 'l2s' | No | Default storage type (default: 'l2s') |
|
|
341
|
+
| `timeout` | number | No | Request timeout in ms (default: 30000) |
|
|
342
|
+
|
|
343
|
+
### Exported Constants
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
export const SAPPHIRE_MAINNET_CHAIN_ID = 23294;
|
|
347
|
+
export const CONTRACT_ADDRESS = '0x9B4aA4B40995bD93256E26706A12535851C4FD95';
|
|
348
|
+
export const VERSION = '1.0.0';
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## Self-Hosting
|
|
354
|
+
|
|
355
|
+
You can self-host the Pribado API to have full control over your data:
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
# Clone the repository
|
|
359
|
+
git clone https://github.com/0xrlawrence/pribado.git
|
|
360
|
+
|
|
361
|
+
# Install dependencies
|
|
362
|
+
npm install
|
|
363
|
+
|
|
364
|
+
# Configure environment
|
|
365
|
+
cp .env.local.example .env.local
|
|
366
|
+
# Edit .env.local with your settings
|
|
367
|
+
|
|
368
|
+
# Run the server
|
|
369
|
+
npm run dev
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
## Documentation
|
|
375
|
+
|
|
376
|
+
- [Security Model](./docs/SECURITY.md)
|
|
377
|
+
- [Integration Guide](./docs/INTEGRATION.md)
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
## License
|
|
382
|
+
|
|
383
|
+
MIT License - Copyright (c) 2025 Ralph Lawrence Pecayo
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## Links
|
|
388
|
+
|
|
389
|
+
- **Website:** [pribado.dev](https://pribado.dev)
|
|
390
|
+
- **GitHub:** [github.com/0xrlawrence/pribado](https://github.com/0xrlawrence/pribado)
|
|
391
|
+
- **Twitter:** [@0xrlawrence](https://twitter.com/0xrlawrence)
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
<p align="center">
|
|
396
|
+
<sub>Built with for Web3 privacy on Oasis Sapphire</sub>
|
|
397
|
+
</p>
|