@stellar/stellar-base 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1262 -0
- package/LICENSE +202 -0
- package/README.md +198 -0
- package/dist/stellar-base.js +30777 -0
- package/dist/stellar-base.min.js +2 -0
- package/lib/account.js +80 -0
- package/lib/address.js +169 -0
- package/lib/asset.js +323 -0
- package/lib/auth.js +253 -0
- package/lib/claimant.js +193 -0
- package/lib/contract.js +113 -0
- package/lib/events.js +42 -0
- package/lib/fee_bump_transaction.js +134 -0
- package/lib/generated/curr_generated.js +8315 -0
- package/lib/generated/next_generated.js +8315 -0
- package/lib/get_liquidity_pool_id.js +57 -0
- package/lib/hashing.js +12 -0
- package/lib/index.js +385 -0
- package/lib/invocation.js +195 -0
- package/lib/keypair.js +308 -0
- package/lib/liquidity_pool_asset.js +126 -0
- package/lib/liquidity_pool_id.js +101 -0
- package/lib/memo.js +270 -0
- package/lib/muxed_account.js +159 -0
- package/lib/network.js +22 -0
- package/lib/numbers/index.js +85 -0
- package/lib/numbers/int128.js +50 -0
- package/lib/numbers/int256.js +50 -0
- package/lib/numbers/sc_int.js +134 -0
- package/lib/numbers/uint128.js +50 -0
- package/lib/numbers/uint256.js +50 -0
- package/lib/numbers/xdr_large_int.js +267 -0
- package/lib/operation.js +715 -0
- package/lib/operations/account_merge.js +32 -0
- package/lib/operations/allow_trust.js +57 -0
- package/lib/operations/begin_sponsoring_future_reserves.js +38 -0
- package/lib/operations/bump_sequence.js +37 -0
- package/lib/operations/change_trust.js +52 -0
- package/lib/operations/claim_claimable_balance.js +40 -0
- package/lib/operations/clawback.js +46 -0
- package/lib/operations/clawback_claimable_balance.js +39 -0
- package/lib/operations/create_account.js +37 -0
- package/lib/operations/create_claimable_balance.js +65 -0
- package/lib/operations/create_passive_sell_offer.js +44 -0
- package/lib/operations/end_sponsoring_future_reserves.js +27 -0
- package/lib/operations/extend_footprint_ttl.js +45 -0
- package/lib/operations/index.js +254 -0
- package/lib/operations/inflation.js +23 -0
- package/lib/operations/invoke_host_function.js +219 -0
- package/lib/operations/liquidity_pool_deposit.js +64 -0
- package/lib/operations/liquidity_pool_withdraw.js +50 -0
- package/lib/operations/manage_buy_offer.js +50 -0
- package/lib/operations/manage_data.js +41 -0
- package/lib/operations/manage_sell_offer.js +50 -0
- package/lib/operations/path_payment_strict_receive.js +68 -0
- package/lib/operations/path_payment_strict_send.js +68 -0
- package/lib/operations/payment.js +47 -0
- package/lib/operations/restore_footprint.js +38 -0
- package/lib/operations/revoke_sponsorship.js +301 -0
- package/lib/operations/set_options.js +135 -0
- package/lib/operations/set_trustline_flags.js +84 -0
- package/lib/scval.js +369 -0
- package/lib/signerkey.js +103 -0
- package/lib/signing.js +96 -0
- package/lib/soroban.js +96 -0
- package/lib/sorobandata_builder.js +218 -0
- package/lib/strkey.js +400 -0
- package/lib/transaction.js +369 -0
- package/lib/transaction_base.js +248 -0
- package/lib/transaction_builder.js +753 -0
- package/lib/util/checksum.js +20 -0
- package/lib/util/continued_fraction.js +58 -0
- package/lib/util/decode_encode_muxed_account.js +116 -0
- package/lib/util/util.js +14 -0
- package/lib/xdr.js +9 -0
- package/package.json +133 -0
- package/types/curr.d.ts +14078 -0
- package/types/index.d.ts +1270 -0
- package/types/next.d.ts +14078 -0
- package/types/xdr.d.ts +1 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.manageData = manageData;
|
|
7
|
+
var _xdr = _interopRequireDefault(require("../xdr"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9
|
+
/**
|
|
10
|
+
* This operation adds data entry to the ledger.
|
|
11
|
+
* @function
|
|
12
|
+
* @alias Operation.manageData
|
|
13
|
+
* @param {object} opts Options object
|
|
14
|
+
* @param {string} opts.name - The name of the data entry.
|
|
15
|
+
* @param {string|Buffer} opts.value - The value of the data entry.
|
|
16
|
+
* @param {string} [opts.source] - The optional source account.
|
|
17
|
+
* @returns {xdr.ManageDataOp} Manage Data operation
|
|
18
|
+
*/
|
|
19
|
+
function manageData(opts) {
|
|
20
|
+
var attributes = {};
|
|
21
|
+
if (!(typeof opts.name === 'string' && opts.name.length <= 64)) {
|
|
22
|
+
throw new Error('name must be a string, up to 64 characters');
|
|
23
|
+
}
|
|
24
|
+
attributes.dataName = opts.name;
|
|
25
|
+
if (typeof opts.value !== 'string' && !Buffer.isBuffer(opts.value) && opts.value !== null) {
|
|
26
|
+
throw new Error('value must be a string, Buffer or null');
|
|
27
|
+
}
|
|
28
|
+
if (typeof opts.value === 'string') {
|
|
29
|
+
attributes.dataValue = Buffer.from(opts.value);
|
|
30
|
+
} else {
|
|
31
|
+
attributes.dataValue = opts.value;
|
|
32
|
+
}
|
|
33
|
+
if (attributes.dataValue !== null && attributes.dataValue.length > 64) {
|
|
34
|
+
throw new Error('value cannot be longer that 64 bytes');
|
|
35
|
+
}
|
|
36
|
+
var manageDataOp = new _xdr["default"].ManageDataOp(attributes);
|
|
37
|
+
var opAttributes = {};
|
|
38
|
+
opAttributes.body = _xdr["default"].OperationBody.manageData(manageDataOp);
|
|
39
|
+
this.setSourceAccount(opAttributes, opts);
|
|
40
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
41
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.manageSellOffer = manageSellOffer;
|
|
7
|
+
var _jsXdr = require("@stellar/js-xdr");
|
|
8
|
+
var _xdr = _interopRequireDefault(require("../xdr"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
/**
|
|
11
|
+
* Returns a XDR ManageSellOfferOp. A "manage sell offer" operation creates, updates, or
|
|
12
|
+
* deletes an offer.
|
|
13
|
+
* @function
|
|
14
|
+
* @alias Operation.manageSellOffer
|
|
15
|
+
* @param {object} opts Options object
|
|
16
|
+
* @param {Asset} opts.selling - What you're selling.
|
|
17
|
+
* @param {Asset} opts.buying - What you're buying.
|
|
18
|
+
* @param {string} opts.amount - The total amount you're selling. If 0, deletes the offer.
|
|
19
|
+
* @param {number|string|BigNumber|Object} opts.price - Price of 1 unit of `selling` in terms of `buying`.
|
|
20
|
+
* @param {number} opts.price.n - If `opts.price` is an object: the price numerator
|
|
21
|
+
* @param {number} opts.price.d - If `opts.price` is an object: the price denominator
|
|
22
|
+
* @param {number|string} [opts.offerId ] - If `0`, will create a new offer (default). Otherwise, edits an exisiting offer.
|
|
23
|
+
* @param {string} [opts.source] - The source account (defaults to transaction source).
|
|
24
|
+
* @throws {Error} Throws `Error` when the best rational approximation of `price` cannot be found.
|
|
25
|
+
* @returns {xdr.ManageSellOfferOp} Manage Sell Offer operation
|
|
26
|
+
*/
|
|
27
|
+
function manageSellOffer(opts) {
|
|
28
|
+
var attributes = {};
|
|
29
|
+
attributes.selling = opts.selling.toXDRObject();
|
|
30
|
+
attributes.buying = opts.buying.toXDRObject();
|
|
31
|
+
if (!this.isValidAmount(opts.amount, true)) {
|
|
32
|
+
throw new TypeError(this.constructAmountRequirementsError('amount'));
|
|
33
|
+
}
|
|
34
|
+
attributes.amount = this._toXDRAmount(opts.amount);
|
|
35
|
+
if (opts.price === undefined) {
|
|
36
|
+
throw new TypeError('price argument is required');
|
|
37
|
+
}
|
|
38
|
+
attributes.price = this._toXDRPrice(opts.price);
|
|
39
|
+
if (opts.offerId !== undefined) {
|
|
40
|
+
opts.offerId = opts.offerId.toString();
|
|
41
|
+
} else {
|
|
42
|
+
opts.offerId = '0';
|
|
43
|
+
}
|
|
44
|
+
attributes.offerId = _jsXdr.Hyper.fromString(opts.offerId);
|
|
45
|
+
var manageSellOfferOp = new _xdr["default"].ManageSellOfferOp(attributes);
|
|
46
|
+
var opAttributes = {};
|
|
47
|
+
opAttributes.body = _xdr["default"].OperationBody.manageSellOffer(manageSellOfferOp);
|
|
48
|
+
this.setSourceAccount(opAttributes, opts);
|
|
49
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
50
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.pathPaymentStrictReceive = pathPaymentStrictReceive;
|
|
7
|
+
var _xdr = _interopRequireDefault(require("../xdr"));
|
|
8
|
+
var _decode_encode_muxed_account = require("../util/decode_encode_muxed_account");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
/**
|
|
11
|
+
* Creates a PathPaymentStrictReceive operation.
|
|
12
|
+
*
|
|
13
|
+
* A `PathPaymentStrictReceive` operation sends the specified amount to the
|
|
14
|
+
* destination account. It credits the destination with `destAmount` of
|
|
15
|
+
* `destAsset`, while debiting at most `sendMax` of `sendAsset` from the source.
|
|
16
|
+
* The transfer optionally occurs through a path. XLM payments create the
|
|
17
|
+
* destination account if it does not exist.
|
|
18
|
+
*
|
|
19
|
+
* @function
|
|
20
|
+
* @alias Operation.pathPaymentStrictReceive
|
|
21
|
+
* @see https://developers.stellar.org/docs/start/list-of-operations/#path-payment-strict-receive
|
|
22
|
+
*
|
|
23
|
+
* @param {object} opts - Options object
|
|
24
|
+
* @param {Asset} opts.sendAsset - asset to pay with
|
|
25
|
+
* @param {string} opts.sendMax - maximum amount of sendAsset to send
|
|
26
|
+
* @param {string} opts.destination - destination account to send to
|
|
27
|
+
* @param {Asset} opts.destAsset - asset the destination will receive
|
|
28
|
+
* @param {string} opts.destAmount - amount the destination receives
|
|
29
|
+
* @param {Asset[]} opts.path - array of Asset objects to use as the path
|
|
30
|
+
*
|
|
31
|
+
* @param {string} [opts.source] - The source account for the payment.
|
|
32
|
+
* Defaults to the transaction's source account.
|
|
33
|
+
*
|
|
34
|
+
* @returns {xdr.PathPaymentStrictReceiveOp} the resulting path payment op
|
|
35
|
+
*/
|
|
36
|
+
function pathPaymentStrictReceive(opts) {
|
|
37
|
+
switch (true) {
|
|
38
|
+
case !opts.sendAsset:
|
|
39
|
+
throw new Error('Must specify a send asset');
|
|
40
|
+
case !this.isValidAmount(opts.sendMax):
|
|
41
|
+
throw new TypeError(this.constructAmountRequirementsError('sendMax'));
|
|
42
|
+
case !opts.destAsset:
|
|
43
|
+
throw new Error('Must provide a destAsset for a payment operation');
|
|
44
|
+
case !this.isValidAmount(opts.destAmount):
|
|
45
|
+
throw new TypeError(this.constructAmountRequirementsError('destAmount'));
|
|
46
|
+
default:
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
var attributes = {};
|
|
50
|
+
attributes.sendAsset = opts.sendAsset.toXDRObject();
|
|
51
|
+
attributes.sendMax = this._toXDRAmount(opts.sendMax);
|
|
52
|
+
try {
|
|
53
|
+
attributes.destination = (0, _decode_encode_muxed_account.decodeAddressToMuxedAccount)(opts.destination);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
throw new Error('destination is invalid');
|
|
56
|
+
}
|
|
57
|
+
attributes.destAsset = opts.destAsset.toXDRObject();
|
|
58
|
+
attributes.destAmount = this._toXDRAmount(opts.destAmount);
|
|
59
|
+
var path = opts.path ? opts.path : [];
|
|
60
|
+
attributes.path = path.map(function (x) {
|
|
61
|
+
return x.toXDRObject();
|
|
62
|
+
});
|
|
63
|
+
var payment = new _xdr["default"].PathPaymentStrictReceiveOp(attributes);
|
|
64
|
+
var opAttributes = {};
|
|
65
|
+
opAttributes.body = _xdr["default"].OperationBody.pathPaymentStrictReceive(payment);
|
|
66
|
+
this.setSourceAccount(opAttributes, opts);
|
|
67
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
68
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.pathPaymentStrictSend = pathPaymentStrictSend;
|
|
7
|
+
var _xdr = _interopRequireDefault(require("../xdr"));
|
|
8
|
+
var _decode_encode_muxed_account = require("../util/decode_encode_muxed_account");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
/**
|
|
11
|
+
* Creates a PathPaymentStrictSend operation.
|
|
12
|
+
*
|
|
13
|
+
* A `PathPaymentStrictSend` operation sends the specified amount to the
|
|
14
|
+
* destination account crediting at least `destMin` of `destAsset`, optionally
|
|
15
|
+
* through a path. XLM payments create the destination account if it does not
|
|
16
|
+
* exist.
|
|
17
|
+
*
|
|
18
|
+
* @function
|
|
19
|
+
* @alias Operation.pathPaymentStrictSend
|
|
20
|
+
* @see https://developers.stellar.org/docs/start/list-of-operations/#path-payment-strict-send
|
|
21
|
+
*
|
|
22
|
+
* @param {object} opts - Options object
|
|
23
|
+
* @param {Asset} opts.sendAsset - asset to pay with
|
|
24
|
+
* @param {string} opts.sendAmount - amount of sendAsset to send (excluding fees)
|
|
25
|
+
* @param {string} opts.destination - destination account to send to
|
|
26
|
+
* @param {Asset} opts.destAsset - asset the destination will receive
|
|
27
|
+
* @param {string} opts.destMin - minimum amount of destAsset to be receive
|
|
28
|
+
* @param {Asset[]} opts.path - array of Asset objects to use as the path
|
|
29
|
+
*
|
|
30
|
+
* @param {string} [opts.source] - The source account for the payment.
|
|
31
|
+
* Defaults to the transaction's source account.
|
|
32
|
+
*
|
|
33
|
+
* @returns {xdr.Operation} the resulting path payment operation
|
|
34
|
+
* (xdr.PathPaymentStrictSendOp)
|
|
35
|
+
*/
|
|
36
|
+
function pathPaymentStrictSend(opts) {
|
|
37
|
+
switch (true) {
|
|
38
|
+
case !opts.sendAsset:
|
|
39
|
+
throw new Error('Must specify a send asset');
|
|
40
|
+
case !this.isValidAmount(opts.sendAmount):
|
|
41
|
+
throw new TypeError(this.constructAmountRequirementsError('sendAmount'));
|
|
42
|
+
case !opts.destAsset:
|
|
43
|
+
throw new Error('Must provide a destAsset for a payment operation');
|
|
44
|
+
case !this.isValidAmount(opts.destMin):
|
|
45
|
+
throw new TypeError(this.constructAmountRequirementsError('destMin'));
|
|
46
|
+
default:
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
var attributes = {};
|
|
50
|
+
attributes.sendAsset = opts.sendAsset.toXDRObject();
|
|
51
|
+
attributes.sendAmount = this._toXDRAmount(opts.sendAmount);
|
|
52
|
+
try {
|
|
53
|
+
attributes.destination = (0, _decode_encode_muxed_account.decodeAddressToMuxedAccount)(opts.destination);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
throw new Error('destination is invalid');
|
|
56
|
+
}
|
|
57
|
+
attributes.destAsset = opts.destAsset.toXDRObject();
|
|
58
|
+
attributes.destMin = this._toXDRAmount(opts.destMin);
|
|
59
|
+
var path = opts.path ? opts.path : [];
|
|
60
|
+
attributes.path = path.map(function (x) {
|
|
61
|
+
return x.toXDRObject();
|
|
62
|
+
});
|
|
63
|
+
var payment = new _xdr["default"].PathPaymentStrictSendOp(attributes);
|
|
64
|
+
var opAttributes = {};
|
|
65
|
+
opAttributes.body = _xdr["default"].OperationBody.pathPaymentStrictSend(payment);
|
|
66
|
+
this.setSourceAccount(opAttributes, opts);
|
|
67
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
68
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.payment = payment;
|
|
7
|
+
var _xdr = _interopRequireDefault(require("../xdr"));
|
|
8
|
+
var _decode_encode_muxed_account = require("../util/decode_encode_muxed_account");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
/**
|
|
11
|
+
* Create a payment operation.
|
|
12
|
+
*
|
|
13
|
+
* @function
|
|
14
|
+
* @alias Operation.payment
|
|
15
|
+
* @see https://developers.stellar.org/docs/start/list-of-operations/#payment
|
|
16
|
+
*
|
|
17
|
+
* @param {object} opts - Options object
|
|
18
|
+
* @param {string} opts.destination - destination account ID
|
|
19
|
+
* @param {Asset} opts.asset - asset to send
|
|
20
|
+
* @param {string} opts.amount - amount to send
|
|
21
|
+
*
|
|
22
|
+
* @param {string} [opts.source] - The source account for the payment.
|
|
23
|
+
* Defaults to the transaction's source account.
|
|
24
|
+
*
|
|
25
|
+
* @returns {xdr.Operation} The resulting payment operation (xdr.PaymentOp)
|
|
26
|
+
*/
|
|
27
|
+
function payment(opts) {
|
|
28
|
+
if (!opts.asset) {
|
|
29
|
+
throw new Error('Must provide an asset for a payment operation');
|
|
30
|
+
}
|
|
31
|
+
if (!this.isValidAmount(opts.amount)) {
|
|
32
|
+
throw new TypeError(this.constructAmountRequirementsError('amount'));
|
|
33
|
+
}
|
|
34
|
+
var attributes = {};
|
|
35
|
+
try {
|
|
36
|
+
attributes.destination = (0, _decode_encode_muxed_account.decodeAddressToMuxedAccount)(opts.destination);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
throw new Error('destination is invalid');
|
|
39
|
+
}
|
|
40
|
+
attributes.asset = opts.asset.toXDRObject();
|
|
41
|
+
attributes.amount = this._toXDRAmount(opts.amount);
|
|
42
|
+
var paymentOp = new _xdr["default"].PaymentOp(attributes);
|
|
43
|
+
var opAttributes = {};
|
|
44
|
+
opAttributes.body = _xdr["default"].OperationBody.payment(paymentOp);
|
|
45
|
+
this.setSourceAccount(opAttributes, opts);
|
|
46
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
47
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.restoreFootprint = restoreFootprint;
|
|
7
|
+
var _xdr = _interopRequireDefault(require("../xdr"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9
|
+
/**
|
|
10
|
+
* Builds a footprint restoration operation.
|
|
11
|
+
*
|
|
12
|
+
* It takes no parameters because the relevant footprint is derived from the
|
|
13
|
+
* transaction itself (see {@link TransactionBuilder}'s `opts.sorobanData`
|
|
14
|
+
* parameter (or {@link TransactionBuilder.setSorobanData} /
|
|
15
|
+
* {@link TransactionBuilder.setLedgerKeys}), which is a
|
|
16
|
+
* {@link xdr.SorobanTransactionData} instance that contains fee data & resource
|
|
17
|
+
* usage as part of {@link xdr.SorobanTransactionData}).
|
|
18
|
+
*
|
|
19
|
+
* @function
|
|
20
|
+
* @alias Operation.restoreFootprint
|
|
21
|
+
*
|
|
22
|
+
* @param {object} [opts] - an optional set of parameters
|
|
23
|
+
* @param {string} [opts.source] - an optional source account
|
|
24
|
+
*
|
|
25
|
+
* @returns {xdr.Operation} a Bump Footprint Expiration operation
|
|
26
|
+
* (xdr.RestoreFootprintOp)
|
|
27
|
+
*/
|
|
28
|
+
function restoreFootprint() {
|
|
29
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
30
|
+
var op = new _xdr["default"].RestoreFootprintOp({
|
|
31
|
+
ext: new _xdr["default"].ExtensionPoint(0)
|
|
32
|
+
});
|
|
33
|
+
var opAttributes = {
|
|
34
|
+
body: _xdr["default"].OperationBody.restoreFootprint(op)
|
|
35
|
+
};
|
|
36
|
+
this.setSourceAccount(opAttributes, opts !== null && opts !== void 0 ? opts : {});
|
|
37
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
38
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.revokeAccountSponsorship = revokeAccountSponsorship;
|
|
7
|
+
exports.revokeClaimableBalanceSponsorship = revokeClaimableBalanceSponsorship;
|
|
8
|
+
exports.revokeDataSponsorship = revokeDataSponsorship;
|
|
9
|
+
exports.revokeLiquidityPoolSponsorship = revokeLiquidityPoolSponsorship;
|
|
10
|
+
exports.revokeOfferSponsorship = revokeOfferSponsorship;
|
|
11
|
+
exports.revokeSignerSponsorship = revokeSignerSponsorship;
|
|
12
|
+
exports.revokeTrustlineSponsorship = revokeTrustlineSponsorship;
|
|
13
|
+
var _xdr = _interopRequireDefault(require("../xdr"));
|
|
14
|
+
var _strkey = require("../strkey");
|
|
15
|
+
var _keypair = require("../keypair");
|
|
16
|
+
var _asset = require("../asset");
|
|
17
|
+
var _liquidity_pool_id = require("../liquidity_pool_id");
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
|
+
/**
|
|
20
|
+
* Create a "revoke sponsorship" operation for an account.
|
|
21
|
+
*
|
|
22
|
+
* @function
|
|
23
|
+
* @alias Operation.revokeAccountSponsorship
|
|
24
|
+
* @param {object} opts Options object
|
|
25
|
+
* @param {string} opts.account - The sponsored account ID.
|
|
26
|
+
* @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
|
|
27
|
+
* @returns {xdr.Operation} xdr operation
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const op = Operation.revokeAccountSponsorship({
|
|
31
|
+
* account: 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
function revokeAccountSponsorship() {
|
|
36
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
37
|
+
if (!_strkey.StrKey.isValidEd25519PublicKey(opts.account)) {
|
|
38
|
+
throw new Error('account is invalid');
|
|
39
|
+
}
|
|
40
|
+
var ledgerKey = _xdr["default"].LedgerKey.account(new _xdr["default"].LedgerKeyAccount({
|
|
41
|
+
accountId: _keypair.Keypair.fromPublicKey(opts.account).xdrAccountId()
|
|
42
|
+
}));
|
|
43
|
+
var op = _xdr["default"].RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
|
|
44
|
+
var opAttributes = {};
|
|
45
|
+
opAttributes.body = _xdr["default"].OperationBody.revokeSponsorship(op);
|
|
46
|
+
this.setSourceAccount(opAttributes, opts);
|
|
47
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Create a "revoke sponsorship" operation for a trustline.
|
|
52
|
+
*
|
|
53
|
+
* @function
|
|
54
|
+
* @alias Operation.revokeTrustlineSponsorship
|
|
55
|
+
* @param {object} opts Options object
|
|
56
|
+
* @param {string} opts.account - The account ID which owns the trustline.
|
|
57
|
+
* @param {Asset | LiquidityPoolId} opts.asset - The trustline asset.
|
|
58
|
+
* @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
|
|
59
|
+
* @returns {xdr.Operation} xdr operation
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const op = Operation.revokeTrustlineSponsorship({
|
|
63
|
+
* account: 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7
|
|
64
|
+
* asset: new StellarBase.LiquidityPoolId(
|
|
65
|
+
* 'USDUSD',
|
|
66
|
+
* 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7'
|
|
67
|
+
* )
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
function revokeTrustlineSponsorship() {
|
|
72
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
73
|
+
if (!_strkey.StrKey.isValidEd25519PublicKey(opts.account)) {
|
|
74
|
+
throw new Error('account is invalid');
|
|
75
|
+
}
|
|
76
|
+
var asset;
|
|
77
|
+
if (opts.asset instanceof _asset.Asset) {
|
|
78
|
+
asset = opts.asset.toTrustLineXDRObject();
|
|
79
|
+
} else if (opts.asset instanceof _liquidity_pool_id.LiquidityPoolId) {
|
|
80
|
+
asset = opts.asset.toXDRObject();
|
|
81
|
+
} else {
|
|
82
|
+
throw new TypeError('asset must be an Asset or LiquidityPoolId');
|
|
83
|
+
}
|
|
84
|
+
var ledgerKey = _xdr["default"].LedgerKey.trustline(new _xdr["default"].LedgerKeyTrustLine({
|
|
85
|
+
accountId: _keypair.Keypair.fromPublicKey(opts.account).xdrAccountId(),
|
|
86
|
+
asset: asset
|
|
87
|
+
}));
|
|
88
|
+
var op = _xdr["default"].RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
|
|
89
|
+
var opAttributes = {};
|
|
90
|
+
opAttributes.body = _xdr["default"].OperationBody.revokeSponsorship(op);
|
|
91
|
+
this.setSourceAccount(opAttributes, opts);
|
|
92
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Create a "revoke sponsorship" operation for an offer.
|
|
97
|
+
*
|
|
98
|
+
* @function
|
|
99
|
+
* @alias Operation.revokeOfferSponsorship
|
|
100
|
+
* @param {object} opts Options object
|
|
101
|
+
* @param {string} opts.seller - The account ID which created the offer.
|
|
102
|
+
* @param {string} opts.offerId - The offer ID.
|
|
103
|
+
* @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
|
|
104
|
+
* @returns {xdr.Operation} xdr operation
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* const op = Operation.revokeOfferSponsorship({
|
|
108
|
+
* seller: 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7
|
|
109
|
+
* offerId: '1234'
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
*/
|
|
113
|
+
function revokeOfferSponsorship() {
|
|
114
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
115
|
+
if (!_strkey.StrKey.isValidEd25519PublicKey(opts.seller)) {
|
|
116
|
+
throw new Error('seller is invalid');
|
|
117
|
+
}
|
|
118
|
+
if (typeof opts.offerId !== 'string') {
|
|
119
|
+
throw new Error('offerId is invalid');
|
|
120
|
+
}
|
|
121
|
+
var ledgerKey = _xdr["default"].LedgerKey.offer(new _xdr["default"].LedgerKeyOffer({
|
|
122
|
+
sellerId: _keypair.Keypair.fromPublicKey(opts.seller).xdrAccountId(),
|
|
123
|
+
offerId: _xdr["default"].Int64.fromString(opts.offerId)
|
|
124
|
+
}));
|
|
125
|
+
var op = _xdr["default"].RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
|
|
126
|
+
var opAttributes = {};
|
|
127
|
+
opAttributes.body = _xdr["default"].OperationBody.revokeSponsorship(op);
|
|
128
|
+
this.setSourceAccount(opAttributes, opts);
|
|
129
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Create a "revoke sponsorship" operation for a data entry.
|
|
134
|
+
*
|
|
135
|
+
* @function
|
|
136
|
+
* @alias Operation.revokeDataSponsorship
|
|
137
|
+
* @param {object} opts Options object
|
|
138
|
+
* @param {string} opts.account - The account ID which owns the data entry.
|
|
139
|
+
* @param {string} opts.name - The name of the data entry
|
|
140
|
+
* @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
|
|
141
|
+
* @returns {xdr.Operation} xdr operation
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* const op = Operation.revokeDataSponsorship({
|
|
145
|
+
* account: 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7
|
|
146
|
+
* name: 'foo'
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
*/
|
|
150
|
+
function revokeDataSponsorship() {
|
|
151
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
152
|
+
if (!_strkey.StrKey.isValidEd25519PublicKey(opts.account)) {
|
|
153
|
+
throw new Error('account is invalid');
|
|
154
|
+
}
|
|
155
|
+
if (typeof opts.name !== 'string' || opts.name.length > 64) {
|
|
156
|
+
throw new Error('name must be a string, up to 64 characters');
|
|
157
|
+
}
|
|
158
|
+
var ledgerKey = _xdr["default"].LedgerKey.data(new _xdr["default"].LedgerKeyData({
|
|
159
|
+
accountId: _keypair.Keypair.fromPublicKey(opts.account).xdrAccountId(),
|
|
160
|
+
dataName: opts.name
|
|
161
|
+
}));
|
|
162
|
+
var op = _xdr["default"].RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
|
|
163
|
+
var opAttributes = {};
|
|
164
|
+
opAttributes.body = _xdr["default"].OperationBody.revokeSponsorship(op);
|
|
165
|
+
this.setSourceAccount(opAttributes, opts);
|
|
166
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Create a "revoke sponsorship" operation for a claimable balance.
|
|
171
|
+
*
|
|
172
|
+
* @function
|
|
173
|
+
* @alias Operation.revokeClaimableBalanceSponsorship
|
|
174
|
+
* @param {object} opts Options object
|
|
175
|
+
* @param {string} opts.balanceId - The sponsored claimable balance ID.
|
|
176
|
+
* @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
|
|
177
|
+
* @returns {xdr.Operation} xdr operation
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* const op = Operation.revokeClaimableBalanceSponsorship({
|
|
181
|
+
* balanceId: '00000000da0d57da7d4850e7fc10d2a9d0ebc731f7afb40574c03395b17d49149b91f5be',
|
|
182
|
+
* });
|
|
183
|
+
*
|
|
184
|
+
*/
|
|
185
|
+
function revokeClaimableBalanceSponsorship() {
|
|
186
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
187
|
+
if (typeof opts.balanceId !== 'string') {
|
|
188
|
+
throw new Error('balanceId is invalid');
|
|
189
|
+
}
|
|
190
|
+
var ledgerKey = _xdr["default"].LedgerKey.claimableBalance(new _xdr["default"].LedgerKeyClaimableBalance({
|
|
191
|
+
balanceId: _xdr["default"].ClaimableBalanceId.fromXDR(opts.balanceId, 'hex')
|
|
192
|
+
}));
|
|
193
|
+
var op = _xdr["default"].RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
|
|
194
|
+
var opAttributes = {};
|
|
195
|
+
opAttributes.body = _xdr["default"].OperationBody.revokeSponsorship(op);
|
|
196
|
+
this.setSourceAccount(opAttributes, opts);
|
|
197
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Creates a "revoke sponsorship" operation for a liquidity pool.
|
|
202
|
+
*
|
|
203
|
+
* @function
|
|
204
|
+
* @alias Operation.revokeLiquidityPoolSponsorship
|
|
205
|
+
* @param {object} opts – Options object.
|
|
206
|
+
* @param {string} opts.liquidityPoolId - The sponsored liquidity pool ID in 'hex' string.
|
|
207
|
+
* @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
|
|
208
|
+
* @returns {xdr.Operation} xdr Operation.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* const op = Operation.revokeLiquidityPoolSponsorship({
|
|
212
|
+
* liquidityPoolId: 'dd7b1ab831c273310ddbec6f97870aa83c2fbd78ce22aded37ecbf4f3380fac7',
|
|
213
|
+
* });
|
|
214
|
+
*
|
|
215
|
+
*/
|
|
216
|
+
function revokeLiquidityPoolSponsorship() {
|
|
217
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
218
|
+
if (typeof opts.liquidityPoolId !== 'string') {
|
|
219
|
+
throw new Error('liquidityPoolId is invalid');
|
|
220
|
+
}
|
|
221
|
+
var ledgerKey = _xdr["default"].LedgerKey.liquidityPool(new _xdr["default"].LedgerKeyLiquidityPool({
|
|
222
|
+
liquidityPoolId: _xdr["default"].PoolId.fromXDR(opts.liquidityPoolId, 'hex')
|
|
223
|
+
}));
|
|
224
|
+
var op = _xdr["default"].RevokeSponsorshipOp.revokeSponsorshipLedgerEntry(ledgerKey);
|
|
225
|
+
var opAttributes = {
|
|
226
|
+
body: _xdr["default"].OperationBody.revokeSponsorship(op)
|
|
227
|
+
};
|
|
228
|
+
this.setSourceAccount(opAttributes, opts);
|
|
229
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Create a "revoke sponsorship" operation for a signer.
|
|
234
|
+
*
|
|
235
|
+
* @function
|
|
236
|
+
* @alias Operation.revokeSignerSponsorship
|
|
237
|
+
* @param {object} opts Options object
|
|
238
|
+
* @param {string} opts.account - The account ID where the signer sponsorship is being removed from.
|
|
239
|
+
* @param {object} opts.signer - The signer whose sponsorship is being removed.
|
|
240
|
+
* @param {string} [opts.signer.ed25519PublicKey] - The ed25519 public key of the signer.
|
|
241
|
+
* @param {Buffer|string} [opts.signer.sha256Hash] - sha256 hash (Buffer or hex string).
|
|
242
|
+
* @param {Buffer|string} [opts.signer.preAuthTx] - Hash (Buffer or hex string) of transaction.
|
|
243
|
+
* @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
|
|
244
|
+
* @returns {xdr.Operation} xdr operation
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* const op = Operation.revokeSignerSponsorship({
|
|
248
|
+
* account: 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7
|
|
249
|
+
* signer: {
|
|
250
|
+
* ed25519PublicKey: 'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ'
|
|
251
|
+
* }
|
|
252
|
+
* })
|
|
253
|
+
*
|
|
254
|
+
*/
|
|
255
|
+
function revokeSignerSponsorship() {
|
|
256
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
257
|
+
if (!_strkey.StrKey.isValidEd25519PublicKey(opts.account)) {
|
|
258
|
+
throw new Error('account is invalid');
|
|
259
|
+
}
|
|
260
|
+
var key;
|
|
261
|
+
if (opts.signer.ed25519PublicKey) {
|
|
262
|
+
if (!_strkey.StrKey.isValidEd25519PublicKey(opts.signer.ed25519PublicKey)) {
|
|
263
|
+
throw new Error('signer.ed25519PublicKey is invalid.');
|
|
264
|
+
}
|
|
265
|
+
var rawKey = _strkey.StrKey.decodeEd25519PublicKey(opts.signer.ed25519PublicKey);
|
|
266
|
+
key = new _xdr["default"].SignerKey.signerKeyTypeEd25519(rawKey);
|
|
267
|
+
} else if (opts.signer.preAuthTx) {
|
|
268
|
+
var buffer;
|
|
269
|
+
if (typeof opts.signer.preAuthTx === 'string') {
|
|
270
|
+
buffer = Buffer.from(opts.signer.preAuthTx, 'hex');
|
|
271
|
+
} else {
|
|
272
|
+
buffer = opts.signer.preAuthTx;
|
|
273
|
+
}
|
|
274
|
+
if (!(Buffer.isBuffer(buffer) && buffer.length === 32)) {
|
|
275
|
+
throw new Error('signer.preAuthTx must be 32 bytes Buffer.');
|
|
276
|
+
}
|
|
277
|
+
key = new _xdr["default"].SignerKey.signerKeyTypePreAuthTx(buffer);
|
|
278
|
+
} else if (opts.signer.sha256Hash) {
|
|
279
|
+
var _buffer;
|
|
280
|
+
if (typeof opts.signer.sha256Hash === 'string') {
|
|
281
|
+
_buffer = Buffer.from(opts.signer.sha256Hash, 'hex');
|
|
282
|
+
} else {
|
|
283
|
+
_buffer = opts.signer.sha256Hash;
|
|
284
|
+
}
|
|
285
|
+
if (!(Buffer.isBuffer(_buffer) && _buffer.length === 32)) {
|
|
286
|
+
throw new Error('signer.sha256Hash must be 32 bytes Buffer.');
|
|
287
|
+
}
|
|
288
|
+
key = new _xdr["default"].SignerKey.signerKeyTypeHashX(_buffer);
|
|
289
|
+
} else {
|
|
290
|
+
throw new Error('signer is invalid');
|
|
291
|
+
}
|
|
292
|
+
var signer = new _xdr["default"].RevokeSponsorshipOpSigner({
|
|
293
|
+
accountId: _keypair.Keypair.fromPublicKey(opts.account).xdrAccountId(),
|
|
294
|
+
signerKey: key
|
|
295
|
+
});
|
|
296
|
+
var op = _xdr["default"].RevokeSponsorshipOp.revokeSponsorshipSigner(signer);
|
|
297
|
+
var opAttributes = {};
|
|
298
|
+
opAttributes.body = _xdr["default"].OperationBody.revokeSponsorship(op);
|
|
299
|
+
this.setSourceAccount(opAttributes, opts);
|
|
300
|
+
return new _xdr["default"].Operation(opAttributes);
|
|
301
|
+
}
|