@envarai/envarpay 0.2.0-alpha.19 → 0.2.0-alpha.20

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 (54) hide show
  1. package/README.md +18 -63
  2. package/dist/commerce/alerts.d.ts +5 -15
  3. package/dist/commerce/alerts.js +21 -77
  4. package/dist/commerce/card.js +1 -1
  5. package/dist/commerce/cli.js +17 -145
  6. package/dist/commerce/config.d.ts +1 -4
  7. package/dist/commerce/config.js +4 -82
  8. package/dist/commerce/configure.d.ts +0 -1
  9. package/dist/commerce/configure.js +0 -80
  10. package/dist/commerce/discovery.d.ts +1 -5
  11. package/dist/commerce/discovery.js +1 -4
  12. package/dist/commerce/envar-balance.js +1 -1
  13. package/dist/commerce/envar.d.ts +1 -32
  14. package/dist/commerce/envar.js +3 -82
  15. package/dist/commerce/operations.d.ts +1 -2
  16. package/dist/commerce/operations.js +17 -20
  17. package/dist/commerce/pricing.d.ts +0 -1
  18. package/dist/commerce/pricing.js +1 -3
  19. package/dist/commerce/runtime.d.ts +0 -2
  20. package/dist/commerce/runtime.js +0 -2
  21. package/dist/commerce/server.d.ts +0 -1
  22. package/dist/commerce/server.js +2 -3
  23. package/dist/commerce/setup.js +4 -3
  24. package/dist/commerce/types.d.ts +0 -59
  25. package/examples/envar-integration-policy.json +1 -9
  26. package/examples/seller.json +143 -26
  27. package/package.json +3 -16
  28. package/schemas/envarpay.config.schema.json +1 -80
  29. package/dist/commerce/buyer-store.d.ts +0 -101
  30. package/dist/commerce/buyer-store.js +0 -168
  31. package/dist/commerce/buyer.d.ts +0 -138
  32. package/dist/commerce/buyer.js +0 -775
  33. package/dist/commerce/chain.d.ts +0 -24
  34. package/dist/commerce/chain.js +0 -196
  35. package/dist/commerce/client-runtime.d.ts +0 -8
  36. package/dist/commerce/client-runtime.js +0 -7
  37. package/dist/commerce/management.d.ts +0 -14
  38. package/dist/commerce/management.js +0 -140
  39. package/dist/commerce/mpp-client.d.ts +0 -70
  40. package/dist/commerce/mpp-client.js +0 -29
  41. package/dist/commerce/mpp-runtime.d.ts +0 -4
  42. package/dist/commerce/mpp-runtime.js +0 -4
  43. package/dist/commerce/mpp.d.ts +0 -53
  44. package/dist/commerce/mpp.js +0 -163
  45. package/dist/commerce/peer-proxy.d.ts +0 -44
  46. package/dist/commerce/peer-proxy.js +0 -673
  47. package/dist/commerce/stripe-issuer.d.ts +0 -41
  48. package/dist/commerce/stripe-issuer.js +0 -351
  49. package/dist/commerce/stripe-provider.d.ts +0 -11
  50. package/dist/commerce/stripe-provider.js +0 -132
  51. package/dist/commerce/x402.d.ts +0 -38
  52. package/dist/commerce/x402.js +0 -181
  53. package/examples/buyer-policy.json +0 -18
  54. package/schemas/buyer-policy.schema.json +0 -253
@@ -27,19 +27,6 @@ export interface Offer {
27
27
  paymentProfile?: string;
28
28
  }
