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

chore(PSDK-640): add networkId to WalletData #343

Open
wants to merge 1 commit into
base: v0.13.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/coinbase/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ export enum FundOperationStatus {
export type WalletData = {
walletId: string;
seed: string;
networkId: string;
};

/**
Expand All @@ -828,6 +829,7 @@ export type SeedData = {
encrypted: boolean;
authTag: string;
iv: string;
networkId: string;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/coinbase/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
}

/**
Expand Down Expand Up @@ -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");
Expand Down
7 changes: 6 additions & 1 deletion src/tests/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -138,6 +142,7 @@ describe("Coinbase SDK E2E Test", () => {
encrypted: false,
authTag: "",
iv: "",
networkId: exportedWallet.networkId,
});
}, 60000);
});
Expand Down
1 change: 1 addition & 0 deletions src/tests/wallet_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Loading