@vlayer/sdk 0.1.0-nightly-20241009-c348db7 → 0.1.0-nightly-20241011-0d0e255
Sign up to get free protection for your applications and to get access to all the features.
- 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 +1 -2
- package/src/api/lib/types/vlayer.ts +6 -1
- package/src/api/lib/types/webProofProvider.ts +7 -39
- package/src/api/prover.ts +1 -13
- package/src/api/webProof/providers/extension.ts +7 -4
- 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/node_modules/@vlayer/web-proof-commons/.gitignore +0 -175
- package/node_modules/@vlayer/web-proof-commons/README.md +0 -4
- package/node_modules/@vlayer/web-proof-commons/index.ts +0 -1
- package/node_modules/@vlayer/web-proof-commons/lib/index.ts +0 -1
- package/node_modules/@vlayer/web-proof-commons/lib/message.ts +0 -20
- package/node_modules/@vlayer/web-proof-commons/package.json +0 -17
- package/node_modules/@vlayer/web-proof-commons/tsconfig.json +0 -27
- package/src/api/lib/types/utils.ts +0 -3
- package/src/api/lib/types/webProof.ts +0 -111
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
|
-
import { WebProof } from "types/webProof.ts";
|
2
1
|
import { AbiFunction, Hex, Abi, ContractFunctionName } from "viem";
|
3
|
-
import { Branded } from "types/utils.ts";
|
4
2
|
import type { ContractFunctionArgsWithout } from "./viem";
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}
|
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
|
-
>;
|
3
|
+
import {
|
4
|
+
Branded,
|
5
|
+
WebProof,
|
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,12 +6,12 @@ import {
|
|
6
6
|
|
7
7
|
import {
|
8
8
|
ExtensionAction,
|
9
|
-
ExtensionMessage,
|
9
|
+
type ExtensionMessage,
|
10
10
|
ExtensionMessageType,
|
11
|
+
type MessageToExtension,
|
12
|
+
WebProof,
|
11
13
|
} from "@vlayer/web-proof-commons";
|
12
14
|
|
13
|
-
import { WebProof } from "../../lib/types/webProof";
|
14
|
-
|
15
15
|
// NOTE @types/chrome and webextension-polyfill work only in the extension context
|
16
16
|
// and looks that there is no community driven package providing typings for chrome.runtime
|
17
17
|
// or polyfill logic for the browser APIs available in the browser context
|
@@ -20,7 +20,10 @@ import { WebProof } from "../../lib/types/webProof";
|
|
20
20
|
|
21
21
|
declare const chrome: {
|
22
22
|
runtime: {
|
23
|
-
sendMessage: (
|
23
|
+
sendMessage: (
|
24
|
+
extensionId: string | undefined,
|
25
|
+
message: MessageToExtension,
|
26
|
+
) => void;
|
24
27
|
connect: (extensionId: string) => {
|
25
28
|
onMessage: {
|
26
29
|
addListener: (message: unknown) => void;
|
@@ -1,175 +0,0 @@
|
|
1
|
-
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
2
|
-
|
3
|
-
# Logs
|
4
|
-
|
5
|
-
logs
|
6
|
-
_.log
|
7
|
-
npm-debug.log_
|
8
|
-
yarn-debug.log*
|
9
|
-
yarn-error.log*
|
10
|
-
lerna-debug.log*
|
11
|
-
.pnpm-debug.log*
|
12
|
-
|
13
|
-
# Caches
|
14
|
-
|
15
|
-
.cache
|
16
|
-
|
17
|
-
# Diagnostic reports (https://nodejs.org/api/report.html)
|
18
|
-
|
19
|
-
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
20
|
-
|
21
|
-
# Runtime data
|
22
|
-
|
23
|
-
pids
|
24
|
-
_.pid
|
25
|
-
_.seed
|
26
|
-
*.pid.lock
|
27
|
-
|
28
|
-
# Directory for instrumented libs generated by jscoverage/JSCover
|
29
|
-
|
30
|
-
lib-cov
|
31
|
-
|
32
|
-
# Coverage directory used by tools like istanbul
|
33
|
-
|
34
|
-
coverage
|
35
|
-
*.lcov
|
36
|
-
|
37
|
-
# nyc test coverage
|
38
|
-
|
39
|
-
.nyc_output
|
40
|
-
|
41
|
-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
42
|
-
|
43
|
-
.grunt
|
44
|
-
|
45
|
-
# Bower dependency directory (https://bower.io/)
|
46
|
-
|
47
|
-
bower_components
|
48
|
-
|
49
|
-
# node-waf configuration
|
50
|
-
|
51
|
-
.lock-wscript
|
52
|
-
|
53
|
-
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
54
|
-
|
55
|
-
build/Release
|
56
|
-
|
57
|
-
# Dependency directories
|
58
|
-
|
59
|
-
node_modules/
|
60
|
-
jspm_packages/
|
61
|
-
|
62
|
-
# Snowpack dependency directory (https://snowpack.dev/)
|
63
|
-
|
64
|
-
web_modules/
|
65
|
-
|
66
|
-
# TypeScript cache
|
67
|
-
|
68
|
-
*.tsbuildinfo
|
69
|
-
|
70
|
-
# Optional npm cache directory
|
71
|
-
|
72
|
-
.npm
|
73
|
-
|
74
|
-
# Optional eslint cache
|
75
|
-
|
76
|
-
.eslintcache
|
77
|
-
|
78
|
-
# Optional stylelint cache
|
79
|
-
|
80
|
-
.stylelintcache
|
81
|
-
|
82
|
-
# Microbundle cache
|
83
|
-
|
84
|
-
.rpt2_cache/
|
85
|
-
.rts2_cache_cjs/
|
86
|
-
.rts2_cache_es/
|
87
|
-
.rts2_cache_umd/
|
88
|
-
|
89
|
-
# Optional REPL history
|
90
|
-
|
91
|
-
.node_repl_history
|
92
|
-
|
93
|
-
# Output of 'npm pack'
|
94
|
-
|
95
|
-
*.tgz
|
96
|
-
|
97
|
-
# Yarn Integrity file
|
98
|
-
|
99
|
-
.yarn-integrity
|
100
|
-
|
101
|
-
# dotenv environment variable files
|
102
|
-
|
103
|
-
.env
|
104
|
-
.env.development.local
|
105
|
-
.env.test.local
|
106
|
-
.env.production.local
|
107
|
-
.env.local
|
108
|
-
|
109
|
-
# parcel-bundler cache (https://parceljs.org/)
|
110
|
-
|
111
|
-
.parcel-cache
|
112
|
-
|
113
|
-
# Next.js build output
|
114
|
-
|
115
|
-
.next
|
116
|
-
out
|
117
|
-
|
118
|
-
# Nuxt.js build / generate output
|
119
|
-
|
120
|
-
.nuxt
|
121
|
-
dist
|
122
|
-
|
123
|
-
# Gatsby files
|
124
|
-
|
125
|
-
# Comment in the public line in if your project uses Gatsby and not Next.js
|
126
|
-
|
127
|
-
# https://nextjs.org/blog/next-9-1#public-directory-support
|
128
|
-
|
129
|
-
# public
|
130
|
-
|
131
|
-
# vuepress build output
|
132
|
-
|
133
|
-
.vuepress/dist
|
134
|
-
|
135
|
-
# vuepress v2.x temp and cache directory
|
136
|
-
|
137
|
-
.temp
|
138
|
-
|
139
|
-
# Docusaurus cache and generated files
|
140
|
-
|
141
|
-
.docusaurus
|
142
|
-
|
143
|
-
# Serverless directories
|
144
|
-
|
145
|
-
.serverless/
|
146
|
-
|
147
|
-
# FuseBox cache
|
148
|
-
|
149
|
-
.fusebox/
|
150
|
-
|
151
|
-
# DynamoDB Local files
|
152
|
-
|
153
|
-
.dynamodb/
|
154
|
-
|
155
|
-
# TernJS port file
|
156
|
-
|
157
|
-
.tern-port
|
158
|
-
|
159
|
-
# Stores VSCode versions used for testing VSCode extensions
|
160
|
-
|
161
|
-
.vscode-test
|
162
|
-
|
163
|
-
# yarn v2
|
164
|
-
|
165
|
-
.yarn/cache
|
166
|
-
.yarn/unplugged
|
167
|
-
.yarn/build-state.yml
|
168
|
-
.yarn/install-state.gz
|
169
|
-
.pnp.*
|
170
|
-
|
171
|
-
# IntelliJ based IDEs
|
172
|
-
.idea
|
173
|
-
|
174
|
-
# Finder (MacOS) folder config
|
175
|
-
.DS_Store
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from "./lib";
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from "./message";
|
@@ -1,20 +0,0 @@
|
|
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
|
-
};
|
@@ -1,17 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "@vlayer/web-proof-commons",
|
3
|
-
"private": true,
|
4
|
-
"version": "1.0.0",
|
5
|
-
"module": "index.ts",
|
6
|
-
"type": "module",
|
7
|
-
"scripts": {
|
8
|
-
"lint": "eslint lib",
|
9
|
-
"lint:fix": "eslint --fix lib"
|
10
|
-
},
|
11
|
-
"devDependencies": {
|
12
|
-
"@types/bun": "latest"
|
13
|
-
},
|
14
|
-
"peerDependencies": {
|
15
|
-
"typescript": "^5.0.0"
|
16
|
-
}
|
17
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
// Enable latest features
|
4
|
-
"lib": ["ESNext", "DOM"],
|
5
|
-
"target": "ESNext",
|
6
|
-
"module": "ESNext",
|
7
|
-
"moduleDetection": "force",
|
8
|
-
"jsx": "react-jsx",
|
9
|
-
"allowJs": true,
|
10
|
-
|
11
|
-
// Bundler mode
|
12
|
-
"moduleResolution": "bundler",
|
13
|
-
"allowImportingTsExtensions": true,
|
14
|
-
"verbatimModuleSyntax": true,
|
15
|
-
"noEmit": true,
|
16
|
-
|
17
|
-
// Best practices
|
18
|
-
"strict": true,
|
19
|
-
"skipLibCheck": true,
|
20
|
-
"noFallthroughCasesInSwitch": true,
|
21
|
-
|
22
|
-
// Some stricter flags (disabled by default)
|
23
|
-
"noUnusedLocals": false,
|
24
|
-
"noUnusedParameters": false,
|
25
|
-
"noPropertyAccessFromIndexSignature": false
|
26
|
-
}
|
27
|
-
}
|
@@ -1,111 +0,0 @@
|
|
1
|
-
// NOTE : this is copied from tlsn-js 5.4
|
2
|
-
// for some reason newest versions doesn't export this type (clarification is in progress)
|
3
|
-
// probably it should be reexported from tlsn-js
|
4
|
-
|
5
|
-
export interface WebProof {
|
6
|
-
session: Session;
|
7
|
-
substrings: Substrings;
|
8
|
-
notaryUrl: string;
|
9
|
-
}
|
10
|
-
|
11
|
-
export interface Session {
|
12
|
-
header: Header;
|
13
|
-
signature: Signature;
|
14
|
-
session_info: SessionInfo;
|
15
|
-
}
|
16
|
-
|
17
|
-
export interface SessionInfo {
|
18
|
-
server_name: ServerName;
|
19
|
-
handshake_decommitment: HandshakeDecommitment;
|
20
|
-
}
|
21
|
-
|
22
|
-
export interface HandshakeDecommitment {
|
23
|
-
nonce: number[];
|
24
|
-
data: Data;
|
25
|
-
}
|
26
|
-
|
27
|
-
export interface Data {
|
28
|
-
server_cert_details: ServerCERTDetails;
|
29
|
-
server_kx_details: ServerKxDetails;
|
30
|
-
client_random: number[];
|
31
|
-
server_random: number[];
|
32
|
-
}
|
33
|
-
|
34
|
-
export interface ServerCERTDetails {
|
35
|
-
cert_chain: Array<number[]>;
|
36
|
-
ocsp_response: number[];
|
37
|
-
scts: null;
|
38
|
-
}
|
39
|
-
|
40
|
-
export interface ServerKxDetails {
|
41
|
-
kx_params: number[];
|
42
|
-
kx_sig: KxSig;
|
43
|
-
}
|
44
|
-
|
45
|
-
export interface KxSig {
|
46
|
-
scheme: string;
|
47
|
-
sig: number[];
|
48
|
-
}
|
49
|
-
|
50
|
-
export interface Header {
|
51
|
-
encoder_seed: number[];
|
52
|
-
merkle_root: number[];
|
53
|
-
sent_len: number;
|
54
|
-
recv_len: number;
|
55
|
-
handshake_summary: HandshakeSummary;
|
56
|
-
}
|
57
|
-
|
58
|
-
export interface HandshakeSummary {
|
59
|
-
time: number;
|
60
|
-
server_public_key: ServerPublicKey;
|
61
|
-
handshake_commitment: number[];
|
62
|
-
}
|
63
|
-
|
64
|
-
export interface ServerPublicKey {
|
65
|
-
group: string;
|
66
|
-
key: number[];
|
67
|
-
}
|
68
|
-
|
69
|
-
export interface ServerName {
|
70
|
-
Dns: string;
|
71
|
-
}
|
72
|
-
|
73
|
-
export interface Signature {
|
74
|
-
P256: string;
|
75
|
-
}
|
76
|
-
|
77
|
-
export interface Substrings {
|
78
|
-
openings: { [key: string]: Opening[] };
|
79
|
-
inclusion_proof: InclusionProof;
|
80
|
-
}
|
81
|
-
|
82
|
-
export interface InclusionProof {
|
83
|
-
proof: unknown[];
|
84
|
-
total_leaves: number;
|
85
|
-
}
|
86
|
-
|
87
|
-
export interface Opening {
|
88
|
-
kind?: string;
|
89
|
-
ranges?: Range[];
|
90
|
-
direction?: string;
|
91
|
-
Blake3?: Blake3;
|
92
|
-
}
|
93
|
-
|
94
|
-
export interface Blake3 {
|
95
|
-
data: number[];
|
96
|
-
nonce: number[];
|
97
|
-
}
|
98
|
-
|
99
|
-
export interface Range {
|
100
|
-
start: number;
|
101
|
-
end: number;
|
102
|
-
}
|
103
|
-
export const assertWebProof = function (candidate: {
|
104
|
-
notaryUrl?: string;
|
105
|
-
}): asserts candidate is WebProof {
|
106
|
-
//for now only thing we check is notary url
|
107
|
-
//TODO: implement later once we known the conteact with tlsn-js
|
108
|
-
if (!candidate.notaryUrl) {
|
109
|
-
throw new Error("Missing required parameter");
|
110
|
-
}
|
111
|
-
};
|