本文整理汇总了TypeScript中bip39.validateMnemonic函数的典型用法代码示例。如果您正苦于以下问题:TypeScript validateMnemonic函数的具体用法?TypeScript validateMnemonic怎么用?TypeScript validateMnemonic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validateMnemonic函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Error
return Promise.resolve().then(() => {
// must be bip39 mnemonic
if (!bip39.validateMnemonic(phrase)) {
throw new Error('Not a valid bip39 nmemonic')
}
// normalize plaintext to fixed length byte string
const plaintextNormalized = Buffer.from(
bip39.mnemonicToEntropy(phrase), 'hex'
)
// AES-128-CBC with SHA256 HMAC
const salt = crypto.randomBytes(16)
const keysAndIV = crypto.pbkdf2Sync(password, salt, 100000, 48, 'sha512')
const encKey = keysAndIV.slice(0, 16)
const macKey = keysAndIV.slice(16, 32)
const iv = keysAndIV.slice(32, 48)
const cipher = crypto.createCipheriv('aes-128-cbc', encKey, iv)
let cipherText = cipher.update(plaintextNormalized).toString('hex')
cipherText += cipher.final().toString('hex')
const hmacPayload = Buffer.concat([salt, Buffer.from(cipherText, 'hex')])
const hmac = crypto.createHmac('sha256', macKey)
hmac.write(hmacPayload)
const hmacDigest = hmac.digest()
const payload = Buffer.concat([salt, hmacDigest, Buffer.from(cipherText, 'hex')])
return payload
})
示例2: postRequest
postRequest(factory.testAppForSuccessRegistration(), '/user/activate').send(activateParams).end((err, res) => {
expect(res.status).to.eq(200);
expect(res.body.accessToken).to.eq('token');
expect(res.body.wallets[0].ticker).to.eq('ETH');
expect(res.body.wallets[0].balance).to.eq('0');
expect(res.body.wallets[0]).to.have.property('privateKey');
expect(res.body.wallets[0]).to.not.have.property('salt');
expect(bip39.validateMnemonic(res.body.wallets[0].mnemonic)).to.eq(true);
expect(Web3.utils.isAddress(res.body.wallets[0].address)).to.eq(true);
done();
});
示例3: PasswordError
return Promise.resolve().then(() => {
const salt = dataBuffer.slice(0, 16)
const hmacSig = dataBuffer.slice(16, 48) // 32 bytes
const cipherText = dataBuffer.slice(48)
const hmacPayload = Buffer.concat([salt, cipherText])
const keysAndIV = crypto.pbkdf2Sync(password, salt, 100000, 48, 'sha512')
const encKey = keysAndIV.slice(0, 16)
const macKey = keysAndIV.slice(16, 32)
const iv = keysAndIV.slice(32, 48)
const decipher = crypto.createDecipheriv('aes-128-cbc', encKey, iv)
let plaintext = decipher.update(cipherText).toString('hex')
plaintext += decipher.final().toString('hex')
const hmac = crypto.createHmac('sha256', macKey)
hmac.write(hmacPayload)
const hmacDigest = hmac.digest()
// hash both hmacSig and hmacDigest so string comparison time
// is uncorrelated to the ciphertext
const hmacSigHash = crypto.createHash('sha256')
.update(hmacSig)
.digest()
.toString('hex')
const hmacDigestHash = crypto.createHash('sha256')
.update(hmacDigest)
.digest()
.toString('hex')
if (hmacSigHash !== hmacDigestHash) {
// not authentic
throw new PasswordError('Wrong password (HMAC mismatch)')
}
const mnemonic = bip39.entropyToMnemonic(plaintext)
if (!bip39.validateMnemonic(mnemonic)) {
throw new PasswordError('Wrong password (invalid plaintext)')
}
return mnemonic
})
示例4:
import * as bip39 from 'bip39';
// Test generate a random mnemonic
const mnemonic: string = bip39.generateMnemonic();
// Test generate a random mnemonic with strength
bip39.generateMnemonic(64);
// Test mnemonic to seed
const seedHex: string = bip39.mnemonicToSeedHex('basket actual');
const seed: Buffer = bip39.mnemonicToSeed('basket actual');
// Test validation
bip39.validateMnemonic(mnemonic);