-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: blu3beri <[email protected]>
- Loading branch information
blu3beri
committed
Mar 13, 2023
1 parent
f8e423c
commit fac9efb
Showing
4 changed files
with
190 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 72 additions & 26 deletions
98
packages/indy-sdk-to-askar-migration/tests/migrate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,85 @@ | ||
import { ariesAskar } from '@hyperledger/aries-askar-nodejs' | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import type { InitConfig, WalletConfig } from '@aries-framework/core' | ||
|
||
import { AskarModule } from '@aries-framework/askar' | ||
import { utils, ConsoleLogger, LogLevel, KeyDerivationMethod, Agent } from '@aries-framework/core' | ||
import { IndySdkModule } from '@aries-framework/indy-sdk' | ||
import { agentDependencies } from '@aries-framework/node' | ||
import { ariesAskar, Migration } from '@hyperledger/aries-askar-nodejs' | ||
import { registerAriesAskar } from '@hyperledger/aries-askar-shared' | ||
import fs from 'fs' | ||
import indy from 'indy-sdk' | ||
import { homedir } from 'os' | ||
import path from 'path' | ||
|
||
import { IndySdkToAskarMigrationUpdater } from '../src' | ||
|
||
describe('Migrate', () => { | ||
const config: InitConfig = { | ||
label: 'test-agent', | ||
walletConfig: { | ||
id: `walletwallet.0-${utils.uuid()}`, | ||
key: 'GfwU1DC7gEZNs3w41tjBiZYj7BNToDoFEqKY6wZXqs1A', | ||
keyDerivationMethod: KeyDerivationMethod.Raw, | ||
}, | ||
// logger: new ConsoleLogger(LogLevel.trace), | ||
} | ||
|
||
const oldAgent = new Agent({ | ||
config, | ||
modules: { indySdk: new IndySdkModule({ indySdk: indy }) }, | ||
dependencies: agentDependencies, | ||
}) | ||
|
||
const newAgent = new Agent({ | ||
config, | ||
modules: { askar: new AskarModule() }, | ||
dependencies: agentDependencies, | ||
}) | ||
|
||
const oldDbPath = `${homedir()}/.indy_client/wallet/${oldAgent.config.walletConfig?.id}/sqlite.db` | ||
const newDbPath = `${homedir()}/.afj/data/wallet/${newAgent.config.walletConfig?.id}/sqlite.db` | ||
|
||
beforeAll(() => { | ||
registerAriesAskar({ askar: ariesAskar }) | ||
}) | ||
|
||
// beforeEach(async () => { | ||
// await new Promise((resolve) => | ||
// fs.copyFile( | ||
// '/Users/beri/.indy_client/wallet/walletwallet.0/sqlite.db', | ||
// '/Users/beri/.indy_client/wallet/walletwallet.0/sqlite.bak.db', | ||
// resolve | ||
// ) | ||
// ) | ||
// }) | ||
|
||
// TODO: update with an aca-py issued revokable credential | ||
// community agent MIGHT have revocrevoc | ||
// TODO: should take uninitialized agent | ||
test('indy-sdk sqlite to aries-askar sqlite', async () => { | ||
// try { | ||
const walletName = 'walletwallet.0' | ||
const walletKey = 'GfwU1DC7gEZNs3w41tjBiZYj7BNToDoFEqKY6wZXqs1A' | ||
const dbPath = `/Users/beri/Developer/work/hyperledger/aries-askar/tests/indy_wallet_sqlite_upgraded.db` | ||
const specUri = `sqlite://${dbPath}` | ||
const updater = await IndySdkToAskarMigrationUpdater.init(specUri, walletName, walletKey) | ||
const genericRecord = { foo: 'bar' } | ||
|
||
await oldAgent.initialize() | ||
|
||
const record = await oldAgent.genericRecords.save({ content: genericRecord }) | ||
|
||
const walletConfig: WalletConfig = { | ||
key: oldAgent.config.walletConfig!.key, | ||
id: oldAgent.config.walletConfig!.id, | ||
keyDerivationMethod: oldAgent.config.walletConfig!.keyDerivationMethod, | ||
} | ||
|
||
await oldAgent.shutdown() | ||
|
||
await Migration.migrate({ | ||
walletName: walletConfig.id, | ||
walletKey: walletConfig.key, | ||
kdfLevel: walletConfig.keyDerivationMethod?.toString() ?? 'ARGON2I_MOD', | ||
specUri: oldDbPath, | ||
}) | ||
|
||
const updater = await IndySdkToAskarMigrationUpdater.initialize({ uri: `sqlite://${oldDbPath}`, agent: oldAgent }) | ||
await updater.update() | ||
// } finally { | ||
// await new Promise((resolve) => | ||
// fs.rename( | ||
// '/Users/beri/.indy_client/wallet/walletwallet.0/sqlite.bak.db', | ||
// '/Users/beri/.indy_client/wallet/walletwallet.0/sqlite.db', | ||
// resolve | ||
// ) | ||
// ) | ||
// } | ||
|
||
fs.mkdirSync(path.dirname(newDbPath), { recursive: true }) | ||
|
||
await newAgent.initialize() | ||
// await newAgent.wallet.import(oldAgent.config.walletConfig!, { | ||
// path: oldDbPath, | ||
// key: oldAgent.config.walletConfig!.key, | ||
// }) | ||
|
||
await expect(newAgent.genericRecords.findById(record.id)).resolves.toMatchObject(genericRecord) | ||
}) | ||
}) |
Oops, something went wrong.