()
| 32 | } |
| 33 | |
| 34 | async authenticate(): Promise<string> { |
| 35 | let ownerAddress = (await this.layer2Web3.eth.getAccounts())[0]; |
| 36 | let { nonce, version } = await this.getNonce(); |
| 37 | let name = await networkName(this.layer2Web3); |
| 38 | let chainId = networkIds[name]; |
| 39 | const typedData = { |
| 40 | types: { |
| 41 | //eslint-disable-next-line @typescript-eslint/naming-convention |
| 42 | EIP712Domain: [ |
| 43 | { name: 'name', type: 'string' }, |
| 44 | { name: 'version', type: 'string' }, |
| 45 | { name: 'chainId', type: 'uint256' }, |
| 46 | ], |
| 47 | //eslint-disable-next-line @typescript-eslint/naming-convention |
| 48 | HubAuthentication: [ |
| 49 | { name: 'user', type: 'address' }, |
| 50 | { name: 'nonce', type: 'string' }, |
| 51 | ], |
| 52 | }, |
| 53 | domain: { |
| 54 | name: this.hubRootUrl.replace(/https?:\/\//, ''), |
| 55 | version, |
| 56 | chainId, |
| 57 | }, |
| 58 | primaryType: 'HubAuthentication', |
| 59 | message: { |
| 60 | user: ownerAddress, |
| 61 | nonce, |
| 62 | }, |
| 63 | }; |
| 64 | let signature = await signTypedData(this.layer2Web3, ownerAddress, typedData); |
| 65 | let postBody = JSON.stringify({ |
| 66 | data: { |
| 67 | attributes: { |
| 68 | authData: typedData, |
| 69 | signature, |
| 70 | }, |
| 71 | }, |
| 72 | }); |
| 73 | let response = await global.fetch(`${this.hubRootUrl}/api/session`, { |
| 74 | method: 'POST', |
| 75 | headers: { |
| 76 | //eslint-disable-next-line @typescript-eslint/naming-convention |
| 77 | 'Content-Type': 'application/vnd.api+json', |
| 78 | }, |
| 79 | body: postBody, |
| 80 | }); |
| 81 | if (response.ok) { |
| 82 | let responseJson = await response.json(); |
| 83 | return responseJson.data.attributes.authToken; |
| 84 | } else { |
| 85 | let responseJson = await response.json(); |
| 86 | console.error('Failed.', responseJson); |
| 87 | // TODO: throw error? |
| 88 | return ''; |
| 89 | } |
| 90 | } |
| 91 | } |
nothing calls this directly
no test coverage detected