paypro: example - add privkey option. refactor.
This commit is contained in:
parent
e93e3d83f4
commit
253d66994c
|
@ -50,7 +50,8 @@ Customer: Payment sent successfully.
|
||||||
If you want to alter the address or public key the testnet coins get sent to by
|
If you want to alter the address or public key the testnet coins get sent to by
|
||||||
the payment server, you can pass in the `--pubkey` or `--address` options.
|
the payment server, you can pass in the `--pubkey` or `--address` options.
|
||||||
`address` has to be a testnet address, whereas `pubkey` is a hex encoded public
|
`address` has to be a testnet address, whereas `pubkey` is a hex encoded public
|
||||||
key.
|
key. The `--privkey` option is also available in the standard bitcoind privkey
|
||||||
|
format.
|
||||||
|
|
||||||
## Other Options
|
## Other Options
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var qs = require('querystring');
|
var qs = require('querystring');
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
// Disable strictSSL
|
// Disable strictSSL
|
||||||
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
|
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
|
||||||
|
@ -71,7 +72,7 @@ app.use(function(req, res, next) {
|
||||||
};
|
};
|
||||||
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET,POST');
|
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
|
||||||
res.setHeader('Access-Control-Allow-Headers', [
|
res.setHeader('Access-Control-Allow-Headers', [
|
||||||
'Host',
|
'Host',
|
||||||
'Connection',
|
'Connection',
|
||||||
|
@ -138,19 +139,34 @@ app.get('/-/request', function(req, res, next) {
|
||||||
[2000, 1000, 10000].forEach(function(value) {
|
[2000, 1000, 10000].forEach(function(value) {
|
||||||
var po = new PayPro();
|
var po = new PayPro();
|
||||||
po = po.makeOutput();
|
po = po.makeOutput();
|
||||||
|
|
||||||
// number of satoshis to be paid
|
// number of satoshis to be paid
|
||||||
po.set('amount', value);
|
po.set('amount', value);
|
||||||
|
|
||||||
// a TxOut script where the payment should be sent. similar to OP_CHECKSIG
|
// a TxOut script where the payment should be sent. similar to OP_CHECKSIG
|
||||||
if (argv.pubkey || argv.address) {
|
|
||||||
|
// Instead of creating it ourselves:
|
||||||
|
// if (!argv.pubkey && !argv.privkey && !argv.address) {
|
||||||
|
// argv.pubkey = '3730febcba04bad0cd476cfb820f9c37d7466fd9';
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (argv.pubkey || argv.privkey || argv.address) {
|
||||||
var pubKey;
|
var pubKey;
|
||||||
if (argv.address) {
|
if (argv.pubkey) {
|
||||||
pubKey = bitcore.Base58Check.decode(new Buffer(argv.address));
|
|
||||||
} else {
|
|
||||||
pubKey = new Buffer(argv.pubkey, 'hex');
|
pubKey = new Buffer(argv.pubkey, 'hex');
|
||||||
|
// If it were possible:
|
||||||
|
// pubKey = bitcore.Script.fromCompressedPubKey(new Buffer(argv.pubkey)).toCompressedPubKey();
|
||||||
|
} else if (argv.privkey) {
|
||||||
|
pubKey = bitcore.Key.recoverPubKey(new Buffer(argv.privkey)).toCompressedPubKey();
|
||||||
|
} else if (argv.address) {
|
||||||
|
pubKey = bitcore.Base58Check.decode(new Buffer(argv.address));
|
||||||
|
// pubKey = bitcore.Script.fromUncompressedPubKey(pubKey).toCompressedPubKey();
|
||||||
}
|
}
|
||||||
var pubKeyHash = bitcore.util.sha256ripe160(pubKey);
|
// var pubKeyHash = bitcore.util.sha256ripe160(pubKey);
|
||||||
var address = new bitcore.Address(pubKeyHash, 'testnet');
|
// var address = new bitcore.Address(111, pubKeyHash);
|
||||||
var scriptPubKey = addr.getScriptPubKey();
|
var address = bitcore.Address.fromPubKey(pubKey, 'testnet');
|
||||||
|
var scriptPubKey = address.getScriptPubKey();
|
||||||
|
assert.equal(scriptPubKey.isPubkeyHash(), true);
|
||||||
po.set('script', scriptPubKey.getBuffer());
|
po.set('script', scriptPubKey.getBuffer());
|
||||||
} else {
|
} else {
|
||||||
po.set('script', new Buffer([
|
po.set('script', new Buffer([
|
||||||
|
@ -182,6 +198,7 @@ app.get('/-/request', function(req, res, next) {
|
||||||
172 // OP_CHECKSIG
|
172 // OP_CHECKSIG
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
outputs.push(po.message);
|
outputs.push(po.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue