@tanakayuto/intmax402-core 0.2.2 → 0.2.4
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/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/parse.js +6 -0
- package/dist/www-authenticate.d.ts +2 -0
- package/dist/www-authenticate.js +19 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.parseAuthorization = exports.parseWWWAuthenticate = exports.verifyNonce = exports.generateNonce = void 0;
|
|
17
|
+
exports.buildWWWAuthenticate = exports.parseAuthorization = exports.parseWWWAuthenticate = exports.verifyNonce = exports.generateNonce = void 0;
|
|
18
18
|
__exportStar(require("./types"), exports);
|
|
19
19
|
var nonce_1 = require("./nonce");
|
|
20
20
|
Object.defineProperty(exports, "generateNonce", { enumerable: true, get: function () { return nonce_1.generateNonce; } });
|
|
@@ -23,3 +23,5 @@ Object.defineProperty(exports, "verifyNonce", { enumerable: true, get: function
|
|
|
23
23
|
var parse_1 = require("./parse");
|
|
24
24
|
Object.defineProperty(exports, "parseWWWAuthenticate", { enumerable: true, get: function () { return parse_1.parseWWWAuthenticate; } });
|
|
25
25
|
Object.defineProperty(exports, "parseAuthorization", { enumerable: true, get: function () { return parse_1.parseAuthorization; } });
|
|
26
|
+
var www_authenticate_1 = require("./www-authenticate");
|
|
27
|
+
Object.defineProperty(exports, "buildWWWAuthenticate", { enumerable: true, get: function () { return www_authenticate_1.buildWWWAuthenticate; } });
|
package/dist/parse.js
CHANGED
|
@@ -42,10 +42,16 @@ function parseAuthorization(header) {
|
|
|
42
42
|
// address: 42 chars (0x + 40 hex), nonce: 64 chars (sha256 hex), signature: 132 chars (0x + 130 hex)
|
|
43
43
|
if (result.address.length !== 42)
|
|
44
44
|
return null;
|
|
45
|
+
if (!/^0[xX][0-9a-fA-F]{40}$/.test(result.address))
|
|
46
|
+
return null;
|
|
45
47
|
if (result.nonce.length !== 64)
|
|
46
48
|
return null;
|
|
49
|
+
if (!/^[0-9a-f]{64}$/.test(result.nonce))
|
|
50
|
+
return null;
|
|
47
51
|
if (result.signature.length !== 132)
|
|
48
52
|
return null;
|
|
53
|
+
if (!/^0x[0-9a-fA-F]{130}$/.test(result.signature))
|
|
54
|
+
return null;
|
|
49
55
|
if (result.txHash && result.txHash.length > 128)
|
|
50
56
|
return null;
|
|
51
57
|
return {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildWWWAuthenticate = buildWWWAuthenticate;
|
|
4
|
+
// Remove characters that could break the WWW-Authenticate header format
|
|
5
|
+
function sanitize(value) {
|
|
6
|
+
return value.replace(/["\\r\n]/g, "");
|
|
7
|
+
}
|
|
8
|
+
function buildWWWAuthenticate(nonce, config) {
|
|
9
|
+
let header = `INTMAX402 realm="intmax402", nonce="${nonce}", mode="${config.mode}"`;
|
|
10
|
+
if (config.serverAddress)
|
|
11
|
+
header += `, serverAddress="${sanitize(config.serverAddress)}"`;
|
|
12
|
+
if (config.amount)
|
|
13
|
+
header += `, amount="${sanitize(config.amount)}"`;
|
|
14
|
+
if (config.tokenAddress)
|
|
15
|
+
header += `, tokenAddress="${sanitize(config.tokenAddress)}"`;
|
|
16
|
+
if (config.chainId)
|
|
17
|
+
header += `, chainId="${sanitize(config.chainId)}"`;
|
|
18
|
+
return header;
|
|
19
|
+
}
|