@vlayer/sdk 0.1.0-nightly-20241028-591419e → 0.1.0-nightly-202410293-42360cf

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. package/dist/api/email/dnsResolver.d.ts +1 -0
  2. package/dist/api/email/dnsResolver.js +6 -0
  3. package/dist/api/email/dnsResolver.test.d.ts +1 -0
  4. package/dist/api/email/dnsResolver.test.js +12 -0
  5. package/dist/api/email/parseEmail.d.ts +10 -0
  6. package/dist/api/email/parseEmail.js +38 -0
  7. package/dist/api/email/parseEmail.test.d.ts +1 -0
  8. package/dist/api/email/parseEmail.test.js +91 -0
  9. package/dist/api/email/preverify.d.ts +4 -0
  10. package/dist/api/email/preverify.js +18 -0
  11. package/dist/api/email/preverify.test.d.ts +1 -0
  12. package/dist/api/email/preverify.test.js +25 -0
  13. package/dist/api/helpers.d.ts +38 -0
  14. package/dist/api/helpers.js +72 -0
  15. package/dist/api/lib/client.d.ts +6 -0
  16. package/dist/api/lib/client.js +45 -0
  17. package/dist/api/lib/types/ethereum.d.ts +14 -0
  18. package/dist/api/lib/types/ethereum.js +12 -0
  19. package/dist/api/lib/types/index.js +3 -0
  20. package/dist/api/lib/types/viem.d.ts +8 -0
  21. package/dist/api/lib/types/viem.js +1 -0
  22. package/dist/api/lib/types/vlayer.d.ts +47 -0
  23. package/dist/api/lib/types/vlayer.js +1 -0
  24. package/dist/api/lib/types/webProofProvider.d.ts +29 -0
  25. package/dist/api/lib/types/webProofProvider.js +1 -0
  26. package/dist/api/prover.d.ts +2 -0
  27. package/dist/api/prover.js +15 -0
  28. package/dist/api/v_call.d.ts +2 -0
  29. package/dist/api/v_call.js +30 -0
  30. package/dist/api/webProof/createWebProof.d.ts +2 -0
  31. package/dist/api/webProof/createWebProof.js +7 -0
  32. package/dist/api/webProof/index.js +3 -0
  33. package/dist/api/webProof/providers/extension.d.ts +2 -0
  34. package/dist/api/webProof/providers/extension.js +32 -0
  35. package/dist/api/webProof/providers/index.js +1 -0
  36. package/dist/api/webProof/steps/expectUrl.d.ts +2 -0
  37. package/dist/api/webProof/steps/expectUrl.js +8 -0
  38. package/dist/api/webProof/steps/index.d.ts +9 -0
  39. package/dist/api/webProof/steps/index.js +9 -0
  40. package/dist/api/webProof/steps/notarize.d.ts +2 -0
  41. package/dist/api/webProof/steps/notarize.js +9 -0
  42. package/dist/api/webProof/steps/startPage.d.ts +2 -0
  43. package/dist/api/webProof/steps/startPage.js +8 -0
  44. package/dist/index.d.ts +7 -0
  45. package/dist/index.js +7 -0
  46. package/dist/testHelpers/readFile.d.ts +1 -0
  47. package/dist/testHelpers/readFile.js +2 -0
  48. package/dist/web-proof-commons/index.d.ts +3 -0
  49. package/dist/web-proof-commons/index.js +3 -0
  50. package/dist/web-proof-commons/types/message.d.ts +56 -0
  51. package/dist/web-proof-commons/types/message.js +5 -0
  52. package/dist/web-proof-commons/types/webProof.d.ts +86 -0
  53. package/dist/web-proof-commons/types/webProof.js +10 -0
  54. package/dist/web-proof-commons/utils.d.ts +7 -0
  55. package/dist/web-proof-commons/utils.js +5 -0
  56. package/package.json +17 -7
  57. package/.changeset/config.json +0 -11
  58. package/CHANGELOG.md +0 -7
  59. package/eslint.config.ts +0 -22
  60. package/src/api/email/dnsResolver.test.ts +0 -18
  61. package/src/api/email/dnsResolver.ts +0 -7
  62. package/src/api/email/parseEmail.test.ts +0 -133
  63. package/src/api/email/parseEmail.ts +0 -49
  64. package/src/api/email/preverify.test.ts +0 -37
  65. package/src/api/email/preverify.ts +0 -19
  66. package/src/api/email/testdata/test_email.txt +0 -21
  67. package/src/api/email/testdata/test_email_multiple_dkims.txt +0 -28
  68. package/src/api/email/testdata/test_email_unknown_domain.txt +0 -21
  69. package/src/api/helpers.ts +0 -173
  70. package/src/api/lib/client.ts +0 -76
  71. package/src/api/lib/types/ethereum.ts +0 -43
  72. package/src/api/lib/types/viem.ts +0 -28
  73. package/src/api/lib/types/vlayer.ts +0 -60
  74. package/src/api/lib/types/webProofProvider.ts +0 -44
  75. package/src/api/prover.ts +0 -34
  76. package/src/api/v_call.ts +0 -45
  77. package/src/api/webProof/createWebProof.ts +0 -9
  78. package/src/api/webProof/providers/extension.ts +0 -72
  79. package/src/api/webProof/steps/expectUrl.ts +0 -12
  80. package/src/api/webProof/steps/index.ts +0 -11
  81. package/src/api/webProof/steps/notarize.ts +0 -17
  82. package/src/api/webProof/steps/startPage.ts +0 -12
  83. package/src/index.ts +0 -9
  84. package/src/testHelpers/readFile.ts +0 -3
  85. package/src/web-proof-commons/index.ts +0 -3
  86. package/src/web-proof-commons/types/message.ts +0 -73
  87. package/src/web-proof-commons/types/webProof.ts +0 -111
  88. package/src/web-proof-commons/utils.ts +0 -12
  89. package/tsconfig.json +0 -24
  90. package/vite.config.ts +0 -7
  91. /package/{src/api/lib/types/index.ts → dist/api/lib/types/index.d.ts} +0 -0
  92. /package/{src/api/webProof/index.ts → dist/api/webProof/index.d.ts} +0 -0
  93. /package/{src/api/webProof/providers/index.ts → dist/api/webProof/providers/index.d.ts} +0 -0
