@qorechain/evm 0.3.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,1010 @@
1
+ 'use strict';
2
+
3
+ var viem = require('viem');
4
+ var accounts = require('viem/accounts');
5
+
6
+ // src/client.ts
7
+ function resolveRpcUrl(opts) {
8
+ const url = opts.rpcUrl ?? opts.endpoints?.evmRpc;
9
+ if (!url) {
10
+ throw new Error("createEvmClient: provide `rpcUrl` or `endpoints.evmRpc`");
11
+ }
12
+ return url;
13
+ }
14
+ function resolveWsUrl(opts) {
15
+ return opts.wsUrl ?? opts.endpoints?.evmWs;
16
+ }
17
+ async function createEvmClient(opts) {
18
+ const rpcUrl = resolveRpcUrl(opts);
19
+ const wsUrl = resolveWsUrl(opts);
20
+ const transport = opts.transport ?? viem.http(rpcUrl);
21
+ const decimals = opts.decimals ?? 18;
22
+ let chainId = opts.chainId;
23
+ if (chainId === void 0) {
24
+ const probe = viem.createPublicClient({ transport });
25
+ chainId = await probe.getChainId();
26
+ }
27
+ const chain = viem.defineChain({
28
+ id: chainId,
29
+ name: "QoreChain EVM",
30
+ nativeCurrency: { name: "QOR", symbol: "QOR", decimals },
31
+ rpcUrls: {
32
+ default: {
33
+ http: [rpcUrl],
34
+ ...wsUrl ? { webSocket: [wsUrl] } : {}
35
+ }
36
+ }
37
+ });
38
+ const publicClient = viem.createPublicClient({ chain, transport });
39
+ const getWalletClient = (account) => viem.createWalletClient({ account, chain, transport });
40
+ return {
41
+ publicClient,
42
+ getWalletClient,
43
+ chain,
44
+ getChainId: async () => chainId
45
+ };
46
+ }
47
+ function evmAccountFromPrivateKey(privateKey) {
48
+ return accounts.privateKeyToAccount(privateKey);
49
+ }
50
+
51
+ // src/abi.ts
52
+ var ERC20_ABI = [
53
+ {
54
+ type: "function",
55
+ name: "name",
56
+ stateMutability: "view",
57
+ inputs: [],
58
+ outputs: [{ name: "", type: "string" }]
59
+ },
60
+ {
61
+ type: "function",
62
+ name: "symbol",
63
+ stateMutability: "view",
64
+ inputs: [],
65
+ outputs: [{ name: "", type: "string" }]
66
+ },
67
+ {
68
+ type: "function",
69
+ name: "decimals",
70
+ stateMutability: "view",
71
+ inputs: [],
72
+ outputs: [{ name: "", type: "uint8" }]
73
+ },
74
+ {
75
+ type: "function",
76
+ name: "totalSupply",
77
+ stateMutability: "view",
78
+ inputs: [],
79
+ outputs: [{ name: "", type: "uint256" }]
80
+ },
81
+ {
82
+ type: "function",
83
+ name: "balanceOf",
84
+ stateMutability: "view",
85
+ inputs: [{ name: "account", type: "address" }],
86
+ outputs: [{ name: "", type: "uint256" }]
87
+ },
88
+ {
89
+ type: "function",
90
+ name: "allowance",
91
+ stateMutability: "view",
92
+ inputs: [
93
+ { name: "owner", type: "address" },
94
+ { name: "spender", type: "address" }
95
+ ],
96
+ outputs: [{ name: "", type: "uint256" }]
97
+ },
98
+ {
99
+ type: "function",
100
+ name: "transfer",
101
+ stateMutability: "nonpayable",
102
+ inputs: [
103
+ { name: "to", type: "address" },
104
+ { name: "amount", type: "uint256" }
105
+ ],
106
+ outputs: [{ name: "", type: "bool" }]
107
+ },
108
+ {
109
+ type: "function",
110
+ name: "approve",
111
+ stateMutability: "nonpayable",
112
+ inputs: [
113
+ { name: "spender", type: "address" },
114
+ { name: "amount", type: "uint256" }
115
+ ],
116
+ outputs: [{ name: "", type: "bool" }]
117
+ },
118
+ {
119
+ type: "event",
120
+ name: "Transfer",
121
+ inputs: [
122
+ { indexed: true, name: "from", type: "address" },
123
+ { indexed: true, name: "to", type: "address" },
124
+ { indexed: false, name: "value", type: "uint256" }
125
+ ]
126
+ },
127
+ {
128
+ type: "event",
129
+ name: "Approval",
130
+ inputs: [
131
+ { indexed: true, name: "owner", type: "address" },
132
+ { indexed: true, name: "spender", type: "address" },
133
+ { indexed: false, name: "value", type: "uint256" }
134
+ ]
135
+ }
136
+ ];
137
+ var ERC721_ABI = [
138
+ {
139
+ type: "function",
140
+ name: "name",
141
+ stateMutability: "view",
142
+ inputs: [],
143
+ outputs: [{ name: "", type: "string" }]
144
+ },
145
+ {
146
+ type: "function",
147
+ name: "symbol",
148
+ stateMutability: "view",
149
+ inputs: [],
150
+ outputs: [{ name: "", type: "string" }]
151
+ },
152
+ {
153
+ type: "function",
154
+ name: "balanceOf",
155
+ stateMutability: "view",
156
+ inputs: [{ name: "owner", type: "address" }],
157
+ outputs: [{ name: "", type: "uint256" }]
158
+ },
159
+ {
160
+ type: "function",
161
+ name: "ownerOf",
162
+ stateMutability: "view",
163
+ inputs: [{ name: "tokenId", type: "uint256" }],
164
+ outputs: [{ name: "", type: "address" }]
165
+ },
166
+ {
167
+ type: "function",
168
+ name: "tokenURI",
169
+ stateMutability: "view",
170
+ inputs: [{ name: "tokenId", type: "uint256" }],
171
+ outputs: [{ name: "", type: "string" }]
172
+ },
173
+ {
174
+ type: "function",
175
+ name: "getApproved",
176
+ stateMutability: "view",
177
+ inputs: [{ name: "tokenId", type: "uint256" }],
178
+ outputs: [{ name: "", type: "address" }]
179
+ },
180
+ {
181
+ type: "function",
182
+ name: "isApprovedForAll",
183
+ stateMutability: "view",
184
+ inputs: [
185
+ { name: "owner", type: "address" },
186
+ { name: "operator", type: "address" }
187
+ ],
188
+ outputs: [{ name: "", type: "bool" }]
189
+ },
190
+ {
191
+ type: "function",
192
+ name: "approve",
193
+ stateMutability: "nonpayable",
194
+ inputs: [
195
+ { name: "to", type: "address" },
196
+ { name: "tokenId", type: "uint256" }
197
+ ],
198
+ outputs: []
199
+ },
200
+ {
201
+ type: "function",
202
+ name: "setApprovalForAll",
203
+ stateMutability: "nonpayable",
204
+ inputs: [
205
+ { name: "operator", type: "address" },
206
+ { name: "approved", type: "bool" }
207
+ ],
208
+ outputs: []
209
+ },
210
+ {
211
+ type: "function",
212
+ name: "transferFrom",
213
+ stateMutability: "nonpayable",
214
+ inputs: [
215
+ { name: "from", type: "address" },
216
+ { name: "to", type: "address" },
217
+ { name: "tokenId", type: "uint256" }
218
+ ],
219
+ outputs: []
220
+ },
221
+ {
222
+ type: "function",
223
+ name: "safeTransferFrom",
224
+ stateMutability: "nonpayable",
225
+ inputs: [
226
+ { name: "from", type: "address" },
227
+ { name: "to", type: "address" },
228
+ { name: "tokenId", type: "uint256" }
229
+ ],
230
+ outputs: []
231
+ },
232
+ {
233
+ type: "function",
234
+ name: "safeTransferFrom",
235
+ stateMutability: "nonpayable",
236
+ inputs: [
237
+ { name: "from", type: "address" },
238
+ { name: "to", type: "address" },
239
+ { name: "tokenId", type: "uint256" },
240
+ { name: "data", type: "bytes" }
241
+ ],
242
+ outputs: []
243
+ },
244
+ {
245
+ type: "event",
246
+ name: "Transfer",
247
+ inputs: [
248
+ { indexed: true, name: "from", type: "address" },
249
+ { indexed: true, name: "to", type: "address" },
250
+ { indexed: true, name: "tokenId", type: "uint256" }
251
+ ]
252
+ },
253
+ {
254
+ type: "event",
255
+ name: "Approval",
256
+ inputs: [
257
+ { indexed: true, name: "owner", type: "address" },
258
+ { indexed: true, name: "approved", type: "address" },
259
+ { indexed: true, name: "tokenId", type: "uint256" }
260
+ ]
261
+ },
262
+ {
263
+ type: "event",
264
+ name: "ApprovalForAll",
265
+ inputs: [
266
+ { indexed: true, name: "owner", type: "address" },
267
+ { indexed: true, name: "operator", type: "address" },
268
+ { indexed: false, name: "approved", type: "bool" }
269
+ ]
270
+ }
271
+ ];
272
+ var ERC1155_ABI = [
273
+ {
274
+ type: "function",
275
+ name: "balanceOf",
276
+ stateMutability: "view",
277
+ inputs: [
278
+ { name: "account", type: "address" },
279
+ { name: "id", type: "uint256" }
280
+ ],
281
+ outputs: [{ name: "", type: "uint256" }]
282
+ },
283
+ {
284
+ type: "function",
285
+ name: "balanceOfBatch",
286
+ stateMutability: "view",
287
+ inputs: [
288
+ { name: "accounts", type: "address[]" },
289
+ { name: "ids", type: "uint256[]" }
290
+ ],
291
+ outputs: [{ name: "", type: "uint256[]" }]
292
+ },
293
+ {
294
+ type: "function",
295
+ name: "uri",
296
+ stateMutability: "view",
297
+ inputs: [{ name: "id", type: "uint256" }],
298
+ outputs: [{ name: "", type: "string" }]
299
+ },
300
+ {
301
+ type: "function",
302
+ name: "isApprovedForAll",
303
+ stateMutability: "view",
304
+ inputs: [
305
+ { name: "account", type: "address" },
306
+ { name: "operator", type: "address" }
307
+ ],
308
+ outputs: [{ name: "", type: "bool" }]
309
+ },
310
+ {
311
+ type: "function",
312
+ name: "setApprovalForAll",
313
+ stateMutability: "nonpayable",
314
+ inputs: [
315
+ { name: "operator", type: "address" },
316
+ { name: "approved", type: "bool" }
317
+ ],
318
+ outputs: []
319
+ },
320
+ {
321
+ type: "function",
322
+ name: "safeTransferFrom",
323
+ stateMutability: "nonpayable",
324
+ inputs: [
325
+ { name: "from", type: "address" },
326
+ { name: "to", type: "address" },
327
+ { name: "id", type: "uint256" },
328
+ { name: "amount", type: "uint256" },
329
+ { name: "data", type: "bytes" }
330
+ ],
331
+ outputs: []
332
+ },
333
+ {
334
+ type: "function",
335
+ name: "safeBatchTransferFrom",
336
+ stateMutability: "nonpayable",
337
+ inputs: [
338
+ { name: "from", type: "address" },
339
+ { name: "to", type: "address" },
340
+ { name: "ids", type: "uint256[]" },
341
+ { name: "amounts", type: "uint256[]" },
342
+ { name: "data", type: "bytes" }
343
+ ],
344
+ outputs: []
345
+ },
346
+ {
347
+ type: "event",
348
+ name: "TransferSingle",
349
+ inputs: [
350
+ { indexed: true, name: "operator", type: "address" },
351
+ { indexed: true, name: "from", type: "address" },
352
+ { indexed: true, name: "to", type: "address" },
353
+ { indexed: false, name: "id", type: "uint256" },
354
+ { indexed: false, name: "value", type: "uint256" }
355
+ ]
356
+ },
357
+ {
358
+ type: "event",
359
+ name: "ApprovalForAll",
360
+ inputs: [
361
+ { indexed: true, name: "account", type: "address" },
362
+ { indexed: true, name: "operator", type: "address" },
363
+ { indexed: false, name: "approved", type: "bool" }
364
+ ]
365
+ }
366
+ ];
367
+ var IQORE_PQC_ABI = [
368
+ {
369
+ type: "function",
370
+ name: "pqcVerify",
371
+ stateMutability: "view",
372
+ inputs: [
373
+ { name: "pubkey", type: "bytes" },
374
+ { name: "signature", type: "bytes" },
375
+ { name: "message", type: "bytes" }
376
+ ],
377
+ outputs: [{ name: "valid", type: "bool" }]
378
+ },
379
+ {
380
+ type: "function",
381
+ name: "pqcKeyStatus",
382
+ stateMutability: "view",
383
+ inputs: [{ name: "account", type: "address" }],
384
+ outputs: [
385
+ { name: "registered", type: "bool" },
386
+ { name: "algorithmId", type: "uint8" },
387
+ { name: "pubkey", type: "bytes" }
388
+ ]
389
+ }
390
+ ];
391
+ var IQORE_AI_ABI = [
392
+ {
393
+ type: "function",
394
+ name: "aiRiskScore",
395
+ stateMutability: "view",
396
+ inputs: [{ name: "txData", type: "bytes" }],
397
+ outputs: [
398
+ { name: "score", type: "uint256" },
399
+ { name: "level", type: "uint8" }
400
+ ]
401
+ },
402
+ {
403
+ type: "function",
404
+ name: "aiAnomalyCheck",
405
+ stateMutability: "view",
406
+ inputs: [
407
+ { name: "sender", type: "address" },
408
+ { name: "amount", type: "uint256" }
409
+ ],
410
+ outputs: [
411
+ { name: "anomalyScore", type: "uint256" },
412
+ { name: "flagged", type: "bool" }
413
+ ]
414
+ }
415
+ ];
416
+ var IQORE_CONSENSUS_ABI = [
417
+ {
418
+ type: "function",
419
+ name: "rlConsensusParams",
420
+ stateMutability: "view",
421
+ inputs: [],
422
+ outputs: [
423
+ { name: "blockTime", type: "uint256" },
424
+ { name: "baseGasPrice", type: "uint256" },
425
+ { name: "validatorSetSize", type: "uint256" },
426
+ { name: "epoch", type: "uint256" }
427
+ ]
428
+ }
429
+ ];
430
+
431
+ // src/erc20.ts
432
+ function balanceOf(client, token, account) {
433
+ return client.readContract({
434
+ address: token,
435
+ abi: ERC20_ABI,
436
+ functionName: "balanceOf",
437
+ args: [account]
438
+ });
439
+ }
440
+ function allowance(client, token, owner, spender) {
441
+ return client.readContract({
442
+ address: token,
443
+ abi: ERC20_ABI,
444
+ functionName: "allowance",
445
+ args: [owner, spender]
446
+ });
447
+ }
448
+ async function metadata(client, token) {
449
+ const [name2, symbol2, decimals] = await Promise.all([
450
+ client.readContract({ address: token, abi: ERC20_ABI, functionName: "name" }),
451
+ client.readContract({ address: token, abi: ERC20_ABI, functionName: "symbol" }),
452
+ client.readContract({ address: token, abi: ERC20_ABI, functionName: "decimals" })
453
+ ]);
454
+ return { name: name2, symbol: symbol2, decimals };
455
+ }
456
+ function transfer(client, token, to, amount) {
457
+ return client.writeContract({
458
+ address: token,
459
+ abi: ERC20_ABI,
460
+ functionName: "transfer",
461
+ args: [to, amount],
462
+ account: client.account,
463
+ chain: client.chain
464
+ });
465
+ }
466
+ function approve(client, token, spender, amount) {
467
+ return client.writeContract({
468
+ address: token,
469
+ abi: ERC20_ABI,
470
+ functionName: "approve",
471
+ args: [spender, amount],
472
+ account: client.account,
473
+ chain: client.chain
474
+ });
475
+ }
476
+ var erc20 = {
477
+ balanceOf,
478
+ allowance,
479
+ metadata,
480
+ transfer,
481
+ approve
482
+ };
483
+
484
+ // src/erc721.ts
485
+ function balanceOf2(client, token, owner) {
486
+ return client.readContract({
487
+ address: token,
488
+ abi: ERC721_ABI,
489
+ functionName: "balanceOf",
490
+ args: [owner]
491
+ });
492
+ }
493
+ function ownerOf(client, token, tokenId) {
494
+ return client.readContract({
495
+ address: token,
496
+ abi: ERC721_ABI,
497
+ functionName: "ownerOf",
498
+ args: [tokenId]
499
+ });
500
+ }
501
+ function tokenURI(client, token, tokenId) {
502
+ return client.readContract({
503
+ address: token,
504
+ abi: ERC721_ABI,
505
+ functionName: "tokenURI",
506
+ args: [tokenId]
507
+ });
508
+ }
509
+ function getApproved(client, token, tokenId) {
510
+ return client.readContract({
511
+ address: token,
512
+ abi: ERC721_ABI,
513
+ functionName: "getApproved",
514
+ args: [tokenId]
515
+ });
516
+ }
517
+ function isApprovedForAll(client, token, owner, operator) {
518
+ return client.readContract({
519
+ address: token,
520
+ abi: ERC721_ABI,
521
+ functionName: "isApprovedForAll",
522
+ args: [owner, operator]
523
+ });
524
+ }
525
+ function name(client, token) {
526
+ return client.readContract({
527
+ address: token,
528
+ abi: ERC721_ABI,
529
+ functionName: "name"
530
+ });
531
+ }
532
+ function symbol(client, token) {
533
+ return client.readContract({
534
+ address: token,
535
+ abi: ERC721_ABI,
536
+ functionName: "symbol"
537
+ });
538
+ }
539
+ async function metadata2(client, token) {
540
+ const [n, s] = await Promise.all([name(client, token), symbol(client, token)]);
541
+ return { name: n, symbol: s };
542
+ }
543
+ function approve2(client, token, to, tokenId) {
544
+ return client.writeContract({
545
+ address: token,
546
+ abi: ERC721_ABI,
547
+ functionName: "approve",
548
+ args: [to, tokenId],
549
+ account: client.account,
550
+ chain: client.chain
551
+ });
552
+ }
553
+ function setApprovalForAll(client, token, operator, approved) {
554
+ return client.writeContract({
555
+ address: token,
556
+ abi: ERC721_ABI,
557
+ functionName: "setApprovalForAll",
558
+ args: [operator, approved],
559
+ account: client.account,
560
+ chain: client.chain
561
+ });
562
+ }
563
+ function transferFrom(client, token, from, to, tokenId) {
564
+ return client.writeContract({
565
+ address: token,
566
+ abi: ERC721_ABI,
567
+ functionName: "transferFrom",
568
+ args: [from, to, tokenId],
569
+ account: client.account,
570
+ chain: client.chain
571
+ });
572
+ }
573
+ function safeTransferFrom(client, token, from, to, tokenId, data) {
574
+ if (data !== void 0) {
575
+ return client.writeContract({
576
+ address: token,
577
+ abi: ERC721_ABI,
578
+ functionName: "safeTransferFrom",
579
+ args: [from, to, tokenId, data],
580
+ account: client.account,
581
+ chain: client.chain
582
+ });
583
+ }
584
+ return client.writeContract({
585
+ address: token,
586
+ abi: ERC721_ABI,
587
+ functionName: "safeTransferFrom",
588
+ args: [from, to, tokenId],
589
+ account: client.account,
590
+ chain: client.chain
591
+ });
592
+ }
593
+ var erc721 = {
594
+ balanceOf: balanceOf2,
595
+ ownerOf,
596
+ tokenURI,
597
+ getApproved,
598
+ isApprovedForAll,
599
+ name,
600
+ symbol,
601
+ metadata: metadata2,
602
+ approve: approve2,
603
+ setApprovalForAll,
604
+ transferFrom,
605
+ safeTransferFrom
606
+ };
607
+
608
+ // src/erc1155.ts
609
+ function balanceOf3(client, token, account, id) {
610
+ return client.readContract({
611
+ address: token,
612
+ abi: ERC1155_ABI,
613
+ functionName: "balanceOf",
614
+ args: [account, id]
615
+ });
616
+ }
617
+ function balanceOfBatch(client, token, accounts, ids) {
618
+ return client.readContract({
619
+ address: token,
620
+ abi: ERC1155_ABI,
621
+ functionName: "balanceOfBatch",
622
+ args: [accounts, ids]
623
+ });
624
+ }
625
+ function uri(client, token, id) {
626
+ return client.readContract({
627
+ address: token,
628
+ abi: ERC1155_ABI,
629
+ functionName: "uri",
630
+ args: [id]
631
+ });
632
+ }
633
+ function isApprovedForAll2(client, token, account, operator) {
634
+ return client.readContract({
635
+ address: token,
636
+ abi: ERC1155_ABI,
637
+ functionName: "isApprovedForAll",
638
+ args: [account, operator]
639
+ });
640
+ }
641
+ function setApprovalForAll2(client, token, operator, approved) {
642
+ return client.writeContract({
643
+ address: token,
644
+ abi: ERC1155_ABI,
645
+ functionName: "setApprovalForAll",
646
+ args: [operator, approved],
647
+ account: client.account,
648
+ chain: client.chain
649
+ });
650
+ }
651
+ function safeTransferFrom2(client, token, from, to, id, amount, data = "0x") {
652
+ return client.writeContract({
653
+ address: token,
654
+ abi: ERC1155_ABI,
655
+ functionName: "safeTransferFrom",
656
+ args: [from, to, id, amount, data],
657
+ account: client.account,
658
+ chain: client.chain
659
+ });
660
+ }
661
+ function safeBatchTransferFrom(client, token, from, to, ids, amounts, data = "0x") {
662
+ return client.writeContract({
663
+ address: token,
664
+ abi: ERC1155_ABI,
665
+ functionName: "safeBatchTransferFrom",
666
+ args: [from, to, ids, amounts, data],
667
+ account: client.account,
668
+ chain: client.chain
669
+ });
670
+ }
671
+ var erc1155 = {
672
+ balanceOf: balanceOf3,
673
+ balanceOfBatch,
674
+ uri,
675
+ isApprovedForAll: isApprovedForAll2,
676
+ setApprovalForAll: setApprovalForAll2,
677
+ safeTransferFrom: safeTransferFrom2,
678
+ safeBatchTransferFrom
679
+ };
680
+
681
+ // src/fees.ts
682
+ async function estimateEip1559Fees(client) {
683
+ const { maxFeePerGas, maxPriorityFeePerGas } = await client.estimateFeesPerGas();
684
+ return { maxFeePerGas, maxPriorityFeePerGas };
685
+ }
686
+ function gasPrice(client) {
687
+ return client.getGasPrice();
688
+ }
689
+ var fees = {
690
+ estimateEip1559Fees,
691
+ gasPrice
692
+ };
693
+
694
+ // src/contracts.ts
695
+ function deployContract(client, { abi, bytecode, args }) {
696
+ return client.deployContract({
697
+ abi,
698
+ bytecode,
699
+ args,
700
+ account: client.account,
701
+ chain: client.chain
702
+ });
703
+ }
704
+ function readContract(client, params) {
705
+ return client.readContract(params);
706
+ }
707
+ function writeContract(client, params) {
708
+ const p = params;
709
+ return client.writeContract({
710
+ account: client.account,
711
+ chain: client.chain,
712
+ ...p
713
+ });
714
+ }
715
+ var PRECOMPILE_ADDRESSES = {
716
+ /** CrossVM Bridge precompile. */
717
+ crossVmBridge: "0x0000000000000000000000000000000000000901",
718
+ /** PQC signature verification (`IQorePQC.pqcVerify`). */
719
+ pqcVerify: "0x0000000000000000000000000000000000000A01",
720
+ /** PQC key registration status (`IQorePQC.pqcKeyStatus`). */
721
+ pqcKeyStatus: "0x0000000000000000000000000000000000000A02",
722
+ /** AI transaction risk score (`IQoreAI.aiRiskScore`). */
723
+ aiRiskScore: "0x0000000000000000000000000000000000000B01",
724
+ /** AI anomaly check (`IQoreAI.aiAnomalyCheck`). */
725
+ aiAnomalyCheck: "0x0000000000000000000000000000000000000B02",
726
+ /** Consensus parameters (`IQoreConsensus.rlConsensusParams`). */
727
+ rlConsensusParams: "0x0000000000000000000000000000000000000C01"
728
+ };
729
+ var addr = (a) => viem.getAddress(a);
730
+ function pqcVerify(client, { pubkey, signature, message }) {
731
+ return client.readContract({
732
+ address: addr(PRECOMPILE_ADDRESSES.pqcVerify),
733
+ abi: IQORE_PQC_ABI,
734
+ functionName: "pqcVerify",
735
+ args: [pubkey, signature, message]
736
+ });
737
+ }
738
+ async function pqcKeyStatus(client, account) {
739
+ const [registered, algorithmId, pubkey] = await client.readContract({
740
+ address: addr(PRECOMPILE_ADDRESSES.pqcKeyStatus),
741
+ abi: IQORE_PQC_ABI,
742
+ functionName: "pqcKeyStatus",
743
+ args: [account]
744
+ });
745
+ return { registered, algorithmId, pubkey };
746
+ }
747
+ async function aiRiskScore(client, txData) {
748
+ const [score, level] = await client.readContract({
749
+ address: addr(PRECOMPILE_ADDRESSES.aiRiskScore),
750
+ abi: IQORE_AI_ABI,
751
+ functionName: "aiRiskScore",
752
+ args: [txData]
753
+ });
754
+ return { score, level };
755
+ }
756
+ async function aiAnomalyCheck(client, { sender, amount }) {
757
+ const [anomalyScore, flagged] = await client.readContract({
758
+ address: addr(PRECOMPILE_ADDRESSES.aiAnomalyCheck),
759
+ abi: IQORE_AI_ABI,
760
+ functionName: "aiAnomalyCheck",
761
+ args: [sender, amount]
762
+ });
763
+ return { anomalyScore, flagged };
764
+ }
765
+ async function rlConsensusParams(client) {
766
+ const [blockTime, baseGasPrice, validatorSetSize, epoch] = await client.readContract({
767
+ address: addr(PRECOMPILE_ADDRESSES.rlConsensusParams),
768
+ abi: IQORE_CONSENSUS_ABI,
769
+ functionName: "rlConsensusParams"
770
+ });
771
+ return { blockTime, baseGasPrice, validatorSetSize, epoch };
772
+ }
773
+ var precompiles = {
774
+ pqcVerify,
775
+ pqcKeyStatus,
776
+ aiRiskScore,
777
+ aiAnomalyCheck,
778
+ rlConsensusParams
779
+ };
780
+ function resolveProvider(provider) {
781
+ if (provider) return provider;
782
+ if (typeof window === "undefined") {
783
+ throw new Error(
784
+ "EVM wallet: no browser `window` available. Run in a browser, or pass `provider` explicitly."
785
+ );
786
+ }
787
+ const injected = window.ethereum;
788
+ if (!injected) {
789
+ throw new Error(
790
+ "EVM wallet: no injected EIP-1193 provider found (window.ethereum). Install MetaMask, or pass `provider`."
791
+ );
792
+ }
793
+ return injected;
794
+ }
795
+ function toHexChainId(chainId) {
796
+ return `0x${chainId.toString(16)}`;
797
+ }
798
+ async function requestAccounts(provider) {
799
+ const accounts = await provider.request({
800
+ method: "eth_requestAccounts"
801
+ });
802
+ if (!accounts || accounts.length === 0) {
803
+ throw new Error("EVM wallet: provider returned no accounts");
804
+ }
805
+ return accounts;
806
+ }
807
+ async function addQoreChainNetwork(provider, network, opts = {}) {
808
+ const chainId = opts.chainId ?? Number(await provider.request({ method: "eth_chainId" }));
809
+ await provider.request({
810
+ method: "wallet_addEthereumChain",
811
+ params: [
812
+ {
813
+ chainId: toHexChainId(chainId),
814
+ chainName: network.coin.display === "QOR" ? "QoreChain EVM" : network.coin.display,
815
+ nativeCurrency: {
816
+ name: network.coin.display,
817
+ symbol: network.coin.display,
818
+ decimals: 18
819
+ },
820
+ rpcUrls: [network.endpoints.evmRpc],
821
+ ...opts.blockExplorerUrl ? { blockExplorerUrls: [opts.blockExplorerUrl] } : {}
822
+ }
823
+ ]
824
+ });
825
+ }
826
+ async function switchChain(provider, chainId) {
827
+ await provider.request({
828
+ method: "wallet_switchEthereumChain",
829
+ params: [{ chainId: toHexChainId(chainId) }]
830
+ });
831
+ }
832
+ async function getEvmWalletClient(opts = {}) {
833
+ const provider = resolveProvider(opts.provider);
834
+ const accounts = await requestAccounts(provider);
835
+ const address = accounts[0];
836
+ const chainId = opts.chainId ?? Number(await provider.request({ method: "eth_chainId" }));
837
+ const decimals = opts.decimals ?? 18;
838
+ const chain = viem.defineChain({
839
+ id: chainId,
840
+ name: "QoreChain EVM",
841
+ nativeCurrency: { name: "QOR", symbol: "QOR", decimals },
842
+ rpcUrls: { default: { http: [] } }
843
+ });
844
+ const walletClient = viem.createWalletClient({
845
+ account: address,
846
+ chain,
847
+ transport: viem.custom(provider)
848
+ });
849
+ return { walletClient, address, provider, chain };
850
+ }
851
+ function discoverEvmProviders(timeoutMs = 200) {
852
+ if (typeof window === "undefined") return Promise.resolve([]);
853
+ return new Promise((resolve) => {
854
+ const found = /* @__PURE__ */ new Map();
855
+ const onAnnounce = (event) => {
856
+ const detail = event.detail;
857
+ if (detail?.info?.uuid) found.set(detail.info.uuid, detail);
858
+ };
859
+ window.addEventListener("eip6963:announceProvider", onAnnounce);
860
+ window.dispatchEvent(new Event("eip6963:requestProvider"));
861
+ setTimeout(() => {
862
+ window.removeEventListener(
863
+ "eip6963:announceProvider",
864
+ onAnnounce
865
+ );
866
+ resolve([...found.values()]);
867
+ }, timeoutMs);
868
+ });
869
+ }
870
+ function extractRevertData(err) {
871
+ const e = err;
872
+ const d = e?.data ?? e?.cause?.data;
873
+ if (typeof d === "string" && d.startsWith("0x")) return d;
874
+ if (d && typeof d === "object" && "data" in d) {
875
+ const inner = d.data;
876
+ if (typeof inner === "string" && inner.startsWith("0x")) return inner;
877
+ }
878
+ return void 0;
879
+ }
880
+ function decodeEvmError(error, abi) {
881
+ if (error instanceof viem.BaseError) {
882
+ const revert = error.walk(
883
+ (e) => e instanceof viem.ContractFunctionRevertedError
884
+ );
885
+ if (revert instanceof viem.ContractFunctionRevertedError) {
886
+ const data2 = revert.data;
887
+ if (data2?.errorName === "Error") {
888
+ const reason = data2.args?.[0] ?? revert.reason ?? "reverted";
889
+ return { message: `reverted: ${reason}`, kind: "revert", errorName: "Error" };
890
+ }
891
+ if (data2?.errorName === "Panic") {
892
+ return {
893
+ message: `panic: ${String(data2.args?.[0])}`,
894
+ kind: "panic",
895
+ errorName: "Panic",
896
+ args: data2.args
897
+ };
898
+ }
899
+ if (data2?.errorName) {
900
+ return {
901
+ message: `custom error ${data2.errorName}(${(data2.args ?? []).map((a) => String(a)).join(", ")})`,
902
+ kind: "custom_error",
903
+ errorName: data2.errorName,
904
+ args: data2.args
905
+ };
906
+ }
907
+ if (revert.reason) {
908
+ return { message: `reverted: ${revert.reason}`, kind: "revert" };
909
+ }
910
+ }
911
+ const data = extractRevertData(error);
912
+ if (data && abi) {
913
+ try {
914
+ const decoded = viem.decodeErrorResult({ abi, data });
915
+ return {
916
+ message: `custom error ${decoded.errorName}(${(decoded.args ?? []).map((a) => String(a)).join(", ")})`,
917
+ kind: "custom_error",
918
+ errorName: decoded.errorName,
919
+ args: decoded.args,
920
+ data
921
+ };
922
+ } catch {
923
+ }
924
+ }
925
+ const deepest = error.walk();
926
+ return {
927
+ message: deepest.shortMessage ?? error.shortMessage ?? error.message,
928
+ kind: "execution",
929
+ data
930
+ };
931
+ }
932
+ if (error instanceof Error) {
933
+ return { message: error.message, kind: "rpc" };
934
+ }
935
+ return { message: String(error), kind: "unknown" };
936
+ }
937
+ function resolveTransport(opts) {
938
+ if (opts.transport) return opts.transport;
939
+ const url = opts.wsUrl ?? opts.endpoints?.evmWs;
940
+ if (!url) {
941
+ throw new Error(
942
+ "createEvmSubscriptionClient: provide `wsUrl`, `endpoints.evmWs`, or a `transport`"
943
+ );
944
+ }
945
+ return viem.webSocket(url);
946
+ }
947
+ function createEvmSubscriptionClient(opts) {
948
+ const transport = resolveTransport(opts);
949
+ return viem.createPublicClient({ transport, chain: opts.chain });
950
+ }
951
+ function watchBlocks(client, args) {
952
+ return client.watchBlocks(args);
953
+ }
954
+ function watchEvent(client, args) {
955
+ return client.watchEvent(args);
956
+ }
957
+ function watchContractEvent(client, args) {
958
+ return client.watchContractEvent(args);
959
+ }
960
+ function watchPendingTransactions(client, args) {
961
+ return client.watchPendingTransactions(args);
962
+ }
963
+
964
+ // src/index.ts
965
+ var VERSION = "0.3.0";
966
+
967
+ exports.ERC1155_ABI = ERC1155_ABI;
968
+ exports.ERC20_ABI = ERC20_ABI;
969
+ exports.ERC721_ABI = ERC721_ABI;
970
+ exports.IQORE_AI_ABI = IQORE_AI_ABI;
971
+ exports.IQORE_CONSENSUS_ABI = IQORE_CONSENSUS_ABI;
972
+ exports.IQORE_PQC_ABI = IQORE_PQC_ABI;
973
+ exports.PRECOMPILE_ADDRESSES = PRECOMPILE_ADDRESSES;
974
+ exports.VERSION = VERSION;
975
+ exports.addQoreChainNetwork = addQoreChainNetwork;
976
+ exports.aiAnomalyCheck = aiAnomalyCheck;
977
+ exports.aiRiskScore = aiRiskScore;
978
+ exports.allowance = allowance;
979
+ exports.approve = approve;
980
+ exports.balanceOf = balanceOf;
981
+ exports.createEvmClient = createEvmClient;
982
+ exports.createEvmSubscriptionClient = createEvmSubscriptionClient;
983
+ exports.decodeEvmError = decodeEvmError;
984
+ exports.deployContract = deployContract;
985
+ exports.discoverEvmProviders = discoverEvmProviders;
986
+ exports.erc1155 = erc1155;
987
+ exports.erc20 = erc20;
988
+ exports.erc721 = erc721;
989
+ exports.estimateEip1559Fees = estimateEip1559Fees;
990
+ exports.evmAccountFromPrivateKey = evmAccountFromPrivateKey;
991
+ exports.fees = fees;
992
+ exports.gasPrice = gasPrice;
993
+ exports.getEvmWalletClient = getEvmWalletClient;
994
+ exports.metadata = metadata;
995
+ exports.pqcKeyStatus = pqcKeyStatus;
996
+ exports.pqcVerify = pqcVerify;
997
+ exports.precompiles = precompiles;
998
+ exports.readContract = readContract;
999
+ exports.requestAccounts = requestAccounts;
1000
+ exports.rlConsensusParams = rlConsensusParams;
1001
+ exports.switchChain = switchChain;
1002
+ exports.toHexChainId = toHexChainId;
1003
+ exports.transfer = transfer;
1004
+ exports.watchBlocks = watchBlocks;
1005
+ exports.watchContractEvent = watchContractEvent;
1006
+ exports.watchEvent = watchEvent;
1007
+ exports.watchPendingTransactions = watchPendingTransactions;
1008
+ exports.writeContract = writeContract;
1009
+ //# sourceMappingURL=index.cjs.map
1010
+ //# sourceMappingURL=index.cjs.map