Skip to content

Commit

Permalink
Allow custom EWS storage (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFirekeeper authored May 15, 2024
1 parent bd059d4 commit 008102b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private string DecryptShare(string encryptedShare, string password)
}
else
{
iterationCount = DEPRECATED_ITERATION_COUNT;
iterationCount = CURRENT_ITERATION_COUNT;
}

byte[] key = GetEncryptionKey(password, salt, iterationCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ internal partial class LocalStorage : LocalStorageBase
private readonly Storage storage;
private readonly string filePath;

internal LocalStorage(string clientId)
internal LocalStorage(string clientId, string storageDirectoryPath = null)
{
string directory;
#if UNITY_5_3_OR_NEWER
directory = Application.persistentDataPath;
#else
directory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
directory = storageDirectoryPath ?? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
// Console.WriteLine($"Embedded Wallet Storage: Using '{directory}'");
#endif
directory = Path.Combine(directory, "EWS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ internal partial class EmbeddedWallet
private const int KEY_SIZE = 256 / 8;
private const int TAG_SIZE = 16;
private const int CURRENT_ITERATION_COUNT = 650_000;
private const int DEPRECATED_ITERATION_COUNT = 5_000_000;
private const string WALLET_PRIVATE_KEY_PREFIX = "thirdweb_";
private const string ENCRYPTION_SEPARATOR = ":";

public EmbeddedWallet(ThirdwebClient client)
public EmbeddedWallet(ThirdwebClient client, string storageDirectoryPath = null)
{
localStorage = new LocalStorage(client.ClientId);
localStorage = new LocalStorage(client.ClientId, storageDirectoryPath);
server = new Server(client.ClientId, client.BundleId, "dotnet", Constants.VERSION, client.SecretKey);
ivGenerator = new IvGenerator();
}
Expand Down
10 changes: 8 additions & 2 deletions Thirdweb/Thirdweb.Wallets/InAppWallet/InAppWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ internal InAppWallet(ThirdwebClient client, string email, string phoneNumber, st
_authProvider = authProvider;
}

public static async Task<InAppWallet> Create(ThirdwebClient client, string email = null, string phoneNumber = null, AuthProvider authprovider = AuthProvider.Default)
public static async Task<InAppWallet> Create(
ThirdwebClient client,
string email = null,
string phoneNumber = null,
AuthProvider authprovider = AuthProvider.Default,
string storageDirectoryPath = null
)
{
if (string.IsNullOrEmpty(email) && string.IsNullOrEmpty(phoneNumber) && authprovider == AuthProvider.Default)
{
Expand All @@ -46,7 +52,7 @@ public static async Task<InAppWallet> Create(ThirdwebClient client, string email
_ => throw new ArgumentException("Invalid AuthProvider"),
};

var embeddedWallet = new EmbeddedWallet(client);
var embeddedWallet = new EmbeddedWallet(client, storageDirectoryPath);
EthECKey ecKey;
try
{
Expand Down

0 comments on commit 008102b

Please sign in to comment.