Skip to content

Instantly share code, notes, and snippets.

View brendanw's full-sized avatar

Brendan brendanw

View GitHub Profile
@brendanw
brendanw / IPlainClient.kt
Last active April 21, 2020 00:19
A hacky means for making api calls with coroutines-native-mt while we wait for ktor bugs to get fixed.
/**
* An http client to use until ktor works with multithreaded coroutines.
* This goes in a common module that ios and android clients depend on.
* We just return a string as shared components can use kotlinx serialization
* thereafter to handle response parsing.
*/
interface IPlainClient {
fun get(
baseUrl: String,
path: String,
open class BaseViewModel<T : Any, R : Any>(
initialState: T
) : CoroutineScope {
private val job = Job()
override val coroutineContext: CoroutineContext = Dispatchers.Main + job
protected val _state = ConflatedBroadcastChannel<T>(initialState)
val state = _state.asFlow()
val cState = state.wrap()
// Function to generate AccountSalt
import { buildPoseidon } from 'circomlibjs';
/**
* Attempt at reproducing the account salt generation that zkemail does on the backend at ->
* https://github.com/zkemail/relayer-utils/blob/aefb00fdcfbfde7fced50e5a0b086e5cc2ff64cd/src/cryptos.rs#L198
* @param email
* @param accountCode
*/
export async function generateAccountSalt(email: string, accountCode: bigint): Promise<string> {