Components
Signxdr

Sign XDR

The "Sign XDR" component adds a signature to the xdr envelope and provides the new xdr envelope string.

Features

  • Collects signers secret key, and adds it to the xdr envelope.
  • Upon Submission, The new XDR Envelope string is displayed.
  • Provides a straightforward way to add a signature to an xdr string and returns the new xdr string.

Additional Resources

Stellar uses a binary format called External Data Representation (XDR) to store and transmit ledger data, transactions, results, history, and messages. XDR is designed to be efficient for network communication but is not readable by humans.

To make XDR data more accessible, tools like Horizon and the Stellar SDKs are used to convert XDR into formats that are easier to understand and work with. These conversions help developers interact with Stellar's data and integrate it into applications more effectively.

Signatures serve as authorization for transactions within the network. Every transaction must be authorized by at least one public key to be considered valid, and typically, this authorization comes from the source account's signature. In certain cases, transactions may require multiple signatures, a concept we'll explore further in the section covering multisignature (multisig) setups.

⚠️

Review the documentation on thresholds below, you can permanently lock yourself out of the account

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

NuGet Package Implementation
<pakana.stellar.components.Pages.SignXdr/>
C#
@page "/AddSignature"
@rendermode InteractiveAuto
 
<h2>Add Signature to Stellar XDR</h2>
<div>
    <textarea id="xdrInputro" placeholder="Enter XDR string here" rows="4"cols="50"></textarea>
    <input type="text" id="secretKeymine" placeholder="Enter your secret key">
    <button onclick="addSignature()">Add Signature</button>
    <p id="newXdrOutput"></p>
    <button onclick="copyNewXdr()">Copy XDR</button>
</div>
 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.2.2/stellar-sdk.min.js"></script>
<script src="your-file-path/xdrSign.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.

Stellar CDN
*Current Version as of 2024-24-02*
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.2.2/stellar-sdk.js"></script>
JavaScript
 
<script>
    function addSignature() {
 const xdrInput = document.getElementById('xdrInput').value;
    const secretKey = document.getElementById('secretKey').value;
    const StellarSdk = window.StellarSdk;
    try {
 const transaction = new StellarSdk.Transaction(xdrInput,
    StellarSdk.Networks.TESTNET);
    const keypair = StellarSdk.Keypair.fromSecret(secretKey);
    transaction.sign(keypair);
    const newXdr = transaction.toEnvelope().toXDR('base64');
    document.getElementById('newXdrOutput').textContent = 'New XDR with
    signature: ' + newXdr;
 } catch (e) {
        console.error('Error adding signature:', e);
    alert('Failed to add signature. Error: ' + e.message);
 }
 }
    function copyNewXdr() {
 const newXdrOutput = document.getElementById('newXdrOutput');
    const range = document.createRange();
    range.selectNode(newXdrOutput);
    window.getSelection().removeAllRanges();
    window.getSelection().addRange(range);
    document.execCommand('copy');
    window.getSelection().removeAllRanges();
    alert('Copied!');
 }
</script>
 
 
HTML
 
<body>
    <h2>Add Signature to Stellar XDR</h2>
    <div>
        <textarea id="xdrInput" placeholder="Enter XDR string here" rows="4"
                  cols="50"></textarea>
        <input type="text" id="secretKey" placeholder="Enter your secret key">
        <button onclick="addSignature()">Add Signature</button>
        <p id="newXdrOutput"></p>
        <button onclick="copyNewXdr()">Copy XDR</button>
    </div>
</body>