mppx 0.2.0 → 0.2.1
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/Challenge.d.ts +3 -3
- package/dist/Challenge.js +3 -3
- package/dist/PaymentRequest.d.ts +2 -2
- package/dist/PaymentRequest.d.ts.map +1 -1
- package/dist/PaymentRequest.js +8 -3
- package/dist/PaymentRequest.js.map +1 -1
- package/dist/server/Mppx.js +1 -1
- package/package.json +2 -1
- package/src/Challenge.test.ts +6 -6
- package/src/Challenge.ts +7 -7
- package/src/PaymentRequest.test.ts +4 -4
- package/src/PaymentRequest.ts +8 -3
- package/src/client/Mppx.test.ts +4 -4
- package/src/client/Transport.test.ts +5 -5
- package/src/mcp-sdk/client/McpClient.test.ts +1 -1
- package/src/server/Mppx.ts +1 -1
- package/src/server/Transport.test.ts +6 -6
package/dist/Challenge.d.ts
CHANGED
|
@@ -139,7 +139,7 @@ export declare namespace from {
|
|
|
139
139
|
* import { Methods } from 'mppx/tempo'
|
|
140
140
|
*
|
|
141
141
|
* // With HMAC-bound ID (recommended for servers)
|
|
142
|
-
* const challenge = Challenge.
|
|
142
|
+
* const challenge = Challenge.fromMethod(
|
|
143
143
|
* Methods.charge,
|
|
144
144
|
* {
|
|
145
145
|
* realm: 'api.example.com',
|
|
@@ -154,8 +154,8 @@ export declare namespace from {
|
|
|
154
154
|
* )
|
|
155
155
|
* ```
|
|
156
156
|
*/
|
|
157
|
-
export declare function
|
|
158
|
-
export declare namespace
|
|
157
|
+
export declare function fromMethod<const method extends Method.Method>(method: method, parameters: fromMethod.Parameters<method>): fromMethod.ReturnType<method>;
|
|
158
|
+
export declare namespace fromMethod {
|
|
159
159
|
type Parameters<method extends Method.Method> = OneOf<{
|
|
160
160
|
/** Explicit challenge ID. */
|
|
161
161
|
id: string;
|
package/dist/Challenge.js
CHANGED
|
@@ -100,7 +100,7 @@ export function from(parameters, options) {
|
|
|
100
100
|
* import { Methods } from 'mppx/tempo'
|
|
101
101
|
*
|
|
102
102
|
* // With HMAC-bound ID (recommended for servers)
|
|
103
|
-
* const challenge = Challenge.
|
|
103
|
+
* const challenge = Challenge.fromMethod(
|
|
104
104
|
* Methods.charge,
|
|
105
105
|
* {
|
|
106
106
|
* realm: 'api.example.com',
|
|
@@ -115,10 +115,10 @@ export function from(parameters, options) {
|
|
|
115
115
|
* )
|
|
116
116
|
* ```
|
|
117
117
|
*/
|
|
118
|
-
export function
|
|
118
|
+
export function fromMethod(method, parameters) {
|
|
119
119
|
const { name: methodName, intent } = method;
|
|
120
120
|
const { description, digest, expires, id, realm, secretKey } = parameters;
|
|
121
|
-
const request = PaymentRequest.
|
|
121
|
+
const request = PaymentRequest.fromMethod(method, parameters.request);
|
|
122
122
|
return from({
|
|
123
123
|
...(id ? { id } : { secretKey }),
|
|
124
124
|
realm,
|
package/dist/PaymentRequest.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export declare function from<const request extends Request>(request: request): r
|
|
|
60
60
|
* import { Request } from 'mppx'
|
|
61
61
|
* import { Methods } from 'mppx/tempo'
|
|
62
62
|
*
|
|
63
|
-
* const request = Request.
|
|
63
|
+
* const request = Request.fromMethod(Methods.charge, {
|
|
64
64
|
* amount: '1000000',
|
|
65
65
|
* currency: '0x20c0000000000000000000000000000000000001',
|
|
66
66
|
* recipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f8fE00',
|
|
@@ -69,7 +69,7 @@ export declare function from<const request extends Request>(request: request): r
|
|
|
69
69
|
* })
|
|
70
70
|
* ```
|
|
71
71
|
*/
|
|
72
|
-
export declare function
|
|
72
|
+
export declare function fromMethod<const method extends Method.Method>(method: method, request: z.input<method['schema']['request']>): Request<z.output<method['schema']['request']>>;
|
|
73
73
|
/**
|
|
74
74
|
* Serializes a request to a base64url string.
|
|
75
75
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentRequest.d.ts","sourceRoot":"","sources":["../src/PaymentRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PaymentRequest.d.ts","sourceRoot":"","sources":["../src/PaymentRequest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,KAAK,MAAM,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,KAAK,CAAC,MAAM,UAAU,CAAA;AAKlC;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,OAAO,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACnF,OAAO,CAAC,OAAO,CAAC,CAAA;AAElB;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGpD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAAC,KAAK,CAAC,OAAO,SAAS,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAE7E;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAC3D,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,GAC5C,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAEhD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAIlD"}
|
package/dist/PaymentRequest.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
1
2
|
import { Base64 } from 'ox';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const canonicalize = require('canonicalize');
|
|
2
5
|
/**
|
|
3
6
|
* Deserializes a base64url string to a request.
|
|
4
7
|
*
|
|
@@ -48,7 +51,7 @@ export function from(request) {
|
|
|
48
51
|
* import { Request } from 'mppx'
|
|
49
52
|
* import { Methods } from 'mppx/tempo'
|
|
50
53
|
*
|
|
51
|
-
* const request = Request.
|
|
54
|
+
* const request = Request.fromMethod(Methods.charge, {
|
|
52
55
|
* amount: '1000000',
|
|
53
56
|
* currency: '0x20c0000000000000000000000000000000000001',
|
|
54
57
|
* recipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f8fE00',
|
|
@@ -57,7 +60,7 @@ export function from(request) {
|
|
|
57
60
|
* })
|
|
58
61
|
* ```
|
|
59
62
|
*/
|
|
60
|
-
export function
|
|
63
|
+
export function fromMethod(method, request) {
|
|
61
64
|
return method.schema.request.parse(request);
|
|
62
65
|
}
|
|
63
66
|
/**
|
|
@@ -75,7 +78,9 @@ export function fromIntent(method, request) {
|
|
|
75
78
|
* ```
|
|
76
79
|
*/
|
|
77
80
|
export function serialize(request) {
|
|
78
|
-
const json =
|
|
81
|
+
const json = canonicalize(request);
|
|
82
|
+
if (!json)
|
|
83
|
+
throw new Error('Failed to canonicalize request');
|
|
79
84
|
return Base64.fromString(json, { pad: false, url: true });
|
|
80
85
|
}
|
|
81
86
|
//# sourceMappingURL=PaymentRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentRequest.js","sourceRoot":"","sources":["../src/PaymentRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"PaymentRequest.js","sourceRoot":"","sources":["../src/PaymentRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;AAK3B,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9C,MAAM,YAAY,GAAG,OAAO,CAAC,cAAc,CAA2C,CAAA;AAmBtF;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,IAAI,CAAgC,OAAgB;IAClE,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,UAAU,CACxB,MAAc,EACd,OAA6C;IAE7C,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAmD,CAAA;AAC/F,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,OAAgB;IACxC,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;IAClC,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;IAC5D,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;AAC3D,CAAC"}
|
package/dist/server/Mppx.js
CHANGED
|
@@ -70,7 +70,7 @@ function createMethodFn(parameters) {
|
|
|
70
70
|
// Recompute challenge from options. The HMAC-bound ID means we don't need to
|
|
71
71
|
// store challenges server-side—if the client echoes back a credential with
|
|
72
72
|
// a matching ID, we know it was issued by us with these exact parameters.
|
|
73
|
-
const challenge = Challenge.
|
|
73
|
+
const challenge = Challenge.fromMethod(method, {
|
|
74
74
|
description,
|
|
75
75
|
expires,
|
|
76
76
|
realm,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mppx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
@@ -105,6 +105,7 @@
|
|
|
105
105
|
"@remix-run/fetch-proxy": "^0.7.1",
|
|
106
106
|
"@remix-run/node-fetch-server": "^0.13.0",
|
|
107
107
|
"cac": "^6.7.14",
|
|
108
|
+
"canonicalize": "^2.1.0",
|
|
108
109
|
"ox": "^0.12.0",
|
|
109
110
|
"zod": "^4.3.6"
|
|
110
111
|
},
|
package/src/Challenge.test.ts
CHANGED
|
@@ -106,9 +106,9 @@ describe('from', () => {
|
|
|
106
106
|
})
|
|
107
107
|
})
|
|
108
108
|
|
|
109
|
-
describe('
|
|
109
|
+
describe('fromMethod', () => {
|
|
110
110
|
test('behavior: creates validated challenge from intent', () => {
|
|
111
|
-
const challenge = Challenge.
|
|
111
|
+
const challenge = Challenge.fromMethod(Methods.charge, {
|
|
112
112
|
id: 'abc123',
|
|
113
113
|
realm: 'api.example.com',
|
|
114
114
|
request: {
|
|
@@ -138,7 +138,7 @@ describe('fromIntent', () => {
|
|
|
138
138
|
})
|
|
139
139
|
|
|
140
140
|
test('behavior: includes methodDetails in request', () => {
|
|
141
|
-
const challenge = Challenge.
|
|
141
|
+
const challenge = Challenge.fromMethod(Methods.charge, {
|
|
142
142
|
id: 'abc123',
|
|
143
143
|
realm: 'api.example.com',
|
|
144
144
|
request: {
|
|
@@ -174,7 +174,7 @@ describe('fromIntent', () => {
|
|
|
174
174
|
})
|
|
175
175
|
|
|
176
176
|
test('behavior: includes optional digest and expires', () => {
|
|
177
|
-
const challenge = Challenge.
|
|
177
|
+
const challenge = Challenge.fromMethod(Methods.charge, {
|
|
178
178
|
id: 'abc123',
|
|
179
179
|
realm: 'api.example.com',
|
|
180
180
|
request: {
|
|
@@ -193,7 +193,7 @@ describe('fromIntent', () => {
|
|
|
193
193
|
})
|
|
194
194
|
|
|
195
195
|
test('behavior: creates challenge with HMAC-bound id via secretKey', () => {
|
|
196
|
-
const challenge = Challenge.
|
|
196
|
+
const challenge = Challenge.fromMethod(Methods.charge, {
|
|
197
197
|
realm: 'api.example.com',
|
|
198
198
|
request: {
|
|
199
199
|
amount: '1',
|
|
@@ -212,7 +212,7 @@ describe('fromIntent', () => {
|
|
|
212
212
|
|
|
213
213
|
test('error: invalid request', () => {
|
|
214
214
|
expect(() =>
|
|
215
|
-
Challenge.
|
|
215
|
+
Challenge.fromMethod(Methods.charge, {
|
|
216
216
|
id: 'abc123',
|
|
217
217
|
realm: 'api.example.com',
|
|
218
218
|
request: {
|
package/src/Challenge.ts
CHANGED
|
@@ -186,7 +186,7 @@ export declare namespace from {
|
|
|
186
186
|
* import { Methods } from 'mppx/tempo'
|
|
187
187
|
*
|
|
188
188
|
* // With HMAC-bound ID (recommended for servers)
|
|
189
|
-
* const challenge = Challenge.
|
|
189
|
+
* const challenge = Challenge.fromMethod(
|
|
190
190
|
* Methods.charge,
|
|
191
191
|
* {
|
|
192
192
|
* realm: 'api.example.com',
|
|
@@ -201,14 +201,14 @@ export declare namespace from {
|
|
|
201
201
|
* )
|
|
202
202
|
* ```
|
|
203
203
|
*/
|
|
204
|
-
export function
|
|
204
|
+
export function fromMethod<const method extends Method.Method>(
|
|
205
205
|
method: method,
|
|
206
|
-
parameters:
|
|
207
|
-
):
|
|
206
|
+
parameters: fromMethod.Parameters<method>,
|
|
207
|
+
): fromMethod.ReturnType<method> {
|
|
208
208
|
const { name: methodName, intent } = method
|
|
209
209
|
const { description, digest, expires, id, realm, secretKey } = parameters
|
|
210
210
|
|
|
211
|
-
const request = PaymentRequest.
|
|
211
|
+
const request = PaymentRequest.fromMethod(method, parameters.request)
|
|
212
212
|
|
|
213
213
|
return from({
|
|
214
214
|
...(id ? { id } : { secretKey }),
|
|
@@ -219,10 +219,10 @@ export function fromIntent<const method extends Method.Method>(
|
|
|
219
219
|
description,
|
|
220
220
|
digest,
|
|
221
221
|
expires,
|
|
222
|
-
} as from.Parameters) as
|
|
222
|
+
} as from.Parameters) as fromMethod.ReturnType<method>
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
export declare namespace
|
|
225
|
+
export declare namespace fromMethod {
|
|
226
226
|
type Parameters<method extends Method.Method> = OneOf<
|
|
227
227
|
| {
|
|
228
228
|
/** Explicit challenge ID. */
|
|
@@ -19,9 +19,9 @@ describe('from', () => {
|
|
|
19
19
|
})
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
describe('
|
|
22
|
+
describe('fromMethod', () => {
|
|
23
23
|
test('creates a validated request from intent', () => {
|
|
24
|
-
const request = PaymentRequest.
|
|
24
|
+
const request = PaymentRequest.fromMethod(Methods.charge, {
|
|
25
25
|
amount: '1',
|
|
26
26
|
currency: '0x20c0000000000000000000000000000000000001',
|
|
27
27
|
decimals: 6,
|
|
@@ -39,7 +39,7 @@ describe('fromIntent', () => {
|
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
test('includes methodDetails fields', () => {
|
|
42
|
-
const request = PaymentRequest.
|
|
42
|
+
const request = PaymentRequest.fromMethod(Methods.charge, {
|
|
43
43
|
amount: '1',
|
|
44
44
|
currency: '0x20c0000000000000000000000000000000000001',
|
|
45
45
|
decimals: 6,
|
|
@@ -62,7 +62,7 @@ describe('fromIntent', () => {
|
|
|
62
62
|
|
|
63
63
|
test('throws on invalid request', () => {
|
|
64
64
|
expect(() =>
|
|
65
|
-
PaymentRequest.
|
|
65
|
+
PaymentRequest.fromMethod(Methods.charge, {
|
|
66
66
|
amount: 123,
|
|
67
67
|
currency: '0x20c0000000000000000000000000000000000001',
|
|
68
68
|
recipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f8fE00',
|
package/src/PaymentRequest.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
1
2
|
import { Base64 } from 'ox'
|
|
2
3
|
import type { Compute } from './internal/types.js'
|
|
3
4
|
import type * as Method from './Method.js'
|
|
4
5
|
import type * as z from './zod.js'
|
|
5
6
|
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
const canonicalize = require('canonicalize') as (input: unknown) => string | undefined
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* Intent-specific payment parameters.
|
|
8
12
|
*
|
|
@@ -71,7 +75,7 @@ export function from<const request extends Request>(request: request): request {
|
|
|
71
75
|
* import { Request } from 'mppx'
|
|
72
76
|
* import { Methods } from 'mppx/tempo'
|
|
73
77
|
*
|
|
74
|
-
* const request = Request.
|
|
78
|
+
* const request = Request.fromMethod(Methods.charge, {
|
|
75
79
|
* amount: '1000000',
|
|
76
80
|
* currency: '0x20c0000000000000000000000000000000000001',
|
|
77
81
|
* recipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f8fE00',
|
|
@@ -80,7 +84,7 @@ export function from<const request extends Request>(request: request): request {
|
|
|
80
84
|
* })
|
|
81
85
|
* ```
|
|
82
86
|
*/
|
|
83
|
-
export function
|
|
87
|
+
export function fromMethod<const method extends Method.Method>(
|
|
84
88
|
method: method,
|
|
85
89
|
request: z.input<method['schema']['request']>,
|
|
86
90
|
): Request<z.output<method['schema']['request']>> {
|
|
@@ -102,6 +106,7 @@ export function fromIntent<const method extends Method.Method>(
|
|
|
102
106
|
* ```
|
|
103
107
|
*/
|
|
104
108
|
export function serialize(request: Request): string {
|
|
105
|
-
const json =
|
|
109
|
+
const json = canonicalize(request)
|
|
110
|
+
if (!json) throw new Error('Failed to canonicalize request')
|
|
106
111
|
return Base64.fromString(json, { pad: false, url: true })
|
|
107
112
|
}
|
package/src/client/Mppx.test.ts
CHANGED
|
@@ -79,7 +79,7 @@ describe('createCredential', () => {
|
|
|
79
79
|
methods: [tempo({ account: accounts[1], getClient: () => client })],
|
|
80
80
|
})
|
|
81
81
|
|
|
82
|
-
const challenge = Challenge.
|
|
82
|
+
const challenge = Challenge.fromMethod(Methods.charge, {
|
|
83
83
|
realm,
|
|
84
84
|
secretKey,
|
|
85
85
|
request: {
|
|
@@ -192,7 +192,7 @@ describe('createCredential', () => {
|
|
|
192
192
|
methods: [tempo({ getClient: () => client })],
|
|
193
193
|
})
|
|
194
194
|
|
|
195
|
-
const challenge = Challenge.
|
|
195
|
+
const challenge = Challenge.fromMethod(Methods.charge, {
|
|
196
196
|
realm,
|
|
197
197
|
secretKey,
|
|
198
198
|
request: {
|
|
@@ -224,7 +224,7 @@ describe('createCredential', () => {
|
|
|
224
224
|
methods: [tempo({ account: accounts[1], getClient: () => client })],
|
|
225
225
|
})
|
|
226
226
|
|
|
227
|
-
const challenge = Challenge.
|
|
227
|
+
const challenge = Challenge.fromMethod(Methods.charge, {
|
|
228
228
|
realm,
|
|
229
229
|
secretKey,
|
|
230
230
|
request: {
|
|
@@ -255,7 +255,7 @@ describe('createCredential', () => {
|
|
|
255
255
|
transport: Transport.mcp(),
|
|
256
256
|
})
|
|
257
257
|
|
|
258
|
-
const challenge = Challenge.
|
|
258
|
+
const challenge = Challenge.fromMethod(Methods.charge, {
|
|
259
259
|
realm,
|
|
260
260
|
secretKey,
|
|
261
261
|
request: {
|
|
@@ -6,7 +6,7 @@ import { describe, expect, test } from 'vitest'
|
|
|
6
6
|
const realm = 'api.example.com'
|
|
7
7
|
const secretKey = 'test-secret-key'
|
|
8
8
|
|
|
9
|
-
const challenge = Challenge.
|
|
9
|
+
const challenge = Challenge.fromMethod(Methods.charge, {
|
|
10
10
|
realm,
|
|
11
11
|
secretKey,
|
|
12
12
|
request: {
|
|
@@ -60,7 +60,7 @@ describe('http', () => {
|
|
|
60
60
|
expect(transport.getChallenge(response)).toMatchInlineSnapshot(`
|
|
61
61
|
{
|
|
62
62
|
"expires": "2025-01-01T00:00:00.000Z",
|
|
63
|
-
"id": "
|
|
63
|
+
"id": "wv3vZAjsySM50i4f1sJCZxyOLNry0dLSOwuWDBqrXaw",
|
|
64
64
|
"intent": "charge",
|
|
65
65
|
"method": "tempo",
|
|
66
66
|
"realm": "api.example.com",
|
|
@@ -91,7 +91,7 @@ describe('http', () => {
|
|
|
91
91
|
const headers = result.headers as Headers
|
|
92
92
|
|
|
93
93
|
expect(headers.get('Authorization')).toMatchInlineSnapshot(
|
|
94
|
-
`"Payment
|
|
94
|
+
`"Payment eyJjaGFsbGVuZ2UiOnsiZXhwaXJlcyI6IjIwMjUtMDEtMDFUMDA6MDA6MDAuMDAwWiIsImlkIjoid3YzdlpBanN5U001MGk0ZjFzSkNaeHlPTE5yeTBkTFNPd3VXREJxclhhdyIsImludGVudCI6ImNoYXJnZSIsIm1ldGhvZCI6InRlbXBvIiwicmVhbG0iOiJhcGkuZXhhbXBsZS5jb20iLCJyZXF1ZXN0IjoiZXlKaGJXOTFiblFpT2lJeE1EQXdJaXdpWTNWeWNtVnVZM2tpT2lJd2VESXdZekF3TURBd01EQXdNREF3TURBd01EQXdNREF3TURBd01EQXdNREF3TURBd01EQXdNREVpTENKbGVIQnBjbVZ6SWpvaU1qQXlOUzB3TVMwd01WUXdNRG93TURvd01DNHdNREJhSWl3aWNtVmphWEJwWlc1MElqb2lNSGczTkRKa016VkRZelkyTXpSRE1EVXpNamt5TldFellqZzBORUpqT1dVM05UazFaamhtUlRBd0luMCJ9LCJwYXlsb2FkIjp7InNpZ25hdHVyZSI6IjB4YWJjMTIzIiwidHlwZSI6InRyYW5zYWN0aW9uIn19"`,
|
|
95
95
|
)
|
|
96
96
|
})
|
|
97
97
|
|
|
@@ -182,7 +182,7 @@ describe('mcp', () => {
|
|
|
182
182
|
expect(transport.getChallenge(response)).toMatchInlineSnapshot(`
|
|
183
183
|
{
|
|
184
184
|
"expires": "2025-01-01T00:00:00.000Z",
|
|
185
|
-
"id": "
|
|
185
|
+
"id": "wv3vZAjsySM50i4f1sJCZxyOLNry0dLSOwuWDBqrXaw",
|
|
186
186
|
"intent": "charge",
|
|
187
187
|
"method": "tempo",
|
|
188
188
|
"realm": "api.example.com",
|
|
@@ -239,7 +239,7 @@ describe('mcp', () => {
|
|
|
239
239
|
"org.paymentauth/credential": {
|
|
240
240
|
"challenge": {
|
|
241
241
|
"expires": "2025-01-01T00:00:00.000Z",
|
|
242
|
-
"id": "
|
|
242
|
+
"id": "wv3vZAjsySM50i4f1sJCZxyOLNry0dLSOwuWDBqrXaw",
|
|
243
243
|
"intent": "charge",
|
|
244
244
|
"method": "tempo",
|
|
245
245
|
"realm": "api.example.com",
|
|
@@ -154,7 +154,7 @@ describe('McpClient.wrap', () => {
|
|
|
154
154
|
})
|
|
155
155
|
|
|
156
156
|
test('error: throws when method not found', async () => {
|
|
157
|
-
const challenge = Challenge.
|
|
157
|
+
const challenge = Challenge.fromMethod(tempo_server.charge({ getClient: () => testClient }), {
|
|
158
158
|
realm,
|
|
159
159
|
secretKey,
|
|
160
160
|
request: {
|
package/src/server/Mppx.ts
CHANGED
|
@@ -160,7 +160,7 @@ function createMethodFn(parameters: createMethodFn.Parameters): createMethodFn.R
|
|
|
160
160
|
// Recompute challenge from options. The HMAC-bound ID means we don't need to
|
|
161
161
|
// store challenges server-side—if the client echoes back a credential with
|
|
162
162
|
// a matching ID, we know it was issued by us with these exact parameters.
|
|
163
|
-
const challenge = Challenge.
|
|
163
|
+
const challenge = Challenge.fromMethod(method, {
|
|
164
164
|
description,
|
|
165
165
|
expires,
|
|
166
166
|
realm,
|
|
@@ -7,7 +7,7 @@ import { BadRequestError, ChannelClosedError } from '../Errors.js'
|
|
|
7
7
|
const realm = 'api.example.com'
|
|
8
8
|
const secretKey = 'test-secret-key'
|
|
9
9
|
|
|
10
|
-
const challenge = Challenge.
|
|
10
|
+
const challenge = Challenge.fromMethod(Methods.charge, {
|
|
11
11
|
realm,
|
|
12
12
|
secretKey,
|
|
13
13
|
request: {
|
|
@@ -43,7 +43,7 @@ describe('http', () => {
|
|
|
43
43
|
{
|
|
44
44
|
"challenge": {
|
|
45
45
|
"expires": "2025-01-01T00:00:00.000Z",
|
|
46
|
-
"id": "
|
|
46
|
+
"id": "6FkNG-Uv4Ff-viAxYvfyNLhbXbEXcfsbdEtB74ADviw",
|
|
47
47
|
"intent": "charge",
|
|
48
48
|
"method": "tempo",
|
|
49
49
|
"realm": "api.example.com",
|
|
@@ -93,7 +93,7 @@ describe('http', () => {
|
|
|
93
93
|
{
|
|
94
94
|
"headers": {
|
|
95
95
|
"cache-control": "no-store",
|
|
96
|
-
"www-authenticate": "Payment id="
|
|
96
|
+
"www-authenticate": "Payment id="6FkNG-Uv4Ff-viAxYvfyNLhbXbEXcfsbdEtB74ADviw", realm="api.example.com", method="tempo", intent="charge", request="eyJhbW91bnQiOiIxMDAwMDAwMDAwIiwiY3VycmVuY3kiOiIweDIwYzAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDEiLCJleHBpcmVzIjoiMjAyNS0wMS0wMVQwMDowMDowMC4wMDBaIiwicmVjaXBpZW50IjoiMHg3NDJkMzVDYzY2MzRDMDUzMjkyNWEzYjg0NEJjOWU3NTk1ZjhmRTAwIn0", expires="2025-01-01T00:00:00.000Z"",
|
|
97
97
|
},
|
|
98
98
|
"status": 402,
|
|
99
99
|
}
|
|
@@ -183,7 +183,7 @@ describe('mcp', () => {
|
|
|
183
183
|
{
|
|
184
184
|
"challenge": {
|
|
185
185
|
"expires": "2025-01-01T00:00:00.000Z",
|
|
186
|
-
"id": "
|
|
186
|
+
"id": "6FkNG-Uv4Ff-viAxYvfyNLhbXbEXcfsbdEtB74ADviw",
|
|
187
187
|
"intent": "charge",
|
|
188
188
|
"method": "tempo",
|
|
189
189
|
"realm": "api.example.com",
|
|
@@ -221,7 +221,7 @@ describe('mcp', () => {
|
|
|
221
221
|
"challenges": [
|
|
222
222
|
{
|
|
223
223
|
"expires": "2025-01-01T00:00:00.000Z",
|
|
224
|
-
"id": "
|
|
224
|
+
"id": "6FkNG-Uv4Ff-viAxYvfyNLhbXbEXcfsbdEtB74ADviw",
|
|
225
225
|
"intent": "charge",
|
|
226
226
|
"method": "tempo",
|
|
227
227
|
"realm": "api.example.com",
|
|
@@ -262,7 +262,7 @@ describe('mcp', () => {
|
|
|
262
262
|
"result": {
|
|
263
263
|
"_meta": {
|
|
264
264
|
"org.paymentauth/receipt": {
|
|
265
|
-
"challengeId": "
|
|
265
|
+
"challengeId": "6FkNG-Uv4Ff-viAxYvfyNLhbXbEXcfsbdEtB74ADviw",
|
|
266
266
|
"method": "tempo",
|
|
267
267
|
"reference": "0xtxhash",
|
|
268
268
|
"status": "success",
|