Initialization
Last updated
Was this helpful?
Last updated
Was this helpful?
First, the app needs to receive an authorization token from SAFE Launcher. Then, it needs to obtain a cipher options handle and fetch a config file.
store.js
For this example app, APP_NAME
, APP_ID
and APP_VERSION
have been set to the following values:
config.js
SAFE Launcher displays a prompt with basic information about the app along with the requested permission (LOW_LEVEL_API
). You can authorize this request by clicking on "ALLOW".
After you authorize the request, the app receives an authorization token and stores it in a global variable.
store.js
The app fetches a cipher options handle for symmetric encryption. It will be used to encrypt your Markdown files. That way, only you will be able to read them.
store.js
The app stores the cipher options handle in a global variable.
store.js
The solution is to generate a random "user prefix" and store it inside a config file located in the app's root directory. This random user prefix will be used to assign IDs to the files you create. The ID of each file will be based on your user prefix and the filename. That way, the app can reuse the same random user prefix instead of creating a new one for each file.
In order to keep track of the filenames, the app creates a file index that will be used to store the names of all your files. This file index will be stored inside an unversioned structured data with an ID based on your user prefix.
Therefore, the app is able to retrieve all your files simply by retrieving your user prefix, which will be stored inside a config file located in the app's root directory. Using your user prefix, the app can fetch your file index, which contains the names of all your files. Individual files can be fetched using your user prefix and the filename.
The app generates a random "user prefix" that will be used to assign IDs to the files you create.
store.js
The app tries to create a config file in its root directory. This config file is used to store your user prefix.
store.js
For this example app, FILE_NAME
has been set to app_config.json
.
store.js
If a config file called app_config.json
already exists in the app's root directory, SAFE Launcher will return an error and the app will simply use the existing config file instead.
The app reads the content of the config file.
store.js
The app then stores your user prefix – which was contained inside the config file – in a global variable.
store.js
The app sends an to SAFE Launcher.
Each Markdown file you create will be stored inside a new . The app needs a way to retrieve your files on the SAFE Network. If the app doesn't properly keep track of the data it creates using the , the user might be unable to retrieve and delete data stored by the app.
Finally, the app needs to associated with your user prefix. Your file index contains the name of all your files.