From 2e8b6cc4caa9f0973358fed867759613bd265de6 Mon Sep 17 00:00:00 2001 From: Yaroslav Moria <5eeman@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:18:02 +0100 Subject: [PATCH 1/2] Fixed example. Added integration tests for BJJ lib. Removed obsolete rust package and flutter-wrapper folder. --- android/build.gradle | 2 + example/android/app/build.gradle | 5 +- example/integration_test/app_test.dart | 194 ---- example/integration_test/bjj_test.dart | 95 ++ .../integration_test/libpolygonid_test.dart | 134 ++- example/ios/Podfile | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 397 ++++++- example/ios/Runner/AppDelegate.swift | 2 +- example/ios/Runner/Base.lproj/Main.storyboard | 13 +- ios/Classes/SwiftPolygonIdSdkPlugin.swift | 9 + ios/polygonid_flutter_sdk.podspec | 2 +- lib/identity/libs/bjj/eddsa_babyjub.dart | 6 +- polygonid-flutter-wrapper/.gitignore | 50 - polygonid-flutter-wrapper/.metadata | 10 - polygonid-flutter-wrapper/README.md | 3 - .../analysis_options.yaml | 4 - polygonid-flutter-wrapper/lib/main.dart | 21 - .../maven-publish.gradle | 87 -- polygonid-flutter-wrapper/pubspec.yaml | 95 -- rust/Cargo.lock | 977 ------------------ rust/Cargo.toml | 35 - rust/Makefile | 104 -- rust/benches/bench_babyjubjub.rs | 58 -- rust/cbindgen.toml | 8 - rust/rs-lib-android-build.sh | 11 - rust/src/eddsa/mod.rs | 753 -------------- rust/src/eddsa/utils.rs | 268 ----- rust/src/lib.rs | 685 ------------ 28 files changed, 549 insertions(+), 3481 deletions(-) delete mode 100644 example/integration_test/app_test.dart create mode 100644 example/integration_test/bjj_test.dart delete mode 100644 polygonid-flutter-wrapper/.gitignore delete mode 100644 polygonid-flutter-wrapper/.metadata delete mode 100644 polygonid-flutter-wrapper/README.md delete mode 100644 polygonid-flutter-wrapper/analysis_options.yaml delete mode 100644 polygonid-flutter-wrapper/lib/main.dart delete mode 100644 polygonid-flutter-wrapper/maven-publish.gradle delete mode 100644 polygonid-flutter-wrapper/pubspec.yaml delete mode 100644 rust/Cargo.lock delete mode 100644 rust/Cargo.toml delete mode 100644 rust/Makefile delete mode 100644 rust/benches/bench_babyjubjub.rs delete mode 100644 rust/cbindgen.toml delete mode 100644 rust/rs-lib-android-build.sh delete mode 100644 rust/src/eddsa/mod.rs delete mode 100644 rust/src/eddsa/utils.rs delete mode 100644 rust/src/lib.rs diff --git a/android/build.gradle b/android/build.gradle index 0a18a387a..110368c72 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -34,6 +34,8 @@ android { compileSdkVersion 34 ndkVersion "26.3.11579264" + namespace "io.iden3.polygonid_flutter_sdk" + compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 376ada65b..6a0602266 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -51,9 +51,8 @@ android { versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - ndk{ - // TODO: armeabi-v7a and x86 not supported yet - abiFilters 'arm64-v8a', 'x86_64' /*,'armeabi-v7a', 'x86',*/ + ndk { + abiFilters 'arm64-v8a', 'x86_64' } } diff --git a/example/integration_test/app_test.dart b/example/integration_test/app_test.dart deleted file mode 100644 index 1f05aa9c9..000000000 --- a/example/integration_test/app_test.dart +++ /dev/null @@ -1,194 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_svg/flutter_svg.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:integration_test/integration_test.dart'; -import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; -import 'package:polygonid_flutter_sdk/identity/domain/exceptions/identity_exceptions.dart'; -import 'package:polygonid_flutter_sdk_example/src/presentation/app.dart'; -import 'package:polygonid_flutter_sdk_example/src/presentation/dependency_injection/dependencies_provider.dart' - as di; -import 'package:polygonid_flutter_sdk_example/src/presentation/navigations/routes.dart'; -import 'package:polygonid_flutter_sdk_example/src/presentation/ui/auth/widgets/auth.dart'; -import 'package:polygonid_flutter_sdk_example/utils/custom_dimensions.dart'; -import 'package:polygonid_flutter_sdk_example/utils/custom_strings.dart'; - -//import 'app_test.mocks.dart'; - -const String identifier = "retrievedIdentifier"; -const String invalidQrCodeScanResponse = "invalidQrCodeScanResponse"; -const String validQrCodeScanResponse = - '{"id":"193546d2-db06-4c49-8e92-686dd5c92b23",' - '"typ":"application/iden3comm-plain-json",' - '"type":"https://iden3-communication.io/authorization/1.0/request",' - '"thid":"193546d2-db06-4c49-8e92-686dd5c92b23",' - '"body":{"callbackUrl":"https://issuer.polygonid.me/api/callback?sessionId=148757","reason":"test flow","scope":[]},' - '"from":"1125GJqgw6YEsKFwj63GY87MMxPL9kwDKxPUiwMLNZ"}'; - -@GenerateMocks([]) -void main() { - IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - WidgetsFlutterBinding.ensureInitialized(); - - /// APP INTEGRATION TEST WITH MOCK DATA - /// - /*group('app integration test with mocked data', () { - setUpAll(() async { - await di.init(); - }); - - /// SPLASH PAGE - testWidgets( - 'initial state, splash screen and after n seconds navigate to home', - (widgetTester) async { - when(identityRepository.getCurrentIdentifier()) - .thenAnswer((realInvocation) => Future.value(null)); - await widgetTester.pumpWidget(const App()); - await widgetTester.pumpAndSettle(); - expect(find.byType(SvgPicture), findsOneWidget); - - await widgetTester.pumpAndSettle(CustomDimensions.splashDuration); - expect(find.text(CustomStrings.homeDescription), findsOneWidget); - await widgetTester.pumpAndSettle(); - }, - ); - - /// HOME PAGE - testWidgets( - 'home screen test', - (WidgetTester widgetTester) async { - await widgetTester.pumpWidget(const App()); - await widgetTester.pumpAndSettle(); - - AppState state = widgetTester.state(find.byType(App)); - - NavigatorState navigatorState = state.navigatorKey.currentState!; - navigatorState.pushReplacementNamed(Routes.homePath); - - // 1. getCurrentIdentifier() with identity not created yet case - await widgetTester.pump(); - when(identityRepository.getCurrentIdentifier()) - .thenAnswer((realInvocation) => Future.value(null)); - await widgetTester.pumpAndSettle(); - - expect(find.text(CustomStrings.homeDescription), findsOneWidget); - expect(find.text(CustomStrings.homeIdentifierSectionPlaceHolder), - findsOneWidget); - expect(find.byKey(const ValueKey('identifier')), findsOneWidget); - - // 2. exception while calling createIdentity() - await widgetTester.pump(); - when(identityRepository.createIdentity()).thenAnswer( - (realInvocation) => Future.error(IdentityException('error'))); - await widgetTester.pumpAndSettle(); - - await widgetTester.tap(find.byType(ElevatedButton)); - await widgetTester.pumpAndSettle(const Duration(seconds: 1)); - - expect(find.text('error'), findsOneWidget); - - // 3. createIdentity() positive case - await widgetTester.pump(); - when(identityRepository.createIdentity()) - .thenAnswer((realInvocation) => Future.value(identifier)); - await widgetTester.tap(find.byType(ElevatedButton)); - await widgetTester.pumpAndSettle(const Duration(seconds: 1)); - - expect(find.text(CustomStrings.homeIdentifierSectionPlaceHolder), - findsNothing); - - await widgetTester.pumpAndSettle(); - - // 4. getCurrentIdentifier() positive case - await widgetTester.pump(); - when(identityRepository.getCurrentIdentifier()) - .thenAnswer((realInvocation) => Future.value(identifier)); - await widgetTester.pump(); - navigatorState.pushReplacementNamed(Routes.homePath); - - await widgetTester.pumpAndSettle(const Duration(seconds: 1)); - - expect(find.text(CustomStrings.homeIdentifierSectionPlaceHolder), - findsNothing); - - await widgetTester.pumpAndSettle(); - }, - ); - - /// AUTHENTICATION PAGE - testWidgets( - 'authentication screen test', - (WidgetTester widgetTester) async { - final key = GlobalKey(); - await widgetTester.pumpWidget( - MaterialApp( - navigatorKey: key, - initialRoute: Routes.authPath, - routes: { - Routes.authPath: (BuildContext context) => AuthScreen(), - Routes.qrCodeScannerPath: (BuildContext context) => Container(), - }, - ), - ); - - await widgetTester.pump(); - await widgetTester.pumpAndSettle(); - expect(find.text(CustomStrings.authDescription), findsOneWidget); - - await widgetTester.pump(); - - await widgetTester.pumpAndSettle(); - - // Tap to scan code and then return null from scanning page - await widgetTester.tap(find.byType(ElevatedButton)); - await widgetTester.pumpAndSettle(); - - key.currentState?.pop(null); - await widgetTester.pumpAndSettle(); - - expect(find.text('no qr code scanned'), findsOneWidget); - - //Tap to scan and then return an invalid qrCode - await widgetTester.tap(find.byType(ElevatedButton)); - await widgetTester.pumpAndSettle(); - - key.currentState?.pop(invalidQrCodeScanResponse); - await widgetTester.pumpAndSettle(); - - expect(find.text('Scanned code is not valid'), findsOneWidget); - - //Tap to scan and then return a valid qrCode but identity not yet created - await widgetTester.tap(find.byType(ElevatedButton)); - await widgetTester.pumpAndSettle(); - - when(identityRepository.getCurrentIdentifier()) - .thenAnswer((realInvocation) => Future.value(null)); - - key.currentState?.pop(validQrCodeScanResponse); - await widgetTester.pumpAndSettle(); - - expect(find.text('an identity is needed before trying to authenticate'), - findsOneWidget); - - //Tap to scan and then return a valid qrCode - await widgetTester.tap(find.byType(ElevatedButton)); - await widgetTester.pumpAndSettle(); - - when(identityRepository.getCurrentIdentifier()) - .thenAnswer((realInvocation) => Future.value(identifier)); - - when(iden3commRepository.authenticate( - issuerMessage: anyNamed('issuerMessage'), - identifier: anyNamed('identifier'))) - .thenAnswer((realInvocation) => Future.value()); - - key.currentState?.pop(validQrCodeScanResponse); - await widgetTester.pumpAndSettle(); - - expect(find.text('Authenticated successfully'), findsOneWidget); - - await widgetTester.pumpAndSettle(); - }, - ); - });*/ -} diff --git a/example/integration_test/bjj_test.dart b/example/integration_test/bjj_test.dart new file mode 100644 index 000000000..5071e1fc9 --- /dev/null +++ b/example/integration_test/bjj_test.dart @@ -0,0 +1,95 @@ +import 'dart:ffi'; +import 'dart:io'; + +import 'package:ffi/ffi.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:polygonid_flutter_sdk/common/utils/hex_utils.dart'; +import 'package:polygonid_flutter_sdk/identity/libs/bjj/bjj.dart'; + +void main() { + final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + final lib = BabyjubjubLib(); + + group('Test point compress/uncompress', () { + const pointX = + "1213174356443492223913701748605807399689671830803048423391713277352597320264"; + const pointY = + "7302787176091879756002280810960328852823951595761559038108460949327195887723"; + + const compressedPoint = + "6B58E72B1BB6DD8C2B20CB62E90F1AE7F7F054C059B962382643721B273B2510"; + + testWidgets('Compress point', (WidgetTester tester) async { + final compressedPoint = lib.packPoint(pointX, pointY); + + expect( + compressedPoint, + equals(compressedPoint), + ); + }); + + testWidgets('Uncompress point', (WidgetTester tester) async { + final uncompressedPoint = lib.unpackPoint(compressedPoint); + + expect(uncompressedPoint, isNotNull); + expect(uncompressedPoint![0], equals(pointX)); + expect(uncompressedPoint[1], equals(pointY)); + }); + }); + + group("Message sign and signature verify", () { + const privateKey = + "85612f904a52e7eb2e0ab742ab1ae3de36561497fea24f1fc4619a5efc73eae8"; + const message = + "6841496992415663132898117430955063618911128754688221768758387076131201387307"; + + const signature = + "740942df0bffc2f386d9d7e4e30be0981d54a2c16af82e85af1978459b489eafe0ab5d8e12f724f93998827f02a1624705d0ea22f92fd769901a1df7bfc87401"; + + testWidgets("Sign", (WidgetTester tester) async { + final signature = lib.signPoseidon( + privateKey, + message, + ); + + expect(signature, equals(signature)); + }); + + testWidgets("Verify signature", (WidgetTester tester) async { + final valid = lib.verifyPoseidon( + privateKey, + signature, + message, + ); + + expect(valid, isTrue); + }); + }); + + group("Private key to public key test", () { + const privateKey = + "85612f904a52e7eb2e0ab742ab1ae3de36561497fea24f1fc4619a5efc73eae8"; + + const expectedX = + "10642469561299443157177646279099633166785806044568900244804593097533061888748"; + const expectedY = + "7588418921868074418607355872196117318956729766890665605182116638798290735907"; + + testWidgets("Private key to public", (WidgetTester tester) async { + final publicKeyRaw = lib.prv2pub(privateKey); + + final stringList = publicKeyRaw.split(","); + stringList[0] = stringList[0].replaceAll("Fr(", ""); + stringList[0] = stringList[0].replaceAll(")", ""); + stringList[1] = stringList[1].replaceAll("Fr(", ""); + stringList[1] = stringList[1].replaceAll(")", ""); + BigInt x = HexUtils.hexToInt(stringList[0]); + BigInt y = HexUtils.hexToInt(stringList[1]); + + expect(x.toString(), equals(expectedX)); + expect(y.toString(), equals(expectedY)); + }); + }); +} diff --git a/example/integration_test/libpolygonid_test.dart b/example/integration_test/libpolygonid_test.dart index 2f82c929c..387134730 100644 --- a/example/integration_test/libpolygonid_test.dart +++ b/example/integration_test/libpolygonid_test.dart @@ -1,4 +1,3 @@ -/* import 'dart:convert'; import 'dart:ffi'; import 'dart:io'; @@ -6,6 +5,7 @@ import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; +import 'package:polygonid_flutter_sdk/common/infrastructure/stacktrace_stream_manager.dart'; import 'package:polygonid_flutter_sdk/credential/libs/polygonidcore/pidcore_credential.dart'; import 'package:polygonid_flutter_sdk/iden3comm/libs/polygonidcore/pidcore_iden3comm.dart'; import 'package:polygonid_flutter_sdk/identity/libs/polygonidcore/pidcore_identity.dart'; @@ -16,124 +16,148 @@ import 'polygonidcore_mocks.dart'; void main() { final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + final stacktraceManager = StacktraceManager(); + group('Test polygonId core lib identity functions', () { - final pidCoreIdentity = PolygonIdCoreIdentity(); + final pidCoreIdentity = PolygonIdCoreIdentity(stacktraceManager); testWidgets('PolygonIdCoreIdentity calculate genesis Id', (WidgetTester tester) async { expect( - pidCoreIdentity.calculateGenesisId( - PolygonIdCoreMocks.calculateGenesisIdInputJson, - PolygonIdCoreMocks.environmentConfigJson, - ), - equals(PolygonIdCoreMocks.calculateGenesisIdOutputJson)); + pidCoreIdentity.calculateGenesisId( + PolygonIdCoreMocks.calculateGenesisIdInputJson, + PolygonIdCoreMocks.environmentConfigJson, + ), + equals(PolygonIdCoreMocks.calculateGenesisIdOutputJson), + ); }); testWidgets('PolygonIdCoreIdentity calculate profile Id', (WidgetTester tester) async { expect( - pidCoreIdentity.calculateProfileId( - PolygonIdCoreMocks.calculateProfileIdInputJson), - equals(PolygonIdCoreMocks.calculateProfileIdOutputJson)); + pidCoreIdentity.calculateProfileId( + PolygonIdCoreMocks.calculateProfileIdInputJson, + ), + equals(PolygonIdCoreMocks.calculateProfileIdOutputJson), + ); }); testWidgets('PolygonIdCoreIdentity convert id to big int', (WidgetTester tester) async { expect( - pidCoreIdentity - .convertIdToBigInt(jsonEncode(PolygonIdCoreMocks.idToIntInput)), - equals(jsonEncode(PolygonIdCoreMocks.idToIntOutput))); + pidCoreIdentity.convertIdToBigInt( + jsonEncode(PolygonIdCoreMocks.idToIntInput), + ), + equals(jsonEncode(PolygonIdCoreMocks.idToIntOutput)), + ); }); }); group('Test polygonId core lib credential functions', () { - final pidCoreCredential = PolygonIdCoreCredential(); + final pidCoreCredential = PolygonIdCoreCredential(stacktraceManager); testWidgets('PolygonIdCoreIdentity create claim', (WidgetTester tester) async { expect( - pidCoreCredential - .createClaim(PolygonIdCoreMocks.createClaimInputJson), - equals(PolygonIdCoreMocks.createClaimOutput)); + pidCoreCredential.createClaim(PolygonIdCoreMocks.createClaimInputJson), + equals(PolygonIdCoreMocks.createClaimOutput), + ); }); testWidgets('PolygonIdCoreIdentity create claim all fields 1', (WidgetTester tester) async { expect( - pidCoreCredential - .createClaim(PolygonIdCoreMocks.createClaimAllFields1InputJson), - equals(PolygonIdCoreMocks.createClaimAllFields1Output)); + pidCoreCredential.createClaim( + PolygonIdCoreMocks.createClaimAllFields1InputJson, + ), + equals(PolygonIdCoreMocks.createClaimAllFields1Output), + ); }); testWidgets('PolygonIdCoreIdentity create claim all fields 2', (WidgetTester tester) async { expect( - pidCoreCredential - .createClaim(PolygonIdCoreMocks.createClaimAllFields2InputJson), - equals(PolygonIdCoreMocks.createClaimAllFields2Output)); + pidCoreCredential.createClaim( + PolygonIdCoreMocks.createClaimAllFields2InputJson, + ), + equals(PolygonIdCoreMocks.createClaimAllFields2Output), + ); }); }); group('Test polygonId core lib iden3comm functions', () { - final pidCoreIden3comm = PolygonIdCoreIden3comm(); + final pidCoreIden3comm = PolygonIdCoreIden3comm(stacktraceManager); testWidgets('PolygonIdCoreIdentity get Auth Inputs', (WidgetTester tester) async { - expect(pidCoreIden3comm.getAuthInputs(PolygonIdCoreMocks.authV2InputJson), - equals(PolygonIdCoreMocks.authV2OutputJson)); + expect( + pidCoreIden3comm.getAuthInputs(PolygonIdCoreMocks.authV2InputJson), + equals(PolygonIdCoreMocks.authV2OutputJson), + ); }); }); group('Test polygonId core lib proof functions', () { - final pidCoreProof = PolygonIdCoreProof(); + final pidCoreProof = PolygonIdCoreProof(stacktraceManager); testWidgets('PolygonIdCoreIdentity get sig proofs inputs', (WidgetTester tester) async { var result = pidCoreProof.getSigProofInputs( - PolygonIdCoreMocks.sigV2InputJson, - PolygonIdCoreMocks.sigV2InputConfigJson); + PolygonIdCoreMocks.sigV2InputJson, + PolygonIdCoreMocks.sigV2InputConfigJson, + ); var resultJson = jsonDecode(result) as Map; resultJson['inputs'].remove('timestamp'); expect( - jsonEncode(resultJson), equals(PolygonIdCoreMocks.sigV2OutputJson)); + jsonEncode(resultJson), + equals(PolygonIdCoreMocks.sigV2OutputJson), + ); }); testWidgets('PolygonIdCoreIdentity proof from smart contract', (WidgetTester tester) async { expect( - pidCoreProof.proofFromSmartContract( - PolygonIdCoreMocks.proofFromSmartContractInputJson), - equals(PolygonIdCoreMocks.proofFromSmartContractOutputJson)); + pidCoreProof.proofFromSmartContract( + PolygonIdCoreMocks.proofFromSmartContractInputJson, + ), + equals(PolygonIdCoreMocks.proofFromSmartContractOutputJson), + ); }); // TODO: fix localhost url from input - */ -/*testWidgets('PolygonIdCoreIdentity get sig on chain proofs inputs', - (WidgetTester tester) async { - expect( - pidCoreProof.getSigOnchainProofInputs( - PolygonIdCoreMocks.sigV2OnChainInputJson), - equals(PolygonIdCoreMocks.sigV2OnChainOutputJson)); - }); + testWidgets('PolygonIdCoreIdentity get sig on chain proofs inputs', + (WidgetTester tester) async { + expect( + pidCoreProof.getSigOnchainProofInputs( + PolygonIdCoreMocks.sigV2OnChainInputJson, + PolygonIdCoreMocks.sigV2InputConfigJson, + ), + equals(PolygonIdCoreMocks.sigV2OnChainOutputJson), + ); + }); // TODO: fix localhost url from input testWidgets('PolygonIdCoreIdentity get mtp proofs inputs', - (WidgetTester tester) async { - expect( - pidCoreProof.getMTProofInputs( - PolygonIdCoreMocks.mtpV2InputJson), - equals(PolygonIdCoreMocks.mtpV2OutputJson)); - }); + (WidgetTester tester) async { + expect( + pidCoreProof.getMTProofInputs( + PolygonIdCoreMocks.mtpV2InputJson, + PolygonIdCoreMocks.sigV2InputConfigJson, + ), + equals(PolygonIdCoreMocks.mtpV2OutputJson), + ); + }); // TODO: fix localhost url from input testWidgets('PolygonIdCoreIdentity get sig proofs inputs', - (WidgetTester tester) async { - expect( - pidCoreProof.getMTPOnchainProofInputs( - PolygonIdCoreMocks.mtpV2OnChainInputJson), - equals(PolygonIdCoreMocks.mtpV2OnChainOutputJson)); - });*/ /* - + (WidgetTester tester) async { + expect( + pidCoreProof.getMTPOnchainProofInputs( + PolygonIdCoreMocks.mtpV2OnChainInputJson, + PolygonIdCoreMocks.sigV2InputConfigJson, + ), + equals(PolygonIdCoreMocks.mtpV2OnChainOutputJson), + ); + }); }); } -*/ diff --git a/example/ios/Podfile b/example/ios/Podfile index 901cc492d..b3d587c84 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -55,7 +55,7 @@ post_install do |installer| target.build_configurations.each do |config| xcconfig_path = config.base_configuration_reference.real_path xcconfig = File.read(xcconfig_path) - new_xcconfig = xcconfig.sub('OTHER_LDFLAGS = $(inherited)', 'OTHER_LDFLAGS = $(inherited) -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_authV2.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryMTPV2.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryV3.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_linkedMultiQuery10.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryV3OnChain.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryMTPV2OnChain.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2OnChain.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libfr.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libpolygonid.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libbabyjubjub.a" -lc++ -lz') + new_xcconfig = xcconfig.sub('OTHER_LDFLAGS = $(inherited)', 'OTHER_LDFLAGS = $(inherited) -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libpolygonid.a" -lc++ -lz') File.open(xcconfig_path, "w") { |file| file << new_xcconfig } end end diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index b4a75c8ed..4e9790866 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -9,13 +9,13 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 7081E0E56861953872D362ED /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D9D06ACA15E25CB07E9F6C7 /* Pods_Runner.framework */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; + A990ED02FB39BC73CD414172 /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51C7ABAA13EC8BDBFCB96030 /* Pods_RunnerTests.framework */; }; D1C9DADC29D2DD3B007FDAAF /* RunnerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D1C9DADB29D2DD3B007FDAAF /* RunnerTests.m */; }; - E91B8C57F183DF9749C5D6C5 /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9B10C6268FDF9EDFEA15C0D /* Pods_RunnerTests.framework */; }; + DB06CC0D53A578B6E6411D65 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 724AD9D2BAA7ACFCB3390BF3 /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -42,17 +42,19 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 1112DD8E53090754672A5D9A /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 2720ABE411B5ED627D8F4EDA /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 6D1385A93B092715E86E40B0 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; + 51C7ABAA13EC8BDBFCB96030 /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 5B1BE4D82140DD00FEE13DE9 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; + 724AD9D2BAA7ACFCB3390BF3 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 79E380C282D8B7D9B57FD0AD /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; - 7BD1AEEB1E50785A2BC05B7B /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; - 7D9D06ACA15E25CB07E9F6C7 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 8B48286B71FAD3B7F636A1AF /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = ""; }; - 955365E1D920085E23A5AE40 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; + 8E04155224C02DE0B351C95B /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -60,11 +62,9 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - C9B10C6268FDF9EDFEA15C0D /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + AB42E9ABC0FFC5047F3D9893 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; D1C9DAD929D2DD3B007FDAAF /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; D1C9DADB29D2DD3B007FDAAF /* RunnerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RunnerTests.m; sourceTree = ""; }; - D359AD60039D56ADB104B22D /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; - EC748B05F6687897A71F255A /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -72,7 +72,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7081E0E56861953872D362ED /* Pods_Runner.framework in Frameworks */, + DB06CC0D53A578B6E6411D65 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -80,7 +80,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - E91B8C57F183DF9749C5D6C5 /* Pods_RunnerTests.framework in Frameworks */, + A990ED02FB39BC73CD414172 /* Pods_RunnerTests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -90,12 +90,12 @@ 27AD81D474401F3D028852AD /* Pods */ = { isa = PBXGroup; children = ( - EC748B05F6687897A71F255A /* Pods-Runner.debug.xcconfig */, - D359AD60039D56ADB104B22D /* Pods-Runner.release.xcconfig */, - 955365E1D920085E23A5AE40 /* Pods-Runner.profile.xcconfig */, - 6D1385A93B092715E86E40B0 /* Pods-RunnerTests.debug.xcconfig */, - 7BD1AEEB1E50785A2BC05B7B /* Pods-RunnerTests.release.xcconfig */, - 8B48286B71FAD3B7F636A1AF /* Pods-RunnerTests.profile.xcconfig */, + 79E380C282D8B7D9B57FD0AD /* Pods-Runner.debug.xcconfig */, + 2720ABE411B5ED627D8F4EDA /* Pods-Runner.release.xcconfig */, + AB42E9ABC0FFC5047F3D9893 /* Pods-Runner.profile.xcconfig */, + 1112DD8E53090754672A5D9A /* Pods-RunnerTests.debug.xcconfig */, + 5B1BE4D82140DD00FEE13DE9 /* Pods-RunnerTests.release.xcconfig */, + 8E04155224C02DE0B351C95B /* Pods-RunnerTests.profile.xcconfig */, ); path = Pods; sourceTree = ""; @@ -119,7 +119,7 @@ D1C9DADA29D2DD3B007FDAAF /* RunnerTests */, 97C146EF1CF9000F007C117D /* Products */, 27AD81D474401F3D028852AD /* Pods */, - CBFEA47AE88C535808DAAF1C /* Frameworks */, + 9957A415186FE5C95C9ADE23 /* Frameworks */, ); sourceTree = ""; }; @@ -147,11 +147,11 @@ path = Runner; sourceTree = ""; }; - CBFEA47AE88C535808DAAF1C /* Frameworks */ = { + 9957A415186FE5C95C9ADE23 /* Frameworks */ = { isa = PBXGroup; children = ( - 7D9D06ACA15E25CB07E9F6C7 /* Pods_Runner.framework */, - C9B10C6268FDF9EDFEA15C0D /* Pods_RunnerTests.framework */, + 724AD9D2BAA7ACFCB3390BF3 /* Pods_Runner.framework */, + 51C7ABAA13EC8BDBFCB96030 /* Pods_RunnerTests.framework */, ); name = Frameworks; sourceTree = ""; @@ -171,14 +171,14 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - 76BC526FF4F8C650B37E3767 /* [CP] Check Pods Manifest.lock */, + 7320A577E377C47ED6D585DB /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, - 04E6FF680108798E6C7D366B /* [CP] Embed Pods Frameworks */, + F387C277377F21F124A22900 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -193,7 +193,7 @@ isa = PBXNativeTarget; buildConfigurationList = D1C9DAE229D2DD3B007FDAAF /* Build configuration list for PBXNativeTarget "RunnerTests" */; buildPhases = ( - 7480EF689A27390976576D58 /* [CP] Check Pods Manifest.lock */, + 44435A536AE36AB9C6416196 /* [CP] Check Pods Manifest.lock */, D1C9DAD529D2DD3B007FDAAF /* Sources */, D1C9DAD629D2DD3B007FDAAF /* Frameworks */, D1C9DAD729D2DD3B007FDAAF /* Resources */, @@ -268,23 +268,6 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 04E6FF680108798E6C7D366B /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", - ); - name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; @@ -301,7 +284,7 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; - 7480EF689A27390976576D58 /* [CP] Check Pods Manifest.lock */ = { + 44435A536AE36AB9C6416196 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -323,7 +306,7 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 76BC526FF4F8C650B37E3767 /* [CP] Check Pods Manifest.lock */ = { + 7320A577E377C47ED6D585DB /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -360,6 +343,23 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n"; }; + F387C277377F21F124A22900 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -468,15 +468,114 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEAD_CODE_STRIPPING = YES; + DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = 6K7H9274Q6; ENABLE_BITCODE = NO; + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "i386 arm64"; INFOPLIST_FILE = Runner/Info.plist; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; IPHONEOS_DEPLOYMENT_TARGET = 14.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); + OTHER_LDFLAGS = ( + "$(inherited)", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_authV2.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryMTPV2.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryV3.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_linkedMultiQuery10.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryV3OnChain.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryMTPV2OnChain.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2OnChain.a\"", + "-lc++", + "-lz", + "-ObjC", + "-l\"c++\"", + "-l\"polygonid\"", + "-l\"swiftCoreGraphics\"", + "-l\"sqlite3\"", + "-l\"z\"", + "-framework", + "\"AVFoundation\"", + "-framework", + "\"Accelerate\"", + "-framework", + "\"CoreGraphics\"", + "-framework", + "\"CoreImage\"", + "-framework", + "\"CoreMedia\"", + "-framework", + "\"CoreTelephony\"", + "-framework", + "\"CoreVideo\"", + "-framework", + "\"CryptoSwift\"", + "-framework", + "\"FBLPromises\"", + "-framework", + "\"Foundation\"", + "-framework", + "\"GTMSessionFetcher\"", + "-framework", + "\"GoogleDataTransport\"", + "-framework", + "\"GoogleToolboxForMac\"", + "-framework", + "\"GoogleUtilities\"", + "-framework", + "\"GoogleUtilitiesComponents\"", + "-framework", + "\"LocalAuthentication\"", + "-framework", + "\"MLImage\"", + "-framework", + "\"MLKitBarcodeScanning\"", + "-framework", + "\"MLKitCommon\"", + "-framework", + "\"MLKitVision\"", + "-framework", + "\"Security\"", + "-framework", + "\"SystemConfiguration\"", + "-framework", + "\"UIKit\"", + "-framework", + "\"background_downloader\"", + "-framework", + "\"camera_avfoundation\"", + "-framework", + "\"flutter_secure_storage\"", + "-framework", + "\"google_mlkit_barcode_scanning\"", + "-framework", + "\"google_mlkit_commons\"", + "-framework", + "\"image_picker_ios\"", + "-framework", + "\"integration_test\"", + "-framework", + "\"nanopb\"", + "-framework", + "\"package_info_plus\"", + "-framework", + "\"path_provider_foundation\"", + "-framework", + "\"polygonid_flutter_sdk\"", + "-framework", + "\"scan\"", + ); PRODUCT_BUNDLE_IDENTIFIER = "com.polygonid.polygonid-flutter-sdk.example"; PRODUCT_NAME = "$(TARGET_NAME)"; STRIP_STYLE = "non-global"; @@ -602,15 +701,114 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEAD_CODE_STRIPPING = YES; + DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = 6K7H9274Q6; ENABLE_BITCODE = NO; + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 i386"; INFOPLIST_FILE = Runner/Info.plist; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; IPHONEOS_DEPLOYMENT_TARGET = 14.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); + OTHER_LDFLAGS = ( + "$(inherited)", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_authV2.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryMTPV2.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryV3.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_linkedMultiQuery10.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryV3OnChain.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryMTPV2OnChain.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2OnChain.a\"", + "-lc++", + "-lz", + "-ObjC", + "-l\"c++\"", + "-l\"polygonid\"", + "-l\"swiftCoreGraphics\"", + "-l\"sqlite3\"", + "-l\"z\"", + "-framework", + "\"AVFoundation\"", + "-framework", + "\"Accelerate\"", + "-framework", + "\"CoreGraphics\"", + "-framework", + "\"CoreImage\"", + "-framework", + "\"CoreMedia\"", + "-framework", + "\"CoreTelephony\"", + "-framework", + "\"CoreVideo\"", + "-framework", + "\"CryptoSwift\"", + "-framework", + "\"FBLPromises\"", + "-framework", + "\"Foundation\"", + "-framework", + "\"GTMSessionFetcher\"", + "-framework", + "\"GoogleDataTransport\"", + "-framework", + "\"GoogleToolboxForMac\"", + "-framework", + "\"GoogleUtilities\"", + "-framework", + "\"GoogleUtilitiesComponents\"", + "-framework", + "\"LocalAuthentication\"", + "-framework", + "\"MLImage\"", + "-framework", + "\"MLKitBarcodeScanning\"", + "-framework", + "\"MLKitCommon\"", + "-framework", + "\"MLKitVision\"", + "-framework", + "\"Security\"", + "-framework", + "\"SystemConfiguration\"", + "-framework", + "\"UIKit\"", + "-framework", + "\"background_downloader\"", + "-framework", + "\"camera_avfoundation\"", + "-framework", + "\"flutter_secure_storage\"", + "-framework", + "\"google_mlkit_barcode_scanning\"", + "-framework", + "\"google_mlkit_commons\"", + "-framework", + "\"image_picker_ios\"", + "-framework", + "\"integration_test\"", + "-framework", + "\"nanopb\"", + "-framework", + "\"package_info_plus\"", + "-framework", + "\"path_provider_foundation\"", + "-framework", + "\"polygonid_flutter_sdk\"", + "-framework", + "\"scan\"", + ); PRODUCT_BUNDLE_IDENTIFIER = "com.polygonid.polygonid-flutter-sdk.example"; PRODUCT_NAME = "$(TARGET_NAME)"; STRIP_STYLE = "non-global"; @@ -628,15 +826,114 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEAD_CODE_STRIPPING = YES; + DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = 6K7H9274Q6; ENABLE_BITCODE = NO; + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "i386 arm64"; INFOPLIST_FILE = Runner/Info.plist; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; IPHONEOS_DEPLOYMENT_TARGET = 14.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); + OTHER_LDFLAGS = ( + "$(inherited)", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_authV2.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryMTPV2.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryV3.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_linkedMultiQuery10.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryV3OnChain.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQueryMTPV2OnChain.a\"", + "-force_load", + "\"${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2OnChain.a\"", + "-lc++", + "-lz", + "-ObjC", + "-l\"c++\"", + "-l\"polygonid\"", + "-l\"swiftCoreGraphics\"", + "-l\"sqlite3\"", + "-l\"z\"", + "-framework", + "\"AVFoundation\"", + "-framework", + "\"Accelerate\"", + "-framework", + "\"CoreGraphics\"", + "-framework", + "\"CoreImage\"", + "-framework", + "\"CoreMedia\"", + "-framework", + "\"CoreTelephony\"", + "-framework", + "\"CoreVideo\"", + "-framework", + "\"CryptoSwift\"", + "-framework", + "\"FBLPromises\"", + "-framework", + "\"Foundation\"", + "-framework", + "\"GTMSessionFetcher\"", + "-framework", + "\"GoogleDataTransport\"", + "-framework", + "\"GoogleToolboxForMac\"", + "-framework", + "\"GoogleUtilities\"", + "-framework", + "\"GoogleUtilitiesComponents\"", + "-framework", + "\"LocalAuthentication\"", + "-framework", + "\"MLImage\"", + "-framework", + "\"MLKitBarcodeScanning\"", + "-framework", + "\"MLKitCommon\"", + "-framework", + "\"MLKitVision\"", + "-framework", + "\"Security\"", + "-framework", + "\"SystemConfiguration\"", + "-framework", + "\"UIKit\"", + "-framework", + "\"background_downloader\"", + "-framework", + "\"camera_avfoundation\"", + "-framework", + "\"flutter_secure_storage\"", + "-framework", + "\"google_mlkit_barcode_scanning\"", + "-framework", + "\"google_mlkit_commons\"", + "-framework", + "\"image_picker_ios\"", + "-framework", + "\"integration_test\"", + "-framework", + "\"nanopb\"", + "-framework", + "\"package_info_plus\"", + "-framework", + "\"path_provider_foundation\"", + "-framework", + "\"polygonid_flutter_sdk\"", + "-framework", + "\"scan\"", + ); PRODUCT_BUNDLE_IDENTIFIER = "com.polygonid.polygonid-flutter-sdk.example"; PRODUCT_NAME = "$(TARGET_NAME)"; STRIP_STYLE = "non-global"; @@ -648,7 +945,7 @@ }; D1C9DADF29D2DD3B007FDAAF /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 6D1385A93B092715E86E40B0 /* Pods-RunnerTests.debug.xcconfig */; + baseConfigurationReference = 1112DD8E53090754672A5D9A /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; @@ -676,7 +973,7 @@ }; D1C9DAE029D2DD3B007FDAAF /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7BD1AEEB1E50785A2BC05B7B /* Pods-RunnerTests.release.xcconfig */; + baseConfigurationReference = 5B1BE4D82140DD00FEE13DE9 /* Pods-RunnerTests.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; @@ -703,7 +1000,7 @@ }; D1C9DAE129D2DD3B007FDAAF /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 8B48286B71FAD3B7F636A1AF /* Pods-RunnerTests.profile.xcconfig */; + baseConfigurationReference = 8E04155224C02DE0B351C95B /* Pods-RunnerTests.profile.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; diff --git a/example/ios/Runner/AppDelegate.swift b/example/ios/Runner/AppDelegate.swift index 70693e4a8..b63630348 100644 --- a/example/ios/Runner/AppDelegate.swift +++ b/example/ios/Runner/AppDelegate.swift @@ -1,7 +1,7 @@ import UIKit import Flutter -@UIApplicationMain +@main @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, diff --git a/example/ios/Runner/Base.lproj/Main.storyboard b/example/ios/Runner/Base.lproj/Main.storyboard index f3c28516f..f91153d09 100644 --- a/example/ios/Runner/Base.lproj/Main.storyboard +++ b/example/ios/Runner/Base.lproj/Main.storyboard @@ -1,8 +1,10 @@ - - + + + - + + @@ -14,13 +16,14 @@ - + - + + diff --git a/ios/Classes/SwiftPolygonIdSdkPlugin.swift b/ios/Classes/SwiftPolygonIdSdkPlugin.swift index 02c1ad18e..1e9c8f459 100644 --- a/ios/Classes/SwiftPolygonIdSdkPlugin.swift +++ b/ios/Classes/SwiftPolygonIdSdkPlugin.swift @@ -53,5 +53,14 @@ public class SwiftPolygonIdSdkPlugin: NSObject, FlutterPlugin { // witnesscalc mtpv2 onchain bindings witnesscalc_credentialAtomicQueryMTPV2OnChain(nil, 0, nil, 0, nil, nil, nil, 0); + + // witnesscalc v3 bindings + witnesscalc_credentialAtomicQueryV3(nil, 0, nil, 0, nil, nil, nil, 0); + + // witnesscalc v3 onchain bindings + witnesscalc_credentialAtomicQueryV3OnChain(nil, 0, nil, 0, nil, nil, nil, 0); + + // witnesscalc linked multi query 10 bindings + witnesscalc_linkedMultiQuery10(nil, 0, nil, 0, nil, nil, nil, 0); } } diff --git a/ios/polygonid_flutter_sdk.podspec b/ios/polygonid_flutter_sdk.podspec index c593be076..64480d610 100644 --- a/ios/polygonid_flutter_sdk.podspec +++ b/ios/polygonid_flutter_sdk.podspec @@ -24,7 +24,7 @@ PolygonID SDK flutter plugin project. # s.ios.deployment_target = '9.0' # s.ios.vendored_frameworks = 'Frameworks/Core.xcframework' # Flutter.framework does not contain a i386 nor arm64 slice. - s.pod_target_xcconfig = { "OTHER_LDFLAGS" => "-force_load $(PODS_TARGET_SRCROOT)/Frameworks/libbabyjubjub.a -force_load $(PODS_TARGET_SRCROOT)/Frameworks/libpolygonid.a -force_load $(PODS_TARGET_SRCROOT)/Frameworks/libwitnesscalc_authV2.a -force_load $(PODS_TARGET_SRCROOT)/Frameworks/libwitnesscalc_credentialAtomicQueryMTPV2.a -force_load $(PODS_TARGET_SRCROOT)/Frameworks/libwitnesscalc_credentialAtomicQuerySigV2.a -force_load $(PODS_TARGET_SRCROOT)/Frameworks/libwitnesscalc_credentialAtomicQuerySigV2OnChain.a -force_load $(PODS_TARGET_SRCROOT)/Frameworks/libwitnesscalc_credentialAtomicQueryMTPV2OnChain.a -force_load $(PODS_TARGET_SRCROOT)/Frameworks/libwitnesscalc_credentialAtomicQueryV3.a -force_load $(PODS_TARGET_SRCROOT)/Frameworks/libwitnesscalc_credentialAtomicQueryV3OnChain.a -force_load $(PODS_TARGET_SRCROOT)/Frameworks/libwitnesscalc_linkedMultiQuery10.a -lc++ -lz" } + s.pod_target_xcconfig = { "OTHER_LDFLAGS" => "-force_load $(PODS_TARGET_SRCROOT)/Frameworks/libpolygonid.a -lc++ -lz" } # s.vendored_libraries = "Frameworks/**/*.a" s.pod_target_xcconfig = { 'STRIP_STYLE' => 'non-global', diff --git a/lib/identity/libs/bjj/eddsa_babyjub.dart b/lib/identity/libs/bjj/eddsa_babyjub.dart index 850d46242..663761d33 100644 --- a/lib/identity/libs/bjj/eddsa_babyjub.dart +++ b/lib/identity/libs/bjj/eddsa_babyjub.dart @@ -140,8 +140,10 @@ class PrivateKey { String sign(BigInt messageHash) { BabyjubjubLib bjjLib = BabyjubjubLib(); - String signature = - bjjLib.signPoseidon(HexUtils.bytesToHex(sk), messageHash.toString()); + String signature = bjjLib.signPoseidon( + HexUtils.bytesToHex(sk), + messageHash.toString(), + ); return signature; } diff --git a/polygonid-flutter-wrapper/.gitignore b/polygonid-flutter-wrapper/.gitignore deleted file mode 100644 index 9141595fb..000000000 --- a/polygonid-flutter-wrapper/.gitignore +++ /dev/null @@ -1,50 +0,0 @@ -.DS_Store -.dart_tool/ - -.packages -.pub/ - -.idea/ -.vagrant/ -.sconsign.dblite -.svn/ - -migrate_working_dir/ - -*.swp -profile - -DerivedData/ - -.generated/ - -*.pbxuser -*.mode1v3 -*.mode2v3 -*.perspectivev3 - -!default.pbxuser -!default.mode1v3 -!default.mode2v3 -!default.perspectivev3 - -xcuserdata - -*.moved-aside - -*.pyc -*sync/ -Icon? -.tags* - -build/ -.android/ -.ios/ -.flutter-plugins -.flutter-plugins-dependencies - -# Symbolication related -app.*.symbols - -# Obfuscation related -app.*.map.json diff --git a/polygonid-flutter-wrapper/.metadata b/polygonid-flutter-wrapper/.metadata deleted file mode 100644 index 10baa68e9..000000000 --- a/polygonid-flutter-wrapper/.metadata +++ /dev/null @@ -1,10 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: c07f7888888435fd9df505aa2efc38d3cf65681b - channel: stable - -project_type: module diff --git a/polygonid-flutter-wrapper/README.md b/polygonid-flutter-wrapper/README.md deleted file mode 100644 index 8346eb9ad..000000000 --- a/polygonid-flutter-wrapper/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# polygonid_flutter_wrapper - -Flutter Module wrapper around PolygonID Flutter SDK diff --git a/polygonid-flutter-wrapper/analysis_options.yaml b/polygonid-flutter-wrapper/analysis_options.yaml deleted file mode 100644 index a5744c1cf..000000000 --- a/polygonid-flutter-wrapper/analysis_options.yaml +++ /dev/null @@ -1,4 +0,0 @@ -include: package:flutter_lints/flutter.yaml - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options diff --git a/polygonid-flutter-wrapper/lib/main.dart b/polygonid-flutter-wrapper/lib/main.dart deleted file mode 100644 index 30cd7fb83..000000000 --- a/polygonid-flutter-wrapper/lib/main.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter/cupertino.dart'; -import 'package:polygonid_flutter_sdk/common/domain/entities/env_entity.dart'; -import 'package:polygonid_flutter_sdk/sdk/polygon_id_sdk.dart'; - -void main() { - WidgetsFlutterBinding.ensureInitialized(); -} - -/// Initialize the Flutter SDK wrapper -/// This method is called from the native side -@pragma('vm:entry-point') -Future init(List? env) { - WidgetsFlutterBinding.ensureInitialized(); - - return PolygonIdSdk.init( - env: env != null && env.isNotEmpty - ? EnvEntity.fromJson(jsonDecode(env[0])) - : null); -} diff --git a/polygonid-flutter-wrapper/maven-publish.gradle b/polygonid-flutter-wrapper/maven-publish.gradle deleted file mode 100644 index 99b8d113f..000000000 --- a/polygonid-flutter-wrapper/maven-publish.gradle +++ /dev/null @@ -1,87 +0,0 @@ -// Maven -apply from: "$rootDir/../../android/sdk.properties" -apply plugin: 'maven-publish' - -task createLocalMavenZip(type: Zip) { - from("$rootDir/../build/host/outputs/repo") { - include "io/flutter/plugins/**/**/$sdkVersion/**" - exclude 'io/github/**' - into 'm2' - } - archiveName = 'm2.zip' -} - -publishing { - publications { - wrapperDebug(MavenPublication) { - groupId = 'io.github.0xpolygonid.polygonid_flutter_wrapper' - artifactId = 'debug' - version = sdkVersion - - pom { - name = 'PolygonID Flutter Wrapper' - description = 'The wrapper around PolygonID Flutter SDK. This wrapper is needed to be able to use FlutterEngine in Android.' - url = 'https://polygon.technology/polygon-id' - packaging = 'aar' - - licenses { - license { - name = 'Apache License 2.0' - url = 'http://www.apache.org/licenses/' - } - license { - name = 'MIT License' - url = 'https://mit-license.org/' - } - } - - developers { - developer { - name = 'Flavien Norindr' - email = 'id@polygon.technology' - organization = 'Polygon' - organizationUrl = 'https://polygon.technology' - } - developer { - name = 'Emanuel Muroni' - email = 'id@polygon.technology' - organization = 'Polygon' - organizationUrl = 'https://polygon.technology' - } - developer { - name = 'Raùl Jareño' - email = 'id@polygon.technology' - organization = 'Polygon' - organizationUrl = 'https://polygon.technology' - } - } - - scm { - connection = 'scm:git@github.com:0xPolygonID/polygonid-flutter-sdk.git' - developerConnection = 'scm:git@github.com:0xPolygonID/polygonid-flutter-sdk.git' - url = 'https://github.com/0xPolygonID/polygonid-flutter-sdk' - } - } - - artifact(createLocalMavenZip) - - afterEvaluate { - from components.debug - } - } - } -} - -afterEvaluate { - tasks.named('publishWrapperDebugPublicationToMavenLocal') { - dependsOn(tasks.named('publishDebugPublicationToMavenRepository')) - } -} - -//task listTasks { -// doLast { -// println tasks -// } -//} -// -//publish.finalizedBy publishWrapperDebugPublicationToMavenLocal diff --git a/polygonid-flutter-wrapper/pubspec.yaml b/polygonid-flutter-wrapper/pubspec.yaml deleted file mode 100644 index 8fb425e08..000000000 --- a/polygonid-flutter-wrapper/pubspec.yaml +++ /dev/null @@ -1,95 +0,0 @@ -name: polygonid_flutter_wrapper -description: Flutter Module wrapper around PolygonID Flutter SDK -publish_to: none - -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# In Android, build-name is used as versionName while build-number used as versionCode. -# Read more about Android versioning at https://developer.android.com/studio/publish/versioning -# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. -# Read more about iOS versioning at -# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -# -# This version is used _only_ for the Runner app, which is used if you just do -# a `flutter run` or a `flutter make-host-app-editable`. It has no impact -# on any other native host app that you embed your Flutter project into. -version: 1.0.1 - -environment: - sdk: '>=2.19.2 <4.0.0' - -dependencies: - flutter: - sdk: flutter - - polygonid_flutter_sdk: - path: ../ -# git: -# url: https://github.com/iden3/polygonid-flutter-sdk.git -# ref: feature/PID-339_android - - path_provider: 2.0.15 - package_info_plus: ^4.0.1 - -dev_dependencies: - flutter_test: - sdk: flutter - flutter_lints: ^2.0.0 - injectable_generator: ^2.4.0 - build_runner: ^2.3.3 - -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -flutter: - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. - uses-material-design: true - - # To add Flutter specific assets to your application, add an assets section, - # like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/assets-and-images/#from-packages - - # To add Flutter specific custom fonts to your application, add a fonts - # section here, in this "flutter" section. Each entry in this list should - # have a "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages - - - # This section identifies your Flutter project as a module meant for - # embedding in a native host app. These identifiers should _not_ ordinarily - # be changed after generation - they are used to ensure that the tooling can - # maintain consistency when adding or modifying assets and plugins. - # They also do not have any bearing on your native host application's - # identifiers, which may be completely independent or the same as these. - module: - androidX: true - androidPackage: technology.polygon.polygonid_flutter_wrapper - iosBundleIdentifier: technology.polygon.polygonidFlutterWrapper diff --git a/rust/Cargo.lock b/rust/Cargo.lock deleted file mode 100644 index 3d94bd425..000000000 --- a/rust/Cargo.lock +++ /dev/null @@ -1,977 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - -[[package]] -name = "autocfg" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" - -[[package]] -name = "babyjubjub-rs" -version = "0.0.7" -dependencies = [ - "arrayref", - "blake", - "criterion", - "ff_ce", - "generic-array", - "lazy_static", - "num", - "num-bigint", - "num-traits", - "poseidon-rs", - "rand 0.4.6", - "rand 0.6.5", - "rustc-hex", - "tiny-keccak", -] - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "blake" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f76cff23583935d01f1d259e546bf988450648a644da066de24717fdd015aa81" -dependencies = [ - "gcc", - "libc", -] - -[[package]] -name = "bstr" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" -dependencies = [ - "lazy_static", - "memchr", - "regex-automata", - "serde", -] - -[[package]] -name = "bumpalo" -version = "3.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099e596ef14349721d9016f6b80dd3419ea1bf289ab9b44df8e4dfd3a005d5d9" - -[[package]] -name = "byteorder" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" - -[[package]] -name = "cast" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" -dependencies = [ - "rustc_version", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clap" -version = "2.33.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" -dependencies = [ - "bitflags", - "textwrap", - "unicode-width", -] - -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - -[[package]] -name = "const_fn" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" - -[[package]] -name = "criterion" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab327ed7354547cc2ef43cbe20ef68b988e70b4b593cbd66a2a61733123a3d23" -dependencies = [ - "atty", - "cast", - "clap", - "criterion-plot", - "csv", - "itertools 0.10.0", - "lazy_static", - "num-traits", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_cbor", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e022feadec601fba1649cfa83586381a4ad31c6bf3a9ab7d408118b05dd9889d" -dependencies = [ - "cast", - "itertools 0.9.0", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d" -dependencies = [ - "cfg-if", - "const_fn", - "crossbeam-utils", - "lazy_static", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" -dependencies = [ - "autocfg 1.0.1", - "cfg-if", - "lazy_static", -] - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "csv" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d58633299b24b515ac72a3f869f8b91306a3cec616a602843a383acd6f9e97" -dependencies = [ - "bstr", - "csv-core", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" -dependencies = [ - "memchr", -] - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "ff_ce" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3a682c12d0cc98a32ab7540401a5ea1ed21d11571eea11d5829cd721f85ff0" -dependencies = [ - "byteorder", - "ff_derive_ce", - "hex", - "rand 0.4.6", -] - -[[package]] -name = "ff_derive_ce" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c052fa6d4c2f12305ec364bfb8ef884836f3f61ea015b202372ff996d1ac4b" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "gcc" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" - -[[package]] -name = "generic-array" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd" -dependencies = [ - "typenum", -] - -[[package]] -name = "half" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" - -[[package]] -name = "hermit-abi" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" -dependencies = [ - "libc", -] - -[[package]] -name = "hex" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" - -[[package]] -name = "itertools" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" -dependencies = [ - "either", -] - -[[package]] -name = "itertools" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" - -[[package]] -name = "js-sys" -version = "0.3.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" - -[[package]] -name = "log" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "memchr" -version = "2.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" - -[[package]] -name = "memoffset" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87" -dependencies = [ - "autocfg 1.0.1", -] - -[[package]] -name = "num" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36" -dependencies = [ - "num-bigint", - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" -dependencies = [ - "autocfg 1.0.1", - "num-integer", - "num-traits", - "rand 0.5.6", -] - -[[package]] -name = "num-complex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" -dependencies = [ - "autocfg 1.0.1", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" -dependencies = [ - "autocfg 1.0.1", - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" -dependencies = [ - "autocfg 1.0.1", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" -dependencies = [ - "autocfg 1.0.1", - "num-bigint", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" -dependencies = [ - "autocfg 1.0.1", -] - -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - -[[package]] -name = "plotters" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ca0ae5f169d0917a7c7f5a9c1a3d3d9598f18f529dd2b8373ed988efea307a" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07fffcddc1cb3a1de753caa4e4df03b79922ba43cf882acc1bdd7e8df9f4590" - -[[package]] -name = "plotters-svg" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b38a02e23bd9604b842a812063aec4ef702b57989c37b655254bb61c471ad211" -dependencies = [ - "plotters-backend", -] - -[[package]] -name = "poseidon-rs" -version = "0.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c76e4996e3d9572d8b5cd56f495dda3fb748fd4cd6bdca754270b8b66a9a2dd3" -dependencies = [ - "ff_ce", - "rand 0.4.6", - "serde_json", -] - -[[package]] -name = "proc-macro2" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - -[[package]] -name = "rand" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "winapi", -] - -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.7", - "libc", - "rand_chacha", - "rand_core 0.4.2", - "rand_hc", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi", -] - -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.3.1", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rayon" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" -dependencies = [ - "autocfg 1.0.1", - "crossbeam-deque", - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" -dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "lazy_static", - "num_cpus", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "regex" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" -dependencies = [ - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" -dependencies = [ - "byteorder", -] - -[[package]] -name = "regex-syntax" -version = "0.6.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" - -[[package]] -name = "rustc-hex" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e" - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - -[[package]] -name = "ryu" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - -[[package]] -name = "serde" -version = "1.0.123" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" - -[[package]] -name = "serde_cbor" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" -dependencies = [ - "half", - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.123" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.62" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "syn" -version = "1.0.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "tiny-keccak" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d8a021c69bb74a44ccedb824a046447e2c84a01df9e5c20779750acb38e11b2" -dependencies = [ - "crunchy", -] - -[[package]] -name = "tinytemplate" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ada8616fad06a2d0c455adc530de4ef57605a8120cc65da9653e0e9623ca74" -dependencies = [ - "serde", - "serde_json", -] - -[[package]] -name = "typenum" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" - -[[package]] -name = "unicode-width" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" - -[[package]] -name = "unicode-xid" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" - -[[package]] -name = "walkdir" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" -dependencies = [ - "same-file", - "winapi", - "winapi-util", -] - -[[package]] -name = "wasm-bindgen" -version = "0.2.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64" - -[[package]] -name = "web-sys" -version = "0.3.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/rust/Cargo.toml b/rust/Cargo.toml deleted file mode 100644 index 8c90c477b..000000000 --- a/rust/Cargo.toml +++ /dev/null @@ -1,35 +0,0 @@ -[package] -name = "babyjubjub-rs" -version = "0.0.7" -authors = ["arnaucube "] -edition = "2018" -license = "GPL-3.0" -description = "BabyJubJub elliptic curve implementation" -repository = "https://github.com/arnaucube/babyjubjub-rs" -readme = "README.md" - -[lib] -name = "babyjubjub" -crate-type = ["lib","staticlib", "cdylib"] - -[dependencies] -ff = {package="ff_ce" , version="0.11", features = ["derive"]} -rand = "0.4" -rand6 = {package="rand", version="0.6.5"} -num = "0.2.0" -num-bigint = {version = "0.2.2", features = ["rand"]} -num-traits = "0.2.8" -blake = "2.0.1" -generic-array = "0.13.2" -tiny-keccak = "1.5" -rustc-hex = "1.0.0" -poseidon-rs = "0.0.8" -arrayref = "0.3.5" -lazy_static = "1.4.0" - -[dev-dependencies] -criterion = "0.3" - -[[bench]] -name = "bench_babyjubjub" -harness = false diff --git a/rust/Makefile b/rust/Makefile deleted file mode 100644 index 8617ae807..000000000 --- a/rust/Makefile +++ /dev/null @@ -1,104 +0,0 @@ -.DEFAULT_GOAL := help -PROJECTNAME=$(shell basename "$(PWD)") -SOURCES=$(sort $(wildcard ./src/*.rs ./src/**/*.rs)) - -OS_NAME=$(shell uname | tr '[:upper:]' '[:lower:]') -PATH := $(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(OS_NAME)-x86_64/bin:$(PATH) - -ANDROID_AARCH64_LINKER=$(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(OS_NAME)-x86_64/bin/aarch64-linux-android29-clang -ANDROID_ARMV7_LINKER=$(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(OS_NAME)-x86_64/bin/armv7a-linux-androideabi29-clang -ANDROID_I686_LINKER=$(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(OS_NAME)-x86_64/bin/i686-linux-android29-clang -ANDROID_X86_64_LINKER=$(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(OS_NAME)-x86_64/bin/x86_64-linux-android29-clang - -SHELL := /bin/bash - -# ############################################################################## -# # GENERAL -# ############################################################################## - -.PHONY: help -help: makefile - @echo - @echo " Available actions in "$(PROJECTNAME)":" - @echo - @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' - @echo - -## init: Install missing dependencies. -.PHONY: init -init: - rustup target add aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios - rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android - @if [ $$(uname) == "Darwin" ] ; then cargo install cargo-lipo ; fi - cargo install cbindgen - -## : - -# ############################################################################## -# # RECIPES -# ############################################################################## - -## all: Compile iOS, Android and bindings targets -all: ios android bindings - -## ios: Compile the iOS universal library -ios: target/universal/release/libexample.a - -target/universal/release/libexample.a: $(SOURCES) ndk-home - @if [ $$(uname) == "Darwin" ] ; then \ - cargo lipo --release ; \ - else echo "Skipping iOS compilation on $$(uname)" ; \ - fi - -## android: Compile the android targets (arm64, armv7 and i686) -android: target/aarch64-linux-android/release/libexample.so target/armv7-linux-androideabi/release/libexample.so target/i686-linux-android/release/libexample.so target/x86_64-linux-android/release/libexample.so - -target/aarch64-linux-android/release/libexample.so: $(SOURCES) ndk-home - CC_aarch64_linux_android=$(ANDROID_AARCH64_LINKER) \ - CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$(ANDROID_AARCH64_LINKER) \ - cargo build --target aarch64-linux-android --release - -target/armv7-linux-androideabi/release/libexample.so: $(SOURCES) ndk-home - CC_armv7_linux_androideabi=$(ANDROID_ARMV7_LINKER) \ - CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=$(ANDROID_ARMV7_LINKER) \ - cargo build --target armv7-linux-androideabi --release - -target/i686-linux-android/release/libexample.so: $(SOURCES) ndk-home - CC_i686_linux_android=$(ANDROID_I686_LINKER) \ - CARGO_TARGET_I686_LINUX_ANDROID_LINKER=$(ANDROID_I686_LINKER) \ - cargo build --target i686-linux-android --release - -target/x86_64-linux-android/release/libexample.so: $(SOURCES) ndk-home - CC_x86_64_linux_android=$(ANDROID_X86_64_LINKER) \ - CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=$(ANDROID_X86_64_LINKER) \ - cargo build --target x86_64-linux-android --release - -.PHONY: ndk-home -ndk-home: - @if [ ! -d "${ANDROID_NDK_HOME}" ] ; then \ - echo "Error: Please, set the ANDROID_NDK_HOME env variable to point to your NDK folder" ; \ - exit 1 ; \ - fi - -## bindings: Generate the .h file for iOS -bindings: target/bindings.h - -target/bindings.h: $(SOURCES) - ## cbindgen $^ -c cbindgen.toml | grep -v \#include | uniq > $@ - cbindgen ./src/lib.rs -c cbindgen.toml | grep -v \#include | uniq > $@ -## : - -# ############################################################################## -# # OTHER -# ############################################################################## - -## clean: -.PHONY: clean -clean: - cargo clean - rm -f target/bindings.h target/bindings.src.h - -## test: -.PHONY: test -test: - cargo test diff --git a/rust/benches/bench_babyjubjub.rs b/rust/benches/bench_babyjubjub.rs deleted file mode 100644 index f017c9fb1..000000000 --- a/rust/benches/bench_babyjubjub.rs +++ /dev/null @@ -1,58 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion}; - -extern crate rand; -#[macro_use] -extern crate ff; -use ff::*; - -extern crate num; -extern crate num_bigint; -use num_bigint::{BigInt, ToBigInt}; - -use babyjubjub_rs::{utils, Point}; -use babyjubjub::eddsa::Point; - -fn criterion_benchmark(c: &mut Criterion) { - let p: Point = Point { - x: babyjubjub_rs::Fr::from_str( - "17777552123799933955779906779655732241715742912184938656739573121738514868268", - ) - .unwrap(), - y: babyjubjub_rs::Fr::from_str( - "2626589144620713026669568689430873010625803728049924121243784502389097019475", - ) - .unwrap(), - }; - let q = p.clone(); - - let p_projective = p.projective(); - let q_projective = q.projective(); - - c.bench_function("add", |b| b.iter(|| p_projective.add(&q_projective))); - let r: BigInt = BigInt::parse_bytes(b"3", 10).unwrap(); - c.bench_function("mul_scalar_small", |b| b.iter(|| p.mul_scalar(&r))); - let r: BigInt = BigInt::parse_bytes( - b"2626589144620713026669568689430873010625803728049924121243784502389097019475", - 10, - ) - .unwrap(); - c.bench_function("mul_scalar", |b| b.iter(|| p.mul_scalar(&r))); - - c.bench_function("point compress", |b| b.iter(|| p.compress())); - let p_comp = p.compress(); - c.bench_function("point decompress", |b| { - b.iter(|| babyjubjub_rs::decompress_point(p_comp)) - }); - - let sk = babyjubjub_rs::new_key(); - let pk = sk.public().unwrap(); - let msg = 5.to_bigint().unwrap(); - c.bench_function("sign", |b| b.iter(|| sk.sign(msg.clone()))); - let sig = sk.sign(msg.clone()).unwrap(); - c.bench_function("verify", |b| { - b.iter(|| babyjubjub_rs::verify(pk.clone(), sig.clone(), msg.clone())) - }); -} - -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); diff --git a/rust/cbindgen.toml b/rust/cbindgen.toml deleted file mode 100644 index d5dacd9e5..000000000 --- a/rust/cbindgen.toml +++ /dev/null @@ -1,8 +0,0 @@ -language = "C" -autogen_warning = "// NOTE: Append the lines below to ios/Classes/HermezPlugin.h" -#namespace = "ffi" -#include_guard = "CBINDGEN_BINDINGS_H" - -[defines] -"target_os = ios" = "TARGET_OS_IOS" -"target_os = macos" = "TARGET_OS_MACOS" diff --git a/rust/rs-lib-android-build.sh b/rust/rs-lib-android-build.sh deleted file mode 100644 index 8205ace01..000000000 --- a/rust/rs-lib-android-build.sh +++ /dev/null @@ -1,11 +0,0 @@ -# $ANDROID_NDK_HOME is already set and pointing to the Android NDK folder - -# ENV -AARCH64_LINKER=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android26-clang -ARMV7_LINKER=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi26-clang -I686_LINKER=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android26-clang - -# Build -CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$AARCH64_LINKER cargo build - target aarch64-linux-android - release -CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=$ARMV7_LINKER cargo build - target armv7-linux-androideabi - release -CARGO_TARGET_I686_LINUX_ANDROID_LINKER=$I686_LINKER cargo build - target i686-linux-android - release diff --git a/rust/src/eddsa/mod.rs b/rust/src/eddsa/mod.rs deleted file mode 100644 index 67f0902e3..000000000 --- a/rust/src/eddsa/mod.rs +++ /dev/null @@ -1,753 +0,0 @@ -//extern crate rand; -//#[macro_use] -//extern crate ff; -use ff::*; - -use poseidon_rs::Poseidon; -pub type Fr = poseidon_rs::Fr; // alias - -//#[macro_use] -//extern crate arrayref; -//extern crate generic_array; -//extern crate num; -//extern crate num_bigint; -//extern crate num_traits; - -//extern crate rand6; -use rand6::Rng; - -// use blake2::{Blake2b, Digest}; -//extern crate blake; // compatible version with Blake used at circomlib -//#[macro_use] -//use blake_hash::Digest; - -use std::cmp::min; - -use num_bigint::{BigInt, RandBigInt, Sign, ToBigInt}; -use num_traits::One; - -use generic_array::GenericArray; - -pub mod utils; - -lazy_static! { - static ref D: Fr = Fr::from_str("168696").unwrap(); - static ref D_BIG: BigInt = BigInt::parse_bytes(b"168696", 10).unwrap(); - static ref A: Fr = Fr::from_str("168700").unwrap(); - static ref A_BIG: BigInt = BigInt::parse_bytes(b"168700", 10).unwrap(); - pub static ref Q: BigInt = BigInt::parse_bytes( - b"21888242871839275222246405745257275088548364400416034343698204186575808495617",10 - ) - .unwrap(); - pub static ref B8: Point = Point { - x: Fr::from_str( - "5299619240641551281634865583518297030282874472190772894086521144482721001553", - ) - .unwrap(), - y: Fr::from_str( - "16950150798460657717958625567821834550301663161624707787222815936182638968203", - ) - .unwrap(), - }; - static ref ORDER: Fr = Fr::from_str( - "21888242871839275222246405745257275088614511777268538073601725287587578984328", - ) - .unwrap(); - - // SUBORDER = ORDER >> 3 - static ref SUBORDER: BigInt = &BigInt::parse_bytes( - b"21888242871839275222246405745257275088614511777268538073601725287587578984328", - 10, - ) - .unwrap() - >> 3; - static ref POSEIDON: poseidon_rs::Poseidon = Poseidon::new(); -} - -#[derive(Clone, Debug)] -pub struct PointProjective { - pub x: Fr, - pub y: Fr, - pub z: Fr, -} - -impl PointProjective { - pub fn affine(&self) -> Point { - if self.z.is_zero() { - return Point { - x: Fr::zero(), - y: Fr::zero(), - }; - } - - let zinv = self.z.inverse().unwrap(); - let mut x = self.x.clone(); - x.mul_assign(&zinv); - let mut y = self.y.clone(); - y.mul_assign(&zinv); - - Point { - x: x.clone(), - y: y.clone(), - } - } - pub fn add(&self, q: &PointProjective) -> PointProjective { - // add-2008-bbjlp https://hyperelliptic.org/EFD/g1p/auto-twisted-projective.html#doubling-dbl-2008-bbjlp - let mut a = self.z.clone(); - a.mul_assign(&q.z); - let mut b = a; - b.square(); - let mut c = self.x.clone(); - c.mul_assign(&q.x); - let mut d = self.y.clone(); - d.mul_assign(&q.y); - let mut e = D.clone(); - e.mul_assign(&c); - e.mul_assign(&d); - let mut f = b; - f.sub_assign(&e); - let mut g = b; - g.add_assign(&e); - let mut x1y1 = self.x.clone(); - x1y1.add_assign(&self.y); - let mut x2y2 = q.clone().x; - x2y2.add_assign(&q.y); - let mut aux = x1y1; - aux.mul_assign(&x2y2); - aux.sub_assign(&c); - aux.sub_assign(&d); - let mut x3 = a; - x3.mul_assign(&f); - x3.mul_assign(&aux); - let mut ac = A.clone(); - ac.mul_assign(&c); - let mut dac = d; - dac.sub_assign(&ac); - let mut y3 = a; - y3.mul_assign(&g); - y3.mul_assign(&dac); - let mut z3 = f; - z3.mul_assign(&g); - - PointProjective { - x: x3.clone(), - y: y3.clone(), - z: z3.clone(), - } - } -} - -#[derive(Clone, Debug)] -pub struct Point { - pub x: Fr, - pub y: Fr, -} - -impl Point { - pub fn projective(&self) -> PointProjective { - PointProjective { - x: self.x.clone(), - y: self.y.clone(), - z: Fr::one(), - } - } - - pub fn mul_scalar(&self, n: &BigInt) -> Point { - let mut r: PointProjective = PointProjective { - x: Fr::zero(), - y: Fr::one(), - z: Fr::one(), - }; - let mut exp: PointProjective = self.projective(); - let (_, b) = n.to_bytes_le(); - for i in 0..n.bits() { - if test_bit(&b, i) { - r = r.add(&exp); - } - exp = exp.add(&exp); - } - r.affine() - } - - pub fn compress(&self) -> [u8; 32] { - let p = &self; - let mut r: [u8; 32] = [0; 32]; - let x_big = BigInt::parse_bytes(to_hex(&p.x).as_bytes(), 16).unwrap(); - let y_big = BigInt::parse_bytes(to_hex(&p.y).as_bytes(), 16).unwrap(); - let (_, y_bytes) = y_big.to_bytes_le(); - let len = min(y_bytes.len(), r.len()); - r[..len].copy_from_slice(&y_bytes[..len]); - if &x_big > &(&Q.clone() >> 1) { - r[31] = r[31] | 0x80; - } - r - } - - pub fn equals(&self, p: Point) -> bool { - if self.x == p.x && self.y == p.y { - return true; - } - false - } -} - -pub fn test_bit(b: &Vec, i: usize) -> bool { - return b[i / 8] & (1 << (i % 8)) != 0; -} - -pub fn decompress_point(bb: [u8; 32]) -> Result { - // https://tools.ietf.org/html/rfc8032#section-5.2.3 - let mut sign: bool = false; - let mut b = bb.clone(); - if b[31] & 0x80 != 0x00 { - sign = true; - b[31] = b[31] & 0x7F; - } - let y: BigInt = BigInt::from_bytes_le(Sign::Plus, &b[..]); - if y >= Q.clone() { - return Err("y outside the Finite Field over R".to_string()); - } - let one: BigInt = One::one(); - - // x^2 = (1 - y^2) / (a - d * y^2) (mod p) - let den = utils::modinv( - &utils::modulus( - &(&A_BIG.clone() - utils::modulus(&(&D_BIG.clone() * (&y * &y)), &Q)), - &Q, - ), - &Q, - )?; - let mut x: BigInt = utils::modulus(&((one - utils::modulus(&(&y * &y), &Q)) * den), &Q); - x = utils::modsqrt(&x, &Q)?; - - if sign && !(&x > &(&Q.clone() >> 1)) || (!sign && (&x > &(&Q.clone() >> 1))) { - x = x * -1.to_bigint().unwrap(); - } - x = utils::modulus(&x, &Q); - let x_fr: Fr = Fr::from_str(&x.to_string()).unwrap(); - let y_fr: Fr = Fr::from_str(&y.to_string()).unwrap(); - Ok(Point { x: x_fr, y: y_fr }) -} - -#[derive(Debug, Clone)] -pub struct Signature { - pub r_b8: Point, - pub s: BigInt, -} - -impl Signature { - pub fn compress(&self) -> [u8; 64] { - let mut b: Vec = Vec::new(); - b.append(&mut self.r_b8.compress().to_vec()); - let (_, s_bytes) = self.s.to_bytes_le(); - let mut s_32bytes: [u8; 32] = [0; 32]; - let len = min(s_bytes.len(), s_32bytes.len()); - s_32bytes[..len].copy_from_slice(&s_bytes[..len]); - b.append(&mut s_32bytes.to_vec()); - let mut r: [u8; 64] = [0; 64]; - r[..].copy_from_slice(&b[..]); - r - } -} - -pub fn decompress_signature(b: &[u8; 64]) -> Result { - let r_b8_bytes: [u8; 32] = *array_ref!(b[..32], 0, 32); - let s: BigInt = BigInt::from_bytes_le(Sign::Plus, &b[32..]); - let r_b8 = decompress_point(r_b8_bytes); - match r_b8 { - Result::Err(err) => return Err(err.to_string()), - Result::Ok(res) => Ok(Signature { - r_b8: res.clone(), - s: s, - }), - } -} - -pub struct PrivateKey { - pub key: [u8; 32], -} - -impl PrivateKey { - pub fn import(b: Vec) -> Result { - if b.len() != 32 { - return Err(String::from("imported key can not be bigger than 32 bytes")); - } - let mut sk: [u8; 32] = [0; 32]; - sk.copy_from_slice(&b[..32]); - Ok(PrivateKey { key: sk }) - } - - pub fn scalar_key(&self) -> BigInt { - // not-compatible with circomlib implementation, but using Blake2b - // let mut hasher = Blake2b::new(); - // hasher.update(sk_raw_bytes); - // let mut h = hasher.finalize(); - - // compatible with circomlib implementation - //let hash = blake_hash::Blake512::digest(&self.key.to_vec()); - let mut hash = [0; 64]; - blake::hash(512,&self.key,&mut hash).unwrap(); - let mut h: Vec = hash[..32].to_vec(); - - h[0] = h[0] & 0xF8; - h[31] = h[31] & 0x7F; - h[31] = h[31] | 0x40; - - let sk = BigInt::from_bytes_le(Sign::Plus, &h[..]); - sk >> 3 - } - - pub fn public(&self) -> Point { - // https://tools.ietf.org/html/rfc8032#section-5.1.5 - let pk = B8.mul_scalar(&self.scalar_key()); - pk.clone() - } - - pub fn sign(&self, msg: BigInt) -> Result { - if msg > Q.clone() { - return Err("msg outside the Finite Field".to_string()); - } - // let (_, sk_bytes) = self.key.to_bytes_le(); - // let mut hasher = Blake2b::new(); - // hasher.update(sk_bytes); - // let mut h = hasher.finalize(); // h: hash(sk), s: h[32:64] - let mut h = [0; 64]; - blake::hash(512,&self.key,&mut h).unwrap(); - //let mut h = blake_hash::Blake512::digest(&self.key); - - let (_, msg_bytes) = msg.to_bytes_le(); - let mut msg32: [u8; 32] = [0; 32]; - msg32[..msg_bytes.len()].copy_from_slice(&msg_bytes[..]); - let msg_fr: Fr = Fr::from_str(&msg.to_string()).unwrap(); - - // https://tools.ietf.org/html/rfc8032#section-5.1.6 - let s = GenericArray::::from_mut_slice(&mut h[32..64]); - let r_bytes = utils::concatenate_arrays(s, &msg32); - let mut r_hashed = [0; 64]; - blake::hash(512,&r_bytes,&mut r_hashed).unwrap(); - //let r_hashed = blake_hash::Blake512::digest(&r_bytes); - let mut r = BigInt::from_bytes_le(Sign::Plus, &r_hashed[..]); - r = utils::modulus(&r, &SUBORDER); - let r8: Point = B8.mul_scalar(&r); - let a = &self.public(); - - let hm_input = vec![r8.x.clone(), r8.y.clone(), a.x.clone(), a.y.clone(), msg_fr]; - let hm = POSEIDON.hash(hm_input)?; - - let mut s = &self.scalar_key() << 3; - let hm_b = BigInt::parse_bytes(to_hex(&hm).as_bytes(), 16).unwrap(); - s = hm_b * s; - s = r + s; - s = s % &SUBORDER.clone(); - - Ok(Signature { - r_b8: r8.clone(), - s: s, - }) - } - - pub fn sign_schnorr(&self, m: BigInt) -> Result<(Point, BigInt), String> { - // random r - let mut rng = rand6::thread_rng(); - let k = rng.gen_biguint(1024).to_bigint().unwrap(); - - // r = k·G - let r = B8.mul_scalar(&k); - - // h = H(x, r, m) - let pk = &self.public(); - let h = schnorr_hash(&pk, m, &r)?; - - // s= k+x·h - let sk_scalar = self.scalar_key(); - let s = k + &sk_scalar * &h; - Ok((r, s)) - } -} - -pub fn schnorr_hash(pk: &Point, msg: BigInt, c: &Point) -> Result { - if msg > Q.clone() { - return Err("msg outside the Finite Field".to_string()); - } - let msg_fr: Fr = Fr::from_str(&msg.to_string()).unwrap(); - let hm_input = vec![pk.x.clone(), pk.y.clone(), c.x.clone(), c.y.clone(), msg_fr]; - let h = POSEIDON.hash(hm_input)?; - let h_b = BigInt::parse_bytes(to_hex(&h).as_bytes(), 16).unwrap(); - Ok(h_b) -} - -pub fn verify_schnorr(pk: Point, m: BigInt, r: Point, s: BigInt) -> Result { - // sG = s·G - let sg = B8.mul_scalar(&s); - - // r + h · x - let h = schnorr_hash(&pk, m, &r)?; - let pk_h = pk.mul_scalar(&h); - let right = r.projective().add(&pk_h.projective()); - - Ok(sg.equals(right.affine())) -} - -pub fn new_key() -> PrivateKey { - // https://tools.ietf.org/html/rfc8032#section-5.1.5 - let mut rng = rand6::thread_rng(); - let sk_raw = rng.gen_biguint(1024).to_bigint().unwrap(); - let (_, sk_raw_bytes) = sk_raw.to_bytes_be(); - PrivateKey::import(sk_raw_bytes[..32].to_vec()).unwrap() -} - -pub fn verify(pk: Point, sig: Signature, msg: BigInt) -> bool { - if msg > Q.clone() { - return false; - } - let msg_fr: Fr = Fr::from_str(&msg.to_string()).unwrap(); - let hm_input = vec![ - sig.r_b8.x.clone(), - sig.r_b8.y.clone(), - pk.x.clone(), - pk.y.clone(), - msg_fr, - ]; - let hm = match POSEIDON.hash(hm_input) { - Result::Err(_) => return false, - Result::Ok(hm) => hm, - }; - let l = B8.mul_scalar(&sig.s); - let hm_b = BigInt::parse_bytes(to_hex(&hm).as_bytes(), 16).unwrap(); - let r = sig - .r_b8 - .projective() - .add(&pk.mul_scalar(&(8.to_bigint().unwrap() * hm_b)).projective()); - l.equals(r.affine()) -} - -#[cfg(test)] -mod tests { - use super::*; - extern crate rustc_hex; - use rustc_hex::{FromHex, ToHex}; - - #[test] - fn test_add_same_point() { - let p: PointProjective = PointProjective { - x: Fr::from_str( - "17777552123799933955779906779655732241715742912184938656739573121738514868268", - ) - .unwrap(), - y: Fr::from_str( - "2626589144620713026669568689430873010625803728049924121243784502389097019475", - ) - .unwrap(), - z: Fr::one(), - }; - let q: PointProjective = PointProjective { - x: Fr::from_str( - "17777552123799933955779906779655732241715742912184938656739573121738514868268", - ) - .unwrap(), - y: Fr::from_str( - "2626589144620713026669568689430873010625803728049924121243784502389097019475", - ) - .unwrap(), - z: Fr::one(), - }; - let res = p.add(&q).affine(); - assert_eq!( - res.x, - Fr::from_str( - "6890855772600357754907169075114257697580319025794532037257385534741338397365" - ) - .unwrap() - ); - assert_eq!( - res.y, - Fr::from_str( - "4338620300185947561074059802482547481416142213883829469920100239455078257889" - ) - .unwrap() - ); - } - #[test] - fn test_add_different_points() { - let p: PointProjective = PointProjective { - x: Fr::from_str( - "17777552123799933955779906779655732241715742912184938656739573121738514868268", - ) - .unwrap(), - y: Fr::from_str( - "2626589144620713026669568689430873010625803728049924121243784502389097019475", - ) - .unwrap(), - z: Fr::one(), - }; - let q: PointProjective = PointProjective { - x: Fr::from_str( - "16540640123574156134436876038791482806971768689494387082833631921987005038935", - ) - .unwrap(), - y: Fr::from_str( - "20819045374670962167435360035096875258406992893633759881276124905556507972311", - ) - .unwrap(), - z: Fr::one(), - }; - let res = p.add(&q).affine(); - assert_eq!( - res.x, - Fr::from_str( - "7916061937171219682591368294088513039687205273691143098332585753343424131937" - ) - .unwrap() - ); - assert_eq!( - res.y, - Fr::from_str( - "14035240266687799601661095864649209771790948434046947201833777492504781204499" - ) - .unwrap() - ); - } - - #[test] - fn test_mul_scalar() { - let p: Point = Point { - x: Fr::from_str( - "17777552123799933955779906779655732241715742912184938656739573121738514868268", - ) - .unwrap(), - y: Fr::from_str( - "2626589144620713026669568689430873010625803728049924121243784502389097019475", - ) - .unwrap(), - }; - let res_m = p.mul_scalar(&3.to_bigint().unwrap()); - let res_a = p.projective().add(&p.projective()); - let res_a = res_a.add(&p.projective()).affine(); - assert_eq!(res_m.x, res_a.x); - assert_eq!( - res_m.x, - Fr::from_str( - "19372461775513343691590086534037741906533799473648040012278229434133483800898" - ) - .unwrap() - ); - assert_eq!( - res_m.y, - Fr::from_str( - "9458658722007214007257525444427903161243386465067105737478306991484593958249" - ) - .unwrap() - ); - - let n = BigInt::parse_bytes( - b"14035240266687799601661095864649209771790948434046947201833777492504781204499", - 10, - ) - .unwrap(); - let res2 = p.mul_scalar(&n); - assert_eq!( - res2.x, - Fr::from_str( - "17070357974431721403481313912716834497662307308519659060910483826664480189605" - ) - .unwrap() - ); - assert_eq!( - res2.y, - Fr::from_str( - "4014745322800118607127020275658861516666525056516280575712425373174125159339" - ) - .unwrap() - ); - } - - #[test] - fn test_new_key_sign_verify_0() { - let sk = new_key(); - let pk = sk.public(); - let msg = 5.to_bigint().unwrap(); - let sig = sk.sign(msg.clone()).unwrap(); - let v = verify(pk, sig, msg); - assert_eq!(v, true); - } - - #[test] - fn test_new_key_sign_verify_1() { - let sk = new_key(); - let pk = sk.public(); - let msg = BigInt::parse_bytes(b"123456789012345678901234567890", 10).unwrap(); - let sig = sk.sign(msg.clone()).unwrap(); - let v = verify(pk, sig, msg); - assert_eq!(v, true); - } - - #[test] - fn test_point_compress_decompress() { - let p: Point = Point { - x: Fr::from_str( - "17777552123799933955779906779655732241715742912184938656739573121738514868268", - ) - .unwrap(), - y: Fr::from_str( - "2626589144620713026669568689430873010625803728049924121243784502389097019475", - ) - .unwrap(), - }; - let p_comp = p.compress(); - assert_eq!( - p_comp[..].to_hex(), - "53b81ed5bffe9545b54016234682e7b2f699bd42a5e9eae27ff4051bc698ce85" - ); - let p2 = decompress_point(p_comp).unwrap(); - assert_eq!(p.x, p2.x); - assert_eq!(p.y, p2.y); - } - - #[test] - fn test_point_decompress0() { - let y_bytes_raw = "b5328f8791d48f20bec6e481d91c7ada235f1facf22547901c18656b6c3e042f" - .from_hex() - .unwrap(); - let mut y_bytes: [u8; 32] = [0; 32]; - y_bytes.copy_from_slice(&y_bytes_raw); - let p = decompress_point(y_bytes).unwrap(); - - let expected_px_raw = "b86cc8d9c97daef0afe1a4753c54fb2d8a530dc74c7eee4e72b3fdf2496d2113" - .from_hex() - .unwrap(); - let mut e_px_bytes: [u8; 32] = [0; 32]; - e_px_bytes.copy_from_slice(&expected_px_raw); - let expected_px: Fr = - Fr::from_str(&BigInt::from_bytes_le(Sign::Plus, &e_px_bytes).to_string()).unwrap(); - assert_eq!(&p.x, &expected_px); - } - - #[test] - fn test_point_decompress1() { - let y_bytes_raw = "70552d3ff548e09266ded29b33ce75139672b062b02aa66bb0d9247ffecf1d0b" - .from_hex() - .unwrap(); - let mut y_bytes: [u8; 32] = [0; 32]; - y_bytes.copy_from_slice(&y_bytes_raw); - let p = decompress_point(y_bytes).unwrap(); - - let expected_px_raw = "30f1635ba7d56f9cb32c3ffbe6dca508a68c7f43936af11a23c785ce98cb3404" - .from_hex() - .unwrap(); - let mut e_px_bytes: [u8; 32] = [0; 32]; - e_px_bytes.copy_from_slice(&expected_px_raw); - let expected_px: Fr = - Fr::from_str(&BigInt::from_bytes_le(Sign::Plus, &e_px_bytes).to_string()).unwrap(); - assert_eq!(&p.x, &expected_px); - } - - #[test] - fn test_point_decompress_loop() { - for _ in 0..5 { - let random_bytes = rand6::thread_rng().gen::<[u8; 32]>(); - let sk_raw: BigInt = BigInt::from_bytes_le(Sign::Plus, &random_bytes[..]); - let (_, sk_raw_bytes) = sk_raw.to_bytes_be(); - let mut h = [0; 64]; - blake::hash(512,&sk_raw_bytes,&mut h).unwrap(); - //let mut h = blake_hash::Blake512::digest(&sk_raw_bytes); - - h[0] = h[0] & 0xF8; - h[31] = h[31] & 0x7F; - h[31] = h[31] | 0x40; - - let sk = BigInt::from_bytes_le(Sign::Plus, &h[..]); - let point = B8.mul_scalar(&sk); - let cmp_point = point.compress(); - let dcmp_point = decompress_point(cmp_point).unwrap(); - - assert_eq!(&point.x, &dcmp_point.x); - assert_eq!(&point.y, &dcmp_point.y); - } - } - - #[test] - fn test_signature_compress_decompress() { - let sk = new_key(); - let pk = sk.public(); - - for i in 0..5 { - let msg_raw = "123456".to_owned() + &i.to_string(); - let msg = BigInt::parse_bytes(msg_raw.as_bytes(), 10).unwrap(); - let sig = sk.sign(msg.clone()).unwrap(); - - let compressed_sig = sig.compress(); - let decompressed_sig = decompress_signature(&compressed_sig).unwrap(); - assert_eq!(&sig.r_b8.x, &decompressed_sig.r_b8.x); - assert_eq!(&sig.r_b8.y, &decompressed_sig.r_b8.y); - assert_eq!(&sig.s, &decompressed_sig.s); - - let v = verify(pk.clone(), decompressed_sig, msg); - assert_eq!(v, true); - } - } - - #[test] - fn test_schnorr_signature() { - let sk = new_key(); - let pk = sk.public(); - - let msg = BigInt::parse_bytes(b"123456789012345678901234567890", 10).unwrap(); - let (s, e) = sk.sign_schnorr(msg.clone()).unwrap(); - let verification = verify_schnorr(pk, msg, s, e).unwrap(); - assert_eq!(true, verification); - } - - #[test] - fn test_circomlib_testvector() { - let sk_raw_bytes = - hex::decode("0001020304050607080900010203040506070809000102030405060708090001") - .unwrap(); - - // test blake compatible with circomlib implementation - let mut h = [0; 64]; - blake::hash(512,&sk_raw_bytes,&mut h).unwrap(); - //let h = blake_hash::Blake512::digest(&sk_raw_bytes); - assert_eq!(h.to_hex(), "c992db23d6290c70ffcc02f7abeb00b9d00fa8b43e55d7949c28ba6be7545d3253882a61bd004a236ef1cdba01b27ba0aedfb08eefdbfb7c19657c880b43ddf1"); - - // test private key - let sk = PrivateKey::import( - hex::decode("0001020304050607080900010203040506070809000102030405060708090001") - .unwrap(), - ) - .unwrap(); - assert_eq!( - sk.scalar_key().to_string(), - "6466070937662820620902051049739362987537906109895538826186780010858059362905" - ); - - // test public key - let pk = sk.public(); - assert_eq!( - pk.x.to_string(), - "Fr(0x1d5ac1f31407018b7d413a4f52c8f74463b30e6ac2238220ad8b254de4eaa3a2)" - ); - assert_eq!( - pk.y.to_string(), - "Fr(0x1e1de8a908826c3f9ac2e0ceee929ecd0caf3b99b3ef24523aaab796a6f733c4)" - ); - - // test signature & verification - let msg = BigInt::from_bytes_le(Sign::Plus, &hex::decode("00010203040506070809").unwrap()); - println!("msg {:?}", msg.to_string()); - let sig = sk.sign(msg.clone()).unwrap(); - assert_eq!( - sig.r_b8.x.to_string(), - "Fr(0x192b4e51adf302c8139d356d0e08e2404b5ace440ef41fc78f5c4f2428df0765)" - ); - assert_eq!( - sig.r_b8.y.to_string(), - "Fr(0x2202bebcf57b820863e0acc88970b6ca7d987a0d513c2ddeb42e3f5d31b4eddf)" - ); - assert_eq!( - sig.s.to_string(), - "1672775540645840396591609181675628451599263765380031905495115170613215233181" - ); - let v = verify(pk, sig, msg); - assert_eq!(v, true); - } -} diff --git a/rust/src/eddsa/utils.rs b/rust/src/eddsa/utils.rs deleted file mode 100644 index 376304076..000000000 --- a/rust/src/eddsa/utils.rs +++ /dev/null @@ -1,268 +0,0 @@ -extern crate num; -extern crate num_bigint; -extern crate num_traits; - -use num_bigint::{BigInt, ToBigInt}; -use num_traits::{One, Zero}; - -pub fn modulus(a: &BigInt, m: &BigInt) -> BigInt { - ((a % m) + m) % m -} - -pub fn modinv(a: &BigInt, q: &BigInt) -> Result { - let big_zero: BigInt = Zero::zero(); - if a == &big_zero { - return Err("no mod inv of Zero".to_string()); - } - - let mut mn = (q.clone(), a.clone()); - let mut xy: (BigInt, BigInt) = (Zero::zero(), One::one()); - - while mn.1 != big_zero { - xy = (xy.1.clone(), xy.0 - (mn.0.clone() / mn.1.clone()) * xy.1); - mn = (mn.1.clone(), modulus(&mn.0, &mn.1)); - } - - while xy.0 < Zero::zero() { - xy.0 = modulus(&xy.0, q); - } - Ok(xy.0) -} - -/* -pub fn modinv_v2(a0: &BigInt, m0: &BigInt) -> BigInt { - if m0 == &One::one() { - return One::one(); - } - - let (mut a, mut m, mut x0, mut inv): (BigInt, BigInt, BigInt, BigInt) = - (a0.clone(), m0.clone(), Zero::zero(), One::one()); - - while a > One::one() { - inv = inv - (&a / m.clone()) * x0.clone(); - a = a % m.clone(); - std::mem::swap(&mut a, &mut m); - std::mem::swap(&mut x0, &mut inv); - } - - if inv < Zero::zero() { - inv += m0.clone() - } - inv -} - -pub fn modinv_v3(a: &BigInt, q: &BigInt) -> BigInt { - let mut aa: BigInt = a.clone(); - let mut qq: BigInt = q.clone(); - if qq < Zero::zero() { - qq = -qq; - } - if aa < Zero::zero() { - aa = -aa; - } - let d = num::Integer::gcd(&aa, &qq); - if d != One::one() { - println!("ERR no mod_inv"); - } - let res: BigInt; - if d < Zero::zero() { - res = d + qq; - } else { - res = d; - } - res -} -pub fn modinv_v4(x: &BigInt, q: &BigInt) -> BigInt { - let (gcd, inverse, _) = extended_gcd(x.clone(), q.clone()); - let one: BigInt = One::one(); - if gcd == one { - modulus(&inverse, q) - } else { - panic!("error: gcd!=one") - } -} -pub fn extended_gcd(a: BigInt, b: BigInt) -> (BigInt, BigInt, BigInt) { - let (mut s, mut old_s) = (BigInt::zero(), BigInt::one()); - let (mut t, mut old_t) = (BigInt::one(), BigInt::zero()); - let (mut r, mut old_r) = (b, a); - - while r != BigInt::zero() { - let quotient = &old_r / &r; - old_r -= "ient * &r; - std::mem::swap(&mut old_r, &mut r); - old_s -= "ient * &s; - std::mem::swap(&mut old_s, &mut s); - old_t -= quotient * &t; - std::mem::swap(&mut old_t, &mut t); - } - - let _quotients = (t, s); // == (a, b) / gcd - - (old_r, old_s, old_t) -} -*/ - -pub fn concatenate_arrays(x: &[T], y: &[T]) -> Vec { - x.iter().chain(y).cloned().collect() -} - -pub fn modsqrt(a: &BigInt, q: &BigInt) -> Result { - // Tonelli-Shanks Algorithm (https://en.wikipedia.org/wiki/Tonelli%E2%80%93Shanks_algorithm) - // - // This implementation is following the Go lang core implementation https://golang.org/src/math/big/int.go?s=23173:23210#L859 - // Also described in https://www.maa.org/sites/default/files/pdf/upload_library/22/Polya/07468342.di020786.02p0470a.pdf - // -> section 6 - - let zero: BigInt = Zero::zero(); - let one: BigInt = One::one(); - if legendre_symbol(&a, q) != 1 { - return Err("not a mod p square".to_string()); - } else if a == &zero { - return Err("not a mod p square".to_string()); - } else if q == &2.to_bigint().unwrap() { - return Err("not a mod p square".to_string()); - } else if q % 4.to_bigint().unwrap() == 3.to_bigint().unwrap() { - let r = a.modpow(&((q + one) / 4), &q); - return Ok(r); - } - - let mut s = q - &one; - let mut e: BigInt = Zero::zero(); - while &s % 2 == zero { - s = s >> 1; - e = e + &one; - } - - let mut n: BigInt = 2.to_bigint().unwrap(); - while legendre_symbol(&n, q) != -1 { - n = &n + &one; - } - - let mut y = a.modpow(&((&s + &one) >> 1), q); - let mut b = a.modpow(&s, q); - let mut g = n.modpow(&s, q); - let mut r = e; - - loop { - let mut t = b.clone(); - let mut m: BigInt = Zero::zero(); - while &t != &one { - t = modulus(&(&t * &t), q); - m = m + &one; - } - - if m == zero { - return Ok(y.clone()); - } - - t = g.modpow(&(2.to_bigint().unwrap().modpow(&(&r - &m - 1), q)), q); - g = g.modpow(&(2.to_bigint().unwrap().modpow(&(r - &m), q)), q); - y = modulus(&(y * t), q); - b = modulus(&(b * &g), q); - r = m.clone(); - } -} - -#[allow(dead_code)] -pub fn modsqrt_v2(a: &BigInt, q: &BigInt) -> Result { - // Tonelli-Shanks Algorithm (https://en.wikipedia.org/wiki/Tonelli%E2%80%93Shanks_algorithm) - // - // This implementation is following this Python implementation by Dusk https://github.com/dusk-network/dusk-zerocaf/blob/master/tools/tonelli.py - - let zero: BigInt = Zero::zero(); - let one: BigInt = One::one(); - if legendre_symbol(&a, q) != 1 { - return Err("not a mod p square".to_string()); - } else if a == &zero { - return Err("not a mod p square".to_string()); - } else if q == &2.to_bigint().unwrap() { - return Err("not a mod p square".to_string()); - } else if q % 4.to_bigint().unwrap() == 3.to_bigint().unwrap() { - let r = a.modpow(&((q + one) / 4), &q); - return Ok(r); - } - - let mut p = q - &one; - let mut s: BigInt = Zero::zero(); - while &p % 2.to_bigint().unwrap() == zero { - s = s + &one; - p = p >> 1; - } - - let mut z: BigInt = One::one(); - while legendre_symbol(&z, q) != -1 { - z = &z + &one; - } - let mut c = z.modpow(&p, q); - - let mut x = a.modpow(&((&p + &one) >> 1), q); - let mut t = a.modpow(&p, q); - let mut m = s; - - while &t != &one { - let mut i: BigInt = One::one(); - let mut e: BigInt = 2.to_bigint().unwrap(); - while i < m { - if t.modpow(&e, q) == one { - break; - } - e = e * 2.to_bigint().unwrap(); - i = i + &one; - } - - let b = c.modpow(&(2.to_bigint().unwrap().modpow(&(&m - &i - 1), q)), q); - x = modulus(&(x * &b), q); - t = modulus(&(t * &b * &b), q); - c = modulus(&(&b * &b), q); - m = i.clone(); - } - return Ok(x); -} - -pub fn legendre_symbol(a: &BigInt, q: &BigInt) -> i32 { - // returns 1 if has a square root modulo q - let one: BigInt = One::one(); - let ls: BigInt = a.modpow(&((q - &one) >> 1), &q); - if &(ls) == &(q - one) { - return -1; - } - 1 -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_mod_inverse() { - let a = BigInt::parse_bytes(b"123456789123456789123456789123456789123456789", 10).unwrap(); - let b = BigInt::parse_bytes(b"12345678", 10).unwrap(); - assert_eq!( - modinv(&a, &b).unwrap(), - BigInt::parse_bytes(b"641883", 10).unwrap() - ); - } - - #[test] - fn test_sqrtmod() { - let a = BigInt::parse_bytes( - b"6536923810004159332831702809452452174451353762940761092345538667656658715568", - 10, - ) - .unwrap(); - let q = BigInt::parse_bytes( - b"7237005577332262213973186563042994240857116359379907606001950938285454250989", - 10, - ) - .unwrap(); - - assert_eq!( - (modsqrt(&a, &q).unwrap()).to_string(), - "5464794816676661649783249706827271879994893912039750480019443499440603127256" - ); - assert_eq!( - (modsqrt_v2(&a, &q).unwrap()).to_string(), - "5464794816676661649783249706827271879994893912039750480019443499440603127256" - ); - } -} diff --git a/rust/src/lib.rs b/rust/src/lib.rs deleted file mode 100644 index c9d9aafa9..000000000 --- a/rust/src/lib.rs +++ /dev/null @@ -1,685 +0,0 @@ -// WARNING still updating the code, it works, but is still in process the refactor. - -pub mod eddsa; - -use poseidon_rs::Poseidon; -pub type Fr = poseidon_rs::Fr; - -extern crate ff; - -#[macro_use] -extern crate arrayref; -extern crate generic_array; -//extern crate mimc_rs; -extern crate num; -extern crate num_bigint; -extern crate num_traits; -extern crate rand6; -extern crate rand; -extern crate blake; // compatible version with Blake used at circomlib -#[macro_use] -extern crate lazy_static; - -use ff::*; - -use crate::eddsa::{Signature, decompress_point, Point, PrivateKey, verify, decompress_signature}; -use num_bigint::{Sign, BigInt}; -use std::convert::TryInto; -use std::os::raw::{c_char}; -use std::ffi::{CStr, CString}; -use std::cmp::min; -use std::str::FromStr; -use rustc_hex::{FromHex, ToHex}; -use std::panic::catch_unwind; - -/*lazy_static! { - static ref B8: Point = Point { - x: Fr::from_str( - "5299619240641551281634865583518297030282874472190772894086521144482721001553", - ) - .unwrap(), - y: Fr::from_str( - "16950150798460657717958625567821834550301663161624707787222815936182638968203", - ) - .unwrap(), - // z: Fr::one(), - }; -}*/ - -#[no_mangle] -pub /*extern*/ fn pack_signature_internal(signature: *const c_char) -> *mut c_char { - let signature_cstr = unsafe { CStr::from_ptr(signature) }; - let signature_str = match signature_cstr.to_str() { - Err(_) => "there", - Ok(string) => string, - }; - let signature_bytes_raw = signature_str.from_hex().unwrap(); - let mut signature_bytes: [u8; 64] = [0; 64]; - signature_bytes.copy_from_slice(&signature_bytes_raw); - - let r_b8_bytes: [u8; 32] = *array_ref!(signature_bytes[..32], 0, 32); - let s: BigInt = BigInt::from_bytes_le(Sign::Plus, &signature_bytes[32..]); - - //let x_big = BigInt::parse_bytes(&r_b8_bytes[..16], 16).unwrap(); - //let y_big = BigInt::parse_bytes(&r_b8_bytes[16..], 16).unwrap(); - /*let (_, x_bytes) = x_big.to_bytes_le(); - let (_, y_bytes) = y_big.to_bytes_le(); - - let mut x_16bytes: [u8; 16] = [0; 16]; - let lenx = min(x_bytes.len(), x_16bytes.len()); - x_16bytes[..lenx].copy_from_slice(&x_bytes[..lenx]); - b.append(&mut x_16bytes.to_vec()); - - let mut y_16bytes: [u8; 16] = [0; 16]; - let leny = min(y_bytes.len(), y_16bytes.len()); - y_16bytes[..leny].copy_from_slice(&y_bytes[..leny]); - b.append(&mut y_16bytes.to_vec());*/ - - - //let x_string = to_hex_string(r_b8_bytes[..16].to_vec()); - //let x_str = x_string.as_str(); - //let y_string = to_hex_string(r_b8_bytes[16..].to_vec()); - - //let r_b8 = decompress_point(r_b8_bytes).unwrap(); - //let y_str = y_string.as_str(); - //let x_big = BigInt::parse_bytes(&r_b8_bytes[0..15], 16).unwrap(); - //let y_big = BigInt::parse_bytes(&r_b8_bytes[15..32], 16).unwrap(); - let x_big: BigInt = BigInt::from_bytes_le(Sign::Plus, &r_b8_bytes[0..15]); - let y_big: BigInt = BigInt::from_bytes_le(Sign::Plus, &r_b8_bytes[15..32]); - //let y_big = x_big.clone(); - - let x:Fr = Fr::from_str( - &x_big.to_string(), - ).unwrap(); - - let y:Fr = Fr::from_str( - &y_big.to_string(), - ).unwrap(); - - let r_b8: Point = Point { - x: x, - y: y, - }; - - let sig = Signature { r_b8 : r_b8.clone(), s }; - let res = sig.compress(); - - let hex_string = to_hex_string(res.to_vec()); - CString::new(hex_string.as_str()).unwrap().into_raw() -} - -#[no_mangle] -pub extern fn pack_signature(signature: *const c_char) -> *mut c_char { - let result = catch_unwind(|| pack_signature_internal(signature)); - match result { - Ok(res) => res, - Err(e) => { - println!("pack_signature Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - -#[no_mangle] -pub /*extern*/ fn unpack_signature_internal(compressed_signature: *const c_char) -> *mut c_char { - let compressed_signature_cstr = unsafe { CStr::from_ptr(compressed_signature) }; - let compressed_signature_str = match compressed_signature_cstr.to_str() { - Err(_) => "there", - Ok(string) => string, - }; - let compressed_signature_bytes_raw = compressed_signature_str.from_hex().unwrap(); - let mut compressed_signature_bytes: [u8; 64] = [0; 64]; - compressed_signature_bytes.copy_from_slice(&compressed_signature_bytes_raw); - let decompressed_sig = decompress_signature(&compressed_signature_bytes).unwrap(); - - let mut b: Vec = Vec::new(); - - let x_big = BigInt::parse_bytes(to_hex(&decompressed_sig.r_b8.x).as_bytes(), 16).unwrap(); - let y_big = BigInt::parse_bytes(to_hex(&decompressed_sig.r_b8.y).as_bytes(), 16).unwrap(); - let (_, x_bytes) = x_big.to_bytes_le(); - let (_, y_bytes) = y_big.to_bytes_le(); - - let mut x_16bytes: [u8; 16] = [0; 16]; - let lenx = min(x_bytes.len(), x_16bytes.len()); - x_16bytes[..lenx].copy_from_slice(&x_bytes[..lenx]); - b.append(&mut x_16bytes.to_vec()); - - let mut y_16bytes: [u8; 16] = [0; 16]; - let leny = min(y_bytes.len(), y_16bytes.len()); - y_16bytes[..leny].copy_from_slice(&y_bytes[..leny]); - b.append(&mut y_16bytes.to_vec()); - - let (_, s_bytes) = decompressed_sig.s.to_bytes_le(); - let mut s_32bytes: [u8; 32] = [0; 32]; - let lens = min(s_bytes.len(), s_32bytes.len()); - s_32bytes[..lens].copy_from_slice(&s_bytes[..lens]); - b.append(&mut s_32bytes.to_vec()); - - let mut r: [u8; 64] = [0; 64]; - let res_len = min(r.len(), b.len()); - r[..res_len].copy_from_slice(&b[..res_len]); - - let hex_string = to_hex_string(r.to_vec()); - CString::new(hex_string.as_str()).unwrap().into_raw() -} - -#[no_mangle] -pub extern fn unpack_signature(compressed_signature: *const c_char) -> *mut c_char { - println!("Rust unpack_signature"); - let result = catch_unwind(|| unpack_signature_internal(compressed_signature)); - match result { - Ok(res) => res, - Err(e) => { - println!("unpack_signature Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - -#[no_mangle] -pub /*extern*/ fn pack_point_internal(point_x: *const c_char, point_y: *const c_char) -> *mut c_char { - let point_x_cstr = unsafe { CStr::from_ptr(point_x) }; - let point_x_str = match point_x_cstr.to_str() { - Err(_) => "there", - Ok(string) => string, - }; - let point_y_cstr = unsafe { CStr::from_ptr(point_y) }; - let point_y_str = match point_y_cstr.to_str() { - Err(_) => "there", - Ok(string) => string, - }; - let p: Point = Point { - x: Fr::from_str(point_x_str).unwrap(), - y: Fr::from_str(point_y_str).unwrap(), - }; - - let compressed_point = p.compress(); - let hex_string = to_hex_string(compressed_point.to_vec()); - CString::new(hex_string.as_str()).unwrap().into_raw() -} - -#[no_mangle] -pub extern fn pack_point(point_x: *const c_char, point_y: *const c_char) -> *mut c_char { - let result = catch_unwind(|| pack_point_internal(point_x, point_y)); - match result { - Ok(res) => res, - Err(e) => { - println!("pack_point Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - -pub fn to_hex_string(bytes: Vec) -> String { - let strs: Vec = bytes.iter() - .map(|b| format!("{:02X}", b)) - .collect(); - strs.join("") -} - -#[no_mangle] -pub /*extern*/ fn unpack_point_internal(compressed_point: *const c_char) -> *mut c_char { - let compressed_point_str = unsafe { CStr::from_ptr(compressed_point) }.to_str().unwrap(); - let y_bytes_raw = compressed_point_str.from_hex().unwrap(); - let mut y_bytes: [u8; 32] = [0; 32]; - y_bytes.copy_from_slice(&y_bytes_raw); - let p = decompress_point(y_bytes).unwrap(); - let x_big = BigInt::parse_bytes(to_hex(&p.x).as_bytes(), 16).unwrap(); - let y_big = BigInt::parse_bytes(to_hex(&p.y).as_bytes(), 16).unwrap(); - let mut result_string: String = "".to_owned(); - result_string.push_str(&x_big.to_string()); - result_string.push_str(","); - result_string.push_str(&y_big.to_string()); - CString::new(result_string.as_str()).unwrap().into_raw() -} - -#[no_mangle] -pub extern fn unpack_point(compressed_point: *const c_char) -> *mut c_char { - let result = catch_unwind(|| unpack_point_internal(compressed_point)); - match result { - Ok(res) => res, - Err(e) => { - println!("unpack_point Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - -#[no_mangle] -pub /*extern*/ fn prv2pub_internal(private_key: *const c_char) -> *mut c_char { - /*let private_key_bytes: [u8; 32] = *array_ref!(private_key[..32], 0, 32); - let private_key = PrivateKey::import(private_key_bytes.to_vec()).unwrap();*/ - let private_key_str = unsafe { CStr::from_ptr(private_key) }.to_str().unwrap(); - //let pk_bigint = BigInt::from_str(private_key_str).unwrap(); - let pk_bytes_raw = private_key_str.from_hex().unwrap(); - let mut pk_bytes: [u8; 32] = [0; 32]; - pk_bytes.copy_from_slice(&pk_bytes_raw); - let pk = PrivateKey { key: pk_bytes }; - let public_key = pk.public(); - let mut result_string: String = "".to_owned(); - result_string.push_str(&public_key.x.to_string()); - result_string.push_str(","); - result_string.push_str(&public_key.y.to_string()); - CString::new(result_string.as_str()).unwrap().into_raw() -} - -#[no_mangle] -pub extern fn prv2pub(private_key: *const c_char) -> *mut c_char { - let result = catch_unwind(|| prv2pub_internal(private_key)); - match result { - Ok(res) => res, - Err(e) => { - println!("prv2pub Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - - -#[no_mangle] -pub /*extern*/ fn poseidon_hash_internal(input: *const c_char) -> *mut c_char { - - let input_str = unsafe { CStr::from_ptr(input) }.to_str().unwrap(); - let b0: Fr = Fr::from_str(input_str).unwrap(); - - let hm_input = vec![b0.clone()]; - //let hm_input = vec![x.clone(), y.clone(), z.clone()]; - let poseidon = Poseidon::new(); - let hm = poseidon.hash(hm_input).unwrap(); - //hm.to_string: Fr(0x29176100eaa962bdc1fe6c654d6a3c130e96a4d1168b33848b897dc502820133) - return CString::new(to_hex(&hm).as_str()).unwrap().into_raw(); - //return CString::new(hm.to_string()).unwrap().into_raw(); -} - -#[no_mangle] -pub extern fn poseidon_hash(input: *const c_char) -> *mut c_char { - let result = catch_unwind(|| poseidon_hash_internal(input)); - match result { - Ok(res) => res, - Err(e) => { - println!("poseidon_hash Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - -#[no_mangle] -pub extern "C" fn poseidon_hash2_internal(input1: *const c_char, input2: *const c_char) -> *mut c_char { - let input_str1 = unsafe { CStr::from_ptr(input1) }.to_str().unwrap(); - let input_str2 = unsafe { CStr::from_ptr(input2) }.to_str().unwrap(); - - let b1: Fr = Fr::from_str(input_str1).unwrap(); - let b2: Fr = Fr::from_str(input_str2).unwrap(); - - let hm_input = vec![b1.clone(), b2.clone()]; - - let poseidon = Poseidon::new(); - let hm = poseidon.hash(hm_input).unwrap(); - - return CString::new(to_hex(&hm).as_str()).unwrap().into_raw(); -} - -#[no_mangle] -pub extern "C" fn poseidon_hash2(input1: *const c_char, input2: *const c_char) -> *mut c_char { - let result = catch_unwind(|| poseidon_hash2_internal(input1, input2)); - match result { - Ok(res) => res, - Err(e) => { - println!("poseidon_hash2 Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - -#[no_mangle] -pub extern "C" fn poseidon_hash3_internal(input1: *const c_char, input2: *const c_char, input3: *const c_char) -> *mut c_char { - let input_str1 = unsafe { CStr::from_ptr(input1) }.to_str().unwrap(); - let input_str2 = unsafe { CStr::from_ptr(input2) }.to_str().unwrap(); - let input_str3 = unsafe { CStr::from_ptr(input3) }.to_str().unwrap(); - - let b1: Fr = Fr::from_str(input_str1).unwrap(); - let b2: Fr = Fr::from_str(input_str2).unwrap(); - let b3: Fr = Fr::from_str(input_str3).unwrap(); - - let hm_input = vec![b1.clone(), b2.clone(), b3.clone()]; - - let poseidon = Poseidon::new(); - let hm = poseidon.hash(hm_input).unwrap(); - - return CString::new(to_hex(&hm).as_str()).unwrap().into_raw(); -} - -#[no_mangle] -pub extern "C" fn poseidon_hash3(input1: *const c_char, input2: *const c_char, input3: *const c_char) -> *mut c_char { - let result = catch_unwind(|| poseidon_hash3_internal(input1, input2, input3)); - match result { - Ok(res) => res, - Err(e) => { - println!("poseidon_hash3 Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - -#[no_mangle] -pub extern "C" fn poseidon_hash4_internal(input1: *const c_char, input2: *const c_char, input3: *const c_char, input4: *const c_char) -> *mut c_char { - let input_str1 = unsafe { CStr::from_ptr(input1) }.to_str().unwrap(); - let input_str2 = unsafe { CStr::from_ptr(input2) }.to_str().unwrap(); - let input_str3 = unsafe { CStr::from_ptr(input3) }.to_str().unwrap(); - let input_str4 = unsafe { CStr::from_ptr(input4) }.to_str().unwrap(); - - let b1: Fr = Fr::from_str(input_str1).unwrap(); - let b2: Fr = Fr::from_str(input_str2).unwrap(); - let b3: Fr = Fr::from_str(input_str3).unwrap(); - let b4: Fr = Fr::from_str(input_str4).unwrap(); - - let hm_input = vec![b1.clone(), b2.clone(), b3.clone(), b4.clone()]; - - let poseidon = Poseidon::new(); - let hm = poseidon.hash(hm_input).unwrap(); - - return CString::new(to_hex(&hm).as_str()).unwrap().into_raw(); -} - -#[no_mangle] -pub extern "C" fn poseidon_hash4(input1: *const c_char, input2: *const c_char, input3: *const c_char, input4: *const c_char) -> *mut c_char { - let result = catch_unwind(|| poseidon_hash4_internal(input1, input2, input3, input4)); - match result { - Ok(res) => res, - Err(e) => { - println!("poseidon_hash4 Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - - -#[no_mangle] -//pub extern fn hash_poseidon(tx_compressed_data: *const c_char, to_eth_addr: *const c_char, to_bjj_ay: *const c_char, rq_txcompressed_data_v2: *const c_char, rq_to_eth_addr: *const c_char, rq_to_bjj_ay: *const c_char) -> *mut c_char { -pub /*extern*/ fn hash_poseidon_internal(claims_tree: *const c_char, revocation_tree: *const c_char, roots_tree_root: *const c_char) -> *mut c_char { - //let claims_tree_str = unsafe { CStr::from_ptr(claims_tree) }.to_str().unwrap(); - //let claims_tree_bigint = match claims_tree_str.parse::() { - // Ok(n) => BigInt::from(n), - // Err(e) => BigInt::zero(), - // }; - //let b0: Fr = Fr::from_str( - // &claims_tree_bigint.to_string(), - // ).unwrap(); - - //let revocation_tree_str = unsafe { CStr::from_ptr(revocation_tree) }.to_str().unwrap(); - //let revocation_tree_bigint = match revocation_tree_str.parse::() { - // Ok(n) => BigInt::from(n), - // Err(e) => BigInt::zero(), - // }; - //let b1: Fr = Fr::from_str( - // &revocation_tree_bigint.to_string(), - // ).unwrap(); - - //let roots_tree_root_str = unsafe { CStr::from_ptr(roots_tree_root) }.to_str().unwrap(); - // let roots_tree_root_bigint = match roots_tree_root_str.parse::() { - // Ok(n) => BigInt::from(n), - // Err(e) => BigInt::zero(), - // }; - // let b2: Fr = Fr::from_str( - // &roots_tree_root_bigint.to_string(), - // ).unwrap(); - - //let x: Fr = Fr::from_str( - // "4648350302718598839424502774166524253703556728225603109003078358379460427828", - // ).unwrap(); - //let x: Fr = Fr::from_str( - // "23520646440406697341854711669252473191475099932451150382882460752222516889098").unwrap(); - //let y: Fr = Fr::zero(); - //let z: Fr = Fr::zero(); - - let claims_tree_str = unsafe { CStr::from_ptr(claims_tree) }.to_str().unwrap(); - let b0: Fr = Fr::from_str(claims_tree_str).unwrap(); - - let revocation_tree_str = unsafe { CStr::from_ptr(revocation_tree) }.to_str().unwrap(); - let b1: Fr = Fr::from_str(revocation_tree_str).unwrap(); - - let roots_tree_root_str = unsafe { CStr::from_ptr(roots_tree_root) }.to_str().unwrap(); - let b2: Fr = Fr::from_str(roots_tree_root_str).unwrap(); - - //if to_eth_addr.is_null() { - // let to_eth_addr_str = unsafe { CStr::from_ptr(to_eth_addr) }.to_str().unwrap(); - // let b1: Fr = Fr::from_str(to_eth_addr_str).unwrap(); - // let mut b1_input = vec![b1.clone()]; - // hm_input.append(&mut b1_input); - //} - - //if to_bjj_ay.is_null() { - // let to_bjj_ay_str = unsafe { CStr::from_ptr(to_bjj_ay) }.to_str().unwrap(); - // let b2: Fr = Fr::from_str(to_bjj_ay_str).unwrap(); - // let mut b2_input = vec![b2.clone()]; - // hm_input.append(&mut b2_input); - //} - - //if rq_txcompressed_data_v2.is_null() { - // let rq_txcompressed_data_v2_str = unsafe { CStr::from_ptr(rq_txcompressed_data_v2) }.to_str().unwrap(); - // let b3: Fr = Fr::from_str(rq_txcompressed_data_v2_str).unwrap(); - // let mut b3_input = vec![b3.clone()]; - // hm_input.append(&mut b3_input); - //} - - //if rq_to_eth_addr.is_null() { - // let rq_to_eth_addr_str = unsafe { CStr::from_ptr(rq_to_eth_addr) }.to_str().unwrap(); - // let b4: Fr = Fr::from_str(rq_to_eth_addr_str).unwrap(); - // let mut b4_input = vec![b4.clone()]; - // hm_input.append(&mut b4_input); - //} - - //if rq_to_bjj_ay.is_null() { - // let rq_to_bjj_ay_str = unsafe { CStr::from_ptr(rq_to_bjj_ay) }.to_str().unwrap(); - // let b5: Fr = Fr::from_str(rq_to_bjj_ay_str).unwrap(); - // let mut b5_input = vec![b5.clone()]; - // hm_input.append(&mut b5_input); - //} - - let hm_input = vec![b0.clone(), b1.clone(), b2.clone()]; - //let hm_input = vec![x.clone(), y.clone(), z.clone()]; - let poseidon = Poseidon::new(); - let hm = poseidon.hash(hm_input).unwrap(); - return CString::new(to_hex(&hm).as_str()).unwrap().into_raw(); -} - - -#[no_mangle] -pub extern fn hash_poseidon(claims_tree: *const c_char, revocation_tree: *const c_char, roots_tree_root: *const c_char) -> *mut c_char { - let result = catch_unwind(|| hash_poseidon_internal(claims_tree, revocation_tree, roots_tree_root)); - match result { - Ok(res) => res, - Err(e) => { - println!("hash_poseidon Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - -#[no_mangle] -pub /*extern*/ fn sign_poseidon_internal(private_key: *const c_char, msg: *const c_char) -> *mut c_char { - let private_key_str = unsafe { CStr::from_ptr(private_key) }.to_str().unwrap(); - //let pk_bigint = BigInt::from_str(private_key_str).unwrap(); - let pk_bytes_raw = private_key_str.from_hex().unwrap(); - let mut pk_bytes: [u8; 32] = [0; 32]; - pk_bytes.copy_from_slice(&pk_bytes_raw); - let pk = PrivateKey { key: pk_bytes }; - let message_str = unsafe { CStr::from_ptr(msg) }.to_str().unwrap(); - let message_bigint = BigInt::from_str(message_str).unwrap(); - let sig = pk.sign(message_bigint.clone()).unwrap(); - let compressed_signature = sig.compress(); - let hex_string = compressed_signature.to_hex(); - CString::new(hex_string.as_str()).unwrap().into_raw() -} - -#[no_mangle] -pub extern fn sign_poseidon(private_key: *const c_char, msg: *const c_char) -> *mut c_char { - let result = catch_unwind(|| sign_poseidon_internal(private_key, msg)); - match result { - Ok(res) => res, - Err(e) => { - println!("sign_poseidon Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - -fn bytes_from_str(s: *const c_char) -> Result, String> { - if s.is_null() { - return Err("str pointer is null".to_owned()); - }; - let s = unsafe { CStr::from_ptr(s) }.to_str() - .map_err(|e| format!("utf8 string error: {}", e.to_string()))?; - s.from_hex().map_err(|e| format!("hex decode error: {}", e.to_string())) -} - -fn bigint_from_str(s: *const c_char) -> Result { - if s.is_null() { - return Err("str pointer is null".to_owned()); - }; - let s = unsafe { CStr::from_ptr(s) }.to_str() - .map_err(|e| format!("utf8 string error: {}", e.to_string()))?; - BigInt::from_str(s).map_err(|e| format!("bigint parse error: {}", e.to_string())) -} - -fn priv_key(private_key: *const c_char) -> Result { - let pk_bytes = bytes_from_str(private_key).map_err(|e| format!("private key error: {}", e))?; - Ok(PrivateKey { key: pk_bytes.try_into() - .map_err(|_| "private key should be exactly 32 bytes long".to_owned())? }) -} - -fn unpack_sig(compressed_signature: *const c_char) -> Result { - let signature_bytes = bytes_from_str(compressed_signature) - .map_err(|e| format!("signature error: {}", e.to_string()))?; - let signature_bytes: [u8; 64] = signature_bytes.try_into() - .map_err(|_| "signature should be exactly 64 bytes long".to_owned())?; - decompress_signature(&signature_bytes) -} - -#[no_mangle] -pub fn verify_poseidon_internal(private_key: *const c_char, compressed_signature: *const c_char, message: *const c_char) -> *mut c_char { - let pk = priv_key(private_key) - .unwrap_or_else(|err_msg| panic!("{}", err_msg)); - let sig = unpack_sig(compressed_signature) - .unwrap_or_else(|err_msg| panic!("{}", err_msg)); - let message_bigint = bigint_from_str(message) - .unwrap_or_else(|err_msg| panic!("message parse error: {}", err_msg)); - - if verify(pk.public(), sig, message_bigint) { - CString::new("1".to_owned()).unwrap().into_raw() - } else { - CString::new("0".to_owned()).unwrap().into_raw() - } -} - - -#[no_mangle] -pub extern fn verify_poseidon(private_key: *const c_char, compressed_signature: *const c_char, message: *const c_char) -> *mut c_char { - let result = catch_unwind(|| verify_poseidon_internal(private_key, compressed_signature, message)); - match result { - Ok(res) => res, - Err(e) => { - println!("verify_poseidon Rust Err: {:?}", e); - std::ptr::null_mut() - } - } -} - -#[no_mangle] -pub extern fn cstring_free(str: *mut c_char) { - unsafe { - if str.is_null() { return } - drop(CString::from_raw(str)); - }; -} - -#[cfg(test)] -mod tests { - use std::ptr::null; - use super::*; - - #[test] - #[should_panic(expected = "private key error: str pointer is null")] - fn test_verify_poseidon_internal_with_null_private_key_should_panic() { - verify_poseidon_internal(null(), null(), null()); - } - - #[test] - fn test_verify_poseidon_with_null_private_key_should_panic() { - let x = verify_poseidon(null(), null(), null()); - assert!(x.is_null()); - } - - #[test] - #[should_panic(expected = "private key error: hex decode error: Invalid character 'p' at position 0")] - fn test_verify_poseidon_internal_with_incorrect_hex_private_key_should_panic() { - let pk = CString::new("pk").unwrap(); - verify_poseidon_internal(pk.into_raw(), null(), null()); - } - - #[test] - #[should_panic(expected = "signature error: str pointer is null")] - fn test_verify_poseidon_null_sig() { - let pk = CString::new("459a964f864b613e0fae29bd5395cb7e5cb16d9501d898a5630d25dc56ab87aa").unwrap(); - let msg = CString::new("184467440737095516150").unwrap(); - verify_poseidon_internal(pk.into_raw(), null(), msg.into_raw()); - } - - #[test] - #[should_panic(expected = "message parse error: str pointer is null")] - fn test_verify_poseidon_null_msg() { - let pk = CString::new("459a964f864b613e0fae29bd5395cb7e5cb16d9501d898a5630d25dc56ab87aa").unwrap(); - let sig = CString::new("aac24e561679c387a075ea22a153d8d060ee751555da44484f96ef3721537c9cf436f9668439cc183382a0ec1445ca594c8b626041bba1c28870c318e41cb305").unwrap(); - verify_poseidon_internal(pk.into_raw(), sig.into_raw(), null()); - } - - #[test] - fn test_verify_poseidon_ok() { - let pk = CString::new("459a964f864b613e0fae29bd5395cb7e5cb16d9501d898a5630d25dc56ab87aa").unwrap(); - let sig = CString::new("aac24e561679c387a075ea22a153d8d060ee751555da44484f96ef3721537c9cf436f9668439cc183382a0ec1445ca594c8b626041bba1c28870c318e41cb305").unwrap(); - let msg = CString::new("184467440737095516150").unwrap(); - let r = verify_poseidon(pk.into_raw(), sig.into_raw(), msg.into_raw()); - - let r = unsafe { CStr::from_ptr(r) }.to_str().unwrap(); - assert_eq!(r, "1"); - } - - #[test] - fn test_verify_poseidon_invalid_sig() { - let pk = CString::new("459a964f864b613e0fae29bd5395cb7e5cb16d9501d898a5630d25dc56ab87aa").unwrap(); - let sig = CString::new("aac24e561679c387a075ea22a153d8d060ee751555da44484f96ef3721537c9cf436f9668439cc183382a0ec1445ca594c8b626041bba1c28870c318e41cb307").unwrap(); - let msg = CString::new("184467440737095516150").unwrap(); - let r = verify_poseidon(pk.into_raw(), sig.into_raw(), msg.into_raw()); - - let r = unsafe { CStr::from_ptr(r) }.to_str().unwrap(); - assert_eq!(r, "0"); - } - - #[test] - #[should_panic(expected = "message parse error: bigint parse error: invalid digit found in string")] - fn test_verify_poseidon_internal_invalid_msg() { - let pk = CString::new("459a964f864b613e0fae29bd5395cb7e5cb16d9501d898a5630d25dc56ab87aa").unwrap(); - let sig = CString::new("aac24e561679c387a075ea22a153d8d060ee751555da44484f96ef3721537c9cf436f9668439cc183382a0ec1445ca594c8b626041bba1c28870c318e41cb307").unwrap(); - let msg = CString::new("abc").unwrap(); - verify_poseidon_internal(pk.into_raw(), sig.into_raw(), msg.into_raw()); - } - - #[test] - #[should_panic(expected = "signature should be exactly 64 bytes long")] - fn test_verify_poseidon_internal_sig_len_error() { - let pk = CString::new("459a964f864b613e0fae29bd5395cb7e5cb16d9501d898a5630d25dc56ab87aa").unwrap(); - let sig = CString::new("aac24e561679c387a075ea22a153d8d060ee751555da44484f96ef3721537c9cf436f9668439cc183382a0ec1445ca594c8b626041bba1c28870c318e41cb3").unwrap(); - let msg = CString::new("abc").unwrap(); - verify_poseidon_internal(pk.into_raw(), sig.into_raw(), msg.into_raw()); - } - - #[test] - // #[should_panic(expected = "signature should be exactly 64 bytes long")] - fn test_verify_poseidon_sig_len_error() { - let pk = CString::new("459a964f864b613e0fae29bd5395cb7e5cb16d9501d898a5630d25dc56ab87aa").unwrap(); - let sig = CString::new("aac24e561679c387a075ea22a153d8d060ee751555da44484f96ef3721537c9cf436f9668439cc183382a0ec1445ca594c8b626041bba1c28870c318e41cb3").unwrap(); - let msg = CString::new("abc").unwrap(); - let r = verify_poseidon(pk.into_raw(), sig.into_raw(), msg.into_raw()); - assert_eq!(std::ptr::null_mut(), r); - } -} \ No newline at end of file From 0c736bd0281110996938c049571a2378528b9ad6 Mon Sep 17 00:00:00 2001 From: Yaroslav Moria <5eeman@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:51:07 +0100 Subject: [PATCH 2/2] Update polygonid_flutter_sdk.yml --- .github/workflows/polygonid_flutter_sdk.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/polygonid_flutter_sdk.yml b/.github/workflows/polygonid_flutter_sdk.yml index 88b4d1fac..4e9086973 100644 --- a/.github/workflows/polygonid_flutter_sdk.yml +++ b/.github/workflows/polygonid_flutter_sdk.yml @@ -50,9 +50,6 @@ jobs: - name: Run tests run: flutter test --coverage - - name: Run Rust library test - run: cd rust && cargo test - - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 with: