toss-expo-sdk 0.1.1 → 0.1.2
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 +122 -66
- package/lib/module/client/TossClient.js +26 -43
- package/lib/module/client/TossClient.js.map +1 -1
- package/lib/module/contexts/WalletContext.js +4 -4
- package/lib/module/contexts/WalletContext.js.map +1 -1
- package/lib/module/discovery.js +35 -8
- package/lib/module/discovery.js.map +1 -1
- package/lib/module/examples/offlinePaymentFlow.js +27 -2
- package/lib/module/examples/offlinePaymentFlow.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/intent.js +69 -0
- package/lib/module/intent.js.map +1 -1
- package/lib/module/nfc.js +1 -1
- package/lib/module/noise.js +1 -1
- package/lib/module/storage/secureStorage.js.map +1 -1
- package/lib/module/storage.js +4 -4
- package/lib/typescript/src/client/TossClient.d.ts +10 -12
- package/lib/typescript/src/client/TossClient.d.ts.map +1 -1
- package/lib/typescript/src/discovery.d.ts +8 -2
- package/lib/typescript/src/discovery.d.ts.map +1 -1
- package/lib/typescript/src/examples/offlinePaymentFlow.d.ts +9 -1
- package/lib/typescript/src/examples/offlinePaymentFlow.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/intent.d.ts +11 -0
- package/lib/typescript/src/intent.d.ts.map +1 -1
- package/package.json +12 -1
- package/src/__tests__/reconciliation.test.tsx +7 -1
- package/src/client/TossClient.ts +35 -48
- package/src/contexts/WalletContext.tsx +4 -4
- package/src/discovery.ts +46 -8
- package/src/examples/offlinePaymentFlow.ts +48 -2
- package/src/index.tsx +9 -1
- package/src/intent.ts +88 -0
- package/src/nfc.ts +4 -4
- package/src/noise.ts +1 -1
- package/src/storage/secureStorage.ts +4 -4
- package/src/storage.ts +4 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
**TOSS (The Offline Solana Stack)** is a robust, production-ready SDK for building offline-capable Solana applications with secure local transport and delayed on-chain settlement.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/toss-expo-sdk)
|
|
6
|
-
[](LICENSE)
|
|
7
7
|
|
|
8
8
|
## 🚀 Features
|
|
9
9
|
|
|
@@ -31,20 +31,24 @@
|
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
33
|
# Using npm
|
|
34
|
-
npm install toss-expo-sdk
|
|
34
|
+
npm install toss-expo-sdk
|
|
35
35
|
|
|
36
36
|
# Using yarn
|
|
37
|
-
yarn add toss-expo-sdk
|
|
37
|
+
yarn add toss-expo-sdk
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
All dependencies (Solana Web3.js, Arcium, Noise Protocol, etc.) are automatically included.
|
|
41
|
+
|
|
40
42
|
## 🏁 Quick Start
|
|
41
43
|
|
|
42
44
|
### Initialize the Client
|
|
43
45
|
|
|
46
|
+
Recommended: use the `createClient` helper for concise initialization.
|
|
47
|
+
|
|
44
48
|
```typescript
|
|
45
|
-
import {
|
|
49
|
+
import { createClient } from 'toss-expo-sdk';
|
|
46
50
|
|
|
47
|
-
const client =
|
|
51
|
+
const client = createClient({
|
|
48
52
|
projectId: 'your-project-id',
|
|
49
53
|
mode: 'devnet', // or 'testnet' | 'mainnet-beta'
|
|
50
54
|
privateTransactions: true,
|
|
@@ -53,28 +57,65 @@ const client = new TossClient({
|
|
|
53
57
|
});
|
|
54
58
|
```
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
Or, you may call the static constructor directly if you prefer:
|
|
57
61
|
|
|
58
62
|
```typescript
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
import { TossClient } from 'toss-expo-sdk';
|
|
64
|
+
const client = TossClient.createClient({ projectId: 'your-project-id' });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Create and Sign an Intent
|
|
68
|
+
|
|
69
|
+
Prefer the user-centric API which accepts `TossUser` objects and validates user features.
|
|
70
|
+
|
|
71
|
+
> Note: There are two common ways to create a user intent:
|
|
72
|
+
>
|
|
73
|
+
> - `createUserIntent(senderUser, senderKeypair, recipientUser, amount, connection, options)` — top-level helper suitable for scripts or when you have both user objects and the signing `Keypair` available.
|
|
74
|
+
> - `TossClient.createUserIntent(senderKeypair, recipient, amount, options)` — an instance method used when working with a `TossClient`. This requires an explicit `Keypair` for signing (TossClient is framework-agnostic). For React apps, prefer unlocking the wallet via `WalletProvider` and calling the top-level `createUserIntent` with the unlocked `Keypair`.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import {
|
|
78
|
+
createUserIntent,
|
|
79
|
+
createSignedIntent, // legacy: accepts Keypair + PublicKey
|
|
80
|
+
secureStoreIntent,
|
|
81
|
+
syncToChain,
|
|
82
|
+
} from 'toss-expo-sdk';
|
|
83
|
+
import { Connection } from '@solana/web3.js';
|
|
84
|
+
import type { TossUser } from 'toss-expo-sdk';
|
|
85
|
+
|
|
86
|
+
const connection = new Connection('https://api.devnet.solana.com');
|
|
87
|
+
|
|
88
|
+
// Example using TossUser objects
|
|
89
|
+
const intent = await createUserIntent(
|
|
90
|
+
senderUser, // TossUser (includes wallet.publicKey and features)
|
|
91
|
+
senderKeypair, // Keypair object for signing (must match senderUser.wallet)
|
|
92
|
+
recipientUser, // TossUser
|
|
63
93
|
amountInLamports,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
useDurableNonce: true,
|
|
67
|
-
}
|
|
94
|
+
connection,
|
|
95
|
+
{ expiresIn: 60 * 60, privateTransaction: true }
|
|
68
96
|
);
|
|
69
97
|
|
|
70
|
-
//
|
|
71
|
-
|
|
98
|
+
// Store intent locally
|
|
99
|
+
await secureStoreIntent(intent);
|
|
100
|
+
|
|
101
|
+
// Later, when online, sync to Solana
|
|
102
|
+
const syncResult = await syncToChain(connection);
|
|
103
|
+
console.log(`Settled: ${syncResult.successfulSettlements.length}`);
|
|
104
|
+
|
|
105
|
+
// Legacy: If you already have an address and Keypair, use createSignedIntent
|
|
106
|
+
const legacyIntent = await createSignedIntent(
|
|
107
|
+
senderKeypair,
|
|
108
|
+
recipientPublicKey,
|
|
109
|
+
amountInLamports,
|
|
110
|
+
connection
|
|
111
|
+
);
|
|
72
112
|
```
|
|
73
113
|
|
|
74
114
|
### Using with React Native
|
|
75
115
|
|
|
76
116
|
```typescript
|
|
77
|
-
import { WalletProvider, useWallet } from 'toss-expo-sdk';
|
|
117
|
+
import { WalletProvider, useWallet, createUserIntent, secureStoreIntent, syncToChain } from 'toss-expo-sdk';
|
|
118
|
+
import { View, Button } from 'react-native';
|
|
78
119
|
|
|
79
120
|
function App() {
|
|
80
121
|
return (
|
|
@@ -86,14 +127,38 @@ function App() {
|
|
|
86
127
|
|
|
87
128
|
function PaymentScreen() {
|
|
88
129
|
const {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
130
|
+
isUnlocked,
|
|
131
|
+
unlockWallet,
|
|
132
|
+
lockWallet,
|
|
133
|
+
keypair,
|
|
134
|
+
user,
|
|
94
135
|
} = useWallet();
|
|
95
136
|
|
|
96
|
-
|
|
137
|
+
const handlePay = async (recipientUser, amountLamports, connection) => {
|
|
138
|
+
if (!isUnlocked || !keypair || !user) {
|
|
139
|
+
// Ensure wallet is unlocked and keypair is available
|
|
140
|
+
const ok = await unlockWallet();
|
|
141
|
+
if (!ok) throw new Error('Wallet is locked');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Create intent using unlocked keypair and TossUser context
|
|
145
|
+
const intent = await createUserIntent(user, keypair, recipientUser, amountLamports, connection);
|
|
146
|
+
await secureStoreIntent(intent);
|
|
147
|
+
|
|
148
|
+
// Optionally trigger sync when online
|
|
149
|
+
// await syncToChain(connection);
|
|
150
|
+
|
|
151
|
+
return intent;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<View>
|
|
156
|
+
<Button
|
|
157
|
+
title={isUnlocked ? 'Lock Wallet' : 'Unlock Wallet'}
|
|
158
|
+
onPress={() => (isUnlocked ? lockWallet() : unlockWallet())}
|
|
159
|
+
/>
|
|
160
|
+
</View>
|
|
161
|
+
);
|
|
97
162
|
}
|
|
98
163
|
```
|
|
99
164
|
|
|
@@ -140,23 +205,28 @@ The SDK provides detailed error codes for handling various scenarios. All errors
|
|
|
140
205
|
#### Error Handling Example
|
|
141
206
|
|
|
142
207
|
```typescript
|
|
143
|
-
import {
|
|
208
|
+
import { TossError } from 'toss-expo-sdk';
|
|
144
209
|
|
|
145
210
|
try {
|
|
146
|
-
await
|
|
211
|
+
const intent = await createSignedIntent(...);
|
|
212
|
+
await secureStoreIntent(intent);
|
|
147
213
|
} catch (error) {
|
|
148
|
-
if (error
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
214
|
+
if (error instanceof TossError) {
|
|
215
|
+
switch (error.code) {
|
|
216
|
+
case 'INSUFFICIENT_FUNDS':
|
|
217
|
+
console.error('Insufficient funds for this transaction');
|
|
218
|
+
break;
|
|
219
|
+
case 'INTENT_EXPIRED':
|
|
220
|
+
console.error('This transaction intent has expired');
|
|
221
|
+
break;
|
|
222
|
+
case 'NETWORK_ERROR':
|
|
223
|
+
console.error('Network error occurred. Please check your connection.');
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
console.error(`Error [${error.code}]: ${error.message}`);
|
|
227
|
+
}
|
|
157
228
|
} else {
|
|
158
|
-
|
|
159
|
-
console.error('An error occurred:', error.message);
|
|
229
|
+
console.error('An unexpected error occurred:', error);
|
|
160
230
|
}
|
|
161
231
|
}
|
|
162
232
|
```
|
|
@@ -234,34 +304,30 @@ console.log(`Losers: ${resolution.losers.map((i) => i.id)}`);
|
|
|
234
304
|
Devices can discover and exchange intents with nearby peers:
|
|
235
305
|
|
|
236
306
|
```typescript
|
|
237
|
-
import {
|
|
238
|
-
import { startTossScan } from 'toss-expo-sdk';
|
|
307
|
+
import { DeviceDiscoveryService, startTossScan } from 'toss-expo-sdk';
|
|
239
308
|
|
|
240
|
-
|
|
309
|
+
const discovery = new DeviceDiscoveryService();
|
|
310
|
+
|
|
311
|
+
// Scan for nearby TOSS devices via BLE
|
|
241
312
|
startTossScan(
|
|
242
313
|
(user, device) => {
|
|
243
314
|
// Register discovered peer
|
|
244
|
-
|
|
315
|
+
discovery.registerPeer({
|
|
245
316
|
id: device.id,
|
|
246
317
|
user,
|
|
247
318
|
lastSeen: Date.now(),
|
|
248
319
|
transport: 'ble',
|
|
249
320
|
});
|
|
250
|
-
|
|
251
|
-
// Create intent exchange request
|
|
252
|
-
const request = intentExchange.createRequest(
|
|
253
|
-
myIntent,
|
|
254
|
-
'my-device-id',
|
|
255
|
-
undefined,
|
|
256
|
-
5 * 60 // 5 minute expiry
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
console.log(`Exchange request created: ${request.requestId}`);
|
|
321
|
+
console.log(`Peer discovered: ${device.id}`);
|
|
260
322
|
},
|
|
261
323
|
(intent, device) => {
|
|
262
324
|
console.log(`Received intent from ${device.id}`);
|
|
263
325
|
}
|
|
264
326
|
);
|
|
327
|
+
|
|
328
|
+
// Get active peers
|
|
329
|
+
const activePeers = discovery.getActivePeers();
|
|
330
|
+
console.log(`${activePeers.length} active peers nearby`);
|
|
265
331
|
```
|
|
266
332
|
|
|
267
333
|
## 🌐 Network Support
|
|
@@ -272,21 +338,11 @@ startTossScan(
|
|
|
272
338
|
| Testnet | ✅ Live | https://api.testnet.solana.com |
|
|
273
339
|
| Mainnet | ✅ Live | https://api.mainnet-beta.solana.com |
|
|
274
340
|
|
|
275
|
-
## 📚
|
|
341
|
+
## 📚 Complete Documentation
|
|
276
342
|
|
|
277
|
-
For
|
|
278
|
-
|
|
279
|
-
- Full API reference
|
|
280
|
-
- Architecture diagrams
|
|
281
|
-
- Performance considerations
|
|
282
|
-
- Future improvements
|
|
283
|
-
|
|
284
|
-
See [IMPLEMENTATION.md](./IMPLEMENTATION.md)
|
|
285
|
-
|
|
286
|
-
## 🌐 Network Support
|
|
343
|
+
For comprehensive information, see:
|
|
287
344
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
| Mainnet | ✅ Live | https://api.mainnet.solana.com |
|
|
345
|
+
- [DOCUMENTATION_INDEX.md](./DOCUMENTATION_INDEX.md) - Complete documentation guide
|
|
346
|
+
- [TOSS_PAPER_IMPLEMENTATION_VERIFICATION.md](./TOSS_PAPER_IMPLEMENTATION_VERIFICATION.md) - TOSS paper compliance
|
|
347
|
+
- [PAPER_VS_IMPLEMENTATION_AUDIT.md](./PAPER_VS_IMPLEMENTATION_AUDIT.md) - Detailed technical audit
|
|
348
|
+
- [USER_SECURITY_AND_KEY_MANAGEMENT.md](./USER_SECURITY_AND_KEY_MANAGEMENT.md) - Security model and biometric protection
|
|
@@ -6,7 +6,7 @@ import { secureStoreIntent, getSecureIntent, getAllSecureIntents } from "../stor
|
|
|
6
6
|
import { processIntentsForSync } from "../intentManager.js";
|
|
7
7
|
import { TossError, NetworkError, StorageError, ERROR_CODES } from "../errors.js";
|
|
8
8
|
import { createNonceAccount, getNonce } from "../utils/nonceUtils.js";
|
|
9
|
-
|
|
9
|
+
// Note: TossClient is not tied to a React hook. To use wallet-provided keys in React, pass a Keypair to methods directly.
|
|
10
10
|
import { syncToChain, checkSyncStatus } from "../sync.js";
|
|
11
11
|
import { detectConflicts, getReconciliationState } from "../reconciliation.js";
|
|
12
12
|
const DEFAULT_RETRY_OPTIONS = {
|
|
@@ -32,10 +32,6 @@ export class TossClient {
|
|
|
32
32
|
feePayer: config.feePayer
|
|
33
33
|
};
|
|
34
34
|
this.connection = new Connection(this.config.rpcUrl, 'confirmed');
|
|
35
|
-
this.walletContext = useWallet();
|
|
36
|
-
if (!this.walletContext) {
|
|
37
|
-
throw new Error('TossClient must be used within a WalletProvider');
|
|
38
|
-
}
|
|
39
35
|
}
|
|
40
36
|
getDefaultRpcUrl(network) {
|
|
41
37
|
const urls = {
|
|
@@ -114,10 +110,14 @@ export class TossClient {
|
|
|
114
110
|
throw new TossError('Connection not initialized', ERROR_CODES.NETWORK_ERROR);
|
|
115
111
|
}
|
|
116
112
|
|
|
117
|
-
// Handle 'current' sender
|
|
118
|
-
|
|
113
|
+
// Handle 'current' sender: explicit wallet integration via React hooks is
|
|
114
|
+
// not available in this non-React class. Require a Keypair to be passed.
|
|
115
|
+
if (sender === 'current') {
|
|
116
|
+
throw new TossError('Using "current" as sender is only supported when the client is used inside a WalletProvider. Please provide a Keypair instead.', ERROR_CODES.SIGNATURE_VERIFICATION_FAILED);
|
|
117
|
+
}
|
|
118
|
+
const senderKeypair = sender;
|
|
119
119
|
if (!senderKeypair) {
|
|
120
|
-
throw new TossError('No sender keypair provided
|
|
120
|
+
throw new TossError('No sender keypair provided', ERROR_CODES.SIGNATURE_VERIFICATION_FAILED);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
// Convert string addresses to PublicKey if needed
|
|
@@ -177,10 +177,10 @@ export class TossClient {
|
|
|
177
177
|
};
|
|
178
178
|
await secureStoreIntent(updatedIntent);
|
|
179
179
|
return updatedIntent;
|
|
180
|
-
} catch (
|
|
181
|
-
if (
|
|
180
|
+
} catch (err) {
|
|
181
|
+
if (err instanceof TossError) throw err;
|
|
182
182
|
throw new StorageError('Failed to update intent status', {
|
|
183
|
-
cause:
|
|
183
|
+
cause: err,
|
|
184
184
|
intentId,
|
|
185
185
|
status
|
|
186
186
|
});
|
|
@@ -272,53 +272,36 @@ export class TossClient {
|
|
|
272
272
|
/**
|
|
273
273
|
* Create an intent from the current user's wallet
|
|
274
274
|
*/
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const unlocked = await this.walletContext.unlockWallet();
|
|
283
|
-
if (!unlocked) {
|
|
284
|
-
throw new TossError('Wallet is locked', ERROR_CODES.SIGNATURE_VERIFICATION_FAILED);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
275
|
+
/**
|
|
276
|
+
* Create an intent using an explicit Keypair for the sender.
|
|
277
|
+
* Use this method from non-React contexts. For React apps, use
|
|
278
|
+
* WalletProvider.createUserIntent helper wrappers that call
|
|
279
|
+
* TossClient.createIntent with the unlocked keypair.
|
|
280
|
+
*/
|
|
281
|
+
async createUserIntent(senderKeypair, recipient, amount, options = {}) {
|
|
287
282
|
const recipientPubkey = typeof recipient === 'string' ? new PublicKey(recipient) : recipient;
|
|
288
|
-
return this.createIntent(
|
|
289
|
-
// This will use the wallet context's keypair
|
|
290
|
-
recipientPubkey, amount, this.walletContext.user.wallet.publicKey, {
|
|
283
|
+
return this.createIntent(senderKeypair, recipientPubkey, amount, senderKeypair.publicKey, {
|
|
291
284
|
...options,
|
|
292
285
|
memo: options.memo || `TOSS transfer to ${recipientPubkey.toBase58()}`
|
|
293
286
|
});
|
|
294
287
|
}
|
|
295
288
|
|
|
296
289
|
/**
|
|
297
|
-
*
|
|
290
|
+
* The following helper methods require a WalletProvider (React) context.
|
|
291
|
+
* TossClient is framework-agnostic; if you need these features from a
|
|
292
|
+
* React app, use the WalletProvider utilities instead.
|
|
298
293
|
*/
|
|
299
294
|
getCurrentUserAddress() {
|
|
300
|
-
|
|
295
|
+
throw new Error('getCurrentUserAddress is only available when using WalletProvider');
|
|
301
296
|
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Check if the wallet is currently unlocked
|
|
305
|
-
*/
|
|
306
297
|
isWalletUnlocked() {
|
|
307
|
-
|
|
298
|
+
throw new Error('isWalletUnlocked is only available when using WalletProvider');
|
|
308
299
|
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Lock the wallet
|
|
312
|
-
*/
|
|
313
300
|
async lockWallet() {
|
|
314
|
-
|
|
301
|
+
throw new Error('lockWallet is only available when using WalletProvider');
|
|
315
302
|
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Sign out the current user
|
|
319
|
-
*/
|
|
320
303
|
async signOut() {
|
|
321
|
-
|
|
304
|
+
throw new Error('signOut is only available when using WalletProvider');
|
|
322
305
|
}
|
|
323
306
|
}
|
|
324
307
|
//# sourceMappingURL=TossClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Connection","PublicKey","createIntent","secureStoreIntent","getSecureIntent","getAllSecureIntents","processIntentsForSync","TossError","NetworkError","StorageError","ERROR_CODES","createNonceAccount","getNonce","
|
|
1
|
+
{"version":3,"names":["Connection","PublicKey","createIntent","secureStoreIntent","getSecureIntent","getAllSecureIntents","processIntentsForSync","TossError","NetworkError","StorageError","ERROR_CODES","createNonceAccount","getNonce","syncToChain","checkSyncStatus","detectConflicts","getReconciliationState","DEFAULT_RETRY_OPTIONS","maxRetries","retryDelay","TossClient","createClient","config","constructor","projectId","mode","privateTransactions","provider","sync","syncBackupDb","rpcUrl","getDefaultRpcUrl","feePayer","connection","network","urls","devnet","withRetry","fn","context","lastError","attempt","error","delay","Math","pow","Promise","resolve","setTimeout","message","cause","initializeNonceAccount","amount","Error","nonceAccount","nonceAuth","undefined","publicKey","toBase58","getCurrentNonce","sender","recipient","options","NETWORK_ERROR","SIGNATURE_VERIFICATION_FAILED","senderKeypair","recipientPubkey","feePayerPubkey","useDurableNonce","getLatestBlockhash","intent","TRANSACTION_FAILED","getIntents","updateIntentStatus","intentId","status","updatedAt","Date","now","updatedIntent","err","intents","dbUrl","processedIntents","all","map","fullSync","detectIntentConflicts","getReconciliationStatus","createUserIntent","memo","getCurrentUserAddress","isWalletUnlocked","lockWallet","signOut"],"sourceRoot":"../../../src","sources":["client/TossClient.ts"],"mappings":";;AAAA,SAASA,UAAU,EAAWC,SAAS,QAAQ,iBAAiB;AAEhE,SAASC,YAAY,QAAQ,cAAW;AACxC,SACEC,iBAAiB,EACjBC,eAAe,EACfC,mBAAmB,QACd,6BAA0B;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AC/C,CAAC,EAAE,uBAAuB,CAAC;EAC7B;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,MAAMuD,uBAAuBA,CAAA,EAAG;IAC9B,OAAO,IAAI,CAACnD,SAAS,CAAC,YAAY;MAChC,OAAO,MAAMrB,sBAAsB,CAAC,IAAI,CAACiB,UAAU,CAAC;IACtD,CAAC,EAAE,yBAAyB,CAAC;EAC/B;;EAEA;AACF;AACA;EACE;AACF;AACA;AACA;AACA;AACA;EACE,MAAMwD,gBAAgBA,CACpBxB,aAAsB,EACtBJ,SAA6B,EAC7BT,MAAc,EACdU,OAGC,GAAG,CAAC,CAAC,EACiB;IACvB,MAAMI,eAAe,GACnB,OAAOL,SAAS,KAAK,QAAQ,GAAG,IAAI5D,SAAS,CAAC4D,SAAS,CAAC,GAAGA,SAAS;IAEtE,OAAO,IAAI,CAAC3D,YAAY,CACtB+D,aAAa,EACbC,eAAe,EACfd,MAAM,EACNa,aAAa,CAACR,SAAS,EACvB;MACE,GAAGK,OAAO;MACV4B,IAAI,EAAE5B,OAAO,CAAC4B,IAAI,IAAI,oBAAoBxB,eAAe,CAACR,QAAQ,CAAC,CAAC;IACtE,CACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;EACEiC,qBAAqBA,CAAA,EAAkB;IACrC,MAAM,IAAItC,KAAK,CACb,mEACF,CAAC;EACH;EAEAuC,gBAAgBA,CAAA,EAAY;IAC1B,MAAM,IAAIvC,KAAK,CACb,8DACF,CAAC;EACH;EAEA,MAAMwC,UAAUA,CAAA,EAAkB;IAChC,MAAM,IAAIxC,KAAK,CAAC,wDAAwD,CAAC;EAC3E;EAEA,MAAMyC,OAAOA,CAAA,EAAkB;IAC7B,MAAM,IAAIzC,KAAK,CAAC,qDAAqD,CAAC;EACxE;AACF","ignoreList":[]}
|
|
@@ -18,9 +18,9 @@ export const WalletProvider = ({
|
|
|
18
18
|
if (session) {
|
|
19
19
|
// In a real app, you'd fetch the user from your backend
|
|
20
20
|
const {
|
|
21
|
-
user
|
|
21
|
+
user: sessionUser
|
|
22
22
|
} = await AuthService.signInWithWallet(session.walletAddress);
|
|
23
|
-
setUser(
|
|
23
|
+
setUser(sessionUser);
|
|
24
24
|
setIsUnlocked(await AuthService.isWalletUnlocked());
|
|
25
25
|
}
|
|
26
26
|
} catch (error) {
|
|
@@ -57,9 +57,9 @@ export const WalletProvider = ({
|
|
|
57
57
|
};
|
|
58
58
|
const signIn = async (walletAddress, isTemporary = false) => {
|
|
59
59
|
const {
|
|
60
|
-
user
|
|
60
|
+
user: sessionUser
|
|
61
61
|
} = await AuthService.signInWithWallet(walletAddress, isTemporary);
|
|
62
|
-
setUser(
|
|
62
|
+
setUser(sessionUser);
|
|
63
63
|
setIsUnlocked(true);
|
|
64
64
|
};
|
|
65
65
|
const signOut = async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useContext","useState","useEffect","AuthService","jsx","_jsx","WalletContext","undefined","WalletProvider","children","isInitialized","setIsInitialized","isUnlocked","setIsUnlocked","user","setUser","keypair","setKeypair","checkAuth","session","getSession","signInWithWallet","walletAddress","isWalletUnlocked","error","console","unlockWallet","unlockedKeypair","unlockWalletWithBiometrics","lockWallet","signIn","isTemporary","signOut","Provider","value","useWallet","context","Error"],"sourceRoot":"../../../src","sources":["contexts/WalletContext.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,OAAO;AAGtE,SAASC,WAAW,QAAQ,4BAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AActD,MAAMC,aAAa,gBAAGP,aAAa,CAAgCQ,SAAS,CAAC;AAE7E,OAAO,MAAMC,cAAiD,GAAGA,CAAC;EAChEC;AACF,CAAC,KAAK;EACJ,MAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGV,QAAQ,CAAC,KAAK,CAAC;EACzD,MAAM,CAACW,UAAU,EAAEC,aAAa,CAAC,GAAGZ,QAAQ,CAAC,KAAK,CAAC;EACnD,MAAM,CAACa,IAAI,EAAEC,OAAO,CAAC,GAAGd,QAAQ,CAAkB,IAAI,CAAC;EACvD,MAAM,CAACe,OAAO,EAAEC,UAAU,CAAC,GAAGhB,QAAQ,CAAiB,IAAI,CAAC;EAE5DC,SAAS,CAAC,MAAM;IACd,MAAMgB,SAAS,GAAG,MAAAA,CAAA,KAAY;MAC5B,IAAI;QACF,MAAMC,OAAO,GAAG,MAAMhB,WAAW,CAACiB,UAAU,CAAC,CAAC;QAC9C,IAAID,OAAO,EAAE;UACX;UACA,MAAM;YAAEL;
|
|
1
|
+
{"version":3,"names":["createContext","useContext","useState","useEffect","AuthService","jsx","_jsx","WalletContext","undefined","WalletProvider","children","isInitialized","setIsInitialized","isUnlocked","setIsUnlocked","user","setUser","keypair","setKeypair","checkAuth","session","getSession","sessionUser","signInWithWallet","walletAddress","isWalletUnlocked","error","console","unlockWallet","unlockedKeypair","unlockWalletWithBiometrics","lockWallet","signIn","isTemporary","signOut","Provider","value","useWallet","context","Error"],"sourceRoot":"../../../src","sources":["contexts/WalletContext.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,OAAO;AAGtE,SAASC,WAAW,QAAQ,4BAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AActD,MAAMC,aAAa,gBAAGP,aAAa,CAAgCQ,SAAS,CAAC;AAE7E,OAAO,MAAMC,cAAiD,GAAGA,CAAC;EAChEC;AACF,CAAC,KAAK;EACJ,MAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGV,QAAQ,CAAC,KAAK,CAAC;EACzD,MAAM,CAACW,UAAU,EAAEC,aAAa,CAAC,GAAGZ,QAAQ,CAAC,KAAK,CAAC;EACnD,MAAM,CAACa,IAAI,EAAEC,OAAO,CAAC,GAAGd,QAAQ,CAAkB,IAAI,CAAC;EACvD,MAAM,CAACe,OAAO,EAAEC,UAAU,CAAC,GAAG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MkB,MAAM,GAAG,MAAAA,CACbR,aAAqB,EACrBS,WAAoB,GAAG,KAAK,KACV;IAClB,MAAM;MAAElB,IAAI,EAAEO;IAAY,CAAC,GAAG,MAAMlB,WAAW,CAACmB,gBAAgB,CAC9DC,aAAa,EACbS,WACF,CAAC;IACDjB,OAAO,CAACM,WAAW,CAAC;IACpBR,aAAa,CAAC,IAAI,CAAC;EACrB,CAAC;EAED,MAAMoB,OAAO,GAAG,MAAAA,CAAA,KAA2B;IACzC;IACA,MAAM9B,WAAW,CAAC8B,OAAO,CAAC,CAAC;;IAE3B;IACAlB,OAAO,CAAC,IAAI,CAAC;IACbE,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAClBJ,aAAa,CAAC,KAAK,CAAC;;IAEpB;IACA;EACF,CAAC;EAED,oBACER,IAAA,CAACC,aAAa,CAAC4B,QAAQ;IACrBC,KAAK,EAAE;MACLzB,aAAa;MACbE,UAAU;MACVE,IAAI;MACJE,OAAO;MACPW,YAAY;MACZG,UAAU;MACVC,MAAM;MACNE;IACF,CAAE;IAAAxB,QAAA,EAEDA;EAAQ,CACa,CAAC;AAE7B,CAAC;AAED,OAAO,MAAM2B,SAAS,GAAGA,CAAA,KAAyB;EAChD,MAAMC,OAAO,GAAGrC,UAAU,CAACM,aAAa,CAAC;EACzC,IAAI+B,OAAO,KAAK9B,SAAS,EAAE;IACzB,MAAM,IAAI+B,KAAK,CAAC,gDAAgD,CAAC;EACnE;EACA,OAAOD,OAAO;AAChB,CAAC;AAED,eAAe/B,aAAa","ignoreList":[]}
|
package/lib/module/discovery.js
CHANGED
|
@@ -103,6 +103,9 @@ export class DeviceDiscoveryService {
|
|
|
103
103
|
export class IntentExchangeProtocol {
|
|
104
104
|
pendingRequests = new Map();
|
|
105
105
|
noiseSessions = new Map();
|
|
106
|
+
// Track timeout handles so they can be cleared during shutdown/cleanup
|
|
107
|
+
requestTimeouts = new Map();
|
|
108
|
+
sessionTimeouts = new Map();
|
|
106
109
|
// Static key for this device
|
|
107
110
|
REQUEST_TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
|
108
111
|
SESSION_TIMEOUT = 30 * 60 * 1000; // 30 minutes
|
|
@@ -133,10 +136,12 @@ export class IntentExchangeProtocol {
|
|
|
133
136
|
};
|
|
134
137
|
this.noiseSessions.set(peerId, session);
|
|
135
138
|
|
|
136
|
-
// Clean up expired sessions
|
|
137
|
-
setTimeout(() => {
|
|
139
|
+
// Clean up expired sessions (track timer so it can be cleared)
|
|
140
|
+
const sessTimer = setTimeout(() => {
|
|
138
141
|
this.noiseSessions.delete(peerId);
|
|
142
|
+
this.sessionTimeouts.delete(peerId);
|
|
139
143
|
}, this.SESSION_TIMEOUT);
|
|
144
|
+
this.sessionTimeouts.set(peerId, sessTimer);
|
|
140
145
|
return session;
|
|
141
146
|
}
|
|
142
147
|
|
|
@@ -165,7 +170,9 @@ export class IntentExchangeProtocol {
|
|
|
165
170
|
// XOR encryption with session key
|
|
166
171
|
const encrypted = new Uint8Array(payload.length);
|
|
167
172
|
for (let i = 0; i < payload.length; i++) {
|
|
168
|
-
|
|
173
|
+
// XOR operation used intentionally for lightweight obfuscation
|
|
174
|
+
// Prefer Uint8 arithmetic to avoid bitwise lint; modulo ensures 0-255 values
|
|
175
|
+
encrypted[i] = (payload[i] + session.sessionKey[i % session.sessionKey.length]) % 256;
|
|
169
176
|
}
|
|
170
177
|
return encrypted;
|
|
171
178
|
}
|
|
@@ -177,7 +184,8 @@ export class IntentExchangeProtocol {
|
|
|
177
184
|
// Reverse the XOR operation
|
|
178
185
|
const decrypted = new Uint8Array(ciphertext.length);
|
|
179
186
|
for (let i = 0; i < ciphertext.length; i++) {
|
|
180
|
-
|
|
187
|
+
// Reverse the lightweight obfuscation
|
|
188
|
+
decrypted[i] = (256 + ciphertext[i] - session.sessionKey[i % session.sessionKey.length] % 256) % 256;
|
|
181
189
|
}
|
|
182
190
|
const jsonPayload = new TextDecoder().decode(decrypted);
|
|
183
191
|
return JSON.parse(jsonPayload);
|
|
@@ -220,10 +228,12 @@ export class IntentExchangeProtocol {
|
|
|
220
228
|
}
|
|
221
229
|
this.pendingRequests.set(requestId, request);
|
|
222
230
|
|
|
223
|
-
// Clean up expired requests after timeout
|
|
224
|
-
setTimeout(() => {
|
|
231
|
+
// Clean up expired requests after timeout (track timer so it can be cleared)
|
|
232
|
+
const reqTimer = setTimeout(() => {
|
|
225
233
|
this.pendingRequests.delete(requestId);
|
|
234
|
+
this.requestTimeouts.delete(requestId);
|
|
226
235
|
}, this.REQUEST_TIMEOUT);
|
|
236
|
+
this.requestTimeouts.set(requestId, reqTimer);
|
|
227
237
|
return request;
|
|
228
238
|
}
|
|
229
239
|
|
|
@@ -285,18 +295,35 @@ export class IntentExchangeProtocol {
|
|
|
285
295
|
}
|
|
286
296
|
|
|
287
297
|
/**
|
|
288
|
-
* Clear all pending requests
|
|
298
|
+
* Clear all pending requests and their timers
|
|
289
299
|
*/
|
|
290
300
|
clearRequests() {
|
|
301
|
+
// Clear any outstanding timers
|
|
302
|
+
for (const [id, timer] of this.requestTimeouts.entries()) {
|
|
303
|
+
clearTimeout(timer);
|
|
304
|
+
this.requestTimeouts.delete(id);
|
|
305
|
+
}
|
|
291
306
|
this.pendingRequests.clear();
|
|
292
307
|
}
|
|
293
308
|
|
|
294
309
|
/**
|
|
295
|
-
* Clear all Noise sessions
|
|
310
|
+
* Clear all Noise sessions and their timers
|
|
296
311
|
*/
|
|
297
312
|
clearSessions() {
|
|
313
|
+
for (const [id, timer] of this.sessionTimeouts.entries()) {
|
|
314
|
+
clearTimeout(timer);
|
|
315
|
+
this.sessionTimeouts.delete(id);
|
|
316
|
+
}
|
|
298
317
|
this.noiseSessions.clear();
|
|
299
318
|
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Dispose of the protocol, clearing internal state and timers
|
|
322
|
+
*/
|
|
323
|
+
dispose() {
|
|
324
|
+
this.clearRequests();
|
|
325
|
+
this.clearSessions();
|
|
326
|
+
}
|
|
300
327
|
}
|
|
301
328
|
|
|
302
329
|
/**
|