removed unused methods from hivesigner helper

This commit is contained in:
Nouman Tahir 2021-06-23 17:52:35 +05:00
parent 2e57286cfb
commit 039e90b769
3 changed files with 19 additions and 66 deletions

View File

@ -1,8 +1,8 @@
import axios from 'axios';
import Config from 'react-native-config';
import VersionNumber from 'react-native-version-number';
import {store} from '../redux/store/store';
import {get} from 'lodash';
import { get } from 'lodash';
import { store } from '../redux/store/store';
const api = axios.create({
baseURL: Config.ECENCY_BACKEND_API,
@ -17,16 +17,16 @@ api.interceptors.request.use((request) => {
const state = store.getState();
const accessToken = get(state, 'account.currentAccount.accessToken');
if(accessToken){
if(!request.data){
request.data = {}
if (accessToken) {
if (!request.data) {
request.data = {};
}
request.data.code = accessToken;
console.log('Added access token:', accessToken)
}else{
console.warn("No access token available")
console.log('Added access token:', accessToken);
} else {
console.warn('No access token available');
}
return request;
});

View File

@ -3,6 +3,7 @@ import sha256 from 'crypto-js/sha256';
import Config from 'react-native-config';
import get from 'lodash/get';
import { cryptoUtils } from '@hiveio/dhive';
import { getUser } from './dhive';
import {
setUserData,
@ -22,7 +23,6 @@ import { getSCAccessToken } from '../ecency/ecency';
// Constants
import AUTH_TYPE from '../../constants/authType';
import { cryptoUtils } from '@hiveio/dhive';
import { makeHsCode } from '../../utils/hive-signer-helper';
export const login = async (username, password, isPinCodeOpen) => {
@ -64,19 +64,16 @@ export const login = async (username, password, isPinCodeOpen) => {
}
});
// Prepare hivesigner code
const signer = (message) => {
const hash = cryptoUtils.sha256(message)
return new Promise(
(resolve) => {
const key = privateKeys['activeKey']
const signedKey = key.sign(hash)
const signedStr = signedKey.toString();
resolve(signedStr)
}
);
}
const hash = cryptoUtils.sha256(message);
return new Promise((resolve) => {
const key = privateKeys.activeKey;
const signedKey = key.sign(hash);
const signedStr = signedKey.toString();
resolve(signedStr);
});
};
const code = await makeHsCode(account.name, signer);
const scTokens = await getSCAccessToken(code);
@ -127,7 +124,7 @@ export const login = async (username, password, isPinCodeOpen) => {
return {
...account,
password,
accessToken:get(scTokens, 'access_token', '')
accessToken: get(scTokens, 'access_token', ''),
};
}
return Promise.reject(new Error('auth.invalid_credentials'));

View File

@ -1,14 +1,5 @@
import { b64uEnc } from "./b64";
export const getAuthUrl = (redir: string = `${window.location.origin}/auth`) => {
const app = "ecency.app";
const scope = "vote,comment,delete_comment,comment_options,custom_json,claim_reward_balance,offline";
return `https://hivesigner.com/oauth2/authorize?client_id=${app}&redirect_uri=${encodeURIComponent(
redir
)}&response_type=code&scope=${encodeURIComponent(scope)}`;
};
export interface HiveSignerMessage {
signed_message: {
type: string;
@ -20,18 +11,6 @@ export interface HiveSignerMessage {
}
export const decodeToken = (code: string): HiveSignerMessage | null => {
const buff = Buffer.from(code, "base64");
try {
const s = buff.toString("ascii");
return JSON.parse(s);
} catch (e) {
return null;
}
}
export const makeHsCode = async (account: string, signer: (message: string) => Promise<string>): Promise<string> => {
const timestamp = new Date().getTime() / 1000;
const messageObj: HiveSignerMessage = {signed_message: {type: 'code', app: "ecency.app"}, authors: [account], timestamp};
@ -40,26 +19,3 @@ export const makeHsCode = async (account: string, signer: (message: string) => P
messageObj.signatures = [signature];
return b64uEnc(JSON.stringify(messageObj));
}
export const buildHotSignUrl = (endpoint: string, params: {
[key: string]: string;
}, redirect: string): any => {
const _params = {
...params,
redirect_uri: `https://ecency.com/${redirect}`
}
const queryString = new URLSearchParams(_params).toString();
return `https://hivesigner.com/sign/${endpoint}?${queryString}`;
}
export const hotSign = (endpoint: string, params: {
[key: string]: any;
}, redirect: string) => {
const webUrl = buildHotSignUrl(endpoint, params, redirect);
const win = window.open(webUrl, '_blank');
return win!.focus();
}