og-fe-tee-verification 0.0.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/README.md +97 -0
- package/dist/cjs/index.d.ts +230 -0
- package/dist/cjs/index.js +441 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.d.mts +230 -0
- package/dist/esm/index.mjs +400 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# og-fe-settlement-verify
|
|
2
|
+
|
|
3
|
+
A small frontend-friendly client for fetching Walrus blobs from the Sui Core aggregator.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm install og-fe-settlement-verify
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { fetchWalrusBlobText } from "og-fe-settlement-verify";
|
|
15
|
+
|
|
16
|
+
const blobText = await fetchWalrusBlobText("your-walrus-blob-id");
|
|
17
|
+
console.log(blobText);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## API
|
|
21
|
+
|
|
22
|
+
### `getWalrusBlobUrl(blobId, options?)`
|
|
23
|
+
|
|
24
|
+
Builds the aggregator URL for a blob ID.
|
|
25
|
+
|
|
26
|
+
### `fetchWalrusBlob(blobId, options?)`
|
|
27
|
+
|
|
28
|
+
Fetches the raw blob `Response`.
|
|
29
|
+
|
|
30
|
+
### `fetchWalrusBlobBytes(blobId, options?)`
|
|
31
|
+
|
|
32
|
+
Fetches the blob and returns an `ArrayBuffer`.
|
|
33
|
+
|
|
34
|
+
### `fetchWalrusBlobText(blobId, options?)`
|
|
35
|
+
|
|
36
|
+
Fetches the blob and returns a string.
|
|
37
|
+
|
|
38
|
+
### `fetchWalrusBlobJson<T>(blobId, options?)`
|
|
39
|
+
|
|
40
|
+
Fetches the blob and parses the body as JSON.
|
|
41
|
+
|
|
42
|
+
### `fetchWalrusBatchTree(blobId, options?)`
|
|
43
|
+
|
|
44
|
+
Fetches a batch Merkle tree blob and returns the decoded items for UI use.
|
|
45
|
+
|
|
46
|
+
### `DEFAULT_WALRUS_VERIFIER_CONTRACT_ADDRESS`
|
|
47
|
+
|
|
48
|
+
The default verifier contract address:
|
|
49
|
+
`0xa06dAFA3D713b74e4e1E74B34bd1588C9FD6C290`
|
|
50
|
+
|
|
51
|
+
### `DEFAULT_WALRUS_RPC_URL`
|
|
52
|
+
|
|
53
|
+
The default RPC URL:
|
|
54
|
+
`https://ogevmdevnet.opengradient.ai`
|
|
55
|
+
|
|
56
|
+
### `verifyWalrusBatchTreeItemSignature(args)`
|
|
57
|
+
|
|
58
|
+
Calls `verifySignatureNoTimestamp(teeId, inputHash, outputHash, timestamp, signature)` for a
|
|
59
|
+
single batch item. `args.verifierContractAddress` is optional and defaults to
|
|
60
|
+
`DEFAULT_WALRUS_VERIFIER_CONTRACT_ADDRESS`.
|
|
61
|
+
|
|
62
|
+
### `verifyWalrusBatchTreeSignatures(args)`
|
|
63
|
+
|
|
64
|
+
Runs `verifySignatureNoTimestamp(...)` for every item in a fetched Walrus batch tree.
|
|
65
|
+
`args.verifierContractAddress` is optional and defaults to
|
|
66
|
+
`DEFAULT_WALRUS_VERIFIER_CONTRACT_ADDRESS`.
|
|
67
|
+
|
|
68
|
+
### `createWalrusClient(options?)`
|
|
69
|
+
|
|
70
|
+
Creates a reusable client with a shared base URL and fetch implementation.
|
|
71
|
+
|
|
72
|
+
## Example
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { createWalrusClient } from "og-fe-settlement-verify";
|
|
76
|
+
|
|
77
|
+
const walrus = createWalrusClient({
|
|
78
|
+
baseUrl: "https://aggregator.suicore.com",
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const imageBytes = await walrus.fetchBlobBytes("your-walrus-blob-id");
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Batch Tree Notes
|
|
85
|
+
|
|
86
|
+
- The current facilitator batch tree stores raw `tee_signature` bytes in each leaf.
|
|
87
|
+
- That means the UI can call onchain `verifySignatureNoTimestamp(...)` directly for every item in
|
|
88
|
+
the blob.
|
|
89
|
+
- The current batch leaf order is `tee_id, input_hash, output_hash, tee_signature, tee_timestamp`.
|
|
90
|
+
|
|
91
|
+
## Notes
|
|
92
|
+
|
|
93
|
+
- The default aggregator is `https://aggregator.suicore.com`.
|
|
94
|
+
- The default verifier contract is `0xa06dAFA3D713b74e4e1E74B34bd1588C9FD6C290`.
|
|
95
|
+
- The default RPC URL is `https://ogevmdevnet.opengradient.ai`.
|
|
96
|
+
- Walrus aggregators return the raw blob bytes from `GET /v1/blobs/<blob-id>`.
|
|
97
|
+
- Blob IDs are URL-encoded before the request is made.
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { StandardMerkleTree } from '@openzeppelin/merkle-tree';
|
|
2
|
+
import { Hex } from 'viem';
|
|
3
|
+
|
|
4
|
+
declare const DEFAULT_WALRUS_AGGREGATOR_URL = "https://aggregator.suicore.com";
|
|
5
|
+
declare const DEFAULT_WALRUS_VERIFIER_CONTRACT_ADDRESS: Hex;
|
|
6
|
+
declare const DEFAULT_WALRUS_RPC_URL = "https://ogevmdevnet.opengradient.ai";
|
|
7
|
+
declare const WALRUS_BATCH_LEAF_ENCODING: readonly ["bytes32", "bytes32", "bytes32", "bytes", "uint256"];
|
|
8
|
+
declare const verifierContractAbi: readonly [{
|
|
9
|
+
readonly type: "function";
|
|
10
|
+
readonly name: "verifySignatureNoTimestamp";
|
|
11
|
+
readonly stateMutability: "view";
|
|
12
|
+
readonly inputs: readonly [{
|
|
13
|
+
readonly name: "teeId";
|
|
14
|
+
readonly type: "bytes32";
|
|
15
|
+
}, {
|
|
16
|
+
readonly name: "inputHash";
|
|
17
|
+
readonly type: "bytes32";
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "outputHash";
|
|
20
|
+
readonly type: "bytes32";
|
|
21
|
+
}, {
|
|
22
|
+
readonly name: "timestamp";
|
|
23
|
+
readonly type: "uint256";
|
|
24
|
+
}, {
|
|
25
|
+
readonly name: "signature";
|
|
26
|
+
readonly type: "bytes";
|
|
27
|
+
}];
|
|
28
|
+
readonly outputs: readonly [{
|
|
29
|
+
readonly name: "";
|
|
30
|
+
readonly type: "bool";
|
|
31
|
+
}];
|
|
32
|
+
}];
|
|
33
|
+
/**
|
|
34
|
+
* Shared client options for Walrus blob requests.
|
|
35
|
+
*/
|
|
36
|
+
interface WalrusClientOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Base aggregator URL.
|
|
39
|
+
*
|
|
40
|
+
* @defaultValue "https://aggregator.suicore.com"
|
|
41
|
+
*/
|
|
42
|
+
baseUrl?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Fetch implementation to use. Defaults to `globalThis.fetch`.
|
|
45
|
+
*/
|
|
46
|
+
fetch?: typeof globalThis.fetch;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Request options for blob fetches.
|
|
50
|
+
*/
|
|
51
|
+
interface FetchWalrusBlobOptions extends Omit<RequestInit, "body" | "method">, WalrusClientOptions {
|
|
52
|
+
}
|
|
53
|
+
type WalrusBatchLeafTuple = [Hex, Hex, Hex, Hex, string];
|
|
54
|
+
type WalrusBatchTreeDump = {
|
|
55
|
+
format: "standard-v1";
|
|
56
|
+
leafEncoding: string[];
|
|
57
|
+
tree: Hex[];
|
|
58
|
+
values: Array<{
|
|
59
|
+
value: WalrusBatchLeafTuple;
|
|
60
|
+
treeIndex: number;
|
|
61
|
+
hash: Hex;
|
|
62
|
+
}>;
|
|
63
|
+
};
|
|
64
|
+
type WalrusBatchTreeItem = {
|
|
65
|
+
index: number;
|
|
66
|
+
tee_id: Hex;
|
|
67
|
+
input_hash: Hex;
|
|
68
|
+
output_hash: Hex;
|
|
69
|
+
tee_signature: Hex;
|
|
70
|
+
tee_timestamp: string;
|
|
71
|
+
tuple: WalrusBatchLeafTuple;
|
|
72
|
+
};
|
|
73
|
+
type LoadedWalrusBatchTree = {
|
|
74
|
+
blobId: string;
|
|
75
|
+
merkleRoot: Hex;
|
|
76
|
+
tree: StandardMerkleTree<WalrusBatchLeafTuple>;
|
|
77
|
+
dump: WalrusBatchTreeDump;
|
|
78
|
+
items: WalrusBatchTreeItem[];
|
|
79
|
+
};
|
|
80
|
+
type WalrusSignatureEncoding = "auto" | "hex" | "utf8" | "base64";
|
|
81
|
+
type WalrusSignatureVerificationClient = {
|
|
82
|
+
readContract(args: {
|
|
83
|
+
address: Hex;
|
|
84
|
+
abi: typeof verifierContractAbi;
|
|
85
|
+
functionName: "verifySignatureNoTimestamp";
|
|
86
|
+
args: readonly [Hex, Hex, Hex, bigint, Hex];
|
|
87
|
+
}): Promise<boolean>;
|
|
88
|
+
};
|
|
89
|
+
type VerifyWalrusBatchTreeItemSignatureArgs = {
|
|
90
|
+
item: WalrusBatchTreeItem;
|
|
91
|
+
verifierContractAddress?: Hex;
|
|
92
|
+
publicClient: WalrusSignatureVerificationClient;
|
|
93
|
+
};
|
|
94
|
+
type VerifyWalrusBatchTreeSignaturesArgs = {
|
|
95
|
+
blobId?: string;
|
|
96
|
+
tree?: LoadedWalrusBatchTree;
|
|
97
|
+
verifierContractAddress?: Hex;
|
|
98
|
+
publicClient: WalrusSignatureVerificationClient;
|
|
99
|
+
aggregatorUrl?: string;
|
|
100
|
+
fetch?: typeof globalThis.fetch;
|
|
101
|
+
};
|
|
102
|
+
type WalrusBatchTreeItemVerification = {
|
|
103
|
+
item: WalrusBatchTreeItem;
|
|
104
|
+
verified: boolean | null;
|
|
105
|
+
error?: string;
|
|
106
|
+
};
|
|
107
|
+
type WalrusBatchTreeVerificationResult = {
|
|
108
|
+
blobId: string;
|
|
109
|
+
merkleRoot: Hex;
|
|
110
|
+
results: WalrusBatchTreeItemVerification[];
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Thrown when a Walrus blob request fails.
|
|
114
|
+
*/
|
|
115
|
+
declare class WalrusBlobFetchError extends Error {
|
|
116
|
+
readonly blobId: string;
|
|
117
|
+
readonly status: number;
|
|
118
|
+
readonly statusText: string;
|
|
119
|
+
readonly url: string;
|
|
120
|
+
/**
|
|
121
|
+
* Creates a new Walrus blob fetch error.
|
|
122
|
+
*
|
|
123
|
+
* @param blobId - The blob ID that was requested.
|
|
124
|
+
* @param response - The failed HTTP response.
|
|
125
|
+
* @param url - The resolved blob URL.
|
|
126
|
+
*/
|
|
127
|
+
constructor(blobId: string, response: Response, url: string);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Type guard for Walrus blob fetch errors.
|
|
131
|
+
*
|
|
132
|
+
* @param error - Unknown thrown value.
|
|
133
|
+
* @returns Whether the value is a WalrusBlobFetchError.
|
|
134
|
+
*/
|
|
135
|
+
declare function isWalrusBlobFetchError(error: unknown): error is WalrusBlobFetchError;
|
|
136
|
+
/**
|
|
137
|
+
* Builds the Sui Core aggregator URL for a Walrus blob ID.
|
|
138
|
+
*
|
|
139
|
+
* @param blobId - Walrus blob ID.
|
|
140
|
+
* @param options - Optional URL settings.
|
|
141
|
+
* @returns The full blob URL.
|
|
142
|
+
*/
|
|
143
|
+
declare function getWalrusBlobUrl(blobId: string, options?: Pick<WalrusClientOptions, "baseUrl">): string;
|
|
144
|
+
/**
|
|
145
|
+
* Fetches a Walrus blob and returns the raw HTTP response.
|
|
146
|
+
*
|
|
147
|
+
* @param blobId - Walrus blob ID.
|
|
148
|
+
* @param options - Optional request configuration.
|
|
149
|
+
* @returns The successful blob response.
|
|
150
|
+
*/
|
|
151
|
+
declare function fetchWalrusBlob(blobId: string, options?: FetchWalrusBlobOptions): Promise<Response>;
|
|
152
|
+
/**
|
|
153
|
+
* Fetches a Walrus blob and returns its bytes.
|
|
154
|
+
*
|
|
155
|
+
* @param blobId - Walrus blob ID.
|
|
156
|
+
* @param options - Optional request configuration.
|
|
157
|
+
* @returns The blob bytes.
|
|
158
|
+
*/
|
|
159
|
+
declare function fetchWalrusBlobBytes(blobId: string, options?: FetchWalrusBlobOptions): Promise<ArrayBuffer>;
|
|
160
|
+
/**
|
|
161
|
+
* Fetches a Walrus blob and returns its text content.
|
|
162
|
+
*
|
|
163
|
+
* @param blobId - Walrus blob ID.
|
|
164
|
+
* @param options - Optional request configuration.
|
|
165
|
+
* @returns The blob body as text.
|
|
166
|
+
*/
|
|
167
|
+
declare function fetchWalrusBlobText(blobId: string, options?: FetchWalrusBlobOptions): Promise<string>;
|
|
168
|
+
/**
|
|
169
|
+
* Fetches a Walrus blob and parses it as JSON.
|
|
170
|
+
*
|
|
171
|
+
* @param blobId - Walrus blob ID.
|
|
172
|
+
* @param options - Optional request configuration.
|
|
173
|
+
* @returns The parsed JSON payload.
|
|
174
|
+
*/
|
|
175
|
+
declare function fetchWalrusBlobJson<T>(blobId: string, options?: FetchWalrusBlobOptions): Promise<T>;
|
|
176
|
+
/**
|
|
177
|
+
* Fetches and parses a Walrus batch Merkle tree blob.
|
|
178
|
+
*
|
|
179
|
+
* @param blobId - Walrus batch blob ID.
|
|
180
|
+
* @param options - Optional request configuration.
|
|
181
|
+
* @returns The loaded tree plus decoded batch items.
|
|
182
|
+
*/
|
|
183
|
+
declare function fetchWalrusBatchTree(blobId: string, options?: FetchWalrusBlobOptions): Promise<LoadedWalrusBatchTree>;
|
|
184
|
+
/**
|
|
185
|
+
* Parses a Walrus batch Merkle tree payload into strongly typed items.
|
|
186
|
+
*
|
|
187
|
+
* @param blobId - Walrus batch blob ID.
|
|
188
|
+
* @param dump - Raw tree dump JSON.
|
|
189
|
+
* @returns The loaded tree plus decoded batch items.
|
|
190
|
+
*/
|
|
191
|
+
declare function parseWalrusBatchTree(blobId: string, dump: WalrusBatchTreeDump): LoadedWalrusBatchTree;
|
|
192
|
+
/**
|
|
193
|
+
* Encodes a raw tee signature into bytes calldata for the onchain verifySignatureNoTimestamp call.
|
|
194
|
+
*
|
|
195
|
+
* @param signature - Raw signature value.
|
|
196
|
+
* @param encoding - Signature encoding strategy.
|
|
197
|
+
* @returns Encoded bytes calldata.
|
|
198
|
+
*/
|
|
199
|
+
declare function encodeWalrusSignature(signature: string, encoding?: WalrusSignatureEncoding): Hex;
|
|
200
|
+
/**
|
|
201
|
+
* Calls verifySignatureNoTimestamp for a single Walrus batch item.
|
|
202
|
+
*
|
|
203
|
+
* @param args - Verification inputs for one batch item.
|
|
204
|
+
* @returns Whether the onchain verifySignatureNoTimestamp call returned true.
|
|
205
|
+
*/
|
|
206
|
+
declare function verifyWalrusBatchTreeItemSignature(args: VerifyWalrusBatchTreeItemSignatureArgs): Promise<boolean>;
|
|
207
|
+
/**
|
|
208
|
+
* Calls verifySignatureNoTimestamp for every item in a Walrus batch tree.
|
|
209
|
+
*
|
|
210
|
+
* @param args - Verification inputs for the whole Walrus batch tree.
|
|
211
|
+
* @returns Per-item verification results.
|
|
212
|
+
*/
|
|
213
|
+
declare function verifyWalrusBatchTreeSignatures(args: VerifyWalrusBatchTreeSignaturesArgs): Promise<WalrusBatchTreeVerificationResult>;
|
|
214
|
+
/**
|
|
215
|
+
* Creates a reusable Walrus client.
|
|
216
|
+
*
|
|
217
|
+
* @param options - Shared client options.
|
|
218
|
+
* @returns Bound Walrus helper methods.
|
|
219
|
+
*/
|
|
220
|
+
declare function createWalrusClient(options?: WalrusClientOptions): {
|
|
221
|
+
getBlobUrl(blobId: string): string;
|
|
222
|
+
fetchBlob(blobId: string, requestInit?: FetchWalrusBlobOptions): Promise<Response>;
|
|
223
|
+
fetchBlobBytes(blobId: string, requestInit?: FetchWalrusBlobOptions): Promise<ArrayBuffer>;
|
|
224
|
+
fetchBlobText(blobId: string, requestInit?: FetchWalrusBlobOptions): Promise<string>;
|
|
225
|
+
fetchBlobJson<T>(blobId: string, requestInit?: FetchWalrusBlobOptions): Promise<T>;
|
|
226
|
+
fetchBatchTree(blobId: string, requestInit?: FetchWalrusBlobOptions): Promise<LoadedWalrusBatchTree>;
|
|
227
|
+
verifyBatchTreeSignatures(args: Omit<VerifyWalrusBatchTreeSignaturesArgs, "blobId" | "fetch">): Promise<WalrusBatchTreeVerificationResult>;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export { DEFAULT_WALRUS_AGGREGATOR_URL, DEFAULT_WALRUS_RPC_URL, DEFAULT_WALRUS_VERIFIER_CONTRACT_ADDRESS, type FetchWalrusBlobOptions, type LoadedWalrusBatchTree, type VerifyWalrusBatchTreeItemSignatureArgs, type VerifyWalrusBatchTreeSignaturesArgs, WALRUS_BATCH_LEAF_ENCODING, type WalrusBatchLeafTuple, type WalrusBatchTreeDump, type WalrusBatchTreeItem, type WalrusBatchTreeItemVerification, type WalrusBatchTreeVerificationResult, WalrusBlobFetchError, type WalrusClientOptions, type WalrusSignatureEncoding, type WalrusSignatureVerificationClient, createWalrusClient, encodeWalrusSignature, fetchWalrusBatchTree, fetchWalrusBlob, fetchWalrusBlobBytes, fetchWalrusBlobJson, fetchWalrusBlobText, getWalrusBlobUrl, isWalrusBlobFetchError, parseWalrusBatchTree, verifyWalrusBatchTreeItemSignature, verifyWalrusBatchTreeSignatures };
|