29
29
  export type PaymentProfile = {
30
- adapter: 'x402';
31
- scheme: 'exact';
32
- network: string;
33
- asset: string;
34
- payTo: string;
35
- facilitatorUrl: string;
36
- } | {
37
- adapter: 'mpp';
38
- method: 'stripe';
39
- intent: 'charge';
40
- currency: 'usd';
41
- accountRef: string;
42
- } | {
43
30
  adapter: 'envar_balance';
44
31
  currency: 'usd';
45
32
  accountRef: string;
@@ -73,52 +60,6 @@ export interface CommerceConfig {
73
60
  paymentProfiles: Record<string, PaymentProfile>;
74
61
  services: Service[];
75
62
  }
76
- /** A separately reviewed transport profile; local terms are never advertised as seller promises. */
77
- export interface StandardA2APeer {
78
- id: string;
79
- cardUrl: string;
80
- mode: 'standard-a2a';
81
- protocol: 'x402';
82
- currency: string;
83
- recipient: string;
84
- maxPerPurchase: string;
85
- endpoint: string;
86
- authentication: 'none' | 'bearer';
87
- localContract: {
88
- revision: number;
89
- offerId: string;
90
- inputSchema: Record<string, unknown>;
91
- amount: string;
92
- paidOnly: true;
93
- };
94
- }
95
- export interface BuyerPolicy {
96
- policyVersion: 1;
97
- paymentsEnabled: boolean;
98
- approval: 'per_purchase' | 'within_preapproved_limits';
99
- peers: (StandardA2APeer | {
100
- id: string;
101
- cardUrl: string;
102
- mode?: 'envarpay';
103
- protocol: 'x402' | 'mpp';
104
- currency: string;
105
- recipient: string;
106
- maxPerPurchase: string;
107
- } | {
108
- id: string;
109
- cardUrl: string;
110
- mode?: 'envarpay';
111
- protocol: 'free';
112
- currency: null;
113
- recipient: null;
114
- maxPerPurchase: '0';
115
- })[];
116
- budgets: {
117
- currency: string;
118
- maxTotal: string;
119
- period: 'cumulative';
120
- }[];
121
- }
122
63
  export interface PriceQuote {
123
64
  quoteVersion: 1;
124
65
  quoteId: string;
@@ -6,13 +6,5 @@
6
6
  "acceptUpdates": true,
7
7
  "allowedServices": ["research"],
8
8
  "allowedUpstreamOrigins": ["http://hermes:9000"],
9
- "allowedX402": [
10
- {
11
- "network": "eip155:84532",
12
- "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
13
- "payTo": "0x2222222222222222222222222222222222222222",
14
- "facilitatorOrigin": "https://facilitator.example"
15
- }
16
- ],
17
- "allowedMppAccounts": ["seller-stripe"]
9
+ "allowedBalanceAccounts": ["envar"]
18
10
  }
@@ -1,52 +1,169 @@
1
1
  {
2
2
  "configVersion": 1,
3
- "agent": {"id": "hermes-researcher", "name": "我的研究助手"},
3
+ "agent": {
4
+ "id": "hermes-researcher",
5
+ "name": "我的研究助手"
6
+ },
4
7
  "paymentProfiles": {
5
- "base-usdc": {
6
- "adapter": "x402", "scheme": "exact", "network": "eip155:84532",
7
- "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
8
- "payTo": "0x2222222222222222222222222222222222222222",
9
- "facilitatorUrl": "https://facilitator.example"
10
- },
11
- "stripe-usd": {"adapter": "mpp", "method": "stripe", "intent": "charge", "currency": "usd", "accountRef": "seller-stripe"}
8
+ "envar-usd": {
9
+ "adapter": "envar_balance",
10
+ "currency": "usd",
11
+ "accountRef": "envar"
12
+ }
12
13
  },
13
14
  "services": [
14
15
  {
15
- "id": "research", "name": "竞品调研", "revision": 1,
16
- "execution": {"type": "a2a", "cardUrl": "http://hermes:9000/research/agent-card.json"},
16
+ "id": "research",
17
+ "name": "竞品调研",
18
+ "revision": 1,
19
+ "execution": {
20
+ "type": "a2a",
21
+ "cardUrl": "http://hermes:9000/research/agent-card.json"
22
+ },
17
23
  "contract": {
18
24
  "inputSchema": {
19
25
  "$schema": "https://json-schema.org/draft/2020-12/schema",
20
- "type": "object", "additionalProperties": false, "required": ["topic", "competitors"],
26
+ "type": "object",
27
+ "additionalProperties": false,
28
+ "required": [
29
+ "topic",
30
+ "competitors"
31
+ ],
21
32
  "properties": {
22
- "topic": {"type": "string", "minLength": 1, "maxLength": 500},
23
- "competitors": {"type": "array", "minItems": 1, "maxItems": 3, "uniqueItems": true, "items": {"type": "string", "minLength": 1, "maxLength": 120}}
33
+ "topic": {
34
+ "type": "string",
35
+ "minLength": 1,
36
+ "maxLength": 500
37
+ },
38
+ "competitors": {
39
+ "type": "array",
40
+ "minItems": 1,
41
+ "maxItems": 3,
42
+ "uniqueItems": true,
43
+ "items": {
44
+ "type": "string",
45
+ "minLength": 1,
46
+ "maxLength": 120
47
+ }
48
+ }
24
49
  }
25
50
  },
26
- "deliverables": ["report.md", "comparison.csv"], "targetDurationSeconds": 600, "includedRevisions": 0
51
+ "deliverables": [
52
+ "report.md",
53
+ "comparison.csv"
54
+ ],
55
+ "targetDurationSeconds": 600,
56
+ "includedRevisions": 0
27
57
  },
28
58
  "offers": [
29
- {"id": "usdc-once", "pricing": {"kind": "fixed", "amount": "3000000"}, "collection": {"kind": "upfront"}, "paymentProfile": "base-usdc"},
30
- {"id": "card-once", "pricing": {"kind": "fixed", "amount": "300"}, "collection": {"kind": "upfront"}, "paymentProfile": "stripe-usd"}
59
+ {
60
+ "id": "balance-once",
61
+ "pricing": {
62
+ "kind": "fixed",
63
+ "amount": "3000000"
64
+ },
65
+ "collection": {
66
+ "kind": "upfront"
67
+ },
68
+ "paymentProfile": "envar-usd"
69
+ }
31
70
  ]
32
71
  },
33
72
  {
34
- "id": "summary-preview", "name": "免费试读", "revision": 1,
35
- "execution": {"type": "a2a", "cardUrl": "http://hermes:9000/preview/agent-card.json"},
73
+ "id": "summary-preview",
74
+ "name": "免费试读",
75
+ "revision": 1,
76
+ "execution": {
77
+ "type": "a2a",
78
+ "cardUrl": "http://hermes:9000/preview/agent-card.json"
79
+ },
36
80
  "contract": {
37
- "inputSchema": {"type": "object", "additionalProperties": false, "required": ["text"], "properties": {"text": {"type": "string", "minLength": 1, "maxLength": 500}}},
38
- "deliverables": ["summary.txt"], "targetDurationSeconds": 60, "includedRevisions": 0
81
+ "inputSchema": {
82
+ "type": "object",
83
+ "additionalProperties": false,
84
+ "required": [
85
+ "text"
86
+ ],
87
+ "properties": {
88
+ "text": {
89
+ "type": "string",
90
+ "minLength": 1,
91
+ "maxLength": 500
92
+ }
93
+ }
94
+ },
95
+ "deliverables": [
96
+ "summary.txt"
97
+ ],
98
+ "targetDurationSeconds": 60,
99
+ "includedRevisions": 0
39
100
  },
40
- "offers": [{"id": "free", "pricing": {"kind": "free"}, "collection": {"kind": "none"}}]
101
+ "offers": [
102
+ {
103
+ "id": "free",
104
+ "pricing": {
105
+ "kind": "free"
106
+ },
107
+ "collection": {
108
+ "kind": "none"
109
+ }
110
+ }
111
+ ]
41
112
  },
42
113
  {
43
- "id": "translation", "name": "文档翻译", "revision": 1,
44
- "execution": {"type": "a2a", "cardUrl": "http://openclaw:9000/translate/agent-card.json"},
114
+ "id": "translation",
115
+ "name": "文档翻译",
116
+ "revision": 1,
117
+ "execution": {
118
+ "type": "a2a",
119
+ "cardUrl": "http://openclaw:9000/translate/agent-card.json"
120
+ },
45
121
  "contract": {
46
- "inputSchema": {"type": "object", "additionalProperties": false, "required": ["documents"], "properties": {"documents": {"type": "array", "minItems": 1, "maxItems": 20, "items": {"type": "string", "minLength": 1, "maxLength": 10000}}}},
47
- "deliverables": ["translations.json"], "targetDurationSeconds": 600, "includedRevisions": 0
122
+ "inputSchema": {
123
+ "type": "object",
124
+ "additionalProperties": false,
125
+ "required": [
126
+ "documents"
127
+ ],
128
+ "properties": {
129
+ "documents": {
130
+ "type": "array",
131
+ "minItems": 1,
132
+ "maxItems": 20,
133
+ "items": {
134
+ "type": "string",
135
+ "minLength": 1,
136
+ "maxLength": 10000
137
+ }
138
+ }
139
+ }
140
+ },
141
+ "deliverables": [
142
+ "translations.json"
143
+ ],
144
+ "targetDurationSeconds": 600,
145
+ "includedRevisions": 0
48
146
  },
49
- "offers": [{"id": "per-document", "pricing": {"kind": "quantity", "unit": "document", "unitAmount": "100000", "quantity": {"pointer": "/documents", "measure": "count", "min": 1, "max": 20}}, "collection": {"kind": "upfront"}, "paymentProfile": "base-usdc"}]
147
+ "offers": [
148
+ {
149
+ "id": "per-document",
150
+ "pricing": {
151
+ "kind": "quantity",
152
+ "unit": "document",
153
+ "unitAmount": "100000",
154
+ "quantity": {
155
+ "pointer": "/documents",
156
+ "measure": "count",
157
+ "min": 1,
158
+ "max": 20
159
+ }
160
+ },
161
+ "collection": {
162
+ "kind": "upfront"
163
+ },
164
+ "paymentProfile": "envar-usd"
165
+ }
166
+ ]
50
167
  }
51
168
  ]
52
169
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@envarai/envarpay",
3
- "version": "0.2.0-alpha.19",
4
- "description": "Independent A2A service commerce, budgeted buyers and x402/MPP payments",
3
+ "version": "0.2.0-alpha.20",
4
+ "description": "A2A services with Envar account-balance payments",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "engines": {
@@ -20,18 +20,10 @@
20
20
  "types": "./dist/commerce/runtime.d.ts",
21
21
  "import": "./dist/commerce/runtime.js"
22
22
  },
23
- "./client": {
24
- "types": "./dist/commerce/client-runtime.d.ts",
25
- "import": "./dist/commerce/client-runtime.js"
26
- },
27
23
  "./server": {
28
24
  "types": "./dist/commerce/runtime.d.ts",
29
25
  "import": "./dist/commerce/runtime.js"
30
26
  },
31
- "./mpp": {
32
- "types": "./dist/commerce/mpp-runtime.d.ts",
33
- "import": "./dist/commerce/mpp-runtime.js"
34
- },
35
27
  "./envar": {
36
28
  "types": "./dist/commerce/envar.d.ts",
37
29
  "import": "./dist/commerce/envar.js"
@@ -54,21 +46,16 @@
54
46
  "tag": "next"
55
47
  },
56
48
  "scripts": {
57
- "build": "tsc",
49
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc",
58
50
  "test": "npm run build && node --test test/*.test.mjs",
59
51
  "prepack": "npm run build"
60
52
  },
61
53
  "dependencies": {
62
54
  "@a2a-js/sdk": "1.2.1",
63
55
  "@modelcontextprotocol/sdk": "^1.31.0",
64
- "@x402/core": "2.24.0",
65
- "@x402/evm": "2.24.0",
66
- "@x402/extensions": "2.24.0",
67
56
  "ajv": "8.20.0",
68
57
  "ajv-formats": "3.0.1",
69
58
  "canonicalize": "2.1.0",
70
- "mppx": "0.13.1",
71
- "viem": "2.57.1",
72
59
  "yaml": "2.8.2",
73
60
  "zod": "4.6.5"
74
61
  },
@@ -38,19 +38,7 @@
38
38
  "propertyNames": {
39
39
  "$ref": "#/$defs/id"
40
40
  },
41
- "additionalProperties": {
42
- "oneOf": [
43
- {
44
- "$ref": "#/$defs/x402"
45
- },
46
- {
47
- "$ref": "#/$defs/mpp"
48
- },
49
- {
50
- "$ref": "#/$defs/envarBalance"
51
- }
52
- ]
53
- }
41
+ "additionalProperties": { "$ref": "#/$defs/envarBalance" }
54
42
  },
55
43
  "services": {
56
44
  "type": "array",
@@ -70,79 +58,12 @@
70
58
  "type": "string",
71
59
  "pattern": "^[1-9][0-9]{0,77}$"
72
60
  },
73
- "address": {
74
- "type": "string",
75
- "pattern": "^0x[0-9a-fA-F]{40}$"
76
- },
77
61
  "httpUrl": {
78
62
  "type": "string",
79
63
  "format": "uri",
80
64
  "pattern": "^https?://",
81
65
  "maxLength": 2048
82
66
  },
83
- "x402": {
84
- "type": "object",
85
- "additionalProperties": false,
86
- "required": [
87
- "adapter",
88
- "scheme",
89
- "network",
90
- "asset",
91
- "payTo",
92
- "facilitatorUrl"
93
- ],
94
- "properties": {
95
- "adapter": {
96
- "const": "x402"
97
- },
98
- "scheme": {
99
- "const": "exact"
100
- },
101
- "network": {
102
- "type": "string",
103
- "pattern": "^eip155:[1-9][0-9]*$"
104
- },
105
- "asset": {
106
- "$ref": "#/$defs/address"
107
- },
108
- "payTo": {
109
- "$ref": "#/$defs/address"
110
- },
111
- "facilitatorUrl": {
112
- "type": "string",
113
- "format": "uri",
114
- "pattern": "^https://"
115
- }
116
- }
117
- },
118
- "mpp": {
119
- "type": "object",
120
- "additionalProperties": false,
121
- "required": [
122
- "adapter",
123
- "method",
124
- "intent",
125
- "currency",
126
- "accountRef"
127
- ],
128
- "properties": {
129
- "adapter": {
130
- "const": "mpp"
131
- },
132
- "method": {
133
- "const": "stripe"
134
- },
135
- "intent": {
136
- "const": "charge"
137
- },
138
- "currency": {
139
- "const": "usd"
140
- },
141
- "accountRef": {
142
- "$ref": "#/$defs/id"
143
- }
144
- }
145
- },
146
67
  "envarBalance": {
147
68
  "type": "object",
148
69
  "additionalProperties": false,
@@ -1,101 +0,0 @@
1
- import type { PaymentRequired, PaymentRequirements, SettleResponse } from '@x402/core/types';
2
- import type { Challenge } from 'mppx';
3
- import type { MppReceipt } from './mpp-client.js';
4
- import { type BuyerPolicy, type Input } from './types.js';
5
- export interface BuyerQuote {
6
- messageId: string;
7
- payer: string;
8
- amount: string;
9
- currency: string | null;
10
- recipient: string | null;
11
- expiresAt: string;
12
- serviceId: string;
13
- serviceRevision: number;
14
- offerId: string;
15
- inputDigest: string;
16
- termsDigest: string;
17
- quoteId: string;
18
- /** Absent for the original seller-advertised EnvarPay contract. */
19
- termsSource?: 'local-policy';
20
- }
21
- export interface BuyerRecord {
22
- id: string;
23
- caller: string;
24
- peerId: string;
25
- cardUrl: string;
26
- endpoint: string;
27
- messageId: string;
28
- fingerprint: string;
29
- body: string;
30
- quoteToken: string;
31
- quote: BuyerQuote;
32
- input: Input;
33
- inputSchema: Record<string, unknown>;
34
- peerMode?: 'standard-a2a';
35
- standardBinding?: {
36
- policyDigest: string;
37
- bodyDigest: string;
38
- challengeDigest: string;
39
- };
40
- continuations?: {
41
- messageId: string;
42
- input: Input;
43
- body?: string;
44
- state: 'pending' | 'unknown' | 'resolved';
45
- beforeDigest: string;
46
- }[];
47
- protocol?: 'x402' | 'mpp' | 'free';
48
- mppChallenge?: Challenge.Challenge;
49
- tokenOperationId?: string;
50
- tokenRef?: string;
51
- mppMode?: 'test' | 'live';
52
- mppPaymentMethod?: string;
53
- required?: PaymentRequired;
54
- requirements?: PaymentRequirements;
55
- createdAt: string;
56
- updatedAt: string;
57
- state: 'previewed' | 'signing' | 'submitted' | 'unknown' | 'completed' | 'failed';
58
- paymentState: 'quoted' | 'reserved' | 'unknown' | 'confirmed' | 'rejected' | 'not_required';
59
- executionState: string;
60
- credentialRef?: string;
61
- nonce?: string;
62
- fromBlock?: string;
63
- receipt?: SettleResponse | MppReceipt;
64
- task?: Record<string, unknown>;
65
- result?: unknown;
66
- errorCode?: string;
67
- rejectionEvidence?: {
68
- kind: 'finalized_expired_unused';
69
- checkedAt: string;
70
- nonce: string;
71
- };
72
- }
73
- /** One wallet ledger, one process. Unknown authorizations retain cumulative budget. */
74
- export declare class BuyerStore {
75
- private readonly db;
76
- private readonly owner?;
77
- constructor(path: string);
78
- close(): void;
79
- private transaction;
80
- get(id: string, caller: string): BuyerRecord | undefined;
81
- assertMessageOwner(caller: string, messageId: string): void;
82
- find(caller: string, messageId: string): BuyerRecord | undefined;
83
- insert(value: Omit<BuyerRecord, 'id' | 'createdAt' | 'updatedAt' | 'state' | 'paymentState' | 'executionState'>): BuyerRecord;
84
- update(id: string, patch: Partial<Pick<BuyerRecord, 'state' | 'paymentState' | 'executionState' | 'credentialRef' | 'nonce' | 'fromBlock' | 'receipt' | 'task' | 'result' | 'errorCode' | 'continuations' | 'tokenOperationId' | 'tokenRef' | 'rejectionEvidence'>>): BuyerRecord;
85
- pendingTasks(): BuyerRecord[];
86
- usage(currency: string): {
87
- reserved: string;
88
- spent: string;
89
- };
90
- reserve(id: string, caller: string, policy: BuyerPolicy): {
91
- record: BuyerRecord;
92
- fresh: boolean;
93
- };
94
- beginFree(id: string, caller: string): {
95
- record: BuyerRecord;
96
- fresh: boolean;
97
- };
98
- rejectBeforeSigning(id: string, caller: string, errorCode: string): BuyerRecord;
99
- rejectExpiredAuthorization(id: string, caller: string): BuyerRecord;
100
- confirmed(id: string, receipt: SettleResponse | MppReceipt): BuyerRecord;
101
- }