@vlayer/sdk 0.1.0-nightly-20241009-483ba9f → 0.1.0-nightly-20241009-3c85ef5

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.
@@ -0,0 +1 @@
1
+ export * from "./lib";
@@ -0,0 +1 @@
1
+ export * from "./message";
@@ -0,0 +1,20 @@
1
+ export const enum ExtensionAction {
2
+ RequestWebProof,
3
+ }
4
+
5
+ export const enum ExtensionMessageType {
6
+ ProofDone = "ProofDone",
7
+ ProofError = "ProofError",
8
+ RedirectBack = "RedirectBack",
9
+ }
10
+
11
+ export type ExtensionMessage =
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ | { type: ExtensionMessageType.ProofDone; proof: any } // Change to WebProof
14
+ | { type: ExtensionMessageType.ProofError; error: string }
15
+ | { type: ExtensionMessageType.RedirectBack };
16
+
17
+ export type WebProverSessionConfig = {
18
+ notaryUrl: string;
19
+ wsProxyUrl: string;
20
+ };
@@ -4,6 +4,10 @@
4
4
  "version": "1.0.0",
5
5
  "module": "index.ts",
6
6
  "type": "module",
7
+ "scripts": {
8
+ "lint": "eslint lib",
9
+ "lint:fix": "eslint --fix lib"
10
+ },
7
11
  "devDependencies": {
8
12
  "@types/bun": "latest"
9
13
  },
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@vlayer/sdk",
3
3
  "type": "module",
4
4
  "module": "src/index.ts",
5
- "version": "0.1.0-nightly-20241009-483ba9f",
5
+ "version": "0.1.0-nightly-20241009-3c85ef5",
6
6
  "types": "src/index.ts",
