Skip to content

Commit 634b42f

Browse files
committed
feat: rebase and enable encrypted wallet filewith authScheme
1 parent d6489ca commit 634b42f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/lib/miden/back/vault.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ export class Vault {
175175
await midenClient.webClient.addAccountSecretKeyToWebStore(sk);
176176
} else {
177177
const walletSeed = deriveClientSeed(walletAccount.type, mnemonic, walletAccount.hdIndex);
178-
const secretKey = SecretKey.rpoFalconWithRNG(walletSeed);
178+
const secretKey =
179+
walletAccount.authScheme === AuthScheme.Falcon
180+
? SecretKey.rpoFalconWithRNG(walletSeed)
181+
: SecretKey.ecdsaWithRNG(walletSeed);
179182
await midenClient.webClient.addAccountSecretKeyToWebStore(secretKey);
180183
}
181184
}
@@ -380,7 +383,11 @@ export class Vault {
380383
async importAccount(privateKey: string, name?: string): Promise<WalletAccount[]> {
381384
return withError('Failed to import account', async () => {
382385
const allAccounts = await fetchAndDecryptOneWithLegacyFallBack<WalletAccount[]>(accountsStrgKey, this.passKey);
383-
const secretKey = SecretKey.deserialize(new Uint8Array(Buffer.from(privateKey, 'hex')));
386+
const buff = Buffer.from(privateKey, 'hex');
387+
if (buff[0] !== 0 && buff[0] !== 1) {
388+
throw new PublicError('Invalid private key format');
389+
}
390+
const secretKey = SecretKey.deserialize(new Uint8Array(buff));
384391
const pubKeyWord = secretKey.publicKey().toCommitment();
385392

386393
const pubKeyHex = pubKeyWord.toHex().slice(2); // remove '0x' prefix
@@ -393,6 +400,7 @@ export class Vault {
393400
name: name || `Imported Account ${allAccounts.length + 1}`,
394401
isPublic: true,
395402
type: WalletType.OnChain,
403+
authScheme: buff[0] === 0 ? AuthScheme.Falcon : AuthScheme.ECDSA,
396404
hdIndex: -1 // -1 indicates imported account
397405
};
398406

src/lib/shared/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ export interface WalletAccount {
153153
isPublic: boolean;
154154
type: WalletType;
155155
hdIndex: number;
156-
// Optional here for backwards compatibility
157-
authScheme?: AuthScheme;
156+
authScheme: AuthScheme;
158157
}
159158

160159
export interface WalletNetwork {

0 commit comments

Comments
 (0)