{"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;AAClF,OAAM,OAAO,OAAO,KAAK,+CAA+C;CACxE,MAAM,gBAAgB,MAAM,kBAAkB,QAAQ,cAAc;AAEpE,OAAM,OAAO,OAAO,MAAM,gEAAgE;CAC1F,MAAM,aAAa,MAAM,cAAc,YAAY,MAAM,SAAS;EAChE,QAAQ;EACR,MAAM,gBAAgB;EACvB,CAAC;AAEF,OAAM,OAAO,OAAO,MAAM,oBAAoB,WAAW,OAAO,iCAAiC;AACjG,MAAK,MAAM,gBAAgB,YAAY;AACrC,QAAM,OAAO,OAAO,MAAM,wCAAwC,aAAa,GAAG,yBAAyB;EAE3G,MAAM,SAAS,aAAa;AAC5B,yBAAuB,OAAO,aAAa;AAG3C,QAAM,cAAc,OAAO,MAAM,SAAS,aAAa;AAEvD,QAAM,OAAO,OAAO,MAClB,yDAAyD,OAAO,cAAc,aAAa,IAAI,0BAChG;;;AAIL,SAAgB,uBAAgD,OAAc,WAAsB;AAClG,OAAM,OAAO,OAAO,MAClB,gCAAgC,UAAU,GAAG,WAAW,UAAU,IAAI,8BACvE;AAID,WAAU,MAFe,UAAU,OAAO,mBAAmB;AAK7D,WAAU,OAAO,oBAAoB,OAAU"}