Skip to content

Commit e71e7d7

Browse files
authored
[Vault] default to engine-cloud vault proxy (#7058)
1 parent 8d47864 commit e71e7d7

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

.changeset/all-bears-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/vault-sdk": patch
3+
---
4+
5+
added secret key and default vault url

packages/vault-sdk/src/sdk.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,33 @@ function decryptFromEnclave(
106106
export type VaultClient = {
107107
baseUrl: string;
108108
publicKey: Uint8Array;
109+
headers: Record<string, string>;
109110
};
110111

111-
export async function createVaultClient({
112-
baseUrl,
113-
}: {
114-
baseUrl: string;
112+
export async function createVaultClient(clientOptions?: {
113+
baseUrl?: string;
114+
secretKey?: string;
115115
}): Promise<VaultClient> {
116+
const baseUrl = clientOptions?.baseUrl ?? "https://engine.thirdweb.com";
116117
// Construct the full URL for the fetch call
117118
const url = new URL("api/v1/enclave", baseUrl).toString();
118119

119120
type IntrospectionResponse = {
120121
publicKey: string;
121122
};
122123

124+
const headers = {
125+
// Indicate we accept JSON responses
126+
Accept: "application/json",
127+
...(clientOptions?.secretKey
128+
? { "x-secret-key": clientOptions?.secretKey }
129+
: {}),
130+
};
131+
123132
try {
124133
const response = await fetch(url, {
125134
method: "GET",
126-
headers: {
127-
// Indicate we accept JSON responses
128-
Accept: "application/json",
129-
},
135+
headers,
130136
});
131137

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

151157
return {
152-
baseUrl: baseUrl, // Store baseUrl
158+
baseUrl, // Store baseUrl
159+
headers,
153160
publicKey: publicKeyBytes,
154161
};
155162
} catch (error) {
@@ -180,6 +187,7 @@ async function sendRequest<P extends Payload>({
180187
const response = await fetch(url, {
181188
method: "POST",
182189
headers: {
190+
...client.headers,
183191
"Content-Type": "application/json",
184192
Accept: "application/json", // Good practice to specify accept header
185193
},

0 commit comments

Comments
 (0)