Skip to content
Open
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 @@ -16,4 +16,6 @@ public interface IAdapterOperations
public Task<SignedResult> SignTransactions(IEnumerable<byte[]> transactions);
[Preserve]
public Task<SignedResult> SignMessages(IEnumerable<byte[]> messages, IEnumerable<byte[]> addresses);
[Preserve]
public Task<CapabilitiesResult> GetCapabilities();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine.Scripting;

// ReSharper disable once CheckNamespace

[Preserve]
public class CapabilitiesResult
{
[JsonProperty("max_transactions_per_request", NullValueHandling = NullValueHandling.Ignore)]
[RequiredMember]
public int? MaxTransactionsPerRequest { get; set; }

[JsonProperty("max_messages_per_request", NullValueHandling = NullValueHandling.Ignore)]
[RequiredMember]
public int? MaxMessagesPerRequest { get; set; }

[JsonProperty("supported_transaction_versions")]
[RequiredMember]
public List<string> SupportedTransactionVersions { get; set; }

[JsonProperty("features", NullValueHandling = NullValueHandling.Ignore)]
[RequiredMember]
public List<string> Features { get; set; }
Comment on lines +18 to +24
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Initialize collection properties to avoid null-driven crashes.

On Line 20 and Line 24, both lists can deserialize as null, which makes downstream iteration fragile. Prefer non-null defaults.

💡 Proposed fix
     [JsonProperty("supported_transaction_versions")]
     [RequiredMember]
-    public List<string> SupportedTransactionVersions { get; set; }
+    public List<string> SupportedTransactionVersions { get; set; } = new();

     [JsonProperty("features", NullValueHandling = NullValueHandling.Ignore)]
     [RequiredMember]
-    public List<string> Features { get; set; }
+    public List<string> Features { get; set; } = new();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[JsonProperty("supported_transaction_versions")]
[RequiredMember]
public List<string> SupportedTransactionVersions { get; set; }
[JsonProperty("features", NullValueHandling = NullValueHandling.Ignore)]
[RequiredMember]
public List<string> Features { get; set; }
[JsonProperty("supported_transaction_versions")]
[RequiredMember]
public List<string> SupportedTransactionVersions { get; set; } = new();
[JsonProperty("features", NullValueHandling = NullValueHandling.Ignore)]
[RequiredMember]
public List<string> Features { get; set; } = new();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@Runtime/codebase/SolanaMobileStack/JsonRpcClient/Responses/CapabilitiesResult.cs`
around lines 18 - 24, CapabilitiesResult's collection properties
SupportedTransactionVersions and Features can be deserialized as null and cause
NREs; update the property declarations in the CapabilitiesResult class to
initialize both SupportedTransactionVersions and Features to empty List<string>
instances (e.g., new List<string>()) so consumers can safely iterate without
null checks and keep the existing JsonProperty/RequiredMember attributes intact.

}

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

13 changes: 13 additions & 0 deletions Runtime/codebase/SolanaMobileStack/MobileWalletAdapterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ private JsonRequest PrepareSignMessagesRequest(IEnumerable<byte[]> messages, IEn
return request;
}

[Preserve]
public Task<CapabilitiesResult> GetCapabilities()
{
var request = new JsonRequest
{
JsonRpc = "2.0",
Method = "get_capabilities",
Params = new JsonRequest.JsonRequestParams(),
Id = NextMessageId()
};
return SendRequest<CapabilitiesResult>(request);
}

private int NextMessageId()
{
return _mNextMessageId++;
Expand Down
21 changes: 21 additions & 0 deletions Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,27 @@ public override async Task<byte[]> SignMessage(byte[] message)
return signedMessages.SignedPayloadsBytes[0];
}

public async Task<CapabilitiesResult> GetCapabilities()
{
CapabilitiesResult capabilities = null;
var localAssociationScenario = new LocalAssociationScenario();
var result = await localAssociationScenario.StartAndExecute(
new List<Action<IAdapterOperations>>
{
async client =>
{
capabilities = await client.GetCapabilities();
}
}
);
if (!result.WasSuccessful)
{
Debug.LogError(result.Error.Message);
throw new Exception(result.Error.Message);
}
return capabilities;
}
Comment on lines +191 to +208
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Guard against null capabilities payload before returning.

On Line 207, capabilities may still be null even when the scenario itself reports success, which can lead to downstream null dereferences.

🛡️ Proposed fix
         if (!result.WasSuccessful)
         {
             Debug.LogError(result.Error.Message);
             throw new Exception(result.Error.Message);
         }
+        if (capabilities == null)
+        {
+            throw new Exception("get_capabilities returned an empty result.");
+        }
         return capabilities;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
CapabilitiesResult capabilities = null;
var localAssociationScenario = new LocalAssociationScenario();
var result = await localAssociationScenario.StartAndExecute(
new List<Action<IAdapterOperations>>
{
async client =>
{
capabilities = await client.GetCapabilities();
}
}
);
if (!result.WasSuccessful)
{
Debug.LogError(result.Error.Message);
throw new Exception(result.Error.Message);
}
return capabilities;
}
CapabilitiesResult capabilities = null;
var localAssociationScenario = new LocalAssociationScenario();
var result = await localAssociationScenario.StartAndExecute(
new List<Action<IAdapterOperations>>
{
async client =>
{
capabilities = await client.GetCapabilities();
}
}
);
if (!result.WasSuccessful)
{
Debug.LogError(result.Error.Message);
throw new Exception(result.Error.Message);
}
if (capabilities == null)
{
throw new Exception("get_capabilities returned an empty result.");
}
return capabilities;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs` around lines
191 - 208, The method captures a CapabilitiesResult into the local variable
capabilities via LocalAssociationScenario.StartAndExecute/ GetCapabilities but
may return null even when result.WasSuccessful; after the call to
StartAndExecute and the success check, add a null guard for the capabilities
variable (from this method's local “capabilities”) and handle it
consistently—either throw a descriptive Exception or log an error with
Debug.LogError and throw (e.g., "Capabilities payload was null after successful
association")—so callers never receive a null CapabilitiesResult.


protected override Task<Account> _CreateAccount(string mnemonic = null, string password = null)
{
throw new NotImplementedException("Can't create a new account in phantom wallet");
Expand Down