@inflowpayai/x402 0.5.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 +84 -0
- package/dist/extensions/index.cjs +78 -0
- package/dist/extensions/index.cjs.map +1 -0
- package/dist/extensions/index.d.cts +32 -0
- package/dist/extensions/index.d.ts +32 -0
- package/dist/extensions/index.js +66 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extras/index.cjs +17 -0
- package/dist/extras/index.cjs.map +1 -0
- package/dist/extras/index.d.cts +23 -0
- package/dist/extras/index.d.ts +23 -0
- package/dist/extras/index.js +14 -0
- package/dist/extras/index.js.map +1 -0
- package/dist/index.cjs +421 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +571 -0
- package/dist/index.d.ts +571 -0
- package/dist/index.js +401 -0
- package/dist/index.js.map +1 -0
- package/dist/payment-identifier-BNYznClf.d.cts +103 -0
- package/dist/payment-identifier-BNYznClf.d.ts +103 -0
- package/dist/security/index.cjs +17 -0
- package/dist/security/index.cjs.map +1 -0
- package/dist/security/index.d.cts +14 -0
- package/dist/security/index.d.ts +14 -0
- package/dist/security/index.js +15 -0
- package/dist/security/index.js.map +1 -0
- package/package.json +97 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-call context threaded into {@link ExtensionHandler.buildDeclaration}. Reserved for forward compatibility: handlers
|
|
3
|
+
* may inspect fields here in future revisions. The seller's `inflowAccepts` currently passes `{}`.
|
|
4
|
+
*/
|
|
5
|
+
type DeclarationContext = Record<string, never>;
|
|
6
|
+
/**
|
|
7
|
+
* Per-call context threaded into {@link ExtensionHandler.buildPayloadEntry}. Populated by the buyer signer when
|
|
8
|
+
* constructing a `PaymentPayload`.
|
|
9
|
+
*/
|
|
10
|
+
interface SignContext {
|
|
11
|
+
/**
|
|
12
|
+
* Caller-supplied payment identifier (from `SignOptions.paymentId`) when the SDK writes the extensions map directly —
|
|
13
|
+
* i.e. on the foundation-signed branch. Absent on the InFlow-signed branch, where the server embeds the identifier
|
|
14
|
+
* server-side.
|
|
15
|
+
*/
|
|
16
|
+
providedPaymentId?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Pluggable handler for one protocol extension. Sellers call `buildDeclaration` to populate
|
|
20
|
+
* `PaymentRequired.extensions[name]`; buyers call `readDeclaration` to parse what the server emitted, and
|
|
21
|
+
* `buildPayloadEntry` to produce the corresponding `PaymentPayload.extensions[name]` value.
|
|
22
|
+
*
|
|
23
|
+
* @typeParam TDeclaration - Shape of the declaration object the seller emits and the buyer reads.
|
|
24
|
+
* @typeParam TPayloadEntry - Shape of the per-payload entry the buyer emits.
|
|
25
|
+
*/
|
|
26
|
+
interface ExtensionHandler<TDeclaration, TPayloadEntry> {
|
|
27
|
+
/** Extension name, matching the wire key in `extensions[]` maps. */
|
|
28
|
+
readonly name: string;
|
|
29
|
+
/**
|
|
30
|
+
* Build the per-response declaration. Return `null` to omit this extension from the response entirely.
|
|
31
|
+
*
|
|
32
|
+
* @param context - {@link DeclarationContext}.
|
|
33
|
+
* @returns The declaration value, or `null`.
|
|
34
|
+
*/
|
|
35
|
+
buildDeclaration(context: DeclarationContext): TDeclaration | null;
|
|
36
|
+
/**
|
|
37
|
+
* Parse a declaration emitted by a server. Implementations should be defensive: anything that doesn't match the
|
|
38
|
+
* expected shape returns `null`.
|
|
39
|
+
*
|
|
40
|
+
* @param decl - The raw value read from `PaymentRequired.extensions[name]`.
|
|
41
|
+
* @returns The parsed declaration, or `null` when the input was missing or malformed.
|
|
42
|
+
*/
|
|
43
|
+
readDeclaration(decl: unknown): TDeclaration | null;
|
|
44
|
+
/**
|
|
45
|
+
* Build the per-payload entry. Return `null` to skip embedding for this call — common when the declaration was
|
|
46
|
+
* `required: false` and the caller did not opt in.
|
|
47
|
+
*
|
|
48
|
+
* @param declaration - The parsed declaration the server emitted on the matching 402.
|
|
49
|
+
* @param context - {@link SignContext}.
|
|
50
|
+
* @returns The payload-entry value, or `null` to omit.
|
|
51
|
+
*/
|
|
52
|
+
buildPayloadEntry(declaration: TDeclaration, context: SignContext): TPayloadEntry | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Extension name on the wire — the key in `extensions[]` maps. */
|
|
56
|
+
declare const EXTENSION_PAYMENT_IDENTIFIER: "payment-identifier";
|
|
57
|
+
declare const PAYMENT_ID_MIN_LENGTH = 16;
|
|
58
|
+
declare const PAYMENT_ID_MAX_LENGTH = 128;
|
|
59
|
+
/** Regex a valid payment identifier must match. Mirrors the x402 `payment-identifier` extension spec. */
|
|
60
|
+
declare const PAYMENT_ID_REGEX: RegExp;
|
|
61
|
+
/**
|
|
62
|
+
* Default prefix used by {@link generatePaymentId}. Mirrors the format produced by InFlow's automatic
|
|
63
|
+
* transaction-id-derived identifiers (`pay_<32 hex chars>`).
|
|
64
|
+
*/
|
|
65
|
+
declare const PAYMENT_ID_DEFAULT_PREFIX = "pay_";
|
|
66
|
+
/** Declaration shape attached to `PaymentRequired.extensions['payment-identifier']`. */
|
|
67
|
+
interface PaymentIdentifierDeclaration {
|
|
68
|
+
/**
|
|
69
|
+
* When `true`, the payload's `extensions['payment-identifier'].paymentId` is mandatory; settlement fails without it.
|
|
70
|
+
* When `false`, the field is optional and may be omitted.
|
|
71
|
+
*/
|
|
72
|
+
required: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** Payload-entry shape attached to `PaymentPayload.extensions['payment-identifier']`. */
|
|
75
|
+
interface PaymentIdentifierPayloadEntry {
|
|
76
|
+
/** The identifier value, satisfying {@link validatePaymentId}. */
|
|
77
|
+
paymentId: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Validate a payment-identifier string against the extension spec.
|
|
81
|
+
*
|
|
82
|
+
* @param id - Candidate identifier. Returns `false` for any non-string input.
|
|
83
|
+
* @returns `true` when `id` is a string of length 16–128 containing only `a–z`, `A–Z`, `0–9`, `_`, and `-`. `false`
|
|
84
|
+
* otherwise.
|
|
85
|
+
*/
|
|
86
|
+
declare function validatePaymentId(id: unknown): id is string;
|
|
87
|
+
/**
|
|
88
|
+
* Generate a new payment identifier.
|
|
89
|
+
*
|
|
90
|
+
* @param prefix - String prefix prepended to a random 32-character hex suffix. Defaults to `'pay_'`. Must satisfy
|
|
91
|
+
* `^[a-zA-Z0-9_-]*$` and yield a total length of 16–128 when combined with the suffix.
|
|
92
|
+
* @returns A string of the form `<prefix><32 hex chars>` (lowercase).
|
|
93
|
+
* @throws {Error} When `prefix` contains characters not allowed by {@link PAYMENT_ID_REGEX} or the resulting identifier
|
|
94
|
+
* falls outside the 16–128-character bound.
|
|
95
|
+
*/
|
|
96
|
+
declare function generatePaymentId(prefix?: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Handler for the x402 `payment-identifier` extension. Used by the seller (`inflowAccepts`) and the buyer (signer flows
|
|
99
|
+
* that compose external `x402Client` signers).
|
|
100
|
+
*/
|
|
101
|
+
declare const PAYMENT_IDENTIFIER: ExtensionHandler<PaymentIdentifierDeclaration, PaymentIdentifierPayloadEntry>;
|
|
102
|
+
|
|
103
|
+
export { type DeclarationContext as D, EXTENSION_PAYMENT_IDENTIFIER as E, PAYMENT_IDENTIFIER as P, type SignContext as S, type ExtensionHandler as a, PAYMENT_ID_DEFAULT_PREFIX as b, PAYMENT_ID_MAX_LENGTH as c, PAYMENT_ID_MIN_LENGTH as d, PAYMENT_ID_REGEX as e, type PaymentIdentifierDeclaration as f, type PaymentIdentifierPayloadEntry as g, generatePaymentId as h, validatePaymentId as v };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var buffer = require('buffer');
|
|
4
|
+
var crypto = require('crypto');
|
|
5
|
+
|
|
6
|
+
// src/security/index.ts
|
|
7
|
+
function timingSafeEqualStrings(a, b) {
|
|
8
|
+
if (typeof a !== "string" || typeof b !== "string") return false;
|
|
9
|
+
const ab = buffer.Buffer.from(a, "utf8");
|
|
10
|
+
const bb = buffer.Buffer.from(b, "utf8");
|
|
11
|
+
if (ab.length !== bb.length) return false;
|
|
12
|
+
return crypto.timingSafeEqual(ab, bb);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.timingSafeEqualStrings = timingSafeEqualStrings;
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
17
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/security/index.ts"],"names":["Buffer","timingSafeEqual"],"mappings":";;;;;;AAcO,SAAS,sBAAA,CAAuB,GAAY,CAAA,EAAqB;AACtE,EAAA,IAAI,OAAO,CAAA,KAAM,QAAA,IAAY,OAAO,CAAA,KAAM,UAAU,OAAO,KAAA;AAC3D,EAAA,MAAM,EAAA,GAAKA,aAAA,CAAO,IAAA,CAAK,CAAA,EAAG,MAAM,CAAA;AAChC,EAAA,MAAM,EAAA,GAAKA,aAAA,CAAO,IAAA,CAAK,CAAA,EAAG,MAAM,CAAA;AAChC,EAAA,IAAI,EAAA,CAAG,MAAA,KAAW,EAAA,CAAG,MAAA,EAAQ,OAAO,KAAA;AACpC,EAAA,OAAOC,sBAAA,CAAgB,IAAI,EAAE,CAAA;AAC/B","file":"index.cjs","sourcesContent":["import { Buffer } from 'node:buffer';\nimport { timingSafeEqual } from 'node:crypto';\n\n/**\n * Constant-time string equality.\n *\n * @param a - First value. Anything other than a string returns `false`.\n * @param b - Second value. Anything other than a string returns `false`.\n * @returns `true` when both arguments are strings, have equal UTF-8 byte length, and have identical byte content. The\n * comparison time does not depend on where the strings differ. Returns `false` otherwise.\n *\n * Use for comparing opaque tokens such as payment identifiers and extension-supplied HMAC values where naive equality\n * (`===`) could leak timing information.\n */\nexport function timingSafeEqualStrings(a: unknown, b: unknown): boolean {\n if (typeof a !== 'string' || typeof b !== 'string') return false;\n const ab = Buffer.from(a, 'utf8');\n const bb = Buffer.from(b, 'utf8');\n if (ab.length !== bb.length) return false;\n return timingSafeEqual(ab, bb);\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constant-time string equality.
|
|
3
|
+
*
|
|
4
|
+
* @param a - First value. Anything other than a string returns `false`.
|
|
5
|
+
* @param b - Second value. Anything other than a string returns `false`.
|
|
6
|
+
* @returns `true` when both arguments are strings, have equal UTF-8 byte length, and have identical byte content. The
|
|
7
|
+
* comparison time does not depend on where the strings differ. Returns `false` otherwise.
|
|
8
|
+
*
|
|
9
|
+
* Use for comparing opaque tokens such as payment identifiers and extension-supplied HMAC values where naive equality
|
|
10
|
+
* (`===`) could leak timing information.
|
|
11
|
+
*/
|
|
12
|
+
declare function timingSafeEqualStrings(a: unknown, b: unknown): boolean;
|
|
13
|
+
|
|
14
|
+
export { timingSafeEqualStrings };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constant-time string equality.
|
|
3
|
+
*
|
|
4
|
+
* @param a - First value. Anything other than a string returns `false`.
|
|
5
|
+
* @param b - Second value. Anything other than a string returns `false`.
|
|
6
|
+
* @returns `true` when both arguments are strings, have equal UTF-8 byte length, and have identical byte content. The
|
|
7
|
+
* comparison time does not depend on where the strings differ. Returns `false` otherwise.
|
|
8
|
+
*
|
|
9
|
+
* Use for comparing opaque tokens such as payment identifiers and extension-supplied HMAC values where naive equality
|
|
10
|
+
* (`===`) could leak timing information.
|
|
11
|
+
*/
|
|
12
|
+
declare function timingSafeEqualStrings(a: unknown, b: unknown): boolean;
|
|
13
|
+
|
|
14
|
+
export { timingSafeEqualStrings };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { timingSafeEqual } from 'crypto';
|
|
3
|
+
|
|
4
|
+
// src/security/index.ts
|
|
5
|
+
function timingSafeEqualStrings(a, b) {
|
|
6
|
+
if (typeof a !== "string" || typeof b !== "string") return false;
|
|
7
|
+
const ab = Buffer.from(a, "utf8");
|
|
8
|
+
const bb = Buffer.from(b, "utf8");
|
|
9
|
+
if (ab.length !== bb.length) return false;
|
|
10
|
+
return timingSafeEqual(ab, bb);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { timingSafeEqualStrings };
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/security/index.ts"],"names":[],"mappings":";;;;AAcO,SAAS,sBAAA,CAAuB,GAAY,CAAA,EAAqB;AACtE,EAAA,IAAI,OAAO,CAAA,KAAM,QAAA,IAAY,OAAO,CAAA,KAAM,UAAU,OAAO,KAAA;AAC3D,EAAA,MAAM,EAAA,GAAK,MAAA,CAAO,IAAA,CAAK,CAAA,EAAG,MAAM,CAAA;AAChC,EAAA,MAAM,EAAA,GAAK,MAAA,CAAO,IAAA,CAAK,CAAA,EAAG,MAAM,CAAA;AAChC,EAAA,IAAI,EAAA,CAAG,MAAA,KAAW,EAAA,CAAG,MAAA,EAAQ,OAAO,KAAA;AACpC,EAAA,OAAO,eAAA,CAAgB,IAAI,EAAE,CAAA;AAC/B","file":"index.js","sourcesContent":["import { Buffer } from 'node:buffer';\nimport { timingSafeEqual } from 'node:crypto';\n\n/**\n * Constant-time string equality.\n *\n * @param a - First value. Anything other than a string returns `false`.\n * @param b - Second value. Anything other than a string returns `false`.\n * @returns `true` when both arguments are strings, have equal UTF-8 byte length, and have identical byte content. The\n * comparison time does not depend on where the strings differ. Returns `false` otherwise.\n *\n * Use for comparing opaque tokens such as payment identifiers and extension-supplied HMAC values where naive equality\n * (`===`) could leak timing information.\n */\nexport function timingSafeEqualStrings(a: unknown, b: unknown): boolean {\n if (typeof a !== 'string' || typeof b !== 'string') return false;\n const ab = Buffer.from(a, 'utf8');\n const bb = Buffer.from(b, 'utf8');\n if (ab.length !== bb.length) return false;\n return timingSafeEqual(ab, bb);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inflowpayai/x402",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "InFlow x402 SDK core: protocol types, HTTP client, scheme constants.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"node": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./security": {
|
|
20
|
+
"types": "./dist/security/index.d.ts",
|
|
21
|
+
"node": {
|
|
22
|
+
"import": "./dist/security/index.js",
|
|
23
|
+
"require": "./dist/security/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"default": "./dist/security/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./extensions": {
|
|
28
|
+
"types": "./dist/extensions/index.d.ts",
|
|
29
|
+
"node": {
|
|
30
|
+
"import": "./dist/extensions/index.js",
|
|
31
|
+
"require": "./dist/extensions/index.cjs"
|
|
32
|
+
},
|
|
33
|
+
"default": "./dist/extensions/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./extras": {
|
|
36
|
+
"types": "./dist/extras/index.d.ts",
|
|
37
|
+
"node": {
|
|
38
|
+
"import": "./dist/extras/index.js",
|
|
39
|
+
"require": "./dist/extras/index.cjs"
|
|
40
|
+
},
|
|
41
|
+
"default": "./dist/extras/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist",
|
|
47
|
+
"README.md",
|
|
48
|
+
"LICENSE"
|
|
49
|
+
],
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=22.13.0"
|
|
52
|
+
},
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@x402/core": "^2.12.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependenciesMeta": {
|
|
58
|
+
"@x402/core": {
|
|
59
|
+
"optional": false
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@vitest/coverage-v8": "^2.1.0",
|
|
64
|
+
"@x402/core": "^2.12.0",
|
|
65
|
+
"msw": "^2.4.0"
|
|
66
|
+
},
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public",
|
|
69
|
+
"provenance": true
|
|
70
|
+
},
|
|
71
|
+
"repository": {
|
|
72
|
+
"type": "git",
|
|
73
|
+
"url": "git+https://github.com/inflowpayai/inflow-node.git",
|
|
74
|
+
"directory": "packages/x402"
|
|
75
|
+
},
|
|
76
|
+
"bugs": {
|
|
77
|
+
"url": "https://github.com/inflowpayai/inflow-node/issues"
|
|
78
|
+
},
|
|
79
|
+
"homepage": "https://github.com/inflowpayai/inflow-node/tree/main/packages/x402#readme",
|
|
80
|
+
"keywords": [
|
|
81
|
+
"x402",
|
|
82
|
+
"payments",
|
|
83
|
+
"inflow",
|
|
84
|
+
"@inflowpayai",
|
|
85
|
+
"core",
|
|
86
|
+
"types"
|
|
87
|
+
],
|
|
88
|
+
"scripts": {
|
|
89
|
+
"build": "tsup",
|
|
90
|
+
"dev": "tsup --watch",
|
|
91
|
+
"test": "vitest run --coverage",
|
|
92
|
+
"test:watch": "vitest",
|
|
93
|
+
"lint": "eslint src test --max-warnings 0",
|
|
94
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
95
|
+
"clean": "rm -rf dist .turbo"
|
|
96
|
+
}
|
|
97
|
+
}
|