bitpay / bitcore-message Goto Github PK
View Code? Open in Web Editor NEWBitcoin Message Verification and Signing for Bitcore
Bitcoin Message Verification and Signing for Bitcore
undefined
> Message('hello, world').verify("bc1pydpj45r52e5njm4j7apj3sycjnaugl5znprkph9y676lv9ad0zsq4785ga", "ILtDggv+4LT25kBsbqeZ72X1AdvZ4d43pEOlrTVXEU8tdZUoRCvIkyEN9hI0GX1NjsbvzHCS7kMHF9z9QL3jDhI=");
Uncaught Error: Non-base58 character
at Object.decode (/Users/a/Downloads/hardhat/node_modules/bitcore-lib/node_modules/bs58/lib/bs58.js:51:37)
at Base58.decode (/Users/a/Downloads/hardhat/node_modules/bitcore-lib/lib/encoding/base58.js:48:26)
at Base58Check.decode (/Users/a/Downloads/hardhat/node_modules/bitcore-lib/lib/encoding/base58check.js:45:31)
at Address._transformString (/Users/a/Downloads/hardhat/node_modules/bitcore-lib/lib/address.js:279:35)
at Address.fromString (/Users/a/Downloads/hardhat/node_modules/bitcore-lib/lib/address.js:379:22)
at Message.verify (/Users/a/Downloads/hardhat/node_modules/bitcore-message/lib/message.js:90:30)
>
>
For example, sign
could check if privateKey is a String or Buffer and convert accordingly. I can add these, but I'll wait for #2 to be merged to avoid any conflicts.
The sign method is giving me "bitcore.ErrorInvalidArgument: Invalid Argument: First argument should be an instance of PrivateKey" although I created the private key with bitcore. I believe the problem is that the bitcore-message module uses a different bitcore module internally then the one I created the private key with.
I've been trying to verify the following testnet message/signature with bitcore-message, but keep getting this stack trace.
message: localhost:3000
address: mx5u3nqdPpzvEZ3vfnuUQEyHg3gHd8zrrH
signature: G4Bi9/Z7hF17MpE9t7Txm3n0aBH6yCVLFB1VWzkZRz17FxErgA/oOWmwXWYr6/ILlRCmeYjc8MeI8PQWYAElZY8=
Invalid Argument: Error: i must be 0, 1, 2, or 3
Error
at Error.NodeError (/src/node_modules/bitcore/lib/errors/index.js:20:41)
at Object.module.exports.checkArgument (/src/node_modules/bitcore/lib/util/preconditions.js:14:13)
at Function.Signature.fromCompact (/src/node_modules/bitcore/lib/crypto/signature.js:41:5)
at Message.verify (/src/node_modules/bitcore-message/lib/message.js:92:29)
at authenticate (/src/server/helpers/authenticate.js:38:32)
at Layer.handle [as handle_request] (/src/node_modules/express/lib/router/layer.js:82:5)
These 2 things dont want to work together:
var bitcore = require('bitcore-lib');
var Message = require('bitcore-message');
Is this module explicitly for signing/verification, or could we add encryption and decryption of messages?
If you use this with bitcore-lib-cash you will get issues when trying to sign.
In particular
throw new errors.InvalidArgument(argumentName, message, docsPath);
^
Invalid Argument: First argument should be an instance of PrivateKey
This is because bitcore-message requires bitcore-lib not bitcore-lib-cash as a dependency. Thus they reference a different instance of PrivateKey
Simple fix is to change the bitcore-lib dependency to bitcore-lib-cash to proceed.
Just a pain if you run npm update/install, you will have to change this back each time.
Solving all "include guard" headaches: bitpay/bitcore-lib#21
image is trying to fetch from: http://bitcore.io/css/images/module-message.png but gets 404
Bitcoin issue 10542 discusses how to expand the current sign/verify functionality to include Segwit.
The basic idea is to expand the header byte to help identify the segwit address scheme
35-38 p2sh segwit pubkey (base58)
39-42 segwit pubkey (bech32)
The Trezor FW has already implemented this in commit b5f9a5
As bitcoin core is likely to implement this and Trezor already has, it would be useful to have it implemented in a block explorer too.
This code throws an error:
var privateKey = new bitcore.PrivateKey('5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss');
var message = new Message('This is an example of a signed message.');
var signature = message.sign(privateKey);
var verified = message.verify(privateKey.toAddress(), signature);
The problem: https://github.com/bitpay/bitcore/blob/master/lib/crypto/signature.js#L35
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.