Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/radius-mcp-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
recoverTypedDataAddress,
type TypedData,
} from 'viem';
import type { CacheConfig, RadiusConfig, MCPHandler, MCPRequest, MCPResponse, EVMAuthErrorResponse, EVMAuthProof, ProofErrorCode } from './types/index.js';
import type { CacheConfig, RadiusConfig, MCPRequest, MCPResponse, EVMAuthErrorResponse, EVMAuthProof, ProofErrorCode } from './types/index.js';
import { RadiusError } from './types/errors.js';

const ERC1155_ABI = [
Expand Down Expand Up @@ -148,10 +148,10 @@ export class RadiusMcpSdk {
}
}

protect(tokenId: number | number[], handler: MCPHandler): MCPHandler {
protect<T extends (...args: any[]) => any>(tokenId: number | number[], handler: T): T {
const tokenIds = Array.isArray(tokenId) ? tokenId : [tokenId];

return async (request: MCPRequest, extra?: unknown): Promise<MCPResponse> => {
return (async (request: MCPRequest, extra?: unknown): Promise<MCPResponse> => {
const authFlowId = `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;

if (this.config.debug) {
Expand Down Expand Up @@ -274,7 +274,7 @@ export class RadiusMcpSdk {
}
return this.handleError(error as Error, tokenIds, toolName);
}
};
}) as T;
}

private extractProof(request: MCPRequest): EVMAuthProof | null {
Expand Down
34 changes: 20 additions & 14 deletions src/types/errors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
export const RadiusErrorCode = {
INVALID_CONFIG: 'INVALID_CONFIG',
PROOF_INVALID: 'PROOF_INVALID',
PROOF_EXPIRED: 'PROOF_EXPIRED',
PROOF_MALFORMED: 'PROOF_MALFORMED',
CHAIN_MISMATCH: 'CHAIN_MISMATCH',
CONTRACT_ERROR: 'CONTRACT_ERROR',
NETWORK_ERROR: 'NETWORK_ERROR',
SIGNATURE_INVALID: 'SIGNATURE_INVALID',
CONTRACT_MISMATCH: 'CONTRACT_MISMATCH',
SIGNER_MISMATCH: 'SIGNER_MISMATCH',
NONCE_INVALID: 'NONCE_INVALID',
PROOF_MISSING: 'PROOF_MISSING',
AUTH_PROOF_MISSING: 'AUTH_PROOF_MISSING',
AUTH_INVALID: 'AUTH_INVALID',
TOKEN_MISSING: 'TOKEN_MISSING'
} as const;

export type RadiusErrorCode = typeof RadiusErrorCode[keyof typeof RadiusErrorCode];

export class RadiusError extends Error {
constructor(
public code: RadiusErrorCode,
Expand All @@ -8,17 +28,3 @@ export class RadiusError extends Error {
this.name = 'RadiusError';
}
}

export type RadiusErrorCode =
| 'INVALID_CONFIG'
| 'PROOF_INVALID'
| 'PROOF_EXPIRED'
| 'PROOF_MALFORMED'
| 'CHAIN_MISMATCH'
| 'CONTRACT_ERROR'
| 'NETWORK_ERROR'
| 'SIGNATURE_INVALID'
| 'CONTRACT_MISMATCH'
| 'SIGNER_MISMATCH'
| 'NONCE_INVALID'
| 'PROOF_MISSING';