@tanakayuto/intmax402-express 0.1.0 → 0.1.2
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/middleware.js +4 -4
- package/package.json +2 -2
package/dist/middleware.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.intmax402 = intmax402;
|
|
4
|
-
const
|
|
4
|
+
const intmax402_core_1 = require("@tanakayuto/intmax402-core");
|
|
5
5
|
const crypto_1 = require("./crypto");
|
|
6
6
|
function buildWWWAuthenticate(nonce, config) {
|
|
7
7
|
let header = `INTMAX402 realm="intmax402", nonce="${nonce}", mode="${config.mode}"`;
|
|
@@ -24,7 +24,7 @@ function intmax402(config) {
|
|
|
24
24
|
const authHeader = req.headers.authorization;
|
|
25
25
|
if (!authHeader) {
|
|
26
26
|
const ip = req.ip || req.socket.remoteAddress || "unknown";
|
|
27
|
-
const nonce = (0,
|
|
27
|
+
const nonce = (0, intmax402_core_1.generateNonce)(config.secret, ip, req.path, config.bindIp ?? false);
|
|
28
28
|
const statusCode = config.mode === "payment" ? 402 : 401;
|
|
29
29
|
res.setHeader("WWW-Authenticate", buildWWWAuthenticate(nonce, config));
|
|
30
30
|
res.status(statusCode).json({
|
|
@@ -34,13 +34,13 @@ function intmax402(config) {
|
|
|
34
34
|
});
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
const credential = (0,
|
|
37
|
+
const credential = (0, intmax402_core_1.parseAuthorization)(authHeader);
|
|
38
38
|
if (!credential) {
|
|
39
39
|
res.status(401).json({ error: "Invalid authorization header" });
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
const ip = req.ip || req.socket.remoteAddress || "unknown";
|
|
43
|
-
if (!(0,
|
|
43
|
+
if (!(0, intmax402_core_1.verifyNonce)(credential.nonce, config.secret, ip, req.path, config.bindIp ?? false)) {
|
|
44
44
|
res.status(401).json({ error: "Invalid or expired nonce" });
|
|
45
45
|
return;
|
|
46
46
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanakayuto/intmax402-express",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@tanakayuto/intmax402-core": "0.1.
|
|
7
|
+
"@tanakayuto/intmax402-core": "0.1.2",
|
|
8
8
|
"ethers": "^6.16.0"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|