@bbuilders/djeon402-sdk-client 1.0.1

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,1314 @@
1
+ // src/vue/useApprove.ts
2
+ import { ref } from "vue";
3
+
4
+ // src/vue/useDjeon402.ts
5
+ import { inject, provide, readonly } from "vue";
6
+
7
+ // src/client.ts
8
+ import { createPublicClient, http } from "viem";
9
+ import { base } from "viem/chains";
10
+
11
+ // src/modules/admin.ts
12
+ import {
13
+ DJEON402_ABI,
14
+ validateAddress
15
+ } from "@bbuilders/djeon402-core";
16
+ var AdminModule = class {
17
+ constructor(sdk) {
18
+ this.sdk = sdk;
19
+ }
20
+ /**
21
+ * Get role hashes
22
+ */
23
+ async getRoles() {
24
+ const [minter, burner, pauser, blacklister, admin] = await Promise.all([
25
+ this.sdk.publicClient.readContract({
26
+ address: this.sdk.contractAddress,
27
+ abi: DJEON402_ABI,
28
+ functionName: "MINTER_ROLE"
29
+ }),
30
+ this.sdk.publicClient.readContract({
31
+ address: this.sdk.contractAddress,
32
+ abi: DJEON402_ABI,
33
+ functionName: "BURNER_ROLE"
34
+ }),
35
+ this.sdk.publicClient.readContract({
36
+ address: this.sdk.contractAddress,
37
+ abi: DJEON402_ABI,
38
+ functionName: "PAUSER_ROLE"
39
+ }),
40
+ this.sdk.publicClient.readContract({
41
+ address: this.sdk.contractAddress,
42
+ abi: DJEON402_ABI,
43
+ functionName: "BLACKLISTER_ROLE"
44
+ }),
45
+ this.sdk.publicClient.readContract({
46
+ address: this.sdk.contractAddress,
47
+ abi: DJEON402_ABI,
48
+ functionName: "DEFAULT_ADMIN_ROLE"
49
+ })
50
+ ]);
51
+ return {
52
+ MINTER_ROLE: minter,
53
+ BURNER_ROLE: burner,
54
+ PAUSER_ROLE: pauser,
55
+ BLACKLISTER_ROLE: blacklister,
56
+ DEFAULT_ADMIN_ROLE: admin
57
+ };
58
+ }
59
+ /**
60
+ * Check if address has role
61
+ */
62
+ async hasRole(role, account) {
63
+ validateAddress(account);
64
+ const result = await this.sdk.publicClient.readContract({
65
+ address: this.sdk.contractAddress,
66
+ abi: DJEON402_ABI,
67
+ functionName: "hasRole",
68
+ args: [role, account]
69
+ });
70
+ return {
71
+ role,
72
+ address: account,
73
+ hasRole: result
74
+ };
75
+ }
76
+ /**
77
+ * Check if address is blacklisted
78
+ */
79
+ async isBlacklisted(account) {
80
+ validateAddress(account);
81
+ const isBlacklisted = await this.sdk.publicClient.readContract({
82
+ address: this.sdk.contractAddress,
83
+ abi: DJEON402_ABI,
84
+ functionName: "isBlacklisted",
85
+ args: [account]
86
+ });
87
+ return {
88
+ isBlacklisted,
89
+ address: account
90
+ };
91
+ }
92
+ /**
93
+ * Blacklist an address
94
+ */
95
+ async blacklist(params) {
96
+ const { walletClient, account } = params;
97
+ if (!walletClient.account) {
98
+ throw new Error("Wallet client must have an account");
99
+ }
100
+ validateAddress(account);
101
+ const hash = await walletClient.writeContract({
102
+ address: this.sdk.contractAddress,
103
+ abi: DJEON402_ABI,
104
+ functionName: "blacklist",
105
+ args: [account],
106
+ account: walletClient.account,
107
+ chain: walletClient.chain
108
+ });
109
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
110
+ return {
111
+ success: receipt.status === "success",
112
+ hash,
113
+ blockNumber: receipt.blockNumber.toString()
114
+ };
115
+ }
116
+ /**
117
+ * Remove from blacklist
118
+ */
119
+ async unBlacklist(params) {
120
+ const { walletClient, account } = params;
121
+ if (!walletClient.account) {
122
+ throw new Error("Wallet client must have an account");
123
+ }
124
+ validateAddress(account);
125
+ const hash = await walletClient.writeContract({
126
+ address: this.sdk.contractAddress,
127
+ abi: DJEON402_ABI,
128
+ functionName: "unBlacklist",
129
+ args: [account],
130
+ account: walletClient.account,
131
+ chain: walletClient.chain
132
+ });
133
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
134
+ return {
135
+ success: receipt.status === "success",
136
+ hash,
137
+ blockNumber: receipt.blockNumber.toString()
138
+ };
139
+ }
140
+ /**
141
+ * Pause contract
142
+ */
143
+ async pause(params) {
144
+ const { walletClient } = params;
145
+ if (!walletClient.account) {
146
+ throw new Error("Wallet client must have an account");
147
+ }
148
+ const hash = await walletClient.writeContract({
149
+ address: this.sdk.contractAddress,
150
+ abi: DJEON402_ABI,
151
+ functionName: "pause",
152
+ account: walletClient.account,
153
+ chain: walletClient.chain
154
+ });
155
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
156
+ return {
157
+ success: receipt.status === "success",
158
+ hash,
159
+ blockNumber: receipt.blockNumber.toString()
160
+ };
161
+ }
162
+ /**
163
+ * Unpause contract
164
+ */
165
+ async unpause(params) {
166
+ const { walletClient } = params;
167
+ if (!walletClient.account) {
168
+ throw new Error("Wallet client must have an account");
169
+ }
170
+ const hash = await walletClient.writeContract({
171
+ address: this.sdk.contractAddress,
172
+ abi: DJEON402_ABI,
173
+ functionName: "unpause",
174
+ account: walletClient.account,
175
+ chain: walletClient.chain
176
+ });
177
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
178
+ return {
179
+ success: receipt.status === "success",
180
+ hash,
181
+ blockNumber: receipt.blockNumber.toString()
182
+ };
183
+ }
184
+ };
185
+
186
+ // src/modules/kyc.ts
187
+ import {
188
+ KYC_REGISTRY_ABI,
189
+ validateAddress as validateAddress2
190
+ } from "@bbuilders/djeon402-core";
191
+ var KYCModule = class {
192
+ constructor(sdk) {
193
+ this.sdk = sdk;
194
+ }
195
+ /**
196
+ * Get KYC data for an address
197
+ */
198
+ async getData(address) {
199
+ if (!this.sdk.kycRegistryAddress) {
200
+ throw new Error("KYC Registry address not configured");
201
+ }
202
+ validateAddress2(address);
203
+ const kycData = await this.sdk.publicClient.readContract({
204
+ address: this.sdk.kycRegistryAddress,
205
+ abi: KYC_REGISTRY_ABI,
206
+ functionName: "getKYCData",
207
+ args: [address]
208
+ });
209
+ const result = kycData;
210
+ const [level, expiryDate, kycHash, isActive, dailyLimit, dailySpent] = result;
211
+ const levelNames = ["None", "Tier1", "Tier2", "Tier3"];
212
+ const expiryDateReadable = new Date(Number(expiryDate) * 1e3).toISOString();
213
+ return {
214
+ level,
215
+ levelName: levelNames[level],
216
+ expiryDate: Number(expiryDate),
217
+ expiryDateReadable,
218
+ kycHash,
219
+ isActive,
220
+ dailyLimit: dailyLimit.toString(),
221
+ dailyLimitRaw: dailyLimit.toString(),
222
+ dailySpent: dailySpent.toString(),
223
+ dailySpentRaw: dailySpent.toString(),
224
+ userAddress: address
225
+ };
226
+ }
227
+ /**
228
+ * Get remaining daily limit
229
+ */
230
+ async getRemainingLimit(address) {
231
+ if (!this.sdk.kycRegistryAddress) {
232
+ throw new Error("KYC Registry address not configured");
233
+ }
234
+ validateAddress2(address);
235
+ const remaining = await this.sdk.publicClient.readContract({
236
+ address: this.sdk.kycRegistryAddress,
237
+ abi: KYC_REGISTRY_ABI,
238
+ functionName: "getRemainingDailyLimit",
239
+ args: [address]
240
+ });
241
+ return {
242
+ address,
243
+ remainingLimit: remaining.toString()
244
+ };
245
+ }
246
+ /**
247
+ * Verify KYC (admin only)
248
+ */
249
+ async verify(params) {
250
+ if (!this.sdk.kycRegistryAddress) {
251
+ throw new Error("KYC Registry address not configured");
252
+ }
253
+ const { walletClient, userAddress, level, expiryDate, documentHash } = params;
254
+ if (!walletClient.account) {
255
+ throw new Error("Wallet client must have an account");
256
+ }
257
+ validateAddress2(userAddress);
258
+ if (level < 0 || level > 3) {
259
+ throw new Error("Invalid KYC level. Must be 0-3");
260
+ }
261
+ const hash = await walletClient.writeContract({
262
+ address: this.sdk.kycRegistryAddress,
263
+ abi: KYC_REGISTRY_ABI,
264
+ functionName: "verifyKYC",
265
+ args: [userAddress, level, BigInt(expiryDate), documentHash],
266
+ account: walletClient.account,
267
+ chain: walletClient.chain
268
+ });
269
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
270
+ return {
271
+ success: receipt.status === "success",
272
+ hash,
273
+ blockNumber: receipt.blockNumber.toString()
274
+ };
275
+ }
276
+ /**
277
+ * Update KYC level (admin only)
278
+ */
279
+ async updateKYC(params) {
280
+ if (!this.sdk.kycRegistryAddress) {
281
+ throw new Error("KYC Registry address not configured");
282
+ }
283
+ const { walletClient, userAddress, level, expiryDate = 0 } = params;
284
+ if (!walletClient.account) {
285
+ throw new Error("Wallet client must have an account");
286
+ }
287
+ validateAddress2(userAddress);
288
+ const hash = await walletClient.writeContract({
289
+ address: this.sdk.kycRegistryAddress,
290
+ abi: KYC_REGISTRY_ABI,
291
+ functionName: "updateKYC",
292
+ args: [userAddress, level, BigInt(expiryDate)],
293
+ account: walletClient.account,
294
+ chain: walletClient.chain
295
+ });
296
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
297
+ return {
298
+ success: receipt.status === "success",
299
+ hash,
300
+ blockNumber: receipt.blockNumber.toString()
301
+ };
302
+ }
303
+ /**
304
+ * Revoke KYC (admin only)
305
+ */
306
+ async revokeKYC(params) {
307
+ if (!this.sdk.kycRegistryAddress) {
308
+ throw new Error("KYC Registry address not configured");
309
+ }
310
+ const { walletClient, userAddress } = params;
311
+ if (!walletClient.account) {
312
+ throw new Error("Wallet client must have an account");
313
+ }
314
+ validateAddress2(userAddress);
315
+ const hash = await walletClient.writeContract({
316
+ address: this.sdk.kycRegistryAddress,
317
+ abi: KYC_REGISTRY_ABI,
318
+ functionName: "revokeKYC",
319
+ args: [userAddress],
320
+ account: walletClient.account,
321
+ chain: walletClient.chain
322
+ });
323
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
324
+ return {
325
+ success: receipt.status === "success",
326
+ hash,
327
+ blockNumber: receipt.blockNumber.toString()
328
+ };
329
+ }
330
+ /**
331
+ * Set daily limit for a user (admin only)
332
+ */
333
+ async setDailyLimit(params) {
334
+ if (!this.sdk.kycRegistryAddress) {
335
+ throw new Error("KYC Registry address not configured");
336
+ }
337
+ const { walletClient, userAddress, limitUSD } = params;
338
+ if (!walletClient.account) {
339
+ throw new Error("Wallet client must have an account");
340
+ }
341
+ validateAddress2(userAddress);
342
+ const limitInSmallestUnit = BigInt(parseFloat(limitUSD) * 1e6);
343
+ const hash = await walletClient.writeContract({
344
+ address: this.sdk.kycRegistryAddress,
345
+ abi: KYC_REGISTRY_ABI,
346
+ functionName: "setDailyLimit",
347
+ args: [userAddress, limitInSmallestUnit],
348
+ account: walletClient.account,
349
+ chain: walletClient.chain
350
+ });
351
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
352
+ return {
353
+ success: receipt.status === "success",
354
+ hash,
355
+ blockNumber: receipt.blockNumber.toString()
356
+ };
357
+ }
358
+ /**
359
+ * Check if a transaction amount is within the user's daily limit
360
+ */
361
+ async checkDailyLimit(params) {
362
+ if (!this.sdk.kycRegistryAddress) {
363
+ throw new Error("KYC Registry address not configured");
364
+ }
365
+ const { walletClient, userAddress, amountUSD } = params;
366
+ if (!walletClient.account) {
367
+ throw new Error("Wallet client must have an account");
368
+ }
369
+ validateAddress2(userAddress);
370
+ const amountInSmallestUnit = BigInt(parseFloat(amountUSD) * 1e6);
371
+ const result = await walletClient.writeContract({
372
+ address: this.sdk.kycRegistryAddress,
373
+ abi: KYC_REGISTRY_ABI,
374
+ functionName: "checkDailyLimit",
375
+ args: [userAddress, amountInSmallestUnit],
376
+ account: walletClient.account,
377
+ chain: walletClient.chain
378
+ });
379
+ return result;
380
+ }
381
+ /**
382
+ * Check if a user's KYC is valid (view)
383
+ */
384
+ async isKYCValid(userAddress) {
385
+ if (!this.sdk.kycRegistryAddress) {
386
+ throw new Error("KYC Registry address not configured");
387
+ }
388
+ validateAddress2(userAddress);
389
+ const result = await this.sdk.publicClient.readContract({
390
+ address: this.sdk.kycRegistryAddress,
391
+ abi: KYC_REGISTRY_ABI,
392
+ functionName: "isKYCValid",
393
+ args: [userAddress]
394
+ });
395
+ return result;
396
+ }
397
+ };
398
+
399
+ // src/modules/token.ts
400
+ import {
401
+ DJEON402_ABI as DJEON402_ABI2,
402
+ formatTokenAmount,
403
+ parseTokenAmount,
404
+ validateAddress as validateAddress3,
405
+ validateAmount
406
+ } from "@bbuilders/djeon402-core";
407
+ var TokenModule = class {
408
+ constructor(sdk) {
409
+ this.sdk = sdk;
410
+ }
411
+ /**
412
+ * Get token information
413
+ */
414
+ async getInfo() {
415
+ const [name, symbol, decimals, totalSupply, paused] = await Promise.all([
416
+ this.sdk.publicClient.readContract({
417
+ address: this.sdk.contractAddress,
418
+ abi: DJEON402_ABI2,
419
+ functionName: "name"
420
+ }),
421
+ this.sdk.publicClient.readContract({
422
+ address: this.sdk.contractAddress,
423
+ abi: DJEON402_ABI2,
424
+ functionName: "symbol"
425
+ }),
426
+ this.sdk.publicClient.readContract({
427
+ address: this.sdk.contractAddress,
428
+ abi: DJEON402_ABI2,
429
+ functionName: "decimals"
430
+ }),
431
+ this.sdk.publicClient.readContract({
432
+ address: this.sdk.contractAddress,
433
+ abi: DJEON402_ABI2,
434
+ functionName: "totalSupply"
435
+ }),
436
+ this.sdk.publicClient.readContract({
437
+ address: this.sdk.contractAddress,
438
+ abi: DJEON402_ABI2,
439
+ functionName: "paused"
440
+ })
441
+ ]);
442
+ return {
443
+ name,
444
+ symbol,
445
+ decimals,
446
+ totalSupply: formatTokenAmount(totalSupply, decimals),
447
+ totalSupplyRaw: totalSupply.toString(),
448
+ paused,
449
+ contractAddress: this.sdk.contractAddress
450
+ };
451
+ }
452
+ /**
453
+ * Get balance of an address
454
+ */
455
+ async getBalance(address) {
456
+ validateAddress3(address);
457
+ const [balance, decimals] = await Promise.all([
458
+ this.sdk.publicClient.readContract({
459
+ address: this.sdk.contractAddress,
460
+ abi: DJEON402_ABI2,
461
+ functionName: "balanceOf",
462
+ args: [address]
463
+ }),
464
+ this.sdk.publicClient.readContract({
465
+ address: this.sdk.contractAddress,
466
+ abi: DJEON402_ABI2,
467
+ functionName: "decimals"
468
+ })
469
+ ]);
470
+ return {
471
+ address,
472
+ balance: formatTokenAmount(balance, decimals),
473
+ balanceRaw: balance.toString()
474
+ };
475
+ }
476
+ /**
477
+ * Get allowance
478
+ */
479
+ async getAllowance(owner, spender) {
480
+ validateAddress3(owner);
481
+ validateAddress3(spender);
482
+ const [allowance, decimals] = await Promise.all([
483
+ this.sdk.publicClient.readContract({
484
+ address: this.sdk.contractAddress,
485
+ abi: DJEON402_ABI2,
486
+ functionName: "allowance",
487
+ args: [owner, spender]
488
+ }),
489
+ this.sdk.publicClient.readContract({
490
+ address: this.sdk.contractAddress,
491
+ abi: DJEON402_ABI2,
492
+ functionName: "decimals"
493
+ })
494
+ ]);
495
+ return {
496
+ owner,
497
+ spender,
498
+ allowance: formatTokenAmount(allowance, decimals),
499
+ allowanceRaw: allowance.toString()
500
+ };
501
+ }
502
+ /**
503
+ * Transfer tokens using wallet client
504
+ */
505
+ async transfer(params) {
506
+ const { walletClient, to, amount } = params;
507
+ if (!walletClient.account) {
508
+ throw new Error("Wallet client must have an account");
509
+ }
510
+ validateAddress3(to);
511
+ validateAmount(amount);
512
+ const decimals = await this.sdk.publicClient.readContract({
513
+ address: this.sdk.contractAddress,
514
+ abi: DJEON402_ABI2,
515
+ functionName: "decimals"
516
+ });
517
+ const amountBigInt = parseTokenAmount(amount, decimals);
518
+ const hash = await walletClient.writeContract({
519
+ address: this.sdk.contractAddress,
520
+ abi: DJEON402_ABI2,
521
+ functionName: "transfer",
522
+ args: [to, amountBigInt],
523
+ account: walletClient.account,
524
+ chain: walletClient.chain
525
+ });
526
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({
527
+ hash
528
+ });
529
+ return {
530
+ success: receipt.status === "success",
531
+ hash,
532
+ from: walletClient.account.address,
533
+ to,
534
+ amount,
535
+ amountRaw: amountBigInt.toString(),
536
+ blockNumber: receipt.blockNumber.toString(),
537
+ status: receipt.status
538
+ };
539
+ }
540
+ /**
541
+ * Approve spending
542
+ */
543
+ async approve(params) {
544
+ const { walletClient, spender, amount } = params;
545
+ if (!walletClient.account) {
546
+ throw new Error("Wallet client must have an account");
547
+ }
548
+ validateAddress3(spender);
549
+ validateAmount(amount);
550
+ const decimals = await this.sdk.publicClient.readContract({
551
+ address: this.sdk.contractAddress,
552
+ abi: DJEON402_ABI2,
553
+ functionName: "decimals"
554
+ });
555
+ const amountBigInt = parseTokenAmount(amount, decimals);
556
+ const hash = await walletClient.writeContract({
557
+ address: this.sdk.contractAddress,
558
+ abi: DJEON402_ABI2,
559
+ functionName: "approve",
560
+ args: [spender, amountBigInt],
561
+ account: walletClient.account,
562
+ chain: walletClient.chain
563
+ });
564
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
565
+ return {
566
+ success: receipt.status === "success",
567
+ hash,
568
+ blockNumber: receipt.blockNumber.toString()
569
+ };
570
+ }
571
+ /**
572
+ * Mint tokens (requires MINTER_ROLE)
573
+ */
574
+ async mint(params) {
575
+ const { walletClient, to, amount } = params;
576
+ if (!walletClient.account) {
577
+ throw new Error("Wallet client must have an account");
578
+ }
579
+ validateAddress3(to);
580
+ validateAmount(amount);
581
+ const decimals = await this.sdk.publicClient.readContract({
582
+ address: this.sdk.contractAddress,
583
+ abi: DJEON402_ABI2,
584
+ functionName: "decimals"
585
+ });
586
+ const amountBigInt = parseTokenAmount(amount, decimals);
587
+ const hash = await walletClient.writeContract({
588
+ address: this.sdk.contractAddress,
589
+ abi: DJEON402_ABI2,
590
+ functionName: "mint",
591
+ args: [to, amountBigInt],
592
+ account: walletClient.account,
593
+ chain: walletClient.chain
594
+ });
595
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
596
+ return {
597
+ success: receipt.status === "success",
598
+ hash,
599
+ blockNumber: receipt.blockNumber.toString()
600
+ };
601
+ }
602
+ /**
603
+ * Burn tokens (requires BURNER_ROLE)
604
+ */
605
+ async burn(params) {
606
+ const { walletClient, amount } = params;
607
+ if (!walletClient.account) {
608
+ throw new Error("Wallet client must have an account");
609
+ }
610
+ validateAmount(amount);
611
+ const decimals = await this.sdk.publicClient.readContract({
612
+ address: this.sdk.contractAddress,
613
+ abi: DJEON402_ABI2,
614
+ functionName: "decimals"
615
+ });
616
+ const amountBigInt = parseTokenAmount(amount, decimals);
617
+ const hash = await walletClient.writeContract({
618
+ address: this.sdk.contractAddress,
619
+ abi: DJEON402_ABI2,
620
+ functionName: "burn",
621
+ args: [amountBigInt],
622
+ account: walletClient.account,
623
+ chain: walletClient.chain
624
+ });
625
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
626
+ return {
627
+ success: receipt.status === "success",
628
+ hash,
629
+ blockNumber: receipt.blockNumber.toString()
630
+ };
631
+ }
632
+ };
633
+
634
+ // src/modules/x402.ts
635
+ import {
636
+ DJEON402_ABI as DJEON402_ABI3,
637
+ parseTokenAmount as parseTokenAmount2,
638
+ validateAddress as validateAddress4,
639
+ validateAmount as validateAmount2
640
+ } from "@bbuilders/djeon402-core";
641
+ var X402Module = class {
642
+ constructor(sdk) {
643
+ this.sdk = sdk;
644
+ }
645
+ /**
646
+ * Generate a random nonce
647
+ */
648
+ generateNonce() {
649
+ const randomBytes = new Uint8Array(32);
650
+ crypto.getRandomValues(randomBytes);
651
+ return `0x${Array.from(randomBytes).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
652
+ }
653
+ /**
654
+ * Get EIP-712 domain separator
655
+ */
656
+ async getDomainSeparator() {
657
+ const domain = await this.sdk.publicClient.readContract({
658
+ address: this.sdk.contractAddress,
659
+ abi: DJEON402_ABI3,
660
+ functionName: "DOMAIN_SEPARATOR"
661
+ });
662
+ return domain;
663
+ }
664
+ /**
665
+ * Get authorization state (whether a nonce has been used)
666
+ */
667
+ async getAuthorizationState(authorizer, nonce) {
668
+ return await this.sdk.publicClient.readContract({
669
+ address: this.sdk.contractAddress,
670
+ abi: DJEON402_ABI3,
671
+ functionName: "authorizationState",
672
+ args: [authorizer, nonce]
673
+ });
674
+ }
675
+ /**
676
+ * Sign transfer authorization using wallet
677
+ */
678
+ async signTransferWithWallet(params) {
679
+ const { walletClient, to, amount, validAfter = 0n, validBefore, nonce } = params;
680
+ if (!walletClient.account) {
681
+ throw new Error("Wallet client must have an account");
682
+ }
683
+ validateAddress4(to);
684
+ validateAmount2(amount);
685
+ const from = walletClient.account.address;
686
+ const decimals = await this.sdk.publicClient.readContract({
687
+ address: this.sdk.contractAddress,
688
+ abi: DJEON402_ABI3,
689
+ functionName: "decimals"
690
+ });
691
+ const value = parseTokenAmount2(amount, decimals);
692
+ const transferNonce = nonce || this.generateNonce();
693
+ const validBeforeTimestamp = validBefore ?? BigInt(Math.floor(Date.now() / 1e3) + 3600);
694
+ const name = await this.sdk.publicClient.readContract({
695
+ address: this.sdk.contractAddress,
696
+ abi: DJEON402_ABI3,
697
+ functionName: "name"
698
+ });
699
+ const domain = {
700
+ name,
701
+ version: "1",
702
+ chainId: this.sdk.chainId,
703
+ verifyingContract: this.sdk.contractAddress
704
+ };
705
+ const types = {
706
+ TransferWithAuthorization: [
707
+ { name: "from", type: "address" },
708
+ { name: "to", type: "address" },
709
+ { name: "value", type: "uint256" },
710
+ { name: "validAfter", type: "uint256" },
711
+ { name: "validBefore", type: "uint256" },
712
+ { name: "nonce", type: "bytes32" }
713
+ ]
714
+ };
715
+ const message = {
716
+ from,
717
+ to,
718
+ value,
719
+ validAfter,
720
+ validBefore: validBeforeTimestamp,
721
+ nonce: transferNonce
722
+ };
723
+ const signature = await walletClient.signTypedData({
724
+ account: walletClient.account,
725
+ domain,
726
+ types,
727
+ primaryType: "TransferWithAuthorization",
728
+ message
729
+ });
730
+ const v = parseInt(signature.slice(130, 132), 16);
731
+ const r = `0x${signature.slice(2, 66)}`;
732
+ const s = `0x${signature.slice(66, 130)}`;
733
+ return {
734
+ from,
735
+ to,
736
+ value,
737
+ validAfter,
738
+ validBefore: validBeforeTimestamp,
739
+ nonce: transferNonce,
740
+ v,
741
+ r,
742
+ s
743
+ };
744
+ }
745
+ /**
746
+ * Sign receive authorization using wallet (receiver signs)
747
+ */
748
+ async signReceiveWithWallet(params) {
749
+ const { walletClient, from, amount, validAfter = 0n, validBefore, nonce } = params;
750
+ if (!walletClient.account) {
751
+ throw new Error("Wallet client must have an account");
752
+ }
753
+ validateAddress4(from);
754
+ validateAmount2(amount);
755
+ const to = walletClient.account.address;
756
+ const decimals = await this.sdk.publicClient.readContract({
757
+ address: this.sdk.contractAddress,
758
+ abi: DJEON402_ABI3,
759
+ functionName: "decimals"
760
+ });
761
+ const value = parseTokenAmount2(amount, decimals);
762
+ const receiveNonce = nonce || this.generateNonce();
763
+ const validBeforeTimestamp = validBefore ?? BigInt(Math.floor(Date.now() / 1e3) + 3600);
764
+ const name = await this.sdk.publicClient.readContract({
765
+ address: this.sdk.contractAddress,
766
+ abi: DJEON402_ABI3,
767
+ functionName: "name"
768
+ });
769
+ const domain = {
770
+ name,
771
+ version: "1",
772
+ chainId: this.sdk.chainId,
773
+ verifyingContract: this.sdk.contractAddress
774
+ };
775
+ const types = {
776
+ ReceiveWithAuthorization: [
777
+ { name: "from", type: "address" },
778
+ { name: "to", type: "address" },
779
+ { name: "value", type: "uint256" },
780
+ { name: "validAfter", type: "uint256" },
781
+ { name: "validBefore", type: "uint256" },
782
+ { name: "nonce", type: "bytes32" }
783
+ ]
784
+ };
785
+ const message = {
786
+ from,
787
+ to,
788
+ value,
789
+ validAfter,
790
+ validBefore: validBeforeTimestamp,
791
+ nonce: receiveNonce
792
+ };
793
+ const signature = await walletClient.signTypedData({
794
+ account: walletClient.account,
795
+ domain,
796
+ types,
797
+ primaryType: "ReceiveWithAuthorization",
798
+ message
799
+ });
800
+ const v = parseInt(signature.slice(130, 132), 16);
801
+ const r = `0x${signature.slice(2, 66)}`;
802
+ const s = `0x${signature.slice(66, 130)}`;
803
+ return {
804
+ from,
805
+ to,
806
+ value,
807
+ validAfter,
808
+ validBefore: validBeforeTimestamp,
809
+ nonce: receiveNonce,
810
+ v,
811
+ r,
812
+ s
813
+ };
814
+ }
815
+ /**
816
+ * Execute receive with authorization (caller must be the receiver)
817
+ */
818
+ async executeReceive(params) {
819
+ const { walletClient, authorization } = params;
820
+ if (!walletClient.account) {
821
+ throw new Error("Wallet client must have an account");
822
+ }
823
+ const { from, to, value, validAfter, validBefore, nonce, v, r, s } = authorization;
824
+ const hash = await walletClient.writeContract({
825
+ address: this.sdk.contractAddress,
826
+ abi: DJEON402_ABI3,
827
+ functionName: "receiveWithAuthorization",
828
+ args: [from, to, value, validAfter, validBefore, nonce, v, r, s],
829
+ account: walletClient.account,
830
+ chain: walletClient.chain
831
+ });
832
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
833
+ return {
834
+ success: receipt.status === "success",
835
+ hash,
836
+ blockNumber: receipt.blockNumber.toString()
837
+ };
838
+ }
839
+ /**
840
+ * Sign cancel authorization using wallet
841
+ */
842
+ async signCancelWithWallet(params) {
843
+ const { walletClient, authorizer, nonce: authNonce } = params;
844
+ if (!walletClient.account) {
845
+ throw new Error("Wallet client must have an account");
846
+ }
847
+ const name = await this.sdk.publicClient.readContract({
848
+ address: this.sdk.contractAddress,
849
+ abi: DJEON402_ABI3,
850
+ functionName: "name"
851
+ });
852
+ const domain = {
853
+ name,
854
+ version: "1",
855
+ chainId: this.sdk.chainId,
856
+ verifyingContract: this.sdk.contractAddress
857
+ };
858
+ const types = {
859
+ CancelAuthorization: [
860
+ { name: "authorizer", type: "address" },
861
+ { name: "nonce", type: "bytes32" }
862
+ ]
863
+ };
864
+ const message = { authorizer, nonce: authNonce };
865
+ const signature = await walletClient.signTypedData({
866
+ account: walletClient.account,
867
+ domain,
868
+ types,
869
+ primaryType: "CancelAuthorization",
870
+ message
871
+ });
872
+ const v = parseInt(signature.slice(130, 132), 16);
873
+ const r = `0x${signature.slice(2, 66)}`;
874
+ const s = `0x${signature.slice(66, 130)}`;
875
+ return { authorizer, nonce: authNonce, v, r, s };
876
+ }
877
+ /**
878
+ * Cancel an authorization (marks nonce as used)
879
+ */
880
+ async cancelAuthorization(params) {
881
+ const { walletClient } = params;
882
+ const { authorizer, nonce, v, r, s } = await this.signCancelWithWallet(params);
883
+ const hash = await walletClient.writeContract({
884
+ address: this.sdk.contractAddress,
885
+ abi: DJEON402_ABI3,
886
+ functionName: "cancelAuthorization",
887
+ args: [authorizer, nonce, v, r, s],
888
+ account: walletClient.account,
889
+ chain: walletClient.chain
890
+ });
891
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
892
+ return {
893
+ success: receipt.status === "success",
894
+ hash,
895
+ blockNumber: receipt.blockNumber.toString()
896
+ };
897
+ }
898
+ /**
899
+ * Execute transfer with authorization (relayer function)
900
+ */
901
+ async executeTransfer(params) {
902
+ const { walletClient, authorization } = params;
903
+ if (!walletClient.account) {
904
+ throw new Error("Wallet client must have an account");
905
+ }
906
+ const { from, to, value, validAfter, validBefore, nonce, v, r, s } = authorization;
907
+ const hash = await walletClient.writeContract({
908
+ address: this.sdk.contractAddress,
909
+ abi: DJEON402_ABI3,
910
+ functionName: "transferWithAuthorization",
911
+ args: [from, to, value, validAfter, validBefore, nonce, v, r, s],
912
+ account: walletClient.account,
913
+ chain: walletClient.chain
914
+ });
915
+ const receipt = await this.sdk.publicClient.waitForTransactionReceipt({ hash });
916
+ return {
917
+ success: receipt.status === "success",
918
+ hash,
919
+ blockNumber: receipt.blockNumber.toString()
920
+ };
921
+ }
922
+ /**
923
+ * Fetch wrapper that auto-handles 402 Payment Required responses.
924
+ * On 402, decodes PAYMENT-REQUIRED header, signs authorization, retries with PAYMENT-SIGNATURE.
925
+ */
926
+ async fetchWithPayment(walletClient, url, options = {}) {
927
+ const response = await fetch(url, options);
928
+ if (response.status !== 402) return response;
929
+ const paymentRequiredHeader = response.headers.get("PAYMENT-REQUIRED");
930
+ if (!paymentRequiredHeader) {
931
+ throw new Error("402 response missing PAYMENT-REQUIRED header");
932
+ }
933
+ const paymentRequired = JSON.parse(atob(paymentRequiredHeader));
934
+ const accepted = paymentRequired.accepts?.[0];
935
+ if (!accepted) {
936
+ throw new Error("No accepted payment methods in 402 response");
937
+ }
938
+ const authData = await this.signTransferWithWallet({
939
+ walletClient,
940
+ to: accepted.payTo,
941
+ amount: accepted.amount
942
+ });
943
+ const paymentPayload = {
944
+ x402Version: paymentRequired.x402Version || 2,
945
+ resource: paymentRequired.resource,
946
+ accepted,
947
+ payload: {
948
+ signature: `0x${authData.r.slice(2)}${authData.s.slice(2)}${authData.v.toString(16).padStart(2, "0")}`,
949
+ authorization: {
950
+ from: authData.from,
951
+ to: authData.to,
952
+ value: authData.value.toString(),
953
+ validAfter: authData.validAfter.toString(),
954
+ validBefore: authData.validBefore.toString(),
955
+ nonce: authData.nonce
956
+ }
957
+ }
958
+ };
959
+ const encoded = btoa(JSON.stringify(paymentPayload));
960
+ return fetch(url, {
961
+ ...options,
962
+ headers: {
963
+ ...Object.fromEntries(new Headers(options.headers).entries()),
964
+ "PAYMENT-SIGNATURE": encoded
965
+ }
966
+ });
967
+ }
968
+ };
969
+
970
+ // src/client.ts
971
+ var Djeon402ClientSDK = class {
972
+ constructor(config) {
973
+ const { rpcUrl, contractAddress, kycRegistryAddress, chainId } = config;
974
+ this.contractAddress = contractAddress;
975
+ this.kycRegistryAddress = kycRegistryAddress;
976
+ this.chainId = chainId;
977
+ const chain = chainId === 8453 ? base : {
978
+ id: chainId,
979
+ name: "Custom Chain",
980
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
981
+ rpcUrls: {
982
+ default: { http: [rpcUrl || ""] },
983
+ public: { http: [rpcUrl || ""] }
984
+ }
985
+ };
986
+ this.publicClient = createPublicClient({
987
+ chain,
988
+ transport: http(rpcUrl)
989
+ });
990
+ this.token = new TokenModule(this);
991
+ this.admin = new AdminModule(this);
992
+ this.kyc = new KYCModule(this);
993
+ this.x402 = new X402Module(this);
994
+ }
995
+ /**
996
+ * Get chain configuration
997
+ */
998
+ getChain() {
999
+ return this.chainId === 8453 ? base : {
1000
+ id: this.chainId,
1001
+ name: "Custom Chain",
1002
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
1003
+ rpcUrls: {
1004
+ default: { http: [this.publicClient.transport.url || ""] },
1005
+ public: { http: [this.publicClient.transport.url || ""] }
1006
+ }
1007
+ };
1008
+ }
1009
+ };
1010
+
1011
+ // src/vue/useDjeon402.ts
1012
+ var Djeon402Key = /* @__PURE__ */ Symbol("djeon402");
1013
+ function provideDjeon402(config) {
1014
+ const sdk = new Djeon402ClientSDK({
1015
+ contractAddress: config.contractAddress,
1016
+ kycRegistryAddress: config.kycRegistryAddress,
1017
+ chainId: config.chainId,
1018
+ rpcUrl: config.rpcUrl || ""
1019
+ });
1020
+ const context = {
1021
+ sdk,
1022
+ config: readonly(config)
1023
+ };
1024
+ provide(Djeon402Key, context);
1025
+ return context;
1026
+ }
1027
+ function useDjeon402() {
1028
+ const context = inject(Djeon402Key);
1029
+ if (!context) {
1030
+ throw new Error("useDjeon402 must be used within provideDjeon402");
1031
+ }
1032
+ return context;
1033
+ }
1034
+
1035
+ // src/vue/useApprove.ts
1036
+ function useApprove(walletClient) {
1037
+ const { sdk } = useDjeon402();
1038
+ const data = ref(null);
1039
+ const error = ref(null);
1040
+ const isLoading = ref(false);
1041
+ const approve = async (spender, amount) => {
1042
+ if (!walletClient.value) {
1043
+ throw new Error("Wallet not connected");
1044
+ }
1045
+ isLoading.value = true;
1046
+ error.value = null;
1047
+ try {
1048
+ data.value = await sdk.token.approve({
1049
+ walletClient: walletClient.value,
1050
+ spender,
1051
+ amount
1052
+ });
1053
+ return data.value;
1054
+ } catch (e) {
1055
+ error.value = e;
1056
+ throw e;
1057
+ } finally {
1058
+ isLoading.value = false;
1059
+ }
1060
+ };
1061
+ return {
1062
+ approve,
1063
+ data,
1064
+ error,
1065
+ isLoading
1066
+ };
1067
+ }
1068
+
1069
+ // src/vue/useBalance.ts
1070
+ import { ref as ref2, watch } from "vue";
1071
+ function useBalance(address) {
1072
+ const { sdk } = useDjeon402();
1073
+ const data = ref2(null);
1074
+ const error = ref2(null);
1075
+ const isLoading = ref2(false);
1076
+ const fetch2 = async () => {
1077
+ if (!address.value) return;
1078
+ isLoading.value = true;
1079
+ error.value = null;
1080
+ try {
1081
+ data.value = await sdk.token.getBalance(address.value);
1082
+ } catch (e) {
1083
+ error.value = e;
1084
+ } finally {
1085
+ isLoading.value = false;
1086
+ }
1087
+ };
1088
+ watch(
1089
+ address,
1090
+ () => {
1091
+ fetch2();
1092
+ },
1093
+ { immediate: true }
1094
+ );
1095
+ return {
1096
+ data,
1097
+ error,
1098
+ isLoading,
1099
+ refetch: fetch2
1100
+ };
1101
+ }
1102
+
1103
+ // src/vue/useIsBlacklisted.ts
1104
+ import { ref as ref3, watch as watch2 } from "vue";
1105
+ function useIsBlacklisted(address) {
1106
+ const { sdk } = useDjeon402();
1107
+ const data = ref3(null);
1108
+ const error = ref3(null);
1109
+ const isLoading = ref3(false);
1110
+ const fetch2 = async () => {
1111
+ if (!address.value) return;
1112
+ isLoading.value = true;
1113
+ error.value = null;
1114
+ try {
1115
+ data.value = await sdk.admin.isBlacklisted(address.value);
1116
+ } catch (e) {
1117
+ error.value = e;
1118
+ } finally {
1119
+ isLoading.value = false;
1120
+ }
1121
+ };
1122
+ watch2(
1123
+ address,
1124
+ () => {
1125
+ fetch2();
1126
+ },
1127
+ { immediate: true }
1128
+ );
1129
+ return {
1130
+ data,
1131
+ error,
1132
+ isLoading,
1133
+ refetch: fetch2
1134
+ };
1135
+ }
1136
+
1137
+ // src/vue/useKYCData.ts
1138
+ import { ref as ref4, watch as watch3 } from "vue";
1139
+ function useKYCData(address) {
1140
+ const { sdk } = useDjeon402();
1141
+ const data = ref4(null);
1142
+ const error = ref4(null);
1143
+ const isLoading = ref4(false);
1144
+ const fetch2 = async () => {
1145
+ if (!address.value) return;
1146
+ isLoading.value = true;
1147
+ error.value = null;
1148
+ try {
1149
+ data.value = await sdk.kyc.getData(address.value);
1150
+ } catch (e) {
1151
+ error.value = e;
1152
+ } finally {
1153
+ isLoading.value = false;
1154
+ }
1155
+ };
1156
+ watch3(
1157
+ address,
1158
+ () => {
1159
+ fetch2();
1160
+ },
1161
+ { immediate: true }
1162
+ );
1163
+ return {
1164
+ data,
1165
+ error,
1166
+ isLoading,
1167
+ refetch: fetch2
1168
+ };
1169
+ }
1170
+
1171
+ // src/vue/useTokenInfo.ts
1172
+ import { onMounted, ref as ref5 } from "vue";
1173
+ function useTokenInfo() {
1174
+ const { sdk } = useDjeon402();
1175
+ const data = ref5(null);
1176
+ const error = ref5(null);
1177
+ const isLoading = ref5(false);
1178
+ const fetch2 = async () => {
1179
+ isLoading.value = true;
1180
+ error.value = null;
1181
+ try {
1182
+ data.value = await sdk.token.getInfo();
1183
+ } catch (e) {
1184
+ error.value = e;
1185
+ } finally {
1186
+ isLoading.value = false;
1187
+ }
1188
+ };
1189
+ onMounted(() => {
1190
+ fetch2();
1191
+ });
1192
+ return {
1193
+ data,
1194
+ error,
1195
+ isLoading,
1196
+ refetch: fetch2
1197
+ };
1198
+ }
1199
+
1200
+ // src/vue/useTransfer.ts
1201
+ import { ref as ref6 } from "vue";
1202
+ function useTransfer(walletClient) {
1203
+ const { sdk } = useDjeon402();
1204
+ const data = ref6(null);
1205
+ const error = ref6(null);
1206
+ const isLoading = ref6(false);
1207
+ const transfer = async (to, amount) => {
1208
+ if (!walletClient.value) {
1209
+ throw new Error("Wallet not connected");
1210
+ }
1211
+ isLoading.value = true;
1212
+ error.value = null;
1213
+ try {
1214
+ data.value = await sdk.token.transfer({
1215
+ walletClient: walletClient.value,
1216
+ to,
1217
+ amount
1218
+ });
1219
+ return data.value;
1220
+ } catch (e) {
1221
+ error.value = e;
1222
+ throw e;
1223
+ } finally {
1224
+ isLoading.value = false;
1225
+ }
1226
+ };
1227
+ return {
1228
+ transfer,
1229
+ data,
1230
+ error,
1231
+ isLoading
1232
+ };
1233
+ }
1234
+
1235
+ // src/vue/useX402Receive.ts
1236
+ import { ref as ref7 } from "vue";
1237
+ function useX402Receive(walletClient) {
1238
+ const { sdk } = useDjeon402();
1239
+ const data = ref7(null);
1240
+ const error = ref7(null);
1241
+ const isLoading = ref7(false);
1242
+ const signReceive = async (params) => {
1243
+ if (!walletClient.value) {
1244
+ throw new Error("Wallet not connected");
1245
+ }
1246
+ isLoading.value = true;
1247
+ error.value = null;
1248
+ try {
1249
+ data.value = await sdk.x402.signReceiveWithWallet({
1250
+ walletClient: walletClient.value,
1251
+ ...params
1252
+ });
1253
+ return data.value;
1254
+ } catch (e) {
1255
+ error.value = e;
1256
+ throw e;
1257
+ } finally {
1258
+ isLoading.value = false;
1259
+ }
1260
+ };
1261
+ return {
1262
+ signReceive,
1263
+ authorization: data,
1264
+ error,
1265
+ isLoading
1266
+ };
1267
+ }
1268
+
1269
+ // src/vue/useX402Transfer.ts
1270
+ import { ref as ref8 } from "vue";
1271
+ function useX402Transfer(walletClient) {
1272
+ const { sdk } = useDjeon402();
1273
+ const data = ref8(null);
1274
+ const error = ref8(null);
1275
+ const isLoading = ref8(false);
1276
+ const signTransfer = async (params) => {
1277
+ if (!walletClient.value) {
1278
+ throw new Error("Wallet not connected");
1279
+ }
1280
+ isLoading.value = true;
1281
+ error.value = null;
1282
+ try {
1283
+ data.value = await sdk.x402.signTransferWithWallet({
1284
+ walletClient: walletClient.value,
1285
+ ...params
1286
+ });
1287
+ return data.value;
1288
+ } catch (e) {
1289
+ error.value = e;
1290
+ throw e;
1291
+ } finally {
1292
+ isLoading.value = false;
1293
+ }
1294
+ };
1295
+ return {
1296
+ signTransfer,
1297
+ authorization: data,
1298
+ error,
1299
+ isLoading
1300
+ };
1301
+ }
1302
+ export {
1303
+ provideDjeon402,
1304
+ useApprove,
1305
+ useBalance,
1306
+ useDjeon402,
1307
+ useIsBlacklisted,
1308
+ useKYCData,
1309
+ useTokenInfo,
1310
+ useTransfer,
1311
+ useX402Receive,
1312
+ useX402Transfer
1313
+ };
1314
+ //# sourceMappingURL=index.js.map