s402 0.1.6 → 0.1.7
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/CHANGELOG.md +50 -0
- package/README.md +9 -6
- package/SECURITY.md +1 -1
- package/dist/http.mjs +9 -0
- package/dist/types.d.mts +33 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,50 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.1.6] - 2026-02-19
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **Security audit patches** (15 true positives, H-1 through M-6, L-2):
|
|
13
|
+
- H-1: `process()` wraps `resolveScheme`/`verify`/`settle` in try/catch — unhandled rejections no longer crash server middleware; returns `{success: false}` instead
|
|
14
|
+
- H-2: In-flight dedup `Set` on `process()` — concurrent identical payloads can no longer both reach `scheme.settle()`
|
|
15
|
+
- H-3: `Promise.race()` timeouts — 5s for verify, 15s for settle — prevents hanging RPC calls from exhausting the event loop
|
|
16
|
+
- M-1: `facilitatorUrl` in x402 compat now validated via `new URL()` — rejects `javascript:`, `file://`, and other non-http(s) schemes (SSRF guard)
|
|
17
|
+
- M-2: `isValidAmount` → `isValidU64Amount` on decode — rejects amounts above u64 max at the wire boundary
|
|
18
|
+
- M-5: Settle catch returns `SETTLEMENT_FAILED` (`retryable: true`) instead of `VERIFICATION_FAILED` (`retryable: false`) — agents can now retry on transient RPC failures
|
|
19
|
+
- M-6: `payTo` validation tightened from `startsWith('0x')` to full Sui address regex `/^0x[0-9a-fA-F]{64}$/` — rejects `'0x'` alone and non-hex chars
|
|
20
|
+
- L-2: `expiresAt` guard extended to reject `<= 0` — negative timestamps and zero are now invalid at decode time
|
|
21
|
+
|
|
22
|
+
## [0.1.5] - 2026-02-19
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- Author updated to SweeInc brand name
|
|
27
|
+
- Renamed `@sweepay/*` → `@sweefi/*` across all documentation
|
|
28
|
+
|
|
29
|
+
## [0.1.4] - 2026-02-18
|
|
30
|
+
|
|
31
|
+
_Version bump for npm publish after license change._
|
|
32
|
+
|
|
33
|
+
## [0.1.3] - 2026-02-18
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- License changed from MIT to Apache-2.0
|
|
38
|
+
- Documentation consolidated (removed codebase-tour, added complete guide)
|
|
39
|
+
- Updated tagline to "HTTP 402 payment protocol"
|
|
40
|
+
|
|
41
|
+
### Added
|
|
42
|
+
|
|
43
|
+
- CI and npm version badges to README
|
|
44
|
+
|
|
45
|
+
## [0.1.2] - 2026-02-16
|
|
46
|
+
|
|
47
|
+
### Added
|
|
48
|
+
|
|
49
|
+
- CI workflow (GitHub Actions) with tag-based npm releases
|
|
50
|
+
- Separate build job for Node 22
|
|
51
|
+
|
|
8
52
|
## [0.1.1] - 2026-02-16
|
|
9
53
|
|
|
10
54
|
### Fixed
|
|
@@ -33,4 +77,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
33
77
|
- Property-based fuzz testing via fast-check
|
|
34
78
|
- 207 tests, zero runtime dependencies
|
|
35
79
|
|
|
80
|
+
[0.1.6]: https://github.com/s402-protocol/core/compare/v0.1.5...v0.1.6
|
|
81
|
+
[0.1.5]: https://github.com/s402-protocol/core/compare/v0.1.4...v0.1.5
|
|
82
|
+
[0.1.4]: https://github.com/s402-protocol/core/compare/v0.1.3...v0.1.4
|
|
83
|
+
[0.1.3]: https://github.com/s402-protocol/core/compare/v0.1.2...v0.1.3
|
|
84
|
+
[0.1.2]: https://github.com/s402-protocol/core/compare/v0.1.1...v0.1.2
|
|
85
|
+
[0.1.1]: https://github.com/s402-protocol/core/compare/v0.1.0...v0.1.1
|
|
36
86
|
[0.1.0]: https://github.com/s402-protocol/core/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -45,11 +45,14 @@ s402 <-- You are here. Protocol spec. Zero runtime deps.
|
|
|
45
45
|
|-- Compat Optional x402 migration aid
|
|
46
46
|
|-- Errors Typed error codes with recovery hints
|
|
47
47
|
|
|
|
48
|
-
@sweefi/sui <-- Sui
|
|
49
|
-
@sweefi/
|
|
48
|
+
@sweefi/sui <-- Sui adapter: 40 PTB builders + SuiPaymentAdapter + createS402Client
|
|
49
|
+
@sweefi/server <-- Chain-agnostic HTTP: s402Gate middleware + wrapFetchWithS402
|
|
50
|
+
@sweefi/ui-core <-- State machine + PaymentAdapter interface
|
|
51
|
+
@sweefi/vue <-- Vue 3 plugin + useSweefiPayment() composable
|
|
52
|
+
@sweefi/react <-- React context + useSweefiPayment() hook
|
|
50
53
|
```
|
|
51
54
|
|
|
52
|
-
`s402` is **chain-agnostic protocol plumbing**. It defines _what_ gets sent over HTTP. The Sui-specific _how_
|
|
55
|
+
`s402` is **chain-agnostic protocol plumbing**. It defines _what_ gets sent over HTTP. The Sui-specific _how_ lives in [`@sweefi/sui`](https://www.npmjs.com/package/@sweefi/sui).
|
|
53
56
|
|
|
54
57
|
## Payment Schemes
|
|
55
58
|
|
|
@@ -158,7 +161,7 @@ const requirements: s402PaymentRequirements = {
|
|
|
158
161
|
network: 'sui:mainnet',
|
|
159
162
|
asset: '0x2::sui::SUI',
|
|
160
163
|
amount: '1000000', // 0.001 SUI in MIST
|
|
161
|
-
payTo: '
|
|
164
|
+
payTo: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
162
165
|
};
|
|
163
166
|
|
|
164
167
|
response.status = 402;
|
|
@@ -258,7 +261,7 @@ import type {
|
|
|
258
261
|
} from 's402';
|
|
259
262
|
```
|
|
260
263
|
|
|
261
|
-
The reference Sui implementation of all five schemes
|
|
264
|
+
The reference Sui implementation of all five schemes is available in [`@sweefi/sui`](https://www.npmjs.com/package/@sweefi/sui).
|
|
262
265
|
|
|
263
266
|
## Wire Format
|
|
264
267
|
|
|
@@ -303,7 +306,7 @@ const requirements: s402PaymentRequirements = {
|
|
|
303
306
|
network: 'sui:mainnet',
|
|
304
307
|
asset: '0x2::sui::SUI',
|
|
305
308
|
amount: '1000000',
|
|
306
|
-
payTo: '
|
|
309
|
+
payTo: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
307
310
|
expiresAt: Date.now() + 5 * 60 * 1000, // 5-minute window
|
|
308
311
|
};
|
|
309
312
|
```
|
package/SECURITY.md
CHANGED
|
@@ -15,7 +15,7 @@ You will receive an acknowledgment within 48 hours. We aim to provide a fix or m
|
|
|
15
15
|
|
|
16
16
|
This policy covers the `s402` npm package — the protocol types, HTTP encoding/decoding, scheme registry, and compat layer.
|
|
17
17
|
|
|
18
|
-
Security issues in downstream packages (`@sweefi/sui`, `@sweefi/
|
|
18
|
+
Security issues in downstream packages (`@sweefi/sui`, `@sweefi/server`, `@sweefi/ui-core`, etc.) should be reported to the same email.
|
|
19
19
|
|
|
20
20
|
## What qualifies
|
|
21
21
|
|
package/dist/http.mjs
CHANGED
|
@@ -345,6 +345,8 @@ function validateRequirementsShape(obj) {
|
|
|
345
345
|
if (typeof record.payTo !== "string") missing.push("payTo (string)");
|
|
346
346
|
else if (!/^0x[0-9a-fA-F]{64}$/.test(record.payTo)) throw new s402Error("INVALID_PAYLOAD", `payTo must be a 32-byte Sui address (0x + 64 hex chars), got "${record.payTo.substring(0, 20)}..."`);
|
|
347
347
|
if (missing.length > 0) throw new s402Error("INVALID_PAYLOAD", `Malformed payment requirements: missing ${missing.join(", ")}`);
|
|
348
|
+
if (/[\x00-\x1f\x7f]/.test(record.network)) throw new s402Error("INVALID_PAYLOAD", "network contains control characters");
|
|
349
|
+
if (/[\x00-\x1f\x7f]/.test(record.asset)) throw new s402Error("INVALID_PAYLOAD", "asset contains control characters");
|
|
348
350
|
if (Array.isArray(record.accepts) && record.accepts.length === 0) throw new s402Error("INVALID_PAYLOAD", "accepts array must contain at least one scheme");
|
|
349
351
|
const accepts = record.accepts;
|
|
350
352
|
for (const scheme of accepts) if (typeof scheme !== "string") throw new s402Error("INVALID_PAYLOAD", `Invalid entry in accepts array: expected string, got ${typeof scheme}`);
|
|
@@ -354,6 +356,13 @@ function validateRequirementsShape(obj) {
|
|
|
354
356
|
if (record.expiresAt !== void 0) {
|
|
355
357
|
if (typeof record.expiresAt !== "number" || !Number.isFinite(record.expiresAt) || record.expiresAt <= 0) throw new s402Error("INVALID_PAYLOAD", `expiresAt must be a positive finite number (Unix timestamp ms), got ${record.expiresAt}`);
|
|
356
358
|
}
|
|
359
|
+
if (record.protocolFeeAddress !== void 0) {
|
|
360
|
+
if (typeof record.protocolFeeAddress !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(record.protocolFeeAddress)) throw new s402Error("INVALID_PAYLOAD", `protocolFeeAddress must be a 32-byte Sui address (0x + 64 hex chars), got "${String(record.protocolFeeAddress).substring(0, 20)}..."`);
|
|
361
|
+
}
|
|
362
|
+
if (record.facilitatorUrl !== void 0) {
|
|
363
|
+
if (typeof record.facilitatorUrl !== "string") throw new s402Error("INVALID_PAYLOAD", `facilitatorUrl must be a string, got ${typeof record.facilitatorUrl}`);
|
|
364
|
+
if (/[\x00-\x1f\x7f]/.test(record.facilitatorUrl)) throw new s402Error("INVALID_PAYLOAD", "facilitatorUrl contains control characters (potential header injection)");
|
|
365
|
+
}
|
|
357
366
|
validateSubObjects(record);
|
|
358
367
|
}
|
|
359
368
|
/** Validate that a decoded payment payload has the required shape. */
|
package/dist/types.d.mts
CHANGED
|
@@ -28,9 +28,27 @@ interface s402PaymentRequirements {
|
|
|
28
28
|
facilitatorUrl?: string;
|
|
29
29
|
/** AP2 mandate requirements (if agent spending authorization is needed) */
|
|
30
30
|
mandate?: s402MandateRequirements;
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Protocol fee in basis points (0-10000). **Advisory only.**
|
|
33
|
+
*
|
|
34
|
+
* This field is a transparency hint for the client's UI — it lets the payer
|
|
35
|
+
* see the total cost before committing. It is NOT the source of truth for
|
|
36
|
+
* settlement math. The authoritative fee rate is owned by the Facilitator
|
|
37
|
+
* (configured in its ProtocolState or equivalent on-chain object) and
|
|
38
|
+
* enforced at the smart contract level.
|
|
39
|
+
*
|
|
40
|
+
* Resource Servers SHOULD omit this field and let the Facilitator provide
|
|
41
|
+
* it via its `/.well-known/s402-facilitator` endpoint. If included, it MUST
|
|
42
|
+
* match the Facilitator's configured rate — a mismatch is a warning sign.
|
|
43
|
+
*
|
|
44
|
+
* Trust model: Facilitator owns the fee. Resource Server cannot override it.
|
|
45
|
+
*/
|
|
32
46
|
protocolFeeBps?: number;
|
|
33
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Address that receives the protocol fee.
|
|
49
|
+
* Advisory only — authoritative value is in Facilitator's on-chain config.
|
|
50
|
+
* Defaults to the Facilitator's own address if omitted.
|
|
51
|
+
*/
|
|
34
52
|
protocolFeeAddress?: string;
|
|
35
53
|
/** Whether the server requires an on-chain receipt NFT */
|
|
36
54
|
receiptRequired?: boolean;
|
|
@@ -107,6 +125,19 @@ interface s402PrepaidExtra {
|
|
|
107
125
|
minDeposit: string;
|
|
108
126
|
/** Withdrawal delay in ms. Agent must wait this long after last claim. Min 60s, max 7d. */
|
|
109
127
|
withdrawalDelayMs: string;
|
|
128
|
+
/**
|
|
129
|
+
* Provider's Ed25519 public key (hex string, 32 bytes).
|
|
130
|
+
* When present, enables v0.2 signed receipt mode — claims enter a pending
|
|
131
|
+
* state and can be disputed with cryptographic fraud proofs.
|
|
132
|
+
* @since v0.2
|
|
133
|
+
*/
|
|
134
|
+
providerPubkey?: string;
|
|
135
|
+
/**
|
|
136
|
+
* Dispute window in milliseconds. Min 60s (60000), max 24h (86400000).
|
|
137
|
+
* Only relevant when providerPubkey is set.
|
|
138
|
+
* @since v0.2
|
|
139
|
+
*/
|
|
140
|
+
disputeWindowMs?: string;
|
|
110
141
|
}
|
|
111
142
|
/** Mandate requirements in a 402 response — tells client what mandate is needed */
|
|
112
143
|
interface s402MandateRequirements {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "s402",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "s402 — Sui-native HTTP 402 wire format. Types, HTTP encoding, and scheme registry for five payment schemes. Wire-compatible with x402. Zero runtime dependencies.",
|
|
6
6
|
"license": "Apache-2.0",
|