From 039e90b769e08a0a493a05a7955e0fa469d45518 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Wed, 23 Jun 2021 17:52:35 +0500 Subject: [PATCH] removed unused methods from hivesigner helper --- src/config/ecencyApi.js | 18 +++++++------- src/providers/hive/auth.js | 23 ++++++++--------- src/utils/hive-signer-helper.ts | 44 --------------------------------- 3 files changed, 19 insertions(+), 66 deletions(-) diff --git a/src/config/ecencyApi.js b/src/config/ecencyApi.js index 0b735883d..91525356a 100644 --- a/src/config/ecencyApi.js +++ b/src/config/ecencyApi.js @@ -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; }); diff --git a/src/providers/hive/auth.js b/src/providers/hive/auth.js index 211d23628..ff3af1bdd 100644 --- a/src/providers/hive/auth.js +++ b/src/providers/hive/auth.js @@ -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')); diff --git a/src/utils/hive-signer-helper.ts b/src/utils/hive-signer-helper.ts index e63ed2ad0..16cbe4270 100644 --- a/src/utils/hive-signer-helper.ts +++ b/src/utils/hive-signer-helper.ts @@ -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): Promise => { 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(); -} \ No newline at end of file