Verify Signers Weight
The "Verify Signers Weight" component allows users to verify a Stellar public account signers and their signing weights.
The component includes fields for displaying the signers public address and their weight on a given account.
Features
- Verifys a Stellar accounts signers and weights.
- Displays the signers public address and the weights of each signer.
Additional Resources
Each task is categorized into one of three thresholds: low, medium, or high, each assigned a numeric level between 0 and 255. This level dictates the required signature weight for authorizing the task. For further details, refer to Stellars documentation section on Operations and Transactions.
C#
Install the Pakana.Stellar.Components NuGet package via the NuGet Package Manager Console.
.Net8.0 or greater is required.
dotnet add package Pakana.Stellar.Components
StellarSDK Dependency will install automatically
<pakana.stellar.components.Pages.SignerWeights/>
@page "/Manage"
@rendermode InteractiveAuto
@inject IJSRuntime JSRuntime
@using System.Text.Json
<h1>Stellar Account Signers and Weights</h1>
<EditForm Model="@this" OnValidSubmit="FetchAccountDetails">
<div>
<label for="publicAddressInput">Public Address:</label>
<InputText id="publicAddressInput" @bind-Value="publicAddress" placeholder="Enter public address" />
<button type="submit">Fetch Account Details</button>
</div>
</EditForm>
@if (accountDetailsVisible)
{
<div style="margin-top: 20px;">
<h2>Account Details</h2>
<p><strong>Public Address:</strong> @publicAddress</p>
<p><strong>High Threshold:</strong> @highThreshold</p>
<p><strong>Signers:</strong></p>
<ul>
@foreach (var signer in signers)
{
<li>@signer.Key (@signer.Weight)</li>
}
</ul>
</div>
}
@code {
private string publicAddress = "GCK4ZVCR74F5AHGZPPWUN6MG6DIRBVN3F2VFRMGEXWQYRW7EUSML27VB"; // Example testnet address
private int highThreshold;
private List<Signer> signers = new List<Signer>();
private bool accountDetailsVisible = false;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JSRuntime.InvokeVoidAsync("loadStellarSdk");
}
}
private async Task FetchAccountDetails()
{
try
{
var accountDetails = await JSRuntime.InvokeAsync<JsonElement>("fetchAccountDetailsFromStellar", publicAddress);
if (accountDetails.ValueKind != JsonValueKind.Undefined && accountDetails.ValueKind != JsonValueKind.Null)
{
highThreshold = accountDetails.GetProperty("highThreshold").GetInt32();
var signersJson = accountDetails.GetProperty("signers");
signers = new List<Signer>();
foreach (JsonElement signerElement in signersJson.EnumerateArray())
{
signers.Add(new Signer
{
Key = signerElement.GetProperty("key").GetString(),
Weight = signerElement.GetProperty("weight").GetInt32()
});
}
accountDetailsVisible = true;
}
else
{
throw new InvalidOperationException("Failed to fetch account details or no data found.");
}
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error fetching account details: {ex.Message}");
accountDetailsVisible = false;
}
}
public class Signer
{
public string Key { get; set; }
public int Weight { get; set; }
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.3.0/stellar-sdk.min.js"></script>
<script src="your-file-path/signerWeights.js"></script>
Javascript
We've provided simple HTML and JavaScript that can be used in your project as partial-components or be customized and integrated into your existing codebase.
*Current Version as of 2024-24-02*
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.2.2/stellar-sdk.js"></script>
<script>
async function fetchAccountDetails() {
const publicAddress = document.getElementById('publicAddressInput').value.trim();
try {
const server = new StellarSdk.Horizon.Server('https://horizon-testnet.stellar.org');
const account = await server.loadAccount(publicAddress);
const {thresholds, signers} = account;
document.getElementById('publicAddress').textContent = publicAddress;
document.getElementById('highThreshold').textContent = thresholds.high_threshold;
const signersList = document.getElementById('signersList');
signersList.innerHTML = ''; // Clear previous signers
signers.forEach(signer => {
const listItem = document.createElement('li');
listItem.textContent = `${signer.key} (${signer.weight})`;
signersList.appendChild(listItem);
});
document.getElementById('accountDetails').style.display = 'block';
} catch (error) {
console.error('Error fetching account details:', error);
alert('Error fetching account details. Please check the public address.');
}
}
</script>
<body>
<h1>Stellar Account Signers and Weights</h1>
<label for="publicAddress">Public Address:</label>
<input type="text" id="publicAddressInput" placeholder="Enter public address">
<button onclick="fetchAccountDetails()">Fetch Account Details</button>
<div id="accountDetails" style="display: none; margin-top: 20px;">
<h2>Account Details</h2>
<p><strong>Public Address:</strong> <span id="publicAddress"></span></p>
<p><strong>High Threshold:</strong> <span id="highThreshold"></span></p>
<p><strong>Signers:</strong></p>
<ul id="signersList"></ul>
</div>
</body>