Skip to content

Commit

Permalink
Merge pull request #456 from 0xPolygonID/refactor/native_bjj_migration
Browse files Browse the repository at this point in the history
Native bjj migration
  • Loading branch information
5eeman authored Nov 12, 2024
2 parents 0cf0d88 + bc43744 commit 0b20e2b
Show file tree
Hide file tree
Showing 42 changed files with 1,248 additions and 562 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ post_install do |installer|
if target.name == "Pods-Runner"
puts "Updating #{target.name} OTHER_LDFLAGS"
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_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/libpolygonid.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libbabyjubjub.a"')
File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
end
end
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_credentialAtomicQueryMTPV2OnChain.a" -force_load "${PODS_ROOT}/../.symlinks/plugins/polygonid_flutter_sdk/ios/libwitnesscalc_credentialAtomicQuerySigV2OnChain.a"')
File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
end
end
end
end
```
Expand Down
31 changes: 0 additions & 31 deletions android/src/main/jniLibs/arm64-v8a/libbabyjubjub.h

This file was deleted.

Binary file removed android/src/main/jniLibs/arm64-v8a/libbabyjubjub.so
Binary file not shown.
11 changes: 11 additions & 0 deletions android/src/main/jniLibs/arm64-v8a/libpolygonid.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ extern GoUint8 PLGNAtomicQueryV3OnChainInputs(char** jsonResponse, char* in, cha
//
extern GoUint8 PLGNALinkedMultiQueryInputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern void PLGNFreeStatus(PLGNStatus* status);

// Deprecated: Use PLGNCleanCache2 instead. We need to support consistent path
// to the cache directory. This function supposed the cache directory is empty
// and should be calculated based on user's $HOME directory.
//
extern GoUint8 PLGNCleanCache(PLGNStatus** status);
extern GoUint8 PLGNCleanCache2(char* cfg, PLGNStatus** status);
extern GoUint8 PLGNCacheCredentials(char* in, char* cfg, PLGNStatus** status);

// PLGNW3CCredentialFromOnchainHex returns a verifiable credential from an onchain data hex string.
Expand Down Expand Up @@ -243,6 +249,11 @@ extern GoUint8 PLGNW3CCredentialFromOnchainHex(char** jsonResponse, char* in, ch
// }
//
extern GoUint8 PLGNDescribeID(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubSignPoseidon(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubVerifyPoseidon(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubPrivate2Public(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubPublicUncompress(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubPublicCompress(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);

#ifdef __cplusplus
}
Expand Down
Binary file modified android/src/main/jniLibs/arm64-v8a/libpolygonid.so
Binary file not shown.
11 changes: 11 additions & 0 deletions android/src/main/jniLibs/libpolygonid.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ extern GoUint8 PLGNAtomicQueryV3OnChainInputs(char** jsonResponse, char* in, cha
//
extern GoUint8 PLGNALinkedMultiQueryInputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern void PLGNFreeStatus(PLGNStatus* status);

// Deprecated: Use PLGNCleanCache2 instead. We need to support consistent path
// to the cache directory. This function supposed the cache directory is empty
// and should be calculated based on user's $HOME directory.
//
extern GoUint8 PLGNCleanCache(PLGNStatus** status);
extern GoUint8 PLGNCleanCache2(char* cfg, PLGNStatus** status);
extern GoUint8 PLGNCacheCredentials(char* in, char* cfg, PLGNStatus** status);

// PLGNW3CCredentialFromOnchainHex returns a verifiable credential from an onchain data hex string.
Expand Down Expand Up @@ -243,6 +249,11 @@ extern GoUint8 PLGNW3CCredentialFromOnchainHex(char** jsonResponse, char* in, ch
// }
//
extern GoUint8 PLGNDescribeID(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubSignPoseidon(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubVerifyPoseidon(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubPrivate2Public(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubPublicUncompress(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubPublicCompress(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);

#ifdef __cplusplus
}
Expand Down
27 changes: 0 additions & 27 deletions android/src/main/jniLibs/x86_64/libbabyjubjub.h

This file was deleted.

Binary file removed android/src/main/jniLibs/x86_64/libbabyjubjub.so
Binary file not shown.
11 changes: 11 additions & 0 deletions android/src/main/jniLibs/x86_64/libpolygonid.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ extern GoUint8 PLGNAtomicQueryV3OnChainInputs(char** jsonResponse, char* in, cha
//
extern GoUint8 PLGNALinkedMultiQueryInputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern void PLGNFreeStatus(PLGNStatus* status);

// Deprecated: Use PLGNCleanCache2 instead. We need to support consistent path
// to the cache directory. This function supposed the cache directory is empty
// and should be calculated based on user's $HOME directory.
//
extern GoUint8 PLGNCleanCache(PLGNStatus** status);
extern GoUint8 PLGNCleanCache2(char* cfg, PLGNStatus** status);
extern GoUint8 PLGNCacheCredentials(char* in, char* cfg, PLGNStatus** status);

// PLGNW3CCredentialFromOnchainHex returns a verifiable credential from an onchain data hex string.
Expand Down Expand Up @@ -243,6 +249,11 @@ extern GoUint8 PLGNW3CCredentialFromOnchainHex(char** jsonResponse, char* in, ch
// }
//
extern GoUint8 PLGNDescribeID(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubSignPoseidon(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubVerifyPoseidon(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubPrivate2Public(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubPublicUncompress(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);
extern GoUint8 PLGNBabyJubJubPublicCompress(char** jsonResponse, char* in, char* cfg, PLGNStatus** status);

#ifdef __cplusplus
}
Expand Down
Binary file modified android/src/main/jniLibs/x86_64/libpolygonid.so
Binary file not shown.
25 changes: 0 additions & 25 deletions example/android/app/src/main/cpp/wtns_utils.hpp

This file was deleted.

55 changes: 0 additions & 55 deletions example/android/app/src/main/cpp/zkey_utils.cpp

This file was deleted.

39 changes: 0 additions & 39 deletions example/android/app/src/main/cpp/zkey_utils.hpp

This file was deleted.

34 changes: 18 additions & 16 deletions example/integration_test/bjj_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ 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/domain/entities/env_config_entity.dart';
import 'package:polygonid_flutter_sdk/common/libs/polygonidcore/pidcore_base.dart';
import 'package:polygonid_flutter_sdk/common/utils/hex_utils.dart';
import 'package:polygonid_flutter_sdk/identity/libs/bjj/bjj.dart';

import 'polygonidcore_mocks.dart';

void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();

PolygonIdCore.setEnvConfig(EnvConfigEntity(ipfsNodeUrl: ""));

final lib = BabyjubjubLib();

group('Test point compress/uncompress', () {
Expand All @@ -22,7 +28,7 @@ void main() {
"6B58E72B1BB6DD8C2B20CB62E90F1AE7F7F054C059B962382643721B273B2510";

testWidgets('Compress point', (WidgetTester tester) async {
final compressedPoint = lib.packPoint(pointX, pointY);
final compressedPoint = lib.compressPoint(pointX, pointY);

expect(
compressedPoint,
Expand All @@ -31,10 +37,10 @@ void main() {
});

testWidgets('Uncompress point', (WidgetTester tester) async {
final uncompressedPoint = lib.unpackPoint(compressedPoint);
final uncompressedPoint = lib.uncompressPoint(compressedPoint);

expect(uncompressedPoint, isNotNull);
expect(uncompressedPoint![0], equals(pointX));
expect(uncompressedPoint[0], equals(pointX));
expect(uncompressedPoint[1], equals(pointY));
});
});
Expand All @@ -58,8 +64,10 @@ void main() {
});

testWidgets("Verify signature", (WidgetTester tester) async {
final publicKey = lib.prv2pub(privateKey);

final valid = lib.verifyPoseidon(
privateKey,
publicKey,
signature,
message,
);
Expand All @@ -78,18 +86,12 @@ void main() {
"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));
final publicKeyHex = lib.prv2pub(privateKey);

final points = lib.uncompressPoint(publicKeyHex);

expect(points[0], equals(expectedX));
expect(points[1], equals(expectedY));
});
});
}
23 changes: 0 additions & 23 deletions example/integration_test/circomlib_test.dart

This file was deleted.

Loading

0 comments on commit 0b20e2b

Please sign in to comment.