@vlayer/sdk 0.1.0-nightly-20241009-c348db7 → 0.1.0-nightly-20241010-e69694a
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.
- package/node_modules/@vlayer/web-proof-commons/lib/index.ts +1 -0
- package/node_modules/@vlayer/web-proof-commons/lib/message.ts +51 -0
- package/node_modules/@vlayer/web-proof-commons/lib/utils.ts +12 -0
- package/package.json +1 -1
- package/src/api/lib/client.ts +53 -2
- package/src/api/lib/types/ethereum.ts +1 -1
- package/src/api/lib/types/index.ts +0 -1
- package/src/api/lib/types/vlayer.ts +6 -1
- package/src/api/lib/types/webProofProvider.ts +6 -38
- package/src/api/prover.ts +1 -13
- package/src/api/webProof/providers/extension.ts +6 -2
- package/src/api/webProof/steps/expectUrl.ts +1 -1
- package/src/api/webProof/steps/notarize.ts +1 -1
- package/src/api/webProof/steps/startPage.ts +1 -1
- package/src/api/lib/types/utils.ts +0 -3
@@ -1,7 +1,23 @@
|
|
1
|
+
import type { Branded } from "./utils.ts";
|
2
|
+
|
3
|
+
export const EXTENSION_STEP = {
|
4
|
+
expectUrl: "expectUrl",
|
5
|
+
startPage: "startPage",
|
6
|
+
notarize: "notarize",
|
7
|
+
} as const;
|
8
|
+
|
9
|
+
export type ExtensionStep =
|
10
|
+
(typeof EXTENSION_STEP)[keyof typeof EXTENSION_STEP];
|
11
|
+
|
1
12
|
export const enum ExtensionAction {
|
2
13
|
RequestWebProof,
|
3
14
|
}
|
4
15
|
|
16
|
+
export type MessageToExtension = {
|
17
|
+
action: ExtensionAction;
|
18
|
+
payload: WebProverSessionConfig;
|
19
|
+
};
|
20
|
+
|
5
21
|
export const enum ExtensionMessageType {
|
6
22
|
ProofDone = "ProofDone",
|
7
23
|
ProofError = "ProofError",
|
@@ -17,4 +33,39 @@ export type ExtensionMessage =
|
|
17
33
|
export type WebProverSessionConfig = {
|
18
34
|
notaryUrl: string;
|
19
35
|
wsProxyUrl: string;
|
36
|
+
logoUrl: string;
|
37
|
+
steps: WebProofStep[];
|
20
38
|
};
|
39
|
+
|
40
|
+
export type WebProofStep =
|
41
|
+
| WebProofStepNotarize
|
42
|
+
| WebProofStepExpectUrl
|
43
|
+
| WebProofStepStartPage;
|
44
|
+
|
45
|
+
export type WebProofStepNotarize = Branded<
|
46
|
+
{
|
47
|
+
url: string;
|
48
|
+
method: string;
|
49
|
+
label: string;
|
50
|
+
step: typeof EXTENSION_STEP.notarize;
|
51
|
+
},
|
52
|
+
"notarize"
|
53
|
+
>;
|
54
|
+
|
55
|
+
export type WebProofStepExpectUrl = Branded<
|
56
|
+
{
|
57
|
+
url: string;
|
58
|
+
label: string;
|
59
|
+
step: typeof EXTENSION_STEP.expectUrl;
|
60
|
+
},
|
61
|
+
"expectUrl"
|
62
|
+
>;
|
63
|
+
|
64
|
+
export type WebProofStepStartPage = Branded<
|
65
|
+
{
|
66
|
+
url: string;
|
67
|
+
label: string;
|
68
|
+
step: typeof EXTENSION_STEP.startPage;
|
69
|
+
},
|
70
|
+
"startPage"
|
71
|
+
>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
declare const __brand: unique symbol;
|
2
|
+
type Brand<B> = { [__brand]: B };
|
3
|
+
export type Branded<T, B> = T & Brand<B>;
|
4
|
+
|
5
|
+
export function isDefined<T>(
|
6
|
+
value: T | undefined,
|
7
|
+
message: string = "Value is undefined",
|
8
|
+
): asserts value is T {
|
9
|
+
if (value === undefined) {
|
10
|
+
throw new Error(message);
|
11
|
+
}
|
12
|
+
}
|
package/package.json
CHANGED
package/src/api/lib/client.ts
CHANGED
@@ -1,8 +1,25 @@
|
|
1
|
-
import { VlayerClient } from "types/vlayer";
|
1
|
+
import { VCallResponse, VlayerClient } from "types/vlayer";
|
2
2
|
import { WebProofProvider } from "types/webProofProvider";
|
3
3
|
|
4
4
|
import { prove } from "../prover";
|
5
5
|
import { createExtensionWebProofProvider } from "../webProof";
|
6
|
+
import { type Abi, decodeFunctionResult } from "viem";
|
7
|
+
|
8
|
+
function dropProofFromArgs(args: unknown) {
|
9
|
+
if (Array.isArray(args)) {
|
10
|
+
return args.slice(1);
|
11
|
+
}
|
12
|
+
return [];
|
13
|
+
}
|
14
|
+
|
15
|
+
function generateRandomHash() {
|
16
|
+
let hash = "0x";
|
17
|
+
for (let i = 0; i < 40; ++i) {
|
18
|
+
hash += Math.floor(Math.random() * 16).toString(16);
|
19
|
+
}
|
20
|
+
return hash;
|
21
|
+
}
|
22
|
+
|
6
23
|
export const createVlayerClient = (
|
7
24
|
{
|
8
25
|
url = "http://127.0.0.1:3000",
|
@@ -17,9 +34,43 @@ export const createVlayerClient = (
|
|
17
34
|
): VlayerClient => {
|
18
35
|
// TODO : implement high level api
|
19
36
|
console.log("createVlayerClient with", url, webProofProvider);
|
37
|
+
const resultHashMap = new Map<
|
38
|
+
string,
|
39
|
+
[Promise<VCallResponse>, Abi, string]
|
40
|
+
>();
|
41
|
+
|
20
42
|
return {
|
21
43
|
prove: async ({ address, functionName, chainId, proverAbi, args }) => {
|
22
|
-
|
44
|
+
const result_promise = prove(
|
45
|
+
address,
|
46
|
+
proverAbi,
|
47
|
+
functionName,
|
48
|
+
args,
|
49
|
+
chainId,
|
50
|
+
url,
|
51
|
+
);
|
52
|
+
const hash = generateRandomHash();
|
53
|
+
resultHashMap.set(hash, [result_promise, proverAbi, functionName]);
|
54
|
+
return { hash };
|
55
|
+
},
|
56
|
+
waitForProvingResult: async ({ hash }) => {
|
57
|
+
const savedProvingData = resultHashMap.get(hash);
|
58
|
+
if (!savedProvingData) {
|
59
|
+
throw new Error("No result found for hash " + hash);
|
60
|
+
}
|
61
|
+
const {
|
62
|
+
result: { proof, evm_call_result },
|
63
|
+
} = await savedProvingData[0];
|
64
|
+
|
65
|
+
const result = dropProofFromArgs(
|
66
|
+
decodeFunctionResult({
|
67
|
+
abi: savedProvingData[1] as Abi,
|
68
|
+
data: evm_call_result,
|
69
|
+
functionName: savedProvingData[2] as string,
|
70
|
+
}),
|
71
|
+
);
|
72
|
+
|
73
|
+
return { proof, result };
|
23
74
|
},
|
24
75
|
};
|
25
76
|
};
|
@@ -66,7 +66,12 @@ export type VlayerClient = {
|
|
66
66
|
F extends ContractFunctionName<T>,
|
67
67
|
>(
|
68
68
|
args: VlayerClientProveArgs<T, F>,
|
69
|
-
) =>
|
69
|
+
) => Promise<{ hash: string }>;
|
70
|
+
waitForProvingResult: ({
|
71
|
+
hash,
|
72
|
+
}: {
|
73
|
+
hash: string;
|
74
|
+
}) => Promise<{ proof: Proof; result: unknown[] }>;
|
70
75
|
};
|
71
76
|
|
72
77
|
export type VlayerClientProveArgs<
|
@@ -1,44 +1,11 @@
|
|
1
1
|
import { WebProof } from "types/webProof.ts";
|
2
2
|
import { AbiFunction, Hex, Abi, ContractFunctionName } from "viem";
|
3
|
-
import { Branded } from "types/utils.ts";
|
4
3
|
import type { ContractFunctionArgsWithout } from "./viem";
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
} as const;
|
11
|
-
|
12
|
-
export type ExtensionStep =
|
13
|
-
(typeof EXTENSION_STEP)[keyof typeof EXTENSION_STEP];
|
14
|
-
|
15
|
-
export type WebProofStepNotarize = Branded<
|
16
|
-
{
|
17
|
-
url: string;
|
18
|
-
method: string;
|
19
|
-
label: string;
|
20
|
-
step: typeof EXTENSION_STEP.notarize;
|
21
|
-
},
|
22
|
-
"notarize"
|
23
|
-
>;
|
24
|
-
|
25
|
-
export type WebProofStepExpectUrl = Branded<
|
26
|
-
{
|
27
|
-
url: string;
|
28
|
-
label: string;
|
29
|
-
step: typeof EXTENSION_STEP.expectUrl;
|
30
|
-
},
|
31
|
-
"expectUrl"
|
32
|
-
>;
|
33
|
-
|
34
|
-
export type WebProofStepStartPage = Branded<
|
35
|
-
{
|
36
|
-
url: string;
|
37
|
-
label: string;
|
38
|
-
step: typeof EXTENSION_STEP.startPage;
|
39
|
-
},
|
40
|
-
"startPage"
|
41
|
-
>;
|
4
|
+
import {
|
5
|
+
Branded,
|
6
|
+
WebProofStepExpectUrl,
|
7
|
+
WebProofStepStartPage,
|
8
|
+
} from "@vlayer/web-proof-commons";
|
42
9
|
|
43
10
|
export type WebProofSetupInput = {
|
44
11
|
logoUrl: string;
|
@@ -62,6 +29,7 @@ export type ProverCallCommitment<
|
|
62
29
|
commitmentArgs: ContractFunctionArgsWithout<T, F, { name: "webProof" }>;
|
63
30
|
chainId: number;
|
64
31
|
};
|
32
|
+
|
65
33
|
export type GetWebProofArgs<
|
66
34
|
T extends readonly [AbiFunction, ...Abi[number][]],
|
67
35
|
F extends ContractFunctionName<T>,
|
package/src/api/prover.ts
CHANGED
@@ -5,7 +5,6 @@ import {
|
|
5
5
|
type Address,
|
6
6
|
ContractFunctionArgs,
|
7
7
|
ContractFunctionName,
|
8
|
-
decodeFunctionResult,
|
9
8
|
encodeFunctionData,
|
10
9
|
} from "viem";
|
11
10
|
|
@@ -35,16 +34,5 @@ export async function prove<
|
|
35
34
|
chain_id: chainId,
|
36
35
|
};
|
37
36
|
|
38
|
-
|
39
|
-
result: { proof, evm_call_result },
|
40
|
-
} = await v_call(call, context, url);
|
41
|
-
|
42
|
-
const [, ...result] = decodeFunctionResult({
|
43
|
-
abi: abi as Abi,
|
44
|
-
data: evm_call_result,
|
45
|
-
functionName: functionName as string,
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
47
|
-
}) as any[];
|
48
|
-
|
49
|
-
return { proof, result };
|
37
|
+
return v_call(call, context, url);
|
50
38
|
}
|
@@ -6,8 +6,9 @@ import {
|
|
6
6
|
|
7
7
|
import {
|
8
8
|
ExtensionAction,
|
9
|
-
ExtensionMessage,
|
9
|
+
type ExtensionMessage,
|
10
10
|
ExtensionMessageType,
|
11
|
+
type MessageToExtension,
|
11
12
|
} from "@vlayer/web-proof-commons";
|
12
13
|
|
13
14
|
import { WebProof } from "../../lib/types/webProof";
|
@@ -20,7 +21,10 @@ import { WebProof } from "../../lib/types/webProof";
|
|
20
21
|
|
21
22
|
declare const chrome: {
|
22
23
|
runtime: {
|
23
|
-
sendMessage: (
|
24
|
+
sendMessage: (
|
25
|
+
extensionId: string | undefined,
|
26
|
+
message: MessageToExtension,
|
27
|
+
) => void;
|
24
28
|
connect: (extensionId: string) => {
|
25
29
|
onMessage: {
|
26
30
|
addListener: (message: unknown) => void;
|