/
raiden
/
obsidian-git-encrypt
Обзор
Документация
Войти
/
raiden
/
obsidian-git-encrypt
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/crypto/keyHandle.ts
52 строки
1 KB
Robert Kuzhin
feat: add encrypted mirror and manifest store
09 авг 2026, 10:06
09 авг 2026, 10:06
7f1b7fe
Код
Авторство
О чём код?
import { DestroyedKeyError } from "./errors.js"; declare const keyHandleBrand: unique symbol; /** An opaque reference to Vault Key material owned by the crypto core. */ export interface KeyHandle { readonly [keyHandleBrand]: true; } interface KeyRecord { readonly vaultId: string; readonly key: Uint8Array; } class KeyHandleToken { // Runtime identity is intentionally the only data stored on the handle. } const records = new WeakMap<object, KeyRecord>(); export function createKeyHandle(vaultId: string, source: Uint8Array): KeyHandle { const token = new KeyHandleToken(); records.set(token, { vaultId, key: new Uint8Array(source) }); return token as KeyHandle; } export function copyKeyRecord(handle: KeyHandle): KeyRecord { const record = records.get(handle); if (record === undefined) { throw new DestroyedKeyError(); } return { vaultId: record.vaultId, key: new Uint8Array(record.key) }; } export function getKeyHandleVaultId(handle: KeyHandle): string { const record = records.get(handle); if (record === undefined) { throw new DestroyedKeyError(); } return record.vaultId; } export function destroyKeyHandle(handle: KeyHandle): void { const record = records.get(handle); if (record === undefined) { return; } record.key.fill(0); records.delete(handle); }