Skip to content

Commit

Permalink
chore: improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
0xApotheosis committed Oct 18, 2023
1 parent 670a4f7 commit 941770b
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
/// <reference types="bip32/types/crypto" />

import * as core from "@shapeshiftoss/hdwallet-core";
import * as bip32crypto from "bip32/src/crypto";
import { createSHA512, pbkdf2 } from "hash-wasm";
import { TextEncoder } from "web-encoding";

import * as BIP32 from "../../core/bip32";
import * as BIP39 from "../../core/bip39";
import { safeBufferFrom } from "../../types";
import * as BIP32Engine from "./bip32";
import type { Seed as SeedType } from "../../core/bip32";
import type { Mnemonic as Bip39Mnemonic } from "../../core/bip39";
import { Seed } from "./bip32";
import { Revocable, revocable } from "./revocable";

export * from "../../core/bip39";

export class Mnemonic extends Revocable(class {}) implements BIP39.Mnemonic {
export class Mnemonic extends Revocable(class {}) implements Bip39Mnemonic {
readonly #mnemonic: string;

protected constructor(mnemonic: string) {
super();
this.#mnemonic = mnemonic.normalize("NFKD");
}

static async create(mnemonic: string): Promise<BIP39.Mnemonic> {
static async create(mnemonic: string): Promise<Bip39Mnemonic> {
const obj = new Mnemonic(mnemonic);
return revocable(obj, (x) => obj.addRevoker(x));
}

async toSeed(passphrase?: string): Promise<BIP32.Seed> {
async toSeed(passphrase?: string): Promise<SeedType> {
if (passphrase !== undefined && typeof passphrase !== "string") throw new Error("bad passphrase type");

const mnemonic = this.#mnemonic;
const salt = new TextEncoder().encode(`mnemonic${passphrase ?? ""}`.normalize("NFKD"));

const out = await BIP32Engine.Seed.create(
const out = await Seed.create(
Buffer.from(
await pbkdf2({
password: mnemonic,
Expand Down

0 comments on commit 941770b

Please sign in to comment.