Skip to content

Commit

Permalink
Updating setSeed return type
Browse files Browse the repository at this point in the history
  • Loading branch information
erdimaden committed May 24, 2024
1 parent d15e20e commit 603ca87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/coinbase/tests/user_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,11 @@ describe("User Class", () => {
});
Coinbase.apiClients.address!.listAddresses = mockReturnValue(mockAddressModel);
const [unhydratedWallet] = await user.getWallets();
const wallet = await unhydratedWallet.setSeed(seed);
expect(wallet).toBeInstanceOf(Wallet);
expect(wallet?.getId()).toBe(walletId);
expect(unhydratedWallet.canSign()).toBe(false);
await unhydratedWallet.setSeed(seed);
expect(unhydratedWallet).toBeInstanceOf(Wallet);
expect(unhydratedWallet?.getId()).toBe(walletId);
expect(unhydratedWallet.canSign()).toBe(true);
});

it("should prevent access to master wallet required methods", async () => {
Expand Down
9 changes: 4 additions & 5 deletions src/coinbase/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,11 @@ export class Wallet {
* Returns the Wallet model.
*
* @param seed - The seed to use for the Wallet. Expects a 32-byte hexadecimal with no 0x prefix.
* @returns The Wallet object.
*/
public async setSeed(seed: string): Promise<Wallet | undefined> {
return this.master === undefined
? await Wallet.init(this.model, seed, this.addressModels)
: undefined;
public async setSeed(seed: string): Promise<void> {
if (this.master === undefined) {
this.master = HDKey.fromMasterSeed(bip39.mnemonicToSeedSync(seed));
}
}

/**
Expand Down

0 comments on commit 603ca87

Please sign in to comment.