diff --git a/README.md b/README.md index 175a2675b..925da9a83 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/android/src/main/jniLibs/arm64-v8a/libbabyjubjub.h b/android/src/main/jniLibs/arm64-v8a/libbabyjubjub.h deleted file mode 100644 index 2bd9ed065..000000000 --- a/android/src/main/jniLibs/arm64-v8a/libbabyjubjub.h +++ /dev/null @@ -1,31 +0,0 @@ -// NOTE: Append the lines below to ios/Classes/Plugin.h - -char *pack_signature(const char *signature); - -char *unpack_signature(const char *compressed_signature); - -char *pack_point(const char *point_x, const char *point_y); - -char *unpack_point(const char *compressed_point); - -char *prv2pub(const char *private_key); - -char *poseidon_hash(const char *input); - -char *poseidon_hash2(const char *in1, const char *in2); - -char *poseidon_hash3(const char *in1, const char *in2, const char *in3); - -char *poseidon_hash4(const char *in1, const char *in2, const char *in3, const char *in4); - -char *hash_poseidon(const char *claims_tree, - const char *revocation_tree, - const char *roots_tree_root); - -char *sign_poseidon(const char *private_key, const char *msg); - -char *verify_poseidon(const char *private_key, - const char *compressed_signature, - const char *message); - -void cstring_free(char *str); diff --git a/android/src/main/jniLibs/arm64-v8a/libbabyjubjub.so b/android/src/main/jniLibs/arm64-v8a/libbabyjubjub.so deleted file mode 100755 index bb1f643a8..000000000 Binary files a/android/src/main/jniLibs/arm64-v8a/libbabyjubjub.so and /dev/null differ diff --git a/android/src/main/jniLibs/arm64-v8a/libpolygonid.h b/android/src/main/jniLibs/arm64-v8a/libpolygonid.h index 9a6e5ec6b..59f1ad4a3 100644 --- a/android/src/main/jniLibs/arm64-v8a/libpolygonid.h +++ b/android/src/main/jniLibs/arm64-v8a/libpolygonid.h @@ -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. @@ -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 } diff --git a/android/src/main/jniLibs/arm64-v8a/libpolygonid.so b/android/src/main/jniLibs/arm64-v8a/libpolygonid.so index 50eb11881..687009c55 100644 Binary files a/android/src/main/jniLibs/arm64-v8a/libpolygonid.so and b/android/src/main/jniLibs/arm64-v8a/libpolygonid.so differ diff --git a/android/src/main/jniLibs/libpolygonid.h b/android/src/main/jniLibs/libpolygonid.h index 9a6e5ec6b..59f1ad4a3 100644 --- a/android/src/main/jniLibs/libpolygonid.h +++ b/android/src/main/jniLibs/libpolygonid.h @@ -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. @@ -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 } diff --git a/android/src/main/jniLibs/x86_64/libbabyjubjub.h b/android/src/main/jniLibs/x86_64/libbabyjubjub.h deleted file mode 100644 index de3a8983b..000000000 --- a/android/src/main/jniLibs/x86_64/libbabyjubjub.h +++ /dev/null @@ -1,27 +0,0 @@ -// NOTE: Append the lines below to ios/Classes/Plugin.h - -char *pack_signature(const char *signature); - -char *unpack_signature(const char *compressed_signature); - -char *pack_point(const char *point_x, const char *point_y); - -char *unpack_point(const char *compressed_point); - -char *prv2pub(const char *private_key); - -char *poseidon_hash(const char *input); - -char *poseidon_hash2(const char *const *input); - -char *hash_poseidon(const char *claims_tree, - const char *revocation_tree, - const char *roots_tree_root); - -char *sign_poseidon(const char *private_key, const char *msg); - -char *verify_poseidon(const char *private_key, - const char *compressed_signature, - const char *message); - -void cstring_free(char *str); diff --git a/android/src/main/jniLibs/x86_64/libbabyjubjub.so b/android/src/main/jniLibs/x86_64/libbabyjubjub.so deleted file mode 100755 index bcab080c7..000000000 Binary files a/android/src/main/jniLibs/x86_64/libbabyjubjub.so and /dev/null differ diff --git a/android/src/main/jniLibs/x86_64/libpolygonid.h b/android/src/main/jniLibs/x86_64/libpolygonid.h index 9a6e5ec6b..59f1ad4a3 100644 --- a/android/src/main/jniLibs/x86_64/libpolygonid.h +++ b/android/src/main/jniLibs/x86_64/libpolygonid.h @@ -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. @@ -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 } diff --git a/android/src/main/jniLibs/x86_64/libpolygonid.so b/android/src/main/jniLibs/x86_64/libpolygonid.so index 15c1892db..d43e68bcf 100644 Binary files a/android/src/main/jniLibs/x86_64/libpolygonid.so and b/android/src/main/jniLibs/x86_64/libpolygonid.so differ diff --git a/example/android/app/src/main/cpp/wtns_utils.hpp b/example/android/app/src/main/cpp/wtns_utils.hpp deleted file mode 100644 index 70aebc294..000000000 --- a/example/android/app/src/main/cpp/wtns_utils.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef WTNS_UTILS -#define WTNS_UTILS - -#include - -#include "binfile_utils.hpp" - -namespace WtnsUtils { - - class Header { - public: - u_int32_t n8; - mpz_t prime; - - u_int32_t nVars; - - Header(); - ~Header(); - }; - - std::unique_ptr
loadHeader(BinFileUtils::BinFile *f); - -} - -#endif // ZKEY_UTILS_H \ No newline at end of file diff --git a/example/android/app/src/main/cpp/zkey_utils.cpp b/example/android/app/src/main/cpp/zkey_utils.cpp deleted file mode 100644 index a0477fa43..000000000 --- a/example/android/app/src/main/cpp/zkey_utils.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include - -#include "zkey_utils.hpp" - -namespace ZKeyUtils { - - -Header::Header() { -} - -Header::~Header() { - mpz_clear(qPrime); - mpz_clear(rPrime); -} - - -std::unique_ptr
loadHeader(BinFileUtils::BinFile *f) { - auto h = new Header(); - - f->startReadSection(1); - uint32_t protocol = f->readU32LE(); - if (protocol != 1) { - throw std::invalid_argument( "zkey file is not groth16" ); - } - f->endReadSection(); - - f->startReadSection(2); - - h->n8q = f->readU32LE(); - mpz_init(h->qPrime); - mpz_import(h->qPrime, h->n8q, -1, 1, -1, 0, f->read(h->n8q)); - - h->n8r = f->readU32LE(); - mpz_init(h->rPrime); - mpz_import(h->rPrime, h->n8r , -1, 1, -1, 0, f->read(h->n8r)); - - h->nVars = f->readU32LE(); - h->nPublic = f->readU32LE(); - h->domainSize = f->readU32LE(); - - h->vk_alpha1 = f->read(h->n8q*2); - h->vk_beta1 = f->read(h->n8q*2); - h->vk_beta2 = f->read(h->n8q*4); - h->vk_gamma2 = f->read(h->n8q*4); - h->vk_delta1 = f->read(h->n8q*2); - h->vk_delta2 = f->read(h->n8q*4); - f->endReadSection(); - - h->nCoefs = f->getSectionSize(4) / (12 + h->n8r); - - return std::unique_ptr
(h); -} - -} // namespace - diff --git a/example/android/app/src/main/cpp/zkey_utils.hpp b/example/android/app/src/main/cpp/zkey_utils.hpp deleted file mode 100644 index 5bd5e6734..000000000 --- a/example/android/app/src/main/cpp/zkey_utils.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef ZKEY_UTILS_H -#define ZKEY_UTILS_H - -#include -#include - -#include "binfile_utils.hpp" - -namespace ZKeyUtils { - - class Header { - - - public: - u_int32_t n8q; - mpz_t qPrime; - u_int32_t n8r; - mpz_t rPrime; - - u_int32_t nVars; - u_int32_t nPublic; - u_int32_t domainSize; - u_int64_t nCoefs; - - void *vk_alpha1; - void *vk_beta1; - void *vk_beta2; - void *vk_gamma2; - void *vk_delta1; - void *vk_delta2; - - Header(); - ~Header(); - }; - - std::unique_ptr
loadHeader(BinFileUtils::BinFile *f); -} - -#endif // ZKEY_UTILS_H diff --git a/example/integration_test/bjj_test.dart b/example/integration_test/bjj_test.dart index 5071e1fc9..ac0426d60 100644 --- a/example/integration_test/bjj_test.dart +++ b/example/integration_test/bjj_test.dart @@ -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', () { @@ -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, @@ -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)); }); }); @@ -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, ); @@ -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)); }); }); } diff --git a/example/integration_test/circomlib_test.dart b/example/integration_test/circomlib_test.dart deleted file mode 100644 index 82f79df56..000000000 --- a/example/integration_test/circomlib_test.dart +++ /dev/null @@ -1,23 +0,0 @@ -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'; - -void main() { - final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - - group('Test circomlib functions', () { - testWidgets('Can instantiate Pack Signature', (WidgetTester tester) async { - final bjjLib = Platform.isAndroid - ? DynamicLibrary.open("libbabyjubjub.so") - : DynamicLibrary.process(); - final packSignature = bjjLib.lookupFunction< - Pointer Function(Pointer packSignature), - Pointer Function( - Pointer packSignature)>('pack_signature'); - expect(packSignature, isA()); - }); - }); -} diff --git a/example/integration_test/libpolygonid_test.dart b/example/integration_test/libpolygonid_test.dart index 387134730..1d0427bac 100644 --- a/example/integration_test/libpolygonid_test.dart +++ b/example/integration_test/libpolygonid_test.dart @@ -84,80 +84,4 @@ void main() { ); }); }); - - group('Test polygonId core lib iden3comm functions', () { - final pidCoreIden3comm = PolygonIdCoreIden3comm(stacktraceManager); - - testWidgets('PolygonIdCoreIdentity get Auth Inputs', - (WidgetTester tester) async { - expect( - pidCoreIden3comm.getAuthInputs(PolygonIdCoreMocks.authV2InputJson), - equals(PolygonIdCoreMocks.authV2OutputJson), - ); - }); - }); - - group('Test polygonId core lib proof functions', () { - final pidCoreProof = PolygonIdCoreProof(stacktraceManager); - - testWidgets('PolygonIdCoreIdentity get sig proofs inputs', - (WidgetTester tester) async { - var result = pidCoreProof.getSigProofInputs( - PolygonIdCoreMocks.sigV2InputJson, - PolygonIdCoreMocks.sigV2InputConfigJson, - ); - var resultJson = jsonDecode(result) as Map; - resultJson['inputs'].remove('timestamp'); - expect( - jsonEncode(resultJson), - equals(PolygonIdCoreMocks.sigV2OutputJson), - ); - }); - - testWidgets('PolygonIdCoreIdentity proof from smart contract', - (WidgetTester tester) async { - expect( - 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, - 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, - 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, - PolygonIdCoreMocks.sigV2InputConfigJson, - ), - equals(PolygonIdCoreMocks.mtpV2OnChainOutputJson), - ); - }); - }); } diff --git a/example/ios/Podfile b/example/ios/Podfile index b3d587c84..a2de91bfc 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -40,6 +40,7 @@ end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) + # polygonid-setup target.build_configurations.each do |config| cflags = config.build_settings['OTHER_CFLAGS'] || ['$(inherited)'] @@ -48,16 +49,20 @@ post_install do |installer| config.build_settings['SWIFT_VERSION'] = '5.0' config.build_settings['ENABLE_BITCODE'] = 'NO' config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0' - config.build_settings['STRIP_STYLE'] = 'non-global' + config.build_settings['DEAD_CODE_STRIPPING'] = 'NO' end + 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/libpolygonid.a" -lc++ -lz') - File.open(xcconfig_path, "w") { |file| file << new_xcconfig } + if (config.base_configuration_reference != nil) + xcconfig_path = config.base_configuration_reference.real_path + xcconfig = File.read(xcconfig_path) + new_xcconfig = xcconfig.sub('OTHER_LDFLAGS = $(inherited)', 'OTHER_LDFLAGS = $(inherited) -lc++ -lz') + File.open(xcconfig_path, "w") { |file| file << new_xcconfig } + end end end + end end diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock new file mode 100644 index 000000000..683f8f2e0 --- /dev/null +++ b/example/ios/Podfile.lock @@ -0,0 +1,189 @@ +PODS: + - background_downloader (0.0.1): + - Flutter + - camera_avfoundation (0.0.1): + - Flutter + - CryptoSwift (1.8.3) + - Flutter (1.0.0) + - flutter_rapidsnark (0.0.1): + - Flutter + - rapidsnark (= 0.0.1-alpha.5) + - flutter_secure_storage (6.0.0): + - Flutter + - google_mlkit_barcode_scanning (0.7.0): + - Flutter + - google_mlkit_commons + - GoogleMLKit/BarcodeScanning (~> 4.0.0) + - google_mlkit_commons (0.4.0): + - Flutter + - MLKitVision + - GoogleDataTransport (9.4.1): + - GoogleUtilities/Environment (~> 7.7) + - nanopb (< 2.30911.0, >= 2.30908.0) + - PromisesObjC (< 3.0, >= 1.2) + - GoogleMLKit/BarcodeScanning (4.0.0): + - GoogleMLKit/MLKitCore + - MLKitBarcodeScanning (~> 3.0.0) + - GoogleMLKit/MLKitCore (4.0.0): + - MLKitCommon (~> 9.0.0) + - GoogleToolboxForMac/DebugUtils (2.3.2): + - GoogleToolboxForMac/Defines (= 2.3.2) + - GoogleToolboxForMac/Defines (2.3.2) + - GoogleToolboxForMac/Logger (2.3.2): + - GoogleToolboxForMac/Defines (= 2.3.2) + - "GoogleToolboxForMac/NSData+zlib (2.3.2)": + - GoogleToolboxForMac/Defines (= 2.3.2) + - "GoogleToolboxForMac/NSDictionary+URLArguments (2.3.2)": + - GoogleToolboxForMac/DebugUtils (= 2.3.2) + - GoogleToolboxForMac/Defines (= 2.3.2) + - "GoogleToolboxForMac/NSString+URLArguments (= 2.3.2)" + - "GoogleToolboxForMac/NSString+URLArguments (2.3.2)" + - GoogleUtilities/Environment (7.13.3): + - GoogleUtilities/Privacy + - PromisesObjC (< 3.0, >= 1.2) + - GoogleUtilities/Logger (7.13.3): + - GoogleUtilities/Environment + - GoogleUtilities/Privacy + - GoogleUtilities/Privacy (7.13.3) + - GoogleUtilities/UserDefaults (7.13.3): + - GoogleUtilities/Logger + - GoogleUtilities/Privacy + - GoogleUtilitiesComponents (1.1.0): + - GoogleUtilities/Logger + - GTMSessionFetcher/Core (2.3.0) + - image_picker_ios (0.0.1): + - Flutter + - integration_test (0.0.1): + - Flutter + - MLImage (1.0.0-beta4) + - MLKitBarcodeScanning (3.0.0): + - MLKitCommon (~> 9.0) + - MLKitVision (~> 5.0) + - MLKitCommon (9.0.0): + - GoogleDataTransport (~> 9.0) + - GoogleToolboxForMac/Logger (~> 2.1) + - "GoogleToolboxForMac/NSData+zlib (~> 2.1)" + - "GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)" + - GoogleUtilities/UserDefaults (~> 7.0) + - GoogleUtilitiesComponents (~> 1.0) + - GTMSessionFetcher/Core (< 3.0, >= 1.1) + - MLKitVision (5.0.0): + - GoogleToolboxForMac/Logger (~> 2.1) + - "GoogleToolboxForMac/NSData+zlib (~> 2.1)" + - GTMSessionFetcher/Core (< 3.0, >= 1.1) + - MLImage (= 1.0.0-beta4) + - MLKitCommon (~> 9.0) + - nanopb (2.30910.0): + - nanopb/decode (= 2.30910.0) + - nanopb/encode (= 2.30910.0) + - nanopb/decode (2.30910.0) + - nanopb/encode (2.30910.0) + - package_info_plus (0.4.5): + - Flutter + - path_provider_foundation (0.0.1): + - Flutter + - FlutterMacOS + - polygonid_flutter_sdk (2.3.6): + - CryptoSwift + - Flutter + - PromisesObjC (2.4.0) + - rapidsnark (0.0.1-alpha.5): + - rapidsnark/rapidsnark (= 0.0.1-alpha.5) + - rapidsnark/C (0.0.1-alpha.5) + - rapidsnark/rapidsnark (0.0.1-alpha.5): + - rapidsnark/C + - scan (0.0.1): + - Flutter + +DEPENDENCIES: + - background_downloader (from `.symlinks/plugins/background_downloader/ios`) + - camera_avfoundation (from `.symlinks/plugins/camera_avfoundation/ios`) + - Flutter (from `Flutter`) + - flutter_rapidsnark (from `.symlinks/plugins/flutter_rapidsnark/ios`) + - flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`) + - google_mlkit_barcode_scanning (from `.symlinks/plugins/google_mlkit_barcode_scanning/ios`) + - google_mlkit_commons (from `.symlinks/plugins/google_mlkit_commons/ios`) + - image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`) + - integration_test (from `.symlinks/plugins/integration_test/ios`) + - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) + - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) + - polygonid_flutter_sdk (from `.symlinks/plugins/polygonid_flutter_sdk/ios`) + - scan (from `.symlinks/plugins/scan/ios`) + +SPEC REPOS: + trunk: + - CryptoSwift + - GoogleDataTransport + - GoogleMLKit + - GoogleToolboxForMac + - GoogleUtilities + - GoogleUtilitiesComponents + - GTMSessionFetcher + - MLImage + - MLKitBarcodeScanning + - MLKitCommon + - MLKitVision + - nanopb + - PromisesObjC + - rapidsnark + +EXTERNAL SOURCES: + background_downloader: + :path: ".symlinks/plugins/background_downloader/ios" + camera_avfoundation: + :path: ".symlinks/plugins/camera_avfoundation/ios" + Flutter: + :path: Flutter + flutter_rapidsnark: + :path: ".symlinks/plugins/flutter_rapidsnark/ios" + flutter_secure_storage: + :path: ".symlinks/plugins/flutter_secure_storage/ios" + google_mlkit_barcode_scanning: + :path: ".symlinks/plugins/google_mlkit_barcode_scanning/ios" + google_mlkit_commons: + :path: ".symlinks/plugins/google_mlkit_commons/ios" + image_picker_ios: + :path: ".symlinks/plugins/image_picker_ios/ios" + integration_test: + :path: ".symlinks/plugins/integration_test/ios" + package_info_plus: + :path: ".symlinks/plugins/package_info_plus/ios" + path_provider_foundation: + :path: ".symlinks/plugins/path_provider_foundation/darwin" + polygonid_flutter_sdk: + :path: ".symlinks/plugins/polygonid_flutter_sdk/ios" + scan: + :path: ".symlinks/plugins/scan/ios" + +SPEC CHECKSUMS: + background_downloader: 9f788ffc5de45acf87d6380e91ca0841066c18cf + camera_avfoundation: dd002b0330f4981e1bbcb46ae9b62829237459a4 + CryptoSwift: 967f37cea5a3294d9cce358f78861652155be483 + Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 + flutter_rapidsnark: ded255c197aac9911fa75822447486eced081719 + flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be + google_mlkit_barcode_scanning: ec351dc4eeea0e004996607817b75a0b9fd278ba + google_mlkit_commons: 26607e403b3301ec966e578a308c98c6ac3e9477 + GoogleDataTransport: 6c09b596d841063d76d4288cc2d2f42cc36e1e2a + GoogleMLKit: 2bd0dc6253c4d4f227aad460f69215a504b2980e + GoogleToolboxForMac: 8bef7c7c5cf7291c687cf5354f39f9db6399ad34 + GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15 + GoogleUtilitiesComponents: 679b2c881db3b615a2777504623df6122dd20afe + GTMSessionFetcher: 3a63d75eecd6aa32c2fc79f578064e1214dfdec2 + image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1 + integration_test: 252f60fa39af5e17c3aa9899d35d908a0721b573 + MLImage: 7bb7c4264164ade9bf64f679b40fb29c8f33ee9b + MLKitBarcodeScanning: 04e264482c5f3810cb89ebc134ef6b61e67db505 + MLKitCommon: c1b791c3e667091918d91bda4bba69a91011e390 + MLKitVision: 8baa5f46ee3352614169b85250574fde38c36f49 + nanopb: 438bc412db1928dac798aa6fd75726007be04262 + package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c + path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 + polygonid_flutter_sdk: cb3414f867f0080e6170cfdbb8c29c65956e37ad + PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47 + rapidsnark: 4e70fa2f70e3b0846a0c1bf94a635113f261ada9 + scan: aea35bb4aa59ccc8839c576a18cd57c7d492cc86 + +PODFILE CHECKSUM: b9df976ea8a0f3dd60817c9e699f66bc8808062e + +COCOAPODS: 1.15.2 diff --git a/example/lib/src/presentation/ui/splash/splash_bloc.dart b/example/lib/src/presentation/ui/splash/splash_bloc.dart index e54c4c7c2..9defae21a 100644 --- a/example/lib/src/presentation/ui/splash/splash_bloc.dart +++ b/example/lib/src/presentation/ui/splash/splash_bloc.dart @@ -23,14 +23,8 @@ class SplashBloc extends Bloc { PolygonIdSdk.I.proof.initCircuitsDownloadAndGetInfoStream( circuitsToDownload: [ CircuitsToDownloadParam( - circuitsName: "circuitsV2", - bucketUrl: - "https://circuits.polygonid.me/circuits/v1.0.0/polygonid-keys.zip", - ), - CircuitsToDownloadParam( - circuitsName: "circuitsV3", - bucketUrl: - "https://iden3-circuits-bucket.s3.eu-west-1.amazonaws.com/circuitsv3-beta-1-1.zip", + circuitsName: "circuits", + bucketUrl: "https://circuits.privado.id/v1.0.1/keys.zip", ), ], ); diff --git a/ios/Classes/PolygonIdSdkPlugin.h b/ios/Classes/PolygonIdSdkPlugin.h index fcaaa23e6..e6bf601f3 100644 --- a/ios/Classes/PolygonIdSdkPlugin.h +++ b/ios/Classes/PolygonIdSdkPlugin.h @@ -1,5 +1,5 @@ #import -#import "libbabyjubjub.h" +#import "libpolygonid.h" @interface PolygonIdSdkPlugin : NSObject @end diff --git a/ios/Classes/SwiftPolygonIdSdkPlugin.swift b/ios/Classes/SwiftPolygonIdSdkPlugin.swift index 1e9c8f459..d4855ef0c 100644 --- a/ios/Classes/SwiftPolygonIdSdkPlugin.swift +++ b/ios/Classes/SwiftPolygonIdSdkPlugin.swift @@ -14,19 +14,11 @@ public class SwiftPolygonIdSdkPlugin: NSObject, FlutterPlugin { } public static func dummyMethodToEnforceBundling() { - // LibBabyjubjub bindings - pack_point("17777552123799933955779906779655732241715742912184938656739573121738514868268", "2626589144620713026669568689430873010625803728049924121243784502389097019475"); - unpack_point("53b81ed5bffe9545b54016234682e7b2f699bd42a5e9eae27ff4051bc698ce85"); - prv2pub("0001020304050607080900010203040506070809000102030405060708090001"); - sign_poseidon("", ""); - verify_poseidon("", "", ""); - let str = "string" - let unsafePointer = UnsafeMutablePointer(mutating: (str as NSString).utf8String) - cstring_free(unsafePointer); - - // LibPolygonid bindings + // libpolygonid bindings PLGNAuthV2InputsMarshal(nil, nil, nil); PLGNCalculateGenesisID(nil, nil, nil); + PLGNNewGenesisID(nil, nil, nil, nil); + PLGNNewGenesisIDFromEth(nil, nil, nil, nil); PLGNCreateClaim(nil, nil, nil); PLGNIDToInt(nil, nil, nil); PLGNProofFromSmartContract(nil, nil, nil); @@ -37,7 +29,23 @@ public class SwiftPolygonIdSdkPlugin: NSObject, FlutterPlugin { PLGNMtpV2Inputs(nil, nil, nil); PLGNAtomicQuerySigV2OnChainInputs(nil, nil, nil, nil); PLGNAtomicQueryMtpV2OnChainInputs(nil, nil, nil, nil); + PLGNAtomicQueryV3Inputs(nil, nil, nil, nil); + PLGNAtomicQueryV3OnChainInputs(nil, nil, nil, nil); + PLGNALinkedMultiQueryInputs(nil, nil, nil, nil); PLGNFreeStatus(nil); + + PLGNCleanCache(nil); + PLGNCleanCache2(nil, nil); + PLGNCacheCredentials(nil, nil, nil); + + PLGNW3CCredentialFromOnchainHex(nil, nil, nil, nil); + + PLGNDescribeID(nil, nil, nil, nil); + PLGNBabyJubJubSignPoseidon(nil, nil, nil, nil); + PLGNBabyJubJubVerifyPoseidon(nil, nil, nil, nil); + PLGNBabyJubJubPrivate2Public(nil, nil, nil, nil); + PLGNBabyJubJubPublicUncompress(nil, nil, nil, nil); + PLGNBabyJubJubPublicCompress(nil, nil, nil, nil); // witnesscalc authv2 bindings witnesscalc_authV2(nil, 0, nil, 0, nil, nil, nil, 0); diff --git a/ios/Classes/libbabyjubjub.h b/ios/Classes/libbabyjubjub.h deleted file mode 100644 index 96948e065..000000000 --- a/ios/Classes/libbabyjubjub.h +++ /dev/null @@ -1,15 +0,0 @@ -// NOTE: Append the lines below to ios/Classes/Plugin.h - -char *pack_point(const char *point_x, const char *point_y); - -char *unpack_point(const char *compressed_point); - -char *prv2pub(const char *private_key); - -char *sign_poseidon(const char *private_key, const char *msg); - -char *verify_poseidon(const char *private_key, - const char *compressed_signature, - const char *message); - -void cstring_free(char *str); \ No newline at end of file diff --git a/ios/Frameworks/libpolygonid.xcframework/Info.plist b/ios/Frameworks/libpolygonid.xcframework/Info.plist new file mode 100644 index 000000000..7b995570c --- /dev/null +++ b/ios/Frameworks/libpolygonid.xcframework/Info.plist @@ -0,0 +1,47 @@ + + + + + AvailableLibraries + + + BinaryPath + libpolygonid.a + HeadersPath + Headers + LibraryIdentifier + ios-arm64 + LibraryPath + libpolygonid.a + SupportedArchitectures + + arm64 + + SupportedPlatform + ios + + + BinaryPath + libpolygonid.a + HeadersPath + Headers + LibraryIdentifier + ios-arm64-simulator + LibraryPath + libpolygonid.a + SupportedArchitectures + + arm64 + + SupportedPlatform + ios + SupportedPlatformVariant + simulator + + + CFBundlePackageType + XFWK + XCFrameworkFormatVersion + 1.0 + + diff --git a/ios/Classes/libpolygonid.h b/ios/Frameworks/libpolygonid.xcframework/ios-arm64-simulator/Headers/libpolygonid.h similarity index 91% rename from ios/Classes/libpolygonid.h rename to ios/Frameworks/libpolygonid.xcframework/ios-arm64-simulator/Headers/libpolygonid.h index 9a6e5ec6b..59f1ad4a3 100644 --- a/ios/Classes/libpolygonid.h +++ b/ios/Frameworks/libpolygonid.xcframework/ios-arm64-simulator/Headers/libpolygonid.h @@ -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. @@ -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 } diff --git a/ios/libpolygonid-ios-simulator-arm64.a b/ios/Frameworks/libpolygonid.xcframework/ios-arm64-simulator/libpolygonid.a similarity index 78% rename from ios/libpolygonid-ios-simulator-arm64.a rename to ios/Frameworks/libpolygonid.xcframework/ios-arm64-simulator/libpolygonid.a index 9f547ef14..29e06571d 100644 Binary files a/ios/libpolygonid-ios-simulator-arm64.a and b/ios/Frameworks/libpolygonid.xcframework/ios-arm64-simulator/libpolygonid.a differ diff --git a/ios/Frameworks/libpolygonid.xcframework/ios-arm64/Headers/libpolygonid.h b/ios/Frameworks/libpolygonid.xcframework/ios-arm64/Headers/libpolygonid.h new file mode 100644 index 000000000..59f1ad4a3 --- /dev/null +++ b/ios/Frameworks/libpolygonid.xcframework/ios-arm64/Headers/libpolygonid.h @@ -0,0 +1,260 @@ +/* Code generated by cmd/cgo; DO NOT EDIT. */ + +/* package github.com/0xPolygonID/c-polygonid/cmd/polygonid */ + + +#line 1 "cgo-builtin-export-prolog" + +#include + +#ifndef GO_CGO_EXPORT_PROLOGUE_H +#define GO_CGO_EXPORT_PROLOGUE_H + +#ifndef GO_CGO_GOSTRING_TYPEDEF +typedef struct { const char *p; ptrdiff_t n; } _GoString_; +#endif + +#endif + +/* Start of preamble from import "C" comments. */ + + +#line 3 "polygonid.go" + +#include +#include + +typedef enum +{ + PLGNSTATUSCODE_ERROR, + PLGNSTATUSCODE_NIL_POINTER, + // error extracting credential status from verifiable credential + PLGNSTATUSCODE_USER_CREDENTIAL_STATUS_EXTRACTION_ERROR, + // error resolving credential status (e.g. getting the status from chain of DHS) + PLGNSTATUSCODE_USER_CREDENTIAL_STATUS_RESOLVE_ERROR, + // error getting merkletree proof from credential status + PLGNSTATUSCODE_USER_CREDENTIAL_STATUS_MT_BUILD_ERROR, + // merkletree proof is invalid + PLGNSTATUSCODE_USER_CREDENTIAL_STATUS_MT_STATE_ERROR, + // credential is revoked + PLGNSTATUSCODE_USER_CREDENTIAL_STATUS_REVOKED_ERROR, + // the same as above but for issuer credential (for signature proofs) + PLGNSTATUSCODE_ISSUER_CREDENTIAL_STATUS_EXTRACTION_ERROR, + PLGNSTATUSCODE_ISSUER_CREDENTIAL_STATUS_RESOLVE_ERROR, + PLGNSTATUSCODE_ISSUER_CREDENTIAL_STATUS_MT_BUILD_ERROR, + PLGNSTATUSCODE_ISSUER_CREDENTIAL_STATUS_MT_STATE_ERROR, + PLGNSTATUSCODE_ISSUER_CREDENTIAL_STATUS_REVOKED_ERROR, +} PLGNStatusCode; + +typedef struct _PLGNStatus +{ + PLGNStatusCode status; + char *error_msg; +} PLGNStatus; + +#line 1 "cgo-generated-wrapper" + + +/* End of preamble from import "C" comments. */ + + +/* Start of boilerplate cgo prologue. */ +#line 1 "cgo-gcc-export-header-prolog" + +#ifndef GO_CGO_PROLOGUE_H +#define GO_CGO_PROLOGUE_H + +typedef signed char GoInt8; +typedef unsigned char GoUint8; +typedef short GoInt16; +typedef unsigned short GoUint16; +typedef int GoInt32; +typedef unsigned int GoUint32; +typedef long long GoInt64; +typedef unsigned long long GoUint64; +typedef GoInt64 GoInt; +typedef GoUint64 GoUint; +typedef size_t GoUintptr; +typedef float GoFloat32; +typedef double GoFloat64; +#ifdef _MSC_VER +#include +typedef _Fcomplex GoComplex64; +typedef _Dcomplex GoComplex128; +#else +typedef float _Complex GoComplex64; +typedef double _Complex GoComplex128; +#endif + +/* + static assertion to make sure the file is being used on architecture + at least with matching size of GoInt. +*/ +typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; + +#ifndef GO_CGO_GOSTRING_TYPEDEF +typedef _GoString_ GoString; +#endif +typedef void *GoMap; +typedef void *GoChan; +typedef struct { void *t; void *v; } GoInterface; +typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; + +#endif + +/* End of boilerplate cgo prologue. */ + +#ifdef __cplusplus +extern "C" { +#endif + +extern GoUint8 PLGNAuthV2InputsMarshal(char** jsonResponse, char* in, PLGNStatus** status); + +// Deprecated: Use PLGNNewGenesisID instead. It supports environment +// configuration, giving the ability to register custom DID methods. +// +extern GoUint8 PLGNCalculateGenesisID(char** jsonResponse, char* in, PLGNStatus** status); +extern GoUint8 PLGNNewGenesisID(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); +extern GoUint8 PLGNNewGenesisIDFromEth(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); +extern GoUint8 PLGNCreateClaim(char** jsonResponse, char* in, PLGNStatus** status); + +// PLGNIDToInt returns the ID as a big int string +// Input should be a valid JSON object: string enclosed by double quotes. +// Output is a valid JSON object to: string enclosed by double quotes. +// +extern GoUint8 PLGNIDToInt(char** jsonResponse, char* in, PLGNStatus** status); +extern GoUint8 PLGNProofFromSmartContract(char** jsonResponse, char* in, PLGNStatus** status); +extern GoUint8 PLGNProfileID(char** jsonResponse, char* in, PLGNStatus** status); + +// PLGNAtomicQuerySigV2Inputs returns the inputs for the +// credentialAtomicQuerySigV2 with optional selective disclosure. +// +// Additional configuration may be required for Reverse Hash Service +// revocation validation. In other case cfg may be nil. +// +// The configuration example may be found in the [README.md] file. +// +// [README.md]: https://github.com/0xPolygonID/c-polygonid/blob/main/README.md#configuration +// +extern GoUint8 PLGNAtomicQuerySigV2Inputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNSigV2Inputs returns the inputs for the Sig circuit v2 with +// optional selective disclosure. +// +// Deprecated: Does not support Reverse Hash Service credential status +// validation! Use PLGNAtomicQuerySigV2Inputs method with configuration instead. +// +extern GoUint8 PLGNSigV2Inputs(char** jsonResponse, char* in, PLGNStatus** status); + +// PLGNAtomicQueryMtpV2Inputs returns the inputs for the +// credentialAtomicQueryMTPV2 with optional selective disclosure. +// +// Additional configuration may be required for Reverse Hash Service +// revocation validation. In other case cfg may be nil. +// +// The configuration example may be found in the [README.md] file. +// +// [README.md]: https://github.com/0xPolygonID/c-polygonid/blob/main/README.md#configuration +// +extern GoUint8 PLGNAtomicQueryMtpV2Inputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNMtpV2Inputs returns the inputs for the MTP circuit v2 with +// optional selective disclosure. +// +// Deprecated: Does not support Reverse Hash Service credential status +// validation! Use PLGNAtomicQueryMtpV2Inputs method with configuration instead. +// +extern GoUint8 PLGNMtpV2Inputs(char** jsonResponse, char* in, PLGNStatus** status); + +// PLGNAtomicQuerySigV2OnChainInputs returns the inputs for the +// credentialAtomicQuerySigV2OnChain circuit with optional selective disclosure. +// +// Additional configuration may be required for Reverse Hash Service +// revocation validation. In other case cfg may be nil. +// +// The configuration example may be found in the [README.md] file. +// +// [README.md]: https://github.com/0xPolygonID/c-polygonid/blob/main/README.md#configuration +// +extern GoUint8 PLGNAtomicQuerySigV2OnChainInputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNAtomicQueryMtpV2OnChainInputs returns the inputs for the +// credentialAtomicQueryMTPV2OnChain circuit with optional selective disclosure. +// +// Additional configuration may be required for Reverse Hash Service +// revocation validation. In other case cfg may be nil. +// +// The configuration example may be found in the [README.md] file. +// +// [README.md]: https://github.com/0xPolygonID/c-polygonid/blob/main/README.md#configuration +// +extern GoUint8 PLGNAtomicQueryMtpV2OnChainInputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNAtomicQueryV3Inputs returns the inputs for the credentialAtomicQueryV3 +// circuit with optional selective disclosure. +// +extern GoUint8 PLGNAtomicQueryV3Inputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNAtomicQueryV3OnChainInputs returns the inputs for the +// credentialAtomicQueryV3OnChain circuit with optional selective disclosure. +// +extern GoUint8 PLGNAtomicQueryV3OnChainInputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNALinkedMultiQueryInputs returns the inputs for the +// linkedMultiQuery10-beta.1 circuit. +// +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. +// +// Sample input: +// +// { +// "issuerDID": "did:polygonid:polygon:mumbai:2qCU58EJgrEMJvPfhUCnFCwuKQTkX8VmJX2sJCH6C8", +// "hexdata": "0x0...", +// "version": "0.0.1" +// } +// +// The configuration example may be found in the [README.md] file. +// +// [README.md]: https://github.com/0xPolygonID/c-polygonid/blob/main/README.md#configuration +// +extern GoUint8 PLGNW3CCredentialFromOnchainHex(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNDescribeID parses ID and return it in different representations. +// Request example: +// +// {"id":"31Akw5AB2xBrwqmbDUA2XoSGCfTepz52q9jmFE4mXA"} +// +// {"idAsInt":"24460059377712687587111979692736628604804094576108957842967948238113620738"} +// +// There is possible to pass both id & idAsInt fields in the request. But if the +// resulted ID would not be equal, error returns. +// +// Response example: +// +// { +// "did": "did:polygonid:linea:testnet:31Akw5AB2xBrwqmbDUA2XoSGCfTepz52q9jmFE4mXA", +// "id": "31Akw5AB2xBrwqmbDUA2XoSGCfTepz52q9jmFE4mXA", +// "idAsInt": "24460059377712687587111979692736628604804094576108957842967948238113620738", +// } +// +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 +} +#endif diff --git a/ios/libpolygonid-ios.a b/ios/Frameworks/libpolygonid.xcframework/ios-arm64/libpolygonid.a similarity index 78% rename from ios/libpolygonid-ios.a rename to ios/Frameworks/libpolygonid.xcframework/ios-arm64/libpolygonid.a index d005e58a3..db220928a 100644 Binary files a/ios/libpolygonid-ios.a and b/ios/Frameworks/libpolygonid.xcframework/ios-arm64/libpolygonid.a differ diff --git a/ios/Frameworks/libpolygonid.xcframework/libpolygonid.h b/ios/Frameworks/libpolygonid.xcframework/libpolygonid.h new file mode 100644 index 000000000..59f1ad4a3 --- /dev/null +++ b/ios/Frameworks/libpolygonid.xcframework/libpolygonid.h @@ -0,0 +1,260 @@ +/* Code generated by cmd/cgo; DO NOT EDIT. */ + +/* package github.com/0xPolygonID/c-polygonid/cmd/polygonid */ + + +#line 1 "cgo-builtin-export-prolog" + +#include + +#ifndef GO_CGO_EXPORT_PROLOGUE_H +#define GO_CGO_EXPORT_PROLOGUE_H + +#ifndef GO_CGO_GOSTRING_TYPEDEF +typedef struct { const char *p; ptrdiff_t n; } _GoString_; +#endif + +#endif + +/* Start of preamble from import "C" comments. */ + + +#line 3 "polygonid.go" + +#include +#include + +typedef enum +{ + PLGNSTATUSCODE_ERROR, + PLGNSTATUSCODE_NIL_POINTER, + // error extracting credential status from verifiable credential + PLGNSTATUSCODE_USER_CREDENTIAL_STATUS_EXTRACTION_ERROR, + // error resolving credential status (e.g. getting the status from chain of DHS) + PLGNSTATUSCODE_USER_CREDENTIAL_STATUS_RESOLVE_ERROR, + // error getting merkletree proof from credential status + PLGNSTATUSCODE_USER_CREDENTIAL_STATUS_MT_BUILD_ERROR, + // merkletree proof is invalid + PLGNSTATUSCODE_USER_CREDENTIAL_STATUS_MT_STATE_ERROR, + // credential is revoked + PLGNSTATUSCODE_USER_CREDENTIAL_STATUS_REVOKED_ERROR, + // the same as above but for issuer credential (for signature proofs) + PLGNSTATUSCODE_ISSUER_CREDENTIAL_STATUS_EXTRACTION_ERROR, + PLGNSTATUSCODE_ISSUER_CREDENTIAL_STATUS_RESOLVE_ERROR, + PLGNSTATUSCODE_ISSUER_CREDENTIAL_STATUS_MT_BUILD_ERROR, + PLGNSTATUSCODE_ISSUER_CREDENTIAL_STATUS_MT_STATE_ERROR, + PLGNSTATUSCODE_ISSUER_CREDENTIAL_STATUS_REVOKED_ERROR, +} PLGNStatusCode; + +typedef struct _PLGNStatus +{ + PLGNStatusCode status; + char *error_msg; +} PLGNStatus; + +#line 1 "cgo-generated-wrapper" + + +/* End of preamble from import "C" comments. */ + + +/* Start of boilerplate cgo prologue. */ +#line 1 "cgo-gcc-export-header-prolog" + +#ifndef GO_CGO_PROLOGUE_H +#define GO_CGO_PROLOGUE_H + +typedef signed char GoInt8; +typedef unsigned char GoUint8; +typedef short GoInt16; +typedef unsigned short GoUint16; +typedef int GoInt32; +typedef unsigned int GoUint32; +typedef long long GoInt64; +typedef unsigned long long GoUint64; +typedef GoInt64 GoInt; +typedef GoUint64 GoUint; +typedef size_t GoUintptr; +typedef float GoFloat32; +typedef double GoFloat64; +#ifdef _MSC_VER +#include +typedef _Fcomplex GoComplex64; +typedef _Dcomplex GoComplex128; +#else +typedef float _Complex GoComplex64; +typedef double _Complex GoComplex128; +#endif + +/* + static assertion to make sure the file is being used on architecture + at least with matching size of GoInt. +*/ +typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; + +#ifndef GO_CGO_GOSTRING_TYPEDEF +typedef _GoString_ GoString; +#endif +typedef void *GoMap; +typedef void *GoChan; +typedef struct { void *t; void *v; } GoInterface; +typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; + +#endif + +/* End of boilerplate cgo prologue. */ + +#ifdef __cplusplus +extern "C" { +#endif + +extern GoUint8 PLGNAuthV2InputsMarshal(char** jsonResponse, char* in, PLGNStatus** status); + +// Deprecated: Use PLGNNewGenesisID instead. It supports environment +// configuration, giving the ability to register custom DID methods. +// +extern GoUint8 PLGNCalculateGenesisID(char** jsonResponse, char* in, PLGNStatus** status); +extern GoUint8 PLGNNewGenesisID(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); +extern GoUint8 PLGNNewGenesisIDFromEth(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); +extern GoUint8 PLGNCreateClaim(char** jsonResponse, char* in, PLGNStatus** status); + +// PLGNIDToInt returns the ID as a big int string +// Input should be a valid JSON object: string enclosed by double quotes. +// Output is a valid JSON object to: string enclosed by double quotes. +// +extern GoUint8 PLGNIDToInt(char** jsonResponse, char* in, PLGNStatus** status); +extern GoUint8 PLGNProofFromSmartContract(char** jsonResponse, char* in, PLGNStatus** status); +extern GoUint8 PLGNProfileID(char** jsonResponse, char* in, PLGNStatus** status); + +// PLGNAtomicQuerySigV2Inputs returns the inputs for the +// credentialAtomicQuerySigV2 with optional selective disclosure. +// +// Additional configuration may be required for Reverse Hash Service +// revocation validation. In other case cfg may be nil. +// +// The configuration example may be found in the [README.md] file. +// +// [README.md]: https://github.com/0xPolygonID/c-polygonid/blob/main/README.md#configuration +// +extern GoUint8 PLGNAtomicQuerySigV2Inputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNSigV2Inputs returns the inputs for the Sig circuit v2 with +// optional selective disclosure. +// +// Deprecated: Does not support Reverse Hash Service credential status +// validation! Use PLGNAtomicQuerySigV2Inputs method with configuration instead. +// +extern GoUint8 PLGNSigV2Inputs(char** jsonResponse, char* in, PLGNStatus** status); + +// PLGNAtomicQueryMtpV2Inputs returns the inputs for the +// credentialAtomicQueryMTPV2 with optional selective disclosure. +// +// Additional configuration may be required for Reverse Hash Service +// revocation validation. In other case cfg may be nil. +// +// The configuration example may be found in the [README.md] file. +// +// [README.md]: https://github.com/0xPolygonID/c-polygonid/blob/main/README.md#configuration +// +extern GoUint8 PLGNAtomicQueryMtpV2Inputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNMtpV2Inputs returns the inputs for the MTP circuit v2 with +// optional selective disclosure. +// +// Deprecated: Does not support Reverse Hash Service credential status +// validation! Use PLGNAtomicQueryMtpV2Inputs method with configuration instead. +// +extern GoUint8 PLGNMtpV2Inputs(char** jsonResponse, char* in, PLGNStatus** status); + +// PLGNAtomicQuerySigV2OnChainInputs returns the inputs for the +// credentialAtomicQuerySigV2OnChain circuit with optional selective disclosure. +// +// Additional configuration may be required for Reverse Hash Service +// revocation validation. In other case cfg may be nil. +// +// The configuration example may be found in the [README.md] file. +// +// [README.md]: https://github.com/0xPolygonID/c-polygonid/blob/main/README.md#configuration +// +extern GoUint8 PLGNAtomicQuerySigV2OnChainInputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNAtomicQueryMtpV2OnChainInputs returns the inputs for the +// credentialAtomicQueryMTPV2OnChain circuit with optional selective disclosure. +// +// Additional configuration may be required for Reverse Hash Service +// revocation validation. In other case cfg may be nil. +// +// The configuration example may be found in the [README.md] file. +// +// [README.md]: https://github.com/0xPolygonID/c-polygonid/blob/main/README.md#configuration +// +extern GoUint8 PLGNAtomicQueryMtpV2OnChainInputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNAtomicQueryV3Inputs returns the inputs for the credentialAtomicQueryV3 +// circuit with optional selective disclosure. +// +extern GoUint8 PLGNAtomicQueryV3Inputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNAtomicQueryV3OnChainInputs returns the inputs for the +// credentialAtomicQueryV3OnChain circuit with optional selective disclosure. +// +extern GoUint8 PLGNAtomicQueryV3OnChainInputs(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNALinkedMultiQueryInputs returns the inputs for the +// linkedMultiQuery10-beta.1 circuit. +// +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. +// +// Sample input: +// +// { +// "issuerDID": "did:polygonid:polygon:mumbai:2qCU58EJgrEMJvPfhUCnFCwuKQTkX8VmJX2sJCH6C8", +// "hexdata": "0x0...", +// "version": "0.0.1" +// } +// +// The configuration example may be found in the [README.md] file. +// +// [README.md]: https://github.com/0xPolygonID/c-polygonid/blob/main/README.md#configuration +// +extern GoUint8 PLGNW3CCredentialFromOnchainHex(char** jsonResponse, char* in, char* cfg, PLGNStatus** status); + +// PLGNDescribeID parses ID and return it in different representations. +// Request example: +// +// {"id":"31Akw5AB2xBrwqmbDUA2XoSGCfTepz52q9jmFE4mXA"} +// +// {"idAsInt":"24460059377712687587111979692736628604804094576108957842967948238113620738"} +// +// There is possible to pass both id & idAsInt fields in the request. But if the +// resulted ID would not be equal, error returns. +// +// Response example: +// +// { +// "did": "did:polygonid:linea:testnet:31Akw5AB2xBrwqmbDUA2XoSGCfTepz52q9jmFE4mXA", +// "id": "31Akw5AB2xBrwqmbDUA2XoSGCfTepz52q9jmFE4mXA", +// "idAsInt": "24460059377712687587111979692736628604804094576108957842967948238113620738", +// } +// +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 +} +#endif diff --git a/ios/libbabyjubjub.a b/ios/libbabyjubjub.a deleted file mode 100644 index 95d1d8c5f..000000000 Binary files a/ios/libbabyjubjub.a and /dev/null differ diff --git a/ios/libpolygonid-ios-simulator-x86_64.a b/ios/libpolygonid-ios-simulator-x86_64.a deleted file mode 100644 index 8d026d343..000000000 Binary files a/ios/libpolygonid-ios-simulator-x86_64.a and /dev/null differ diff --git a/ios/libpolygonid-ios-simulator.a b/ios/libpolygonid-ios-simulator.a deleted file mode 100644 index 48993fedd..000000000 Binary files a/ios/libpolygonid-ios-simulator.a and /dev/null differ diff --git a/ios/libpolygonid.a b/ios/libpolygonid.a deleted file mode 100644 index 8a99fa491..000000000 Binary files a/ios/libpolygonid.a and /dev/null differ diff --git a/ios/polygonid_flutter_sdk.podspec b/ios/polygonid_flutter_sdk.podspec index 64480d610..5381462c0 100644 --- a/ios/polygonid_flutter_sdk.podspec +++ b/ios/polygonid_flutter_sdk.podspec @@ -10,28 +10,29 @@ Pod::Spec.new do |s| PolygonID SDK flutter plugin project. DESC s.homepage = 'https://polygon.technology/polygon-id' - s.license = { :file => '../LICENSE' } + s.license = { :file => '../LICENSE-MIT' } s.author = { 'Polygon ID' => 'raulj@polygon.technology' } s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.static_framework = true - s.vendored_libraries = "**/*.a" + s.vendored_libraries = "./*.a" s.dependency 'Flutter' s.dependency 'CryptoSwift' s.platform = :ios, '9.0' s.libraries = ["c++", "z"] # s.ios.deployment_target = '9.0' - # s.ios.vendored_frameworks = 'Frameworks/Core.xcframework' + s.preserve_paths = [ + 'Frameworks/libpolygonid.xcframework/**/*', + ] + s.ios.vendored_frameworks = [ + 'Frameworks/libpolygonid.xcframework', +# '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/libpolygonid.a -lc++ -lz" } - # s.vendored_libraries = "Frameworks/**/*.a" s.pod_target_xcconfig = { - 'STRIP_STYLE' => 'non-global', - 'DEAD_CODE_STRIPPING' => 'NO', - 'DEFINES_MODULE' => 'YES', - 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386', - 'EXCLUDED_ARCHS[sdk=iphoneos*]' => 'armv7 armv7s' + "OTHER_LDFLAGS" => "-lc++ -lz", + "DEFINES_MODULE" => "YES" } s.swift_version = '5.0' end diff --git a/lib/common/domain/use_cases/set_env_use_case.dart b/lib/common/domain/use_cases/set_env_use_case.dart index 28071b6dc..07452275b 100644 --- a/lib/common/domain/use_cases/set_env_use_case.dart +++ b/lib/common/domain/use_cases/set_env_use_case.dart @@ -2,6 +2,7 @@ import 'package:polygonid_flutter_sdk/common/domain/domain_logger.dart'; import 'package:polygonid_flutter_sdk/common/domain/entities/env_entity.dart'; import 'package:polygonid_flutter_sdk/common/domain/repositories/config_repository.dart'; import 'package:polygonid_flutter_sdk/common/domain/use_case.dart'; +import 'package:polygonid_flutter_sdk/common/libs/polygonidcore/pidcore_base.dart'; class SetEnvUseCase extends FutureUseCase { final ConfigRepository _configRepository; @@ -10,6 +11,8 @@ class SetEnvUseCase extends FutureUseCase { @override Future execute({required EnvEntity param}) { + PolygonIdCore.setEnvConfig(param.config); + return _configRepository.setEnv(env: param).then((_) async { logger().i("[SetEnvUseCase] $param env has been set"); diff --git a/lib/common/kms/key_providers/bjj_provider.dart b/lib/common/kms/key_providers/bjj_provider.dart index 070827746..375208cf4 100644 --- a/lib/common/kms/key_providers/bjj_provider.dart +++ b/lib/common/kms/key_providers/bjj_provider.dart @@ -39,7 +39,7 @@ class BjjProvider implements IKeyProvider { final kmsId = KmsKeyId( type: keyType, - id: keyPath(keyType, publicKey.hex()), + id: keyPath(keyType, publicKey.hex), ); await keyStore.importKey(alias: kmsId.id, key: privateKey.hex()); @@ -52,7 +52,7 @@ class BjjProvider implements IKeyProvider { @override Future publicKey(KmsKeyId keyId) async { final privateKey = await _privateKey(keyId); - return privateKey.public().hex(); + return privateKey.public().hex; } /// signs prepared payload of size, @@ -87,8 +87,7 @@ class BjjProvider implements IKeyProvider { Uint8List message, String signatureHex, KmsKeyId keyId) async { final publicKey = await this.publicKey(keyId); - final bytes = hexToBytes(publicKey); - final pbkey = PublicKey.newFromCompressed(bytesToUnsignedInt(bytes)); + final pbkey = PublicKey.hex(publicKey); return pbkey.verify( Uint8ArrayUtils.uint8ListToString(message), diff --git a/lib/common/libs/polygonidcore/native_polygonidcore.dart b/lib/common/libs/polygonidcore/native_polygonidcore.dart index 50d39caef..a6a4c8a35 100644 --- a/lib/common/libs/polygonidcore/native_polygonidcore.dart +++ b/lib/common/libs/polygonidcore/native_polygonidcore.dart @@ -3835,6 +3835,24 @@ class NativePolygonIdCoreLib { late final _PLGNCleanCache = _PLGNCleanCachePtr.asFunction< int Function(ffi.Pointer>)>(); + int PLGNCleanCache2( + ffi.Pointer cfg, + ffi.Pointer> status, + ) { + return _PLGNCleanCache2( + cfg, + status, + ); + } + + late final _PLGNCleanCache2Ptr = _lookup< + ffi.NativeFunction< + GoUint8 Function(ffi.Pointer, + ffi.Pointer>)>>('PLGNCleanCache2'); + late final _PLGNCleanCache2 = _PLGNCleanCache2Ptr.asFunction< + int Function( + ffi.Pointer, ffi.Pointer>)>(); + int PLGNCacheCredentials( ffi.Pointer in1, ffi.Pointer cfg, @@ -3909,6 +3927,156 @@ class NativePolygonIdCoreLib { late final _PLGNDescribeID = _PLGNDescribeIDPtr.asFunction< int Function(ffi.Pointer>, ffi.Pointer, ffi.Pointer, ffi.Pointer>)>(); + + int PLGNBabyJubJubSignPoseidon( + ffi.Pointer> jsonResponse, + ffi.Pointer in1, + ffi.Pointer cfg, + ffi.Pointer> status, + ) { + return _PLGNBabyJubJubSignPoseidon( + jsonResponse, + in1, + cfg, + status, + ); + } + + late final _PLGNBabyJubJubSignPoseidonPtr = _lookup< + ffi.NativeFunction< + GoUint8 Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>)>>( + 'PLGNBabyJubJubSignPoseidon'); + late final _PLGNBabyJubJubSignPoseidon = + _PLGNBabyJubJubSignPoseidonPtr.asFunction< + int Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>)>(); + + int PLGNBabyJubJubVerifyPoseidon( + ffi.Pointer> jsonResponse, + ffi.Pointer in1, + ffi.Pointer cfg, + ffi.Pointer> status, + ) { + return _PLGNBabyJubJubVerifyPoseidon( + jsonResponse, + in1, + cfg, + status, + ); + } + + late final _PLGNBabyJubJubVerifyPoseidonPtr = _lookup< + ffi.NativeFunction< + GoUint8 Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>)>>( + 'PLGNBabyJubJubVerifyPoseidon'); + late final _PLGNBabyJubJubVerifyPoseidon = + _PLGNBabyJubJubVerifyPoseidonPtr.asFunction< + int Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>)>(); + + int PLGNBabyJubJubPrivate2Public( + ffi.Pointer> jsonResponse, + ffi.Pointer in1, + ffi.Pointer cfg, + ffi.Pointer> status, + ) { + return _PLGNBabyJubJubPrivate2Public( + jsonResponse, + in1, + cfg, + status, + ); + } + + late final _PLGNBabyJubJubPrivate2PublicPtr = _lookup< + ffi.NativeFunction< + GoUint8 Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>)>>( + 'PLGNBabyJubJubPrivate2Public'); + late final _PLGNBabyJubJubPrivate2Public = + _PLGNBabyJubJubPrivate2PublicPtr.asFunction< + int Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>)>(); + + int PLGNBabyJubJubPublicUncompress( + ffi.Pointer> jsonResponse, + ffi.Pointer in1, + ffi.Pointer cfg, + ffi.Pointer> status, + ) { + return _PLGNBabyJubJubPublicUncompress( + jsonResponse, + in1, + cfg, + status, + ); + } + + late final _PLGNBabyJubJubPublicUncompressPtr = _lookup< + ffi.NativeFunction< + GoUint8 Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>)>>( + 'PLGNBabyJubJubPublicUncompress'); + late final _PLGNBabyJubJubPublicUncompress = + _PLGNBabyJubJubPublicUncompressPtr.asFunction< + int Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>)>(); + + int PLGNBabyJubJubPublicCompress( + ffi.Pointer> jsonResponse, + ffi.Pointer in1, + ffi.Pointer cfg, + ffi.Pointer> status, + ) { + return _PLGNBabyJubJubPublicCompress( + jsonResponse, + in1, + cfg, + status, + ); + } + + late final _PLGNBabyJubJubPublicCompressPtr = _lookup< + ffi.NativeFunction< + GoUint8 Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>)>>( + 'PLGNBabyJubJubPublicCompress'); + late final _PLGNBabyJubJubPublicCompress = + _PLGNBabyJubJubPublicCompressPtr.asFunction< + int Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>)>(); } final class __mbstate_t extends ffi.Union { @@ -5346,6 +5514,8 @@ const int __MAC_14_5 = 140500; const int __MAC_15_0 = 150000; +const int __MAC_15_1 = 150100; + const int __IPHONE_2_0 = 20000; const int __IPHONE_2_1 = 20100; @@ -5506,6 +5676,8 @@ const int __IPHONE_17_5 = 170500; const int __IPHONE_18_0 = 180000; +const int __IPHONE_18_1 = 180100; + const int __WATCHOS_1_0 = 10000; const int __WATCHOS_2_0 = 20000; @@ -5602,6 +5774,8 @@ const int __WATCHOS_10_5 = 100500; const int __WATCHOS_11_0 = 110000; +const int __WATCHOS_11_1 = 110100; + const int __TVOS_9_0 = 90000; const int __TVOS_9_1 = 90100; @@ -5700,6 +5874,8 @@ const int __TVOS_17_5 = 170500; const int __TVOS_18_0 = 180000; +const int __TVOS_18_1 = 180100; + const int __BRIDGEOS_2_0 = 20000; const int __BRIDGEOS_3_0 = 30000; @@ -5754,6 +5930,8 @@ const int __BRIDGEOS_8_5 = 80500; const int __BRIDGEOS_9_0 = 90000; +const int __BRIDGEOS_9_1 = 90100; + const int __DRIVERKIT_19_0 = 190000; const int __DRIVERKIT_20_0 = 200000; @@ -5782,6 +5960,8 @@ const int __DRIVERKIT_23_5 = 230500; const int __DRIVERKIT_24_0 = 240000; +const int __DRIVERKIT_24_1 = 240100; + const int __VISIONOS_1_0 = 10000; const int __VISIONOS_1_1 = 10100; @@ -5790,6 +5970,8 @@ const int __VISIONOS_1_2 = 10200; const int __VISIONOS_2_0 = 20000; +const int __VISIONOS_2_1 = 20100; + const int MAC_OS_X_VERSION_10_0 = 1000; const int MAC_OS_X_VERSION_10_1 = 1010; @@ -5914,9 +6096,11 @@ const int MAC_OS_VERSION_14_5 = 140500; const int MAC_OS_VERSION_15_0 = 150000; -const int __MAC_OS_X_VERSION_MIN_REQUIRED = 150000; +const int MAC_OS_VERSION_15_1 = 150100; + +const int __MAC_OS_X_VERSION_MIN_REQUIRED = 140000; -const int __MAC_OS_X_VERSION_MAX_ALLOWED = 150000; +const int __MAC_OS_X_VERSION_MAX_ALLOWED = 150100; const int __ENABLE_LEGACY_MAC_AVAILABILITY = 1; diff --git a/lib/common/libs/polygonidcore/pidcore_base.dart b/lib/common/libs/polygonidcore/pidcore_base.dart index 3ce2cfd38..03f0ba911 100644 --- a/lib/common/libs/polygonidcore/pidcore_base.dart +++ b/lib/common/libs/polygonidcore/pidcore_base.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'dart:ffi' as ffi; import 'dart:ffi'; import 'dart:io'; @@ -6,11 +7,21 @@ import 'package:ffi/ffi.dart'; import 'package:flutter/foundation.dart'; import 'package:injectable/injectable.dart'; import 'package:polygonid_flutter_sdk/common/domain/domain_logger.dart'; +import 'package:polygonid_flutter_sdk/common/domain/entities/env_config_entity.dart'; +import 'package:polygonid_flutter_sdk/common/domain/error_exception.dart'; +import 'package:polygonid_flutter_sdk/common/utils/collection_utils.dart'; import 'native_polygonidcore.dart'; typedef ConsumedStatusResult = ({PLGNStatusCode statusCode, String message}); +typedef GenericPolygonIdFunction = int Function( + ffi.Pointer>, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>, +); + ConsumedStatusResult _createConsumedStatusResult( PLGNStatusCode statusCode, String message) { return (statusCode: statusCode, message: message); @@ -18,6 +29,8 @@ ConsumedStatusResult _createConsumedStatusResult( @injectable class PolygonIdCore { + static late String _envConfigJson; + static NativePolygonIdCoreLib? _nativePolygonIdCoreLib; static NativePolygonIdCoreLib get nativePolygonIdCoreLib { @@ -33,8 +46,70 @@ class PolygonIdCore { return _nativePolygonIdCoreLib!; } + static void setEnvConfig(EnvConfigEntity envConfig) { + _envConfigJson = jsonEncode(envConfig.toJson()); + } + PolygonIdCore(); + T callGenericCoreFunction({ + required String Function() input, + String? config, + required GenericPolygonIdFunction function, + void Function(PLGNStatusCode)? statusCodeHandler, + required T Function(String) parse, + }) { + final response = malloc>(); + final status = malloc>(); + freeAllocatedMemory() { + malloc.free(response); + malloc.free(status); + } + + final inputPointer = input().toNativeUtf8().cast(); + final cfgPointer = + (config ?? _envConfigJson).toNativeUtf8().cast(); + + final res = function(response, inputPointer, cfgPointer, status); + + final PLGNStatusCode? statusCode = + PLGNStatusCode.values.firstWhereOrNull((e) => e.value == res); + + /// Handle error status codes + if (statusCode == PLGNStatusCode.PLGNSTATUSCODE_ERROR) { + final consumedStatus = consumeStatus(status); + freeAllocatedMemory(); + // TODO Should we track this here? + // _trackError(consumedStatus, "callCoreFunction"); + throw CoreLibraryException( + coreLibraryName: "libpolygonid", + methodName: "callCoreFunction", + errorMessage: consumedStatus.message, + statusCode: consumedStatus.statusCode, + ); + } else if (statusCode != null && statusCodeHandler != null) { + statusCodeHandler(statusCode); + } + + /// Parse the response + T result; + ffi.Pointer jsonResponse = response.value; + ffi.Pointer jsonString = jsonResponse.cast(); + if (jsonString != ffi.nullptr) { + result = parse(jsonString.toDartString()); + } else { + throw CoreLibraryException( + coreLibraryName: "libpolygonid", + methodName: "callCoreFunction", + errorMessage: "Unable to parse response", + statusCode: PLGNStatusCode.PLGNSTATUSCODE_ERROR, + ); + } + + freeAllocatedMemory(); + return result; + } + ConsumedStatusResult consumeStatus( ffi.Pointer> status) { if (status == ffi.nullptr || status.value == ffi.nullptr) { diff --git a/lib/identity/libs/bjj/bjj.dart b/lib/identity/libs/bjj/bjj.dart index 133cb21a4..e9f051b86 100644 --- a/lib/identity/libs/bjj/bjj.dart +++ b/lib/identity/libs/bjj/bjj.dart @@ -1,136 +1,89 @@ -import 'dart:ffi'; -import 'dart:io'; +import 'dart:convert'; -import 'package:ffi/ffi.dart'; import 'package:injectable/injectable.dart'; - -typedef CStringFree = void Function(Pointer); -typedef CStringFreeFFI = Void Function(Pointer); +import 'package:polygonid_flutter_sdk/common/libs/polygonidcore/pidcore_base.dart'; @injectable -class BabyjubjubLib { - final DynamicLibrary _nativeBabyjubjubLib = Platform.isAndroid - ? DynamicLibrary.open("libbabyjubjub.so") - : DynamicLibrary.process(); - - late CStringFree cstringFree; - - BabyjubjubLib() { - _packPoint = _nativeBabyjubjubLib - .lookup< - NativeFunction< - Pointer Function( - Pointer, Pointer)>>("pack_point") - .asFunction(); - - _unpackPoint = _nativeBabyjubjubLib - .lookup Function(Pointer)>>( - "unpack_point") - .asFunction(); - - _prv2Pub = _nativeBabyjubjubLib - .lookup Function(Pointer)>>( - "prv2pub") - .asFunction(); - - _signPoseidon = _nativeBabyjubjubLib - .lookup< - NativeFunction< - Pointer Function( - Pointer, Pointer)>>("sign_poseidon") - .asFunction(); - - _verifyPoseidon = _nativeBabyjubjubLib - .lookup< - NativeFunction< - Pointer Function(Pointer, Pointer, - Pointer)>>("verify_poseidon") - .asFunction(); - - cstringFree = _nativeBabyjubjubLib - .lookup>("cstring_free") - .asFunction(); +class BabyjubjubLib extends PolygonIdCore { + BabyjubjubLib(); + + String compressPoint(String pointX, String pointY) { + return callGenericCoreFunction( + input: () => jsonEncode({ + "public_key_x_int": pointX, + "public_key_y_int": pointY, + }), + function: + PolygonIdCore.nativePolygonIdCoreLib.PLGNBabyJubJubPublicCompress, + parse: (jsonString) { + final json = jsonDecode(jsonString); + return json["public_key"] as String; + }, + ); } - late Pointer Function(Pointer, Pointer) _packPoint; - - String packPoint(String pointX, String pointY) { - //if (lib == null) return "ERROR: The library is not initialized"; - - final ptrX = pointX.toNativeUtf8(); - final ptrY = pointY.toNativeUtf8(); - final resultPtr = _packPoint(ptrX, ptrY); - final result = resultPtr.toDartString(); - //debugPrint("- Response string: $result"); - // Free the string pointer, as we already have - // an owned String to return - //print("- Freeing the native char*"); - cstringFree(resultPtr); - return result; - } - - late Pointer Function(Pointer) _unpackPoint; - - List? unpackPoint(String compressedPoint) { - final pointPtr = compressedPoint.toNativeUtf8(); - final resultPtr = _unpackPoint(pointPtr); - final result = resultPtr.toDartString(); - //print("- Response string: $result"); - // Free the string pointer, as we already have - // an owned String to return - //print("- Freeing the native char*"); - cstringFree(resultPtr); - return result.split(","); + List uncompressPoint(String compressedPoint) { + return callGenericCoreFunction( + input: () => jsonEncode({ + "public_key": compressedPoint, + }), + function: + PolygonIdCore.nativePolygonIdCoreLib.PLGNBabyJubJubPublicUncompress, + parse: (jsonString) { + final json = jsonDecode(jsonString); + return [ + json["public_key_x_int"] as String, + json["public_key_y_int"] as String, + ]; + }, + ); } - // privKey.signPoseidon -> signPoseidon - late Pointer Function(Pointer, Pointer) _signPoseidon; - String signPoseidon(String privateKey, String msg) { - //if (lib == null) return "ERROR: The library is not initialized"; - final prvKeyPtr = privateKey.toNativeUtf8(); - final msgPtr = msg.toNativeUtf8(); - final resultPtr = _signPoseidon(prvKeyPtr, msgPtr); - final String compressedSignature = resultPtr.toDartString(); - //print("- Response string: $compressedSignature"); - // Free the string pointer, as we already have - // an owned String to return - //print("- Freeing the native char*"); - cstringFree(resultPtr); - return compressedSignature; + return callGenericCoreFunction( + input: () => jsonEncode({ + "private_key": privateKey, + "msg_int": msg, + }), + function: PolygonIdCore.nativePolygonIdCoreLib.PLGNBabyJubJubSignPoseidon, + parse: (jsonString) { + final json = jsonDecode(jsonString); + return json["signature"]; + }, + ); } - // privKey.verifyPoseidon -> verifyPoseidon - late Pointer Function(Pointer, Pointer, Pointer) - _verifyPoseidon; - bool verifyPoseidon( - String privateKey, String compressedSignature, String msg) { - final privateKeyPtr = privateKey.toNativeUtf8(); - final sigPtr = compressedSignature.toNativeUtf8(); - final msgPtr = msg.toNativeUtf8(); - final resultPtr = _verifyPoseidon(privateKeyPtr, sigPtr, msgPtr); - final String resultString = resultPtr.toDartString(); - //print("- Response string: $resultString"); - // Free the string pointer, as we already have - // an owned String to return - //print("- Freeing the native char*"); - cstringFree(resultPtr); - final bool result = resultString.compareTo("1") == 0; - return result; + String publicKey, + String compressedSignature, + String msg, + ) { + return callGenericCoreFunction( + input: () => jsonEncode({ + "public_key": publicKey, + "signature": compressedSignature, + "msg_int": msg, + }), + function: + PolygonIdCore.nativePolygonIdCoreLib.PLGNBabyJubJubVerifyPoseidon, + parse: (jsonString) { + final json = jsonDecode(jsonString); + return json["valid"] as bool; + }, + ); } - late Pointer Function(Pointer) _prv2Pub; - String prv2pub(String privateKey) { - final prvKeyPtr = privateKey.toNativeUtf8(); - final resultPtr = _prv2Pub(prvKeyPtr); - final String resultString = resultPtr.toDartString(); - //print("- Response string: $resultString"); - // Free the string pointer, as we already have - // an owned String to return - //print("- Freeing the native char*"); - cstringFree(resultPtr); - return resultString; + return callGenericCoreFunction( + input: () => jsonEncode({ + "private_key": privateKey, + }), + function: + PolygonIdCore.nativePolygonIdCoreLib.PLGNBabyJubJubPrivate2Public, + parse: (jsonString) { + final json = jsonDecode(jsonString); + return json["public_key"] as String; + }, + ); } } diff --git a/lib/identity/libs/bjj/bjj_wallet.dart b/lib/identity/libs/bjj/bjj_wallet.dart index ca0eab2ab..edd9dc058 100644 --- a/lib/identity/libs/bjj/bjj_wallet.dart +++ b/lib/identity/libs/bjj/bjj_wallet.dart @@ -1,8 +1,6 @@ import 'dart:math'; import 'dart:typed_data'; -import 'package:polygonid_flutter_sdk/common/utils/hex_utils.dart'; -import 'package:polygonid_flutter_sdk/common/utils/uint8_list_utils.dart'; import 'package:web3dart/credentials.dart'; import 'eddsa_babyjub.dart' as eddsaBabyJub; @@ -15,10 +13,6 @@ import 'package:bip32/bip32.dart' as bip32; class BjjWallet { late Uint8List privateKey; late List publicKey; - dynamic publicKeyHex; - String? publicKeyCompressed; - String? publicKeyCompressedHex; - String? publicKeyBase64; /// Initialize Babyjubjub wallet from private key /// @@ -30,17 +24,7 @@ class BjjWallet { final priv = eddsaBabyJub.PrivateKey(privateKey); final eddsaBabyJub.PublicKey publicKey = priv.public(); - this.publicKey = [publicKey.p[0].toString(), publicKey.p[1].toString()]; - publicKeyHex = [ - publicKey.p[0].toRadixString(16).padLeft(64, '0'), - publicKey.p[1].toRadixString(16).padLeft(64, '0') - ]; - final compressedPublicKey = - Uint8ArrayUtils.leBuff2int(publicKey.compress()); - publicKeyCompressed = compressedPublicKey.toString(); - publicKeyCompressedHex = - compressedPublicKey.toRadixString(16).padLeft(64, '0'); - publicKeyBase64 = HexUtils.hexToBase64BJJ(publicKeyCompressedHex!); + this.publicKey = [publicKey.p.x.toString(), publicKey.p.y.toString()]; } /// Creates a BjjWallet diff --git a/lib/identity/libs/bjj/eddsa_babyjub.dart b/lib/identity/libs/bjj/eddsa_babyjub.dart index 663761d33..dfa203183 100644 --- a/lib/identity/libs/bjj/eddsa_babyjub.dart +++ b/lib/identity/libs/bjj/eddsa_babyjub.dart @@ -7,9 +7,11 @@ import '../../../common/utils/hex_utils.dart'; import '../../../common/utils/uint8_list_utils.dart'; import 'bjj.dart'; +typedef Point = ({BigInt x, BigInt y}); + /// Class representing EdDSA Baby Jub signature class Signature { - late List r8; + late Point r8; late BigInt s; /// Create a Signature with the R8 point and S scalar @@ -26,55 +28,48 @@ class Signature { } BabyjubjubLib bjjLib = BabyjubjubLib(); - final XYSublist = buf.sublist(0, 32); - // unpackPoint is used to unpack R8 X and Y - final List? unpackedPoint = - bjjLib.unpackPoint(HEX.encode(XYSublist.toList())); + final pointsSublist = buf.sublist(0, 32); + // uncompressPoint is used to unpack R8 X and Y + final unpackedPoint = + bjjLib.uncompressPoint(HEX.encode(pointsSublist.toList())); - BigInt? x = BigInt.tryParse(unpackedPoint![0], radix: 10); - BigInt? y = BigInt.tryParse(unpackedPoint[1], radix: 10); - List r8 = []; - r8.add(x!); - r8.add(y!); + final x = BigInt.parse(unpackedPoint[0]); + final y = BigInt.parse(unpackedPoint[1]); // S is decoded manually BigInt s = Uint8ArrayUtils.beBuff2int( Uint8List.fromList(buf.sublist(32, 64).reversed.toList())); - return Signature(r8, s); + return Signature((x: x, y: y), s); + } + + /// Compress the Signature + /// @returns {Uint8List} - signature compressed into a buffer + Uint8List compress() { + final r8 = HexUtils.hexToBytes( + BabyjubjubLib().compressPoint(this.r8.x.toString(), this.r8.y.toString()), + ); + final s = Uint8ArrayUtils.beInt2Buff(this.s, 32); + return Uint8List.fromList([...r8, ...s]); } } /// Class representing a EdDSA Baby Jub public key class PublicKey { - late List p; + final String hex; + final Point p; /// Create a PublicKey from a curve point p + /// @param {String} hex - hex representation /// @param {List[BigInt]} p - curve point - PublicKey(this.p); - - /// Create a PublicKey from a bigInt compressed pubKey - /// - /// @param {BigInt} compressedBigInt - compressed public key in a bigInt - /// - /// @returns {PublicKey} public key class - static PublicKey newFromCompressed(BigInt compressedBigInt) { - final Uint8List compressedBuffLE = - Uint8ArrayUtils.leInt2Buff(compressedBigInt, 32); - if (compressedBuffLE.length != 32) { - throw ArgumentError('buf must be 32 bytes'); - } + PublicKey._(this.hex, this.p); + + factory PublicKey.hex(String hex) { BabyjubjubLib bjjLib = BabyjubjubLib(); - final p = - bjjLib.unpackPoint(Uint8ArrayUtils.uint8ListToString(compressedBuffLE)); - if (p == null) { - throw ArgumentError('unpackPoint failed'); - } + final p = bjjLib.uncompressPoint(hex); BigInt x = BigInt.parse(p[0]); BigInt y = BigInt.parse(p[1]); - List point = []; - point.add(x); - point.add(y); - return PublicKey(point); + + return PublicKey._(hex, (x: x, y: y)); } /// Compress the PublicKey @@ -82,29 +77,18 @@ class PublicKey { Uint8List compress() { BabyjubjubLib bjjLib = BabyjubjubLib(); return HexUtils.hexToBytes( - bjjLib.packPoint(p[0].toString(), p[1].toString())); + bjjLib.compressPoint(p.x.toString(), p.y.toString()), + ); } bool verify(String messageHash, Signature signature) { BabyjubjubLib bjjLib = BabyjubjubLib(); - List pointList = []; - pointList.add(p[0].toInt()); - pointList.add(p[1].toInt()); - List sigList = []; - sigList.add(signature.r8[0].toInt()); - sigList.add(signature.r8[1].toInt()); - sigList.add(signature.s.toInt()); return bjjLib.verifyPoseidon( - Uint8ArrayUtils.uint8ListToString(Uint8List.fromList(pointList)), - Uint8ArrayUtils.uint8ListToString(Uint8List.fromList(sigList)), + hex, + Uint8ArrayUtils.uint8ListToString(signature.compress()), messageHash, ); } - - String hex() { - BabyjubjubLib bjjLib = BabyjubjubLib(); - return bjjLib.packPoint(p[0].toString(), p[1].toString()); - } } /// Class representing EdDSA Baby Jub private key @@ -124,18 +108,8 @@ class PrivateKey { /// @returns {PublicKey} PublicKey derived from PrivateKey PublicKey public() { BabyjubjubLib bjjLib = BabyjubjubLib(); - String resultString = bjjLib.prv2pub(HexUtils.bytesToHex(sk)); - final stringList = resultString.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]); - List p = []; - p.add(x); - p.add(y); - return PublicKey(p); + String publicKeyHex = bjjLib.prv2pub(HexUtils.bytesToHex(sk)); + return PublicKey.hex(publicKeyHex); } String sign(BigInt messageHash) { diff --git a/lib/identity/libs/polygonidcore/pidcore_identity.dart b/lib/identity/libs/polygonidcore/pidcore_identity.dart index 75b3f4299..59f81ade0 100644 --- a/lib/identity/libs/polygonidcore/pidcore_identity.dart +++ b/lib/identity/libs/polygonidcore/pidcore_identity.dart @@ -32,8 +32,7 @@ class PolygonIdCoreIdentity extends PolygonIdCore { int res = PolygonIdCore.nativePolygonIdCoreLib .PLGNNewGenesisID(response, in1, cfg, status); - // res 0 means error - if (res == 0) { + if (res == PLGNStatusCode.PLGNSTATUSCODE_ERROR.value) { final ConsumedStatusResult consumedStatus = consumeStatus(status); freeAllocatedMemory(); _trackError(consumedStatus, "PLGNNewGenesisID"); @@ -74,8 +73,7 @@ class PolygonIdCoreIdentity extends PolygonIdCore { int res = PolygonIdCore.nativePolygonIdCoreLib .PLGNNewGenesisIDFromEth(response, in1, cfg, status); - // res 0 means error - if (res == 0) { + if (res == PLGNStatusCode.PLGNSTATUSCODE_ERROR.value) { final ConsumedStatusResult consumedStatus = consumeStatus(status); freeAllocatedMemory(); _trackError(consumedStatus, "PLGNNewGenesisIDFromEth"); @@ -115,8 +113,7 @@ class PolygonIdCoreIdentity extends PolygonIdCore { int res = PolygonIdCore.nativePolygonIdCoreLib .PLGNProfileID(response, in1, status); - // res 0 means error - if (res == 0) { + if (res == PLGNStatusCode.PLGNSTATUSCODE_ERROR.value) { final ConsumedStatusResult consumedStatus = consumeStatus(status); freeAllocatedMemory(); _trackError(consumedStatus, "PLGNProfileID"); @@ -158,8 +155,7 @@ class PolygonIdCoreIdentity extends PolygonIdCore { int res = PolygonIdCore.nativePolygonIdCoreLib.PLGNIDToInt(response, in1, status); - // res 0 means error - if (res == 0) { + if (res == PLGNStatusCode.PLGNSTATUSCODE_ERROR.value) { final ConsumedStatusResult consumedStatus = consumeStatus(status); freeAllocatedMemory(); _trackError(consumedStatus, "PLGNIDToInt"); @@ -203,8 +199,7 @@ class PolygonIdCoreIdentity extends PolygonIdCore { int res = PolygonIdCore.nativePolygonIdCoreLib .PLGNDescribeID(response, in1, cfg, status); - // res 0 means error - if (res == 0) { + if (res == PLGNStatusCode.PLGNSTATUSCODE_ERROR.value) { final ConsumedStatusResult consumedStatus = consumeStatus(status); freeAllocatedMemory(); _trackError(consumedStatus, "PLGNDescribeID"); diff --git a/pubspec.yaml b/pubspec.yaml index 553a4b83b..301918aa1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -84,7 +84,7 @@ ffigen: output: 'lib/common/libs/polygonidcore/native_polygonidcore.dart' headers: entry-points: - - 'ios/Classes/libpolygonid.h' + - 'ios/Frameworks/libpolygonid.xcframework/libpolygonid.h' # name: WitnessMtpLib # description: Bindings to `ios/Classes/witnesscalc_credentialAtomicQueryMTPV2.h`.