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
6 changes: 6 additions & 0 deletions src/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,12 @@ function convertXDRSignerKeyToObject(signerKey) {
attrs.sha256Hash = signerKey.hashX().toString('hex');
break;
}
case xdr.SignerKeyType.signerKeyTypeEd25519SignedPayload().name: {
attrs.ed25519SignedPayload = StrKey.encodeSignedPayload(
signerKey.ed25519SignedPayload().toXDR()
);
break;
}
default: {
throw new Error(`Unknown signerKey: ${signerKey.switch().name}`);
}
Expand Down
10 changes: 10 additions & 0 deletions src/operations/revoke_sponsorship.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export function revokeLiquidityPoolSponsorship(opts = {}) {
* @param {string} [opts.signer.ed25519PublicKey] - The ed25519 public key of the signer.
* @param {Buffer|string} [opts.signer.sha256Hash] - sha256 hash (Buffer or hex string).
* @param {Buffer|string} [opts.signer.preAuthTx] - Hash (Buffer or hex string) of transaction.
* @param {string} [opts.signer.ed25519SignedPayload] - Signed payload signer (ed25519 public key + raw payload).
* @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
* @returns {xdr.Operation} xdr operation
*
Expand Down Expand Up @@ -298,6 +299,15 @@ export function revokeSignerSponsorship(opts = {}) {
}

key = new xdr.SignerKey.signerKeyTypeHashX(buffer);
} else if (opts.signer.ed25519SignedPayload) {
if (!StrKey.isValidSignedPayload(opts.signer.ed25519SignedPayload)) {
throw new Error('signer.ed25519SignedPayload is invalid.');
}
const rawKey = StrKey.decodeSignedPayload(opts.signer.ed25519SignedPayload);
const signedPayloadXdr =
xdr.SignerKeyEd25519SignedPayload.fromXDR(rawKey);

key = xdr.SignerKey.signerKeyTypeEd25519SignedPayload(signedPayloadXdr);
} else {
throw new Error('signer is invalid');
}
Expand Down
26 changes: 26 additions & 0 deletions test/unit/operations/classic_ops_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,32 @@ describe('Operation', function () {
expect(obj.type).to.be.equal('revokeSignerSponsorship');
expect(obj.account).to.be.equal(account);
expect(obj.signer.sha256Hash).to.be.equal(signer.sha256Hash);

// ed25519SignedPayload signer
const signedPayload = new StellarBase.xdr.SignerKeyEd25519SignedPayload({
ed25519: StellarBase.StrKey.decodeEd25519PublicKey(account),
payload: Buffer.from('test')
});
const xdrSignerKey =
StellarBase.xdr.SignerKey.signerKeyTypeEd25519SignedPayload(
signedPayload
);
signer = {
ed25519SignedPayload: StellarBase.SignerKey.encodeSignerKey(
xdrSignerKey
)
};
op = StellarBase.Operation.revokeSignerSponsorship({
account,
signer
});
operation = StellarBase.xdr.Operation.fromXDR(op.toXDR('hex'), 'hex');
obj = StellarBase.Operation.fromXDRObject(operation);
expect(obj.type).to.be.equal('revokeSignerSponsorship');
expect(obj.account).to.be.equal(account);
expect(obj.signer.ed25519SignedPayload).to.be.equal(
signer.ed25519SignedPayload
);
});
it('throws an error when account is invalid', function () {
const signer = {
Expand Down