Skip to content

[Vault] default to engine-cloud vault proxy #7058

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

Merged
merged 2 commits into from
May 15, 2025
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
5 changes: 5 additions & 0 deletions .changeset/all-bears-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/vault-sdk": patch
---

added secret key and default vault url
26 changes: 17 additions & 9 deletions packages/vault-sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,33 @@ function decryptFromEnclave(
export type VaultClient = {
baseUrl: string;
publicKey: Uint8Array;
headers: Record<string, string>;
};

export async function createVaultClient({
baseUrl,
}: {
baseUrl: string;
export async function createVaultClient(clientOptions?: {
baseUrl?: string;
secretKey?: string;
}): Promise<VaultClient> {
const baseUrl = clientOptions?.baseUrl ?? "https://engine.thirdweb.com";
// Construct the full URL for the fetch call
const url = new URL("api/v1/enclave", baseUrl).toString();

type IntrospectionResponse = {
publicKey: string;
};

const headers = {
// Indicate we accept JSON responses
Accept: "application/json",
...(clientOptions?.secretKey
? { "x-secret-key": clientOptions?.secretKey }
: {}),
};

try {
const response = await fetch(url, {
method: "GET",
headers: {
// Indicate we accept JSON responses
Accept: "application/json",
},
headers,
});

// fetch doesn't throw on HTTP errors (like 4xx, 5xx) by default.
Expand All @@ -149,7 +155,8 @@ export async function createVaultClient({
const publicKeyBytes = hexToBytes(data.publicKey);

return {
baseUrl: baseUrl, // Store baseUrl
baseUrl, // Store baseUrl
headers,
publicKey: publicKeyBytes,
};
} catch (error) {
Expand Down Expand Up @@ -180,6 +187,7 @@ async function sendRequest<P extends Payload>({
const response = await fetch(url, {
method: "POST",
headers: {
...client.headers,
"Content-Type": "application/json",
Accept: "application/json", // Good practice to specify accept header
},
Expand Down
Loading