agentwallet-sdk 5.0.5 → 5.1.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/README.md +65 -30
- package/dist/ap2/index.d.ts +185 -0
- package/dist/ap2/index.d.ts.map +1 -0
- package/dist/ap2/index.js +255 -0
- package/dist/ap2/index.js.map +1 -0
- package/dist/bridge/unified.d.ts +101 -0
- package/dist/bridge/unified.d.ts.map +1 -0
- package/dist/bridge/unified.js +284 -0
- package/dist/bridge/unified.js.map +1 -0
- package/dist/chains.d.ts +62 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +108 -0
- package/dist/chains.js.map +1 -0
- package/dist/fiat/index.d.ts +10 -0
- package/dist/fiat/index.d.ts.map +1 -0
- package/dist/fiat/index.js +9 -0
- package/dist/fiat/index.js.map +1 -0
- package/dist/fiat/onramp.d.ts +101 -0
- package/dist/fiat/onramp.d.ts.map +1 -0
- package/dist/fiat/onramp.js +155 -0
- package/dist/fiat/onramp.js.map +1 -0
- package/dist/fiat/providers/index.d.ts +16 -0
- package/dist/fiat/providers/index.d.ts.map +1 -0
- package/dist/fiat/providers/index.js +30 -0
- package/dist/fiat/providers/index.js.map +1 -0
- package/dist/fiat/providers/moonpay.d.ts +22 -0
- package/dist/fiat/providers/moonpay.d.ts.map +1 -0
- package/dist/fiat/providers/moonpay.js +107 -0
- package/dist/fiat/providers/moonpay.js.map +1 -0
- package/dist/fiat/providers/stripe.d.ts +26 -0
- package/dist/fiat/providers/stripe.d.ts.map +1 -0
- package/dist/fiat/providers/stripe.js +135 -0
- package/dist/fiat/providers/stripe.js.map +1 -0
- package/dist/fiat/providers/transak.d.ts +26 -0
- package/dist/fiat/providers/transak.d.ts.map +1 -0
- package/dist/fiat/providers/transak.js +119 -0
- package/dist/fiat/providers/transak.js.map +1 -0
- package/dist/fiat/types.d.ts +106 -0
- package/dist/fiat/types.d.ts.map +1 -0
- package/dist/fiat/types.js +13 -0
- package/dist/fiat/types.js.map +1 -0
- package/dist/flash/executor.d.ts +119 -0
- package/dist/flash/executor.d.ts.map +1 -0
- package/dist/flash/executor.js +195 -0
- package/dist/flash/executor.js.map +1 -0
- package/dist/flash/index.d.ts +28 -0
- package/dist/flash/index.d.ts.map +1 -0
- package/dist/flash/index.js +29 -0
- package/dist/flash/index.js.map +1 -0
- package/dist/flash/scanner.d.ts +133 -0
- package/dist/flash/scanner.d.ts.map +1 -0
- package/dist/flash/scanner.js +212 -0
- package/dist/flash/scanner.js.map +1 -0
- package/dist/flash/types.d.ts +136 -0
- package/dist/flash/types.d.ts.map +1 -0
- package/dist/flash/types.js +23 -0
- package/dist/flash/types.js.map +1 -0
- package/dist/gas/index.d.ts +4 -0
- package/dist/gas/index.d.ts.map +1 -0
- package/dist/gas/index.js +3 -0
- package/dist/gas/index.js.map +1 -0
- package/dist/gas/sponsor.d.ts +70 -0
- package/dist/gas/sponsor.d.ts.map +1 -0
- package/dist/gas/sponsor.js +193 -0
- package/dist/gas/sponsor.js.map +1 -0
- package/dist/gas/types.d.ts +76 -0
- package/dist/gas/types.d.ts.map +1 -0
- package/dist/gas/types.js +21 -0
- package/dist/gas/types.js.map +1 -0
- package/dist/identity/agent-identity.d.ts +276 -0
- package/dist/identity/agent-identity.d.ts.map +1 -0
- package/dist/identity/agent-identity.js +300 -0
- package/dist/identity/agent-identity.js.map +1 -0
- package/dist/identity/email-resolver.d.ts +235 -0
- package/dist/identity/email-resolver.js +283 -0
- package/dist/identity/erc6551.d.ts +441 -0
- package/dist/identity/erc6551.d.ts.map +1 -0
- package/dist/identity/erc6551.js +517 -0
- package/dist/identity/erc6551.js.map +1 -0
- package/dist/index.d.ts +286 -213
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/mev/index.d.ts +4 -0
- package/dist/mev/index.d.ts.map +1 -0
- package/dist/mev/index.js +8 -0
- package/dist/mev/index.js.map +1 -0
- package/dist/mev/protection.d.ts +54 -0
- package/dist/mev/protection.d.ts.map +1 -0
- package/dist/mev/protection.js +185 -0
- package/dist/mev/protection.js.map +1 -0
- package/dist/mev/risk.d.ts +19 -0
- package/dist/mev/risk.d.ts.map +1 -0
- package/dist/mev/risk.js +95 -0
- package/dist/mev/risk.js.map +1 -0
- package/dist/mev/types.d.ts +49 -0
- package/dist/mev/types.d.ts.map +1 -0
- package/dist/mev/types.js +2 -0
- package/dist/mev/types.js.map +1 -0
- package/dist/plugins/elizaos.d.ts +52 -0
- package/dist/plugins/elizaos.d.ts.map +1 -0
- package/dist/plugins/elizaos.js +89 -0
- package/dist/plugins/elizaos.js.map +1 -0
- package/dist/settlement/index.d.ts +4 -0
- package/dist/settlement/index.d.ts.map +1 -0
- package/dist/settlement/index.js +3 -0
- package/dist/settlement/index.js.map +1 -0
- package/dist/settlement/types.d.ts +66 -0
- package/dist/settlement/types.d.ts.map +1 -0
- package/dist/settlement/types.js +37 -0
- package/dist/settlement/types.js.map +1 -0
- package/dist/settlement/verifier.d.ts +75 -0
- package/dist/settlement/verifier.d.ts.map +1 -0
- package/dist/settlement/verifier.js +354 -0
- package/dist/settlement/verifier.js.map +1 -0
- package/dist/solana/bridge.d.ts +144 -0
- package/dist/solana/bridge.d.ts.map +1 -0
- package/dist/solana/bridge.js +352 -0
- package/dist/solana/bridge.js.map +1 -0
- package/dist/solana/index.d.ts +8 -0
- package/dist/solana/index.d.ts.map +1 -0
- package/dist/solana/index.js +6 -0
- package/dist/solana/index.js.map +1 -0
- package/dist/solana/swap.d.ts +85 -0
- package/dist/solana/swap.d.ts.map +1 -0
- package/dist/solana/swap.js +173 -0
- package/dist/solana/swap.js.map +1 -0
- package/dist/solana/types.d.ts +126 -0
- package/dist/solana/types.d.ts.map +1 -0
- package/dist/solana/types.js +10 -0
- package/dist/solana/types.js.map +1 -0
- package/dist/solana/wallet.d.ts +83 -0
- package/dist/solana/wallet.d.ts.map +1 -0
- package/dist/solana/wallet.js +164 -0
- package/dist/solana/wallet.js.map +1 -0
- package/dist/solana/x402.d.ts +69 -0
- package/dist/solana/x402.d.ts.map +1 -0
- package/dist/solana/x402.js +154 -0
- package/dist/solana/x402.js.map +1 -0
- package/dist/solver/adapter.d.ts +47 -0
- package/dist/solver/adapter.d.ts.map +1 -0
- package/dist/solver/adapter.js +146 -0
- package/dist/solver/adapter.js.map +1 -0
- package/dist/solver/analyzer.d.ts +48 -0
- package/dist/solver/analyzer.d.ts.map +1 -0
- package/dist/solver/analyzer.js +171 -0
- package/dist/solver/analyzer.js.map +1 -0
- package/dist/solver/builder.d.ts +31 -0
- package/dist/solver/builder.d.ts.map +1 -0
- package/dist/solver/builder.js +60 -0
- package/dist/solver/builder.js.map +1 -0
- package/dist/solver/index.d.ts +22 -0
- package/dist/solver/index.d.ts.map +1 -0
- package/dist/solver/index.js +25 -0
- package/dist/solver/index.js.map +1 -0
- package/dist/solver/types.d.ts +115 -0
- package/dist/solver/types.d.ts.map +1 -0
- package/dist/solver/types.js +10 -0
- package/dist/solver/types.js.map +1 -0
- package/dist/spend-guard/index.d.ts +125 -0
- package/dist/spend-guard/index.d.ts.map +1 -0
- package/dist/spend-guard/index.js +150 -0
- package/dist/spend-guard/index.js.map +1 -0
- package/dist/swap/router/cache.d.ts +13 -0
- package/dist/swap/router/cache.d.ts.map +1 -0
- package/dist/swap/router/cache.js +30 -0
- package/dist/swap/router/cache.js.map +1 -0
- package/dist/swap/router/flashbots.d.ts +10 -0
- package/dist/swap/router/flashbots.d.ts.map +1 -0
- package/dist/swap/router/flashbots.js +43 -0
- package/dist/swap/router/flashbots.js.map +1 -0
- package/dist/swap/router/health.d.ts +17 -0
- package/dist/swap/router/health.d.ts.map +1 -0
- package/dist/swap/router/health.js +38 -0
- package/dist/swap/router/health.js.map +1 -0
- package/dist/swap/router/index.d.ts +10 -0
- package/dist/swap/router/index.d.ts.map +1 -0
- package/dist/swap/router/index.js +10 -0
- package/dist/swap/router/index.js.map +1 -0
- package/dist/swap/router/providers/cowswap.d.ts +11 -0
- package/dist/swap/router/providers/cowswap.d.ts.map +1 -0
- package/dist/swap/router/providers/cowswap.js +79 -0
- package/dist/swap/router/providers/cowswap.js.map +1 -0
- package/dist/swap/router/providers/index.d.ts +20 -0
- package/dist/swap/router/providers/index.d.ts.map +1 -0
- package/dist/swap/router/providers/index.js +32 -0
- package/dist/swap/router/providers/index.js.map +1 -0
- package/dist/swap/router/providers/jupiter.d.ts +12 -0
- package/dist/swap/router/providers/jupiter.d.ts.map +1 -0
- package/dist/swap/router/providers/jupiter.js +73 -0
- package/dist/swap/router/providers/jupiter.js.map +1 -0
- package/dist/swap/router/providers/lifi.d.ts +11 -0
- package/dist/swap/router/providers/lifi.d.ts.map +1 -0
- package/dist/swap/router/providers/lifi.js +123 -0
- package/dist/swap/router/providers/lifi.js.map +1 -0
- package/dist/swap/router/providers/oneinch.d.ts +13 -0
- package/dist/swap/router/providers/oneinch.d.ts.map +1 -0
- package/dist/swap/router/providers/oneinch.js +71 -0
- package/dist/swap/router/providers/oneinch.js.map +1 -0
- package/dist/swap/router/providers/paraswap.d.ts +11 -0
- package/dist/swap/router/providers/paraswap.d.ts.map +1 -0
- package/dist/swap/router/providers/paraswap.js +73 -0
- package/dist/swap/router/providers/paraswap.js.map +1 -0
- package/dist/swap/router/providers/uniswap.d.ts +31 -0
- package/dist/swap/router/providers/uniswap.d.ts.map +1 -0
- package/dist/swap/router/providers/uniswap.js +237 -0
- package/dist/swap/router/providers/uniswap.js.map +1 -0
- package/dist/swap/router/providers/zerox.d.ts +13 -0
- package/dist/swap/router/providers/zerox.d.ts.map +1 -0
- package/dist/swap/router/providers/zerox.js +94 -0
- package/dist/swap/router/providers/zerox.js.map +1 -0
- package/dist/swap/router/router.d.ts +86 -0
- package/dist/swap/router/router.d.ts.map +1 -0
- package/dist/swap/router/router.js +224 -0
- package/dist/swap/router/router.js.map +1 -0
- package/dist/swap/router/rsi/engine.d.ts +60 -0
- package/dist/swap/router/rsi/engine.d.ts.map +1 -0
- package/dist/swap/router/rsi/engine.js +483 -0
- package/dist/swap/router/rsi/engine.js.map +1 -0
- package/dist/swap/router/rsi/index.d.ts +3 -0
- package/dist/swap/router/rsi/index.d.ts.map +1 -0
- package/dist/swap/router/rsi/index.js +3 -0
- package/dist/swap/router/rsi/index.js.map +1 -0
- package/dist/swap/router/rsi/types.d.ts +106 -0
- package/dist/swap/router/rsi/types.d.ts.map +1 -0
- package/dist/swap/router/rsi/types.js +3 -0
- package/dist/swap/router/rsi/types.js.map +1 -0
- package/dist/swap/router/types.d.ts +120 -0
- package/dist/swap/router/types.d.ts.map +1 -0
- package/dist/swap/router/types.js +16 -0
- package/dist/swap/router/types.js.map +1 -0
- package/dist/tax/engine.d.ts +131 -0
- package/dist/tax/engine.d.ts.map +1 -0
- package/dist/tax/engine.js +307 -0
- package/dist/tax/engine.js.map +1 -0
- package/dist/tax/index.d.ts +9 -0
- package/dist/tax/index.d.ts.map +1 -0
- package/dist/tax/index.js +12 -0
- package/dist/tax/index.js.map +1 -0
- package/dist/tax/lots.d.ts +60 -0
- package/dist/tax/lots.d.ts.map +1 -0
- package/dist/tax/lots.js +129 -0
- package/dist/tax/lots.js.map +1 -0
- package/dist/tax/types.d.ts +113 -0
- package/dist/tax/types.d.ts.map +1 -0
- package/dist/tax/types.js +18 -0
- package/dist/tax/types.js.map +1 -0
- package/dist/verifiable-intent/index.d.ts +84 -0
- package/dist/verifiable-intent/index.js +385 -0
- package/dist/yield/index.d.ts +26 -0
- package/dist/yield/index.d.ts.map +1 -0
- package/dist/yield/index.js +29 -0
- package/dist/yield/index.js.map +1 -0
- package/dist/yield/rates.d.ts +114 -0
- package/dist/yield/rates.d.ts.map +1 -0
- package/dist/yield/rates.js +351 -0
- package/dist/yield/rates.js.map +1 -0
- package/dist/yield/types.d.ts +134 -0
- package/dist/yield/types.d.ts.map +1 -0
- package/dist/yield/types.js +24 -0
- package/dist/yield/types.js.map +1 -0
- package/dist/yield/vault.d.ts +112 -0
- package/dist/yield/vault.d.ts.map +1 -0
- package/dist/yield/vault.js +264 -0
- package/dist/yield/vault.js.map +1 -0
- package/package.json +3 -3
- package/LICENSE +0 -21
- package/dist/x402/chains/stellar/index.d.ts +0 -136
- package/dist/x402/chains/stellar/index.d.ts.map +0 -1
- package/dist/x402/chains/stellar/index.js +0 -190
- package/dist/x402/chains/stellar/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# AgentWallet SDK
|
|
2
2
|
|
|
3
|
-
> **📦 CANONICAL PACKAGE:** This is the actively maintained source for the `agentwallet-sdk` npm package (v5+). The old `agentwallet-sdk` GitHub repo is deprecated — use this repo.
|
|
4
|
-
|
|
5
|
-
|
|
6
3
|
Non-custodial AI agent wallet with ERC-8004 on-chain identity, ERC-6551 token-bound accounts, x402 payments, mutual stake escrow, and programmable spending guardrails.
|
|
7
4
|
|
|
8
5
|
Agent Wallet gives AI agents autonomous spending power with hard on-chain limits. No more choosing between "agent can drain everything" and "every transaction needs manual approval."
|
|
@@ -207,48 +204,86 @@ await escrow.verify(escrowId);
|
|
|
207
204
|
|
|
208
205
|
Premium access: [github.com/up2itnow/AgentNexus2](https://github.com/up2itnow/AgentNexus2)
|
|
209
206
|
|
|
210
|
-
##
|
|
207
|
+
## x402 Protocol: Supported Chains and Payment Rails
|
|
211
208
|
|
|
212
|
-
|
|
209
|
+
x402 (HTTP 402 Payment Required) is the native payment protocol for agent-to-service transactions. The agent encounters a 402 response, signs a payment proof, and re-sends the request. One round trip. No accounts, no API keys, no invoices.
|
|
213
210
|
|
|
214
|
-
|
|
215
|
-
https://dexter-settlement-test-production.up.railway.app
|
|
216
|
-
```
|
|
211
|
+
As of March 2026, x402 is live on 3 chains/rails:
|
|
217
212
|
|
|
218
|
-
|
|
|
219
|
-
|
|
220
|
-
| USDC
|
|
221
|
-
|
|
|
213
|
+
| Chain / Rail | Status | Settlement Token | Gas Cost | Notes |
|
|
214
|
+
|---|---|---|---|---|
|
|
215
|
+
| **Base** (Coinbase L2) | Live | USDC | Sub-cent | Primary x402 chain. 15M+ transactions in Jan 2026. |
|
|
216
|
+
| **Etherlink** (Tezos L2) | Live (Mar 2026) | USDC | Sub-cent | EVM-compatible. Same x402 integration, different RPC + chain ID. |
|
|
217
|
+
| **Stripe** (Fiat offramp) | Live (Feb 2026) | USDC -> USD | N/A | Vendors receive USD in Stripe dashboard. Agents pay USDC. |
|
|
222
218
|
|
|
223
|
-
|
|
219
|
+
### x402 + Etherlink Quick Start
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { createWallet, agentExecute } from 'agentwallet-sdk';
|
|
223
|
+
|
|
224
|
+
const wallet = createWallet({
|
|
225
|
+
accountAddress: '0xYourAgent',
|
|
226
|
+
chain: 'etherlink', // new: Tezos L2 support
|
|
227
|
+
walletClient,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// x402 payment flow is identical across chains
|
|
231
|
+
const response = await fetch('https://api.vendor.com/data');
|
|
232
|
+
if (response.status === 402) {
|
|
233
|
+
const details = await response.json();
|
|
234
|
+
const proof = await wallet.createX402Proof(details);
|
|
235
|
+
const paid = await fetch('https://api.vendor.com/data', {
|
|
236
|
+
headers: { 'X-Payment': proof }
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The SDK handles chain-specific RPC endpoints, gas estimation, and USDC contract addresses automatically. Swap `chain: 'base'` to `chain: 'etherlink'` and the x402 flow works identically.
|
|
224
242
|
|
|
225
243
|
## Supported Chains
|
|
226
244
|
|
|
227
|
-
Mainnet: Ethereum, Base, Arbitrum, Polygon, Optimism, Avalanche, BSC, Celo, Gnosis, Linea, Mantle, Scroll, and more.
|
|
245
|
+
Mainnet: Ethereum, Base, Arbitrum, Polygon, Optimism, Avalanche, BSC, Celo, Gnosis, Linea, Mantle, Scroll, Etherlink, and more.
|
|
228
246
|
|
|
229
247
|
Testnet: Base Sepolia, Arbitrum Sepolia, and corresponding testnets.
|
|
230
248
|
|
|
231
|
-
##
|
|
249
|
+
## Complete Agent Identity Stack (v5.1.0)
|
|
232
250
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
251
|
+
One npm install now gives any AI agent a wallet, email address, on-chain ID, reputation, and signed payment intents.
|
|
252
|
+
|
|
253
|
+
| Component | What It Does |
|
|
254
|
+
|-----------|-------------|
|
|
255
|
+
| **EmailResolver** *(NEW)* | AgentMail integration — agents get `email@agentmail.to` linked to wallet. Resolve email→wallet, send/receive with embedded x402 payment requests. |
|
|
256
|
+
| **AgentIdentity** | ERC-8004 + ERC-6551: on-chain NFT identity + Token Bound Account |
|
|
257
|
+
| **ReputationClient** | On-chain reputation scoring — give/read feedback, aggregate scores |
|
|
258
|
+
| **VerifiableIntentClient** | Mastercard-spec signed payment intents with scope enforcement |
|
|
259
|
+
| **ValidationClient** | Request/respond validation workflow (TEE attestations, compliance) |
|
|
260
|
+
|
|
261
|
+
### EmailResolver Quick Start
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import { EmailResolver } from 'agentwallet-sdk';
|
|
265
|
+
|
|
266
|
+
const resolver = new EmailResolver();
|
|
236
267
|
|
|
268
|
+
// Resolve an agent email to its wallet address
|
|
269
|
+
const wallet = await resolver.resolveEmail('myagent@agentmail.to');
|
|
270
|
+
console.log(wallet.address); // 0x...
|
|
237
271
|
|
|
238
|
-
|
|
272
|
+
// Send a payment request embedded in an email
|
|
273
|
+
await resolver.sendWithPayment({
|
|
274
|
+
to: 'vendor@agentmail.to',
|
|
275
|
+
subject: 'Payment for API access',
|
|
276
|
+
amount: 5_000_000n, // 5 USDC
|
|
277
|
+
token: 'USDC',
|
|
278
|
+
chain: 'base',
|
|
279
|
+
});
|
|
280
|
+
```
|
|
239
281
|
|
|
240
|
-
|
|
241
|
-
|---|---|---|
|
|
242
|
-
| Wallet model | Non-custodial, agent holds keys | CLI-based, operator-managed |
|
|
243
|
-
| x402 support | Native, automatic negotiation | Not supported |
|
|
244
|
-
| Spend limits | Programmable (daily, per-tx, per-agent) | Manual configuration |
|
|
245
|
-
| Multi-chain | Ethereum, Base, Etherlink, Polygon, 10+ chains | Polygon-only |
|
|
246
|
-
| Integration | npm package, works in any JS/TS runtime | CLI tool, requires shell access |
|
|
247
|
-
| Agent frameworks | Any (LangChain, CrewAI, Cursor, NemoClaw) | Polygon ecosystem only |
|
|
248
|
-
| Audit trail | Built-in transaction logging | External tooling required |
|
|
249
|
-
| Use case | Autonomous agent payments at scale | Polygon-specific agent ops |
|
|
282
|
+
## Links
|
|
250
283
|
|
|
251
|
-
|
|
284
|
+
- [ERC-8004 Spec](https://eips.ethereum.org/EIPS/eip-8004)
|
|
285
|
+
- [GitHub](https://github.com/agentnexus/agent-wallet-sdk)
|
|
286
|
+
- [npm](https://www.npmjs.com/package/agentwallet-sdk)
|
|
252
287
|
|
|
253
288
|
## License
|
|
254
289
|
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AP2Client — ISO 20022 / AP2 European Payment Module for agentwallet-sdk
|
|
3
|
+
*
|
|
4
|
+
* Non-custodial AI agent bridge for AP2 payments:
|
|
5
|
+
* - Parse ISO 20022 pacs.008 XML → bridge quote
|
|
6
|
+
* - Sign x402 payment header locally (private key never leaves agent)
|
|
7
|
+
* - Execute USDC → EUR settlement via CCTP V2 (Base → EUR off-ramp)
|
|
8
|
+
*
|
|
9
|
+
* AP2 context:
|
|
10
|
+
* Nexi + Google Cloud MoU (2026): AP2 processes ~2.9T EUR/year across Europe.
|
|
11
|
+
* ISO 20022 is the wire standard. This module makes AI agents first-class
|
|
12
|
+
* European payment participants — non-custodially.
|
|
13
|
+
*
|
|
14
|
+
* @module ap2
|
|
15
|
+
*/
|
|
16
|
+
/** Parameters for building a pacs.008 XML message from simple inputs. */
|
|
17
|
+
export interface AP2PaymentParams {
|
|
18
|
+
/** Unique message ID (e.g. "MSG-2026-0001") */
|
|
19
|
+
messageId: string;
|
|
20
|
+
/** ISO 8601 creation datetime (defaults to now) */
|
|
21
|
+
creationDateTime?: string;
|
|
22
|
+
/** Payment amount in EUR (or specified currency) */
|
|
23
|
+
amount: number;
|
|
24
|
+
/** Currency code (default: "EUR") */
|
|
25
|
+
currency?: string;
|
|
26
|
+
/** Debtor full name */
|
|
27
|
+
debtorName: string;
|
|
28
|
+
/** Debtor IBAN */
|
|
29
|
+
debtorIban: string;
|
|
30
|
+
/** Debtor BIC */
|
|
31
|
+
debtorBic: string;
|
|
32
|
+
/** Creditor full name */
|
|
33
|
+
creditorName: string;
|
|
34
|
+
/** Creditor IBAN */
|
|
35
|
+
creditorIban: string;
|
|
36
|
+
/** Creditor BIC */
|
|
37
|
+
creditorBic: string;
|
|
38
|
+
/** Optional end-to-end reference */
|
|
39
|
+
endToEndId?: string;
|
|
40
|
+
/** Optional purpose code (e.g. "SUPP") */
|
|
41
|
+
purposeCode?: string;
|
|
42
|
+
/** Optional unstructured remittance info */
|
|
43
|
+
remittanceInfo?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Bridge quote returned by the AP2 facilitator. */
|
|
46
|
+
export interface AP2Quote {
|
|
47
|
+
/** ISO 20022 message ID */
|
|
48
|
+
messageId: string;
|
|
49
|
+
/** Creditor IBAN for SEPA settlement */
|
|
50
|
+
creditorIban: string;
|
|
51
|
+
/** EUR payment amount */
|
|
52
|
+
amountEur: number;
|
|
53
|
+
/** USDC required (6 decimal precision, as bigint μUSDC) */
|
|
54
|
+
usdcRequired: bigint;
|
|
55
|
+
/** Bridge fee in USDC (μUSDC) */
|
|
56
|
+
bridgeFeeUsdc: bigint;
|
|
57
|
+
/** Estimated settlement time in seconds */
|
|
58
|
+
estimatedSettlementSeconds: number;
|
|
59
|
+
/** x402 payment header string */
|
|
60
|
+
x402PaymentHeader: string;
|
|
61
|
+
/** Raw calldata for agentwallet-sdk */
|
|
62
|
+
agentWalletCalldata: Record<string, unknown>;
|
|
63
|
+
/** Quote expiry ISO timestamp */
|
|
64
|
+
expiresAt: string;
|
|
65
|
+
}
|
|
66
|
+
/** Execution receipt after AP2 payment is submitted. */
|
|
67
|
+
export interface AP2Receipt {
|
|
68
|
+
/** ISO 20022 message ID */
|
|
69
|
+
messageId: string;
|
|
70
|
+
/** On-chain transaction hash */
|
|
71
|
+
txHash: string;
|
|
72
|
+
/** USDC bridged (μUSDC as bigint) */
|
|
73
|
+
usdcBridged: bigint;
|
|
74
|
+
/** SEPA creditor reference */
|
|
75
|
+
sepaReference: string;
|
|
76
|
+
/** Payment status */
|
|
77
|
+
status: 'pending' | 'confirmed' | 'failed' | 'dry_run';
|
|
78
|
+
/** True if this was a dry run simulation */
|
|
79
|
+
dryRun: boolean;
|
|
80
|
+
/** x402 payment header signature */
|
|
81
|
+
x402Signature: string;
|
|
82
|
+
/** Agent Ethereum address */
|
|
83
|
+
agentAddress: string;
|
|
84
|
+
/** CCTP bridge nonce */
|
|
85
|
+
nonce: number;
|
|
86
|
+
/** ISO timestamp of execution */
|
|
87
|
+
executedAt: string;
|
|
88
|
+
/** Creditor IBAN */
|
|
89
|
+
creditorIban: string;
|
|
90
|
+
/** Bridge fee in USDC (μUSDC) */
|
|
91
|
+
bridgeFeeUsdc: bigint;
|
|
92
|
+
}
|
|
93
|
+
/** AP2Client configuration */
|
|
94
|
+
export interface AP2ClientConfig {
|
|
95
|
+
/**
|
|
96
|
+
* URL of the AP2 facilitator (FastAPI handler).
|
|
97
|
+
* Defaults to http://localhost:8420
|
|
98
|
+
*/
|
|
99
|
+
facilitatorUrl?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build a valid ISO 20022 pacs.008 (FIToFICstmrCdtTrf) XML string
|
|
103
|
+
* from simple agent-friendly parameters.
|
|
104
|
+
*
|
|
105
|
+
* @param params - Payment parameters
|
|
106
|
+
* @returns ISO 20022 pacs.008 XML string
|
|
107
|
+
*/
|
|
108
|
+
declare function buildPacs008(params: AP2PaymentParams): string;
|
|
109
|
+
/**
|
|
110
|
+
* AP2Client — Non-custodial ISO 20022 / AP2 payment client for AI agents.
|
|
111
|
+
*
|
|
112
|
+
* Connects to the AP2 facilitator (ap2_handler.py FastAPI service) to
|
|
113
|
+
* get bridge quotes and execute payments via CCTP V2 / x402.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const client = new AP2Client({ facilitatorUrl: 'http://localhost:8420' });
|
|
118
|
+
*
|
|
119
|
+
* const xml = AP2Client.buildPacs008({
|
|
120
|
+
* messageId: 'MSG-2026-0001',
|
|
121
|
+
* amount: 1000,
|
|
122
|
+
* debtorName: 'Agent Zero',
|
|
123
|
+
* debtorIban: 'DE89370400440532013000',
|
|
124
|
+
* debtorBic: 'COBADEFFXXX',
|
|
125
|
+
* creditorName: 'Acme GmbH',
|
|
126
|
+
* creditorIban: 'FR7630006000011234567890189',
|
|
127
|
+
* creditorBic: 'BNPAFRPPXXX',
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* const quote = await client.quote(xml);
|
|
131
|
+
* const receipt = await client.pay(xml);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare class AP2Client {
|
|
135
|
+
private readonly facilitatorUrl;
|
|
136
|
+
constructor(config?: AP2ClientConfig);
|
|
137
|
+
/**
|
|
138
|
+
* Parse ISO 20022 pacs.008 XML and get a bridge quote from the facilitator.
|
|
139
|
+
*
|
|
140
|
+
* @param iso20022Xml - Raw pacs.008 XML string
|
|
141
|
+
* @returns AP2Quote with USDC amounts and x402 calldata
|
|
142
|
+
* @throws Error if the facilitator returns an error or the XML is invalid
|
|
143
|
+
*/
|
|
144
|
+
quote(iso20022Xml: string): Promise<AP2Quote>;
|
|
145
|
+
/**
|
|
146
|
+
* Execute the full AP2 payment: sign x402 header + bridge USDC + settle.
|
|
147
|
+
*
|
|
148
|
+
* Calls the /ap2/execute endpoint on the facilitator, which:
|
|
149
|
+
* 1. Parses the XML
|
|
150
|
+
* 2. Signs x402 header with agent's private key (server-side in this flow)
|
|
151
|
+
* 3. Submits USDC to CCTP V2 bridge
|
|
152
|
+
* 4. Returns receipt
|
|
153
|
+
*
|
|
154
|
+
* @param iso20022Xml - Raw pacs.008 XML string
|
|
155
|
+
* @returns AP2Receipt with txHash and SEPA reference
|
|
156
|
+
* @throws AP2Error on execution failure
|
|
157
|
+
*/
|
|
158
|
+
pay(iso20022Xml: string): Promise<AP2Receipt>;
|
|
159
|
+
/**
|
|
160
|
+
* Generate a valid ISO 20022 pacs.008 XML string from simple parameters.
|
|
161
|
+
*
|
|
162
|
+
* Handles XML escaping, IBAN normalization, and timestamp formatting.
|
|
163
|
+
* Makes AP2 payments agent-friendly — no ISO 20022 expertise required.
|
|
164
|
+
*
|
|
165
|
+
* @param params - Simple payment parameters
|
|
166
|
+
* @returns Valid pacs.008 XML string
|
|
167
|
+
*/
|
|
168
|
+
static buildPacs008(params: AP2PaymentParams): string;
|
|
169
|
+
/**
|
|
170
|
+
* Estimate USDC required for a given EUR amount.
|
|
171
|
+
*
|
|
172
|
+
* Uses the default EUR/USDC rate. For accurate quotes, call quote() instead.
|
|
173
|
+
*
|
|
174
|
+
* @param amountEur - Amount in EUR
|
|
175
|
+
* @returns Estimated USDC amount as bigint (μUSDC, 6 decimals)
|
|
176
|
+
*/
|
|
177
|
+
static estimateUsdc(amountEur: number): bigint;
|
|
178
|
+
}
|
|
179
|
+
/** AP2-specific error with structured context. */
|
|
180
|
+
export declare class AP2Error extends Error {
|
|
181
|
+
readonly context?: Record<string, unknown> | undefined;
|
|
182
|
+
constructor(message: string, context?: Record<string, unknown> | undefined);
|
|
183
|
+
}
|
|
184
|
+
export { buildPacs008 };
|
|
185
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ap2/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;I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/E;AAMD,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AP2Client — ISO 20022 / AP2 European Payment Module for agentwallet-sdk
|
|
3
|
+
*
|
|
4
|
+
* Non-custodial AI agent bridge for AP2 payments:
|
|
5
|
+
* - Parse ISO 20022 pacs.008 XML → bridge quote
|
|
6
|
+
* - Sign x402 payment header locally (private key never leaves agent)
|
|
7
|
+
* - Execute USDC → EUR settlement via CCTP V2 (Base → EUR off-ramp)
|
|
8
|
+
*
|
|
9
|
+
* AP2 context:
|
|
10
|
+
* Nexi + Google Cloud MoU (2026): AP2 processes ~2.9T EUR/year across Europe.
|
|
11
|
+
* ISO 20022 is the wire standard. This module makes AI agents first-class
|
|
12
|
+
* European payment participants — non-custodially.
|
|
13
|
+
*
|
|
14
|
+
* @module ap2
|
|
15
|
+
*/
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Constants
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
/** USDC decimals (6) */
|
|
20
|
+
const USDC_DECIMALS = 6n;
|
|
21
|
+
const USDC_MULTIPLIER = 10n ** USDC_DECIMALS;
|
|
22
|
+
/** EUR → USDC rate (fallback; production uses Chainlink oracle) */
|
|
23
|
+
const EUR_TO_USDC_RATE = 1.08;
|
|
24
|
+
/** Default facilitator URL */
|
|
25
|
+
const DEFAULT_FACILITATOR_URL = 'http://localhost:8420';
|
|
26
|
+
/** Estimated CCTP V2 settlement time (~20 min) */
|
|
27
|
+
const ESTIMATED_SETTLEMENT_SECONDS = 1200;
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// ISO 20022 pacs.008 XML Builder
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
/**
|
|
32
|
+
* Build a valid ISO 20022 pacs.008 (FIToFICstmrCdtTrf) XML string
|
|
33
|
+
* from simple agent-friendly parameters.
|
|
34
|
+
*
|
|
35
|
+
* @param params - Payment parameters
|
|
36
|
+
* @returns ISO 20022 pacs.008 XML string
|
|
37
|
+
*/
|
|
38
|
+
function buildPacs008(params) {
|
|
39
|
+
const now = params.creationDateTime ?? new Date().toISOString().replace(/\.\d+Z$/, '+00:00');
|
|
40
|
+
const currency = params.currency ?? 'EUR';
|
|
41
|
+
const e2eId = params.endToEndId ?? params.messageId;
|
|
42
|
+
const amount = params.amount.toFixed(2);
|
|
43
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
44
|
+
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08">
|
|
45
|
+
<FIToFICstmrCdtTrf>
|
|
46
|
+
<GrpHdr>
|
|
47
|
+
<MsgId>${escapeXml(params.messageId)}</MsgId>
|
|
48
|
+
<CreDtTm>${escapeXml(now)}</CreDtTm>
|
|
49
|
+
<NbOfTxs>1</NbOfTxs>
|
|
50
|
+
<SttlmInf>
|
|
51
|
+
<SttlmMtd>CLRG</SttlmMtd>
|
|
52
|
+
</SttlmInf>
|
|
53
|
+
</GrpHdr>
|
|
54
|
+
<CdtTrfTxInf>
|
|
55
|
+
<PmtId>
|
|
56
|
+
<EndToEndId>${escapeXml(e2eId)}</EndToEndId>
|
|
57
|
+
</PmtId>
|
|
58
|
+
<IntrBkSttlmAmt Ccy="${escapeXml(currency)}">${amount}</IntrBkSttlmAmt>
|
|
59
|
+
<ChrgBr>SHAR</ChrgBr>
|
|
60
|
+
<Dbtr>
|
|
61
|
+
<Nm>${escapeXml(params.debtorName)}</Nm>
|
|
62
|
+
</Dbtr>
|
|
63
|
+
<DbtrAcct>
|
|
64
|
+
<Id>
|
|
65
|
+
<IBAN>${escapeXml(params.debtorIban.replace(/\s/g, '').toUpperCase())}</IBAN>
|
|
66
|
+
</Id>
|
|
67
|
+
</DbtrAcct>
|
|
68
|
+
<DbtrAgt>
|
|
69
|
+
<FinInstnId>
|
|
70
|
+
<BICFI>${escapeXml(params.debtorBic.toUpperCase())}</BICFI>
|
|
71
|
+
</FinInstnId>
|
|
72
|
+
</DbtrAgt>
|
|
73
|
+
<Cdtr>
|
|
74
|
+
<Nm>${escapeXml(params.creditorName)}</Nm>
|
|
75
|
+
</Cdtr>
|
|
76
|
+
<CdtrAcct>
|
|
77
|
+
<Id>
|
|
78
|
+
<IBAN>${escapeXml(params.creditorIban.replace(/\s/g, '').toUpperCase())}</IBAN>
|
|
79
|
+
</Id>
|
|
80
|
+
</CdtrAcct>
|
|
81
|
+
<CdtrAgt>
|
|
82
|
+
<FinInstnId>
|
|
83
|
+
<BICFI>${escapeXml(params.creditorBic.toUpperCase())}</BICFI>
|
|
84
|
+
</FinInstnId>
|
|
85
|
+
</CdtrAgt>${params.purposeCode ? `
|
|
86
|
+
<Purp>
|
|
87
|
+
<Cd>${escapeXml(params.purposeCode)}</Cd>
|
|
88
|
+
</Purp>` : ''}${params.remittanceInfo ? `
|
|
89
|
+
<RmtInf>
|
|
90
|
+
<Ustrd>${escapeXml(params.remittanceInfo)}</Ustrd>
|
|
91
|
+
</RmtInf>` : ''}
|
|
92
|
+
</CdtTrfTxInf>
|
|
93
|
+
</FIToFICstmrCdtTrf>
|
|
94
|
+
</Document>`;
|
|
95
|
+
}
|
|
96
|
+
/** Escape XML special characters. */
|
|
97
|
+
function escapeXml(str) {
|
|
98
|
+
return str
|
|
99
|
+
.replace(/&/g, '&')
|
|
100
|
+
.replace(/</g, '<')
|
|
101
|
+
.replace(/>/g, '>')
|
|
102
|
+
.replace(/"/g, '"')
|
|
103
|
+
.replace(/'/g, ''');
|
|
104
|
+
}
|
|
105
|
+
/** Convert a decimal USDC string to bigint μUSDC. */
|
|
106
|
+
function usdcToBigInt(usdcStr) {
|
|
107
|
+
const [whole, frac = ''] = usdcStr.split('.');
|
|
108
|
+
const fracPadded = frac.padEnd(Number(USDC_DECIMALS), '0').slice(0, Number(USDC_DECIMALS));
|
|
109
|
+
return BigInt(whole) * USDC_MULTIPLIER + BigInt(fracPadded);
|
|
110
|
+
}
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
// AP2Client
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
/**
|
|
115
|
+
* AP2Client — Non-custodial ISO 20022 / AP2 payment client for AI agents.
|
|
116
|
+
*
|
|
117
|
+
* Connects to the AP2 facilitator (ap2_handler.py FastAPI service) to
|
|
118
|
+
* get bridge quotes and execute payments via CCTP V2 / x402.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const client = new AP2Client({ facilitatorUrl: 'http://localhost:8420' });
|
|
123
|
+
*
|
|
124
|
+
* const xml = AP2Client.buildPacs008({
|
|
125
|
+
* messageId: 'MSG-2026-0001',
|
|
126
|
+
* amount: 1000,
|
|
127
|
+
* debtorName: 'Agent Zero',
|
|
128
|
+
* debtorIban: 'DE89370400440532013000',
|
|
129
|
+
* debtorBic: 'COBADEFFXXX',
|
|
130
|
+
* creditorName: 'Acme GmbH',
|
|
131
|
+
* creditorIban: 'FR7630006000011234567890189',
|
|
132
|
+
* creditorBic: 'BNPAFRPPXXX',
|
|
133
|
+
* });
|
|
134
|
+
*
|
|
135
|
+
* const quote = await client.quote(xml);
|
|
136
|
+
* const receipt = await client.pay(xml);
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export class AP2Client {
|
|
140
|
+
constructor(config = {}) {
|
|
141
|
+
this.facilitatorUrl = (config.facilitatorUrl ?? DEFAULT_FACILITATOR_URL).replace(/\/$/, '');
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Parse ISO 20022 pacs.008 XML and get a bridge quote from the facilitator.
|
|
145
|
+
*
|
|
146
|
+
* @param iso20022Xml - Raw pacs.008 XML string
|
|
147
|
+
* @returns AP2Quote with USDC amounts and x402 calldata
|
|
148
|
+
* @throws Error if the facilitator returns an error or the XML is invalid
|
|
149
|
+
*/
|
|
150
|
+
async quote(iso20022Xml) {
|
|
151
|
+
const response = await fetch(`${this.facilitatorUrl}/ap2/payment`, {
|
|
152
|
+
method: 'POST',
|
|
153
|
+
headers: { 'Content-Type': 'application/xml' },
|
|
154
|
+
body: iso20022Xml,
|
|
155
|
+
});
|
|
156
|
+
if (!response.ok) {
|
|
157
|
+
const body = await response.text();
|
|
158
|
+
throw new AP2Error(`Quote failed (${response.status}): ${body}`);
|
|
159
|
+
}
|
|
160
|
+
const json = (await response.json());
|
|
161
|
+
const bq = json.bridge_quote;
|
|
162
|
+
const payment = json.payment;
|
|
163
|
+
return {
|
|
164
|
+
messageId: payment.message_id,
|
|
165
|
+
creditorIban: payment.creditor.iban,
|
|
166
|
+
amountEur: parseFloat(payment.amount),
|
|
167
|
+
usdcRequired: usdcToBigInt(bq.usdc_amount),
|
|
168
|
+
bridgeFeeUsdc: usdcToBigInt(bq.bridge_fee_usdc),
|
|
169
|
+
estimatedSettlementSeconds: ESTIMATED_SETTLEMENT_SECONDS,
|
|
170
|
+
x402PaymentHeader: bq.x402_payment_header,
|
|
171
|
+
agentWalletCalldata: bq.agent_wallet_calldata,
|
|
172
|
+
expiresAt: bq.expires_at,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Execute the full AP2 payment: sign x402 header + bridge USDC + settle.
|
|
177
|
+
*
|
|
178
|
+
* Calls the /ap2/execute endpoint on the facilitator, which:
|
|
179
|
+
* 1. Parses the XML
|
|
180
|
+
* 2. Signs x402 header with agent's private key (server-side in this flow)
|
|
181
|
+
* 3. Submits USDC to CCTP V2 bridge
|
|
182
|
+
* 4. Returns receipt
|
|
183
|
+
*
|
|
184
|
+
* @param iso20022Xml - Raw pacs.008 XML string
|
|
185
|
+
* @returns AP2Receipt with txHash and SEPA reference
|
|
186
|
+
* @throws AP2Error on execution failure
|
|
187
|
+
*/
|
|
188
|
+
async pay(iso20022Xml) {
|
|
189
|
+
const response = await fetch(`${this.facilitatorUrl}/ap2/execute`, {
|
|
190
|
+
method: 'POST',
|
|
191
|
+
headers: { 'Content-Type': 'application/xml' },
|
|
192
|
+
body: iso20022Xml,
|
|
193
|
+
});
|
|
194
|
+
if (!response.ok) {
|
|
195
|
+
const body = await response.text();
|
|
196
|
+
throw new AP2Error(`Execution failed (${response.status}): ${body}`);
|
|
197
|
+
}
|
|
198
|
+
const json = (await response.json());
|
|
199
|
+
const r = json.receipt;
|
|
200
|
+
return {
|
|
201
|
+
messageId: r.message_id,
|
|
202
|
+
txHash: r.tx_hash,
|
|
203
|
+
usdcBridged: usdcToBigInt(r.usdc_bridged),
|
|
204
|
+
sepaReference: r.sepa_reference,
|
|
205
|
+
status: r.status,
|
|
206
|
+
dryRun: r.dry_run,
|
|
207
|
+
x402Signature: r.x402_signature,
|
|
208
|
+
agentAddress: r.agent_address,
|
|
209
|
+
nonce: r.nonce,
|
|
210
|
+
executedAt: r.executed_at,
|
|
211
|
+
creditorIban: r.creditor_iban,
|
|
212
|
+
bridgeFeeUsdc: usdcToBigInt(r.bridge_fee_usdc),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Generate a valid ISO 20022 pacs.008 XML string from simple parameters.
|
|
217
|
+
*
|
|
218
|
+
* Handles XML escaping, IBAN normalization, and timestamp formatting.
|
|
219
|
+
* Makes AP2 payments agent-friendly — no ISO 20022 expertise required.
|
|
220
|
+
*
|
|
221
|
+
* @param params - Simple payment parameters
|
|
222
|
+
* @returns Valid pacs.008 XML string
|
|
223
|
+
*/
|
|
224
|
+
static buildPacs008(params) {
|
|
225
|
+
return buildPacs008(params);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Estimate USDC required for a given EUR amount.
|
|
229
|
+
*
|
|
230
|
+
* Uses the default EUR/USDC rate. For accurate quotes, call quote() instead.
|
|
231
|
+
*
|
|
232
|
+
* @param amountEur - Amount in EUR
|
|
233
|
+
* @returns Estimated USDC amount as bigint (μUSDC, 6 decimals)
|
|
234
|
+
*/
|
|
235
|
+
static estimateUsdc(amountEur) {
|
|
236
|
+
const usdc = amountEur * EUR_TO_USDC_RATE;
|
|
237
|
+
return BigInt(Math.round(usdc * Number(USDC_MULTIPLIER)));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// ---------------------------------------------------------------------------
|
|
241
|
+
// Error class
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
/** AP2-specific error with structured context. */
|
|
244
|
+
export class AP2Error extends Error {
|
|
245
|
+
constructor(message, context) {
|
|
246
|
+
super(message);
|
|
247
|
+
this.context = context;
|
|
248
|
+
this.name = 'AP2Error';
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// ---------------------------------------------------------------------------
|
|
252
|
+
// Re-export builder as standalone function
|
|
253
|
+
// ---------------------------------------------------------------------------
|
|
254
|
+
export { buildPacs008 };
|
|
255
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ap2/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAiIH,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,wBAAwB;AACxB,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,eAAe,GAAG,GAAG,IAAI,aAAa,CAAC;AAE7C,mEAAmE;AACnE,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,8BAA8B;AAC9B,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AAExD,kDAAkD;AAClD,MAAM,4BAA4B,GAAG,IAAI,CAAC;AAE1C,8EAA8E;AAC9E,iCAAiC;AACjC,8EAA8E;AAE9E;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,MAAwB;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,gBAAgB,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC7F,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC;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