Skip to content

Commit

Permalink
add headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ikethirdweb committed Jan 29, 2024
1 parent 6896428 commit 360d032
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 22 deletions.
5 changes: 5 additions & 0 deletions packages/react-native/src/evm/constants/headers.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export const BUNDLE_ID_HEADER = "x-bundle-id";

export const X_SDK_VERSION_HEADER = "x-sdk-version";
export const X_SDK_NAME_HEADER = "x-sdk-name";
export const X_SDK_PLATFORM_HEADER = "x-sdk-platform";
export const X_SDK_OS_HEADER = "x-sdk-os";
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,25 @@ import {
appBundleId,
reactNativePackageVersion,
} from "../../../../utils/version";
import { BUNDLE_ID_HEADER } from "../../../../constants/headers";
import {
BUNDLE_ID_HEADER,
X_SDK_NAME_HEADER,
X_SDK_OS_HEADER,
X_SDK_PLATFORM_HEADER,
X_SDK_VERSION_HEADER,
} from "../../../../constants/headers";
import { ANALYTICS } from "./helpers/analytics";

const HEADERS = {
[EWS_VERSION_HEADER]: (globalThis as any).X_SDK_VERSION,
[BUNDLE_ID_HEADER]: (globalThis as any).APP_BUNDLE_ID,
[THIRDWEB_SESSION_NONCE_HEADER]: ANALYTICS.nonce,
[X_SDK_NAME_HEADER]: (globalThis as any).X_SDK_NAME,
[X_SDK_OS_HEADER]: (globalThis as any).X_SDK_OS,
[X_SDK_PLATFORM_HEADER]: (globalThis as any).X_SDK_PLATFORM,
[X_SDK_VERSION_HEADER]: (globalThis as any).X_SDK_VERSION,
};

