@lumiapassport/core 1.14.2 → 1.14.3
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 +125 -108
- package/dist/internal/error-tracking.cjs +1 -1
- package/dist/internal/error-tracking.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,164 +7,164 @@ Framework-agnostic core SDK for Lumia Passport smart accounts.
|
|
|
7
7
|
- ✅ **Zero React dependencies** - Works in Node.js, browser, and edge functions
|
|
8
8
|
- ✅ **TypeScript-first** - Full type safety
|
|
9
9
|
- ✅ **Modular** - Import only what you need
|
|
10
|
-
- ✅ **Storage abstraction** - Works with
|
|
10
|
+
- ✅ **Storage abstraction** - Works with file storage, memory, or custom storage
|
|
11
11
|
- ✅ **Account Abstraction** - Full ERC-4337 support
|
|
12
12
|
- ✅ **MPC/TSS** - Secure key management
|
|
13
13
|
- ✅ **Server-side wallets** - Backend wallet management with API keys
|
|
14
|
+
- ✅ **Zero configuration** - Works out of the box with Lumia Beam testnet
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
|
|
17
18
|
```bash
|
|
18
|
-
npm install @lumiapassport/core viem
|
|
19
|
+
npm install @lumiapassport/core viem dkls23-wasm
|
|
19
20
|
# or
|
|
20
|
-
pnpm add @lumiapassport/core viem
|
|
21
|
+
pnpm add @lumiapassport/core viem dkls23-wasm
|
|
21
22
|
# or
|
|
22
|
-
yarn add @lumiapassport/core viem
|
|
23
|
+
yarn add @lumiapassport/core viem dkls23-wasm
|
|
23
24
|
```
|
|
24
25
|
|
|
25
|
-
##
|
|
26
|
+
## Quick Start
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
The SDK works out of the box with Lumia Beam testnet. No additional configuration required:
|
|
28
29
|
|
|
29
30
|
```typescript
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
const core = createLumiaPassportCore({
|
|
33
|
-
tssUrl: process.env.LUMIA_TSS_URL,
|
|
34
|
-
bundlerUrl: process.env.LUMIA_BUNDLER_URL,
|
|
35
|
-
chainId: 2030232745,
|
|
36
|
-
tokenStorage: new MemoryStorage(),
|
|
37
|
-
keyshareStorage: new MemoryStorage(),
|
|
38
|
-
});
|
|
31
|
+
import { createServerWalletManager, MemoryKeyshareStorage } from '@lumiapassport/core';
|
|
39
32
|
|
|
40
|
-
// Create
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
// Create manager with just API key
|
|
34
|
+
const manager = createServerWalletManager({
|
|
35
|
+
apiKey: process.env.LUMIA_PASSPORT_API_KEY!, // Get from dashboard.lumiapassport.com
|
|
36
|
+
storage: new MemoryKeyshareStorage(),
|
|
44
37
|
});
|
|
45
38
|
|
|
46
|
-
//
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
'0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
|
|
50
|
-
'1000000000000000000' // 1 ETH in wei
|
|
51
|
-
);
|
|
39
|
+
// Create a wallet
|
|
40
|
+
const wallet = await manager.createWallet('my-wallet');
|
|
41
|
+
console.log('Smart Account address:', wallet.smartAccountAddress);
|
|
52
42
|
```
|
|
53
43
|
|
|
54
|
-
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
### Server-Side Wallets (Recommended)
|
|
47
|
+
|
|
48
|
+
Create and manage backend wallets with a simple high-level API:
|
|
55
49
|
|
|
56
50
|
```typescript
|
|
57
|
-
import {
|
|
51
|
+
import { createServerWalletManager, MemoryKeyshareStorage } from '@lumiapassport/core';
|
|
58
52
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
keyshareStorage: new LocalStorageAdapter(),
|
|
53
|
+
// Create manager
|
|
54
|
+
const manager = createServerWalletManager({
|
|
55
|
+
apiKey: process.env.LUMIA_PASSPORT_API_KEY!, // Get from dashboard.lumiapassport.com
|
|
56
|
+
storage: new MemoryKeyshareStorage(), // Use FileKeyshareStorage or custom storage in production
|
|
64
57
|
});
|
|
65
58
|
|
|
66
|
-
//
|
|
67
|
-
const
|
|
68
|
-
console.log('
|
|
69
|
-
|
|
59
|
+
// Create a wallet (handles all TSS protocol complexity)
|
|
60
|
+
const wallet = await manager.createWallet('treasury_main');
|
|
61
|
+
console.log('Owner address (EOA):', wallet.ownerAddress);
|
|
62
|
+
console.log('Smart Account address:', wallet.smartAccountAddress);
|
|
70
63
|
|
|
71
|
-
|
|
64
|
+
// Send a transaction (Account Abstraction with ERC-4337)
|
|
65
|
+
const userOpHash = await wallet.sendUserOperation(
|
|
66
|
+
'0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb', // recipient
|
|
67
|
+
'1000000000000000000', // 1 ETH in wei
|
|
68
|
+
'0x', // optional contract call data
|
|
69
|
+
'standard' // fee type: 'economy' | 'standard' | 'fast'
|
|
70
|
+
);
|
|
71
|
+
console.log('UserOp hash:', userOpHash);
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
// Wait for transaction confirmation
|
|
74
|
+
const receipt = await manager.waitForUserOperationReceipt(userOpHash);
|
|
75
|
+
console.log('Transaction hash:', receipt.transactionHash);
|
|
76
76
|
|
|
77
|
-
//
|
|
78
|
-
const
|
|
77
|
+
// Sign a message
|
|
78
|
+
const signature = await wallet.signDigest(messageHash);
|
|
79
79
|
|
|
80
|
-
//
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
// List all wallets
|
|
81
|
+
const wallets = await manager.listWallets();
|
|
82
|
+
wallets.forEach(w => {
|
|
83
|
+
console.log(`${w.userId}: ${w.smartAccountAddress}`);
|
|
84
84
|
});
|
|
85
|
+
```
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
throw new Error('Invalid signature');
|
|
88
|
-
}
|
|
87
|
+
### Storage Options
|
|
89
88
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// Poll for receipt to get transaction hash and status
|
|
95
|
-
const waitForReceipt = async (userOpHash: string, maxAttempts = 60, delayMs = 1000) => {
|
|
96
|
-
for (let i = 0; i < maxAttempts; i++) {
|
|
97
|
-
const receipt = await getUserOperationReceipt(userOpHash as `0x${string}`);
|
|
98
|
-
if (receipt) {
|
|
99
|
-
return {
|
|
100
|
-
success: receipt.success,
|
|
101
|
-
transactionHash: receipt.receipt?.transactionHash,
|
|
102
|
-
blockNumber: receipt.receipt?.blockNumber,
|
|
103
|
-
gasUsed: receipt.actualGasUsed,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
107
|
-
}
|
|
108
|
-
throw new Error('Transaction timeout');
|
|
109
|
-
};
|
|
89
|
+
#### MemoryKeyshareStorage (Development only)
|
|
90
|
+
|
|
91
|
+
Simple in-memory storage. **Keyshares are lost on restart!**
|
|
110
92
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
93
|
+
```typescript
|
|
94
|
+
import { MemoryKeyshareStorage } from '@lumiapassport/core';
|
|
95
|
+
|
|
96
|
+
const storage = new MemoryKeyshareStorage();
|
|
114
97
|
```
|
|
115
98
|
|
|
116
|
-
|
|
99
|
+
#### FileKeyshareStorage (Production-ready)
|
|
100
|
+
|
|
101
|
+
Encrypted file-based storage using AES-256-CBC. Available in Node.js only:
|
|
117
102
|
|
|
118
103
|
```typescript
|
|
119
|
-
import {
|
|
104
|
+
import { FileKeyshareStorage } from '@lumiapassport/core/clients/node';
|
|
105
|
+
|
|
106
|
+
const storage = new FileKeyshareStorage({
|
|
107
|
+
storageDir: './data/keyshares',
|
|
108
|
+
encryptionPassword: process.env.LUMIA_PASSPORT_KEYSHARE_ENCRYPTION_PASSWORD!,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Initialize storage directory
|
|
112
|
+
await storage.init();
|
|
120
113
|
|
|
121
|
-
const
|
|
114
|
+
const manager = createServerWalletManager({
|
|
115
|
+
apiKey: process.env.LUMIA_PASSPORT_API_KEY!,
|
|
116
|
+
storage,
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### Custom Storage
|
|
122
121
|
|
|
123
|
-
|
|
124
|
-
const verification = await core.auth.verifyToken(token);
|
|
122
|
+
Implement the `KeyshareStorage` interface for custom backends (AWS KMS, Vault, etc.):
|
|
125
123
|
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
```typescript
|
|
125
|
+
interface KeyshareStorage {
|
|
126
|
+
set(userId: string, keyshare: string): Promise<void> | void;
|
|
127
|
+
get(userId: string): Promise<string | null> | string | null;
|
|
128
|
+
has(userId: string): Promise<boolean> | boolean;
|
|
129
|
+
list(): Promise<string[]> | string[];
|
|
128
130
|
}
|
|
129
131
|
```
|
|
130
132
|
|
|
131
|
-
###
|
|
133
|
+
### Keyshare Backup and Restore
|
|
132
134
|
|
|
133
|
-
|
|
135
|
+
Backup keyshares to Lumia ShareVault for recovery:
|
|
134
136
|
|
|
135
137
|
```typescript
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
MemoryKeyshareStorage,
|
|
139
|
-
} from '@lumiapassport/core';
|
|
138
|
+
// Check if wallet exists on TSS service
|
|
139
|
+
const exists = await manager.walletExists('my-wallet');
|
|
140
140
|
|
|
141
|
-
//
|
|
142
|
-
const
|
|
143
|
-
apiKey: process.env.LUMIA_PASSPORT_API_KEY!, // Get from dashboard
|
|
144
|
-
storage: new MemoryKeyshareStorage(), // Use AWS KMS, Vault, etc. in production
|
|
145
|
-
});
|
|
141
|
+
// Check if we have keyshare locally
|
|
142
|
+
const hasKeyshare = await manager.hasKeyshare('my-wallet');
|
|
146
143
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
console.log('Smart Account address:', wallet.smartAccountAddress);
|
|
144
|
+
if (!hasKeyshare) {
|
|
145
|
+
// Check if backup exists in vault
|
|
146
|
+
const { hasBackup } = await manager.checkBackupExists('my-wallet');
|
|
151
147
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
);
|
|
159
|
-
console.log('Transaction hash:', userOpHash);
|
|
148
|
+
if (hasBackup) {
|
|
149
|
+
// Restore from vault
|
|
150
|
+
await manager.restoreFromVault('my-wallet', process.env.BACKUP_PASSWORD!);
|
|
151
|
+
console.log('Keyshare restored from vault');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
160
154
|
|
|
161
|
-
//
|
|
162
|
-
|
|
155
|
+
// Backup keyshare to vault
|
|
156
|
+
await manager.backupToVault('my-wallet', process.env.BACKUP_PASSWORD!);
|
|
157
|
+
```
|
|
163
158
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
159
|
+
### Using Paymaster (Sponsored Transactions)
|
|
160
|
+
|
|
161
|
+
Configure paymaster for gasless transactions:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const manager = createServerWalletManager({
|
|
165
|
+
apiKey: process.env.LUMIA_PASSPORT_API_KEY!,
|
|
166
|
+
storage,
|
|
167
|
+
paymasterAddress: '0x...' as `0x${string}`, // Your paymaster contract
|
|
168
168
|
});
|
|
169
169
|
```
|
|
170
170
|
|
|
@@ -381,6 +381,22 @@ const logs = await client.getLogs({
|
|
|
381
381
|
fromBlock: 1000000n,
|
|
382
382
|
toBlock: 'latest',
|
|
383
383
|
});
|
|
384
|
+
|
|
385
|
+
// Get transaction receipt (returns null if pending)
|
|
386
|
+
const receipt = await client.getTransactionReceipt({
|
|
387
|
+
hash: '0x...transactionHash',
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// Wait for transaction to be mined
|
|
391
|
+
const receipt = await client.waitForTransactionReceipt({
|
|
392
|
+
hash: '0x...transactionHash',
|
|
393
|
+
confirmations: 1, // optional, default: 1
|
|
394
|
+
pollingInterval: 4000, // optional, default: 4000ms
|
|
395
|
+
timeout: 60000, // optional, default: 60000ms
|
|
396
|
+
onReplaced: (response) => {
|
|
397
|
+
console.log('Transaction replaced:', response.reason);
|
|
398
|
+
},
|
|
399
|
+
});
|
|
384
400
|
```
|
|
385
401
|
|
|
386
402
|
**Features:**
|
|
@@ -388,6 +404,7 @@ const logs = await client.getLogs({
|
|
|
388
404
|
- **RPC Fallback** - Automatic failover to backup RPCs
|
|
389
405
|
- **Multicall Batching** - Batch reads for better performance
|
|
390
406
|
- **Log Pagination** - Automatic chunking for large block ranges
|
|
407
|
+
- **Transaction Receipts** - Get receipt or wait with polling/timeout
|
|
391
408
|
|
|
392
409
|
## API
|
|
393
410
|
|
|
@@ -45,7 +45,7 @@ function initSdkErrorTracking() {
|
|
|
45
45
|
// Don't track performance for SDK (only errors)
|
|
46
46
|
tracesSampleRate: 0,
|
|
47
47
|
// Release version from package.json
|
|
48
|
-
release: `@lumiapassport/core@${"1.14.
|
|
48
|
+
release: `@lumiapassport/core@${"1.14.3"}`,
|
|
49
49
|
environment: "production",
|
|
50
50
|
// Filter to only track SDK errors
|
|
51
51
|
beforeSend(event) {
|
|
@@ -23,7 +23,7 @@ function initSdkErrorTracking() {
|
|
|
23
23
|
// Don't track performance for SDK (only errors)
|
|
24
24
|
tracesSampleRate: 0,
|
|
25
25
|
// Release version from package.json
|
|
26
|
-
release: `@lumiapassport/core@${"1.14.
|
|
26
|
+
release: `@lumiapassport/core@${"1.14.3"}`,
|
|
27
27
|
environment: "production",
|
|
28
28
|
// Filter to only track SDK errors
|
|
29
29
|
beforeSend(event) {
|