@vlayer/sdk 0.1.0-nightly-20241209-1e00031 → 0.1.0-nightly-20241210-eb73222

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.
Files changed (159) hide show
  1. package/dist/api/email/dnsResolver.d.ts +1 -0
  2. package/dist/api/email/dnsResolver.d.ts.map +1 -0
  3. package/dist/api/email/dnsResolver.js +1 -0
  4. package/dist/api/email/dnsResolver.js.map +1 -0
  5. package/dist/api/email/parseEmail.d.ts +2 -1
  6. package/dist/api/email/parseEmail.d.ts.map +1 -0
  7. package/dist/api/email/parseEmail.js +2 -1
  8. package/dist/api/email/parseEmail.js.map +1 -0
  9. package/dist/api/email/preverify.d.ts +2 -1
  10. package/dist/api/email/preverify.d.ts.map +1 -0
  11. package/dist/api/email/preverify.js +2 -1
  12. package/dist/api/email/preverify.js.map +1 -0
  13. package/dist/api/helpers.d.ts +2 -1
  14. package/dist/api/helpers.d.ts.map +1 -0
  15. package/dist/api/helpers.js +1 -0
  16. package/dist/api/helpers.js.map +1 -0
  17. package/dist/api/lib/client.d.ts +3 -2
  18. package/dist/api/lib/client.d.ts.map +1 -0
  19. package/dist/api/lib/client.js +26 -6
  20. package/dist/api/lib/client.js.map +1 -0
  21. package/dist/api/lib/errors.d.ts +1 -0
  22. package/dist/api/lib/errors.d.ts.map +1 -0
  23. package/dist/api/lib/errors.js +1 -0
  24. package/dist/api/lib/errors.js.map +1 -0
  25. package/dist/api/lib/types/ethereum.d.ts +3 -2
  26. package/dist/api/lib/types/ethereum.d.ts.map +1 -0
  27. package/dist/api/lib/types/ethereum.js +3 -0
  28. package/dist/api/lib/types/ethereum.js.map +1 -0
  29. package/dist/api/lib/types/index.d.ts +1 -0
  30. package/dist/api/lib/types/index.d.ts.map +1 -0
  31. package/dist/api/lib/types/index.js +1 -0
  32. package/dist/api/lib/types/index.js.map +1 -0
  33. package/dist/api/lib/types/viem.d.ts +3 -2
  34. package/dist/api/lib/types/viem.d.ts.map +1 -0
  35. package/dist/api/lib/types/viem.js +3 -1
  36. package/dist/api/lib/types/viem.js.map +1 -0
  37. package/dist/api/lib/types/vlayer.d.ts +19 -7
  38. package/dist/api/lib/types/vlayer.d.ts.map +1 -0
  39. package/dist/api/lib/types/vlayer.js +10 -1
  40. package/dist/api/lib/types/vlayer.js.map +1 -0
  41. package/dist/api/lib/types/webProofProvider.d.ts +3 -2
  42. package/dist/api/lib/types/webProofProvider.d.ts.map +1 -0
  43. package/dist/api/lib/types/webProofProvider.js +3 -1
  44. package/dist/api/lib/types/webProofProvider.js.map +1 -0
  45. package/dist/api/prover.d.ts +2 -1
  46. package/dist/api/prover.d.ts.map +1 -0
  47. package/dist/api/prover.js +2 -0
  48. package/dist/api/prover.js.map +1 -0
  49. package/dist/api/utils/prefixAllButNthSubstring.d.ts +1 -0
  50. package/dist/api/utils/prefixAllButNthSubstring.d.ts.map +1 -0
  51. package/dist/api/utils/prefixAllButNthSubstring.js +1 -0
  52. package/dist/api/utils/prefixAllButNthSubstring.js.map +1 -0
  53. package/dist/api/utils/versions.d.ts +1 -0
  54. package/dist/api/utils/versions.d.ts.map +1 -0
  55. package/dist/api/utils/versions.js +1 -0
  56. package/dist/api/utils/versions.js.map +1 -0
  57. package/dist/api/v_call.d.ts +2 -1
  58. package/dist/api/v_call.d.ts.map +1 -0
  59. package/dist/api/v_call.js +2 -0
  60. package/dist/api/v_call.js.map +1 -0
  61. package/dist/api/v_getProofReceipt.d.ts +2 -1
  62. package/dist/api/v_getProofReceipt.d.ts.map +1 -0
  63. package/dist/api/v_getProofReceipt.js +2 -0
  64. package/dist/api/v_getProofReceipt.js.map +1 -0
  65. package/dist/api/v_versions.d.ts +1 -0
  66. package/dist/api/v_versions.d.ts.map +1 -0
  67. package/dist/api/v_versions.js +1 -0
  68. package/dist/api/v_versions.js.map +1 -0
  69. package/dist/api/webProof/createWebProofRequest.d.ts +2 -1
  70. package/dist/api/webProof/createWebProofRequest.d.ts.map +1 -0
  71. package/dist/api/webProof/createWebProofRequest.js +2 -0
  72. package/dist/api/webProof/createWebProofRequest.js.map +1 -0
  73. package/dist/api/webProof/index.d.ts +1 -0
  74. package/dist/api/webProof/index.d.ts.map +1 -0
  75. package/dist/api/webProof/index.js +1 -0
  76. package/dist/api/webProof/index.js.map +1 -0
  77. package/dist/api/webProof/providers/extension.d.ts +1 -0
  78. package/dist/api/webProof/providers/extension.d.ts.map +1 -0
  79. package/dist/api/webProof/providers/extension.js +7 -4
  80. package/dist/api/webProof/providers/extension.js.map +1 -0
  81. package/dist/api/webProof/providers/index.d.ts +1 -0
  82. package/dist/api/webProof/providers/index.d.ts.map +1 -0
  83. package/dist/api/webProof/providers/index.js +1 -0
  84. package/dist/api/webProof/providers/index.js.map +1 -0
  85. package/dist/api/webProof/steps/expectUrl.d.ts +2 -1
  86. package/dist/api/webProof/steps/expectUrl.d.ts.map +1 -0
  87. package/dist/api/webProof/steps/expectUrl.js +1 -0
  88. package/dist/api/webProof/steps/expectUrl.js.map +1 -0
  89. package/dist/api/webProof/steps/index.d.ts +1 -0
  90. package/dist/api/webProof/steps/index.d.ts.map +1 -0
  91. package/dist/api/webProof/steps/index.js +1 -0
  92. package/dist/api/webProof/steps/index.js.map +1 -0
  93. package/dist/api/webProof/steps/notarize.d.ts +2 -1
  94. package/dist/api/webProof/steps/notarize.d.ts.map +1 -0
  95. package/dist/api/webProof/steps/notarize.js +1 -0
  96. package/dist/api/webProof/steps/notarize.js.map +1 -0
  97. package/dist/api/webProof/steps/startPage.d.ts +2 -1
  98. package/dist/api/webProof/steps/startPage.d.ts.map +1 -0
  99. package/dist/api/webProof/steps/startPage.js +1 -0
  100. package/dist/api/webProof/steps/startPage.js.map +1 -0
  101. package/dist/config/createContext.d.ts +3 -2
  102. package/dist/config/createContext.d.ts.map +1 -0
  103. package/dist/config/createContext.js +2 -0
  104. package/dist/config/createContext.js.map +1 -0
  105. package/dist/config/deploy.d.ts +3 -2
  106. package/dist/config/deploy.d.ts.map +1 -0
  107. package/dist/config/deploy.js +3 -0
  108. package/dist/config/deploy.js.map +1 -0
  109. package/dist/config/getChainConfirmations.d.ts +1 -0
  110. package/dist/config/getChainConfirmations.d.ts.map +1 -0
  111. package/dist/config/getChainConfirmations.js +1 -0
  112. package/dist/config/getChainConfirmations.js.map +1 -0
  113. package/dist/config/getConfig.d.ts +1 -0
  114. package/dist/config/getConfig.d.ts.map +1 -0
  115. package/dist/config/getConfig.js +1 -0
  116. package/dist/config/getConfig.js.map +1 -0
  117. package/dist/config/index.d.ts +1 -0
  118. package/dist/config/index.d.ts.map +1 -0
  119. package/dist/config/index.js +1 -0
  120. package/dist/config/index.js.map +1 -0
  121. package/dist/config/writeEnvVariables.d.ts +1 -0
  122. package/dist/config/writeEnvVariables.d.ts.map +1 -0
  123. package/dist/config/writeEnvVariables.js +1 -0
  124. package/dist/config/writeEnvVariables.js.map +1 -0
  125. package/dist/index.d.ts +1 -0
  126. package/dist/index.d.ts.map +1 -0
  127. package/dist/index.js +1 -0
  128. package/dist/index.js.map +1 -0
  129. package/dist/testHelpers/readFile.d.ts +1 -0
  130. package/dist/testHelpers/readFile.d.ts.map +1 -0
  131. package/dist/testHelpers/readFile.js +1 -0
  132. package/dist/testHelpers/readFile.js.map +1 -0
  133. package/dist/web-proof-commons/index.d.ts +1 -0
  134. package/dist/web-proof-commons/index.d.ts.map +1 -0
  135. package/dist/web-proof-commons/index.js +1 -0
  136. package/dist/web-proof-commons/index.js.map +1 -0
  137. package/dist/web-proof-commons/types/message.d.ts +1 -0
  138. package/dist/web-proof-commons/types/message.d.ts.map +1 -0
  139. package/dist/web-proof-commons/types/message.js +8 -1
  140. package/dist/web-proof-commons/types/message.js.map +1 -0
  141. package/dist/web-proof-commons/utils.d.ts +1 -0
  142. package/dist/web-proof-commons/utils.d.ts.map +1 -0
  143. package/dist/web-proof-commons/utils.js +1 -0
  144. package/dist/web-proof-commons/utils.js.map +1 -0
  145. package/package.json +2 -2
  146. package/dist/api/email/dnsResolver.test.d.ts +0 -1
  147. package/dist/api/email/dnsResolver.test.js +0 -17
  148. package/dist/api/email/parseEmail.test.d.ts +0 -1
  149. package/dist/api/email/parseEmail.test.js +0 -91
  150. package/dist/api/email/preverify.test.d.ts +0 -1
  151. package/dist/api/email/preverify.test.js +0 -109
  152. package/dist/api/lib/client.test.d.ts +0 -1
  153. package/dist/api/lib/client.test.js +0 -106
  154. package/dist/api/utils/prefixAllButNthSubstring.test.d.ts +0 -1
  155. package/dist/api/utils/prefixAllButNthSubstring.test.js +0 -14
  156. package/dist/api/utils/versions.test.d.ts +0 -1
  157. package/dist/api/utils/versions.test.js +0 -39
  158. package/dist/api/webProof/providers/extension.test.d.ts +0 -1
  159. package/dist/api/webProof/providers/extension.test.js +0 -101