export async function sendVerificationEmail(options: {
email: string;
clientId: string;
Expand Down Expand Up @@ -195,9 +211,7 @@ export async function socialLogin(oauthOptions: OauthOption, clientId: string) {

const resp = await fetch(headlessLoginLinkWithParams, {
headers: {
[EWS_VERSION_HEADER]: reactNativePackageVersion,
[BUNDLE_ID_HEADER]: appBundleId,
[THIRDWEB_SESSION_NONCE_HEADER]: ANALYTICS.nonce,
...HEADERS,
},
});

Expand Down Expand Up @@ -278,9 +292,7 @@ export async function customJwt(authOptions: AuthOptions, clientId: string) {
method: "POST",
headers: {
"Content-Type": "application/json",
[EWS_VERSION_HEADER]: reactNativePackageVersion,
[BUNDLE_ID_HEADER]: appBundleId,
[THIRDWEB_SESSION_NONCE_HEADER]: ANALYTICS.nonce,
...HEADERS,
},
body: JSON.stringify({
jwt: jwt,
Expand Down Expand Up @@ -328,9 +340,7 @@ export async function authEndpoint(
method: "POST",
headers: {
"Content-Type": "application/json",
[EWS_VERSION_HEADER]: reactNativePackageVersion,
[BUNDLE_ID_HEADER]: appBundleId,
[THIRDWEB_SESSION_NONCE_HEADER]: ANALYTICS.nonce,
...HEADERS,
},
body: JSON.stringify({
payload: payload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,27 @@ import {
appBundleId,
reactNativePackageVersion,
} from "../../../../../../utils/version";
import { BUNDLE_ID_HEADER } from "../../../../../../constants/headers";
import {
BUNDLE_ID_HEADER,
X_SDK_NAME_HEADER,
X_SDK_OS_HEADER,
X_SDK_PLATFORM_HEADER,
X_SDK_VERSION_HEADER,
} from "../../../../../../constants/headers";
import { ANALYTICS } from "../analytics";

const EMBEDDED_WALLET_TOKEN_HEADER = "embedded-wallet-token";
const PAPER_CLIENT_ID_HEADER = "x-thirdweb-client-id";

const HEADERS = {
"Content-Type": "application/json",
[BUNDLE_ID_HEADER]: appBundleId,
[EWS_VERSION_HEADER]: reactNativePackageVersion,
[EWS_VERSION_HEADER]: (globalThis as any).X_SDK_VERSION,
[BUNDLE_ID_HEADER]: (globalThis as any).APP_BUNDLE_ID,
[THIRDWEB_SESSION_NONCE_HEADER]: ANALYTICS.nonce,
[X_SDK_NAME_HEADER]: (globalThis as any).X_SDK_NAME,
[X_SDK_OS_HEADER]: (globalThis as any).X_SDK_OS,
[X_SDK_PLATFORM_HEADER]: (globalThis as any).X_SDK_PLATFORM,
[X_SDK_VERSION_HEADER]: (globalThis as any).X_SDK_VERSION,
};

export const verifyClientId = async (clientId: string) => {
Expand Down Expand Up @@ -68,19 +79,15 @@ export const authFetchEmbeddedWalletUser = async (
Authorization: `Bearer ${EMBEDDED_WALLET_TOKEN_HEADER}:${
authTokenClient || ""
}`,
[BUNDLE_ID_HEADER]: appBundleId,
[PAPER_CLIENT_ID_HEADER]: clientId,
[EWS_VERSION_HEADER]: reactNativePackageVersion,
[THIRDWEB_SESSION_NONCE_HEADER]: ANALYTICS.nonce,
...HEADERS,
}
: {
Authorization: `Bearer ${EMBEDDED_WALLET_TOKEN_HEADER}:${
authTokenClient || ""
}`,
[BUNDLE_ID_HEADER]: appBundleId,
[PAPER_CLIENT_ID_HEADER]: clientId,
[EWS_VERSION_HEADER]: reactNativePackageVersion,
[THIRDWEB_SESSION_NONCE_HEADER]: ANALYTICS.nonce,
...HEADERS,
};
return fetch(url, params);
};
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/evm/common/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export async function verify(
};

const parameters = new URLSearchParams({ ...requestBody });
// do we need to pass headers here?
const result = await fetch(explorerAPIUrl, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
Expand Down Expand Up @@ -474,9 +475,8 @@ async function fetchDeployBytecodeFromPublishedContractMetadata(
getChainProvider("polygon", {}),
) as ContractPublisher;

const publishedMetadataUri = await contract.getPublishedUriFromCompilerUri(
compilerMetaUri,
);
const publishedMetadataUri =
await contract.getPublishedUriFromCompilerUri(compilerMetaUri);
if (publishedMetadataUri.length === 0) {
throw Error(
`Could not resolve published metadata URI from ${compilerMetaUri}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ export class ContractWrapper<

const request = await this.enginePrepareRequest(transaction);

// should we pass headers here?
const res = await fetch(this.options.gasless.engine.relayerUrl, {
...request,
headers: {
Expand Down
5 changes: 5 additions & 0 deletions packages/storage/src/core/uploaders/ipfs-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ export class IpfsUploader implements IStorageUploader<IpfsUploadBatchOptions> {
headers["x-authorize-wallet"] = "true";
}

headers["x-sdk-version"] = (globalThis as any).X_SDK_VERSION;
headers["x-sdk-name"] = (globalThis as any).X_SDK_NAME;
headers["x-sdk-platform"] = (globalThis as any).X_SDK_PLATFORM;
headers["x-sdk-os"] = (globalThis as any).X_SDK_OS;

const res = await fetch(`${this.uploadServerUrl}/ipfs/upload`, {
method: "POST",
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class VerifyingPaymasterAPI extends PaymasterAPI {
}`;
headers["x-authorize-wallet"] = "true";
}

headers["x-sdk-version"] = (globalThis as any).X_SDK_VERSION;
headers["x-sdk-name"] = (globalThis as any).X_SDK_NAME;
headers["x-sdk-platform"] = (globalThis as any).X_SDK_PLATFORM;
headers["x-sdk-os"] = (globalThis as any).X_SDK_OS;
}

// Ask the paymaster to sign the transaction and return a valid paymasterAndData value.
Expand Down
4 changes: 4 additions & 0 deletions packages/wallets/src/evm/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export function track(args: {
headers: {
"Content-Type": "application/json",
"x-client-id": clientId,
"x-sdk-version": (globalThis as any).X_SDK_VERSION,
"x-sdk-name": (globalThis as any).X_SDK_NAME,
"x-sdk-platform": (globalThis as any).X_SDK_PLATFORM,
"x-sdk-os": (globalThis as any).X_SDK_OS,
},
body: JSON.stringify(body),
});
Expand Down

0 comments on commit 360d032

Please sign in to comment.