Better error message when normalize is missing.
This commit is contained in:
parent
7bfaf292db
commit
fad902b438
@ -122,3 +122,13 @@ export function setCensorship(censorship: boolean, permanent?: boolean): void {
|
||||
_censorErrors = !!censorship;
|
||||
_permanentCensorErrors = !!permanent;
|
||||
}
|
||||
|
||||
export function checkNormalize(): void {
|
||||
try {
|
||||
if (String.fromCharCode(0xe9).normalize('NFD') !== String.fromCharCode(0x65, 0x0301)) {
|
||||
throw new Error('broken')
|
||||
}
|
||||
} catch (error) {
|
||||
throwError('platform missing String.prototype.normalize', UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize' });
|
||||
}
|
||||
}
|
||||
|
@ -201,6 +201,8 @@ export function mnemonicToSeed(mnemonic: string, password?: string): string {
|
||||
export function mnemonicToEntropy(mnemonic: string, wordlist?: Wordlist): string {
|
||||
if (!wordlist) { wordlist = langEn; }
|
||||
|
||||
errors.checkNormalize();
|
||||
|
||||
var words = wordlist.split(mnemonic);
|
||||
if ((words.length % 3) !== 0) { throw new Error('invalid mnemonic'); }
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
import { HashZero } from '../constants';
|
||||
|
||||
import { checkNormalize } from '../errors';
|
||||
import { arrayify, concat, hexlify } from './bytes';
|
||||
|
||||
///////////////////////////////
|
||||
@ -23,6 +23,7 @@ export enum UnicodeNormalizationForm {
|
||||
export function toUtf8Bytes(str: string, form: UnicodeNormalizationForm = UnicodeNormalizationForm.current): Uint8Array {
|
||||
|
||||
if (form != UnicodeNormalizationForm.current) {
|
||||
checkNormalize();
|
||||
str = str.normalize(form);
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -132,9 +132,7 @@ class LangJa extends Wordlist {
|
||||
}
|
||||
|
||||
split(mnemonic: string): Array<string> {
|
||||
if (!mnemonic.normalize) {
|
||||
errors.throwError('Japanese is unsupported on this platform; missing String.prototype.normalize', errors.UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize' });
|
||||
}
|
||||
errors.checkNormalize();
|
||||
return mnemonic.split(/(?:\u3000| )+/g);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user