@@ -1,91 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import { getDkimSigners, parseEmail, parseParams } from "./parseEmail.js";
3
- const emailHeaders = `From: "John Doe" <john@d.oe>
4
- To: "Jane Doe" <jane@d.oe>
5
- Subject: Hello World
6
- Date: Thu, 1 Jan 1970 00:00:00 +0000
7
- `;
8
- const dkimHeader = "DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; h=from:to:subject; s=selector1; b=abcdef;";
9
- const body = "Hello, World!";
10
- const emailFixture = `${emailHeaders}${dkimHeader}\n\n${body}`;
11
- describe("parseEmail", () => {
12
- test("should get dkim header from email", async () => { });
13
- test("correctly parses untrimmed email", async () => {
14
- const untrimmed = `\n ${emailFixture} \n`;
15
- const email = await parseEmail(untrimmed);
16
- expect(email.headers.find((h) => h.key === "dkim-signature")).toBeDefined();
17
- });
18
- test("works well with multiple dkim headers", async () => {
19
- const dkimHeader2 = "DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=second.signer; h=from:to:subject; s=selector2; b=abcdef;";
20
- const email = await parseEmail(`${emailHeaders}${dkimHeader}\n${dkimHeader2}\n\n${body}`);
21
- const dkim = email.headers.filter((h) => h.key === "dkim-signature");
22
- expect(dkim).toHaveLength(2);
23
- expect(parseParams(dkim[0].value).s).toBe("selector1");
24
- expect(parseParams(dkim[1].value).s).toBe("selector2");
25
- });
26
- });
27
- describe("getDkimSigners", () => {
28
- test("should get dkim signers from email", async () => {
29
- const email = await parseEmail(emailFixture);
30
- const dkim = getDkimSigners(email);
31
- expect(dkim).toHaveLength(1);
32
- expect(dkim[0].domain).toBe("example.com");
33
- expect(dkim[0].selector).toBe("selector1");
34
- });
35
- test("should get multiple dkim signers from email", async () => {
36
- const dkimHeader2 = "DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=second.signer; h=from:to:subject; s=selector2; b=abcdef;";
37
- const email = await parseEmail(`${emailHeaders}${dkimHeader}\n${dkimHeader2}\n\n${body}`);
38
- const dkim = getDkimSigners(email);
39
- expect(dkim).toHaveLength(2);
40
- expect(dkim[0].domain).toBe("example.com");
41
- expect(dkim[0].selector).toBe("selector1");
42
- expect(dkim[1].domain).toBe("second.signer");
43
- expect(dkim[1].selector).toBe("selector2");
44
- });
45
- test("should throw if no dkim header found", async () => {
46
- const email = await parseEmail(emailHeaders);
47
- expect(() => getDkimSigners(email)).toThrowError("No DKIM header found");
48
- });
49
- test("should throw if dkim header is invalid", async () => {
50
- const email = await parseEmail(`${emailHeaders}DKIM-Signature: invalid\n\n${body}`);
51
- expect(() => getDkimSigners(email)).toThrowError("DKIM header missing domain");
52
- });
53
- test("should throw if dkim header is missing domain", async () => {
54
- const email = await parseEmail(`${emailHeaders}DKIM-Signature: v=1; s=selector\n\n${body}`);
55
- expect(() => getDkimSigners(email)).toThrowError("DKIM header missing domain");
56
- });
57
- test("should throw if dkim header is missing selector", async () => {
58
- const email = await parseEmail(`${emailHeaders}DKIM-Signature: v=1; d=example.com\n\n${body}`);
59
- expect(() => getDkimSigners(email)).toThrowError("DKIM header missing selector");
60
- });
61
- });
62
- describe("parseParams", () => {
63
- test("should parse single parameter", () => {
64
- const params = parseParams("a=b");
65
- expect(params).toEqual({ a: "b" });
66
- });
67
- test("should parse multiple parameters", () => {
68
- const params = parseParams("a=b; c=d; e=f");
69
- expect(params).toEqual({ a: "b", c: "d", e: "f" });
70
- });
71
- test("should trim spaces around parameters", () => {
72
- const params = parseParams(" a = b ; c = d ; e = f ");
73
- expect(params).toEqual({ a: "b", c: "d", e: "f" });
74
- });
75
- test("should handle empty values", () => {
76
- const params = parseParams("a=; b=c");
77
- expect(params).toEqual({ a: "", b: "c" });
78
- });
79
- test("should handle missing values", () => {
80
- const params = parseParams("a; b=c");
81
- expect(params).toEqual({ a: undefined, b: "c" });
82
- });
83
- test("should handle empty string", () => {
84
- const params = parseParams("");
85
- expect(params).toEqual({});
86
- });
87
- test("should handle parameters with extra semicolons", () => {
88
- const params = parseParams("a=b;; c=d;");
89
- expect(params).toEqual({ a: "b", c: "d" });
90
- });
91
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,109 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import { readFile } from "../../testHelpers/readFile.js";
3
- import { findIndicesOfMatchingDomains, preverifyEmail } from "./preverify.js";
4
- const rawEmail = readFile("./src/api/email/testdata/test_email.txt");
5
- describe("Preverify email: integration", () => {
6
- test("adds dns record to email mime", async () => {
7
- const preverifiedEmail = await preverifyEmail(rawEmail);
8
- expect(preverifiedEmail).toMatchObject({
9
- email: rawEmail,
10
- dnsRecords: [expect.stringContaining("v=DKIM1; k=rsa; p=")],
11
- });
12
- });
13
- test("throws error if DKIM not found", async () => {
14
- const emailWithNoDkimHeader = 'From: "Alice"\n\nBody';
15
- await expect(preverifyEmail(emailWithNoDkimHeader)).rejects.toThrow("No DKIM header found");
16
- });
17
- test("throws error if DNS could not be resolved", async () => {
18
- const emailWithNoDkimHeader = readFile("./src/api/email/testdata/test_email_unknown_domain.txt");
19
- await expect(preverifyEmail(emailWithNoDkimHeader)).rejects.toThrow();
20
- });
21
- describe("multiple DKIM headers", () => {
22
- function addDkimWithDomain(domain, email) {
23
- return `DKIM-Signature: v=1; a=rsa-sha256; d=${domain};
24
- s=selector; c=relaxed/relaxed; q=dns/txt; bh=; h=From:Subject:Date:To; b=
25
- ${email}`;
26
- }
27
- function addFakeDkimWithDomain(domain, email) {
28
- return `X-${addDkimWithDomain(domain, email)}`;
29
- }
30
- test("looks for DKIM header with the domain matching the sender and removes all other DKIM headers", async () => {
31
- const emailWithAddedHeaders = [
32
- "example.com",
33
- "hello.kitty",
34
- "google.com",
35
- ].reduce((email, domain) => addDkimWithDomain(domain, email), rawEmail);
36
- const email = await preverifyEmail(emailWithAddedHeaders);
37
- expect(email.email
38
- .startsWith(`X-DKIM-Signature: v=1; a=rsa-sha256; d=google.com;
39
- s=selector; c=relaxed/relaxed; q=dns/txt; bh=; h=From:Subject:Date:To; b=
40
- X-DKIM-Signature: v=1; a=rsa-sha256; d=hello.kitty;
41
- s=selector; c=relaxed/relaxed; q=dns/txt; bh=; h=From:Subject:Date:To; b=
42
- DKIM-Signature: v=1; a=rsa-sha256; d=example.com;
43
- s=selector; c=relaxed/relaxed; q=dns/txt; bh=; h=From:Subject:Date:To; b=
44
- X-DKIM-Signature: a=rsa-sha256; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;\r
45
- c=simple/simple; d=google.com;`)).toBeTruthy();
46
- expect(email.dnsRecords).toStrictEqual(["v=DKIM1; p="]);
47
- });
48
- test("throws error if no DNS record domain matches the sender", async () => {
49
- const emailWithAddedHeaders = addDkimWithDomain("otherdomain.com", rawEmail);
50
- await expect(preverifyEmail(emailWithAddedHeaders)).rejects.toThrow("Found 0 DKIM headers matching the sender domain");
51
- });
52
- test("throws error if multiple DNS record domains match the sender", async () => {
53
- let emailWithAddedHeaders = addDkimWithDomain("example.com", rawEmail);
54
- emailWithAddedHeaders = addDkimWithDomain("example.com", emailWithAddedHeaders);
55
- await expect(preverifyEmail(emailWithAddedHeaders)).rejects.toThrow("Found 2 DKIM headers matching the sender domain");
56
- });
57
- test("ignores x-dkim-signature headers", async () => {
58
- const emailWithPrefixedDkim = addDkimWithDomain("example.com", addFakeDkimWithDomain("example.com", rawEmail));
59
- const email = await preverifyEmail(emailWithPrefixedDkim);
60
- expect(email.email
61
- .startsWith(`DKIM-Signature: v=1; a=rsa-sha256; d=example.com;
62
- s=selector; c=relaxed/relaxed; q=dns/txt; bh=; h=From:Subject:Date:To; b=
63
- X-DKIM-Signature: v=1; a=rsa-sha256; d=example.com;
64
- s=selector; c=relaxed/relaxed; q=dns/txt; bh=; h=From:Subject:Date:To; b=
65
- X-DKIM-Signature: a=rsa-sha256; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;\r
66
- c=simple/simple; d=google.com;`)).toBeTruthy();
67
- });
68
- test("ignores dkim-signature somewhere inside a header", async () => {
69
- const headerWithDkim = `WTF-IS-THIS-HEADER: DKIM-SIGNATURE;`;
70
- const emailWithDkimInHeader = `${headerWithDkim}\n${addDkimWithDomain("example.com", rawEmail)}`;
71
- const email = await preverifyEmail(emailWithDkimInHeader);
72
- expect(email.email.startsWith(`WTF-IS-THIS-HEADER: DKIM-SIGNATURE;
73
- DKIM-Signature: v=1; a=rsa-sha256; d=example.com;
74
- s=selector; c=relaxed/relaxed; q=dns/txt; bh=; h=From:Subject:Date:To; b=
75
- X-DKIM-Signature: a=rsa-sha256; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;\r
76
- c=simple/simple; d=google.com;`)).toBeTruthy();
77
- });
78
- test("ignores dkim-signature somewhere inside a body", async () => {
79
- const emailWithAddedDkim = addDkimWithDomain("example.com", rawEmail);
80
- const emailWithDkimsInBody = `${emailWithAddedDkim}\ndkim-signature dkim-signature\r\ndkim-signature`;
81
- const email = await preverifyEmail(emailWithDkimsInBody);
82
- expect(email.email
83
- .startsWith(`DKIM-Signature: v=1; a=rsa-sha256; d=example.com;
84
- s=selector; c=relaxed/relaxed; q=dns/txt; bh=; h=From:Subject:Date:To; b=
85
- X-DKIM-Signature: a=rsa-sha256; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;\r
86
- c=simple/simple; d=google.com;`)).toBeTruthy();
87
- expect(email.email.endsWith(`\ndkim-signature dkim-signature\r\ndkim-signature`)).toBeTruthy();
88
- });
89
- });
90
- });
91
- describe("findIndicesOfMatchingDomains", () => {
92
- test("returns indices of matching domains", () => {
93
- const signers = [
94
- { domain: "example.com", selector: "selector1" },
95
- { domain: "other.other", selector: "selector2" },
96
- { domain: "example.com", selector: "selector3" },
97
- ];
98
- expect(findIndicesOfMatchingDomains(signers, "example.com")).toStrictEqual([
99
- 0, 2,
100
- ]);
101
- });
102
- test("returns empty array if no matching domains", () => {
103
- const signers = [
104
- { domain: "example.com", selector: "selector1" },
105
- { domain: "example.org", selector: "selector2" },
106
- ];
107
- expect(findIndicesOfMatchingDomains(signers, "other.other")).toStrictEqual([]);
108
- });
109
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,106 +0,0 @@
1
- import { describe, expect, it, vi, beforeEach, beforeAll, } from "vitest";
2
- import { createExtensionWebProofProvider } from "../webProof/index.js";
3
- import { createVlayerClient } from "./client.js";
4
- import { ZkProvingStatus } from "src/web-proof-commons";
5
- import createFetchMock from "vitest-fetch-mock";
6
- const fetchMocker = createFetchMock(vi);
7
- fetchMocker.enableMocks();
8
- beforeEach(() => {
9
- global.chrome = {
10
- runtime: {
11
- sendMessage: vi.fn(),
12
- connect: vi.fn().mockImplementation(() => {
13
- return {
14
- onMessage: {
15
- addListener: vi.fn(),
16
- },
17
- postMessage: vi.fn(),
18
- };
19
- }),
20
- },
21
- };
22
- });
23
- function generateRandomHash() {
24
- let hash = "0x";
25
- for (let i = 0; i < 40; ++i) {
26
- hash += Math.floor(Math.random() * 16).toString(16);
27
- }
28
- return hash;
29
- }
30
- describe("Success zk-proving", () => {
31
- let hash;
32
- let zkProvingSpy;
33
- let vlayer;
34
- beforeAll(() => {
35
- hash = generateRandomHash();
36
- const webProofProvider = createExtensionWebProofProvider();
37
- zkProvingSpy = vi.spyOn(webProofProvider, "notifyZkProvingStatus");
38
- vlayer = createVlayerClient({ webProofProvider });
39
- });
40
- it("should send message to extension that zkproving started", async () => {
41
- fetchMocker.mockResponseOnce(() => {
42
- return {
43
- body: JSON.stringify({
44
- result: hash,
45
- }),
46
- };
47
- });
48
- const result = await vlayer.prove({
49
- address: `0x${"a".repeat(40)}`,
50
- functionName: "main",
51
- proverAbi: [],
52
- args: [],
53
- chainId: 42,
54
- });
55
- expect(result.hash).toBe(hash);
56
- expect(zkProvingSpy).toBeCalledTimes(2);
57
- expect(zkProvingSpy).toHaveBeenNthCalledWith(1, ZkProvingStatus.Proving);
58
- });
59
- it("should send message to extension that zkproving is done", async () => {
60
- fetchMocker.mockResponseOnce(() => {
61
- return {
62
- body: JSON.stringify({
63
- result: {
64
- proof: {},
65
- },
66
- }),
67
- };
68
- });
69
- await vlayer.waitForProvingResult({ hash });
70
- expect(zkProvingSpy).toBeCalledTimes(2);
71
- expect(zkProvingSpy).toHaveBeenNthCalledWith(2, ZkProvingStatus.Done);
72
- });
73
- });
74
- describe("Failed zk-proving", () => {
75
- beforeEach(() => {
76
- fetchMocker.mockResponseOnce((req) => {
77
- if (req.url === "http://127.0.0.1:3000/") {
78
- return {
79
- status: 500,
80
- };
81
- }
82
- return {};
83
- });
84
- });
85
- it("should send message to extension that zkproving started and then that failed ", async () => {
86
- const webProofProvider = createExtensionWebProofProvider();
87
- const zkProvingSpy = vi.spyOn(webProofProvider, "notifyZkProvingStatus");
88
- const vlayer = createVlayerClient({ webProofProvider });
89
- try {
90
- const hash = await vlayer.prove({
91
- address: `0x${"a".repeat(40)}`,
92
- functionName: "main",
93
- proverAbi: [],
94
- args: [],
95
- chainId: 42,
96
- });
97
- await vlayer.waitForProvingResult(hash);
98
- }
99
- catch (e) {
100
- console.log("Error waiting for proving result", e);
101
- }
102
- expect(zkProvingSpy).toBeCalledTimes(2);
103
- expect(zkProvingSpy).toHaveBeenNthCalledWith(1, ZkProvingStatus.Proving);
104
- expect(zkProvingSpy).toHaveBeenNthCalledWith(2, ZkProvingStatus.Error);
105
- });
106
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import { prefixAllButNthSubstring } from "./prefixAllButNthSubstring.js";
3
- describe("prefixAllButNthSubstring", () => {
4
- test("adds 'X-' prefix to all matches except n-th (indexed from 0)", () => {
5
- const str = "abc 123 abc 456 abc 789";
6
- expect(prefixAllButNthSubstring(str, /abc/gi, 3, 0)).toBe("abc 123 X-abc 456 X-abc 789");
7
- expect(prefixAllButNthSubstring(str, /abc/gi, 3, 1)).toBe("X-abc 123 abc 456 X-abc 789");
8
- expect(prefixAllButNthSubstring(str, /abc/gi, 3, 2)).toBe("X-abc 123 X-abc 456 abc 789");
9
- });
10
- test("does not add prefix to substrings past total substring count", () => {
11
- const str = "abc 123 abc 456 abc 789 abc abc";
12
- expect(prefixAllButNthSubstring(str, /abc/gi, 3, 1)).toBe("X-abc 123 abc 456 X-abc 789 abc abc");
13
- });
14
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,39 +0,0 @@
1
- import { describe, test, expect } from "vitest";
2
- import { checkVersionCompatibility } from "./versions.js";
3
- describe("versions compatibility", () => {
4
- test("throws if major version mismatches", () => {
5
- expect(() => {
6
- checkVersionCompatibility("1.2.3", "2.1.3");
7
- }).toThrowError("SDK version 2.1.3 is incompatible with prover version 1.2.3");
8
- });
9
- test("throws if major version mismatches with metadata after dash", () => {
10
- expect(() => {
11
- checkVersionCompatibility("1.2.3-dev-123456-deadbeef", "2.1.3");
12
- }).toThrowError("SDK version 2.1.3 is incompatible with prover version 1.2.3-dev-123456-deadbeef");
13
- });
14
- test("throws if major version is 0 and minor version mismatches", () => {
15
- expect(() => {
16
- checkVersionCompatibility("0.2.3", "0.1.3");
17
- }).toThrowError("SDK version 0.1.3 is incompatible with prover version 0.2.3");
18
- });
19
- test("does not throw if major and minor versions match", () => {
20
- expect(() => {
21
- checkVersionCompatibility("1.2.3", "1.2.13");
22
- }).not.toThrow();
23
- });
24
- test("does not throw if major version is >0 and minor mismatches", () => {
25
- expect(() => {
26
- checkVersionCompatibility("1.2.3", "1.5.8");
27
- }).not.toThrow();
28
- });
29
- test("does not throw if major version is 0 and minor matches", () => {
30
- expect(() => {
31
- checkVersionCompatibility("0.2.3", "0.2.7");
32
- }).not.toThrow();
33
- });
34
- test("works for semvers with metadata after dash", () => {
35
- expect(() => {
36
- checkVersionCompatibility("0.2.3-dev-123456-deadbeef", "0.2.7");
37
- }).not.toThrow();
38
- });
39
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,101 +0,0 @@
1
- import { createExtensionWebProofProvider } from "./extension.js";
2
- import { describe, it, expect, vi } from "vitest";
3
- import { expectUrl, startPage, notarize } from "../steps/index.js";
4
- import { StepValidationError } from "../../../web-proof-commons/index.js";
5
- const chrome = {
6
- runtime: {
7
- disconnectCallbacks: [],
8
- connect: vi.fn().mockImplementation(() => ({
9
- postMessage: vi.fn().mockImplementation(() => { }),
10
- onMessage: {
11
- addListener: vi.fn().mockImplementation(() => { }),
12
- },
13
- onDisconnect: {
14
- addListener: vi.fn().mockImplementation((callback) => {
15
- chrome.runtime.disconnectCallbacks.push(callback);
16
- }),
17
- },
18
- })),
19
- disconnect: vi.fn().mockImplementation(() => {
20
- chrome.runtime.disconnectCallbacks.forEach((callback) => {
21
- callback();
22
- });
23
- }),
24
- },
25
- };
26
- vi.stubGlobal("chrome", chrome);
27
- const defaults = {
28
- logoUrl: "https://example.com/logo.png",
29
- proverCallCommitment: {
30
- address: "0x",
31
- proverAbi: [],
32
- chainId: 1,
33
- functionName: "test",
34
- commitmentArgs: null,
35
- },
36
- };
37
- const invalidUrl = "http:/example.com";
38
- const invalidUrlPattern = "http://+.test";
39
- const validUrl = "https://example.com";
40
- const validUrlPattern = "https://example.com/test";
41
- const label = "test";
42
- describe("ExtensionWebProofProvider", () => {
43
- it("should properly validate startPage step", () => {
44
- const provider = createExtensionWebProofProvider();
45
- expect(() => provider.requestWebProof({
46
- ...defaults,
47
- steps: [startPage(invalidUrl, label)],
48
- })).toThrow(StepValidationError);
49
- });
50
- it("should properly validate expectUrl step", () => {
51
- const provider = createExtensionWebProofProvider();
52
- expect(() => provider.requestWebProof({
53
- ...defaults,
54
- steps: [expectUrl(invalidUrlPattern, label)],
55
- })).toThrow(StepValidationError);
56
- });
57
- it("should properly validate notarize step", () => {
58
- const provider = createExtensionWebProofProvider();
59
- expect(() => provider.requestWebProof({
60
- ...defaults,
61
- steps: [notarize(invalidUrlPattern, "GET", label)],
62
- })).toThrow(StepValidationError);
63
- });
64
- it("successfully validates all steps", () => {
65
- const provider = createExtensionWebProofProvider();
66
- expect(() => provider.requestWebProof({
67
- ...defaults,
68
- steps: [
69
- startPage(validUrl, label),
70
- expectUrl(validUrlPattern, label),
71
- notarize(validUrlPattern, "GET", label),
72
- ],
73
- })).not.toThrow(StepValidationError);
74
- });
75
- it("should properly work backward compatible way with only urls used", () => {
76
- const provider = createExtensionWebProofProvider();
77
- expect(() => provider.requestWebProof({
78
- ...defaults,
79
- steps: [
80
- startPage(validUrl, label),
81
- expectUrl(validUrl, label),
82
- expectUrl(validUrl, label),
83
- notarize(validUrl, "GET", label),
84
- ],
85
- })).not.toThrow();
86
- });
87
- it("should reconnect extension on disconnect", () => {
88
- const provider = createExtensionWebProofProvider();
89
- provider.requestWebProof({
90
- ...defaults,
91
- steps: [
92
- startPage(validUrl, label),
93
- expectUrl(validUrlPattern, label),
94
- notarize(validUrlPattern, "GET", label),
95
- ],
96
- });
97
- chrome.runtime.connect.mockClear();
98
- chrome.runtime.disconnect();
99
- expect(chrome.runtime.connect).toHaveBeenCalled();
100
- });
101
- });