@reclaimprotocol/attestor-core 5.1.1 → 5.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8807,13 +8807,14 @@ function parseHttpResponse(buff) {
8807
8807
  var RE2;
8808
8808
  import("re2").then((m) => {
8809
8809
  RE2 = m.default;
8810
- }).catch(() => {
8810
+ }).catch((err) => {
8811
+ logger.warn({ err }, "Failed to load RE2; falling back to native RegExp");
8811
8812
  });
8812
8813
  function makeRegex(str) {
8813
8814
  if (RE2) {
8814
8815
  return RE2(str, "sgiu");
8815
8816
  }
8816
- return new RegExp(str, "sgiu");
8817
+ return new RegExp(str, "sgi");
8817
8818
  }
8818
8819
  var TEMPLATE_START_CHARCODE = "{".charCodeAt(0);
8819
8820
  var TEMPLATE_END_CHARCODE = "}".charCodeAt(0);
@@ -9038,6 +9039,9 @@ var HTTP_PROVIDER = {
9038
9039
  if (res.headerIndices["date"]) {
9039
9040
  reveals.push(res.headerIndices["date"]);
9040
9041
  }
9042
+ if (res.headerIndices["content-type"]) {
9043
+ reveals.push(res.headerIndices["content-type"]);
9044
+ }
9041
9045
  if (revealFraming && res.headerIndices["transfer-encoding"]) {
9042
9046
  reveals.push(res.headerIndices["transfer-encoding"]);
9043
9047
  }
@@ -9129,36 +9133,53 @@ var HTTP_PROVIDER = {
9129
9133
  const firstRealIdx = allServerBlocks.findIndex((b) => !b.every((x) => x === REDACTION_CHAR_CODE2));
9130
9134
  const serverBlocks = firstRealIdx === -1 ? [] : allServerBlocks.slice(firstRealIdx);
9131
9135
  const response = concatArrays(...serverBlocks);
9132
- let res;
9133
- res = uint8ArrayToStr(response);
9136
+ let bodyStart;
9137
+ if (shouldRevealCrlf(ctx)) {
9138
+ const responseAfterStatus = response.slice(OK_HTTP_HEADER.length);
9139
+ const separatorIdx = findIndexInUint8Array(
9140
+ responseAfterStatus,
9141
+ strToUint8Array("\r\n\r\n")
9142
+ );
9143
+ if (separatorIdx === -1) {
9144
+ throw new Error("Response body start not found");
9145
+ }
9146
+ bodyStart = OK_HTTP_HEADER.length + separatorIdx + 4;
9147
+ } else {
9148
+ bodyStart = OK_HTTP_HEADER.length;
9149
+ }
9150
+ const headersText = uint8ArrayToStr(response.slice(0, bodyStart));
9134
9151
  const okRegex = makeRegex("^HTTP\\/1.1 2\\d{2}");
9135
- const matchRes = okRegex.exec(res);
9152
+ const matchRes = okRegex.exec(headersText);
9136
9153
  if (!matchRes) {
9137
9154
  const statusRegex = makeRegex("^HTTP\\/1.1 (\\d{3})");
9138
- const matchRes2 = statusRegex.exec(res);
9155
+ const matchRes2 = statusRegex.exec(headersText);
9139
9156
  if (matchRes2 && matchRes2.length > 1) {
9140
9157
  throw new Error(`Provider returned error ${matchRes2[1]}`);
9141
9158
  }
9142
- let lineEnd = res.indexOf("*");
9159
+ let lineEnd = headersText.indexOf("*");
9143
9160
  if (lineEnd === -1) {
9144
- lineEnd = res.indexOf("\n");
9161
+ lineEnd = headersText.indexOf("\n");
9145
9162
  }
9146
9163
  if (lineEnd === -1) {
9147
9164
  lineEnd = OK_HTTP_HEADER.length;
9148
9165
  }
9149
9166
  throw new Error(
9150
- `Response did not start with "HTTP/1.1 2XX" got "${res.slice(0, lineEnd)}"`
9167
+ `Response did not start with "HTTP/1.1 2XX" got "${headersText.slice(0, lineEnd)}"`
9151
9168
  );
9152
9169
  }
9153
- let bodyStart;
9154
- if (shouldRevealCrlf(ctx)) {
9155
- bodyStart = res.indexOf("\r\n\r\n", OK_HTTP_HEADER.length) + 4;
9156
- if (bodyStart < 4) {
9157
- throw new Error("Response body start not found");
9170
+ const paramBody = params.body instanceof Uint8Array ? params.body : strToUint8Array(params.body || "");
9171
+ if (paramBody.length > 0 && !matchRedactedStrings(paramBody, req.body)) {
9172
+ throw new Error("request body mismatch");
9173
+ }
9174
+ let body = response.slice(bodyStart);
9175
+ if (shouldRevealChunkFraming(clientVersion)) {
9176
+ if (/transfer-encoding:\s*chunked/i.test(headersText)) {
9177
+ body = dechunkResponseBody(body);
9158
9178
  }
9159
- } else {
9160
- bodyStart = OK_HTTP_HEADER.length;
9161
9179
  }
9180
+ const charset = shouldRevealCrlf(ctx) ? getResponseBodyCharset(headersText) : void 0;
9181
+ const bodyText = decodeResponseBody(body, charset);
9182
+ let res = headersText + bodyText;
9162
9183
  const dateHeader = makeRegex(dateHeaderRegex).exec(res);
9163
9184
  if (dateHeader && dateHeader.length > 1) {
9164
9185
  const serverDate = new Date(dateHeader[1]);
@@ -9166,14 +9187,7 @@ var HTTP_PROVIDER = {
9166
9187
  logger2.info({ dateHeader: dateHeader[0], current: Date.now() }, "date header is off");
9167
9188
  }
9168
9189
  }
9169
- const paramBody = params.body instanceof Uint8Array ? params.body : strToUint8Array(params.body || "");
9170
- if (paramBody.length > 0 && !matchRedactedStrings(paramBody, req.body)) {
9171
- throw new Error("request body mismatch");
9172
- }
9173
- if (shouldRevealChunkFraming(clientVersion)) {
9174
- const headersStr = res.slice(0, bodyStart);
9175
- res = /transfer-encoding:\s*chunked/i.test(headersStr) ? headersStr + dechunkResponseBody(res.slice(bodyStart)) : res;
9176
- } else if (!secretParams) {
9190
+ if (!shouldRevealChunkFraming(clientVersion) && !secretParams) {
9177
9191
  res = res.slice(bodyStart).replace(/\*{3,}/g, "");
9178
9192
  }
9179
9193
  for (const { type, value, invert } of params.responseMatches || []) {
@@ -9264,12 +9278,35 @@ function shouldRevealCrlf({ version }) {
9264
9278
  function shouldRevealChunkFraming(version) {
9265
9279
  return version >= AttestorVersion.ATTESTOR_VERSION_3_2_0;
9266
9280
  }
9281
+ function getResponseBodyCharset(headers) {
9282
+ const contentType = /(?:^|[\r\n*])content-type\s*:\s*([^*\r\n]*)/i.exec(headers)?.[1];
9283
+ if (typeof contentType === "undefined") {
9284
+ return void 0;
9285
+ }
9286
+ const charsetMatch = /(?:^|;)\s*charset\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^;\s]*))/i.exec(contentType);
9287
+ if (!charsetMatch) {
9288
+ return void 0;
9289
+ }
9290
+ const charset = charsetMatch[1]?.replace(/\\(.)/g, "$1") ?? charsetMatch[2];
9291
+ return charset.trim() || void 0;
9292
+ }
9293
+ function decodeResponseBody(body, charset) {
9294
+ try {
9295
+ return new TextDecoder(charset ?? "utf-8").decode(body);
9296
+ } catch (error) {
9297
+ if (charset) {
9298
+ throw new Error(`Unsupported response charset "${charset}"`, { cause: error });
9299
+ }
9300
+ throw error;
9301
+ }
9302
+ }
9267
9303
  function dechunkResponseBody(body) {
9268
9304
  const parser = makeHttpResponseParser();
9269
- parser.onChunk(
9270
- strToUint8Array("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n" + body)
9271
- );
9272
- return uint8ArrayToStr(parser.res.body ?? new Uint8Array());
9305
+ parser.onChunk(concatenateUint8Arrays7([
9306
+ strToUint8Array("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"),
9307
+ body
9308
+ ]));
9309
+ return parser.res.body ?? new Uint8Array();
9273
9310
  }
9274
9311
  function getHostPort(params, secretParams) {
9275
9312
  const { host } = new URL(getURL(params, secretParams));
@@ -9955,6 +9992,7 @@ async function _createClaimOnAttestor({
9955
9992
  block,
9956
9993
  redactedPlaintext,
9957
9994
  overshotToprfFromPrevBlock,
9995
+ overshotOprfRawFromPrevBlock,
9958
9996
  toprfs,
9959
9997
  oprfRawMarkers
9960
9998
  } = reveal;
@@ -9963,7 +10001,8 @@ async function _createClaimOnAttestor({
9963
10001
  redactedPlaintext,
9964
10002
  toprfs,
9965
10003
  oprfRawMarkers,
9966
- overshotToprfFromPrevBlock
10004
+ overshotToprfFromPrevBlock,
10005
+ overshotOprfRawFromPrevBlock
9967
10006
  });
9968
10007
  revealedPackets.push(
9969
10008
  { sender: "server", message: redactedPlaintext }
package/lib/index.js CHANGED
@@ -7124,13 +7124,14 @@ function parseHttpResponse(buff) {
7124
7124
  var RE2;
7125
7125
  import("re2").then((m) => {
7126
7126
  RE2 = m.default;
7127
- }).catch(() => {
7127
+ }).catch((err) => {
7128
+ logger.warn({ err }, "Failed to load RE2; falling back to native RegExp");
7128
7129
  });
7129
7130
  function makeRegex(str) {
7130
7131
  if (RE2) {
7131
7132
  return RE2(str, "sgiu");
7132
7133
  }
7133
- return new RegExp(str, "sgiu");
7134
+ return new RegExp(str, "sgi");
7134
7135
  }
7135
7136
  var TEMPLATE_START_CHARCODE = "{".charCodeAt(0);
7136
7137
  var TEMPLATE_END_CHARCODE = "}".charCodeAt(0);
@@ -7336,6 +7337,9 @@ var HTTP_PROVIDER = {
7336
7337
  if (res.headerIndices["date"]) {
7337
7338
  reveals.push(res.headerIndices["date"]);
7338
7339
  }
7340
+ if (res.headerIndices["content-type"]) {
7341
+ reveals.push(res.headerIndices["content-type"]);
7342
+ }
7339
7343
  if (revealFraming && res.headerIndices["transfer-encoding"]) {
7340
7344
  reveals.push(res.headerIndices["transfer-encoding"]);
7341
7345
  }
@@ -7427,36 +7431,53 @@ var HTTP_PROVIDER = {
7427
7431
  const firstRealIdx = allServerBlocks.findIndex((b) => !b.every((x) => x === REDACTION_CHAR_CODE2));
7428
7432
  const serverBlocks = firstRealIdx === -1 ? [] : allServerBlocks.slice(firstRealIdx);
7429
7433
  const response = concatArrays(...serverBlocks);
7430
- let res;
7431
- res = uint8ArrayToStr(response);
7434
+ let bodyStart;
7435
+ if (shouldRevealCrlf(ctx)) {
7436
+ const responseAfterStatus = response.slice(OK_HTTP_HEADER.length);
7437
+ const separatorIdx = findIndexInUint8Array(
7438
+ responseAfterStatus,
7439
+ strToUint8Array("\r\n\r\n")
7440
+ );
7441
+ if (separatorIdx === -1) {
7442
+ throw new Error("Response body start not found");
7443
+ }
7444
+ bodyStart = OK_HTTP_HEADER.length + separatorIdx + 4;
7445
+ } else {
7446
+ bodyStart = OK_HTTP_HEADER.length;
7447
+ }
7448
+ const headersText = uint8ArrayToStr(response.slice(0, bodyStart));
7432
7449
  const okRegex = makeRegex("^HTTP\\/1.1 2\\d{2}");
7433
- const matchRes = okRegex.exec(res);
7450
+ const matchRes = okRegex.exec(headersText);
7434
7451
  if (!matchRes) {
7435
7452
  const statusRegex = makeRegex("^HTTP\\/1.1 (\\d{3})");
7436
- const matchRes2 = statusRegex.exec(res);
7453
+ const matchRes2 = statusRegex.exec(headersText);
7437
7454
  if (matchRes2 && matchRes2.length > 1) {
7438
7455
  throw new Error(`Provider returned error ${matchRes2[1]}`);
7439
7456
  }
7440
- let lineEnd = res.indexOf("*");
7457
+ let lineEnd = headersText.indexOf("*");
7441
7458
  if (lineEnd === -1) {
7442
- lineEnd = res.indexOf("\n");
7459
+ lineEnd = headersText.indexOf("\n");
7443
7460
  }
7444
7461
  if (lineEnd === -1) {
7445
7462
  lineEnd = OK_HTTP_HEADER.length;
7446
7463
  }
7447
7464
  throw new Error(
7448
- `Response did not start with "HTTP/1.1 2XX" got "${res.slice(0, lineEnd)}"`
7465
+ `Response did not start with "HTTP/1.1 2XX" got "${headersText.slice(0, lineEnd)}"`
7449
7466
  );
7450
7467
  }
7451
- let bodyStart;
7452
- if (shouldRevealCrlf(ctx)) {
7453
- bodyStart = res.indexOf("\r\n\r\n", OK_HTTP_HEADER.length) + 4;
7454
- if (bodyStart < 4) {
7455
- throw new Error("Response body start not found");
7468
+ const paramBody = params.body instanceof Uint8Array ? params.body : strToUint8Array(params.body || "");
7469
+ if (paramBody.length > 0 && !matchRedactedStrings(paramBody, req.body)) {
7470
+ throw new Error("request body mismatch");
7471
+ }
7472
+ let body = response.slice(bodyStart);
7473
+ if (shouldRevealChunkFraming(clientVersion)) {
7474
+ if (/transfer-encoding:\s*chunked/i.test(headersText)) {
7475
+ body = dechunkResponseBody(body);
7456
7476
  }
7457
- } else {
7458
- bodyStart = OK_HTTP_HEADER.length;
7459
7477
  }
7478
+ const charset = shouldRevealCrlf(ctx) ? getResponseBodyCharset(headersText) : void 0;
7479
+ const bodyText = decodeResponseBody(body, charset);
7480
+ let res = headersText + bodyText;
7460
7481
  const dateHeader = makeRegex(dateHeaderRegex).exec(res);
7461
7482
  if (dateHeader && dateHeader.length > 1) {
7462
7483
  const serverDate = new Date(dateHeader[1]);
@@ -7464,14 +7485,7 @@ var HTTP_PROVIDER = {
7464
7485
  logger2.info({ dateHeader: dateHeader[0], current: Date.now() }, "date header is off");
7465
7486
  }
7466
7487
  }
7467
- const paramBody = params.body instanceof Uint8Array ? params.body : strToUint8Array(params.body || "");
7468
- if (paramBody.length > 0 && !matchRedactedStrings(paramBody, req.body)) {
7469
- throw new Error("request body mismatch");
7470
- }
7471
- if (shouldRevealChunkFraming(clientVersion)) {
7472
- const headersStr = res.slice(0, bodyStart);
7473
- res = /transfer-encoding:\s*chunked/i.test(headersStr) ? headersStr + dechunkResponseBody(res.slice(bodyStart)) : res;
7474
- } else if (!secretParams) {
7488
+ if (!shouldRevealChunkFraming(clientVersion) && !secretParams) {
7475
7489
  res = res.slice(bodyStart).replace(/\*{3,}/g, "");
7476
7490
  }
7477
7491
  for (const { type, value, invert } of params.responseMatches || []) {
@@ -7562,12 +7576,35 @@ function shouldRevealCrlf({ version }) {
7562
7576
  function shouldRevealChunkFraming(version) {
7563
7577
  return version >= AttestorVersion.ATTESTOR_VERSION_3_2_0;
7564
7578
  }
7579
+ function getResponseBodyCharset(headers) {
7580
+ const contentType = /(?:^|[\r\n*])content-type\s*:\s*([^*\r\n]*)/i.exec(headers)?.[1];
7581
+ if (typeof contentType === "undefined") {
7582
+ return void 0;
7583
+ }
7584
+ const charsetMatch = /(?:^|;)\s*charset\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^;\s]*))/i.exec(contentType);
7585
+ if (!charsetMatch) {
7586
+ return void 0;
7587
+ }
7588
+ const charset = charsetMatch[1]?.replace(/\\(.)/g, "$1") ?? charsetMatch[2];
7589
+ return charset.trim() || void 0;
7590
+ }
7591
+ function decodeResponseBody(body, charset) {
7592
+ try {
7593
+ return new TextDecoder(charset ?? "utf-8").decode(body);
7594
+ } catch (error) {
7595
+ if (charset) {
7596
+ throw new Error(`Unsupported response charset "${charset}"`, { cause: error });
7597
+ }
7598
+ throw error;
7599
+ }
7600
+ }
7565
7601
  function dechunkResponseBody(body) {
7566
7602
  const parser = makeHttpResponseParser();
7567
- parser.onChunk(
7568
- strToUint8Array("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n" + body)
7569
- );
7570
- return uint8ArrayToStr(parser.res.body ?? new Uint8Array());
7603
+ parser.onChunk(concatenateUint8Arrays6([
7604
+ strToUint8Array("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"),
7605
+ body
7606
+ ]));
7607
+ return parser.res.body ?? new Uint8Array();
7571
7608
  }
7572
7609
  function getHostPort(params, secretParams) {
7573
7610
  const { host } = new URL(getURL(params, secretParams));
@@ -8454,6 +8491,7 @@ async function _createClaimOnAttestor({
8454
8491
  block,
8455
8492
  redactedPlaintext,
8456
8493
  overshotToprfFromPrevBlock,
8494
+ overshotOprfRawFromPrevBlock,
8457
8495
  toprfs,
8458
8496
  oprfRawMarkers
8459
8497
  } = reveal;
@@ -8462,7 +8500,8 @@ async function _createClaimOnAttestor({
8462
8500
  redactedPlaintext,
8463
8501
  toprfs,
8464
8502
  oprfRawMarkers,
8465
- overshotToprfFromPrevBlock
8503
+ overshotToprfFromPrevBlock,
8504
+ overshotOprfRawFromPrevBlock
8466
8505
  });
8467
8506
  revealedPackets.push(
8468
8507
  { sender: "server", message: redactedPlaintext }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reclaimprotocol/attestor-core",
3
- "version": "5.1.1",
3
+ "version": "5.1.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "imports": {