diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 2090bd358f..f551cb8d59 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -9,6 +9,7 @@ export type { ModulesMap, DefaultAgentModules, EmptyModuleMap } from './agent/Ag export { EventEmitter } from './agent/EventEmitter' export { FeatureRegistry } from './agent/FeatureRegistry' export { MessageHandler, MessageHandlerInboundMessage } from './agent/MessageHandler' +export { MessageHandlerRegistry } from './agent/MessageHandlerRegistry' export * from './agent/models' export { AgentConfig } from './agent/AgentConfig' export { AgentMessage } from './agent/AgentMessage' @@ -31,6 +32,7 @@ export { InMemoryMessageRepository } from './storage/InMemoryMessageRepository' export { Repository } from './storage/Repository' export * from './storage/RepositoryEvents' export { StorageService, Query } from './storage/StorageService' +export * from './storage/migration' export { getDirFromFilePath } from './utils/path' export { InjectionSymbols } from './constants' export * from './wallet' diff --git a/packages/core/src/storage/migration/__tests__/0.2.test.ts b/packages/core/src/storage/migration/__tests__/0.2.test.ts index 3003a203ab..b67e361855 100644 --- a/packages/core/src/storage/migration/__tests__/0.2.test.ts +++ b/packages/core/src/storage/migration/__tests__/0.2.test.ts @@ -20,7 +20,7 @@ const walletConfig = { key: `Key: 0.2 Update`, } -describe('UpdateAssistant | v0.2 - v0.3', () => { +describe('UpdateAssistant | v0.2 - v0.3.1', () => { it(`should correctly update proof records and create didcomm records`, async () => { // We need to mock the uuid generation to make sure we generate consistent uuids for the new records created. let uuidCounter = 1 @@ -67,6 +67,11 @@ describe('UpdateAssistant | v0.2 - v0.3', () => { toVersion: '0.3', doUpdate: expect.any(Function), }, + { + fromVersion: '0.3', + toVersion: '0.3.1', + doUpdate: expect.any(Function), + }, ]) await updateAssistant.update() @@ -141,4 +146,56 @@ describe('UpdateAssistant | v0.2 - v0.3', () => { uuidSpy.mockReset() }) + + it(`should correctly update the did records`, async () => { + // We need to mock the uuid generation to make sure we generate consistent uuids for the new records created. + let uuidCounter = 1 + const uuidSpy = jest.spyOn(uuid, 'uuid').mockImplementation(() => `${uuidCounter++}-4e4f-41d9-94c4-f49351b811f1`) + + const aliceDidRecordsString = readFileSync(path.join(__dirname, '__fixtures__/alice-8-dids-0.2.json'), 'utf8') + + const dependencyManager = new DependencyManager() + const storageService = new InMemoryStorageService() + dependencyManager.registerInstance(InjectionSymbols.StorageService, storageService) + + const agent = new Agent( + { + config: { + label: 'Test Agent', + walletConfig, + autoUpdateStorageOnStartup: true, + }, + dependencies: agentDependencies, + }, + dependencyManager + ) + + const fileSystem = agent.injectionContainer.resolve(InjectionSymbols.FileSystem) + + // We need to manually initialize the wallet as we're using the in memory wallet service + // When we call agent.initialize() it will create the wallet and store the current framework + // version in the in memory storage service. We need to manually set the records between initializing + // the wallet and calling agent.initialize() + await agent.wallet.initialize(walletConfig) + + // Set storage after initialization. This mimics as if this wallet + // is opened as an existing wallet instead of a new wallet + storageService.records = JSON.parse(aliceDidRecordsString) + + await agent.initialize() + + // MEDIATOR_ROUTING_RECORD recipientKeys will be different every time, and is not what we're testing here + delete storageService.records.MEDIATOR_ROUTING_RECORD + + expect(storageService.records).toMatchSnapshot() + + // Need to remove backupFiles after each run so we don't get IOErrors + const backupPath = `${fileSystem.basePath}/afj/migration/backup/${backupIdentifier}` + unlinkSync(backupPath) + + await agent.shutdown() + await agent.wallet.delete() + + uuidSpy.mockReset() + }) }) diff --git a/packages/core/src/storage/migration/__tests__/0.3.test.ts b/packages/core/src/storage/migration/__tests__/0.3.test.ts new file mode 100644 index 0000000000..a7ec0f6adb --- /dev/null +++ b/packages/core/src/storage/migration/__tests__/0.3.test.ts @@ -0,0 +1,87 @@ +import type { FileSystem } from '../../FileSystem' + +import { unlinkSync, readFileSync } from 'fs' +import path from 'path' + +import { InMemoryStorageService } from '../../../../../../tests/InMemoryStorageService' +import { agentDependencies } from '../../../../tests/helpers' +import { Agent } from '../../../agent/Agent' +import { InjectionSymbols } from '../../../constants' +import { DependencyManager } from '../../../plugins' +import * as uuid from '../../../utils/uuid' +import { UpdateAssistant } from '../UpdateAssistant' + +const backupDate = new Date('2022-01-21T22:50:20.522Z') +jest.useFakeTimers().setSystemTime(backupDate) +const backupIdentifier = backupDate.getTime() + +const walletConfig = { + id: `Wallet: 0.3 Update`, + key: `Key: 0.3 Update`, +} + +describe('UpdateAssistant | v0.3 - v0.3.1', () => { + it(`should correctly update the did records`, async () => { + // We need to mock the uuid generation to make sure we generate consistent uuids for the new records created. + let uuidCounter = 1 + const uuidSpy = jest.spyOn(uuid, 'uuid').mockImplementation(() => `${uuidCounter++}-4e4f-41d9-94c4-f49351b811f1`) + + const aliceDidRecordsString = readFileSync(path.join(__dirname, '__fixtures__/alice-8-dids-0.3.json'), 'utf8') + + const dependencyManager = new DependencyManager() + const storageService = new InMemoryStorageService() + dependencyManager.registerInstance(InjectionSymbols.StorageService, storageService) + + const agent = new Agent( + { + config: { + label: 'Test Agent', + walletConfig, + }, + dependencies: agentDependencies, + }, + dependencyManager + ) + + const fileSystem = agent.injectionContainer.resolve(InjectionSymbols.FileSystem) + + const updateAssistant = new UpdateAssistant(agent, { + v0_1ToV0_2: { + mediationRoleUpdateStrategy: 'doNotChange', + }, + }) + + await updateAssistant.initialize() + + // Set storage after initialization. This mimics as if this wallet + // is opened as an existing wallet instead of a new wallet + storageService.records = JSON.parse(aliceDidRecordsString) + + expect(await updateAssistant.isUpToDate()).toBe(false) + expect(await updateAssistant.getNeededUpdates()).toEqual([ + { + fromVersion: '0.3', + toVersion: '0.3.1', + doUpdate: expect.any(Function), + }, + ]) + + await updateAssistant.update() + + expect(await updateAssistant.isUpToDate()).toBe(true) + expect(await updateAssistant.getNeededUpdates()).toEqual([]) + + // MEDIATOR_ROUTING_RECORD recipientKeys will be different every time, and is not what we're testing here + delete storageService.records.MEDIATOR_ROUTING_RECORD + expect(storageService.records).toMatchSnapshot() + + // Need to remove backupFiles after each run so we don't get IOErrors + const backupPath = `${fileSystem.basePath}/afj/migration/backup/${backupIdentifier}` + unlinkSync(backupPath) + + await agent.shutdown() + await agent.wallet.delete() + + uuidSpy.mockReset() + }) +}) diff --git a/packages/core/src/storage/migration/__tests__/__fixtures__/alice-8-dids-0.2.json b/packages/core/src/storage/migration/__tests__/__fixtures__/alice-8-dids-0.2.json new file mode 100644 index 0000000000..e6ee2718a1 --- /dev/null +++ b/packages/core/src/storage/migration/__tests__/__fixtures__/alice-8-dids-0.2.json @@ -0,0 +1,417 @@ +{ + "STORAGE_VERSION_RECORD_ID": { + "value": { + "metadata": {}, + "id": "STORAGE_VERSION_RECORD_ID", + "createdAt": "2022-09-08T19:35:53.872Z", + "storageVersion": "0.2" + }, + "id": "STORAGE_VERSION_RECORD_ID", + "type": "StorageVersionRecord", + "tags": {} + }, + "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd": { + "value": { + "_tags": { + "role": "created", + "method": "peer", + "recipientKeyFingerprints": ["z6Mkpg6nDPuYdLMuzNEjaa2Xprh3J2MC1WtNakWUEFqC4wvU"] + }, + "metadata": {}, + "id": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "role": "created", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#57a05508-1d1c-474c-8c68-1afcf3188720"], + "routingKeys": [ + "did:key:z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop#z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop" + ] + } + ], + "authentication": [ + { + "id": "#57a05508-1d1c-474c-8c68-1afcf3188720", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "BDqjd9f7HnsSssQ2u14gym93UT5Lbde1tjbYPysB9j96" + } + ], + "keyAgreement": [ + { + "id": "#59d2ce6f-c9fc-49c6-a8f6-eab14820b028", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "avivQP6GvWj6cBbxbXSSZnZTA4tGsvQ5DB9FXm45tZt" + } + ] + }, + "createdAt": "2022-12-27T13:51:21.344Z" + }, + "id": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "type": "DidRecord", + "tags": { + "role": "created", + "method": "peer", + "recipientKeyFingerprints": ["z6Mkpg6nDPuYdLMuzNEjaa2Xprh3J2MC1WtNakWUEFqC4wvU"] + } + }, + "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W": { + "value": { + "_tags": { + "recipientKeyFingerprints": ["z6MkuLL6bQykGpposTrQhfYceQRR4JDzvdm133xpwb7Dv1oz"], + "role": "received", + "method": "peer" + }, + "metadata": {}, + "id": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "role": "received", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "http://ssi.verifier.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#6173438e-09a5-4b1e-895a-0563f5a169b7"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#6173438e-09a5-4b1e-895a-0563f5a169b7", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "Ft541AjJwHLLky1i26amoJsREix9WkWeM33u7K9Czo2c" + } + ], + "keyAgreement": [ + { + "id": "#a0448ee3-093a-4b16-bc59-8bf8559d60a5", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "JCfZJ72mtgGE9xuekJKV6yoAGzLgQCNkdHKkct8uaNKb" + } + ] + }, + "createdAt": "2022-12-27T13:51:51.414Z" + }, + "id": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "type": "DidRecord", + "tags": { + "role": "received", + "method": "peer", + "recipientKeyFingerprints": ["z6MkuLL6bQykGpposTrQhfYceQRR4JDzvdm133xpwb7Dv1oz"] + } + }, + "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q": { + "value": { + "_tags": { + "recipientKeyFingerprints": ["z6Mkv6Kd744JcBL5P9gi5Ddtehxn1gSMTgM9kbTdfQ9soB8G"], + "role": "created", + "method": "peer" + }, + "metadata": {}, + "id": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "role": "created", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "didcomm:transport/queue", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#d9d97b3e-5615-4e60-9366-a8ab1ec1a84d"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#d9d97b3e-5615-4e60-9366-a8ab1ec1a84d", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "Ge4aWoosGdqcGer1Peg3ocQnC7AW3o6o4aYhq8BrsxLt" + } + ], + "keyAgreement": [ + { + "id": "#c30ea91b-5f49-461f-b0bd-046f947ef668", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "HKBdBGRK8uxgCwge2QHPBzVuuayEQFhC2LM3g1fzMFGE" + } + ] + }, + "createdAt": "2022-12-27T13:50:32.815Z" + }, + "id": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "type": "DidRecord", + "tags": { + "role": "created", + "method": "peer", + "recipientKeyFingerprints": ["z6Mkv6Kd744JcBL5P9gi5Ddtehxn1gSMTgM9kbTdfQ9soB8G"] + } + }, + "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx": { + "value": { + "_tags": { + "method": "peer", + "recipientKeyFingerprints": ["z6MkvcuHjVcNRBM78E3xWy7MnVqQV9hAvTawBsPmg3bR1DaE"], + "role": "created" + }, + "metadata": {}, + "id": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "role": "created", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#22219a28-b52a-4024-bc0f-62d3969131fd"], + "routingKeys": [ + "did:key:z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop#z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop" + ] + } + ], + "authentication": [ + { + "id": "#22219a28-b52a-4024-bc0f-62d3969131fd", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "HAeF9FMw5dre1jDFqQ9WwQHQfaRKWaLaVrUqqmdQ5znr" + } + ], + "keyAgreement": [ + { + "id": "#0f9535d1-9c9c-4491-be1e-1628f365b513", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "FztF8HCahTeL9gYHoHnDFo6HruwnKB19ZtbHFbLndAmE" + } + ] + }, + "createdAt": "2022-12-27T13:51:50.193Z" + }, + "id": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "type": "DidRecord", + "tags": { + "role": "created", + "method": "peer", + "recipientKeyFingerprints": ["z6MkvcuHjVcNRBM78E3xWy7MnVqQV9hAvTawBsPmg3bR1DaE"] + } + }, + "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce": { + "value": { + "_tags": { + "method": "peer", + "role": "received", + "recipientKeyFingerprints": ["z6Mkp1wyxzqoUrZ3TvnerfZBq48o1XLDSPH8ibFALkNABSgh"] + }, + "metadata": {}, + "id": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "role": "received", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#075b7e8b-a7bd-41e1-9b01-044f1ccab1a6"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#075b7e8b-a7bd-41e1-9b01-044f1ccab1a6", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "AZgwNkbN9K4aMRwxB6bLyxaoBx4N2W2n2aLEWUQ9GDuK" + } + ], + "keyAgreement": [ + { + "id": "#bf888dc5-0f54-4e71-9058-c43bebfc7d01", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "3Q8wpgxdCVdJfznYERZR1r9eVnCy7oxpjzGVucDLF2tG" + } + ] + }, + "createdAt": "2022-12-27T13:50:44.957Z" + }, + "id": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "type": "DidRecord", + "tags": { + "role": "received", + "method": "peer", + "recipientKeyFingerprints": ["z6Mkp1wyxzqoUrZ3TvnerfZBq48o1XLDSPH8ibFALkNABSgh"] + } + }, + "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN": { + "value": { + "_tags": { + "role": "received", + "recipientKeyFingerprints": ["z6MkrQzQqPtNjJHGLGjWC7H3mjMSNA36bCBTYJeoR44JoFvH"], + "method": "peer" + }, + "metadata": {}, + "id": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "role": "received", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "ws://ssi.issuer.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#b6d349fb-93fb-4298-b57a-3f2fecffccd8"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#b6d349fb-93fb-4298-b57a-3f2fecffccd8", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "CxjNF9dwPknoDmtoWYKCvdoSYamFBJw6rHjsan6Ht38u" + } + ], + "keyAgreement": [ + { + "id": "#c0917f9f-1102-4f13-800c-ff7b522999eb", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "Eso3A6AmL5qiWr9syqHx8NgdQ8EMkYcitmrW5G7bX9uU" + } + ] + }, + "createdAt": "2022-12-27T13:50:34.057Z" + }, + "id": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "type": "DidRecord", + "tags": { + "role": "received", + "method": "peer", + "recipientKeyFingerprints": ["z6MkrQzQqPtNjJHGLGjWC7H3mjMSNA36bCBTYJeoR44JoFvH"] + } + }, + "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3": { + "value": { + "_tags": { + "method": "peer", + "recipientKeyFingerprints": ["z6Mkt4ohp4uT74HdENeGVGAyVFTerCzzuDXP8kpU3yo6SqqM"], + "role": "received" + }, + "metadata": {}, + "id": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "role": "received", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "http://ssi.verifier.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#5ea98568-dfcd-4614-9495-ba95ec2665d3"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#5ea98568-dfcd-4614-9495-ba95ec2665d3", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "EcYfDpf1mWoA7soZohD8e9uf2dj9VLH2SjuYDhq5Xd3y" + } + ], + "keyAgreement": [ + { + "id": "#506e5ead-ddbc-44ef-848b-6593a692a916", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "EeQHhb6CqWGrQR9PfWpS1L8CedsbK2mZfPdaxaHN4s8b" + } + ] + }, + "createdAt": "2022-12-27T13:51:22.817Z" + }, + "id": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "type": "DidRecord", + "tags": { + "role": "received", + "method": "peer", + "recipientKeyFingerprints": ["z6Mkt4ohp4uT74HdENeGVGAyVFTerCzzuDXP8kpU3yo6SqqM"] + } + }, + "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S": { + "value": { + "_tags": { + "method": "peer", + "recipientKeyFingerprints": ["z6MktdgEKUiH5kt5t2dKAH14WzFYhzj3JFobUf2PFFQAg2ma"], + "role": "created" + }, + "metadata": {}, + "id": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "role": "created", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "didcomm:transport/queue", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#12b8b7d4-87b9-4638-a929-f98df2f1f566"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#12b8b7d4-87b9-4638-a929-f98df2f1f566", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "FBRBjETqkDPcmXncUi3DfthYtRTBtNZEne7TQyS9kozC" + } + ], + "keyAgreement": [ + { + "id": "#77b9cf84-2441-419f-b295-945d06e29edc", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "EgsQArrmCUru9MxR1RNNiomnMFz6E3ia2GfjVvoCjAWY" + } + ] + }, + "createdAt": "2022-12-27T13:50:43.937Z" + }, + "id": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "type": "DidRecord", + "tags": { + "role": "created", + "method": "peer", + "recipientKeyFingerprints": ["z6MktdgEKUiH5kt5t2dKAH14WzFYhzj3JFobUf2PFFQAg2ma"] + } + } +} diff --git a/packages/core/src/storage/migration/__tests__/__fixtures__/alice-8-dids-0.3.json b/packages/core/src/storage/migration/__tests__/__fixtures__/alice-8-dids-0.3.json new file mode 100644 index 0000000000..c0a6597833 --- /dev/null +++ b/packages/core/src/storage/migration/__tests__/__fixtures__/alice-8-dids-0.3.json @@ -0,0 +1,417 @@ +{ + "STORAGE_VERSION_RECORD_ID": { + "value": { + "metadata": {}, + "id": "STORAGE_VERSION_RECORD_ID", + "createdAt": "2022-09-08T19:35:53.872Z", + "storageVersion": "0.3" + }, + "id": "STORAGE_VERSION_RECORD_ID", + "type": "StorageVersionRecord", + "tags": {} + }, + "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd": { + "value": { + "_tags": { + "role": "created", + "method": "peer", + "recipientKeyFingerprints": ["z6Mkpg6nDPuYdLMuzNEjaa2Xprh3J2MC1WtNakWUEFqC4wvU"] + }, + "metadata": {}, + "id": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "role": "created", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#57a05508-1d1c-474c-8c68-1afcf3188720"], + "routingKeys": [ + "did:key:z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop#z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop" + ] + } + ], + "authentication": [ + { + "id": "#57a05508-1d1c-474c-8c68-1afcf3188720", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "BDqjd9f7HnsSssQ2u14gym93UT5Lbde1tjbYPysB9j96" + } + ], + "keyAgreement": [ + { + "id": "#59d2ce6f-c9fc-49c6-a8f6-eab14820b028", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "avivQP6GvWj6cBbxbXSSZnZTA4tGsvQ5DB9FXm45tZt" + } + ] + }, + "createdAt": "2022-12-27T13:51:21.344Z" + }, + "id": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "type": "DidRecord", + "tags": { + "role": "created", + "method": "peer", + "recipientKeyFingerprints": ["z6Mkpg6nDPuYdLMuzNEjaa2Xprh3J2MC1WtNakWUEFqC4wvU"] + } + }, + "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W": { + "value": { + "_tags": { + "recipientKeyFingerprints": ["z6MkuLL6bQykGpposTrQhfYceQRR4JDzvdm133xpwb7Dv1oz"], + "role": "received", + "method": "peer" + }, + "metadata": {}, + "id": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "role": "received", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "http://ssi.verifier.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#6173438e-09a5-4b1e-895a-0563f5a169b7"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#6173438e-09a5-4b1e-895a-0563f5a169b7", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "Ft541AjJwHLLky1i26amoJsREix9WkWeM33u7K9Czo2c" + } + ], + "keyAgreement": [ + { + "id": "#a0448ee3-093a-4b16-bc59-8bf8559d60a5", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "JCfZJ72mtgGE9xuekJKV6yoAGzLgQCNkdHKkct8uaNKb" + } + ] + }, + "createdAt": "2022-12-27T13:51:51.414Z" + }, + "id": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "type": "DidRecord", + "tags": { + "role": "received", + "method": "peer", + "recipientKeyFingerprints": ["z6MkuLL6bQykGpposTrQhfYceQRR4JDzvdm133xpwb7Dv1oz"] + } + }, + "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q": { + "value": { + "_tags": { + "recipientKeyFingerprints": ["z6Mkv6Kd744JcBL5P9gi5Ddtehxn1gSMTgM9kbTdfQ9soB8G"], + "role": "created", + "method": "peer" + }, + "metadata": {}, + "id": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "role": "created", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "didcomm:transport/queue", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#d9d97b3e-5615-4e60-9366-a8ab1ec1a84d"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#d9d97b3e-5615-4e60-9366-a8ab1ec1a84d", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "Ge4aWoosGdqcGer1Peg3ocQnC7AW3o6o4aYhq8BrsxLt" + } + ], + "keyAgreement": [ + { + "id": "#c30ea91b-5f49-461f-b0bd-046f947ef668", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "HKBdBGRK8uxgCwge2QHPBzVuuayEQFhC2LM3g1fzMFGE" + } + ] + }, + "createdAt": "2022-12-27T13:50:32.815Z" + }, + "id": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "type": "DidRecord", + "tags": { + "role": "created", + "method": "peer", + "recipientKeyFingerprints": ["z6Mkv6Kd744JcBL5P9gi5Ddtehxn1gSMTgM9kbTdfQ9soB8G"] + } + }, + "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx": { + "value": { + "_tags": { + "method": "peer", + "recipientKeyFingerprints": ["z6MkvcuHjVcNRBM78E3xWy7MnVqQV9hAvTawBsPmg3bR1DaE"], + "role": "created" + }, + "metadata": {}, + "id": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "role": "created", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#22219a28-b52a-4024-bc0f-62d3969131fd"], + "routingKeys": [ + "did:key:z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop#z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop" + ] + } + ], + "authentication": [ + { + "id": "#22219a28-b52a-4024-bc0f-62d3969131fd", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "HAeF9FMw5dre1jDFqQ9WwQHQfaRKWaLaVrUqqmdQ5znr" + } + ], + "keyAgreement": [ + { + "id": "#0f9535d1-9c9c-4491-be1e-1628f365b513", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "FztF8HCahTeL9gYHoHnDFo6HruwnKB19ZtbHFbLndAmE" + } + ] + }, + "createdAt": "2022-12-27T13:51:50.193Z" + }, + "id": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "type": "DidRecord", + "tags": { + "role": "created", + "method": "peer", + "recipientKeyFingerprints": ["z6MkvcuHjVcNRBM78E3xWy7MnVqQV9hAvTawBsPmg3bR1DaE"] + } + }, + "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce": { + "value": { + "_tags": { + "method": "peer", + "role": "received", + "recipientKeyFingerprints": ["z6Mkp1wyxzqoUrZ3TvnerfZBq48o1XLDSPH8ibFALkNABSgh"] + }, + "metadata": {}, + "id": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "role": "received", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#075b7e8b-a7bd-41e1-9b01-044f1ccab1a6"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#075b7e8b-a7bd-41e1-9b01-044f1ccab1a6", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "AZgwNkbN9K4aMRwxB6bLyxaoBx4N2W2n2aLEWUQ9GDuK" + } + ], + "keyAgreement": [ + { + "id": "#bf888dc5-0f54-4e71-9058-c43bebfc7d01", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "3Q8wpgxdCVdJfznYERZR1r9eVnCy7oxpjzGVucDLF2tG" + } + ] + }, + "createdAt": "2022-12-27T13:50:44.957Z" + }, + "id": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "type": "DidRecord", + "tags": { + "role": "received", + "method": "peer", + "recipientKeyFingerprints": ["z6Mkp1wyxzqoUrZ3TvnerfZBq48o1XLDSPH8ibFALkNABSgh"] + } + }, + "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN": { + "value": { + "_tags": { + "role": "received", + "recipientKeyFingerprints": ["z6MkrQzQqPtNjJHGLGjWC7H3mjMSNA36bCBTYJeoR44JoFvH"], + "method": "peer" + }, + "metadata": {}, + "id": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "role": "received", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "ws://ssi.issuer.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#b6d349fb-93fb-4298-b57a-3f2fecffccd8"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#b6d349fb-93fb-4298-b57a-3f2fecffccd8", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "CxjNF9dwPknoDmtoWYKCvdoSYamFBJw6rHjsan6Ht38u" + } + ], + "keyAgreement": [ + { + "id": "#c0917f9f-1102-4f13-800c-ff7b522999eb", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "Eso3A6AmL5qiWr9syqHx8NgdQ8EMkYcitmrW5G7bX9uU" + } + ] + }, + "createdAt": "2022-12-27T13:50:34.057Z" + }, + "id": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "type": "DidRecord", + "tags": { + "role": "received", + "method": "peer", + "recipientKeyFingerprints": ["z6MkrQzQqPtNjJHGLGjWC7H3mjMSNA36bCBTYJeoR44JoFvH"] + } + }, + "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3": { + "value": { + "_tags": { + "method": "peer", + "recipientKeyFingerprints": ["z6Mkt4ohp4uT74HdENeGVGAyVFTerCzzuDXP8kpU3yo6SqqM"], + "role": "received" + }, + "metadata": {}, + "id": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "role": "received", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "http://ssi.verifier.com", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#5ea98568-dfcd-4614-9495-ba95ec2665d3"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#5ea98568-dfcd-4614-9495-ba95ec2665d3", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "EcYfDpf1mWoA7soZohD8e9uf2dj9VLH2SjuYDhq5Xd3y" + } + ], + "keyAgreement": [ + { + "id": "#506e5ead-ddbc-44ef-848b-6593a692a916", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "EeQHhb6CqWGrQR9PfWpS1L8CedsbK2mZfPdaxaHN4s8b" + } + ] + }, + "createdAt": "2022-12-27T13:51:22.817Z" + }, + "id": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "type": "DidRecord", + "tags": { + "role": "received", + "method": "peer", + "recipientKeyFingerprints": ["z6Mkt4ohp4uT74HdENeGVGAyVFTerCzzuDXP8kpU3yo6SqqM"] + } + }, + "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S": { + "value": { + "_tags": { + "method": "peer", + "recipientKeyFingerprints": ["z6MktdgEKUiH5kt5t2dKAH14WzFYhzj3JFobUf2PFFQAg2ma"], + "role": "created" + }, + "metadata": {}, + "id": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "role": "created", + "didDocument": { + "@context": ["https://w3id.org/did/v1"], + "id": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "service": [ + { + "id": "#inline-0", + "serviceEndpoint": "didcomm:transport/queue", + "type": "did-communication", + "priority": 0, + "recipientKeys": ["#12b8b7d4-87b9-4638-a929-f98df2f1f566"], + "routingKeys": [] + } + ], + "authentication": [ + { + "id": "#12b8b7d4-87b9-4638-a929-f98df2f1f566", + "type": "Ed25519VerificationKey2018", + "controller": "#id", + "publicKeyBase58": "FBRBjETqkDPcmXncUi3DfthYtRTBtNZEne7TQyS9kozC" + } + ], + "keyAgreement": [ + { + "id": "#77b9cf84-2441-419f-b295-945d06e29edc", + "type": "X25519KeyAgreementKey2019", + "controller": "#id", + "publicKeyBase58": "EgsQArrmCUru9MxR1RNNiomnMFz6E3ia2GfjVvoCjAWY" + } + ] + }, + "createdAt": "2022-12-27T13:50:43.937Z" + }, + "id": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "type": "DidRecord", + "tags": { + "role": "created", + "method": "peer", + "recipientKeyFingerprints": ["z6MktdgEKUiH5kt5t2dKAH14WzFYhzj3JFobUf2PFFQAg2ma"] + } + } +} diff --git a/packages/core/src/storage/migration/__tests__/__snapshots__/0.2.test.ts.snap b/packages/core/src/storage/migration/__tests__/__snapshots__/0.2.test.ts.snap index f46399930f..a56e8065c1 100644 --- a/packages/core/src/storage/migration/__tests__/__snapshots__/0.2.test.ts.snap +++ b/packages/core/src/storage/migration/__tests__/__snapshots__/0.2.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`UpdateAssistant | v0.2 - v0.3 should correctly update proof records and create didcomm records 1`] = ` +exports[`UpdateAssistant | v0.2 - v0.3.1 should correctly update proof records and create didcomm records 1`] = ` Object { "3d5d7ad4-f0aa-4b1b-8c2c-780ee383564e": Object { "id": "3d5d7ad4-f0aa-4b1b-8c2c-780ee383564e", @@ -121,7 +121,7 @@ Object { "createdAt": "2022-09-08T19:35:53.872Z", "id": "STORAGE_VERSION_RECORD_ID", "metadata": Object {}, - "storageVersion": "0.3", + "storageVersion": "0.3.1", }, }, "ea840186-3c77-45f4-a2e6-349811ad8994": Object { @@ -238,7 +238,523 @@ Object { } `; -exports[`UpdateAssistant | v0.2 - v0.3 should correctly update the proofs records and create didcomm records with auto update 1`] = ` +exports[`UpdateAssistant | v0.2 - v0.3.1 should correctly update the did records 1`] = ` +Object { + "1-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "1-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "recipientKeyFingerprints": Array [ + "z6Mkpg6nDPuYdLMuzNEjaa2Xprh3J2MC1WtNakWUEFqC4wvU", + ], + "role": "created", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6Mkpg6nDPuYdLMuzNEjaa2Xprh3J2MC1WtNakWUEFqC4wvU", + ], + "role": "created", + }, + "createdAt": "2022-12-27T13:51:21.344Z", + "did": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#57a05508-1d1c-474c-8c68-1afcf3188720", + "publicKeyBase58": "BDqjd9f7HnsSssQ2u14gym93UT5Lbde1tjbYPysB9j96", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#59d2ce6f-c9fc-49c6-a8f6-eab14820b028", + "publicKeyBase58": "avivQP6GvWj6cBbxbXSSZnZTA4tGsvQ5DB9FXm45tZt", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#57a05508-1d1c-474c-8c68-1afcf3188720", + ], + "routingKeys": Array [ + "did:key:z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop#z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop", + ], + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + }, + ], + }, + "id": "1-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "created", + }, + }, + "2-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "2-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "recipientKeyFingerprints": Array [ + "z6MkuLL6bQykGpposTrQhfYceQRR4JDzvdm133xpwb7Dv1oz", + ], + "role": "received", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6MkuLL6bQykGpposTrQhfYceQRR4JDzvdm133xpwb7Dv1oz", + ], + "role": "received", + }, + "createdAt": "2022-12-27T13:51:51.414Z", + "did": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#6173438e-09a5-4b1e-895a-0563f5a169b7", + "publicKeyBase58": "Ft541AjJwHLLky1i26amoJsREix9WkWeM33u7K9Czo2c", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#a0448ee3-093a-4b16-bc59-8bf8559d60a5", + "publicKeyBase58": "JCfZJ72mtgGE9xuekJKV6yoAGzLgQCNkdHKkct8uaNKb", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#6173438e-09a5-4b1e-895a-0563f5a169b7", + ], + "routingKeys": Array [], + "serviceEndpoint": "http://ssi.verifier.com", + "type": "did-communication", + }, + ], + }, + "id": "2-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "received", + }, + }, + "3-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "3-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "recipientKeyFingerprints": Array [ + "z6Mkv6Kd744JcBL5P9gi5Ddtehxn1gSMTgM9kbTdfQ9soB8G", + ], + "role": "created", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6Mkv6Kd744JcBL5P9gi5Ddtehxn1gSMTgM9kbTdfQ9soB8G", + ], + "role": "created", + }, + "createdAt": "2022-12-27T13:50:32.815Z", + "did": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#d9d97b3e-5615-4e60-9366-a8ab1ec1a84d", + "publicKeyBase58": "Ge4aWoosGdqcGer1Peg3ocQnC7AW3o6o4aYhq8BrsxLt", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#c30ea91b-5f49-461f-b0bd-046f947ef668", + "publicKeyBase58": "HKBdBGRK8uxgCwge2QHPBzVuuayEQFhC2LM3g1fzMFGE", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#d9d97b3e-5615-4e60-9366-a8ab1ec1a84d", + ], + "routingKeys": Array [], + "serviceEndpoint": "didcomm:transport/queue", + "type": "did-communication", + }, + ], + }, + "id": "3-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "created", + }, + }, + "4-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "4-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "recipientKeyFingerprints": Array [ + "z6MkvcuHjVcNRBM78E3xWy7MnVqQV9hAvTawBsPmg3bR1DaE", + ], + "role": "created", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6MkvcuHjVcNRBM78E3xWy7MnVqQV9hAvTawBsPmg3bR1DaE", + ], + "role": "created", + }, + "createdAt": "2022-12-27T13:51:50.193Z", + "did": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#22219a28-b52a-4024-bc0f-62d3969131fd", + "publicKeyBase58": "HAeF9FMw5dre1jDFqQ9WwQHQfaRKWaLaVrUqqmdQ5znr", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#0f9535d1-9c9c-4491-be1e-1628f365b513", + "publicKeyBase58": "FztF8HCahTeL9gYHoHnDFo6HruwnKB19ZtbHFbLndAmE", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#22219a28-b52a-4024-bc0f-62d3969131fd", + ], + "routingKeys": Array [ + "did:key:z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop#z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop", + ], + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + }, + ], + }, + "id": "4-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "created", + }, + }, + "5-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "5-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "recipientKeyFingerprints": Array [ + "z6Mkp1wyxzqoUrZ3TvnerfZBq48o1XLDSPH8ibFALkNABSgh", + ], + "role": "received", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6Mkp1wyxzqoUrZ3TvnerfZBq48o1XLDSPH8ibFALkNABSgh", + ], + "role": "received", + }, + "createdAt": "2022-12-27T13:50:44.957Z", + "did": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#075b7e8b-a7bd-41e1-9b01-044f1ccab1a6", + "publicKeyBase58": "AZgwNkbN9K4aMRwxB6bLyxaoBx4N2W2n2aLEWUQ9GDuK", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#bf888dc5-0f54-4e71-9058-c43bebfc7d01", + "publicKeyBase58": "3Q8wpgxdCVdJfznYERZR1r9eVnCy7oxpjzGVucDLF2tG", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#075b7e8b-a7bd-41e1-9b01-044f1ccab1a6", + ], + "routingKeys": Array [], + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + }, + ], + }, + "id": "5-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "received", + }, + }, + "6-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "6-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "recipientKeyFingerprints": Array [ + "z6MkrQzQqPtNjJHGLGjWC7H3mjMSNA36bCBTYJeoR44JoFvH", + ], + "role": "received", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6MkrQzQqPtNjJHGLGjWC7H3mjMSNA36bCBTYJeoR44JoFvH", + ], + "role": "received", + }, + "createdAt": "2022-12-27T13:50:34.057Z", + "did": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#b6d349fb-93fb-4298-b57a-3f2fecffccd8", + "publicKeyBase58": "CxjNF9dwPknoDmtoWYKCvdoSYamFBJw6rHjsan6Ht38u", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#c0917f9f-1102-4f13-800c-ff7b522999eb", + "publicKeyBase58": "Eso3A6AmL5qiWr9syqHx8NgdQ8EMkYcitmrW5G7bX9uU", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#b6d349fb-93fb-4298-b57a-3f2fecffccd8", + ], + "routingKeys": Array [], + "serviceEndpoint": "ws://ssi.issuer.com", + "type": "did-communication", + }, + ], + }, + "id": "6-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "received", + }, + }, + "7-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "7-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "recipientKeyFingerprints": Array [ + "z6Mkt4ohp4uT74HdENeGVGAyVFTerCzzuDXP8kpU3yo6SqqM", + ], + "role": "received", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6Mkt4ohp4uT74HdENeGVGAyVFTerCzzuDXP8kpU3yo6SqqM", + ], + "role": "received", + }, + "createdAt": "2022-12-27T13:51:22.817Z", + "did": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#5ea98568-dfcd-4614-9495-ba95ec2665d3", + "publicKeyBase58": "EcYfDpf1mWoA7soZohD8e9uf2dj9VLH2SjuYDhq5Xd3y", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#506e5ead-ddbc-44ef-848b-6593a692a916", + "publicKeyBase58": "EeQHhb6CqWGrQR9PfWpS1L8CedsbK2mZfPdaxaHN4s8b", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#5ea98568-dfcd-4614-9495-ba95ec2665d3", + ], + "routingKeys": Array [], + "serviceEndpoint": "http://ssi.verifier.com", + "type": "did-communication", + }, + ], + }, + "id": "7-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "received", + }, + }, + "8-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "8-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "recipientKeyFingerprints": Array [ + "z6MktdgEKUiH5kt5t2dKAH14WzFYhzj3JFobUf2PFFQAg2ma", + ], + "role": "created", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6MktdgEKUiH5kt5t2dKAH14WzFYhzj3JFobUf2PFFQAg2ma", + ], + "role": "created", + }, + "createdAt": "2022-12-27T13:50:43.937Z", + "did": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#12b8b7d4-87b9-4638-a929-f98df2f1f566", + "publicKeyBase58": "FBRBjETqkDPcmXncUi3DfthYtRTBtNZEne7TQyS9kozC", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#77b9cf84-2441-419f-b295-945d06e29edc", + "publicKeyBase58": "EgsQArrmCUru9MxR1RNNiomnMFz6E3ia2GfjVvoCjAWY", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#12b8b7d4-87b9-4638-a929-f98df2f1f566", + ], + "routingKeys": Array [], + "serviceEndpoint": "didcomm:transport/queue", + "type": "did-communication", + }, + ], + }, + "id": "8-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "created", + }, + }, + "STORAGE_VERSION_RECORD_ID": Object { + "id": "STORAGE_VERSION_RECORD_ID", + "tags": Object {}, + "type": "StorageVersionRecord", + "value": Object { + "createdAt": "2022-09-08T19:35:53.872Z", + "id": "STORAGE_VERSION_RECORD_ID", + "metadata": Object {}, + "storageVersion": "0.3.1", + }, + }, +} +`; + +exports[`UpdateAssistant | v0.2 - v0.3.1 should correctly update the proofs records and create didcomm records with auto update 1`] = ` Object { "3d5d7ad4-f0aa-4b1b-8c2c-780ee383564e": Object { "id": "3d5d7ad4-f0aa-4b1b-8c2c-780ee383564e", @@ -359,7 +875,7 @@ Object { "createdAt": "2022-09-08T19:35:53.872Z", "id": "STORAGE_VERSION_RECORD_ID", "metadata": Object {}, - "storageVersion": "0.3", + "storageVersion": "0.3.1", }, }, "ea840186-3c77-45f4-a2e6-349811ad8994": Object { diff --git a/packages/core/src/storage/migration/__tests__/__snapshots__/0.3.test.ts.snap b/packages/core/src/storage/migration/__tests__/__snapshots__/0.3.test.ts.snap new file mode 100644 index 0000000000..8169373e57 --- /dev/null +++ b/packages/core/src/storage/migration/__tests__/__snapshots__/0.3.test.ts.snap @@ -0,0 +1,517 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`UpdateAssistant | v0.3 - v0.3.1 should correctly update the did records 1`] = ` +Object { + "1-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "1-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "recipientKeyFingerprints": Array [ + "z6Mkpg6nDPuYdLMuzNEjaa2Xprh3J2MC1WtNakWUEFqC4wvU", + ], + "role": "created", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6Mkpg6nDPuYdLMuzNEjaa2Xprh3J2MC1WtNakWUEFqC4wvU", + ], + "role": "created", + }, + "createdAt": "2022-12-27T13:51:21.344Z", + "did": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#57a05508-1d1c-474c-8c68-1afcf3188720", + "publicKeyBase58": "BDqjd9f7HnsSssQ2u14gym93UT5Lbde1tjbYPysB9j96", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmWxKCTkKYQvzdUshMWy7b8vy3Y7uLtB9hp6BbQhKEtQCd", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#59d2ce6f-c9fc-49c6-a8f6-eab14820b028", + "publicKeyBase58": "avivQP6GvWj6cBbxbXSSZnZTA4tGsvQ5DB9FXm45tZt", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#57a05508-1d1c-474c-8c68-1afcf3188720", + ], + "routingKeys": Array [ + "did:key:z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop#z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop", + ], + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + }, + ], + }, + "id": "1-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "created", + }, + }, + "2-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "2-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "recipientKeyFingerprints": Array [ + "z6MkuLL6bQykGpposTrQhfYceQRR4JDzvdm133xpwb7Dv1oz", + ], + "role": "received", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6MkuLL6bQykGpposTrQhfYceQRR4JDzvdm133xpwb7Dv1oz", + ], + "role": "received", + }, + "createdAt": "2022-12-27T13:51:51.414Z", + "did": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#6173438e-09a5-4b1e-895a-0563f5a169b7", + "publicKeyBase58": "Ft541AjJwHLLky1i26amoJsREix9WkWeM33u7K9Czo2c", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmavZzrLPRYRGd5CgyKV4GBZG43eGzjic9FHXc7jLHY14W", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#a0448ee3-093a-4b16-bc59-8bf8559d60a5", + "publicKeyBase58": "JCfZJ72mtgGE9xuekJKV6yoAGzLgQCNkdHKkct8uaNKb", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#6173438e-09a5-4b1e-895a-0563f5a169b7", + ], + "routingKeys": Array [], + "serviceEndpoint": "http://ssi.verifier.com", + "type": "did-communication", + }, + ], + }, + "id": "2-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "received", + }, + }, + "3-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "3-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "recipientKeyFingerprints": Array [ + "z6Mkv6Kd744JcBL5P9gi5Ddtehxn1gSMTgM9kbTdfQ9soB8G", + ], + "role": "created", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6Mkv6Kd744JcBL5P9gi5Ddtehxn1gSMTgM9kbTdfQ9soB8G", + ], + "role": "created", + }, + "createdAt": "2022-12-27T13:50:32.815Z", + "did": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#d9d97b3e-5615-4e60-9366-a8ab1ec1a84d", + "publicKeyBase58": "Ge4aWoosGdqcGer1Peg3ocQnC7AW3o6o4aYhq8BrsxLt", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmZqQYzwqsYjj7z8kixxDXf9nux8TAsqj2izSpX1oCrd7q", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#c30ea91b-5f49-461f-b0bd-046f947ef668", + "publicKeyBase58": "HKBdBGRK8uxgCwge2QHPBzVuuayEQFhC2LM3g1fzMFGE", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#d9d97b3e-5615-4e60-9366-a8ab1ec1a84d", + ], + "routingKeys": Array [], + "serviceEndpoint": "didcomm:transport/queue", + "type": "did-communication", + }, + ], + }, + "id": "3-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "created", + }, + }, + "4-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "4-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "recipientKeyFingerprints": Array [ + "z6MkvcuHjVcNRBM78E3xWy7MnVqQV9hAvTawBsPmg3bR1DaE", + ], + "role": "created", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6MkvcuHjVcNRBM78E3xWy7MnVqQV9hAvTawBsPmg3bR1DaE", + ], + "role": "created", + }, + "createdAt": "2022-12-27T13:51:50.193Z", + "did": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#22219a28-b52a-4024-bc0f-62d3969131fd", + "publicKeyBase58": "HAeF9FMw5dre1jDFqQ9WwQHQfaRKWaLaVrUqqmdQ5znr", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmRnGYmYBdSinH2953ZgfHWEpqp5W6kJmmYBgRaCs4Yudx", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#0f9535d1-9c9c-4491-be1e-1628f365b513", + "publicKeyBase58": "FztF8HCahTeL9gYHoHnDFo6HruwnKB19ZtbHFbLndAmE", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#22219a28-b52a-4024-bc0f-62d3969131fd", + ], + "routingKeys": Array [ + "did:key:z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop#z6MkqhwtVT5V6kwsNkErPNgSWuRGd4QLFQ324FMfw5oWGHop", + ], + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + }, + ], + }, + "id": "4-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "created", + }, + }, + "5-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "5-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "recipientKeyFingerprints": Array [ + "z6Mkp1wyxzqoUrZ3TvnerfZBq48o1XLDSPH8ibFALkNABSgh", + ], + "role": "received", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6Mkp1wyxzqoUrZ3TvnerfZBq48o1XLDSPH8ibFALkNABSgh", + ], + "role": "received", + }, + "createdAt": "2022-12-27T13:50:44.957Z", + "did": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#075b7e8b-a7bd-41e1-9b01-044f1ccab1a6", + "publicKeyBase58": "AZgwNkbN9K4aMRwxB6bLyxaoBx4N2W2n2aLEWUQ9GDuK", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmb9oo8fn8AZ7rWh1DAfTbM3mnPp9Hq2bJFdHiqjnZX2Ce", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#bf888dc5-0f54-4e71-9058-c43bebfc7d01", + "publicKeyBase58": "3Q8wpgxdCVdJfznYERZR1r9eVnCy7oxpjzGVucDLF2tG", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#075b7e8b-a7bd-41e1-9b01-044f1ccab1a6", + ], + "routingKeys": Array [], + "serviceEndpoint": "ws://ssi.mediator.com", + "type": "did-communication", + }, + ], + }, + "id": "5-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "received", + }, + }, + "6-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "6-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "recipientKeyFingerprints": Array [ + "z6MkrQzQqPtNjJHGLGjWC7H3mjMSNA36bCBTYJeoR44JoFvH", + ], + "role": "received", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6MkrQzQqPtNjJHGLGjWC7H3mjMSNA36bCBTYJeoR44JoFvH", + ], + "role": "received", + }, + "createdAt": "2022-12-27T13:50:34.057Z", + "did": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#b6d349fb-93fb-4298-b57a-3f2fecffccd8", + "publicKeyBase58": "CxjNF9dwPknoDmtoWYKCvdoSYamFBJw6rHjsan6Ht38u", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmSzC6uhWYcxtkr2fBepr66kjvSHuRsSfbmei7nrGj7HfN", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#c0917f9f-1102-4f13-800c-ff7b522999eb", + "publicKeyBase58": "Eso3A6AmL5qiWr9syqHx8NgdQ8EMkYcitmrW5G7bX9uU", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#b6d349fb-93fb-4298-b57a-3f2fecffccd8", + ], + "routingKeys": Array [], + "serviceEndpoint": "ws://ssi.issuer.com", + "type": "did-communication", + }, + ], + }, + "id": "6-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "received", + }, + }, + "7-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "7-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "recipientKeyFingerprints": Array [ + "z6Mkt4ohp4uT74HdENeGVGAyVFTerCzzuDXP8kpU3yo6SqqM", + ], + "role": "received", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6Mkt4ohp4uT74HdENeGVGAyVFTerCzzuDXP8kpU3yo6SqqM", + ], + "role": "received", + }, + "createdAt": "2022-12-27T13:51:22.817Z", + "did": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#5ea98568-dfcd-4614-9495-ba95ec2665d3", + "publicKeyBase58": "EcYfDpf1mWoA7soZohD8e9uf2dj9VLH2SjuYDhq5Xd3y", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmPaCELen1JWMWmhVZS16nDmrAC9yGKQcJCcBs5spXakA3", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#506e5ead-ddbc-44ef-848b-6593a692a916", + "publicKeyBase58": "EeQHhb6CqWGrQR9PfWpS1L8CedsbK2mZfPdaxaHN4s8b", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#5ea98568-dfcd-4614-9495-ba95ec2665d3", + ], + "routingKeys": Array [], + "serviceEndpoint": "http://ssi.verifier.com", + "type": "did-communication", + }, + ], + }, + "id": "7-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "received", + }, + }, + "8-4e4f-41d9-94c4-f49351b811f1": Object { + "id": "8-4e4f-41d9-94c4-f49351b811f1", + "tags": Object { + "did": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "legacyUnqualifiedDid": undefined, + "method": "peer", + "methodSpecificIdentifier": "1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "recipientKeyFingerprints": Array [ + "z6MktdgEKUiH5kt5t2dKAH14WzFYhzj3JFobUf2PFFQAg2ma", + ], + "role": "created", + }, + "type": "DidRecord", + "value": Object { + "_tags": Object { + "method": "peer", + "recipientKeyFingerprints": Array [ + "z6MktdgEKUiH5kt5t2dKAH14WzFYhzj3JFobUf2PFFQAg2ma", + ], + "role": "created", + }, + "createdAt": "2022-12-27T13:50:43.937Z", + "did": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "didDocument": Object { + "@context": Array [ + "https://w3id.org/did/v1", + ], + "authentication": Array [ + Object { + "controller": "#id", + "id": "#12b8b7d4-87b9-4638-a929-f98df2f1f566", + "publicKeyBase58": "FBRBjETqkDPcmXncUi3DfthYtRTBtNZEne7TQyS9kozC", + "type": "Ed25519VerificationKey2018", + }, + ], + "id": "did:peer:1zQmUo1HoiciJS628w4SHweg4Pzs4bZLM4KLZgroSmUwBw7S", + "keyAgreement": Array [ + Object { + "controller": "#id", + "id": "#77b9cf84-2441-419f-b295-945d06e29edc", + "publicKeyBase58": "EgsQArrmCUru9MxR1RNNiomnMFz6E3ia2GfjVvoCjAWY", + "type": "X25519KeyAgreementKey2019", + }, + ], + "service": Array [ + Object { + "id": "#inline-0", + "priority": 0, + "recipientKeys": Array [ + "#12b8b7d4-87b9-4638-a929-f98df2f1f566", + ], + "routingKeys": Array [], + "serviceEndpoint": "didcomm:transport/queue", + "type": "did-communication", + }, + ], + }, + "id": "8-4e4f-41d9-94c4-f49351b811f1", + "metadata": Object {}, + "role": "created", + }, + }, + "STORAGE_VERSION_RECORD_ID": Object { + "id": "STORAGE_VERSION_RECORD_ID", + "tags": Object {}, + "type": "StorageVersionRecord", + "value": Object { + "createdAt": "2022-09-08T19:35:53.872Z", + "id": "STORAGE_VERSION_RECORD_ID", + "metadata": Object {}, + "storageVersion": "0.3.1", + }, + }, +} +`; diff --git a/packages/core/src/storage/migration/index.ts b/packages/core/src/storage/migration/index.ts index e59ac63479..c908e9655d 100644 --- a/packages/core/src/storage/migration/index.ts +++ b/packages/core/src/storage/migration/index.ts @@ -1,3 +1,4 @@ export * from './repository/StorageVersionRecord' export * from './repository/StorageVersionRepository' export * from './StorageUpdateService' +export * from './UpdateAssistant' diff --git a/packages/core/src/storage/migration/updates.ts b/packages/core/src/storage/migration/updates.ts index d079287e61..08c890fdd0 100644 --- a/packages/core/src/storage/migration/updates.ts +++ b/packages/core/src/storage/migration/updates.ts @@ -4,6 +4,7 @@ import type { V0_1ToV0_2UpdateConfig } from './updates/0.1-0.2' import { updateV0_1ToV0_2 } from './updates/0.1-0.2' import { updateV0_2ToV0_3 } from './updates/0.2-0.3' +import { updateV0_3ToV0_3_1 } from './updates/0.3-0.3.1' export const INITIAL_STORAGE_VERSION = '0.1' @@ -34,6 +35,11 @@ export const supportedUpdates = [ toVersion: '0.3', doUpdate: updateV0_2ToV0_3, }, + { + fromVersion: '0.3', + toVersion: '0.3.1', + doUpdate: updateV0_3ToV0_3_1, + }, ] as const // Current version is last toVersion from the supported updates diff --git a/packages/core/src/storage/migration/updates/0.2-0.3/__tests__/did.test.ts b/packages/core/src/storage/migration/updates/0.3-0.3.1/__tests__/did.test.ts similarity index 90% rename from packages/core/src/storage/migration/updates/0.2-0.3/__tests__/did.test.ts rename to packages/core/src/storage/migration/updates/0.3-0.3.1/__tests__/did.test.ts index 2f4bd97710..7ce585b93a 100644 --- a/packages/core/src/storage/migration/updates/0.2-0.3/__tests__/did.test.ts +++ b/packages/core/src/storage/migration/updates/0.3-0.3.1/__tests__/did.test.ts @@ -7,7 +7,7 @@ import { JsonTransformer } from '../../../../../utils' import { Metadata } from '../../../../Metadata' import * as testModule from '../did' -const agentConfig = getAgentConfig('Migration DidRecord 0.2-0.3') +const agentConfig = getAgentConfig('Migration DidRecord 0.3-0.3.1') const agentContext = getAgentContext() jest.mock('../../../../../modules/dids/repository/DidRepository') @@ -29,20 +29,20 @@ jest.mock('../../../../../agent/Agent', () => { // Mock typed object const AgentMock = Agent as jest.Mock -describe('0.2-0.3 | Did', () => { +describe('0.3-0.3.1 | Did', () => { let agent: Agent beforeEach(() => { agent = new AgentMock() }) - describe('migrateDidRecordToV0_3()', () => { + describe('migrateDidRecordToV0_3_1()', () => { it('should fetch all records and apply the needed updates ', async () => { const records: DidRecord[] = [getDid({ id: 'did:peer:123' })] mockFunction(didRepository.getAll).mockResolvedValue(records) - await testModule.migrateDidRecordToV0_3(agent) + await testModule.migrateDidRecordToV0_3_1(agent) expect(didRepository.getAll).toHaveBeenCalledTimes(1) expect(didRepository.save).toHaveBeenCalledTimes(1) diff --git a/packages/core/src/storage/migration/updates/0.2-0.3/did.ts b/packages/core/src/storage/migration/updates/0.3-0.3.1/did.ts similarity index 88% rename from packages/core/src/storage/migration/updates/0.2-0.3/did.ts rename to packages/core/src/storage/migration/updates/0.3-0.3.1/did.ts index f051b0e339..4b8d0571f6 100644 --- a/packages/core/src/storage/migration/updates/0.2-0.3/did.ts +++ b/packages/core/src/storage/migration/updates/0.3-0.3.1/did.ts @@ -11,8 +11,8 @@ import { uuid } from '../../../../utils/uuid' * The following transformations are applied: * - {@link extractDidAsSeparateProperty} */ -export async function migrateDidRecordToV0_3(agent: Agent) { - agent.config.logger.info('Migrating did records to storage version 0.3') +export async function migrateDidRecordToV0_3_1(agent: Agent) { + agent.config.logger.info('Migrating did records to storage version 0.3.1') const didRepository = agent.dependencyManager.resolve(DidRepository) agent.config.logger.debug(`Fetching all did records from storage`) @@ -20,7 +20,7 @@ export async function migrateDidRecordToV0_3(agent: Age agent.config.logger.debug(`Found a total of ${allDids.length} did records to update.`) for (const didRecord of allDids) { - agent.config.logger.debug(`Migrating did record with id ${didRecord.id} to storage version 0.3`) + agent.config.logger.debug(`Migrating did record with id ${didRecord.id} to storage version 0.3.1`) const newId = uuid() @@ -36,7 +36,7 @@ export async function migrateDidRecordToV0_3(agent: Age await didRepository.deleteById(agent.context, didRecord.did) agent.config.logger.debug( - `Successfully migrated did record with old id ${didRecord.did} to new id ${didRecord.id} to storage version 0.3` + `Successfully migrated did record with old id ${didRecord.did} to new id ${didRecord.id} to storage version 0.3.1` ) } } diff --git a/packages/core/src/storage/migration/updates/0.3-0.3.1/index.ts b/packages/core/src/storage/migration/updates/0.3-0.3.1/index.ts new file mode 100644 index 0000000000..6d9e6b40ab --- /dev/null +++ b/packages/core/src/storage/migration/updates/0.3-0.3.1/index.ts @@ -0,0 +1,7 @@ +import type { BaseAgent } from '../../../../agent/BaseAgent' + +import { migrateDidRecordToV0_3_1 } from './did' + +export async function updateV0_3ToV0_3_1(agent: Agent): Promise { + await migrateDidRecordToV0_3_1(agent) +} diff --git a/packages/core/src/utils/__tests__/version.test.ts b/packages/core/src/utils/__tests__/version.test.ts index d9fdcdedb8..77c1bbe808 100644 --- a/packages/core/src/utils/__tests__/version.test.ts +++ b/packages/core/src/utils/__tests__/version.test.ts @@ -3,63 +3,80 @@ import { isFirstVersionEqualToSecond, isFirstVersionHigherThanSecond, parseVersi describe('version', () => { describe('parseVersionString()', () => { it('parses a version string to a tuple', () => { - expect(parseVersionString('1.0')).toStrictEqual([1, 0]) - expect(parseVersionString('2.12')).toStrictEqual([2, 12]) - expect(parseVersionString('0.0')).toStrictEqual([0, 0]) + expect(parseVersionString('1.0')).toStrictEqual([1, 0, 0]) + expect(parseVersionString('2.12')).toStrictEqual([2, 12, 0]) + expect(parseVersionString('2.3.1')).toStrictEqual([2, 3, 1]) + expect(parseVersionString('0.2.1')).toStrictEqual([0, 2, 1]) + expect(parseVersionString('0.0')).toStrictEqual([0, 0, 0]) }) }) describe('isFirstVersionHigherThanSecond()', () => { it('returns true if the major version digit of the first version is higher than the second', () => { - expect(isFirstVersionHigherThanSecond([2, 0], [1, 0])).toBe(true) - expect(isFirstVersionHigherThanSecond([2, 1], [1, 10])).toBe(true) + expect(isFirstVersionHigherThanSecond([2, 0, 0], [1, 0, 0])).toBe(true) + expect(isFirstVersionHigherThanSecond([2, 1, 0], [1, 1, 1])).toBe(true) }) it('returns false if the major version digit of the first version is lower than the second', () => { - expect(isFirstVersionHigherThanSecond([1, 0], [2, 0])).toBe(false) - expect(isFirstVersionHigherThanSecond([1, 10], [2, 1])).toBe(false) + expect(isFirstVersionHigherThanSecond([1, 0, 0], [2, 0, 0])).toBe(false) + expect(isFirstVersionHigherThanSecond([1, 10, 2], [2, 1, 0])).toBe(false) }) it('returns true if the major version digit of both versions are equal, but the minor version of the first version is higher', () => { - expect(isFirstVersionHigherThanSecond([1, 10], [1, 0])).toBe(true) - expect(isFirstVersionHigherThanSecond([2, 11], [2, 10])).toBe(true) + expect(isFirstVersionHigherThanSecond([1, 10, 0], [1, 0, 0])).toBe(true) + expect(isFirstVersionHigherThanSecond([2, 11, 0], [2, 10, 0])).toBe(true) }) it('returns false if the major version digit of both versions are equal, but the minor version of the second version is higher', () => { - expect(isFirstVersionHigherThanSecond([1, 0], [1, 10])).toBe(false) - expect(isFirstVersionHigherThanSecond([2, 10], [2, 11])).toBe(false) + expect(isFirstVersionHigherThanSecond([1, 0, 0], [1, 10, 0])).toBe(false) + expect(isFirstVersionHigherThanSecond([2, 10, 0], [2, 11, 0])).toBe(false) }) - it('returns false if the major and minor version digit of both versions are equal', () => { - expect(isFirstVersionHigherThanSecond([1, 0], [1, 0])).toBe(false) - expect(isFirstVersionHigherThanSecond([2, 10], [2, 10])).toBe(false) + it('returns false if the major, minor and patch version digit of both versions are equal', () => { + expect(isFirstVersionHigherThanSecond([1, 0, 0], [1, 0, 0])).toBe(false) + expect(isFirstVersionHigherThanSecond([2, 10, 0], [2, 10, 0])).toBe(false) + }) + + it('returns true if the major and minor version digit of both versions are equal but patch version is higher', () => { + expect(isFirstVersionHigherThanSecond([1, 0, 1], [1, 0, 0])).toBe(true) + expect(isFirstVersionHigherThanSecond([2, 10, 3], [2, 10, 2])).toBe(true) + }) + + it('returns false if the major and minor version digit of both versions are equal but patch version is lower', () => { + expect(isFirstVersionHigherThanSecond([1, 0, 0], [1, 0, 1])).toBe(false) + expect(isFirstVersionHigherThanSecond([2, 10, 2], [2, 10, 3])).toBe(false) }) }) describe('isFirstVersionEqualToSecond()', () => { it('returns false if the major version digit of the first version is lower than the second', () => { - expect(isFirstVersionEqualToSecond([2, 0], [1, 0])).toBe(false) - expect(isFirstVersionEqualToSecond([2, 1], [1, 10])).toBe(false) + expect(isFirstVersionEqualToSecond([2, 0, 0], [1, 0, 0])).toBe(false) + expect(isFirstVersionEqualToSecond([2, 1, 0], [1, 10, 0])).toBe(false) }) it('returns false if the major version digit of the first version is higher than the second', () => { - expect(isFirstVersionEqualToSecond([1, 0], [2, 0])).toBe(false) - expect(isFirstVersionEqualToSecond([1, 10], [2, 1])).toBe(false) + expect(isFirstVersionEqualToSecond([1, 0, 0], [2, 0, 0])).toBe(false) + expect(isFirstVersionEqualToSecond([1, 10, 0], [2, 1, 0])).toBe(false) }) it('returns false if the major version digit of both versions are equal, but the minor version of the first version is lower', () => { - expect(isFirstVersionEqualToSecond([1, 10], [1, 0])).toBe(false) - expect(isFirstVersionEqualToSecond([2, 11], [2, 10])).toBe(false) + expect(isFirstVersionEqualToSecond([1, 10, 0], [1, 0, 0])).toBe(false) + expect(isFirstVersionEqualToSecond([2, 11, 0], [2, 10, 0])).toBe(false) }) it('returns false if the major version digit of both versions are equal, but the minor version of the second version is lower', () => { - expect(isFirstVersionEqualToSecond([1, 0], [1, 10])).toBe(false) - expect(isFirstVersionEqualToSecond([2, 10], [2, 11])).toBe(false) + expect(isFirstVersionEqualToSecond([1, 0, 0], [1, 10, 0])).toBe(false) + expect(isFirstVersionEqualToSecond([2, 10, 0], [2, 11, 0])).toBe(false) + }) + + it('returns true if the major, minor and patch version digit of both versions are equal', () => { + expect(isFirstVersionEqualToSecond([1, 0, 0], [1, 0, 0])).toBe(true) + expect(isFirstVersionEqualToSecond([2, 10, 0], [2, 10, 0])).toBe(true) }) - it('returns true if the major and minor version digit of both versions are equal', () => { - expect(isFirstVersionEqualToSecond([1, 0], [1, 0])).toBe(true) - expect(isFirstVersionEqualToSecond([2, 10], [2, 10])).toBe(true) + it('returns false if the patch version digit of both versions are different', () => { + expect(isFirstVersionEqualToSecond([1, 0, 1], [1, 0, 0])).toBe(false) + expect(isFirstVersionEqualToSecond([2, 10, 0], [2, 10, 4])).toBe(false) }) }) }) diff --git a/packages/core/src/utils/version.ts b/packages/core/src/utils/version.ts index 33ae345f99..82a9597909 100644 --- a/packages/core/src/utils/version.ts +++ b/packages/core/src/utils/version.ts @@ -1,18 +1,23 @@ export function parseVersionString(version: VersionString): Version { - const [major, minor] = version.split('.') + const [major, minor, patch] = version.split('.') - return [Number(major), Number(minor)] + return [Number(major), Number(minor), Number(patch ?? '0')] } export function isFirstVersionHigherThanSecond(first: Version, second: Version) { - return first[0] > second[0] || (first[0] == second[0] && first[1] > second[1]) + return ( + first[0] > second[0] || + (first[0] == second[0] && first[1] > second[1]) || + (first[0] == second[0] && first[1] == second[1] && first[2] > second[2]) + ) } export function isFirstVersionEqualToSecond(first: Version, second: Version) { - return first[0] === second[0] && first[1] === second[1] + return first[0] === second[0] && first[1] === second[1] && first[2] === second[2] } -export type VersionString = `${number}.${number}` +export type VersionString = `${number}.${number}` | `${number}.${number}.${number}` export type MajorVersion = number export type MinorVersion = number -export type Version = [MajorVersion, MinorVersion] +export type PatchVersion = number +export type Version = [MajorVersion, MinorVersion, PatchVersion]