Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added whalevault support #64

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"license": "MIT",
"dependencies": {
"@sendgrid/mail": "^6.2.1",
"@smokenetwork/smoke-js": "^0.1.2",
"@smokenetwork/smoke-js": "^0.1.3",
"@steem/crypto-session": "git+https://github.com/steemit/crypto-session.git#83a90b319ce5bc6a70362d52a15a815de7e729bb",
"assert": "^1.3.0",
"autoprefixer-loader": "^3.2.0",
Expand Down
7 changes: 4 additions & 3 deletions src/app/components/modules/LoginForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class LoginForm extends Component {
initialValues: props.initialValues,
validation: values => ({
username: !values.username ? tt('g.required') : validate_account_name(values.username.split('/')[0]),
password: !values.password ? tt('g.required') :
password: window.whalevault && values.password != null && values.password == '' ? null : !values.password ? tt('g.required') :
PublicKey.fromString(values.password) ? tt('loginform_jsx.you_need_a_private_password_or_key') :
null,
})
Expand Down Expand Up @@ -137,7 +137,8 @@ class LoginForm extends Component {
const {username, password, saveLogin} = this.state;
const {submitting, valid, handleSubmit} = this.state.login;
const {usernameOnChange, onCancel, /*qrReader*/} = this;
const disabled = submitting || !valid;
const isWV = (typeof window !== 'undefined') && (window.whalevault != null) && (this.state.username.value != '') && (this.state.password.value == '');
const disabled = submitting || (!valid && !isWV);
const opType = loginBroadcastOperation ? loginBroadcastOperation.get('type') : null;
let postType = "";
if (opType === "vote") {
Expand Down Expand Up @@ -200,7 +201,7 @@ class LoginForm extends Component {
<div className="error">{username.error}&nbsp;</div> : null}

<div>
<input type="password" required ref="pw"
<input type="password" ref="pw"
placeholder={tt('loginform_jsx.password_or_wif')} {...password.props} autoComplete="on"
disabled={submitting}/>
{error && <div className="error">{error}&nbsp;</div>}
Expand Down
2 changes: 1 addition & 1 deletion src/app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@
"password_update_succes": "The password for %(accountName)s was successfully updated",
"password_info": "This password or private key was entered incorrectly. There is probably a handwriting or data-entry error. Hint: A password or private key generated by Smoke will never contain 0 (zero), O (capital o), I (capital i) and l (lower case L) characters.",
"enter_your_username": "Enter your username",
"password_or_wif": "Password or WIF",
"password_or_wif": "Password or WIF (leave blank for WhaleVault)",
"this_operation_requires_your_key_or_master_password": "This operation requires your %(authType)s key or Master password.",
"keep_me_logged_in": "Keep me logged in",
"amazing_community": " Free Smoke Power",
Expand Down
Binary file added src/app/redux/.TransactionSaga.js.swp
Binary file not shown.
14 changes: 13 additions & 1 deletion src/app/redux/TransactionSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,23 @@ function* broadcastOperation({
if (!keys || keys.length === 0) {
payload.keys = []
// user may already be logged in, or just enterend a signing passowrd or wif
const signingKey = yield call(findSigningKey, {opType: type, username, password})
var signingKey = null;
const currentUser = yield select(state => state.user.get('current'));
const isWV = currentUser.get('whalevault');
if (!isWV) signingKey = yield call(findSigningKey, {opType: type, username, password})
if (signingKey)
payload.keys.push(signingKey)
else {
if (!password) {
if (isWV) {
const account = yield select(
state => state.user.getIn(['current', 'username'])
)
const scope = ['vote', 'comment', 'delete_comment', 'custom_json', 'claim_reward_balance'].includes(type) ? 'posting' : 'active';
payload.keys.push(account+":"+payload.operations[0][0]+":"+scope);
yield call(broadcastPayload, {payload});
return;
}
yield put(user.actions.showLogin({
operation: {
type,
Expand Down
37 changes: 35 additions & 2 deletions src/app/redux/UserSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {browserHistory} from 'react-router'
import {serverApiLogin, serverApiLogout, serverApiRecordEvent} from '../utils/ServerApiClient';
import {loadFollows} from './FollowSaga'
import {hash, PrivateKey, Signature} from '@smokenetwork/smoke-js/lib/auth/ecc';
import {api} from '@smokenetwork/smoke-js';
import {api, config} from '@smokenetwork/smoke-js';
import {translate} from '../Translator';
import DMCAUserList from '../utils/DMCAUserList';

Expand Down Expand Up @@ -128,8 +128,9 @@ function* usernamePasswordLogin2({
login_owner_pubkey = clean(login_owner_pubkey);
}
}
const isWV = (typeof window !== 'undefined') && (window.whalevault != null) && (username != '') && (password != null) && ((password == '') || password.endsWith(':'));
// no saved password
if (!username || !password) {
if (!username || (!password && !isWV)) {
const offchain_account = yield select(state => state.offchain.get('account'))
if (offchain_account) serverApiLogout()
return
Expand Down Expand Up @@ -162,6 +163,38 @@ function* usernamePasswordLogin2({

let private_keys
try {

if (isWV) {
const smkjs_config = config;
smkjs_config.set('whalevault', window.whalevault);
const posting_pub_key = account.getIn(['posting', 'key_auths', 0, 0]);
try {
const wvPubkeys = yield smkjs_config.get('whalevault').promiseRequestPubKeys('smk_webapp', `smk:${username}`);
window.console.log(wvPubkeys);
if (wvPubkeys.result[`smk:${username}`].postingPubkey !== posting_pub_key) {
yield put(user.actions.loginError({error: 'WhaleVault key mismatch'}))
return;
}
} catch (e) {
yield put(user.actions.loginError({error: 'WhaleVault key not found'}))
return;
}
password = username + ":";
yield put(user.actions.setUser({
username,
private_keys: null,
login_owner_pubkey: posting_pub_key,
vesting_shares: account.get('vesting_shares'),
received_vesting_shares: account.get('received_vesting_shares'),
delegated_vesting_shares: account.get('delegated_vesting_shares'),
whalevault: true
}));
if (afterLoginRedirectToWelcome) browserHistory.push('/created');
const data = new Buffer(`${username}\t${password}\t${''}\t${posting_pub_key || ''}`).toString('hex')
localStorage.setItem('autopost2', data);
return;
}

const private_key = PrivateKey.fromWif(password)
login_wif_owner_pubkey = private_key.toPublicKey().toString()
private_keys = fromJS({
Expand Down