@ibgib/web-gib 0.0.60 → 0.0.62
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/AUTO-GENERATED-version.d.mts +1 -1
- package/dist/AUTO-GENERATED-version.mjs +1 -1
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +1 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/helpers.web.d.mts +3 -1
- package/dist/helpers.web.d.mts.map +1 -1
- package/dist/helpers.web.mjs +17 -1
- package/dist/helpers.web.mjs.map +1 -1
- package/dist/identity/device-delegate-helper.d.mts +91 -0
- package/dist/identity/device-delegate-helper.d.mts.map +1 -0
- package/dist/identity/device-delegate-helper.mjs +190 -0
- package/dist/identity/device-delegate-helper.mjs.map +1 -0
- package/dist/identity/device-delegate.respec.d.mts +2 -0
- package/dist/identity/device-delegate.respec.d.mts.map +1 -0
- package/dist/identity/device-delegate.respec.mjs +106 -0
- package/dist/identity/device-delegate.respec.mjs.map +1 -0
- package/dist/identity/keystone-sync-service.d.mts +18 -0
- package/dist/identity/keystone-sync-service.d.mts.map +1 -1
- package/dist/identity/keystone-sync-service.mjs +77 -1
- package/dist/identity/keystone-sync-service.mjs.map +1 -1
- package/dist/identity/passkey-helper.d.mts +72 -0
- package/dist/identity/passkey-helper.d.mts.map +1 -0
- package/dist/identity/passkey-helper.mjs +237 -0
- package/dist/identity/passkey-helper.mjs.map +1 -0
- package/dist/identity/passkey.respec.d.mts +2 -0
- package/dist/identity/passkey.respec.d.mts.map +1 -0
- package/dist/identity/passkey.respec.mjs +169 -0
- package/dist/identity/passkey.respec.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/storage/storage-helpers.web.d.mts +9 -0
- package/dist/storage/storage-helpers.web.d.mts.map +1 -1
- package/dist/storage/storage-helpers.web.mjs +42 -0
- package/dist/storage/storage-helpers.web.mjs.map +1 -1
- package/dist/ui/component/identity/add-device/add-device.d.mts.map +1 -1
- package/dist/ui/component/identity/add-device/add-device.mjs +31 -43
- package/dist/ui/component/identity/add-device/add-device.mjs.map +1 -1
- package/dist/ui/component/identity/keystone-creator/keystone-creator.d.mts +18 -1
- package/dist/ui/component/identity/keystone-creator/keystone-creator.d.mts.map +1 -1
- package/dist/ui/component/identity/keystone-creator/keystone-creator.html +42 -3
- package/dist/ui/component/identity/keystone-creator/keystone-creator.mjs +524 -104
- package/dist/ui/component/identity/keystone-creator/keystone-creator.mjs.map +1 -1
- package/dist/ui/component/identity/keystone-details/keystone-details.d.mts +19 -1
- package/dist/ui/component/identity/keystone-details/keystone-details.d.mts.map +1 -1
- package/dist/ui/component/identity/keystone-details/keystone-details.html +38 -0
- package/dist/ui/component/identity/keystone-details/keystone-details.mjs +1217 -132
- package/dist/ui/component/identity/keystone-details/keystone-details.mjs.map +1 -1
- package/dist/ui/component/identity/remove-device/remove-device.d.mts.map +1 -1
- package/dist/ui/component/identity/remove-device/remove-device.mjs +1 -0
- package/dist/ui/component/identity/remove-device/remove-device.mjs.map +1 -1
- package/dist/ui/ui-constants.d.mts +1 -0
- package/dist/ui/ui-constants.d.mts.map +1 -1
- package/dist/ui/ui-constants.mjs +1 -0
- package/dist/ui/ui-constants.mjs.map +1 -1
- package/dist/ui/ui-helpers.d.mts +3 -0
- package/dist/ui/ui-helpers.d.mts.map +1 -1
- package/dist/ui/ui-helpers.mjs +110 -6
- package/dist/ui/ui-helpers.mjs.map +1 -1
- package/dist/ui/ui-types.d.mts +5 -0
- package/dist/ui/ui-types.d.mts.map +1 -1
- package/package.json +2 -2
- package/src/AUTO-GENERATED-version.mts +1 -1
- package/src/helpers.mts +1 -0
- package/src/helpers.web.mts +22 -2
- package/src/identity/custodian-delegate-helper.mts.bak +7 -0
- package/src/identity/device-delegate-helper.mts +268 -0
- package/src/identity/device-delegate.respec.mts +125 -0
- package/src/identity/keystone-sync-service.mts +95 -2
- package/src/identity/passkey-helper.mts +304 -0
- package/src/identity/passkey.respec.mts +194 -0
- package/src/index.mts +2 -2
- package/src/storage/storage-helpers.web.mts +47 -0
- package/src/ui/component/identity/add-device/add-device.mts +37 -48
- package/src/ui/component/identity/keystone-creator/keystone-creator.html +42 -3
- package/src/ui/component/identity/keystone-creator/keystone-creator.mts +568 -111
- package/src/ui/component/identity/keystone-details/keystone-details.html +38 -0
- package/src/ui/component/identity/keystone-details/keystone-details.mts +1290 -142
- package/src/ui/component/identity/remove-device/remove-device.mts +1 -0
- package/src/ui/ui-constants.mts +1 -0
- package/src/ui/ui-helpers.mts +118 -5
- package/src/ui/ui-types.mts +6 -0
- package/dist/identity/custodian-delegate-helper.d.mts +0 -22
- package/dist/identity/custodian-delegate-helper.d.mts.map +0 -1
- package/dist/identity/custodian-delegate-helper.mjs +0 -67
- package/dist/identity/custodian-delegate-helper.mjs.map +0 -1
- package/src/identity/custodian-delegate-helper.mts +0 -86
package/src/ui/ui-constants.mts
CHANGED
|
@@ -107,6 +107,7 @@ export const EVENT_IBGIB_UI_MESSAGE = 'ibgib-ui-message';
|
|
|
107
107
|
export const EVENT_IBGIB_IDENTITY_REQUEST_CHANGE = 'ibgib-identity-request-change';
|
|
108
108
|
export const EVENT_IBGIB_IDENTITY_CHANGED = 'ibgib-identity-changed';
|
|
109
109
|
export const EVENT_IBGIB_IDENTITY_UPDATE_AVAILABLE = 'ibgib-identity-update-available';
|
|
110
|
+
export const EVENT_IBGIB_IDENTITY_RENEWAL_REQUIRED = 'ibgib-identity-renewal-required';
|
|
110
111
|
// #endregion Custom Events
|
|
111
112
|
|
|
112
113
|
|
package/src/ui/ui-helpers.mts
CHANGED
|
@@ -49,6 +49,9 @@ export interface ShowFullscreenDialogOpts {
|
|
|
49
49
|
isPassword?: boolean;
|
|
50
50
|
isBusy?: boolean;
|
|
51
51
|
animationEmoji?: string;
|
|
52
|
+
passkeys?: Record<string, any>;
|
|
53
|
+
passkeyButtonTitle?: string;
|
|
54
|
+
onPasskeyAuth?: (passkeyEntry?: any) => Promise<string | undefined>;
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
export async function showFullscreenDialog(opts: ShowFullscreenDialogOpts & { isBusy: true }): Promise<FullscreenDialogController>;
|
|
@@ -64,6 +67,9 @@ export async function showFullscreenDialog({
|
|
|
64
67
|
isPassword,
|
|
65
68
|
isBusy,
|
|
66
69
|
animationEmoji,
|
|
70
|
+
passkeys,
|
|
71
|
+
passkeyButtonTitle,
|
|
72
|
+
onPasskeyAuth,
|
|
67
73
|
}: ShowFullscreenDialogOpts): Promise<string | undefined | FullscreenDialogController> {
|
|
68
74
|
const lc = `[${showFullscreenDialog.name}]`;
|
|
69
75
|
try {
|
|
@@ -112,6 +118,75 @@ export async function showFullscreenDialog({
|
|
|
112
118
|
messageElement.appendChild(animDiv);
|
|
113
119
|
}
|
|
114
120
|
|
|
121
|
+
// Clean up any previous passkey container
|
|
122
|
+
let prevPasskeyContainer = document.getElementById('fullscreen-dialog-passkey-container');
|
|
123
|
+
if (prevPasskeyContainer) { prevPasskeyContainer.remove(); }
|
|
124
|
+
|
|
125
|
+
let passkeyContainer: HTMLDivElement | null = null;
|
|
126
|
+
let btnPasskey: HTMLButtonElement | null = null;
|
|
127
|
+
let selectPasskey: HTMLSelectElement | null = null;
|
|
128
|
+
const validPasskeys = Object.values(passkeys || {}).filter(p => p !== null && p !== undefined);
|
|
129
|
+
|
|
130
|
+
if (validPasskeys.length > 0 && onPasskeyAuth && !isBusy) {
|
|
131
|
+
passkeyContainer = document.createElement('div');
|
|
132
|
+
passkeyContainer.id = 'fullscreen-dialog-passkey-container';
|
|
133
|
+
passkeyContainer.style.margin = '1rem 0';
|
|
134
|
+
passkeyContainer.style.textAlign = 'center';
|
|
135
|
+
|
|
136
|
+
btnPasskey = document.createElement('button');
|
|
137
|
+
btnPasskey.id = 'fullscreen-dialog-btn-passkey';
|
|
138
|
+
btnPasskey.type = 'button';
|
|
139
|
+
btnPasskey.className = 'action-btn';
|
|
140
|
+
btnPasskey.style.width = '100%';
|
|
141
|
+
btnPasskey.style.padding = '0.75rem 1rem';
|
|
142
|
+
btnPasskey.style.background = 'linear-gradient(135deg, #1b5e20, #2e7d32)';
|
|
143
|
+
btnPasskey.style.color = '#ffffff';
|
|
144
|
+
btnPasskey.style.fontWeight = 'bold';
|
|
145
|
+
btnPasskey.style.borderRadius = '8px';
|
|
146
|
+
btnPasskey.style.border = '1px solid rgba(255,255,255,0.2)';
|
|
147
|
+
btnPasskey.style.cursor = 'pointer';
|
|
148
|
+
btnPasskey.style.fontSize = '0.95rem';
|
|
149
|
+
btnPasskey.style.marginBottom = '0.75rem';
|
|
150
|
+
btnPasskey.textContent = passkeyButtonTitle || '🛡️ Touch ID / Security Key';
|
|
151
|
+
|
|
152
|
+
if (validPasskeys.length > 1) {
|
|
153
|
+
selectPasskey = document.createElement('select');
|
|
154
|
+
selectPasskey.style.width = '100%';
|
|
155
|
+
selectPasskey.style.padding = '0.4rem';
|
|
156
|
+
selectPasskey.style.marginBottom = '0.5rem';
|
|
157
|
+
selectPasskey.style.borderRadius = '4px';
|
|
158
|
+
selectPasskey.style.background = 'rgba(0,0,0,0.3)';
|
|
159
|
+
selectPasskey.style.color = 'inherit';
|
|
160
|
+
selectPasskey.style.border = '1px solid rgba(255,255,255,0.2)';
|
|
161
|
+
validPasskeys.forEach((p: any, idx: number) => {
|
|
162
|
+
const opt = document.createElement('option');
|
|
163
|
+
opt.value = idx.toString();
|
|
164
|
+
opt.textContent = `${p.name || 'Key'} (${p.credentialId?.substring(0, 8)}...)`;
|
|
165
|
+
selectPasskey!.appendChild(opt);
|
|
166
|
+
});
|
|
167
|
+
passkeyContainer.appendChild(selectPasskey);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
passkeyContainer.appendChild(btnPasskey);
|
|
171
|
+
|
|
172
|
+
const divider = document.createElement('div');
|
|
173
|
+
divider.style.display = 'flex';
|
|
174
|
+
divider.style.alignItems = 'center';
|
|
175
|
+
divider.style.justifyContent = 'center';
|
|
176
|
+
divider.style.gap = '0.5rem';
|
|
177
|
+
divider.style.fontSize = '0.8rem';
|
|
178
|
+
divider.style.color = 'var(--clr-text-secondary, #b3b3b3)';
|
|
179
|
+
divider.style.margin = '0.5rem 0';
|
|
180
|
+
divider.innerHTML = `
|
|
181
|
+
<span style="flex: 1; height: 1px; background: rgba(255,255,255,0.15);"></span>
|
|
182
|
+
<span>OR enter Password below</span>
|
|
183
|
+
<span style="flex: 1; height: 1px; background: rgba(255,255,255,0.15);"></span>
|
|
184
|
+
`;
|
|
185
|
+
passkeyContainer.appendChild(divider);
|
|
186
|
+
|
|
187
|
+
promptInput.parentElement?.insertBefore(passkeyContainer, promptInput);
|
|
188
|
+
}
|
|
189
|
+
|
|
115
190
|
// reset the input classList and button displays
|
|
116
191
|
promptInput.classList.remove('collapsed');
|
|
117
192
|
cancelButton.classList.remove('collapsed');
|
|
@@ -241,6 +316,12 @@ export async function showFullscreenDialog({
|
|
|
241
316
|
if (prompt || showInput) {
|
|
242
317
|
promptInput.removeEventListener('keypress', onKeypress);
|
|
243
318
|
}
|
|
319
|
+
if (btnPasskey) {
|
|
320
|
+
btnPasskey.removeEventListener('click', onPasskeyClick);
|
|
321
|
+
}
|
|
322
|
+
if (passkeyContainer) {
|
|
323
|
+
passkeyContainer.remove();
|
|
324
|
+
}
|
|
244
325
|
okButton.removeEventListener('click', onOK);
|
|
245
326
|
cancelButton.removeEventListener('click', onCancel);
|
|
246
327
|
dialog.removeEventListener('close', onClose); // Remove dialog-level listener too
|
|
@@ -256,6 +337,38 @@ export async function showFullscreenDialog({
|
|
|
256
337
|
resolve(result);
|
|
257
338
|
};
|
|
258
339
|
|
|
340
|
+
/** user clicks Passkey button */
|
|
341
|
+
const onPasskeyClick = async () => {
|
|
342
|
+
try {
|
|
343
|
+
if (!onPasskeyAuth) return;
|
|
344
|
+
btnPasskey!.disabled = true;
|
|
345
|
+
btnPasskey!.textContent = 'Waiting for biometrics / security key...';
|
|
346
|
+
let selectedPasskey = validPasskeys[0];
|
|
347
|
+
if (selectPasskey) {
|
|
348
|
+
const selectedIdx = parseInt(selectPasskey.value, 10);
|
|
349
|
+
selectedPasskey = validPasskeys[selectedIdx] || validPasskeys[0];
|
|
350
|
+
}
|
|
351
|
+
const passkeySecret = await onPasskeyAuth(selectedPasskey);
|
|
352
|
+
if (passkeySecret) {
|
|
353
|
+
removeEventListeners();
|
|
354
|
+
if (promptInput) { promptInput.value = ''; }
|
|
355
|
+
dialog.close(passkeySecret);
|
|
356
|
+
resolve(passkeySecret);
|
|
357
|
+
} else {
|
|
358
|
+
btnPasskey!.disabled = false;
|
|
359
|
+
btnPasskey!.textContent = passkeyButtonTitle || '🛡️ Touch ID / Security Key';
|
|
360
|
+
}
|
|
361
|
+
} catch (err) {
|
|
362
|
+
console.warn('Passkey assertion in dialog failed/cancelled:', err);
|
|
363
|
+
btnPasskey!.disabled = false;
|
|
364
|
+
btnPasskey!.textContent = passkeyButtonTitle || '🛡️ Touch ID / Security Key';
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
if (btnPasskey) {
|
|
369
|
+
btnPasskey.addEventListener('click', onPasskeyClick);
|
|
370
|
+
}
|
|
371
|
+
|
|
259
372
|
/** user actively clicks Cancel */
|
|
260
373
|
const onCancel = () => {
|
|
261
374
|
removeEventListeners();
|
|
@@ -264,11 +377,11 @@ export async function showFullscreenDialog({
|
|
|
264
377
|
resolve(undefined);
|
|
265
378
|
};
|
|
266
379
|
/**
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
380
|
+
* Handle dialog.close() without button click (e.g., Esc key)
|
|
381
|
+
*
|
|
382
|
+
* NOTE: this does not trigger when dialog.close() is executed. This
|
|
383
|
+
* is only firing when esc is pressed.
|
|
384
|
+
*/
|
|
272
385
|
const onClose = () => {
|
|
273
386
|
removeEventListeners();
|
|
274
387
|
if (promptInput) { promptInput.value = ''; } // Clear input for next time
|
package/src/ui/ui-types.mts
CHANGED
|
@@ -17,3 +17,9 @@ export interface EventIbGibIdentityUpdateAvailableDetail {
|
|
|
17
17
|
localN: number;
|
|
18
18
|
serverLatestAddr: string;
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
export interface EventIbGibIdentityRenewalRequiredDetail {
|
|
22
|
+
activePrimaryAddr: string;
|
|
23
|
+
primaryTjpAddr: string;
|
|
24
|
+
reason: 'expired' | 'missing_secret';
|
|
25
|
+
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module identity/custodian-delegate-helper
|
|
3
|
-
*
|
|
4
|
-
* Client-side helper functions for deriving and storing local cryptographic delegate secrets
|
|
5
|
-
* for full-custodian / passwordless identities.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Retrieves or generates a high-entropy local delegate secret for a passwordless custodian identity.
|
|
9
|
-
* Stored locally in `localStorage` keyed by `primaryTjpAddr`.
|
|
10
|
-
*
|
|
11
|
-
* @param primaryTjpAddr The primary identity keystone TJP address (`ib^gib`).
|
|
12
|
-
*/
|
|
13
|
-
export declare function deriveLocalCustodianDelegateSecret({ primaryTjpAddr, }: {
|
|
14
|
-
primaryTjpAddr: string;
|
|
15
|
-
}): Promise<string>;
|
|
16
|
-
/**
|
|
17
|
-
* Removes the stored local delegate secret for a custodian identity.
|
|
18
|
-
*/
|
|
19
|
-
export declare function clearLocalCustodianDelegateSecret({ primaryTjpAddr, }: {
|
|
20
|
-
primaryTjpAddr: string;
|
|
21
|
-
}): void;
|
|
22
|
-
//# sourceMappingURL=custodian-delegate-helper.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custodian-delegate-helper.d.mts","sourceRoot":"","sources":["../../src/identity/custodian-delegate-helper.mts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;;;;GAKG;AACH,wBAAsB,kCAAkC,CAAC,EACrD,cAAc,GACjB,EAAE;IACC,cAAc,EAAE,MAAM,CAAC;CAC1B,GAAG,OAAO,CAAC,MAAM,CAAC,CAiDlB;AAED;;GAEG;AACH,wBAAgB,iCAAiC,CAAC,EAC9C,cAAc,GACjB,EAAE;IACC,cAAc,EAAE,MAAM,CAAC;CAC1B,GAAG,IAAI,CAIP"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module identity/custodian-delegate-helper
|
|
3
|
-
*
|
|
4
|
-
* Client-side helper functions for deriving and storing local cryptographic delegate secrets
|
|
5
|
-
* for full-custodian / passwordless identities.
|
|
6
|
-
*/
|
|
7
|
-
import { getUUID, hash, HashAlgorithm, extractErrorMsg } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
8
|
-
import { storageGet, storagePut } from "../storage/storage-helpers.web.mjs";
|
|
9
|
-
import { getGlobalDbName, getGlobalStoreName } from "../helpers.web.mjs";
|
|
10
|
-
const LOCAL_STORAGE_PREFIX = 'ibgib_custodian_delegate_secret_';
|
|
11
|
-
/**
|
|
12
|
-
* Retrieves or generates a high-entropy local delegate secret for a passwordless custodian identity.
|
|
13
|
-
* Stored locally in `localStorage` keyed by `primaryTjpAddr`.
|
|
14
|
-
*
|
|
15
|
-
* @param primaryTjpAddr The primary identity keystone TJP address (`ib^gib`).
|
|
16
|
-
*/
|
|
17
|
-
export async function deriveLocalCustodianDelegateSecret({ primaryTjpAddr, }) {
|
|
18
|
-
const lc = `[${deriveLocalCustodianDelegateSecret.name}]`;
|
|
19
|
-
try {
|
|
20
|
-
if (!primaryTjpAddr) {
|
|
21
|
-
throw new Error('primaryTjpAddr is required to derive local custodian delegate secret (E: a1b2c3d4e5f67890123456789a000101)');
|
|
22
|
-
}
|
|
23
|
-
const key = `${LOCAL_STORAGE_PREFIX}${primaryTjpAddr}`;
|
|
24
|
-
const dbName = getGlobalDbName();
|
|
25
|
-
const storeName = getGlobalStoreName();
|
|
26
|
-
// debugger; // what are the dbName and storeName?
|
|
27
|
-
const existingSecret = await storageGet({ dbName, storeName, key });
|
|
28
|
-
if (existingSecret) {
|
|
29
|
-
return existingSecret;
|
|
30
|
-
}
|
|
31
|
-
// Generate high-entropy 512-bit SHA hash secret from fresh UUIDs
|
|
32
|
-
const rawEntropy = await getUUID(32);
|
|
33
|
-
const newSecret = await hash({
|
|
34
|
-
s: rawEntropy,
|
|
35
|
-
algorithm: HashAlgorithm.sha_512
|
|
36
|
-
});
|
|
37
|
-
await storagePut({ dbName, storeName, key, value: newSecret });
|
|
38
|
-
return newSecret;
|
|
39
|
-
// const existingSecret = localStorage.getItem(key);
|
|
40
|
-
// if (existingSecret) {
|
|
41
|
-
// return existingSecret;
|
|
42
|
-
// }
|
|
43
|
-
// // Generate high-entropy 512-bit SHA hash secret from fresh UUIDs
|
|
44
|
-
// const rawEntropy = `${await getUUID()}-${await getUUID()}-${await getUUID()}-${Date.now()}`;
|
|
45
|
-
// const newSecret = await hash({
|
|
46
|
-
// s: rawEntropy,
|
|
47
|
-
// algorithm: HashAlgorithm.sha_512
|
|
48
|
-
// });
|
|
49
|
-
// localStorage.setItem(key, newSecret);
|
|
50
|
-
// return newSecret;
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Removes the stored local delegate secret for a custodian identity.
|
|
59
|
-
*/
|
|
60
|
-
export function clearLocalCustodianDelegateSecret({ primaryTjpAddr, }) {
|
|
61
|
-
if (!primaryTjpAddr) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const key = `${LOCAL_STORAGE_PREFIX}${primaryTjpAddr}`;
|
|
65
|
-
localStorage.removeItem(key);
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=custodian-delegate-helper.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custodian-delegate-helper.mjs","sourceRoot":"","sources":["../../src/identity/custodian-delegate-helper.mts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAChH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAEzE,MAAM,oBAAoB,GAAG,kCAAkC,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kCAAkC,CAAC,EACrD,cAAc,GAGjB;IACG,MAAM,EAAE,GAAG,IAAI,kCAAkC,CAAC,IAAI,GAAG,CAAC;IAC1D,IAAI,CAAC;QACD,IAAI,CAAC,cAAc,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,4GAA4G,CAAC,CAAC;QAClI,CAAC;QAED,MAAM,GAAG,GAAG,GAAG,oBAAoB,GAAG,cAAc,EAAE,CAAC;QAEvD,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;QAEvC,kDAAkD;QAGlD,MAAM,cAAc,GAAG,MAAM,UAAU,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;QACpE,IAAI,cAAc,EAAE,CAAC;YACjB,OAAO,cAAc,CAAC;QAC1B,CAAC;QAED,iEAAiE;QACjE,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,EAAE,CAAC,CAAC;QACrC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC;YACzB,CAAC,EAAE,UAAU;YACb,SAAS,EAAE,aAAa,CAAC,OAAO;SACnC,CAAC,CAAC;QACH,MAAM,UAAU,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAE/D,OAAO,SAAS,CAAC;QAGjB,oDAAoD;QACpD,wBAAwB;QACxB,6BAA6B;QAC7B,IAAI;QAEJ,oEAAoE;QACpE,+FAA+F;QAC/F,iCAAiC;QACjC,qBAAqB;QACrB,uCAAuC;QACvC,MAAM;QAEN,wCAAwC;QACxC,oBAAoB;IACxB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iCAAiC,CAAC,EAC9C,cAAc,GAGjB;IACG,IAAI,CAAC,cAAc,EAAE,CAAC;QAAC,OAAO;IAAC,CAAC;IAChC,MAAM,GAAG,GAAG,GAAG,oBAAoB,GAAG,cAAc,EAAE,CAAC;IACvD,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module identity/custodian-delegate-helper
|
|
3
|
-
*
|
|
4
|
-
* Client-side helper functions for deriving and storing local cryptographic delegate secrets
|
|
5
|
-
* for full-custodian / passwordless identities.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { getUUID, hash, HashAlgorithm, extractErrorMsg } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
9
|
-
import { storageGet, storagePut } from "../storage/storage-helpers.web.mjs";
|
|
10
|
-
import { getGlobalDbName, getGlobalStoreName } from "../helpers.web.mjs";
|
|
11
|
-
|
|
12
|
-
const LOCAL_STORAGE_PREFIX = 'ibgib_custodian_delegate_secret_';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Retrieves or generates a high-entropy local delegate secret for a passwordless custodian identity.
|
|
16
|
-
* Stored locally in `localStorage` keyed by `primaryTjpAddr`.
|
|
17
|
-
*
|
|
18
|
-
* @param primaryTjpAddr The primary identity keystone TJP address (`ib^gib`).
|
|
19
|
-
*/
|
|
20
|
-
export async function deriveLocalCustodianDelegateSecret({
|
|
21
|
-
primaryTjpAddr,
|
|
22
|
-
}: {
|
|
23
|
-
primaryTjpAddr: string;
|
|
24
|
-
}): Promise<string> {
|
|
25
|
-
const lc = `[${deriveLocalCustodianDelegateSecret.name}]`;
|
|
26
|
-
try {
|
|
27
|
-
if (!primaryTjpAddr) {
|
|
28
|
-
throw new Error('primaryTjpAddr is required to derive local custodian delegate secret (E: a1b2c3d4e5f67890123456789a000101)');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const key = `${LOCAL_STORAGE_PREFIX}${primaryTjpAddr}`;
|
|
32
|
-
|
|
33
|
-
const dbName = getGlobalDbName();
|
|
34
|
-
const storeName = getGlobalStoreName();
|
|
35
|
-
|
|
36
|
-
// debugger; // what are the dbName and storeName?
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const existingSecret = await storageGet({ dbName, storeName, key });
|
|
40
|
-
if (existingSecret) {
|
|
41
|
-
return existingSecret;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Generate high-entropy 512-bit SHA hash secret from fresh UUIDs
|
|
45
|
-
const rawEntropy = await getUUID(32);
|
|
46
|
-
const newSecret = await hash({
|
|
47
|
-
s: rawEntropy,
|
|
48
|
-
algorithm: HashAlgorithm.sha_512
|
|
49
|
-
});
|
|
50
|
-
await storagePut({ dbName, storeName, key, value: newSecret });
|
|
51
|
-
|
|
52
|
-
return newSecret;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// const existingSecret = localStorage.getItem(key);
|
|
56
|
-
// if (existingSecret) {
|
|
57
|
-
// return existingSecret;
|
|
58
|
-
// }
|
|
59
|
-
|
|
60
|
-
// // Generate high-entropy 512-bit SHA hash secret from fresh UUIDs
|
|
61
|
-
// const rawEntropy = `${await getUUID()}-${await getUUID()}-${await getUUID()}-${Date.now()}`;
|
|
62
|
-
// const newSecret = await hash({
|
|
63
|
-
// s: rawEntropy,
|
|
64
|
-
// algorithm: HashAlgorithm.sha_512
|
|
65
|
-
// });
|
|
66
|
-
|
|
67
|
-
// localStorage.setItem(key, newSecret);
|
|
68
|
-
// return newSecret;
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Removes the stored local delegate secret for a custodian identity.
|
|
77
|
-
*/
|
|
78
|
-
export function clearLocalCustodianDelegateSecret({
|
|
79
|
-
primaryTjpAddr,
|
|
80
|
-
}: {
|
|
81
|
-
primaryTjpAddr: string;
|
|
82
|
-
}): void {
|
|
83
|
-
if (!primaryTjpAddr) { return; }
|
|
84
|
-
const key = `${LOCAL_STORAGE_PREFIX}${primaryTjpAddr}`;
|
|
85
|
-
localStorage.removeItem(key);
|
|
86
|
-
}
|