@verify-network/protocol 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +147 -2
- package/dist/domain-CXJsoNRU.d.ts +9 -0
- package/dist/ecvrf.d.ts +69 -0
- package/dist/ecvrf.js +174 -0
- package/dist/event.d.ts +101 -0
- package/dist/event.js +53 -0
- package/dist/fee.d.ts +142 -0
- package/dist/fee.js +142 -0
- package/dist/fulfillment.d.ts +32 -0
- package/dist/fulfillment.js +28 -0
- package/dist/index.d.ts +708 -0
- package/dist/index.js +872 -0
- package/dist/request.d.ts +60 -0
- package/dist/request.js +61 -0
- package/package.json +56 -4
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { t as RouterDomain } from "./domain-CXJsoNRU.js";
|
|
2
|
+
import { Address, Hex } from "viem";
|
|
3
|
+
//#region src/request.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A request as the router assigns it. Nothing about it is stored; the fields are
|
|
6
|
+
* hashed into the request id, emitted, and echoed back by the fulfiller (ADR 0001).
|
|
7
|
+
* Widths follow viem: up to 48 bits are a `number`, wider a `bigint`, so a decoded
|
|
8
|
+
* request is passed to a typed ABI call unchanged. `schemas.ts` holds its schema.
|
|
9
|
+
*/
|
|
10
|
+
export type Request = {
|
|
11
|
+
readonly consumer: Address;
|
|
12
|
+
readonly sequence: bigint;
|
|
13
|
+
readonly fulfiller: Address;
|
|
14
|
+
readonly assignedAt: number;
|
|
15
|
+
/** What the request reserved, and the most its fulfillment can ever charge. */
|
|
16
|
+
readonly fee: bigint;
|
|
17
|
+
/** The gas price the reservation was priced at. Settlement charges at this locked price. */
|
|
18
|
+
readonly gasPrice: bigint;
|
|
19
|
+
readonly callbackGasLimit: number;
|
|
20
|
+
readonly callbackData: Hex;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* `Config.STALE_DELAY`, in seconds: how long after its assignment a request may be reported
|
|
24
|
+
* stale (ADR 0024), and from when a fulfillment of it is settled without the premium (ADR 0025),
|
|
25
|
+
* which decays in a straight line over it (ADR 0029).
|
|
26
|
+
*/
|
|
27
|
+
export declare const STALE_DELAY = 30;
|
|
28
|
+
/**
|
|
29
|
+
* `Config.MAX_CALLBACK_DATA_BYTES`: the most callback data a request may carry (ADR 0023). A
|
|
30
|
+
* fulfillment echoes it, so it decides how many share one transaction under the enclave's calldata
|
|
31
|
+
* bound, and so how fast a node at capacity lands them against the stale delay.
|
|
32
|
+
*/
|
|
33
|
+
export declare const MAX_CALLBACK_DATA_BYTES = 16384;
|
|
34
|
+
/** Mirrors `Vrf.staleAt`: the first second the request is reportable as stale. */
|
|
35
|
+
export declare const staleAt: (assignedAt: bigint | number) => bigint;
|
|
36
|
+
/**
|
|
37
|
+
* Mirrors `Vrf.isLate`: whether the stale delay since the assignment has elapsed at `at`, the
|
|
38
|
+
* router's `block.timestamp`. The one predicate the stale report and the settlement share, so the
|
|
39
|
+
* first second a report is taken is the first second a fulfillment's premium has decayed to nothing.
|
|
40
|
+
*/
|
|
41
|
+
export declare const isLate: ({ assignedAt, at }: {
|
|
42
|
+
readonly assignedAt: bigint | number;
|
|
43
|
+
readonly at: bigint | number;
|
|
44
|
+
}) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Mirrors `Vrf.remainingDelay`: the seconds of the stale delay the request has left at `at`, the
|
|
47
|
+
* router's `block.timestamp`. All of them in the block of its assignment, none once it is late.
|
|
48
|
+
* Over `STALE_DELAY`, it is the share of the premium a fulfillment settled then earns (ADR 0029).
|
|
49
|
+
*/
|
|
50
|
+
export declare const remainingDelay: ({ assignedAt, at }: {
|
|
51
|
+
readonly assignedAt: bigint | number;
|
|
52
|
+
readonly at: bigint | number;
|
|
53
|
+
}) => bigint;
|
|
54
|
+
/** Tags the VRF service inside the request id so no other service can collide with it. */
|
|
55
|
+
export declare const SERVICE_VRF: Hex;
|
|
56
|
+
/** Mirrors `Vrf.requestId` in the router. */
|
|
57
|
+
export declare const requestId: ({ chainId, router, request }: RouterDomain & {
|
|
58
|
+
readonly request: Request;
|
|
59
|
+
}) => Hex;
|
|
60
|
+
//#endregion
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { encodeAbiParameters, keccak256, stringToHex } from "viem";
|
|
2
|
+
//#region src/request.ts
|
|
3
|
+
/**
|
|
4
|
+
* `Config.STALE_DELAY`, in seconds: how long after its assignment a request may be reported
|
|
5
|
+
* stale (ADR 0024), and from when a fulfillment of it is settled without the premium (ADR 0025),
|
|
6
|
+
* which decays in a straight line over it (ADR 0029).
|
|
7
|
+
*/
|
|
8
|
+
const STALE_DELAY = 30;
|
|
9
|
+
/**
|
|
10
|
+
* `Config.MAX_CALLBACK_DATA_BYTES`: the most callback data a request may carry (ADR 0023). A
|
|
11
|
+
* fulfillment echoes it, so it decides how many share one transaction under the enclave's calldata
|
|
12
|
+
* bound, and so how fast a node at capacity lands them against the stale delay.
|
|
13
|
+
*/
|
|
14
|
+
const MAX_CALLBACK_DATA_BYTES = 16384;
|
|
15
|
+
/** Mirrors `Vrf.staleAt`: the first second the request is reportable as stale. */
|
|
16
|
+
const staleAt = (assignedAt) => BigInt(assignedAt) + BigInt(30);
|
|
17
|
+
/**
|
|
18
|
+
* Mirrors `Vrf.isLate`: whether the stale delay since the assignment has elapsed at `at`, the
|
|
19
|
+
* router's `block.timestamp`. The one predicate the stale report and the settlement share, so the
|
|
20
|
+
* first second a report is taken is the first second a fulfillment's premium has decayed to nothing.
|
|
21
|
+
*/
|
|
22
|
+
const isLate = ({ assignedAt, at }) => BigInt(at) >= staleAt(assignedAt);
|
|
23
|
+
/**
|
|
24
|
+
* Mirrors `Vrf.remainingDelay`: the seconds of the stale delay the request has left at `at`, the
|
|
25
|
+
* router's `block.timestamp`. All of them in the block of its assignment, none once it is late.
|
|
26
|
+
* Over `STALE_DELAY`, it is the share of the premium a fulfillment settled then earns (ADR 0029).
|
|
27
|
+
*/
|
|
28
|
+
const remainingDelay = ({ assignedAt, at }) => isLate({
|
|
29
|
+
assignedAt,
|
|
30
|
+
at
|
|
31
|
+
}) ? 0n : staleAt(assignedAt) - BigInt(at);
|
|
32
|
+
/** Tags the VRF service inside the request id so no other service can collide with it. */
|
|
33
|
+
const SERVICE_VRF = keccak256(stringToHex("VerifyNetworkVRF"));
|
|
34
|
+
/** Mirrors `Vrf.requestId` in the router. */
|
|
35
|
+
const requestId = ({ chainId, router, request }) => keccak256(encodeAbiParameters([
|
|
36
|
+
{ type: "uint256" },
|
|
37
|
+
{ type: "address" },
|
|
38
|
+
{ type: "bytes32" },
|
|
39
|
+
{ type: "address" },
|
|
40
|
+
{ type: "uint64" },
|
|
41
|
+
{ type: "address" },
|
|
42
|
+
{ type: "uint40" },
|
|
43
|
+
{ type: "uint96" },
|
|
44
|
+
{ type: "uint96" },
|
|
45
|
+
{ type: "uint32" },
|
|
46
|
+
{ type: "bytes32" }
|
|
47
|
+
], [
|
|
48
|
+
BigInt(chainId),
|
|
49
|
+
router,
|
|
50
|
+
SERVICE_VRF,
|
|
51
|
+
request.consumer,
|
|
52
|
+
request.sequence,
|
|
53
|
+
request.fulfiller,
|
|
54
|
+
request.assignedAt,
|
|
55
|
+
request.fee,
|
|
56
|
+
request.gasPrice,
|
|
57
|
+
request.callbackGasLimit,
|
|
58
|
+
keccak256(request.callbackData)
|
|
59
|
+
]));
|
|
60
|
+
//#endregion
|
|
61
|
+
export { MAX_CALLBACK_DATA_BYTES, SERVICE_VRF, STALE_DELAY, isLate, remainingDelay, requestId, staleAt };
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verify-network/protocol",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "The Verify Network VRF protocol off-chain: ECVRF prove and verify, request ids, fulfillment typed data, router events and fees, and the router watch and direct-request client.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./ecvrf": {
|
|
17
|
+
"types": "./dist/ecvrf.d.ts",
|
|
18
|
+
"default": "./dist/ecvrf.js"
|
|
19
|
+
},
|
|
20
|
+
"./event": {
|
|
21
|
+
"types": "./dist/event.d.ts",
|
|
22
|
+
"default": "./dist/event.js"
|
|
23
|
+
},
|
|
24
|
+
"./fee": {
|
|
25
|
+
"types": "./dist/fee.d.ts",
|
|
26
|
+
"default": "./dist/fee.js"
|
|
27
|
+
},
|
|
28
|
+
"./fulfillment": {
|
|
29
|
+
"types": "./dist/fulfillment.d.ts",
|
|
30
|
+
"default": "./dist/fulfillment.js"
|
|
31
|
+
},
|
|
32
|
+
"./request": {
|
|
33
|
+
"types": "./dist/request.d.ts",
|
|
34
|
+
"default": "./dist/request.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "vp pack",
|
|
39
|
+
"prepack": "vp pack && node ../../scripts/publish-manifest.ts apply",
|
|
40
|
+
"postpack": "node ../../scripts/publish-manifest.ts restore",
|
|
41
|
+
"test": "vp test",
|
|
42
|
+
"type-check": "tsc"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@noble/curves": "^2.4.0",
|
|
46
|
+
"@noble/hashes": "^2.4.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"effect": "^4.0.0",
|
|
50
|
+
"viem": "^2.56.3"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=22"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
58
|
+
}
|