2015-01-03 17:04:14 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>JSDoc: Source: wif.js</title>
|
|
|
|
|
|
|
|
<script src="scripts/prettify/prettify.js"> </script>
|
|
|
|
<script src="scripts/prettify/lang-css.js"> </script>
|
|
|
|
<!--[if lt IE 9]>
|
|
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
|
|
<![endif]-->
|
|
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div id="main">
|
|
|
|
|
|
|
|
<h1 class="page-title">Source: wif.js</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<article>
|
|
|
|
<pre class="prettyprint source linenums"><code>/**
|
|
|
|
* Implements WIF encoding/decoding.
|
|
|
|
* @see {@link https://en.bitcoin.it/wiki/Wallet_import_format}
|
|
|
|
* @module bitmessage/wif
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var bufferEqual = require("buffer-equal");
|
|
|
|
var bs58 = require("bs58");
|
2015-01-31 12:54:23 +01:00
|
|
|
var assert = require("./_util").assert;
|
2015-01-03 17:04:14 +01:00
|
|
|
var bmcrypto = require("./crypto");
|
|
|
|
|
|
|
|
// Compute the WIF checksum for the given data.
|
2015-01-31 12:54:23 +01:00
|
|
|
function getwifchecksum(data) {
|
2015-01-03 17:04:14 +01:00
|
|
|
return bmcrypto.sha256(bmcrypto.sha256(data)).slice(0, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode WIF encoded private key.
|
|
|
|
* @param {string} wif - Encoded key
|
|
|
|
* @return {Buffer} Private key.
|
|
|
|
*/
|
|
|
|
exports.decode = function(wif) {
|
|
|
|
var bytes = bs58.decode(wif);
|
|
|
|
assert(bytes[0] === 0x80, "Bad WIF");
|
|
|
|
var data = new Buffer(bytes.slice(0, -4));
|
|
|
|
var checksum = new Buffer(bytes.slice(-4));
|
2015-01-31 12:54:23 +01:00
|
|
|
assert(bufferEqual(checksum, getwifchecksum(data)), "Bad checkum");
|
2015-01-03 17:04:14 +01:00
|
|
|
return data.slice(1);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert private key to a WIF.
|
|
|
|
* @param {Buffer} privateKey - A private key to encode
|
|
|
|
* @return {string} Encoded private key.
|
|
|
|
*/
|
|
|
|
exports.encode = function(privateKey) {
|
|
|
|
var data = Buffer.concat([new Buffer([0x80]), privateKey]);
|
2015-01-31 12:54:23 +01:00
|
|
|
var checksum = getwifchecksum(data);
|
2015-01-03 17:04:14 +01:00
|
|
|
var bytes = Buffer.concat([data, checksum]);
|
|
|
|
return bs58.encode(bytes);
|
|
|
|
};
|
|
|
|
</code></pre>
|
|
|
|
</article>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<nav>
|
2015-01-31 12:54:23 +01:00
|
|
|
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-bitmessage.html">bitmessage</a></li><li><a href="module-bitmessage_address.html">bitmessage/address</a></li><li><a href="module-bitmessage_crypto.html">bitmessage/crypto</a></li><li><a href="module-bitmessage_messages.html">bitmessage/messages</a></li><li><a href="module-bitmessage_objects.html">bitmessage/objects</a></li><li><a href="module-bitmessage_pow.html">bitmessage/pow</a></li><li><a href="module-bitmessage_structs.html">bitmessage/structs</a></li><li><a href="module-bitmessage_user-agent.html">bitmessage/user-agent</a></li><li><a href="module-bitmessage_wif.html">bitmessage/wif</a></li></ul><h3>Classes</h3><ul><li><a href="module-bitmessage_address.Address.html">Address</a></li></ul><h3>Namespaces</h3><ul><li><a href="module-bitmessage_messages.addr.html">addr</a></li><li><a href="module-bitmessage_messages.error.html">error</a></li><li><a href="module-bitmessage_messages.getdata.html">getdata</a></li><li><a href="module-bitmessage_messages.inv.html">inv</a></li><li><a href="module-bitmessage_messages.version.html">version</a></li><li><a href="module-bitmessage_objects.broadcast.html">broadcast</a></li><li><a href="module-bitmessage_objects.getpubkey.html">getpubkey</a></li><li><a href="module-bitmessage_objects.msg.html">msg</a></li><li><a href="module-bitmessage_objects.pubkey.html">pubkey</a></li><li><a href="module-bitmessage_structs.encrypted.html">encrypted</a></li><li><a href="module-bitmessage_structs.inv_vect.html">inv_vect</a></li><li><a href="module-bitmessage_structs.message.html">message</a></li><li><a href="module-bitmessage_structs.net_addr.html">net_addr</a></li><li><a href="module-bitmessage_structs.object.html">object</a></li><li><a href="module-bitmessage_structs.PubkeyBitfield.html">PubkeyBitfield</a></li><li><a href="module-bitmessage_structs.ServicesBitfield.html">ServicesBitfield</a></li><li><a href="module-bitmessage_structs.var_int.html">var_int</a></li><li><a href="module-bitmessage_structs.var_int_list.html">var_int_list</a></li><li><a href="module-bitmessage_structs.var_str.html">var_str</a></li></ul>
|
2015-01-03 17:04:14 +01:00
|
|
|
</nav>
|
|
|
|
|
|
|
|
<br class="clear">
|
|
|
|
|
|
|
|
<footer>
|
2015-01-31 12:54:23 +01:00
|
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-beta1</a> on Sat Jan 31 2015 14:53:21 GMT+0300 (MSK)
|
2015-01-03 17:04:14 +01:00
|
|
|
</footer>
|
|
|
|
|
|
|
|
<script> prettyPrint(); </script>
|
|
|
|
<script src="scripts/linenumber.js"> </script>
|
|
|
|
</body>
|
|
|
|
</html>
|