forro

End-to-end encrypted contract form based on PGP.
git clone git://git.defalsify.org/forro.git
Info | Log | Files | Refs | README | LICENSE

top.js (3291B)


      1 /** prefix for publickey record in remote mutable storage **/
      2 const PUBKEY_PFX  = 'pgp.publickey';
      3 /**
      4  * Bitflag state which tracks all possible states across the application lifetime
      5  *
      6  * @prop {number} DEV Application is running in developer mode
      7  * @prop {number} PANIC Application has panicked i.e. terminated abnormally
      8  * @prop {number} RTS Application is ready to submit content to the backend
      9  * @prop {number} SEND_ERROR Last attempt at sending content to the backend failed
     10  * @prop {number} SETTINGS Settings have been successfully loaded
     11  * @prop {number} REMOTE_KEY Remote encryption key has been successfully loaded
     12  * @prop {number} LOCAL_KEY Local private key exists in store
     13  * @prop {number} LOCAL_KEY_DECRYPTED Local private key has been decrypted and currently resides in memory
     14  * @prop {number} LOCAL_KEY_IDENTIFIED User has provided some identifiable information for the private key (there is no guarantee this is real or not, of course)
     15  * @prop {number} LOCAL_KEY_GENERATE A new local private key has been generated this session
     16  * @prop {number} PASSPHRASE_ACTIVE User has provided a passphrase to unlock the local key
     17  * @prop {number} PASSPHRASE_FAIL Last provided passphrase by user failed to unlock the local key
     18  * @prop {number} ACK_MESSAGE Data endpoint has confirmed receipt of message
     19  * @prop {number} ENC_MESSAGE Message was successfully encrypted locally (and is ready to be sent to remote)
     20  * @prop {number} ACK_PUBKEY Data endpoint has confirmed receipt of public key data for local key
     21  * @prop {number} ENC_PUBKEY Local key publickey was successfully encrypted locally (and is ready to be sent to remote)
     22  * @prop {number} ACK_COUNTER Data endpoint has confirmed receipt of updated message counter 
     23  * @prop {number} ENC_COUNTER Message counter was successfully encrypted locally (and is ready to be sent to remote)
     24  * @prop {number} HELP Application is providing contextual help
     25  * @prop {number} FILE_PROCESS A request to attach a file to the message has been initiated.
     26  * @prop {number} FILE_ADDED A request to attach a file has been successfully processed. Submission will now contain the file content as part of the message.
     27  **/
     28 const STATE = {
     29 	DEV: 1 << 0,
     30 	PANIC: 1 << 1,
     31 	RTS:  1 << 2,
     32 	SEND_ERROR: 1 << 3,
     33 	SETTINGS: 1 << 4,
     34 	REMOTE_KEY: 1 << 5,
     35 	LOCAL_KEY: 1 << 6,
     36 	LOCAL_KEY_DECRYPTED: 1 << 7,
     37 	LOCAL_KEY_IDENTIFIED: 1 << 8,
     38 	LOCAL_KEY_GENERATE: 1 << 9,
     39 	PASSPHRASE_ACTIVE: 1 << 10,
     40 	PASSPHRASE_FAIL: 1 << 11,
     41 	ACK_MESSAGE: 1 << 12,
     42 	ENC_MESSAGE: 1 << 13,
     43 	ACK_PUBKEY: 1 << 14,
     44 	ENC_PUBKEY: 1 << 15,
     45 	ACK_COUNTER: 1 << 16,
     46 	ENC_COUNTER: 1 << 17,
     47 	HELP: 1 << 18,
     48 	FILE_PROCESS: 1 << 19,
     49 	FILE_ADDED: 1 << 20,
     50 };
     51 const STATE_KEYS = Object.keys(STATE);
     52 
     53 let g_passphrase = undefined;
     54 let g_passphrase_use = true;
     55 let g_passphrase_time = 0;
     56 let g_remote_key = undefined;
     57 let g_local_key = undefined;
     58 let g_remote_key_id = '(none)';
     59 let g_remote_key_name = '?';
     60 let g_remote_key_email = undefined;
     61 let g_local_key_id = '(none)';
     62 let g_local_key_name = '?';
     63 let g_local_key_identified = false;
     64 let g_data_endpoint = window.location.href;
     65 let g_state = 0;
     66 let g_helpstate = 0;
     67 let g_counter = undefined;
     68 let g_files = {};
     69 let g_version = '0.1.0';
     70 let g_from = 'no-reply@localhost';
     71 let g_from_name = 'Forro v' + g_version;