0

I am creating a school project, a secure chat like whatsapp / signal. https://github.com/andeluvian/React-Chat

The application works ok, its still a mess but what i need help with to continue the project is to create a local storage for registrationId, keyId,IdentityKeyPair, PreKey, SignedPreKey

What i have tested with is the InMemoryStorage and i can see from logs that i can save most of everything in there.

When i cleared the Authentication.Js to create the localStorage i kinda feel like its not really what i should be doing.

At the SubmitHandle(e)

i do

window.localStorage.setItem('username', this.state.username);
var registrationid = KeyHelper.generateregistrationId();
window.localstorage.setItem('registrationId', registrationId);

At this point everything is fine however when i add identitykeyPair/PreKey/SignedPreKey which is another object i feel like im getting into a mess i use JSON.Stringify to put the objects into localstorage and get Inside Storage

preKey:"{"keyId":1,"keyPair":{"pubKey":{},"privKey":{}}}"

And using JSON.parse i get:

Object
keyId:1
-keyPair: Object
+privKey:Object
+pubKey:Object

:D the pub and privkey should be ArrayBuffer. Can someone brave enough help me create this part where i can store my junk into localstorage and also retrieve it?

Ps. I know there is a lot of easy ways and different libraries out there, but I am kinda limited to the project scope and requirements.

-E2E encrypted chat -Use whisper systems signal protocol

My app uses https://github.com/kentandlime/simple-chat-api as API because the frontend is made from their tutorial.

git elsehow/signal-protocol

I am using the forked library for signal protocol

m00se
  • 11
  • 4
  • take a look at https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API#Storage_limits instead of local storage – Adam Wolski Feb 26 '17 at 20:53
  • Possible duplicate of [Converting between strings and ArrayBuffers](http://stackoverflow.com/questions/6965107/converting-between-strings-and-arraybuffers) – JosiahDaniels Mar 15 '17 at 15:32
  • Hmm i have heard also my teacher say there is a duplicate or it is not necessary to have duplicates, but at the moment I dont know of a better way to store the data of arraybuffer and then load it so it can be used again by the signal protocol – m00se Mar 16 '17 at 16:58
  • `KeyHelper.generateIdentityKeyPair().then((identityKeyPair)=>{ var int32 = new Uint8Array(identityKeyPair.pubKey); var int23 = new Uint8Array(identityKeyPair.privKey); localStorage.setItem('pubKey', JSON.stringify(int32)); localStorage.setItem('privKey',JSON.stringify(int23)); }); var arr1 =localStorage.getItem('privKey'); var arr2 = localStorage.getItem('pubKey'); var a1 = new Uint8Array(arr1); var a2 = new Uint8Array(arr2); let identityKeyPair ={ pubKey: a2.buffer, privKey: a1.buffer }; console.log(identityKeyPair);` – m00se Mar 16 '17 at 17:00

0 Answers0