@vlayer/sdk 0.1.0-nightly-20241009-483ba9f → 0.1.0-nightly-20241009-3c85ef5
Sign up to get free protection for your applications and to get access to all the features.
- package/node_modules/@vlayer/web-proof-commons/index.ts +1 -0
- package/node_modules/@vlayer/web-proof-commons/lib/index.ts +1 -0
- package/node_modules/@vlayer/web-proof-commons/lib/message.ts +20 -0
- package/node_modules/@vlayer/web-proof-commons/package.json +4 -0
- package/package.json +1 -1
- package/src/api/lib/client.ts +14 -8
- package/src/api/prover.ts +4 -3
- package/src/api/v_call.ts +2 -1
- package/src/api/webProof/providers/extension.ts +19 -25
- package/src/index.ts +2 -1
- package/node_modules/@vlayer/web-proof-commons/constants/message.ts +0 -13
@@ -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
|
+
};
|
package/package.json
CHANGED
package/src/api/lib/client.ts
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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 [, ...
|
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,
|
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(
|
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
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
57
|
-
|
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
|
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";
|