Skip to content

Commit 7ebe426

Browse files
authored
Merge pull request #223 from 0xsequence/Feature/getEmailFromWallet
Add ability to get email from sequence wallet
2 parents 16d55b3 + 6400b9f commit 7ebe426

File tree

7 files changed

+44
-12
lines changed

7 files changed

+44
-12
lines changed

Assets/SequenceSDK/WaaS/Tests/MockWaaSWallet.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,10 @@ public Task<IntentResponseGetIdToken> GetIdToken(string nonce = null)
9999
{
100100
throw new NotImplementedException();
101101
}
102+
103+
public string GetEmail()
104+
{
105+
throw new NotImplementedException();
106+
}
102107
}
103108
}

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/EOAWalletToSequenceWalletAdapter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ public Task<IntentResponseGetIdToken> GetIdToken(string nonce = null)
314314
{
315315
throw new NotSupportedException();
316316
}
317+
318+
public string GetEmail()
319+
{
320+
throw new NotSupportedException();
321+
}
317322
}
318323
#endregion
319324

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IWallet.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ public Task<TransactionReturn> SendTransactionWithFeeOptions(Chain network, Tran
160160
public event Action<IntentResponseGetIdToken> OnIdTokenRetrieved;
161161
public event Action<string> OnFailedToRetrieveIdToken;
162162

163+
/// <summary>
164+
/// Get an idToken JWT issued from the Sequence API
165+
/// </summary>
166+
/// <param name="nonce"></param>
167+
/// <returns></returns>
163168
public Task<IntentResponseGetIdToken> GetIdToken(string nonce = null);
169+
170+
/// <summary>
171+
/// Get the email associated with this session
172+
/// </summary>
173+
/// <returns></returns>
174+
public string GetEmail();
164175
}
165176
}

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceLogin.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ private void Configure()
214214

215215
private void TryToLoginWithStoredSessionWallet()
216216
{
217-
(EOAWallet, string) walletInfo = (null, "");
217+
(EOAWallet, string, string) walletInfo = (null, "", "");
218218
try
219219
{
220220
walletInfo = AttemptToCreateWalletFromSecureStorage();
@@ -234,7 +234,7 @@ private void TryToLoginWithStoredSessionWallet()
234234

235235
_sessionId = IntentDataOpenSession.CreateSessionId(_sessionWallet.GetAddress());
236236

237-
SequenceWallet wallet = new SequenceWallet(new Address(walletInfo.Item2), _sessionId, new IntentSender(new HttpClient(WaaSWithAuthUrl), walletInfo.Item1, _sessionId, _waasProjectId, _waasVersion));
237+
SequenceWallet wallet = new SequenceWallet(new Address(walletInfo.Item2), _sessionId, new IntentSender(new HttpClient(WaaSWithAuthUrl), walletInfo.Item1, _sessionId, _waasProjectId, _waasVersion), walletInfo.Item3);
238238

239239
EnsureSessionIsValid(wallet);
240240
}
@@ -268,19 +268,24 @@ private async Task EnsureSessionIsValid(SequenceWallet wallet)
268268
FailedLoginWithStoredSessionWallet("Stored session wallet is not active");
269269
}
270270

271-
private (EOAWallet, string) AttemptToCreateWalletFromSecureStorage()
271+
private (EOAWallet, string, string) AttemptToCreateWalletFromSecureStorage()
272272
{
273273
ISecureStorage secureStorage = SecureStorageFactory.CreateSecureStorage();
274274
string walletInfo = secureStorage.RetrieveString(Application.companyName + "-" + Application.productName + "-" + _walletKey);
275275
if (string.IsNullOrEmpty(walletInfo))
276276
{
277-
return (null, "");
277+
return (null, "", "");
278278
}
279279
string[] walletInfoSplit = walletInfo.Split('-');
280280
string privateKey = walletInfoSplit[0];
281281
string walletAddress = walletInfoSplit[1];
282+
string email = "";
283+
if (walletInfoSplit.Length == 3)
284+
{
285+
email = walletInfoSplit[2];
286+
}
282287
EOAWallet wallet = new EOAWallet(privateKey);
283-
return (wallet, walletAddress);
288+
return (wallet, walletAddress, email);
284289
}
285290

