Skip to content

Commit

Permalink
BREAKING CHANGE: drop fs support in xpubstore (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
homura authored May 21, 2024
1 parent 6e0d0e2 commit 656cbca
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
18 changes: 1 addition & 17 deletions packages/hd/src/xpub_store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AccountExtendedPublicKey } from "./extended_key";
import fs from "fs";

export class XPubStore {
private accountExtendedPublicKey: AccountExtendedPublicKey;
Expand All @@ -12,28 +11,13 @@ export class XPubStore {
return this.accountExtendedPublicKey;
}

save(
path: string,
{
overwrite = false,
}: {
overwrite?: boolean;
} = {}
) {
if (!overwrite && fs.existsSync(path)) {
throw new Error("XPub file already exists!");
}
fs.writeFileSync(path, this.toJson());
}

toJson(): string {
return JSON.stringify({
xpubkey: this.accountExtendedPublicKey.serialize().slice(2),
});
}

static load(path: string): XPubStore {
const json = fs.readFileSync(path, "utf-8");
static fromJson(json: string): XPubStore {
const xpub = JSON.parse(json).xpubkey;
const accountExtendedPublicKey = AccountExtendedPublicKey.parse(
"0x" + xpub
Expand Down
2 changes: 1 addition & 1 deletion packages/hd/tests/xpub_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const accountExtendedPublicKey = new AccountExtendedPublicKey(
const filePath = __dirname + "/fixtures/xpub.json";

test("load", (t) => {
const xpub = XPubStore.load(filePath);
const xpub = XPubStore.fromJson(fs.readFileSync(filePath).toString());
const a = xpub.toAccountExtendedPublicKey();

t.is(a.publicKey, accountExtendedPublicKey.publicKey);
Expand Down
2 changes: 2 additions & 0 deletions website/docs/migrations/migrate-to-v0.23.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Lumos dropped the support of reading configuration from `process.env.LUMOS_CONFI

### `@ckb-lumos/hd`.`Keystore`.`load` and ``save` Are Dropped

### `@ckb-lumos/hd`.`XPubStore`.`load` and ``save` Are Dropped

### `#ckb-lumos/hd-cache`.`CacheManager`.`loadFromKeystore` Is Dropped

Please migrate to `loadFromKeystoreJson`
Expand Down

1 comment on commit 656cbca

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 New canary release: 0.0.0-canary-656cbca-20240521070211

npm install @ckb-lumos/[email protected]

Please sign in to comment.