Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ID-2589 Add json rpc referrer as optional param and set on game bridge #2332

Merged
merged 2 commits into from
Oct 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion examples/passport/telegram-mini-app/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const passportInstance = new passport.Passport({
logoutRedirectUri: process.env.NEXT_PUBLIC_LOGOUT_REDIRECT_URI || "",
audience: "platform_api",
scope: "openid offline_access email transact",
// Enable crossSdkBridge to enable pre-approved transactions
// Set crossSdkBridgeEnabled to enable pre-approved transactions
crossSdkBridgeEnabled: true,
});
// #enddoc passport-telegram-mini-app-configuration
Expand Down
1 change: 1 addition & 0 deletions packages/game-bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ window.callFunction = async (jsonData: string) => {
redirectUri: redirect ?? redirectUri,
logoutRedirectUri: request?.logoutRedirectUri,
crossSdkBridgeEnabled: true,
jsonRpcReferrer: 'http://imtblgamesdk.local',
logoutMode,
};
}
Expand Down
4 changes: 4 additions & 0 deletions packages/passport/sdk/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export class PassportConfiguration {

readonly crossSdkBridgeEnabled: boolean;

readonly jsonRpcReferrer: string;

readonly forceScwDeployBeforeMessageSignature: boolean;

readonly popupOverlayOptions: PopupOverlayOptions;
Expand All @@ -58,6 +60,7 @@ export class PassportConfiguration {
baseConfig,
overrides,
crossSdkBridgeEnabled,
jsonRpcReferrer,
forceScwDeployBeforeMessageSignature,
popupOverlayOptions,
...oidcConfiguration
Expand All @@ -69,6 +72,7 @@ export class PassportConfiguration {
this.oidcConfiguration = oidcConfiguration;
this.baseConfig = baseConfig;
this.crossSdkBridgeEnabled = crossSdkBridgeEnabled || false;
this.jsonRpcReferrer = jsonRpcReferrer || '';
this.forceScwDeployBeforeMessageSignature = forceScwDeployBeforeMessageSignature || false;
this.popupOverlayOptions = popupOverlayOptions || {
disableGenericPopupOverlay: false,
Expand Down
6 changes: 6 additions & 0 deletions packages/passport/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export interface PassportModuleConfiguration
*/
crossSdkBridgeEnabled?: boolean;

/**
* Optional referrer URL to be sent with JSON-RPC requests.
* If specified, this value will be passed as the referrer in fetch options.
*/
jsonRpcReferrer?: string;

/**
* Options for disabling the Passport popup overlays.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/passport/sdk/src/zkEvm/zkEvmProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export class ZkEvmProvider implements Provider {
this.#guardianClient = guardianClient;
this.#passportEventEmitter = passportEventEmitter;

if (config.crossSdkBridgeEnabled) {
if (config.jsonRpcReferrer) {
// StaticJsonRpcProvider by default sets the referrer as "client".
// On Unreal 4 this errors as the browser used is expecting a valid URL.
this.#rpcProvider = new StaticJsonRpcProvider({
url: this.#config.zkEvmRpcUrl,
fetchOptions: { referrer: 'http://imtblgamesdk.local' },
fetchOptions: { referrer: config.jsonRpcReferrer },
});
} else {
this.#rpcProvider = new StaticJsonRpcProvider(this.#config.zkEvmRpcUrl);
Expand Down