本文整理汇总了TypeScript中@waves/signature-generator.utils.crypto类的典型用法代码示例。如果您正苦于以下问题:TypeScript utils.crypto类的具体用法?TypeScript utils.crypto怎么用?TypeScript utils.crypto使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了utils.crypto类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(phrase: string) {
if (phrase.length < get('minimalSeedLength')) {
throw new Error('Your seed length is less than allowed in config');
}
const keys = utils.crypto.buildKeyPair(phrase);
this.phrase = phrase;
this.address = utils.crypto.buildRawAddress(keys.publicKey);
this.keyPair = {
privateKey: libs.base58.encode(keys.privateKey),
publicKey: libs.base58.encode(keys.publicKey)
};
Object.freeze(this);
Object.freeze(this.keyPair);
}
示例2: encryptSeedPhrase
public static encryptSeedPhrase(seedPhrase: string, password: string, encryptionRounds: number = 5000): string {
if (password && password.length < 8) {
// logger.warn('Your password may be too weak');
}
if (encryptionRounds < 1000) {
// logger.warn('Encryption rounds may be too few');
}
if (seedPhrase.length < get('minimalSeedLength')) {
throw new Error('The seed phrase you are trying to encrypt is too short');
}
return utils.crypto.encryptSeed(seedPhrase, password, encryptionRounds);
}
示例3: _generateNewSeed
private static _generateNewSeed(length: number): string {
const random = utils.crypto.generateRandomUint32Array(length);
const wordCount = dictionary.length;
const phrase = [];
for (let i = 0; i < length; i++) {
const wordIndex = random[i] % wordCount;
phrase.push(dictionary[wordIndex]);
}
random.set(new Uint8Array(random.length));
return phrase.join(' ');
}
示例4: decryptSeedPhrase
public static decryptSeedPhrase(encryptedSeedPhrase: string, password: string, encryptionRounds: number = 5000): string {
const wrongPasswordMessage = 'The password is wrong';
let phrase;
try {
phrase = utils.crypto.decryptSeed(encryptedSeedPhrase, password, encryptionRounds);
} catch (e) {
throw new Error(wrongPasswordMessage);
}
if (phrase === '' || phrase.length < get('minimalSeedLength')) {
throw new Error(wrongPasswordMessage);
}
return phrase;
}