Skip to content

Commit

Permalink
Feature/get account list (#166)
Browse files Browse the repository at this point in the history
* Added get account list intent - this allows a user to check the accounts/login methods associated with a wallet address; useful for account federation

* increment package version
  • Loading branch information
BellringerQuinn authored Aug 22, 2024
1 parent ced06ba commit 5d227ee
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Assets/SequenceSDK/WaaS/Tests/MockWaaSWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,12 @@ public Task<IntentResponseSessionAuthProof> GetSessionAuthProof(Chain network, s
{
throw new NotImplementedException();
}

public event Action<IntentResponseAccountList> OnAccountListGenerated;
public event Action<string> OnFailedToGenerateAccountList;
public Task<IntentResponseAccountList> GetAccountList()
{
throw new NotImplementedException();
}
}
}
30 changes: 30 additions & 0 deletions Assets/SequenceSDK/WaaS/Tests/WaaSSessionManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,35 @@ public async Task TestGetSessionAuthProof()

await tcs.Task;
}

[Test]
public async Task TestListAccounts()
{
var tcs = new TaskCompletionSource<bool>();
EndToEndTestHarness testHarness = new EndToEndTestHarness();

testHarness.Login(async wallet =>
{
try
{
IntentResponseAccountList list = await wallet.GetAccountList();
Assert.IsNotNull(list);
Assert.False(string.IsNullOrWhiteSpace(list.currentAccountId));
Assert.IsNotNull(list.accounts);
Assert.Greater(list.accounts.Length, 0);

tcs.TrySetResult(true);
}
catch (System.Exception e)
{
tcs.TrySetException(e);
}
}, (error, method, email, methods) =>
{
tcs.TrySetException(new Exception(error));
});

await tcs.Task;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Newtonsoft.Json;

namespace Sequence.EmbeddedWallet
{
[Serializable]
public class IntentDataListAccounts
{
public string wallet;

public IntentDataListAccounts(string walletAddress)
{
this.wallet = walletAddress;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public IntentPayload(string version, IntentType type, JObject data, Signature[]
{IntentType.SessionAuthProof, "sessionAuthProof"},
{IntentType.InitiateAuth, "initiateAuth"},
{IntentType.FederateAccount, "federateAccount"},
{IntentType.ListAccounts, "listAccounts"},
};
}

Expand All @@ -84,6 +85,7 @@ public enum IntentType
SessionAuthProof,
InitiateAuth,
FederateAccount,
ListAccounts,
None
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ public class Account
public IdentityType identityType;
public string issuer;

public Account(string id, string identityType, string issuer, string email)
public Account(string id, string type, string issuer, string email)
{
this.id = id;
this.identityType = identityType.GetIdentityType();
this.identityType = type.GetIdentityType();
this.issuer = issuer;
this.email = email;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Sequence.EmbeddedWallet
{
public class IntentResponseAccountList
{
public Account[] accounts;
public string currentAccountId;

public IntentResponseAccountList(Account[] accounts, string currentAccountId)
{
this.accounts = accounts;
this.currentAccountId = currentAccountId;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,16 @@ public Task<TransactionReturn> SendTransactionWithFeeOptions(Chain network, Tran
/// <param name="nonce"></param>
/// <returns></returns>
public Task<IntentResponseSessionAuthProof> GetSessionAuthProof(Chain network, string nonce = null);

public event Action<IntentResponseAccountList> OnAccountListGenerated;
public event Action<string> OnFailedToGenerateAccountList;

/// <summary>
/// Get a list of Accounts associated with this wallet
///
/// Can be awaited directly or you can subscribe to the OnAccountListGenerated and OnFailedToGenerateAccountList events to get success and failed responses respectively
/// </summary>
/// <returns></returns>
public Task<IntentResponseAccountList> GetAccountList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,5 +392,23 @@ public async Task<IntentResponseSessionAuthProof> GetSessionAuthProof(Chain netw
return null;
}
}

public event Action<IntentResponseAccountList> OnAccountListGenerated;
public event Action<string> OnFailedToGenerateAccountList;

public async Task<IntentResponseAccountList> GetAccountList()
{
try
{
var result = await _intentSender.SendIntent<IntentResponseAccountList, IntentDataListAccounts>(new IntentDataListAccounts(_address), IntentType.ListAccounts);
OnAccountListGenerated?.Invoke(result);
return result;
}
catch (Exception e)
{
OnFailedToGenerateAccountList?.Invoke("Failed to generate account list: " + e.Message);
return null;
}
}
}
}
2 changes: 1 addition & 1 deletion Packages/Sequence-Unity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xyz.0xsequence.waas-unity",
"version": "3.4.2",
"version": "3.5.0",
"displayName": "Sequence Embedded Wallet SDK",
"description": "A Unity SDK for the Sequence WaaS API",
"unity": "2021.3",
Expand Down

0 comments on commit 5d227ee

Please sign in to comment.