@vlayer/sdk 0.1.0-nightly-20241205-223f353 → 0.1.0-nightly-20241206-b638b72
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/api/lib/client.js +6 -10
- package/dist/api/lib/client.test.js +32 -21
- package/dist/api/lib/types/ethereum.d.ts +1 -1
- package/dist/api/lib/types/vlayer.d.ts +11 -3
- package/dist/api/prover.d.ts +2 -0
- package/dist/api/prover.js +7 -0
- package/dist/api/v_getProofReceipt.d.ts +2 -0
- package/dist/api/v_getProofReceipt.js +32 -0
- package/package.json +1 -1
package/dist/api/lib/client.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { prove } from "../prover.js";
|
1
|
+
import { prove, getProofReceipt } from "../prover.js";
|
2
2
|
import { createExtensionWebProofProvider } from "../webProof/index.js";
|
3
3
|
import { decodeFunctionResult, } from "viem";
|
4
4
|
import { ZkProvingStatus } from "../../web-proof-commons/index.js";
|
@@ -10,7 +10,7 @@ function dropEmptyProofFromArgs(args) {
|
|
10
10
|
}
|
11
11
|
async function getHash(vcall_response) {
|
12
12
|
const result = await vcall_response;
|
13
|
-
return
|
13
|
+
return result.result;
|
14
14
|
}
|
15
15
|
export const createVlayerClient = ({ url = "http://127.0.0.1:3000", webProofProvider = createExtensionWebProofProvider(), } = {
|
16
16
|
url: "http://127.0.0.1:3000",
|
@@ -29,21 +29,17 @@ export const createVlayerClient = ({ url = "http://127.0.0.1:3000", webProofProv
|
|
29
29
|
webProofProvider.notifyZkProvingStatus(ZkProvingStatus.Done);
|
30
30
|
return result;
|
31
31
|
});
|
32
|
-
const
|
33
|
-
resultHashMap.set(hash, [
|
34
|
-
Promise.resolve(result_promise),
|
35
|
-
proverAbi,
|
36
|
-
functionName,
|
37
|
-
]);
|
32
|
+
const hash = await getHash(response);
|
33
|
+
resultHashMap.set(hash, [proverAbi, functionName]);
|
38
34
|
return { hash };
|
39
35
|
},
|
40
36
|
waitForProvingResult: async ({ hash, }) => {
|
37
|
+
const { result: { proof, evm_call_result }, } = await getProofReceipt({ hash }, url);
|
41
38
|
const savedProvingData = resultHashMap.get(hash);
|
42
39
|
if (!savedProvingData) {
|
43
40
|
throw new Error("No result found for hash " + hash);
|
44
41
|
}
|
45
|
-
const [
|
46
|
-
const { result: { proof, evm_call_result }, } = await result_promise;
|
42
|
+
const [proverAbi, functionName] = savedProvingData;
|
47
43
|
const result = dropEmptyProofFromArgs(decodeFunctionResult({
|
48
44
|
abi: proverAbi,
|
49
45
|
data: evm_call_result,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { describe, expect, it, vi, beforeEach } from "vitest";
|
1
|
+
import { describe, expect, it, vi, beforeEach, beforeAll, } from "vitest";
|
2
2
|
import { createExtensionWebProofProvider } from "../webProof/index.js";
|
3
3
|
import { createVlayerClient } from "./client.js";
|
4
4
|
import { ZkProvingStatus } from "src/web-proof-commons";
|
@@ -28,35 +28,46 @@ function generateRandomHash() {
|
|
28
28
|
return hash;
|
29
29
|
}
|
30
30
|
describe("Success zk-proving", () => {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
result: {
|
37
|
-
hash: generateRandomHash(),
|
38
|
-
proof: {},
|
39
|
-
},
|
40
|
-
}),
|
41
|
-
};
|
42
|
-
}
|
43
|
-
return {};
|
44
|
-
});
|
45
|
-
});
|
46
|
-
it("should send message to extension that zkproving started and then that is done", async () => {
|
31
|
+
let hash;
|
32
|
+
let zkProvingSpy;
|
33
|
+
let vlayer;
|
34
|
+
beforeAll(() => {
|
35
|
+
hash = generateRandomHash();
|
47
36
|
const webProofProvider = createExtensionWebProofProvider();
|
48
|
-
|
49
|
-
|
50
|
-
|
37
|
+
zkProvingSpy = vi.spyOn(webProofProvider, "notifyZkProvingStatus");
|
38
|
+
vlayer = createVlayerClient({ webProofProvider });
|
39
|
+
});
|
40
|
+
it("should send message to extension that zkproving started", async () => {
|
41
|
+
fetchMocker.mockResponseOnce(() => {
|
42
|
+
return {
|
43
|
+
body: JSON.stringify({
|
44
|
+
result: hash,
|
45
|
+
}),
|
46
|
+
};
|
47
|
+
});
|
48
|
+
const result = await vlayer.prove({
|
51
49
|
address: `0x${"a".repeat(40)}`,
|
52
50
|
functionName: "main",
|
53
51
|
proverAbi: [],
|
54
52
|
args: [],
|
55
53
|
chainId: 42,
|
56
54
|
});
|
57
|
-
|
55
|
+
expect(result.hash).toBe(hash);
|
58
56
|
expect(zkProvingSpy).toBeCalledTimes(2);
|
59
57
|
expect(zkProvingSpy).toHaveBeenNthCalledWith(1, ZkProvingStatus.Proving);
|
58
|
+
});
|
59
|
+
it("should send message to extension that zkproving is done", async () => {
|
60
|
+
fetchMocker.mockResponseOnce(() => {
|
61
|
+
return {
|
62
|
+
body: JSON.stringify({
|
63
|
+
result: {
|
64
|
+
proof: {},
|
65
|
+
},
|
66
|
+
}),
|
67
|
+
};
|
68
|
+
});
|
69
|
+
await vlayer.waitForProvingResult({ hash });
|
70
|
+
expect(zkProvingSpy).toBeCalledTimes(2);
|
60
71
|
expect(zkProvingSpy).toHaveBeenNthCalledWith(2, ZkProvingStatus.Done);
|
61
72
|
});
|
62
73
|
});
|
@@ -7,7 +7,7 @@ export type ContractSpec = {
|
|
7
7
|
abi: Abi;
|
8
8
|
bytecode: Bytecode;
|
9
9
|
};
|
10
|
-
export type ContractArg = number | string | boolean | bigint | number[] | string[] | boolean[] | bigint[] | Address[];
|
10
|
+
export type ContractArg = number | string | boolean | bigint | number[] | string[] | boolean[] | bigint[] | Address[] | (string | bigint)[] | (string | bigint)[][];
|
11
11
|
export type EthereumAddress = Branded<Hex, "EthereumAddress">;
|
12
12
|
export type EthereumTxHash = Branded<Hex, "EthereumTxHash">;
|
13
13
|
export declare function assertEthereumAddress(hash: string): asserts hash is EthereumAddress;
|
@@ -29,14 +29,22 @@ export type Proof = {
|
|
29
29
|
settleBlockNumber: bigint;
|
30
30
|
};
|
31
31
|
};
|
32
|
-
export
|
32
|
+
export type VCallResult = Hex;
|
33
|
+
export interface VCallResponse {
|
34
|
+
jsonrpc: string;
|
35
|
+
result: VCallResult;
|
36
|
+
id: number;
|
37
|
+
}
|
38
|
+
export type VGetProofReceiptParams = {
|
33
39
|
hash: Hex;
|
40
|
+
};
|
41
|
+
export interface VGetProofReceiptResult {
|
34
42
|
evm_call_result: Hex;
|
35
43
|
proof: Proof;
|
36
44
|
}
|
37
|
-
export interface
|
45
|
+
export interface VGetProofReceiptResponse {
|
38
46
|
jsonrpc: string;
|
39
|
-
result:
|
47
|
+
result: VGetProofReceiptResult;
|
40
48
|
id: number;
|
41
49
|
}
|
42
50
|
export type VlayerClient = {
|
package/dist/api/prover.d.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { type Abi, AbiStateMutability, type Address, ContractFunctionArgs, ContractFunctionName } from "viem";
|
2
|
+
import { type BrandedHash } from "./lib/types/vlayer.js";
|
2
3
|
export interface ProveOptions {
|
3
4
|
preverifyVersions?: boolean;
|
4
5
|
}
|
5
6
|
export declare function prove<T extends Abi, F extends ContractFunctionName<T>>(prover: Address, abi: T, functionName: F, args: ContractFunctionArgs<T, AbiStateMutability, F>, chainId?: number, gasLimit?: number, url?: string, options?: ProveOptions): Promise<import("./lib/types/vlayer.js").VCallResponse>;
|
7
|
+
export declare function getProofReceipt<T extends Abi, F extends ContractFunctionName<T>>(hash: BrandedHash<T, F>, url?: string): Promise<import("./lib/types/vlayer.js").VGetProofReceiptResponse>;
|
package/dist/api/prover.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { encodeFunctionData, } from "viem";
|
2
2
|
import { v_call } from "./v_call.js";
|
3
|
+
import { v_getProofReceipt } from "./v_getProofReceipt.js";
|
3
4
|
import { foundry } from "viem/chains";
|
4
5
|
import { v_versions } from "./v_versions.js";
|
5
6
|
import { checkVersionCompatibility } from "./utils/versions.js";
|
@@ -25,3 +26,9 @@ export async function prove(prover, abi, functionName, args, chainId = foundry.i
|
|
25
26
|
};
|
26
27
|
return v_call(call, context, url);
|
27
28
|
}
|
29
|
+
export async function getProofReceipt(hash, url = "http://127.0.0.1:3000") {
|
30
|
+
const params = {
|
31
|
+
hash: hash.hash,
|
32
|
+
};
|
33
|
+
return v_getProofReceipt(params, url);
|
34
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { parseVCallResponseError } from "./lib/errors.js";
|
2
|
+
function v_getProofReceiptBody(params) {
|
3
|
+
return {
|
4
|
+
method: "v_getProofReceipt",
|
5
|
+
params: params,
|
6
|
+
id: 1,
|
7
|
+
jsonrpc: "2.0",
|
8
|
+
};
|
9
|
+
}
|
10
|
+
export async function v_getProofReceipt(params, url = "http://127.0.0.1:3000") {
|
11
|
+
const response = await fetch(url, {
|
12
|
+
method: "POST",
|
13
|
+
body: JSON.stringify(v_getProofReceiptBody(params)),
|
14
|
+
headers: { "Content-Type": "application/json" },
|
15
|
+
});
|
16
|
+
console.log("response", response);
|
17
|
+
if (!response.ok) {
|
18
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
19
|
+
}
|
20
|
+
const response_json = await response.json();
|
21
|
+
console.log("response_json", response_json);
|
22
|
+
assertObject(response_json);
|
23
|
+
if ("error" in response_json) {
|
24
|
+
throw parseVCallResponseError(response_json.error);
|
25
|
+
}
|
26
|
+
return response_json;
|
27
|
+
}
|
28
|
+
function assertObject(x) {
|
29
|
+
if (typeof x !== "object") {
|
30
|
+
throw new Error("Expected object");
|
31
|
+
}
|
32
|
+
}
|
package/package.json
CHANGED