this repo has no description
1import ExpoModulesCore 2 3enum ExpoAtprotoAuthError: Error { 4 case unsupportedAlgorithm(String) 5 case invalidJwk 6 case invalidHeader(String) 7 case invalidPayload(String) 8 case nullSigner 9} 10 11public class ExpoAtprotoAuthModule: Module { 12 public func definition() -> ModuleDefinition { 13 Name("ExpoAtprotoAuth") 14 15 Function("digest") { (data: Data, algo: String) throws -> Data in 16 if algo != "sha256" { 17 throw ExpoAtprotoAuthError.unsupportedAlgorithm(algo) 18 } 19 return CryptoUtil.digest(data: data) 20 } 21 22 Function("getRandomValues") { (byteLength: Int) -> Data in 23 return CryptoUtil.getRandomValues(byteLength: byteLength) 24 } 25 26 Function("generatePrivateJwk") { (algo: String) throws -> JWK in 27 if algo != "ES256" { 28 throw ExpoAtprotoAuthError.unsupportedAlgorithm(algo) 29 } 30 return CryptoUtil.generateJwk() 31 } 32 33 Function("createJwt") { (header: String, payload: String, jwk: JWK) throws -> String in 34 let key = try CryptoUtil.importJwk(x: jwk.x, y: jwk.y, d: jwk.d) 35 let jwt = try JoseUtil.createJwt(header: header, payload: payload, jwk: key) 36 return jwt 37 } 38 39 Function("verifyJwt") { (token: String, jwk: JWK, options: VerifyOptions) throws -> VerifyResponse in 40 let key = try CryptoUtil.importJwk(x: jwk.x, y: jwk.y, d: jwk.d) 41 let res = try JoseUtil.verifyJwt(token: token, jwk: key, options: options) 42 return res 43 } 44 45 AsyncFunction("setValueAsync") { (value: String) in 46 self.sendEvent("onChange", [ 47 "value": value 48 ]) 49 } 50 } 51}