openclaw-paygate-plugin 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.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # OpenClaw Paygate Plugin
2
+
3
+ A programmatic OpenClaw plugin that enables AI agents to monetize their capabilities using the **402 Payment Required** flow.
4
+
5
+ ## Key Features
6
+ - **Monetization**: Turn your agent's tools into paid services.
7
+ - **Auto-Handshake**: Automatically manages the payment request and verification flow.
8
+ - **Unified Earnings**: All revenue is deposited directly into your agent's BSV wallet.
9
+
10
+ ## AI Tool: `paygate`
11
+ Agents can use the `paygate` tool to:
12
+ - `monetize`: Wrap any tool with a price tag in satoshis.
13
+ - `earnings`: Check the total BSV earned by the agent.
14
+
15
+ ## Architecture
16
+ Built with the **OpenClaw Plugin SDK**, this extension uses standard web middleware to enforce payments for API calls and tool executions.
17
+
18
+ ## License
19
+ MIT
package/SKILL.md ADDED
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: paygate
3
+ description: >
4
+ Tool monetization via 402 Payment Required. Use to put a price tag on your
5
+ capabilities and earn BSV when other agents or users call your tools.
6
+ metadata: '{"openclaw": {"requires": {"bins": ["node"]}}}'
7
+ ---
8
+
9
+ ## Tool Actions
10
+
11
+ | Action | Description |
12
+ |--------|-------------|
13
+ | `monetize` | Wrap an existing tool with a price (in satoshis) |
14
+ | `earnings` | Show total revenue earned through the paygate |
15
+ | `status` | Show active paid endpoints and their prices |
16
+
17
+ ## Usage Guidance
18
+
19
+ ### Starting a Business
20
+ If you have a high-value capability (like a specialized search or complex code analysis), you can start charging for it.
21
+
22
+ ```javascript
23
+ paygate({
24
+ action: "monetize",
25
+ toolName: "expert_analysis",
26
+ priceSats: 100
27
+ })
28
+ ```
29
+
30
+ ### Managing Revenue
31
+ Use the `earnings` action to track how much you have earned from each tool.
32
+
33
+ ```javascript
34
+ paygate({
35
+ action: "earnings"
36
+ })
37
+ ```
38
+
39
+ ## Security & Ethics
40
+ 1. **Fair Pricing**: Only charge for tools that provide significant value.
41
+ 2. **Transparency**: Always inform the user/agent of the price before they commit to a paid tool call.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * OpenClaw Paygate Plugin
3
+ * Monetize agent tools via 402 Payment Required.
4
+ */
5
+ export default function register(api: any): void;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,GAAG,QA8DxC"}
package/dist/index.js ADDED
@@ -0,0 +1,68 @@
1
+ import path from "node:path";
2
+ import os from "node:os";
3
+ /**
4
+ * OpenClaw Paygate Plugin
5
+ * Monetize agent tools via 402 Payment Required.
6
+ */
7
+ export default function register(api) {
8
+ const entry = api.getConfig?.()?.plugins?.entries?.['openclaw-paygate'] || {};
9
+ const pluginConfig = { ...entry, ...(entry.config || {}), ...(api.config || {}) };
10
+ const port = pluginConfig.port || 8080;
11
+ const walletDir = pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet');
12
+ api.logger.info(`[paygate] Initializing Paygate Plugin (port: ${port})`);
13
+ // Register the paygate tool
14
+ api.registerTool({
15
+ name: "paygate",
16
+ description: "Monetize your agent's tools via 402 Payment Required",
17
+ parameters: {
18
+ type: "object",
19
+ properties: {
20
+ action: {
21
+ type: "string",
22
+ enum: ["monetize", "earnings", "status"],
23
+ description: "Action to perform"
24
+ },
25
+ toolName: {
26
+ type: "string",
27
+ description: "Name of the existing OpenClaw tool to monetize"
28
+ },
29
+ priceSats: {
30
+ type: "number",
31
+ description: "Price in satoshis for the tool call"
32
+ }
33
+ },
34
+ required: ["action"]
35
+ },
36
+ async execute(_id, params) {
37
+ try {
38
+ // Implementation logic using payment-express-middleware will go here
39
+ return {
40
+ content: [{
41
+ type: "text",
42
+ text: `Paygate action '${params.action}' received. (Logic implementation pending)`
43
+ }]
44
+ };
45
+ }
46
+ catch (error) {
47
+ return {
48
+ content: [{
49
+ type: "text",
50
+ text: `Error: ${error.message || String(error)}`
51
+ }]
52
+ };
53
+ }
54
+ }
55
+ });
56
+ // Register the background API server
57
+ api.registerService({
58
+ id: "paygate-api-server",
59
+ start: async () => {
60
+ api.logger.info(`[paygate] Starting agent API server on port ${port}...`);
61
+ // Express server logic with 402 middleware goes here
62
+ },
63
+ stop: async () => {
64
+ api.logger.info("[paygate] Stopping agent API server...");
65
+ }
66
+ });
67
+ }
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAQ;IACvC,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;IAC9E,MAAM,YAAY,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC;IAClF,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,IAAI,IAAI,CAAC;IACvC,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAE/F,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,gDAAgD,IAAI,GAAG,CAAC,CAAC;IAEzE,4BAA4B;IAC5B,GAAG,CAAC,YAAY,CAAC;QACf,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,sDAAsD;Q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@@ -0,0 +1,70 @@
1
+ import path from "node:path";
2
+ import os from "node:os";
3
+
4
+ /**
5
+ * OpenClaw Paygate Plugin
6
+ * Monetize agent tools via 402 Payment Required.
7
+ */
8
+ export default function register(api: any) {
9
+ const entry = api.getConfig?.()?.plugins?.entries?.['openclaw-paygate'] || {};
10
+ const pluginConfig = { ...entry, ...(entry.config || {}), ...(api.config || {}) };
11
+ const port = pluginConfig.port || 8080;
12
+ const walletDir = pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet');
13
+
14
+ api.logger.info(`[paygate] Initializing Paygate Plugin (port: ${port})`);
15
+
16
+ // Register the paygate tool
17
+ api.registerTool({
18
+ name: "paygate",
19
+ description: "Monetize your agent's tools via 402 Payment Required",
20
+ parameters: {
21
+ type: "object",
22
+ properties: {
23
+ action: {
24
+ type: "string",
25
+ enum: ["monetize", "earnings", "status"],
26
+ description: "Action to perform"
27
+ },
28
+ toolName: {
29
+ type: "string",
30
+ description: "Name of the existing OpenClaw tool to monetize"
31
+ },
32
+ priceSats: {
33
+ type: "number",
34
+ description: "Price in satoshis for the tool call"
35
+ }
36
+ },
37
+ required: ["action"]
38
+ },
39
+ async execute(_id: string, params: any) {
40
+ try {
41
+ // Implementation logic using payment-express-middleware will go here
42
+ return {
43
+ content: [{
44
+ type: "text",
45
+ text: `Paygate action '${params.action}' received. (Logic implementation pending)`
46
+ }]
47
+ };
48
+ } catch (error: any) {
49
+ return {
50
+ content: [{
51
+ type: "text",
52
+ text: `Error: ${error.message || String(error)}`
53
+ }]
54
+ };
55
+ }
56
+ }
57
+ });
58
+
59
+ // Register the background API server
60
+ api.registerService({
61
+ id: "paygate-api-server",
62
+ start: async () => {
63
+ api.logger.info(`[paygate] Starting agent API server on port ${port}...`);
64
+ // Express server logic with 402 middleware goes here
65
+ },
66
+ stop: async () => {
67
+ api.logger.info("[paygate] Stopping agent API server...");
68
+ }
69
+ });
70
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "id": "openclaw-paygate",
3
+ "name": "BSV Paygate",
4
+ "description": "Monetize agent tools via 402 Payment Required",
5
+ "version": "0.1.0",
6
+ "skills": [
7
+ "./SKILL.md"
8
+ ],
9
+ "configSchema": {
10
+ "type": "object",
11
+ "additionalProperties": false,
12
+ "properties": {
13
+ "port": {
14
+ "type": "number",
15
+ "default": 8080,
16
+ "description": "Port for the agent's API server"
17
+ },
18
+ "walletDir": {
19
+ "type": "string",
20
+ "description": "Path to BSV wallet storage (defaults to ~/.openclaw/bsv-wallet)"
21
+ }
22
+ }
23
+ },
24
+ "uiHints": {
25
+ "port": {
26
+ "label": "API Port",
27
+ "placeholder": "8080"
28
+ }
29
+ }
30
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "openclaw-paygate-plugin",
3
+ "version": "0.1.0",
4
+ "description": "OpenClaw plugin for monetizing tools via 402 Payment Required flow",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "files": [
8
+ "index.ts",
9
+ "openclaw.plugin.json",
10
+ "src/",
11
+ "dist/",
12
+ "SKILL.md",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "prepublishOnly": "npm run build",
18
+ "lint": "eslint src/**/*.ts",
19
+ "test": "npx tsx src/**/*.test.ts"
20
+ },
21
+ "dependencies": {
22
+ "@bsv/sdk": "^2.0.13",
23
+ "express": "^4.21.0",
24
+ "better-sqlite3": "^12.8.0",
25
+ "knex": "^3.2.8",
26
+ "dotenv": "^17.3.1"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^22.10.0",
30
+ "@types/express": "^5.0.0",
31
+ "typescript": "^6.0.2",
32
+ "eslint": "^10.1.0"
33
+ },
34
+ "openclaw": {
35
+ "extensions": [
36
+ "./index.ts"
37
+ ]
38
+ },
39
+ "keywords": [
40
+ "openclaw",
41
+ "plugin",
42
+ "bsv",
43
+ "micropayments",
44
+ "monetization",
45
+ "402"
46
+ ],
47
+ "author": "Tomás Díaz",
48
+ "license": "MIT"
49
+ }