@forgezero/providers 0.1.36 → 0.1.38
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/billing.js +1 -1
- package/dist/database.js +1 -1
- package/dist/email.js +1 -1
- package/dist/git.js +1 -1
- package/dist/http.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/pool.js +1 -1
- package/dist/realtime.d.ts +6 -8
- package/dist/realtime.js +15 -10
- package/dist/storage.js +1 -1
- package/dist/translation.js +1 -1
- package/package.json +2 -2
package/dist/billing.js
CHANGED
package/dist/database.js
CHANGED
package/dist/email.js
CHANGED
package/dist/git.js
CHANGED
package/dist/http.js
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/pool.js
CHANGED
package/dist/realtime.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { type RealtimeBatch } from '@forgezero/runtime/realtime';
|
|
1
|
+
import { type RealtimeBatch, type RealtimePublishResponse } from '@forgezero/runtime/realtime';
|
|
2
2
|
import { type NodeKeyPair } from '@forgezero/runtime/identity';
|
|
3
3
|
export interface RealtimeProviderOptions {
|
|
4
4
|
endpoint: string;
|
|
5
|
-
/**
|
|
6
|
-
secret
|
|
7
|
-
identity
|
|
5
|
+
/** Worker inbound credential. Required in addition to the hybrid proof. */
|
|
6
|
+
secret: string;
|
|
7
|
+
/** Ed25519 + ML-DSA producer identity. Both signatures are mandatory. */
|
|
8
|
+
identity: Readonly<{
|
|
8
9
|
nodeKey: string;
|
|
9
10
|
keys: NodeKeyPair;
|
|
10
11
|
}>;
|
|
@@ -18,8 +19,5 @@ export declare class RealtimeProviderError extends Error {
|
|
|
18
19
|
}
|
|
19
20
|
/** One external request per batch; Worker/DO bindings own the internal fan-out. */
|
|
20
21
|
export declare function cloudflareRealtime(options: RealtimeProviderOptions): {
|
|
21
|
-
publish(input: RealtimeBatch): Promise<
|
|
22
|
-
delivered: number;
|
|
23
|
-
shards: number;
|
|
24
|
-
}>;
|
|
22
|
+
publish(input: RealtimeBatch): Promise<RealtimePublishResponse>;
|
|
25
23
|
};
|
package/dist/realtime.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// src/realtime.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
realtimeBatchBytes,
|
|
4
|
+
realtimeHmac,
|
|
5
|
+
realtimePublishMessage,
|
|
6
|
+
validateRealtimeBatch,
|
|
7
|
+
validateRealtimePublishResponse
|
|
8
|
+
} from "@forgezero/runtime/realtime";
|
|
3
9
|
import { encodeSignatureHeader, signRequest } from "@forgezero/runtime/identity";
|
|
4
10
|
|
|
5
11
|
class RealtimeProviderError extends Error {
|
|
@@ -13,7 +19,7 @@ class RealtimeProviderError extends Error {
|
|
|
13
19
|
var producerPattern = /^[A-Za-z0-9][A-Za-z0-9_.:@/-]{0,127}$/;
|
|
14
20
|
function cloudflareRealtime(options) {
|
|
15
21
|
const endpoint = new URL(options.endpoint);
|
|
16
|
-
if (endpoint.protocol !== "https:" || endpoint.username || endpoint.password || endpoint.search || endpoint.hash || !producerPattern.test(options.producer) ||
|
|
22
|
+
if (endpoint.protocol !== "https:" || endpoint.username || endpoint.password || endpoint.search || endpoint.hash || !producerPattern.test(options.producer) || new TextEncoder().encode(options.secret).byteLength < 32 || options.identity.nodeKey !== options.producer) {
|
|
17
23
|
throw new RealtimeProviderError("INVALID_CONFIG", "Realtime endpoint, producer, or secret is invalid.");
|
|
18
24
|
}
|
|
19
25
|
endpoint.pathname = "/__fz/realtime/publish";
|
|
@@ -27,10 +33,8 @@ function cloudflareRealtime(options) {
|
|
|
27
33
|
const batch = validateRealtimeBatch(input);
|
|
28
34
|
const body = realtimeBatchBytes(batch);
|
|
29
35
|
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
${timestamp}
|
|
33
|
-
${body}`);
|
|
36
|
+
const proof = encodeSignatureHeader(signRequest(options.identity.keys, options.identity.nodeKey, { method: "POST", path: endpoint.pathname, query: "", body }));
|
|
37
|
+
const signature = await realtimeHmac(options.secret, realtimePublishMessage(options.producer, timestamp, body));
|
|
34
38
|
let response;
|
|
35
39
|
try {
|
|
36
40
|
response = await fetcher(endpoint, {
|
|
@@ -43,7 +47,8 @@ ${body}`);
|
|
|
43
47
|
"x-fz-realtime-producer": options.producer,
|
|
44
48
|
"x-fz-realtime-timestamp": timestamp,
|
|
45
49
|
"x-fz-realtime-signature": signature,
|
|
46
|
-
|
|
50
|
+
"x-fz-realtime-proof": proof,
|
|
51
|
+
"x-fz-node-key": options.identity.nodeKey,
|
|
47
52
|
"idempotency-key": batch.batchId
|
|
48
53
|
}
|
|
49
54
|
});
|
|
@@ -54,11 +59,11 @@ ${body}`);
|
|
|
54
59
|
await response.body?.cancel();
|
|
55
60
|
throw new RealtimeProviderError(response.status >= 500 ? "UNAVAILABLE" : "REFUSED", `Realtime edge returned HTTP ${response.status}.`);
|
|
56
61
|
}
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
try {
|
|
63
|
+
return validateRealtimePublishResponse(await response.json());
|
|
64
|
+
} catch {
|
|
59
65
|
throw new RealtimeProviderError("UNAVAILABLE", "Realtime edge returned malformed evidence.");
|
|
60
66
|
}
|
|
61
|
-
return { delivered: result.delivered, shards: result.shards };
|
|
62
67
|
}
|
|
63
68
|
};
|
|
64
69
|
}
|
package/dist/storage.js
CHANGED
package/dist/translation.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forgezero/providers",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"LICENSE"
|
|
86
86
|
],
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@forgezero/runtime": "^0.1.
|
|
88
|
+
"@forgezero/runtime": "^0.1.29",
|
|
89
89
|
"@noble/curves": "2.2.0",
|
|
90
90
|
"@noble/hashes": "2.2.0",
|
|
91
91
|
"@noble/post-quantum": "0.6.1"
|