Skip to content

Commit

Permalink
Merge pull request #458 from 0xPolygonID/fix/example_n_cleanup
Browse files Browse the repository at this point in the history
Fixed example.
  • Loading branch information
5eeman authored Nov 12, 2024
2 parents 1cca8b5 + 0c736bd commit 0cf0d88
Show file tree
Hide file tree
Showing 29 changed files with 549 additions and 3,484 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/polygonid_flutter_sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ jobs:
- name: Run tests
run: flutter test --coverage

- name: Run Rust library test
run: cd rust && cargo test

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ android {
compileSdkVersion 34
ndkVersion "26.3.11579264"

namespace "io.iden3.polygonid_flutter_sdk"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand Down
5 changes: 2 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ android {
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk{
// TODO: armeabi-v7a and x86 not supported yet
abiFilters 'arm64-v8a', 'x86_64' /*,'armeabi-v7a', 'x86',*/
ndk {
abiFilters 'arm64-v8a', 'x86_64'
}
}

Expand Down
194 changes: 0 additions & 194 deletions example/integration_test/app_test.dart

This file was deleted.

95 changes: 95 additions & 0 deletions example/integration_test/bjj_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import 'dart:ffi';
import 'dart:io';

import 'package:ffi/ffi.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:polygonid_flutter_sdk/common/utils/hex_utils.dart';
import 'package:polygonid_flutter_sdk/identity/libs/bjj/bjj.dart';

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

final lib = BabyjubjubLib();

group('Test point compress/uncompress', () {
const pointX =
"1213174356443492223913701748605807399689671830803048423391713277352597320264";
const pointY =
"7302787176091879756002280810960328852823951595761559038108460949327195887723";

const compressedPoint =
"6B58E72B1BB6DD8C2B20CB62E90F1AE7F7F054C059B962382643721B273B2510";

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

expect(
compressedPoint,
equals(compressedPoint),
);
});

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

expect(uncompressedPoint, isNotNull);
expect(uncompressedPoint![0], equals(pointX));
expect(uncompressedPoint[1], equals(pointY));
});
});

group("Message sign and signature verify", () {
const privateKey =
"85612f904a52e7eb2e0ab742ab1ae3de36561497fea24f1fc4619a5efc73eae8";
const message =
"6841496992415663132898117430955063618911128754688221768758387076131201387307";

const signature =
"740942df0bffc2f386d9d7e4e30be0981d54a2c16af82e85af1978459b489eafe0ab5d8e12f724f93998827f02a1624705d0ea22f92fd769901a1df7bfc87401";

testWidgets("Sign", (WidgetTester tester) async {
final signature = lib.signPoseidon(
privateKey,
message,
);

expect(signature, equals(signature));
});

testWidgets("Verify signature", (WidgetTester tester) async {
final valid = lib.verifyPoseidon(
privateKey,
signature,
message,
);

expect(valid, isTrue);
});
});

group("Private key to public key test", () {
const privateKey =
"85612f904a52e7eb2e0ab742ab1ae3de36561497fea24f1fc4619a5efc73eae8";

const expectedX =
"10642469561299443157177646279099633166785806044568900244804593097533061888748";
const expectedY =
"7588418921868074418607355872196117318956729766890665605182116638798290735907";

testWidgets("Private key to public", (WidgetTester tester) async {
final publicKeyRaw = lib.prv2pub(privateKey);

final stringList = publicKeyRaw.split(",");
stringList[0] = stringList[0].replaceAll("Fr(", "");
stringList[0] = stringList[0].replaceAll(")", "");
stringList[1] = stringList[1].replaceAll("Fr(", "");
stringList[1] = stringList[1].replaceAll(")", "");
BigInt x = HexUtils.hexToInt(stringList[0]);
BigInt y = HexUtils.hexToInt(stringList[1]);

expect(x.toString(), equals(expectedX));
expect(y.toString(), equals(expectedY));
});
});
}
Loading

0 comments on commit 0cf0d88

Please sign in to comment.