@lynq/crypto 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/dist/index.d.ts +62 -0
- package/dist/index.mjs +2 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 hogekai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ToolContext, ToolMiddleware, MCPServer } from '@lynq/lynq';
|
|
2
|
+
|
|
3
|
+
interface CryptoPaymentOptions {
|
|
4
|
+
/** Middleware name. Default: "crypto" */
|
|
5
|
+
name?: string;
|
|
6
|
+
/** Token symbol. Default: "USDC" */
|
|
7
|
+
token?: "USDC" | "USDT" | "DAI" | "ETH" | string;
|
|
8
|
+
/** Recipient wallet address. */
|
|
9
|
+
recipient: string;
|
|
10
|
+
/** Amount in token units. */
|
|
11
|
+
amount: number;
|
|
12
|
+
/** Network. Default: "base" */
|
|
13
|
+
network?: "base" | "base-sepolia" | "ethereum" | "polygon" | "solana" | string;
|
|
14
|
+
/** Base URL of your server. */
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
/** Callback path. Default: "/payment/crypto/callback" */
|
|
17
|
+
callbackPath?: string;
|
|
18
|
+
/** Session key for payment data. Default: "payment" */
|
|
19
|
+
sessionKey?: string;
|
|
20
|
+
/** If true, only charge once per session per tool. Default: false */
|
|
21
|
+
once?: boolean;
|
|
22
|
+
/** Message shown to user. */
|
|
23
|
+
message?: string;
|
|
24
|
+
/** Timeout in ms. Default: 300000 */
|
|
25
|
+
timeout?: number;
|
|
26
|
+
/** Custom skip condition. Takes priority over sessionKey check. */
|
|
27
|
+
skipIf?: (c: ToolContext) => boolean | Promise<boolean>;
|
|
28
|
+
/** Called after payment completes successfully, before next(). */
|
|
29
|
+
onComplete?: (c: ToolContext) => void | Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** @deprecated Use `CryptoPaymentOptions` instead. */
|
|
32
|
+
type UsdcPaymentOptions = CryptoPaymentOptions;
|
|
33
|
+
declare function crypto(options: CryptoPaymentOptions): ToolMiddleware;
|
|
34
|
+
/** @deprecated Use `crypto()` from `@lynq/crypto` instead. */
|
|
35
|
+
declare const usdcPayment: typeof crypto;
|
|
36
|
+
interface HandleCallbackOptions {
|
|
37
|
+
/** RPC URL for the network. */
|
|
38
|
+
rpcUrl?: string;
|
|
39
|
+
/** Expected recipient address. */
|
|
40
|
+
recipient: string;
|
|
41
|
+
/** Expected amount. */
|
|
42
|
+
amount: number;
|
|
43
|
+
/** Session key. Default: "payment" */
|
|
44
|
+
sessionKey?: string;
|
|
45
|
+
}
|
|
46
|
+
/** @deprecated Use `HandleCallbackOptions` instead. */
|
|
47
|
+
type HandleUsdcCallbackOptions = HandleCallbackOptions;
|
|
48
|
+
/**
|
|
49
|
+
* Handle crypto payment callback. Call from your HTTP callback route.
|
|
50
|
+
* Verifies the on-chain transaction, stores in session, and completes elicitation.
|
|
51
|
+
*/
|
|
52
|
+
declare function handleCallback(server: MCPServer, params: {
|
|
53
|
+
state: string;
|
|
54
|
+
txHash: string;
|
|
55
|
+
}, options: HandleCallbackOptions): Promise<{
|
|
56
|
+
success: boolean;
|
|
57
|
+
error?: string;
|
|
58
|
+
}>;
|
|
59
|
+
/** @deprecated Use `handleCallback()` from `@lynq/crypto` instead. */
|
|
60
|
+
declare const handleUsdcCallback: typeof handleCallback;
|
|
61
|
+
|
|
62
|
+
export { type CryptoPaymentOptions, type HandleCallbackOptions, type HandleUsdcCallbackOptions, type UsdcPaymentOptions, crypto, handleCallback, handleUsdcCallback, usdcPayment };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {payment}from'@lynq/lynq/payment';function g(e){let{recipient:n,amount:t,token:r="USDC",network:a="base",baseUrl:o,callbackPath:s="/payment/crypto/callback",once:p=false}=e,y=e.name??"crypto",m=e.sessionKey??"payment",d=e.message??`Payment required (${t} ${r}).`,i={name:y,sessionKey:m,message:d,buildUrl:({sessionId:c,elicitationId:l})=>{let f=new URLSearchParams({recipient:n,amount:String(t),token:r,network:a,state:`${c}:${l}`});return `${o}${s}?${f}`}};e.timeout!==void 0&&(i.timeout=e.timeout),e.skipIf&&(i.skipIf=e.skipIf),e.onComplete&&(i.onComplete=e.onComplete);let u=payment(i);return p?u:{...u,onResult(c,l){return l.session.set(m,void 0),c}}}var P=g;async function C(e,n,t){let r=t.sessionKey??"payment",[a,o]=n.state.split(":");if(!a||!o)return {success:false,error:"Invalid state parameter"};try{return await h(n.txHash,t)?(e.session(a).set(r,{provider:"crypto",txHash:n.txHash,amount:t.amount,recipient:t.recipient,paidAt:new Date().toISOString()}),e.completeElicitation(o),{success:!0}):{success:!1,error:"Transaction verification failed"}}catch(s){return {success:false,error:s instanceof Error?s.message:String(s)}}}var x=C;async function h(e,n){let t=n.rpcUrl??"https://mainnet.base.org";try{return (await(await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:"eth_getTransactionReceipt",params:[e]})})).json()).result?.status==="0x1"}catch{return false}}
|
|
2
|
+
export{g as crypto,C as handleCallback,x as handleUsdcCallback,P as usdcPayment};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lynq/crypto",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Crypto payment provider for lynq MCP framework.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@lynq/lynq": "^0.8.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"tsup": "^8.0.0",
|
|
21
|
+
"typescript": "^5.6.0",
|
|
22
|
+
"vitest": "^2.0.0",
|
|
23
|
+
"zod": "^3.24.0"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/hogekai/lynq",
|
|
31
|
+
"directory": "packages/crypto"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
41
|
+
}
|
|
42
|
+
}
|