bitcore-lib icon indicating copy to clipboard operation
bitcore-lib copied to clipboard

How to get message signing working in a browser? (bower install, require, not defined)

Open stefek99 opened this issue 7 years ago • 4 comments

I would like to create a standalone demo like this: http://plnkr.co/edit/Rqc7Yv45SUq0DuKCMQAA?p=preview

First I want to get it running on my machine so:

bower install bitcore-lib
bower install bitcore-message

Super simple html file:

<script src="bower_components/bitcore-lib/bitcore-lib.js"></script>
<script src="bower_components/bitcore-message/bitcore-message.js"></script>

<script>
var address = 'n1ZCYg9YXtB5XCZazLxSmPDa8iwJRZHhGx';
var signature = 'H/DIn8uA1scAuKLlCx+/9LnAcJtwQQ0PmcPrJUq90aboLv3fH5fFvY+vmbfOSFEtGarznYli6ShPr9RXwY9UrIY=';
var verified = Message('hello, world').verify(address, signature);
alert(verified);
</script>

Code above taken from the docs: https://github.com/bitpay/bitcore-message

Unfortunately it gives me an error: Uncaught ReferenceError: Message is not defined

Ideally, I would like to use CDN https://cdnjs.com/ or https://wzrd.in/ to host the standalone proof of concept... I was never good at solving build dependencies so fully appreciating your help!

These are good examples but using node, I would like it to run in a browser: https://github.com/bitpay/bitcore-lib/blob/master/docs/examples.md#sign-a-bitcoin-message

stefek99 avatar Apr 27 '17 07:04 stefek99

<!doctype html>
<html>
  <head>
    <script src="https://wzrd.in/debug-standalone/bitcore-message@latest"></script>
    <script>
    var address = 'n1ZCYg9YXtB5XCZazLxSmPDa8iwJRZHhGx';
    var signature = 'H/DIn8uA1scAuKLlCx+/9LnAcJtwQQ0PmcPrJUq90aboLv3fH5fFvY+vmbfOSFEtGarznYli6ShPr9RXwY9UrIY=';
    var verified = bitcoreMessage('hello, world').verify(address, signature);
    console.log('result:', verified);
    </script>
  </head>
  <body>
  </body>
</html>

https://wzrd.in/standalone/bitcore-message@latest is not working =\

fanatid avatar Apr 27 '17 07:04 fanatid

Thank you for speedy reply!

Massive network request

image

True:

https://wzrd.in/standalone/bitcore-message@latest is not working =\

Can you please advise me how to get it running locally?

In that way I'll be more productive (no 4MB request) and I'll better understand the process...

stefek99 avatar Apr 27 '17 07:04 stefek99

You should build bitcore-message with browserify with --standalone flag.

fanatid avatar Apr 27 '17 07:04 fanatid

image

I also need to read more about WIF: https://en.bitcoin.it/wiki/Wallet_import_format

stefek99 avatar Apr 27 '17 07:04 stefek99