Skip to content

Instantly share code, notes, and snippets.

// If you want to do something related to analytics in your app , then you should work in this file.
class AnalyticsService: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
#if ALPHA
//register with one id
#else
//Register with another one
#endif
//Analytics manager starttracking
#import "AppServicesSwift-Swift.h"
@implementation AppDelegate (Forward)
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
for (UIResponder<UIApplicationDelegate> *service in self.services) {
if ([service respondsToSelector: anInvocation.selector]) {
[anInvocation invokeWithTarget: service];
}
class AppDelegate: UIResponder, UIApplicationDelegate {
@objc public var window: UIWindow?
@objc public let services: [UIApplicationDelegate] = [
PersistenceService(),
AnalyticsService(),
CrashReporterService()
]
@cyborch
cyborch / Verify.kt
Created August 2, 2019 11:29
Verify membership of a set in an RSA accumulator
fun verifyMembership(A: BigInteger, x: BigInteger, proof: BigInteger): Boolean {
return proof.modPow(x, n) == A
}
@cyborch
cyborch / Prove.kt
Created August 2, 2019 11:24
Prove membership of a set in an RSA accumulator
fun proveMembershipOrNull(x: BigInteger): RSAProof? {
return if (!data.containsKey(x)) {
null
} else {
var product = BigInteger.ONE
for ((k, v) in data) {
if (k != x) {
product *= hashToPrime(k, ACCUMULATED_PRIME_SIZE, v).first
}
}
@cyborch
cyborch / AddToAccumulator.kt
Last active August 2, 2019 11:16
Snippet of RSA accumulator which demonstrates adding a value to a set
fun add(x: BigInteger): RSACommit {
return if (data.containsKey(x)) {
commitment
} else {
val (hashPrime, nonce) = hashToPrime(x, ACCUMULATED_PRIME_SIZE)
commitment = commitment.modPow(hashPrime, n)
data[x] = nonce
commitment
}
}
@cyborch
cyborch / Verifier.kt
Created August 2, 2019 10:15
Verifier service for cryptographic accumulator
fun main() {
val app = Javalin.create().start(7000)
app.post("/verify") { ctx ->
val body = ctx.bodyAsClass(VerifyBody::class.java)
ctx.json(RSAAccumulator.verifyMembership(BigInteger(body.commitment), body.proof))
}
}
@cyborch
cyborch / Prover.kt
Created August 2, 2019 10:11
Prover service for cryptographic accumulator
fun main() {
val acc = RSAAccumulator()
val app = Javalin.create().start(7000)
app.get("/commitment") { ctx ->
ctx.result(acc.commitment.toString(10))
}
app.put("/add/:member") { ctx ->
val member = ctx.pathParam("member")
acc.add(member)
ctx.json(ProofResponse(acc.proveMembership(member)))
@cyborch
cyborch / docker-helper.sh
Created April 6, 2018 11:08
Docker helper functions
#!/bin/bash
# Activate a named docker machine
docker-machine-set-active() {
eval $(docker-machine env $1)
}
# Create digital ocean droplet
docker-create-droplet() {
if [[ "$1" == "" || "$2" == "" || "$3" == "" ]] ; then
@cyborch
cyborch / xcode.sh
Created March 6, 2018 15:42
Open specified xcode project or workspace, or open a workspace or project in specified directory
# Open specified xcode project or worspace, or open a workspace or project in specified directory
xcode() {
dir=`pwd`
if [[ "$1" != "" ]] ; then
if [ ! -d $1 ] ; then
open -a Xcode $1
return
else