const { PrivateDeviceSchema: t } = require("@holepunchto/keet-core-schemas"),
{ AddDeviceKeyOperation: e, AddDeviceAttestationOperation: i } = t.Operations
module.exports = class {
static Operations = new Set([e.TYPE, i.TYPE])
constructor(t) {
;((this.profile = t), (this.keys = null), (this.attestations = null))
}
initialize() {
;((this.keys = this.profile.view.collections.privateDeviceKeys),
(this.attestations = this.profile.view.collections.privateDeviceAttestations))
}
async _applyAddDeviceKeyOperation(t, { id: e }) {
const { devicePublicKey: i } = t.value
;(await this.keys.get(e.key)) || (await this.keys.update(e.key, i, { upsert: !0 }))
}
async _applyAddDeviceAttestationOperation(t) {
const { devicePublicKey: e, attestation: i } = t.value
;(await this.attestations.get(e)) || (await this.attestations.update(e, i, { upsert: !0 }))
}
async autobaseApply(t, s) {
switch (t.type) {
case e.TYPE:
return this._applyAddDeviceKeyOperation(t, s)
case i.TYPE:
return this._applyAddDeviceAttestationOperation(t, s)
}
}
}