|
| 1 | +import {SimpleHandler} from './main'; |
| 2 | +import {RequestType} from './types'; |
| 3 | +import {SendToOffscreen} from '../../../offscreen/client'; |
| 4 | +import {HasPermissions} from './has_permissions'; |
| 5 | +import {NotaryProveRequest} from '../../notary/types'; |
| 6 | +import {getAccessToken} from '../../alarms/access_token'; |
| 7 | +import {PresentationJSON} from 'tlsn-js/build/types'; |
| 8 | +import { |
| 9 | + OffscreenRequestType, |
| 10 | + TLSNProveOffscreenRequest, |
| 11 | + TLSNProveOffscreenResponse, |
| 12 | +} from '../../../offscreen/handlers/types'; |
| 13 | +import {MaxConcurrency} from '../wrappers/cached'; |
| 14 | + |
| 15 | +export interface NotaryProveResponse { |
| 16 | + presentation: PresentationJSON; |
| 17 | +} |
| 18 | + |
| 19 | +export const NotaryProve = MaxConcurrency( |
| 20 | + new SimpleHandler<NotaryProveRequest, NotaryProveResponse>( |
| 21 | + RequestType.NOTARY_PROVE, |
| 22 | + async (request: NotaryProveRequest): Promise<NotaryProveResponse> => { |
| 23 | + const steamPoweredPermissions = await HasPermissions.handleRequest( |
| 24 | + { |
| 25 | + permissions: [], |
| 26 | + origins: ['https://api.steampowered.com/*'], |
| 27 | + }, |
| 28 | + {} |
| 29 | + ); |
| 30 | + if (!steamPoweredPermissions.granted) { |
| 31 | + throw new Error('must have api.steampowered.com permissions in order to prove API requests'); |
| 32 | + } |
| 33 | + |
| 34 | + const access_token = await getAccessToken(request.expected_steam_id); |
| 35 | + |
| 36 | + const response = await SendToOffscreen<TLSNProveOffscreenRequest, TLSNProveOffscreenResponse>( |
| 37 | + OffscreenRequestType.TLSN_PROVE, |
| 38 | + { |
| 39 | + notary_request: request, |
| 40 | + access_token, |
| 41 | + } |
| 42 | + ); |
| 43 | + |
| 44 | + return { |
| 45 | + presentation: response.presentation, |
| 46 | + }; |
| 47 | + } |
| 48 | + ), |
| 49 | + 2 |
| 50 | +); |
0 commit comments