-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
664 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/connect-iframe/webpack/sessions.webpack.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import path from 'path'; | ||
import webpack from 'webpack'; | ||
import merge from 'webpack-merge'; | ||
|
||
import { config as baseConfig } from './base.webpack.config'; | ||
import { getSharedworkerDistPathForProject } from './utils'; | ||
|
||
const project = process.env.PROJECT || 'iframe'; | ||
|
||
if (project !== 'iframe' && project !== 'suite-web') { | ||
throw new Error(`Unsupported project: ${project}`); | ||
} | ||
const DIST = getSharedworkerDistPathForProject(project); | ||
|
||
console.log('DIST', DIST); | ||
|
||
const config: webpack.Configuration = { | ||
// common instructions that are able to build correctly imports from @trezor/connect (reusing this in popup) | ||
entry: { | ||
['sessions-background-sharedworker']: { | ||
filename: 'workers/[name].js', | ||
import: path.resolve( | ||
__dirname, | ||
'../../transport/src/sessions/background-sharedworker.ts', | ||
), | ||
}, | ||
}, | ||
output: { | ||
filename: 'js/[name].[contenthash].js', | ||
path: DIST, | ||
publicPath: './', | ||
}, | ||
}; | ||
|
||
export default merge([config, baseConfig]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import path from 'path'; | ||
|
||
type Project = 'iframe' | 'suite-web'; | ||
|
||
export const getDistPathForProject = (project: Project = 'iframe') => { | ||
const basePath = path.join(__dirname, '..', '..'); | ||
switch (project) { | ||
case 'iframe': | ||
return path.join(basePath, 'connect-iframe', 'build'); | ||
case 'suite-web': | ||
return path.join(basePath, 'suite-web', 'build'); | ||
default: | ||
throw new Error('Missing project.'); | ||
} | ||
}; | ||
|
||
export const getSharedworkerDistPathForProject = (project: Project = 'iframe') => { | ||
const basePath = path.join(__dirname, '..', '..'); | ||
switch (project) { | ||
case 'iframe': | ||
return path.join(basePath, 'connect-iframe', 'build'); | ||
case 'suite-web': | ||
// It is hardcoded in suite-web: | ||
// https://github.com/trezor/trezor-suite/blob/feat/use-core-in-suite-web/suite-common/connect-init/src/connectInitThunks.ts#L120 | ||
// return path.join(basePath, 'suite-web', 'build', 'static', 'connect'); | ||
return path.join(basePath, 'suite-web', 'build'); | ||
default: | ||
throw new Error('Missing project.'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { factory } from '@trezor/connect/src/factory'; | ||
import { config } from '@trezor/connect/src/data/config'; | ||
import { TrezorConnectDynamic } from '@trezor/connect/src/impl/dynamic'; | ||
import { CoreInModule } from '@trezor/connect/src/impl/core-in-module'; | ||
// import webUSBB utton from '../webusb/button'; | ||
import type { ConnectSettingsPublic } from '@trezor/connect/src/types'; | ||
import type { ConnectFactoryDependencies } from '@trezor/connect/src/factory'; | ||
import { ERRORS, TRANSPORT } from '@trezor/connect/src/exports'; | ||
|
||
const impl = new TrezorConnectDynamic< | ||
'core-in-module', | ||
ConnectSettingsPublic, | ||
ConnectFactoryDependencies<ConnectSettingsPublic> | ||
>({ | ||
implementations: [ | ||
{ | ||
type: 'core-in-module', | ||
impl: new CoreInModule(), | ||
}, | ||
], | ||
getInitTarget: () => 'core-in-module', | ||
handleErrorFallback: () => new Promise(resolve => resolve(false)), | ||
}); | ||
|
||
const disableWebUSB = () => { | ||
if (!impl.lastSettings) { | ||
throw ERRORS.TypedError('Init_NotInitialized'); | ||
} | ||
|
||
// @ts-ignore | ||
Check failure on line 30 in packages/connect-web/src/module/index.ts GitHub Actions / Linting and formatting
|
||
impl.handleCoreMessage({ type: TRANSPORT.DISABLE_WEBUSB }); | ||
}; | ||
|
||
const requestWebUSBDevice = async () => { | ||
try { | ||
await window.navigator.usb.requestDevice({ filters: config.webusb }); | ||
// @ts-ignore | ||
Check failure on line 37 in packages/connect-web/src/module/index.ts GitHub Actions / Linting and formatting
|
||
impl.handleCoreMessage({ type: TRANSPORT.REQUEST_DEVICE }); | ||
} catch (_err) { | ||
console.log('_err', _err); | ||
} | ||
}; | ||
|
||
// const renderWebUSBButton = (className?: string) => { | ||
// if (!impl.lastSettings) { | ||
// throw ERRORS.TypedError('Init_NotInitialized'); | ||
// } | ||
// webUSBButton(className, impl.lastSettings.webusbSrc); | ||
// }; | ||
|
||
const TrezorConnect = factory( | ||
{ | ||
eventEmitter: impl.eventEmitter, | ||
init: impl.init.bind(impl), | ||
call: impl.call.bind(impl), | ||
manifest: impl.manifest.bind(impl), | ||
requestLogin: impl.requestLogin.bind(impl), | ||
uiResponse: impl.uiResponse.bind(impl), | ||
cancel: impl.cancel.bind(impl), | ||
dispose: impl.dispose.bind(impl), | ||
}, | ||
{ | ||
// renderWebUSBButton: renderWebUSBButton.bind(impl), | ||
disableWebUSB: disableWebUSB.bind(impl), | ||
requestWebUSBDevice: requestWebUSBDevice.bind(impl), | ||
}, | ||
); | ||
|
||
export default TrezorConnect; | ||
export * from '@trezor/connect/src/exports'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.