@@ -106,27 +106,33 @@ function decryptFromEnclave(
106
106
export type VaultClient = {
107
107
baseUrl : string ;
108
108
publicKey : Uint8Array ;
109
+ headers : Record < string , string > ;
109
110
} ;
110
111
111
- export async function createVaultClient ( {
112
- baseUrl,
113
- } : {
114
- baseUrl : string ;
112
+ export async function createVaultClient ( clientOptions ?: {
113
+ baseUrl ?: string ;
114
+ secretKey ?: string ;
115
115
} ) : Promise < VaultClient > {
116
+ const baseUrl = clientOptions ?. baseUrl ?? "https://engine.thirdweb.com" ;
116
117
// Construct the full URL for the fetch call
117
118
const url = new URL ( "api/v1/enclave" , baseUrl ) . toString ( ) ;
118
119
119
120
type IntrospectionResponse = {
120
121
publicKey : string ;
121
122
} ;
122
123
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
+
123
132
try {
124
133
const response = await fetch ( url , {
125
134
method : "GET" ,
126
- headers : {
127
- // Indicate we accept JSON responses
128
- Accept : "application/json" ,
129
- } ,
135
+ headers,
130
136
} ) ;
131
137
132
138
// fetch doesn't throw on HTTP errors (like 4xx, 5xx) by default.
@@ -149,7 +155,8 @@ export async function createVaultClient({
149
155
const publicKeyBytes = hexToBytes ( data . publicKey ) ;
150
156
151
157
return {
152
- baseUrl : baseUrl , // Store baseUrl
158
+ baseUrl, // Store baseUrl
159
+ headers,
153
160
publicKey : publicKeyBytes ,
154
161
} ;
155
162
} catch ( error ) {
@@ -180,6 +187,7 @@ async function sendRequest<P extends Payload>({
180
187
const response = await fetch ( url , {
181
188
method : "POST" ,
182
189
headers : {
190
+ ...client . headers ,
183
191
"Content-Type" : "application/json" ,
184
192
Accept : "application/json" , // Good practice to specify accept header
185
193
} ,
0 commit comments