Skip to content

Commit

Permalink
iOS build fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
5eeman committed Dec 20, 2024
1 parent 9e0f403 commit 45215d9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# react-native-circom-witnesscalc

React native wrapper for circom-witnesscalc library intended for zero knowledge proof witness calculation.
React native wrapper for [circom-witnesscalc](https://github.com/iden3/circom-witnesscalc) library intended for zero knowledge proof witness calculation.

## Installation

Expand Down
27 changes: 23 additions & 4 deletions example/ios/CircomWitnesscalcExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
00E356F31AD99517003FC87E /* CircomWitnesscalcExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* CircomWitnesscalcExampleTests.m */; };
07316902DD5722F3A813574F /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = DE2A572BA6C92F6FE29AE7D2 /* PrivacyInfo.xcprivacy */; };
0C80B921A6F3F58F76C31292 /* libPods-CircomWitnesscalcExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-CircomWitnesscalcExample.a */; };
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
Expand Down Expand Up @@ -44,6 +45,7 @@
5DCACB8F33CDC322A6C60F78 /* libPods-CircomWitnesscalcExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CircomWitnesscalcExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = CircomWitnesscalcExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
89C6BE57DB24E9ADA2F236DE /* Pods-CircomWitnesscalcExample-CircomWitnesscalcExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CircomWitnesscalcExample-CircomWitnesscalcExampleTests.release.xcconfig"; path = "Target Support Files/Pods-CircomWitnesscalcExample-CircomWitnesscalcExampleTests/Pods-CircomWitnesscalcExample-CircomWitnesscalcExampleTests.release.xcconfig"; sourceTree = "<group>"; };
DE2A572BA6C92F6FE29AE7D2 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = CircomWitnesscalcExample/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -94,6 +96,7 @@
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
13B07FB71A68108700A75B9A /* main.m */,
13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */,
DE2A572BA6C92F6FE29AE7D2 /* PrivacyInfo.xcprivacy */,
);
name = CircomWitnesscalcExample;
sourceTree = "<group>";
Expand Down Expand Up @@ -245,6 +248,7 @@
files = (
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
07316902DD5722F3A813574F /* PrivacyInfo.xcprivacy in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -431,7 +435,7 @@
"-lc++",
"$(inherited)",
);
PRODUCT_BUNDLE_IDENTIFIER = "circomwitnesscalc.example";
PRODUCT_BUNDLE_IDENTIFIER = circomwitnesscalc.example;
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CircomWitnesscalcExample.app/CircomWitnesscalcExample";
};
Expand All @@ -455,7 +459,7 @@
"-lc++",
"$(inherited)",
);
PRODUCT_BUNDLE_IDENTIFIER = "circomwitnesscalc.example";
PRODUCT_BUNDLE_IDENTIFIER = circomwitnesscalc.example;
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CircomWitnesscalcExample.app/CircomWitnesscalcExample";
};
Expand All @@ -468,6 +472,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 6K7H9274Q6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = CircomWitnesscalcExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -480,7 +485,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "circomwitnesscalc.example";
PRODUCT_BUNDLE_IDENTIFIER = circomwitnesscalc.example;
PRODUCT_NAME = CircomWitnesscalcExample;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -495,6 +500,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 6K7H9274Q6;
INFOPLIST_FILE = CircomWitnesscalcExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -506,7 +512,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "circomwitnesscalc.example";
PRODUCT_BUNDLE_IDENTIFIER = circomwitnesscalc.example;
PRODUCT_NAME = CircomWitnesscalcExample;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -582,7 +588,14 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
USE_HERMES = true;
};
name = Debug;
};
Expand Down Expand Up @@ -647,7 +660,13 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
19 changes: 12 additions & 7 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { useState, useEffect } from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { useState } from 'react';
import { Text, View, StyleSheet, Button } from 'react-native';
import { calculateWitness } from 'react-native-circom-witnesscalc';

export default function App() {
const [result, setResult] = useState<string | undefined>();

useEffect(() => {
calculateWitness('', '').then(setResult);
}, []);
const [result, setResult] = useState<string | undefined>('Witness is empty');

return (
<View style={styles.container}>
<Button
title="Calculate Witness"
onPress={async () => {
const base64Witness = await calculateWitness('', '');
const witness = Buffer.from(base64Witness, 'base64');

setResult('Witness length: ' + witness.length);
}}
/>
<Text>Result: {result}</Text>
</View>
);
Expand Down
6 changes: 3 additions & 3 deletions ios/CircomWitnesscalc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ + (BOOL)requiresMainQueueSetup
NSData* graphData = [[NSData alloc]initWithBase64EncodedString:graph options:0];

NSError* error;
NSDictionary *result = [
NSString *result = [
CircomWitnesscalcProxy
calculateWitness: inputsData
graphData: graphData
calculateWitnessProxyWithInputs: inputsData
graph: graphData
error: &error
];

Expand Down
30 changes: 15 additions & 15 deletions ios/CircomWitnesscalcProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import CircomWitnesscalc

@objc(CircomWitnesscalcProxy)
public class CircomWitnesscalcProxy : NSObject {
@objc
public static func calculateWitness(
inputs: NSData,
graph: NSData
) throws -> NSString {
do {
let witness = try calculateWitness(
inputs: inputs as! Data,
graph: graph as! Data
)

return witness.base64EncodedString as NSString
} catch let error {
throw error
}
@objc
public static func calculateWitnessProxy(
inputs: NSData,
graph: NSData
) throws -> NSString {
do {
let witness = try calculateWitness(
inputs: inputs as Data,
graph: graph as Data
)

return witness.base64EncodedString() as NSString
} catch let error {
throw error
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
"type": "modules",
"jsSrcsDir": "src",
"android": {
"javaPackageName": "io.iden3.rn_circom_witnesscalc"
"javaPackageName": "com.circomwitnesscalc"
}
}
}
31 changes: 2 additions & 29 deletions src/NativeCircomWitnesscalc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,7 @@ import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

export interface Spec extends TurboModule {
groth16Prove: (
zkey: string,
witness: string,
proofBufferSize: number | null,
publicBufferSize: number | null,
errorBufferSize: number | null
) => Promise<{ proof: string; pub_signals: string }>;
groth16ProveWithZKeyFilePath: (
zkey_path: string,
witness: string,
proofBufferSize: number | null,
publicBufferSize: number | null,
errorBufferSize: number | null
) => Promise<{ proof: string; pub_signals: string }>;
groth16Verify: (
proof: string,
publicSignals: string,
verificationKey: string,
errorBufferSize: number | null
) => Promise<boolean>;
groth16PublicSizeForZkeyBuf: (
zkey: string,
errorBufferSize: number | null
) => Promise<number>;
groth16PublicSizeForZkeyFile: (
zkeyPath: string,
errorBufferSize: number | null
) => Promise<number>;
calculateWitness: (zkey: string, witness: string) => Promise<string>;
}

export default TurboModuleRegistry.getEnforcing<Spec>('Rapidsnark');
export default TurboModuleRegistry.getEnforcing<Spec>('CircomWitnesscalc');
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const LINKING_ERROR =
const isTurboModuleEnabled = global.__turboModuleProxy != null;

const CircomWitnesscalcModule = isTurboModuleEnabled
? require('./CircomWitnesscalc').default
? require('./NativeCircomWitnesscalc').default
: NativeModules.CircomWitnesscalc;

const CircomWitnesscalc = CircomWitnesscalcModule
Expand Down

0 comments on commit 45215d9

Please sign in to comment.