bitpay / bitcore-lib

A pure and powerful JavaScript Bitcoin library
https://bitcore.io/
Other
613 stars 1.03k forks source link

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

Open stefek99 opened 7 years ago

stefek99 commented 7 years ago

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

fanatid commented 7 years ago
<!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 =\

stefek99 commented 7 years ago

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...

fanatid commented 7 years ago

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

stefek99 commented 7 years ago

image

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