Attempt to implement subtlecrypto key importing (untested)

This commit is contained in:
Emi Simpson 2022-10-19 17:43:54 -04:00
parent 379260d457
commit 6885935089
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
3 changed files with 31 additions and 1 deletions

View File

@ -124,3 +124,24 @@ with base64 =
, version =
"v0.0.8" -- branch, tag, or commit hash
}
with subtlecrypto =
{ dependencies =
[ "aff"
, "aff-promise"
, "arraybuffer-types"
, "console"
, "effect"
, "either"
, "exceptions"
, "foreign"
, "functions"
, "maybe"
, "prelude"
, "transformers"
, "tuples"
, "unsafe-coerce"
]
, repo =
"https://github.com/xc-jp/purescript-subtlecrypto.git"
, version = "master"
}

View File

@ -22,6 +22,7 @@ to generate this file without the comments in this block.
, "maybe"
, "prelude"
, "strings"
, "subtlecrypto"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]

View File

@ -9,12 +9,16 @@ import Effect.Console (log)
import Fetch (fetch)
import Data.Binary.Base64 (decode)
import Data.Either (Either, hush, note)
import Data.ArrayBuffer.Types (Uint8Array)
import Data.Maybe (Maybe(..))
import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array)
import Data.String (drop, indexOf', indexOf, splitAt)
import Data.String.Pattern (Pattern(..))
import Crypto.Subtle.Constants.AES (aesGCM)
import Crypto.Subtle.Key.Import (aes)
import Crypto.Subtle.Key.Import (importKey) as SC
import Crypto.Subtle.Key.Types (CryptoKey, decrypt, raw)
data AviaryError
= MalformedKey
| MalformedUrl
@ -40,6 +44,10 @@ parseUrl url = note MalformedUrl do
decodeKey :: String -> Either AviaryError Uint8Array
decodeKey key = note MalformedKey $ hush $ decode key
importKey :: ArrayBuffer -> Aff CryptoKey
importKey key =
SC.importKey raw key (aes aesGCM) false [decrypt]
main_aff :: Aff Unit
main_aff = do
{ status, text } <- fetch "https://envs.sh/Q_V.txt" {}