diff --git a/package.json b/package.json index f5607f7d4..8fe93ff16 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "cljs:report": "clojure -M:cljs run shadow.cljs.build-report app report.html" }, "dependencies": { + "bip39": "^3.0.3", "codemirror": "^5.58.1", "diff": "^4.0.2", "fuzzysort": "^1.1.4", diff --git a/src/main/frontend/fs.cljs b/src/main/frontend/fs.cljs index 16e46ee6f..0904f940a 100644 --- a/src/main/frontend/fs.cljs +++ b/src/main/frontend/fs.cljs @@ -11,7 +11,8 @@ [lambdaisland.glogi :as log] ["/frontend/utils" :as utils] ["tweetnacl" :as nacl] - ["tweetnacl-util" :as nacl-util])) + ["tweetnacl-util" :as nacl-util] + ["bip39" :as bip39])) ;; We need to cache the file handles in the memory so that ;; the browser will not keep asking permissions. @@ -125,7 +126,9 @@ :else (js/window.workerThread.rimraf dir))) -(defonce secret "IRwamok0gbumjx41O0z83V/nzcqrac5vML6P62zS23c=") +;; (println (bip39/generateMnemonic 256)) +;; (defonce secret "IRwamok0gbumjx41O0z83V/nzcqrac5vML6P62zS23c=") +(defonce secret (bip39/mnemonicToSeedSync "canal this pluck bar elite tape olive toilet cry surprise dish rival wrist tragic click honey solar kangaroo cook cabin replace harvest horse wrong")) (defn new-nonce [] @@ -134,10 +137,9 @@ (defn encrypt [key content] (when key - (let [key-decoded (nacl-util/decodeBase64 key) - nonce (new-nonce) + (let [nonce (new-nonce) content-decoded (nacl-util/decodeUTF8 content) - box (nacl/secretbox content-decoded nonce key-decoded) + box (nacl/secretbox content-decoded nonce key) full-message (new js/Uint8Array (+ nonce.length box.length))] (js/console.log "nonce" (nacl-util/encodeBase64 nonce)) (js/console.log "box" (nacl-util/encodeBase64 box)) @@ -148,11 +150,10 @@ (defn decrypt [key content-with-nonce] (when key - (let [key-decoded (nacl-util/decodeBase64 key) - content-with-nonce-decoded (nacl-util/decodeBase64 content-with-nonce) + (let [content-with-nonce-decoded (nacl-util/decodeBase64 content-with-nonce) nonce (.slice content-with-nonce-decoded 0 nacl/secretbox.nonceLength) content (.slice content-with-nonce-decoded nacl/secretbox.nonceLength content-with-nonce.length) - decrypted (nacl-util/encodeUTF8 (nacl/secretbox.open content nonce key-decoded))] + decrypted (nacl-util/encodeUTF8 (nacl/secretbox.open content nonce key))] (println "decrypted" decrypted) decrypted))) diff --git a/yarn.lock b/yarn.lock index 480f8105b..529a541bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -303,6 +303,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.13.tgz#9e425079799322113ae8477297ae6ef51b8e0cdf" integrity sha512-vbxr0VZ8exFMMAjCW8rJwaya0dMCDyYW2ZRdTyjtrCvJoENMpdUHOT/eTzvgyA5ZnqRZ/sI0NwqAxNHKYokLJQ== +"@types/node@11.11.6": + version "11.11.6" + resolved "https://registry.yarnpkg.com/@types/node/-/node-11.11.6.tgz#df929d1bb2eee5afdda598a41930fe50b43eaa6a" + integrity sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ== + "@types/normalize-package-data@^2.4.0": version "2.4.0" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" @@ -727,6 +732,16 @@ bindings@^1.5.0: dependencies: file-uri-to-path "1.0.0" +bip39@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/bip39/-/bip39-3.0.3.tgz#4a8b79067d6ed2e74f9199ac994a2ab61b176760" + integrity sha512-P0dKrz4g0V0BjXfx7d9QNkJ/Txcz/k+hM9TnjqjUaXtuOfAvxXSw2rJw8DX0e3ZPwnK/IgDxoRqf0bvoVCqbMg== + dependencies: + "@types/node" "11.11.6" + create-hash "^1.1.0" + pbkdf2 "^3.0.9" + randombytes "^2.0.1" + bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.4.0: version "4.11.9" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828" @@ -4152,7 +4167,7 @@ path-type@^4.0.0: resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== -pbkdf2@^3.0.3: +pbkdf2@^3.0.3, pbkdf2@^3.0.9: version "3.1.1" resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.1.1.tgz#cb8724b0fada984596856d1a6ebafd3584654b94" integrity sha512-4Ejy1OPxi9f2tt1rRV7Go7zmfDQ+ZectEQz3VGUQhgq62HtIRPDyG/JtnwIxs6x3uNMwo2V7q1fMvKjb+Tnpqg==