diff --git a/packages/keepkey-desktop-app/.env b/packages/keepkey-desktop-app/.env index 9ffc11a45..097d0300f 100644 --- a/packages/keepkey-desktop-app/.env +++ b/packages/keepkey-desktop-app/.env @@ -46,4 +46,4 @@ REACT_APP_ETHEREUM_INFURA_URL2=https://mainnet.infura.io/v3/527a7b1368e9464fbdc9 REACT_APP_ETHEREUM_INFURA_URL3=https://avalanche-mainnet.infura.io/v3/fb05c87983c4431baafd4600fd33de7e REACT_APP_MIDGARD_URL=https://indexer.thorchain.shapeshift.com/v2 REACT_APP_WALLET_CONNECT_PROJECT_ID=14d36ca1bc76a70273d44d384e8475ae -REACT_APP_SHAPESHIFT_DAPP_URL=https://private.shapeshift.com +REACT_APP_SHAPESHIFT_DAPP_URL=https://keepkey.info diff --git a/packages/keepkey-desktop-app/src/App.tsx b/packages/keepkey-desktop-app/src/App.tsx index 6bee3c3df..2ba61e7cb 100644 --- a/packages/keepkey-desktop-app/src/App.tsx +++ b/packages/keepkey-desktop-app/src/App.tsx @@ -72,12 +72,12 @@ export const App = () => { let defaultDapp = localStorage.getItem('@app/defaultDapp') if (!defaultDapp || defaultDapp === '' || defaultDapp.indexOf('shapeshift') > -1) { const defaultDappShapeShift = { - imageUrl: 'https://assets.coincap.io/assets/icons/fox@2x.png', - url: 'https://private.shapeshift.com/', - name: 'ShapeShift', + imageUrl: 'https://pioneers.dev/coins/keepkey.png', + url: 'https://app.keepkey.info', + name: 'KeepKey', } - //set SS as default dapp + //set as default dapp localStorage.setItem('@app/defaultDapp', JSON.stringify(defaultDappShapeShift)) openDapp(defaultDappShapeShift.url) } else { diff --git a/packages/keepkey-desktop-app/src/config.ts b/packages/keepkey-desktop-app/src/config.ts index deaa18c9f..d94bedc8a 100644 --- a/packages/keepkey-desktop-app/src/config.ts +++ b/packages/keepkey-desktop-app/src/config.ts @@ -53,7 +53,7 @@ const validators = { REACT_APP_KEEPKEY_UPDATER_BASE_URL: url(), REACT_APP_ETHERSCAN_API_KEY: str(), REACT_APP_WALLET_CONNECT_PROJECT_ID: str(), - REACT_APP_SHAPESHIFT_DAPP_URL: str({ default: 'https://private.shapeshift.com' }), + REACT_APP_SHAPESHIFT_DAPP_URL: str({ default: 'https://keepkey.info' }), } function reporter({ errors }: envalid.ReporterOptions) { diff --git a/packages/keepkey-desktop-app/src/pages/Browser/Browser.tsx b/packages/keepkey-desktop-app/src/pages/Browser/Browser.tsx index 743181006..1d6cbed5d 100644 --- a/packages/keepkey-desktop-app/src/pages/Browser/Browser.tsx +++ b/packages/keepkey-desktop-app/src/pages/Browser/Browser.tsx @@ -118,7 +118,7 @@ const checkIfSSDApp = (currentUrl: string) => { } export const Browser = () => { - const [url, setUrl] = useState('https://private.shapeshift.com/') + const [url, setUrl] = useState('https://keepkey.info/') const [urlWc, setUrlWc] = useState('https://wallet-connect-dapp-ochre.vercel.app') const [inputUrl, setInputUrl] = useState(url) const [loading, setLoading] = useState(false) diff --git a/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/components/DappRegistryGrid.tsx b/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/components/DappRegistryGrid.tsx index 193dda08d..d6e9f66c4 100644 --- a/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/components/DappRegistryGrid.tsx +++ b/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/components/DappRegistryGrid.tsx @@ -108,6 +108,7 @@ export const DappRegistryGrid: FC = () => { (app: RegistryItem) => { console.log(TAG,'openDapp app: ', app) history.push('/browser') + dispatch({ type: WalletActions.SET_BROWSER_URL, payload: app.homepage }) setTimeout(() => { dispatch({ type: WalletActions.SET_BROWSER_URL, payload: app.homepage }) }, 2000) diff --git a/packages/keepkey-desktop/src/tcpBridge.ts b/packages/keepkey-desktop/src/tcpBridge.ts index 0a3ec8c0b..75573164a 100644 --- a/packages/keepkey-desktop/src/tcpBridge.ts +++ b/packages/keepkey-desktop/src/tcpBridge.ts @@ -31,6 +31,7 @@ import { logger } from './helpers/middlewares/logger' import { rendererIpc } from './ipcListeners' import { createAndUpdateTray } from './tray' +// Function to start TCP bridge export const startTcpBridge = async (port?: number) => { if (tcpBridgeRunning || tcpBridgeStarting) return setTcpBridgeStarting(true) @@ -50,29 +51,62 @@ export const startTcpBridge = async (port?: number) => { appExpress.use('/spec', express.static(path.join(__dirname, 'api'))) addMiddleware(logger) - setSdkPairingHandler(async (info: PairingInfo) => { - const apiKey = uuid.v4() - console.log('approving pairing request', info, apiKey) - // await promptUser(){} + + // Set up pairing handler + setSdkPairingHandler(async (info: PairingInfo, req: express.Request) => { + const apiKey = uuid.v4(); // Generate a new API key + console.log('req: ',req) + // Ensure the request object is available + if (!req || !req.headers) { + console.error('Request object or headers are missing'); + throw new Error('Request object or headers are missing'); + } + + // Get the request origin or referer to check where the request is coming from + const origin = req.headers.origin || req.headers.referer; + + // Check if the origin or referer is "https://keepkey.info" + if (origin === 'https://app.keepkey.info') { + console.log('Auto-approving pairing request from keepkey.info', info, apiKey); + + // Automatically approve the pairing and save to the database + info.addedOn = Date.now(); + await db.insertOne<{ type: 'sdk-pairing'; apiKey: string; info: PairingInfo }>({ + type: 'sdk-pairing', + apiKey, + info, + }); + + // Return the generated API key without user prompt + return apiKey; + } + + // If the request is not from "https://keepkey.info", proceed with the normal pairing flow + console.log('Prompting user for pairing approval', info, apiKey); let input = { type: 'native', data: info, - } satisfies PairingProps - let result = await (await rendererIpc).modalPair(input) - console.log('PAIR RESULT: ', result) + } satisfies PairingProps; + + // Show the modal to prompt the user + let result = await (await rendererIpc).modalPair(input); + console.log('PAIR RESULT: ', result); + if (result) { - console.log('USER APPROVED!') - info.addedOn = Date.now() + console.log('USER APPROVED!'); + info.addedOn = Date.now(); await db.insertOne<{ type: 'sdk-pairing'; apiKey: string; info: PairingInfo }>({ type: 'sdk-pairing', apiKey, info, - }) - return apiKey + }); + return apiKey; } else { - return 'rejected' + return 'rejected'; } - }) + }); + + // Set up client factory setSdkClientFactory(async (apiKey: string) => { const doc = await db.findOne<{ type: 'sdk-pairing'; apiKey: string; info: PairingInfo }>({ type: 'sdk-pairing', @@ -90,6 +124,8 @@ export const startTcpBridge = async (port?: number) => { logger: console.log.bind(console), } }) + + // Register routes RegisterRoutes(appExpress) await new Promise(resolve => setServer(appExpress.listen(API_PORT, () => resolve(true)))) @@ -100,6 +136,7 @@ export const startTcpBridge = async (port?: number) => { createAndUpdateTray() } +// Function to stop TCP bridge export const stopTcpBridge = async () => { if (tcpBridgeClosing) return false diff --git a/packages/keepkey-sdk-server/src/auth/sdkClient.ts b/packages/keepkey-sdk-server/src/auth/sdkClient.ts index 53a18f411..24d904f4b 100644 --- a/packages/keepkey-sdk-server/src/auth/sdkClient.ts +++ b/packages/keepkey-sdk-server/src/auth/sdkClient.ts @@ -31,10 +31,11 @@ export const [getSdkClientFactory, setSdkClientFactory] = (() => { return [promise, resolver!] })() -export type SdkPairingHandler = (info: PairingInfo) => Promise +export type SdkPairingHandler = (info: PairingInfo, req: any) => Promise; + export const [getSdkPairingHandler, setSdkPairingHandler] = (() => { - let resolver: (_: SdkPairingHandler) => void - const promise = new Promise(resolve => (resolver = resolve)) - return [promise, resolver!] -})() + let resolver: (_: SdkPairingHandler) => void; + const promise = new Promise(resolve => (resolver = resolve)); + return [promise, resolver!]; +})(); diff --git a/packages/keepkey-sdk-server/src/controllers/auth.ts b/packages/keepkey-sdk-server/src/controllers/auth.ts index defaf92f7..1f5a362d3 100644 --- a/packages/keepkey-sdk-server/src/controllers/auth.ts +++ b/packages/keepkey-sdk-server/src/controllers/auth.ts @@ -46,18 +46,22 @@ export class AuthController extends Controller { @OperationId('Pair') @Response(403, 'Pairing request rejected') public async pair( - @Body() - body: PairingInfo, + @Body() body: PairingInfo, + @Request() req: any, // Use @Request() instead of @Req() ): Promise<{ apiKey: string }> { - console.log('pair body', body) - const apiKey = await (await getSdkPairingHandler)(body) + console.log('pair body', body); + console.log('pair req', req); + + // Pass both body (PairingInfo) and req to the pairing handler + const apiKey = await (await getSdkPairingHandler)(body, req); + if (!apiKey) { - this.setStatus(403) - throw {} + this.setStatus(403); + throw new Error('Pairing request rejected'); } return { apiKey, - } + }; } }