Skip to content

Commit

Permalink
feat(askar): use copyTo for export/import
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
genaris committed Oct 30, 2023
1 parent c247385 commit 037f091
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 50 deletions.
4 changes: 2 additions & 2 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"refresh": "rm -rf ./node_modules ./yarn.lock && yarn"
},
"dependencies": {
"@hyperledger/indy-vdr-nodejs": "^0.2.0-dev.2",
"@hyperledger/anoncreds-nodejs": "^0.2.0-dev.3",
"@hyperledger/indy-vdr-nodejs": "^0.2.0-dev.3",
"@hyperledger/anoncreds-nodejs": "^0.2.0-dev.4",
"@hyperledger/aries-askar-nodejs": "^0.2.0-dev.1",
"inquirer": "^8.2.5"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/anoncreds-rs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
"tsyringe": "^4.8.0"
},
"devDependencies": {
"@hyperledger/anoncreds-nodejs": "^0.2.0-dev.3",
"@hyperledger/anoncreds-shared": "^0.2.0-dev.3",
"@hyperledger/anoncreds-nodejs": "^0.2.0-dev.4",
"@hyperledger/anoncreds-shared": "^0.2.0-dev.4",
"@types/ref-array-di": "^1.2.6",
"@types/ref-struct-di": "^1.1.10",
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.0",
"typescript": "~4.9.5"
},
"peerDependencies": {
"@hyperledger/anoncreds-shared": "^0.2.0-dev.3"
"@hyperledger/anoncreds-shared": "^0.2.0-dev.4"
}
}
37 changes: 14 additions & 23 deletions packages/askar/src/wallet/AskarWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,29 +294,19 @@ export class AskarWallet extends AskarBaseWallet {
}
const exportedWalletConfig = await this.getAskarWalletConfig({
...this.walletConfig,
key: exportKey,
storage: { type: 'sqlite', path: destinationPath },
})

// Close this wallet before copying
await this.close()

// Make sure destination path exists
await this.fileSystem.createDirectory(destinationPath)

// Copy wallet to the destination path
await this.fileSystem.copyFile(sourcePath, destinationPath)

