Skip to content
Snippets Groups Projects
Commit beb26280 authored by bl05b3e's avatar bl05b3e
Browse files

[enh] Account: add SCRYPT_PARAMS const

parent d4837a66
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,36 @@ export interface LoadAccountDataOptions { ...@@ -48,6 +48,36 @@ export interface LoadAccountDataOptions {
emitEvent?: boolean; 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'}) @Injectable({providedIn: 'root'})
export class AccountService extends StartableService { export class AccountService extends StartableService {
...@@ -545,18 +575,14 @@ export class AccountService extends StartableService { ...@@ -545,18 +575,14 @@ export class AccountService extends StartableService {
this._$accounts.next(this._$accounts.value.slice() /*create a copy*/); 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; if (!data?.salt || !data?.password) return;
console.info(this._logPrefix + ' Authenticating using salt+pwd...'); console.info(this._logPrefix + ' Authenticating using salt+pwd...');
const passwordU8a = Uint8Array.from(data.password.split('').map(x => x.charCodeAt(0))); 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 saltU8a = Uint8Array.from(data.salt.split('').map(x => x.charCodeAt(0)));
const result = scryptEncode(passwordU8a, saltU8a, <Params>{ const result = scryptEncode(passwordU8a, saltU8a, data.scryptParams || SCRYPT_PARAMS.DEFAULT);
N: 4096, const seedHex = u8aToHex(result.password.slice(0,ED25519_SEED_LENGTH));
r: 16,
p: 1
});
const seedHex = u8aToHex(result.password.slice(0,32));
//console.debug('Computed seed (hex) from salt+pwd:', rawSeedString); //console.debug('Computed seed (hex) from salt+pwd:', rawSeedString);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment