Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"service_worker": "src/background.js",
"type": "module"
},
"permissions": ["storage", "scripting", "alarms", "declarativeNetRequestWithHostAccess"],
"minimum_chrome_version": "109",
"permissions": ["storage", "scripting", "alarms", "declarativeNetRequestWithHostAccess", "offscreen"],
"host_permissions": [
"*://*.steamcommunity.com/market/listings/730/*",
"*://*.steamcommunity.com/id/*/inventory*",
Expand All @@ -73,5 +74,8 @@
"path": "src/steamcommunity_ruleset.json"
}
]
},
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';"
}
}
130 changes: 130 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@
"typescript": "^5.8.3",
"webpack": "^5.98.0",
"webpack-cli": "^6.0.1"
},
"dependencies": {
"buffer": "^6.0.3",
"comlink": "^4.4.2",
"tlsn-js": "0.1.0-alpha.12.0"
}
}
5 changes: 5 additions & 0 deletions src/environment.dev.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export const environment = {
csfloat_base_api_url: 'http://localhost:8080/api',
notary: {
tlsn: 'https://notary.csfloat.com/tlsn/',
ws: 'wss://notary.csfloat.com/ws/',
loggingLevel: 'Error',
},
};
5 changes: 5 additions & 0 deletions src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export const environment = {
csfloat_base_api_url: 'https://csfloat.com/api',
notary: {
tlsn: 'https://notary.csfloat.com/tlsn/',
ws: 'wss://notary.csfloat.com/ws/',
loggingLevel: 'Warn',
},
};
2 changes: 2 additions & 0 deletions src/lib/bridge/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {FetchCSFloatMe} from './fetch_csfloat_me';
import {PingRollbackTrade} from './ping_rollback_trade';
import {FetchTradeHistory} from './fetch_trade_history';
import {FetchSlimTrades} from './fetch_slim_trades';
import {NotaryProve} from './notary_prove';

export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
[RequestType.EXECUTE_SCRIPT_ON_PAGE]: ExecuteScriptOnPage,
Expand Down Expand Up @@ -68,4 +69,5 @@ export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
[RequestType.PING_ROLLBACK_TRADE]: PingRollbackTrade,
[RequestType.FETCH_TRADE_HISTORY]: FetchTradeHistory,
[RequestType.FETCH_SLIM_TRADES]: FetchSlimTrades,
[RequestType.NOTARY_PROVE]: NotaryProve,
};
50 changes: 50 additions & 0 deletions src/lib/bridge/handlers/notary_prove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {SimpleHandler} from './main';
import {RequestType} from './types';
import {SendToOffscreen} from '../../../offscreen/client';
import {HasPermissions} from './has_permissions';
import {NotaryProveRequest} from '../../notary/types';
import {getAccessToken} from '../../alarms/access_token';
import {PresentationJSON} from 'tlsn-js/build/types';
import {
OffscreenRequestType,
TLSNProveOffscreenRequest,
TLSNProveOffscreenResponse,
} from '../../../offscreen/handlers/types';
import {MaxConcurrency} from '../wrappers/cached';

export interface NotaryProveResponse {
presentation: PresentationJSON;
}

export const NotaryProve = MaxConcurrency(
new SimpleHandler<NotaryProveRequest, NotaryProveResponse>(
RequestType.NOTARY_PROVE,
async (request: NotaryProveRequest): Promise<NotaryProveResponse> => {
const steamPoweredPermissions = await HasPermissions.handleRequest(
{
permissions: [],
origins: ['https://api.steampowered.com/*'],
},
{}
);
if (!steamPoweredPermissions.granted) {
throw new Error('must have api.steampowered.com permissions in order to prove API requests');
}

const access_token = await getAccessToken(request.expected_steam_id);

const response = await SendToOffscreen<TLSNProveOffscreenRequest, TLSNProveOffscreenResponse>(
OffscreenRequestType.TLSN_PROVE,
{
notary_request: request,
access_token,
}
);

return {
presentation: response.presentation,
};
}
),
2
);
1 change: 1 addition & 0 deletions src/lib/bridge/handlers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export enum RequestType {
PING_ROLLBACK_TRADE = 30,
FETCH_TRADE_HISTORY = 31,
FETCH_SLIM_TRADES = 32,
NOTARY_PROVE = 33,
}
11 changes: 11 additions & 0 deletions src/lib/bridge/wrappers/cached.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,14 @@ export class CachedHandler<Req, Resp> implements RequestHandler<Req, Resp> {
return this.queue.fetch(request, sender);
}
}

/**
* Sets max concurrency for the given handler. Requests in excess of this limit will block until the active
* requests are finished. Uses a FIFO queue underneath.
*
* @param handler Handler to wrap with a max concurrency
* @param maxConcurrency Max concurrency
*/
export function MaxConcurrency<Req, Resp>(handler: RequestHandler<Req, Resp>, maxConcurrency: number) {
return new CachedHandler(handler, maxConcurrency, /* disable caching */ 0);
}
48 changes: 48 additions & 0 deletions src/lib/notary/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export enum ProofType {
TRADE_OFFERS = 'trade_offers',
TRADE_OFFER = 'trade_offer',
TRADE_HISTORY = 'trade_history',
TRADE_STATUS = 'trade_status',
}

interface ProveRequestPayloads {
// IEconService/GetTradeOffers/v1/
[ProofType.TRADE_OFFERS]: {
get_sent_offers?: boolean;
get_received_offers?: boolean;
get_descriptions?: boolean;
language?: string;
active_only?: boolean;
historical_only?: boolean;
time_historical_cutoff?: number;
cursor?: number;
};
// IEconService/GetTradeOffer/v1/
[ProofType.TRADE_OFFER]: {
tradeofferid: string;
};
// IEconService/GetTradeHistory/v1/
[ProofType.TRADE_HISTORY]: {
max_trades: number;
start_after_time?: number;
start_after_tradeid?: string;
navigating_back?: boolean;
get_descriptions?: boolean;
language?: string;
include_failed?: boolean;
include_total?: boolean;
};
// IEconService/GetTradeStatus/v1/
[ProofType.TRADE_STATUS]: {
tradeid: string;
get_descriptions?: boolean;
language?: string;
};
}

export type NotaryProveRequest = {
[T in ProofType]: {
type: T;
expected_steam_id?: string;
} & ProveRequestPayloads[T];
}[ProofType];
Loading