univo 0.1.17 → 0.1.18

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.
package/dist/cli.mjs CHANGED
@@ -5,7 +5,7 @@ import { config } from 'dotenv';
5
5
  import { WebSocket } from 'partysocket';
6
6
  import { defineCommand, runMain } from 'citty';
7
7
  import { http } from './client.mjs';
8
- import { c as createLogger, e as version, l as name } from './shared/univo.2F7MFHxq.mjs';
8
+ import { c as createLogger, v as version, l as name } from './shared/univo.mtzSyY24.mjs';
9
9
 
10
10
  const log = createLogger({ quiet: false });
11
11
  const dev = defineCommand({
package/dist/client.mjs CHANGED
@@ -1,6 +1,5 @@
1
- import { a as createException, o as compress, f as getSignature, g as getException } from './shared/univo.2F7MFHxq.mjs';
1
+ import { b as createException, o as compress, j as raise, g as getException } from './shared/univo.mtzSyY24.mjs';
2
2
 
3
- const MIN_GZIP_SIZE = 1024;
4
3
  function http(url, opts = {}) {
5
4
  return {
6
5
  async request({ jsonrpc, id, method, params }) {
@@ -10,16 +9,9 @@ function http(url, opts = {}) {
10
9
  headers.set("Content-Type", "application/json");
11
10
  if (method.startsWith("private_")) {
12
11
  if (opts.signingKey === void 0) throw new Error(ClientUnauthorizedError);
13
- if (body.length > MIN_GZIP_SIZE) {
14
- body = await compress(body).catch((cause) => {
15
- throw new Error(ClientCompressionError, { cause });
16
- });
17
- headers.set("Content-Encoding", "gzip");
18
- }
19
- const signature = await getSignature({ key: opts.signingKey, body }).catch((cause) => {
20
- throw new Error(ClientSignatureError, { cause });
21
- });
22
- headers.set("X-Univo-Signature", signature);
12
+ headers.set("Authorization", `Bearer ${opts.signingKey}`);
13
+ body = await compress(body).catch((cause) => raise(ClientCompressionError, { cause }));
14
+ headers.set("Content-Encoding", "gzip");
23
15
  }
24
16
  const res = await fetch(url, { headers, body, method: "POST" }).catch((cause) => {
25
17
  throw new Error(ClientConnectionError, { cause });
@@ -37,7 +29,6 @@ function http(url, opts = {}) {
37
29
  const ClientCompressionError = createException("An error occurred when compressing the request");
38
30
  const ClientConnectionError = createException("An errored occurred when connecting to the server");
39
31
  const ClientResponseError = createException("An error occurred when reading the servers response");
40
- const ClientSignatureError = createException("An error occurred with the outgoing request signature");
41
32
  const ClientUnauthorizedError = createException("Attempted to execute a private method without providing a request signing key");
42
33
 
43
34
  export { http };
package/dist/index.d.mts CHANGED
@@ -49,7 +49,6 @@ type Head = {
49
49
  type Metadata = {
50
50
  version: string;
51
51
  language: string;
52
- max_concurrency: number | undefined;
53
52
  };
54
53
  type Result = {
55
54
  status: string;
@@ -69,10 +68,6 @@ type IndexerOptions<TBlock> = {
69
68
  * Request signing key
70
69
  */
71
70
  signingKey: string;
72
- /**
73
- * Maximum number of concurrent connections to open when backfilling blocks
74
- */
75
- maxConcurrency?: number;
76
71
  /**
77
72
  * This function is to load each block when indexing blocks in realtime. This ensures that all block
78
73
  * data processed originates from a trusted RPC source and can be safely relied on.
package/dist/index.d.ts CHANGED
@@ -49,7 +49,6 @@ type Head = {
49
49
  type Metadata = {
50
50
  version: string;
51
51
  language: string;
52
- max_concurrency: number | undefined;
53
52
  };
54
53
  type Result = {
55
54
  status: string;
@@ -69,10 +68,6 @@ type IndexerOptions<TBlock> = {
69
68
  * Request signing key
70
69
  */
71
70
  signingKey: string;
72
- /**
73
- * Maximum number of concurrent connections to open when backfilling blocks
74
- */
75
- maxConcurrency?: number;
76
71
  /**
77
72
  * This function is to load each block when indexing blocks in realtime. This ensures that all block
78
73
  * data processed originates from a trusted RPC source and can be safely relied on.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as createLogger, v as verifySignature, d as decompress, a as createException, g as getException, h as hexToNumber, i as isAddressEqual, b as catchException, r as retry, e as version, n as nonNullable, f as getSignature } from './shared/univo.2F7MFHxq.mjs';
1
+ import { c as createLogger, d as decompress, a as decoder, b as createException, g as getException, h as hexToNumber, i as isAddressEqual, e as catchException, r as retry, v as version, n as nonNullable, f as getSignature } from './shared/univo.mtzSyY24.mjs';
2
2
 
3
3
  function matchFilter(block, filter) {
4
4
  if (!chainValid(block, filter)) return false;
@@ -46,8 +46,7 @@ function indexer(opts) {
46
46
  const private_getMetadata = async () => {
47
47
  return {
48
48
  version,
49
- language: "javascript",
50
- max_concurrency: opts.maxConcurrency
49
+ language: "javascript"
51
50
  };
52
51
  };
53
52
  const private_getEvents = async () => {
@@ -448,24 +447,27 @@ function indexer(opts) {
448
447
  { status: 400 }
449
448
  );
450
449
  }
451
- let authenticated = false;
452
- const signature = req.headers.get("X-Univo-Signature");
453
- if (signature) {
454
- try {
455
- authenticated = await verifySignature({ key: opts.signingKey, body: body_buffer, signature });
456
- } catch {
450
+ const authorization = req.headers.get("Authorization");
451
+ const authenticated = authorization === `Bearer ${opts.signingKey}`;
452
+ let body_string;
453
+ if (req.headers.get("Content-Encoding") === "gzip") {
454
+ if (!authorization) {
457
455
  return Response.json(
458
- { jsonrpc: "2.0", id: null, error: { code: 0, message: "Failed to verify request signature" } },
456
+ { jsonrpc: "2.0", id: null, error: { code: 0, message: "No bearer token provided" } },
457
+ //
458
+ { status: 400 }
459
+ );
460
+ }
461
+ if (!authenticated) {
462
+ return Response.json(
463
+ { jsonrpc: "2.0", id: null, error: { code: 0, message: "Invalid bearer token" } },
459
464
  //
460
465
  { status: 400 }
461
466
  );
462
467
  }
463
- }
464
- let body_string;
465
- if (req.headers.get("Content-Encoding") === "gzip") {
466
468
  body_string = await decompress(body_buffer);
467
469
  } else {
468
- body_string = new TextDecoder().decode(body_buffer);
470
+ body_string = decoder.decode(body_buffer);
469
471
  }
470
472
  let json;
471
473
  try {
@@ -478,16 +480,16 @@ function indexer(opts) {
478
480
  );
479
481
  }
480
482
  if (json.method.startsWith("private_")) {
481
- if (!signature) {
483
+ if (!authorization) {
482
484
  return Response.json(
483
- { jsonrpc: "2.0", id: json.id, error: { code: 0, message: "No request signature provided" } },
485
+ { jsonrpc: "2.0", id: json.id, error: { code: 0, message: "No bearer token provided" } },
484
486
  //
485
487
  { status: 400 }
486
488
  );
487
489
  }
488
- if (!authenticated) {
490
+ if (authorization !== `Bearer ${opts.signingKey}`) {
489
491
  return Response.json(
490
- { jsonrpc: "2.0", id: json.id, error: { code: 0, message: "Invalid request signature" } },
492
+ { jsonrpc: "2.0", id: json.id, error: { code: 0, message: "Invalid bearer token" } },
491
493
  //
492
494
  { status: 400 }
493
495
  );
package/dist/realtime.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import WS from 'ws';
2
2
  import { WebSocket } from 'partysocket';
3
3
  import { http } from './client.mjs';
4
- import { c as createLogger, r as retry, h as hexToNumber, j as raise, m as mutex, k as assert } from './shared/univo.2F7MFHxq.mjs';
4
+ import { c as createLogger, r as retry, h as hexToNumber, j as raise, m as mutex, k as assert } from './shared/univo.mtzSyY24.mjs';
5
5
 
6
6
  function createSocket(url, opts) {
7
7
  const ws = new WebSocket(url, [], { WebSocket: WS });
@@ -1,5 +1,5 @@
1
1
  const name = "univo";
2
- const version = "0.1.17";
2
+ const version = "0.1.18";
3
3
 
4
4
  function createException(message) {
5
5
  return `univo:${message}`;
@@ -63,19 +63,6 @@ async function getSignature(opts) {
63
63
  const hmac = await crypto.subtle.sign("HMAC", key, opts.body);
64
64
  return [...new Uint8Array(hmac)].map((binary) => binary.toString(16).padStart(2, "0")).join("");
65
65
  }
66
- async function verifySignature(opts) {
67
- const keyData = encoder.encode(opts.key);
68
- const key = await crypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: "SHA-256" }, false, ["verify"]);
69
- const pairs = opts.signature.match(/[\da-f]{2}/gi);
70
- if (!pairs) return false;
71
- if (typeof opts.body === "string") {
72
- const dataToAuthenticate = encoder.encode(opts.body);
73
- const hmac2 = new Uint8Array(pairs.map((byte) => Number.parseInt(byte, 16))).buffer;
74
- return await crypto.subtle.verify("HMAC", key, hmac2, dataToAuthenticate);
75
- }
76
- const hmac = new Uint8Array(pairs.map((byte) => Number.parseInt(byte, 16))).buffer;
77
- return await crypto.subtle.verify("HMAC", key, hmac, opts.body);
78
- }
79
66
  function hexToNumber(hex) {
80
67
  return Number.parseInt(hex, 16);
81
68
  }
@@ -115,5 +102,6 @@ async function decompress(input) {
115
102
  const decompressed = new Blob([input]).stream().pipeThrough(new DecompressionStream("gzip"));
116
103
  return new Response(decompressed).text();
117
104
  }
105
+ const decoder = new TextDecoder();
118
106
 
119
- export { createException as a, catchException as b, createLogger as c, decompress as d, version as e, getSignature as f, getException as g, hexToNumber as h, isAddressEqual as i, raise as j, assert as k, name as l, mutex as m, nonNullable as n, compress as o, retry as r, verifySignature as v };
107
+ export { decoder as a, createException as b, createLogger as c, decompress as d, catchException as e, getSignature as f, getException as g, hexToNumber as h, isAddressEqual as i, raise as j, assert as k, name as l, mutex as m, nonNullable as n, compress as o, retry as r, version as v };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "univo",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "0.1.17",
5
+ "version": "0.1.18",
6
6
  "sideEffects": false,
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",