openwallet-foundation / credo-ts

Typescript framework for building decentralized identity and verifiable credential solutions
https://credo.js.org
Apache License 2.0
270 stars 200 forks source link

Restoring wallet from local storage in bifold fails #1936

Closed Arif-Shahriar028 closed 4 months ago

Arif-Shahriar028 commented 4 months ago

I am working on backup and restore wallet functionality in bifold. Backup functionality is working fine with agent.wallet.export. But when restoring the wallet by agent.wallet.import, I encountered an error:

Error importing wallet '': Error connecting to database pool Caused by: error returned from database: (code: 26) file is not a database

In old version of bifold (v1.0.0-alpha.81), export function creates just one sqlite backup file. But current bifold version (v1.0.0-alpha.256) is creating two backup binary files: fileName-shm and fileName-wal. I am selecting the -wal file path for importing the wallet.

Backup functionality code snippet:

image

Created backup files: image

Restore code snippet: image

I am selecting -wal file by document picker and converting the content uri to relative path of the file.

image

When importing the wallet the encountered error is: image

How can I mitigate this error?

genaris commented 4 months ago

Apart from the wal and shm files, you should be seeing a file without suffix (i.e. backup_wallet_arifshahriar028_1719384806907). That's the one you should select. The three files must be present (toghether in the same directory) when importing, since all of them are needed to open the SQLite database.

Arif-Shahriar028 commented 4 months ago

@genaris I was also expecting a file without suffix. But there is no file generated like this. But the older version of bifold generates only one file without suffix. Following is the generated files by the newer version of bifold:

image

Do you have any idea why the third file is not generating?

Arif-Shahriar028 commented 4 months ago

After agent.wallet.export(), I was using RNFS.unlink(filePath) which deleted the third file I was expecting.

image

After commenting out RNFS.unlink(), the exporting working fine.

@genaris thanks for your idea!