@sebastianp265/safe-server-side-storage-client
Version:
Library for Confidential Server-Side Message Storage Using the Labyrinth Protocol
44 lines (43 loc) • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommonPublicKeyBundle = exports.CommonPrivateKeyBundle = void 0;
const keys_1 = require("../../crypto/keys");
const BytesSerializer_1 = require("../../BytesSerializer");
class CommonPrivateKeyBundle {
deviceKeyPriv;
epochStorageKeyPriv;
constructor(deviceKeyPriv, epochStorageKeyPriv) {
this.deviceKeyPriv = deviceKeyPriv;
this.epochStorageKeyPriv = epochStorageKeyPriv;
}
static generate() {
return new CommonPrivateKeyBundle(keys_1.PrivateKey.generate(), keys_1.PrivateKey.generate());
}
getPublicKeyBundle() {
const epochStorageKeyPub = this.epochStorageKeyPriv.getPublicKey();
return new CommonPublicKeyBundle(this.deviceKeyPriv.getPublicKey(), epochStorageKeyPub, this.deviceKeyPriv.sign(Uint8Array.of(0x30), epochStorageKeyPub.getX25519PublicKeyBytes()));
}
}
exports.CommonPrivateKeyBundle = CommonPrivateKeyBundle;
class CommonPublicKeyBundle {
deviceKeyPub;
epochStorageKeyPub;
epochStorageKeySig;
constructor(deviceKeyPub, epochStorageKeyPub, epochStorageKeySig) {
this.deviceKeyPub = deviceKeyPub;
this.epochStorageKeyPub = epochStorageKeyPub;
this.epochStorageKeySig = epochStorageKeySig;
}
serialize() {
return {
deviceKeyPub: this.deviceKeyPub.serialize(),
epochStorageKeyPub: this.epochStorageKeyPub.serialize(),
epochStorageKeySig: BytesSerializer_1.bytesSerializerProvider.bytesSerializer.serialize(this.epochStorageKeySig),
};
}
static deserialize(devicePublicKeyBundleSerialized) {
const { deviceKeyPub, epochStorageKeyPub, epochStorageKeySig } = devicePublicKeyBundleSerialized;
return new CommonPublicKeyBundle(keys_1.PublicKey.deserialize(deviceKeyPub), keys_1.PublicKey.deserialize(epochStorageKeyPub), BytesSerializer_1.bytesSerializerProvider.bytesSerializer.deserialize(epochStorageKeySig));
}
}
exports.CommonPublicKeyBundle = CommonPublicKeyBundle;