You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.7 KiB
95 lines
2.7 KiB
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Bitcore browser examples</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
</head>
|
|
<body>
|
|
<pre>
|
|
<div id='content'></div>
|
|
</pre>
|
|
<script src="../browser/bundle.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
var Address = require('bitcore').Address;
|
|
|
|
print = function(s,s2,s3){
|
|
var div = document.getElementById('content');
|
|
div.innerHTML += s + (s2||'') + (s3||'') + '<br />';
|
|
};
|
|
|
|
print('<hr> <h1>Address</h1>' );
|
|
var addrStrings = [
|
|
"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
|
|
"1A1zP1eP5QGefi2DMPTfTL5SLmv7Dixxxx",
|
|
"A1zP1eP5QGefi2DMPTfTL5SLmv7Dixxxx",
|
|
"1600 Pennsylvania Ave NW",
|
|
].map(function(addr) {
|
|
return new Address(addr);
|
|
});
|
|
|
|
addrStrings.forEach(function(addr) {
|
|
|
|
try {
|
|
addr.validate();
|
|
print(addr.data + ": is a valid address");
|
|
} catch(e) {
|
|
print(addr.data + ": is not a valid address.");
|
|
}
|
|
|
|
});
|
|
print('<hr> <h1>Key</h1>' );
|
|
/*
|
|
Using bitcore root module
|
|
*/
|
|
var bitcore = require('bitcore');
|
|
var k = bitcore.Key.generateSync();
|
|
print ('Generate Key Pair:');
|
|
print ('Private:' + bitcore.buffertools.toHex(k.private));
|
|
print ('Public:' + bitcore.buffertools.toHex(k.public));
|
|
|
|
print('<hr> <h1>Util</h1>' );
|
|
var coinUtil = bitcore.util;
|
|
|
|
var pk = '03d95e184cce34c3cfa58e9a277a09a7c5ed1b2a8134ea1e52887bc66fa3f47071'
|
|
|
|
var pubKeyHash = coinUtil.sha256(pk);
|
|
print(bitcore.buffertools.toHex(pubKeyHash));
|
|
pubKeyHash = coinUtil.sha256ripe160(pk);
|
|
print(bitcore.buffertools.toHex(pubKeyHash));
|
|
|
|
|
|
var Buffer = bitcore.Buffer;
|
|
|
|
pubKeyHash = coinUtil.ripe160(new bitcore.Buffer('hola'));
|
|
print(bitcore.buffertools.toHex(pubKeyHash));
|
|
|
|
var bu = new Buffer('a5c756101065ac5b8f689139e6d856fa99e54b5000b6428b43729d334cc9277d', 'hex');
|
|
print(bitcore.buffertools.toHex(bu));
|
|
|
|
var pubKeyHash2 = coinUtil.ripe160(bu);
|
|
print(bitcore.buffertools.toHex(pubKeyHash2));
|
|
|
|
|
|
print('<hr><h1>WalletKey </h1>');
|
|
var WalletKey = bitcore.WalletKey;
|
|
var networks = bitcore.networks;
|
|
|
|
|
|
var priv = 'L4cEVwoNDeYdCQfFJAGkGKPnE2TmqLEuBn4znQChD2ojjQRJVKpU';
|
|
var s = new WalletKey({
|
|
network: networks.livenet
|
|
});
|
|
s.fromObj({ priv: priv});
|
|
var o = s.storeObj();
|
|
print("Private: " + o.priv);
|
|
print("Public: " + o.pub);
|
|
print("Addr: " + o.addr);
|
|
|
|
print('<hr><h1>TransactionBuilder</h1>');
|
|
console.log = print;
|
|
</script>
|
|
<script src="./CreateAndSignTx.js"></script>
|
|
</body>
|
|
</html>
|
|
|