Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/650-stealth-wallet'
Browse files Browse the repository at this point in the history
  • Loading branch information
valzav committed Mar 21, 2016
2 parents 1ee2958 + 6e5dc85 commit ec7dccb
Show file tree
Hide file tree
Showing 288 changed files with 17,078 additions and 6,621 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
}
}
}
}
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.idea
node_modules
*/node_modules
*/npm-debug.log
cli/bundle
Expand All @@ -11,5 +12,6 @@ dist
web/app/components/Exchange/exchange.css
cli/bundle.js
web/dist-prod
plasma
plasma/.babelrc

>>>>>>> master
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cd graphene-ui
Before launching the GUI you will need to install the npm packages for each subdirectory:
```
cd dl; npm install
cd ../plasma; npm install
cd ../web; npm install
```

Expand Down
4 changes: 1 addition & 3 deletions cli/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ var repl = require("repl");
var repl_history = require("repl.history");
var promisify = require("repl-promised").promisify;

var Apis = require('../dl/src/rpc_api/ApiInstances');
var Apis = require('@graphene/chain').Apis;
var ApplicationApi = require('../dl/src/rpc_api/ApplicationApi');
var WalletApi = require('../dl/src/rpc_api/WalletApi');
var DebugApi = require('../dl/src/rpc_api/DebugApi');

