import { IEncryptedMessage, StringifiedType } from "@tkey-singularity/common-types";

class DeviceEncryptedMessage implements IEncryptedMessage {
  ciphertext: string;

  ephemPublicKey: string;

  iv: string;

  mac: string;

  constructor(ciphertext: string, ephemPublicKey: string, iv: string, mac: string) {
    this.ciphertext = ciphertext;
    this.ephemPublicKey = ephemPublicKey;
    this.iv = iv;
    this.mac = mac;
  }

  static fromJSON(value: StringifiedType): DeviceEncryptedMessage {
    const { ciphertext, ephemPublicKey, iv, mac } = value;
    return new DeviceEncryptedMessage(ciphertext, ephemPublicKey, iv, mac);
  }

  toJSON(): StringifiedType {
    return {
      ciphertext: this.ciphertext.toString(),
      ephemPublicKey: this.ephemPublicKey.toString(),
      iv: this.iv.toString(),
      mac: this.mac.toString(),
    };
  }
}
export default DeviceEncryptedMessage;
