agentwallet-sdk 5.1.0 → 5.2.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.
Files changed (311) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +240 -20
  3. package/dist/bridge/__tests__/solana.test.d.ts +2 -0
  4. package/dist/bridge/__tests__/solana.test.d.ts.map +1 -0
  5. package/dist/bridge/__tests__/solana.test.js +106 -0
  6. package/dist/bridge/__tests__/solana.test.js.map +1 -0
  7. package/dist/bridge/client.d.ts +21 -7
  8. package/dist/bridge/client.d.ts.map +1 -1
  9. package/dist/bridge/client.js +16 -1
  10. package/dist/bridge/client.js.map +1 -1
  11. package/dist/bridge/index.d.ts +12 -1
  12. package/dist/bridge/index.d.ts.map +1 -1
  13. package/dist/bridge/index.js +11 -0
  14. package/dist/bridge/index.js.map +1 -1
  15. package/dist/bridge/solana.d.ts +132 -0
  16. package/dist/bridge/solana.d.ts.map +1 -0
  17. package/dist/bridge/solana.js +313 -0
  18. package/dist/bridge/solana.js.map +1 -0
  19. package/dist/bridge/types.d.ts +35 -10
  20. package/dist/bridge/types.d.ts.map +1 -1
  21. package/dist/bridge/types.js +16 -4
  22. package/dist/bridge/types.js.map +1 -1
  23. package/dist/index.d.ts +215 -288
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +1 -3
  26. package/dist/index.js.map +1 -1
  27. package/dist/swap/SwapModule.d.ts +17 -3
  28. package/dist/swap/SwapModule.d.ts.map +1 -1
  29. package/dist/swap/SwapModule.js +20 -4
  30. package/dist/swap/SwapModule.js.map +1 -1
  31. package/dist/swap/index.d.ts +9 -2
  32. package/dist/swap/index.d.ts.map +1 -1
  33. package/dist/swap/index.js +8 -1
  34. package/dist/swap/index.js.map +1 -1
  35. package/dist/swap/types.d.ts +58 -1
  36. package/dist/swap/types.d.ts.map +1 -1
  37. package/dist/swap/types.js +56 -1
  38. package/dist/swap/types.js.map +1 -1
  39. package/dist/types.d.ts +20 -1
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/types.js +6 -0
  42. package/dist/types.js.map +1 -1
  43. package/dist/x402/__tests__/client.test.js +77 -5
  44. package/dist/x402/__tests__/client.test.js.map +1 -1
  45. package/dist/x402/chains/stellar/index.d.ts +149 -0
  46. package/dist/x402/chains/stellar/index.d.ts.map +1 -0
  47. package/dist/x402/chains/stellar/index.js +197 -0
  48. package/dist/x402/chains/stellar/index.js.map +1 -0
  49. package/dist/x402/client.d.ts.map +1 -1
  50. package/dist/x402/client.js.map +1 -1
  51. package/dist/x402/types.d.ts +22 -3
  52. package/dist/x402/types.d.ts.map +1 -1
  53. package/dist/x402/types.js +34 -4
  54. package/dist/x402/types.js.map +1 -1
  55. package/package.json +16 -5
  56. package/dist/ap2/index.d.ts +0 -185
  57. package/dist/ap2/index.d.ts.map +0 -1
  58. package/dist/ap2/index.js +0 -255
  59. package/dist/ap2/index.js.map +0 -1
  60. package/dist/bridge/unified.d.ts +0 -101
  61. package/dist/bridge/unified.d.ts.map +0 -1
  62. package/dist/bridge/unified.js +0 -284
  63. package/dist/bridge/unified.js.map +0 -1
  64. package/dist/chains.d.ts +0 -62
  65. package/dist/chains.d.ts.map +0 -1
  66. package/dist/chains.js +0 -108
  67. package/dist/chains.js.map +0 -1
  68. package/dist/fiat/index.d.ts +0 -10
  69. package/dist/fiat/index.d.ts.map +0 -1
  70. package/dist/fiat/index.js +0 -9
  71. package/dist/fiat/index.js.map +0 -1
  72. package/dist/fiat/onramp.d.ts +0 -101
  73. package/dist/fiat/onramp.d.ts.map +0 -1
  74. package/dist/fiat/onramp.js +0 -155
  75. package/dist/fiat/onramp.js.map +0 -1
  76. package/dist/fiat/providers/index.d.ts +0 -16
  77. package/dist/fiat/providers/index.d.ts.map +0 -1
  78. package/dist/fiat/providers/index.js +0 -30
  79. package/dist/fiat/providers/index.js.map +0 -1
  80. package/dist/fiat/providers/moonpay.d.ts +0 -22
  81. package/dist/fiat/providers/moonpay.d.ts.map +0 -1
  82. package/dist/fiat/providers/moonpay.js +0 -107
  83. package/dist/fiat/providers/moonpay.js.map +0 -1
  84. package/dist/fiat/providers/stripe.d.ts +0 -26
  85. package/dist/fiat/providers/stripe.d.ts.map +0 -1
  86. package/dist/fiat/providers/stripe.js +0 -135
  87. package/dist/fiat/providers/stripe.js.map +0 -1
  88. package/dist/fiat/providers/transak.d.ts +0 -26
  89. package/dist/fiat/providers/transak.d.ts.map +0 -1
  90. package/dist/fiat/providers/transak.js +0 -119
  91. package/dist/fiat/providers/transak.js.map +0 -1
  92. package/dist/fiat/types.d.ts +0 -106
  93. package/dist/fiat/types.d.ts.map +0 -1
  94. package/dist/fiat/types.js +0 -13
  95. package/dist/fiat/types.js.map +0 -1
  96. package/dist/flash/executor.d.ts +0 -119
  97. package/dist/flash/executor.d.ts.map +0 -1
  98. package/dist/flash/executor.js +0 -195
  99. package/dist/flash/executor.js.map +0 -1
  100. package/dist/flash/index.d.ts +0 -28
  101. package/dist/flash/index.d.ts.map +0 -1
  102. package/dist/flash/index.js +0 -29
  103. package/dist/flash/index.js.map +0 -1
  104. package/dist/flash/scanner.d.ts +0 -133
  105. package/dist/flash/scanner.d.ts.map +0 -1
  106. package/dist/flash/scanner.js +0 -212
  107. package/dist/flash/scanner.js.map +0 -1
  108. package/dist/flash/types.d.ts +0 -136
  109. package/dist/flash/types.d.ts.map +0 -1
  110. package/dist/flash/types.js +0 -23
  111. package/dist/flash/types.js.map +0 -1
  112. package/dist/gas/index.d.ts +0 -4
  113. package/dist/gas/index.d.ts.map +0 -1
  114. package/dist/gas/index.js +0 -3
  115. package/dist/gas/index.js.map +0 -1
  116. package/dist/gas/sponsor.d.ts +0 -70
  117. package/dist/gas/sponsor.d.ts.map +0 -1
  118. package/dist/gas/sponsor.js +0 -193
  119. package/dist/gas/sponsor.js.map +0 -1
  120. package/dist/gas/types.d.ts +0 -76
  121. package/dist/gas/types.d.ts.map +0 -1
  122. package/dist/gas/types.js +0 -21
  123. package/dist/gas/types.js.map +0 -1
  124. package/dist/identity/agent-identity.d.ts +0 -276
  125. package/dist/identity/agent-identity.d.ts.map +0 -1
  126. package/dist/identity/agent-identity.js +0 -300
  127. package/dist/identity/agent-identity.js.map +0 -1
  128. package/dist/identity/email-resolver.d.ts +0 -235
  129. package/dist/identity/email-resolver.js +0 -283
  130. package/dist/identity/erc6551.d.ts +0 -441
  131. package/dist/identity/erc6551.d.ts.map +0 -1
  132. package/dist/identity/erc6551.js +0 -517
  133. package/dist/identity/erc6551.js.map +0 -1
  134. package/dist/mev/index.d.ts +0 -4
  135. package/dist/mev/index.d.ts.map +0 -1
  136. package/dist/mev/index.js +0 -8
  137. package/dist/mev/index.js.map +0 -1
  138. package/dist/mev/protection.d.ts +0 -54
  139. package/dist/mev/protection.d.ts.map +0 -1
  140. package/dist/mev/protection.js +0 -185
  141. package/dist/mev/protection.js.map +0 -1
  142. package/dist/mev/risk.d.ts +0 -19
  143. package/dist/mev/risk.d.ts.map +0 -1
  144. package/dist/mev/risk.js +0 -95
  145. package/dist/mev/risk.js.map +0 -1
  146. package/dist/mev/types.d.ts +0 -49
  147. package/dist/mev/types.d.ts.map +0 -1
  148. package/dist/mev/types.js +0 -2
  149. package/dist/mev/types.js.map +0 -1
  150. package/dist/settlement/index.d.ts +0 -4
  151. package/dist/settlement/index.d.ts.map +0 -1
  152. package/dist/settlement/index.js +0 -3
  153. package/dist/settlement/index.js.map +0 -1
  154. package/dist/settlement/types.d.ts +0 -66
  155. package/dist/settlement/types.d.ts.map +0 -1
  156. package/dist/settlement/types.js +0 -37
  157. package/dist/settlement/types.js.map +0 -1
  158. package/dist/settlement/verifier.d.ts +0 -75
  159. package/dist/settlement/verifier.d.ts.map +0 -1
  160. package/dist/settlement/verifier.js +0 -354
  161. package/dist/settlement/verifier.js.map +0 -1
  162. package/dist/solana/bridge.d.ts +0 -144
  163. package/dist/solana/bridge.d.ts.map +0 -1
  164. package/dist/solana/bridge.js +0 -352
  165. package/dist/solana/bridge.js.map +0 -1
  166. package/dist/solana/index.d.ts +0 -8
  167. package/dist/solana/index.d.ts.map +0 -1
  168. package/dist/solana/index.js +0 -6
  169. package/dist/solana/index.js.map +0 -1
  170. package/dist/solana/swap.d.ts +0 -85
  171. package/dist/solana/swap.d.ts.map +0 -1
  172. package/dist/solana/swap.js +0 -173
  173. package/dist/solana/swap.js.map +0 -1
  174. package/dist/solana/types.d.ts +0 -126
  175. package/dist/solana/types.d.ts.map +0 -1
  176. package/dist/solana/types.js +0 -10
  177. package/dist/solana/types.js.map +0 -1
  178. package/dist/solana/wallet.d.ts +0 -83
  179. package/dist/solana/wallet.d.ts.map +0 -1
  180. package/dist/solana/wallet.js +0 -164
  181. package/dist/solana/wallet.js.map +0 -1
  182. package/dist/solana/x402.d.ts +0 -69
  183. package/dist/solana/x402.d.ts.map +0 -1
  184. package/dist/solana/x402.js +0 -154
  185. package/dist/solana/x402.js.map +0 -1
  186. package/dist/solver/adapter.d.ts +0 -47
  187. package/dist/solver/adapter.d.ts.map +0 -1
  188. package/dist/solver/adapter.js +0 -146
  189. package/dist/solver/adapter.js.map +0 -1
  190. package/dist/solver/analyzer.d.ts +0 -48
  191. package/dist/solver/analyzer.d.ts.map +0 -1
  192. package/dist/solver/analyzer.js +0 -171
  193. package/dist/solver/analyzer.js.map +0 -1
  194. package/dist/solver/builder.d.ts +0 -31
  195. package/dist/solver/builder.d.ts.map +0 -1
  196. package/dist/solver/builder.js +0 -60
  197. package/dist/solver/builder.js.map +0 -1
  198. package/dist/solver/index.d.ts +0 -22
  199. package/dist/solver/index.d.ts.map +0 -1
  200. package/dist/solver/index.js +0 -25
  201. package/dist/solver/index.js.map +0 -1
  202. package/dist/solver/types.d.ts +0 -115
  203. package/dist/solver/types.d.ts.map +0 -1
  204. package/dist/solver/types.js +0 -10
  205. package/dist/solver/types.js.map +0 -1
  206. package/dist/spend-guard/index.d.ts +0 -125
  207. package/dist/spend-guard/index.d.ts.map +0 -1
  208. package/dist/spend-guard/index.js +0 -150
  209. package/dist/spend-guard/index.js.map +0 -1
  210. package/dist/swap/router/cache.d.ts +0 -13
  211. package/dist/swap/router/cache.d.ts.map +0 -1
  212. package/dist/swap/router/cache.js +0 -30
  213. package/dist/swap/router/cache.js.map +0 -1
  214. package/dist/swap/router/flashbots.d.ts +0 -10
  215. package/dist/swap/router/flashbots.d.ts.map +0 -1
  216. package/dist/swap/router/flashbots.js +0 -43
  217. package/dist/swap/router/flashbots.js.map +0 -1
  218. package/dist/swap/router/health.d.ts +0 -17
  219. package/dist/swap/router/health.d.ts.map +0 -1
  220. package/dist/swap/router/health.js +0 -38
  221. package/dist/swap/router/health.js.map +0 -1
  222. package/dist/swap/router/index.d.ts +0 -10
  223. package/dist/swap/router/index.d.ts.map +0 -1
  224. package/dist/swap/router/index.js +0 -10
  225. package/dist/swap/router/index.js.map +0 -1
  226. package/dist/swap/router/providers/cowswap.d.ts +0 -11
  227. package/dist/swap/router/providers/cowswap.d.ts.map +0 -1
  228. package/dist/swap/router/providers/cowswap.js +0 -79
  229. package/dist/swap/router/providers/cowswap.js.map +0 -1
  230. package/dist/swap/router/providers/index.d.ts +0 -20
  231. package/dist/swap/router/providers/index.d.ts.map +0 -1
  232. package/dist/swap/router/providers/index.js +0 -32
  233. package/dist/swap/router/providers/index.js.map +0 -1
  234. package/dist/swap/router/providers/jupiter.d.ts +0 -12
  235. package/dist/swap/router/providers/jupiter.d.ts.map +0 -1
  236. package/dist/swap/router/providers/jupiter.js +0 -73
  237. package/dist/swap/router/providers/jupiter.js.map +0 -1
  238. package/dist/swap/router/providers/lifi.d.ts +0 -11
  239. package/dist/swap/router/providers/lifi.d.ts.map +0 -1
  240. package/dist/swap/router/providers/lifi.js +0 -123
  241. package/dist/swap/router/providers/lifi.js.map +0 -1
  242. package/dist/swap/router/providers/oneinch.d.ts +0 -13
  243. package/dist/swap/router/providers/oneinch.d.ts.map +0 -1
  244. package/dist/swap/router/providers/oneinch.js +0 -71
  245. package/dist/swap/router/providers/oneinch.js.map +0 -1
  246. package/dist/swap/router/providers/paraswap.d.ts +0 -11
  247. package/dist/swap/router/providers/paraswap.d.ts.map +0 -1
  248. package/dist/swap/router/providers/paraswap.js +0 -73
  249. package/dist/swap/router/providers/paraswap.js.map +0 -1
  250. package/dist/swap/router/providers/uniswap.d.ts +0 -31
  251. package/dist/swap/router/providers/uniswap.d.ts.map +0 -1
  252. package/dist/swap/router/providers/uniswap.js +0 -237
  253. package/dist/swap/router/providers/uniswap.js.map +0 -1
  254. package/dist/swap/router/providers/zerox.d.ts +0 -13
  255. package/dist/swap/router/providers/zerox.d.ts.map +0 -1
  256. package/dist/swap/router/providers/zerox.js +0 -94
  257. package/dist/swap/router/providers/zerox.js.map +0 -1
  258. package/dist/swap/router/router.d.ts +0 -86
  259. package/dist/swap/router/router.d.ts.map +0 -1
  260. package/dist/swap/router/router.js +0 -224
  261. package/dist/swap/router/router.js.map +0 -1
  262. package/dist/swap/router/rsi/engine.d.ts +0 -60
  263. package/dist/swap/router/rsi/engine.d.ts.map +0 -1
  264. package/dist/swap/router/rsi/engine.js +0 -483
  265. package/dist/swap/router/rsi/engine.js.map +0 -1
  266. package/dist/swap/router/rsi/index.d.ts +0 -3
  267. package/dist/swap/router/rsi/index.d.ts.map +0 -1
  268. package/dist/swap/router/rsi/index.js +0 -3
  269. package/dist/swap/router/rsi/index.js.map +0 -1
  270. package/dist/swap/router/rsi/types.d.ts +0 -106
  271. package/dist/swap/router/rsi/types.d.ts.map +0 -1
  272. package/dist/swap/router/rsi/types.js +0 -3
  273. package/dist/swap/router/rsi/types.js.map +0 -1
  274. package/dist/swap/router/types.d.ts +0 -120
  275. package/dist/swap/router/types.d.ts.map +0 -1
  276. package/dist/swap/router/types.js +0 -16
  277. package/dist/swap/router/types.js.map +0 -1
  278. package/dist/tax/engine.d.ts +0 -131
  279. package/dist/tax/engine.d.ts.map +0 -1
  280. package/dist/tax/engine.js +0 -307
  281. package/dist/tax/engine.js.map +0 -1
  282. package/dist/tax/index.d.ts +0 -9
  283. package/dist/tax/index.d.ts.map +0 -1
  284. package/dist/tax/index.js +0 -12
  285. package/dist/tax/index.js.map +0 -1
  286. package/dist/tax/lots.d.ts +0 -60
  287. package/dist/tax/lots.d.ts.map +0 -1
  288. package/dist/tax/lots.js +0 -129
  289. package/dist/tax/lots.js.map +0 -1
  290. package/dist/tax/types.d.ts +0 -113
  291. package/dist/tax/types.d.ts.map +0 -1
  292. package/dist/tax/types.js +0 -18
  293. package/dist/tax/types.js.map +0 -1
  294. package/dist/verifiable-intent/index.d.ts +0 -84
  295. package/dist/verifiable-intent/index.js +0 -385
  296. package/dist/yield/index.d.ts +0 -26
  297. package/dist/yield/index.d.ts.map +0 -1
  298. package/dist/yield/index.js +0 -29
  299. package/dist/yield/index.js.map +0 -1
  300. package/dist/yield/rates.d.ts +0 -114
  301. package/dist/yield/rates.d.ts.map +0 -1
  302. package/dist/yield/rates.js +0 -351
  303. package/dist/yield/rates.js.map +0 -1
  304. package/dist/yield/types.d.ts +0 -134
  305. package/dist/yield/types.d.ts.map +0 -1
  306. package/dist/yield/types.js +0 -24
  307. package/dist/yield/types.js.map +0 -1
  308. package/dist/yield/vault.d.ts +0 -112
  309. package/dist/yield/vault.d.ts.map +0 -1
  310. package/dist/yield/vault.js +0 -264
  311. package/dist/yield/vault.js.map +0 -1
