{"version":3,"file":"VaultRecord.mjs","names":[],"sources":["../../src/repository/VaultRecord.ts"],"sourcesContent":["import type { TagsBase, RecordTags } from '@credo-ts/core'\nimport type { VaultHeader, PolicyMode } from '../models'\n\nimport { BaseRecord, utils } from '@credo-ts/core'\n\nexport type CustomVaultTags = TagsBase\n\nexport type DefaultVaultTags = {\n  vaultId: string\n  docId: string\n  ownerDid: string\n  policyMode?: PolicyMode\n  suite: string\n  epoch: string\n  storageType?: string\n}\n\nexport type VaultTags = RecordTags<VaultRecord>\n\n/**\n * Reference to externally stored vault ciphertext\n */\nexport interface VaultStorageReference {\n  /** Storage type (s3, ipfs, arweave, http) */\n  type: 's3' | 'ipfs' | 'arweave' | 'http'\n  /** Storage URI */\n  uri: string\n  /** SHA-256 checksum of ciphertext */\n  checksum: string\n  /** Size in bytes */\n  size: number\n  /** Content type */\n  contentType?: string\n}\n\nexport interface VaultRecordProps {\n  id?: string\n  createdAt?: Date\n  updatedAt?: Date\n  tags?: CustomVaultTags\n\n  // Core identifiers\n  vaultId: string\n  docId: string\n  ownerDid: string\n\n  // Vault data\n  header: VaultHeader\n  ciphertext: string // base64url encoded encrypted data (may be empty if using storage reference)\n\n  // External storage reference (for large files)\n  storageReference?: VaultStorageReference\n}\n\n/**\n * Database record for an encrypted vault\n *\n * Stores the vault header (metadata) and ciphertext (encrypted data)\n * All encryption/decryption happens client-side\n */\nexport class VaultRecord extends BaseRecord<DefaultVaultTags, CustomVaultTags> {\n  /** Logical vault identifier */\n  public vaultId!: string\n\n  /** Document identifier (unique per document version) */\n  public docId!: string\n\n  /** DID of the vault owner */\n  public ownerDid!: string\n\n  /** Vault header with metadata and policy info */\n  public header!: VaultHeader\n\n  /** Base64url-encoded ciphertext (encrypted data) */\n  public ciphertext!: string\n\n  /** External storage reference (for large files) */\n  public storageReference?: VaultStorageReference\n\n  public static readonly type = 'VaultRecord'\n  public readonly type = VaultRecord.type\n\n  public constructor(props: VaultRecordProps) {\n    super()\n\n    if (props) {\n      this.id = props.id ?? utils.uuid()\n      this.createdAt = props.createdAt ?? new Date()\n      this.updatedAt = props.updatedAt\n\n      this.vaultId = props.vaultId\n      this.docId = props.docId\n      this.ownerDid = props.ownerDid\n      this.header = props.header\n      this.ciphertext = props.ciphertext\n      this.storageReference = props.storageReference\n\n      this._tags = props.tags ?? {}\n    }\n  }\n\n  public getTags(): DefaultVaultTags & CustomVaultTags {\n    return {\n      ...this._tags,\n      vaultId: this.vaultId,\n      docId: this.docId,\n      ownerDid: this.ownerDid,\n      policyMode: this.header.policy?.mode,\n      suite: this.header.suite,\n      epoch: String(this.header.epoch),\n      storageType: this.storageReference?.type,\n    }\n  }\n\n  /**\n   * Get the policy mode of this vault\n   */\n  public get policyMode(): PolicyMode | undefined {\n    return this.header.policy?.mode\n  }\n\n  /**\n   * Check if this is a passphrase-protected vault\n   */\n  public get isPassphraseVault(): boolean {\n    return this.header.suite === 'S3' && !!this.header.salt && !!this.header.argon2\n  }\n\n  /**\n   * Check if this is an any-of policy vault\n   */\n  public get isAnyOfVault(): boolean {\n    return this.header.policy?.mode === 'any-of' && !!this.header.recipients\n  }\n\n  /**\n   * Check if this is a threshold policy vault\n   */\n  public get isThresholdVault(): boolean {\n    return this.header.policy?.mode === 'threshold' && !!this.header.shares\n  }\n\n  /**\n   * Get human-readable description if available\n   */\n  public get description(): string | undefined {\n    return this.header.metadata?.description\n  }\n\n  /**\n   * Get tags if available\n   */\n  public get metadataTags(): string[] | undefined {\n    return this.header.metadata?.tags\n  }\n\n  /**\n   * Check if this vault uses external storage\n   */\n  public get hasExternalStorage(): boolean {\n    return !!this.storageReference\n  }\n\n  /**\n   * Check if ciphertext needs to be downloaded from external storage\n   */\n  public get needsDownload(): boolean {\n    return this.hasExternalStorage && !this.ciphertext\n  }\n\n  /**\n   * Get storage URI if using external storage\n   */\n  public get storageUri(): string | undefined {\n    return this.storageReference?.uri\n  }\n\n  /**\n   * Get ciphertext size (from storage reference or actual data)\n   */\n  public get ciphertextSize(): number {\n    if (this.storageReference) {\n      return this.storageReference.size\n    }\n    // Estimate from base64url encoded string (roughly 3/4 of string length)\n    return Math.floor((this.ciphertext.length * 3) / 4)\n  }\n}\n"],"mappings":";;;;;;;;;AA4DA,IAAa,cAAb,MAAa,oBAAoB,WAA8C;CAsB7E,AAAO,YAAY,OAAyB;AAC1C,SAAO;OAHO,OAAO,YAAY;AAKjC,MAAI,OAAO;AACT,QAAK,KAAK,MAAM,MAAM,MAAM,MAAM;AAClC,QAAK,YAAY,MAAM,6BAAa,IAAI,MAAM;AAC9C,QAAK,YAAY,MAAM;AAEvB,QAAK,UAAU,MAAM;AACrB,QAAK,QAAQ,MAAM;AACnB,QAAK,WAAW,MAAM;AACtB,QAAK,SAAS,MAAM;AACpB,QAAK,aAAa,MAAM;AACxB,QAAK,mBAAmB,MAAM;AAE9B,QAAK,QAAQ,MAAM,QAAQ,EAAE;;;CAIjC,AAAO,UAA8C;AACnD,SAAO;GACL,GAAG,KAAK;GACR,SAAS,KAAK;GACd,OAAO,KAAK;GACZ,UAAU,KAAK;GACf,YAAY,KAAK,OAAO,QAAQ;GAChC,OAAO,KAAK,OAAO;GACnB,OAAO,OAAO,KAAK,OAAO,MAAM;GAChC,aAAa,KAAK,kBAAkB;GACrC;;;;;CAMH,IAAW,aAAqC;AAC9C,SAAO,KAAK,OAAO,QAAQ;;;;;CAM7B,IAAW,oBAA6B;AACtC,SAAO,KAAK,OAAO,UAAU,QAAQ,CAAC,CAAC,KAAK,OAAO,QAAQ,CAAC,CAAC,KAAK,OAAO;;;;;CAM3E,IAAW,eAAwB;AACjC,SAAO,KAAK,OAAO,QAAQ,SAAS,YAAY,CAAC,CAAC,KAAK,OAAO;;;;;CAMhE,IAAW,mBAA4B;AACrC,SAAO,KAAK,OAAO,QAAQ,SAAS,eAAe,CAAC,CAAC,KAAK,OAAO;;;;;CAMnE,IAAW,cAAkC;AAC3C,SAAO,KAAK,OAAO,UAAU;;;;;CAM/B,IAAW,eAAqC;AAC9C,SAAO,KAAK,OAAO,UAAU;;;;;CAM/B,IAAW,qBAA8B;AACvC,SAAO,CAAC,CAAC,KAAK;;;;;CAMhB,IAAW,gBAAyB;AAClC,SAAO,KAAK,sBAAsB,CAAC,KAAK;;;;;CAM1C,IAAW,aAAiC;AAC1C,SAAO,KAAK,kBAAkB;;;;;CAMhC,IAAW,iBAAyB;AAClC,MAAI,KAAK,iBACP,QAAO,KAAK,iBAAiB;AAG/B,SAAO,KAAK,MAAO,KAAK,WAAW,SAAS,IAAK,EAAE;;;YA1G9B,OAAO"}