当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript bip39.validateMnemonic函数代码示例

本文整理汇总了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
  })
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:31,代码来源:wallet.ts

示例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();
 });
开发者ID:Norestlabs-Mariya,项目名称:backend-ico-dashboard,代码行数:11,代码来源:user.controller.spec.ts

示例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
  })
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:43,代码来源:wallet.ts

示例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);
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:14,代码来源:bip39-tests.ts


注:本文中的bip39.validateMnemonic函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。