本文整理匯總了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;
}