@okxweb3/coin-stellar
Version:
@ok/coin-stellar is a Stellar SDK for building Web3 wallets and applications. It supports Stellar and PI blockchains, enabling private key management, address generation, transaction signing, trustline creation, and asset transfers
168 lines • 7.81 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.revokeSignerSponsorship = exports.revokeLiquidityPoolSponsorship = exports.revokeClaimableBalanceSponsorship = exports.revokeDataSponsorship = exports.revokeOfferSponsorship = exports.revokeTrustlineSponsorship = exports.revokeAccountSponsorship = void 0;
const xdr_1 = __importDefault(require("../xdr"));
const strkey_1 = require("../strkey");
const keypair_1 = require("../keypair");
const asset_1 = require("../asset");
const liquidity_pool_id_1 = require("../liquidity_pool_id");
function revokeAccountSponsorship(opts = {}) {
if (!strkey_1.StrKey.isValidEd25519PublicKey(opts.account)) {
throw new Error('account is invalid');
}
const ledgerKey = xdr_1.default.LedgerKey.account(new xdr_1.default.LedgerKeyAccount({
accountId: keypair_1.Keypair.fromPublicKey(opts.account).xdrAccountId()
}));
const op = xdr_1.default.RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
const opAttributes = {};
opAttributes.body = xdr_1.default.OperationBody.revokeSponsorship(op);
this.setSourceAccount(opAttributes, opts);
return new xdr_1.default.Operation(opAttributes);
}
exports.revokeAccountSponsorship = revokeAccountSponsorship;
function revokeTrustlineSponsorship(opts = {}) {
if (!strkey_1.StrKey.isValidEd25519PublicKey(opts.account)) {
throw new Error('account is invalid');
}
let asset;
if (opts.asset instanceof asset_1.Asset) {
asset = opts.asset.toTrustLineXDRObject();
}
else if (opts.asset instanceof liquidity_pool_id_1.LiquidityPoolId) {
asset = opts.asset.toXDRObject();
}
else {
throw new TypeError('asset must be an Asset or LiquidityPoolId');
}
const ledgerKey = xdr_1.default.LedgerKey.trustline(new xdr_1.default.LedgerKeyTrustLine({
accountId: keypair_1.Keypair.fromPublicKey(opts.account).xdrAccountId(),
asset
}));
const op = xdr_1.default.RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
const opAttributes = {};
opAttributes.body = xdr_1.default.OperationBody.revokeSponsorship(op);
this.setSourceAccount(opAttributes, opts);
return new xdr_1.default.Operation(opAttributes);
}
exports.revokeTrustlineSponsorship = revokeTrustlineSponsorship;
function revokeOfferSponsorship(opts = {}) {
if (!strkey_1.StrKey.isValidEd25519PublicKey(opts.seller)) {
throw new Error('seller is invalid');
}
if (typeof opts.offerId !== 'string') {
throw new Error('offerId is invalid');
}
const ledgerKey = xdr_1.default.LedgerKey.offer(new xdr_1.default.LedgerKeyOffer({
sellerId: keypair_1.Keypair.fromPublicKey(opts.seller).xdrAccountId(),
offerId: xdr_1.default.Int64.fromString(opts.offerId)
}));
const op = xdr_1.default.RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
const opAttributes = {};
opAttributes.body = xdr_1.default.OperationBody.revokeSponsorship(op);
this.setSourceAccount(opAttributes, opts);
return new xdr_1.default.Operation(opAttributes);
}
exports.revokeOfferSponsorship = revokeOfferSponsorship;
function revokeDataSponsorship(opts = {}) {
if (!strkey_1.StrKey.isValidEd25519PublicKey(opts.account)) {
throw new Error('account is invalid');
}
if (typeof opts.name !== 'string' || opts.name.length > 64) {
throw new Error('name must be a string, up to 64 characters');
}
const ledgerKey = xdr_1.default.LedgerKey.data(new xdr_1.default.LedgerKeyData({
accountId: keypair_1.Keypair.fromPublicKey(opts.account).xdrAccountId(),
dataName: opts.name
}));
const op = xdr_1.default.RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
const opAttributes = {};
opAttributes.body = xdr_1.default.OperationBody.revokeSponsorship(op);
this.setSourceAccount(opAttributes, opts);
return new xdr_1.default.Operation(opAttributes);
}
exports.revokeDataSponsorship = revokeDataSponsorship;
function revokeClaimableBalanceSponsorship(opts = {}) {
if (typeof opts.balanceId !== 'string') {
throw new Error('balanceId is invalid');
}
const ledgerKey = xdr_1.default.LedgerKey.claimableBalance(new xdr_1.default.LedgerKeyClaimableBalance({
balanceId: xdr_1.default.ClaimableBalanceId.fromXDR(opts.balanceId, 'hex')
}));
const op = xdr_1.default.RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
const opAttributes = {};
opAttributes.body = xdr_1.default.OperationBody.revokeSponsorship(op);
this.setSourceAccount(opAttributes, opts);
return new xdr_1.default.Operation(opAttributes);
}
exports.revokeClaimableBalanceSponsorship = revokeClaimableBalanceSponsorship;
function revokeLiquidityPoolSponsorship(opts = {}) {
if (typeof opts.liquidityPoolId !== 'string') {
throw new Error('liquidityPoolId is invalid');
}
const ledgerKey = xdr_1.default.LedgerKey.liquidityPool(new xdr_1.default.LedgerKeyLiquidityPool({
liquidityPoolId: xdr_1.default.PoolId.fromXDR(opts.liquidityPoolId, 'hex')
}));
const op = xdr_1.default.RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
const opAttributes = {
body: xdr_1.default.OperationBody.revokeSponsorship(op)
};
this.setSourceAccount(opAttributes, opts);
return new xdr_1.default.Operation(opAttributes);
}
exports.revokeLiquidityPoolSponsorship = revokeLiquidityPoolSponsorship;
function revokeSignerSponsorship(opts = {}) {
if (!strkey_1.StrKey.isValidEd25519PublicKey(opts.account)) {
throw new Error('account is invalid');
}
let key;
if (opts.signer.ed25519PublicKey) {
if (!strkey_1.StrKey.isValidEd25519PublicKey(opts.signer.ed25519PublicKey)) {
throw new Error('signer.ed25519PublicKey is invalid.');
}
const rawKey = strkey_1.StrKey.decodeEd25519PublicKey(opts.signer.ed25519PublicKey);
key = new xdr_1.default.SignerKey.signerKeyTypeEd25519(rawKey);
}
else if (opts.signer.preAuthTx) {
let buffer;
if (typeof opts.signer.preAuthTx === 'string') {
buffer = Buffer.from(opts.signer.preAuthTx, 'hex');
}
else {
buffer = opts.signer.preAuthTx;
}
if (!(Buffer.isBuffer(buffer) && buffer.length === 32)) {
throw new Error('signer.preAuthTx must be 32 bytes Buffer.');
}
key = new xdr_1.default.SignerKey.signerKeyTypePreAuthTx(buffer);
}
else if (opts.signer.sha256Hash) {
let buffer;
if (typeof opts.signer.sha256Hash === 'string') {
buffer = Buffer.from(opts.signer.sha256Hash, 'hex');
}
else {
buffer = opts.signer.sha256Hash;
}
if (!(Buffer.isBuffer(buffer) && buffer.length === 32)) {
throw new Error('signer.sha256Hash must be 32 bytes Buffer.');
}
key = new xdr_1.default.SignerKey.signerKeyTypeHashX(buffer);
}
else {
throw new Error('signer is invalid');
}
const signer = new xdr_1.default.RevokeSponsorshipOpSigner({
accountId: keypair_1.Keypair.fromPublicKey(opts.account).xdrAccountId(),
signerKey: key
});
const op = xdr_1.default.RevokeSponsorshipOp.revokeSponsorshipSigner(signer);
const opAttributes = {};
opAttributes.body = xdr_1.default.OperationBody.revokeSponsorship(op);
this.setSourceAccount(opAttributes, opts);
return new xdr_1.default.Operation(opAttributes);
}
exports.revokeSignerSponsorship = revokeSignerSponsorship;
//# sourceMappingURL=revoke_sponsorship.js.map