Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
232cc1f
feat: update aggregateVerifier function and example in android
grvgoel81 Sep 24, 2024
e9bc7ea
feat: added logout() function
grvgoel81 Sep 24, 2024
ba5fb57
feat: code cleanup
grvgoel81 Sep 27, 2024
3e45645
feat: Update SingleFactorAuthFlutterPlugin.swift
grvgoel81 Sep 27, 2024
4029c45
feat: Add example for logout.
grvgoel81 Sep 27, 2024
886e490
feat: update flutter android method channel and sfa android deps
grvgoel81 Nov 11, 2024
2889b07
feat: update flutter android code as per SFA android
grvgoel81 Nov 12, 2024
9eed7eb
feat: add getSessionData() in android and dart
grvgoel81 Nov 12, 2024
39f03fe
feat: update swift code
grvgoel81 Nov 28, 2024
7c9a0cc
feat: update swift code
grvgoel81 Dec 4, 2024
a579365
feat: update pubspec.lock
grvgoel81 Dec 4, 2024
21d041d
feat: update pnp android deps
grvgoel81 Dec 4, 2024
94458c3
Merge branch 'master' into feat/updates
grvgoel81 Dec 4, 2024
b9a296c
feat: update example and pubspec.yaml
grvgoel81 Dec 4, 2024
4beee3a
feat: update pnp android deps
grvgoel81 Dec 4, 2024
2f85648
feat: update SingleFactorAuthFlutterPlugin.swift
grvgoel81 Dec 4, 2024
647f322
feat: update pubspec.lock
grvgoel81 Dec 4, 2024
a36939d
feat: update SessionData from connect() and getSessionData()
grvgoel81 Dec 4, 2024
87f1543
feat: code refactoring and update sfa android sdk deps
grvgoel81 Dec 6, 2024
05f1117
feat: add connected() method
grvgoel81 Dec 6, 2024
e7a2e7c
feat: code refactored for getSessionData() in android
grvgoel81 Dec 6, 2024
b4f5ca6
feat: logout code refactored for null.
grvgoel81 Dec 6, 2024
3492a77
feat: update SFAParams class name to Web3AuthOptions
grvgoel81 Dec 20, 2024
abaad9c
feat: bump deps for min sessionTime updates.
grvgoel81 Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
implementation 'com.github.Web3Auth:single-factor-auth-android:1.2.0'
implementation 'com.github.Web3Auth:single-factor-auth-android:3.0.1'
implementation 'org.torusresearch:fetch-node-details-java:5.0.0'
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'com.google.code.gson:gson:2.10.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import androidx.annotation.NonNull
import com.google.gson.Gson
import com.web3auth.singlefactorauth.SingleFactorAuth
import com.web3auth.singlefactorauth.types.LoginParams
import com.web3auth.singlefactorauth.types.SFAKey
import com.web3auth.singlefactorauth.types.SFAParams
import com.web3auth.singlefactorauth.types.TorusSubVerifierInfo
import com.web3auth.singlefactorauth.types.SessionData
import com.web3auth.singlefactorauth.types.Web3AuthOptions
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
Expand All @@ -27,7 +26,7 @@ class SingleFactorAuthFlutterPlugin : FlutterPlugin, MethodCallHandler {
private lateinit var channel: MethodChannel
private lateinit var context: Context
private lateinit var singleFactorAuth: SingleFactorAuth
private lateinit var sfaParams: SFAParams
private lateinit var web3AuthOptions: Web3AuthOptions
private lateinit var loginParams: LoginParams
private var gson: Gson = Gson()

Expand Down Expand Up @@ -76,21 +75,17 @@ class SingleFactorAuthFlutterPlugin : FlutterPlugin, MethodCallHandler {
"init" -> {
val initArgs = call.arguments<String>()
val params = gson.fromJson(initArgs, SFAOptions::class.java)
sfaParams =
SFAParams(getNetwork(params.network), params.clientId, params.sessionTime)
singleFactorAuth = SingleFactorAuth(sfaParams, context)
web3AuthOptions =
Web3AuthOptions(params.clientId, getNetwork(params.network), params.sessionTime)
singleFactorAuth = SingleFactorAuth(web3AuthOptions, context)
return null
}

"initialize" -> {
try {
val sfaKey = singleFactorAuth.initialize(context)
Log.d("${SingleFactorAuthFlutterPlugin::class.qualifiedName}", "#initialize")
return if (sfaKey.get() != null) {
prepareResultFromSFAkey(sfaKey.get())
} else {
""
}
return null
} catch (e: Throwable) {
throw Error(e)
}
Expand All @@ -99,60 +94,58 @@ class SingleFactorAuthFlutterPlugin : FlutterPlugin, MethodCallHandler {
"connect" -> {
try {
val initArgs = call.arguments<String>()
val params = gson.fromJson(initArgs, Web3AuthOptions::class.java)
if (params.aggregateVerifier.isNullOrEmpty()) {
loginParams = LoginParams(
params.verifier, params.verifierId,
params.idToken
)
} else {
loginParams = LoginParams(
params.aggregateVerifier, params.verifierId,
params.idToken,
arrayOf(
TorusSubVerifierInfo(
params.verifier,
params.idToken
)
)
)
}
val sfaKeyCF = singleFactorAuth.connect(loginParams, context)
val loginParams = gson.fromJson(initArgs, LoginParams::class.java)
val sessionData = singleFactorAuth.connect(loginParams, context)
Log.d("${SingleFactorAuthFlutterPlugin::class.qualifiedName}", "#connect")
val sfaKey = sfaKeyCF
return prepareResult(sfaKey)
val result: SessionData = sessionData
return gson.toJson(result)
} catch (e: Throwable) {
throw Error(e)
}
}

"logout" -> {
try {
val logoutCF = singleFactorAuth.logout(context)
Log.d("${SingleFactorAuthFlutterPlugin::class.qualifiedName}", "#logout")
return null
} catch (e: Throwable) {
throw Error(e)
}
}

"isSessionIdExists" -> {
"getSessionData" -> {
try {
val result = singleFactorAuth.isSessionIdExists()
Log.d(
"${SingleFactorAuthFlutterPlugin::class.qualifiedName}",
"#isSessionIdExists"
"#getSessionData"
)
return result
singleFactorAuth.initialize(context).get()
var sessionData = singleFactorAuth.getSessionData()
val loginResult: SessionData? = sessionData
return if (loginResult == null) {
null
} else {
gson.toJson(loginResult)
}
} catch (e: Throwable) {
Log.e(
"${SingleFactorAuthFlutterPlugin::class.qualifiedName}",
"Error retrieving session data",
e
)
return gson.toJson(mapOf("error" to "Failed to retrieve session data"))
}
}

"connected" -> {
try {
return singleFactorAuth.isConnected()
} catch (e: Throwable) {
throw Error(e)
}
}
}
throw NotImplementedError()
}

private fun prepareResult(sfaKey: SFAKey?): String {
val hashMap: HashMap<String, String> = HashMap<String, String>(2)
hashMap["privateKey"] = sfaKey?.getPrivateKey() as String
hashMap["publicAddress"] = sfaKey?.getPublicAddress() as String
return gson.toJson(hashMap)
}

private fun prepareResultFromSFAkey(sfaKey: SFAKey): String {
val hashMap: HashMap<String, String> = HashMap<String, String>(2)
hashMap["privateKey"] = sfaKey.getPrivateKey() as String ?: ""
hashMap["publicAddress"] = sfaKey.getPublicAddress() as String ?: ""
return gson.toJson(hashMap)
}
}

This file was deleted.

40 changes: 21 additions & 19 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
PODS:
- BigInt (5.2.0)
- curvelib.swift (1.0.1)
- curvelib.swift (2.0.0)
- Flutter (1.0.0)
- JWTDecode (3.2.0)
- KeychainSwift (20.0.0)
- single_factor_auth_flutter (0.0.1):
- Flutter
- SingleFactorAuth (= 8.0.0)
- SingleFactorAuth (8.0.0):
- curvelib.swift (~> 1.0.1)
- Torus-fetchNodeDetails (~> 6.0.3)
- Torus-utils (~> 9.0.1)
- TorusSessionManager (~> 5.0.0)
- Torus-fetchNodeDetails (6.0.3):
- SingleFactorAuth (= 9.0.4)
- SingleFactorAuth (9.0.4):
- JWTDecode (~> 3.2)
- Torus-utils (~> 10.0.0)
- TorusSessionManager (~> 6.0.2)
- Torus-fetchNodeDetails (8.0.0):
- BigInt (~> 5.2.0)
- Torus-utils (9.0.1):
- curvelib.swift (~> 1.0.1)
- Torus-fetchNodeDetails (~> 6.0.3)
- TorusSessionManager (5.0.0):
- curvelib.swift (~> 1.0.1)
- Torus-utils (10.0.0):
- curvelib.swift (~> 2.0.0)
- Torus-fetchNodeDetails (~> 8.0.0)
- TorusSessionManager (6.0.2):
- curvelib.swift (~> 2.0.0)
- KeychainSwift (~> 20.0.0)

DEPENDENCIES:
Expand All @@ -28,6 +28,7 @@ SPEC REPOS:
trunk:
- BigInt
- curvelib.swift
- JWTDecode
- KeychainSwift
- SingleFactorAuth
- Torus-fetchNodeDetails
Expand All @@ -42,14 +43,15 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
BigInt: f668a80089607f521586bbe29513d708491ef2f7
curvelib.swift: d0746ae82bee34016c06da3567a97e493b3c979f
curvelib.swift: b9223e5cac801effed8a5fe8968e952b3fe427a5
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
JWTDecode: 7dae24cb9bf9b608eae61e5081029ec169bb5527
KeychainSwift: 0ce6a4d13f7228054d1a71bb1b500448fb2ab837
single_factor_auth_flutter: 9617e5ffce9c0251bddb19cbe49293f921c13b79
SingleFactorAuth: 2bfa8ad0fe8d0023fffdf1a5f0c9634ca3ee66d8
Torus-fetchNodeDetails: 6c349f47cbca36a4b3f276fe26d03c1b39b20949
Torus-utils: 1d23e6eedf9ee7df9ecc2605b765ad68eb194f71
TorusSessionManager: 42c21f100d895976fabe3806cb9c575392f6e424
single_factor_auth_flutter: aab0e8cb32b6e76fe5cb8a2036489367bc549338
SingleFactorAuth: 6a2639e2d25d4cec901753193b97f8503734734d
Torus-fetchNodeDetails: 2a5fbb222ec28af4128d64e4c2d520c7db456b78
Torus-utils: 4a1db3d9c1aa221df312ffa7ec154e7e4719850a
TorusSessionManager: 3c47c2a4c4d6173a10006eb0af4b86317ee45ff8

PODFILE CHECKSUM: d5c402b2f74646de5c7f24c1231886362b49b38f

Expand Down
74 changes: 44 additions & 30 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:developer';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:single_factor_auth_flutter/enums.dart';
import 'package:single_factor_auth_flutter/input.dart';
import 'package:single_factor_auth_flutter/output.dart';
import 'package:single_factor_auth_flutter/single_factor_auth_flutter.dart';
Expand All @@ -21,7 +22,7 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {
final _singleFactorAuthFlutterPlugin = SingleFactAuthFlutter();
final _singleFactorAuthFlutterPlugin = SingleFactorAuthFlutter();
String _result = '';
bool logoutVisible = false;
Web3AuthNetwork web3AuthNetwork = Web3AuthNetwork.sapphire_mainnet;
Expand All @@ -35,31 +36,27 @@ class _MyAppState extends State<MyApp> {
Future<void> initSdk() async {
if (Platform.isAndroid) {
await init();
if (await _singleFactorAuthFlutterPlugin.isSessionIdExists()) {
initialize();
}
getSessionData();
} else if (Platform.isIOS) {
await init();
if (await _singleFactorAuthFlutterPlugin.isSessionIdExists()) {
initialize();
}
getSessionData();
} else {}
}

Future<void> init() async {
await _singleFactorAuthFlutterPlugin.init(SFAParams(
await _singleFactorAuthFlutterPlugin.init(Web3AuthOptions(
network: web3AuthNetwork,
clientId: 'YOUR_CLIENT_ID',
sessionTime: 86400));
}

Future<void> initialize() async {
log("initialize() called");
final SFAKey? sfaKey = await _singleFactorAuthFlutterPlugin.initialize();
if (sfaKey != null) {
Future<void> getSessionData() async {
log("getSessionData() called");
final SessionData? sessionData =
await _singleFactorAuthFlutterPlugin.getSessionData();
if (sessionData?.publicAddress != null) {
setState(() {
_result =
"Public Add : ${sfaKey.publicAddress} , Private Key : ${sfaKey.privateKey}";
_result = "Session Data: ${sessionData.toString()}";
});
}
}
Expand Down Expand Up @@ -139,14 +136,13 @@ class _MyAppState extends State<MyApp> {
);
}

VoidCallback _getKey(Future<SFAKey> Function() method) {
VoidCallback _getKey(Future<SessionData> Function() method) {
return () async {
try {
final SFAKey response = await method();
final SessionData sessionData = await method();
setState(() {
_result =
"Public Add : ${response.publicAddress} , Private Key : ${response.privateKey}";
log(response.publicAddress);
_result = "Session Data: ${sessionData.toString()}";
log("Full Session Data: ${sessionData.toString()}");
});
} on MissingParamException catch (error) {
log("Missing Param: ${error.paramName}");
Expand All @@ -160,25 +156,43 @@ class _MyAppState extends State<MyApp> {

Future<void> _initialize() async {
try {
final SFAKey? response =
await _singleFactorAuthFlutterPlugin.initialize();
final SessionData? sessionData =
await _singleFactorAuthFlutterPlugin.getSessionData();

setState(() {
_result =
"Public Add : ${response?.publicAddress} , Private Key : ${response?.privateKey}";
log(response!.publicAddress);
_result = "Session Data: ${sessionData.toString()}";
});
} on PrivateKeyNotGeneratedException {
log("Private key not generated");
} on UnKnownException {
log("Unknown exception occurred");
} catch (e, stackTrace) {
log("An unexpected error occurred: $e");
log("Stack trace: $stackTrace");
}
}

Future<SFAKey> getKey() {
//Get key example
Future<SessionData> getKey() {
return _singleFactorAuthFlutterPlugin.connect(LoginParams(
verifier: 'torus-test-health',
verifierId: 'hello@tor.us',
idToken: Utils().es256Token("hello@tor.us"),
verifier: 'torus-test-health',
verifierId: 'hello@tor.us',
idToken: Utils().es256Token("hello@tor.us"),
));
}

//Aggregate verifier key example
Future<SessionData> getAggregateKey() {
return _singleFactorAuthFlutterPlugin.connect(LoginParams(
verifier: 'torus-aggregate-sapphire-mainnet',
verifierId: 'devnettestuser@tor.us',
idToken: Utils().es256Token("devnettestuser@tor.us"),
subVerifierInfoArray: [
TorusSubVerifierInfo(
'torus-test-health', Utils().es256Token("devnettestuser@tor.us"))
]));
}

//Logout example
Future<void> logout() {
return _singleFactorAuthFlutterPlugin.logout();
}
}
Loading