@@ -1,385 +0,0 @@
1
- /**
2
- * VerifiableIntent — Mastercard Verifiable Intent implementation for agentwallet-sdk
3
- *
4
- * Implements the Mastercard Verifiable Intent open standard (March 2026):
5
- * - Create signed intent declarations for agent transactions
6
- * - Verify intent signatures and scope constraints
7
- * - Enforce spending caps, time windows, and merchant category limits
8
- * - Compatible with Google AP2 (Agent Payments Protocol)
9
- *
10
- * The spec defines four pillars:
11
- * 1. Agent Identity — unique Agentic Token per agent
12
- * 2. Intent Declaration — structured payload describing the transaction
13
- * 3. Authorization Chain — proof of human/system delegation
14
- * 4. Scope Limits — spending caps, time windows, merchant categories
15
- *
16
- * @module verifiable-intent
17
- */
18
-
19
- import { createHash, createHmac, randomUUID } from 'crypto';
20
-
21
- // ---------------------------------------------------------------------------
22
- // Types
23
- // ---------------------------------------------------------------------------
24
-
25
- /**
26
- * @typedef {Object} AgentIdentity
27
- * @property {string} agentId - Unique agent identifier (UUID or DID)
28
- * @property {string} principalId - Human/system that delegated authority
29
- * @property {string} agenticToken - Signed token proving agent registration
30
- * @property {number} issuedAt - Unix timestamp of token issuance
31
- * @property {number} expiresAt - Unix timestamp of token expiry
32
- */
33
-
34
- /**
35
- * @typedef {Object} ScopeConstraints
36
- * @property {number} maxAmountPerTx - Maximum amount per single transaction (in minor units)
37
- * @property {number} maxAmountPerDay - Maximum cumulative daily spend (in minor units)
38
- * @property {number} maxTxPerDay - Maximum number of transactions per day
39
- * @property {string[]} [allowedMerchantCategories] - MCC codes the agent can transact with
40
- * @property {string[]} [allowedCurrencies] - ISO 4217 currency codes permitted
41
- * @property {number} [windowStartUtc] - Unix timestamp: scope validity start
42
- * @property {number} [windowEndUtc] - Unix timestamp: scope validity end
43
- */
44
-
45
- /**
46
- * @typedef {Object} IntentDeclaration
47
- * @property {string} intentId - Unique ID for this intent (UUID v4)
48
- * @property {string} agentId - Agent making the request
49
- * @property {string} action - What the agent wants to do ('pay', 'subscribe', 'escrow', 'refund')
50
- * @property {number} amount - Transaction amount in minor units
51
- * @property {string} currency - ISO 4217 currency code
52
- * @property {string} recipientId - Merchant/service/agent receiving payment
53
- * @property {string} description - Human-readable purpose
54
- * @property {number} createdAt - Unix timestamp
55
- * @property {number} expiresAt - Unix timestamp when intent becomes invalid
56
- * @property {Object} [metadata] - Additional key-value pairs
57
- */
58
-
59
- /**
60
- * @typedef {Object} SignedIntent
61
- * @property {IntentDeclaration} intent - The intent payload
62
- * @property {string} signature - HMAC-SHA256 signature of the canonical intent
63
- * @property {string} agenticToken - The agent's identity token
64
- * @property {string} signatureAlgorithm - Always 'HMAC-SHA256' in this implementation
65
- */
66
-
67
- /**
68
- * @typedef {Object} VerificationResult
69
- * @property {boolean} valid - Whether the intent passes all checks
70
- * @property {string[]} errors - List of validation failures (empty if valid)
71
- */
72
-
73
- // ---------------------------------------------------------------------------
74
- // Core Implementation
75
- // ---------------------------------------------------------------------------
76
-
77
- /**
78
- * VerifiableIntentClient — Create, sign, and verify Mastercard Verifiable Intent payloads.
79
- *
80
- * @example
81
- * ```typescript
82
- * const vi = new VerifiableIntentClient({
83
- * agentId: 'agent-001',
84
- * principalId: 'user-bill',
85
- * signingSecret: process.env.AGENT_SIGNING_SECRET,
86
- * scope: {
87
- * maxAmountPerTx: 10000, // $100.00
88
- * maxAmountPerDay: 50000, // $500.00
89
- * maxTxPerDay: 20,
90
- * allowedCurrencies: ['USD', 'EUR'],
91
- * }
92
- * });
93
- *
94
- * const signed = vi.createIntent({
95
- * action: 'pay',
96
- * amount: 5000,
97
- * currency: 'USD',
98
- * recipientId: 'merchant-xyz',
99
- * description: 'API compute credits',
100
- * });
101
- *
102
- * const result = vi.verify(signed);
103
- * // { valid: true, errors: [] }
104
- * ```
105
- */
106
- export class VerifiableIntentClient {
107
- /**
108
- * @param {Object} config
109
- * @param {string} config.agentId - Unique agent identifier
110
- * @param {string} config.principalId - Human/system principal who delegated authority
111
- * @param {string} config.signingSecret - Secret key for HMAC signing (min 32 chars)
112
- * @param {ScopeConstraints} config.scope - Spending and authorization constraints
113
- * @param {number} [config.tokenTtlSeconds=86400] - Agentic token lifetime (default 24h)
114
- * @param {number} [config.intentTtlSeconds=300] - Intent validity window (default 5 min)
115
- */
116
- constructor(config) {
117
- if (!config.signingSecret || config.signingSecret.length < 32) {
118
- throw new VerifiableIntentError('signingSecret must be at least 32 characters');
119
- }
120
- this.agentId = config.agentId;
121
- this.principalId = config.principalId;
122
- this.signingSecret = config.signingSecret;
123
- this.scope = config.scope;
124
- this.tokenTtlSeconds = config.tokenTtlSeconds ?? 86400;
125
- this.intentTtlSeconds = config.intentTtlSeconds ?? 300;
126
-
127
- // Daily tracking for scope enforcement
128
- this._dailySpend = 0;
129
- this._dailyTxCount = 0;
130
- this._dailyResetDate = this._todayUtc();
131
-
132
- // Generate agentic token on initialization
133
- this.identity = this._issueAgenticToken();
134
- }
135
-
136
- /**
137
- * Create and sign a Verifiable Intent declaration.
138
- *
139
- * @param {Object} params
140
- * @param {string} params.action - 'pay' | 'subscribe' | 'escrow' | 'refund'
141
- * @param {number} params.amount - Amount in minor units (cents)
142
- * @param {string} params.currency - ISO 4217 currency code
143
- * @param {string} params.recipientId - Recipient identifier
144
- * @param {string} params.description - Human-readable purpose
145
- * @param {Object} [params.metadata] - Additional context
146
- * @returns {SignedIntent}
147
- */
148
- createIntent(params) {
149
- const now = Math.floor(Date.now() / 1000);
150
-
151
- // Check token validity
152
- if (now >= this.identity.expiresAt) {
153
- this.identity = this._issueAgenticToken();
154
- }
155
-
156
- const intent = {
157
- intentId: randomUUID(),
158
- agentId: this.agentId,
159
- action: params.action,
160
- amount: params.amount,
161
- currency: params.currency,
162
- recipientId: params.recipientId,
163
- description: params.description,
164
- createdAt: now,
165
- expiresAt: now + this.intentTtlSeconds,
166
- metadata: params.metadata ?? {},
167
- };
168
-
169
- // Pre-sign scope validation
170
- const scopeCheck = this._checkScope(intent);
171
- if (!scopeCheck.valid) {
172
- throw new VerifiableIntentError(
173
- `Intent blocked by scope constraints: ${scopeCheck.errors.join(', ')}`
174
- );
175
- }
176
-
177
- const canonical = this._canonicalize(intent);
178
- const signature = this._sign(canonical);
179
-
180
- return {
181
- intent,
182
- signature,
183
- agenticToken: this.identity.agenticToken,
184
- signatureAlgorithm: 'HMAC-SHA256',
185
- };
186
- }
187
-
188
- /**
189
- * Verify a signed intent declaration.
190
- *
191
- * Checks:
192
- * 1. Signature validity (HMAC-SHA256)
193
- * 2. Intent not expired
194
- * 3. Agent identity matches
195
- * 4. Scope constraints satisfied
196
- *
197
- * @param {SignedIntent} signedIntent
198
- * @returns {VerificationResult}
199
- */
200
- verify(signedIntent) {
201
- const errors = [];
202
- const { intent, signature, agenticToken } = signedIntent;
203
- const now = Math.floor(Date.now() / 1000);
204
-
205
- // 1. Signature check
206
- const canonical = this._canonicalize(intent);
207
- const expectedSig = this._sign(canonical);
208
- if (signature !== expectedSig) {
209
- errors.push('Invalid signature');
210
- }
211
-
212
- // 2. Expiry check
213
- if (now >= intent.expiresAt) {
214
- errors.push(`Intent expired at ${new Date(intent.expiresAt * 1000).toISOString()}`);
215
- }
216
-
217
- // 3. Agent identity check
218
- if (intent.agentId !== this.agentId) {
219
- errors.push(`Agent ID mismatch: expected ${this.agentId}, got ${intent.agentId}`);
220
- }
221
-
222
- // 4. Agentic token check
223
- if (agenticToken !== this.identity.agenticToken) {
224
- errors.push('Agentic token mismatch or expired');
225
- }
226
-
227
- // 5. Scope constraints
228
- const scopeResult = this._checkScope(intent);
229
- errors.push(...scopeResult.errors);
230
-
231
- return { valid: errors.length === 0, errors };
232
- }
233
-
234
- /**
235
- * Record a completed transaction against daily limits.
236
- * Call this after a verified intent is successfully executed.
237
- *
238
- * @param {SignedIntent} signedIntent - The executed intent
239
- */
240
- recordExecution(signedIntent) {
241
- this._resetDailyIfNeeded();
242
- this._dailySpend += signedIntent.intent.amount;
243
- this._dailyTxCount += 1;
244
- }
245
-
246
- /**
247
- * Get current daily usage against scope limits.
248
- *
249
- * @returns {{ spentToday: number, txToday: number, remainingBudget: number, remainingTx: number }}
250
- */
251
- getDailyUsage() {
252
- this._resetDailyIfNeeded();
253
- return {
254
- spentToday: this._dailySpend,
255
- txToday: this._dailyTxCount,
256
- remainingBudget: Math.max(0, this.scope.maxAmountPerDay - this._dailySpend),
257
- remainingTx: Math.max(0, this.scope.maxTxPerDay - this._dailyTxCount),
258
- };
259
- }
260
-
261
- /**
262
- * Serialize a signed intent to a portable JSON string for transmission.
263
- *
264
- * @param {SignedIntent} signedIntent
265
- * @returns {string} JSON string
266
- */
267
- static serialize(signedIntent) {
268
- return JSON.stringify(signedIntent);
269
- }
270
-
271
- /**
272
- * Deserialize a JSON string back to a SignedIntent object.
273
- *
274
- * @param {string} json
275
- * @returns {SignedIntent}
276
- */
277
- static deserialize(json) {
278
- const parsed = JSON.parse(json);
279
- if (!parsed.intent || !parsed.signature || !parsed.agenticToken) {
280
- throw new VerifiableIntentError('Invalid SignedIntent structure');
281
- }
282
- return parsed;
283
- }
284
-
285
- // -------------------------------------------------------------------------
286
- // Private methods
287
- // -------------------------------------------------------------------------
288
-
289
- _issueAgenticToken() {
290
- const now = Math.floor(Date.now() / 1000);
291
- const payload = `${this.agentId}:${this.principalId}:${now}`;
292
- const token = createHmac('sha256', this.signingSecret)
293
- .update(payload)
294
- .digest('hex');
295
- return {
296
- agentId: this.agentId,
297
- principalId: this.principalId,
298
- agenticToken: token,
299
- issuedAt: now,
300
- expiresAt: now + this.tokenTtlSeconds,
301
- };
302
- }
303
-
304
- _canonicalize(intent) {
305
- // Deterministic JSON serialization: sorted keys, no whitespace
306
- const ordered = {
307
- action: intent.action,
308
- agentId: intent.agentId,
309
- amount: intent.amount,
310
- createdAt: intent.createdAt,
311
- currency: intent.currency,
312
- description: intent.description,
313
- expiresAt: intent.expiresAt,
314
- intentId: intent.intentId,
315
- metadata: intent.metadata,
316
- recipientId: intent.recipientId,
317
- };
318
- return JSON.stringify(ordered);
319
- }
320
-
321
- _sign(canonical) {
322
- return createHmac('sha256', this.signingSecret)
323
- .update(canonical)
324
- .digest('hex');
325
- }
326
-
327
- _checkScope(intent) {
328
- const errors = [];
329
- this._resetDailyIfNeeded();
330
-
331
- if (intent.amount > this.scope.maxAmountPerTx) {
332
- errors.push(`Amount ${intent.amount} exceeds per-tx limit ${this.scope.maxAmountPerTx}`);
333
- }
334
-
335
- if (this._dailySpend + intent.amount > this.scope.maxAmountPerDay) {
336
- errors.push(
337
- `Daily spend would be ${this._dailySpend + intent.amount}, exceeds limit ${this.scope.maxAmountPerDay}`
338
- );
339
- }
340
-
341
- if (this._dailyTxCount + 1 > this.scope.maxTxPerDay) {
342
- errors.push(`Daily tx count would exceed limit ${this.scope.maxTxPerDay}`);
343
- }
344
-
345
- if (this.scope.allowedCurrencies && !this.scope.allowedCurrencies.includes(intent.currency)) {
346
- errors.push(`Currency ${intent.currency} not in allowed list: ${this.scope.allowedCurrencies.join(', ')}`);
347
- }
348
-
349
- const now = Math.floor(Date.now() / 1000);
350
- if (this.scope.windowStartUtc && now < this.scope.windowStartUtc) {
351
- errors.push('Current time is before scope validity window');
352
- }
353
- if (this.scope.windowEndUtc && now >= this.scope.windowEndUtc) {
354
- errors.push('Current time is past scope validity window');
355
- }
356
-
357
- return { valid: errors.length === 0, errors };
358
- }
359
-
360
- _todayUtc() {
361
- return new Date().toISOString().slice(0, 10);
362
- }
363
-
364
- _resetDailyIfNeeded() {
365
- const today = this._todayUtc();
366
- if (today !== this._dailyResetDate) {
367
- this._dailySpend = 0;
368
- this._dailyTxCount = 0;
369
- this._dailyResetDate = today;
370
- }
371
- }
372
- }
373
-
374
- // ---------------------------------------------------------------------------
375
- // Error class
376
- // ---------------------------------------------------------------------------
377
-
378
- export class VerifiableIntentError extends Error {
379
- constructor(message, context) {
380
- super(message);
381
- this.context = context;
382
- this.name = 'VerifiableIntentError';
383
- }
384
- }
385
- //# sourceMappingURL=index.js.map
@@ -1,26 +0,0 @@
1
- /**
2
- * Yield Vault Module
3
- *
4
- * Puts idle agent capital to work across DeFi vaults and RWA tokens.
5
- *
6
- * Quick start:
7
- * import { YieldVault, YieldRateFetcher } from './yield/index.js';
8
- *
9
- * const vault = new YieldVault({ enabled: true });
10
- * const opportunities = await vault.scan({ token: 'USDC', amountUsd: 10_000 });
11
- * const best = opportunities.find(o => o.viable);
12
- * if (best) {
13
- * const tx = vault.buildDepositTx({
14
- * protocol: best.best.protocol,
15
- * token: 'USDC',
16
- * amount: 10_000_000_000n, // 10k USDC (6 decimals)
17
- * chain: best.best.chain,
18
- * walletAddress: '0xYourAgentWallet',
19
- * });
20
- * // agent signs + sends tx
21
- * }
22
- */
23
- export { YieldVault } from './vault.js';
24
- export { YieldRateFetcher, PROTOCOL_ADDRESSES } from './rates.js';
25
- export type { YieldProtocol, YieldCategory, YieldPosition, YieldRate, YieldOpportunity, YieldVaultConfig, DepositResult, WithdrawResult, } from './types.js';
26
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/yield/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAElE,YAAY,EACV,aAAa,EACb,aAAa,EACb,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC"}
@@ -1,29 +0,0 @@
1
- /**
2
- * @premium This module is part of AgentWallet Premium.
3
- * Contact: https://github.com/up2itnow/AgentNexus2 for access.
4
- */
5
- /**
6
- * Yield Vault Module
7
- *
8
- * Puts idle agent capital to work across DeFi vaults and RWA tokens.
9
- *
10
- * Quick start:
11
- * import { YieldVault, YieldRateFetcher } from './yield/index.js';
12
- *
13
- * const vault = new YieldVault({ enabled: true });
14
- * const opportunities = await vault.scan({ token: 'USDC', amountUsd: 10_000 });
15
- * const best = opportunities.find(o => o.viable);
16
- * if (best) {
17
- * const tx = vault.buildDepositTx({
18
- * protocol: best.best.protocol,
19
- * token: 'USDC',
20
- * amount: 10_000_000_000n, // 10k USDC (6 decimals)
21
- * chain: best.best.chain,
22
- * walletAddress: '0xYourAgentWallet',
23
- * });
24
- * // agent signs + sends tx
25
- * }
26
- */
27
- export { YieldVault } from './vault.js';
28
- export { YieldRateFetcher, PROTOCOL_ADDRESSES } from './rates.js';
29
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/yield/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
@@ -1,114 +0,0 @@
1
- /**
2
- * Yield Rate Fetcher
3
- *
4
- * Fetches current APY rates from DeFi protocols and RWA token sources.
5
- * When a provider is not supplied (tests, offline, no RPC), returns accurate
6
- * mock rates based on current market conditions (~Q1 2026).
7
- *
8
- * DeFi risk scores (0-100, lower = safer):
9
- * Aave V3: 15 — battle-tested, billions TVL, audited
10
- * Compound V3: 20 — mature, lower TVL than Aave
11
- * Morpho Blue: 25 — newer architecture, peer-to-peer matching
12
- *
13
- * RWA risk scores:
14
- * USDC-collateralized RWA: 10–20 (T-bill backed, regulated issuers)
15
- */
16
- import { ethers } from 'ethers';
17
- import type { YieldRate, YieldVaultConfig } from './types.js';
18
- export declare const PROTOCOL_ADDRESSES: {
19
- readonly 'aave-v3': {
20
- readonly ethereum: {
21
- readonly pool: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2";
22
- readonly dataProvider: "0x7B4EB56E7CD4b454BA8ff71E4518426369a138a3";
23
- };
24
- readonly base: {
25
- readonly pool: "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5";
26
- readonly dataProvider: "0x2d8A3C5677189723C4cB8873CfC9C8976ddf54D8";
27
- };
28
- readonly arbitrum: {
29
- readonly pool: "0x794a61358D6845594F94dc1DB02A252b5b4814aD";
30
- readonly dataProvider: "0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654";
31
- };
32
- };
33
- readonly 'compound-v3': {
34
- readonly ethereum: {
35
- readonly comet: "0xc3d688B66703497DAA19211EEdff47f25384cdc3";
36
- };
37
- readonly base: {
38
- readonly comet: "0xb125E6687d4313864e53df431d5425969c15Eb2";
39
- };
40
- readonly arbitrum: {
41
- readonly comet: "0x9c4ec768c28520B50860ea7a15bd7213a9fF58bf";
42
- };
43
- };
44
- readonly usdy: {
45
- readonly ethereum: {
46
- readonly token: "0x96F6eF951840721AdBF7B6A2Ce4A795F61F8f60a";
47
- };
48
- readonly arbitrum: {
49
- readonly token: "0x7fAb54cb9d83BDAF0e94b1C2bA96F64Fb7D86b7A";
50
- };
51
- };
52
- };
53
- export declare class YieldRateFetcher {
54
- /**
55
- * Fetch current supply APY for Aave V3.
56
- *
57
- * On-chain: queries getReserveData() on the Aave Data Provider.
58
- * currentLiquidityRate is in ray format (1e27 = 100% APY).
59
- * APY = (1 + rate / 1e27 / SECONDS_PER_YEAR)^SECONDS_PER_YEAR - 1
60
- *
61
- * Falls back to accurate mock rates when provider is not available.
62
- *
63
- * Risk score: 15 (battle-tested, billions TVL, multiple audits)
64
- */
65
- fetchAaveRate(token: string, chain: string, provider?: ethers.JsonRpcProvider): Promise<YieldRate>;
66
- /**
67
- * Fetch current supply APY for Compound V3.
68
- *
69
- * On-chain: calls getSupplyRate(utilization) on the Comet contract.
70
- * supplyRate is per-second (18 decimals).
71
- * APY = (1 + supplyRate / 1e18)^SECONDS_PER_YEAR - 1
72
- *
73
- * Risk score: 20 (mature protocol, lower TVL than Aave)
74
- */
75
- fetchCompoundRate(token: string, chain: string, provider?: ethers.JsonRpcProvider): Promise<YieldRate>;
76
- /**
77
- * Fetch APY for Morpho Blue.
78
- *
79
- * Morpho Blue uses peer-to-peer rate matching — on-chain query is complex
80
- * (varies per market). We use well-calibrated estimates based on current
81
- * market conditions. Real implementation would query Morpho's API or
82
- * aggregate across market IDs.
83
- *
84
- * Risk score: 25 (newer architecture, audited, growing TVL)
85
- */
86
- fetchMorphoRate(token: string, chain: string, _provider?: ethers.JsonRpcProvider): Promise<YieldRate>;
87
- /**
88
- * Get current RWA token rates.
89
- *
90
- * RWA tokens are backed by tokenized T-bills and short-duration government bonds.
91
- * Rates (~4.8–5.2% APY as of Q1 2026) track the Fed Funds rate.
92
- *
93
- * Agent-friendliness matrix:
94
- * ┌──────────┬──────────────┬───────────┬───────────────────────────────────┐
95
- * │ Protocol │ KYC Required │ Min Dep. │ Chains │
96
- * ├──────────┼──────────────┼───────────┼───────────────────────────────────┤
97
- * │ BUIDL │ ✅ YES │ $1,000,000│ Ethereum only │
98
- * │ OUSG │ ✅ YES │ ~$5,000 │ Ethereum, Base │
99
- * │ USDY │ ❌ NO │ ~$500 │ Ethereum, Arbitrum (best for bots)│
100
- * │ USYC │ ❌ NO │ ~$1,000 │ Ethereum, Base │
101
- * │ wUSTB │ ❌ NO │ ~$100 │ Ethereum │
102
- * └──────────┴──────────────┴───────────┴───────────────────────────────────┘
103
- *
104
- * ⚠️ BUIDL: $1M minimum is a HARD requirement. Do not recommend to retail agents.
105
- */
106
- fetchRWARates(chains: string[]): Promise<YieldRate[]>;
107
- /**
108
- * Fetch all rates across DeFi protocols and RWA tokens.
109
- * Applies config filters (KYC, chains, tokens).
110
- * Returns sorted by APY descending.
111
- */
112
- fetchAllRates(config: YieldVaultConfig): Promise<YieldRate[]>;
113
- }
114
- //# sourceMappingURL=rates.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rates.d.ts","sourceRoot":"","sources":["../../src/yield/rates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAI9D,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwBrB,CAAC;AAsDX,qBAAa,gBAAgB;IAC3B;;;;;;;;;;OAUG;IACG,aAAa,CACjB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,CAAC,eAAe,GAChC,OAAO,CAAC,SAAS,CAAC;IAuCrB;;;;;;;;OAQG;IACG,iBAAiB,CACrB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,CAAC,eAAe,GAChC,OAAO,CAAC,SAAS,CAAC;IAoCrB;;;;;;;;;OASG;IACG,eAAe,CACnB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,CAAC,eAAe,GACjC,OAAO,CAAC,SAAS,CAAC;IAmBrB;;;;;;;;;;;;;;;;;;OAkBG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAgG3D;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;CAsCpE"}