Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom EWS storage #21

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
else
{
iterationCount = DEPRECATED_ITERATION_COUNT;
iterationCount = CURRENT_ITERATION_COUNT;
}

byte[] key = GetEncryptionKey(password, salt, iterationCount);
Expand All @@ -52,7 +52,7 @@
var tag = new byte[TAG_SIZE];
Array.Copy(ciphertextWithTag, ciphertextSize, tag, 0, tag.Length);
encodedShare = new byte[ciphertext.Length];
using AesGcm crypto = new(key);

Check warning on line 55 in Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Encryption/EmbeddedWallet.Cryptography.cs

View workflow job for this annotation

GitHub Actions / build-test-cov

'AesGcm.AesGcm(byte[])' is obsolete: 'AesGcm should indicate the required tag size for encryption and decryption. Use a constructor that accepts the tag size.' (https://aka.ms/dotnet-warnings/SYSLIB0053)

Check warning on line 55 in Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Encryption/EmbeddedWallet.Cryptography.cs

View workflow job for this annotation

GitHub Actions / build-test-cov

'AesGcm.AesGcm(byte[])' is obsolete: 'AesGcm should indicate the required tag size for encryption and decryption. Use a constructor that accepts the tag size.' (https://aka.ms/dotnet-warnings/SYSLIB0053)

Check warning on line 55 in Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Encryption/EmbeddedWallet.Cryptography.cs

View workflow job for this annotation

GitHub Actions / build-test-cov

'AesGcm.AesGcm(byte[])' is obsolete: 'AesGcm should indicate the required tag size for encryption and decryption. Use a constructor that accepts the tag size.' (https://aka.ms/dotnet-warnings/SYSLIB0053)
crypto.Decrypt(iv, ciphertext, tag, encodedShare);
}
catch (CryptographicException)
Expand Down Expand Up @@ -88,7 +88,7 @@
{
var tag = new byte[TAG_SIZE];
encryptedShare = new byte[encodedShare.Length];
using AesGcm crypto = new(key);

Check warning on line 91 in Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Encryption/EmbeddedWallet.Cryptography.cs

View workflow job for this annotation

GitHub Actions / build-test-cov

'AesGcm.AesGcm(byte[])' is obsolete: 'AesGcm should indicate the required tag size for encryption and decryption. Use a constructor that accepts the tag size.' (https://aka.ms/dotnet-warnings/SYSLIB0053)

Check warning on line 91 in Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Encryption/EmbeddedWallet.Cryptography.cs

View workflow job for this annotation

GitHub Actions / build-test-cov

'AesGcm.AesGcm(byte[])' is obsolete: 'AesGcm should indicate the required tag size for encryption and decryption. Use a constructor that accepts the tag size.' (https://aka.ms/dotnet-warnings/SYSLIB0053)

Check warning on line 91 in Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Encryption/EmbeddedWallet.Cryptography.cs

View workflow job for this annotation

GitHub Actions / build-test-cov

'AesGcm.AesGcm(byte[])' is obsolete: 'AesGcm should indicate the required tag size for encryption and decryption. Use a constructor that accepts the tag size.' (https://aka.ms/dotnet-warnings/SYSLIB0053)
crypto.Encrypt(iv, encodedShare, encryptedShare, tag);
encryptedShare = encryptedShare.Concat(tag).ToArray();
}
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
Loading