@vlayer/sdk 0.1.0-nightly-20241122-7018b34 → 0.1.0-nightly-20241125-3bf0279

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,9 +18,9 @@ export const createVlayerClient = ({ url = "http://127.0.0.1:3000", webProofProv
18
18
  }) => {
19
19
  const resultHashMap = new Map();
20
20
  return {
21
- prove: async ({ address, functionName, chainId, proverAbi, args }) => {
21
+ prove: async ({ address, functionName, chainId, gasLimit, proverAbi, args, }) => {
22
22
  webProofProvider.notifyZkProvingStatus(ZkProvingStatus.Proving);
23
- const response = prove(address, proverAbi, functionName, args, chainId, url)
23
+ const response = prove(address, proverAbi, functionName, args, chainId, gasLimit, url)
24
24
  .catch((error) => {
25
25
  webProofProvider.notifyZkProvingStatus(ZkProvingStatus.Error);
26
26
  throw error;
@@ -51,5 +51,36 @@ export const createVlayerClient = ({ url = "http://127.0.0.1:3000", webProofProv
51
51
  }));
52
52
  return [proof, ...result];
53
53
  },
54
+ proveWeb: async function ({ address, proverAbi, functionName, chainId, args, }) {
55
+ const webProofPlaceholder = args[0];
56
+ const commitmentArgs = args.slice(1);
57
+ const webProof = await webProofProvider.getWebProof({
58
+ proverCallCommitment: {
59
+ address,
60
+ proverAbi,
61
+ functionName,
62
+ commitmentArgs,
63
+ chainId,
64
+ },
65
+ logoUrl: webProofPlaceholder.logoUrl,
66
+ steps: webProofPlaceholder.steps,
67
+ });
68
+ const hash = await this.prove({
69
+ address,
70
+ functionName,
71
+ chainId,
72
+ proverAbi,
73
+ args: [
74
+ {
75
+ webProofJson: JSON.stringify({
76
+ tls_proof: webProof,
77
+ notary_pub_key: webProofPlaceholder.notaryPubKey,
78
+ }),
79
+ },
80
+ ...commitmentArgs,
81
+ ],
82
+ });
83
+ return hash;
84
+ },
54
85
  };
55
86
  };
@@ -4,5 +4,5 @@ type Without<T extends readonly unknown[], P> = T extends readonly [
4
4
  infer F,
5
5
  ...infer R
6
6
  ] ? F extends P ? Without<R, P> : readonly [F, ...Without<R, P>] : [];
7
- export type ContractFunctionArgsWithout<abi extends Abi, functionName extends ContractFunctionName<abi>, without> = AbiParametersToPrimitiveTypes<Without<ExtractAbiFunction<abi extends Abi ? abi : Abi, functionName>["inputs"], without>, "inputs"> extends infer args ? [args] extends [never] ? readonly unknown[] : args : readonly unknown[];
7
+ export type ContractFunctionArgsWithout<abi extends Abi, functionName extends ContractFunctionName<abi>, without> = AbiParametersToPrimitiveTypes<Without<ExtractAbiFunction<abi extends Abi ? abi : Abi, functionName>["inputs"], without>, "inputs">;
8
8
  export {};
@@ -1,5 +1,7 @@
1
1
  import { Branded } from "../../../web-proof-commons/utils.js";
2
2
  import { Abi, AbiStateMutability, Address, ContractFunctionArgs, ContractFunctionName, ContractFunctionReturnType, Hex } from "viem";
3
+ import { WebProofRequest } from "./webProofProvider.js";
4
+ import { ContractFunctionArgsWithout } from "./viem.js";
3
5
  type Calldata = string;
4
6
  export type CallParams = {
5
7
  to: Address;
@@ -7,6 +9,7 @@ export type CallParams = {
7
9
  };
8
10
  export type CallContext = {
9
11
  chain_id: number;
12
+ gas_limit: number;
10
13
  };
11
14
  export type BrandedHash<T, F> = Branded<{
12
15
  hash: string;
@@ -42,8 +45,21 @@ export type VlayerClient = {
42
45
  proverAbi: T;
43
46
  functionName: F;
44
47
  chainId?: number;
48
+ gasLimit?: number;
45
49
  args: ContractFunctionArgs<T, AbiStateMutability, F>;
46
50
  }) => Promise<BrandedHash<T, F>>;
47
51
  waitForProvingResult: <T extends Abi, F extends ContractFunctionName<T>>(hash: BrandedHash<T, F>) => Promise<ContractFunctionReturnType<T, AbiStateMutability, F>>;
52
+ proveWeb: <T extends Abi, F extends ContractFunctionName<T>>(args: {
53
+ address: Hex;
54
+ proverAbi: T;
55
+ functionName: F;
56
+ chainId: number;
57
+ args: [
58
+ WebProofRequest,
59
+ ...ContractFunctionArgsWithout<T, F, {
60
+ name: "webProof";
61
+ }>
62
+ ];
63
+ }) => Promise<BrandedHash<T, F>>;
48
64
  };
49
65
  export {};
@@ -1,11 +1,12 @@
1
1
  import { Hex, Abi, ContractFunctionName } from "viem";
2
2
  import type { ContractFunctionArgsWithout } from "./viem.js";
3
3
  import { Branded, ExtensionMessageType, ExtensionMessage, WebProof, WebProofStep, ZkProvingStatus } from "../../../web-proof-commons/index.js";
4
- export type WebProofSetupInput = {
4
+ export type WebProofRequestInput = {
5
5
  logoUrl: string;
6
6
  steps: WebProofStep[];
7
+ notaryPubKey?: string;
7
8
  };
8
- export type WebProofSetup = Branded<WebProofSetupInput & {
9
+ export type WebProofRequest = Branded<WebProofRequestInput & {
9
10
  isWebProof: true;
10
11
  }, "webProof">;
11
12
  export type ProverCallCommitment<T extends Abi, F extends ContractFunctionName<T>> = {
@@ -19,7 +20,7 @@ export type ProverCallCommitment<T extends Abi, F extends ContractFunctionName<T
19
20
  };
20
21
  export type GetWebProofArgs<T extends Abi, F extends ContractFunctionName<T>> = {
21
22
  proverCallCommitment: ProverCallCommitment<T, F>;
22
- } & WebProofSetupInput;
23
+ } & WebProofRequestInput;
23
24
  export type WebProofProvider = {
24
25
  getWebProof: <T extends Abi, F extends ContractFunctionName<T>>(args: GetWebProofArgs<T, F>) => Promise<WebProof>;
25
26
  requestWebProof: <T extends Abi, F extends ContractFunctionName<T>>(args: GetWebProofArgs<T, F>) => void;
@@ -1,2 +1,2 @@
1
1
  import { type Abi, AbiStateMutability, type Address, ContractFunctionArgs, ContractFunctionName } from "viem";
2
- export declare function prove<T extends Abi, F extends ContractFunctionName<T>>(prover: Address, abi: T, functionName: F, args: ContractFunctionArgs<T, AbiStateMutability, F>, chainId?: number, url?: string): Promise<import("./lib/types/vlayer.js").VCallResponse>;
2
+ 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): Promise<import("./lib/types/vlayer.js").VCallResponse>;
@@ -1,7 +1,7 @@
1
1
  import { encodeFunctionData, } from "viem";
2
2
  import { v_call } from "./v_call.js";
3
3
  import { foundry } from "viem/chains";
4
- export async function prove(prover, abi, functionName, args, chainId = foundry.id, url = "http://127.0.0.1:3000") {
4
+ export async function prove(prover, abi, functionName, args, chainId = foundry.id, gasLimit = 1_000_000, url = "http://127.0.0.1:3000") {
5
5
  const calldata = encodeFunctionData({
6
6
  abi: abi,
7
7
  functionName: functionName,
@@ -10,6 +10,7 @@ export async function prove(prover, abi, functionName, args, chainId = foundry.i
10
10
  const call = { to: prover, data: calldata };
11
11
  const context = {
12
12
  chain_id: chainId,
13
+ gas_limit: gasLimit,
13
14
  };
14
15
  return v_call(call, context, url);
15
16
  }
@@ -0,0 +1,2 @@
1
+ import { WebProofRequest, WebProofRequestInput } from "../lib/types/webProofProvider.js";
2
+ export declare const createWebProofRequest: ({ logoUrl, steps, notaryPubKey, }: WebProofRequestInput) => WebProofRequest;
@@ -0,0 +1,9 @@
1
+ const NOTARY_PUB_KEY = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAExpX/4R4z40gI6C/j9zAM39u58LJu\n3Cx5tXTuqhhu/tirnBi5GniMmspOTEsps4ANnPLpMmMSfhJ+IFHbc3qVOA==\n-----END PUBLIC KEY-----\n";
2
+ export const createWebProofRequest = ({ logoUrl, steps, notaryPubKey = NOTARY_PUB_KEY, }) => {
3
+ return {
4
+ logoUrl,
5
+ steps,
6
+ notaryPubKey,
7
+ isWebProof: true,
8
+ };
9
+ };
@@ -1,3 +1,3 @@
1
- export * from "./createWebProof.js";
1
+ export * from "./createWebProofRequest.js";
2
2
  export * from "./steps/index.js";
3
3
  export * from "./providers/index.js";
@@ -1,3 +1,3 @@
1
- export * from "./createWebProof.js";
1
+ export * from "./createWebProofRequest.js";
2
2
  export * from "./steps/index.js";
3
3
  export * from "./providers/index.js";
@@ -11,10 +11,21 @@ class ExtensionWebProofProvider {
11
11
  }
12
12
  notifyZkProvingStatus(status) {
13
13
  if (typeof chrome !== "undefined") {
14
- chrome.runtime.sendMessage(EXTENSION_ID, {
15
- action: "NotifyZkProvingStatus" /* ExtensionAction.NotifyZkProvingStatus */,
16
- payload: { status },
17
- });
14
+ // Chrome does not provide reliable api to check if given extension is installed
15
+ // what we could do is to use management api but
16
+ // 1) this will need to provided extra permission
17
+ // 2) still is not reliable because this api becomes defined when first extension that uses it is installed
18
+ // so still will need to try catch
19
+ try {
20
+ chrome.runtime.sendMessage(EXTENSION_ID, {
21
+ action: "NotifyZkProvingStatus" /* ExtensionAction.NotifyZkProvingStatus */,
22
+ payload: { status },
23
+ });
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
+ }
26
+ catch (e) {
27
+ console.log("Cant send message", "look that extension is not installed ");
28
+ }
18
29
  }
19
30
  }
20
31
  connectToExtension() {
@@ -42,26 +53,26 @@ class ExtensionWebProofProvider {
42
53
  }
43
54
  this.listeners[messageType].push(listener);
44
55
  }
45
- requestWebProof(webProofSetup) {
56
+ requestWebProof(webProofRequest) {
46
57
  this.connectToExtension().postMessage({
47
58
  action: "RequestWebProof" /* ExtensionAction.RequestWebProof */,
48
59
  payload: {
49
60
  notaryUrl: this.notaryUrl,
50
61
  wsProxyUrl: this.wsProxyUrl,
51
- logoUrl: webProofSetup.logoUrl,
52
- steps: webProofSetup.steps,
62
+ logoUrl: webProofRequest.logoUrl,
63
+ steps: webProofRequest.steps,
53
64
  },
54
65
  });
55
66
  }
56
- async getWebProof(webProofSetup) {
67
+ async getWebProof(webProofRequest) {
57
68
  return new Promise((resolve, reject) => {
58
69
  chrome.runtime.sendMessage(EXTENSION_ID, {
59
70
  action: "RequestWebProof" /* ExtensionAction.RequestWebProof */,
60
71
  payload: {
61
72
  notaryUrl: this.notaryUrl,
62
73
  wsProxyUrl: this.wsProxyUrl,
63
- logoUrl: webProofSetup.logoUrl,
64
- steps: webProofSetup.steps,
74
+ logoUrl: webProofRequest.logoUrl,
75
+ steps: webProofRequest.steps,
65
76
  },
66
77
  });
67
78
  this.connectToExtension().onMessage.addListener((message) => {
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "types": "./dist/config/index.d.ts"
16
16
  }
17
17
  },
18
- "version": "0.1.0-nightly-20241122-7018b34",
18
+ "version": "0.1.0-nightly-20241125-3bf0279",
19
19
  "scripts": {
20
20
  "build": "bun tsc && bun tsc-alias",
21
21
  "test:unit": "vitest --run",
@@ -1,2 +0,0 @@
1
- import { WebProofSetup, WebProofSetupInput } from "../lib/types/webProofProvider.js";
2
- export declare const createWebProof: ({ logoUrl, steps }: WebProofSetupInput) => WebProofSetup;
@@ -1,7 +0,0 @@
1
- export const createWebProof = ({ logoUrl, steps }) => {
2
- return {
3
- logoUrl,
4
- steps,
5
- isWebProof: true,
6
- };
7
- };