286291
public event ILogin.OnLoginSuccessHandler OnLoginSuccess;
@@ -374,7 +379,7 @@ public async Task ConnectToWaaS(IntentDataOpenSession loginIntent, LoginMethod m
374379
string sessionId = registerSessionResponse.sessionId;
375380
walletAddress = registerSessionResponse.wallet;
376381
OnLoginSuccess?.Invoke(sessionId, walletAddress);
377-
SequenceWallet wallet = new SequenceWallet(new Address(walletAddress), sessionId, new IntentSender(new HttpClient(SequenceLogin.WaaSWithAuthUrl), _sessionWallet, sessionId, _waasProjectId, _waasVersion));
382+
SequenceWallet wallet = new SequenceWallet(new Address(walletAddress), sessionId, new IntentSender(new HttpClient(SequenceLogin.WaaSWithAuthUrl), _sessionWallet, sessionId, _waasProjectId, _waasVersion), email);
378383
PlayerPrefs.SetInt(WaaSLoginMethod, (int)method);
379384
PlayerPrefs.SetString(OpenIdAuthenticator.LoginEmail, email);
380385
PlayerPrefs.Save();
@@ -415,7 +420,7 @@ public async Task ConnectToWaaS(IntentDataOpenSession loginIntent, LoginMethod m
415420
{
416421
if (_storeSessionWallet && SecureStorageFactory.IsSupportedPlatform())
417422
{
418-
StoreWalletSecurely(walletAddress);
423+
StoreWalletSecurely(walletAddress, email);
419424
}
420425
}
421426
catch (Exception e)
@@ -596,13 +601,13 @@ public async Task ConnectToWaaSAsGuest()
596601
await connector.ConnectToWaaSViaGuest();
597602
}
598603

599-
private void StoreWalletSecurely(string waasWalletAddress)
604+
private void StoreWalletSecurely(string waasWalletAddress, string email)
600605
{
601606
ISecureStorage secureStorage = SecureStorageFactory.CreateSecureStorage();
602607
byte[] privateKeyBytes = new byte[32];
603608
_sessionWallet.privKey.WriteToSpan(privateKeyBytes);
604609
string privateKey = privateKeyBytes.ByteArrayToHexString();
605-
secureStorage.StoreString(Application.companyName + "-" + Application.productName + "-" + _walletKey, privateKey + "-" + waasWalletAddress);
610+
secureStorage.StoreString(Application.companyName + "-" + Application.productName + "-" + _walletKey, privateKey + "-" + waasWalletAddress + "-" + email);
606611
}
607612

608613
public async Task FederateAccount(IntentDataFederateAccount federateAccount, LoginMethod method, string email)

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceWallet.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ public class SequenceWallet : IWallet
2222
private IIntentSender _intentSender;
2323
private const string _sequenceCreatedContractEvent = "CreatedContract(address)";
2424
private string _builderApiKey;
25+
private string _email;
2526

26-
public SequenceWallet(Address address, string sessionId, IIntentSender intentSender)
27+
public SequenceWallet(Address address, string sessionId, IIntentSender intentSender, string email = "")
2728
{
2829
_address = address;
2930
_httpClient = new HttpClient("https://api.sequence.app/rpc");
3031
_intentSender = intentSender;
3132
SessionId = sessionId;
3233
_builderApiKey = SequenceConfig.GetConfig().BuilderAPIKey;
34+
_email = email;
3335
}
3436

3537
public Address GetWalletAddress()
@@ -440,5 +442,9 @@ public async Task<IntentResponseGetIdToken> GetIdToken(string nonce = null)
440442
}
441443
}
442444

445+
public string GetEmail()
446+
{
447+
return _email;
448+
}
443449
}
444450
}

Packages/Sequence-Unity/Sequence/SequenceSDK/Relayer/MintingRequestProofValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class MintingRequestProofValidator
1515
{
1616
public static async Task<bool> IsValidMintingRequestProof(Chain chain, MintingRequestProof proof)
1717
{
18-
SequenceWallet wallet = new SequenceWallet(proof.SigningAddress, null, null);
18+
SequenceWallet wallet = new SequenceWallet(proof.SigningAddress, null, null, "");
1919

2020
try
2121
{

Packages/Sequence-Unity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xyz.0xsequence.waas-unity",
3-
"version": "3.12.1",
3+
"version": "3.13.0",
44
"displayName": "Sequence Embedded Wallet SDK",
55
"description": "A Unity SDK for the Sequence WaaS API",
66
"unity": "2021.3",

0 commit comments

Comments
 (0)