moltspay 0.2.0 → 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/guide/index.d.mts +7 -7
- package/dist/guide/index.d.ts +7 -7
- package/dist/guide/index.js +50 -50
- package/dist/guide/index.js.map +1 -1
- package/dist/guide/index.mjs +50 -50
- package/dist/guide/index.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 +89 -89
- package/dist/index.d.ts +89 -89
- package/dist/index.js +275 -275
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +275 -275
- 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 +72 -72
- package/dist/wallet/index.d.ts +72 -72
- package/dist/wallet/index.js +48 -48
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +48 -48
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/chains/index.d.mts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { C as ChainName, a as ChainConfig } from '../index-
|
|
1
|
+
import { C as ChainName, a as ChainConfig } from '../index-CyFg9s2m.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Blockchain Configuration
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
declare const CHAINS: Record<ChainName, ChainConfig>;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Get chain configuration
|
|
10
10
|
*/
|
|
11
11
|
declare function getChain(name: ChainName): ChainConfig;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* List all supported chains
|
|
14
14
|
*/
|
|
15
15
|
declare function listChains(): ChainName[];
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Get chain config by chainId
|
|
18
18
|
*/
|
|
19
19
|
declare function getChainById(chainId: number): ChainConfig | undefined;
|
|
20
20
|
/**
|
|
21
|
-
* ERC20 ABI
|
|
21
|
+
* ERC20 ABI (minimal, only required methods)
|
|
22
22
|
*/
|
|
23
23
|
declare const ERC20_ABI: string[];
|
|
24
24
|
|
package/dist/chains/index.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { C as ChainName, a as ChainConfig } from '../index-
|
|
1
|
+
import { C as ChainName, a as ChainConfig } from '../index-CyFg9s2m.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Blockchain Configuration
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
declare const CHAINS: Record<ChainName, ChainConfig>;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Get chain configuration
|
|
10
10
|
*/
|
|
11
11
|
declare function getChain(name: ChainName): ChainConfig;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* List all supported chains
|
|
14
14
|
*/
|
|
15
15
|
declare function listChains(): ChainName[];
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Get chain config by chainId
|
|
18
18
|
*/
|
|
19
19
|
declare function getChainById(chainId: number): ChainConfig | undefined;
|
|
20
20
|
/**
|
|
21
|
-
* ERC20 ABI
|
|
21
|
+
* ERC20 ABI (minimal, only required methods)
|
|
22
22
|
*/
|
|
23
23
|
declare const ERC20_ABI: string[];
|
|
24
24
|
|
package/dist/chains/index.js
CHANGED
|
@@ -28,7 +28,7 @@ __export(chains_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(chains_exports);
|
|
30
30
|
var CHAINS = {
|
|
31
|
-
// ============
|
|
31
|
+
// ============ Mainnet ============
|
|
32
32
|
base: {
|
|
33
33
|
name: "Base",
|
|
34
34
|
chainId: 8453,
|
|
@@ -56,7 +56,7 @@ var CHAINS = {
|
|
|
56
56
|
explorerTx: "https://etherscan.io/tx/",
|
|
57
57
|
avgBlockTime: 12
|
|
58
58
|
},
|
|
59
|
-
// ============
|
|
59
|
+
// ============ Testnet ============
|
|
60
60
|
base_sepolia: {
|
|
61
61
|
name: "Base Sepolia",
|
|
62
62
|
chainId: 84532,
|
package/dist/chains/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/chains/index.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"sources":["../../src/chains/index.ts"],"sourcesContent":["/**\n * Blockchain Configuration\n */\n\nimport type { ChainConfig, ChainName } from '../types/index.js';\n\nexport const CHAINS: Record<ChainName, ChainConfig> = {\n // ============ Mainnet ============\n base: {\n name: 'Base',\n chainId: 8453,\n rpc: 'https://mainnet.base.org',\n usdc: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n explorer: 'https://basescan.org/address/',\n explorerTx: 'https://basescan.org/tx/',\n avgBlockTime: 2,\n },\n polygon: {\n name: 'Polygon',\n chainId: 137,\n rpc: 'https://polygon-rpc.com',\n usdc: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',\n explorer: 'https://polygonscan.com/address/',\n explorerTx: 'https://polygonscan.com/tx/',\n avgBlockTime: 2,\n },\n ethereum: {\n name: 'Ethereum',\n chainId: 1,\n rpc: 'https://eth.llamarpc.com',\n usdc: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n explorer: 'https://etherscan.io/address/',\n explorerTx: 'https://etherscan.io/tx/',\n avgBlockTime: 12,\n },\n\n // ============ Testnet ============\n base_sepolia: {\n name: 'Base Sepolia',\n chainId: 84532,\n rpc: 'https://sepolia.base.org',\n usdc: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',\n explorer: 'https://sepolia.basescan.org/address/',\n explorerTx: 'https://sepolia.basescan.org/tx/',\n avgBlockTime: 2,\n },\n sepolia: {\n name: 'Sepolia',\n chainId: 11155111,\n rpc: 'https://rpc.sepolia.org',\n usdc: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',\n explorer: 'https://sepolia.etherscan.io/address/',\n explorerTx: 'https://sepolia.etherscan.io/tx/',\n avgBlockTime: 12,\n },\n};\n\n/**\n * Get chain configuration\n */\nexport function getChain(name: ChainName): ChainConfig {\n const config = CHAINS[name];\n if (!config) {\n throw new Error(`Unsupported chain: ${name}. Supported: ${Object.keys(CHAINS).join(', ')}`);\n }\n return config;\n}\n\n/**\n * List all supported chains\n */\nexport function listChains(): ChainName[] {\n return Object.keys(CHAINS) as ChainName[];\n}\n\n/**\n * Get chain config by chainId\n */\nexport function getChainById(chainId: number): ChainConfig | undefined {\n return Object.values(CHAINS).find(c => c.chainId === chainId);\n}\n\n/**\n * ERC20 ABI (minimal, only required methods)\n */\nexport const ERC20_ABI = [\n 'function balanceOf(address owner) view returns (uint256)',\n 'function transfer(address to, uint256 amount) returns (bool)',\n 'function approve(address spender, uint256 amount) returns (bool)',\n 'function allowance(address owner, address spender) view returns (uint256)',\n 'function decimals() view returns (uint8)',\n 'function symbol() view returns (string)',\n 'function name() view returns (string)',\n 'function nonces(address owner) view returns (uint256)',\n 'function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)',\n 'event Transfer(address indexed from, address indexed to, uint256 value)',\n 'event Approval(address indexed owner, address indexed spender, uint256 value)',\n];\n\nexport type { ChainConfig, ChainName };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,IAAM,SAAyC;AAAA;AAAA,EAEpD,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB;AAAA,EACA,SAAS;AAAA,IACP,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB;AAAA;AAAA,EAGA,cAAc;AAAA,IACZ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB;AAAA,EACA,SAAS;AAAA,IACP,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB;AACF;AAKO,SAAS,SAAS,MAA8B;AACrD,QAAM,SAAS,OAAO,IAAI;AAC1B,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,sBAAsB,IAAI,gBAAgB,OAAO,KAAK,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE;AAAA,EAC5F;AACA,SAAO;AACT;AAKO,SAAS,aAA0B;AACxC,SAAO,OAAO,KAAK,MAAM;AAC3B;AAKO,SAAS,aAAa,SAA0C;AACrE,SAAO,OAAO,OAAO,MAAM,EAAE,KAAK,OAAK,EAAE,YAAY,OAAO;AAC9D;AAKO,IAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
package/dist/chains/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/chains/index.ts
|
|
2
2
|
var CHAINS = {
|
|
3
|
-
// ============
|
|
3
|
+
// ============ Mainnet ============
|
|
4
4
|
base: {
|
|
5
5
|
name: "Base",
|
|
6
6
|
chainId: 8453,
|
|
@@ -28,7 +28,7 @@ var CHAINS = {
|
|
|
28
28
|
explorerTx: "https://etherscan.io/tx/",
|
|
29
29
|
avgBlockTime: 12
|
|
30
30
|
},
|
|
31
|
-
// ============
|
|
31
|
+
// ============ Testnet ============
|
|
32
32
|
base_sepolia: {
|
|
33
33
|
name: "Base Sepolia",
|
|
34
34
|
chainId: 84532,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/chains/index.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"sources":["../../src/chains/index.ts"],"sourcesContent":["/**\n * Blockchain Configuration\n */\n\nimport type { ChainConfig, ChainName } from '../types/index.js';\n\nexport const CHAINS: Record<ChainName, ChainConfig> = {\n // ============ Mainnet ============\n base: {\n name: 'Base',\n chainId: 8453,\n rpc: 'https://mainnet.base.org',\n usdc: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n explorer: 'https://basescan.org/address/',\n explorerTx: 'https://basescan.org/tx/',\n avgBlockTime: 2,\n },\n polygon: {\n name: 'Polygon',\n chainId: 137,\n rpc: 'https://polygon-rpc.com',\n usdc: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',\n explorer: 'https://polygonscan.com/address/',\n explorerTx: 'https://polygonscan.com/tx/',\n avgBlockTime: 2,\n },\n ethereum: {\n name: 'Ethereum',\n chainId: 1,\n rpc: 'https://eth.llamarpc.com',\n usdc: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n explorer: 'https://etherscan.io/address/',\n explorerTx: 'https://etherscan.io/tx/',\n avgBlockTime: 12,\n },\n\n // ============ Testnet ============\n base_sepolia: {\n name: 'Base Sepolia',\n chainId: 84532,\n rpc: 'https://sepolia.base.org',\n usdc: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',\n explorer: 'https://sepolia.basescan.org/address/',\n explorerTx: 'https://sepolia.basescan.org/tx/',\n avgBlockTime: 2,\n },\n sepolia: {\n name: 'Sepolia',\n chainId: 11155111,\n rpc: 'https://rpc.sepolia.org',\n usdc: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',\n explorer: 'https://sepolia.etherscan.io/address/',\n explorerTx: 'https://sepolia.etherscan.io/tx/',\n avgBlockTime: 12,\n },\n};\n\n/**\n * Get chain configuration\n */\nexport function getChain(name: ChainName): ChainConfig {\n const config = CHAINS[name];\n if (!config) {\n throw new Error(`Unsupported chain: ${name}. Supported: ${Object.keys(CHAINS).join(', ')}`);\n }\n return config;\n}\n\n/**\n * List all supported chains\n */\nexport function listChains(): ChainName[] {\n return Object.keys(CHAINS) as ChainName[];\n}\n\n/**\n * Get chain config by chainId\n */\nexport function getChainById(chainId: number): ChainConfig | undefined {\n return Object.values(CHAINS).find(c => c.chainId === chainId);\n}\n\n/**\n * ERC20 ABI (minimal, only required methods)\n */\nexport const ERC20_ABI = [\n 'function balanceOf(address owner) view returns (uint256)',\n 'function transfer(address to, uint256 amount) returns (bool)',\n 'function approve(address spender, uint256 amount) returns (bool)',\n 'function allowance(address owner, address spender) view returns (uint256)',\n 'function decimals() view returns (uint8)',\n 'function symbol() view returns (string)',\n 'function name() view returns (string)',\n 'function nonces(address owner) view returns (uint256)',\n 'function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)',\n 'event Transfer(address indexed from, address indexed to, uint256 value)',\n 'event Approval(address indexed owner, address indexed spender, uint256 value)',\n];\n\nexport type { ChainConfig, ChainName };\n"],"mappings":";AAMO,IAAM,SAAyC;AAAA;AAAA,EAEpD,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB;AAAA,EACA,SAAS;AAAA,IACP,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB;AAAA;AAAA,EAGA,cAAc;AAAA,IACZ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB;AAAA,EACA,SAAS;AAAA,IACP,MAAM;AAAA,IACN,SAAS;AAAA,IACT,KAAK;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB;AACF;AAKO,SAAS,SAAS,MAA8B;AACrD,QAAM,SAAS,OAAO,IAAI;AAC1B,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,sBAAsB,IAAI,gBAAgB,OAAO,KAAK,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE;AAAA,EAC5F;AACA,SAAO;AACT;AAKO,SAAS,aAA0B;AACxC,SAAO,OAAO,KAAK,MAAM;AAC3B;AAKO,SAAS,aAAa,SAA0C;AACrE,SAAO,OAAO,OAAO,MAAM,EAAE,KAAK,OAAK,EAAE,YAAY,OAAO;AAC9D;AAKO,IAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
package/dist/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_ethers = require("ethers");
|
|
|
31
31
|
|
|
32
32
|
// src/chains/index.ts
|
|
33
33
|
var CHAINS = {
|
|
34
|
-
// ============
|
|
34
|
+
// ============ Mainnet ============
|
|
35
35
|
base: {
|
|
36
36
|
name: "Base",
|
|
37
37
|
chainId: 8453,
|
|
@@ -59,7 +59,7 @@ var CHAINS = {
|
|
|
59
59
|
explorerTx: "https://etherscan.io/tx/",
|
|
60
60
|
avgBlockTime: 12
|
|
61
61
|
},
|
|
62
|
-
// ============
|
|
62
|
+
// ============ Testnet ============
|
|
63
63
|
base_sepolia: {
|
|
64
64
|
name: "Base Sepolia",
|
|
65
65
|
chainId: 84532,
|
|
@@ -127,7 +127,7 @@ var PaymentAgent = class _PaymentAgent {
|
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
|
-
*
|
|
130
|
+
* Generate payment request(Invoice)
|
|
131
131
|
*/
|
|
132
132
|
createInvoice(params) {
|
|
133
133
|
const expiresMinutes = params.expiresMinutes || 30;
|
|
@@ -154,14 +154,14 @@ var PaymentAgent = class _PaymentAgent {
|
|
|
154
154
|
return invoice;
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
157
|
+
* Generate wallet deep link(supports MetaMask etc)
|
|
158
158
|
*/
|
|
159
159
|
generateDeepLink(amount, memo) {
|
|
160
160
|
const amountWei = Math.floor(amount * 1e6);
|
|
161
161
|
return `https://metamask.app.link/send/${this.chainConfig.usdc}@${this.chainConfig.chainId}/transfer?address=${this.walletAddress}&uint256=${amountWei}`;
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
164
|
+
* Verify on-chain payment
|
|
165
165
|
*/
|
|
166
166
|
async verifyPayment(txHash, options = {}) {
|
|
167
167
|
try {
|
|
@@ -216,7 +216,7 @@ var PaymentAgent = class _PaymentAgent {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
|
-
*
|
|
219
|
+
* Scan recent transfers (match by amount)
|
|
220
220
|
*/
|
|
221
221
|
async scanRecentTransfers(expectedAmount, timeoutMinutes = 30) {
|
|
222
222
|
try {
|
|
@@ -254,7 +254,7 @@ var PaymentAgent = class _PaymentAgent {
|
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
/**
|
|
257
|
-
*
|
|
257
|
+
* Get wallet balance
|
|
258
258
|
*/
|
|
259
259
|
async getBalance(address) {
|
|
260
260
|
const addr = address || this.walletAddress;
|
|
@@ -270,7 +270,7 @@ var PaymentAgent = class _PaymentAgent {
|
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
|
-
*
|
|
273
|
+
* Format Invoice as human-readable message
|
|
274
274
|
*/
|
|
275
275
|
formatInvoiceMessage(invoice, includeJson = true) {
|
|
276
276
|
let msg = `\u{1F3AC} **Payment Request**
|
|
@@ -332,7 +332,7 @@ var Wallet = class {
|
|
|
332
332
|
);
|
|
333
333
|
}
|
|
334
334
|
/**
|
|
335
|
-
*
|
|
335
|
+
* Get wallet balance
|
|
336
336
|
*/
|
|
337
337
|
async getBalance() {
|
|
338
338
|
const [ethBalance, usdcBalance] = await Promise.all([
|
|
@@ -347,7 +347,7 @@ var Wallet = class {
|
|
|
347
347
|
};
|
|
348
348
|
}
|
|
349
349
|
/**
|
|
350
|
-
*
|
|
350
|
+
* Send USDC transfer
|
|
351
351
|
*/
|
|
352
352
|
async transfer(to, amount) {
|
|
353
353
|
try {
|
|
@@ -388,14 +388,14 @@ var Wallet = class {
|
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
/**
|
|
391
|
-
*
|
|
391
|
+
* Get ETH balance
|
|
392
392
|
*/
|
|
393
393
|
async getEthBalance() {
|
|
394
394
|
const balance = await this.provider.getBalance(this.address);
|
|
395
395
|
return import_ethers2.ethers.formatEther(balance);
|
|
396
396
|
}
|
|
397
397
|
/**
|
|
398
|
-
*
|
|
398
|
+
* Get USDC balance
|
|
399
399
|
*/
|
|
400
400
|
async getUsdcBalance() {
|
|
401
401
|
const balance = await this.usdcContract.balanceOf(this.address);
|
|
@@ -416,7 +416,7 @@ var AuditLog = class {
|
|
|
416
416
|
this.loadLastHash();
|
|
417
417
|
}
|
|
418
418
|
/**
|
|
419
|
-
*
|
|
419
|
+
* Record audit log
|
|
420
420
|
*/
|
|
421
421
|
async log(params) {
|
|
422
422
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -433,7 +433,7 @@ var AuditLog = class {
|
|
|
433
433
|
requester: params.requester,
|
|
434
434
|
prev_hash: this.lastHash,
|
|
435
435
|
hash: "",
|
|
436
|
-
//
|
|
436
|
+
// Filled after calculation
|
|
437
437
|
metadata: params.metadata
|
|
438
438
|
};
|
|
439
439
|
entry.hash = this.calculateHash(entry);
|
|
@@ -444,7 +444,7 @@ var AuditLog = class {
|
|
|
444
444
|
return entry;
|
|
445
445
|
}
|
|
446
446
|
/**
|
|
447
|
-
*
|
|
447
|
+
* Read logs for specified date
|
|
448
448
|
*/
|
|
449
449
|
read(date) {
|
|
450
450
|
const filePath = this.getFilePath(date || /* @__PURE__ */ new Date());
|
|
@@ -456,7 +456,7 @@ var AuditLog = class {
|
|
|
456
456
|
return lines.map((line) => JSON.parse(line));
|
|
457
457
|
}
|
|
458
458
|
/**
|
|
459
|
-
*
|
|
459
|
+
* Verify log integrity
|
|
460
460
|
*/
|
|
461
461
|
verify(date) {
|
|
462
462
|
const entries = this.read(date);
|
|
@@ -474,7 +474,7 @@ var AuditLog = class {
|
|
|
474
474
|
return { valid: errors.length === 0, errors };
|
|
475
475
|
}
|
|
476
476
|
/**
|
|
477
|
-
*
|
|
477
|
+
* Search logs
|
|
478
478
|
*/
|
|
479
479
|
search(filter) {
|
|
480
480
|
const results = [];
|
|
@@ -498,14 +498,14 @@ var AuditLog = class {
|
|
|
498
498
|
return results;
|
|
499
499
|
}
|
|
500
500
|
/**
|
|
501
|
-
*
|
|
501
|
+
* Get log file path
|
|
502
502
|
*/
|
|
503
503
|
getFilePath(date) {
|
|
504
504
|
const dateStr = date.toISOString().slice(0, 10);
|
|
505
505
|
return path.join(this.basePath, `audit_${dateStr}.jsonl`);
|
|
506
506
|
}
|
|
507
507
|
/**
|
|
508
|
-
*
|
|
508
|
+
* Calculate entry hash
|
|
509
509
|
*/
|
|
510
510
|
calculateHash(entry) {
|
|
511
511
|
const data = {
|
|
@@ -522,7 +522,7 @@ var AuditLog = class {
|
|
|
522
522
|
return crypto.createHash("sha256").update(str).digest("hex").slice(0, 16);
|
|
523
523
|
}
|
|
524
524
|
/**
|
|
525
|
-
*
|
|
525
|
+
* Load last log entry hash
|
|
526
526
|
*/
|
|
527
527
|
loadLastHash() {
|
|
528
528
|
const today = /* @__PURE__ */ new Date();
|
|
@@ -537,7 +537,7 @@ var AuditLog = class {
|
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
/**
|
|
540
|
-
*
|
|
540
|
+
* Ensure directory exists
|
|
541
541
|
*/
|
|
542
542
|
ensureDir() {
|
|
543
543
|
if (!fs.existsSync(this.basePath)) {
|
|
@@ -549,9 +549,9 @@ var AuditLog = class {
|
|
|
549
549
|
// src/wallet/SecureWallet.ts
|
|
550
550
|
var DEFAULT_LIMITS = {
|
|
551
551
|
singleMax: 100,
|
|
552
|
-
//
|
|
552
|
+
// Single max $100
|
|
553
553
|
dailyMax: 1e3,
|
|
554
|
-
//
|
|
554
|
+
// Daily max $1000
|
|
555
555
|
requireWhitelist: true
|
|
556
556
|
};
|
|
557
557
|
var SecureWallet = class {
|
|
@@ -572,21 +572,21 @@ var SecureWallet = class {
|
|
|
572
572
|
this.auditLog = new AuditLog(config.auditPath);
|
|
573
573
|
}
|
|
574
574
|
/**
|
|
575
|
-
*
|
|
575
|
+
* Get wallet address
|
|
576
576
|
*/
|
|
577
577
|
get address() {
|
|
578
578
|
return this.wallet.address;
|
|
579
579
|
}
|
|
580
580
|
/**
|
|
581
|
-
*
|
|
581
|
+
* Get balance
|
|
582
582
|
*/
|
|
583
583
|
async getBalance() {
|
|
584
584
|
return this.wallet.getBalance();
|
|
585
585
|
}
|
|
586
586
|
/**
|
|
587
|
-
*
|
|
587
|
+
* Secure transfer (with limit and whitelist checks)
|
|
588
588
|
*
|
|
589
|
-
*
|
|
589
|
+
* Supports two calling methods:
|
|
590
590
|
* - transfer({ to, amount, reason?, requester? })
|
|
591
591
|
* - transfer(to, amount)
|
|
592
592
|
*/
|
|
@@ -686,7 +686,7 @@ var SecureWallet = class {
|
|
|
686
686
|
return result;
|
|
687
687
|
}
|
|
688
688
|
/**
|
|
689
|
-
*
|
|
689
|
+
* Approve pending transfer
|
|
690
690
|
*/
|
|
691
691
|
async approve(requestId, approver) {
|
|
692
692
|
const pending = this.pendingTransfers.get(requestId);
|
|
@@ -727,7 +727,7 @@ var SecureWallet = class {
|
|
|
727
727
|
return result;
|
|
728
728
|
}
|
|
729
729
|
/**
|
|
730
|
-
*
|
|
730
|
+
* Reject pending transfer
|
|
731
731
|
*/
|
|
732
732
|
async reject(requestId, rejecter, reason) {
|
|
733
733
|
const pending = this.pendingTransfers.get(requestId);
|
|
@@ -742,7 +742,7 @@ var SecureWallet = class {
|
|
|
742
742
|
});
|
|
743
743
|
}
|
|
744
744
|
/**
|
|
745
|
-
*
|
|
745
|
+
* Add to whitelist
|
|
746
746
|
*/
|
|
747
747
|
async addToWhitelist(address, addedBy) {
|
|
748
748
|
const addr = address.toLowerCase();
|
|
@@ -755,7 +755,7 @@ var SecureWallet = class {
|
|
|
755
755
|
});
|
|
756
756
|
}
|
|
757
757
|
/**
|
|
758
|
-
*
|
|
758
|
+
* Remove from whitelist
|
|
759
759
|
*/
|
|
760
760
|
async removeFromWhitelist(address, removedBy) {
|
|
761
761
|
const addr = address.toLowerCase();
|
|
@@ -768,32 +768,32 @@ var SecureWallet = class {
|
|
|
768
768
|
});
|
|
769
769
|
}
|
|
770
770
|
/**
|
|
771
|
-
*
|
|
771
|
+
* Check if address is whitelisted
|
|
772
772
|
*/
|
|
773
773
|
isWhitelisted(address) {
|
|
774
774
|
return this.whitelist.has(address.toLowerCase());
|
|
775
775
|
}
|
|
776
776
|
/**
|
|
777
|
-
*
|
|
777
|
+
* Get pending transfers list
|
|
778
778
|
*/
|
|
779
779
|
getPendingTransfers() {
|
|
780
780
|
return Array.from(this.pendingTransfers.values()).filter((p) => p.status === "pending");
|
|
781
781
|
}
|
|
782
782
|
/**
|
|
783
|
-
*
|
|
783
|
+
* Get current limit config
|
|
784
784
|
*/
|
|
785
785
|
getLimits() {
|
|
786
786
|
return { ...this.limits };
|
|
787
787
|
}
|
|
788
788
|
/**
|
|
789
|
-
*
|
|
789
|
+
* Get daily used amount
|
|
790
790
|
*/
|
|
791
791
|
getDailyUsed() {
|
|
792
792
|
this.updateDailyTotal();
|
|
793
793
|
return this.dailyTotal;
|
|
794
794
|
}
|
|
795
795
|
/**
|
|
796
|
-
*
|
|
796
|
+
* Update daily limit counter
|
|
797
797
|
*/
|
|
798
798
|
updateDailyTotal() {
|
|
799
799
|
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|