@bbuilders/djeon402-core 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.
package/dist/index.js ADDED
@@ -0,0 +1,616 @@
1
+ import { keccak256, formatUnits, parseUnits, isAddress } from 'viem';
2
+
3
+ // src/abi/index.ts
4
+ var DJEON402_ABI = [
5
+ // ERC-20 Standard
6
+ {
7
+ type: "function",
8
+ name: "name",
9
+ inputs: [],
10
+ outputs: [{ type: "string" }],
11
+ stateMutability: "view"
12
+ },
13
+ {
14
+ type: "function",
15
+ name: "symbol",
16
+ inputs: [],
17
+ outputs: [{ type: "string" }],
18
+ stateMutability: "view"
19
+ },
20
+ {
21
+ type: "function",
22
+ name: "decimals",
23
+ inputs: [],
24
+ outputs: [{ type: "uint8" }],
25
+ stateMutability: "view"
26
+ },
27
+ {
28
+ type: "function",
29
+ name: "totalSupply",
30
+ inputs: [],
31
+ outputs: [{ type: "uint256" }],
32
+ stateMutability: "view"
33
+ },
34
+ {
35
+ type: "function",
36
+ name: "balanceOf",
37
+ inputs: [{ name: "account", type: "address" }],
38
+ outputs: [{ type: "uint256" }],
39
+ stateMutability: "view"
40
+ },
41
+ {
42
+ type: "function",
43
+ name: "allowance",
44
+ inputs: [
45
+ { name: "owner", type: "address" },
46
+ { name: "spender", type: "address" }
47
+ ],
48
+ outputs: [{ type: "uint256" }],
49
+ stateMutability: "view"
50
+ },
51
+ {
52
+ type: "function",
53
+ name: "transfer",
54
+ inputs: [
55
+ { name: "to", type: "address" },
56
+ { name: "amount", type: "uint256" }
57
+ ],
58
+ outputs: [{ type: "bool" }],
59
+ stateMutability: "nonpayable"
60
+ },
61
+ {
62
+ type: "function",
63
+ name: "approve",
64
+ inputs: [
65
+ { name: "spender", type: "address" },
66
+ { name: "amount", type: "uint256" }
67
+ ],
68
+ outputs: [{ type: "bool" }],
69
+ stateMutability: "nonpayable"
70
+ },
71
+ {
72
+ type: "function",
73
+ name: "transferFrom",
74
+ inputs: [
75
+ { name: "from", type: "address" },
76
+ { name: "to", type: "address" },
77
+ { name: "amount", type: "uint256" }
78
+ ],
79
+ outputs: [{ type: "bool" }],
80
+ stateMutability: "nonpayable"
81
+ },
82
+ // ERC-2612 Permit
83
+ {
84
+ type: "function",
85
+ name: "permit",
86
+ inputs: [
87
+ { name: "owner", type: "address" },
88
+ { name: "spender", type: "address" },
89
+ { name: "value", type: "uint256" },
90
+ { name: "deadline", type: "uint256" },
91
+ { name: "v", type: "uint8" },
92
+ { name: "r", type: "bytes32" },
93
+ { name: "s", type: "bytes32" }
94
+ ],
95
+ outputs: [],
96
+ stateMutability: "nonpayable"
97
+ },
98
+ {
99
+ type: "function",
100
+ name: "nonces",
101
+ inputs: [{ name: "owner", type: "address" }],
102
+ outputs: [{ type: "uint256" }],
103
+ stateMutability: "view"
104
+ },
105
+ {
106
+ type: "function",
107
+ name: "DOMAIN_SEPARATOR",
108
+ inputs: [],
109
+ outputs: [{ type: "bytes32" }],
110
+ stateMutability: "view"
111
+ },
112
+ // EIP-3009 Transfer With Authorization
113
+ {
114
+ type: "function",
115
+ name: "transferWithAuthorization",
116
+ inputs: [
117
+ { name: "from", type: "address" },
118
+ { name: "to", type: "address" },
119
+ { name: "value", type: "uint256" },
120
+ { name: "validAfter", type: "uint256" },
121
+ { name: "validBefore", type: "uint256" },
122
+ { name: "nonce", type: "bytes32" },
123
+ { name: "v", type: "uint8" },
124
+ { name: "r", type: "bytes32" },
125
+ { name: "s", type: "bytes32" }
126
+ ],
127
+ outputs: [],
128
+ stateMutability: "nonpayable"
129
+ },
130
+ {
131
+ type: "function",
132
+ name: "receiveWithAuthorization",
133
+ inputs: [
134
+ { name: "from", type: "address" },
135
+ { name: "to", type: "address" },
136
+ { name: "value", type: "uint256" },
137
+ { name: "validAfter", type: "uint256" },
138
+ { name: "validBefore", type: "uint256" },
139
+ { name: "nonce", type: "bytes32" },
140
+ { name: "v", type: "uint8" },
141
+ { name: "r", type: "bytes32" },
142
+ { name: "s", type: "bytes32" }
143
+ ],
144
+ outputs: [],
145
+ stateMutability: "nonpayable"
146
+ },
147
+ {
148
+ type: "function",
149
+ name: "cancelAuthorization",
150
+ inputs: [
151
+ { name: "authorizer", type: "address" },
152
+ { name: "nonce", type: "bytes32" },
153
+ { name: "v", type: "uint8" },
154
+ { name: "r", type: "bytes32" },
155
+ { name: "s", type: "bytes32" }
156
+ ],
157
+ outputs: [],
158
+ stateMutability: "nonpayable"
159
+ },
160
+ {
161
+ type: "function",
162
+ name: "authorizationState",
163
+ inputs: [
164
+ { name: "authorizer", type: "address" },
165
+ { name: "nonce", type: "bytes32" }
166
+ ],
167
+ outputs: [{ type: "bool" }],
168
+ stateMutability: "view"
169
+ },
170
+ // Mint & Burn
171
+ {
172
+ type: "function",
173
+ name: "mint",
174
+ inputs: [
175
+ { name: "to", type: "address" },
176
+ { name: "amount", type: "uint256" }
177
+ ],
178
+ outputs: [],
179
+ stateMutability: "nonpayable"
180
+ },
181
+ {
182
+ type: "function",
183
+ name: "burn",
184
+ inputs: [{ name: "amount", type: "uint256" }],
185
+ outputs: [],
186
+ stateMutability: "nonpayable"
187
+ },
188
+ // Blacklist
189
+ {
190
+ type: "function",
191
+ name: "blacklist",
192
+ inputs: [{ name: "account", type: "address" }],
193
+ outputs: [],
194
+ stateMutability: "nonpayable"
195
+ },
196
+ {
197
+ type: "function",
198
+ name: "unBlacklist",
199
+ inputs: [{ name: "account", type: "address" }],
200
+ outputs: [],
201
+ stateMutability: "nonpayable"
202
+ },
203
+ {
204
+ type: "function",
205
+ name: "isBlacklisted",
206
+ inputs: [{ name: "account", type: "address" }],
207
+ outputs: [{ type: "bool" }],
208
+ stateMutability: "view"
209
+ },
210
+ // Pausable
211
+ {
212
+ type: "function",
213
+ name: "pause",
214
+ inputs: [],
215
+ outputs: [],
216
+ stateMutability: "nonpayable"
217
+ },
218
+ {
219
+ type: "function",
220
+ name: "unpause",
221
+ inputs: [],
222
+ outputs: [],
223
+ stateMutability: "nonpayable"
224
+ },
225
+ {
226
+ type: "function",
227
+ name: "paused",
228
+ inputs: [],
229
+ outputs: [{ type: "bool" }],
230
+ stateMutability: "view"
231
+ },
232
+ // Access Control
233
+ {
234
+ type: "function",
235
+ name: "hasRole",
236
+ inputs: [
237
+ { name: "role", type: "bytes32" },
238
+ { name: "account", type: "address" }
239
+ ],
240
+ outputs: [{ type: "bool" }],
241
+ stateMutability: "view"
242
+ },
243
+ {
244
+ type: "function",
245
+ name: "grantRole",
246
+ inputs: [
247
+ { name: "role", type: "bytes32" },
248
+ { name: "account", type: "address" }
249
+ ],
250
+ outputs: [],
251
+ stateMutability: "nonpayable"
252
+ },
253
+ {
254
+ type: "function",
255
+ name: "revokeRole",
256
+ inputs: [
257
+ { name: "role", type: "bytes32" },
258
+ { name: "account", type: "address" }
259
+ ],
260
+ outputs: [],
261
+ stateMutability: "nonpayable"
262
+ },
263
+ {
264
+ type: "function",
265
+ name: "renounceRole",
266
+ inputs: [{ name: "role", type: "bytes32" }],
267
+ outputs: [],
268
+ stateMutability: "nonpayable"
269
+ },
270
+ // Role constants
271
+ {
272
+ type: "function",
273
+ name: "DEFAULT_ADMIN_ROLE",
274
+ inputs: [],
275
+ outputs: [{ type: "bytes32" }],
276
+ stateMutability: "pure"
277
+ },
278
+ {
279
+ type: "function",
280
+ name: "MINTER_ROLE",
281
+ inputs: [],
282
+ outputs: [{ type: "bytes32" }],
283
+ stateMutability: "pure"
284
+ },
285
+ {
286
+ type: "function",
287
+ name: "BURNER_ROLE",
288
+ inputs: [],
289
+ outputs: [{ type: "bytes32" }],
290
+ stateMutability: "pure"
291
+ },
292
+ {
293
+ type: "function",
294
+ name: "PAUSER_ROLE",
295
+ inputs: [],
296
+ outputs: [{ type: "bytes32" }],
297
+ stateMutability: "pure"
298
+ },
299
+ {
300
+ type: "function",
301
+ name: "BLACKLISTER_ROLE",
302
+ inputs: [],
303
+ outputs: [{ type: "bytes32" }],
304
+ stateMutability: "pure"
305
+ },
306
+ {
307
+ type: "function",
308
+ name: "KYC_ADMIN_ROLE",
309
+ inputs: [],
310
+ outputs: [{ type: "bytes32" }],
311
+ stateMutability: "pure"
312
+ },
313
+ // Version
314
+ {
315
+ type: "function",
316
+ name: "version",
317
+ inputs: [],
318
+ outputs: [{ type: "string" }],
319
+ stateMutability: "pure"
320
+ },
321
+ // Events
322
+ {
323
+ type: "event",
324
+ name: "Transfer",
325
+ inputs: [
326
+ { name: "from", type: "address", indexed: true },
327
+ { name: "to", type: "address", indexed: true },
328
+ { name: "value", type: "uint256", indexed: false }
329
+ ]
330
+ },
331
+ {
332
+ type: "event",
333
+ name: "Approval",
334
+ inputs: [
335
+ { name: "owner", type: "address", indexed: true },
336
+ { name: "spender", type: "address", indexed: true },
337
+ { name: "value", type: "uint256", indexed: false }
338
+ ]
339
+ },
340
+ {
341
+ type: "event",
342
+ name: "Mint",
343
+ inputs: [
344
+ { name: "minter", type: "address", indexed: true },
345
+ { name: "to", type: "address", indexed: true },
346
+ { name: "amount", type: "uint256", indexed: false }
347
+ ]
348
+ },
349
+ {
350
+ type: "event",
351
+ name: "Burn",
352
+ inputs: [
353
+ { name: "burner", type: "address", indexed: true },
354
+ { name: "amount", type: "uint256", indexed: false }
355
+ ]
356
+ },
357
+ {
358
+ type: "event",
359
+ name: "Blacklisted",
360
+ inputs: [{ name: "account", type: "address", indexed: true }]
361
+ },
362
+ {
363
+ type: "event",
364
+ name: "UnBlacklisted",
365
+ inputs: [{ name: "account", type: "address", indexed: true }]
366
+ },
367
+ {
368
+ type: "event",
369
+ name: "Paused",
370
+ inputs: [{ name: "account", type: "address", indexed: false }]
371
+ },
372
+ {
373
+ type: "event",
374
+ name: "Unpaused",
375
+ inputs: [{ name: "account", type: "address", indexed: false }]
376
+ },
377
+ {
378
+ type: "event",
379
+ name: "AuthorizationUsed",
380
+ inputs: [
381
+ { name: "authorizer", type: "address", indexed: true },
382
+ { name: "nonce", type: "bytes32", indexed: true }
383
+ ]
384
+ },
385
+ {
386
+ type: "event",
387
+ name: "AuthorizationCanceled",
388
+ inputs: [
389
+ { name: "authorizer", type: "address", indexed: true },
390
+ { name: "nonce", type: "bytes32", indexed: true }
391
+ ]
392
+ },
393
+ // Errors
394
+ { type: "error", name: "InvalidAddress", inputs: [] },
395
+ { type: "error", name: "InsufficientBalance", inputs: [] },
396
+ { type: "error", name: "InsufficientAllowance", inputs: [] },
397
+ {
398
+ type: "error",
399
+ name: "AccountBlacklisted",
400
+ inputs: [{ name: "account", type: "address" }]
401
+ },
402
+ { type: "error", name: "ContractPaused", inputs: [] },
403
+ { type: "error", name: "AccessDenied", inputs: [] },
404
+ { type: "error", name: "InvalidSignature", inputs: [] },
405
+ { type: "error", name: "AuthorizationExpired", inputs: [] },
406
+ { type: "error", name: "AuthorizationNotYetValid", inputs: [] },
407
+ { type: "error", name: "AuthorizationAlreadyUsed", inputs: [] },
408
+ { type: "error", name: "PermitExpired", inputs: [] }
409
+ ];
410
+ var KYC_REGISTRY_ABI = [
411
+ // View Functions
412
+ {
413
+ type: "function",
414
+ name: "getKYCData",
415
+ inputs: [{ name: "user", type: "address" }],
416
+ outputs: [
417
+ { name: "level", type: "uint8" },
418
+ { name: "expiryDate", type: "uint256" },
419
+ { name: "kycHash", type: "string" },
420
+ { name: "isActive", type: "bool" },
421
+ { name: "dailyLimit", type: "uint256" },
422
+ { name: "dailySpent", type: "uint256" }
423
+ ],
424
+ stateMutability: "view"
425
+ },
426
+ {
427
+ type: "function",
428
+ name: "getKYCLevel",
429
+ inputs: [{ name: "user", type: "address" }],
430
+ outputs: [{ name: "", type: "uint8" }],
431
+ stateMutability: "view"
432
+ },
433
+ {
434
+ type: "function",
435
+ name: "isKYCValid",
436
+ inputs: [{ name: "user", type: "address" }],
437
+ outputs: [{ name: "", type: "bool" }],
438
+ stateMutability: "view"
439
+ },
440
+ {
441
+ type: "function",
442
+ name: "getRemainingDailyLimit",
443
+ inputs: [{ name: "user", type: "address" }],
444
+ outputs: [{ name: "", type: "uint256" }],
445
+ stateMutability: "view"
446
+ },
447
+ {
448
+ type: "function",
449
+ name: "isProviderApproved",
450
+ inputs: [{ name: "provider", type: "address" }],
451
+ outputs: [{ name: "", type: "bool" }],
452
+ stateMutability: "view"
453
+ },
454
+ // State-changing Functions
455
+ {
456
+ type: "function",
457
+ name: "verifyKYC",
458
+ inputs: [
459
+ { name: "user", type: "address" },
460
+ { name: "level", type: "uint8" },
461
+ { name: "expiryDate", type: "uint256" },
462
+ { name: "kycHash", type: "string" }
463
+ ],
464
+ outputs: [],
465
+ stateMutability: "nonpayable"
466
+ },
467
+ {
468
+ type: "function",
469
+ name: "updateKYC",
470
+ inputs: [
471
+ { name: "user", type: "address" },
472
+ { name: "level", type: "uint8" },
473
+ { name: "expiryDate", type: "uint256" }
474
+ ],
475
+ outputs: [],
476
+ stateMutability: "nonpayable"
477
+ },
478
+ {
479
+ type: "function",
480
+ name: "revokeKYC",
481
+ inputs: [{ name: "user", type: "address" }],
482
+ outputs: [],
483
+ stateMutability: "nonpayable"
484
+ },
485
+ {
486
+ type: "function",
487
+ name: "setDailyLimit",
488
+ inputs: [
489
+ { name: "user", type: "address" },
490
+ { name: "newLimit", type: "uint256" }
491
+ ],
492
+ outputs: [],
493
+ stateMutability: "nonpayable"
494
+ },
495
+ {
496
+ type: "function",
497
+ name: "checkDailyLimit",
498
+ inputs: [
499
+ { name: "user", type: "address" },
500
+ { name: "amount", type: "uint256" }
501
+ ],
502
+ outputs: [{ name: "", type: "bool" }],
503
+ stateMutability: "nonpayable"
504
+ },
505
+ {
506
+ type: "function",
507
+ name: "approveProvider",
508
+ inputs: [{ name: "provider", type: "address" }],
509
+ outputs: [],
510
+ stateMutability: "nonpayable"
511
+ },
512
+ {
513
+ type: "function",
514
+ name: "revokeProvider",
515
+ inputs: [{ name: "provider", type: "address" }],
516
+ outputs: [],
517
+ stateMutability: "nonpayable"
518
+ },
519
+ // Events
520
+ {
521
+ type: "event",
522
+ name: "KYCVerified",
523
+ inputs: [
524
+ { name: "user", type: "address", indexed: true },
525
+ { name: "level", type: "uint8", indexed: false },
526
+ { name: "expiryDate", type: "uint256", indexed: false },
527
+ { name: "dailyLimit", type: "uint256", indexed: false }
528
+ ]
529
+ },
530
+ {
531
+ type: "event",
532
+ name: "KYCRevoked",
533
+ inputs: [{ name: "user", type: "address", indexed: true }]
534
+ },
535
+ {
536
+ type: "event",
537
+ name: "KYCUpdated",
538
+ inputs: [
539
+ { name: "user", type: "address", indexed: true },
540
+ { name: "level", type: "uint8", indexed: false },
541
+ { name: "expiryDate", type: "uint256", indexed: false }
542
+ ]
543
+ }
544
+ ];
545
+ var DEFAULT_CHAIN_ID = 31337;
546
+ var DEFAULT_RPC_URL = "http://127.0.0.1:8545";
547
+ var DJEON402_DECIMALS = 18;
548
+ var EIP712_DOMAIN_NAME = "DONGJEON402 Token";
549
+ var EIP712_DOMAIN_VERSION = "1";
550
+ var TRANSFER_WITH_AUTHORIZATION_TYPEHASH = keccak256(
551
+ Buffer.from(
552
+ "TransferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)"
553
+ )
554
+ );
555
+ var RECEIVE_WITH_AUTHORIZATION_TYPEHASH = keccak256(
556
+ Buffer.from(
557
+ "ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)"
558
+ )
559
+ );
560
+ var CANCEL_AUTHORIZATION_TYPEHASH = keccak256(
561
+ Buffer.from("CancelAuthorization(address authorizer,bytes32 nonce)")
562
+ );
563
+ var KYC_LEVEL_NAMES = ["None", "Tier1", "Tier2", "Tier3"];
564
+ var DEFAULT_VALID_AFTER = 0n;
565
+ var DEFAULT_VALID_BEFORE = () => BigInt(Math.floor(Date.now() / 1e3) + 3600);
566
+ function formatTokenAmount(value, decimals = DJEON402_DECIMALS) {
567
+ return formatUnits(value, decimals);
568
+ }
569
+ function parseTokenAmount(value, decimals = DJEON402_DECIMALS) {
570
+ return parseUnits(value, decimals);
571
+ }
572
+ function formatTimestamp(timestamp) {
573
+ const ts = typeof timestamp === "bigint" ? Number(timestamp) : timestamp;
574
+ if (ts === 0) return "No Expiry";
575
+ return new Date(ts * 1e3).toISOString();
576
+ }
577
+ function getKYCLevelName(level) {
578
+ const names = ["None", "Tier1", "Tier2", "Tier3"];
579
+ return names[level];
580
+ }
581
+ function validateAddress(address) {
582
+ if (!isAddress(address)) {
583
+ throw new Error(`Invalid address: ${address}`);
584
+ }
585
+ }
586
+ function validatePrivateKey(privateKey) {
587
+ if (!privateKey.startsWith("0x")) {
588
+ throw new Error("Private key must start with 0x");
589
+ }
590
+ if (privateKey.length !== 66) {
591
+ throw new Error("Private key must be 66 characters (0x + 64 hex characters)");
592
+ }
593
+ }
594
+ function validateAmount(amount) {
595
+ const num = parseFloat(amount);
596
+ if (Number.isNaN(num) || num <= 0) {
597
+ throw new Error(`Invalid amount: ${amount}. Must be a positive number.`);
598
+ }
599
+ }
600
+ function validateKYCLevel(level) {
601
+ if (![0, 1, 2, 3].includes(level)) {
602
+ throw new Error(`Invalid KYC level: ${level}. Must be 0, 1, 2, or 3.`);
603
+ }
604
+ }
605
+ function validateHex(hex) {
606
+ if (!hex.startsWith("0x")) {
607
+ throw new Error("Hex string must start with 0x");
608
+ }
609
+ if (!/^0x[0-9a-fA-F]+$/.test(hex)) {
610
+ throw new Error("Invalid hex string");
611
+ }
612
+ }
613
+
614
+ export { CANCEL_AUTHORIZATION_TYPEHASH, DEFAULT_CHAIN_ID, DEFAULT_RPC_URL, DEFAULT_VALID_AFTER, DEFAULT_VALID_BEFORE, DJEON402_ABI, DJEON402_DECIMALS, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, KYC_LEVEL_NAMES, KYC_REGISTRY_ABI, RECEIVE_WITH_AUTHORIZATION_TYPEHASH, TRANSFER_WITH_AUTHORIZATION_TYPEHASH, formatTimestamp, formatTokenAmount, getKYCLevelName, parseTokenAmount, validateAddress, validateAmount, validateHex, validateKYCLevel, validatePrivateKey };
615
+ //# sourceMappingURL=index.js.map
616
+ //# sourceMappingURL=index.js.map