Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 5fa68a6

Browse files
committed
feat: add offline adr
1 parent 0cd33d7 commit 5fa68a6

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

offline_verifying.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# OpenAttestation Verifier
2+
3+
## Problem
4+
5+
Currently, after a document has been issued in the Document Creator, the user has to download the file before clicking the Verify Documents tab and uploading the document for verification which may be cumbersome. Created documents can be easily accessed through their `links.self.href` attribute only because the Document creator uses this function to upload the document to a server:
6+
7+
```js
8+
export const uploadToStorage = async (
9+
doc: WrappedDocument,
10+
documentStorage: DocumentStorage
11+
): Promise<AxiosResponse> => {
12+
const qrCodeObj = decodeQrCode(doc.rawDocument.links.self.href);
13+
const uri = qrCodeObj.payload.uri;
14+
15+
return axios({
16+
method: "post",
17+
url: uri,
18+
headers: getHeaders(documentStorage),
19+
data: {
20+
document: doc.wrappedDocument,
21+
},
22+
});
23+
};
24+
```
25+
However, as the user may not have consented to an upload, this poses a problem in our current workflow. The current implementation of easy verification of a document can be found in the [gallery](https://gallery.openattestation.com/).
26+
27+
## Goal
28+
29+
To explore the option of opening a document without uploading it to a server. This will save the step of downloading, opening another window and uploading the document. Possible usecases include: Allowing a user to view a .tt document with .tt files as attachments easily in another tab.
30+
31+
## Proposed Solution
32+
33+
We can use the postMessage method to conduct parent and child communication. To detect the message sent, an eventListener can be added in the DropZone. For example:
34+
35+
```js
36+
window.addEventListener(
37+
"message",
38+
(event) => {
39+
if (event.data.document) {
40+
updateCertificate(event.data.document);
41+
}
42+
},
43+
false
44+
);
45+
46+
```
47+
48+
In order for the parent to communicate with its child window, a reference can be saved to the return value of `window.open()`. For example:
49+
50+
```js
51+
const childWin = window.open(url, "_blank");
52+
```
53+
54+
Once the reference is made, the parent can send messages to the child window via postMessage:
55+
56+
```js
57+
childWin.postMessage({ document: MY_JSON_FILE });
58+
```
59+
60+
## Alternative Solution
61+
62+
Other methods we considered were:
63+
64+
1. LocalStorage method
65+
We could store the document data on the user's local storage and upon clicking the Verify Document tab, load the data into the verifier before clearing it. However, this method is not recommended as there is no data protection, creating a security risk. There is also a ~5MB data limit which may be too low to store document data. Objects cannot be stored as well and must be stringified.
66+
67+
2. Broadcast Channel API
68+
We could create a channel to allow a child window to subscribe to, enabling it to receive messages from its parent. More information about the implementation can be found [here](https://dev.to/dcodeyt/send-data-between-tabs-with-javascript-2oa). This method is better than listening to changes on the local storage as it is more secure and full objects can be posted. However, as of November 2020, this method is not supported by Safari, IE and Edge.

0 commit comments

Comments
 (0)