diff --git a/__tests__/fixtures/local-database-before-3.0.sqlite b/__tests__/fixtures/local-database-before-migration-with-prefix.sqlite similarity index 70% rename from __tests__/fixtures/local-database-before-3.0.sqlite rename to __tests__/fixtures/local-database-before-migration-with-prefix.sqlite index 3dca8b1fe..ee6a0caea 100644 Binary files a/__tests__/fixtures/local-database-before-3.0.sqlite and b/__tests__/fixtures/local-database-before-migration-with-prefix.sqlite differ diff --git a/__tests__/fixtures/local-database-before-migration.sqlite b/__tests__/fixtures/local-database-before-migration.sqlite index 60db72339..d45deee0e 100644 Binary files a/__tests__/fixtures/local-database-before-migration.sqlite and b/__tests__/fixtures/local-database-before-migration.sqlite differ diff --git a/__tests__/initial.migration.test.ts b/__tests__/initial.migration.test.ts index f64285638..c75898502 100644 --- a/__tests__/initial.migration.test.ts +++ b/__tests__/initial.migration.test.ts @@ -20,7 +20,7 @@ import { KeyManager } from '../packages/key-manager/src' import { DIDManager } from '../packages/did-manager/src' import { FakeDidProvider, FakeDidResolver } from './utils/fake-did' -import { createConnection, Connection } from 'typeorm' +import { createConnection, Connection, ConnectionOptions } from 'typeorm' import { Resolver } from 'did-resolver' import { getResolver as ethrDidResolver } from 'ethr-did-resolver' import { getResolver as webDidResolver } from 'web-did-resolver' @@ -28,158 +28,213 @@ import fs from 'fs' jest.setTimeout(30000) -const databaseBeforeFile = __dirname + '/fixtures/local-database-before-migration.sqlite' -const databaseFile = __dirname + '/migrated1.database.sqlite' -const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c' -const secretKey = '29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c' +const infuraProjectId = '3586660d179141e3801c3895de1c2eba' +const dbEncryptionKey = '29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c' describe('database initial migration tests', () => { - describe('using pre-migration database fixture', () => { - type TestingAgentPlugins = IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver & IDIDComm - let agent: TAgent - let dbConnection: Promise - - beforeAll(async () => { - fs.copyFileSync(databaseBeforeFile, databaseFile) - - dbConnection = createConnection({ - name: 'test', - type: 'sqlite', - database: databaseFile, - synchronize: false, - migrations: migrations, - migrationsRun: true, - logging: false, - entities: Entities, - }) + describe('simple migrations', () => { + const dbFile = __dirname + '/fixtures/local-database-before-migration.sqlite' + createTestsUsingOptions(dbFile, {}) + }) - agent = createAgent({ - context: { - // authenticatedDid: 'did:example:3456' - }, - plugins: [ - new KeyManager({ - store: new KeyStore(dbConnection), - kms: { - local: new KeyManagementSystem(new PrivateKeyStore(dbConnection, new SecretBox(secretKey))), - }, - }), - new DIDManager({ - store: new DIDStore(dbConnection), - defaultProvider: 'did:ethr:goerli', - providers: { - 'did:ethr:goerli': new EthrDIDProvider({ - defaultKms: 'local', - network: 'goerli', - rpcUrl: 'https://goerli.infura.io/v3/' + infuraProjectId, - }), - 'did:web': new WebDIDProvider({ - defaultKms: 'local', - }), - 'did:key': new KeyDIDProvider({ - defaultKms: 'local', + describe('migrations WITH entityPrefix', () => { + const dbFile = __dirname + '/fixtures/local-database-before-migration-with-prefix.sqlite' + createTestsUsingOptions(dbFile, { + entityPrefix: 'veramo_', + }) + }) + + function createTestsUsingOptions( + databaseBeforeFile: string, + connectionOverrides: Partial, + ) { + describe('using pre-migration database fixture', () => { + const databaseFile = databaseBeforeFile + '.tmp' + type TestingAgentPlugins = IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver & IDIDComm + let agent: TAgent + let dbConnection: Promise + + beforeAll(async () => { + fs.copyFileSync(databaseBeforeFile, databaseFile) + + dbConnection = createConnection({ + name: 'test', + type: 'sqlite', + database: databaseFile, + synchronize: false, + migrations: migrations, + migrationsRun: true, + logging: false, + entities: Entities, + ...connectionOverrides, + } as ConnectionOptions) + + agent = createAgent({ + context: { + // authenticatedDid: 'did:example:3456' + }, + plugins: [ + new KeyManager({ + store: new KeyStore(dbConnection), + kms: { + local: new KeyManagementSystem( + new PrivateKeyStore(dbConnection, new SecretBox(dbEncryptionKey)), + ), + }, + }), + new DIDManager({ + store: new DIDStore(dbConnection), + defaultProvider: 'did:ethr:goerli', + providers: { + 'did:ethr:goerli': new EthrDIDProvider({ + defaultKms: 'local', + network: 'goerli', + rpcUrl: 'https://goerli.infura.io/v3/' + infuraProjectId, + }), + 'did:web': new WebDIDProvider({ + defaultKms: 'local', + }), + 'did:key': new KeyDIDProvider({ + defaultKms: 'local', + }), + 'did:fake': new FakeDidProvider(), + }, + }), + new DIDResolverPlugin({ + resolver: new Resolver({ + ...ethrDidResolver({ infuraProjectId }), + ...webDidResolver(), + ...getDidKeyResolver(), + ...new FakeDidResolver(() => agent).getDidFakeResolver(), }), - 'did:fake': new FakeDidProvider(), - }, - }), - new DIDResolverPlugin({ - resolver: new Resolver({ - ...ethrDidResolver({ infuraProjectId }), - ...webDidResolver(), - ...getDidKeyResolver(), - ...new FakeDidResolver(() => agent).getDidFakeResolver(), }), - }), - new DataStore(dbConnection), - new DataStoreORM(dbConnection), - new DIDComm(), - ], + new DataStore(dbConnection), + new DataStoreORM(dbConnection), + new DIDComm(), + ], + }) + return true + }) + afterAll(async () => { + await (await dbConnection).close() + fs.unlinkSync(databaseFile) }) - return true - }) - afterAll(async () => { - await (await dbConnection).close() - fs.unlinkSync(databaseFile) - }) - it('signs using a migrated key', async () => { - expect.assertions(2) - // output of agent.keyManagerGet() before migration - const key = { - kid: '048bb0844ebbcf434048862008991b01cdebb564207f0cea08e5c8d925cec3542bb4c8c1630f38a6b05528ec7460139fe0978bf34a1e4ff32ec210bbaed98dddda', - kms: 'local', - type: 'Secp256k1', - publicKeyHex: - '048bb0844ebbcf434048862008991b01cdebb564207f0cea08e5c8d925cec3542bb4c8c1630f38a6b05528ec7460139fe0978bf34a1e4ff32ec210bbaed98dddda', - privateKeyHex: 'bb956a5f43283fc4da8ea202ce5ff93e1961d397b98c5871bd6fe420ce56cd53', - meta: { - algorithms: ['ES256K', 'ES256K-R', 'eth_signTransaction', 'eth_signTypedData', 'eth_signMessage'], - }, - } - const migratedKey = await agent.keyManagerGet({ kid: key.kid }) - expect(migratedKey.kid).toEqual(key.kid) - const signedMessage = await agent.keyManagerSign({ - data: 'hello world', - keyRef: migratedKey.kid, - algorithm: 'ES256K', - encoding: 'utf-8', + it('loads a migrated key', async () => { + // output of agent.keyManagerGet() before migration + const key = { + kid: '04539ffde912c094bc48b64c9ee71b2baece24c710bcad2c7bacced615f60ae53949cdc95379eb50556d11cb0afab0e5a6ca8cb475d413b2f12307cc2d7f5438de', + kms: 'local', + type: 'Secp256k1', + publicKeyHex: + '04539ffde912c094bc48b64c9ee71b2baece24c710bcad2c7bacced615f60ae53949cdc95379eb50556d11cb0afab0e5a6ca8cb475d413b2f12307cc2d7f5438de', + privateKeyHex: 'a5e81a8cd50cf5c31d5b87db3e153e2817f86de350a60edc2335f76d5c3b4e0d', + meta: { + algorithms: ['ES256K', 'ES256K-R', 'eth_signTransaction', 'eth_signTypedData', 'eth_signMessage'], + }, + } + const migratedKey = await agent.keyManagerGet({ kid: key.kid }) + expect(migratedKey.kid).toEqual(key.kid) + expect(migratedKey).not.toHaveProperty('privateKeyHex') + const signedMessage = await agent.keyManagerSign({ + data: 'hello world', + keyRef: migratedKey.kid, + algorithm: 'ES256K', + encoding: 'utf-8', + }) + expect(signedMessage).toEqual( + 'vzDocUViJh7ooOCZ-jBHKZddEsTa4yClHwhIL9SHJwjAv3bC6TZIcUnX36ZqNBWvLbnNAQvdtzqrVf3l0pv3QQ', + ) }) - expect(signedMessage).toEqual( - 'JDaZFSC4eWQdau4G9a8l8ml0rhwmzCY4oEDIr-cjWK2nVCOGZP94HV3EfbpO_X3bZKPITLg8FJgVVSyRRPcObQ', - ) - }) - it('reads a credential by hash', async () => { - const cred = await agent.dataStoreGetVerifiableCredential({ - hash: '133b9636e2fe2b7a77b88ca5d81998773b8bc3ebe0b1f3f80dc419dfa0bb797bea779ba0946d603c3ea8611fee5148395894f327661531929294a61589d4d0e7', + it('unpacks DIDComm message intended for migrated managed key', async () => { + const packed = { + message: + '{"protected":"eyJ0eXAiOiJhcHBsaWNhdGlvbi9kaWRjb21tLWVuY3J5cHRlZCtqc29uIiwiZW5jIjoiWEMyMFAifQ","iv":"mBAgYLce2JpmKtmlNQLG6w9lm6kqf4Ne","ciphertext":"D9_7Xxj51xn3T9yBU-rZmxSTrR82Pi4G7hWCDSxSpRUlmUh2uJoqeCHixSTFeZvFAfw2ryROjrxbpCh5Arg-wqrW3WwKGpVFHXO_r0jHso5lNMO-vGjxOULN","tag":"9Qs-esw1tcnM0jE_Q3LxIQ","recipients":[{"encrypted_key":"kGNaBfhPS2VETu-_iYaUwy13sC1ZVm3i_qYiYkuEleA","header":{"alg":"ECDH-ES+XC20PKW","iv":"1sK1pyOwy_hNY_WsJPGdoFqE8ken51IA","tag":"MplY66h-bHnuSdP1ZGLYyw","epk":{"kty":"OKP","crv":"X25519","x":"UZx8Uf3BJ-m3wm7sBjvCp1UXuHA9v0Qu5KvWfWyBNio"},"kid":"did:key:z6MkiPXoC2uAWPdQpotWxzNMJpaDbfPxaQWcbux5avNwEMfD#z6LSqL9zfeZa53RwpAkjxN7Gizvzv4rjAT7GwhLVYLPXK5dC"}}]}', + } + const msg = await agent.unpackDIDCommMessage(packed) + expect(msg.message.body).toEqual({ hello: 'world' }) }) - expect(cred.credentialSubject.name).toEqual('Alice') - }) - it('reads a presentation by hash', async () => { - const cred = await agent.dataStoreGetVerifiablePresentation({ - hash: '4cfe965596a0d343ff2cc02afd32068bced34caa2b1e7e3f253b23e420de106b58a613f06f55d9d9cbbdbe0b0f051a45d44404020b123c58f0ee48bdaeafdc90', + it('signs using a migrated key', async () => { + expect.assertions(2) + // output of agent.keyManagerGet() before migration + const key = { + kid: '048bb0844ebbcf434048862008991b01cdebb564207f0cea08e5c8d925cec3542bb4c8c1630f38a6b05528ec7460139fe0978bf34a1e4ff32ec210bbaed98dddda', + kms: 'local', + type: 'Secp256k1', + publicKeyHex: + '048bb0844ebbcf434048862008991b01cdebb564207f0cea08e5c8d925cec3542bb4c8c1630f38a6b05528ec7460139fe0978bf34a1e4ff32ec210bbaed98dddda', + privateKeyHex: 'bb956a5f43283fc4da8ea202ce5ff93e1961d397b98c5871bd6fe420ce56cd53', + meta: { + algorithms: ['ES256K', 'ES256K-R', 'eth_signTransaction', 'eth_signTypedData', 'eth_signMessage'], + }, + } + const migratedKey = await agent.keyManagerGet({ kid: key.kid }) + expect(migratedKey.kid).toEqual(key.kid) + const signedMessage = await agent.keyManagerSign({ + data: 'hello world', + keyRef: migratedKey.kid, + algorithm: 'ES256K', + encoding: 'utf-8', + }) + expect(signedMessage).toEqual( + 'JDaZFSC4eWQdau4G9a8l8ml0rhwmzCY4oEDIr-cjWK2nVCOGZP94HV3EfbpO_X3bZKPITLg8FJgVVSyRRPcObQ', + ) }) - expect(cred?.verifiableCredential?.[0]?.credentialSubject?.name).toEqual('Alice') - }) - it('reads existing messages', async () => { - const msgs = await agent.dataStoreORMGetMessages() - expect(msgs.length).toEqual(3) - }) + it('reads a credential by hash', async () => { + const cred = await agent.dataStoreGetVerifiableCredential({ + hash: '133b9636e2fe2b7a77b88ca5d81998773b8bc3ebe0b1f3f80dc419dfa0bb797bea779ba0946d603c3ea8611fee5148395894f327661531929294a61589d4d0e7', + }) + expect(cred.credentialSubject.name).toEqual('Alice') + }) - it('reads existing message with attachments', async () => { - const msgs = await agent.dataStoreORMGetMessages({ - where: [ - { - column: 'id', - value: [ - '13065b8bb97cd37410f4f43cfa878f396aa906701e70c7e2bb86c5de1fe1351a41fb05f445cb68b1ba2805858db619ddd26c71e30a0079c200843d52276213d8', - ], - }, - ], + it('reads a presentation by hash', async () => { + const cred = await agent.dataStoreGetVerifiablePresentation({ + hash: '4cfe965596a0d343ff2cc02afd32068bced34caa2b1e7e3f253b23e420de106b58a613f06f55d9d9cbbdbe0b0f051a45d44404020b123c58f0ee48bdaeafdc90', + }) + expect(cred?.verifiableCredential?.[0]?.credentialSubject?.name).toEqual('Alice') }) - expect(msgs[0]?.presentations?.length).toEqual(1) - expect(msgs[0]?.credentials?.length).toEqual(1) - }) - it('reads a credential by claim', async () => { - const creds = await agent.dataStoreORMGetVerifiableCredentialsByClaims({ - where: [ - { column: 'type', value: ['name'] }, - { column: 'value', value: ['Alice'] }, - ], + it('reads existing messages', async () => { + const msgs = await agent.dataStoreORMGetMessages() + expect(msgs.length).toEqual(3) + }) + + it('reads existing message with attachments', async () => { + const msgs = await agent.dataStoreORMGetMessages({ + where: [ + { + column: 'id', + value: [ + '13065b8bb97cd37410f4f43cfa878f396aa906701e70c7e2bb86c5de1fe1351a41fb05f445cb68b1ba2805858db619ddd26c71e30a0079c200843d52276213d8', + ], + }, + ], + }) + expect(msgs[0]?.presentations?.length).toEqual(1) + expect(msgs[0]?.credentials?.length).toEqual(1) }) - expect(creds.length).toEqual(1) - }) - it('unpacks DIDComm message intended for migrated managed key', async () => { - const packed = { - message: - '{"protected":"eyJ0eXAiOiJhcHBsaWNhdGlvbi9kaWRjb21tLWVuY3J5cHRlZCtqc29uIiwiZW5jIjoiWEMyMFAifQ","iv":"_lIE23TIaFAPT_YRvlGzZnXhwQh8AqJ2","ciphertext":"uinIkbE-D8h-IkHPsNHsI9ni2EmGLo368OO0F_AaZG3KP_IAhfA2F8Bevt-LrWxoQJn2_NDhudXCbTpypK0fAnmY9tUEooLimdLxdxLsXHBBr2oZLiQoiRNxxGCSBc0EmQbek4-9b2M3jUauStoptQ","tag":"JbjiNGIYxDPY-_Oj6MHpAA","recipients":[{"encrypted_key":"y2JT-2YpW4PgNJBRKKQyWzGuC-KGDVc2wvN889tIGoY","header":{"alg":"ECDH-ES+XC20PKW","iv":"8Xy5KfRVkrzY8lbCK5ZAdotp9Idxl0_P","tag":"vEzPgqiv3vFc1DppvdVXnA","epk":{"kty":"OKP","crv":"X25519","x":"JFD40GD40ywqCyoeQ4jGJz_adfOqUg6ukX0tYU7iFw8"},"kid":"did:key:z6MktEQbgrewCxg3bXkdKAqHJXSEMJVcxUhcEvkWVqyBpzYn#z6LSpCBthn9h34KEFKPaDjm5Ce7ZQYUtwyqTmwDqTDbAJHBk"}}]}', - } - const msg = await agent.unpackDIDCommMessage(packed) - expect(msg.message.body).toEqual({ hello: 'world' }) + it('reads a credential by claim', async () => { + const creds = await agent.dataStoreORMGetVerifiableCredentialsByClaims({ + where: [ + { column: 'type', value: ['name'] }, + { column: 'value', value: ['Alice'] }, + ], + }) + expect(creds.length).toEqual(1) + }) + + it('unpacks DIDComm message intended for migrated managed key', async () => { + const packed = { + message: + '{"protected":"eyJ0eXAiOiJhcHBsaWNhdGlvbi9kaWRjb21tLWVuY3J5cHRlZCtqc29uIiwiZW5jIjoiWEMyMFAifQ","iv":"_lIE23TIaFAPT_YRvlGzZnXhwQh8AqJ2","ciphertext":"uinIkbE-D8h-IkHPsNHsI9ni2EmGLo368OO0F_AaZG3KP_IAhfA2F8Bevt-LrWxoQJn2_NDhudXCbTpypK0fAnmY9tUEooLimdLxdxLsXHBBr2oZLiQoiRNxxGCSBc0EmQbek4-9b2M3jUauStoptQ","tag":"JbjiNGIYxDPY-_Oj6MHpAA","recipients":[{"encrypted_key":"y2JT-2YpW4PgNJBRKKQyWzGuC-KGDVc2wvN889tIGoY","header":{"alg":"ECDH-ES+XC20PKW","iv":"8Xy5KfRVkrzY8lbCK5ZAdotp9Idxl0_P","tag":"vEzPgqiv3vFc1DppvdVXnA","epk":{"kty":"OKP","crv":"X25519","x":"JFD40GD40ywqCyoeQ4jGJz_adfOqUg6ukX0tYU7iFw8"},"kid":"did:key:z6MktEQbgrewCxg3bXkdKAqHJXSEMJVcxUhcEvkWVqyBpzYn#z6LSpCBthn9h34KEFKPaDjm5Ce7ZQYUtwyqTmwDqTDbAJHBk"}}]}', + } + const msg = await agent.unpackDIDCommMessage(packed) + expect(msg.message.body).toEqual({ hello: 'world' }) + }) }) - }) + } }) diff --git a/__tests__/keyMigration.test.ts b/__tests__/keyMigration.test.ts deleted file mode 100644 index df4fe7e5d..000000000 --- a/__tests__/keyMigration.test.ts +++ /dev/null @@ -1,141 +0,0 @@ -import { createAgent, TAgent, IDIDManager, IResolver, IKeyManager, IDataStore } from '../packages/core/src' -import { DIDResolverPlugin } from '../packages/did-resolver/src' -import { EthrDIDProvider } from '../packages/did-provider-ethr/src' -import { WebDIDProvider } from '../packages/did-provider-web/src' -import { KeyDIDProvider } from '../packages/did-provider-key/src' -import { DIDComm, IDIDComm } from '../packages/did-comm/src' -import { KeyManagementSystem, SecretBox } from '../packages/kms-local/src' -import { - Entities, - IDataStoreORM, - DataStore, - DataStoreORM, - KeyStore, - DIDStore, - PrivateKeyStore, - migrations, -} from '../packages/data-store/src' -import { getDidKeyResolver } from '../packages/did-provider-key/src' -import { KeyManager } from '../packages/key-manager/src' -import { DIDManager } from '../packages/did-manager/src' -import { FakeDidProvider, FakeDidResolver } from './utils/fake-did' - -import { createConnection, Connection } from 'typeorm' -import { Resolver } from 'did-resolver' -import { getResolver as ethrDidResolver } from 'ethr-did-resolver' -import { getResolver as webDidResolver } from 'web-did-resolver' -import fs from 'fs' - -jest.setTimeout(30000) - -const databaseBeforeFile = __dirname + '/fixtures/local-database-before-3.0.sqlite' -const databaseFile = __dirname + '/migrated.keys.database.sqlite' -const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c' -const secretKey = '29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c' - -describe('database private-key migration tests', () => { - describe('using pre-migration database fixture', () => { - type TestingAgentPlugins = IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver & IDIDComm - let agent: TAgent - let dbConnection: Promise - - beforeAll(async () => { - fs.copyFileSync(databaseBeforeFile, databaseFile) - - dbConnection = createConnection({ - name: 'key-migration-test', - type: 'sqlite', - database: databaseFile, - synchronize: false, - migrations: migrations, - migrationsRun: true, - logging: false, - entities: Entities, - }) - - agent = createAgent({ - context: { - // authenticatedDid: 'did:example:3456' - }, - plugins: [ - new KeyManager({ - store: new KeyStore(dbConnection), - kms: { - local: new KeyManagementSystem(new PrivateKeyStore(dbConnection, new SecretBox(secretKey))), - }, - }), - new DIDManager({ - store: new DIDStore(dbConnection), - defaultProvider: 'did:ethr:goerli', - providers: { - 'did:ethr:goerli': new EthrDIDProvider({ - defaultKms: 'local', - network: 'goerli', - rpcUrl: 'https://goerli.infura.io/v3/' + infuraProjectId, - }), - 'did:web': new WebDIDProvider({ - defaultKms: 'local', - }), - 'did:key': new KeyDIDProvider({ - defaultKms: 'local', - }), - 'did:fake': new FakeDidProvider(), - }, - }), - new DIDResolverPlugin({ - resolver: new Resolver({ - ...ethrDidResolver({ infuraProjectId }), - ...webDidResolver(), - ...getDidKeyResolver(), - ...new FakeDidResolver(() => agent).getDidFakeResolver(), - }), - }), - new DataStore(dbConnection), - new DataStoreORM(dbConnection), - new DIDComm(), - ], - }) - return true - }) - afterAll(async () => { - await (await dbConnection).close() - fs.unlinkSync(databaseFile) - }) - - it('loads a migrated key', async () => { - // output of agent.keyManagerGet() before migration - const key = { - kid: '04539ffde912c094bc48b64c9ee71b2baece24c710bcad2c7bacced615f60ae53949cdc95379eb50556d11cb0afab0e5a6ca8cb475d413b2f12307cc2d7f5438de', - kms: 'local', - type: 'Secp256k1', - publicKeyHex: - '04539ffde912c094bc48b64c9ee71b2baece24c710bcad2c7bacced615f60ae53949cdc95379eb50556d11cb0afab0e5a6ca8cb475d413b2f12307cc2d7f5438de', - privateKeyHex: 'a5e81a8cd50cf5c31d5b87db3e153e2817f86de350a60edc2335f76d5c3b4e0d', - meta: { - algorithms: ['ES256K', 'ES256K-R', 'eth_signTransaction', 'eth_signTypedData', 'eth_signMessage'], - }, - } - const migratedKey = await agent.keyManagerGet({ kid: key.kid }) - expect(migratedKey.kid).toEqual(key.kid) - expect(migratedKey).not.toHaveProperty('privateKeyHex') - const signedMessage = await agent.keyManagerSign({ - data: 'hello world', - keyRef: migratedKey.kid, - algorithm: 'ES256K', - encoding: 'utf-8', - }) - expect(signedMessage).toEqual( - 'vzDocUViJh7ooOCZ-jBHKZddEsTa4yClHwhIL9SHJwjAv3bC6TZIcUnX36ZqNBWvLbnNAQvdtzqrVf3l0pv3QQ', - ) - }) - - it('unpacks DIDComm message intended for migrated managed key', async () => { - const packed = { - message: - '{"protected":"eyJ0eXAiOiJhcHBsaWNhdGlvbi9kaWRjb21tLWVuY3J5cHRlZCtqc29uIiwiZW5jIjoiWEMyMFAifQ","iv":"mBAgYLce2JpmKtmlNQLG6w9lm6kqf4Ne","ciphertext":"D9_7Xxj51xn3T9yBU-rZmxSTrR82Pi4G7hWCDSxSpRUlmUh2uJoqeCHixSTFeZvFAfw2ryROjrxbpCh5Arg-wqrW3WwKGpVFHXO_r0jHso5lNMO-vGjxOULN","tag":"9Qs-esw1tcnM0jE_Q3LxIQ","recipients":[{"encrypted_key":"kGNaBfhPS2VETu-_iYaUwy13sC1ZVm3i_qYiYkuEleA","header":{"alg":"ECDH-ES+XC20PKW","iv":"1sK1pyOwy_hNY_WsJPGdoFqE8ken51IA","tag":"MplY66h-bHnuSdP1ZGLYyw","epk":{"kty":"OKP","crv":"X25519","x":"UZx8Uf3BJ-m3wm7sBjvCp1UXuHA9v0Qu5KvWfWyBNio"},"kid":"did:key:z6MkiPXoC2uAWPdQpotWxzNMJpaDbfPxaQWcbux5avNwEMfD#z6LSqL9zfeZa53RwpAkjxN7Gizvzv4rjAT7GwhLVYLPXK5dC"}}]}', - } - const msg = await agent.unpackDIDCommMessage(packed) - expect(msg.message.body).toEqual({ hello: 'world' }) - }) - }) -}) diff --git a/__tests__/localAgent.test.ts b/__tests__/localAgent.test.ts index 17e0d3c52..0c66acca2 100644 --- a/__tests__/localAgent.test.ts +++ b/__tests__/localAgent.test.ts @@ -62,7 +62,7 @@ import messageHandler from './shared/messageHandler' import didDiscovery from './shared/didDiscovery' import dbInitOptions from './shared/dbInitOptions' -const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c' +const infuraProjectId = '3586660d179141e3801c3895de1c2eba' const secretKey = '29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c' let agent: TAgent< diff --git a/__tests__/localMemoryStoreAgent.test.ts b/__tests__/localMemoryStoreAgent.test.ts index 8f419db3f..b9f4d3e59 100644 --- a/__tests__/localMemoryStoreAgent.test.ts +++ b/__tests__/localMemoryStoreAgent.test.ts @@ -49,7 +49,7 @@ import didComm from './shared/didcomm' import messageHandler from './shared/messageHandler' const databaseFile = 'local-database2.sqlite' -const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c' +const infuraProjectId = '3586660d179141e3801c3895de1c2eba' let agent: TAgent< IDIDManager & diff --git a/__tests__/restAgent.test.ts b/__tests__/restAgent.test.ts index 26e0b3589..66b05f2fa 100644 --- a/__tests__/restAgent.test.ts +++ b/__tests__/restAgent.test.ts @@ -68,7 +68,7 @@ import messageHandler from './shared/messageHandler' import didDiscovery from './shared/didDiscovery' const databaseFile = 'rest-database.sqlite' -const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c' +const infuraProjectId = '3586660d179141e3801c3895de1c2eba' const secretKey = '29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c' const port = 3002 const basePath = '/agent' diff --git a/packages/cli/default/default.yml b/packages/cli/default/default.yml index 43907925b..8280f0ffa 100644 --- a/packages/cli/default/default.yml +++ b/packages/cli/default/default.yml @@ -176,7 +176,7 @@ didResolver: ethr-did-resolver: $require: ethr-did-resolver?t=function&p=/ethr#getResolver $args: - - infuraProjectId: 5ffc47f65c4042ce847ef66a3fa70d4c + - infuraProjectId: 3586660d179141e3801c3895de1c2eba web-did-resolver: $require: web-did-resolver?t=function&p=/web#getResolver @@ -223,7 +223,7 @@ didManager: $args: - defaultKms: local network: mainnet - rpcUrl: https://mainnet.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c + rpcUrl: https://mainnet.infura.io/v3/3586660d179141e3801c3895de1c2eba gas: 1000001 ttl: 31104001 did:ethr:rinkeby: @@ -231,7 +231,7 @@ didManager: $args: - defaultKms: local network: rinkeby - rpcUrl: https://rinkeby.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c + rpcUrl: https://rinkeby.infura.io/v3/3586660d179141e3801c3895de1c2eba gas: 1000001 ttl: 31104001 did:ethr:ropsten: @@ -239,7 +239,7 @@ didManager: $args: - defaultKms: local network: ropsten - rpcUrl: https://ropsten.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c + rpcUrl: https://ropsten.infura.io/v3/3586660d179141e3801c3895de1c2eba gas: 1000001 ttl: 31104001 did:ethr:kovan: @@ -247,7 +247,7 @@ didManager: $args: - defaultKms: local network: kovan - rpcUrl: https://kovan.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c + rpcUrl: https://kovan.infura.io/v3/3586660d179141e3801c3895de1c2eba gas: 1000001 ttl: 31104001 did:ethr:goerli: @@ -255,7 +255,7 @@ didManager: $args: - defaultKms: local network: goerli - rpcUrl: https://goerli.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c + rpcUrl: https://goerli.infura.io/v3/3586660d179141e3801c3895de1c2eba gas: 1000001 ttl: 31104001 did:web: diff --git a/packages/cli/src/dev.ts b/packages/cli/src/dev.ts index 300224879..5f19691ac 100644 --- a/packages/cli/src/dev.ts +++ b/packages/cli/src/dev.ts @@ -50,6 +50,7 @@ function createSchema(generator: TJS.SchemaGenerator, symbol: string) { schemaStr = schemaStr.replace(/Where\<(.*)\>/gm, 'Where-$1') schemaStr = schemaStr.replace(/Order\<(.*)\>/gm, 'Order-$1') schemaStr = schemaStr.replace(/FindArgs\<(.*)\>/gm, 'FindArgs-$1') + schemaStr = schemaStr.replace(/https \:\/\//gm, 'https://') return JSON.parse(schemaStr) } diff --git a/packages/core/plugin.schema.json b/packages/core/plugin.schema.json index 225eba564..9300ea0a5 100644 --- a/packages/core/plugin.schema.json +++ b/packages/core/plugin.schema.json @@ -7,7 +7,7 @@ "properties": { "didDocument": { "$ref": "#/components/schemas/DIDDocument", - "description": "the DID document from which to extract the fragment. This MUST be the document resolved by {@link resolveDid }" + "description": "the DID document from which to extract the fragment. This MUST be the document resolved by {@link resolveDid }" }, "didUrl": { "type": "string", @@ -1479,7 +1479,7 @@ "required": [ "hash" ], - "description": "Input arguments for {@link IDataStore.IDataStoreDeleteVerifiableCredentialArgs| IDataStoreDeleteVerifiableCredentialArgs }" + "description": "Input arguments for {@link IDataStore.IDataStoreDeleteVerifiableCredentialArgs | IDataStoreDeleteVerifiableCredentialArgs }" }, "IDataStoreGetMessageArgs": { "type": "object", @@ -1584,7 +1584,7 @@ "id", "type" ], - "description": "DIDComm message" + "description": "Represents a DIDComm v1 message payload, with optionally decoded credentials and presentations." }, "IMetaData": { "type": "object", @@ -1672,13 +1672,13 @@ }, "required": [ "@context", - "type", - "issuer", - "issuanceDate", "credentialSubject", - "proof" + "issuanceDate", + "issuer", + "proof", + "type" ], - "description": "Verifiable Credential {@link https://github.com/decentralized-identifier/did-jwt-vc }" + "description": "Represents a signed Verifiable Credential payload (includes proof). See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }" }, "VerifiablePresentation": { "type": "object", @@ -1729,13 +1729,13 @@ } }, "required": [ - "holder", "@context", + "holder", + "proof", "type", - "verifier", - "proof" + "verifier" ], - "description": "Verifiable Presentation {@link https://github.com/decentralized-identifier/did-jwt-vc }" + "description": "Represents a signed Verifiable Presentation (includes proof). See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model }" }, "IDataStoreGetVerifiableCredentialArgs": { "type": "object", @@ -2004,7 +2004,7 @@ "id", "type" ], - "description": "DIDComm message" + "description": "Represents a DIDComm v1 message payload, with optionally decoded credentials and presentations." }, "VerifiableCredential": { "type": "object", @@ -2075,13 +2075,13 @@ }, "required": [ "@context", - "type", - "issuer", - "issuanceDate", "credentialSubject", - "proof" + "issuanceDate", + "issuer", + "proof", + "type" ], - "description": "Verifiable Credential {@link https://github.com/decentralized-identifier/did-jwt-vc }" + "description": "Represents a signed Verifiable Credential payload (includes proof). See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }" }, "VerifiablePresentation": { "type": "object", @@ -2132,13 +2132,13 @@ } }, "required": [ - "holder", "@context", + "holder", + "proof", "type", - "verifier", - "proof" + "verifier" ], - "description": "Verifiable Presentation {@link https://github.com/decentralized-identifier/did-jwt-vc }" + "description": "Represents a signed Verifiable Presentation (includes proof). See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model }" } }, "methods": { diff --git a/packages/core/src/types/IMessage.ts b/packages/core/src/types/IMessage.ts index 3e4afc1b8..e6b7f7314 100644 --- a/packages/core/src/types/IMessage.ts +++ b/packages/core/src/types/IMessage.ts @@ -1,51 +1,31 @@ /** - * Verifiable Credential {@link https://github.com/decentralized-identifier/did-jwt-vc} + * Represents a signed Verifiable Credential payload (includes proof). + * See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model} + * * @public */ -export interface VerifiableCredential { - '@context': string[] - id?: string - type: string[] - issuer: { id: string; [x: string]: any } - issuanceDate: string - expirationDate?: string - credentialSubject: { - id?: string - [x: string]: any - } - credentialStatus?: { - id: string - type: string - } +export interface VerifiableCredential extends W3CCredential { proof: { type?: string [x: string]: any } - [x: string]: any } /** - * Verifiable Presentation {@link https://github.com/decentralized-identifier/did-jwt-vc} + * Represents a signed Verifiable Presentation (includes proof). + * See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model} * @public */ -export interface VerifiablePresentation { - id?: string - holder: string - issuanceDate?: string - expirationDate?: string - '@context': string[] - type: string[] - verifier: string[] - verifiableCredential?: VerifiableCredential[] +export interface VerifiablePresentation extends W3CPresentation { proof: { type?: string [x: string]: any } - [x: string]: any } /** - * W3CCredential {@link https://github.com/decentralized-identifier/did-jwt-vc} + * Represents an unsigned W3C Credential payload. + * See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model} * @public */ export interface W3CCredential { @@ -67,7 +47,8 @@ export interface W3CCredential { } /** - * W3CPresentation {@link https://github.com/decentralized-identifier/did-jwt-vc} + * Represents an unsigned W3C Presentation payload. + * See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model} * @public */ export interface W3CPresentation { @@ -99,7 +80,7 @@ export interface IMetaData { } /** - * DIDComm message + * Represents a DIDComm v1 message payload, with optionally decoded credentials and presentations. * @public */ export interface IMessage { diff --git a/packages/data-store/plugin.schema.json b/packages/data-store/plugin.schema.json index ee3d9e4dd..240a636ed 100644 --- a/packages/data-store/plugin.schema.json +++ b/packages/data-store/plugin.schema.json @@ -400,7 +400,7 @@ "id", "type" ], - "description": "DIDComm message" + "description": "Represents a DIDComm v1 message payload, with optionally decoded credentials and presentations." }, "IMetaData": { "type": "object", @@ -488,13 +488,13 @@ }, "required": [ "@context", - "type", - "issuer", - "issuanceDate", "credentialSubject", - "proof" + "issuanceDate", + "issuer", + "proof", + "type" ], - "description": "Verifiable Credential {@link https://github.com/decentralized-identifier/did-jwt-vc }" + "description": "Represents a signed Verifiable Credential payload (includes proof). See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }" }, "VerifiablePresentation": { "type": "object", @@ -545,13 +545,13 @@ } }, "required": [ - "holder", "@context", + "holder", + "proof", "type", - "verifier", - "proof" + "verifier" ], - "description": "Verifiable Presentation {@link https://github.com/decentralized-identifier/did-jwt-vc }" + "description": "Represents a signed Verifiable Presentation (includes proof). See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model }" }, "FindCredentialsArgs": { "$ref": "#/components/schemas/FindArgs-TCredentialColumns" diff --git a/packages/data-store/src/__tests__/data-store-orm.test.ts b/packages/data-store/src/__tests__/data-store-orm.test.ts index e1332c7e6..0312bf2a2 100644 --- a/packages/data-store/src/__tests__/data-store-orm.test.ts +++ b/packages/data-store/src/__tests__/data-store-orm.test.ts @@ -8,14 +8,7 @@ import { } from '@veramo/core' import { createConnection, Connection } from 'typeorm' import { DataStoreORM, IDataStoreORM } from '../data-store-orm' -import { - FindArgs, - TClaimsColumns, - TCredentialColumns, - TMessageColumns, - TPresentationColumns, - TIdentifiersColumns, -} from '../types' +import { FindArgs, TCredentialColumns, TMessageColumns, TPresentationColumns } from '../types' import { DataStore } from '../data-store' import { Entities } from '../index' import fs from 'fs' diff --git a/packages/data-store/src/entities/message.ts b/packages/data-store/src/entities/message.ts index e6598666d..847ca19ce 100644 --- a/packages/data-store/src/entities/message.ts +++ b/packages/data-store/src/entities/message.ts @@ -6,8 +6,6 @@ import { ManyToMany, PrimaryColumn, JoinTable, - CreateDateColumn, - UpdateDateColumn, BeforeInsert, BeforeUpdate, } from 'typeorm' @@ -85,7 +83,7 @@ export class Message extends BaseEntity { nullable: true, cascade: ['insert'], eager: true, - onDelete: "CASCADE", + onDelete: 'CASCADE', }) from?: Identifier @@ -93,7 +91,7 @@ export class Message extends BaseEntity { nullable: true, cascade: ['insert'], eager: true, - onDelete: "CASCADE" + onDelete: 'CASCADE', }) to?: Identifier diff --git a/packages/data-store/src/entities/presentation.ts b/packages/data-store/src/entities/presentation.ts index 7e1dd04fd..119378df2 100644 --- a/packages/data-store/src/entities/presentation.ts +++ b/packages/data-store/src/entities/presentation.ts @@ -1,15 +1,6 @@ import { VerifiablePresentation } from '@veramo/core' import { blake2bHex } from 'blakejs' -import { - Entity, - Column, - BaseEntity, - ManyToOne, - JoinTable, - PrimaryColumn, - BeforeInsert, - ManyToMany, -} from 'typeorm' +import { Entity, Column, BaseEntity, ManyToOne, JoinTable, PrimaryColumn, ManyToMany } from 'typeorm' import { Identifier } from './identifier' import { Message } from './message' import { Credential, createCredentialEntity } from './credential' @@ -36,7 +27,7 @@ export class Presentation extends BaseEntity { @ManyToOne((type) => Identifier, (identifier) => identifier.issuedPresentations, { cascade: ['insert'], eager: true, - onDelete: "CASCADE" + onDelete: 'CASCADE', }) //@ts-ignore holder: Identifier diff --git a/packages/data-store/src/entities/private-key.ts b/packages/data-store/src/entities/private-key.ts index 3e2662f0b..5cb1d2716 100644 --- a/packages/data-store/src/entities/private-key.ts +++ b/packages/data-store/src/entities/private-key.ts @@ -1,6 +1,5 @@ -import { KeyMetadata, TKeyType } from '@veramo/core' -import { Entity, Column, PrimaryColumn, BaseEntity, ManyToOne, ManyToMany } from 'typeorm' -import { Identifier } from './identifier' +import { TKeyType } from '@veramo/core' +import { Entity, Column, PrimaryColumn, BaseEntity } from 'typeorm' export type KeyType = TKeyType diff --git a/packages/data-store/src/identifier/key-store.ts b/packages/data-store/src/identifier/key-store.ts index f1d3ff4d9..d397bda50 100644 --- a/packages/data-store/src/identifier/key-store.ts +++ b/packages/data-store/src/identifier/key-store.ts @@ -1,5 +1,5 @@ import { IKey, ManagedKeyInfo } from '@veramo/core' -import { AbstractKeyStore, AbstractSecretBox } from '@veramo/key-manager' +import { AbstractKeyStore } from '@veramo/key-manager' import { Connection } from 'typeorm' import { Key } from '../entities/key' diff --git a/packages/data-store/src/migrations/1.createDatabase.ts b/packages/data-store/src/migrations/1.createDatabase.ts index 63991d102..8005ed84a 100644 --- a/packages/data-store/src/migrations/1.createDatabase.ts +++ b/packages/data-store/src/migrations/1.createDatabase.ts @@ -1,4 +1,4 @@ -import { ColumnType, MigrationInterface, QueryRunner, Table, TableColumn } from 'typeorm' +import { MigrationInterface, QueryRunner, Table } from 'typeorm' import Debug from 'debug' const debug = Debug('veramo:data-store:initial-migration') @@ -7,6 +7,13 @@ const debug = Debug('veramo:data-store:initial-migration') */ export class CreateDatabase1447159020001 implements MigrationInterface { async up(queryRunner: QueryRunner): Promise { + function getTableName(givenName: string): string { + return ( + queryRunner.connection.entityMetadatas.find((meta) => meta.givenTableName === givenName)?.tableName || + givenName + ) + } + const dateTimeType: string = queryRunner.connection.driver.mappedDataTypes.createDate as string debug(`creating identifier table`) @@ -14,7 +21,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE UNIQUE INDEX \"IDX_6098cca69c838d91e55ef32fe1\" ON \"identifier\" (\"alias\", \"provider\")", await queryRunner.createTable( new Table({ - name: 'identifier', + name: getTableName('identifier'), columns: [ { name: 'did', type: 'varchar', isPrimary: true }, { name: 'provider', type: 'varchar', isNullable: true }, @@ -37,7 +44,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE TABLE \"key\" (\"kid\" varchar PRIMARY KEY NOT NULL, \"kms\" varchar NOT NULL, \"type\" varchar NOT NULL, \"publicKeyHex\" varchar NOT NULL, \"privateKeyHex\" varchar NOT NULL, \"meta\" text, \"identifierDid\" varchar, CONSTRAINT \"FK_3f40a9459b53adf1729dbd3b787\" FOREIGN KEY (\"identifierDid\") REFERENCES \"identifier\" (\"did\") ON DELETE NO ACTION ON UPDATE NO ACTION)", await queryRunner.createTable( new Table({ - name: 'key', + name: getTableName('key'), columns: [ { name: 'kid', type: 'varchar', isPrimary: true }, { name: 'kms', type: 'varchar' }, @@ -51,7 +58,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { { columnNames: ['identifierDid'], referencedColumnNames: ['did'], - referencedTableName: 'identifier', + referencedTableName: getTableName('identifier'), }, ], }), @@ -62,7 +69,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE TABLE \"service\" (\"id\" varchar PRIMARY KEY NOT NULL, \"type\" varchar NOT NULL, \"serviceEndpoint\" varchar NOT NULL, \"description\" varchar, \"identifierDid\" varchar, CONSTRAINT \"FK_e16e0280d906951809f95dd09f1\" FOREIGN KEY (\"identifierDid\") REFERENCES \"identifier\" (\"did\") ON DELETE NO ACTION ON UPDATE NO ACTION)", await queryRunner.createTable( new Table({ - name: 'service', + name: getTableName('service'), columns: [ { name: 'id', type: 'varchar', isPrimary: true }, { name: 'type', type: 'varchar' }, @@ -74,7 +81,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { { columnNames: ['identifierDid'], referencedColumnNames: ['did'], - referencedTableName: 'identifier', + referencedTableName: getTableName('identifier'), onDelete: 'cascade', }, ], @@ -86,7 +93,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE TABLE \"credential\" (\"hash\" varchar PRIMARY KEY NOT NULL, \"raw\" text NOT NULL, \"id\" varchar, \"issuanceDate\" datetime NOT NULL, \"expirationDate\" datetime, \"context\" text NOT NULL, \"type\" text NOT NULL, \"issuerDid\" varchar, \"subjectDid\" varchar, CONSTRAINT \"FK_123d0977e0976565ee0932c0b9e\" FOREIGN KEY (\"issuerDid\") REFERENCES \"identifier\" (\"did\") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT \"FK_b790831f44e2fa7f9661a017b0a\" FOREIGN KEY (\"subjectDid\") REFERENCES \"identifier\" (\"did\") ON DELETE NO ACTION ON UPDATE NO ACTION)", await queryRunner.createTable( new Table({ - name: 'credential', + name: getTableName('credential'), columns: [ { name: 'hash', type: 'varchar', isPrimary: true }, { name: 'raw', type: 'text' }, @@ -102,13 +109,13 @@ export class CreateDatabase1447159020001 implements MigrationInterface { { columnNames: ['issuerDid'], referencedColumnNames: ['did'], - referencedTableName: 'identifier', + referencedTableName: getTableName('identifier'), onDelete: 'cascade', }, { columnNames: ['subjectDid'], referencedColumnNames: ['did'], - referencedTableName: 'identifier', + referencedTableName: getTableName('identifier'), }, ], }), @@ -119,7 +126,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE TABLE \"claim\" (\"hash\" varchar PRIMARY KEY NOT NULL, \"issuanceDate\" datetime NOT NULL, \"expirationDate\" datetime, \"context\" text NOT NULL, \"credentialType\" text NOT NULL, \"type\" varchar NOT NULL, \"value\" text, \"isObj\" boolean NOT NULL, \"issuerDid\" varchar, \"subjectDid\" varchar, \"credentialHash\" varchar, CONSTRAINT \"FK_d972c73d0f875c0d14c35b33baa\" FOREIGN KEY (\"issuerDid\") REFERENCES \"identifier\" (\"did\") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT \"FK_f411679379d373424100a1c73f4\" FOREIGN KEY (\"subjectDid\") REFERENCES \"identifier\" (\"did\") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT \"FK_3d494b79143de3d0e793883e351\" FOREIGN KEY (\"credentialHash\") REFERENCES \"credential\" (\"hash\") ON DELETE NO ACTION ON UPDATE NO ACTION)", await queryRunner.createTable( new Table({ - name: 'claim', + name: getTableName('claim'), columns: [ { name: 'hash', type: 'varchar', isPrimary: true }, { name: 'issuanceDate', type: dateTimeType }, @@ -137,18 +144,18 @@ export class CreateDatabase1447159020001 implements MigrationInterface { { columnNames: ['issuerDid'], referencedColumnNames: ['did'], - referencedTableName: 'identifier', + referencedTableName: getTableName('identifier'), onDelete: 'cascade', }, { columnNames: ['subjectDid'], referencedColumnNames: ['did'], - referencedTableName: 'identifier', + referencedTableName: getTableName('identifier'), }, { columnNames: ['credentialHash'], referencedColumnNames: ['hash'], - referencedTableName: 'credential', + referencedTableName: getTableName('credential'), onDelete: 'cascade', }, ], @@ -160,7 +167,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE TABLE \"presentation\" (\"hash\" varchar PRIMARY KEY NOT NULL, \"raw\" text NOT NULL, \"id\" varchar, \"issuanceDate\" datetime NOT NULL, \"expirationDate\" datetime, \"context\" text NOT NULL, \"type\" text NOT NULL, \"holderDid\" varchar, CONSTRAINT \"FK_a5e418449d9f527776a3bd0ca61\" FOREIGN KEY (\"holderDid\") REFERENCES \"identifier\" (\"did\") ON DELETE NO ACTION ON UPDATE NO ACTION)", await queryRunner.createTable( new Table({ - name: 'presentation', + name: getTableName('presentation'), columns: [ { name: 'hash', type: 'varchar', isPrimary: true }, { name: 'raw', type: 'text' }, @@ -175,7 +182,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { { columnNames: ['holderDid'], referencedColumnNames: ['did'], - referencedTableName: 'identifier', + referencedTableName: getTableName('identifier'), onDelete: 'cascade', }, ], @@ -187,7 +194,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE TABLE \"message\" (\"id\" varchar PRIMARY KEY NOT NULL, \"saveDate\" datetime NOT NULL DEFAULT (datetime('now')), \"updateDate\" datetime NOT NULL DEFAULT (datetime('now')), \"createdAt\" datetime, \"expiresAt\" datetime, \"threadId\" varchar, \"type\" varchar NOT NULL, \"raw\" varchar, \"data\" text, \"replyTo\" text, \"replyUrl\" varchar, \"metaData\" text, \"fromDid\" varchar, \"toDid\" varchar, CONSTRAINT \"FK_63bf73143b285c727bd046e6710\" FOREIGN KEY (\"fromDid\") REFERENCES \"identifier\" (\"did\") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT \"FK_1a666b2c29bb2b68d91259f55df\" FOREIGN KEY (\"toDid\") REFERENCES \"identifier\" (\"did\") ON DELETE NO ACTION ON UPDATE NO ACTION)", await queryRunner.createTable( new Table({ - name: 'message', + name: getTableName('message'), columns: [ { name: 'id', type: 'varchar', isPrimary: true }, { name: 'saveDate', type: dateTimeType }, @@ -208,12 +215,12 @@ export class CreateDatabase1447159020001 implements MigrationInterface { { columnNames: ['fromDid'], referencedColumnNames: ['did'], - referencedTableName: 'identifier', + referencedTableName: getTableName('identifier'), }, { columnNames: ['toDid'], referencedColumnNames: ['did'], - referencedTableName: 'identifier', + referencedTableName: getTableName('identifier'), }, ], }), @@ -226,7 +233,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE INDEX \"IDX_3a460e48557bad5564504ddad9\" ON \"presentation_verifier_identifier\" (\"identifierDid\")", await queryRunner.createTable( new Table({ - name: 'presentation_verifier_identifier', + name: getTableName('presentation_verifier_identifier'), columns: [ { name: 'presentationHash', type: 'varchar', isPrimary: true }, { name: 'identifierDid', type: 'varchar', isPrimary: true }, @@ -240,13 +247,13 @@ export class CreateDatabase1447159020001 implements MigrationInterface { { columnNames: ['presentationHash'], referencedColumnNames: ['hash'], - referencedTableName: 'presentation', + referencedTableName: getTableName('presentation'), onDelete: 'cascade', }, { columnNames: ['identifierDid'], referencedColumnNames: ['did'], - referencedTableName: 'identifier', + referencedTableName: getTableName('identifier'), onDelete: 'cascade', }, ], @@ -260,7 +267,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE INDEX \"IDX_ef88f92988763fee884c37db63\" ON \"presentation_credentials_credential\" (\"credentialHash\")", await queryRunner.createTable( new Table({ - name: 'presentation_credentials_credential', + name: getTableName('presentation_credentials_credential'), columns: [ { name: 'presentationHash', type: 'varchar', isPrimary: true }, { name: 'credentialHash', type: 'varchar', isPrimary: true }, @@ -274,13 +281,13 @@ export class CreateDatabase1447159020001 implements MigrationInterface { { columnNames: ['presentationHash'], referencedColumnNames: ['hash'], - referencedTableName: 'presentation', + referencedTableName: getTableName('presentation'), onDelete: 'cascade', }, { columnNames: ['credentialHash'], referencedColumnNames: ['hash'], - referencedTableName: 'credential', + referencedTableName: getTableName('credential'), onDelete: 'cascade', }, ], @@ -294,7 +301,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE INDEX \"IDX_a13b5cf828c669e61faf489c18\" ON \"message_presentations_presentation\" (\"presentationHash\")", await queryRunner.createTable( new Table({ - name: 'message_presentations_presentation', + name: getTableName('message_presentations_presentation'), columns: [ { name: 'messageId', type: 'varchar', isPrimary: true }, { name: 'presentationHash', type: 'varchar', isPrimary: true }, @@ -308,13 +315,13 @@ export class CreateDatabase1447159020001 implements MigrationInterface { { columnNames: ['messageId'], referencedColumnNames: ['id'], - referencedTableName: 'message', + referencedTableName: getTableName('message'), onDelete: 'cascade', }, { columnNames: ['presentationHash'], referencedColumnNames: ['hash'], - referencedTableName: 'presentation', + referencedTableName: getTableName('presentation'), onDelete: 'cascade', }, ], @@ -328,7 +335,7 @@ export class CreateDatabase1447159020001 implements MigrationInterface { // "CREATE INDEX \"IDX_8ae8195a94b667b185d2c023e3\" ON \"message_credentials_credential\" (\"credentialHash\")", await queryRunner.createTable( new Table({ - name: 'message_credentials_credential', + name: getTableName('message_credentials_credential'), columns: [ { name: 'messageId', type: 'varchar', isPrimary: true }, { name: 'credentialHash', type: 'varchar', isPrimary: true }, @@ -342,13 +349,13 @@ export class CreateDatabase1447159020001 implements MigrationInterface { { columnNames: ['messageId'], referencedColumnNames: ['id'], - referencedTableName: 'message', + referencedTableName: getTableName('message'), onDelete: 'cascade', }, { columnNames: ['credentialHash'], referencedColumnNames: ['hash'], - referencedTableName: 'credential', + referencedTableName: getTableName('credential'), onDelete: 'cascade', }, ], diff --git a/packages/data-store/src/migrations/2.simplifyRelations.ts b/packages/data-store/src/migrations/2.simplifyRelations.ts index 319642110..11d2ff54b 100644 --- a/packages/data-store/src/migrations/2.simplifyRelations.ts +++ b/packages/data-store/src/migrations/2.simplifyRelations.ts @@ -1,4 +1,4 @@ -import { MigrationInterface, QueryRunner, Table, TableColumn } from 'typeorm' +import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm' import Debug from 'debug' const debug = Debug('veramo:data-store:initial-migration') @@ -7,8 +7,22 @@ const debug = Debug('veramo:data-store:initial-migration') */ export class SimplifyRelations1447159020002 implements MigrationInterface { async up(queryRunner: QueryRunner): Promise { - await queryRunner.changeColumn("key", "identifierDid", new TableColumn({ name: 'identifierDid', type: 'varchar', isNullable: true })) - await queryRunner.changeColumn("service", "identifierDid", new TableColumn({ name: 'identifierDid', type: 'varchar', isNullable: true })) + function getTableName(givenName: string): string { + return ( + queryRunner.connection.entityMetadatas.find((meta) => meta.givenTableName === givenName)?.tableName || + givenName + ) + } + await queryRunner.changeColumn( + getTableName('key'), + 'identifierDid', + new TableColumn({ name: 'identifierDid', type: 'varchar', isNullable: true }), + ) + await queryRunner.changeColumn( + getTableName('service'), + 'identifierDid', + new TableColumn({ name: 'identifierDid', type: 'varchar', isNullable: true }), + ) } async down(queryRunner: QueryRunner): Promise { diff --git a/packages/data-store/src/migrations/createPrivateKeyStorage.ts b/packages/data-store/src/migrations/createPrivateKeyStorage.ts index e8cae8240..26a24f048 100644 --- a/packages/data-store/src/migrations/createPrivateKeyStorage.ts +++ b/packages/data-store/src/migrations/createPrivateKeyStorage.ts @@ -9,11 +9,17 @@ const debug = Debug('veramo:data-store:key-migration') */ export class CreatePrivateKeyStorage1629293428674 implements MigrationInterface { async up(queryRunner: QueryRunner): Promise { + function getTableName(givenName: string): string { + return ( + queryRunner.connection.entityMetadatas.find((meta) => meta.givenTableName === givenName)?.tableName || + givenName + ) + } // 1.create new table debug(`creating new private-key table`) await queryRunner.createTable( new Table({ - name: 'private-key', + name: getTableName('private-key'), columns: [ { name: 'alias', @@ -43,15 +49,26 @@ export class CreatePrivateKeyStorage1629293428674 implements MigrationInterface privateKeyHex: key.privateKeyHex, })) debug(`${privKeys.length} keys need to be migrated`) - await queryRunner.manager.createQueryBuilder().insert().into('private-key').values(privKeys).execute() + await queryRunner.manager + .createQueryBuilder() + .insert() + .into(getTableName('private-key')) + .values(privKeys) + .execute() // 3. drop old column debug(`dropping privKeyHex column from old key table`) - await queryRunner.dropColumn('key', 'privateKeyHex') + await queryRunner.dropColumn(getTableName('key'), 'privateKeyHex') //4. done debug(`migrated ${privKeys.length} keys to private key storage`) } async down(queryRunner: QueryRunner): Promise { + function getTableName(givenName: string): string { + return ( + queryRunner.connection.entityMetadatas.find((meta) => meta.givenTableName === givenName)?.tableName || + givenName + ) + } // 1. add old column back debug(`adding back privateKeyHex column to key table`) await queryRunner.addColumn( @@ -68,15 +85,15 @@ export class CreatePrivateKeyStorage1629293428674 implements MigrationInterface debug(`copying ${keys.length} keys`) for (const key of keys) { await queryRunner.manager - .createQueryBuilder() - .update(PreMigrationKey) - .set({ privateKeyHex: key.privateKeyHex }) - .where('kid = :alias', { alias: key.alias }) - .execute() + .createQueryBuilder() + .update(PreMigrationKey) + .set({ privateKeyHex: key.privateKeyHex }) + .where('kid = :alias', { alias: key.alias }) + .execute() } debug(`dropping private-key table`) // 3. drop the new private key table - await queryRunner.dropTable('private-key') + await queryRunner.dropTable(getTableName('private-key')) // 4. done debug(`rolled back ${keys.length} keys`) } diff --git a/packages/did-comm/plugin.schema.json b/packages/did-comm/plugin.schema.json index ffd1f0311..1e6564ea7 100644 --- a/packages/did-comm/plugin.schema.json +++ b/packages/did-comm/plugin.schema.json @@ -263,7 +263,7 @@ "id", "type" ], - "description": "DIDComm message" + "description": "Represents a DIDComm v1 message payload, with optionally decoded credentials and presentations." }, "IMetaData": { "type": "object", @@ -351,13 +351,13 @@ }, "required": [ "@context", - "type", - "issuer", - "issuanceDate", "credentialSubject", - "proof" + "issuanceDate", + "issuer", + "proof", + "type" ], - "description": "Verifiable Credential {@link https://github.com/decentralized-identifier/did-jwt-vc }" + "description": "Represents a signed Verifiable Credential payload (includes proof). See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }" }, "VerifiablePresentation": { "type": "object", @@ -408,13 +408,13 @@ } }, "required": [ - "holder", "@context", + "holder", + "proof", "type", - "verifier", - "proof" + "verifier" ], - "description": "Verifiable Presentation {@link https://github.com/decentralized-identifier/did-jwt-vc }" + "description": "Represents a signed Verifiable Presentation (includes proof). See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model }" }, "IUnpackDIDCommMessageArgs": { "$ref": "#/components/schemas/IPackedDIDCommMessage", diff --git a/packages/did-provider-ethr/src/__tests__/identity-provider.test.ts b/packages/did-provider-ethr/src/__tests__/identity-provider.test.ts index bf92745cb..a87bfb973 100644 --- a/packages/did-provider-ethr/src/__tests__/identity-provider.test.ts +++ b/packages/did-provider-ethr/src/__tests__/identity-provider.test.ts @@ -13,7 +13,7 @@ describe('dummy', () => { }) // describe('@veramo/did-provider-ethr', () => { -// const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c' +// const infuraProjectId = '3586660d179141e3801c3895de1c2eba' // const rpcUrl = 'https://rinkeby.infura.io/v3/' + infuraProjectId // const resolver = new DIDResolverPlugin({ infuraProjectId }) // const key = { diff --git a/packages/selective-disclosure/plugin.schema.json b/packages/selective-disclosure/plugin.schema.json index f46689fc1..afc995a22 100644 --- a/packages/selective-disclosure/plugin.schema.json +++ b/packages/selective-disclosure/plugin.schema.json @@ -90,13 +90,13 @@ } }, "required": [ - "holder", "@context", + "holder", + "proof", "type", - "verifier", - "proof" + "verifier" ], - "description": "Verifiable Presentation {@link https://github.com/decentralized-identifier/did-jwt-vc }" + "description": "Represents a signed Verifiable Presentation (includes proof). See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model }" }, "VerifiableCredential": { "type": "object", @@ -167,13 +167,13 @@ }, "required": [ "@context", - "type", - "issuer", - "issuanceDate", "credentialSubject", - "proof" + "issuanceDate", + "issuer", + "proof", + "type" ], - "description": "Verifiable Credential {@link https://github.com/decentralized-identifier/did-jwt-vc }" + "description": "Represents a signed Verifiable Credential payload (includes proof). See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }" }, "ICreateSelectiveDisclosureRequestArgs": { "type": "object",