Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hotfix] Wallet.import Must Load List of Addresses during Hydration #145

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -190,13 +190,14 @@ await store(data);
For convenience during testing, we provide a `saveSeed` method that stores the wallet's seed in your local file system. This is an insecure method of storing wallet seeds and should only be used for development purposes.

```typescript
wallet.saveSeed(wallet);
const seedFilePath = "";
wallet.saveSeed(seedFilePath);
```

To encrypt the saved data, set encrypt to true. Note that your CDP API key also serves as the encryption key for the data persisted locally. To re-instantiate wallets with encrypted data, ensure that your SDK is configured with the same API key when invoking `saveSeed` and `loadSeed`.

```typescript
wallet.saveSeed(wallet, true);
wallet.saveSeed(seedFilePath, true);
```

The below code demonstrates how to re-instantiate a Wallet from the data export.
@@ -209,8 +210,6 @@ const importedWallet = await user.importWallet(data);
To import Wallets that were persisted to your local file system using `saveSeed`, use the below code.

```typescript
// Ensure your seed file path is updated
const seedFilePath = "";
const userWallet = await user.getWallet(wallet.getId());
await userWallet.loadSeed(seedFilePath);
```
1 change: 1 addition & 0 deletions src/coinbase/wallet.ts
Original file line number Diff line number Diff line change
@@ -119,6 +119,7 @@ export class Wallet {
}
const walletModel = await Coinbase.apiClients.wallet!.getWallet(data.walletId);
const wallet = Wallet.init(walletModel.data, data.seed);
await wallet.listAddresses();
return wallet;
}

9 changes: 8 additions & 1 deletion src/tests/wallet_test.ts
Original file line number Diff line number Diff line change
@@ -784,6 +784,13 @@ describe("Wallet Class", () => {
it("should return true for canSign when the wallet is initialized with a seed", () => {
expect(wallet.canSign()).toBe(true);
});

it("should be able to be imported", async () => {
const walletData = seedWallet.export();
const importedWallet = await Wallet.import(walletData);
expect(importedWallet).toBeInstanceOf(Wallet);
expect(Coinbase.apiClients.address!.listAddresses).toHaveBeenCalledTimes(1);
});
});

describe("#listBalances", () => {
@@ -974,7 +981,7 @@ describe("Wallet Class", () => {
});
});

describe(".loadSeed", () => {
describe("#loadSeed", () => {
const seed = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f";
let apiPrivateKey;
const filePath = "seeds.json";