7
7
  "scripts": {
8
8
  "build": "npm run gen:types",
@@ -2,18 +2,24 @@ import { VlayerClient } from "types/vlayer";
2
2
  import { WebProofProvider } from "types/webProofProvider";
3
3
 
4
4
  import { prove } from "../prover";
5
- export const createVlayerClient = ({
6
- url,
7
- webProofProvider,
8
- }: {
9
- url: string;
10
- webProofProvider: WebProofProvider;
11
- }): VlayerClient => {
5
+ import { createExtensionWebProofProvider } from "../webProof";
6
+ export const createVlayerClient = (
7
+ {
8
+ url = "http://127.0.0.1:3000",
9
+ webProofProvider = createExtensionWebProofProvider(),
10
+ }: {
11
+ url?: string;
12
+ webProofProvider?: WebProofProvider;
13
+ } = {
14
+ url: "http://127.0.0.1:3000",
15
+ webProofProvider: createExtensionWebProofProvider(),
16
+ },
17
+ ): VlayerClient => {
12
18
  // TODO : implement high level api
13
19
  console.log("createVlayerClient with", url, webProofProvider);
14
20
  return {
15
21
  prove: async ({ address, functionName, chainId, proverAbi, args }) => {
16
- return prove(address, proverAbi, functionName, args, chainId);
22
+ return prove(address, proverAbi, functionName, args, chainId, url);
17
23
  },
18
24
  };
19
25
  };
package/src/api/prover.ts CHANGED
@@ -27,6 +27,7 @@ export async function prove<
27
27
  functionName: F,
28
28
  args: ContractFunctionArgs<T, AbiStateMutability, F>,
29
29
  chainId: number = foundry.id,
30
+ url: string = "http://127.0.0.1:3000",
30
31
  ) {
31
32
  const calldata = encodeFunctionData({
32
33
  abi: abi as Abi,
@@ -41,14 +42,14 @@ export async function prove<
41
42
 
42
43
  const {
43
44
  result: { proof, evm_call_result },
44
- } = await v_call(call, context);
45
+ } = await v_call(call, context, url);
45
46
 
46
- const [, ...returnValue] = decodeFunctionResult({
47
+ const [, ...result] = decodeFunctionResult({
47
48
  abi: abi as Abi,
48
49
  data: evm_call_result,
49
50
  functionName: functionName as string,
50
51
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
52
  }) as any[];
52
53
 
53
- return { proof, returnValue };
54
+ return { proof, result };
54
55
  }
package/src/api/v_call.ts CHANGED
@@ -12,8 +12,9 @@ function v_callBody(call: CallParams, context: CallContext) {
12
12
  export async function v_call(
13
13
  call: CallParams,
14
14
  context: CallContext,
15
+ url: string = "http://127.0.0.1:3000",
15
16
  ): Promise<VCallResponse> {
16
- const response = await fetch("http://127.0.0.1:3000", {
17
+ const response = await fetch(url, {
17
18
  method: "POST",
18
19
  body: JSON.stringify(v_callBody(call, context)),
19
20
  headers: { "Content-Type": "application/json" },
@@ -7,7 +7,8 @@ import {
7
7
  import {
8
8
  ExtensionAction,
9
9
  ExtensionMessage,
10
- } from "@vlayer/web-proof-commons/constants/message";
10
+ ExtensionMessageType,
11
+ } from "@vlayer/web-proof-commons";
11
12
 
12
13
  import { WebProof } from "../../lib/types/webProof";
13
14
 
@@ -31,10 +32,15 @@ declare const chrome: {
31
32
  // this id is fixed in the extension by the key in manifest.json
32
33
  const EXTENSION_ID = "ghigbilfcgeibjkkajaekabeldkmijcd";
33
34
 
34
- export const createExtensionWebProofProvider = ({
35
- notaryUrl = "https://notary.pse.dev/v0.1.0-alpha.5/",
36
- wsProxyUrl = "wss://notary.pse.dev/proxy",
37
- }: WebProofProviderSetup): WebProofProvider => {
35
+ export const createExtensionWebProofProvider = (
36
+ {
37
+ notaryUrl = "https://notary.pse.dev/v0.1.0-alpha.5/",
38
+ wsProxyUrl = "wss://notary.pse.dev/proxy",
39
+ }: WebProofProviderSetup = {
40
+ notaryUrl: "https://notary.pse.dev/v0.1.0-alpha.5/",
41
+ wsProxyUrl: "wss://notary.pse.dev/proxy",
42
+ },
43
+ ): WebProofProvider => {
38
44
  return {
39
45
  getWebProof: async function (webProofSetup: WebProofSetupInput) {
40
46
  return new Promise<WebProof>((resolve, reject) => {
@@ -49,26 +55,14 @@ export const createExtensionWebProofProvider = ({
49
55
  });
50
56
  const port = chrome.runtime.connect(EXTENSION_ID);
51
57
  // TODO: validate message in runtime
52
- port.onMessage.addListener(
53
- (
54
- message:
55
- | {
56
- type: ExtensionMessage.ProofDone;
57
- proof: WebProof;
58
- }
59
- | {
60
- type: ExtensionMessage.ProofError;
61
- error: { message: string };
62
- },
63
- ) => {
64
- if (message.type === ExtensionMessage.ProofDone) {
65
- resolve(message.proof);
66
- }
67
- if (message.type === ExtensionMessage.ProofError) {
68
- reject(message.error);
69
- }
70
- },
71
- );
58
+ port.onMessage.addListener((message: ExtensionMessage) => {
59
+ if (message.type === ExtensionMessageType.ProofDone) {
60
+ resolve(message.proof);
61
+ }
62
+ if (message.type === ExtensionMessageType.ProofError) {
63
+ reject(message.error);
64
+ }
65
+ });
72
66
  });
73
67
  },
74
68
  };
package/src/index.ts CHANGED
@@ -2,10 +2,11 @@ export { v_call } from "./api/v_call";
2
2
  export type { CallParams, CallContext } from "types/vlayer";
3
3
  export type { ContractSpec } from "types/ethereum";
4
4
 
5
- export { getContractSpec, prove } from "./api/prover";
5
+ export { getContractSpec } from "./api/prover";
6
6
  export * as testHelpers from "./api/helpers";
7
7
  export { client as createTestClient } from "./api/helpers";
8
8
  export { preverifyEmail } from "./api/email/preverify.ts";
9
+ export { createVlayerClient } from "./api/lib/client.ts";
9
10
 
10
11
  export * from "./api/webProof";
11
12
  export * from "./api/lib/types";
@@ -1,13 +0,0 @@
1
- export const enum ExtensionAction {
2
- RequestWebProof,
3
- }
4
-
5
- export const enum ExtensionMessage {
6
- ProofDone,
7
- ProofError,
8
- }
9
-
10
- export type WebProverSessionConfig = {
11
- notaryUrl: string;
12
- wsProxyUrl: string;
13
- };