Skip to content

Commit 99bc653

Browse files
refactor!: introduces namespacing, error classes and renames legacy types (#14)
* Initial refactoring Namespaced everything Json fileds to properties Enums for types (instead of strings) DateTime conversion for view models. PlayerPrefs type safety Enums formatting * Added additional editorconfig options for clarity * Renamed RpcProvider to EthereumWalletProvider. * Fixed refactor names. * Additional post refactor fix. * Dotnet format * Exception cleanup * IDisposable for EmbeddedWalletManager so it can properly cleanup listeners. * Added SafeFireAndForget to Utils since we use it in multiple places. * PrivyUser is now internal exposing just an interface. * PR cleanup Added null‑checks/try‑catches in token helpers and unsubscribed auth event Corrected .editorconfig key Hardened README samples Added InternalError enum & refined OTP error mapping Used SafeFireAndForget with logging for initialization Fixed misleading exception message in wallet manager * PR Feedback EmbeddedWallets -> EmbeddedEthereumWallets EmbeddedWallets is deprecated, use EmbeddedEthereumWallets now. * Updated PrivyUser to use new EmbeddedEthereumWallets Updated PrivyUser to use new EmbeddedEthereumWallets * Harden exception handling Harden exception handling by using numeric status codes instead of parsing string values. * Update SDK/README.md Remove extra comment Co-authored-by: Lucas Lois <lucas.lois@privy.io> * Update SDK/README.md Explicit types Co-authored-by: Lucas Lois <lucas.lois@privy.io> * Update SDK/README.md removed internal comment Co-authored-by: Lucas Lois <lucas.lois@privy.io> * Doc update * Update preferred modifier order * Made TaskExtension internal. * Remove ms conversion logic. * Rename CreateWallet -> CreateEthereumWallet * Renamed CreateWalletAtHdIndex -> CreateEthereumWalletAtHdIndex * Update enums to reflect OAuth * Addressed PR feedback. --------- Co-authored-by: Lucas Lois <lucas.lois@privy.io>
1 parent 8516a08 commit 99bc653

125 files changed

Lines changed: 915 additions & 766 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ csharp_space_before_colon_in_inheritance_clause = true
3434
csharp_space_after_colon_in_inheritance_clause = true
3535

3636
# Expression-level preferences
37+
38+
# prefer auto-properties over manual backing fields
39+
dotnet_style_prefer_auto_properties = true:suggestion
40+
41+
# prefer expression-bodied members when simple
42+
csharp_style_expression_bodied_methods = true:suggestion
43+
3744
dotnet_style_object_initializer = true:error
3845
dotnet_style_collection_initializer = true:error
3946

@@ -88,3 +95,6 @@ dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case_style
8895

8996
dotnet_naming_symbols.types.applicable_kinds = class, struct, enum, delegate
9097
dotnet_naming_symbols.types.applicable_accessibilities = *
98+
99+
# Modifier order preferences
100+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion

CONTRIBUTING.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22

33
For questions or support, email <support@privy.io>.
44

5-
## Formatting
65

7-
This project uses [`dotnet format`](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-format)
8-
with an `.editorconfig` to enforce a consistent C# code style.
9-
CI will reject pull requests that contain unformatted code.
6+
### Code style & formatting
7+
8+
We use `dotnet format` together with an `.editorconfig` file to enforce
9+
consistent C# style and catch simple linting issues. A few rules worth
10+
highlighting:
11+
12+
* `dotnet_style_prefer_auto_properties = true` – always prefer auto‑properties
13+
to manually backed fields.
14+
* `csharp_style_expression_bodied_methods = true` – use expression
15+
bodies for short methods.* Naming rules enforce `PascalCase` for enums, types, constants and public
16+
members, and `I` prefix for interfaces.
17+
18+
The `.editorconfig` in the repo contains additional options; see the
19+
[Microsoft code style documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/code-style-rule-options)
20+
for a complete list.
1021

1122
**Set up the pre-commit hook** (auto-formats staged files on every commit):
1223

SDK/README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,33 @@ If you are contributing to the Privy SDK codebase, **read
3030
### Initialization
3131

3232
```csharp
33+
using Privy.Core;
34+
using Privy.Config;
35+
3336
var config = new PrivyConfig{
3437
AppId = "YOUR_APP_ID",
3538
ClientId = "CLIENT_ID"
3639
};
3740

41+
// synchronous initialization – returns the SDK instance immediately
3842
PrivyManager.Initialize(config);
3943
```
4044

4145
### Check user's authentication state
4246

4347
When the Privy SDK is initialized, it will automatically begin to load its necessary
4448
dependencies and restoring user session data.
45-
By awaiting on `GetAuthState` you can ensure the SDK will be ready to use in full
46-
after returning.
49+
By awaiting on `GetAuthState` you can ensure the SDK has finished its
50+
background setup before proceeding; this call will block until initialization completes.
4751

4852
```csharp
4953
var authState = await PrivyManager.Instance.GetAuthState();
5054

5155
switch (authState) {
5256
case AuthState.Authenticated:
5357
// User is authenticated. Grab the user's linked accounts
54-
var privyUser = await PrivyManager.Instance.GetUser();
55-
var linkedAccounts = privyUser.LinkedAccounts;
58+
var user = await PrivyManager.Instance.GetUser();
59+
var linkedAccounts = user.LinkedAccounts;
5660
break;
5761
case AuthState.Unauthenticated:
5862
// User is not authenticated.
@@ -82,21 +86,22 @@ try {
8286
}
8387
```
8488

85-
### PrivyUser
89+
### PrivyUser (`IPrivyUser`)
90+
91+
The SDK exposes the authenticated user as an interface. Refer to `IPrivyUser` for details.
8692

8793
```csharp
88-
PrivyUser user = PrivyManager.Instance.User;
94+
IPrivyUser user = await PrivyManager.Instance.GetUser();
8995
```
90-
9196
### Creating an Embedded Wallet
9297

9398
```csharp
9499
try {
95-
PrivyUser privyUser = PrivyManager.Instance.User;
100+
IPrivyUser privyUser = await PrivyManager.Instance.GetUser();
96101

97102
if (privyUser != null) {
98-
IEmbeddedWallet wallet = await PrivyManager.Instance.User.CreateWallet();
99-
Debug.Log("New wallet created with address: " + wallet.address);
103+
IEmbeddedEthereumWallet wallet = await privyUser.CreateEthereumWallet();
104+
Debug.Log("New wallet created with address: " + wallet.Address);
100105
}
101106
} catch {
102107
Debug.Log("Error creating embedded wallet.");
@@ -107,7 +112,23 @@ try {
107112

108113
```csharp
109114
try {
110-
IEmbeddedWallet embeddedWallet = PrivyManager.Instance.User.EmbeddedWallets[0];
115+
// obtain the current user and ensure they're authenticated
116+
IPrivyUser privyUser = await PrivyManager.Instance.GetUser();
117+
if (privyUser == null)
118+
{
119+
Debug.LogWarning("No authenticated user – cannot perform RPC request.");
120+
return;
121+
}
122+
123+
// make sure there is at least one embedded wallet available
124+
IEmbeddedEthereumWallet[] wallets = privyUser.EmbeddedEthereumWallets;
125+
if (wallets == null || wallets.Count == 0)
126+
{
127+
Debug.LogWarning("No embedded wallets found for user.");
128+
return;
129+
}
130+
131+
IEmbeddedEthereumWallet embeddedWallet = wallets[0];
111132

112133
var rpcRequest = new RpcRequest
113134
{

SDK/Runtime/Analytics/ClientAnalyticsIdRepository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using Privy.Internal.Storage;
3+
using Privy.Utils;
24

3-
namespace Privy
5+
namespace Privy.Analytics
46
{
57
public class ClientAnalyticsIdRepository : IClientAnalyticsIdRepository
68
{

SDK/Runtime/Analytics/IAnalyticsManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Threading.Tasks;
22

3-
namespace Privy
3+
namespace Privy.Analytics
44
{
55
internal interface IAnalyticsManager
66
{

SDK/Runtime/Analytics/IAnalyticsRepository.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Threading.Tasks;
3+
using Privy.Internal.Networking;
34
using Newtonsoft.Json;
5+
using Privy.Utils;
46

5-
namespace Privy
7+
namespace Privy.Analytics
68
{
79
internal interface IAnalyticsRepository
810
{
@@ -12,10 +14,10 @@ internal interface IAnalyticsRepository
1214
internal class AnalyticsEventRequestData
1315
{
1416
[JsonProperty("event_name")]
15-
public string EventName;
17+
public string EventName { get; set; }
1618

1719
[JsonProperty("client_id")]
18-
public string ClientId;
20+
public string ClientId { get; set; }
1921
}
2022

2123
class AnalyticsRepository : IAnalyticsRepository

SDK/Runtime/Analytics/IClientAnalyticsIdRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Privy
1+
namespace Privy.Analytics
22
{
33
public interface IClientAnalyticsIdRepository
44
{

0 commit comments

Comments
 (0)