Skip to content

Commit c3e51fd

Browse files
wentzelddev-dist
andauthored
fix: correct confidentialHTTP SDK reference and guide docs (#3503)
* fix: correct confidentialHTTP SDK reference and guide docs - Move EncryptOutput/encryptOutput from ConfidentialHTTPRequest to HTTPRequest - Fix Client.SendRequest signature: cre.Runtime not cre.NodeRuntime - Remove nonexistent high-level SendRequest/ConfidentialHTTPSendRequester patterns - Remove incorrect RunInNodeMode wrapping (not needed for confidential HTTP) - Fix all code examples in both Go and TS guides * fix: correct step numbering in TS confidential HTTP guide * fix: apply Prettier formatting to modified docs * llms --------- Co-authored-by: devin distefano <devin.distefano@smartcontract.com>
1 parent a7c3417 commit c3e51fd

6 files changed

Lines changed: 238 additions & 644 deletions

File tree

src/content/cre/guides/workflow/using-confidential-http-client/making-requests-go.mdx

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ type Result struct {
9494

9595
### Step 4: Implement the request logic
9696

97-
Use `cre.RunInNodeMode` to make the confidential request. The `confidentialhttp.Client` requires a `NodeRuntime`:
97+
Unlike the regular HTTP client, the Confidential HTTP client takes a `cre.Runtime` directly and does not require `cre.RunInNodeMode` wrapping:
9898

9999
```go
100-
func makeConfidentialRequest(config Config, nodeRuntime cre.NodeRuntime) (Result, error) {
100+
func makeConfidentialRequest(config Config, runtime cre.Runtime) (Result, error) {
101101
// 1. Define the request body with secret template placeholders
102102
payload := `{"auth": "{{.myApiKey}}", "action": "getTransaction", "id": "tx-123"}`
103103

@@ -113,17 +113,17 @@ func makeConfidentialRequest(config Config, nodeRuntime cre.NodeRuntime) (Result
113113

114114
// 3. Create the client and send the request
115115
client := confidentialhttp.Client{}
116-
resp, err := client.SendRequest(nodeRuntime, &confidentialhttp.ConfidentialHTTPRequest{
116+
resp, err := client.SendRequest(runtime, &confidentialhttp.ConfidentialHTTPRequest{
117117
Request: &confidentialhttp.HTTPRequest{
118-
Url: config.URL,
119-
Method: "POST",
120-
Body: &confidentialhttp.HTTPRequest_BodyString{BodyString: payload},
118+
Url: config.URL,
119+
Method: "POST",
120+
Body: &confidentialhttp.HTTPRequest_BodyString{BodyString: payload},
121121
MultiHeaders: headers,
122+
EncryptOutput: false,
122123
},
123124
VaultDonSecrets: []*confidentialhttp.SecretIdentifier{
124125
{Key: "myApiKey"},
125126
},
126-
EncryptOutput: false,
127127
}).Await()
128128
if err != nil {
129129
return Result{}, fmt.Errorf("confidential HTTP request failed: %w", err)
@@ -141,14 +141,11 @@ func makeConfidentialRequest(config Config, nodeRuntime cre.NodeRuntime) (Result
141141

142142
### Step 5: Wire it into your workflow
143143

144-
Call the request function from your trigger handler using `cre.RunInNodeMode`:
144+
Call the request function from your trigger handler:
145145

146146
```go
147147
func onCronTrigger(config *Config, runtime cre.Runtime, outputs *cron.Payload) (string, error) {
148-
result, err := cre.RunInNodeMode(*config, runtime,
149-
makeConfidentialRequest,
150-
cre.ConsensusIdenticalAggregation[Result](),
151-
).Await()
148+
result, err := makeConfidentialRequest(*config, runtime)
152149
if err != nil {
153150
return "", fmt.Errorf("failed to get result: %w", err)
154151
}
@@ -212,18 +209,18 @@ By default, the API response is returned unencrypted (`EncryptOutput: false`). T
212209
1. **Include the key in your `VaultDonSecrets`** and set `EncryptOutput: true`:
213210

214211
```go
215-
resp, err := client.SendRequest(nodeRuntime, &confidentialhttp.ConfidentialHTTPRequest{
212+
resp, err := client.SendRequest(runtime, &confidentialhttp.ConfidentialHTTPRequest{
216213
Request: &confidentialhttp.HTTPRequest{
217-
Url: config.URL,
218-
Method: "POST",
219-
Body: &confidentialhttp.HTTPRequest_BodyString{BodyString: payload},
220-
MultiHeaders: headers,
214+
Url: config.URL,
215+
Method: "POST",
216+
Body: &confidentialhttp.HTTPRequest_BodyString{BodyString: payload},
217+
MultiHeaders: headers,
218+
EncryptOutput: true,
221219
},
222220
VaultDonSecrets: []*confidentialhttp.SecretIdentifier{
223221
{Key: "myApiKey"},
224222
{Key: "san_marino_aes_gcm_encryption_key"},
225223
},
226-
EncryptOutput: true,
227224
}).Await()
228225
```
229226

@@ -309,10 +306,7 @@ func InitWorkflow(config *Config, logger *slog.Logger, secretsProvider cre.Secre
309306
}
310307

311308
func onCronTrigger(config *Config, runtime cre.Runtime, outputs *cron.Payload) (string, error) {
312-
result, err := cre.RunInNodeMode(*config, runtime,
313-
makeConfidentialRequest,
314-
cre.ConsensusIdenticalAggregation[Result](),
315-
).Await()
309+
result, err := makeConfidentialRequest(*config, runtime)
316310
if err != nil {
317311
return "", fmt.Errorf("failed to get result: %w", err)
318312
}
@@ -321,7 +315,7 @@ func onCronTrigger(config *Config, runtime cre.Runtime, outputs *cron.Payload) (
321315
return result.TransactionID, nil
322316
}
323317

324-
func makeConfidentialRequest(config Config, nodeRuntime cre.NodeRuntime) (Result, error) {
318+
func makeConfidentialRequest(config Config, runtime cre.Runtime) (Result, error) {
325319
payload := `{"auth": "{{.myApiKey}}", "action": "getTransaction", "id": "tx-123"}`
326320

327321
headers := map[string]*confidentialhttp.HeaderValues{
@@ -334,18 +328,18 @@ func makeConfidentialRequest(config Config, nodeRuntime cre.NodeRuntime) (Result
334328
}
335329

336330
client := confidentialhttp.Client{}
337-
resp, err := client.SendRequest(nodeRuntime, &confidentialhttp.ConfidentialHTTPRequest{
331+
resp, err := client.SendRequest(runtime, &confidentialhttp.ConfidentialHTTPRequest{
338332
Request: &confidentialhttp.HTTPRequest{
339-
Url: config.URL,
340-
Method: "POST",
341-
Body: &confidentialhttp.HTTPRequest_BodyString{BodyString: payload},
342-
MultiHeaders: headers,
333+
Url: config.URL,
334+
Method: "POST",
335+
Body: &confidentialhttp.HTTPRequest_BodyString{BodyString: payload},
336+
MultiHeaders: headers,
337+
EncryptOutput: true,
343338
},
344339
VaultDonSecrets: []*confidentialhttp.SecretIdentifier{
345340
{Key: "myApiKey"},
346341
{Key: "san_marino_aes_gcm_encryption_key"},
347342
},
348-
EncryptOutput: true,
349343
}).Await()
350344
if err != nil {
351345
return Result{}, fmt.Errorf("confidential HTTP request failed: %w", err)

src/content/cre/guides/workflow/using-confidential-http-client/making-requests-ts.mdx

Lines changed: 32 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,27 @@ type TransactionResult = {
8787
}
8888
```
8989

90-
### Step 4: Implement the fetch function
90+
### Step 4: Implement the request and wire it into your workflow
9191

92-
Create the function that will be passed to `sendRequest()`. This function receives a `ConfidentialHTTPSendRequester` and your config as parameters:
92+
Unlike the regular HTTP client, the Confidential HTTP client takes a `Runtime` directly and does not require `runInNodeMode` wrapping:
9393

9494
```typescript
95-
import { type ConfidentialHTTPSendRequester, ok, json } from "@chainlink/cre-sdk"
95+
import { CronCapability, ConfidentialHTTPClient, handler, ok, json, type Runtime, Runner } from "@chainlink/cre-sdk"
96+
97+
const onCronTrigger = (runtime: Runtime<Config>): TransactionResult => {
98+
const confHTTPClient = new ConfidentialHTTPClient()
9699
97-
const fetchTransaction = (sendRequester: ConfidentialHTTPSendRequester, config: Config): TransactionResult => {
98100
// 1. Send the confidential request
99-
const response = sendRequester
100-
.sendRequest({
101+
const response = confHTTPClient
102+
.sendRequest(runtime, {
101103
request: {
102-
url: config.url,
104+
url: runtime.config.url,
103105
method: "GET",
104106
multiHeaders: {
105107
Authorization: { values: ["Basic {{.myApiKey}}"] },
106108
},
107109
},
108-
vaultDonSecrets: [{ key: "myApiKey", owner: config.owner }],
110+
vaultDonSecrets: [{ key: "myApiKey", owner: runtime.config.owner }],
109111
})
110112
.result()
111113
@@ -115,37 +117,13 @@ const fetchTransaction = (sendRequester: ConfidentialHTTPSendRequester, config:
115117
}
116118

117119
// 3. Parse and return the result
118-
return json(response) as TransactionResult
119-
}
120-
```
121-
122-
### Step 5: Wire it into your workflow
123-
124-
In your trigger handler, call `confHTTPClient.sendRequest()` with your fetch function and a consensus method:
125-
126-
```typescript
127-
import {
128-
CronCapability,
129-
ConfidentialHTTPClient,
130-
handler,
131-
consensusIdenticalAggregation,
132-
type Runtime,
133-
Runner,
134-
} from "@chainlink/cre-sdk"
135-
136-
const onCronTrigger = (runtime: Runtime<Config>): string => {
137-
const confHTTPClient = new ConfidentialHTTPClient()
138-
139-
const result = confHTTPClient
140-
.sendRequest(runtime, fetchTransaction, consensusIdenticalAggregation<TransactionResult>())(runtime.config)
141-
.result()
142-
120+
const result = json(response) as TransactionResult
143121
runtime.log(`Transaction result: ${result.transactionId} — ${result.status}`)
144-
return result.transactionId
122+
return result
145123
}
146124
```
147125

148-
### Step 6: Simulate
126+
### Step 5: Simulate
149127

150128
Run the simulation:
151129

@@ -197,17 +175,20 @@ export AES_KEY_ALL="your-256-bit-hex-encoded-key"
197175
1. **Include the key in your `vaultDonSecrets`** and set `encryptOutput: true`:
198176

199177
```typescript
200-
const response = sendRequester
201-
.sendRequest({
178+
const response = confHTTPClient
179+
.sendRequest(runtime, {
202180
request: {
203-
url: config.url,
181+
url: runtime.config.url,
204182
method: "GET",
205183
multiHeaders: {
206184
Authorization: { values: ["Basic {{.myApiKey}}"] },
207185
},
186+
encryptOutput: true,
208187
},
209-
vaultDonSecrets: [{ key: "myApiKey", owner: config.owner }, { key: "san_marino_aes_gcm_encryption_key" }],
210-
encryptOutput: true,
188+
vaultDonSecrets: [
189+
{ key: "myApiKey", owner: runtime.config.owner },
190+
{ key: "san_marino_aes_gcm_encryption_key" },
191+
],
211192
})
212193
.result()
213194
```
@@ -229,17 +210,7 @@ The SDK response helpers `ok()`, `text()`, and `json()` work with Confidential H
229210
Here's the full workflow code for a confidential HTTP request with secret injection:
230211

231212
```typescript
232-
import {
233-
CronCapability,
234-
ConfidentialHTTPClient,
235-
handler,
236-
consensusIdenticalAggregation,
237-
ok,
238-
json,
239-
type ConfidentialHTTPSendRequester,
240-
type Runtime,
241-
Runner,
242-
} from "@chainlink/cre-sdk"
213+
import { CronCapability, ConfidentialHTTPClient, handler, ok, json, type Runtime, Runner } from "@chainlink/cre-sdk"
243214
import { z } from "zod"
244215

245216
// Config schema
@@ -257,38 +228,30 @@ type TransactionResult = {
257228
status: string
258229
}
259230

260-
// Fetch function — receives a ConfidentialHTTPSendRequester and config
261-
const fetchTransaction = (sendRequester: ConfidentialHTTPSendRequester, config: Config): TransactionResult => {
262-
const response = sendRequester
263-
.sendRequest({
231+
// Main workflow handler
232+
const onCronTrigger = (runtime: Runtime<Config>): TransactionResult => {
233+
const confHTTPClient = new ConfidentialHTTPClient()
234+
235+
const response = confHTTPClient
236+
.sendRequest(runtime, {
264237
request: {
265-
url: config.url,
238+
url: runtime.config.url,
266239
method: "GET",
267240
multiHeaders: {
268241
Authorization: { values: ["Basic {{.myApiKey}}"] },
269242
},
270243
},
271-
vaultDonSecrets: [{ key: "myApiKey", owner: config.owner }],
244+
vaultDonSecrets: [{ key: "myApiKey", owner: runtime.config.owner }],
272245
})
273246
.result()
274247

275248
if (!ok(response)) {
276249
throw new Error(`HTTP request failed with status: ${response.statusCode}`)
277250
}
278251

279-
return json(response) as TransactionResult
280-
}
281-
282-
// Main workflow handler
283-
const onCronTrigger = (runtime: Runtime<Config>): string => {
284-
const confHTTPClient = new ConfidentialHTTPClient()
285-
286-
const result = confHTTPClient
287-
.sendRequest(runtime, fetchTransaction, consensusIdenticalAggregation<TransactionResult>())(runtime.config)
288-
.result()
289-
252+
const result = json(response) as TransactionResult
290253
runtime.log(`Transaction result: ${result.transactionId} — ${result.status}`)
291-
return result.transactionId
254+
return result
292255
}
293256

294257
// Initialize workflow

0 commit comments

Comments
 (0)