UNPKG

@sebastianp265/safe-server-side-storage-client

Version:

Library for Confidential Server-Side Message Storage Using the Labyrinth Protocol

78 lines (77 loc) 4.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DevicePublicKeyBundle = exports.DevicePrivateKeyBundle = exports.DeviceKeyBundle = void 0; const keys_1 = require("../../crypto/keys"); const DeviceAndVirtualDeviceCommonKeyBundle_1 = require("./DeviceAndVirtualDeviceCommonKeyBundle"); const BytesSerializer_1 = require("../../BytesSerializer"); class DeviceKeyBundle { priv; pub; constructor(priv, pub) { this.priv = priv; this.pub = pub; } static generate() { const priv = DevicePrivateKeyBundle.generate(); return new DeviceKeyBundle(priv, priv.getPublicKeyBundle()); } serialize() { return { priv: this.priv.serialize(), pub: this.pub.serialize(), }; } static deserialize(serialized) { const { priv, pub } = serialized; return new DeviceKeyBundle(DevicePrivateKeyBundle.deserialize(priv), DevicePublicKeyBundle.deserialize(pub)); } } exports.DeviceKeyBundle = DeviceKeyBundle; class DevicePrivateKeyBundle extends DeviceAndVirtualDeviceCommonKeyBundle_1.CommonPrivateKeyBundle { epochStorageAuthKeyPriv; constructor(deviceKeyPriv, epochStorageKeyPriv, epochStorageAuthKeyPriv) { super(deviceKeyPriv, epochStorageKeyPriv); this.epochStorageAuthKeyPriv = epochStorageAuthKeyPriv; } static generate() { return new DevicePrivateKeyBundle(keys_1.PrivateKey.generate(), keys_1.PrivateKey.generate(), keys_1.PrivateKey.generate()); } serialize() { return { deviceKeyPriv: this.deviceKeyPriv.serialize(), epochStorageKeyPriv: this.epochStorageKeyPriv.serialize(), epochStorageAuthKeyPriv: this.epochStorageAuthKeyPriv.serialize(), }; } static deserialize(devicePrivateKeyBundleSerialized) { const { deviceKeyPriv, epochStorageKeyPriv, epochStorageAuthKeyPriv } = devicePrivateKeyBundleSerialized; return new DevicePrivateKeyBundle(keys_1.PrivateKey.deserialize(deviceKeyPriv), keys_1.PrivateKey.deserialize(epochStorageKeyPriv), keys_1.PrivateKey.deserialize(epochStorageAuthKeyPriv)); } getPublicKeyBundle() { const { deviceKeyPub, epochStorageKeyPub, epochStorageKeySig } = super.getPublicKeyBundle(); const epochStorageAuthKeyPub = this.epochStorageAuthKeyPriv.getPublicKey(); return new DevicePublicKeyBundle(deviceKeyPub, epochStorageKeyPub, epochStorageKeySig, epochStorageAuthKeyPub, this.deviceKeyPriv.sign(Uint8Array.of(0x31), epochStorageAuthKeyPub.getX25519PublicKeyBytes())); } } exports.DevicePrivateKeyBundle = DevicePrivateKeyBundle; class DevicePublicKeyBundle extends DeviceAndVirtualDeviceCommonKeyBundle_1.CommonPublicKeyBundle { epochStorageAuthKeyPub; epochStorageAuthKeySig; constructor(deviceKeyPub, epochStorageKeyPub, epochStorageKeySig, epochStorageAuthKeyPub, epochStorageAuthKeySig) { super(deviceKeyPub, epochStorageKeyPub, epochStorageKeySig); this.epochStorageAuthKeyPub = epochStorageAuthKeyPub; this.epochStorageAuthKeySig = epochStorageAuthKeySig; } serialize() { return { ...super.serialize(), epochStorageAuthKeyPub: this.epochStorageAuthKeyPub.serialize(), epochStorageAuthKeySig: BytesSerializer_1.bytesSerializerProvider.bytesSerializer.serialize(this.epochStorageAuthKeySig), }; } static deserialize(devicePublicKeyBundleSerialized) { const { deviceKeyPub, epochStorageKeyPub, epochStorageKeySig, epochStorageAuthKeyPub, epochStorageAuthKeySig, } = devicePublicKeyBundleSerialized; return new DevicePublicKeyBundle(keys_1.PublicKey.deserialize(deviceKeyPub), keys_1.PublicKey.deserialize(epochStorageKeyPub), BytesSerializer_1.bytesSerializerProvider.bytesSerializer.deserialize(epochStorageKeySig), keys_1.PublicKey.deserialize(epochStorageAuthKeyPub), BytesSerializer_1.bytesSerializerProvider.bytesSerializer.deserialize(epochStorageAuthKeySig)); } } exports.DevicePublicKeyBundle = DevicePublicKeyBundle;