moltspay 0.2.1 → 0.2.2
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/chains/index.d.mts +6 -6
- package/dist/chains/index.d.ts +6 -6
- package/dist/chains/index.js +2 -2
- package/dist/chains/index.js.map +1 -1
- package/dist/chains/index.mjs +2 -2
- package/dist/chains/index.mjs.map +1 -1
- package/dist/cli.js +36 -36
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +36 -36
- package/dist/cli.mjs.map +1 -1
- package/dist/{index-CZzgdtin.d.mts → index-CyFg9s2m.d.mts} +1 -1
- package/dist/{index-CZzgdtin.d.ts → index-CyFg9s2m.d.ts} +1 -1
- package/dist/index.d.mts +26 -26
- package/dist/index.d.ts +26 -26
- package/dist/index.js +69 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -69
- package/dist/index.mjs.map +1 -1
- package/dist/orders/index.d.mts +13 -13
- package/dist/orders/index.d.ts +13 -13
- package/dist/orders/index.js +10 -10
- package/dist/orders/index.js.map +1 -1
- package/dist/orders/index.mjs +10 -10
- package/dist/orders/index.mjs.map +1 -1
- package/dist/permit/index.d.mts +11 -11
- package/dist/permit/index.d.ts +11 -11
- package/dist/permit/index.js +14 -14
- package/dist/permit/index.js.map +1 -1
- package/dist/permit/index.mjs +14 -14
- package/dist/permit/index.mjs.map +1 -1
- package/dist/verify/index.d.mts +4 -4
- package/dist/verify/index.d.ts +4 -4
- package/dist/verify/index.js +13 -13
- package/dist/verify/index.js.map +1 -1
- package/dist/verify/index.mjs +13 -13
- package/dist/verify/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +22 -22
- package/dist/wallet/index.d.ts +22 -22
- package/dist/wallet/index.js +30 -30
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +30 -30
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { ethers } from "ethers";
|
|
|
8
8
|
|
|
9
9
|
// src/chains/index.ts
|
|
10
10
|
var CHAINS = {
|
|
11
|
-
// ============
|
|
11
|
+
// ============ Mainnet ============
|
|
12
12
|
base: {
|
|
13
13
|
name: "Base",
|
|
14
14
|
chainId: 8453,
|
|
@@ -36,7 +36,7 @@ var CHAINS = {
|
|
|
36
36
|
explorerTx: "https://etherscan.io/tx/",
|
|
37
37
|
avgBlockTime: 12
|
|
38
38
|
},
|
|
39
|
-
// ============
|
|
39
|
+
// ============ Testnet ============
|
|
40
40
|
base_sepolia: {
|
|
41
41
|
name: "Base Sepolia",
|
|
42
42
|
chainId: 84532,
|
|
@@ -104,7 +104,7 @@ var PaymentAgent = class _PaymentAgent {
|
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
107
|
+
* Generate payment request(Invoice)
|
|
108
108
|
*/
|
|
109
109
|
createInvoice(params) {
|
|
110
110
|
const expiresMinutes = params.expiresMinutes || 30;
|
|
@@ -131,14 +131,14 @@ var PaymentAgent = class _PaymentAgent {
|
|
|
131
131
|
return invoice;
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
|
-
*
|
|
134
|
+
* Generate wallet deep link(supports MetaMask etc)
|
|
135
135
|
*/
|
|
136
136
|
generateDeepLink(amount, memo) {
|
|
137
137
|
const amountWei = Math.floor(amount * 1e6);
|
|
138
138
|
return `https://metamask.app.link/send/${this.chainConfig.usdc}@${this.chainConfig.chainId}/transfer?address=${this.walletAddress}&uint256=${amountWei}`;
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
*
|
|
141
|
+
* Verify on-chain payment
|
|
142
142
|
*/
|
|
143
143
|
async verifyPayment(txHash, options = {}) {
|
|
144
144
|
try {
|
|
@@ -193,7 +193,7 @@ var PaymentAgent = class _PaymentAgent {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
/**
|
|
196
|
-
*
|
|
196
|
+
* Scan recent transfers (match by amount)
|
|
197
197
|
*/
|
|
198
198
|
async scanRecentTransfers(expectedAmount, timeoutMinutes = 30) {
|
|
199
199
|
try {
|
|
@@ -231,7 +231,7 @@ var PaymentAgent = class _PaymentAgent {
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
/**
|
|
234
|
-
*
|
|
234
|
+
* Get wallet balance
|
|
235
235
|
*/
|
|
236
236
|
async getBalance(address) {
|
|
237
237
|
const addr = address || this.walletAddress;
|
|
@@ -247,7 +247,7 @@ var PaymentAgent = class _PaymentAgent {
|
|
|
247
247
|
};
|
|
248
248
|
}
|
|
249
249
|
/**
|
|
250
|
-
*
|
|
250
|
+
* Format Invoice as human-readable message
|
|
251
251
|
*/
|
|
252
252
|
formatInvoiceMessage(invoice, includeJson = true) {
|
|
253
253
|
let msg = `\u{1F3AC} **Payment Request**
|
|
@@ -309,7 +309,7 @@ var Wallet = class {
|
|
|
309
309
|
);
|
|
310
310
|
}
|
|
311
311
|
/**
|
|
312
|
-
*
|
|
312
|
+
* Get wallet balance
|
|
313
313
|
*/
|
|
314
314
|
async getBalance() {
|
|
315
315
|
const [ethBalance, usdcBalance] = await Promise.all([
|
|
@@ -324,7 +324,7 @@ var Wallet = class {
|
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
326
|
/**
|
|
327
|
-
*
|
|
327
|
+
* Send USDC transfer
|
|
328
328
|
*/
|
|
329
329
|
async transfer(to, amount) {
|
|
330
330
|
try {
|
|
@@ -365,14 +365,14 @@ var Wallet = class {
|
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
/**
|
|
368
|
-
*
|
|
368
|
+
* Get ETH balance
|
|
369
369
|
*/
|
|
370
370
|
async getEthBalance() {
|
|
371
371
|
const balance = await this.provider.getBalance(this.address);
|
|
372
372
|
return ethers2.formatEther(balance);
|
|
373
373
|
}
|
|
374
374
|
/**
|
|
375
|
-
*
|
|
375
|
+
* Get USDC balance
|
|
376
376
|
*/
|
|
377
377
|
async getUsdcBalance() {
|
|
378
378
|
const balance = await this.usdcContract.balanceOf(this.address);
|
|
@@ -393,7 +393,7 @@ var AuditLog = class {
|
|
|
393
393
|
this.loadLastHash();
|
|
394
394
|
}
|
|
395
395
|
/**
|
|
396
|
-
*
|
|
396
|
+
* Record audit log
|
|
397
397
|
*/
|
|
398
398
|
async log(params) {
|
|
399
399
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -410,7 +410,7 @@ var AuditLog = class {
|
|
|
410
410
|
requester: params.requester,
|
|
411
411
|
prev_hash: this.lastHash,
|
|
412
412
|
hash: "",
|
|
413
|
-
//
|
|
413
|
+
// Filled after calculation
|
|
414
414
|
metadata: params.metadata
|
|
415
415
|
};
|
|
416
416
|
entry.hash = this.calculateHash(entry);
|
|
@@ -421,7 +421,7 @@ var AuditLog = class {
|
|
|
421
421
|
return entry;
|
|
422
422
|
}
|
|
423
423
|
/**
|
|
424
|
-
*
|
|
424
|
+
* Read logs for specified date
|
|
425
425
|
*/
|
|
426
426
|
read(date) {
|
|
427
427
|
const filePath = this.getFilePath(date || /* @__PURE__ */ new Date());
|
|
@@ -433,7 +433,7 @@ var AuditLog = class {
|
|
|
433
433
|
return lines.map((line) => JSON.parse(line));
|
|
434
434
|
}
|
|
435
435
|
/**
|
|
436
|
-
*
|
|
436
|
+
* Verify log integrity
|
|
437
437
|
*/
|
|
438
438
|
verify(date) {
|
|
439
439
|
const entries = this.read(date);
|
|
@@ -451,7 +451,7 @@ var AuditLog = class {
|
|
|
451
451
|
return { valid: errors.length === 0, errors };
|
|
452
452
|
}
|
|
453
453
|
/**
|
|
454
|
-
*
|
|
454
|
+
* Search logs
|
|
455
455
|
*/
|
|
456
456
|
search(filter) {
|
|
457
457
|
const results = [];
|
|
@@ -475,14 +475,14 @@ var AuditLog = class {
|
|
|
475
475
|
return results;
|
|
476
476
|
}
|
|
477
477
|
/**
|
|
478
|
-
*
|
|
478
|
+
* Get log file path
|
|
479
479
|
*/
|
|
480
480
|
getFilePath(date) {
|
|
481
481
|
const dateStr = date.toISOString().slice(0, 10);
|
|
482
482
|
return path.join(this.basePath, `audit_${dateStr}.jsonl`);
|
|
483
483
|
}
|
|
484
484
|
/**
|
|
485
|
-
*
|
|
485
|
+
* Calculate entry hash
|
|
486
486
|
*/
|
|
487
487
|
calculateHash(entry) {
|
|
488
488
|
const data = {
|
|
@@ -499,7 +499,7 @@ var AuditLog = class {
|
|
|
499
499
|
return crypto.createHash("sha256").update(str).digest("hex").slice(0, 16);
|
|
500
500
|
}
|
|
501
501
|
/**
|
|
502
|
-
*
|
|
502
|
+
* Load last log entry hash
|
|
503
503
|
*/
|
|
504
504
|
loadLastHash() {
|
|
505
505
|
const today = /* @__PURE__ */ new Date();
|
|
@@ -514,7 +514,7 @@ var AuditLog = class {
|
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
516
|
/**
|
|
517
|
-
*
|
|
517
|
+
* Ensure directory exists
|
|
518
518
|
*/
|
|
519
519
|
ensureDir() {
|
|
520
520
|
if (!fs.existsSync(this.basePath)) {
|
|
@@ -526,9 +526,9 @@ var AuditLog = class {
|
|
|
526
526
|
// src/wallet/SecureWallet.ts
|
|
527
527
|
var DEFAULT_LIMITS = {
|
|
528
528
|
singleMax: 100,
|
|
529
|
-
//
|
|
529
|
+
// Single max $100
|
|
530
530
|
dailyMax: 1e3,
|
|
531
|
-
//
|
|
531
|
+
// Daily max $1000
|
|
532
532
|
requireWhitelist: true
|
|
533
533
|
};
|
|
534
534
|
var SecureWallet = class {
|
|
@@ -549,21 +549,21 @@ var SecureWallet = class {
|
|
|
549
549
|
this.auditLog = new AuditLog(config.auditPath);
|
|
550
550
|
}
|
|
551
551
|
/**
|
|
552
|
-
*
|
|
552
|
+
* Get wallet address
|
|
553
553
|
*/
|
|
554
554
|
get address() {
|
|
555
555
|
return this.wallet.address;
|
|
556
556
|
}
|
|
557
557
|
/**
|
|
558
|
-
*
|
|
558
|
+
* Get balance
|
|
559
559
|
*/
|
|
560
560
|
async getBalance() {
|
|
561
561
|
return this.wallet.getBalance();
|
|
562
562
|
}
|
|
563
563
|
/**
|
|
564
|
-
*
|
|
564
|
+
* Secure transfer (with limit and whitelist checks)
|
|
565
565
|
*
|
|
566
|
-
*
|
|
566
|
+
* Supports two calling methods:
|
|
567
567
|
* - transfer({ to, amount, reason?, requester? })
|
|
568
568
|
* - transfer(to, amount)
|
|
569
569
|
*/
|
|
@@ -663,7 +663,7 @@ var SecureWallet = class {
|
|
|
663
663
|
return result;
|
|
664
664
|
}
|
|
665
665
|
/**
|
|
666
|
-
*
|
|
666
|
+
* Approve pending transfer
|
|
667
667
|
*/
|
|
668
668
|
async approve(requestId, approver) {
|
|
669
669
|
const pending = this.pendingTransfers.get(requestId);
|
|
@@ -704,7 +704,7 @@ var SecureWallet = class {
|
|
|
704
704
|
return result;
|
|
705
705
|
}
|
|
706
706
|
/**
|
|
707
|
-
*
|
|
707
|
+
* Reject pending transfer
|
|
708
708
|
*/
|
|
709
709
|
async reject(requestId, rejecter, reason) {
|
|
710
710
|
const pending = this.pendingTransfers.get(requestId);
|
|
@@ -719,7 +719,7 @@ var SecureWallet = class {
|
|
|
719
719
|
});
|
|
720
720
|
}
|
|
721
721
|
/**
|
|
722
|
-
*
|
|
722
|
+
* Add to whitelist
|
|
723
723
|
*/
|
|
724
724
|
async addToWhitelist(address, addedBy) {
|
|
725
725
|
const addr = address.toLowerCase();
|
|
@@ -732,7 +732,7 @@ var SecureWallet = class {
|
|
|
732
732
|
});
|
|
733
733
|
}
|
|
734
734
|
/**
|
|
735
|
-
*
|
|
735
|
+
* Remove from whitelist
|
|
736
736
|
*/
|
|
737
737
|
async removeFromWhitelist(address, removedBy) {
|
|
738
738
|
const addr = address.toLowerCase();
|
|
@@ -745,32 +745,32 @@ var SecureWallet = class {
|
|
|
745
745
|
});
|
|
746
746
|
}
|
|
747
747
|
/**
|
|
748
|
-
*
|
|
748
|
+
* Check if address is whitelisted
|
|
749
749
|
*/
|
|
750
750
|
isWhitelisted(address) {
|
|
751
751
|
return this.whitelist.has(address.toLowerCase());
|
|
752
752
|
}
|
|
753
753
|
/**
|
|
754
|
-
*
|
|
754
|
+
* Get pending transfers list
|
|
755
755
|
*/
|
|
756
756
|
getPendingTransfers() {
|
|
757
757
|
return Array.from(this.pendingTransfers.values()).filter((p) => p.status === "pending");
|
|
758
758
|
}
|
|
759
759
|
/**
|
|
760
|
-
*
|
|
760
|
+
* Get current limit config
|
|
761
761
|
*/
|
|
762
762
|
getLimits() {
|
|
763
763
|
return { ...this.limits };
|
|
764
764
|
}
|
|
765
765
|
/**
|
|
766
|
-
*
|
|
766
|
+
* Get daily used amount
|
|
767
767
|
*/
|
|
768
768
|
getDailyUsed() {
|
|
769
769
|
this.updateDailyTotal();
|
|
770
770
|
return this.dailyTotal;
|
|
771
771
|
}
|
|
772
772
|
/**
|
|
773
|
-
*
|
|
773
|
+
* Update daily limit counter
|
|
774
774
|
*/
|
|
775
775
|
updateDailyTotal() {
|
|
776
776
|
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|