UNPKG

@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

45 lines 1.93 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setTrustLineFlags = void 0; const xdr_1 = __importDefault(require("../xdr")); const keypair_1 = require("../keypair"); function setTrustLineFlags(opts = {}) { const attributes = {}; if (typeof opts.flags !== 'object' || Object.keys(opts.flags).length === 0) { throw new Error('opts.flags must be a map of boolean flags to modify'); } const mapping = { authorized: xdr_1.default.TrustLineFlags.authorizedFlag(), authorizedToMaintainLiabilities: xdr_1.default.TrustLineFlags.authorizedToMaintainLiabilitiesFlag(), clawbackEnabled: xdr_1.default.TrustLineFlags.trustlineClawbackEnabledFlag() }; let clearFlag = 0; let setFlag = 0; Object.keys(opts.flags).forEach((flagName) => { if (!Object.prototype.hasOwnProperty.call(mapping, flagName)) { throw new Error(`unsupported flag name specified: ${flagName}`); } const flagValue = opts.flags[flagName]; const bit = mapping[flagName].value; if (flagValue === true) { setFlag |= bit; } else if (flagValue === false) { clearFlag |= bit; } }); attributes.trustor = keypair_1.Keypair.fromPublicKey(opts.trustor).xdrAccountId(); attributes.asset = opts.asset.toXDRObject(); attributes.clearFlags = clearFlag; attributes.setFlags = setFlag; const opAttributes = { body: xdr_1.default.OperationBody.setTrustLineFlags(new xdr_1.default.SetTrustLineFlagsOp(attributes)) }; this.setSourceAccount(opAttributes, opts); return new xdr_1.default.Operation(opAttributes); } exports.setTrustLineFlags = setTrustLineFlags; //# sourceMappingURL=set_trustline_flags.js.map