]> git.codecow.com Git - libnemo.git/commitdiff
Add wallet types so they can be restored properly later.
authorChris Duncan <chris@zoso.dev>
Fri, 25 Jul 2025 13:01:54 +0000 (06:01 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 25 Jul 2025 13:01:54 +0000 (06:01 -0700)
src/lib/wallets/bip44-wallet.ts
src/lib/wallets/blake2b-wallet.ts
src/lib/wallets/ledger-wallet.ts
src/lib/wallets/wallet.ts
src/types.d.ts

index 1b1614e72e46a7ff1b40e6fb1104014a07d147d5..a3dff4f090c7f645ff18ae86bfe8eb9a387bcbad 100644 (file)
@@ -39,7 +39,7 @@ export class Bip44Wallet extends Wallet {
                        throw new Error(`Bip44Wallet cannot be instantiated directly. Use 'await Bip44Wallet.create()' instead.`)\r
                }\r
                Bip44Wallet.#isInternal = false\r
-               super(id, seed, mnemonic)\r
+               super(id, 'BIP-44', seed, mnemonic)\r
        }\r
 \r
        /**\r
index 4132cc0a015f6f6d6950f066afe291885c722a11..9bd6f74f1caca0ae4cd673cf42b15fc3f7fb23ed 100644 (file)
@@ -33,7 +33,7 @@ export class Blake2bWallet extends Wallet {
                        throw new Error(`Blake2bWallet cannot be instantiated directly. Use 'await Blake2bWallet.create()' instead.`)\r
                }\r
                Blake2bWallet.#isInternal = false\r
-               super(id, seed, mnemonic)\r
+               super(id, 'BLAKE2b', seed, mnemonic)\r
        }\r
 \r
        /**\r
index e10356bc6a3a594b6fa4b14dd89bcb4db047b388..87e25e67bb16d2ab87155c2649b6fddebaa6290c 100644 (file)
@@ -40,7 +40,7 @@ export class LedgerWallet extends Wallet {
                        throw new Error(`LedgerWallet cannot be instantiated directly. Use 'await LedgerWallet.create()' instead.`)\r
                }\r
                LedgerWallet.#isInternal = false\r
-               super(id)\r
+               super(id, 'Ledger')\r
        }\r
 \r
        /**\r
index 2a4570824f25a46adaea3cecab5f49fe267f50de..010d51d497a4b5e57ba2f6fbb8d79f5e5cf3fe30 100644 (file)
@@ -8,7 +8,7 @@ import { ADDRESS_GAP } from '#src/lib/constants.js'
 import { bytes, hex, utf8 } from '#src/lib/convert.js'\r
 import { Entropy } from '#src/lib/entropy.js'\r
 import { Rpc } from '#src/lib/rpc.js'\r
-import { Key, KeyPair } from '#types'\r
+import { Key, KeyPair, WalletType } from '#types'\r
 import { SafeWorker } from '#workers'\r
 \r
 /**\r
@@ -44,6 +44,7 @@ export abstract class Wallet {
        #locked: boolean\r
        #m?: Bip39Mnemonic\r
        #s?: Uint8Array<ArrayBuffer>\r
+       #type: WalletType\r
 \r
        get id () { return this.#id.hex }\r
        get isLocked () { return this.#locked }\r
@@ -56,8 +57,9 @@ export abstract class Wallet {
                if (this.#locked || this.#s == null) throw new Error('failed to get seed', { cause: 'wallet locked' })\r
                return bytes.toHex(this.#s)\r
        }\r
+       get type () { return this.#type }\r
 \r
-       constructor (id: Entropy, seed?: Uint8Array<ArrayBuffer>, mnemonic?: Bip39Mnemonic) {\r
+       constructor (id: Entropy, type: WalletType, seed?: Uint8Array<ArrayBuffer>, mnemonic?: Bip39Mnemonic) {\r
                if (this.constructor === Wallet) {\r
                        throw new Error('Wallet is an abstract class and cannot be instantiated directly.')\r
                }\r
@@ -66,6 +68,7 @@ export abstract class Wallet {
                this.#locked = false\r
                this.#m = mnemonic\r
                this.#s = seed\r
+               this.#type = type\r
        }\r
 \r
        /**\r
index 6f0efeb4d2bf7fb4bfa1c6c6da2806a4b74fc7c8..636e1b22d9c0a07d2a142c00304da888e3cb19d3 100644 (file)
@@ -583,6 +583,8 @@ export declare const Tools: {
        verify: typeof verify
 }
 
+export type WalletType = 'BIP-44' | 'BLAKE2b' | 'Ledger'
+
 /**
 * Represents a wallet containing numerous Nano accounts derived from a single
 * source, the form of which can vary based on the type of wallet. The Wallet
@@ -604,6 +606,7 @@ export declare abstract class Wallet {
        get isUnlocked (): boolean
        get mnemonic (): string
        get seed (): string
+       get type (): WalletType
        constructor (id: Entropy, seed?: Uint8Array<ArrayBuffer>, mnemonic?: Bip39Mnemonic)
        /**
        * Retrieves an account from a wallet using its child key derivation function.