Skip to content

Commit 481c4ee

Browse files
committed
[FIX] reorder OPRF and de-chunking for TEEs
1 parent ac35c07 commit 481c4ee

2 files changed

Lines changed: 41 additions & 40 deletions

File tree

src/tests/http-provider.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describeWithServer('HTTP Provider', opts => {
1515
const resp = await createClaimOnAttestor({
1616
name: 'http',
1717
params: {
18-
url: 'https://news.ycombinator.{{param1}}/{{param4}}',
18+
url: 'https://news.ycombinator.com/{{param4}}',
1919
method: 'GET',
2020
responseMatches: [{
2121
type: 'regex',
@@ -40,6 +40,7 @@ describeWithServer('HTTP Provider', opts => {
4040
client: opts.client,
4141
zkEngine: 'gnark'
4242
})
43+
console.log('ERROOOOOR' + resp.error?.message)
4344
assert.ok(!resp.error)
4445
assert.match(
4546
resp.claim?.context || '',
@@ -66,7 +67,7 @@ describeWithServer('HTTP Provider', opts => {
6667
hash: 'oprf'
6768
}
6869
],
69-
paramValues:{ domain:'Example Domain' }
70+
paramValues: { domain: 'Example Domain' }
7071
},
7172
secretParams: {
7273
cookieStr: '<cookie-str>'

src/utils/http-parser.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,38 @@ import { findIndexInUint8Array, uint8ArrayToStr } from '#src/utils/generics.ts'
66
import { REDACTION_CHAR_CODE } from '#src/utils/redactions.ts'
77

88
export type HttpRequest = {
9-
method: string
10-
url: string
11-
protocol: string
12-
headers: IncomingHttpHeaders
13-
body?: Uint8Array
9+
method: string
10+
url: string
11+
protocol: string
12+
headers: IncomingHttpHeaders
13+
body?: Uint8Array
1414
}
1515

1616
export type HttpResponse = {
17-
statusCode: number
18-
statusMessage: string
19-
headers: IncomingHttpHeaders
20-
body: Uint8Array
21-
headersComplete: boolean
22-
complete: boolean
23-
24-
/**
25-
* Index of the first byte of the status line
26-
*/
27-
statusLineEndIndex?: number
28-
/**
29-
* Index of the first byte of the body
30-
* in the complete response
31-
*/
32-
bodyStartIndex?: number
33-
/**
34-
* If using chunked transfer encoding,
35-
* this will be set & contain indices of each
36-
* chunk in the complete response
37-
*/
38-
chunks?: ArraySlice[]
39-
40-
headerIndices: Map<string, ArraySlice>
17+
statusCode: number
18+
statusMessage: string
19+
headers: IncomingHttpHeaders
20+
body: Uint8Array
21+
headersComplete: boolean
22+
complete: boolean
23+
24+
/**
25+
* Index of the first byte of the status line
26+
*/
27+
statusLineEndIndex?: number
28+
/**
29+
* Index of the first byte of the body
30+
* in the complete response
31+
*/
32+
bodyStartIndex?: number
33+
/**
34+
* If using chunked transfer encoding,
35+
* this will be set & contain indices of each
36+
* chunk in the complete response
37+
*/
38+
chunks?: ArraySlice[]
39+
40+
headerIndices: Map<string, ArraySlice>
4141
/**
4242
* index of separator \r\n\r\n between headers and body
4343
*/
@@ -58,7 +58,7 @@ export function makeHttpResponseParser() {
5858
body: new Uint8Array(),
5959
complete: false,
6060
headersComplete: false,
61-
headerIndices: new Map<string, ArraySlice>(),
61+
headerIndices:new Map<string, ArraySlice>(),
6262
headerEndIdx: 0
6363
}
6464

@@ -70,9 +70,9 @@ export function makeHttpResponseParser() {
7070
return {
7171
res,
7272
/**
73-
* Parse the next chunk of data
74-
* @param data the data to parse
75-
*/
73+
* Parse the next chunk of data
74+
* @param data the data to parse
75+
*/
7676
onChunk(data: Uint8Array) {
7777
// concatenate the remaining data from the last chunk
7878
remaining = concatenateUint8Arrays([remaining, data])
@@ -110,8 +110,8 @@ export function makeHttpResponseParser() {
110110
const [key, value] = line.split(': ')
111111
res.headers[key.toLowerCase()] = value
112112
res.headerIndices[key.toLowerCase()] = {
113-
fromIndex: currentByteIdx - line.length - HTTP_HEADER_LINE_END.length,
114-
toIndex: currentByteIdx - HTTP_HEADER_LINE_END.length
113+
fromIndex:currentByteIdx - line.length - HTTP_HEADER_LINE_END.length,
114+
toIndex:currentByteIdx - HTTP_HEADER_LINE_END.length
115115
}
116116
} else {
117117
throw new Error('got more data after response was complete')
@@ -166,9 +166,9 @@ export function makeHttpResponseParser() {
166166
}
167167
},
168168
/**
169-
* Call to prevent further parsing; indicating the end of the request
170-
* Checks that the response is valid & complete, otherwise throws an error
171-
*/
169+
* Call to prevent further parsing; indicating the end of the request
170+
* Checks that the response is valid & complete, otherwise throws an error
171+
*/
172172
streamEnded() {
173173
if(!res.headersComplete) {
174174
throw new Error('stream ended before headers were complete')

0 commit comments

Comments
 (0)