@@ -1,28 +0,0 @@
1
- DKIM-Signature: a=rsa-sha256; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
2
- c=simple/simple; d=google.com;
3
- h=Received:From:To:Subject:Date:Message-ID; i=joe@football.example.com;
4
- s=20230601; t=1615825284; v=1;
5
- b=Xh4Ujb2wv5x54gXtulCiy4C0e+plRm6pZ4owF+kICpYzs/8WkTVIDBrzhJP0DAYCpnL62T0G
6
- k+0OH8pi/yqETVjKtKk+peMnNvKkut0GeWZMTze0bfq3/JUK3Ln3jTzzpXxrgVnvBxeY9EZIL4g
7
- s4wwFRRKz/1bksZGSjD8uuSU=
8
- DKIM-Signature: a=rsa-sha256; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
9
- c=simple/simple; d=google.com;
10
- h=Received:From:To:Subject:Date:Message-ID; i=joe@football.example.com;
11
- s=20230601; t=1615825284; v=1;
12
- b=Xh4Ujb2wv5x54gXtulCiy4C0e+plRm6pZ4owF+kICpYzs/8WkTVIDBrzhJP0DAYCpnL62T0G
13
- k+0OH8pi/yqETVjKtKk+peMnNvKkut0GeWZMTze0bfq3/JUK3Ln3jTzzpXxrgVnvBxeY9EZIL4g
14
- s4wwFRRKz/1bksZGSjD8uuSU=
15
- Received: from client1.football.example.com [192.0.2.1]
16
- by submitserver.example.com with SUBMISSION;
17
- Fri, 11 Jul 2003 21:01:54 -0700 (PDT)
18
- From: Joe SixPack <joe@football.example.com>
19
- To: Suzie Q <suzie@shopping.example.net>
20
- Subject: Is dinner ready?
21
- Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT)
22
- Message-ID: <20030712040037.46341.5F8J@football.example.com>
23
-
24
- Hi.
25
-
26
- We lost the game. Are you hungry yet?
27
-
28
- Joe.
@@ -1,21 +0,0 @@
1
- DKIM-Signature: a=rsa-sha256; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
2
- c=simple/simple; d=foobar.xyz;
3
- h=Received:From:To:Subject:Date:Message-ID; i=joe@football.example.com;
4
- s=wertyu; t=1615825284; v=1;
5
- b=Xh4Ujb2wv5x54gXtulCiy4C0e+plRm6pZ4owF+kICpYzs/8WkTVIDBrzhJP0DAYCpnL62T0G
6
- k+0OH8pi/yqETVjKtKk+peMnNvKkut0GeWZMTze0bfq3/JUK3Ln3jTzzpXxrgVnvBxeY9EZIL4g
7
- s4wwFRRKz/1bksZGSjD8uuSU=
8
- Received: from client1.football.example.com [192.0.2.1]
9
- by submitserver.example.com with SUBMISSION;
10
- Fri, 11 Jul 2003 21:01:54 -0700 (PDT)
11
- From: Joe SixPack <joe@football.example.com>
12
- To: Suzie Q <suzie@shopping.example.net>
13
- Subject: Is dinner ready?
14
- Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT)
15
- Message-ID: <20030712040037.46341.5F8J@football.example.com>
16
-
17
- Hi.
18
-
19
- We lost the game. Are you hungry yet?
20
-
21
- Joe.
@@ -1,173 +0,0 @@
1
- import {
2
- type Abi,
3
- Account,
4
- type Address,
5
- type Chain,
6
- type ContractFunctionArgs,
7
- type ContractFunctionName,
8
- createTestClient,
9
- type Hex,
10
- http,
11
- HttpTransport,
12
- publicActions,
13
- PublicClient,
14
- walletActions,
15
- WriteContractParameters,
16
- } from "viem";
17
-
18
- import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
19
- import { foundry } from "viem/chains";
20
-
21
- import type { ContractSpec, ContractArg } from "types/ethereum";
22
-
23
- const rpcUrls: Map<number, HttpTransport> = new Map([[foundry.id, http()]]);
24
-
25
- export const chainIds = [foundry.id];
26
-
27
- export function createAnvilClient(
28
- chainId: number = foundry.id,
29
- ): ReturnType<typeof walletActions> & PublicClient {
30
- const transport = rpcUrls.get(chainId);
31
- if (transport == undefined) {
32
- throw Error(`No url for chainId ${chainId}`);
33
- }
34
-
35
- return createTestClient({
36
- chain: foundry,
37
- mode: "anvil",
38
- transport: transport,
39
- })
40
- .extend(publicActions)
41
- .extend(walletActions);
42
- }
43
-
44
- export async function deployContract(
45
- contractSpec: ContractSpec,
46
- args: ContractArg[] = [],
47
- chainId: number = foundry.id,
48
- ): Promise<Address> {
49
- const ethClient = createAnvilClient(chainId);
50
-
51
- const [deployer] = await ethClient.getAddresses();
52
-
53
- const txHash = await ethClient.deployContract({
54
- abi: contractSpec.abi,
55
- bytecode: contractSpec.bytecode.object,
56
- account: deployer,
57
- args,
58
- chain: foundry,
59
- });
60
-
61
- const receipt = await ethClient.waitForTransactionReceipt({ hash: txHash });
62
-
63
- if (receipt.status != "success") {
64
- throw new Error(
65
- `Contract deployment failed with status: ${receipt.status}`,
66
- );
67
- }
68
-
69
- return receipt.contractAddress as Address;
70
- }
71
-
72
- type DeploySpec<T extends Abi> = {
73
- abi: T;
74
- bytecode: {
75
- object: Hex;
76
- };
77
- };
78
-
79
- type Tail<T> = T extends readonly [unknown, ...infer U] ? U : [];
80
-
81
- export async function deployProverVerifier<P extends Abi, V extends Abi>(
82
- proverSpec: DeploySpec<P>,
83
- verifierSpec: DeploySpec<V>,
84
- args: {
85
- prover?: ContractArg[];
86
- verifier?: Tail<ContractArg>[];
87
- } = {},
88
- chainId: number = foundry.id,
89
- ) {
90
- console.log("Deploying prover");
91
- const proverAddress = await deployContract(
92
- proverSpec,
93
- args.prover ?? [],
94
- chainId,
95
- );
96
- console.log(`Prover has been deployed on ${proverAddress} address`);
97
-
98
- console.log("Deploying verifier");
99
- const verifierAddress = await deployContract(
100
- verifierSpec,
101
- [proverAddress, ...(args.verifier ?? [])],
102
- chainId,
103
- );
104
- console.log(`Verifier has been deployed on ${verifierAddress} address`);
105
-
106
- return [proverAddress, verifierAddress];
107
- }
108
-
109
- export async function call<
110
- T extends Abi,
111
- F extends ContractFunctionName<T, "pure" | "view">,
112
- >(
113
- abi: T,
114
- address: Address,
115
- functionName: F,
116
- args?: ContractFunctionArgs<T, "pure" | "view", F>,
117
- chainId: number = foundry.id,
118
- ) {
119
- const ethClient = createAnvilClient(chainId);
120
-
121
- return ethClient.readContract({
122
- abi,
123
- address,
124
- functionName,
125
- args,
126
- });
127
- }
128
-
129
- export async function writeContract<
130
- T extends Abi,
131
- F extends ContractFunctionName<T, "payable" | "nonpayable">,
132
- >(
133
- address: Address,
134
- abi: T,
135
- functionName: F,
136
- args: ContractFunctionArgs<T, "payable" | "nonpayable", F>,
137
- sender?: Address,
138
- chain: Chain = foundry,
139
- ) {
140
- const ethClient = createAnvilClient(chain.id);
141
- const selectedSender = sender || (await ethClient.getAddresses())[0];
142
-
143
- const txHash = await ethClient.writeContract({
144
- address,
145
- abi: abi as Abi,
146
- functionName,
147
- args: args as readonly unknown[],
148
- chain,
149
- account: selectedSender,
150
- chainOverride: undefined,
151
- } as WriteContractParameters<
152
- Abi,
153
- ContractFunctionName<Abi, "nonpayable" | "payable">,
154
- ContractFunctionArgs<Abi, "nonpayable" | "payable", F>,
155
- Chain | undefined,
156
- Account | undefined,
157
- Chain | undefined
158
- >);
159
-
160
- const txReceipt = await ethClient.waitForTransactionReceipt({ hash: txHash });
161
-
162
- if (txReceipt.status != "success") {
163
- throw new Error(`Transaction failed with status: ${txReceipt.status}`);
164
- }
165
-
166
- return txReceipt;
167
- }
168
-
169
- export const getTestAccount = () => privateKeyToAccount(generatePrivateKey());
170
-
171
- export const getTestAddresses = (
172
- chainId: number = foundry.id,
173
- ): Promise<Address[]> => createAnvilClient(chainId).getAddresses();
@@ -1,76 +0,0 @@
1
- import { VCallResponse, VlayerClient } from "types/vlayer";
2
- import { WebProofProvider } from "types/webProofProvider";
3
-
4
- import { prove } from "../prover";
5
- import { createExtensionWebProofProvider } from "../webProof";
6
- import { type Abi, decodeFunctionResult } from "viem";
7
-
8
- function dropEmptyProofFromArgs(args: unknown) {
9
- if (Array.isArray(args)) {
10
- return args.slice(1) as unknown[];
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
-
23
- export const createVlayerClient = (
24
- {
25
- url = "http://127.0.0.1:3000",
26
- webProofProvider = createExtensionWebProofProvider(),
27
- }: {
28
- url?: string;
29
- webProofProvider?: WebProofProvider;
30
- } = {
31
- url: "http://127.0.0.1:3000",
32
- webProofProvider: createExtensionWebProofProvider(),
33
- },
34
- ): VlayerClient => {
35
- console.log("createVlayerClient with", url, webProofProvider);
36
- const resultHashMap = new Map<
37
- string,
38
- [Promise<VCallResponse>, Abi, string]
39
- >();
40
-
41
- return {
42
- // eslint-disable-next-line @typescript-eslint/require-await
43
- prove: async ({ address, functionName, chainId, proverAbi, args }) => {
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 = dropEmptyProofFromArgs(
66
- decodeFunctionResult({
67
- abi: savedProvingData[1],
68
- data: evm_call_result,
69
- functionName: savedProvingData[2],
70
- }),
71
- );
72
-
73
- return [proof, ...result];
74
- },
75
- };
76
- };
@@ -1,43 +0,0 @@
1
- import { Abi, Address, Hex } from "viem";
2
- import { Branded } from "../../../web-proof-commons";
3
-
4
- export type Bytecode = {
5
- object: Hex;
6
- };
7
-
8
- export type ContractSpec = {
9
- abi: Abi;
10
- bytecode: Bytecode;
11
- };
12
-
13
- export type ContractArg =
14
- | number
15
- | string
16
- | boolean
17
- | bigint
18
- | number[]
19
- | string[]
20
- | boolean[]
21
- | bigint[]
22
- | Address[];
23
-
24
- export type EthereumAddress = Branded<Hex, "EthereumAddress">;
25
- export type EthereumTxHash = Branded<Hex, "EthereumTxHash">;
26
-
27
- export function assertEthereumAddress(
28
- hash: string,
29
- ): asserts hash is EthereumAddress {
30
- const regex = /^(0x)?[0-9a-fA-F]{40}$/;
31
- if (!regex.test(hash)) {
32
- throw new Error(`Invalid ethereum account ${hash}`);
33
- }
34
- }
35
-
36
- export function assertEthereumTxHash(
37
- hash: string,
38
- ): asserts hash is EthereumTxHash {
39
- const regex = /^(0x)?[0-9a-fA-F]{64}$/;
40
- if (!regex.test(hash)) {
41
- throw new Error(`Invalid ethereum tx hash ${hash}`);
42
- }
43
- }
@@ -1,28 +0,0 @@
1
- import { Abi, ContractFunctionName } from "viem";
2
- import { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
3
-
4
- type Without<T extends readonly unknown[], P> = T extends readonly [
5
- infer F,
6
- ...infer R,
7
- ]
8
- ? F extends P
9
- ? Without<R, P>
10
- : readonly [F, ...Without<R, P>]
11
- : [];
12
-
13
- export type ContractFunctionArgsWithout<
14
- abi extends Abi,
15
- functionName extends ContractFunctionName<abi>,
16
- without,
17
- > =
18
- AbiParametersToPrimitiveTypes<
19
- Without<
20
- ExtractAbiFunction<abi extends Abi ? abi : Abi, functionName>["inputs"],
21
- without
22
- >,
23
- "inputs"
24
- > extends infer args
25
- ? [args] extends [never]
26
- ? readonly unknown[]
27
- : args
28
- : readonly unknown[];
@@ -1,60 +0,0 @@
1
- import {
2
- Abi,
3
- AbiStateMutability,
4
- Address,
5
- ContractFunctionArgs,
6
- ContractFunctionName,
7
- Hex,
8
- } from "viem";
9
-
10
- type Calldata = string;
11
-
12
- export type CallParams = {
13
- to: Address;
14
- data: Calldata;
15
- };
16
-
17
- export type CallContext = {
18
- chain_id: number; // 31337
19
- };
20
-
21
- export type Proof = {
22
- length: bigint;
23
- seal: {
24
- verifierSelector: Hex;
25
- seal: readonly [Hex, Hex, Hex, Hex, Hex, Hex, Hex, Hex];
26
- mode: number;
27
- };
28
- callAssumptions: {
29
- proverContractAddress: Address;
30
- functionSelector: Hex;
31
- settleBlockHash: Hex;
32
- settleBlockNumber: bigint;
33
- };
34
- };
35
-
36
- export interface VCallResult {
37
- evm_call_result: Hex;
38
- proof: Proof;
39
- }
40
-
41
- export interface VCallResponse {
42
- jsonrpc: string;
43
- result: VCallResult;
44
- id: number;
45
- }
46
-
47
- export type VlayerClient = {
48
- prove: <T extends Abi, F extends ContractFunctionName<T>>(args: {
49
- address: Hex;
50
- proverAbi: T;
51
- functionName: F;
52
- chainId: number;
53
- args: ContractFunctionArgs<T, AbiStateMutability, F>;
54
- }) => Promise<{ hash: string }>;
55
- waitForProvingResult: ({
56
- hash,
57
- }: {
58
- hash: string;
59
- }) => Promise<[Proof, ...unknown[]]>;
60
- };
@@ -1,44 +0,0 @@
1
- import { Hex, Abi, ContractFunctionName } from "viem";
2
- import type { ContractFunctionArgsWithout } from "./viem";
3
- import { Branded, WebProof, WebProofStep } from "../../../web-proof-commons";
4
-
5
- export type WebProofSetupInput = {
6
- logoUrl: string;
7
- steps: WebProofStep[];
8
- };
9
-
10
- export type WebProofSetup = Branded<
11
- WebProofSetupInput & {
12
- isWebProof: true;
13
- },
14
- "webProof"
15
- >;
16
-
17
- export type ProverCallCommitment<
18
- T extends Abi,
19
- F extends ContractFunctionName<T>,
20
- > = {
21
- address: Hex;
22
- proverAbi: T;
23
- functionName: F;
24
- commitmentArgs: ContractFunctionArgsWithout<T, F, { name: "webProof" }>;
25
- chainId: number;
26
- };
27
-
28
- export type GetWebProofArgs<
29
- T extends Abi,
30
- F extends ContractFunctionName<T>,
31
- > = {
32
- proverCallCommitment: ProverCallCommitment<T, F>;
33
- } & WebProofSetupInput;
34
-
35
- export type WebProofProvider = {
36
- getWebProof: <T extends Abi, F extends ContractFunctionName<T>>(
37
- args: GetWebProofArgs<T, F>,
38
- ) => Promise<WebProof>;
39
- };
40
-
41
- export type WebProofProviderSetup = {
42
- notaryUrl?: string;
43
- wsProxyUrl?: string;
44
- };
package/src/api/prover.ts DELETED
@@ -1,34 +0,0 @@
1
- import {
2
- type Abi,
3
- AbiStateMutability,
4
- type Address,
5
- ContractFunctionArgs,
6
- ContractFunctionName,
7
- encodeFunctionData,
8
- } from "viem";
9
-
10
- import { type CallContext, type CallParams } from "types/vlayer";
11
- import { v_call } from "./v_call";
12
- import { foundry } from "viem/chains";
13
-
14
- export async function prove<T extends Abi, F extends ContractFunctionName<T>>(
15
- prover: Address,
16
- abi: T,
17
- functionName: F,
18
- args: ContractFunctionArgs<T, AbiStateMutability, F>,
19
- chainId: number = foundry.id,
20
- url: string = "http://127.0.0.1:3000",
21
- ) {
22
- const calldata = encodeFunctionData({
23
- abi: abi as Abi,
24
- functionName: functionName as string,
25
- args: args as readonly unknown[],
26
- });
27
-
28
- const call: CallParams = { to: prover, data: calldata };
29
- const context: CallContext = {
30
- chain_id: chainId,
31
- };
32
-
33
- return v_call(call, context, url);
34
- }
package/src/api/v_call.ts DELETED
@@ -1,45 +0,0 @@
1
- import { CallContext, CallParams, VCallResponse } from "types/vlayer";
2
-
3
- function v_callBody(call: CallParams, context: CallContext) {
4
- return {
5
- method: "v_call",
6
- params: [call, context],
7
- id: 1,
8
- jsonrpc: "2.0",
9
- };
10
- }
11
-
12
- export async function v_call(
13
- call: CallParams,
14
- context: CallContext,
15
- url: string = "http://127.0.0.1:3000",
16
- ): Promise<VCallResponse> {
17
- const response = await fetch(url, {
18
- method: "POST",
19
- body: JSON.stringify(v_callBody(call, context)),
20
- headers: { "Content-Type": "application/json" },
21
- });
22
-
23
- if (!response.ok) {
24
- throw new Error(`HTTP error! status: ${response.status}`);
25
- }
26
-
27
- const response_json = await response.json();
28
-
29
- //TODO we should launch some schema validation here
30
- assertObject(response_json);
31
-
32
- if ("error" in response_json) {
33
- throw new Error(
34
- `Error response: ${(response_json.error as { message: string }).message || "unknown error"}`,
35
- );
36
- }
37
-
38
- return response_json as Promise<VCallResponse>;
39
- }
40
-
41
- function assertObject(x: unknown): asserts x is object {
42
- if (typeof x !== "object") {
43
- throw new Error("Expected object");
44
- }
45
- }
@@ -1,9 +0,0 @@
1
- import { WebProofSetup, WebProofSetupInput } from "types/webProofProvider.ts";
2
-
3
- export const createWebProof = ({ logoUrl, steps }: WebProofSetupInput) => {
4
- return {
5
- logoUrl,
6
- steps,
7
- isWebProof: true,
8
- } as WebProofSetup;
9
- };
@@ -1,72 +0,0 @@
1
- import {
2
- type WebProofProvider,
3
- type WebProofProviderSetup,
4
- type WebProofSetupInput,
5
- } from "../../lib/types/webProofProvider";
6
-
7
- import {
8
- ExtensionAction,
9
- type ExtensionMessage,
10
- ExtensionMessageType,
11
- type MessageToExtension,
12
- WebProof,
13
- } from "../../../web-proof-commons";
14
-
15
- // NOTE @types/chrome and webextension-polyfill work only in the extension context
16
- // and looks that there is no community driven package providing typings for chrome.runtime
17
- // or polyfill logic for the browser APIs available in the browser context
18
- // we intentionally use chrome here instead of browser as we support only chrome for now
19
- // and there could be some differences in the API between browsers
20
-
21
- declare const chrome: {
22
- runtime: {
23
- sendMessage: (
24
- extensionId: string | undefined,
25
- message: MessageToExtension,
26
- ) => void;
27
- connect: (extensionId: string) => {
28
- onMessage: {
29
- addListener: (message: unknown) => void;
30
- };
31
- };
32
- };
33
- };
34
-
35
- // this id is fixed in the extension by the key in manifest.json
36
- const EXTENSION_ID = "jbchhcgphfokabmfacnkafoeeeppjmpl";
37
-
38
- export const createExtensionWebProofProvider = (
39
- {
40
- notaryUrl = "https://notary.pse.dev/v0.1.0-alpha.5/",
41
- wsProxyUrl = "wss://notary.pse.dev/proxy",
42
- }: WebProofProviderSetup = {
43
- notaryUrl: "https://notary.pse.dev/v0.1.0-alpha.5/",
44
- wsProxyUrl: "wss://notary.pse.dev/proxy",
45
- },
46
- ): WebProofProvider => {
47
- return {
48
- getWebProof: async function (webProofSetup: WebProofSetupInput) {
49
- return new Promise<WebProof>((resolve, reject) => {
50
- chrome.runtime.sendMessage(EXTENSION_ID, {
51
- action: ExtensionAction.RequestWebProof,
52
- payload: {
53
- notaryUrl,
54
- wsProxyUrl,
55
- logoUrl: webProofSetup.logoUrl,
56
- steps: webProofSetup.steps,
57
- },
58
- });
59
- const port = chrome.runtime.connect(EXTENSION_ID);
60
- // TODO: validate message in runtime
61
- port.onMessage.addListener((message: ExtensionMessage) => {
62
- if (message.type === ExtensionMessageType.ProofDone) {
63
- resolve(message.proof);
64
- }
65
- if (message.type === ExtensionMessageType.ProofError) {
66
- reject(new Error(message.error));
67
- }
68
- });
69
- });
70
- },
71
- };
72
- };
@@ -1,12 +0,0 @@
1
- import {
2
- EXTENSION_STEP,
3
- WebProofStepExpectUrl,
4
- } from "../../../web-proof-commons";
5
-
6
- export const expectUrl = (url: string, label: string) => {
7
- return {
8
- url,
9
- label,
10
- step: EXTENSION_STEP.expectUrl,
11
- } as WebProofStepExpectUrl;
12
- };
@@ -1,11 +0,0 @@
1
- import { expectUrl } from "./expectUrl.ts";
2
- import { startPage } from "./startPage.ts";
3
- import { notarize } from "./notarize.ts";
4
-
5
- const steps = {
6
- expectUrl,
7
- startPage,
8
- notarize,
9
- };
10
-
11
- export { expectUrl, startPage, notarize, steps };
@@ -1,17 +0,0 @@
1
- import {
2
- EXTENSION_STEP,
3
- WebProofStepNotarize,
4
- } from "../../../web-proof-commons";
5
-
6
- export const notarize = (
7
- url: string,
8
- method: string = "GET",
9
- label: string,
10
- ) => {
11
- return {
12
- url,
13
- method,
14
- label,
15
- step: EXTENSION_STEP.notarize,
16
- } as WebProofStepNotarize;
17
- };
@@ -1,12 +0,0 @@
1
- import {
2
- EXTENSION_STEP,
3
- WebProofStepStartPage,
4
- } from "../../../web-proof-commons";
5
-
6
- export const startPage = (url: string, label: string) => {
7
- return {
8
- url,
9
- label,
10
- step: EXTENSION_STEP.startPage,
11
- } as WebProofStepStartPage;
12
- };