@zskj-idaas/sdk 1.0.0 → 1.0.1
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.js +119 -1
- package/dist/index.mjs +119 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -42,11 +42,129 @@ function base64UrlEncode(buffer) {
|
|
|
42
42
|
});
|
|
43
43
|
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
44
44
|
}
|
|
45
|
+
async function sha256(data) {
|
|
46
|
+
if (typeof crypto !== "undefined" && crypto.subtle) {
|
|
47
|
+
return crypto.subtle.digest("SHA-256", data);
|
|
48
|
+
}
|
|
49
|
+
const K = [
|
|
50
|
+
1116352408,
|
|
51
|
+
1899447441,
|
|
52
|
+
3049323471,
|
|
53
|
+
3921009573,
|
|
54
|
+
961987163,
|
|
55
|
+
1508970993,
|
|
56
|
+
2453635748,
|
|
57
|
+
2870763221,
|
|
58
|
+
3624381080,
|
|
59
|
+
310598401,
|
|
60
|
+
607225278,
|
|
61
|
+
1426881987,
|
|
62
|
+
1925078388,
|
|
63
|
+
2162078206,
|
|
64
|
+
2614888103,
|
|
65
|
+
3248222580,
|
|
66
|
+
3835390401,
|
|
67
|
+
4022224774,
|
|
68
|
+
264347078,
|
|
69
|
+
604807628,
|
|
70
|
+
770255983,
|
|
71
|
+
1249150122,
|
|
72
|
+
1555081692,
|
|
73
|
+
1996064986,
|
|
74
|
+
2554220882,
|
|
75
|
+
2821834349,
|
|
76
|
+
2952996808,
|
|
77
|
+
3210313671,
|
|
78
|
+
3336571891,
|
|
79
|
+
3584528711,
|
|
80
|
+
113926993,
|
|
81
|
+
338241895,
|
|
82
|
+
666307205,
|
|
83
|
+
773529912,
|
|
84
|
+
1294757372,
|
|
85
|
+
1396182291,
|
|
86
|
+
1695183700,
|
|
87
|
+
1986661051,
|
|
88
|
+
2177026350,
|
|
89
|
+
2456956037,
|
|
90
|
+
2730485921,
|
|
91
|
+
2820302411,
|
|
92
|
+
3259730800,
|
|
93
|
+
3345764771,
|
|
94
|
+
3516065817,
|
|
95
|
+
3600352804,
|
|
96
|
+
4094571909,
|
|
97
|
+
275423344,
|
|
98
|
+
430227734,
|
|
99
|
+
506948616,
|
|
100
|
+
659060556,
|
|
101
|
+
883997877,
|
|
102
|
+
958139571,
|
|
103
|
+
1322822218,
|
|
104
|
+
1537002063,
|
|
105
|
+
1747873779,
|
|
106
|
+
1955562222,
|
|
107
|
+
2024104815,
|
|
108
|
+
2227730452,
|
|
109
|
+
2361852424,
|
|
110
|
+
2428436474,
|
|
111
|
+
2756734187,
|
|
112
|
+
3204031479,
|
|
113
|
+
3329325298
|
|
114
|
+
];
|
|
115
|
+
const rotr = (n, x) => x >>> n | x << 32 - n;
|
|
116
|
+
const ch = (x, y, z) => x & y ^ ~x & z;
|
|
117
|
+
const maj = (x, y, z) => x & y ^ x & z ^ y & z;
|
|
118
|
+
const sigma0 = (x) => rotr(2, x) ^ rotr(13, x) ^ rotr(22, x);
|
|
119
|
+
const sigma1 = (x) => rotr(6, x) ^ rotr(11, x) ^ rotr(25, x);
|
|
120
|
+
const gamma0 = (x) => rotr(7, x) ^ rotr(18, x) ^ x >>> 3;
|
|
121
|
+
const gamma1 = (x) => rotr(17, x) ^ rotr(19, x) ^ x >>> 10;
|
|
122
|
+
const len = data.length;
|
|
123
|
+
const bitLen = len * 8;
|
|
124
|
+
const padLen = (len + 8 >> 6 << 6) + 64;
|
|
125
|
+
const padded = new Uint8Array(padLen);
|
|
126
|
+
padded.set(data);
|
|
127
|
+
padded[len] = 128;
|
|
128
|
+
const view = new DataView(padded.buffer);
|
|
129
|
+
view.setUint32(padLen - 4, bitLen, false);
|
|
130
|
+
let h0 = 1779033703, h1 = 3144134277, h2 = 1013904242, h3 = 2773480762;
|
|
131
|
+
let h4 = 1359893119, h5 = 2600822924, h6 = 528734635, h7 = 1541459225;
|
|
132
|
+
for (let offset = 0; offset < padLen; offset += 64) {
|
|
133
|
+
const w = new Array(64);
|
|
134
|
+
for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4, false);
|
|
135
|
+
for (let i = 16; i < 64; i++) w[i] = gamma1(w[i - 2]) + w[i - 7] + gamma0(w[i - 15]) + w[i - 16] | 0;
|
|
136
|
+
let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;
|
|
137
|
+
for (let i = 0; i < 64; i++) {
|
|
138
|
+
const t1 = h + sigma1(e) + ch(e, f, g) + K[i] + w[i] | 0;
|
|
139
|
+
const t2 = sigma0(a) + maj(a, b, c) | 0;
|
|
140
|
+
h = g;
|
|
141
|
+
g = f;
|
|
142
|
+
f = e;
|
|
143
|
+
e = d + t1 | 0;
|
|
144
|
+
d = c;
|
|
145
|
+
c = b;
|
|
146
|
+
b = a;
|
|
147
|
+
a = t1 + t2 | 0;
|
|
148
|
+
}
|
|
149
|
+
h0 = h0 + a | 0;
|
|
150
|
+
h1 = h1 + b | 0;
|
|
151
|
+
h2 = h2 + c | 0;
|
|
152
|
+
h3 = h3 + d | 0;
|
|
153
|
+
h4 = h4 + e | 0;
|
|
154
|
+
h5 = h5 + f | 0;
|
|
155
|
+
h6 = h6 + g | 0;
|
|
156
|
+
h7 = h7 + h | 0;
|
|
157
|
+
}
|
|
158
|
+
const result = new ArrayBuffer(32);
|
|
159
|
+
const dv = new DataView(result);
|
|
160
|
+
[h0, h1, h2, h3, h4, h5, h6, h7].forEach((v, i) => dv.setUint32(i * 4, v, false));
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
45
163
|
async function createPKCE() {
|
|
46
164
|
const codeVerifier = generateRandomString(64);
|
|
47
165
|
const encoder = new TextEncoder();
|
|
48
166
|
const data = encoder.encode(codeVerifier);
|
|
49
|
-
const digest = await
|
|
167
|
+
const digest = await sha256(data);
|
|
50
168
|
const codeChallenge = base64UrlEncode(digest);
|
|
51
169
|
return { codeVerifier, codeChallenge };
|
|
52
170
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -12,11 +12,129 @@ function base64UrlEncode(buffer) {
|
|
|
12
12
|
});
|
|
13
13
|
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
14
14
|
}
|
|
15
|
+
async function sha256(data) {
|
|
16
|
+
if (typeof crypto !== "undefined" && crypto.subtle) {
|
|
17
|
+
return crypto.subtle.digest("SHA-256", data);
|
|
18
|
+
}
|
|
19
|
+
const K = [
|
|
20
|
+
1116352408,
|
|
21
|
+
1899447441,
|
|
22
|
+
3049323471,
|
|
23
|
+
3921009573,
|
|
24
|
+
961987163,
|
|
25
|
+
1508970993,
|
|
26
|
+
2453635748,
|
|
27
|
+
2870763221,
|
|
28
|
+
3624381080,
|
|
29
|
+
310598401,
|
|
30
|
+
607225278,
|
|
31
|
+
1426881987,
|
|
32
|
+
1925078388,
|
|
33
|
+
2162078206,
|
|
34
|
+
2614888103,
|
|
35
|
+
3248222580,
|
|
36
|
+
3835390401,
|
|
37
|
+
4022224774,
|
|
38
|
+
264347078,
|
|
39
|
+
604807628,
|
|
40
|
+
770255983,
|
|
41
|
+
1249150122,
|
|
42
|
+
1555081692,
|
|
43
|
+
1996064986,
|
|
44
|
+
2554220882,
|
|
45
|
+
2821834349,
|
|
46
|
+
2952996808,
|
|
47
|
+
3210313671,
|
|
48
|
+
3336571891,
|
|
49
|
+
3584528711,
|
|
50
|
+
113926993,
|
|
51
|
+
338241895,
|
|
52
|
+
666307205,
|
|
53
|
+
773529912,
|
|
54
|
+
1294757372,
|
|
55
|
+
1396182291,
|
|
56
|
+
1695183700,
|
|
57
|
+
1986661051,
|
|
58
|
+
2177026350,
|
|
59
|
+
2456956037,
|
|
60
|
+
2730485921,
|
|
61
|
+
2820302411,
|
|
62
|
+
3259730800,
|
|
63
|
+
3345764771,
|
|
64
|
+
3516065817,
|
|
65
|
+
3600352804,
|
|
66
|
+
4094571909,
|
|
67
|
+
275423344,
|
|
68
|
+
430227734,
|
|
69
|
+
506948616,
|
|
70
|
+
659060556,
|
|
71
|
+
883997877,
|
|
72
|
+
958139571,
|
|
73
|
+
1322822218,
|
|
74
|
+
1537002063,
|
|
75
|
+
1747873779,
|
|
76
|
+
1955562222,
|
|
77
|
+
2024104815,
|
|
78
|
+
2227730452,
|
|
79
|
+
2361852424,
|
|
80
|
+
2428436474,
|
|
81
|
+
2756734187,
|
|
82
|
+
3204031479,
|
|
83
|
+
3329325298
|
|
84
|
+
];
|
|
85
|
+
const rotr = (n, x) => x >>> n | x << 32 - n;
|
|
86
|
+
const ch = (x, y, z) => x & y ^ ~x & z;
|
|
87
|
+
const maj = (x, y, z) => x & y ^ x & z ^ y & z;
|
|
88
|
+
const sigma0 = (x) => rotr(2, x) ^ rotr(13, x) ^ rotr(22, x);
|
|
89
|
+
const sigma1 = (x) => rotr(6, x) ^ rotr(11, x) ^ rotr(25, x);
|
|
90
|
+
const gamma0 = (x) => rotr(7, x) ^ rotr(18, x) ^ x >>> 3;
|
|
91
|
+
const gamma1 = (x) => rotr(17, x) ^ rotr(19, x) ^ x >>> 10;
|
|
92
|
+
const len = data.length;
|
|
93
|
+
const bitLen = len * 8;
|
|
94
|
+
const padLen = (len + 8 >> 6 << 6) + 64;
|
|
95
|
+
const padded = new Uint8Array(padLen);
|
|
96
|
+
padded.set(data);
|
|
97
|
+
padded[len] = 128;
|
|
98
|
+
const view = new DataView(padded.buffer);
|
|
99
|
+
view.setUint32(padLen - 4, bitLen, false);
|
|
100
|
+
let h0 = 1779033703, h1 = 3144134277, h2 = 1013904242, h3 = 2773480762;
|
|
101
|
+
let h4 = 1359893119, h5 = 2600822924, h6 = 528734635, h7 = 1541459225;
|
|
102
|
+
for (let offset = 0; offset < padLen; offset += 64) {
|
|
103
|
+
const w = new Array(64);
|
|
104
|
+
for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4, false);
|
|
105
|
+
for (let i = 16; i < 64; i++) w[i] = gamma1(w[i - 2]) + w[i - 7] + gamma0(w[i - 15]) + w[i - 16] | 0;
|
|
106
|
+
let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;
|
|
107
|
+
for (let i = 0; i < 64; i++) {
|
|
108
|
+
const t1 = h + sigma1(e) + ch(e, f, g) + K[i] + w[i] | 0;
|
|
109
|
+
const t2 = sigma0(a) + maj(a, b, c) | 0;
|
|
110
|
+
h = g;
|
|
111
|
+
g = f;
|
|
112
|
+
f = e;
|
|
113
|
+
e = d + t1 | 0;
|
|
114
|
+
d = c;
|
|
115
|
+
c = b;
|
|
116
|
+
b = a;
|
|
117
|
+
a = t1 + t2 | 0;
|
|
118
|
+
}
|
|
119
|
+
h0 = h0 + a | 0;
|
|
120
|
+
h1 = h1 + b | 0;
|
|
121
|
+
h2 = h2 + c | 0;
|
|
122
|
+
h3 = h3 + d | 0;
|
|
123
|
+
h4 = h4 + e | 0;
|
|
124
|
+
h5 = h5 + f | 0;
|
|
125
|
+
h6 = h6 + g | 0;
|
|
126
|
+
h7 = h7 + h | 0;
|
|
127
|
+
}
|
|
128
|
+
const result = new ArrayBuffer(32);
|
|
129
|
+
const dv = new DataView(result);
|
|
130
|
+
[h0, h1, h2, h3, h4, h5, h6, h7].forEach((v, i) => dv.setUint32(i * 4, v, false));
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
15
133
|
async function createPKCE() {
|
|
16
134
|
const codeVerifier = generateRandomString(64);
|
|
17
135
|
const encoder = new TextEncoder();
|
|
18
136
|
const data = encoder.encode(codeVerifier);
|
|
19
|
-
const digest = await
|
|
137
|
+
const digest = await sha256(data);
|
|
20
138
|
const codeChallenge = base64UrlEncode(digest);
|
|
21
139
|
return { codeVerifier, codeChallenge };
|
|
22
140
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zskj-idaas/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "IDaaS OIDC Client SDK for browser applications — supports Authorization Code Flow with PKCE, token management, and authenticated fetch.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|