var iDB = require("../dl/src/idb-instance");
Expand Down Expand Up @@ -39,7 +38,6 @@ init_promise.then(()=> {
repl_instance.context.$g.net = network_api;
repl_instance.context.$g.history = history_api;
repl_instance.context.$g.app = new ApplicationApi();
repl_instance.context.$g.wallet = new WalletApi();
repl_instance.context.$g.debug = new DebugApi();
})
}).catch(error => {
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"fake-indexeddb": "^1.0.3",
"json-loader": "^0.5.1",
"lodash": "^3.10.1",
"lzma": "^2.1.9",
"lzma": "2.1.6",
"repl": "^0.1.3",
"repl-promised": "^0.1.0",
"repl.history": "^0.1.3",
Expand Down
6 changes: 3 additions & 3 deletions dl/programs/bloom_filter_wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var fs = require('fs')

require('coffee-script/register') // npm install coffee-script

var h = require('../src/common/hash')
var key_utils = require('../src/common/key_utils')
var chain_config = require('../src/chain/config')
var h = require('@graphene/ecc').hash
var key_utils = require('@graphene/ecc').key
var chain_config = require('@graphene/chain').chain_config

chain_config.address_prefix = "BTS"

Expand Down
28 changes: 21 additions & 7 deletions dl/src/actions/AccountActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import alt from "../alt-instance";
import utils from "../common/utils";
import AccountApi from "../api/accountApi";

import WalletApi from "../rpc_api/WalletApi";
import ApplicationApi from "../rpc_api/ApplicationApi";
import WalletDb from "../stores/WalletDb";
import WalletActions from "../actions/WalletActions";
import { TransactionBuilder } from "@graphene/chain"

let accountSubs = {};
let accountLookup = {};
let accountSearch = {};
let wallet_api = new WalletApi();
let application_api = new ApplicationApi()
let inProgress = {};

Expand Down Expand Up @@ -45,9 +44,6 @@ class AccountActions {
this.dispatch(name);
}

/**
* TODO: This is a function of teh wallet_api and has no business being part of AccountActions
*/
transfer(from_account, to_account, amount, asset, memo, propose_account, fee_asset_id = "1.3.0") {
try {
return application_api.transfer({
Expand All @@ -65,7 +61,7 @@ class AccountActions {
}

/**
* This method exists ont he AccountActions because after creating the account via the wallet, the account needs
* This method exists on the AccountActions because after creating the account via the wallet, the account needs
* to be linked and added to the local database.
*/
createAccount(
Expand All @@ -92,7 +88,7 @@ class AccountActions {
* be linked.
*/
upgradeAccount(account_id, lifetime) {
var tr = wallet_api.new_transaction();
var tr = new TransactionBuilder();
tr.add_type_operation("account_upgrade", {
"fee": {
amount: 0,
Expand All @@ -111,6 +107,24 @@ class AccountActions {
unlinkAccount(name) {
this.dispatch(name);
}

addPrivateAccount(name) {
const cwallet = WalletDb.getState().cwallet;
cwallet.createBlindAccount(name, WalletDb.getBrainKey() + name);
this.dispatch(name);
}

addPrivateContact(label, public_key) {
const cwallet = WalletDb.getState().cwallet;
cwallet.setKeyLabel(public_key, label);
this.dispatch(label);
}

removePrivateContact(name) {
const cwallet = WalletDb.getState().cwallet;
// TODO: cwallet.deleteKeyLabel(public_key, label);
this.dispatch(name);
}
}

export default alt.createActions(AccountActions);
21 changes: 9 additions & 12 deletions dl/src/actions/AssetActions.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
var alt = require("../alt-instance");
import Apis from "rpc_api/ApiInstances";
import { Apis } from "@graphene/chain";
import utils from "common/utils";
import WalletApi from "../rpc_api/WalletApi";
import WalletDb from "stores/WalletDb";
import ChainStore from "api/ChainStore";
import { ChainStore } from "@graphene/chain";
import big from "bignumber.js";
import assetConstants from "chain/asset_constants";

let wallet_api = new WalletApi();
import { TransactionBuilder } from "@graphene/chain";

let inProgress = {};

class AssetActions {

fundPool(account_id, core, asset, amount) {
let tr = wallet_api.new_transaction();
let tr = new TransactionBuilder();
let precision = utils.get_asset_precision(core.get("precision"));
tr.add_type_operation("asset_fund_fee_pool", {
"fee": {
Expand All @@ -35,7 +32,7 @@ class AssetActions {
}

claimPoolFees(account_id, asset, amount) {
let tr = wallet_api.new_transaction();
let tr = new TransactionBuilder();
let precision = utils.get_asset_precision(asset.get("precision"));

tr.add_type_operation("asset_claim_fees", {
Expand All @@ -60,8 +57,8 @@ class AssetActions {

createAsset(account_id, createObject, flags, permissions, cer, isBitAsset, is_prediction_market, bitasset_opts, description) {
// Create asset action here...
console.log("create asset:", createObject, "flags:", flags, "isBitAsset:", isBitAsset, "bitasset_opts:", bitasset_opts);
let tr = wallet_api.new_transaction();
console.log("create asset:", createObject, "flags:", flags, "permissions:", permissions);
let tr = new TransactionBuilder();
let precision = utils.get_asset_precision(createObject.precision);

big.config({DECIMAL_PLACES: createObject.precision});
Expand Down Expand Up @@ -136,7 +133,7 @@ class AssetActions {
isBitAsset, bitasset_opts, original_bitasset_opts, description) {

// Create asset action here...
let tr = wallet_api.new_transaction();
let tr = new TransactionBuilder();
let quotePrecision = utils.get_asset_precision(asset.get("precision"));

big.config({DECIMAL_PLACES: asset.get("precision")});
Expand Down Expand Up @@ -226,7 +223,7 @@ class AssetActions {
issueAsset(account_id, issueObject) {
console.log("account_id: ", account_id, issueObject);
// Create asset action here...
var tr = wallet_api.new_transaction();
var tr = new TransactionBuilder();
tr.add_type_operation("asset_issue", {
fee: {
amount: 0,
Expand Down
114 changes: 2 additions & 112 deletions dl/src/actions/BackupActions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import alt from "alt-instance"
import iDB from "idb-instance"

import lzma from "lzma"
import {saveAs} from "common/filesaver.js"

import PrivateKey from 'ecc/key_private'
import PublicKey from 'ecc/key_public'
import Aes from 'ecc/aes'
import key from "common/key_utils"

import { Aes, PrivateKey, PublicKey, key } from "@graphene/ecc"
import WalletActions from "actions/WalletActions"
import WalletDb from "stores/WalletDb"

Expand Down Expand Up @@ -36,108 +30,4 @@ class BackupActions {
}

var BackupActionsWrapped = alt.createActions(BackupActions)
export default BackupActionsWrapped

export function backup(backup_pubkey) {
return new Promise( resolve => {
resolve(createWalletObject().then( wallet_object => {
var compression = 1
return createWalletBackup(backup_pubkey, wallet_object, compression)
}))
})
}

/** No click backup.. Works great, but not used (yet?) */
// export function backupToBin(
// backup_pubkey = WalletDb.getWallet().password_pubkey,
// saveAsCallback = saveAs
// ) {
// backup(backup_pubkey).then( contents => {
// var name = iDB.getCurrentWalletName() + ".bin"
// var blob = new Blob([ contents ], {
// type: "application/octet-stream; charset=us-ascii"})
//
// if(blob.size !== contents.length)
// throw new Error("Invalid backup to download conversion")
//
// saveAsCallback(blob, name);
// WalletActions.setBackupDate()
// })
// }

export function restore(backup_wif, backup, wallet_name) {
return new Promise( resolve => {
resolve(decryptWalletBackup(backup_wif, backup).then( wallet_object => {
return WalletActions.restore(wallet_name, wallet_object)
}))
})
}

export function createWalletObject() {
return iDB.backup()
}

/**
compression_mode can be 1-9 (1 is fast and pretty good; 9 is slower and probably much better)
*/
export function createWalletBackup(
backup_pubkey, wallet_object, compression_mode, entropy) {
return new Promise( resolve => {
var public_key = PublicKey.fromPublicKeyString(backup_pubkey)
var onetime_private_key = key.get_random_key(entropy)
var walletString = JSON.stringify(wallet_object, null, 0)
lzma.compress(walletString, compression_mode, compressedWalletBytes => {
var backup_buffer =
Aes.encrypt_with_checksum(onetime_private_key, public_key,
null/*nonce*/, compressedWalletBytes)

var onetime_public_key = onetime_private_key.toPublicKey()
var backup = Buffer.concat([ onetime_public_key.toBuffer(), backup_buffer ])
resolve(backup)
})
})
}

export function decryptWalletBackup(backup_wif, backup_buffer) {
return new Promise( (resolve, reject) => {
if( ! Buffer.isBuffer(backup_buffer))
backup_buffer = new Buffer(backup_buffer, 'binary')

var private_key = PrivateKey.fromWif(backup_wif)
var public_key
try {
public_key = PublicKey.fromBuffer(backup_buffer.slice(0, 33))
} catch(e) {
console.error(e, e.stack)
throw new Error("Invalid backup file")
}

backup_buffer = backup_buffer.slice(33)
try {
backup_buffer = Aes.decrypt_with_checksum(
private_key, public_key, null/*nonce*/, backup_buffer)
} catch(error) {
console.error("Error decrypting wallet", error, error.stack)
reject("invalid_decryption_key")
return
}

try {
lzma.decompress(backup_buffer, wallet_string => {
try {
var wallet_object = JSON.parse(wallet_string)
resolve(wallet_object)
} catch(error) {
if( ! wallet_string) wallet_string = ""
console.error("Error parsing wallet json",
wallet_string.substring(0,10)+ "...")
reject("Error parsing wallet json")
}
})
} catch(error) {
console.error("Error decompressing wallet", error, error.stack)
reject("Error decompressing wallet")
return
}
})
}
export default BackupActionsWrapped
2 changes: 1 addition & 1 deletion dl/src/actions/BlockchainActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var alt = require("../alt-instance");
import Apis from "rpc_api/ApiInstances";
import { Apis } from "@graphene/chain";

let subs = {
globals: false
Expand Down
14 changes: 7 additions & 7 deletions dl/src/actions/MarketsActions.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var alt = require("../alt-instance");
import Apis from "rpc_api/ApiInstances";
import WalletApi from "rpc_api/WalletApi";
import { Apis } from "@graphene/chain";
import WalletDb from "../stores/WalletDb";
import {operations} from "chain/chain_types";
import ChainStore from "api/ChainStore";
import { chain_types } from "@graphene/chain";
import { ChainStore } from "@graphene/chain";
import { TransactionBuilder } from "@graphene/chain";
import marketUtils from "common/market_utils";
import Immutable from "immutable";

let operations = chain_types.operations
let ops = Object.keys(operations);

let subs = {};
let currentBucketSize;
let wallet_api = new WalletApi();
let marketStats = {};
let statTTL = 60 * 2 * 1000; // 2 minutes

Expand Down Expand Up @@ -275,7 +275,7 @@ class MarketsActions {

createLimitOrder(account, sellAmount, sellAsset, buyAmount, buyAsset, expiration, isFillOrKill, fee_asset_id) {

var tr = wallet_api.new_transaction();
var tr = new TransactionBuilder();

let feeAsset = ChainStore.getAsset(fee_asset_id);
if( feeAsset.getIn(["options", "core_exchange_rate", "base", "asset_id"]) === "1.3.0" && feeAsset.getIn(["options", "core_exchange_rate", "quote", "asset_id"]) === "1.3.0" ) {
Expand Down Expand Up @@ -361,7 +361,7 @@ class MarketsActions {
}

cancelLimitOrder(accountID, orderID) {
var tr = wallet_api.new_transaction();
var tr = new TransactionBuilder();
tr.add_type_operation("limit_order_cancel", {
fee: {
amount: 0,
Expand Down
Loading

0 comments on commit ec7dccb

Please sign in to comment.