MyWallet
![Coverage Status](https://camo.githubusercontent.com/43fe7b75dfe6a55276b9309f9378135b942e9d3fd117164c75eb0cbe7694bd08/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f626c6f636b636861696e2f4d792d57616c6c65742d56332f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)
JavaScript Model for Blockchain.info wallet.
Build
npm install
grunt build
Tests
npm test
Dev
Watch files and re-build
grunt
Clean
Clean generated files:
grunt clean
Getting Started
Load dist/my-wallet.js
.
Optional: set alias for modules you use
var MyWallet = Blockchain.MyWallet;
var WalletStore = Blockchain.WalletStore;
var Spender = Blockchain.Spender;
var API = Blockchain.API;
Disable logout, if desired, for development work:
MyWallet.disableLogout(true);
// Set an interval, since logout gets reactived by certain parts of the code
window.setInterval(function() { MyWallet.disableLogout(true); }, 60000);
My Wallet communicates about its state with user-defined event listeners. Setup a listener like so:
function myListenerFun(eventName, data) {
// Handle events
}
// Register listener function with MyWallet
MyWallet.addEventListener(myListenerFun);
Some events that we need to process:
Event Name | Our Action |
---|---|
did_multiaddr |
Populate wallet statistics on the UI |
hd_wallets_does_not_exist |
Create an HD wallet |
on_wallet_decrypt_finish |
Get wallet transaction history |
To build an HD wallet with an existing legacy wallet, we must initialize after receiving event notification from MyWallet.
var passphrase = MyWallet.generateHDWalletPassphrase();
MyWallet.initializeHDWallet(passphrase, null, null, _successFun, _errorFun);
Load a wallet from the server, with no 2FA
var guid = "my-wallet-guid-1234-bcde";
var pass = "wallet-password";
var twoFactorCode = null;
MyWallet.fetchWalletJSON(guid, null, null, pass, twoFactorCode,
successFun, need2FAfun, wrong2FAfun, otherErrorFun);
// Do stuff with the wallet
var LegacyAddresses = MyWallet.getLegacyActiveAddresses();
In order to fetch the wallet history, make a call to get_history
:
MyWallet.get_history(_successFun, _errorFun);
get_history
will trigger the did_multiaddr
event on completion, so the wallet stats and display can be updated.
Distribution
Run GITHUB_USER=... GITHUB_PASSWORD=... grunt dist
to check all dependencies against dependency-whitelist.json
and generate `my-wallet.min.js``.
If package.json contains a version like "1.2.", the latest version is 1.2.3, but the latest whitelisted version is 1.2.2 then it will use 1.2.2 and show a warning. This also applies to dependencies! Even if you specificy a package version like 1.2., if that package depends on an another package and specifies a specific version that's not whitelist, the script will abort.
Adding a browserified dependency
npm install newpackage --save
- Add the require where needed
npm install
Whitelist dependencies
- Add the tagged version and the commit hash to dependency-whitelist.json.
- Run
grunt dist
Security
Security issues can be reported to us in the following venues:
- Email: security@blockchain.info
- Bug Bounty: https://www.crowdcurity.com/blockchain-info