@1ly/mcp-server 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/LICENSE +21 -0
- package/README.md +330 -0
- package/dist/budget.d.ts +7 -0
- package/dist/budget.d.ts.map +1 -0
- package/dist/budget.js +64 -0
- package/dist/budget.js.map +1 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +37 -0
- package/dist/config.js.map +1 -0
- package/dist/http.d.ts +26 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +85 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +22 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +23 -0
- package/dist/mcp.js.map +1 -0
- package/dist/selftest.d.ts +2 -0
- package/dist/selftest.d.ts.map +1 -0
- package/dist/selftest.js +57 -0
- package/dist/selftest.js.map +1 -0
- package/dist/tools/call.d.ts +36 -0
- package/dist/tools/call.d.ts.map +1 -0
- package/dist/tools/call.js +131 -0
- package/dist/tools/call.js.map +1 -0
- package/dist/tools/create-link.d.ts +44 -0
- package/dist/tools/create-link.d.ts.map +1 -0
- package/dist/tools/create-link.js +62 -0
- package/dist/tools/create-link.js.map +1 -0
- package/dist/tools/delete-link.d.ts +22 -0
- package/dist/tools/delete-link.d.ts.map +1 -0
- package/dist/tools/delete-link.js +37 -0
- package/dist/tools/delete-link.js.map +1 -0
- package/dist/tools/details.d.ts +23 -0
- package/dist/tools/details.d.ts.map +1 -0
- package/dist/tools/details.js +101 -0
- package/dist/tools/details.js.map +1 -0
- package/dist/tools/get-stats.d.ts +26 -0
- package/dist/tools/get-stats.d.ts.map +1 -0
- package/dist/tools/get-stats.js +44 -0
- package/dist/tools/get-stats.js.map +1 -0
- package/dist/tools/list-links.d.ts +18 -0
- package/dist/tools/list-links.d.ts.map +1 -0
- package/dist/tools/list-links.js +30 -0
- package/dist/tools/list-links.js.map +1 -0
- package/dist/tools/review.d.ts +35 -0
- package/dist/tools/review.d.ts.map +1 -0
- package/dist/tools/review.js +73 -0
- package/dist/tools/review.js.map +1 -0
- package/dist/tools/search.d.ts +40 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +79 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/update-link.d.ts +43 -0
- package/dist/tools/update-link.d.ts.map +1 -0
- package/dist/tools/update-link.js +61 -0
- package/dist/tools/update-link.js.map +1 -0
- package/dist/types.d.ts +61 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/wallet/evm.d.ts +48 -0
- package/dist/wallet/evm.d.ts.map +1 -0
- package/dist/wallet/evm.js +229 -0
- package/dist/wallet/evm.js.map +1 -0
- package/dist/wallet/solana.d.ts +6 -0
- package/dist/wallet/solana.d.ts.map +1 -0
- package/dist/wallet/solana.js +95 -0
- package/dist/wallet/solana.js.map +1 -0
- package/package.json +70 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface ApiResult {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
description: string;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
price: number;
|
|
7
|
+
currency: string;
|
|
8
|
+
type: "api" | "standard";
|
|
9
|
+
seller: {
|
|
10
|
+
username: string;
|
|
11
|
+
displayName: string;
|
|
12
|
+
};
|
|
13
|
+
stats: {
|
|
14
|
+
buyers: number;
|
|
15
|
+
reviews: number;
|
|
16
|
+
rating: number | null;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface SearchResponse {
|
|
20
|
+
results: ApiResult[];
|
|
21
|
+
pagination: {
|
|
22
|
+
total: number;
|
|
23
|
+
limit: number;
|
|
24
|
+
offset: number;
|
|
25
|
+
hasMore: boolean;
|
|
26
|
+
};
|
|
27
|
+
meta: {
|
|
28
|
+
responseTime: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface Review {
|
|
32
|
+
id: string;
|
|
33
|
+
positive: boolean;
|
|
34
|
+
comment: string | null;
|
|
35
|
+
wallet: string;
|
|
36
|
+
createdAt: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ReviewsResponse {
|
|
39
|
+
reviews: Review[];
|
|
40
|
+
stats: {
|
|
41
|
+
total: number;
|
|
42
|
+
positive: number;
|
|
43
|
+
negative: number;
|
|
44
|
+
rating: number | null;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export interface PaymentRequirements {
|
|
48
|
+
network: string;
|
|
49
|
+
price: string;
|
|
50
|
+
treasury: string;
|
|
51
|
+
facilitator?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface PurchaseMetadata {
|
|
54
|
+
purchaseId: string;
|
|
55
|
+
reviewUrl: string;
|
|
56
|
+
reviewToken: string;
|
|
57
|
+
paidAmount?: number;
|
|
58
|
+
network?: string;
|
|
59
|
+
txSignature?: string;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,KAAK,GAAG,UAAU,CAAC;IACzB,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,KAAK,EAAE;QACL,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,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types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type PrivateKeyAccount } from "viem/accounts";
|
|
2
|
+
import type { PaymentRequired } from "@x402/core/types";
|
|
3
|
+
export declare function loadEvmWallet(keyInput: string): Promise<PrivateKeyAccount>;
|
|
4
|
+
export declare function getEvmWalletAddress(keyInput: string): Promise<string>;
|
|
5
|
+
interface PaymentRequirements {
|
|
6
|
+
maxAmountRequired?: string;
|
|
7
|
+
amount?: string;
|
|
8
|
+
payTo?: string;
|
|
9
|
+
receiver?: string;
|
|
10
|
+
x402Version?: number;
|
|
11
|
+
scheme?: string;
|
|
12
|
+
network?: string;
|
|
13
|
+
asset?: string;
|
|
14
|
+
}
|
|
15
|
+
interface Body402 {
|
|
16
|
+
x402Version?: number;
|
|
17
|
+
accepts?: Array<{
|
|
18
|
+
scheme: string;
|
|
19
|
+
network: string;
|
|
20
|
+
amount?: string;
|
|
21
|
+
maxAmountRequired?: string;
|
|
22
|
+
payTo: string;
|
|
23
|
+
asset?: string;
|
|
24
|
+
maxTimeoutSeconds?: number;
|
|
25
|
+
extra?: Record<string, unknown>;
|
|
26
|
+
}>;
|
|
27
|
+
resource?: {
|
|
28
|
+
url: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
mimeType?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Build EVM payment using @x402/evm library
|
|
35
|
+
* This matches the format used by the frontend DynamicX402Client
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildEvmPayment(requirements: PaymentRequirements, account: PrivateKeyAccount, body402?: Body402): Promise<string>;
|
|
38
|
+
export declare function loadEvmWalletWithKey(keyInput: string): Promise<{
|
|
39
|
+
account: PrivateKeyAccount;
|
|
40
|
+
privateKey: `0x${string}`;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Simplified EVM payment builder that works with stored private key
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildEvmPaymentSimple(requirements: PaymentRequirements, keyInput: string, body402?: Body402): Promise<string>;
|
|
46
|
+
export declare function buildEvmPaymentSignature(paymentRequired: PaymentRequired, keyInput: string): Promise<string>;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=evm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../src/wallet/evm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAM5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMxD,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAahF;AAED,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG3E;AAED,UAAU,mBAAmB;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,OAAO;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACjC,CAAC,CAAC;IACH,QAAQ,CAAC,EAAE;QACT,GAAG,EAAE,MAAM,CAAC;QACZ,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAaD;;;GAGG;AACH,wBAAsB,eAAe,CACnC,YAAY,EAAE,mBAAmB,EACjC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,MAAM,CAAC,CAmEjB;AAYD,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,iBAAiB,CAAC;IAAC,UAAU,EAAE,KAAK,MAAM,EAAE,CAAA;CAAE,CAAC,CAc/H;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,YAAY,EAAE,mBAAmB,EACjC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,MAAM,CAAC,CAmDjB;AAED,wBAAsB,wBAAwB,CAC5C,eAAe,EAAE,eAAe,EAChC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAoCjB"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadEvmWallet = loadEvmWallet;
|
|
37
|
+
exports.getEvmWalletAddress = getEvmWalletAddress;
|
|
38
|
+
exports.buildEvmPayment = buildEvmPayment;
|
|
39
|
+
exports.loadEvmWalletWithKey = loadEvmWalletWithKey;
|
|
40
|
+
exports.buildEvmPaymentSimple = buildEvmPaymentSimple;
|
|
41
|
+
exports.buildEvmPaymentSignature = buildEvmPaymentSignature;
|
|
42
|
+
const accounts_1 = require("viem/accounts");
|
|
43
|
+
const chains_1 = require("viem/chains");
|
|
44
|
+
const client_1 = require("@x402/core/client");
|
|
45
|
+
const http_1 = require("@x402/core/http");
|
|
46
|
+
const evm_1 = require("@x402/evm");
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
// Determine network from env
|
|
49
|
+
const IS_TESTNET = process.env.BASE_NETWORK === "sepolia" || process.env.NODE_ENV !== "production";
|
|
50
|
+
const CHAIN = IS_TESTNET ? chains_1.baseSepolia : chains_1.base;
|
|
51
|
+
async function loadEvmWallet(keyInput) {
|
|
52
|
+
let privateKey;
|
|
53
|
+
if (keyInput.startsWith("0x")) {
|
|
54
|
+
privateKey = keyInput;
|
|
55
|
+
}
|
|
56
|
+
else if (fs.existsSync(keyInput)) {
|
|
57
|
+
const content = fs.readFileSync(keyInput, "utf-8").trim();
|
|
58
|
+
privateKey = (content.startsWith("0x") ? content : `0x${content}`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw new Error(`EVM wallet key file not found: ${keyInput}`);
|
|
62
|
+
}
|
|
63
|
+
return (0, accounts_1.privateKeyToAccount)(privateKey);
|
|
64
|
+
}
|
|
65
|
+
async function getEvmWalletAddress(keyInput) {
|
|
66
|
+
const account = await loadEvmWallet(keyInput);
|
|
67
|
+
return account.address;
|
|
68
|
+
}
|
|
69
|
+
function resolvePaymentRequired(httpClient, responseBody) {
|
|
70
|
+
// @x402/core only accepts v2 via PAYMENT-REQUIRED header; use body directly when present.
|
|
71
|
+
if (responseBody && responseBody.x402Version && responseBody.x402Version !== 1) {
|
|
72
|
+
return responseBody;
|
|
73
|
+
}
|
|
74
|
+
return httpClient.getPaymentRequiredResponse(() => null, responseBody);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build EVM payment using @x402/evm library
|
|
78
|
+
* This matches the format used by the frontend DynamicX402Client
|
|
79
|
+
*/
|
|
80
|
+
async function buildEvmPayment(requirements, account, body402) {
|
|
81
|
+
// Create EVM signer compatible with @x402/evm
|
|
82
|
+
const evmSigner = {
|
|
83
|
+
address: account.address,
|
|
84
|
+
signTypedData: async (params) => {
|
|
85
|
+
const { signTypedData } = await import("viem/accounts");
|
|
86
|
+
return signTypedData({
|
|
87
|
+
privateKey: account.source === "privateKey"
|
|
88
|
+
? account.privateKey
|
|
89
|
+
: await getPrivateKeyFromAccount(account),
|
|
90
|
+
domain: params.domain,
|
|
91
|
+
types: params.types,
|
|
92
|
+
primaryType: params.primaryType,
|
|
93
|
+
message: params.message,
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
// Build x402 client with EVM scheme
|
|
98
|
+
const coreClient = new client_1.x402Client().register("eip155:*", new evm_1.ExactEvmScheme(evmSigner));
|
|
99
|
+
const httpClient = new http_1.x402HTTPClient(coreClient);
|
|
100
|
+
// Reconstruct the 402 response body if not provided
|
|
101
|
+
const responseBody = body402 || {
|
|
102
|
+
x402Version: requirements.x402Version || 2,
|
|
103
|
+
accepts: [{
|
|
104
|
+
scheme: requirements.scheme || "exact",
|
|
105
|
+
network: requirements.network || `eip155:${CHAIN.id}`,
|
|
106
|
+
amount: requirements.maxAmountRequired || requirements.amount || "0",
|
|
107
|
+
payTo: requirements.payTo || requirements.receiver || "",
|
|
108
|
+
asset: requirements.asset,
|
|
109
|
+
maxTimeoutSeconds: 300,
|
|
110
|
+
}],
|
|
111
|
+
resource: {
|
|
112
|
+
url: "https://1ly.store/api",
|
|
113
|
+
description: "API access",
|
|
114
|
+
mimeType: "application/json",
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
// Parse payment required response
|
|
118
|
+
const paymentRequired = resolvePaymentRequired(httpClient, responseBody);
|
|
119
|
+
// Create payment payload (signs EIP-712)
|
|
120
|
+
const paymentPayload = await httpClient.createPaymentPayload(paymentRequired);
|
|
121
|
+
// Encode as header value
|
|
122
|
+
const headers = httpClient.encodePaymentSignatureHeader(paymentPayload);
|
|
123
|
+
// Get the payment header value (try different header names)
|
|
124
|
+
const paymentValue = headers["PAYMENT-SIGNATURE"] ||
|
|
125
|
+
headers["Payment-Signature"] ||
|
|
126
|
+
headers["payment-signature"] ||
|
|
127
|
+
headers["X-PAYMENT"];
|
|
128
|
+
if (!paymentValue) {
|
|
129
|
+
// If using older format, encode the whole payload
|
|
130
|
+
return Buffer.from(JSON.stringify(paymentPayload)).toString("base64");
|
|
131
|
+
}
|
|
132
|
+
return paymentValue;
|
|
133
|
+
}
|
|
134
|
+
// Helper to extract private key from account
|
|
135
|
+
async function getPrivateKeyFromAccount(account) {
|
|
136
|
+
// This is a workaround - viem doesn't expose privateKey directly on the account
|
|
137
|
+
// In practice, we store it when loading
|
|
138
|
+
throw new Error("Cannot extract private key from account. Use loadEvmWallet directly.");
|
|
139
|
+
}
|
|
140
|
+
// Store private key reference for signing
|
|
141
|
+
let storedPrivateKey = null;
|
|
142
|
+
async function loadEvmWalletWithKey(keyInput) {
|
|
143
|
+
let privateKey;
|
|
144
|
+
if (keyInput.startsWith("0x")) {
|
|
145
|
+
privateKey = keyInput;
|
|
146
|
+
}
|
|
147
|
+
else if (fs.existsSync(keyInput)) {
|
|
148
|
+
const content = fs.readFileSync(keyInput, "utf-8").trim();
|
|
149
|
+
privateKey = (content.startsWith("0x") ? content : `0x${content}`);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
throw new Error(`EVM wallet key file not found: ${keyInput}`);
|
|
153
|
+
}
|
|
154
|
+
storedPrivateKey = privateKey;
|
|
155
|
+
return { account: (0, accounts_1.privateKeyToAccount)(privateKey), privateKey };
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Simplified EVM payment builder that works with stored private key
|
|
159
|
+
*/
|
|
160
|
+
async function buildEvmPaymentSimple(requirements, keyInput, body402) {
|
|
161
|
+
const { privateKey } = await loadEvmWalletWithKey(keyInput);
|
|
162
|
+
const account = (0, accounts_1.privateKeyToAccount)(privateKey);
|
|
163
|
+
const evmSigner = {
|
|
164
|
+
address: account.address,
|
|
165
|
+
signTypedData: async (params) => {
|
|
166
|
+
const { signTypedData } = await import("viem/accounts");
|
|
167
|
+
return signTypedData({
|
|
168
|
+
privateKey,
|
|
169
|
+
domain: params.domain,
|
|
170
|
+
types: params.types,
|
|
171
|
+
primaryType: params.primaryType,
|
|
172
|
+
message: params.message,
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
const coreClient = new client_1.x402Client().register("eip155:*", new evm_1.ExactEvmScheme(evmSigner));
|
|
177
|
+
const httpClient = new http_1.x402HTTPClient(coreClient);
|
|
178
|
+
const responseBody = body402 || {
|
|
179
|
+
x402Version: requirements.x402Version || 2,
|
|
180
|
+
accepts: [{
|
|
181
|
+
scheme: requirements.scheme || "exact",
|
|
182
|
+
network: requirements.network || `eip155:${CHAIN.id}`,
|
|
183
|
+
amount: requirements.maxAmountRequired || requirements.amount || "0",
|
|
184
|
+
payTo: requirements.payTo || requirements.receiver || "",
|
|
185
|
+
asset: requirements.asset,
|
|
186
|
+
maxTimeoutSeconds: 300,
|
|
187
|
+
}],
|
|
188
|
+
resource: {
|
|
189
|
+
url: "https://1ly.store/api",
|
|
190
|
+
description: "API access",
|
|
191
|
+
mimeType: "application/json",
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
const paymentRequired = resolvePaymentRequired(httpClient, responseBody);
|
|
195
|
+
const paymentPayload = await httpClient.createPaymentPayload(paymentRequired);
|
|
196
|
+
const headers = httpClient.encodePaymentSignatureHeader(paymentPayload);
|
|
197
|
+
return headers["PAYMENT-SIGNATURE"] ||
|
|
198
|
+
headers["Payment-Signature"] ||
|
|
199
|
+
headers["X-PAYMENT"] ||
|
|
200
|
+
Buffer.from(JSON.stringify(paymentPayload)).toString("base64");
|
|
201
|
+
}
|
|
202
|
+
async function buildEvmPaymentSignature(paymentRequired, keyInput) {
|
|
203
|
+
const { privateKey } = await loadEvmWalletWithKey(keyInput);
|
|
204
|
+
const account = (0, accounts_1.privateKeyToAccount)(privateKey);
|
|
205
|
+
const evmSigner = {
|
|
206
|
+
address: account.address,
|
|
207
|
+
signTypedData: async (params) => {
|
|
208
|
+
const { signTypedData } = await import("viem/accounts");
|
|
209
|
+
return signTypedData({
|
|
210
|
+
privateKey,
|
|
211
|
+
domain: params.domain,
|
|
212
|
+
types: params.types,
|
|
213
|
+
primaryType: params.primaryType,
|
|
214
|
+
message: params.message,
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
const coreClient = new client_1.x402Client((_, accepts) => {
|
|
219
|
+
return accepts.find((entry) => String(entry.network).startsWith("eip155:")) || accepts[0];
|
|
220
|
+
}).register("eip155:*", new evm_1.ExactEvmScheme(evmSigner));
|
|
221
|
+
const httpClient = new http_1.x402HTTPClient(coreClient);
|
|
222
|
+
const paymentPayload = await httpClient.createPaymentPayload(paymentRequired);
|
|
223
|
+
const headers = httpClient.encodePaymentSignatureHeader(paymentPayload);
|
|
224
|
+
return (headers["PAYMENT-SIGNATURE"] ||
|
|
225
|
+
headers["Payment-Signature"] ||
|
|
226
|
+
headers["payment-signature"] ||
|
|
227
|
+
headers["X-PAYMENT"]);
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=evm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evm.js","sourceRoot":"","sources":["../../src/wallet/evm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,sCAaC;AAED,kDAGC;AA+CD,0CAuEC;AAYD,oDAcC;AAKD,sDAuDC;AAED,4DAuCC;AAnRD,4CAA4E;AAC5E,wCAAgD;AAChD,8CAA+C;AAC/C,0CAAiD;AACjD,mCAA2C;AAC3C,uCAAyB;AAGzB,6BAA6B;AAC7B,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AACnG,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,oBAAW,CAAC,CAAC,CAAC,aAAI,CAAC;AAEvC,KAAK,UAAU,aAAa,CAAC,QAAgB;IAClD,IAAI,UAAyB,CAAC;IAE9B,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,UAAU,GAAG,QAAyB,CAAC;IACzC,CAAC;SAAM,IAAI,E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,WAAW,EAAE,MAAM,CAAC,WAAqB;gBACzC,OAAO,EAAE,MAAM,CAAC,OAAkC;aACnD,CAAC,CAAC;QACL,CAAC;KACF,CAAC;IAEF,MAAM,UAAU,GAAG,IAAI,mBAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE;QAC/C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5F,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,oBAAc,CAAC,SAAkB,CAAC,CAAC,CAAC;IAChE,MAAM,UAAU,GAAG,IAAI,qBAAc,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,cAAc,GAAG,MAAM,UAAU,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAC;IAC9E,MAAM,OAAO,GAAG,UAAU,CAAC,4BAA4B,CAAC,cAAc,CAAC,CAAC;IAExE,OAAO,CACL,OAAO,CAAC,mBAAmB,CAAC;QAC5B,OAAO,CAAC,mBAAmB,CAAC;QAC5B,OAAO,CAAC,mBAAmB,CAAC;QAC5B,OAAO,CAAC,WAAW,CAAC,CACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Keypair } from "@solana/web3.js";
|
|
2
|
+
import type { PaymentRequired } from "@x402/core/types";
|
|
3
|
+
export declare function loadSolanaWallet(keyPath: string): Promise<Keypair>;
|
|
4
|
+
export declare function getWalletAddress(type: "solana" | "evm", key: string): Promise<string>;
|
|
5
|
+
export declare function buildSolanaPaymentSignature(paymentRequired: PaymentRequired, wallet: Keypair): Promise<string>;
|
|
6
|
+
//# sourceMappingURL=solana.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../src/wallet/solana.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAO1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBxE;AAED,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,QAAQ,GAAG,KAAK,EACtB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,CAMjB;AAED,wBAAsB,2BAA2B,CAC/C,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,MAAM,CAAC,CAoBjB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadSolanaWallet = loadSolanaWallet;
|
|
37
|
+
exports.getWalletAddress = getWalletAddress;
|
|
38
|
+
exports.buildSolanaPaymentSignature = buildSolanaPaymentSignature;
|
|
39
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const client_1 = require("@x402/core/client");
|
|
42
|
+
const http_1 = require("@x402/core/http");
|
|
43
|
+
const client_2 = require("@x402/svm/exact/client");
|
|
44
|
+
const svm_1 = require("@x402/svm");
|
|
45
|
+
const signers_1 = require("@solana/signers");
|
|
46
|
+
async function loadSolanaWallet(keyPath) {
|
|
47
|
+
let keyData;
|
|
48
|
+
if (keyPath.startsWith("[")) {
|
|
49
|
+
keyData = JSON.parse(keyPath);
|
|
50
|
+
}
|
|
51
|
+
else if (fs.existsSync(keyPath)) {
|
|
52
|
+
const fileContent = fs.readFileSync(keyPath, "utf-8");
|
|
53
|
+
const parsed = JSON.parse(fileContent);
|
|
54
|
+
// Handle both formats:
|
|
55
|
+
// 1. { publicKey: "...", secretKey: [...] } - test wallet format
|
|
56
|
+
// 2. [...] - standard Solana keypair format
|
|
57
|
+
if (Array.isArray(parsed)) {
|
|
58
|
+
keyData = parsed;
|
|
59
|
+
}
|
|
60
|
+
else if (parsed.secretKey && Array.isArray(parsed.secretKey)) {
|
|
61
|
+
keyData = parsed.secretKey;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new Error("Invalid wallet file format");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new Error(`Wallet key file not found: ${keyPath}`);
|
|
69
|
+
}
|
|
70
|
+
return web3_js_1.Keypair.fromSecretKey(Uint8Array.from(keyData));
|
|
71
|
+
}
|
|
72
|
+
async function getWalletAddress(type, key) {
|
|
73
|
+
if (type === "solana") {
|
|
74
|
+
const wallet = await loadSolanaWallet(key);
|
|
75
|
+
return wallet.publicKey.toBase58();
|
|
76
|
+
}
|
|
77
|
+
throw new Error("EVM wallet not yet implemented");
|
|
78
|
+
}
|
|
79
|
+
async function buildSolanaPaymentSignature(paymentRequired, wallet) {
|
|
80
|
+
const signer = await (0, signers_1.createKeyPairSignerFromBytes)(wallet.secretKey);
|
|
81
|
+
const svmSigner = (0, svm_1.toClientSvmSigner)(signer);
|
|
82
|
+
const coreClient = new client_1.x402Client((_, accepts) => {
|
|
83
|
+
return (accepts.find((entry) => String(entry.network).startsWith("solana:")) ||
|
|
84
|
+
accepts[0]);
|
|
85
|
+
});
|
|
86
|
+
(0, client_2.registerExactSvmScheme)(coreClient, { signer: svmSigner });
|
|
87
|
+
const httpClient = new http_1.x402HTTPClient(coreClient);
|
|
88
|
+
const paymentPayload = await httpClient.createPaymentPayload(paymentRequired);
|
|
89
|
+
const headers = httpClient.encodePaymentSignatureHeader(paymentPayload);
|
|
90
|
+
return (headers["PAYMENT-SIGNATURE"] ||
|
|
91
|
+
headers["Payment-Signature"] ||
|
|
92
|
+
headers["payment-signature"] ||
|
|
93
|
+
headers["X-PAYMENT"]);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=solana.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana.js","sourceRoot":"","sources":["../../src/wallet/solana.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,4CAwBC;AAED,4CAS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discover and pay for APIs with AI agents",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"1ly-mcp": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/**",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"dev": "tsc --watch",
|
|
18
|
+
"start": "node dist/index.js",
|
|
19
|
+
"lint": "eslint src",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"test:mcp": "npx tsx scripts/test-mcp.ts",
|
|
22
|
+
"prepack": "npm run build",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"mcp",
|
|
27
|
+
"ai",
|
|
28
|
+
"agent",
|
|
29
|
+
"api",
|
|
30
|
+
"payments",
|
|
31
|
+
"x402",
|
|
32
|
+
"1ly",
|
|
33
|
+
"solana",
|
|
34
|
+
"claude",
|
|
35
|
+
"cursor"
|
|
36
|
+
],
|
|
37
|
+
"author": "1ly.store",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/1lystore/mcp-server.git"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://docs.1ly.store",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/1lystore/mcp-server/issues"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
52
|
+
"@solana/signers": "^2.3.0",
|
|
53
|
+
"@solana/web3.js": "^1.98.0",
|
|
54
|
+
"@x402/core": "^2.2.0",
|
|
55
|
+
"@x402/evm": "^2.2.0",
|
|
56
|
+
"@x402/svm": "^2.2.0",
|
|
57
|
+
"viem": "^2.0.0",
|
|
58
|
+
"zod": "^3.23.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@types/node": "^20.0.0",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
63
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
64
|
+
"eslint": "^9.0.0",
|
|
65
|
+
"globals": "^14.0.0",
|
|
66
|
+
"tsx": "^4.21.0",
|
|
67
|
+
"typescript": "^5.0.0",
|
|
68
|
+
"vitest": "^2.0.0"
|
|
69
|
+
}
|
|
70
|
+
}
|