The app fetches the structured data that contains your email data.
Contents
Check if a config file is present
To check if there's a config file in its root directory, the app attempts to retrieve a file called "config".
Copy GET /nfs/file/:rootPath/:filePath
nfs_actions.js
Copy export const getConfigFile = token => {
return {
type: ACTION_TYPES.GET_CONFIG_FILE,
payload: {
request: {
url: `/nfs/file/${CONSTANTS.ROOT_PATH}/config`,
headers: {
'Authorization': token,
Range: 'bytes=0-'
},
responseType: 'arraybuffer'
}
}
};
};
If a config file is not found
The app will create a root structured data with a random ID. All structured data items need to have an ID that is 32 bytes long. Therefore, the app generates a 32 bytes long random ID using this function:
app_utils.js
Copy export const generateStructredDataId = () => {
return base64.encode(crypto.randomBytes(32).toString('base64'));
};
Copy {
"id": "",
"saved": []
}
Get a cipher options handle
First, the app fetches a cipher options handle for symmetric encryption.
Copy /cipher-opts/:encType/:keyHandle?
cipher-opts_actions.js
Copy export const getCipherOptsHandle = (token, encType, keyHandle='') => ({
type: ACTION_TYPES.GET_CIPHER_OPTS_HANDLE,
payload: {
request: {
url: `/cipher-opts/${encType}/${keyHandle}`,
headers: {
'Authorization': token,
}
}
}
});
Create a root structured data
Copy POST /structured-data
structured_data_actions.js
Copy export const createStructuredData = (token, name, data, cipherHandle) => ({
type: ACTION_TYPES.CREATE_STRUCTURED_DATA,
payload: {
request: {
method: 'post',
url: '/structured-data',
headers: {
'Authorization': token
},
data: {
name,
typeTag: CONSTANTS.TAG_TYPE.DEFAULT,
cipherOpts: cipherHandle,
data: new Buffer(JSON.stringify(data)).toString('base64')
}
}
}
});
Drop the cipher handle
The app drops the "cipher options" handle for symmetric encryption.
Copy DELETE /cipher-opts/:handleId
cipher-opts_actions.js
Copy export const deleteCipherOptsHandle = (token, handleId) => ({
type: ACTION_TYPES.DELETE_CIPHER_OPTS_HANDLE,
payload: {
request: {
method: 'delete',
url: `/cipher-opts/${handleId}`,
headers: {
'Authorization': token,
}
}
}
});
Save the root structured data
The app saves your root structured data to the SAFE Network.
Copy PUT /structured-data/:handleId
structured_data_actions.js
Copy export const putStructuredData = (token, handleId) => ({
type: ACTION_TYPES.PUT_STRUCTURED_DATA,
payload: {
request: {
method: 'put',
url: `/structured-data/${handleId}`,
headers: {
'Authorization': token
}
}
}
});
Create a config file
After your root structured data is successfully created, the app stores its ID in a config file. That way, the app will be able to retrieve your email data in the future.
This config file is stored in the app's root directory, which is private. Therefore, it will automatically be encrypted and no one else will be able to read it.
Copy POST /nfs/file/:rootPath/:filePath
nfs_actions.js
Copy export const writeConfigFile = (token, coreId) => {
return {
type: ACTION_TYPES.WRITE_CONFIG_FILE,
payload: {
request: {
method: 'post',
url: `/nfs/file/${CONSTANTS.ROOT_PATH}/config`,
headers: {
'Authorization': token,
'Content-Type': 'plain/text'
},
data: new Uint8Array(Buffer(coreId))
}
}
}
};
After the config file is successfully created, the app transitions to the Create Account page.
If a config file is found
The app will fetch your email data (email ID and saved emails) using the ID stored in the config file.
Get a data identifier handle
First, the app fetches a data identifier handle using the ID of your root structured data.
Copy POST /data-id/structured-data
data_id_handle_actions.js
Copy export const getStructuredDataIdHandle = (token, name, typeTag) => ({
type: ACTION_TYPES.GET_STRUCTURED_DATA_ID_HANDLE,
payload: {
request: {
method: 'post',
url: '/data-id/structured-data',
headers: {
'Authorization': token
},
data: {
typeTag,
name
}
}
}
});
Get a structured data handle
The app fetches a structured data handle using the data identifier handle of your root structured data.
Copy GET /structured-data/handle/:dataIdHandle
structured_data_actions.js
Copy export const fetchStructuredDataHandle = (token, dataIdHandle) => ({
type: ACTION_TYPES.FETCH_STRUCTURE_DATA_HANDLE,
payload: {
request: {
url: `/structured-data/handle/${dataIdHandle}`,
headers: {
'Authorization': token
}
}
}
});
Fetch the root structured data
After the structured data handle is successfully retrieved, the app fetches the structured data that contains your email data.
Copy GET /structured-data/:handleId/:version?
structured_data_actions.js
Copy export const fetchStructuredData = (token, handleId) => ({
type: ACTION_TYPES.FETCH_STRUCTURED_DATA,
payload: {
request: {
url: `/structured-data/${handleId}`,
headers: {
'Authorization': token,
'Content-Type': 'text/plain'
}
}
}
});
If the structured data doesn't contain an email ID
If you hadn't created an email ID yet, the app transitions to the Create Account page.
If the structured data contains an email ID
If you had already created an email ID, the app transitions to the Inbox page.