Skip to content

Commit

Permalink
Cache config. Pass 'X-Access-Key' header (builder api key) when makin…
Browse files Browse the repository at this point in the history
…g IsValidSignature request
  • Loading branch information
BellringerQuinn committed Dec 18, 2023
1 parent 8887a2a commit 31bdfa2
Show file tree
Hide file tree
Showing 10 changed files with 508 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Assets/SequenceExamples/Scripts/UI/LoginPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ protected override void Awake()
config.IdentityPoolId,
config.KMSEncryptionKeyId,
config.CognitoClientId),
config.WaaSProjectId, config.WaaSVersion, config.BuilderAPIKey_Prod);
config.WaaSProjectId,
config.WaaSVersion);
SetupLoginHandler(loginHandler);

_loginSuccessPage = GetComponentInChildren<LoginSuccessPage>();
Expand Down
11 changes: 8 additions & 3 deletions Assets/SequenceSDK/Config/SequenceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ public class SequenceConfig : ScriptableObject
public string BuilderAPIKey_Prod;
public string BuilderAPIKey_Dev;

private static SequenceConfig _config;

public static SequenceConfig GetConfig()
{
SequenceConfig config = Resources.Load<SequenceConfig>("SequenceConfig");
if (_config == null)
{
_config = Resources.Load<SequenceConfig>("SequenceConfig");
}

if (config == null)
if (_config == null)
{
throw new Exception("SequenceConfig not found. Make sure to create and configure it and place it at the root of your Resources folder. Create it from the top bar with Assets > Create > Sequence > SequenceConfig");
}

return config;
return _config;
}
}
}
1 change: 1 addition & 0 deletions Assets/SequenceSDK/WaaS/HttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public HttpClient(string url)
this._defaultHeaders = new Dictionary<string, string>();
_defaultHeaders["Content-Type"] = "application/json";
_defaultHeaders["Accept"] = "application/json";
_defaultHeaders["X-Access-Token"] = SequenceConfig.GetConfig().BuilderAPIKey_Prod;
}

public void AddDefaultHeader(string key, string value)
Expand Down
5 changes: 1 addition & 4 deletions Assets/SequenceSDK/WaaS/IntentSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ public class IntentSender
private Wallet.IWallet _sessionWallet;
private int _waasProjectId;
private string _waasVersion;
private string _builderApiKey;

public IntentSender(HttpClient httpClient, DataKey dataKey, Wallet.IWallet sessionWallet, string sessionId, int waasProjectId, string waasVersion, string builderApiKey)
public IntentSender(HttpClient httpClient, DataKey dataKey, Wallet.IWallet sessionWallet, string sessionId, int waasProjectId, string waasVersion)
{
_httpClient = httpClient;
_dataKey = dataKey;
_sessionWallet = sessionWallet;
SessionId = sessionId;
_waasProjectId = waasProjectId;
_waasVersion = waasVersion;
_builderApiKey = builderApiKey;
}

public async Task<T> SendIntent<T, T2>(T2 args)
Expand Down Expand Up @@ -107,7 +105,6 @@ public async Task<T> PostIntent<T>(string payload, string path)
WaaSPayload intent = new WaaSPayload(_dataKey.Ciphertext.ByteArrayToHexStringWithPrefix(), payloadCiphertext, signedPayload);
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("X-Sequence-Tenant", _waasProjectId.ToString());
headers.Add("X-Access-Token", _builderApiKey);
if (typeof(T) == typeof(IntentReturn<TransactionReturn>))
{
var transactionReturn = await SendTransactionIntent(intent, headers);
Expand Down
9 changes: 3 additions & 6 deletions Assets/SequenceSDK/WaaS/WaaSLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ public class WaaSLogin : ILogin
private OpenIdAuthenticator _authenticator;
private IValidator _validator;
private string _challengeSession;
private string _builderApiKey;

public WaaSLogin(AWSConfig awsConfig, int waasProjectId, string waasVersion, string builderApiKey, IValidator validator = null)
public WaaSLogin(AWSConfig awsConfig, int waasProjectId, string waasVersion, IValidator validator = null)
{
_awsConfig = awsConfig;
_waasProjectId = waasProjectId;
_waasVersion = waasVersion;
_builderApiKey = builderApiKey;
_authenticator = new OpenIdAuthenticator();
_authenticator.PlatformSpecificSetup();
Application.deepLinkActivated += _authenticator.HandleDeepLink;
Expand Down Expand Up @@ -172,8 +170,7 @@ public async Task ConnectToWaaS(string idToken, LoginMethod method)
sessionWallet,
"Unknown",
_waasProjectId,
_waasVersion,
_builderApiKey);
_waasVersion);
string loginPayload = AssembleLoginPayloadJson(idToken, sessionWallet);

try
Expand All @@ -182,7 +179,7 @@ public async Task ConnectToWaaS(string idToken, LoginMethod method)
string sessionId = registerSessionResponse.session.id;
string walletAddress = registerSessionResponse.data.wallet;
OnLoginSuccess?.Invoke(sessionId, walletAddress);
WaaSWallet wallet = new WaaSWallet(new Address(walletAddress), sessionId, sessionWallet, dataKey, _waasProjectId, _waasVersion, _builderApiKey);
WaaSWallet wallet = new WaaSWallet(new Address(walletAddress), sessionId, sessionWallet, dataKey, _waasProjectId, _waasVersion);
WaaSWallet.OnWaaSWalletCreated?.Invoke(wallet);
string email = Sequence.Authentication.JwtHelper.GetIdTokenJwtPayload(idToken).email;
PlayerPrefs.SetInt(WaaSLoginMethod, (int)method);
Expand Down
4 changes: 2 additions & 2 deletions Assets/SequenceSDK/WaaS/WaaSWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public class WaaSWallet : IWallet
private HttpClient _httpClient;
private IntentSender _intentSender;

public WaaSWallet(Address address, string sessionId, EthWallet sessionWallet, DataKey awsDataKey, int waasProjectId, string waasVersion, string builderApiKey)
public WaaSWallet(Address address, string sessionId, EthWallet sessionWallet, DataKey awsDataKey, int waasProjectId, string waasVersion)
{
_address = address;
_httpClient = new HttpClient("https://api.sequence.app/rpc");
_intentSender = new IntentSender(new HttpClient(WaaSLogin.WaaSWithAuthUrl), awsDataKey, sessionWallet, sessionId, waasProjectId, waasVersion, builderApiKey);
_intentSender = new IntentSender(new HttpClient(WaaSLogin.WaaSWithAuthUrl), awsDataKey, sessionWallet, sessionId, waasProjectId, waasVersion);
SessionId = sessionId;
}

Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ EditorBuildSettings:
- enabled: 0
path:
guid: 00000000000000000000000000000000
- enabled: 1
- enabled: 0
path: Assets/SequenceExamples/Scenes/Demo.unity
guid: 4dfb06a7c845a4513907bd9b1a335575
- enabled: 0
- enabled: 1
path: Assets/SequenceSDK/WaaS/Tests/WaaSEndToEndTests.unity
guid: 6a48e95d2401d41339a9d99c129ae1f9
m_configObjects:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/b22672caa7657539aff4191873269232.json"
}
Loading

0 comments on commit 31bdfa2

Please sign in to comment.