toss-expo-sdk 0.1.2 → 1.0.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 +380 -25
- package/lib/module/ble.js +59 -4
- package/lib/module/ble.js.map +1 -1
- package/lib/module/client/BLETransactionHandler.js +277 -0
- package/lib/module/client/BLETransactionHandler.js.map +1 -0
- package/lib/module/client/NonceAccountManager.js +364 -0
- package/lib/module/client/NonceAccountManager.js.map +1 -0
- package/lib/module/client/TossClient.js +1 -1
- package/lib/module/client/TossClient.js.map +1 -1
- package/lib/module/examples/enhancedFeaturesFlow.js +233 -0
- package/lib/module/examples/enhancedFeaturesFlow.js.map +1 -0
- package/lib/module/examples/offlinePaymentFlow.js +27 -27
- package/lib/module/examples/offlinePaymentFlow.js.map +1 -1
- package/lib/module/hooks/useOfflineBLETransactions.js +314 -0
- package/lib/module/hooks/useOfflineBLETransactions.js.map +1 -0
- package/lib/module/index.js +18 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/intent.js +129 -0
- package/lib/module/intent.js.map +1 -1
- package/lib/module/noise.js +175 -0
- package/lib/module/noise.js.map +1 -1
- package/lib/module/qr.js +2 -2
- package/lib/module/reconciliation.js +155 -0
- package/lib/module/reconciliation.js.map +1 -1
- package/lib/module/services/authService.js +166 -3
- package/lib/module/services/authService.js.map +1 -1
- package/lib/module/storage/secureStorage.js +102 -0
- package/lib/module/storage/secureStorage.js.map +1 -1
- package/lib/module/sync.js +25 -1
- package/lib/module/sync.js.map +1 -1
- package/lib/module/types/nonceAccount.js +2 -0
- package/lib/module/types/nonceAccount.js.map +1 -0
- package/lib/module/types/tossUser.js +16 -1
- package/lib/module/types/tossUser.js.map +1 -1
- package/lib/module/utils/compression.js +210 -0
- package/lib/module/utils/compression.js.map +1 -0
- package/lib/module/wifi.js +311 -0
- package/lib/module/wifi.js.map +1 -0
- package/lib/typescript/src/__tests__/solana-program-simple.test.d.ts +8 -0
- package/lib/typescript/src/__tests__/solana-program-simple.test.d.ts.map +1 -0
- package/lib/typescript/src/ble.d.ts +31 -2
- package/lib/typescript/src/ble.d.ts.map +1 -1
- package/lib/typescript/src/client/BLETransactionHandler.d.ts +98 -0
- package/lib/typescript/src/client/BLETransactionHandler.d.ts.map +1 -0
- package/lib/typescript/src/client/NonceAccountManager.d.ts +82 -0
- package/lib/typescript/src/client/NonceAccountManager.d.ts.map +1 -0
- package/lib/typescript/src/examples/enhancedFeaturesFlow.d.ts +45 -0
- package/lib/typescript/src/examples/enhancedFeaturesFlow.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useOfflineBLETransactions.d.ts +91 -0
- package/lib/typescript/src/hooks/useOfflineBLETransactions.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -4
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/intent.d.ts +15 -0
- package/lib/typescript/src/intent.d.ts.map +1 -1
- package/lib/typescript/src/noise.d.ts +62 -0
- package/lib/typescript/src/noise.d.ts.map +1 -1
- package/lib/typescript/src/reconciliation.d.ts +6 -0
- package/lib/typescript/src/reconciliation.d.ts.map +1 -1
- package/lib/typescript/src/services/authService.d.ts +26 -1
- package/lib/typescript/src/services/authService.d.ts.map +1 -1
- package/lib/typescript/src/storage/secureStorage.d.ts +16 -0
- package/lib/typescript/src/storage/secureStorage.d.ts.map +1 -1
- package/lib/typescript/src/sync.d.ts +6 -1
- package/lib/typescript/src/sync.d.ts.map +1 -1
- package/lib/typescript/src/types/nonceAccount.d.ts +59 -0
- package/lib/typescript/src/types/nonceAccount.d.ts.map +1 -0
- package/lib/typescript/src/types/tossUser.d.ts +16 -0
- package/lib/typescript/src/types/tossUser.d.ts.map +1 -1
- package/lib/typescript/src/utils/compression.d.ts +52 -0
- package/lib/typescript/src/utils/compression.d.ts.map +1 -0
- package/lib/typescript/src/wifi.d.ts +116 -0
- package/lib/typescript/src/wifi.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/solana-program-simple.test.ts +256 -0
- package/src/ble.ts +105 -4
- package/src/client/BLETransactionHandler.ts +364 -0
- package/src/client/NonceAccountManager.ts +444 -0
- package/src/client/TossClient.ts +1 -1
- package/src/examples/enhancedFeaturesFlow.ts +272 -0
- package/src/examples/offlinePaymentFlow.ts +27 -27
- package/src/hooks/useOfflineBLETransactions.ts +438 -0
- package/src/index.tsx +52 -6
- package/src/intent.ts +166 -0
- package/src/noise.ts +238 -0
- package/src/qr.tsx +2 -2
- package/src/reconciliation.ts +184 -0
- package/src/services/authService.ts +190 -3
- package/src/storage/secureStorage.ts +138 -0
- package/src/sync.ts +40 -0
- package/src/types/nonceAccount.ts +75 -0
- package/src/types/tossUser.ts +35 -2
- package/src/utils/compression.ts +247 -0
- package/src/wifi.ts +401 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WiFi Direct Transport for TOSS
|
|
5
|
+
*
|
|
6
|
+
* Higher-bandwidth alternative to BLE for device-to-device communication
|
|
7
|
+
* Fallback to BLE if WiFi Direct unavailable
|
|
8
|
+
*
|
|
9
|
+
* Uses native React Native APIs for production-ready implementation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { NativeModules, Platform } from 'react-native';
|
|
13
|
+
import { TossError } from "./errors.js";
|
|
14
|
+
const {
|
|
15
|
+
WiFiDirect
|
|
16
|
+
} = NativeModules;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* WiFi Direct connection state
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* WiFi Direct socket for data transmission
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* WiFi Direct Transport Handler
|
|
28
|
+
* Wrapper around native WiFi Direct capabilities
|
|
29
|
+
*
|
|
30
|
+
* Supports higher MTU (1200+ bytes) than BLE (480 bytes)
|
|
31
|
+
* Useful for batch transmission of intents
|
|
32
|
+
*/
|
|
33
|
+
export class WiFiDirectTransport {
|
|
34
|
+
connectedPeers = new Map();
|
|
35
|
+
SOCKET_TIMEOUT = 30000; // 30 seconds
|
|
36
|
+
WIFI_MTU = 1200; // Conservative MTU for WiFi packets
|
|
37
|
+
|
|
38
|
+
constructor(_platform = 'android') {
|
|
39
|
+
if (!WiFiDirect) {
|
|
40
|
+
console.warn('WiFi Direct not available in this environment (requires native module)');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Check if WiFi Direct is available on device
|
|
46
|
+
*/
|
|
47
|
+
async isAvailable() {
|
|
48
|
+
if (!WiFiDirect) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
if (Platform.OS === 'android') {
|
|
53
|
+
return await WiFiDirect.isAvailable();
|
|
54
|
+
}
|
|
55
|
+
// iOS uses different APIs (Bonjour, Multipeer Connectivity)
|
|
56
|
+
return true;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.warn('Error checking WiFi Direct availability:', error);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Enable WiFi Direct on device
|
|
65
|
+
*/
|
|
66
|
+
async enable() {
|
|
67
|
+
if (!WiFiDirect) {
|
|
68
|
+
throw new TossError('WiFi Direct native module not available', 'WIFI_DIRECT_UNAVAILABLE');
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
if (Platform.OS === 'android') {
|
|
72
|
+
await WiFiDirect.enable();
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw new TossError(`Failed to enable WiFi Direct: ${error instanceof Error ? error.message : String(error)}`, 'WIFI_DIRECT_ERROR');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Discover nearby WiFi Direct peers
|
|
81
|
+
*/
|
|
82
|
+
async discoverPeers(timeoutSeconds = 10) {
|
|
83
|
+
if (!WiFiDirect) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const peers = await WiFiDirect.discoverPeers(timeoutSeconds * 1000);
|
|
88
|
+
return peers.map(p => ({
|
|
89
|
+
deviceName: p.deviceName,
|
|
90
|
+
deviceAddress: p.deviceAddress,
|
|
91
|
+
isGroupOwner: p.isGroupOwner,
|
|
92
|
+
signalStrength: p.signalStrength
|
|
93
|
+
}));
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.warn('Peer discovery failed:', error);
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Connect to a specific WiFi Direct peer
|
|
102
|
+
*/
|
|
103
|
+
async connectToPeer(deviceAddress) {
|
|
104
|
+
if (!WiFiDirect) {
|
|
105
|
+
throw new TossError('WiFi Direct not available', 'WIFI_DIRECT_UNAVAILABLE');
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const socket = {
|
|
109
|
+
peerId: deviceAddress,
|
|
110
|
+
connected: false,
|
|
111
|
+
bytesTransferred: 0,
|
|
112
|
+
lastActivityTime: Date.now()
|
|
113
|
+
};
|
|
114
|
+
await WiFiDirect.connect(deviceAddress);
|
|
115
|
+
socket.connected = true;
|
|
116
|
+
this.connectedPeers.set(deviceAddress, socket);
|
|
117
|
+
return socket;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
throw new TossError(`Failed to connect to WiFi Direct peer: ${error instanceof Error ? error.message : String(error)}`, 'WIFI_DIRECT_CONNECT_ERROR');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Send intent via WiFi Direct connection
|
|
125
|
+
* Uses larger MTU than BLE for efficiency
|
|
126
|
+
*/
|
|
127
|
+
async sendIntent(socket, intent) {
|
|
128
|
+
if (!socket.connected) {
|
|
129
|
+
throw new TossError('WiFi Direct socket not connected', 'WIFI_DIRECT_DISCONNECTED');
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const intentBuffer = Buffer.from(JSON.stringify(intent), 'utf-8');
|
|
133
|
+
const chunks = Math.ceil(intentBuffer.length / this.WIFI_MTU);
|
|
134
|
+
let totalTransferred = 0;
|
|
135
|
+
for (let i = 0; i < chunks; i++) {
|
|
136
|
+
const start = i * this.WIFI_MTU;
|
|
137
|
+
const end = Math.min(start + this.WIFI_MTU, intentBuffer.length);
|
|
138
|
+
const chunk = intentBuffer.slice(start, end);
|
|
139
|
+
|
|
140
|
+
// Send with simple header: chunk number + total chunks
|
|
141
|
+
const chunkHeader = Buffer.allocUnsafe(2);
|
|
142
|
+
chunkHeader.writeUInt8(i, 0);
|
|
143
|
+
chunkHeader.writeUInt8(chunks, 1);
|
|
144
|
+
const packet = Buffer.concat([chunkHeader, chunk]);
|
|
145
|
+
await WiFiDirect.sendData(socket.peerId, packet);
|
|
146
|
+
totalTransferred += chunk.length;
|
|
147
|
+
|
|
148
|
+
// Update socket stats
|
|
149
|
+
socket.bytesTransferred += chunk.length;
|
|
150
|
+
socket.lastActivityTime = Date.now();
|
|
151
|
+
|
|
152
|
+
// Small delay between chunks to avoid congestion
|
|
153
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
success: true,
|
|
157
|
+
bytesTransferred: totalTransferred,
|
|
158
|
+
chunks
|
|
159
|
+
};
|
|
160
|
+
} catch (error) {
|
|
161
|
+
throw new TossError(`Failed to send intent via WiFi Direct: ${error instanceof Error ? error.message : String(error)}`, 'WIFI_DIRECT_SEND_ERROR');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Send offline transaction via WiFi Direct
|
|
167
|
+
*/
|
|
168
|
+
async sendOfflineTransaction(socket, transaction) {
|
|
169
|
+
const txBuffer = Buffer.from(JSON.stringify(transaction), 'utf-8');
|
|
170
|
+
const chunks = Math.ceil(txBuffer.length / this.WIFI_MTU);
|
|
171
|
+
let totalTransferred = 0;
|
|
172
|
+
for (let i = 0; i < chunks; i++) {
|
|
173
|
+
const start = i * this.WIFI_MTU;
|
|
174
|
+
const end = Math.min(start + this.WIFI_MTU, txBuffer.length);
|
|
175
|
+
const chunk = txBuffer.slice(start, end);
|
|
176
|
+
const chunkHeader = Buffer.allocUnsafe(2);
|
|
177
|
+
chunkHeader.writeUInt8(i, 0);
|
|
178
|
+
chunkHeader.writeUInt8(chunks, 1);
|
|
179
|
+
const packet = Buffer.concat([chunkHeader, chunk]);
|
|
180
|
+
await WiFiDirect.sendData(socket.peerId, packet);
|
|
181
|
+
totalTransferred += chunk.length;
|
|
182
|
+
socket.bytesTransferred += chunk.length;
|
|
183
|
+
socket.lastActivityTime = Date.now();
|
|
184
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
success: true,
|
|
188
|
+
bytesTransferred: totalTransferred,
|
|
189
|
+
chunks
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Receive data from WiFi Direct peer
|
|
195
|
+
*/
|
|
196
|
+
async receiveData(socket, expectedChunks) {
|
|
197
|
+
const chunks = [];
|
|
198
|
+
const receivedChunks = new Set();
|
|
199
|
+
try {
|
|
200
|
+
while (receivedChunks.size < expectedChunks) {
|
|
201
|
+
const packet = await WiFiDirect.receiveData(socket.peerId, 5000); // 5 second timeout
|
|
202
|
+
|
|
203
|
+
if (packet) {
|
|
204
|
+
const chunkNumber = packet[0];
|
|
205
|
+
// Header byte (not used in reassembly)
|
|
206
|
+
const chunkData = packet.slice(2);
|
|
207
|
+
chunks[chunkNumber] = chunkData;
|
|
208
|
+
receivedChunks.add(chunkNumber);
|
|
209
|
+
socket.lastActivityTime = Date.now();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Check timeout
|
|
213
|
+
if (Date.now() - socket.lastActivityTime > this.SOCKET_TIMEOUT) {
|
|
214
|
+
throw new TossError('WiFi Direct socket timeout', 'WIFI_DIRECT_TIMEOUT');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return Buffer.concat(chunks);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
throw new TossError(`Failed to receive data via WiFi Direct: ${error instanceof Error ? error.message : String(error)}`, 'WIFI_DIRECT_RECEIVE_ERROR');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Disconnect from WiFi Direct peer
|
|
225
|
+
*/
|
|
226
|
+
async disconnect(peerId) {
|
|
227
|
+
try {
|
|
228
|
+
const socket = this.connectedPeers.get(peerId);
|
|
229
|
+
if (socket) {
|
|
230
|
+
socket.connected = false;
|
|
231
|
+
this.connectedPeers.delete(peerId);
|
|
232
|
+
}
|
|
233
|
+
if (WiFiDirect) {
|
|
234
|
+
await WiFiDirect.disconnect(peerId);
|
|
235
|
+
}
|
|
236
|
+
} catch (error) {
|
|
237
|
+
console.warn(`Error disconnecting from ${peerId}:`, error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Get all connected peers
|
|
243
|
+
*/
|
|
244
|
+
getConnectedPeers() {
|
|
245
|
+
return Array.from(this.connectedPeers.values()).filter(socket => socket.connected);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Get MTU size for this transport
|
|
250
|
+
*/
|
|
251
|
+
getMTU() {
|
|
252
|
+
return this.WIFI_MTU;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Clean up expired connections
|
|
257
|
+
*/
|
|
258
|
+
cleanupExpiredConnections() {
|
|
259
|
+
const now = Date.now();
|
|
260
|
+
for (const [peerId, socket] of this.connectedPeers.entries()) {
|
|
261
|
+
if (now - socket.lastActivityTime > this.SOCKET_TIMEOUT) {
|
|
262
|
+
this.disconnect(peerId).catch(() => {});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Smart transport selector
|
|
270
|
+
* Automatically chooses best transport for given context
|
|
271
|
+
*/
|
|
272
|
+
export class SmartTransportSelector {
|
|
273
|
+
constructor() {
|
|
274
|
+
this.wifiDirect = new WiFiDirectTransport();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Select best available transport for intent transmission
|
|
279
|
+
*
|
|
280
|
+
* Preference order:
|
|
281
|
+
* 1. WiFi Direct (fastest, 1200 MTU)
|
|
282
|
+
* 2. BLE (fallback, 480 MTU)
|
|
283
|
+
*/
|
|
284
|
+
async selectTransport() {
|
|
285
|
+
const wifiAvailable = await this.wifiDirect.isAvailable();
|
|
286
|
+
if (wifiAvailable) {
|
|
287
|
+
return 'wifi';
|
|
288
|
+
}
|
|
289
|
+
return 'ble';
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Check if WiFi Direct should be used
|
|
294
|
+
* Factors: availability, proximity, battery level
|
|
295
|
+
*/
|
|
296
|
+
async shouldUseWiFi(checkBattery = false) {
|
|
297
|
+
const available = await this.wifiDirect.isAvailable();
|
|
298
|
+
if (!available) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Optional: check battery level
|
|
303
|
+
if (checkBattery) {
|
|
304
|
+
// In production, query Battery API
|
|
305
|
+
// For now, assume battery OK
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=wifi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","TossError","WiFiDirect","WiFiDirectTransport","connectedPeers","Map","SOCKET_TIMEOUT","WIFI_MTU","constructor","_platform","console","warn","isAvailable","OS","error","enable","Error","message","String","discoverPeers","timeoutSeconds","peers","map","p","deviceName","deviceAddress","isGroupOwner","signalStrength","connectToPeer","socket","peerId","connected","bytesTransferred","lastActivityTime","Date","now","connect","set","sendIntent","intent","intentBuffer","Buffer","from","JSON","stringify","chunks","Math","ceil","length","totalTransferred","i","start","end","min","chunk","slice","chunkHeader","allocUnsafe","writeUInt8","packet","concat","sendData","Promise","resolve","setTimeout","success","sendOfflineTransaction","transaction","txBuffer","receiveData","expectedChunks","receivedChunks","Set","size","chunkNumber","chunkData","add","disconnect","get","delete","getConnectedPeers","Array","values","filter","getMTU","cleanupExpiredConnections","entries","catch","SmartTransportSelector","wifiDirect","selectTransport","wifiAvailable","shouldUseWiFi","checkBattery","available"],"sourceRoot":"../../src","sources":["wifi.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAGtD,SAASC,SAAS,QAAQ,aAAU;AAEpC,MAAM;EAAEC;AAAW,CAAC,GAAGH,aAAa;;AAEpC;AACA;AACA;;AAQA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,mBAAmB,CAAC;EACvBC,cAAc,GAAkC,IAAIC,GAAG,CAAC,CAAC;EAChDC,cAAc,GAAG,KAAK,CAAC,CAAC;EACxBC,QAAQ,GAAG,IAAI,CAAC,CAAC;;EAElCC,WAAWA,CAACC,SAA4B,GAAG,SAAS,EAAE;IACpD,IAAI,CAACP,UAAU,EAAE;MACfQ,OAAO,CAACC,IAAI,CACV,wEACF,CAAC;IACH;EACF;;EAEA;AACF;AACA;EACE,MAAMC,WAAWA,CAAA,EAAqB;IACpC,IAAI,CAACV,UAAU,EAAE;MACf,OAAO,KAAK;IACd;IAEA,IAAI;MACF,IAAIF,QAAQ,CAACa,EAAE,KAAK,SAAS,EAAE;QAC7B,OAAO,MAAMX,UAAU,CAACU,WAAW,CAAC,CAAC;MACvC;MACA;MACA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,MAAM,IAAI,CAACF,UAAU,CAAC7E,WAAW,CAAC,CAAC;IAEzD,IAAI+E,aAAa,EAAE;MACjB,OAAO,MAAM;IACf;IAEA,OAAO,KAAK;EACd;;EAEA;AACF;AACA;AACA;EACE,MAAMC,aAAaA,CAACC,YAAqB,GAAG,KAAK,EAAoB;IACnE,MAAMC,SAAS,GAAG,MAAM,IAAI,CAACL,UAAU,CAAC7E,WAAW,CAAC,CAAC;IAErD,IAAI,CAACkF,SAAS,EAAE;MACd,OAAO,KAAK;IACd;;IAEA;IACA,IAAID,YAAY,EAAE;MAChB;MACA;MACA,OAAO,IAAI;IACb;IAEA,OAAO,IAAI;EACb;AACF","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana-program-simple.test.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/solana-program-simple.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
import { Device } from 'react-native-ble-plx';
|
|
2
2
|
import type { TossUser } from './types/tossUser';
|
|
3
3
|
import type { SolanaIntent } from './intent';
|
|
4
|
+
import type { OfflineTransaction } from './types/nonceAccount';
|
|
4
5
|
export declare function requestBLEPermissions(): Promise<void>;
|
|
5
|
-
export declare function startTossScan(onUserFound: (user: TossUser, device: Device) => void, onIntentFound: (intent: SolanaIntent, device: Device) => void): void;
|
|
6
|
+
export declare function startTossScan(onUserFound: (user: TossUser, device: Device) => void, onIntentFound: (intent: SolanaIntent, device: Device) => void, onOfflineTransactionFound?: (tx: OfflineTransaction, device: Device) => void): void;
|
|
6
7
|
export declare function advertiseUser(user: TossUser): Promise<void>;
|
|
7
8
|
export declare function stopAdvertising(): Promise<void>;
|
|
8
9
|
export declare function sendIntentToDevice(deviceId: string, intent: SolanaIntent): Promise<void>;
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Send fragmented offline transaction over BLE with Noise Protocol encryption
|
|
12
|
+
* Automatically handles MTU limitations and retries
|
|
13
|
+
*/
|
|
14
|
+
export declare function sendOfflineTransactionFragmented(device: Device, transaction: OfflineTransaction | SolanaIntent, noiseEncryptFn?: (data: Uint8Array) => Promise<any>, isIntent?: boolean): Promise<{
|
|
15
|
+
success: boolean;
|
|
16
|
+
sentFragments: number;
|
|
17
|
+
failedFragments: number[];
|
|
18
|
+
messageId: string;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Receive and reassemble fragmented message from BLE
|
|
22
|
+
*/
|
|
23
|
+
export declare function receiveOfflineTransactionFragment(fragment: any, noiseDecryptFn?: (encrypted: any) => Promise<Uint8Array>): Promise<{
|
|
24
|
+
complete: boolean;
|
|
25
|
+
transaction?: OfflineTransaction | SolanaIntent;
|
|
26
|
+
progress: {
|
|
27
|
+
received: number;
|
|
28
|
+
total: number;
|
|
29
|
+
};
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Get current BLE MTU configuration
|
|
33
|
+
*/
|
|
34
|
+
export declare function getBLEMTUConfig(): import(".").BLEMTUConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Set custom BLE MTU configuration
|
|
37
|
+
*/
|
|
38
|
+
export declare function setBLEMTUConfig(config: Partial<any>): void;
|
|
10
39
|
//# sourceMappingURL=ble.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ble.d.ts","sourceRoot":"","sources":["../../../src/ble.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"ble.d.ts","sourceRoot":"","sources":["../../../src/ble.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,QAAQ,EAAE,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,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C,CAAC,CAKD;AAED;;GAEG;AACH,wBAAgB,eAAe,6BAE9B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,QAEnD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Device } from 'react-native-ble-plx';
|
|
2
|
+
import type { SolanaIntent } from '../intent';
|
|
3
|
+
import type { OfflineTransaction } from '../types/nonceAccount';
|
|
4
|
+
/**
|
|
5
|
+
* BLE MTU Configuration for different device types
|
|
6
|
+
*/
|
|
7
|
+
export interface BLEMTUConfig {
|
|
8
|
+
maxPayloadSize: number;
|
|
9
|
+
chunkSize: number;
|
|
10
|
+
maxRetries: number;
|
|
11
|
+
timeout: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents a fragmented message with header information
|
|
15
|
+
*/
|
|
16
|
+
export interface BLEFragment {
|
|
17
|
+
messageId: string;
|
|
18
|
+
sequenceNumber: number;
|
|
19
|
+
totalFragments: number;
|
|
20
|
+
checksumValue: number;
|
|
21
|
+
payload: Uint8Array;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Represents a Noise-encrypted BLE message
|
|
25
|
+
*/
|
|
26
|
+
export interface EncryptedBLEMessage {
|
|
27
|
+
version: number;
|
|
28
|
+
ciphertext: Uint8Array;
|
|
29
|
+
nonce: Uint8Array;
|
|
30
|
+
tag: Uint8Array;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* BLETransactionHandler
|
|
34
|
+
* Manages secure, fragmented BLE transmission of offline transactions
|
|
35
|
+
* with Noise Protocol encryption
|
|
36
|
+
*/
|
|
37
|
+
export declare class BLETransactionHandler {
|
|
38
|
+
private mtuConfig;
|
|
39
|
+
private fragmentCache;
|
|
40
|
+
private messageIdMap;
|
|
41
|
+
constructor(platform?: 'android' | 'ios');
|
|
42
|
+
/**
|
|
43
|
+
* Fragment a large transaction/intent into BLE-safe chunks
|
|
44
|
+
* Respects MTU limitations and adds framing information
|
|
45
|
+
*/
|
|
46
|
+
fragmentTransaction(transaction: OfflineTransaction | SolanaIntent, isIntent?: boolean): BLEFragment[];
|
|
47
|
+
/**
|
|
48
|
+
* Prepare encrypted BLE message for transmission
|
|
49
|
+
* Uses Noise Protocol for end-to-end encryption
|
|
50
|
+
*/
|
|
51
|
+
prepareEncryptedMessage(fragment: BLEFragment, noiseEncryptFn: (data: Uint8Array) => Promise<EncryptedBLEMessage>): Promise<EncryptedBLEMessage>;
|
|
52
|
+
/**
|
|
53
|
+
* Send fragmented transaction over BLE with encryption
|
|
54
|
+
* Handles retries and verification
|
|
55
|
+
*/
|
|
56
|
+
sendFragmentedTransactionBLE(device: Device, transaction: OfflineTransaction | SolanaIntent, sendFn: (deviceId: string, characteristicUUID: string, data: Buffer) => Promise<void>, noiseEncryptFn?: (data: Uint8Array) => Promise<EncryptedBLEMessage>, isIntent?: boolean): Promise<{
|
|
57
|
+
success: boolean;
|
|
58
|
+
sentFragments: number;
|
|
59
|
+
failedFragments: number[];
|
|
60
|
+
messageId: string;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Receive and reassemble fragmented messages
|
|
64
|
+
*/
|
|
65
|
+
receiveFragmentedMessage(fragment: BLEFragment, _noiseDecryptFn?: (encrypted: EncryptedBLEMessage) => Promise<Uint8Array>): Promise<{
|
|
66
|
+
complete: boolean;
|
|
67
|
+
transaction?: OfflineTransaction | SolanaIntent;
|
|
68
|
+
progress: {
|
|
69
|
+
received: number;
|
|
70
|
+
total: number;
|
|
71
|
+
};
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Reassemble fragments into original message
|
|
75
|
+
*/
|
|
76
|
+
private reassembleMessage;
|
|
77
|
+
/**
|
|
78
|
+
* Serialize BLE fragment for transmission
|
|
79
|
+
*/
|
|
80
|
+
private serializeFragment;
|
|
81
|
+
/**
|
|
82
|
+
* Calculate CRC32 checksum for fragment verification
|
|
83
|
+
*/
|
|
84
|
+
private calculateCRC32;
|
|
85
|
+
/**
|
|
86
|
+
* Delay utility for retries
|
|
87
|
+
*/
|
|
88
|
+
private delay;
|
|
89
|
+
/**
|
|
90
|
+
* Get MTU configuration
|
|
91
|
+
*/
|
|
92
|
+
getMTUConfig(): BLEMTUConfig;
|
|
93
|
+
/**
|
|
94
|
+
* Set custom MTU configuration
|
|
95
|
+
*/
|
|
96
|
+
setMTUConfig(config: Partial<BLEMTUConfig>): void;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=BLETransactionHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BLETransactionHandler.d.ts","sourceRoot":"","sources":["../../../../src/client/BLETransactionHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAoBD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,UAAU,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE,UAAU,CAAC;IAClB,GAAG,EAAE,UAAU,CAAC;CACjB;AAED;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AAC;KACH,CAAC;IAyDF;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA2BzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAYzB;;OAEG;IACH,OAAO,CAAC,cAAc;IAgBtB;;OAEG;IACH,OAAO,CAAC,KAAK;IAIb;;OAEG;IACH,YAAY,IAAI,YAAY;IAI5B;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;CAMlD"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { PublicKey, Keypair, Connection, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
+
import type { NonceAccountInfo, NonceAccountCacheEntry, CreateNonceAccountOptions, OfflineTransaction } from '../types/nonceAccount';
|
|
3
|
+
import type { TossUser } from '../types/tossUser';
|
|
4
|
+
/**
|
|
5
|
+
* NonceAccountManager
|
|
6
|
+
* Manages durable nonce accounts for secure offline transactions
|
|
7
|
+
* with biometric protection and encrypted storage
|
|
8
|
+
*/
|
|
9
|
+
export declare class NonceAccountManager {
|
|
10
|
+
private cache;
|
|
11
|
+
private connection;
|
|
12
|
+
constructor(connection: Connection);
|
|
13
|
+
/**
|
|
14
|
+
* Create a new durable nonce account for a user
|
|
15
|
+
* Securely stores the nonce account with biometric protection
|
|
16
|
+
*/
|
|
17
|
+
createNonceAccount(user: TossUser, nonceAuthorityKeypair: Keypair, owner: PublicKey, options?: CreateNonceAccountOptions): Promise<NonceAccountInfo>;
|
|
18
|
+
/**
|
|
19
|
+
* Store nonce account securely in device's secure enclave
|
|
20
|
+
* Encrypted and protected by biometric authentication
|
|
21
|
+
*/
|
|
22
|
+
private storeNonceAccountSecurely;
|
|
23
|
+
/**
|
|
24
|
+
* Retrieve nonce account from secure storage
|
|
25
|
+
* Requires biometric verification
|
|
26
|
+
*/
|
|
27
|
+
getNonceAccountSecure(userId: string, authenticator?: () => Promise<void>): Promise<NonceAccountInfo | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Cache nonce account info for quick access
|
|
30
|
+
*/
|
|
31
|
+
private cacheNonceAccount;
|
|
32
|
+
/**
|
|
33
|
+
* Get cached nonce account info
|
|
34
|
+
*/
|
|
35
|
+
getCachedNonceAccount(userId: string): NonceAccountCacheEntry | null;
|
|
36
|
+
/**
|
|
37
|
+
* Prepare offline transaction using nonce account
|
|
38
|
+
* Creates a transaction that can be signed and executed offline
|
|
39
|
+
*/
|
|
40
|
+
prepareOfflineTransaction(user: TossUser, _instructions: TransactionInstruction[], nonceAccountInfo: NonceAccountInfo): Promise<OfflineTransaction>;
|
|
41
|
+
/**
|
|
42
|
+
* Renew nonce account (refresh blockhash and nonce state)
|
|
43
|
+
*/
|
|
44
|
+
renewNonceAccount(userId: string, _nonceAccountAddress: PublicKey): Promise<NonceAccountInfo | null>;
|
|
45
|
+
/**
|
|
46
|
+
* Revoke nonce account (mark as unusable)
|
|
47
|
+
*/
|
|
48
|
+
revokeNonceAccount(userId: string, _nonceAccountAddress: PublicKey): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Clean up expired nonce accounts from cache
|
|
51
|
+
*/
|
|
52
|
+
cleanupExpiredCache(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Validate nonce account status
|
|
55
|
+
*/
|
|
56
|
+
isNonceAccountValid(nonceAccountInfo: NonceAccountInfo): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* GAP #6 FIX: Initialize a durable nonce account onchain
|
|
59
|
+
* Per TOSS Paper Section 4.2: "Replay-protected" nonces
|
|
60
|
+
* This creates the actual SystemProgram nonce account on the blockchain
|
|
61
|
+
*/
|
|
62
|
+
initializeDurableNonceAccountOnchain(authority: PublicKey, nonceAccountKeypair: Keypair, payer: PublicKey, minRentLamports: number): Promise<string>;
|
|
63
|
+
/**
|
|
64
|
+
* GAP #6 FIX: Consume (advance) a nonce account after successful transaction
|
|
65
|
+
* Per TOSS Paper Section 9: Nonce advancement for replay protection
|
|
66
|
+
*/
|
|
67
|
+
consumeNonceAccount(nonceAccountAddress: PublicKey, nonceAuthority: PublicKey): Promise<TransactionInstruction>;
|
|
68
|
+
/**
|
|
69
|
+
* GAP #6 FIX: Validate nonce account state on chain
|
|
70
|
+
* Checks that nonce account exists and is properly configured
|
|
71
|
+
*/
|
|
72
|
+
validateNonceAccountOnchain(nonceAccountAddress: PublicKey, _expectedAuthority?: PublicKey): Promise<{
|
|
73
|
+
valid: boolean;
|
|
74
|
+
error?: string;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* GAP #6 FIX: Get current nonce value from blockchain
|
|
78
|
+
* Reads the actual nonce state from the nonce account
|
|
79
|
+
*/
|
|
80
|
+
getCurrentNonceFromChain(nonceAccountAddress: PublicKey): Promise<number>;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=NonceAccountManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonceAccountManager.d.ts","sourceRoot":"","sources":["../../../../src/client/NonceAccountManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,OAAO,EACP,UAAU,EAIV,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,KAAK,CAAkD;IAC/D,OAAO,CAAC,UAAU,CAAa;gBAEnB,UAAU,EAAE,UAAU;IAIlC;;;OAGG;IACG,kBAAkB,CACtB,IAAI,EAAE,QAAQ,EACd,qBAAqB,EAAE,OAAO,EAC9B,KAAK,EAAE,SAAS,EAChB,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,gBAAgB,CAAC;IAoD5B;;;OAGG;YACW,yBAAyB;IAqBvC;;;OAGG;IACG,qBAAqB,CACzB,MAA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SAAS,GAC7B,OAAO,CAAC,MAAM,CAAC;CAiBnB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complete Example: Enhanced TOSS Flow with Compression, Incentives & WiFi
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates:
|
|
5
|
+
* 1. Compression of intent metadata
|
|
6
|
+
* 2. Smart transport selection (WiFi > BLE)
|
|
7
|
+
* 3. Relay incentive tracking
|
|
8
|
+
* 4. Mesh clustering for optimal routing
|
|
9
|
+
*/
|
|
10
|
+
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
11
|
+
/**
|
|
12
|
+
* Example 1: Metadata Compression Flow
|
|
13
|
+
*
|
|
14
|
+
* Compress large memo text before transmission
|
|
15
|
+
*/
|
|
16
|
+
export declare function exampleCompressedIntentFlow(sender: Keypair, recipient: PublicKey, amount: number, connection: Connection): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Example 2: Smart Transport Selection
|
|
19
|
+
*
|
|
20
|
+
* Automatically choose WiFi Direct if available, fallback to BLE
|
|
21
|
+
*/
|
|
22
|
+
export declare function exampleSmartTransportFlow(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Example 3: Relay Incentive Tracking
|
|
25
|
+
*
|
|
26
|
+
* Calculate and track rewards for devices relaying transactions
|
|
27
|
+
*/
|
|
28
|
+
export declare function exampleRelayIncentiveFlow(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Example 4: Mesh Clustering & Smart Routing
|
|
31
|
+
*
|
|
32
|
+
* Use signal strength to form clusters and find optimal paths
|
|
33
|
+
*/
|
|
34
|
+
export declare function exampleMeshClusteringFlow(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Example 5: Complete Production Flow
|
|
37
|
+
*
|
|
38
|
+
* Integrates compression + WiFi transport + incentives + optimal routing
|
|
39
|
+
*/
|
|
40
|
+
export declare function exampleCompleteEnhancedFlow(sender: Keypair, recipient: PublicKey, amount: number, connection: Connection, _feePayer: PublicKey): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Run all examples
|
|
43
|
+
*/
|
|
44
|
+
export declare function runAllExamples(connection: Connection): Promise<void>;
|
|
45
|
+
//# sourceMappingURL=enhancedFeaturesFlow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enhancedFeaturesFlow.d.ts","sourceRoot":"","sources":["../../../../src/examples/enhancedFeaturesFlow.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQjE;;;;GAIG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,IAAI,CAAC,CAsCf;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC,CAsB/D;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC,CA6B/D;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC,CAwB/D;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CA0Df;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAiC1E"}
|