Skip to content

Commit 7bba82c

Browse files
[hotfix] Wallet.import Must Load List of Addresses during Hydration (coinbase#145)
1 parent 1bc6462 commit 7bba82c

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,14 @@ await store(data);
190190
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.
191191

192192
```typescript
193-
wallet.saveSeed(wallet);
193+
const seedFilePath = "";
194+
wallet.saveSeed(seedFilePath);
194195
```
195196

196197
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`.
197198

198199
```typescript
199-
wallet.saveSeed(wallet, true);
200+
wallet.saveSeed(seedFilePath, true);
200201
```
201202

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

211212
```typescript
212-
// Ensure your seed file path is updated
213-
const seedFilePath = "";
214213
const userWallet = await user.getWallet(wallet.getId());
215214
await userWallet.loadSeed(seedFilePath);
216215
```

src/coinbase/wallet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class Wallet {
119119
}
120120
const walletModel = await Coinbase.apiClients.wallet!.getWallet(data.walletId);
121121
const wallet = Wallet.init(walletModel.data, data.seed);
122+
await wallet.listAddresses();
122123
return wallet;
123124
}
124125

src/tests/wallet_test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,13 @@ describe("Wallet Class", () => {
784784
it("should return true for canSign when the wallet is initialized with a seed", () => {
785785
expect(wallet.canSign()).toBe(true);
786786
});
787+
788+
it("should be able to be imported", async () => {
789+
const walletData = seedWallet.export();
790+
const importedWallet = await Wallet.import(walletData);
791+
expect(importedWallet).toBeInstanceOf(Wallet);
792+
expect(Coinbase.apiClients.address!.listAddresses).toHaveBeenCalledTimes(1);
793+
});
787794
});
788795

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

977-
describe(".loadSeed", () => {
984+
describe("#loadSeed", () => {
978985
const seed = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f";
979986
let apiPrivateKey;
980987
const filePath = "seeds.json";

0 commit comments

Comments
 (0)