@@ -8,8 +8,6 @@ import TransportWebUSB from "@ledgerhq/hw-transport-webusb";
88
99import { LedgerSigner } from "../ledgersigner" ;
1010
11- declare const window : any ;
12-
1311const getElement = ( id : string ) : HTMLInputElement => {
1412 const e = document . getElementById ( id ) ;
1513 assert ( e instanceof HTMLInputElement , "got the wrong element!" ) ;
@@ -50,7 +48,7 @@ function createSignDoc(accountNumber: number, address: string): string {
5048 return JSON . stringify ( signDoc , null , 2 ) ;
5149}
5250
53- window . updateMessage = ( accountNumberInput : unknown ) : void => {
51+ const updateMessage = ( accountNumberInput : unknown ) : void => {
5452 assert ( typeof accountNumberInput === "string" ) ;
5553 const accountNumber = Uint53 . fromString ( accountNumberInput ) . toNumber ( ) ;
5654 const account = accounts [ accountNumber ] ;
@@ -73,10 +71,9 @@ const setPath = (accountNumberInput: unknown): void => {
7371 const pathInput = getElement ( "path" ) ;
7472 pathInput . value = path ;
7573} ;
76- window . setPath = setPath ;
7774
7875// This must be called by the user an cannot be done on load (see "TransportWebUSBGestureRequired").
79- window . createSigner = async function createSigner ( ) : Promise < LedgerSigner > {
76+ const createSigner = async function createSigner ( ) : Promise < LedgerSigner > {
8077 const interactiveTimeout = 120_000 ;
8178 const ledgerTransport = await TransportWebUSB . create ( interactiveTimeout , interactiveTimeout ) ;
8279 return new LedgerSigner ( ledgerTransport , {
@@ -85,7 +82,7 @@ window.createSigner = async function createSigner(): Promise<LedgerSigner> {
8582 } ) ;
8683} ;
8784
88- window . getAccounts = async function getAccounts ( signer : LedgerSigner | undefined ) : Promise < void > {
85+ const getAccounts = async function getAccounts ( signer : LedgerSigner | undefined ) : Promise < void > {
8986 if ( signer === undefined ) {
9087 console . error ( "Please wait for transport to connect" ) ;
9188 return ;
@@ -123,7 +120,7 @@ window.getAccounts = async function getAccounts(signer: LedgerSigner | undefined
123120 }
124121} ;
125122
126- window . showAddress = async function showAddress ( signer : LedgerSigner | undefined ) : Promise < void > {
123+ const showAddress = async function showAddress ( signer : LedgerSigner | undefined ) : Promise < void > {
127124 if ( signer === undefined ) {
128125 console . error ( "Please wait for transport to connect" ) ;
129126 return ;
@@ -132,7 +129,7 @@ window.showAddress = async function showAddress(signer: LedgerSigner | undefined
132129 await signer . showAddress ( path ) ;
133130} ;
134131
135- window . sign = async function sign ( signer : LedgerSigner | undefined ) : Promise < void > {
132+ const sign = async function sign ( signer : LedgerSigner | undefined ) : Promise < void > {
136133 if ( signer === undefined ) {
137134 console . error ( "Please wait for transport to connect" ) ;
138135 return ;
@@ -150,3 +147,5 @@ window.sign = async function sign(signer: LedgerSigner | undefined): Promise<voi
150147 signatureDiv . textContent = String ( error ) ;
151148 }
152149} ;
150+
151+ Object . assign ( window , { updateMessage, setPath, createSigner, getAccounts, showAddress, sign } ) ;
0 commit comments