@vlayer/sdk 0.1.0-nightly-20241112-4be2839 → 0.1.0-nightly-20241114-f00047a
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/api/lib/client.js +6 -5
- package/dist/api/lib/client.test.js +4 -4
- package/dist/api/lib/types/vlayer.d.ts +8 -8
- package/dist/api/webProof/providers/extension.js +0 -3
- package/dist/config/createContext.d.ts +4953 -0
- package/dist/config/createContext.js +29 -0
- package/dist/config/deploy.d.ts +17 -0
- package/dist/config/deploy.js +54 -0
- package/dist/config/getChainConfirmations.d.ts +1 -0
- package/dist/config/getChainConfirmations.js +6 -0
- package/dist/config/getConfig.d.ts +8 -0
- package/dist/config/getConfig.js +49 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.js +4 -0
- package/dist/config/writeEnvVariables.d.ts +3 -0
- package/dist/config/writeEnvVariables.js +16 -0
- package/package.json +6 -1
package/dist/api/lib/client.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { prove } from "../prover.js";
|
2
2
|
import { createExtensionWebProofProvider } from "../webProof/index.js";
|
3
|
-
import { decodeFunctionResult } from "viem";
|
3
|
+
import { decodeFunctionResult, } from "viem";
|
4
4
|
import { ZkProvingStatus } from "../../web-proof-commons/index.js";
|
5
5
|
function dropEmptyProofFromArgs(args) {
|
6
6
|
if (Array.isArray(args)) {
|
@@ -39,16 +39,17 @@ export const createVlayerClient = ({ url = "http://127.0.0.1:3000", webProofProv
|
|
39
39
|
resultHashMap.set(hash, [result_promise, proverAbi, functionName]);
|
40
40
|
return { hash };
|
41
41
|
},
|
42
|
-
waitForProvingResult: async ({ hash }) => {
|
42
|
+
waitForProvingResult: async ({ hash, }) => {
|
43
43
|
const savedProvingData = resultHashMap.get(hash);
|
44
44
|
if (!savedProvingData) {
|
45
45
|
throw new Error("No result found for hash " + hash);
|
46
46
|
}
|
47
|
-
const
|
47
|
+
const [result_promise, proverAbi, functionName] = savedProvingData;
|
48
|
+
const { result: { proof, evm_call_result }, } = await result_promise;
|
48
49
|
const result = dropEmptyProofFromArgs(decodeFunctionResult({
|
49
|
-
abi:
|
50
|
+
abi: proverAbi,
|
50
51
|
data: evm_call_result,
|
51
|
-
functionName
|
52
|
+
functionName,
|
52
53
|
}));
|
53
54
|
return [proof, ...result];
|
54
55
|
},
|
@@ -39,14 +39,14 @@ describe("Success zk-proving", () => {
|
|
39
39
|
const webProofProvider = createExtensionWebProofProvider();
|
40
40
|
const zkProvingSpy = vi.spyOn(webProofProvider, "notifyZkProvingStatus");
|
41
41
|
const vlayer = createVlayerClient({ webProofProvider });
|
42
|
-
const
|
42
|
+
const hash = await vlayer.prove({
|
43
43
|
address: `0x${"a".repeat(40)}`,
|
44
44
|
functionName: "main",
|
45
45
|
proverAbi: [],
|
46
46
|
args: [],
|
47
47
|
chainId: 42,
|
48
48
|
});
|
49
|
-
await vlayer.waitForProvingResult(
|
49
|
+
await vlayer.waitForProvingResult(hash);
|
50
50
|
expect(zkProvingSpy).toBeCalledTimes(2);
|
51
51
|
expect(zkProvingSpy).toHaveBeenNthCalledWith(1, ZkProvingStatus.Proving);
|
52
52
|
expect(zkProvingSpy).toHaveBeenNthCalledWith(2, ZkProvingStatus.Done);
|
@@ -67,7 +67,7 @@ describe("Failed zk-proving", () => {
|
|
67
67
|
const webProofProvider = createExtensionWebProofProvider();
|
68
68
|
const zkProvingSpy = vi.spyOn(webProofProvider, "notifyZkProvingStatus");
|
69
69
|
const vlayer = createVlayerClient({ webProofProvider });
|
70
|
-
const
|
70
|
+
const hash = await vlayer.prove({
|
71
71
|
address: `0x${"a".repeat(40)}`,
|
72
72
|
functionName: "main",
|
73
73
|
proverAbi: [],
|
@@ -75,7 +75,7 @@ describe("Failed zk-proving", () => {
|
|
75
75
|
chainId: 42,
|
76
76
|
});
|
77
77
|
try {
|
78
|
-
await vlayer.waitForProvingResult(
|
78
|
+
await vlayer.waitForProvingResult(hash);
|
79
79
|
}
|
80
80
|
catch (e) {
|
81
81
|
console.log("Error waiting for proving result", e);
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { Branded } from "../../../web-proof-commons/utils.js";
|
2
|
+
import { Abi, AbiStateMutability, Address, ContractFunctionArgs, ContractFunctionName, ContractFunctionReturnType, Hex } from "viem";
|
2
3
|
type Calldata = string;
|
3
4
|
export type CallParams = {
|
4
5
|
to: Address;
|
@@ -7,6 +8,9 @@ export type CallParams = {
|
|
7
8
|
export type CallContext = {
|
8
9
|
chain_id: number;
|
9
10
|
};
|
11
|
+
export type BrandedHash<T, F> = Branded<{
|
12
|
+
hash: string;
|
13
|
+
}, [T, F]>;
|
10
14
|
export type Proof = {
|
11
15
|
seal: {
|
12
16
|
verifierSelector: Hex;
|
@@ -36,13 +40,9 @@ export type VlayerClient = {
|
|
36
40
|
address: Hex;
|
37
41
|
proverAbi: T;
|
38
42
|
functionName: F;
|
39
|
-
chainId
|
43
|
+
chainId?: number;
|
40
44
|
args: ContractFunctionArgs<T, AbiStateMutability, F>;
|
41
|
-
}) => Promise<
|
42
|
-
|
43
|
-
}>;
|
44
|
-
waitForProvingResult: ({ hash, }: {
|
45
|
-
hash: string;
|
46
|
-
}) => Promise<[Proof, ...unknown[]]>;
|
45
|
+
}) => Promise<BrandedHash<T, F>>;
|
46
|
+
waitForProvingResult: <T extends Abi, F extends ContractFunctionName<T>>(hash: BrandedHash<T, F>) => Promise<ContractFunctionReturnType<T, AbiStateMutability, F>>;
|
47
47
|
};
|
48
48
|
export {};
|