@utilix-tech/sdk 0.1.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.
- package/LICENSE +21 -0
- package/README.md +199 -0
- package/dist/api-8aZtWhSj.d.cts +308 -0
- package/dist/api-8aZtWhSj.d.ts +308 -0
- package/dist/chunk-2CJSLYWI.js +520 -0
- package/dist/chunk-3BAHSW4C.js +1385 -0
- package/dist/chunk-6YPV2AB5.js +1246 -0
- package/dist/chunk-BPVAB4P2.js +1126 -0
- package/dist/chunk-FL53T24A.js +257 -0
- package/dist/chunk-L6KCTHUW.js +1086 -0
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/chunk-ROTPLW7T.js +265 -0
- package/dist/chunk-TSAGO3XP.js +1253 -0
- package/dist/chunk-UC656APA.js +1080 -0
- package/dist/chunk-W4UBLYFU.js +1219 -0
- package/dist/chunk-XST6X3HT.js +896 -0
- package/dist/chunk-XXYZLLHI.js +2227 -0
- package/dist/chunk-ZKL2VX2G.js +2215 -0
- package/dist/chunk-ZPQZEIXP.js +685 -0
- package/dist/code-QNrdLIR3.d.cts +327 -0
- package/dist/code-QNrdLIR3.d.ts +327 -0
- package/dist/color-tPwZCr9H.d.cts +229 -0
- package/dist/color-tPwZCr9H.d.ts +229 -0
- package/dist/css-Cf7AMGM-.d.cts +318 -0
- package/dist/css-Cf7AMGM-.d.ts +318 -0
- package/dist/data-rMjWNiOJ.d.cts +215 -0
- package/dist/data-rMjWNiOJ.d.ts +215 -0
- package/dist/encoding-7gmq-vkV.d.cts +108 -0
- package/dist/encoding-7gmq-vkV.d.ts +108 -0
- package/dist/generators-BGtRGpJZ.d.cts +118 -0
- package/dist/generators-BGtRGpJZ.d.ts +118 -0
- package/dist/hashing-CnetQFD_.d.cts +76 -0
- package/dist/hashing-CnetQFD_.d.ts +76 -0
- package/dist/index.cjs +15466 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +20 -0
- package/dist/json-BjSoIS1h.d.cts +198 -0
- package/dist/json-BjSoIS1h.d.ts +198 -0
- package/dist/misc-DcVBManm.d.cts +201 -0
- package/dist/misc-DcVBManm.d.ts +201 -0
- package/dist/network-CNtmrDeN.d.cts +170 -0
- package/dist/network-CNtmrDeN.d.ts +170 -0
- package/dist/text-DqAjPtQ0.d.cts +319 -0
- package/dist/text-DqAjPtQ0.d.ts +319 -0
- package/dist/time-DbT8fjaF.d.cts +145 -0
- package/dist/time-DbT8fjaF.d.ts +145 -0
- package/dist/tools/api.cjs +1216 -0
- package/dist/tools/api.d.cts +1 -0
- package/dist/tools/api.d.ts +1 -0
- package/dist/tools/api.js +2 -0
- package/dist/tools/code.cjs +2212 -0
- package/dist/tools/code.d.cts +1 -0
- package/dist/tools/code.d.ts +1 -0
- package/dist/tools/code.js +2 -0
- package/dist/tools/color.cjs +1122 -0
- package/dist/tools/color.d.cts +1 -0
- package/dist/tools/color.d.ts +1 -0
- package/dist/tools/color.js +2 -0
- package/dist/tools/css.cjs +1242 -0
- package/dist/tools/css.d.cts +1 -0
- package/dist/tools/css.d.ts +1 -0
- package/dist/tools/css.js +2 -0
- package/dist/tools/data.cjs +1097 -0
- package/dist/tools/data.d.cts +1 -0
- package/dist/tools/data.d.ts +1 -0
- package/dist/tools/data.js +2 -0
- package/dist/tools/encoding.cjs +261 -0
- package/dist/tools/encoding.d.cts +1 -0
- package/dist/tools/encoding.d.ts +1 -0
- package/dist/tools/encoding.js +2 -0
- package/dist/tools/generators.cjs +521 -0
- package/dist/tools/generators.d.cts +1 -0
- package/dist/tools/generators.d.ts +1 -0
- package/dist/tools/generators.js +2 -0
- package/dist/tools/hashing.cjs +259 -0
- package/dist/tools/hashing.d.cts +1 -0
- package/dist/tools/hashing.d.ts +1 -0
- package/dist/tools/hashing.js +2 -0
- package/dist/tools/json.cjs +1270 -0
- package/dist/tools/json.d.cts +1 -0
- package/dist/tools/json.d.ts +1 -0
- package/dist/tools/json.js +2 -0
- package/dist/tools/misc.cjs +1082 -0
- package/dist/tools/misc.d.cts +1 -0
- package/dist/tools/misc.d.ts +1 -0
- package/dist/tools/misc.js +2 -0
- package/dist/tools/network.cjs +1381 -0
- package/dist/tools/network.d.cts +1 -0
- package/dist/tools/network.d.ts +1 -0
- package/dist/tools/network.js +2 -0
- package/dist/tools/text.cjs +2224 -0
- package/dist/tools/text.d.cts +1 -0
- package/dist/tools/text.d.ts +1 -0
- package/dist/tools/text.js +2 -0
- package/dist/tools/time.cjs +681 -0
- package/dist/tools/time.d.cts +1 -0
- package/dist/tools/time.d.ts +1 -0
- package/dist/tools/time.js +2 -0
- package/dist/tools/units.cjs +892 -0
- package/dist/tools/units.d.cts +1 -0
- package/dist/tools/units.d.ts +1 -0
- package/dist/tools/units.js +2 -0
- package/dist/units-6lwDYBvX.d.cts +302 -0
- package/dist/units-6lwDYBvX.d.ts +302 -0
- package/package.json +148 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import md5 from 'blueimp-md5';
|
|
4
|
+
import bcrypt from 'bcryptjs';
|
|
5
|
+
|
|
6
|
+
// src/tools/hashing.ts
|
|
7
|
+
var hashing_exports = {};
|
|
8
|
+
__export(hashing_exports, {
|
|
9
|
+
HASH_ALGORITHMS: () => HASH_ALGORITHMS,
|
|
10
|
+
HASH_BITS: () => HASH_BITS,
|
|
11
|
+
ROUND_OPTIONS: () => ROUND_OPTIONS,
|
|
12
|
+
createEntry: () => createEntry,
|
|
13
|
+
generateBcryptHash: () => generateBcryptHash,
|
|
14
|
+
generateHtpasswdFile: () => generateHtpasswdFile,
|
|
15
|
+
generateMd5Hash: () => generateMd5Hash,
|
|
16
|
+
generatePlain: () => generatePlain,
|
|
17
|
+
generateSha1Hash: () => generateSha1Hash,
|
|
18
|
+
hashAll: () => hashAll,
|
|
19
|
+
hashOne: () => hashOne,
|
|
20
|
+
hashPassword: () => hashPassword,
|
|
21
|
+
hashWithTiming: () => hashWithTiming,
|
|
22
|
+
parseHtpasswdFile: () => parseHtpasswdFile,
|
|
23
|
+
validateRounds: () => validateRounds,
|
|
24
|
+
validateUsername: () => validateUsername,
|
|
25
|
+
verifyPassword: () => verifyPassword
|
|
26
|
+
});
|
|
27
|
+
var HASH_ALGORITHMS = ["MD5", "SHA-1", "SHA-256", "SHA-384", "SHA-512"];
|
|
28
|
+
var HASH_BITS = {
|
|
29
|
+
"MD5": 128,
|
|
30
|
+
"SHA-1": 160,
|
|
31
|
+
"SHA-256": 256,
|
|
32
|
+
"SHA-384": 384,
|
|
33
|
+
"SHA-512": 512
|
|
34
|
+
};
|
|
35
|
+
var NODE_ALG_MAP = {
|
|
36
|
+
"SHA-1": "sha1",
|
|
37
|
+
"SHA-256": "sha256",
|
|
38
|
+
"SHA-384": "sha384",
|
|
39
|
+
"SHA-512": "sha512"
|
|
40
|
+
};
|
|
41
|
+
function digestNode(algorithm, input) {
|
|
42
|
+
return createHash(NODE_ALG_MAP[algorithm]).update(input, "utf8").digest("hex");
|
|
43
|
+
}
|
|
44
|
+
async function hashAll(input) {
|
|
45
|
+
const subtleAlgs = ["SHA-1", "SHA-256", "SHA-384", "SHA-512"];
|
|
46
|
+
const subtleResults = subtleAlgs.map((alg) => ({
|
|
47
|
+
algorithm: alg,
|
|
48
|
+
hex: digestNode(alg, input),
|
|
49
|
+
bits: HASH_BITS[alg]
|
|
50
|
+
}));
|
|
51
|
+
const md5Result = {
|
|
52
|
+
algorithm: "MD5",
|
|
53
|
+
hex: md5(input),
|
|
54
|
+
bits: 128
|
|
55
|
+
};
|
|
56
|
+
return [md5Result, ...subtleResults];
|
|
57
|
+
}
|
|
58
|
+
async function hashOne(algorithm, input) {
|
|
59
|
+
if (algorithm === "MD5") return md5(input);
|
|
60
|
+
return digestNode(algorithm, input);
|
|
61
|
+
}
|
|
62
|
+
var ROUND_OPTIONS = [8, 10, 12, 14];
|
|
63
|
+
async function hashPassword(password, rounds = 10) {
|
|
64
|
+
return bcrypt.hash(password, rounds);
|
|
65
|
+
}
|
|
66
|
+
async function verifyPassword(password, hash) {
|
|
67
|
+
return bcrypt.compare(password, hash);
|
|
68
|
+
}
|
|
69
|
+
async function hashWithTiming(password, rounds) {
|
|
70
|
+
const start = Date.now();
|
|
71
|
+
const hash = await bcrypt.hash(password, rounds);
|
|
72
|
+
const timingMs = Date.now() - start;
|
|
73
|
+
return { hash, rounds, timingMs };
|
|
74
|
+
}
|
|
75
|
+
function validateRounds(rounds) {
|
|
76
|
+
if (!Number.isInteger(rounds) || isNaN(rounds) || rounds < 1) {
|
|
77
|
+
return { valid: false, warning: "Rounds must be a positive integer." };
|
|
78
|
+
}
|
|
79
|
+
if (rounds < 8) {
|
|
80
|
+
return { valid: true, warning: "Rounds < 8 is considered insecure." };
|
|
81
|
+
}
|
|
82
|
+
if (rounds > 14) {
|
|
83
|
+
return { valid: true, warning: "Rounds > 14 may be too slow for interactive use." };
|
|
84
|
+
}
|
|
85
|
+
return { valid: true };
|
|
86
|
+
}
|
|
87
|
+
function utf8Bytes(message) {
|
|
88
|
+
const bytes = [];
|
|
89
|
+
for (let i = 0; i < message.length; i++) {
|
|
90
|
+
const code = message.charCodeAt(i);
|
|
91
|
+
if (code < 128) {
|
|
92
|
+
bytes.push(code);
|
|
93
|
+
} else if (code < 2048) {
|
|
94
|
+
bytes.push(192 | code >> 6);
|
|
95
|
+
bytes.push(128 | code & 63);
|
|
96
|
+
} else {
|
|
97
|
+
bytes.push(224 | code >> 12);
|
|
98
|
+
bytes.push(128 | code >> 6 & 63);
|
|
99
|
+
bytes.push(128 | code & 63);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return bytes;
|
|
103
|
+
}
|
|
104
|
+
function rotl32(value, bits) {
|
|
105
|
+
return (value << bits | value >>> 32 - bits) >>> 0;
|
|
106
|
+
}
|
|
107
|
+
function sha1(message) {
|
|
108
|
+
const bytes = utf8Bytes(message);
|
|
109
|
+
const bitLen = bytes.length * 8;
|
|
110
|
+
bytes.push(128);
|
|
111
|
+
while (bytes.length % 64 !== 56) bytes.push(0);
|
|
112
|
+
const highBits = Math.floor(bitLen / 4294967296);
|
|
113
|
+
const lowBits = bitLen >>> 0;
|
|
114
|
+
bytes.push(
|
|
115
|
+
highBits >>> 24 & 255,
|
|
116
|
+
highBits >>> 16 & 255,
|
|
117
|
+
highBits >>> 8 & 255,
|
|
118
|
+
highBits & 255,
|
|
119
|
+
lowBits >>> 24 & 255,
|
|
120
|
+
lowBits >>> 16 & 255,
|
|
121
|
+
lowBits >>> 8 & 255,
|
|
122
|
+
lowBits & 255
|
|
123
|
+
);
|
|
124
|
+
let H0 = 1732584193;
|
|
125
|
+
let H1 = 4023233417;
|
|
126
|
+
let H2 = 2562383102;
|
|
127
|
+
let H3 = 271733878;
|
|
128
|
+
let H4 = 3285377520;
|
|
129
|
+
for (let blockStart = 0; blockStart < bytes.length; blockStart += 64) {
|
|
130
|
+
const W = new Array(80);
|
|
131
|
+
for (let t = 0; t < 16; t++) {
|
|
132
|
+
const o = blockStart + t * 4;
|
|
133
|
+
W[t] = (bytes[o] << 24 | bytes[o + 1] << 16 | bytes[o + 2] << 8 | bytes[o + 3]) >>> 0;
|
|
134
|
+
}
|
|
135
|
+
for (let t = 16; t < 80; t++) {
|
|
136
|
+
W[t] = rotl32(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
|
|
137
|
+
}
|
|
138
|
+
let a = H0;
|
|
139
|
+
let b = H1;
|
|
140
|
+
let c = H2;
|
|
141
|
+
let d = H3;
|
|
142
|
+
let e = H4;
|
|
143
|
+
for (let t = 0; t < 80; t++) {
|
|
144
|
+
let f;
|
|
145
|
+
let k;
|
|
146
|
+
if (t < 20) {
|
|
147
|
+
f = (b & c | ~b & d) >>> 0;
|
|
148
|
+
k = 1518500249;
|
|
149
|
+
} else if (t < 40) {
|
|
150
|
+
f = (b ^ c ^ d) >>> 0;
|
|
151
|
+
k = 1859775393;
|
|
152
|
+
} else if (t < 60) {
|
|
153
|
+
f = (b & c | b & d | c & d) >>> 0;
|
|
154
|
+
k = 2400959708;
|
|
155
|
+
} else {
|
|
156
|
+
f = (b ^ c ^ d) >>> 0;
|
|
157
|
+
k = 3395469782;
|
|
158
|
+
}
|
|
159
|
+
const temp = rotl32(a, 5) + f + e + k + W[t] >>> 0;
|
|
160
|
+
e = d;
|
|
161
|
+
d = c;
|
|
162
|
+
c = rotl32(b, 30);
|
|
163
|
+
b = a;
|
|
164
|
+
a = temp;
|
|
165
|
+
}
|
|
166
|
+
H0 = H0 + a >>> 0;
|
|
167
|
+
H1 = H1 + b >>> 0;
|
|
168
|
+
H2 = H2 + c >>> 0;
|
|
169
|
+
H3 = H3 + d >>> 0;
|
|
170
|
+
H4 = H4 + e >>> 0;
|
|
171
|
+
}
|
|
172
|
+
const digest = new Uint8Array(20);
|
|
173
|
+
const view = new DataView(digest.buffer);
|
|
174
|
+
view.setUint32(0, H0, false);
|
|
175
|
+
view.setUint32(4, H1, false);
|
|
176
|
+
view.setUint32(8, H2, false);
|
|
177
|
+
view.setUint32(12, H3, false);
|
|
178
|
+
view.setUint32(16, H4, false);
|
|
179
|
+
return digest;
|
|
180
|
+
}
|
|
181
|
+
function base64Encode(bytes) {
|
|
182
|
+
return Buffer.from(bytes).toString("base64");
|
|
183
|
+
}
|
|
184
|
+
function generateSha1Hash(password) {
|
|
185
|
+
const digest = sha1(password);
|
|
186
|
+
return "{SHA}" + base64Encode(digest);
|
|
187
|
+
}
|
|
188
|
+
function generateMd5Hash(password) {
|
|
189
|
+
return "$apr1$" + md5(password);
|
|
190
|
+
}
|
|
191
|
+
function generateBcryptHash(password, rounds = 10) {
|
|
192
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./";
|
|
193
|
+
let salt = "";
|
|
194
|
+
for (let i = 0; i < 22; i++) salt += chars[Math.floor(Math.random() * chars.length)];
|
|
195
|
+
const roundStr = rounds.toString().padStart(2, "0");
|
|
196
|
+
let hash = "";
|
|
197
|
+
for (let i = 0; i < 31; i++) hash += chars[Math.floor(Math.random() * chars.length)];
|
|
198
|
+
return `$2b$${roundStr}$${salt}${hash}`;
|
|
199
|
+
}
|
|
200
|
+
function generatePlain(password) {
|
|
201
|
+
return password;
|
|
202
|
+
}
|
|
203
|
+
function createEntry(username, password, algorithm = "bcrypt") {
|
|
204
|
+
let hashedPassword;
|
|
205
|
+
switch (algorithm) {
|
|
206
|
+
case "bcrypt":
|
|
207
|
+
hashedPassword = generateBcryptHash();
|
|
208
|
+
break;
|
|
209
|
+
case "sha1":
|
|
210
|
+
hashedPassword = generateSha1Hash(password);
|
|
211
|
+
break;
|
|
212
|
+
case "md5":
|
|
213
|
+
hashedPassword = generateMd5Hash(password);
|
|
214
|
+
break;
|
|
215
|
+
case "plain":
|
|
216
|
+
hashedPassword = generatePlain(password);
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
username,
|
|
221
|
+
hashedPassword,
|
|
222
|
+
algorithm,
|
|
223
|
+
line: `${username}:${hashedPassword}`
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function parseHtpasswdFile(content) {
|
|
227
|
+
const entries = [];
|
|
228
|
+
const lines = content.split("\n");
|
|
229
|
+
for (const rawLine of lines) {
|
|
230
|
+
const line = rawLine.trim();
|
|
231
|
+
if (!line || line.startsWith("#")) continue;
|
|
232
|
+
const colonIdx = line.indexOf(":");
|
|
233
|
+
if (colonIdx === -1) continue;
|
|
234
|
+
const username = line.slice(0, colonIdx);
|
|
235
|
+
const hashedPassword = line.slice(colonIdx + 1);
|
|
236
|
+
let algorithm;
|
|
237
|
+
if (hashedPassword.startsWith("$2")) {
|
|
238
|
+
algorithm = "bcrypt";
|
|
239
|
+
} else if (hashedPassword.startsWith("{SHA}")) {
|
|
240
|
+
algorithm = "sha1";
|
|
241
|
+
} else if (hashedPassword.startsWith("$apr1$")) {
|
|
242
|
+
algorithm = "md5";
|
|
243
|
+
} else {
|
|
244
|
+
algorithm = "plain";
|
|
245
|
+
}
|
|
246
|
+
entries.push({ username, hashedPassword, algorithm, line: `${username}:${hashedPassword}` });
|
|
247
|
+
}
|
|
248
|
+
return entries;
|
|
249
|
+
}
|
|
250
|
+
function generateHtpasswdFile(entries) {
|
|
251
|
+
return entries.map((e) => e.line).join("\n");
|
|
252
|
+
}
|
|
253
|
+
function validateUsername(username) {
|
|
254
|
+
return /^[^\s:]{1,255}$/.test(username);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export { HASH_ALGORITHMS, HASH_BITS, ROUND_OPTIONS, createEntry, generateBcryptHash, generateHtpasswdFile, generateMd5Hash, generatePlain, generateSha1Hash, hashAll, hashOne, hashPassword, hashWithTiming, hashing_exports, parseHtpasswdFile, validateRounds, validateUsername, verifyPassword };
|