@obscura-fhe/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,488 @@
1
+ import * as viem from 'viem';
2
+ import { Address, PublicClient, Hex } from 'viem';
3
+
4
+ /** Arbitrum Sepolia deployment snapshot — sync from contracts-hardhat/deployments/arb-sepolia.json */
5
+ interface ObscuraAddresses {
6
+ ocUSDC_Pay: Address;
7
+ ObscuraPay: Address;
8
+ ObscuraPayStreamV3: Address;
9
+ ObscuraConfidentialEscrow: Address;
10
+ ObscuraInvoice: Address;
11
+ ObscuraStealthRegistry: Address;
12
+ ObscuraVote: Address;
13
+ ObscuraTreasury: Address;
14
+ ObscuraRewards: Address;
15
+ ObscuraCreditFactory: Address;
16
+ ObscuraCreditOracle: Address;
17
+ ObscuraCreditIRM: Address;
18
+ ObscuraCreditAuction: Address;
19
+ ObscuraCreditScoreV2: Address;
20
+ CreditCanonicalPayOcUSDCMarket: Address;
21
+ v2_ConservativeVault: Address;
22
+ v2_BalancedVault: Address;
23
+ ObscuraGovernor: Address;
24
+ ObscuraTimelock: Address;
25
+ }
26
+ declare const ARBITRUM_SEPOLIA_CHAIN_ID = 421614;
27
+ declare const DEFAULT_RPC_URL = "https://sepolia-rollup.arbitrum.io/rpc";
28
+ declare const DEFAULT_API_URL = "https://obscura-api-n62v.onrender.com";
29
+ declare const DEFAULT_SUPABASE_URL = "https://quoovjkjwgtdqwdofubh.supabase.co";
30
+ declare const DEFAULT_ADDRESSES: ObscuraAddresses;
31
+
32
+ type ReputationTier = "new" | "active" | "steady" | "reliable";
33
+ type ReputationSourceApp = "all" | "pay" | "credit" | "vote";
34
+ interface ReputationSignalSummary {
35
+ label: string;
36
+ count: number;
37
+ cappedWeight: number;
38
+ latestAt: string | null;
39
+ }
40
+ interface ReputationSummary {
41
+ wallet: Address;
42
+ sourceApp: ReputationSourceApp;
43
+ totalCappedWeight: number;
44
+ tier: ReputationTier;
45
+ signals: Record<string, ReputationSignalSummary>;
46
+ sources?: Record<string, number>;
47
+ updatedAt: string | null;
48
+ }
49
+ interface NotificationPrefs {
50
+ wallet: Address;
51
+ push_enabled: boolean;
52
+ email_enabled: boolean;
53
+ email?: string;
54
+ events: string[];
55
+ }
56
+ interface PushSubscriptionJSON {
57
+ endpoint: string;
58
+ expirationTime?: number | null;
59
+ keys: {
60
+ p256dh: string;
61
+ auth: string;
62
+ };
63
+ }
64
+ type ActivityEventType = "all" | "sent" | "received" | "stream" | "invoice" | "escrow" | "stealth" | "credit" | "vote";
65
+ interface ActivityItem {
66
+ id: number;
67
+ chain_id: number;
68
+ block_number: string;
69
+ tx_hash: string;
70
+ log_index: number;
71
+ contract_address: string;
72
+ event_name: string;
73
+ wallet: string;
74
+ participants: string[];
75
+ args: Record<string, unknown>;
76
+ created_at: string;
77
+ }
78
+ interface ActivityListOptions {
79
+ filter?: ActivityEventType;
80
+ page?: number;
81
+ pageSize?: number;
82
+ }
83
+ interface ActivityListResult {
84
+ items: ActivityItem[];
85
+ page: number;
86
+ pageSize: number;
87
+ hasMore: boolean;
88
+ }
89
+ /** FHE encrypted uint64 input tuple for contract calls */
90
+ interface InEuint64 {
91
+ ctHash: bigint;
92
+ securityZone: number;
93
+ utype: number;
94
+ signature: `0x${string}`;
95
+ }
96
+ interface ContractCall {
97
+ address: Address;
98
+ abi: readonly unknown[];
99
+ functionName: string;
100
+ args: readonly unknown[];
101
+ chainId: number;
102
+ }
103
+ interface ProposalState {
104
+ id: bigint;
105
+ creator: Address;
106
+ title: string;
107
+ description: string;
108
+ options: string[];
109
+ startTime: bigint;
110
+ endTime: bigint;
111
+ finalized: boolean;
112
+ winningOption: bigint;
113
+ }
114
+ interface ObscuraSDKConfig {
115
+ chainId?: number;
116
+ rpcUrl?: string;
117
+ apiUrl?: string;
118
+ supabaseUrl?: string;
119
+ supabaseAnonKey?: string;
120
+ addresses?: Partial<ObscuraAddresses>;
121
+ publicClient?: viem.PublicClient;
122
+ walletClient?: viem.WalletClient;
123
+ fhe?: FheProvider;
124
+ }
125
+
126
+ interface FheEncryptOptions {
127
+ contractAddress: Address;
128
+ onStep?: (step: string) => void;
129
+ }
130
+ /** Injectable FHE adapter — host supplies @cofhe/sdk or custom implementation */
131
+ interface FheProvider {
132
+ encryptUint64(value: bigint, options: FheEncryptOptions): Promise<InEuint64>;
133
+ decryptCtHash?(ctHash: bigint, contractAddress: Address): Promise<bigint>;
134
+ }
135
+ declare class FheRequiredError extends Error {
136
+ constructor(operation: string);
137
+ }
138
+
139
+ declare const ACTIVITY_EVENT_FILTERS: Record<ActivityEventType, readonly string[]>;
140
+ type ActivityEventFilterMap = typeof ACTIVITY_EVENT_FILTERS;
141
+
142
+ declare class ActivityModule {
143
+ private readonly client;
144
+ constructor(supabaseUrl: string | undefined, supabaseAnonKey: string | undefined);
145
+ getEventFilters(): ActivityEventFilterMap;
146
+ listForWallet(wallet: Address, options?: ActivityListOptions): Promise<ActivityListResult>;
147
+ }
148
+
149
+ interface CreditModuleDeps {
150
+ chainId: number;
151
+ addresses: ObscuraAddresses;
152
+ fhe?: FheProvider;
153
+ }
154
+ declare class CreditModule {
155
+ private readonly deps;
156
+ constructor(deps: CreditModuleDeps);
157
+ getMarketAddress(override?: Address): Address;
158
+ buildSupplyCollateral(amount: bigint, encryptedAmount?: InEuint64, marketAddress?: Address): Promise<ContractCall>;
159
+ buildBorrow(amount: bigint, encryptedAmount?: InEuint64, marketAddress?: Address): Promise<ContractCall>;
160
+ buildRepay(amount: bigint, encryptedAmount?: InEuint64, marketAddress?: Address): Promise<ContractCall>;
161
+ }
162
+
163
+ declare class HttpClient {
164
+ private readonly baseUrl;
165
+ constructor(baseUrl: string);
166
+ get url(): string;
167
+ get<T>(path: string, init?: RequestInit): Promise<T>;
168
+ post<T>(path: string, body: unknown, init?: RequestInit): Promise<T>;
169
+ delete<T>(path: string, body?: unknown, init?: RequestInit): Promise<T>;
170
+ }
171
+ declare class HttpError extends Error {
172
+ readonly status: number;
173
+ constructor(status: number, message: string);
174
+ }
175
+
176
+ declare class NotificationsModule {
177
+ private readonly http;
178
+ constructor(http: HttpClient);
179
+ getVapidPublicKey(): Promise<string>;
180
+ getPrefs(wallet: Address): Promise<NotificationPrefs | null>;
181
+ savePrefs(prefs: NotificationPrefs): Promise<void>;
182
+ subscribe(wallet: Address, subscription: PushSubscriptionJSON): Promise<void>;
183
+ unsubscribe(wallet: Address): Promise<void>;
184
+ }
185
+
186
+ interface PayModuleDeps {
187
+ chainId: number;
188
+ addresses: ObscuraAddresses;
189
+ publicClient: PublicClient;
190
+ fhe?: FheProvider;
191
+ }
192
+ declare class PayModule {
193
+ private readonly deps;
194
+ constructor(deps: PayModuleDeps);
195
+ get ocUsdcAddress(): Address;
196
+ /** Returns encrypted balance ctHash (uint256) for account */
197
+ getShieldedBalance(account: Address): Promise<bigint>;
198
+ buildShield(amount: bigint, encryptedAmount?: InEuint64): Promise<ContractCall>;
199
+ buildUnshield(to: Address, amount: bigint, encryptedAmount?: InEuint64): Promise<ContractCall>;
200
+ buildTransfer(to: Address, amount: bigint, encryptedAmount?: InEuint64): Promise<ContractCall>;
201
+ }
202
+
203
+ declare class ReputationModule {
204
+ private readonly http;
205
+ constructor(http: HttpClient);
206
+ getSummary(wallet: Address): Promise<ReputationSummary>;
207
+ }
208
+
209
+ interface VoteModuleDeps {
210
+ chainId: number;
211
+ addresses: ObscuraAddresses;
212
+ publicClient: PublicClient;
213
+ fhe?: FheProvider;
214
+ }
215
+ declare class VoteModule {
216
+ private readonly deps;
217
+ constructor(deps: VoteModuleDeps);
218
+ get voteAddress(): Address;
219
+ getProposalCount(): Promise<bigint>;
220
+ getProposal(id: bigint): Promise<ProposalState>;
221
+ buildCastVote(proposalId: bigint, optionIndex: number, encryptedOption?: InEuint64): Promise<ContractCall>;
222
+ buildDelegate(delegatee: Address): ContractCall;
223
+ }
224
+
225
+ declare class ObscuraSDK {
226
+ readonly chainId: number;
227
+ readonly addresses: ObscuraAddresses;
228
+ readonly publicClient: PublicClient;
229
+ readonly fhe?: FheProvider;
230
+ readonly pay: PayModule;
231
+ readonly credit: CreditModule;
232
+ readonly vote: VoteModule;
233
+ readonly reputation: ReputationModule;
234
+ readonly activity: ActivityModule;
235
+ readonly notifications: NotificationsModule;
236
+ private readonly walletClient?;
237
+ private constructor();
238
+ static create(config?: ObscuraSDKConfig): ObscuraSDK;
239
+ encodeCall(call: ContractCall): Hex;
240
+ sendCall(call: ContractCall, account: Address): Promise<Hex>;
241
+ }
242
+
243
+ declare function createDefaultPublicClient(rpcUrl: string, chainId: number): PublicClient;
244
+ declare function encodeCall(call: ContractCall): Hex;
245
+
246
+ /** Serialize InEuint64 for viem contract args (bigint ctHash) */
247
+ declare function toContractInEuint64(input: InEuint64): {
248
+ ctHash: bigint;
249
+ securityZone: number;
250
+ utype: number;
251
+ signature: `0x${string}`;
252
+ };
253
+ declare function normalizeWallet(wallet: string): Address | null;
254
+
255
+ declare const OC_USDC_PAY_ABI: readonly [{
256
+ readonly name: "confidentialBalanceOf";
257
+ readonly type: "function";
258
+ readonly stateMutability: "view";
259
+ readonly inputs: readonly [{
260
+ readonly name: "account";
261
+ readonly type: "address";
262
+ }];
263
+ readonly outputs: readonly [{
264
+ readonly name: "";
265
+ readonly type: "uint256";
266
+ }];
267
+ }, {
268
+ readonly name: "shield";
269
+ readonly type: "function";
270
+ readonly stateMutability: "nonpayable";
271
+ readonly inputs: readonly [{
272
+ readonly name: "amount";
273
+ readonly type: "uint256";
274
+ }, {
275
+ readonly name: "encryptedAmount";
276
+ readonly type: "tuple";
277
+ readonly components: readonly [{
278
+ readonly name: "ctHash";
279
+ readonly type: "uint256";
280
+ }, {
281
+ readonly name: "securityZone";
282
+ readonly type: "uint8";
283
+ }, {
284
+ readonly name: "utype";
285
+ readonly type: "uint8";
286
+ }, {
287
+ readonly name: "signature";
288
+ readonly type: "bytes";
289
+ }];
290
+ }];
291
+ readonly outputs: readonly [];
292
+ }, {
293
+ readonly name: "unshield";
294
+ readonly type: "function";
295
+ readonly stateMutability: "nonpayable";
296
+ readonly inputs: readonly [{
297
+ readonly name: "to";
298
+ readonly type: "address";
299
+ }, {
300
+ readonly name: "encryptedAmount";
301
+ readonly type: "tuple";
302
+ readonly components: readonly [{
303
+ readonly name: "ctHash";
304
+ readonly type: "uint256";
305
+ }, {
306
+ readonly name: "securityZone";
307
+ readonly type: "uint8";
308
+ }, {
309
+ readonly name: "utype";
310
+ readonly type: "uint8";
311
+ }, {
312
+ readonly name: "signature";
313
+ readonly type: "bytes";
314
+ }];
315
+ }];
316
+ readonly outputs: readonly [];
317
+ }, {
318
+ readonly name: "confidentialTransfer";
319
+ readonly type: "function";
320
+ readonly stateMutability: "nonpayable";
321
+ readonly inputs: readonly [{
322
+ readonly name: "to";
323
+ readonly type: "address";
324
+ }, {
325
+ readonly name: "encryptedAmount";
326
+ readonly type: "tuple";
327
+ readonly components: readonly [{
328
+ readonly name: "ctHash";
329
+ readonly type: "uint256";
330
+ }, {
331
+ readonly name: "securityZone";
332
+ readonly type: "uint8";
333
+ }, {
334
+ readonly name: "utype";
335
+ readonly type: "uint8";
336
+ }, {
337
+ readonly name: "signature";
338
+ readonly type: "bytes";
339
+ }];
340
+ }];
341
+ readonly outputs: readonly [];
342
+ }];
343
+ declare const CREDIT_MARKET_ABI: readonly [{
344
+ readonly name: "supplyCollateral";
345
+ readonly type: "function";
346
+ readonly stateMutability: "nonpayable";
347
+ readonly inputs: readonly [{
348
+ readonly name: "encryptedAmount";
349
+ readonly type: "tuple";
350
+ readonly components: readonly [{
351
+ readonly name: "ctHash";
352
+ readonly type: "uint256";
353
+ }, {
354
+ readonly name: "securityZone";
355
+ readonly type: "uint8";
356
+ }, {
357
+ readonly name: "utype";
358
+ readonly type: "uint8";
359
+ }, {
360
+ readonly name: "signature";
361
+ readonly type: "bytes";
362
+ }];
363
+ }];
364
+ readonly outputs: readonly [];
365
+ }, {
366
+ readonly name: "borrow";
367
+ readonly type: "function";
368
+ readonly stateMutability: "nonpayable";
369
+ readonly inputs: readonly [{
370
+ readonly name: "encryptedAmount";
371
+ readonly type: "tuple";
372
+ readonly components: readonly [{
373
+ readonly name: "ctHash";
374
+ readonly type: "uint256";
375
+ }, {
376
+ readonly name: "securityZone";
377
+ readonly type: "uint8";
378
+ }, {
379
+ readonly name: "utype";
380
+ readonly type: "uint8";
381
+ }, {
382
+ readonly name: "signature";
383
+ readonly type: "bytes";
384
+ }];
385
+ }];
386
+ readonly outputs: readonly [];
387
+ }, {
388
+ readonly name: "repay";
389
+ readonly type: "function";
390
+ readonly stateMutability: "nonpayable";
391
+ readonly inputs: readonly [{
392
+ readonly name: "encryptedAmount";
393
+ readonly type: "tuple";
394
+ readonly components: readonly [{
395
+ readonly name: "ctHash";
396
+ readonly type: "uint256";
397
+ }, {
398
+ readonly name: "securityZone";
399
+ readonly type: "uint8";
400
+ }, {
401
+ readonly name: "utype";
402
+ readonly type: "uint8";
403
+ }, {
404
+ readonly name: "signature";
405
+ readonly type: "bytes";
406
+ }];
407
+ }];
408
+ readonly outputs: readonly [];
409
+ }];
410
+ declare const OBSCURA_VOTE_ABI: readonly [{
411
+ readonly name: "proposalCount";
412
+ readonly type: "function";
413
+ readonly stateMutability: "view";
414
+ readonly inputs: readonly [];
415
+ readonly outputs: readonly [{
416
+ readonly name: "";
417
+ readonly type: "uint256";
418
+ }];
419
+ }, {
420
+ readonly name: "getProposal";
421
+ readonly type: "function";
422
+ readonly stateMutability: "view";
423
+ readonly inputs: readonly [{
424
+ readonly name: "proposalId";
425
+ readonly type: "uint256";
426
+ }];
427
+ readonly outputs: readonly [{
428
+ readonly name: "creator";
429
+ readonly type: "address";
430
+ }, {
431
+ readonly name: "title";
432
+ readonly type: "string";
433
+ }, {
434
+ readonly name: "description";
435
+ readonly type: "string";
436
+ }, {
437
+ readonly name: "options";
438
+ readonly type: "string[]";
439
+ }, {
440
+ readonly name: "startTime";
441
+ readonly type: "uint256";
442
+ }, {
443
+ readonly name: "endTime";
444
+ readonly type: "uint256";
445
+ }, {
446
+ readonly name: "finalized";
447
+ readonly type: "bool";
448
+ }, {
449
+ readonly name: "winningOption";
450
+ readonly type: "uint256";
451
+ }];
452
+ }, {
453
+ readonly name: "castVote";
454
+ readonly type: "function";
455
+ readonly stateMutability: "nonpayable";
456
+ readonly inputs: readonly [{
457
+ readonly name: "proposalId";
458
+ readonly type: "uint256";
459
+ }, {
460
+ readonly name: "encryptedOption";
461
+ readonly type: "tuple";
462
+ readonly components: readonly [{
463
+ readonly name: "ctHash";
464
+ readonly type: "uint256";
465
+ }, {
466
+ readonly name: "securityZone";
467
+ readonly type: "uint8";
468
+ }, {
469
+ readonly name: "utype";
470
+ readonly type: "uint8";
471
+ }, {
472
+ readonly name: "signature";
473
+ readonly type: "bytes";
474
+ }];
475
+ }];
476
+ readonly outputs: readonly [];
477
+ }, {
478
+ readonly name: "delegate";
479
+ readonly type: "function";
480
+ readonly stateMutability: "nonpayable";
481
+ readonly inputs: readonly [{
482
+ readonly name: "delegatee";
483
+ readonly type: "address";
484
+ }];
485
+ readonly outputs: readonly [];
486
+ }];
487
+
488
+ export { ACTIVITY_EVENT_FILTERS, ARBITRUM_SEPOLIA_CHAIN_ID, type ActivityEventFilterMap, type ActivityEventType, type ActivityItem, type ActivityListOptions, type ActivityListResult, ActivityModule, CREDIT_MARKET_ABI, type ContractCall, CreditModule, DEFAULT_ADDRESSES, DEFAULT_API_URL, DEFAULT_RPC_URL, DEFAULT_SUPABASE_URL, type FheEncryptOptions, type FheProvider, FheRequiredError, HttpError, type InEuint64, type NotificationPrefs, NotificationsModule, OBSCURA_VOTE_ABI, OC_USDC_PAY_ABI, type ObscuraAddresses, ObscuraSDK, type ObscuraSDKConfig, PayModule, type ProposalState, type PushSubscriptionJSON, ReputationModule, type ReputationSignalSummary, type ReputationSourceApp, type ReputationSummary, type ReputationTier, VoteModule, createDefaultPublicClient, encodeCall, normalizeWallet, toContractInEuint64 };