Skip to content

Commit

Permalink
[hotfix] Wallet.import Must Load List of Addresses during Hydration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
John-peterson-coinbase authored Aug 12, 2024
1 parent 1bc6462 commit 7bba82c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
```
Expand Down
1 change: 1 addition & 0 deletions src/coinbase/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 8 additions & 1 deletion src/tests/wallet_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -974,7 +981,7 @@ describe("Wallet Class", () => {
});
});

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

0 comments on commit 7bba82c

Please sign in to comment.