// Open exported wallet and rotate its key to the one requested
const exportedWalletStore = await Store.open({
await this.store.copyTo({
recreate: false,
uri: exportedWalletConfig.uri,
keyMethod: exportedWalletConfig.keyMethod,
passKey: exportedWalletConfig.passKey,
})
await exportedWalletStore.rekey({ keyMethod: exportedWalletConfig.keyMethod, passKey: exportKey })

await exportedWalletStore.close()

await this._open(this.walletConfig)
} catch (error) {
const errorMessage = `Error exporting wallet '${this.walletConfig.id}': ${error.message}`
this.logger.error(errorMessage, {
Expand All @@ -343,25 +333,26 @@ export class AskarWallet extends AskarBaseWallet {

// Import path already exists
if (await this.fileSystem.exists(destinationPath)) {
throw new WalletExportPathExistsError(`Unable to import wallet. Path '${importConfig.path}' already exists`)
throw new WalletExportPathExistsError(`Unable to import wallet. Path '${destinationPath}' already exists`)
}

// Make sure destination path exists
await this.fileSystem.createDirectory(destinationPath)

// Copy wallet to the destination path
await this.fileSystem.copyFile(sourcePath, destinationPath)

// Open imported wallet and rotate its key to the one requested
const importedWalletStore = await Store.open({
uri: importWalletConfig.uri,
// Open imported wallet and copy to destination
const sourceWalletStore = await Store.open({
uri: `sqlite://${sourcePath}`,
keyMethod: importWalletConfig.keyMethod,
passKey: importKey,
})

await importedWalletStore.rekey({ keyMethod: importWalletConfig.keyMethod, passKey: importWalletConfig.passKey })
await sourceWalletStore.copyTo({
recreate: false,
uri: importWalletConfig.uri,
keyMethod: importWalletConfig.keyMethod,
passKey: importWalletConfig.passKey,
})

await importedWalletStore.close()
await sourceWalletStore.close()
} catch (error) {
const errorMessage = `Error importing wallet '${walletConfig.id}': ${error.message}`
this.logger.error(errorMessage, {
Expand Down
2 changes: 1 addition & 1 deletion packages/askar/tests/askar-sqlite.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('Askar SQLite agents', () => {
// Initialize the wallet again and assert record does not exist
// This should create a new wallet
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await bobAgent.wallet.initialize(bobAgentOptions.config.walletConfig!)
await bobAgent.wallet.initialize(bobAgent.config.walletConfig!)
expect(await bobBasicMessageRepository.findById(bobAgent.context, basicMessageRecord.id)).toBeNull()
await bobAgent.wallet.delete()

Expand Down
6 changes: 3 additions & 3 deletions packages/indy-vdr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"@aries-framework/core": "0.4.2"
},
"devDependencies": {
"@hyperledger/indy-vdr-nodejs": "^0.2.0-dev.2",
"@hyperledger/indy-vdr-shared": "^0.2.0-dev.2",
"@hyperledger/indy-vdr-nodejs": "^0.2.0-dev.3",
"@hyperledger/indy-vdr-shared": "^0.2.0-dev.3",
"@stablelib/ed25519": "^1.0.2",
"@types/ref-array-di": "^1.2.6",
"@types/ref-struct-di": "^1.1.10",
Expand All @@ -38,6 +38,6 @@
"typescript": "~4.9.5"
},
"peerDependencies": {
"@hyperledger/indy-vdr-shared": "^0.2.0-dev.2"
"@hyperledger/indy-vdr-shared": "^0.2.0-dev.3"
}
}
36 changes: 18 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1125,22 +1125,22 @@
resolved "https://registry.yarnpkg.com/@hutson/parse-repository-url/-/parse-repository-url-3.0.2.tgz#98c23c950a3d9b6c8f0daed06da6c3af06981340"
integrity sha512-H9XAx3hc0BQHY6l+IFSWHDySypcXsvsuLhgYLUGywmJ5pswRVQJUHpOsobnLYp2ZUaUlKiKDrgWWhosOwAEM8Q==

"@hyperledger/anoncreds-nodejs@^0.2.0-dev.3":
version "0.2.0-dev.3"
resolved "https://registry.yarnpkg.com/@hyperledger/anoncreds-nodejs/-/anoncreds-nodejs-0.2.0-dev.3.tgz#de79e978e569646b0efc4cca3509bffa36cccc8d"
integrity sha512-WDJ2okgg3pOIyOttDGfmSjFNu2xmZsRsNba23z3O0WyKZZ0JdrmPdDpOnbbtuiPKq88NtE0GRH+vo9aTRsQ4hw==
"@hyperledger/anoncreds-nodejs@^0.2.0-dev.4":
version "0.2.0-dev.4"
resolved "https://registry.yarnpkg.com/@hyperledger/anoncreds-nodejs/-/anoncreds-nodejs-0.2.0-dev.4.tgz#ac125817beb631dedbe27cb8d4c21d2123104d5e"
integrity sha512-EH/jAH+aATH9KByWF1lk1p76BN6VIsRZhG7jyRT1LAaaUNnmpQnjX6d/Mfkofvk4xFIRbp0cDl/UjaKaKfLsww==
dependencies:
"@2060.io/ffi-napi" "4.0.8"
"@2060.io/ref-napi" "3.0.6"
"@hyperledger/anoncreds-shared" "0.2.0-dev.3"
"@hyperledger/anoncreds-shared" "0.2.0-dev.4"
"@mapbox/node-pre-gyp" "^1.0.11"
ref-array-di "1.2.2"
ref-struct-di "1.1.1"

"@hyperledger/[email protected].3", "@hyperledger/anoncreds-shared@^0.2.0-dev.3":
version "0.2.0-dev.3"
resolved "https://registry.yarnpkg.com/@hyperledger/anoncreds-shared/-/anoncreds-shared-0.2.0-dev.3.tgz#13909ad67370f6bee137f24c4a1dae7397c94a77"
integrity sha512-fuj+4N/ZMEp6d6Kkdk1J81MOz6goSUm9+Io60G5iC3nAVTu18ntM0qPUgAW67FXAcCxYrjdwQ1i6kW6dv1iBYw==
"@hyperledger/[email protected].4", "@hyperledger/anoncreds-shared@^0.2.0-dev.4":
version "0.2.0-dev.4"
resolved "https://registry.yarnpkg.com/@hyperledger/anoncreds-shared/-/anoncreds-shared-0.2.0-dev.4.tgz#8050647fcb153b594671270d4c51b3b423e575be"
integrity sha512-8hwXc9zab8MgXgwo0OL5bShxMAfDEiBAB1/r+8mbwgANefDZwHwNOkq0yQLwT2KfSsvH9la7N2ehrtUf5E2FKg==

"@hyperledger/aries-askar-nodejs@^0.2.0-dev.1":
version "0.2.0-dev.1"
Expand All @@ -1162,22 +1162,22 @@
dependencies:
buffer "^6.0.3"

"@hyperledger/indy-vdr-nodejs@^0.2.0-dev.2":
version "0.2.0-dev.2"
resolved "https://registry.yarnpkg.com/@hyperledger/indy-vdr-nodejs/-/indy-vdr-nodejs-0.2.0-dev.2.tgz#9349df0c3ff3d09e779483a31fb9ceffba829264"
integrity sha512-m8cBonthinPAiGvyKIfVk/AIRMUhkzcjslQKRbdOiexSaWuk5TprKQByLgt/9KRZZOzx9hvoChQ1a1tS/4alXQ==
"@hyperledger/indy-vdr-nodejs@^0.2.0-dev.3":
version "0.2.0-dev.3"
resolved "https://registry.yarnpkg.com/@hyperledger/indy-vdr-nodejs/-/indy-vdr-nodejs-0.2.0-dev.3.tgz#c7262df6545606c893994e236c635c287cd64fd0"
integrity sha512-W4z8AtrNGb4hbbdisz6HAFqyAoX9c4oT3qo/8mizKyuYCSiSwlmAllkIFjCt93xyYmecTivkY2V2BcWpaUW47A==
dependencies:
"@2060.io/ffi-napi" "4.0.8"
"@2060.io/ref-napi" "3.0.6"
"@hyperledger/indy-vdr-shared" "0.2.0-dev.2"
"@hyperledger/indy-vdr-shared" "0.2.0-dev.3"
"@mapbox/node-pre-gyp" "^1.0.10"
ref-array-di "^1.2.2"
ref-struct-di "^1.1.1"

"@hyperledger/[email protected].2", "@hyperledger/indy-vdr-shared@^0.2.0-dev.2":
version "0.2.0-dev.2"
resolved "https://registry.yarnpkg.com/@hyperledger/indy-vdr-shared/-/indy-vdr-shared-0.2.0-dev.2.tgz#359804ba033e796391270b3da9a5a3ab816f73da"
integrity sha512-z5H08W4/lQXrZxgeY4mAKsFRZ43d7HQlcqR8XmAUvZmjYOYwvNv215y1esujazmYsJfmdl+6SVSWhZK46qzyTw==
"@hyperledger/[email protected].3", "@hyperledger/indy-vdr-shared@^0.2.0-dev.3":
version "0.2.0-dev.3"
resolved "https://registry.yarnpkg.com/@hyperledger/indy-vdr-shared/-/indy-vdr-shared-0.2.0-dev.3.tgz#14994a034691ffe08e14e5f7d60fd63237616d04"
integrity sha512-5/zgSxp4zZUuFLabWdpB6ttfD0aLIquR9qab+HAJFUYDiWGHKP7bztiu07p4Dvhtgah+ZFOFgQo7WC492DXBoQ==

"@isaacs/string-locale-compare@^1.1.0":
version "1.1.0"
Expand Down

0 comments on commit 037f091

Please sign in to comment.