From ffa8518d81c1342afac51c6a454df57557294be4 Mon Sep 17 00:00:00 2001 From: Ryan Gilbert Date: Tue, 17 Dec 2024 11:08:43 -0500 Subject: [PATCH] chore: add networkId to WalletData --- CHANGELOG.md | 1 + src/coinbase/types.ts | 2 ++ src/coinbase/wallet.ts | 3 ++- src/tests/e2e.ts | 7 ++++++- src/tests/wallet_test.ts | 1 + 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85e3b7b9..b73bb193 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Add support for fetching address reputation - Add `reputation` method to `Address` to fetch the reputation of the address. +- Add `networkId` to `WalletData` so that it is saved with the seed data and surfaced via the export function ## [0.12.0] - Skipped diff --git a/src/coinbase/types.ts b/src/coinbase/types.ts index 506d2da7..b07a790b 100644 --- a/src/coinbase/types.ts +++ b/src/coinbase/types.ts @@ -818,6 +818,7 @@ export enum FundOperationStatus { export type WalletData = { walletId: string; seed: string; + networkId: string; }; /** @@ -828,6 +829,7 @@ export type SeedData = { encrypted: boolean; authTag: string; iv: string; + networkId: string; }; /** diff --git a/src/coinbase/wallet.ts b/src/coinbase/wallet.ts index b8b16e97..7151c28c 100644 --- a/src/coinbase/wallet.ts +++ b/src/coinbase/wallet.ts @@ -221,7 +221,7 @@ export class Wallet { if (!this.seed) { throw new Error("Cannot export Wallet without loaded seed"); } - return { walletId: this.getId()!, seed: this.seed }; + return { walletId: this.getId()!, seed: this.seed, networkId: this.getNetworkId() }; } /** @@ -631,6 +631,7 @@ export class Wallet { encrypted: encrypt, authTag: authTag, iv: iv, + networkId: data.networkId, }; fs.writeFileSync(filePath, JSON.stringify(existingSeedsInStore, null, 2), "utf8"); diff --git a/src/tests/e2e.ts b/src/tests/e2e.ts index 6fc2fce1..dba5626d 100644 --- a/src/tests/e2e.ts +++ b/src/tests/e2e.ts @@ -54,7 +54,11 @@ describe("Coinbase SDK E2E Test", () => { const walletId = Object.keys(seedFile)[0]; const seed = seedFile[walletId].seed; - const importedWallet = await Wallet.import({ seed, walletId }); + const importedWallet = await Wallet.import({ + seed, + walletId, + networkId: Coinbase.networks.BaseSepolia, + }); expect(importedWallet).toBeDefined(); expect(importedWallet.getId()).toBe(walletId); console.log( @@ -138,6 +142,7 @@ describe("Coinbase SDK E2E Test", () => { encrypted: false, authTag: "", iv: "", + networkId: exportedWallet.networkId, }); }, 60000); }); diff --git a/src/tests/wallet_test.ts b/src/tests/wallet_test.ts index ba37aef3..c1e63468 100644 --- a/src/tests/wallet_test.ts +++ b/src/tests/wallet_test.ts @@ -1197,6 +1197,7 @@ describe("Wallet Class", () => { expect(walletSeedData[walletId].iv).toBe(""); expect(walletSeedData[walletId].authTag).toBe(""); expect(walletSeedData[walletId].seed).toBe(seed); + expect(walletSeedData[walletId].networkId).toBe(seedWallet.getNetworkId()); }); it("should save the seed when encryption is true", async () => {