Skip to content

Commit 9b4c2a9

Browse files
committed
Make hdkey module use a named export
1 parent 42f5135 commit 9b4c2a9

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

packages/ethereum-cryptography/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,10 @@ console.log(sign(msgHash, privateKey).toString("hex"));
354354
The `hdkey` submodule provides a library for keys derivation according to
355355
[BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki).
356356

357-
It has the exact same API than the version `1.x` of
357+
It has almost the exact same API than the version `1.x` of
358358
[`hdkey` from cryptocoinjs](https://github.com/cryptocoinjs/hdkey),
359359
but it's backed by this package's primitives, and has built-in TypeScript types.
360+
Its only difference is that it has to be be used with a named import.
360361

361362
### Function types
362363

@@ -400,14 +401,15 @@ interface Versions {
400401
### Example usage
401402
402403
```js
403-
const HDKey = require("ethereum-cryptography/hdkey");
404+
const { HDKey } = require("ethereum-cryptography/hdkey");
404405

405406
const seed = "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542";
406407
const hdkey = HDKey.fromMasterSeed(Buffer.from(seed, "hex"));
407408
const childkey = hdkey.derive("m/0/2147483647'/1");
408409

409410
console.log(childkey.privateExtendedKey);
410411
```
412+
411413
## Browser usage
412414
413415
This package works with all the major Javascript bundlers. It is
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import * as hdkeyPure from "./pure/hdkey";
22

3-
let hdkeyModule: typeof hdkeyPure;
3+
let hdkey: typeof hdkeyPure.HDKey;
44

55
try {
66
// tslint:disable-next-line no-implicit-dependencies
7-
hdkeyModule = require("ethereum-cryptography-native/hdkey");
7+
hdkey = require("ethereum-cryptography-native/hdkey").HDKey;
88
} catch {
99
// This module is slightly more complicated, as we don't want to use the
1010
// 100% pure version of hdkey if the native one isn't installed.
1111

1212
// We require this local version of hdkey-without-crypto because it uses
1313
// the built-in crypto module
14-
hdkeyModule = require("./vendor/hdkey-without-crypto");
14+
hdkey = require("./vendor/hdkey-without-crypto");
1515
}
1616

17-
export = hdkeyModule;
17+
export const HDKey = hdkey;
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
interface Versions {
1+
export interface Versions {
22
private: number;
33
public: number;
44
}
55

6-
declare class HDKey {
6+
export declare class HDKeyT {
77
public static HARDENED_OFFSET: number;
8-
public static fromMasterSeed(seed: Buffer, versions: Versions): HDKey;
9-
public static fromExtendedKey(base58key: string, versions: Versions): HDKey;
10-
public static fromJSON(json: { xpriv: string }): HDKey;
8+
public static fromMasterSeed(seed: Buffer, versions: Versions): HDKeyT;
9+
public static fromExtendedKey(base58key: string, versions: Versions): HDKeyT;
10+
public static fromJSON(json: { xpriv: string }): HDKeyT;
1111

1212
public versions: Versions;
1313
public depth: number;
@@ -23,14 +23,14 @@ declare class HDKey {
2323
public publicExtendedKey: string;
2424

2525
private constructor(versios: Versions);
26-
public derive(path: string): HDKey;
27-
public deriveChild(index: number): HDKey;
26+
public derive(path: string): HDKeyT;
27+
public deriveChild(index: number): HDKeyT;
2828
public sign(hash: Buffer): Buffer;
2929
public verify(hash: Buffer, signature: Buffer): boolean;
3030
public wipePrivateData(): this;
3131
public toJSON(): { xpriv: string; xpub: string };
3232
}
3333

34-
const hdkey: typeof HDKey = require("./vendor/hdkey-without-crypto");
34+
const hdkey: typeof HDKeyT = require("./vendor/hdkey-without-crypto");
3535

36-
export = hdkey;
36+
export const HDKey = hdkey;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import hdkey from "../../src/hdkey";
1+
import { HDKey } from "../../src/hdkey";
22
import { createTests } from "../test-vectors/hdkey";
33

4-
createTests(hdkey);
4+
createTests(HDKey);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import hdkey from "../../src/pure/hdkey";
1+
import { HDKey } from "../../src/pure/hdkey";
22
import { createTests } from "../test-vectors/hdkey";
33

4-
createTests(hdkey);
4+
createTests(HDKey);

0 commit comments

Comments
 (0)