@idpartners/client-attestation-sdk 1.0.1 → 1.4.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.
@@ -0,0 +1,114 @@
1
+ /**
2
+ * WWW-Authenticate parsing (RFC 9110 section 11.6.1) by the rule every port shares (vectors/README.md, "The
3
+ * WWW-Authenticate rule"; cases in vectors/www-authenticate.json). Anything that does not follow the grammar
4
+ * makes the whole value malformed, so a caller that acts on a challenge fails closed.
5
+ * @internal
6
+ */
7
+ const TCHAR = /[!#$%&'*+\-.^_`|~0-9A-Za-z]/;
8
+ const TOKEN68 = /[\-._~+/0-9A-Za-z]/;
9
+ function ows(s, i) {
10
+ while (i < s.length && (s[i] === " " || s[i] === "\t"))
11
+ i++;
12
+ return i;
13
+ }
14
+ function token(s, i) {
15
+ while (i < s.length && TCHAR.test(s[i]))
16
+ i++;
17
+ return i;
18
+ }
19
+ function token68(s, i) {
20
+ const start = i;
21
+ while (i < s.length && TOKEN68.test(s[i]))
22
+ i++;
23
+ if (i === start)
24
+ return undefined;
25
+ while (s[i] === "=")
26
+ i++;
27
+ const k = ows(s, i);
28
+ return k === s.length || s[k] === "," ? i : undefined;
29
+ }
30
+ function qdtext(c) {
31
+ return c === 0x09 || c === 0x20 || c === 0x21 || (c >= 0x23 && c <= 0x5b) || (c >= 0x5d && c <= 0x7e) || c >= 0x80;
32
+ }
33
+ function quotedPairChar(c) {
34
+ return c === 0x09 || (c >= 0x20 && c <= 0x7e) || c >= 0x80;
35
+ }
36
+ /** A token or quoted-string at `i`: [value, index after it], or undefined. */
37
+ function value(s, i) {
38
+ if (s[i] === '"') {
39
+ let out = "";
40
+ for (i++; i < s.length;) {
41
+ const c = s.charCodeAt(i);
42
+ if (c === 0x22)
43
+ return [out, i + 1];
44
+ if (c === 0x5c) {
45
+ if (i + 1 >= s.length || !quotedPairChar(s.charCodeAt(i + 1)))
46
+ return undefined;
47
+ out += s[i + 1];
48
+ i += 2;
49
+ }
50
+ else if (qdtext(c)) {
51
+ out += s[i];
52
+ i++;
53
+ }
54
+ else {
55
+ return undefined;
56
+ }
57
+ }
58
+ return undefined;
59
+ }
60
+ const k = token(s, i);
61
+ return k > i ? [s.slice(i, k), k] : undefined;
62
+ }
63
+ /**
64
+ * Every field value of a WWW-Authenticate header, combined as one list (RFC 9110 section 5.3), as
65
+ * challenges; undefined when the combined value is malformed.
66
+ * @internal
67
+ */
68
+ export function parseWwwAuthenticate(values) {
69
+ const s = values.join(", ");
70
+ const out = [];
71
+ let i = 0;
72
+ for (;;) {
73
+ while (i < s.length && (s[i] === " " || s[i] === "\t" || s[i] === ","))
74
+ i++;
75
+ if (i >= s.length)
76
+ return out;
77
+ const start = i;
78
+ i = token(s, i);
79
+ if (i === start)
80
+ return undefined;
81
+ const name = s.slice(start, i).toLowerCase();
82
+ const j = ows(s, i);
83
+ if (s[j] === "=") {
84
+ if (out.length === 0)
85
+ return undefined;
86
+ const got = value(s, ows(s, j + 1));
87
+ if (got === undefined)
88
+ return undefined;
89
+ const params = out[out.length - 1].params;
90
+ if (params.has(name))
91
+ return undefined;
92
+ params.set(name, got[0]);
93
+ i = got[1];
94
+ }
95
+ else {
96
+ out.push({ scheme: name, params: new Map() });
97
+ const k = j > i ? token68(s, j) : undefined;
98
+ if (k === undefined) {
99
+ i = j; // its first auth-param (if any) follows without a comma
100
+ continue;
101
+ }
102
+ i = k;
103
+ }
104
+ i = ows(s, i);
105
+ if (i < s.length && s[i] !== ",")
106
+ return undefined;
107
+ }
108
+ }
109
+ /** A DPoP challenge whose error is exactly "use_dpop_nonce" (RFC 9449 section 9). @internal */
110
+ export function isDpopNonceChallenge(values) {
111
+ const challenges = parseWwwAuthenticate(values);
112
+ return challenges !== undefined &&
113
+ challenges.some((c) => c.scheme === "dpop" && c.params.get("error") === "use_dpop_nonce");
114
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idpartners/client-attestation-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.4.0",
4
4
  "description": "Client-side builder SDK for OAuth Attestation-Based Client Authentication",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -50,6 +50,7 @@
50
50
  "@types/node": "^20.0.0",
51
51
  "@vitest/coverage-v8": "^4.1.11",
52
52
  "esbuild": "^0.28.1",
53
+ "fast-check": "4.10.2",
53
54
  "tsx": "^4.23.15",
54
55
  "typescript": "^7.0.2",
55
56
  "vitest": "^4.1.11",