@vlayer/sdk 0.1.0-nightly-20241206-b638b72 → 0.1.0-nightly-20241209-52a03e4
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.
@@ -31,6 +31,10 @@ class ExtensionWebProofProvider {
|
|
31
31
|
connectToExtension() {
|
32
32
|
if (!this.port) {
|
33
33
|
this.port = chrome.runtime.connect(EXTENSION_ID);
|
34
|
+
this.port.onDisconnect.addListener(() => {
|
35
|
+
this.port = null;
|
36
|
+
this.connectToExtension();
|
37
|
+
});
|
34
38
|
this.port.onMessage.addListener((message) => {
|
35
39
|
if (message.type === ExtensionMessageType.ProofDone) {
|
36
40
|
this.listeners[ExtensionMessageType.ProofDone]?.forEach((cb) => {
|
@@ -1,7 +1,29 @@
|
|
1
1
|
import { createExtensionWebProofProvider } from "./extension.js";
|
2
|
-
import { describe, it, expect } from "vitest";
|
2
|
+
import { describe, it, expect, vi } from "vitest";
|
3
3
|
import { expectUrl, startPage, notarize } from "../steps/index.js";
|
4
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);
|
5
27
|
const defaults = {
|
6
28
|
logoUrl: "https://example.com/logo.png",
|
7
29
|
proverCallCommitment: {
|
@@ -60,6 +82,20 @@ describe("ExtensionWebProofProvider", () => {
|
|
60
82
|
expectUrl(validUrl, label),
|
61
83
|
notarize(validUrl, "GET", label),
|
62
84
|
],
|
63
|
-
})).not.toThrow(
|
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();
|
64
100
|
});
|
65
101
|
});
|
package/package.json
CHANGED