\r
abstract ckd (index: number[]): Promise<KeyPair[]>\r
\r
- constructor (seed?: string, mnemonic?: Bip39Mnemonic, id?: string) {\r
+ constructor (id: Entropy, seed?: string, mnemonic?: Bip39Mnemonic) {\r
if (this.constructor === Wallet) {\r
throw new Error('Wallet is an abstract class and cannot be instantiated directly.')\r
}\r
this.#accounts = []\r
this.#id = id\r
- ? new Entropy(id)\r
- : new Entropy(16)\r
this.#mnemonic = mnemonic ?? null\r
this.#safe = new Safe()\r
this.#seed = seed ?? null\r
export class Bip44Wallet extends Wallet {\r
static #isInternal: boolean = false\r
\r
- constructor (seed: string, mnemonic?: Bip39Mnemonic, id?: string) {\r
+ constructor (id: Entropy, seed: string, mnemonic?: Bip39Mnemonic) {\r
if (!Bip44Wallet.#isInternal) {\r
throw new Error(`Bip44Wallet cannot be instantiated directly. Use 'await Bip44Wallet.create()' instead.`)\r
}\r
Bip44Wallet.#isInternal = false\r
- super(seed, mnemonic, id)\r
+ super(id, seed, mnemonic)\r
}\r
\r
/**\r
static async create (key: CryptoKey, salt?: string): Promise<Bip44Wallet>\r
static async create (passkey: string | CryptoKey, salt: string = ''): Promise<Bip44Wallet> {\r
try {\r
- const e = new Entropy()\r
+ const e = await Entropy.create()\r
return await Bip44Wallet.fromEntropy(passkey as string, e.hex, salt)\r
} catch (err) {\r
throw new Error(`Error creating new Bip44Wallet: ${err}`)\r
static async fromEntropy (key: CryptoKey, entropy: string, salt?: string): Promise<Bip44Wallet>\r
static async fromEntropy (passkey: string | CryptoKey, entropy: string, salt: string = ''): Promise<Bip44Wallet> {\r
try {\r
- const e = new Entropy(entropy)\r
+ const id = await Entropy.create(16)\r
+ const e = await Entropy.import(entropy)\r
const m = await Bip39Mnemonic.fromEntropy(e.hex)\r
const s = await m.toBip39Seed(salt)\r
Bip44Wallet.#isInternal = true\r
- const wallet = new this(s, m)\r
+ const wallet = new this(id, s, m)\r
await wallet.lock(passkey as string)\r
return wallet\r
} catch (err) {\r
static async fromMnemonic (key: CryptoKey, mnemonic: string, salt?: string): Promise<Bip44Wallet>\r
static async fromMnemonic (passkey: string | CryptoKey, mnemonic: string, salt: string = ''): Promise<Bip44Wallet> {\r
try {\r
+ const id = await Entropy.create(16)\r
const m = await Bip39Mnemonic.fromPhrase(mnemonic)\r
const s = await m.toBip39Seed(salt)\r
Bip44Wallet.#isInternal = true\r
- const wallet = new this(s, m)\r
+ const wallet = new this(id, s, m)\r
await wallet.lock(passkey as string)\r
return wallet\r
} catch (err) {\r
if (!/^[0-9a-fA-F]+$/i.test(seed)) {\r
throw new Error('Seed contains invalid hexadecimal characters.')\r
}\r
+ const id = await Entropy.create(16)\r
Bip44Wallet.#isInternal = true\r
- const wallet = new this(seed)\r
+ const wallet = new this(id, seed)\r
await wallet.lock(passkey as string)\r
return wallet\r
}\r
throw new TypeError('Wallet ID is required to restore')\r
}\r
Bip44Wallet.#isInternal = true\r
- return new this('', undefined, id)\r
+ return new this(await Entropy.import(id), '')\r
}\r
\r
/**\r
export class Blake2bWallet extends Wallet {\r
static #isInternal: boolean = false\r
\r
- constructor (seed: string, mnemonic?: Bip39Mnemonic, id?: string) {\r
+ constructor (id: Entropy, seed: string, mnemonic?: Bip39Mnemonic) {\r
if (!Blake2bWallet.#isInternal) {\r
throw new Error(`Blake2bWallet cannot be instantiated directly. Use 'await Blake2bWallet.create()' instead.`)\r
}\r
Blake2bWallet.#isInternal = false\r
- super(seed, mnemonic, id)\r
+ super(id, seed, mnemonic)\r
}\r
\r
/**\r
static async create (key: CryptoKey): Promise<Blake2bWallet>\r
static async create (passkey: string | CryptoKey): Promise<Blake2bWallet> {\r
try {\r
- const seed = new Entropy()\r
+ const seed = await Entropy.create()\r
return await Blake2bWallet.fromSeed(passkey as string, seed.hex)\r
} catch (err) {\r
throw new Error(`Error creating new Blake2bWallet: ${err}`)\r
if (!/^[0-9a-fA-F]+$/i.test(seed)) {\r
throw new Error('Seed contains invalid hexadecimal characters.')\r
}\r
+ const id = await Entropy.create(16)\r
const s = seed\r
const m = await Bip39Mnemonic.fromEntropy(seed)\r
Blake2bWallet.#isInternal = true\r
- const wallet = new this(s, m)\r
+ const wallet = new this(id, s, m)\r
await wallet.lock(passkey as string)\r
return wallet\r
}\r
static async fromMnemonic (key: CryptoKey, mnemonic: string): Promise<Blake2bWallet>\r
static async fromMnemonic (passkey: string | CryptoKey, mnemonic: string): Promise<Blake2bWallet> {\r
try {\r
+ const id = await Entropy.create(16)\r
const m = await Bip39Mnemonic.fromPhrase(mnemonic)\r
const s = await m.toBlake2bSeed()\r
Blake2bWallet.#isInternal = true\r
- const wallet = new this(s, m)\r
+ const wallet = new this(id, s, m)\r
await wallet.lock(passkey as string)\r
return wallet\r
} catch (err) {\r
throw new TypeError('Wallet ID is required to restore')\r
}\r
Blake2bWallet.#isInternal = true\r
- return new this('', undefined, id)\r
+ return new this(await Entropy.import(id), '')\r
}\r
\r
/**\r
\r
get ledger () { return this.#ledger }\r
\r
- constructor (ledger: Ledger, id?: string) {\r
+ constructor (id: Entropy, ledger: Ledger) {\r
if (!LedgerWallet.#isInternal) {\r
throw new Error(`LedgerWallet cannot be instantiated directly. Use 'await LedgerWallet.create()' instead.`)\r
}\r
LedgerWallet.#isInternal = false\r
- super(undefined, undefined, id)\r
+ super(id)\r
this.#ledger = ledger\r
}\r
\r
static async create (): Promise<LedgerWallet> {\r
const { Ledger } = await import('./ledger.js')\r
const l = await Ledger.init()\r
+ const id = await Entropy.create(16)\r
LedgerWallet.#isInternal = true\r
- return new this(l)\r
+ return new this(id, l)\r
}\r
\r
/**\r
const { Ledger } = await import('./ledger.js')\r
const l = await Ledger.init()\r
LedgerWallet.#isInternal = true\r
- return new this(l, id)\r
+ return new this(await Entropy.import(id), l)\r
}\r
\r
/**\r