缓冲模块未装载凉亭

时间:2017-04-11 18:16:39

标签: javascript jquery bower browserify

我需要在浏览器中将字符串转换为缓冲区。目前,为了操纵DOM,我正在使用jquery。我试过bower install buffer --savethis link

在我的javascript代码中输入

const Buffer = require('buffer');
const bitcore = require('bitcore-lib')
const Mnemonic = require('bitcore-mnemonic');

let wordList = generateWords()
let wordBuffer = new Buffer(wordList);
let hash = bitcore.crypto.Hash.sha256(wordBuffer);
let bn = bitcore.crypto.BN.fromBuffer(hash);
let privateKey = new bitcore.PrivateKey(bn)
let publicKey = privateKey.toAddress();
console.log('private key ' + privateKey.toString());
console.log('publicKey ' + publicKey.toString());
console.log(wordBuffer);

这应该根据输入字符串输出一个缓冲区。但是我收到了错误

bitcore-lib.js:1 Uncaught Error: Cannot find module 'buffer'
    at s (bitcore-lib.js:1)
    at s (bitcore-mnemonic.js:1)
    at s (bitcore-mnemonic.js:1)
    at generate-address.js:3
    at generate-address.js:42

我的html代码加载javascript文件如下

  <script src="../bower_components/bitcore-lib/bitcore-lib.js" type="text/javascript"></script>
  <script src="../bower_components/bitcore-mnemonic/bitcore-mnemonic.js" type="text/javascript"></script>
  <script src="../bower_components/buffer/buffer.min.js" type="text/javascript"></script>
  <script src="../assets/jquery.min.js" type="text/javascript"></script>
  <script src="../scripts/generate-address.js" type="text/javascript"></script>

我在凉亭中使用bitcore-libbitcore-mnemonic。我理解,如果人们觉得这是一个重复的问题,但是我已经完成了10多个问题并尝试了所有解决方案,但无法解决这个问题,所以我错过了一些东西。请帮忙。 TIA

1 个答案:

答案 0 :(得分:1)

您不必使用require方法。

试试这个:

let wordBuffer = new buffer.Buffer(wordList,'hex');