@vlayer/sdk 0.1.0-nightly-20241009-483ba9f → 0.1.0-nightly-20241009-c348db7

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-c348db7",
6
6
  "types": "src/index.ts",
7
7
  "scripts": {
8
8
  "build": "npm run gen:types",
@@ -21,7 +21,7 @@ const rpcUrls: Map<number, HttpTransport> = new Map([[foundry.id, http()]]);
21
21
 
22
22
  export const chainIds = [foundry.id];
23
23
 
24
- export function client(
24
+ export function createAnvilClient(
25
25
  chainId: number = foundry.id,
26
26
  ): ReturnType<typeof walletActions> & PublicClient {
27
27
  const transport = rpcUrls.get(chainId);
@@ -43,7 +43,7 @@ export async function deployContract(
43
43
  args: ContractArg[] = [],
44
44
  chainId: number = foundry.id,
45
45
  ): Promise<Address> {
46
- const ethClient = client(chainId);
46
+ const ethClient = createAnvilClient(chainId);
47
47
 
48
48
  const [deployer] = await ethClient.getAddresses();
49
49
 
@@ -113,7 +113,7 @@ export async function call<
113
113
  args?: ContractFunctionArgs<T, "pure" | "view", F>,
114
114
  chainId: number = foundry.id,
115
115
  ) {
116
- const ethClient = client(chainId);
116
+ const ethClient = createAnvilClient(chainId);
117
117
 
118
118
  return ethClient.readContract({
119
119
  abi,
@@ -134,7 +134,7 @@ export async function writeContract<
134
134
  sender?: Address,
135
135
  chainId: number = foundry.id,
136
136
  ) {
137
- const ethClient = client(chainId);
137
+ const ethClient = createAnvilClient(chainId);
138
138
  const selectedSender = sender || (await ethClient.getAddresses())[0];
139
139
 
140
140
  const txHash = await ethClient.writeContract({
@@ -160,4 +160,4 @@ export const getTestAccount = () => privateKeyToAccount(generatePrivateKey());
160
160
 
161
161
  export const getTestAddresses = (
162
162
  chainId: number = foundry.id,
163
- ): Promise<Address[]> => client(chainId).getAddresses();
163
+ ): Promise<Address[]> => createAnvilClient(chainId).getAddresses();
@@ -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
@@ -11,13 +11,8 @@ import {
11
11
 
12
12
  import { type CallContext, type CallParams } from "types/vlayer";
13
13
  import { v_call } from "./v_call";
14
- import { ContractSpec } from "types/ethereum";
15
14
  import { foundry } from "viem/chains";
16
15
 
17
- export async function getContractSpec(file: string): Promise<ContractSpec> {
18
- return Bun.file(file).json();
19
- }
20
-
21
16
  export async function prove<
22
17
  T extends readonly [AbiFunction, ...Abi[number][]],
23
18
  F extends ContractFunctionName<T>,
@@ -27,6 +22,7 @@ export async function prove<
27
22
  functionName: F,
28
23
  args: ContractFunctionArgs<T, AbiStateMutability, F>,
29
24
  chainId: number = foundry.id,
25
+ url: string = "http://127.0.0.1:3000",
30
26
  ) {
31
27
  const calldata = encodeFunctionData({
32
28
  abi: abi as Abi,
@@ -41,14 +37,14 @@ export async function prove<
41
37
 
42
38
  const {
43
39
  result: { proof, evm_call_result },
44
- } = await v_call(call, context);
40
+ } = await v_call(call, context, url);
45
41
 
46
- const [, ...returnValue] = decodeFunctionResult({
42
+ const [, ...result] = decodeFunctionResult({
47
43
  abi: abi as Abi,
48
44
  data: evm_call_result,
49
45
  functionName: functionName as string,
50
46
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
47
  }) as any[];
52
48
 
53
- return { proof, returnValue };
49
+ return { proof, result };
54
50
  }
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
@@ -1,11 +1,6 @@
1
- export { v_call } from "./api/v_call";
2
- export type { CallParams, CallContext } from "types/vlayer";
3
- export type { ContractSpec } from "types/ethereum";
4
-
5
- export { getContractSpec, prove } from "./api/prover";
6
1
  export * as testHelpers from "./api/helpers";
7
- export { client as createTestClient } from "./api/helpers";
8
2
  export { preverifyEmail } from "./api/email/preverify.ts";
3
+ export { createVlayerClient } from "./api/lib/client.ts";
9
4
 
10
5
  export * from "./api/webProof";
11
6
  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
- };