@vlayer/sdk 0.1.0-nightly-20241015-4fe37fa → 0.1.0-nightly-20241016-2d34385

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@vlayer/sdk",
3
3
  "type": "module",
4
- "module": "src/index.ts",
5
- "version": "0.1.0-nightly-20241015-4fe37fa",
4
+ "exports": "./src/index.ts",
5
+ "version": "0.1.0-nightly-20241016-2d34385",
6
6
  "types": "src/index.ts",
7
7
  "scripts": {
8
8
  "build": "npm run gen:types",
@@ -21,10 +21,7 @@
21
21
  "dependencies": {
22
22
  "dns-over-http-resolver": "^3.0.3",
23
23
  "postal-mime": "^2.3.2",
24
- "viem": "^2.21.0",
25
- "@vlayer/web-proof-commons": "file:../../web-proof-commons"
26
- },
27
- "bundleDependencies": [
28
- "@vlayer/web-proof-commons"
29
- ]
24
+ "viem": "2.21.0",
25
+ "vite-tsconfig-paths": "^5.0.1"
26
+ }
30
27
  }
@@ -13,13 +13,16 @@ import {
13
13
  } from "viem";
14
14
 
15
15
  import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
16
- import { foundry } from "viem/chains";
16
+ import { foundry, optimismSepolia } from "viem/chains";
17
17
 
18
18
  import type { ContractSpec, ContractArg } from "types/ethereum";
19
19
 
20
- const rpcUrls: Map<number, HttpTransport> = new Map([[foundry.id, http()]]);
20
+ const rpcUrls: Map<number, HttpTransport> = new Map([
21
+ [foundry.id, http()],
22
+ [optimismSepolia.id, http("https://sepolia.optimism.io")],
23
+ ]);
21
24
 
22
- export const chainIds = [foundry.id];
25
+ export const chainIds = [foundry.id, optimismSepolia.id];
23
26
 
24
27
  export function createAnvilClient(
25
28
  chainId: number = foundry.id,
@@ -1,4 +1,3 @@
1
1
  export * from "./ethereum";
2
- export * from "@vlayer/web-proof-commons/lib/types/webProof";
3
2
  export * from "./vlayer";
4
3
  export * from "./webProofProvider";
package/tsconfig.json CHANGED
@@ -24,6 +24,7 @@
24
24
  "paths": {
25
25
  "types/*": ["./src/api/lib/types/*"],
26
26
  "testHelpers/*": ["./src/testHelpers/*"],
27
+ "@vlayer/web-proof-commons" : ["./web-proof-commons"],
27
28
  },
28
29
 
29
30
  }
package/vite.config.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+ import tsconfigPaths from "vite-tsconfig-paths";
4
+
5
+ export default defineConfig({
6
+ plugins: [tsconfigPaths(), react()],
7
+ });
@@ -0,0 +1,3 @@
1
+ export * from "./types/message.ts";
2
+ export * from "./types/webProof.ts";
3
+ export * from "./utils";
@@ -0,0 +1,71 @@
1
+ import type { Branded } from "../utils.ts";
2
+ import type { WebProof } from "./webProof.ts";
3
+
4
+ export const EXTENSION_STEP = {
5
+ expectUrl: "expectUrl",
6
+ startPage: "startPage",
7
+ notarize: "notarize",
8
+ } as const;
9
+
10
+ export type ExtensionStep =
11
+ (typeof EXTENSION_STEP)[keyof typeof EXTENSION_STEP];
12
+
13
+ export const enum ExtensionAction {
14
+ RequestWebProof,
15
+ }
16
+
17
+ export type MessageToExtension = {
18
+ action: ExtensionAction;
19
+ payload: WebProverSessionConfig;
20
+ };
21
+
22
+ export const enum ExtensionMessageType {
23
+ ProofDone = "ProofDone",
24
+ ProofError = "ProofError",
25
+ RedirectBack = "RedirectBack",
26
+ }
27
+
28
+ export type ExtensionMessage =
29
+ | { type: ExtensionMessageType.ProofDone; proof: WebProof }
30
+ | { type: ExtensionMessageType.ProofError; error: string }
31
+ | { type: ExtensionMessageType.RedirectBack };
32
+
33
+ export type WebProverSessionConfig = {
34
+ notaryUrl: string;
35
+ wsProxyUrl: string;
36
+ logoUrl: string;
37
+ steps: WebProofStep[];
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,111 @@
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
+ };
@@ -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
+ }