Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private seedValidate ({ suri, type }: RequestSeedValidate): ResponseSeedValidate {
const { phrase } = keyExtractSuri(suri);
if (isHex(phrase)) {
assert(isHex(phrase, 256), 'Hex seed needs to be 256-bits');
} else {
// sadly isHex detects as string, so we need a cast here
assert(SEED_LENGTHS.includes((phrase as string).split(' ').length), `Mnemonic needs to contain ${SEED_LENGTHS.join(', ')} words`);
assert(mnemonicValidate(phrase), 'Not a valid mnemonic seed');
}
return {
address: keyring.createFromUri(suri, {}, type).address,
suri
};
}
function addressFromSeed (phrase: string, derivePath: string, pairType: KeypairType): string {
return keyring
.createFromUri(`${phrase.trim()}${derivePath}`, {}, pairType)
.address;
}
function addressFromSeed (phrase: string, derivePath: string, pairType: KeypairType): string {
return keyring
.createFromUri(`${phrase.trim()}${derivePath}`, {}, pairType)
.address;
}
const _onClickNew = (): void => {
const phrase = mnemonicGenerate(12);
const { address } = keyring.createFromUri(phrase);
setAddress(keyring.encodeAddress(address, ss58Format));
setPhrase(phrase);
};
const _onChangeSS58Format = ({ currentTarget: { value } }: React.SyntheticEvent): void => {
const _onClickNew = (): void => {
const phrase = mnemonicGenerate(12);
const { address } = keyring.createFromUri(phrase);
setAddress(keyring.encodeAddress(address, ss58Format));
setPhrase(phrase);
};
useEffect((): void => {
try {
const { phrase } = keyExtractSuri(suri);
assert(mnemonicValidate(phrase), 'Invalid mnemonic phrase');
setPublicKey(u8aToHex(keyring.createFromUri(suri, {}, crypto).publicKey));
} catch (error) {
setPublicKey(EMPTY_KEY);
}
}, [crypto, suri]);
private seedCreate ({ length = SEED_DEFAULT_LENGTH, type }: RequestSeedCreate): ResponseSeedCreate {
const seed = mnemonicGenerate(length);
return {
address: keyring.createFromUri(seed, {}, type).address,
seed
};
}