mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 13:00:39 +00:00
18d3490c4f
- Added functions for managing account passkeys including creation, listing, updating, and deletion. - Introduced login methods using account passkeys with options for direct unlock and login-only modes. - Enhanced error handling and response parsing for passkey-related API calls. - Updated UI styles for account passkey management components. - Added new translations for account passkey features in multiple languages. - Modified network status handling to improve service reachability checks.
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { User, UserDecryptionOptions, WebAuthnPrfDecryptionOption } from '../types';
|
|
|
|
function normalizeOptionalPublicKey(value: unknown): string {
|
|
if (value == null) return '';
|
|
return String(value);
|
|
}
|
|
|
|
export function buildAccountKeys(user: Pick<User, 'privateKey' | 'publicKey'>): Record<string, unknown> | null {
|
|
if (!user.privateKey) {
|
|
return null;
|
|
}
|
|
|
|
const publicKey = normalizeOptionalPublicKey(user.publicKey);
|
|
|
|
return {
|
|
publicKeyEncryptionKeyPair: {
|
|
wrappedPrivateKey: user.privateKey,
|
|
publicKey,
|
|
Object: 'publicKeyEncryptionKeyPair',
|
|
},
|
|
Object: 'privateKeys',
|
|
};
|
|
}
|
|
|
|
export function buildMasterPasswordUnlock(
|
|
user: Pick<User, 'email' | 'key' | 'kdfType' | 'kdfIterations' | 'kdfMemory' | 'kdfParallelism'>
|
|
): UserDecryptionOptions['MasterPasswordUnlock'] {
|
|
return {
|
|
Kdf: {
|
|
KdfType: user.kdfType,
|
|
Iterations: user.kdfIterations,
|
|
Memory: user.kdfMemory ?? null,
|
|
Parallelism: user.kdfParallelism ?? null,
|
|
},
|
|
MasterKeyEncryptedUserKey: user.key,
|
|
MasterKeyWrappedUserKey: user.key,
|
|
Salt: user.email.toLowerCase(),
|
|
Object: 'masterPasswordUnlock',
|
|
};
|
|
}
|
|
|
|
export function buildUserDecryptionOptions(
|
|
user: Pick<User, 'email' | 'key' | 'kdfType' | 'kdfIterations' | 'kdfMemory' | 'kdfParallelism'>,
|
|
webAuthnPrfOption: WebAuthnPrfDecryptionOption | null = null
|
|
): UserDecryptionOptions {
|
|
return {
|
|
HasMasterPassword: true,
|
|
Object: 'userDecryptionOptions',
|
|
MasterPasswordUnlock: buildMasterPasswordUnlock(user),
|
|
TrustedDeviceOption: null,
|
|
KeyConnectorOption: null,
|
|
WebAuthnPrfOption: webAuthnPrfOption,
|
|
};
|
|
}
|
|
|
|
export function buildUserDecryptionCompat(
|
|
user: Pick<User, 'email' | 'key' | 'kdfType' | 'kdfIterations' | 'kdfMemory' | 'kdfParallelism'>
|
|
): Record<string, unknown> {
|
|
return {
|
|
masterPasswordUnlock: {
|
|
kdf: {
|
|
kdfType: user.kdfType,
|
|
iterations: user.kdfIterations,
|
|
memory: user.kdfMemory ?? null,
|
|
parallelism: user.kdfParallelism ?? null,
|
|
},
|
|
masterKeyWrappedUserKey: user.key,
|
|
masterKeyEncryptedUserKey: user.key,
|
|
salt: user.email.toLowerCase(),
|
|
},
|
|
};
|
|
}
|