class DelegatedSigner implements StellarCustomSigner {
private delegateSecret: string;
private authorityPublicKey: string;
constructor(delegateSecret: string, authorityPublicKey: string) {
this.delegateSecret = delegateSecret;
this.authorityPublicKey = authorityPublicKey;
}
async signTransaction(xdr: string): Promise<{
signedTxXdr: string;
signerAddress?: string;
}> {
// Sign with delegate key but identify as authority
const delegateKeypair = Keypair.fromSecret(this.delegateSecret);
const transaction = xdr.Transaction.fromXDR(xdr, 'base64');
transaction.sign(delegateKeypair);
return {
signedTxXdr: transaction.toXDR('base64'),
signerAddress: this.authorityPublicKey // Authority identity
};
}
}
// Usage with authority delegation
const config: StellarConfig = {
secretKeyOrCustomSigner: new DelegatedSigner(
'SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', // Delegate secret
'GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' // Authority public
),
publicKey: 'GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', // Authority public
url: 'https://soroban-testnet.stellar.org'
};