@vlayer/sdk 0.1.0-nightly-20241112-4be2839 → 0.1.0-nightly-20241113-0b85bf8

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 { result: { proof, evm_call_result }, } = await savedProvingData[0];
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: savedProvingData[1],
50
+ abi: proverAbi,
50
51
  data: evm_call_result,
51
- functionName: savedProvingData[2],
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 { hash } = await vlayer.prove({
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({ hash });
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 { hash } = await vlayer.prove({
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({ hash });
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 { Abi, AbiStateMutability, Address, ContractFunctionArgs, ContractFunctionName, Hex } from "viem";
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;
@@ -38,11 +42,7 @@ export type VlayerClient = {
38
42
  functionName: F;
39
43
  chainId: number;
40
44
  args: ContractFunctionArgs<T, AbiStateMutability, F>;
41
- }) => Promise<{
42
- hash: string;
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 {};
@@ -16,9 +16,6 @@ class ExtensionWebProofProvider {
16
16
  payload: { status },
17
17
  });
18
18
  }
19
- else {
20
- console.log("Run out of chrome context");
21
- }
22
19
  }
23
20
  connectToExtension() {
24
21
  if (!this.port) {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "types": "./dist/api/webProof/index.d.ts"
12
12
  }
13
13
  },
14
- "version": "0.1.0-nightly-20241112-4be2839",
14
+ "version": "0.1.0-nightly-20241113-0b85bf8",
15
15
  "scripts": {
16
16
  "build": "bun tsc && bun tsc-alias",
17
17
  "test:unit": "vitest --run",