@polkadot/util-crypto#hdValidatePath TypeScript Examples
The following examples show how to use
@polkadot/util-crypto#hdValidatePath.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Create.tsx From crust-apps with Apache License 2.0 | 6 votes |
function deriveValidate (seed: string, seedType: SeedType, derivePath: string, pairType: PairType): DeriveValidationOutput {
try {
const { password, path } = keyExtractSuri(pairType === 'ethereum' ? `${seed}/${derivePath}` : `${seed}${derivePath}`);
let result: DeriveValidationOutput = {};
// show a warning in case the password contains an unintended / character
if (password?.includes('/')) {
result = { warning: 'WARNING_SLASH_PASSWORD' };
}
// we don't allow soft for ed25519
if (pairType === 'ed25519' && path.some(({ isSoft }): boolean => isSoft)) {
return { ...result, error: 'SOFT_NOT_ALLOWED' };
}
// we don't allow password for hex seed
if (seedType === 'raw' && password) {
return { ...result, error: 'PASSWORD_IGNORED' };
}
if (pairType === 'ethereum' && !hdValidatePath(derivePath)) {
return { ...result, error: 'INVALID_DERIVATION_PATH' };
}
return result;
} catch (error) {
return { error: (error as Error).message };
}
}