univo 0.1.16 → 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 +1 -1
- package/dist/client.mjs +4 -13
- package/dist/index.d.mts +0 -5
- package/dist/index.d.ts +0 -5
- package/dist/index.mjs +21 -19
- package/dist/realtime.mjs +1 -1
- package/dist/shared/{univo.C9TrncJq.mjs → univo.mtzSyY24.mjs} +7 -54
- package/package.json +1 -1
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,
|
|
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 {
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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,
|
|
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 () => {
|
|
@@ -440,7 +439,7 @@ function indexer(opts) {
|
|
|
440
439
|
const handler = async (req) => {
|
|
441
440
|
let body_buffer;
|
|
442
441
|
try {
|
|
443
|
-
body_buffer =
|
|
442
|
+
body_buffer = await req.arrayBuffer();
|
|
444
443
|
} catch {
|
|
445
444
|
return Response.json(
|
|
446
445
|
{ jsonrpc: "2.0", id: null, error: { code: 0, message: "Invalid request body" } },
|
|
@@ -448,24 +447,27 @@ function indexer(opts) {
|
|
|
448
447
|
{ status: 400 }
|
|
449
448
|
);
|
|
450
449
|
}
|
|
451
|
-
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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: "
|
|
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 =
|
|
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 (!
|
|
483
|
+
if (!authorization) {
|
|
482
484
|
return Response.json(
|
|
483
|
-
{ jsonrpc: "2.0", id: json.id, error: { code: 0, message: "No
|
|
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 (
|
|
490
|
+
if (authorization !== `Bearer ${opts.signingKey}`) {
|
|
489
491
|
return Response.json(
|
|
490
|
-
{ jsonrpc: "2.0", id: json.id, error: { code: 0, message: "Invalid
|
|
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.
|
|
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.
|
|
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
|
}
|
|
@@ -108,47 +95,13 @@ function nonNullable(value) {
|
|
|
108
95
|
return value !== null && value !== void 0;
|
|
109
96
|
}
|
|
110
97
|
async function compress(input) {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
const writer = stream.writable.getWriter();
|
|
114
|
-
writer.write(encoded);
|
|
115
|
-
writer.close();
|
|
116
|
-
const chunks = [];
|
|
117
|
-
const reader = stream.readable.getReader();
|
|
118
|
-
while (true) {
|
|
119
|
-
const { done, value } = await reader.read();
|
|
120
|
-
if (done) break;
|
|
121
|
-
chunks.push(value);
|
|
122
|
-
}
|
|
123
|
-
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
124
|
-
const result = new Uint8Array(totalLength);
|
|
125
|
-
let offset = 0;
|
|
126
|
-
for (const chunk of chunks) {
|
|
127
|
-
result.set(chunk, offset);
|
|
128
|
-
offset += chunk.length;
|
|
129
|
-
}
|
|
130
|
-
return result;
|
|
98
|
+
const compressed = new Blob([input]).stream().pipeThrough(new CompressionStream("gzip"));
|
|
99
|
+
return new Response(compressed).arrayBuffer();
|
|
131
100
|
}
|
|
132
101
|
async function decompress(input) {
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
writer.write(input);
|
|
136
|
-
writer.close();
|
|
137
|
-
const chunks = [];
|
|
138
|
-
const reader = stream.readable.getReader();
|
|
139
|
-
while (true) {
|
|
140
|
-
const { done, value } = await reader.read();
|
|
141
|
-
if (done) break;
|
|
142
|
-
chunks.push(value);
|
|
143
|
-
}
|
|
144
|
-
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
145
|
-
const result = new Uint8Array(totalLength);
|
|
146
|
-
let offset = 0;
|
|
147
|
-
for (const chunk of chunks) {
|
|
148
|
-
result.set(chunk, offset);
|
|
149
|
-
offset += chunk.length;
|
|
150
|
-
}
|
|
151
|
-
return new TextDecoder().decode(result);
|
|
102
|
+
const decompressed = new Blob([input]).stream().pipeThrough(new DecompressionStream("gzip"));
|
|
103
|
+
return new Response(decompressed).text();
|
|
152
104
|
}
|
|
105
|
+
const decoder = new TextDecoder();
|
|
153
106
|
|
|
154
|
-
export {
|
|
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 };
|