universe-code 0.0.89 → 0.0.91
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,148 @@
|
|
|
1
|
+
class EncryptionService {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.PASS =
|
|
4
|
+
"9f2d3b7c4a6e8f0b-1c2d3e4f5a6b7c8d-9e0f1a2b3c4d5e6f7-a8b9c0d1e2f3a4";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// --- Encoding helpers ---
|
|
8
|
+
enc(str) {
|
|
9
|
+
return new TextEncoder().encode(str);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
dec(buf) {
|
|
13
|
+
return new TextDecoder().decode(buf);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// --- Base64 helpers (React + Angular safe) ---
|
|
17
|
+
b64(a) {
|
|
18
|
+
const bytes = new Uint8Array(a);
|
|
19
|
+
let binary = "";
|
|
20
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
21
|
+
binary += String.fromCharCode(bytes[i]);
|
|
22
|
+
}
|
|
23
|
+
return btoa(binary);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
ub64(s) {
|
|
27
|
+
const binaryStr = atob(s);
|
|
28
|
+
const bytes = new Uint8Array(binaryStr.length);
|
|
29
|
+
for (let i = 0; i < binaryStr.length; i++) {
|
|
30
|
+
bytes[i] = binaryStr.charCodeAt(i);
|
|
31
|
+
}
|
|
32
|
+
return bytes;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// --- Key methods ---
|
|
36
|
+
async getKey() {
|
|
37
|
+
const km = await crypto.subtle.importKey(
|
|
38
|
+
"raw",
|
|
39
|
+
this.enc(this.PASS),
|
|
40
|
+
"PBKDF2",
|
|
41
|
+
false,
|
|
42
|
+
["deriveKey"]
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return crypto.subtle.deriveKey(
|
|
46
|
+
{
|
|
47
|
+
name: "PBKDF2",
|
|
48
|
+
salt: this.enc("fixed-salt"),
|
|
49
|
+
iterations: 100000,
|
|
50
|
+
hash: "SHA-256"
|
|
51
|
+
},
|
|
52
|
+
km,
|
|
53
|
+
{ name: "AES-GCM", length: 256 },
|
|
54
|
+
false,
|
|
55
|
+
["encrypt", "decrypt"]
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async key1() {
|
|
60
|
+
const km = await crypto.subtle.importKey(
|
|
61
|
+
"raw",
|
|
62
|
+
this.enc(this.PASS),
|
|
63
|
+
"PBKDF2",
|
|
64
|
+
false,
|
|
65
|
+
["deriveKey"]
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return crypto.subtle.deriveKey(
|
|
69
|
+
{
|
|
70
|
+
name: "PBKDF2",
|
|
71
|
+
salt: this.enc("x"),
|
|
72
|
+
iterations: 50000,
|
|
73
|
+
hash: "SHA-256"
|
|
74
|
+
},
|
|
75
|
+
km,
|
|
76
|
+
{ name: "AES-GCM", length: 256 },
|
|
77
|
+
false,
|
|
78
|
+
["encrypt", "decrypt"]
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// --- Encryption ---
|
|
83
|
+
async encryption(obj) {
|
|
84
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
85
|
+
const key = await this.getKey();
|
|
86
|
+
|
|
87
|
+
const ct = await crypto.subtle.encrypt(
|
|
88
|
+
{ name: "AES-GCM", iv },
|
|
89
|
+
key,
|
|
90
|
+
this.enc(JSON.stringify(obj))
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
iv: this.b64(iv),
|
|
95
|
+
payload: this.b64(ct)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async encryption1(obj) {
|
|
100
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
101
|
+
const key = await this.key1();
|
|
102
|
+
|
|
103
|
+
const ct = await crypto.subtle.encrypt(
|
|
104
|
+
{ name: "AES-GCM", iv },
|
|
105
|
+
key,
|
|
106
|
+
this.enc(JSON.stringify(obj))
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
iv: this.b64(iv),
|
|
111
|
+
payload: this.b64(ct)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// --- Decryption ---
|
|
116
|
+
async decryption(data) {
|
|
117
|
+
const key = await this.getKey();
|
|
118
|
+
|
|
119
|
+
const pt = await crypto.subtle.decrypt(
|
|
120
|
+
{ name: "AES-GCM", iv: this.ub64(data.iv) },
|
|
121
|
+
key,
|
|
122
|
+
this.ub64(data.payload)
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
return JSON.parse(this.dec(pt));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async decryption1(o) {
|
|
129
|
+
const key = await this.key1();
|
|
130
|
+
|
|
131
|
+
const pt = await crypto.subtle.decrypt(
|
|
132
|
+
{ name: "AES-GCM", iv: this.ub64(o.iv) },
|
|
133
|
+
key,
|
|
134
|
+
this.ub64(o.payload)
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
return JSON.parse(this.dec(pt));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async decrptApiResponse(data) {
|
|
141
|
+
if (!data.includes("###")) return null;
|
|
142
|
+
const [iv, payload] = data.split("###");
|
|
143
|
+
return this.decryption1({ iv, payload });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Export / usage
|
|
148
|
+
export const encryptionService = new EncryptionService();
|
package/dist/angular/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { IdbService } from './indexdb/services/idbService.js';
|
|
2
|
-
export { ColorSparkService, initSpark, singleSpark } from './spark/index.js';
|
|
2
|
+
export { ColorSparkService, initSpark, singleSpark } from './spark/index.js';
|
|
3
|
+
export { encryptionService } from './encryption/index.js';
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/* ========= UNIVERSAL CRYPTO SERVICE ========= */
|
|
2
|
+
/* Works in Angular, React, Next.js (SSR safe), Browser */
|
|
3
|
+
|
|
4
|
+
const SECRET_PASS =
|
|
5
|
+
"9f2d3b7c4a6e8f0b-1c2d3e4f5a6b7c8d-9e0f1a2b3c4d5e6f7-a8b9c0d1e2f3a4";
|
|
6
|
+
|
|
7
|
+
const PASS = SECRET_PASS;
|
|
8
|
+
|
|
9
|
+
/* ---------- Helpers ---------- */
|
|
10
|
+
|
|
11
|
+
const enc = (str) => new TextEncoder().encode(str);
|
|
12
|
+
const dec = (buf) => new TextDecoder().decode(buf);
|
|
13
|
+
|
|
14
|
+
const hasBuffer = typeof Buffer !== "undefined";
|
|
15
|
+
|
|
16
|
+
/* Base64 encode (Node + Browser safe) */
|
|
17
|
+
const b64 = (data) => {
|
|
18
|
+
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
19
|
+
|
|
20
|
+
if (hasBuffer) {
|
|
21
|
+
return Buffer.from(bytes).toString("base64");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let binary = "";
|
|
25
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
26
|
+
binary += String.fromCharCode(bytes[i]);
|
|
27
|
+
}
|
|
28
|
+
return btoa(binary);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/* Base64 decode (Node + Browser safe) */
|
|
32
|
+
const ub64 = (base64) => {
|
|
33
|
+
if (hasBuffer) {
|
|
34
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const binary = atob(base64);
|
|
38
|
+
const bytes = new Uint8Array(binary.length);
|
|
39
|
+
for (let i = 0; i < binary.length; i++) {
|
|
40
|
+
bytes[i] = binary.charCodeAt(i);
|
|
41
|
+
}
|
|
42
|
+
return bytes;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/* WebCrypto subtle (Browser + Node/Next) */
|
|
46
|
+
const subtle = () => {
|
|
47
|
+
if (typeof window !== "undefined" && window.crypto?.subtle) {
|
|
48
|
+
return window.crypto.subtle;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (globalThis.crypto?.subtle) {
|
|
52
|
+
return globalThis.crypto.subtle;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new Error("WebCrypto API not supported in this environment");
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/* Random values (Browser + Node) */
|
|
59
|
+
const randomIV = () => {
|
|
60
|
+
if (typeof window !== "undefined" && window.crypto) {
|
|
61
|
+
return window.crypto.getRandomValues(new Uint8Array(12));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return globalThis.crypto.getRandomValues(new Uint8Array(12));
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/* ---------- Key Derivation ---------- */
|
|
68
|
+
|
|
69
|
+
async function getKey() {
|
|
70
|
+
const keyMaterial = await subtle().importKey(
|
|
71
|
+
"raw",
|
|
72
|
+
enc(SECRET_PASS),
|
|
73
|
+
"PBKDF2",
|
|
74
|
+
false,
|
|
75
|
+
["deriveKey"]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
return subtle().deriveKey(
|
|
79
|
+
{
|
|
80
|
+
name: "PBKDF2",
|
|
81
|
+
salt: enc("fixed-salt"),
|
|
82
|
+
iterations: 100000,
|
|
83
|
+
hash: "SHA-256",
|
|
84
|
+
},
|
|
85
|
+
keyMaterial,
|
|
86
|
+
{ name: "AES-GCM", length: 256 },
|
|
87
|
+
false,
|
|
88
|
+
["encrypt", "decrypt"]
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function key1() {
|
|
93
|
+
const keyMaterial = await subtle().importKey(
|
|
94
|
+
"raw",
|
|
95
|
+
enc(PASS),
|
|
96
|
+
"PBKDF2",
|
|
97
|
+
false,
|
|
98
|
+
["deriveKey"]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return subtle().deriveKey(
|
|
102
|
+
{
|
|
103
|
+
name: "PBKDF2",
|
|
104
|
+
salt: enc("x"),
|
|
105
|
+
iterations: 50000,
|
|
106
|
+
hash: "SHA-256",
|
|
107
|
+
},
|
|
108
|
+
keyMaterial,
|
|
109
|
+
{ name: "AES-GCM", length: 256 },
|
|
110
|
+
false,
|
|
111
|
+
["encrypt", "decrypt"]
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* ---------- Crypto Service ---------- */
|
|
116
|
+
|
|
117
|
+
export const encryptionService = {
|
|
118
|
+
/* Encrypt using main key */
|
|
119
|
+
async encryption(obj) {
|
|
120
|
+
const iv = randomIV();
|
|
121
|
+
const key = await getKey();
|
|
122
|
+
|
|
123
|
+
const encrypted = await subtle().encrypt(
|
|
124
|
+
{ name: "AES-GCM", iv },
|
|
125
|
+
key,
|
|
126
|
+
enc(JSON.stringify(obj))
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
iv: b64(iv),
|
|
131
|
+
payload: b64(encrypted),
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
/* Decrypt using main key */
|
|
136
|
+
async decryption(data) {
|
|
137
|
+
const key = await getKey();
|
|
138
|
+
|
|
139
|
+
const decrypted = await subtle().decrypt(
|
|
140
|
+
{ name: "AES-GCM", iv: ub64(data.iv) },
|
|
141
|
+
key,
|
|
142
|
+
ub64(data.payload)
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
return JSON.parse(dec(decrypted));
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
/* Encrypt using secondary key */
|
|
149
|
+
async encryption1(obj) {
|
|
150
|
+
const iv = randomIV();
|
|
151
|
+
const key = await key1();
|
|
152
|
+
|
|
153
|
+
const encrypted = await subtle().encrypt(
|
|
154
|
+
{ name: "AES-GCM", iv },
|
|
155
|
+
key,
|
|
156
|
+
enc(JSON.stringify(obj))
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
iv: b64(iv),
|
|
161
|
+
payload: b64(encrypted),
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
/* Decrypt using secondary key */
|
|
166
|
+
async decryption1(data) {
|
|
167
|
+
const key = await key1();
|
|
168
|
+
|
|
169
|
+
const decrypted = await subtle().decrypt(
|
|
170
|
+
{ name: "AES-GCM", iv: ub64(data.iv) },
|
|
171
|
+
key,
|
|
172
|
+
ub64(data.payload)
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
return JSON.parse(dec(decrypted));
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/* API helper */
|
|
179
|
+
async decryptApiResponse(data) {
|
|
180
|
+
if (!data || !data.includes("###")) return null;
|
|
181
|
+
const [iv, payload] = data.split("###");
|
|
182
|
+
return this.decryption1({ iv, payload });
|
|
183
|
+
},
|
|
184
|
+
};
|
package/dist/react/index.js
CHANGED
|
@@ -2,14 +2,16 @@ import { getIdbStore } from './indexdb/store/idbStore.js';
|
|
|
2
2
|
import { useIdbStore } from './indexdb/hooks/idbHook.js';
|
|
3
3
|
import { configureIdb } from "./indexdb/store/config.js";
|
|
4
4
|
import { useColorSpark } from "./spark/index.js";
|
|
5
|
+
import { encryptionService } from "./encryption/index.js";
|
|
5
6
|
|
|
6
7
|
// Export everything as a unified object or individual pieces
|
|
7
|
-
export { configureIdb, getIdbStore, useIdbStore, useColorSpark };
|
|
8
|
+
export { configureIdb, getIdbStore, useIdbStore, useColorSpark, encryptionService };
|
|
8
9
|
|
|
9
10
|
// Default export for easy usage
|
|
10
11
|
export default {
|
|
11
12
|
configureIdb,
|
|
12
13
|
getIdbStore,
|
|
13
14
|
useIdbStore,
|
|
14
|
-
useColorSpark
|
|
15
|
+
useColorSpark,
|
|
16
|
+
encryptionService
|
|
15
17
|
};
|
package/dist/uiux/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { UniverseToaster, toaster } from "./toaster";
|
|
2
|
-
export { UniverseDataTable } from "./
|
|
2
|
+
export { UniverseDataTable } from "./table";
|
|
@@ -56,7 +56,7 @@ style.textContent = `
|
|
|
56
56
|
display: flex;
|
|
57
57
|
align-items: center;
|
|
58
58
|
gap: 0.3rem;
|
|
59
|
-
font-size:
|
|
59
|
+
font-size: 12px;
|
|
60
60
|
color: #757272;
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -95,7 +95,7 @@ style.textContent = `
|
|
|
95
95
|
white-space: nowrap;
|
|
96
96
|
text-align: left;
|
|
97
97
|
color: #4b5563;
|
|
98
|
-
font-size: var(--entriesTextFontSize,
|
|
98
|
+
font-size: var(--entriesTextFontSize, 12px);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/* Pagination buttons */
|
|
@@ -331,13 +331,17 @@ class UniverseDataTable {
|
|
|
331
331
|
|
|
332
332
|
if (this.shouldShowPagination) {
|
|
333
333
|
const jumpInputs = this.container.querySelectorAll("input.jumpto");
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
334
|
+
jumpInputs.forEach((input) => {
|
|
335
|
+
input.addEventListener("input", (e) => {
|
|
336
|
+
this.jumpToPage = e.target.value;
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
input.addEventListener("keypress", (e) => this.handleKeyPress(e));
|
|
340
|
+
});
|
|
337
341
|
|
|
338
342
|
const goButtons = this.container.querySelectorAll(".go-btn");
|
|
339
343
|
goButtons.forEach((btn) => {
|
|
340
|
-
if (!btn.disabled) btn.addEventListener("click", () => this.handleJumpToPage());
|
|
344
|
+
if (!btn.disabled) btn.addEventListener("click", () => this.handleJumpToPage(this.jumpToPage));
|
|
341
345
|
});
|
|
342
346
|
|
|
343
347
|
const pgButtons = this.container.querySelectorAll(".pg-btn");
|