{"version":3,"file":"did.mjs","names":[],"sources":["../../../../../src/storage/migration/updates/0.3.1-0.4/did.ts"],"sourcesContent":["import type { BaseAgent } from '../../../../agent/BaseAgent'\nimport type { DidRecord } from '../../../../modules/dids'\n\nimport { DidDocumentRole, DidRepository } from '../../../../modules/dids'\n\n/**\n * Migrates the {@link DidRecord} to 0.4 compatible format. It fetches all did records from storage\n * with method sov and applies the needed updates to the records. After a record has been transformed, it is updated\n * in storage and the next record will be transformed.\n *\n * The following transformations are applied:\n *  - {@link migrateSovDidToIndyDid}\n */\nexport async function migrateDidRecordToV0_4<Agent extends BaseAgent>(agent: Agent) {\n  agent.config.logger.info('Migrating did records to storage version 0.4')\n  const didRepository = agent.dependencyManager.resolve(DidRepository)\n\n  agent.config.logger.debug('Fetching all did records with did method did:sov from storage')\n  const allSovDids = await didRepository.findByQuery(agent.context, {\n    method: 'sov',\n    role: DidDocumentRole.Created,\n  })\n\n  agent.config.logger.debug(`Found a total of ${allSovDids.length} did:sov did records to update.`)\n  for (const sovDidRecord of allSovDids) {\n    agent.config.logger.debug(`Migrating did:sov did record with id ${sovDidRecord.id} to storage version 0.4`)\n\n    const oldDid = sovDidRecord.did\n    migrateSovDidToIndyDid(agent, sovDidRecord)\n\n    // Save updated did record\n    await didRepository.update(agent.context, sovDidRecord)\n\n    agent.config.logger.debug(\n      `Successfully migrated did:sov did record with old did ${oldDid} to new did ${sovDidRecord.did} for storage version 0.4`\n    )\n  }\n}\n\nexport function migrateSovDidToIndyDid<Agent extends BaseAgent>(agent: Agent, didRecord: DidRecord) {\n  agent.config.logger.debug(\n    `Migrating did record with id ${didRecord.id} and did ${didRecord.did} to indy did for version 0.4`\n  )\n\n  const qualifiedIndyDid = didRecord.getTag('qualifiedIndyDid') as string\n\n  didRecord.did = qualifiedIndyDid\n\n  // Unset qualifiedIndyDid tag\n  didRecord.setTag('qualifiedIndyDid', undefined)\n}\n"],"mappings":";;;;;;;;;;;;AAaA,eAAsB,uBAAgD,OAAc;CAClF,MAAM,OAAO,OAAO,KAAK,8CAA8C;CACvE,MAAM,gBAAgB,MAAM,kBAAkB,QAAQ,aAAa;CAEnE,MAAM,OAAO,OAAO,MAAM,+DAA+D;CACzF,MAAM,aAAa,MAAM,cAAc,YAAY,MAAM,SAAS;EAChE,QAAQ;EACR,MAAA;CACF,CAAC;CAED,MAAM,OAAO,OAAO,MAAM,oBAAoB,WAAW,OAAO,gCAAgC;CAChG,KAAK,MAAM,gBAAgB,YAAY;EACrC,MAAM,OAAO,OAAO,MAAM,wCAAwC,aAAa,GAAG,wBAAwB;EAE1G,MAAM,SAAS,aAAa;EAC5B,uBAAuB,OAAO,YAAY;EAG1C,MAAM,cAAc,OAAO,MAAM,SAAS,YAAY;EAEtD,MAAM,OAAO,OAAO,MAClB,yDAAyD,OAAO,cAAc,aAAa,IAAI,yBACjG;CACF;AACF;AAEA,SAAgB,uBAAgD,OAAc,WAAsB;CAClG,MAAM,OAAO,OAAO,MAClB,gCAAgC,UAAU,GAAG,WAAW,UAAU,IAAI,6BACxE;CAIA,UAAU,MAFe,UAAU,OAAO,kBAEX;CAG/B,UAAU,OAAO,oBAAoB,KAAA,CAAS;AAChD"}