diff --git a/examples/blockreader.js b/examples/blockreader.js deleted file mode 100644 index b4cf61e..0000000 --- a/examples/blockreader.js +++ /dev/null @@ -1,25 +0,0 @@ -var Block = require('../lib/block'); -var BufferReader = require('../lib/bufferreader'); -var BufferWriter = require('../lib/bufferwriter'); - -//This example will parse the blocks in a block file. -//To use, pipe in a blk*****.dat file. e.g.: -//cat blk00000.dat | node blockreader.js - -var head = null; - -process.stdin.on('readable', function() { - if (!head) { - head = process.stdin.read(8); - if (!head) - return; - } - var body = process.stdin.read(head.slice(4).readUInt32LE(0)); - if (!body) - return; - var blockbuf = BufferWriter().write(head).write(body).concat(); - var block = Block().fromBuffer(blockbuf); - console.log(block.toJSON()); - head = null; - process.stdin.unshift(process.stdin.read()); -}); diff --git a/examples/ecdsa.js b/examples/ecdsa.js deleted file mode 100644 index c0bc155..0000000 --- a/examples/ecdsa.js +++ /dev/null @@ -1,21 +0,0 @@ -var ECDSA = require('../lib/ecdsa'); -var Keypair = require('../lib/keypair'); -var Hash = require('../lib/hash'); - -//ECDSA is the signature algorithm used in bitcoin - -//start with a keypair that you will use for signing -var keypair = Keypair().fromRandom(); - -//a message to be signed (normally you would have the hash of a transaction) -var messagebuf = new Buffer('This is a message I would like to sign'); - -//calculate a 32 byte hash for use in ECDSA. one way to do that is sha256. -var hashbuf = Hash.sha256(messagebuf); - -var sig = ECDSA.sign(hashbuf, keypair); - -//Anyone with the public key can verify -var pubkey = keypair.pubkey; -console.log('Valid signature? ' + ECDSA.verify(hashbuf, sig, pubkey)); - diff --git a/examples/stealthmessage.js b/examples/stealthmessage.js deleted file mode 100644 index 809af13..0000000 --- a/examples/stealthmessage.js +++ /dev/null @@ -1,63 +0,0 @@ -var Pubkey = require('../lib/pubkey'); -var Address = require('../lib/address'); -var Stealthkey = require('../lib/expmt/stealthkey'); -var StealthAddress = require('../lib/expmt/stealthaddress'); -var StealthMessage = require('../lib/expmt/stealthmessage'); -var Keypair = require('../lib/keypair') - -//First, the person receiving must make a stealth key. - -var sk = Stealthkey().fromRandom(); - -//It has an associated stealth address. - -var sa = StealthAddress().fromStealthkey(sk); - -console.log('Stealth address: ' + sa); - -//Now make a message. - -var messagebuf = new Buffer('Hello there. Only you know this message is to you, and only you know what it says.'); - -//Encrypt the message with the stealth address. - -var encbuf = StealthMessage.encrypt(messagebuf, sa); - -console.log('Hex of the encrypted message: ' + encbuf.toString('hex')); - -//Note that the first 20 bytes are a pubkeyhash, which may be interpreted as a bitcoin address. -//This address has never been seen before in public. - -var address = Address().set({hashbuf: encbuf.slice(0, 20)}); - -console.log('The randomly generated address the message is to: ' + address); - -//And the next 33 bytes are a nonce public key, which the message is "from". -//It has never been seen before in public. - -var pubkey = Pubkey().fromDER(encbuf.slice(20, 20 + 33)); - -console.log('Nonce public key: ' + pubkey); - -//The owner of the stealth key can check to see if it is for them. - -console.log('Is the message for me? ' + (StealthMessage.isForMe(encbuf, sk) ? "yes" : "no")); - -//The owner can decrypt it. - -var messagebuf2 = StealthMessage.decrypt(encbuf, sk); - -console.log('Decrypted message: ' + messagebuf2.toString()); - -//If you do not have the payload privkey, you can still use isForMe. -sk.payloadKeypair.privkey = undefined; - -console.log('Without payload privkey, is the message for me? ' + (StealthMessage.isForMe(encbuf, sk) ? "yes" : "no")); - -//...but not decrypt - -try { - StealthMessage.decrypt(encbuf, sk); -} catch (e) { - console.log("...but without the payload privkey, I can't decrypt."); -}