@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.
package/dist/index.cjs ADDED
@@ -0,0 +1,670 @@
1
+ 'use strict';
2
+
3
+ var viem = require('viem');
4
+ var chains = require('viem/chains');
5
+ var supabaseJs = require('@supabase/supabase-js');
6
+
7
+ // src/config/defaults.ts
8
+ var ARBITRUM_SEPOLIA_CHAIN_ID = 421614;
9
+ var DEFAULT_RPC_URL = "https://sepolia-rollup.arbitrum.io/rpc";
10
+ var DEFAULT_API_URL = "https://obscura-api-n62v.onrender.com";
11
+ var DEFAULT_SUPABASE_URL = "https://quoovjkjwgtdqwdofubh.supabase.co";
12
+ var DEFAULT_ADDRESSES = {
13
+ ocUSDC_Pay: "0xEd46020Df8abe7BB1E096f27d089F4326D223a53",
14
+ ObscuraPay: "0x91CdD9a481C732bEB09Ce039da23DC11e83547a4",
15
+ ObscuraPayStreamV3: "0xE4328F139F03138D63f7fdF90A8Ef240e04653fA",
16
+ ObscuraConfidentialEscrow: "0x293810A2081114CcE0c98A709a0c31aE07c01D75",
17
+ ObscuraInvoice: "0x62a86C8d68fF32ea41Faf349db6EF7EF496620b7",
18
+ ObscuraStealthRegistry: "0xa36e791a611D36e2C817a7DA0f41547D30D4917d",
19
+ ObscuraVote: "0xe358776AfdbA95d7c9F040e6ef1f5A021aF91730",
20
+ ObscuraTreasury: "0x89252ee3f920978EEfDB650760fe56BA1Ede8c08",
21
+ ObscuraRewards: "0x435ea117404553A6868fbe728A7A284FCEd15BC2",
22
+ ObscuraCreditFactory: "0x5aDC1965D155f4b18119222CBA7a7A4be4F45680",
23
+ ObscuraCreditOracle: "0x5F00910533AB6fc12a35a87BaFe856EF2cb323c3",
24
+ ObscuraCreditIRM: "0xA072c038cE98dEC8F5350D451145fB98F5EA57Bc",
25
+ ObscuraCreditAuction: "0x205FfC0A3b8207B645c1a6B1b4805eb3FfC828F0",
26
+ ObscuraCreditScoreV2: "0xe5B0c6c06C0B1fd7d7CD5D2e93997693863d3D4D",
27
+ CreditCanonicalPayOcUSDCMarket: "0x1Ec113297c7F9516A6604aa3b18C180559a6f551",
28
+ v2_ConservativeVault: "0xCEBb042ae8FDE217a9FdE5b8a82E23827FdBB898",
29
+ v2_BalancedVault: "0xF508315bD4C5EC4c71C5E431AE972C0dC6B78Bbc",
30
+ ObscuraGovernor: "0xE4807C9F90a0da8F5B5bafa4361B15ff855b7186",
31
+ ObscuraTimelock: "0x07b7961627f433a1d9001F82Ac4af9F19b9a9E05"
32
+ };
33
+ function mergeAddresses(partial) {
34
+ return { ...DEFAULT_ADDRESSES, ...partial };
35
+ }
36
+
37
+ // src/fhe/types.ts
38
+ var FheRequiredError = class extends Error {
39
+ constructor(operation) {
40
+ super(
41
+ `FHE provider required for ${operation}. Pass fhe in ObscuraSDK.create() or supply a pre-encrypted InEuint64.`
42
+ );
43
+ this.name = "FheRequiredError";
44
+ }
45
+ };
46
+
47
+ // src/core/utils.ts
48
+ async function resolveInEuint64(value, contractAddress, fhe, preEncrypted) {
49
+ if (preEncrypted) return preEncrypted;
50
+ if (!fhe) throw new FheRequiredError("encrypted amount");
51
+ return fhe.encryptUint64(value, { contractAddress });
52
+ }
53
+ function toContractInEuint64(input) {
54
+ return {
55
+ ctHash: input.ctHash,
56
+ securityZone: input.securityZone,
57
+ utype: input.utype,
58
+ signature: input.signature
59
+ };
60
+ }
61
+ function normalizeWallet(wallet) {
62
+ if (!/^0x[0-9a-fA-F]{40}$/.test(wallet)) return null;
63
+ return wallet.toLowerCase();
64
+ }
65
+ function stripTrailingSlash(url) {
66
+ return url.replace(/\/$/, "");
67
+ }
68
+
69
+ // src/core/http.ts
70
+ var HttpClient = class {
71
+ constructor(baseUrl) {
72
+ this.baseUrl = baseUrl;
73
+ }
74
+ baseUrl;
75
+ get url() {
76
+ return stripTrailingSlash(this.baseUrl);
77
+ }
78
+ async get(path, init) {
79
+ const response = await fetch(`${this.url}${path}`, {
80
+ ...init,
81
+ method: "GET",
82
+ headers: { Accept: "application/json", ...init?.headers }
83
+ });
84
+ if (!response.ok) {
85
+ const body = await response.text().catch(() => "");
86
+ throw new HttpError(response.status, `GET ${path} failed (${response.status})${body ? `: ${body}` : ""}`);
87
+ }
88
+ return response.json();
89
+ }
90
+ async post(path, body, init) {
91
+ const response = await fetch(`${this.url}${path}`, {
92
+ ...init,
93
+ method: "POST",
94
+ headers: {
95
+ Accept: "application/json",
96
+ "Content-Type": "application/json",
97
+ ...init?.headers
98
+ },
99
+ body: JSON.stringify(body)
100
+ });
101
+ if (!response.ok) {
102
+ const text = await response.text().catch(() => "");
103
+ throw new HttpError(response.status, `POST ${path} failed (${response.status})${text ? `: ${text}` : ""}`);
104
+ }
105
+ return response.json();
106
+ }
107
+ async delete(path, body, init) {
108
+ const response = await fetch(`${this.url}${path}`, {
109
+ ...init,
110
+ method: "DELETE",
111
+ headers: {
112
+ Accept: "application/json",
113
+ "Content-Type": "application/json",
114
+ ...init?.headers
115
+ },
116
+ body: body !== void 0 ? JSON.stringify(body) : void 0
117
+ });
118
+ if (!response.ok) {
119
+ const text = await response.text().catch(() => "");
120
+ throw new HttpError(response.status, `DELETE ${path} failed (${response.status})${text ? `: ${text}` : ""}`);
121
+ }
122
+ return response.json();
123
+ }
124
+ };
125
+ var HttpError = class extends Error {
126
+ constructor(status, message) {
127
+ super(message);
128
+ this.status = status;
129
+ this.name = "HttpError";
130
+ }
131
+ status;
132
+ };
133
+ function resolveChain(chainId) {
134
+ if (chainId === ARBITRUM_SEPOLIA_CHAIN_ID) return chains.arbitrumSepolia;
135
+ return {
136
+ ...chains.arbitrumSepolia,
137
+ id: chainId
138
+ };
139
+ }
140
+ function createDefaultPublicClient(rpcUrl, chainId) {
141
+ return viem.createPublicClient({
142
+ chain: resolveChain(chainId),
143
+ transport: viem.http(rpcUrl || DEFAULT_RPC_URL)
144
+ });
145
+ }
146
+ function encodeCall(call) {
147
+ return viem.encodeFunctionData({
148
+ abi: call.abi,
149
+ functionName: call.functionName,
150
+ args: [...call.args]
151
+ });
152
+ }
153
+ async function sendContractCall(call, walletClient, account) {
154
+ const hash = await walletClient.writeContract({
155
+ address: call.address,
156
+ abi: call.abi,
157
+ functionName: call.functionName,
158
+ args: [...call.args],
159
+ chain: resolveChain(call.chainId),
160
+ account
161
+ });
162
+ return hash;
163
+ }
164
+ function makeCall(chainId, address, abi, functionName, args) {
165
+ return { address, abi, functionName, args, chainId };
166
+ }
167
+
168
+ // src/config/activity-filters.ts
169
+ var CREDIT_ACTIVITY_EVENT_NAMES = [
170
+ "ObscuraCreditMarket.Supplied",
171
+ "ObscuraCreditMarket.Withdrawn",
172
+ "ObscuraCreditMarket.Borrowed",
173
+ "ObscuraCreditMarket.Repaid",
174
+ "ObscuraCreditMarket.Liquidated",
175
+ "ObscuraCreditMarket.CollateralSupplied",
176
+ "ObscuraCreditMarket.CollateralWithdrawn",
177
+ "ObscuraCreditVault.Deposited",
178
+ "ObscuraCreditVault.Withdrew",
179
+ "ObscuraCreditAuction.AuctionCreated",
180
+ "ObscuraCreditAuction.BidPlaced",
181
+ "ObscuraCreditAuction.AuctionSettled",
182
+ "ObscuraCreditScoreV2.ScoreUpdated"
183
+ ];
184
+ var VOTE_ACTIVITY_EVENT_NAMES = [
185
+ "ObscuraVote.ProposalCreated",
186
+ "ObscuraVote.VoteCast",
187
+ "ObscuraVote.VoteChanged",
188
+ "ObscuraVote.Delegated",
189
+ "ObscuraVote.DelegationRemoved",
190
+ "ObscuraVote.ProposalFinalized",
191
+ "ObscuraTreasury.SpendAttached",
192
+ "ObscuraTreasury.SpendExecuted",
193
+ "ObscuraRewards.RewardAccrued",
194
+ "ObscuraRewards.RewardWithdrawn"
195
+ ];
196
+ var ACTIVITY_EVENT_FILTERS = {
197
+ all: [],
198
+ sent: ["ObscuraPay.PaymentSent"],
199
+ received: ["ObscuraPay.PaymentReceived"],
200
+ stream: [
201
+ "ObscuraPayStreamV2.StreamCreated",
202
+ "ObscuraPayStreamV2.StreamCancelled",
203
+ "ObscuraPayStreamV2.StreamWithdrawn",
204
+ "ObscuraPayStreamV3.StreamCreated",
205
+ "ObscuraPayStreamV3.StreamCancelled",
206
+ "ObscuraPayStreamV3.CycleSettled"
207
+ ],
208
+ invoice: ["ObscuraInvoice.InvoiceCreated", "ObscuraInvoice.InvoicePaid"],
209
+ escrow: [
210
+ "ObscuraConfidentialEscrow.EscrowCreated",
211
+ "ObscuraConfidentialEscrow.EscrowFunded",
212
+ "ObscuraConfidentialEscrow.EscrowRedeemed",
213
+ "ObscuraConfidentialEscrow.EscrowCancelled",
214
+ "ObscuraConfidentialEscrow.EscrowRefunded"
215
+ ],
216
+ stealth: ["ObscuraStealthRegistry.Announcement", "ObscuraStealthRegistry.MetaAddressSet"],
217
+ credit: CREDIT_ACTIVITY_EVENT_NAMES,
218
+ vote: VOTE_ACTIVITY_EVENT_NAMES
219
+ };
220
+
221
+ // src/modules/activity.ts
222
+ var DEFAULT_PAGE_SIZE = 20;
223
+ var ActivityModule = class {
224
+ client;
225
+ constructor(supabaseUrl, supabaseAnonKey) {
226
+ this.client = supabaseUrl && supabaseAnonKey ? supabaseJs.createClient(supabaseUrl, supabaseAnonKey) : null;
227
+ }
228
+ getEventFilters() {
229
+ return ACTIVITY_EVENT_FILTERS;
230
+ }
231
+ async listForWallet(wallet, options = {}) {
232
+ if (!this.client) {
233
+ throw new Error(
234
+ "Supabase not configured. Pass supabaseUrl and supabaseAnonKey to ObscuraSDK.create()."
235
+ );
236
+ }
237
+ const normalized = normalizeWallet(wallet);
238
+ if (!normalized) throw new Error("Invalid wallet address");
239
+ const filter = options.filter ?? "all";
240
+ const page = options.page ?? 0;
241
+ const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE;
242
+ let query = this.client.from("obscura_activity").select("*").contains("participants", [normalized]).order("block_number", { ascending: false }).range(page * pageSize, page * pageSize + pageSize - 1);
243
+ const allowed = ACTIVITY_EVENT_FILTERS[filter];
244
+ if (allowed.length > 0) {
245
+ query = query.in("event_name", [...allowed]);
246
+ }
247
+ const { data, error } = await query;
248
+ if (error) throw new Error(error.message);
249
+ const items = data ?? [];
250
+ return {
251
+ items,
252
+ page,
253
+ pageSize,
254
+ hasMore: items.length === pageSize
255
+ };
256
+ }
257
+ };
258
+
259
+ // src/abis/index.ts
260
+ var IN_EUINT64_COMPONENTS = [
261
+ { name: "ctHash", type: "uint256" },
262
+ { name: "securityZone", type: "uint8" },
263
+ { name: "utype", type: "uint8" },
264
+ { name: "signature", type: "bytes" }
265
+ ];
266
+ var OC_USDC_PAY_ABI = [
267
+ {
268
+ name: "confidentialBalanceOf",
269
+ type: "function",
270
+ stateMutability: "view",
271
+ inputs: [{ name: "account", type: "address" }],
272
+ outputs: [{ name: "", type: "uint256" }]
273
+ },
274
+ {
275
+ name: "shield",
276
+ type: "function",
277
+ stateMutability: "nonpayable",
278
+ inputs: [
279
+ { name: "amount", type: "uint256" },
280
+ { name: "encryptedAmount", type: "tuple", components: [...IN_EUINT64_COMPONENTS] }
281
+ ],
282
+ outputs: []
283
+ },
284
+ {
285
+ name: "unshield",
286
+ type: "function",
287
+ stateMutability: "nonpayable",
288
+ inputs: [
289
+ { name: "to", type: "address" },
290
+ { name: "encryptedAmount", type: "tuple", components: [...IN_EUINT64_COMPONENTS] }
291
+ ],
292
+ outputs: []
293
+ },
294
+ {
295
+ name: "confidentialTransfer",
296
+ type: "function",
297
+ stateMutability: "nonpayable",
298
+ inputs: [
299
+ { name: "to", type: "address" },
300
+ { name: "encryptedAmount", type: "tuple", components: [...IN_EUINT64_COMPONENTS] }
301
+ ],
302
+ outputs: []
303
+ }
304
+ ];
305
+ var CREDIT_MARKET_ABI = [
306
+ {
307
+ name: "supplyCollateral",
308
+ type: "function",
309
+ stateMutability: "nonpayable",
310
+ inputs: [
311
+ { name: "encryptedAmount", type: "tuple", components: [...IN_EUINT64_COMPONENTS] }
312
+ ],
313
+ outputs: []
314
+ },
315
+ {
316
+ name: "borrow",
317
+ type: "function",
318
+ stateMutability: "nonpayable",
319
+ inputs: [
320
+ { name: "encryptedAmount", type: "tuple", components: [...IN_EUINT64_COMPONENTS] }
321
+ ],
322
+ outputs: []
323
+ },
324
+ {
325
+ name: "repay",
326
+ type: "function",
327
+ stateMutability: "nonpayable",
328
+ inputs: [
329
+ { name: "encryptedAmount", type: "tuple", components: [...IN_EUINT64_COMPONENTS] }
330
+ ],
331
+ outputs: []
332
+ }
333
+ ];
334
+ var OBSCURA_VOTE_ABI = [
335
+ {
336
+ name: "proposalCount",
337
+ type: "function",
338
+ stateMutability: "view",
339
+ inputs: [],
340
+ outputs: [{ name: "", type: "uint256" }]
341
+ },
342
+ {
343
+ name: "getProposal",
344
+ type: "function",
345
+ stateMutability: "view",
346
+ inputs: [{ name: "proposalId", type: "uint256" }],
347
+ outputs: [
348
+ { name: "creator", type: "address" },
349
+ { name: "title", type: "string" },
350
+ { name: "description", type: "string" },
351
+ { name: "options", type: "string[]" },
352
+ { name: "startTime", type: "uint256" },
353
+ { name: "endTime", type: "uint256" },
354
+ { name: "finalized", type: "bool" },
355
+ { name: "winningOption", type: "uint256" }
356
+ ]
357
+ },
358
+ {
359
+ name: "castVote",
360
+ type: "function",
361
+ stateMutability: "nonpayable",
362
+ inputs: [
363
+ { name: "proposalId", type: "uint256" },
364
+ { name: "encryptedOption", type: "tuple", components: [...IN_EUINT64_COMPONENTS] }
365
+ ],
366
+ outputs: []
367
+ },
368
+ {
369
+ name: "delegate",
370
+ type: "function",
371
+ stateMutability: "nonpayable",
372
+ inputs: [{ name: "delegatee", type: "address" }],
373
+ outputs: []
374
+ }
375
+ ];
376
+
377
+ // src/modules/credit.ts
378
+ var CreditModule = class {
379
+ constructor(deps) {
380
+ this.deps = deps;
381
+ }
382
+ deps;
383
+ getMarketAddress(override) {
384
+ return override ?? this.deps.addresses.CreditCanonicalPayOcUSDCMarket;
385
+ }
386
+ async buildSupplyCollateral(amount, encryptedAmount, marketAddress) {
387
+ const market = this.getMarketAddress(marketAddress);
388
+ const enc = await resolveInEuint64(amount, market, this.deps.fhe, encryptedAmount);
389
+ return makeCall(this.deps.chainId, market, CREDIT_MARKET_ABI, "supplyCollateral", [
390
+ toContractInEuint64(enc)
391
+ ]);
392
+ }
393
+ async buildBorrow(amount, encryptedAmount, marketAddress) {
394
+ const market = this.getMarketAddress(marketAddress);
395
+ const enc = await resolveInEuint64(amount, market, this.deps.fhe, encryptedAmount);
396
+ return makeCall(this.deps.chainId, market, CREDIT_MARKET_ABI, "borrow", [
397
+ toContractInEuint64(enc)
398
+ ]);
399
+ }
400
+ async buildRepay(amount, encryptedAmount, marketAddress) {
401
+ const market = this.getMarketAddress(marketAddress);
402
+ const enc = await resolveInEuint64(amount, market, this.deps.fhe, encryptedAmount);
403
+ return makeCall(this.deps.chainId, market, CREDIT_MARKET_ABI, "repay", [
404
+ toContractInEuint64(enc)
405
+ ]);
406
+ }
407
+ };
408
+
409
+ // src/modules/notifications.ts
410
+ var NotificationsModule = class {
411
+ constructor(http2) {
412
+ this.http = http2;
413
+ }
414
+ http;
415
+ async getVapidPublicKey() {
416
+ const { publicKey } = await this.http.get("/vapid-public-key");
417
+ return publicKey;
418
+ }
419
+ async getPrefs(wallet) {
420
+ const normalized = normalizeWallet(wallet);
421
+ if (!normalized) throw new Error("Invalid wallet address");
422
+ try {
423
+ return await this.http.get(`/prefs/${normalized}`);
424
+ } catch (err) {
425
+ if (err instanceof HttpError && err.status === 404) return null;
426
+ throw err;
427
+ }
428
+ }
429
+ async savePrefs(prefs) {
430
+ const normalized = normalizeWallet(prefs.wallet);
431
+ if (!normalized) throw new Error("Invalid wallet address");
432
+ await this.http.post("/prefs", {
433
+ ...prefs,
434
+ wallet: normalized
435
+ });
436
+ }
437
+ async subscribe(wallet, subscription) {
438
+ const normalized = normalizeWallet(wallet);
439
+ if (!normalized) throw new Error("Invalid wallet address");
440
+ if (!subscription?.endpoint) throw new Error("subscription.endpoint is required");
441
+ await this.http.post("/subscribe", { wallet: normalized, subscription });
442
+ }
443
+ async unsubscribe(wallet) {
444
+ const normalized = normalizeWallet(wallet);
445
+ if (!normalized) throw new Error("Invalid wallet address");
446
+ await this.http.delete("/subscribe", { wallet: normalized });
447
+ }
448
+ };
449
+
450
+ // src/modules/pay.ts
451
+ var PayModule = class {
452
+ constructor(deps) {
453
+ this.deps = deps;
454
+ }
455
+ deps;
456
+ get ocUsdcAddress() {
457
+ return this.deps.addresses.ocUSDC_Pay;
458
+ }
459
+ /** Returns encrypted balance ctHash (uint256) for account */
460
+ async getShieldedBalance(account) {
461
+ return this.deps.publicClient.readContract({
462
+ address: this.deps.addresses.ocUSDC_Pay,
463
+ abi: OC_USDC_PAY_ABI,
464
+ functionName: "confidentialBalanceOf",
465
+ args: [account]
466
+ });
467
+ }
468
+ async buildShield(amount, encryptedAmount) {
469
+ const enc = await resolveInEuint64(
470
+ amount,
471
+ this.deps.addresses.ocUSDC_Pay,
472
+ this.deps.fhe,
473
+ encryptedAmount
474
+ );
475
+ return makeCall(
476
+ this.deps.chainId,
477
+ this.deps.addresses.ocUSDC_Pay,
478
+ OC_USDC_PAY_ABI,
479
+ "shield",
480
+ [amount, toContractInEuint64(enc)]
481
+ );
482
+ }
483
+ async buildUnshield(to, amount, encryptedAmount) {
484
+ const enc = await resolveInEuint64(
485
+ amount,
486
+ this.deps.addresses.ocUSDC_Pay,
487
+ this.deps.fhe,
488
+ encryptedAmount
489
+ );
490
+ return makeCall(
491
+ this.deps.chainId,
492
+ this.deps.addresses.ocUSDC_Pay,
493
+ OC_USDC_PAY_ABI,
494
+ "unshield",
495
+ [to, toContractInEuint64(enc)]
496
+ );
497
+ }
498
+ async buildTransfer(to, amount, encryptedAmount) {
499
+ const enc = await resolveInEuint64(
500
+ amount,
501
+ this.deps.addresses.ocUSDC_Pay,
502
+ this.deps.fhe,
503
+ encryptedAmount
504
+ );
505
+ return makeCall(
506
+ this.deps.chainId,
507
+ this.deps.addresses.ocUSDC_Pay,
508
+ OC_USDC_PAY_ABI,
509
+ "confidentialTransfer",
510
+ [to, toContractInEuint64(enc)]
511
+ );
512
+ }
513
+ };
514
+
515
+ // src/modules/reputation.ts
516
+ var ReputationModule = class {
517
+ constructor(http2) {
518
+ this.http = http2;
519
+ }
520
+ http;
521
+ async getSummary(wallet) {
522
+ const normalized = normalizeWallet(wallet);
523
+ if (!normalized) {
524
+ throw new Error("Invalid wallet address");
525
+ }
526
+ return this.http.get(`/reputation/${normalized}`);
527
+ }
528
+ };
529
+
530
+ // src/modules/vote.ts
531
+ var VoteModule = class {
532
+ constructor(deps) {
533
+ this.deps = deps;
534
+ }
535
+ deps;
536
+ get voteAddress() {
537
+ return this.deps.addresses.ObscuraVote;
538
+ }
539
+ async getProposalCount() {
540
+ return this.deps.publicClient.readContract({
541
+ address: this.deps.addresses.ObscuraVote,
542
+ abi: OBSCURA_VOTE_ABI,
543
+ functionName: "proposalCount"
544
+ });
545
+ }
546
+ async getProposal(id) {
547
+ const result = await this.deps.publicClient.readContract({
548
+ address: this.deps.addresses.ObscuraVote,
549
+ abi: OBSCURA_VOTE_ABI,
550
+ functionName: "getProposal",
551
+ args: [id]
552
+ });
553
+ return {
554
+ id,
555
+ creator: result[0],
556
+ title: result[1],
557
+ description: result[2],
558
+ options: [...result[3]],
559
+ startTime: result[4],
560
+ endTime: result[5],
561
+ finalized: result[6],
562
+ winningOption: result[7]
563
+ };
564
+ }
565
+ async buildCastVote(proposalId, optionIndex, encryptedOption) {
566
+ const enc = await resolveInEuint64(
567
+ BigInt(optionIndex),
568
+ this.deps.addresses.ObscuraVote,
569
+ this.deps.fhe,
570
+ encryptedOption
571
+ );
572
+ return makeCall(
573
+ this.deps.chainId,
574
+ this.deps.addresses.ObscuraVote,
575
+ OBSCURA_VOTE_ABI,
576
+ "castVote",
577
+ [proposalId, toContractInEuint64(enc)]
578
+ );
579
+ }
580
+ buildDelegate(delegatee) {
581
+ return makeCall(
582
+ this.deps.chainId,
583
+ this.deps.addresses.ObscuraVote,
584
+ OBSCURA_VOTE_ABI,
585
+ "delegate",
586
+ [delegatee]
587
+ );
588
+ }
589
+ };
590
+
591
+ // src/client.ts
592
+ var ObscuraSDK = class _ObscuraSDK {
593
+ chainId;
594
+ addresses;
595
+ publicClient;
596
+ fhe;
597
+ pay;
598
+ credit;
599
+ vote;
600
+ reputation;
601
+ activity;
602
+ notifications;
603
+ walletClient;
604
+ constructor(config) {
605
+ this.chainId = config.chainId ?? ARBITRUM_SEPOLIA_CHAIN_ID;
606
+ this.addresses = mergeAddresses(config.addresses);
607
+ this.fhe = config.fhe;
608
+ this.walletClient = config.walletClient;
609
+ const rpcUrl = config.rpcUrl ?? DEFAULT_RPC_URL;
610
+ this.publicClient = config.publicClient ?? createDefaultPublicClient(rpcUrl, this.chainId);
611
+ const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
612
+ const http2 = new HttpClient(apiUrl);
613
+ const moduleDeps = {
614
+ chainId: this.chainId,
615
+ addresses: this.addresses,
616
+ publicClient: this.publicClient,
617
+ fhe: this.fhe
618
+ };
619
+ this.pay = new PayModule(moduleDeps);
620
+ this.credit = new CreditModule({
621
+ chainId: this.chainId,
622
+ addresses: this.addresses,
623
+ fhe: this.fhe
624
+ });
625
+ this.vote = new VoteModule(moduleDeps);
626
+ this.reputation = new ReputationModule(http2);
627
+ this.notifications = new NotificationsModule(http2);
628
+ this.activity = new ActivityModule(
629
+ config.supabaseUrl ?? DEFAULT_SUPABASE_URL,
630
+ config.supabaseAnonKey
631
+ );
632
+ }
633
+ static create(config = {}) {
634
+ return new _ObscuraSDK(config);
635
+ }
636
+ encodeCall(call) {
637
+ return encodeCall(call);
638
+ }
639
+ async sendCall(call, account) {
640
+ if (!this.walletClient) {
641
+ throw new Error("walletClient required for sendCall. Pass walletClient in ObscuraSDK.create().");
642
+ }
643
+ return sendContractCall(call, this.walletClient, account);
644
+ }
645
+ };
646
+
647
+ exports.ACTIVITY_EVENT_FILTERS = ACTIVITY_EVENT_FILTERS;
648
+ exports.ARBITRUM_SEPOLIA_CHAIN_ID = ARBITRUM_SEPOLIA_CHAIN_ID;
649
+ exports.ActivityModule = ActivityModule;
650
+ exports.CREDIT_MARKET_ABI = CREDIT_MARKET_ABI;
651
+ exports.CreditModule = CreditModule;
652
+ exports.DEFAULT_ADDRESSES = DEFAULT_ADDRESSES;
653
+ exports.DEFAULT_API_URL = DEFAULT_API_URL;
654
+ exports.DEFAULT_RPC_URL = DEFAULT_RPC_URL;
655
+ exports.DEFAULT_SUPABASE_URL = DEFAULT_SUPABASE_URL;
656
+ exports.FheRequiredError = FheRequiredError;
657
+ exports.HttpError = HttpError;
658
+ exports.NotificationsModule = NotificationsModule;
659
+ exports.OBSCURA_VOTE_ABI = OBSCURA_VOTE_ABI;
660
+ exports.OC_USDC_PAY_ABI = OC_USDC_PAY_ABI;
661
+ exports.ObscuraSDK = ObscuraSDK;
662
+ exports.PayModule = PayModule;
663
+ exports.ReputationModule = ReputationModule;
664
+ exports.VoteModule = VoteModule;
665
+ exports.createDefaultPublicClient = createDefaultPublicClient;
666
+ exports.encodeCall = encodeCall;
667
+ exports.normalizeWallet = normalizeWallet;
668
+ exports.toContractInEuint64 = toContractInEuint64;
669
+ //# sourceMappingURL=index.cjs.map
670
+ //# sourceMappingURL=index.cjs.map