aegis-ows-gate 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/dist/announce.d.ts +3 -0
- package/dist/announce.d.ts.map +1 -0
- package/dist/announce.js +20 -0
- package/dist/announce.js.map +1 -0
- package/dist/discover.d.ts +9 -0
- package/dist/discover.d.ts.map +1 -0
- package/dist/discover.js +21 -0
- package/dist/discover.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +155 -0
- package/dist/index.js.map +1 -0
- package/dist/solana-pay.d.ts +2 -0
- package/dist/solana-pay.d.ts.map +1 -0
- package/dist/solana-pay.js +33 -0
- package/dist/solana-pay.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"announce.d.ts","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAmB3E"}
|
package/dist/announce.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { postMessage } from "@aegis-ows/shared";
|
|
2
|
+
export function announceServices(config, baseUrl) {
|
|
3
|
+
const services = Object.entries(config.endpoints)
|
|
4
|
+
.filter(([_, ep]) => ep.price !== "0")
|
|
5
|
+
.map(([path, ep]) => ({
|
|
6
|
+
endpoint: path,
|
|
7
|
+
price: ep.price,
|
|
8
|
+
token: ep.token ?? "USDC",
|
|
9
|
+
description: ep.description ?? path,
|
|
10
|
+
baseUrl,
|
|
11
|
+
}));
|
|
12
|
+
const announcement = {
|
|
13
|
+
type: "service_announcement",
|
|
14
|
+
agentId: config.walletName,
|
|
15
|
+
timestamp: new Date().toISOString(),
|
|
16
|
+
services,
|
|
17
|
+
};
|
|
18
|
+
postMessage(announcement);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=announce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"announce.js","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA4B,MAAM,mBAAmB,CAAC;AAG1E,MAAM,UAAU,gBAAgB,CAAC,MAAmB,EAAE,OAAe;IACnE,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;SAC9C,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,KAAK,GAAG,CAAC;SACrC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACpB,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,EAAE,CAAC,KAAK;QACf,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,MAAM;QACzB,WAAW,EAAE,EAAE,CAAC,WAAW,IAAI,IAAI;QACnC,OAAO;KACR,CAAC,CAAC,CAAC;IAEN,MAAM,YAAY,GAAwB;QACxC,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,MAAM,CAAC,UAAU;QAC1B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,QAAQ;KACT,CAAC;IAEF,WAAW,CAAC,YAAY,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface DiscoveredService {
|
|
2
|
+
endpoint: string;
|
|
3
|
+
price: string;
|
|
4
|
+
token: string;
|
|
5
|
+
description: string;
|
|
6
|
+
fullUrl: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function findServices(query: string, callerAgentId: string): DiscoveredService[];
|
|
9
|
+
//# sourceMappingURL=discover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../src/discover.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAmBtF"}
|
package/dist/discover.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { discoverServices, postMessage } from "@aegis-ows/shared";
|
|
2
|
+
export function findServices(query, callerAgentId) {
|
|
3
|
+
// Post a query message to the bus (for visibility in dashboard)
|
|
4
|
+
const queryMsg = {
|
|
5
|
+
type: "service_query",
|
|
6
|
+
agentId: callerAgentId,
|
|
7
|
+
timestamp: new Date().toISOString(),
|
|
8
|
+
query,
|
|
9
|
+
};
|
|
10
|
+
postMessage(queryMsg);
|
|
11
|
+
// Search announcements
|
|
12
|
+
const matches = discoverServices(query);
|
|
13
|
+
return matches.map((m) => ({
|
|
14
|
+
endpoint: m.endpoint,
|
|
15
|
+
price: m.price,
|
|
16
|
+
token: m.token,
|
|
17
|
+
description: m.description,
|
|
18
|
+
fullUrl: m.baseUrl + m.endpoint,
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=discover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.js","sourceRoot":"","sources":["../src/discover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAqB,MAAM,mBAAmB,CAAC;AAUrF,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,aAAqB;IAC/D,gEAAgE;IAChE,MAAM,QAAQ,GAAiB;QAC7B,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,aAAa;QACtB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,KAAK;KACN,CAAC;IACF,WAAW,CAAC,QAAQ,CAAC,CAAC;IAEtB,uBAAuB;IACvB,MAAM,OAAO,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACzB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,QAAQ;KAChC,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
import { Router } from "express";
|
|
3
|
+
export { announceServices } from "./announce.js";
|
|
4
|
+
export { findServices, type DiscoveredService } from "./discover.js";
|
|
5
|
+
export interface AegisGateOptions {
|
|
6
|
+
price: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
agentId: string;
|
|
9
|
+
walletAddress?: string;
|
|
10
|
+
network?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function aegisGate(options: AegisGateOptions): (req: Request, res: Response, next: NextFunction) => void;
|
|
14
|
+
export declare function payAndFetch(url: string, callerAgentId: string): Promise<unknown>;
|
|
15
|
+
export interface AegisConfig {
|
|
16
|
+
walletName: string;
|
|
17
|
+
network?: string;
|
|
18
|
+
endpoints: Record<string, {
|
|
19
|
+
price: string;
|
|
20
|
+
token?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
export declare function loadConfig(configPath?: string): AegisConfig;
|
|
25
|
+
export declare function aegisGateFromConfig(configPath?: string): Router;
|
|
26
|
+
//# sourceMappingURL=index.d.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ED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { appendEarningsEntry, ensureAegisDir } from "@aegis-ows/shared";
|
|
5
|
+
import { appendLedgerEntry } from "@aegis-ows/shared";
|
|
6
|
+
import { signMessage, getWallet } from "@open-wallet-standard/core";
|
|
7
|
+
import { sendSolPayment } from "./solana-pay.js";
|
|
8
|
+
export { announceServices } from "./announce.js";
|
|
9
|
+
export { findServices } from "./discover.js";
|
|
10
|
+
export function aegisGate(options) {
|
|
11
|
+
const token = options.token ?? "USDC";
|
|
12
|
+
const network = options.network ?? "eip155:1";
|
|
13
|
+
// Try to get real wallet address from OWS at initialization
|
|
14
|
+
let resolvedAddress = options.walletAddress ?? `wallet:${options.agentId}`;
|
|
15
|
+
try {
|
|
16
|
+
const w = getWallet(options.agentId);
|
|
17
|
+
const evmAccount = w?.accounts?.find((a) => a.chainId.startsWith("eip155:"));
|
|
18
|
+
if (evmAccount) {
|
|
19
|
+
resolvedAddress = evmAccount.address;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// OWS not available, use fallback
|
|
24
|
+
}
|
|
25
|
+
return (req, res, next) => {
|
|
26
|
+
const paymentHeader = req.headers["x-payment"];
|
|
27
|
+
if (!paymentHeader) {
|
|
28
|
+
const walletAddress = resolvedAddress;
|
|
29
|
+
res.status(402).json({
|
|
30
|
+
// x402 spec fields
|
|
31
|
+
x402Version: 1,
|
|
32
|
+
payTo: walletAddress,
|
|
33
|
+
price: options.price,
|
|
34
|
+
token,
|
|
35
|
+
// extended fields for backward compat
|
|
36
|
+
network,
|
|
37
|
+
resource: req.path,
|
|
38
|
+
agentId: options.agentId,
|
|
39
|
+
description: options.description,
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const payment = JSON.parse(paymentHeader);
|
|
45
|
+
// Verify timestamp freshness to prevent replay attacks (5-minute window)
|
|
46
|
+
if (payment.timestamp) {
|
|
47
|
+
const age = Date.now() - new Date(payment.timestamp).getTime();
|
|
48
|
+
if (age > 5 * 60 * 1000) {
|
|
49
|
+
res.status(401).json({ error: "Payment proof expired" });
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Verify that a non-trivial txHash / signature is present
|
|
54
|
+
if (!payment.txHash || payment.txHash.length < 10) {
|
|
55
|
+
res.status(401).json({ error: "Invalid payment signature" });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
ensureAegisDir();
|
|
59
|
+
appendEarningsEntry({
|
|
60
|
+
timestamp: new Date().toISOString(),
|
|
61
|
+
agentId: options.agentId,
|
|
62
|
+
endpoint: req.path,
|
|
63
|
+
fromAgent: payment.fromAgent ?? "unknown",
|
|
64
|
+
token,
|
|
65
|
+
amount: options.price,
|
|
66
|
+
txHash: payment.txHash,
|
|
67
|
+
});
|
|
68
|
+
next();
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
res.status(400).json({ error: "Invalid payment header" });
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export async function payAndFetch(url, callerAgentId) {
|
|
76
|
+
// Step 1: Probe the endpoint
|
|
77
|
+
const probeRes = await fetch(url);
|
|
78
|
+
if (probeRes.status !== 402) {
|
|
79
|
+
return probeRes.json();
|
|
80
|
+
}
|
|
81
|
+
const details = await probeRes.json();
|
|
82
|
+
// Support both new spec field names and legacy field names
|
|
83
|
+
const amount = details.price ?? details.amount ?? "0";
|
|
84
|
+
const recipient = details.payTo ?? details.recipient ?? details.agentId;
|
|
85
|
+
// Step 2: Log spending
|
|
86
|
+
ensureAegisDir();
|
|
87
|
+
appendLedgerEntry({
|
|
88
|
+
timestamp: new Date().toISOString(),
|
|
89
|
+
apiKeyId: callerAgentId,
|
|
90
|
+
chainId: details.network ?? "eip155:1",
|
|
91
|
+
token: details.token ?? "USDC",
|
|
92
|
+
amount,
|
|
93
|
+
tool: url,
|
|
94
|
+
description: `x402 payment to ${recipient} for ${details.resource ?? url}`,
|
|
95
|
+
});
|
|
96
|
+
// Step 3: Sign a payment proof using the caller's OWS wallet
|
|
97
|
+
const paymentTimestamp = new Date().toISOString();
|
|
98
|
+
let txProof;
|
|
99
|
+
try {
|
|
100
|
+
const message = JSON.stringify({
|
|
101
|
+
action: "x402_payment",
|
|
102
|
+
to: recipient,
|
|
103
|
+
amount,
|
|
104
|
+
token: details.token ?? "USDC",
|
|
105
|
+
timestamp: paymentTimestamp,
|
|
106
|
+
});
|
|
107
|
+
const result = signMessage(callerAgentId, "evm", message);
|
|
108
|
+
txProof = result.signature;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Fallback to mock if OWS wallet not available (e.g., on Vercel)
|
|
112
|
+
txProof = `mock-tx-${Date.now()}`;
|
|
113
|
+
}
|
|
114
|
+
// Try real on-chain Solana payment when the network is Solana
|
|
115
|
+
if (details.network?.includes("solana") || (recipient && recipient.length === 44)) {
|
|
116
|
+
const solTxHash = await sendSolPayment(callerAgentId, recipient ?? "", parseFloat(amount) * 0.001);
|
|
117
|
+
if (solTxHash) {
|
|
118
|
+
txProof = solTxHash;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Step 4: Retry with payment — include timestamp so Gate can verify freshness
|
|
122
|
+
const paidRes = await fetch(url, {
|
|
123
|
+
headers: {
|
|
124
|
+
"X-PAYMENT": JSON.stringify({
|
|
125
|
+
fromAgent: callerAgentId,
|
|
126
|
+
token: details.token,
|
|
127
|
+
amount,
|
|
128
|
+
txHash: txProof,
|
|
129
|
+
timestamp: paymentTimestamp,
|
|
130
|
+
}),
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
return paidRes.json();
|
|
134
|
+
}
|
|
135
|
+
export function loadConfig(configPath) {
|
|
136
|
+
const path = configPath ?? join(process.cwd(), "aegis.config.json");
|
|
137
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
138
|
+
}
|
|
139
|
+
export function aegisGateFromConfig(configPath) {
|
|
140
|
+
const config = loadConfig(configPath);
|
|
141
|
+
const router = Router();
|
|
142
|
+
for (const [path, endpoint] of Object.entries(config.endpoints)) {
|
|
143
|
+
if (endpoint.price === "0")
|
|
144
|
+
continue; // Free endpoints don't need gate
|
|
145
|
+
router.use(path, aegisGate({
|
|
146
|
+
price: endpoint.price,
|
|
147
|
+
token: endpoint.token ?? "USDC",
|
|
148
|
+
agentId: config.walletName,
|
|
149
|
+
network: config.network ?? "eip155:1",
|
|
150
|
+
description: endpoint.description,
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
return router;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,YAAY,EAA0B,MAAM,eAAe,CAAC;AAWrE,MAAM,UAAU,SAAS,CAAC,OAAyB;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,UAAU,CAAC;IAE9C,4D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AG;YAAE,SAAS,CAAC,iCAAiC;QACvE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC;YACzB,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,KAAK,EAAE,QAAQ,CAAC,KAAK,IAAI,MAAM;YAC/B,OAAO,EAAE,MAAM,CAAC,UAAU;YAC1B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,UAAU;YACrC,WAAW,EAAE,QAAQ,CAAC,WAAW;SAClC,CAAC,CAAC,CAAC;IACN,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana-pay.d.ts","sourceRoot":"","sources":["../src/solana-pay.ts"],"names":[],"mappings":"AAKA,wBAAsB,cAAc,CAClC,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA0BxB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Connection, PublicKey, SystemProgram, Transaction, LAMPORTS_PER_SOL } from "@solana/web3.js";
|
|
2
|
+
import { execSync } from "node:child_process";
|
|
3
|
+
const DEVNET_RPC = "https://api.devnet.solana.com";
|
|
4
|
+
export async function sendSolPayment(fromWalletName, toAddress, amountSol) {
|
|
5
|
+
try {
|
|
6
|
+
const conn = new Connection(DEVNET_RPC, "finalized");
|
|
7
|
+
const fromAddr = getWalletSolanaAddress(fromWalletName);
|
|
8
|
+
if (!fromAddr)
|
|
9
|
+
return null;
|
|
10
|
+
const from = new PublicKey(fromAddr);
|
|
11
|
+
const to = new PublicKey(toAddress);
|
|
12
|
+
const { blockhash } = await conn.getLatestBlockhash("finalized");
|
|
13
|
+
const tx = new Transaction({ recentBlockhash: blockhash, feePayer: from })
|
|
14
|
+
.add(SystemProgram.transfer({ fromPubkey: from, toPubkey: to, lamports: Math.floor(amountSol * LAMPORTS_PER_SOL) }));
|
|
15
|
+
const hex = Buffer.from(tx.serialize({ verifySignatures: false, requireAllSignatures: false })).toString("hex");
|
|
16
|
+
const result = execSync(`ows sign send-tx --chain solana --wallet ${fromWalletName} --rpc-url ${DEVNET_RPC} --json --tx ${hex}`, { encoding: "utf-8", timeout: 30000, env: { ...process.env, PATH: (process.env.HOME ?? "") + "/.ows/bin:" + process.env.PATH } });
|
|
17
|
+
const parsed = JSON.parse(result.trim());
|
|
18
|
+
return parsed.tx_hash ?? null;
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
console.error("Solana payment failed:", err.message?.slice(0, 100));
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function getWalletSolanaAddress(name) {
|
|
26
|
+
const addresses = {
|
|
27
|
+
"data-miner": "2G55SdspdgSLcrXm3ZcfSHuDhvuhXtQLWqf1zVbAYCcq",
|
|
28
|
+
"analyst": "CePyeKXCtB6RzAatosDnnun3yryUzETKXA5rNEjPeSkL",
|
|
29
|
+
"research-buyer": "9LK89Mk3xQP3qf3bJjxW8Qe9HoiPer4EisY5tUoPY22A",
|
|
30
|
+
};
|
|
31
|
+
return addresses[name] ?? null;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=solana-pay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana-pay.js","sourceRoot":"","sources":["../src/solana-pay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACtG,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,UAAU,GAAG,+BAA+B,CAAC;AAEnD,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,cAAsB,EACtB,SAAiB,EACjB,SAAiB;IAEjB,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,UAAU,EA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jE,OAAO,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC;IAChC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAG,GAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QAC/E,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAY;IAC1C,MAAM,SAAS,GAA2B;QACxC,YAAY,EAAE,8CAA8C;QAC5D,SAAS,EAAE,8CAA8C;QACzD,gBAAgB,EAAE,8CAA8C;KACjE,CAAC;IACF,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AACjC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aegis-ows-gate",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Express middleware for x402 micropayments — turn any API into a paid service",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"aegis-gate": "dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"keywords": [
|
|
17
|
+
"x402",
|
|
18
|
+
"micropayments",
|
|
19
|
+
"express",
|
|
20
|
+
"middleware",
|
|
21
|
+
"ows",
|
|
22
|
+
"agents",
|
|
23
|
+
"commerce",
|
|
24
|
+
"solana"
|
|
25
|
+
],
|
|
26
|
+
"author": "Raj Karia",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/rajkaria/aegis"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://useaegis.xyz",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"dev": "tsc --watch"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@open-wallet-standard/core": "*",
|
|
39
|
+
"@solana/web3.js": "^1.98.0",
|
|
40
|
+
"express": "^5.0.0",
|
|
41
|
+
"aegis-ows-shared": "^0.1.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "^5.7.0",
|
|
45
|
+
"@types/node": "^22.0.0",
|
|
46
|
+
"@types/express": "^5.0.0"
|
|
47
|
+
}
|
|
48
|
+
}
|