@atxp/common 0.2.5

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.
Files changed (66) hide show
  1. package/README.md +176 -0
  2. package/dist/commonTestHelpers.d.ts +83 -0
  3. package/dist/commonTestHelpers.d.ts.map +1 -0
  4. package/dist/commonTestHelpers.js +115 -0
  5. package/dist/commonTestHelpers.js.map +1 -0
  6. package/dist/index.d.ts +15 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +15 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/jwt.d.ts +9 -0
  11. package/dist/jwt.d.ts.map +1 -0
  12. package/dist/jwt.js +29 -0
  13. package/dist/jwt.js.map +1 -0
  14. package/dist/logger.d.ts +18 -0
  15. package/dist/logger.d.ts.map +1 -0
  16. package/dist/logger.js +43 -0
  17. package/dist/logger.js.map +1 -0
  18. package/dist/mcpJson.d.ts +9 -0
  19. package/dist/mcpJson.d.ts.map +1 -0
  20. package/dist/mcpJson.js +127 -0
  21. package/dist/mcpJson.js.map +1 -0
  22. package/dist/memoryOAuthDb.d.ts +25 -0
  23. package/dist/memoryOAuthDb.d.ts.map +1 -0
  24. package/dist/memoryOAuthDb.js +97 -0
  25. package/dist/memoryOAuthDb.js.map +1 -0
  26. package/dist/oAuthDb.d.ts +26 -0
  27. package/dist/oAuthDb.d.ts.map +1 -0
  28. package/dist/oAuthDb.js +145 -0
  29. package/dist/oAuthDb.js.map +1 -0
  30. package/dist/oAuthDbFactory.d.ts +30 -0
  31. package/dist/oAuthDbFactory.d.ts.map +1 -0
  32. package/dist/oAuthDbFactory.js +37 -0
  33. package/dist/oAuthDbFactory.js.map +1 -0
  34. package/dist/oAuthResource.d.ts +35 -0
  35. package/dist/oAuthResource.d.ts.map +1 -0
  36. package/dist/oAuthResource.js +241 -0
  37. package/dist/oAuthResource.js.map +1 -0
  38. package/dist/paymentRequiredError.d.ts +6 -0
  39. package/dist/paymentRequiredError.d.ts.map +1 -0
  40. package/dist/paymentRequiredError.js +14 -0
  41. package/dist/paymentRequiredError.js.map +1 -0
  42. package/dist/platform/index.d.ts +27 -0
  43. package/dist/platform/index.d.ts.map +1 -0
  44. package/dist/platform/index.js +204 -0
  45. package/dist/platform/index.js.map +1 -0
  46. package/dist/redisOAuthDb.d.ts +36 -0
  47. package/dist/redisOAuthDb.d.ts.map +1 -0
  48. package/dist/redisOAuthDb.js +160 -0
  49. package/dist/redisOAuthDb.js.map +1 -0
  50. package/dist/servers.d.ts +14 -0
  51. package/dist/servers.d.ts.map +1 -0
  52. package/dist/servers.js +14 -0
  53. package/dist/servers.js.map +1 -0
  54. package/dist/sseParser.d.ts +27 -0
  55. package/dist/sseParser.d.ts.map +1 -0
  56. package/dist/sseParser.js +100 -0
  57. package/dist/sseParser.js.map +1 -0
  58. package/dist/types.d.ts +71 -0
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +9 -0
  61. package/dist/types.js.map +1 -0
  62. package/dist/utils.d.ts +19 -0
  63. package/dist/utils.d.ts.map +1 -0
  64. package/dist/utils.js +24 -0
  65. package/dist/utils.js.map +1 -0
  66. package/package.json +43 -0
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # @atxp/common
2
+
3
+ ATXP Core - Shared utilities and types for Authorization Token Exchange Protocol.
4
+
5
+ ## Overview
6
+
7
+ The ATXP Common package provides shared utilities, types, and core functionality used by both ATXP client and server implementations. It contains the foundational components for OAuth authentication, JWT token handling, payment processing, and MCP protocol utilities.
8
+
9
+ **🚀 Getting Started**: Learn more about ATXP in [the docs](https://docs.atxp.ai/atxp).
10
+
11
+ ## Features
12
+
13
+ - 🔐 **JWT Token Management**: Secure token creation, validation, and parsing
14
+ - 🗄️ **OAuth Database**: Abstract database interface with memory and SQLite implementations
15
+ - 📡 **MCP JSON Utilities**: Type-safe MCP protocol message handling
16
+ - 💰 **Payment Error Handling**: Structured payment requirement error types
17
+ - 🛠️ **Platform Utilities**: Cross-platform compatibility helpers
18
+ - 📊 **SSE Parser**: Server-sent events parsing for real-time communication
19
+ - 🔧 **Logger**: Configurable logging system
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @atxp/common
25
+ ```
26
+
27
+ This package is typically installed automatically as a dependency of `@atxp/client` or `@atxp/server`.
28
+
29
+ ## Key Components
30
+
31
+ ### JWT Token Management
32
+
33
+ ```typescript
34
+ import { createJWT, verifyJWT, parseJWT } from '@atxp/common';
35
+
36
+ // Create signed JWT
37
+ const token = await createJWT({ userId: '123' }, secretKey);
38
+
39
+ // Verify and parse JWT
40
+ const payload = await verifyJWT(token, secretKey);
41
+
42
+ // Parse without verification (for debugging)
43
+ const { header, payload } = parseJWT(token);
44
+ ```
45
+
46
+ ### OAuth Database Interface
47
+
48
+ ```typescript
49
+ import { OAuthDb, MemoryOAuthDb } from '@atxp/common';
50
+
51
+ // Use in-memory database for development
52
+ const oAuthDb = new MemoryOAuthDb();
53
+
54
+ // Store OAuth tokens
55
+ await oAuthDb.storeTokens('client123', {
56
+ access_token: 'token',
57
+ refresh_token: 'refresh',
58
+ expires_in: 3600
59
+ });
60
+
61
+ // Retrieve tokens
62
+ const tokens = await oAuthDb.getTokens('client123');
63
+ ```
64
+
65
+ ### MCP Protocol Utilities
66
+
67
+ ```typescript
68
+ import {
69
+ MCPRequest,
70
+ MCPResponse,
71
+ MCPError,
72
+ createMCPResponse,
73
+ createMCPError
74
+ } from '@atxp/common';
75
+
76
+ // Type-safe MCP request handling
77
+ function handleMCPRequest(request: MCPRequest): MCPResponse {
78
+ if (request.method === 'tools/call') {
79
+ return createMCPResponse(request.id, { result: 'success' });
80
+ }
81
+ return createMCPError(request.id, -32601, 'Method not found');
82
+ }
83
+ ```
84
+
85
+ ### Payment Error Handling
86
+
87
+ ```typescript
88
+ import { PaymentRequiredError } from '@atxp/common';
89
+
90
+ // Throw structured payment requirement
91
+ throw new PaymentRequiredError({
92
+ amount: '0.01',
93
+ currency: 'USDC',
94
+ destination: 'solana-wallet-address',
95
+ reference: 'unique-payment-reference'
96
+ });
97
+ ```
98
+
99
+ ### Platform Utilities
100
+
101
+ ```typescript
102
+ import { Platform } from '@atxp/common';
103
+
104
+ // Detect runtime environment
105
+ const platform = Platform.detect();
106
+
107
+ if (platform.isNode) {
108
+ // Node.js specific code
109
+ } else if (platform.isExpo) {
110
+ // Expo/React Native specific code
111
+ }
112
+
113
+ // Get appropriate database implementation
114
+ const db = Platform.createOAuthDb();
115
+ ```
116
+
117
+ ## Type Definitions
118
+
119
+ The package exports comprehensive TypeScript types for:
120
+
121
+ - **OAuth Types**: Token responses, authorization flows, client configurations
122
+ - **MCP Types**: Protocol messages, tool definitions, error structures
123
+ - **Payment Types**: Payment requirements, transaction references, currency info
124
+ - **Server Types**: Authentication contexts, middleware definitions
125
+
126
+ ## Database Implementations
127
+
128
+ ### MemoryOAuthDb
129
+
130
+ In-memory OAuth token storage for development and testing:
131
+
132
+ ```typescript
133
+ import { MemoryOAuthDb } from '@atxp/common';
134
+
135
+ const db = new MemoryOAuthDb();
136
+ // Tokens stored in memory, cleared on process restart
137
+ ```
138
+
139
+ ### SQLite Implementation
140
+
141
+ Platform-specific SQLite implementations are automatically selected:
142
+ - Node.js: Uses `better-sqlite3`
143
+ - Expo/React Native: Uses `expo-sqlite`
144
+
145
+ ## Logging
146
+
147
+ Configurable logging system with multiple levels:
148
+
149
+ ```typescript
150
+ import { Logger } from '@atxp/common';
151
+
152
+ const logger = new Logger('MyComponent');
153
+
154
+ logger.debug('Debug message');
155
+ logger.info('Info message');
156
+ logger.warn('Warning message');
157
+ logger.error('Error message');
158
+ ```
159
+
160
+ ## Utilities
161
+
162
+ Various utility functions for:
163
+ - Async operation helpers
164
+ - Data validation and sanitization
165
+ - Error handling and formatting
166
+ - Time and date operations
167
+
168
+ ## Examples
169
+
170
+ This package is used internally by the client and server packages. See:
171
+ - `@atxp/client` for client-side usage examples
172
+ - `@atxp/server` for server-side usage examples
173
+
174
+ ## License
175
+
176
+ MIT
@@ -0,0 +1,83 @@
1
+ import { UrlString } from './types.js';
2
+ import { JSONRPCResponse, Result, CallToolResult, ContentBlock, JSONRPCError } from '@modelcontextprotocol/sdk/types.js';
3
+ export declare const DESTINATION = "testDestination";
4
+ export declare const SOURCE = "testSource";
5
+ export declare function mcpResponse({ id, result }?: {
6
+ id?: number;
7
+ result?: Result;
8
+ }): JSONRPCResponse;
9
+ export declare function mcpToolResult({ content, structuredContent, isError }?: {
10
+ content?: ContentBlock[];
11
+ structuredContent?: any;
12
+ isError?: boolean;
13
+ }): CallToolResult;
14
+ export declare function mcpToolErrorResponse({ content, structuredContent, }?: {
15
+ content?: ContentBlock[];
16
+ structuredContent?: any;
17
+ }): JSONRPCResponse;
18
+ export declare function paymentRequiredMessage(paymentUrl: UrlString, id: string): string;
19
+ /**
20
+ * Creates a 401 Unauthorized response with OAuth challenge
21
+ */
22
+ export declare function authRequiredResponse(resourceMetadataUrl?: string): {
23
+ status: number;
24
+ headers: {
25
+ 'www-authenticate': string;
26
+ };
27
+ };
28
+ /**
29
+ * Creates an MCP initialize response with the full JSON-RPC wrapper
30
+ */
31
+ export declare function mcpInitializeResponse(id?: number, protocolVersion?: string): {
32
+ jsonrpc: "2.0";
33
+ id: string | number;
34
+ result: {
35
+ [x: string]: unknown;
36
+ _meta?: {
37
+ [x: string]: unknown;
38
+ } | undefined;
39
+ };
40
+ };
41
+ /**
42
+ * Creates an MCP tool call response with custom content
43
+ */
44
+ export declare function mcpToolResponse(id?: number, text?: string): {
45
+ jsonrpc: "2.0";
46
+ id: string | number;
47
+ result: {
48
+ [x: string]: unknown;
49
+ _meta?: {
50
+ [x: string]: unknown;
51
+ } | undefined;
52
+ };
53
+ };
54
+ export declare function mcpResponseHandler(toolResponse?: JSONRPCResponse): (url: any, opts: any) => {
55
+ status: number;
56
+ body: {
57
+ jsonrpc: "2.0";
58
+ id: string | number;
59
+ result: {
60
+ [x: string]: unknown;
61
+ _meta?: {
62
+ [x: string]: unknown;
63
+ } | undefined;
64
+ };
65
+ };
66
+ } | {
67
+ status: number;
68
+ body: {};
69
+ };
70
+ export declare function mcpErrorResponse({ id, code, message, data }: {
71
+ id?: number;
72
+ code?: number;
73
+ message?: string;
74
+ data?: any;
75
+ }): JSONRPCError;
76
+ export declare function mcpElicitationRequiredErrorResponse({ id, message, elicitationId, url, data }: {
77
+ id?: number;
78
+ message?: string;
79
+ elicitationId?: string;
80
+ url?: string;
81
+ data?: any;
82
+ }): JSONRPCError;
83
+ //# sourceMappingURL=commonTestHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonTestHelpers.d.ts","sourceRoot":"","sources":["../src/commonTestHelpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAGzH,eAAO,MAAM,WAAW,oBAAoB,CAAC;AAC7C,eAAO,MAAM,MAAM,eAAe,CAAC;AAGnC,wBAAgB,WAAW,CAAC,EAAC,EAAM,EAAE,MAAwB,EAAC,GAAE;IAC9D,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;CACX,GAAG,eAAe,CAEvB;AAED,wBAAgB,aAAa,CAAC,EAC1B,OAA+C,EAC/C,iBAA6B,EAC7B,OAAe,EAChB,GAAE;IACD,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;CACd,GAAG,cAAc,CAExB;AAED,wBAAgB,oBAAoB,CAAC,EACnC,OAA8C,EAC9C,iBAA6B,GAC9B,GAAE;IACD,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,iBAAiB,CAAC,EAAE,GAAG,CAAC;CACpB,GAAG,eAAe,CAGvB;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAGhF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,mBAAmB,GAAE,MAAuE;;;;;EAOhI;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,GAAE,MAAU,EAAE,eAAe,GAAE,MAAqB;;;;;;;;;EAY3F;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAAE,GAAE,MAAU,EAAE,IAAI,GAAE,MAAsB;;;;;;;;;EAO3E;AAED,wBAAgB,kBAAkB,CAAC,YAAY,GAAE,eAAmD,IAClF,KAAK,GAAG,EAAE,MAAM,GAAG;;;;;;;;;;;;;;;EAyCpC;AAED,wBAAgB,gBAAgB,CAAC,EAAC,EAAM,EAAE,IAAa,EAAE,OAAsB,EAAE,IAAgB,EAAC,EAAG;IACnG,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,CAAA;CACX,GAAG,YAAY,CAMf;AAED,wBAAgB,mCAAmC,CAAC,EAAC,EAAM,EAAE,OAAsB,EAAE,aAAqB,EAAE,GAAgD,EAAE,IAAS,EAAC,EAAG;IACzK,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,GAAG,CAAA;CACX,GAAG,YAAY,CAKf"}
@@ -0,0 +1,115 @@
1
+ import { paymentRequiredError } from './paymentRequiredError.js';
2
+ export const DESTINATION = 'testDestination';
3
+ export const SOURCE = 'testSource';
4
+ export function mcpResponse({ id = 1, result = mcpToolResult() } = {}) {
5
+ return { jsonrpc: "2.0", id, result };
6
+ }
7
+ export function mcpToolResult({ content = [{ type: 'text', text: 'tool-result' }], structuredContent = undefined, isError = false } = {}) {
8
+ return { content, structuredContent, isError };
9
+ }
10
+ export function mcpToolErrorResponse({ content = [{ type: 'text', text: 'tool-error' }], structuredContent = undefined, } = {}) {
11
+ const result = mcpToolResult({ isError: true, content, structuredContent });
12
+ return mcpResponse({ result });
13
+ }
14
+ export function paymentRequiredMessage(paymentUrl, id) {
15
+ const err = paymentRequiredError(paymentUrl, id);
16
+ return err.message;
17
+ }
18
+ /**
19
+ * Creates a 401 Unauthorized response with OAuth challenge
20
+ */
21
+ export function authRequiredResponse(resourceMetadataUrl = 'https://example.com/.well-known/oauth-protected-resource/mcp') {
22
+ return {
23
+ status: 401,
24
+ headers: {
25
+ 'www-authenticate': `Bearer resource_metadata="${resourceMetadataUrl}"`
26
+ }
27
+ };
28
+ }
29
+ /**
30
+ * Creates an MCP initialize response with the full JSON-RPC wrapper
31
+ */
32
+ export function mcpInitializeResponse(id = 0, protocolVersion = '2025-06-18') {
33
+ return mcpResponse({
34
+ id,
35
+ result: {
36
+ protocolVersion,
37
+ capabilities: {},
38
+ serverInfo: {
39
+ name: 'test-server',
40
+ version: '1.0.0'
41
+ }
42
+ }
43
+ });
44
+ }
45
+ /**
46
+ * Creates an MCP tool call response with custom content
47
+ */
48
+ export function mcpToolResponse(id = 1, text = 'tool-result') {
49
+ return mcpResponse({
50
+ id,
51
+ result: mcpToolResult({
52
+ content: [{ type: 'text', text }]
53
+ })
54
+ });
55
+ }
56
+ export function mcpResponseHandler(toolResponse = mcpToolResponse(1, 'hello world')) {
57
+ return function (url, opts) {
58
+ // fetch-mock might pass the URL and options differently
59
+ let body;
60
+ if (typeof url === 'string' && opts && opts.body) {
61
+ body = opts.body;
62
+ }
63
+ else if (url && url.options && url.options.body) {
64
+ body = url.options.body;
65
+ }
66
+ else {
67
+ // Return a default response
68
+ return {
69
+ status: 200,
70
+ body: mcpResponse()
71
+ };
72
+ }
73
+ // Parse the request to get the ID and method
74
+ const request = JSON.parse(body);
75
+ // Return a response based on the request method
76
+ if (request.method === 'initialize') {
77
+ return {
78
+ status: 200,
79
+ body: mcpInitializeResponse(request.id)
80
+ };
81
+ }
82
+ else if (request.method === 'tools/call') {
83
+ toolResponse.id = request.id;
84
+ return {
85
+ status: 200,
86
+ body: toolResponse
87
+ };
88
+ }
89
+ else if (request.method === 'notifications/initialized') {
90
+ // No response needed for notifications
91
+ return { status: 200, body: {} };
92
+ }
93
+ else {
94
+ // Default response
95
+ return {
96
+ status: 200,
97
+ body: mcpResponse({ id: request.id, result: {} })
98
+ };
99
+ }
100
+ };
101
+ }
102
+ export function mcpErrorResponse({ id = 1, code = -32000, message = 'test error', data = undefined }) {
103
+ return {
104
+ jsonrpc: '2.0',
105
+ id,
106
+ error: { code, message, data }
107
+ };
108
+ }
109
+ export function mcpElicitationRequiredErrorResponse({ id = 1, message = 'test error', elicitationId = '123', url = 'https://auth.atxp.ai/payment-request/123', data = {} }) {
110
+ // Code as per https://github.com/modelcontextprotocol/modelcontextprotocol/pull/887
111
+ const code = -32604;
112
+ const elicitationData = { elicitations: [{ mode: 'url', elicitationId, url }] };
113
+ return mcpErrorResponse({ id, code, message, data: { ...data, ...elicitationData } });
114
+ }
115
+ //# sourceMappingURL=commonTestHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonTestHelpers.js","sourceRoot":"","sources":["../src/commonTestHelpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAC7C,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAC;AAGnC,MAAM,UAAU,WAAW,CAAC,EAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,aAAa,EAAE,KAGzD,EAAE;IACJ,OAAO,EAAE,OAAO,EAAE,KAAc,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,EAC1B,OAAO,GAAG,CAAC,EAAC,IAA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,CAAC;YAC1D,uCAAuC;YACvC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,mBAAmB;YACnB,OAAO;gBACL,MAAM,EAAE,GAAG;gBACX,IAAI,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;aAClD,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAC,EAAE,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,EAAE,IAAI,GAAG,SAAS,EAKhG;IACC,OAAO;QACL,OAAO,EAAE,KAAc;QACvB,EAAE;QACF,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;KAC/B,CAAA;AACH,CAAC;AAED,MAAM,UAAU,mCAAmC,CAAC,EAAC,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,YAAY,EAAE,aAAa,GAAG,KAAK,EAAE,GAAG,GAAG,0CAA0C,EAAE,IAAI,GAAG,EAAE,EAMtK;IACC,oFAAoF;IACpF,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC;IACpB,MAAM,eAAe,GAAG,EAAC,YAAY,EAAE,CAAC,EAAC,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAC,CAAC,EAAC,CAAA;IAC3E,OAAO,gBAAgB,CAAC,EAAC,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAC,GAAG,IAAI,EAAE,GAAG,eAAe,EAAC,EAAC,CAAC,CAAC;AACpF,CAAC"}
@@ -0,0 +1,15 @@
1
+ export * from './jwt.js';
2
+ export * from './logger.js';
3
+ export * from './oAuthDb.js';
4
+ export * from './memoryOAuthDb.js';
5
+ export * from './oAuthDbFactory.js';
6
+ export * from './redisOAuthDb.js';
7
+ export * from './oAuthResource.js';
8
+ export * from './paymentRequiredError.js';
9
+ export * from './servers.js';
10
+ export * from './types.js';
11
+ export * from './utils.js';
12
+ export * from './mcpJson.js';
13
+ export * from './sseParser.js';
14
+ export * from './platform/index.js';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA2B,CAAA;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ export * from './jwt.js';
2
+ export * from './logger.js';
3
+ export * from './oAuthDb.js';
4
+ export * from './memoryOAuthDb.js';
5
+ export * from './oAuthDbFactory.js';
6
+ export * from './redisOAuthDb.js';
7
+ export * from './oAuthResource.js';
8
+ export * from './paymentRequiredError.js';
9
+ export * from './servers.js';
10
+ export * from './types.js';
11
+ export * from './utils.js';
12
+ export * from './mcpJson.js';
13
+ export * from './sseParser.js';
14
+ export * from './platform/index.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA2B,CAAA;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
package/dist/jwt.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generate a JWT using the jose library and EdDSA (Ed25519) private key.
3
+ * @param walletId - The subject (public key, wallet address, etc.)
4
+ * @param privateKey - Ed25519 private key as a CryptoKey or Uint8Array
5
+ * @param paymentIds - Optional array of payment IDs to include in the payload
6
+ * @returns JWT string
7
+ */
8
+ export declare const generateJWT: (walletId: string, privateKey: CryptoKey | Uint8Array, paymentRequestId: string, codeChallenge: string) => Promise<string>;
9
+ //# sourceMappingURL=jwt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GACtB,UAAU,MAAM,EAChB,YAAY,SAAS,GAAG,UAAU,EAClC,kBAAkB,MAAM,EACxB,eAAe,MAAM,KACpB,OAAO,CAAC,MAAM,CAehB,CAAC"}
package/dist/jwt.js ADDED
@@ -0,0 +1,29 @@
1
+ import { SignJWT } from 'jose';
2
+ // TODO: revisit this
3
+ const ISSUER = 'atxp.ai';
4
+ const AUDIENCE = 'https://api.atxp.ai';
5
+ /**
6
+ * Generate a JWT using the jose library and EdDSA (Ed25519) private key.
7
+ * @param walletId - The subject (public key, wallet address, etc.)
8
+ * @param privateKey - Ed25519 private key as a CryptoKey or Uint8Array
9
+ * @param paymentIds - Optional array of payment IDs to include in the payload
10
+ * @returns JWT string
11
+ */
12
+ export const generateJWT = async (walletId, privateKey, paymentRequestId, codeChallenge) => {
13
+ const payload = {
14
+ code_challenge: codeChallenge,
15
+ };
16
+ if (paymentRequestId)
17
+ payload.payment_request_id = paymentRequestId;
18
+ if (codeChallenge)
19
+ payload.code_challenge = codeChallenge;
20
+ return await new SignJWT(payload)
21
+ .setProtectedHeader({ alg: 'EdDSA', typ: 'JWT' })
22
+ .setIssuedAt()
23
+ .setIssuer(ISSUER)
24
+ .setAudience(AUDIENCE)
25
+ .setSubject(walletId)
26
+ .setExpirationTime('2m')
27
+ .sign(privateKey);
28
+ };
29
+ //# sourceMappingURL=jwt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.js","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,qBAAqB;AACrB,MAAM,MAAM,GAAG,SAAS,CAAC;AACzB,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AAEvC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,QAAgB,EAChB,UAAkC,EAClC,gBAAwB,EACxB,aAAqB,EACJ,EAAE;IACnB,MAAM,OAAO,GAAqB;QAChC,cAAc,EAAE,aAAa;KAC9B,CAAC;IACF,IAAI,gBAAgB;QAAE,OAAO,CAAC,kBAAkB,GAAG,gBAAgB,CAAC;IACpE,IAAI,aAAa;QAAE,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC;IAE1D,OAAO,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;SAC9B,kBAAkB,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;SAChD,WAAW,EAAE;SACb,SAAS,CAAC,MAAM,CAAC;SACjB,WAAW,CAAC,QAAQ,CAAC;SACrB,UAAU,CAAC,QAAQ,CAAC;SACpB,iBAAiB,CAAC,IAAI,CAAC;SACvB,IAAI,CAAC,UAAU,CAAC,CAAC;AACtB,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { Logger, LogLevel } from './types.js';
2
+ export declare class ConsoleLogger implements Logger {
3
+ private readonly prefix;
4
+ private _level;
5
+ constructor({ prefix, level }?: Partial<{
6
+ prefix: string;
7
+ level: LogLevel;
8
+ }>);
9
+ get level(): LogLevel;
10
+ set level(level: LogLevel);
11
+ private log;
12
+ private getConsoleMethod;
13
+ debug: (message: string) => void;
14
+ info: (message: string) => void;
15
+ warn: (message: string) => void;
16
+ error: (message: string) => void;
17
+ }
18
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE9C,qBAAa,aAAc,YAAW,MAAM;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,MAAM,CAAW;gBAEb,EAAC,MAAiB,EAAE,KAAqB,EAAC,GAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,QAAQ,CAAA;KAAC,CAAM;IAKvG,IAAI,KAAK,IAAI,QAAQ,CAEpB;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,QAAQ,EAExB;IAED,OAAO,CAAC,GAAG;IAOX,OAAO,CAAC,gBAAgB;IAUxB,KAAK,GAAI,SAAS,MAAM,UAEvB;IACD,IAAI,GAAI,SAAS,MAAM,UAEtB;IACD,IAAI,GAAI,SAAS,MAAM,UAEtB;IACD,KAAK,GAAI,SAAS,MAAM,UAEvB;CACF"}
package/dist/logger.js ADDED
@@ -0,0 +1,43 @@
1
+ /* eslint-disable no-console */
2
+ import { assertNever } from './utils.js';
3
+ import { LogLevel } from './types.js';
4
+ export class ConsoleLogger {
5
+ constructor({ prefix = '[atxp]', level = LogLevel.INFO } = {}) {
6
+ this.debug = (message) => {
7
+ this.log(LogLevel.DEBUG, message);
8
+ };
9
+ this.info = (message) => {
10
+ this.log(LogLevel.INFO, message);
11
+ };
12
+ this.warn = (message) => {
13
+ this.log(LogLevel.WARN, message);
14
+ };
15
+ this.error = (message) => {
16
+ this.log(LogLevel.ERROR, message);
17
+ };
18
+ this.prefix = prefix;
19
+ this._level = level;
20
+ }
21
+ get level() {
22
+ return this._level;
23
+ }
24
+ set level(level) {
25
+ this._level = level;
26
+ }
27
+ log(level, message) {
28
+ if (level >= this._level) {
29
+ const consoleMethod = this.getConsoleMethod(level);
30
+ consoleMethod(`${this.prefix} ${message}`);
31
+ }
32
+ }
33
+ getConsoleMethod(level) {
34
+ switch (level) {
35
+ case LogLevel.DEBUG: return console.debug.bind(console);
36
+ case LogLevel.INFO: return console.info.bind(console);
37
+ case LogLevel.WARN: return console.warn.bind(console);
38
+ case LogLevel.ERROR: return console.error.bind(console);
39
+ default: return assertNever(level, `Unknown log level: ${level}`);
40
+ }
41
+ }
42
+ }
43
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAU,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,OAAO,aAAa;IAIxB,YAAY,EAAC,MAAM,GAAG,QAAQ,EAAE,KAAK,GAAG,QAAQ,CAAC,IAAI,KAAgD,EAAE;QA8BvG,UAAK,GAAG,CAAC,OAAe,EAAE,EAAE;YAC1B,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACpC,CAAC,CAAA;QACD,SAAI,GAAG,CAAC,OAAe,EAAE,EAAE;YACzB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC,CAAA;QACD,SAAI,GAAG,CAAC,OAAe,EAAE,EAAE;YACzB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC,CAAA;QACD,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 @@
1
+ import { AuthorizationServerUrl } from './types.js';
2
+ import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
3
+ import { Logger } from './types.js';
4
+ export declare function parsePaymentRequests(message: JSONRPCMessage): {
5
+ url: AuthorizationServerUrl;
6
+ id: string;
7
+ }[];
8
+ export declare function parseMcpMessages(json: unknown, logger?: Logger): Promise<JSONRPCMessage[]>;
9
+ //# sourceMappingURL=mcpJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcpJson.d.ts","sourceRoot":"","sources":["../src/mcpJson.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAmE,cAAc,EAAwB,MAAM,oCAAoC,CAAC;AAC3J,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAIpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,GAAG;IAAC,GAAG,EAAE,sBAAsB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAC,EAAE,CAsDzG;AAeD,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAiDhG"}