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