inibase 1.2.11 → 1.2.13
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/utils.server.d.ts +2 -1
- package/dist/utils.server.js +9 -5
- package/package.json +1 -1
package/dist/utils.server.d.ts
CHANGED
|
@@ -23,7 +23,8 @@ export declare const hashPassword: (password: string) => string;
|
|
|
23
23
|
*/
|
|
24
24
|
export declare const comparePassword: (hash: string, password: string) => boolean;
|
|
25
25
|
export declare const encodeID: (id: number | string) => string;
|
|
26
|
-
export declare
|
|
26
|
+
export declare function decodeID(input: string, raw: true): string;
|
|
27
|
+
export declare function decodeID(input?: string, raw?: false): number;
|
|
27
28
|
export declare const extractIdsFromSchema: (schema: Schema) => number[];
|
|
28
29
|
/**
|
|
29
30
|
* Finds the last ID number in a schema, potentially decoding it if encrypted.
|
package/dist/utils.server.js
CHANGED
|
@@ -54,18 +54,22 @@ const getKeyAndIv = () => {
|
|
|
54
54
|
}
|
|
55
55
|
return { key, iv: key.subarray(0, 16) };
|
|
56
56
|
};
|
|
57
|
-
// Optimized encodeID
|
|
58
57
|
export const encodeID = (id) => {
|
|
59
58
|
const { key, iv } = getKeyAndIv();
|
|
60
59
|
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
61
60
|
return cipher.update(id.toString(), "utf8", "hex") + cipher.final("hex");
|
|
62
61
|
};
|
|
63
|
-
|
|
64
|
-
export const decodeID = (input) => {
|
|
62
|
+
export function decodeID(input, raw) {
|
|
65
63
|
const { key, iv } = getKeyAndIv();
|
|
66
64
|
const decipher = createDecipheriv("aes-256-cbc", key, iv);
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
try {
|
|
66
|
+
const rawData = decipher.update(input, "hex", "utf8") + decipher.final("utf8");
|
|
67
|
+
return raw ? rawData : Number(rawData);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
69
73
|
// Function to recursively flatten an array of objects and their nested children
|
|
70
74
|
export const extractIdsFromSchema = (schema) => {
|
|
71
75
|
const result = [];
|