toss-expo-sdk 0.1.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/LICENSE +20 -0
- package/README.md +292 -0
- package/lib/module/ble.js +103 -0
- package/lib/module/ble.js.map +1 -0
- package/lib/module/client/TossClient.js +324 -0
- package/lib/module/client/TossClient.js.map +1 -0
- package/lib/module/client/index.js +4 -0
- package/lib/module/client/index.js.map +1 -0
- package/lib/module/contexts/WalletContext.js +99 -0
- package/lib/module/contexts/WalletContext.js.map +1 -0
- package/lib/module/discovery.js +434 -0
- package/lib/module/discovery.js.map +1 -0
- package/lib/module/errors.js +47 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/examples/offlinePaymentFlow.js +234 -0
- package/lib/module/examples/offlinePaymentFlow.js.map +1 -0
- package/lib/module/index.js +32 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/intent.js +223 -0
- package/lib/module/intent.js.map +1 -0
- package/lib/module/intentManager.js +145 -0
- package/lib/module/intentManager.js.map +1 -0
- package/lib/module/internal/arciumHelper.js +50 -0
- package/lib/module/internal/arciumHelper.js.map +1 -0
- package/lib/module/nfc.js +54 -0
- package/lib/module/nfc.js.map +1 -0
- package/lib/module/noise.js +14 -0
- package/lib/module/noise.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/qr.js +57 -0
- package/lib/module/qr.js.map +1 -0
- package/lib/module/reconciliation.js +329 -0
- package/lib/module/reconciliation.js.map +1 -0
- package/lib/module/services/authService.js +205 -0
- package/lib/module/services/authService.js.map +1 -0
- package/lib/module/storage/secureStorage.js +89 -0
- package/lib/module/storage/secureStorage.js.map +1 -0
- package/lib/module/storage.js +16 -0
- package/lib/module/storage.js.map +1 -0
- package/lib/module/sync.js +64 -0
- package/lib/module/sync.js.map +1 -0
- package/lib/module/types/tossUser.js +41 -0
- package/lib/module/types/tossUser.js.map +1 -0
- package/lib/module/utils/nonceUtils.js +38 -0
- package/lib/module/utils/nonceUtils.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/__tests__/index.test.d.ts +1 -0
- package/lib/typescript/src/__tests__/index.test.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/reconciliation.test.d.ts +6 -0
- package/lib/typescript/src/__tests__/reconciliation.test.d.ts.map +1 -0
- package/lib/typescript/src/ble.d.ts +10 -0
- package/lib/typescript/src/ble.d.ts.map +1 -0
- package/lib/typescript/src/client/TossClient.d.ts +110 -0
- package/lib/typescript/src/client/TossClient.d.ts.map +1 -0
- package/lib/typescript/src/client/index.d.ts +3 -0
- package/lib/typescript/src/client/index.d.ts.map +1 -0
- package/lib/typescript/src/contexts/WalletContext.d.ts +20 -0
- package/lib/typescript/src/contexts/WalletContext.d.ts.map +1 -0
- package/lib/typescript/src/discovery.d.ts +188 -0
- package/lib/typescript/src/discovery.d.ts.map +1 -0
- package/lib/typescript/src/errors.d.ts +27 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/examples/offlinePaymentFlow.d.ts +48 -0
- package/lib/typescript/src/examples/offlinePaymentFlow.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +13 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/intent.d.ts +84 -0
- package/lib/typescript/src/intent.d.ts.map +1 -0
- package/lib/typescript/src/intentManager.d.ts +46 -0
- package/lib/typescript/src/intentManager.d.ts.map +1 -0
- package/lib/typescript/src/internal/arciumHelper.d.ts +19 -0
- package/lib/typescript/src/internal/arciumHelper.d.ts.map +1 -0
- package/lib/typescript/src/nfc.d.ts +7 -0
- package/lib/typescript/src/nfc.d.ts.map +1 -0
- package/lib/typescript/src/noise.d.ts +5 -0
- package/lib/typescript/src/noise.d.ts.map +1 -0
- package/lib/typescript/src/qr.d.ts +6 -0
- package/lib/typescript/src/qr.d.ts.map +1 -0
- package/lib/typescript/src/reconciliation.d.ts +65 -0
- package/lib/typescript/src/reconciliation.d.ts.map +1 -0
- package/lib/typescript/src/services/authService.d.ts +55 -0
- package/lib/typescript/src/services/authService.d.ts.map +1 -0
- package/lib/typescript/src/storage/secureStorage.d.ts +7 -0
- package/lib/typescript/src/storage/secureStorage.d.ts.map +1 -0
- package/lib/typescript/src/storage.d.ts +4 -0
- package/lib/typescript/src/storage.d.ts.map +1 -0
- package/lib/typescript/src/sync.d.ts +40 -0
- package/lib/typescript/src/sync.d.ts.map +1 -0
- package/lib/typescript/src/types/tossUser.d.ts +39 -0
- package/lib/typescript/src/types/tossUser.d.ts.map +1 -0
- package/lib/typescript/src/utils/nonceUtils.d.ts +8 -0
- package/lib/typescript/src/utils/nonceUtils.d.ts.map +1 -0
- package/package.json +176 -0
- package/src/__tests__/index.test.tsx +1 -0
- package/src/__tests__/reconciliation.test.tsx +361 -0
- package/src/ble.ts +138 -0
- package/src/client/TossClient.ts +435 -0
- package/src/client/index.ts +2 -0
- package/src/contexts/WalletContext.tsx +127 -0
- package/src/discovery.ts +542 -0
- package/src/errors.ts +51 -0
- package/src/examples/offlinePaymentFlow.ts +331 -0
- package/src/index.tsx +61 -0
- package/src/intent.ts +328 -0
- package/src/intentManager.ts +164 -0
- package/src/internal/arciumHelper.ts +58 -0
- package/src/nfc.ts +57 -0
- package/src/noise.ts +9 -0
- package/src/qr.tsx +65 -0
- package/src/reconciliation.ts +421 -0
- package/src/services/authService.ts +238 -0
- package/src/storage/secureStorage.ts +100 -0
- package/src/storage.ts +17 -0
- package/src/sync.ts +101 -0
- package/src/types/tossUser.ts +81 -0
- package/src/utils/nonceUtils.ts +56 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { Keypair } from '@solana/web3.js';
|
|
3
|
+
import type { TossUser } from '../types/tossUser';
|
|
4
|
+
type WalletContextType = {
|
|
5
|
+
isInitialized: boolean;
|
|
6
|
+
isUnlocked: boolean;
|
|
7
|
+
user: TossUser | null;
|
|
8
|
+
keypair: Keypair | null;
|
|
9
|
+
unlockWallet: () => Promise<boolean>;
|
|
10
|
+
lockWallet: () => Promise<void>;
|
|
11
|
+
signIn: (walletAddress: string, isTemporary?: boolean) => Promise<void>;
|
|
12
|
+
signOut: () => Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
declare const WalletContext: import("react").Context<WalletContextType | undefined>;
|
|
15
|
+
export declare const WalletProvider: React.FC<{
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const useWallet: () => WalletContextType;
|
|
19
|
+
export default WalletContext;
|
|
20
|
+
//# sourceMappingURL=WalletContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WalletContext.d.ts","sourceRoot":"","sources":["../../../../src/contexts/WalletContext.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,KAAK,iBAAiB,GAAG;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAEF,QAAA,MAAM,aAAa,wDAA0D,CAAC;AAE9E,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,CAiG5D,CAAC;AAEF,eAAO,MAAM,SAAS,QAAO,iBAM5B,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device Discovery and Intent Exchange Protocol for TOSS
|
|
3
|
+
*
|
|
4
|
+
* Implements Section 11-12 of the TOSS Technical Paper:
|
|
5
|
+
* - Device discovery and peer identification
|
|
6
|
+
* - Intent exchange protocol
|
|
7
|
+
* - Trust establishment between offline peers
|
|
8
|
+
* - Conflict resolution for multi-device scenarios
|
|
9
|
+
*/
|
|
10
|
+
import type { SolanaIntent } from './intent';
|
|
11
|
+
import type { TossUser } from './types/tossUser';
|
|
12
|
+
/**
|
|
13
|
+
* Peer device information discovered via transport
|
|
14
|
+
*/
|
|
15
|
+
export interface PeerDevice {
|
|
16
|
+
id: string;
|
|
17
|
+
user?: TossUser;
|
|
18
|
+
lastSeen: number;
|
|
19
|
+
transport: 'ble' | 'nfc' | 'qr' | 'mesh';
|
|
20
|
+
signalStrength?: number;
|
|
21
|
+
trustScore?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Encrypted intent exchange session
|
|
25
|
+
*/
|
|
26
|
+
export interface NoiseSession {
|
|
27
|
+
peerId: string;
|
|
28
|
+
sessionKey: Uint8Array;
|
|
29
|
+
encryptionCipher: any;
|
|
30
|
+
createdAt: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Intent exchange request/response
|
|
34
|
+
*/
|
|
35
|
+
export interface IntentExchangeRequest {
|
|
36
|
+
requestId: string;
|
|
37
|
+
timestamp: number;
|
|
38
|
+
intent: SolanaIntent;
|
|
39
|
+
requesterId: string;
|
|
40
|
+
requesterUser?: TossUser;
|
|
41
|
+
expiresAt: number;
|
|
42
|
+
encrypted?: boolean;
|
|
43
|
+
ciphertext?: Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
export interface IntentExchangeResponse {
|
|
46
|
+
requestId: string;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
status: 'accepted' | 'rejected' | 'deferred';
|
|
49
|
+
responderId: string;
|
|
50
|
+
reason?: string;
|
|
51
|
+
acknowledgedIntentIds?: string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Device discovery service
|
|
55
|
+
*/
|
|
56
|
+
export declare class DeviceDiscoveryService {
|
|
57
|
+
private discoveredPeers;
|
|
58
|
+
private readonly PEER_TIMEOUT;
|
|
59
|
+
private readonly MAX_PEERS;
|
|
60
|
+
/**
|
|
61
|
+
* Register a discovered peer device
|
|
62
|
+
*/
|
|
63
|
+
registerPeer(peer: PeerDevice): void;
|
|
64
|
+
/**
|
|
65
|
+
* Get all active peers (not timed out)
|
|
66
|
+
*/
|
|
67
|
+
getActivePeers(): PeerDevice[];
|
|
68
|
+
/**
|
|
69
|
+
* Get a specific peer by ID
|
|
70
|
+
*/
|
|
71
|
+
getPeer(peerId: string): PeerDevice | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Update trust score for a peer based on interaction
|
|
74
|
+
*/
|
|
75
|
+
updateTrustScore(peerId: string, delta: number, maxScore?: number): void;
|
|
76
|
+
/**
|
|
77
|
+
* Clear all discovered peers
|
|
78
|
+
*/
|
|
79
|
+
clearPeers(): void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Intent exchange protocol handler with Noise encryption support
|
|
83
|
+
*/
|
|
84
|
+
export declare class IntentExchangeProtocol {
|
|
85
|
+
private pendingRequests;
|
|
86
|
+
private noiseSessions;
|
|
87
|
+
private deviceStaticKey;
|
|
88
|
+
private readonly REQUEST_TIMEOUT;
|
|
89
|
+
private readonly SESSION_TIMEOUT;
|
|
90
|
+
constructor();
|
|
91
|
+
/**
|
|
92
|
+
* Establish a secure Noise session with a peer
|
|
93
|
+
*/
|
|
94
|
+
establishSecureSession(peerId: string): NoiseSession;
|
|
95
|
+
/**
|
|
96
|
+
* Get an active Noise session with a peer
|
|
97
|
+
*/
|
|
98
|
+
getSecureSession(peerId: string): NoiseSession | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Encrypt request payload using Noise session
|
|
101
|
+
*/
|
|
102
|
+
private encryptRequestPayload;
|
|
103
|
+
/**
|
|
104
|
+
* Decrypt request payload using Noise session
|
|
105
|
+
*/
|
|
106
|
+
private decryptRequestPayload;
|
|
107
|
+
/**
|
|
108
|
+
* Create a new intent exchange request with optional Noise encryption
|
|
109
|
+
*/
|
|
110
|
+
createRequest(intent: SolanaIntent, requesterId: string, requesterUser?: TossUser, expiresIn?: number, // 5 minutes default
|
|
111
|
+
useEncryption?: boolean, // Enable Noise encryption
|
|
112
|
+
peerId?: string): IntentExchangeRequest;
|
|
113
|
+
/**
|
|
114
|
+
* Respond to an intent exchange request
|
|
115
|
+
*/
|
|
116
|
+
createResponse(requestId: string, responderId: string, status: 'accepted' | 'rejected' | 'deferred', reason?: string, acknowledgedIntentIds?: string[]): IntentExchangeResponse;
|
|
117
|
+
/**
|
|
118
|
+
* Get a pending request, decrypting if necessary
|
|
119
|
+
*/
|
|
120
|
+
getRequest(requestId: string, peerId?: string): IntentExchangeRequest | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Get the static key for this device (for peer verification)
|
|
123
|
+
*/
|
|
124
|
+
getDeviceStaticKey(): Uint8Array;
|
|
125
|
+
/**
|
|
126
|
+
* Clear all pending requests
|
|
127
|
+
*/
|
|
128
|
+
clearRequests(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Clear all Noise sessions
|
|
131
|
+
*/
|
|
132
|
+
clearSessions(): void;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Device and intent routing service for multi-hop scenarios
|
|
136
|
+
*/
|
|
137
|
+
export declare class IntentRoutingService {
|
|
138
|
+
private routingTable;
|
|
139
|
+
private readonly MAX_HOPS;
|
|
140
|
+
/**
|
|
141
|
+
* Register a routing path to a device
|
|
142
|
+
*/
|
|
143
|
+
registerRoute(targetDeviceId: string, viaPeers: string[]): void;
|
|
144
|
+
/**
|
|
145
|
+
* Get the best route to a device
|
|
146
|
+
*/
|
|
147
|
+
getRoute(targetDeviceId: string): string[] | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Find all reachable devices
|
|
150
|
+
*/
|
|
151
|
+
getReachableDevices(): string[];
|
|
152
|
+
/**
|
|
153
|
+
* Validate a route is still viable
|
|
154
|
+
*/
|
|
155
|
+
validateRoute(targetDeviceId: string, activePeers: PeerDevice[]): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Clear all routes
|
|
158
|
+
*/
|
|
159
|
+
clearRoutes(): void;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Multi-device conflict resolver
|
|
163
|
+
*
|
|
164
|
+
* When multiple devices are offline and both create intents for the same
|
|
165
|
+
* action, this detects and resolves the conflict per TOSS principles.
|
|
166
|
+
*/
|
|
167
|
+
export declare class MultiDeviceConflictResolver {
|
|
168
|
+
/**
|
|
169
|
+
* Detect conflicting intents from different devices
|
|
170
|
+
*/
|
|
171
|
+
static detectConflicts(intents: SolanaIntent[]): SolanaIntent[][];
|
|
172
|
+
/**
|
|
173
|
+
* Resolve conflicts using deterministic rules per TOSS spec
|
|
174
|
+
*
|
|
175
|
+
* Rules (in order):
|
|
176
|
+
* 1. Earliest nonce wins (replay protection)
|
|
177
|
+
* 2. Earliest timestamp wins (FIFO fairness)
|
|
178
|
+
* 3. Lexicographically first signature wins (deterministic tiebreak)
|
|
179
|
+
*/
|
|
180
|
+
static resolveConflicts(conflictingIntents: SolanaIntent[]): {
|
|
181
|
+
winner: SolanaIntent;
|
|
182
|
+
losers: SolanaIntent[];
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export declare const deviceDiscovery: DeviceDiscoveryService;
|
|
186
|
+
export declare const intentExchange: IntentExchangeProtocol;
|
|
187
|
+
export declare const intentRouting: IntentRoutingService;
|
|
188
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../src/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAKjD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,KAAK,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,CAAC;IACzC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,gBAAgB,EAAE,GAAG,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,UAAU,GAAG,UAA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xB;CA0CF;AAED,eAAO,MAAM,eAAe,wBAA+B,CAAC;AAC5D,eAAO,MAAM,cAAc,wBAA+B,CAAC;AAC3D,eAAO,MAAM,aAAa,sBAA6B,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare class TossError extends Error {
|
|
2
|
+
code: string;
|
|
3
|
+
details?: any | undefined;
|
|
4
|
+
constructor(message: string, code: string, details?: any | undefined);
|
|
5
|
+
}
|
|
6
|
+
export declare class IntentValidationError extends TossError {
|
|
7
|
+
constructor(message: string, details?: any);
|
|
8
|
+
}
|
|
9
|
+
export declare class NetworkError extends TossError {
|
|
10
|
+
constructor(message: string, details?: any);
|
|
11
|
+
}
|
|
12
|
+
export declare class StorageError extends TossError {
|
|
13
|
+
constructor(message: string, details?: any);
|
|
14
|
+
}
|
|
15
|
+
export declare class SignatureError extends TossError {
|
|
16
|
+
constructor(message: string, details?: any);
|
|
17
|
+
}
|
|
18
|
+
export declare const ERROR_CODES: {
|
|
19
|
+
readonly INVALID_INTENT: "INVALID_INTENT";
|
|
20
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
21
|
+
readonly STORAGE_ERROR: "STORAGE_ERROR";
|
|
22
|
+
readonly SIGNATURE_VERIFICATION_FAILED: "SIGNATURE_VERIFICATION_FAILED";
|
|
23
|
+
readonly INTENT_EXPIRED: "INTENT_EXPIRED";
|
|
24
|
+
readonly INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS";
|
|
25
|
+
readonly TRANSACTION_FAILED: "TRANSACTION_FAILED";
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;IAGzB,IAAI,EAAE,MAAM;IACZ,OAAO,CAAC,EAAE,GAAG;gBAFpB,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,GAAG,YAAA;CAQvB;AAED,qBAAa,qBAAsB,SAAQ,SAAS;gBACtC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAI3C;AAED,qBAAa,YAAa,SAAQ,SAAS;gBAC7B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAI3C;AAED,qBAAa,YAAa,SAAQ,SAAS;gBAC7B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAI3C;AAED,qBAAa,cAAe,SAAQ,SAAS;gBAC/B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAI3C;AAED,eAAO,MAAM,WAAW;;;;;;;;CAQd,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complete Offline Payment Flow Example
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates the full TOSS lifecycle per Section 12 of the Technical Paper:
|
|
5
|
+
* 1. Sender constructs and signs payment intent
|
|
6
|
+
* 2. Intent is exchanged offline via BLE/NFC/QR
|
|
7
|
+
* 3. Both devices store pending intent
|
|
8
|
+
* 4. When connectivity is restored, devices reconcile
|
|
9
|
+
* 5. Intent is submitted onchain with deterministic outcome
|
|
10
|
+
*/
|
|
11
|
+
import { Connection, Keypair } from '@solana/web3.js';
|
|
12
|
+
import { type SolanaIntent } from '../intent';
|
|
13
|
+
import { type PeerDevice } from '../discovery';
|
|
14
|
+
/**
|
|
15
|
+
* Example: Sender initiates offline payment
|
|
16
|
+
*
|
|
17
|
+
* This simulates a sender who wants to send lamports to a recipient
|
|
18
|
+
* while offline. The intent is created, signed, and stored locally.
|
|
19
|
+
*/
|
|
20
|
+
export declare function exampleInitiateOfflinePayment(senderKeypair: Keypair, recipientAddress: string, amountLamports: number, connection: Connection): Promise<SolanaIntent>;
|
|
21
|
+
/**
|
|
22
|
+
* Example: Intent exchange via proximity (BLE/NFC)
|
|
23
|
+
*
|
|
24
|
+
* One device has an intent it wants to share with a nearby peer.
|
|
25
|
+
* This demonstrates the intent exchange protocol.
|
|
26
|
+
*/
|
|
27
|
+
export declare function exampleExchangeIntentWithPeer(intent: SolanaIntent, localDeviceId: string, peerDeviceId: string, peerDevice: PeerDevice): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Example: Multiple devices create conflicting intents
|
|
30
|
+
*
|
|
31
|
+
* Demonstrates TOSS's deterministic conflict resolution when
|
|
32
|
+
* multiple offline devices create intents for the same action.
|
|
33
|
+
*/
|
|
34
|
+
export declare function exampleMultiDeviceConflict(connection: Connection): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Example: Full offline-to-settlement flow
|
|
37
|
+
*
|
|
38
|
+
* Shows the complete journey of an intent from creation to onchain settlement.
|
|
39
|
+
*/
|
|
40
|
+
export declare function exampleCompleteOfflineFlow(senderKeypair: Keypair, recipientAddress: string, amountLamports: number, connection: Connection): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Example: Verify intent before exchange
|
|
43
|
+
*
|
|
44
|
+
* Good practice: receivers should verify intent signatures
|
|
45
|
+
* before accepting and storing them.
|
|
46
|
+
*/
|
|
47
|
+
export declare function exampleVerifyIntentBeforeAcceptance(intent: SolanaIntent, connection: Connection): Promise<boolean>;
|
|
48
|
+
//# sourceMappingURL=offlinePaymentFlow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offlinePaymentFlow.d.ts","sourceRoot":"","sources":["../../../../src/examples/offlinePaymentFlow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAa,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAgB,KAAK,YAAY,EAAgB,MAAM,WAAW,CAAC;AAK1E,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,cAAc,CAAC;AAItB;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,aAAa,EAAE,OAAO,EACtB,gBAAgB,EAAE,MAAM,EACxB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,YAAY,CAAC,CAyBvB;AAED;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,YAAY,EACpB,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,IAAI,CAAC,CAwCf;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,IAAI,CAAC,CAsDf;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAC9C,aAAa,EAAE,OAAO,EACtB,gBAAgB,EAAE,MAAM,EACxB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,IAAI,CAAC,CA4Gf;AAED;;;;;GAKG;AACH,wBAAsB,mCAAmC,CACvD,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,OAAO,CAAC,CAoBlB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { createIntent, type SolanaIntent, type IntentStatus } from './intent';
|
|
2
|
+
export { verifyIntentSignature, isIntentExpired, updateIntentStatus, validateIntent, processIntentsForSync, filterExpiredIntents, } from './intentManager';
|
|
3
|
+
export { storePendingIntent, getPendingIntents, clearPendingIntents, } from './storage';
|
|
4
|
+
export { startTossScan, requestBLEPermissions } from './ble';
|
|
5
|
+
export { initNFC, readNFCUser, writeUserToNFC, writeIntentToNFC } from './nfc';
|
|
6
|
+
export { QRScanner } from './qr';
|
|
7
|
+
export { TossClient, type TossConfig } from './client/TossClient';
|
|
8
|
+
import { TossClient } from './client/TossClient';
|
|
9
|
+
export declare const createClient: typeof TossClient.createClient;
|
|
10
|
+
export { syncToChain, checkSyncStatus, type SyncResult } from './sync';
|
|
11
|
+
export { reconcilePendingIntents, settleIntent, validateIntentOnchain, buildTransactionFromIntent, submitTransactionToChain, detectConflicts, getReconciliationState, type SettlementResult, type ReconciliationState, } from './reconciliation';
|
|
12
|
+
export { DeviceDiscoveryService, IntentExchangeProtocol, IntentRoutingService, MultiDeviceConflictResolver, deviceDiscovery, intentExchange, intentRouting, type PeerDevice, type IntentExchangeRequest, type IntentExchangeResponse, } from './discovery';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAG9E,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGlE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,eAAO,MAAM,YAAY,gCAA0B,CAAC;AAGpD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGvE,OAAO,EACL,uBAAuB,EACvB,YAAY,EACZ,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,eAAe,EACf,sBAAsB,EACtB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,2BAA2B,EAC3B,eAAe,EACf,cAAc,EACd,aAAa,EACb,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,GAC5B,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { PublicKey, Keypair, Connection } from '@solana/web3.js';
|
|
2
|
+
import { type ArciumEncryptedOutput } from './internal/arciumHelper';
|
|
3
|
+
/**
|
|
4
|
+
* Status of an intent in its lifecycle
|
|
5
|
+
*/
|
|
6
|
+
export type IntentStatus = 'pending' | 'settled' | 'failed' | 'expired';
|
|
7
|
+
/**
|
|
8
|
+
* Core type for an offline intent following TOSS specification
|
|
9
|
+
*/
|
|
10
|
+
export interface SolanaIntent {
|
|
11
|
+
id: string;
|
|
12
|
+
from: string;
|
|
13
|
+
to: string;
|
|
14
|
+
amount: number;
|
|
15
|
+
nonce: number;
|
|
16
|
+
expiry: number;
|
|
17
|
+
signature: string;
|
|
18
|
+
status: IntentStatus;
|
|
19
|
+
createdAt: number;
|
|
20
|
+
updatedAt: number;
|
|
21
|
+
error?: string;
|
|
22
|
+
blockhash?: string;
|
|
23
|
+
feePayer?: string;
|
|
24
|
+
signatures?: string[];
|
|
25
|
+
serialized?: string;
|
|
26
|
+
nonceAccount?: string;
|
|
27
|
+
nonceAuth?: string;
|
|
28
|
+
encrypted?: ArciumEncryptedOutput;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for creating a new intent
|
|
32
|
+
*/
|
|
33
|
+
export interface CreateIntentOptions {
|
|
34
|
+
/** Whether to encrypt the transaction details using Arcium */
|
|
35
|
+
privateTransaction?: boolean;
|
|
36
|
+
/** Program ID for Arcium encryption */
|
|
37
|
+
mxeProgramId?: PublicKey;
|
|
38
|
+
/** Provider for blockchain access */
|
|
39
|
+
provider?: any;
|
|
40
|
+
/** Expiry time in seconds from now (default: 1 hour) */
|
|
41
|
+
expiresIn?: number;
|
|
42
|
+
/** Custom nonce (auto-generated if not provided) */
|
|
43
|
+
nonce?: number;
|
|
44
|
+
/** Keypair for the nonce account (for durable transactions) */
|
|
45
|
+
nonceAccount?: Keypair;
|
|
46
|
+
/** Public key authorized to use the nonce account */
|
|
47
|
+
nonceAuth?: PublicKey;
|
|
48
|
+
/** Fee payer for the transaction (defaults to sender) */
|
|
49
|
+
feePayer?: PublicKey | string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Manages nonce values for transaction replay protection
|
|
53
|
+
*/
|
|
54
|
+
declare class NonceManager {
|
|
55
|
+
private nonceStore;
|
|
56
|
+
private readonly NONCE_EXPIRY;
|
|
57
|
+
getNextNonce(publicKey: PublicKey, connection: Connection): Promise<number>;
|
|
58
|
+
private extractNonceFromAccountInfo;
|
|
59
|
+
private cleanupNonces;
|
|
60
|
+
}
|
|
61
|
+
export declare const nonceManager: NonceManager;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a signed intent that can be verified offline
|
|
64
|
+
*/
|
|
65
|
+
export declare function createSignedIntent(sender: Keypair, recipient: PublicKey, amount: number, connection: Connection, options?: CreateIntentOptions): Promise<SolanaIntent>;
|
|
66
|
+
/**
|
|
67
|
+
* Verifies the signature, nonce, and expiry of an intent
|
|
68
|
+
*/
|
|
69
|
+
export declare function verifyIntent(intent: SolanaIntent, connection?: Connection): Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* Creates an offline Solana intent following TOSS specification.
|
|
72
|
+
* If privateTransaction is true, encrypts internal data with Arcium.
|
|
73
|
+
*/
|
|
74
|
+
export declare function createIntent(sender: Keypair, recipient: PublicKey, amount: number, connection: Connection, options?: CreateIntentOptions): Promise<SolanaIntent>;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if an intent has expired
|
|
77
|
+
*/
|
|
78
|
+
export declare function isIntentExpired(intent: SolanaIntent): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Updates the status of an intent
|
|
81
|
+
*/
|
|
82
|
+
export declare function updateIntentStatus(intent: SolanaIntent, status: IntentStatus, error?: string): SolanaIntent;
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=intent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent.d.ts","sourceRoot":"","sources":["../../../src/intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAMjE,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,yBAAyB,CAAC;AAGjC;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,YAAY;IAE3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,YAAY,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IAGf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IAGnB,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,8DAA8D;IAC9D,kBAAkB,CAAC,EAAE,OAAO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AY,GAAG,OAAO,CAE7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,EACpB,KAAK,CAAC,EAAE,MAAM,GACb,YAAY,CAOd"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SolanaIntent, IntentStatus } from './intent';
|
|
2
|
+
/**
|
|
3
|
+
* Verifies the signature of a Solana intent
|
|
4
|
+
* @param intent The intent to verify
|
|
5
|
+
* @returns boolean indicating if the signature is valid
|
|
6
|
+
*/
|
|
7
|
+
export declare function verifyIntentSignature(intent: SolanaIntent): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if an intent has expired
|
|
10
|
+
* @param intent The intent to check
|
|
11
|
+
* @returns boolean indicating if the intent has expired
|
|
12
|
+
*/
|
|
13
|
+
export declare function isIntentExpired(intent: SolanaIntent): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Updates the status of an intent
|
|
16
|
+
* @param intent The intent to update
|
|
17
|
+
* @param status The new status
|
|
18
|
+
* @param error Optional error message if status is 'failed'
|
|
19
|
+
* @returns A new intent with updated status
|
|
20
|
+
*/
|
|
21
|
+
export declare function updateIntentStatus(intent: SolanaIntent, status: IntentStatus, error?: string): SolanaIntent;
|
|
22
|
+
/**
|
|
23
|
+
* Validates an intent against current blockchain state
|
|
24
|
+
* Note: This is a placeholder - actual implementation would check against a Solana node
|
|
25
|
+
* @param intent The intent to validate
|
|
26
|
+
* @param currentBlockhash Current network blockhash
|
|
27
|
+
* @returns Validation result with success status and optional error message
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateIntent(intent: SolanaIntent, currentBlockhash: string): Promise<{
|
|
30
|
+
valid: boolean;
|
|
31
|
+
error?: string;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Processes a batch of intents for synchronization
|
|
35
|
+
* @param intents Array of intents to process
|
|
36
|
+
* @param connection Connection to Solana network
|
|
37
|
+
* @returns Processed intents with updated statuses
|
|
38
|
+
*/
|
|
39
|
+
export declare function processIntentsForSync(intents: SolanaIntent[], connection: any): Promise<SolanaIntent[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Filters out expired intents and updates their status
|
|
42
|
+
* @param intents Array of intents to check
|
|
43
|
+
* @returns Tuple of [validIntents, expiredIntents]
|
|
44
|
+
*/
|
|
45
|
+
export declare function filterExpiredIntents(intents: SolanaIntent[]): [SolanaIntent[], SolanaIntent[]];
|
|
46
|
+
//# sourceMappingURL=intentManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intentManager.d.ts","sourceRoot":"","sources":["../../../src/intentManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAgBnE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,EACpB,KAAK,CAAC,EAAE,MAAM,GACb,YAAY,CAOd;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,YAAY,EACpB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAiC7C;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,YAAY,EAAE,EACvB,UAAU,EAAE,GAAG,GACd,OAAO,CAAC,YAAY,EAAE,CAAC,CA+BzB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,YAAY,EAAE,GACtB,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,CAAC,CAalC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PublicKey } from '@solana/web3.js';
|
|
2
|
+
/**
|
|
3
|
+
* Output from Arcium encryption (internal only)
|
|
4
|
+
*/
|
|
5
|
+
export type ArciumEncryptedOutput = {
|
|
6
|
+
ciphertext: number[][];
|
|
7
|
+
publicKey: Uint8Array;
|
|
8
|
+
nonce: Uint8Array;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Internal helper to encrypt a set of numeric values with Arcium.
|
|
12
|
+
* Does not leak anything about Arcium to the SDK consumer.
|
|
13
|
+
*
|
|
14
|
+
* @param mxeProgramId PublicKey of the MXE
|
|
15
|
+
* @param plaintextValues numeric values for encryption
|
|
16
|
+
* @param provider Solana provider (e.g., AnchorProvider)
|
|
17
|
+
*/
|
|
18
|
+
export declare function encryptForArciumInternal(mxeProgramId: PublicKey, plaintextValues: bigint[], provider: any): Promise<ArciumEncryptedOutput>;
|
|
19
|
+
//# sourceMappingURL=arciumHelper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arciumHelper.d.ts","sourceRoot":"","sources":["../../../../src/internal/arciumHelper.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC;IACvB,SAAS,EAAE,UAAU,CAAC;IACtB,KAAK,EAAE,UAAU,CAAC;CACnB,CAAC;AACF;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,CAC5C,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,MAAM,EAAE,EACzB,QAAQ,EAAE,GAAG,GACZ,OAAO,CAAC,qBAAqB,CAAC,CA4BhC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TossUser } from './types/tossUser';
|
|
2
|
+
import type { SolanaIntent } from './intent';
|
|
3
|
+
export declare function initNFC(): Promise<void>;
|
|
4
|
+
export declare function readNFCUser(): Promise<TossUser>;
|
|
5
|
+
export declare function writeUserToNFC(user: TossUser): Promise<boolean>;
|
|
6
|
+
export declare function writeIntentToNFC(intent: SolanaIntent): Promise<boolean>;
|
|
7
|
+
//# sourceMappingURL=nfc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nfc.d.ts","sourceRoot":"","sources":["../../../src/nfc.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,wBAAgB,OAAO,kBAEtB;AAGD,wBAAsB,WAAW,IAAI,OAAO,CAAC,QAAQ,CAAC,CAgBrD;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAYrE;AAGD,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAY7E"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize Noise secure session with a static key.
|
|
3
|
+
*/
|
|
4
|
+
export declare function initNoiseSession(staticKey: Uint8Array): (components: import("@chainsafe/libp2p-noise").NoiseComponents) => import("@libp2p/interface").ConnectionEncrypter<import("@chainsafe/libp2p-noise").NoiseExtensions>;
|
|
5
|
+
//# sourceMappingURL=noise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise.d.ts","sourceRoot":"","sources":["../../../src/noise.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,UAAU,yKAGrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qr.d.ts","sourceRoot":"","sources":["../../../src/qr.tsx"],"names":[],"mappings":"AASA,KAAK,cAAc,GAAG;IACpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC,CAAC;AAEF,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,cAAc,2CAwCnD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reconciliation and Settlement Module for TOSS
|
|
3
|
+
*
|
|
4
|
+
* Implements Section 9-10 of the TOSS Technical Paper:
|
|
5
|
+
* - Synchronisation and reconciliation with onchain state
|
|
6
|
+
* - Deterministic failure handling
|
|
7
|
+
* - Conflict resolution
|
|
8
|
+
*/
|
|
9
|
+
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
|
|
10
|
+
import type { SolanaIntent } from './intent';
|
|
11
|
+
/**
|
|
12
|
+
* Result of intent settlement attempt
|
|
13
|
+
*/
|
|
14
|
+
export interface SettlementResult {
|
|
15
|
+
intentId: string;
|
|
16
|
+
status: 'success' | 'failed' | 'rejected';
|
|
17
|
+
signature?: string;
|
|
18
|
+
error?: string;
|
|
19
|
+
timestamp: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* State of a device's reconciliation with onchain
|
|
23
|
+
*/
|
|
24
|
+
export interface ReconciliationState {
|
|
25
|
+
lastSyncTime: number;
|
|
26
|
+
lastSyncSlot: number;
|
|
27
|
+
processedIntents: string[];
|
|
28
|
+
failedIntents: string[];
|
|
29
|
+
conflictingIntents: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validates an intent can be settled with current onchain state
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateIntentOnchain(intent: SolanaIntent, connection: Connection): Promise<{
|
|
35
|
+
valid: boolean;
|
|
36
|
+
error?: string;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Builds a Solana transaction from an intent
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildTransactionFromIntent(intent: SolanaIntent, connection: Connection, feePayer?: PublicKey): Promise<Transaction>;
|
|
42
|
+
/**
|
|
43
|
+
* Submits a transaction to the network with confirmation
|
|
44
|
+
*/
|
|
45
|
+
export declare function submitTransactionToChain(transaction: Transaction, connection: Connection, maxRetries?: number): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Attempts to settle a single intent and returns the result
|
|
48
|
+
*/
|
|
49
|
+
export declare function settleIntent(intent: SolanaIntent, connection: Connection, feePayer?: PublicKey): Promise<SettlementResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Core reconciliation: process all pending intents for settlement
|
|
52
|
+
*/
|
|
53
|
+
export declare function reconcilePendingIntents(connection: Connection, feePayer?: PublicKey): Promise<SettlementResult[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Detects conflicts between local intents and onchain state
|
|
56
|
+
*/
|
|
57
|
+
export declare function detectConflicts(connection: Connection): Promise<{
|
|
58
|
+
intentId: string;
|
|
59
|
+
conflict: string;
|
|
60
|
+
}[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Gets reconciliation state summary
|
|
63
|
+
*/
|
|
64
|
+
export declare function getReconciliationState(connection: Connection): Promise<ReconciliationState>;
|
|
65
|
+
//# sourceMappingURL=reconciliation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconciliation.d.ts","sourceRoot":"","sources":["../../../src/reconciliation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,UAAU,EACV,SAAS,EACT,WAAW,EAEZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,UAAU,CAAC;AAQ3D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,UAAU,CAAC;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;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