@seedhape/core 0.1.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 (133) hide show
  1. package/dist/__tests__/acp.test.d.ts +2 -0
  2. package/dist/__tests__/acp.test.d.ts.map +1 -0
  3. package/dist/__tests__/acp.test.js +16 -0
  4. package/dist/__tests__/acp.test.js.map +1 -0
  5. package/dist/__tests__/ap2-official.test.d.ts +2 -0
  6. package/dist/__tests__/ap2-official.test.d.ts.map +1 -0
  7. package/dist/__tests__/ap2-official.test.js +49 -0
  8. package/dist/__tests__/ap2-official.test.js.map +1 -0
  9. package/dist/__tests__/mpp.test.d.ts +2 -0
  10. package/dist/__tests__/mpp.test.d.ts.map +1 -0
  11. package/dist/__tests__/mpp.test.js +42 -0
  12. package/dist/__tests__/mpp.test.js.map +1 -0
  13. package/dist/__tests__/outbound.test.d.ts +2 -0
  14. package/dist/__tests__/outbound.test.d.ts.map +1 -0
  15. package/dist/__tests__/outbound.test.js +23 -0
  16. package/dist/__tests__/outbound.test.js.map +1 -0
  17. package/dist/__tests__/protocols.test.d.ts +2 -0
  18. package/dist/__tests__/protocols.test.d.ts.map +1 -0
  19. package/dist/__tests__/protocols.test.js +16 -0
  20. package/dist/__tests__/protocols.test.js.map +1 -0
  21. package/dist/__tests__/providers.test.d.ts +2 -0
  22. package/dist/__tests__/providers.test.d.ts.map +1 -0
  23. package/dist/__tests__/providers.test.js +41 -0
  24. package/dist/__tests__/providers.test.js.map +1 -0
  25. package/dist/__tests__/reconciliation.test.d.ts +2 -0
  26. package/dist/__tests__/reconciliation.test.d.ts.map +1 -0
  27. package/dist/__tests__/reconciliation.test.js +35 -0
  28. package/dist/__tests__/reconciliation.test.js.map +1 -0
  29. package/dist/__tests__/spending-controls.test.d.ts +2 -0
  30. package/dist/__tests__/spending-controls.test.d.ts.map +1 -0
  31. package/dist/__tests__/spending-controls.test.js +47 -0
  32. package/dist/__tests__/spending-controls.test.js.map +1 -0
  33. package/dist/__tests__/tax-and-policy.test.d.ts +7 -0
  34. package/dist/__tests__/tax-and-policy.test.d.ts.map +1 -0
  35. package/dist/__tests__/tax-and-policy.test.js +389 -0
  36. package/dist/__tests__/tax-and-policy.test.js.map +1 -0
  37. package/dist/__tests__/web-bot-auth.test.d.ts +2 -0
  38. package/dist/__tests__/web-bot-auth.test.d.ts.map +1 -0
  39. package/dist/__tests__/web-bot-auth.test.js +33 -0
  40. package/dist/__tests__/web-bot-auth.test.js.map +1 -0
  41. package/dist/__tests__/x402-solana.test.d.ts +2 -0
  42. package/dist/__tests__/x402-solana.test.d.ts.map +1 -0
  43. package/dist/__tests__/x402-solana.test.js +155 -0
  44. package/dist/__tests__/x402-solana.test.js.map +1 -0
  45. package/dist/acp.d.ts +28 -0
  46. package/dist/acp.d.ts.map +1 -0
  47. package/dist/acp.js +49 -0
  48. package/dist/acp.js.map +1 -0
  49. package/dist/ap2/mandates.d.ts +319 -0
  50. package/dist/ap2/mandates.d.ts.map +1 -0
  51. package/dist/ap2/mandates.js +214 -0
  52. package/dist/ap2/mandates.js.map +1 -0
  53. package/dist/ap2/official.d.ts +156 -0
  54. package/dist/ap2/official.d.ts.map +1 -0
  55. package/dist/ap2/official.js +222 -0
  56. package/dist/ap2/official.js.map +1 -0
  57. package/dist/ap2/policy.d.ts +93 -0
  58. package/dist/ap2/policy.d.ts.map +1 -0
  59. package/dist/ap2/policy.js +216 -0
  60. package/dist/ap2/policy.js.map +1 -0
  61. package/dist/index.d.ts +22 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +22 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/india/fx.d.ts +59 -0
  66. package/dist/india/fx.d.ts.map +1 -0
  67. package/dist/india/fx.js +93 -0
  68. package/dist/india/fx.js.map +1 -0
  69. package/dist/india/vda-tax.d.ts +151 -0
  70. package/dist/india/vda-tax.d.ts.map +1 -0
  71. package/dist/india/vda-tax.js +226 -0
  72. package/dist/india/vda-tax.js.map +1 -0
  73. package/dist/mandate-builder.d.ts +102 -0
  74. package/dist/mandate-builder.d.ts.map +1 -0
  75. package/dist/mandate-builder.js +99 -0
  76. package/dist/mandate-builder.js.map +1 -0
  77. package/dist/mpp.d.ts +53 -0
  78. package/dist/mpp.d.ts.map +1 -0
  79. package/dist/mpp.js +164 -0
  80. package/dist/mpp.js.map +1 -0
  81. package/dist/orchestrator.d.ts +115 -0
  82. package/dist/orchestrator.d.ts.map +1 -0
  83. package/dist/orchestrator.js +351 -0
  84. package/dist/orchestrator.js.map +1 -0
  85. package/dist/postgres-store.d.ts +60 -0
  86. package/dist/postgres-store.d.ts.map +1 -0
  87. package/dist/postgres-store.js +441 -0
  88. package/dist/postgres-store.js.map +1 -0
  89. package/dist/protocols.d.ts +18 -0
  90. package/dist/protocols.d.ts.map +1 -0
  91. package/dist/protocols.js +24 -0
  92. package/dist/protocols.js.map +1 -0
  93. package/dist/reconciliation.d.ts +27 -0
  94. package/dist/reconciliation.d.ts.map +1 -0
  95. package/dist/reconciliation.js +38 -0
  96. package/dist/reconciliation.js.map +1 -0
  97. package/dist/store.d.ts +110 -0
  98. package/dist/store.d.ts.map +1 -0
  99. package/dist/store.js +369 -0
  100. package/dist/store.js.map +1 -0
  101. package/dist/types.d.ts +195 -0
  102. package/dist/types.d.ts.map +1 -0
  103. package/dist/types.js +30 -0
  104. package/dist/types.js.map +1 -0
  105. package/dist/util/canonical.d.ts +9 -0
  106. package/dist/util/canonical.d.ts.map +1 -0
  107. package/dist/util/canonical.js +35 -0
  108. package/dist/util/canonical.js.map +1 -0
  109. package/dist/wallet/provider.d.ts +118 -0
  110. package/dist/wallet/provider.d.ts.map +1 -0
  111. package/dist/wallet/provider.js +160 -0
  112. package/dist/wallet/provider.js.map +1 -0
  113. package/dist/wallet/providers.d.ts +107 -0
  114. package/dist/wallet/providers.d.ts.map +1 -0
  115. package/dist/wallet/providers.js +188 -0
  116. package/dist/wallet/providers.js.map +1 -0
  117. package/dist/web-bot-auth.d.ts +54 -0
  118. package/dist/web-bot-auth.d.ts.map +1 -0
  119. package/dist/web-bot-auth.js +112 -0
  120. package/dist/web-bot-auth.js.map +1 -0
  121. package/dist/x402/client.d.ts +101 -0
  122. package/dist/x402/client.d.ts.map +1 -0
  123. package/dist/x402/client.js +291 -0
  124. package/dist/x402/client.js.map +1 -0
  125. package/dist/x402/outbound.d.ts +15 -0
  126. package/dist/x402/outbound.d.ts.map +1 -0
  127. package/dist/x402/outbound.js +59 -0
  128. package/dist/x402/outbound.js.map +1 -0
  129. package/dist/x402/types.d.ts +80 -0
  130. package/dist/x402/types.d.ts.map +1 -0
  131. package/dist/x402/types.js +2 -0
  132. package/dist/x402/types.js.map +1 -0
  133. package/package.json +29 -0
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Shared domain types for the Seedhape stack.
3
+ *
4
+ * Money is NEVER represented as a float. On-chain amounts are bigint in the
5
+ * asset's base units (USDC = 6 decimals). INR amounts are bigint in paise
6
+ * (1 INR = 100 paise). Conversion happens only at explicit boundaries.
7
+ */
8
+ export type Address = `0x${string}`;
9
+ export type Hex = `0x${string}`;
10
+ /** CAIP-2 style network identifier. x402 v2 uses these. */
11
+ export type NetworkId = "eip155:8453" | "eip155:84532" | "eip155:137" | string;
12
+ export declare const NETWORKS: Record<string, {
13
+ caip2: NetworkId;
14
+ chainId: number;
15
+ name: string;
16
+ }>;
17
+ export interface AssetRef {
18
+ /** ERC-20 contract address. */
19
+ address: Address;
20
+ network: NetworkId;
21
+ decimals: number;
22
+ symbol: string;
23
+ /** EIP-712 domain name/version of the token, needed for EIP-3009 signing. */
24
+ eip712?: {
25
+ name: string;
26
+ version: string;
27
+ };
28
+ }
29
+ /** USDC deployments. `eip712.name` matters — Base mainnet uses "USDC", some testnets differ. */
30
+ export declare const USDC: Record<string, AssetRef>;
31
+ export type MandateHash = Hex;
32
+ /**
33
+ * Intent Mandate — signed ONCE by the human, off the hot path.
34
+ * This is the constraint envelope every later payment must fit inside.
35
+ */
36
+ export interface IntentMandate {
37
+ /** Wallet that owns the funds (the human). */
38
+ subject: Address;
39
+ /** Session key / smart-account delegate that will actually sign payments. */
40
+ agent: Address;
41
+ /** Freeform description of what the agent is authorised to do, for the audit log. */
42
+ purpose: string;
43
+ /** Max value of a single payment, in asset base units. */
44
+ maxPerTransaction: bigint;
45
+ /** Max cumulative value inside a rolling window, in asset base units. */
46
+ maxPerPeriod: bigint;
47
+ /** Rolling window length in seconds (e.g. 86400 for a daily cap). */
48
+ periodSeconds: number;
49
+ /** Max number of payments inside the rolling window. Guards slow-drain. */
50
+ maxTxPerPeriod: number;
51
+ /** Empty array = any merchant allowed (subject to other rules). */
52
+ allowedPayTo: Address[];
53
+ /** Host allowlist for the x402 resource, e.g. ["api.weather.in"]. Empty = any. */
54
+ allowedHosts: string[];
55
+ /** Assets this mandate covers. */
56
+ asset: AssetRef;
57
+ notBefore: number;
58
+ expiry: number;
59
+ nonce: Hex;
60
+ /** Chain the EIP-712 signature is bound to. */
61
+ chainId: number;
62
+ }
63
+ export interface SignedIntentMandate {
64
+ mandate: IntentMandate;
65
+ hash: MandateHash;
66
+ signature: Hex;
67
+ /** Optional MetaMask ERC-7710 context created for this mandate. */
68
+ delegation?: {
69
+ provider: "metamask-erc7710";
70
+ delegate?: Address;
71
+ delegationManager: Address;
72
+ permissionContext: Hex;
73
+ delegator: Address;
74
+ allowanceAmount?: bigint;
75
+ expiry?: number;
76
+ };
77
+ /** Official AP2 open Checkout and Payment SD-JWTs, once authorized. */
78
+ ap2?: {
79
+ checkout: string;
80
+ payment: string;
81
+ issuer: string;
82
+ issuedAt: number;
83
+ expiresAt: number;
84
+ };
85
+ /** Set when the user revokes early. */
86
+ revokedAt?: number;
87
+ }
88
+ /**
89
+ * Cart Mandate — built from the merchant's 402 challenge.
90
+ * Binds a concrete quote to the intent it is being justified under.
91
+ */
92
+ export interface CartMandate {
93
+ intentHash: MandateHash;
94
+ payTo: Address;
95
+ /** Full resource URL being purchased. */
96
+ resource: string;
97
+ /** Human-readable description supplied by the merchant. */
98
+ description: string;
99
+ amount: bigint;
100
+ asset: AssetRef;
101
+ quotedAt: number;
102
+ expiry: number;
103
+ nonce: Hex;
104
+ chainId: number;
105
+ }
106
+ export interface SignedCartMandate {
107
+ mandate: CartMandate;
108
+ hash: MandateHash;
109
+ signature: Hex;
110
+ }
111
+ /**
112
+ * Payment Mandate — the final authorisation, bound to both prior mandates
113
+ * and to the exact x402 payload that will hit the wire.
114
+ */
115
+ export interface PaymentMandate {
116
+ intentHash: MandateHash;
117
+ cartHash: MandateHash;
118
+ payTo: Address;
119
+ amount: bigint;
120
+ asset: AssetRef;
121
+ /** keccak256 of the canonical JSON of the x402 payment payload. */
122
+ payloadHash: Hex;
123
+ createdAt: number;
124
+ nonce: Hex;
125
+ chainId: number;
126
+ }
127
+ export interface SignedPaymentMandate {
128
+ mandate: PaymentMandate;
129
+ hash: MandateHash;
130
+ signature: Hex;
131
+ }
132
+ export type SpendStatus = "pending" | "settled" | "failed" | "blocked";
133
+ export interface SpendRecord {
134
+ id: string;
135
+ userId: string;
136
+ intentHash: MandateHash;
137
+ cartHash?: MandateHash;
138
+ paymentHash?: MandateHash;
139
+ ap2?: {
140
+ checkoutMandate: string;
141
+ paymentMandate: string;
142
+ checkoutJwt: string;
143
+ };
144
+ resource: string;
145
+ host: string;
146
+ payTo: Address;
147
+ amount: bigint;
148
+ asset: AssetRef;
149
+ /** INR paise value at execution time, from the FX snapshot. */
150
+ inrPaise: bigint;
151
+ /** USD-per-INR rate used, scaled 1e8, retained for audit. */
152
+ fxRateScaled: bigint;
153
+ status: SpendStatus;
154
+ /** On-chain settlement tx from the facilitator, when known. */
155
+ txHash?: Hex;
156
+ createdAt: number;
157
+ settledAt?: number;
158
+ /** Populated when status === "blocked". */
159
+ blockReason?: string;
160
+ }
161
+ /** A completed onramp fill — the tax cost basis lot. */
162
+ export interface OnrampLot {
163
+ id: string;
164
+ userId: string;
165
+ /** USDC base units acquired. */
166
+ quantity: bigint;
167
+ /** Remaining unconsumed quantity, for FIFO. */
168
+ remaining: bigint;
169
+ /** Total INR paise paid, inclusive of provider fees. */
170
+ costInrPaise: bigint;
171
+ acquiredAt: number;
172
+ providerTxId: string;
173
+ provider: string;
174
+ }
175
+ /** Persisted hosted-commerce event, shared by the web app and its Store. */
176
+ export interface CommerceEvent {
177
+ id: string;
178
+ side: "buyer" | "merchant";
179
+ status: "prepared" | "settled" | "failed";
180
+ productId: string;
181
+ amount?: string;
182
+ payer?: string;
183
+ transaction?: string;
184
+ at: number;
185
+ }
186
+ export interface PolicyDecision {
187
+ allowed: boolean;
188
+ /** Machine-readable reason codes, e.g. ["PER_TX_CAP_EXCEEDED"]. */
189
+ reasons: string[];
190
+ /** Human-readable explanation surfaced back to the agent and the user. */
191
+ explanation: string;
192
+ /** True when the payment is legal under the mandate but flagged as unusual. */
193
+ requiresConfirmation?: boolean;
194
+ }
195
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,OAAO,GAAG,KAAK,MAAM,EAAE,CAAC;AACpC,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAEhC,2DAA2D;AAC3D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,cAAc,GAAG,YAAY,GAAG,MAAM,CAAC;AAE/E,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAIxF,CAAC;AAEF,MAAM,WAAW,QAAQ;IACvB,+BAA+B;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,SAAS,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,MAAM,CAAC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MAAM,CAAC;IACX,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IAC3B,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,mEAAmE;IACnE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,0EAA0E;IAC1E,WAAW,EAAE,MAAM,CAAC;IACpB,+EAA+E;IAC/E,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC"}
package/dist/types.js ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Shared domain types for the Seedhape stack.
3
+ *
4
+ * Money is NEVER represented as a float. On-chain amounts are bigint in the
5
+ * asset's base units (USDC = 6 decimals). INR amounts are bigint in paise
6
+ * (1 INR = 100 paise). Conversion happens only at explicit boundaries.
7
+ */
8
+ export const NETWORKS = {
9
+ base: { caip2: "eip155:8453", chainId: 8453, name: "base" },
10
+ "base-sepolia": { caip2: "eip155:84532", chainId: 84532, name: "base-sepolia" },
11
+ polygon: { caip2: "eip155:137", chainId: 137, name: "polygon" },
12
+ };
13
+ /** USDC deployments. `eip712.name` matters — Base mainnet uses "USDC", some testnets differ. */
14
+ export const USDC = {
15
+ base: {
16
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
17
+ network: "eip155:8453",
18
+ decimals: 6,
19
+ symbol: "USDC",
20
+ eip712: { name: "USDC", version: "2" },
21
+ },
22
+ "base-sepolia": {
23
+ address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
24
+ network: "eip155:84532",
25
+ decimals: 6,
26
+ symbol: "USDC",
27
+ eip712: { name: "USDC", version: "2" },
28
+ },
29
+ };
30
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,MAAM,CAAC,MAAM,QAAQ,GAAwE;IAC3F,IAAI,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;IAC3D,cAAc,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE;IAC/E,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE;CAChE,CAAC;AAYF,gGAAgG;AAChG,MAAM,CAAC,MAAM,IAAI,GAA6B;IAC5C,IAAI,EAAE;QACJ,OAAO,EAAE,4CAA4C;QACrD,OAAO,EAAE,aAAa;QACtB,QAAQ,EAAE,CAAC;QACX,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;KACvC;IACD,cAAc,EAAE;QACd,OAAO,EAAE,4CAA4C;QACrD,OAAO,EAAE,cAAc;QACvB,QAAQ,EAAE,CAAC;QACX,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE;KACvC;CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Deterministic JSON serialisation, used wherever a hash must be reproducible
3
+ * across processes and language runtimes (mandate payload hashes, audit
4
+ * exports). Follows RFC 8785 key ordering. bigints serialise as decimal
5
+ * strings, since JSON has no bigint and silently coercing to Number would
6
+ * corrupt amounts above 2^53.
7
+ */
8
+ export declare function canonicalJson(value: unknown): string;
9
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../../src/util/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAqBpD"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Deterministic JSON serialisation, used wherever a hash must be reproducible
3
+ * across processes and language runtimes (mandate payload hashes, audit
4
+ * exports). Follows RFC 8785 key ordering. bigints serialise as decimal
5
+ * strings, since JSON has no bigint and silently coercing to Number would
6
+ * corrupt amounts above 2^53.
7
+ */
8
+ export function canonicalJson(value) {
9
+ return ser(value);
10
+ function ser(v) {
11
+ if (v === null || v === undefined)
12
+ return "null";
13
+ if (typeof v === "bigint")
14
+ return JSON.stringify(v.toString());
15
+ if (typeof v === "boolean")
16
+ return v ? "true" : "false";
17
+ if (typeof v === "number") {
18
+ if (!Number.isFinite(v))
19
+ throw new Error("non-finite number");
20
+ return Object.is(v, -0) ? "0" : String(v);
21
+ }
22
+ if (typeof v === "string")
23
+ return JSON.stringify(v);
24
+ if (Array.isArray(v))
25
+ return `[${v.map(ser).join(",")}]`;
26
+ if (typeof v === "object") {
27
+ const e = Object.entries(v)
28
+ .filter(([, x]) => x !== undefined)
29
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
30
+ return `{${e.map(([k, x]) => `${JSON.stringify(k)}:${ser(x)}`).join(",")}}`;
31
+ }
32
+ throw new Error(`cannot canonicalize ${typeof v}`);
33
+ }
34
+ }
35
+ //# sourceMappingURL=canonical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../src/util/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IAElB,SAAS,GAAG,CAAC,CAAU;QACrB,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC;QACjD,IAAI,OA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CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QAC9E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,OAAO,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Wallet abstraction.
3
+ *
4
+ * The custody boundary is the single most important decision in this stack, so
5
+ * it is an interface rather than an implementation. Three things must be true
6
+ * of whatever you plug in here:
7
+ *
8
+ * 1. The server must never be able to move the user's whole balance. It signs
9
+ * with a *session key* that a smart account has granted a bounded, revocable
10
+ * spend permission to. The user's root key never touches this process.
11
+ *
12
+ * 2. The on-chain permission must be at least as tight as the AP2 mandate.
13
+ * The policy engine is defence in depth; the spend permission is the
14
+ * security boundary. If they disagree, on-chain wins and that is correct.
15
+ *
16
+ * 3. Revocation must be possible without this server's cooperation. If a user
17
+ * can only revoke by asking us nicely, we are custodial in substance
18
+ * whatever the architecture diagram says.
19
+ *
20
+ * `LocalSessionKeySigner` below satisfies (1) and (2) for development. For
21
+ * production, implement this interface against Turnkey, Privy, Coinbase CDP,
22
+ * or MetaMask Delegation Toolkit so the key material lives in an enclave with
23
+ * its own policy engine, not in this process's memory.
24
+ */
25
+ import type { Address, Hex } from "../types.js";
26
+ export interface SessionKeyGrant {
27
+ /** Smart account that owns the funds. */
28
+ account: Address;
29
+ /** Session key permitted to spend from it. */
30
+ sessionKey: Address;
31
+ token: Address;
32
+ /** Max spend per period, in token base units. Enforced on-chain. */
33
+ allowance: bigint;
34
+ periodSeconds: number;
35
+ start: number;
36
+ end: number;
37
+ /** Tx that registered the permission, for audit. */
38
+ grantTx?: Hex;
39
+ }
40
+ export interface WalletProvider {
41
+ /** Address that appears as `from` in EIP-3009 authorisations. */
42
+ readonly address: Address;
43
+ signTypedData(args: {
44
+ domain: Record<string, unknown>;
45
+ types: Record<string, unknown>;
46
+ primaryType: string;
47
+ message: Record<string, unknown>;
48
+ }): Promise<Hex>;
49
+ /** Current on-chain spend permission, if the provider can report one. */
50
+ currentGrant(): Promise<SessionKeyGrant | null>;
51
+ /** Remaining allowance in the active on-chain period. */
52
+ remainingAllowance(): Promise<bigint | null>;
53
+ }
54
+ /**
55
+ * Development signer. The private key is a session key, NOT the user's root key.
56
+ *
57
+ * Do not ship this to production as-is: the key sits in process memory and in
58
+ * whatever environment variable you loaded it from. It exists so the rest of
59
+ * the stack can be exercised end to end without an enclave dependency.
60
+ */
61
+ export declare class LocalSessionKeySigner implements WalletProvider {
62
+ private readonly grant;
63
+ private readonly spentThisPeriod;
64
+ readonly address: Address;
65
+ private readonly account;
66
+ constructor(privateKey: Hex, grant?: SessionKeyGrant | null, spentThisPeriod?: () => Promise<bigint>);
67
+ signTypedData(args: {
68
+ domain: Record<string, unknown>;
69
+ types: Record<string, unknown>;
70
+ primaryType: string;
71
+ message: Record<string, unknown>;
72
+ }): Promise<Hex>;
73
+ currentGrant(): Promise<SessionKeyGrant | null>;
74
+ remainingAllowance(): Promise<bigint | null>;
75
+ }
76
+ /**
77
+ * Production adapter for a custody service or smart-account signer.
78
+ *
79
+ * The service owns the key and enforces its own policy. This process only
80
+ * receives a signature and a read-only grant snapshot. The HTTP contract is:
81
+ * POST {baseUrl}/sign-typed-data -> { signature: "0x..." }
82
+ * GET {baseUrl}/grant -> { grant: SessionKeyGrant | null }
83
+ * GET {baseUrl}/remaining -> { remaining: "123" | null }
84
+ */
85
+ export declare class HttpCustodyWalletProvider implements WalletProvider {
86
+ private readonly cfg;
87
+ readonly address: Address;
88
+ private readonly fetchImpl;
89
+ private readonly baseUrl;
90
+ constructor(cfg: {
91
+ baseUrl: string;
92
+ bearerToken: string;
93
+ address: Address;
94
+ fetchImpl?: typeof fetch;
95
+ });
96
+ signTypedData(args: {
97
+ domain: Record<string, unknown>;
98
+ types: Record<string, unknown>;
99
+ primaryType: string;
100
+ message: Record<string, unknown>;
101
+ }): Promise<Hex>;
102
+ currentGrant(): Promise<SessionKeyGrant | null>;
103
+ remainingAllowance(): Promise<bigint | null>;
104
+ private request;
105
+ }
106
+ /**
107
+ * Refuses to sign anything. Used when a user has connected the MCP server but
108
+ * has not yet granted a spend permission, so `pay` tools fail with a clear
109
+ * message instead of a confusing signature error.
110
+ */
111
+ export declare class UnfundedWallet implements WalletProvider {
112
+ readonly address: Address;
113
+ constructor(address: Address);
114
+ signTypedData(): Promise<Hex>;
115
+ currentGrant(): Promise<null>;
116
+ remainingAllowance(): Promise<null>;
117
+ }
118
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/wallet/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,8CAA8C;IAC9C,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,oEAAoE;IACpE,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,oDAAoD;IACpD,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,aAAa,CAAC,IAAI,EAAE;QAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,WAAW,EA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,GAAG,EAAE;QAChC,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;KAC1B;IAMK,aAAa,CAAC,IAAI,EAAE;QACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAClC,GAAG,OAAO,CAAC,GAAG,CAAC;IAaV,YAAY,IAAI,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAqB/C,kBAAkB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;YAMpC,OAAO;CAetB;AAED;;;;GAIG;AACH,qBAAa,cAAe,YAAW,cAAc;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO;gBAAhB,OAAO,EAAE,OAAO;IAC/B,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC;IAM7B,YAAY;IAGZ,kBAAkB;CAGzB"}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Wallet abstraction.
3
+ *
4
+ * The custody boundary is the single most important decision in this stack, so
5
+ * it is an interface rather than an implementation. Three things must be true
6
+ * of whatever you plug in here:
7
+ *
8
+ * 1. The server must never be able to move the user's whole balance. It signs
9
+ * with a *session key* that a smart account has granted a bounded, revocable
10
+ * spend permission to. The user's root key never touches this process.
11
+ *
12
+ * 2. The on-chain permission must be at least as tight as the AP2 mandate.
13
+ * The policy engine is defence in depth; the spend permission is the
14
+ * security boundary. If they disagree, on-chain wins and that is correct.
15
+ *
16
+ * 3. Revocation must be possible without this server's cooperation. If a user
17
+ * can only revoke by asking us nicely, we are custodial in substance
18
+ * whatever the architecture diagram says.
19
+ *
20
+ * `LocalSessionKeySigner` below satisfies (1) and (2) for development. For
21
+ * production, implement this interface against Turnkey, Privy, Coinbase CDP,
22
+ * or MetaMask Delegation Toolkit so the key material lives in an enclave with
23
+ * its own policy engine, not in this process's memory.
24
+ */
25
+ import { privateKeyToAccount } from "viem/accounts";
26
+ /**
27
+ * Development signer. The private key is a session key, NOT the user's root key.
28
+ *
29
+ * Do not ship this to production as-is: the key sits in process memory and in
30
+ * whatever environment variable you loaded it from. It exists so the rest of
31
+ * the stack can be exercised end to end without an enclave dependency.
32
+ */
33
+ export class LocalSessionKeySigner {
34
+ grant;
35
+ spentThisPeriod;
36
+ address;
37
+ account;
38
+ constructor(privateKey, grant = null, spentThisPeriod = async () => 0n) {
39
+ this.grant = grant;
40
+ this.spentThisPeriod = spentThisPeriod;
41
+ this.account = privateKeyToAccount(privateKey);
42
+ this.address = this.account.address;
43
+ }
44
+ async signTypedData(args) {
45
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
+ return this.account.signTypedData(args);
47
+ }
48
+ async currentGrant() {
49
+ return this.grant;
50
+ }
51
+ async remainingAllowance() {
52
+ if (!this.grant)
53
+ return null;
54
+ const spent = await this.spentThisPeriod();
55
+ const left = this.grant.allowance - spent;
56
+ return left > 0n ? left : 0n;
57
+ }
58
+ }
59
+ /**
60
+ * Production adapter for a custody service or smart-account signer.
61
+ *
62
+ * The service owns the key and enforces its own policy. This process only
63
+ * receives a signature and a read-only grant snapshot. The HTTP contract is:
64
+ * POST {baseUrl}/sign-typed-data -> { signature: "0x..." }
65
+ * GET {baseUrl}/grant -> { grant: SessionKeyGrant | null }
66
+ * GET {baseUrl}/remaining -> { remaining: "123" | null }
67
+ */
68
+ export class HttpCustodyWalletProvider {
69
+ cfg;
70
+ address;
71
+ fetchImpl;
72
+ baseUrl;
73
+ constructor(cfg) {
74
+ this.cfg = cfg;
75
+ this.address = cfg.address;
76
+ this.baseUrl = cfg.baseUrl.replace(/\/$/, "");
77
+ this.fetchImpl = cfg.fetchImpl ?? fetch;
78
+ }
79
+ async signTypedData(args) {
80
+ const response = await this.request("/sign-typed-data", {
81
+ method: "POST",
82
+ body: JSON.stringify(args),
83
+ headers: { "content-type": "application/json" },
84
+ });
85
+ const signature = response.signature;
86
+ if (typeof signature !== "string" || !/^0x[0-9a-fA-F]+$/.test(signature)) {
87
+ throw new Error("Custody service returned an invalid typed-data signature.");
88
+ }
89
+ return signature;
90
+ }
91
+ async currentGrant() {
92
+ const response = await this.request("/grant");
93
+ const grant = response.grant;
94
+ if (!grant)
95
+ return null;
96
+ if (typeof grant.account !== "string" || typeof grant.sessionKey !== "string" ||
97
+ typeof grant.token !== "string" || typeof grant.allowance !== "string" && typeof grant.allowance !== "number" ||
98
+ typeof grant.periodSeconds !== "number" || typeof grant.start !== "number" || typeof grant.end !== "number") {
99
+ throw new Error("Custody service returned an invalid spend grant.");
100
+ }
101
+ return {
102
+ account: grant.account,
103
+ sessionKey: grant.sessionKey,
104
+ token: grant.token,
105
+ allowance: BigInt(grant.allowance),
106
+ periodSeconds: grant.periodSeconds,
107
+ start: grant.start,
108
+ end: grant.end,
109
+ grantTx: typeof grant.grantTx === "string" ? grant.grantTx : undefined,
110
+ };
111
+ }
112
+ async remainingAllowance() {
113
+ const response = await this.request("/remaining");
114
+ const remaining = response.remaining;
115
+ return remaining === null || remaining === undefined ? null : BigInt(remaining);
116
+ }
117
+ async request(path, init = {}) {
118
+ const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
119
+ ...init,
120
+ headers: {
121
+ authorization: `Bearer ${this.cfg.bearerToken}`,
122
+ accept: "application/json",
123
+ ...(init.headers ?? {}),
124
+ },
125
+ });
126
+ const text = await response.text();
127
+ let body;
128
+ try {
129
+ body = text ? JSON.parse(text) : null;
130
+ }
131
+ catch {
132
+ body = text;
133
+ }
134
+ if (!response.ok)
135
+ throw new Error(`Custody service ${path} failed with ${response.status}: ${String(text)}`);
136
+ return body;
137
+ }
138
+ }
139
+ /**
140
+ * Refuses to sign anything. Used when a user has connected the MCP server but
141
+ * has not yet granted a spend permission, so `pay` tools fail with a clear
142
+ * message instead of a confusing signature error.
143
+ */
144
+ export class UnfundedWallet {
145
+ address;
146
+ constructor(address) {
147
+ this.address = address;
148
+ }
149
+ async signTypedData() {
150
+ throw new Error("No spend permission has been granted for this wallet. Run the `grant_spend_permission` " +
151
+ "flow to authorise a session key before attempting a payment.");
152
+ }
153
+ async currentGrant() {
154
+ return null;
155
+ }
156
+ async remainingAllowance() {
157
+ return null;
158
+ }
159
+ }
160
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/wallet/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAoCpD;;;;;;GAMG;AACH,MAAM,OAAO,qBAAqB;IAMb;IACA;IANV,OAAO,CAAU;IACT,OAAO,CAAyC;IAEjE,YACE,UAAe,EACE,QAAgC,IAAI,EACpC,kBAAyC,KAAK,IAAI,EAAE,CAAC,EAAE;QADvD,UAAK,GAAL,KAAK,CAA+B;QACpC,oBAAe,GAAf,eAAe,CAAwC;QAExE,IAAI,CAAC,OAAO,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,IAKnB;QACC,8DAA8D;QAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAW,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAC7B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC3C,MAAM,I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