diff --git a/src/app/wallet/account.service.ts b/src/app/wallet/account.service.ts index 3871f7a5b3bcf6ae99398c62b9a11869a495670e..19fa4f1b78e934b34f8be835c093cdbe29b9f3a3 100644 --- a/src/app/wallet/account.service.ts +++ b/src/app/wallet/account.service.ts @@ -48,6 +48,36 @@ export interface LoadAccountDataOptions { emitEvent?: boolean; } +export const SCRYPT_PARAMS = { + SIMPLE: <Params>{ + N: 2048, + r: 8, + p: 1 + }, + DEFAULT: <Params>{ + N: 4096, + r: 16, + p: 1 + }, + SECURE: <Params>{ + N: 16384, + r: 32, + p: 2 + }, + HARDEST: <Params>{ + N: 65536, + r: 32, + p: 4 + }, + EXTREME: <Params>{ + N: 262144, + r: 64, + p: 8 + } +}; + +const ED25519_SEED_LENGTH = 32; + @Injectable({providedIn: 'root'}) export class AccountService extends StartableService { @@ -545,18 +575,14 @@ export class AccountService extends StartableService { this._$accounts.next(this._$accounts.value.slice() /*create a copy*/); } - async addV1Account(data: {salt: string, password: string; meta?: AccountMeta}): Promise<Account> { + async addV1Account(data: {salt: string, password: string; meta?: AccountMeta, scryptParams?: Params}): Promise<Account> { if (!data?.salt || !data?.password) return; console.info(this._logPrefix + ' Authenticating using salt+pwd...'); const passwordU8a = Uint8Array.from(data.password.split('').map(x => x.charCodeAt(0))); const saltU8a = Uint8Array.from(data.salt.split('').map(x => x.charCodeAt(0))); - const result = scryptEncode(passwordU8a, saltU8a, <Params>{ - N: 4096, - r: 16, - p: 1 - }); - const seedHex = u8aToHex(result.password.slice(0,32)); + const result = scryptEncode(passwordU8a, saltU8a, data.scryptParams || SCRYPT_PARAMS.DEFAULT); + const seedHex = u8aToHex(result.password.slice(0,ED25519_SEED_LENGTH)); //console.debug('Computed seed (hex) from salt+pwd:', rawSeedString);