New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

stellar-base

Package Overview
Dependencies
Maintainers
9
Versions
182
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stellar-base - npm Package Compare versions

Comparing version 9.0.0-soroban.0 to 9.0.0-soroban.1

57

lib/contract.js

@@ -19,5 +19,6 @@ "use strict";

*
* `Contract` represents a single contract in the Stellar network. Contract embodies the interface of the contract. See
* [Contracts](https://developers.stellar.org/docs/glossary/contracts/) for
* more information about how contracts work in Stellar.
* `Contract` represents a single contract in the Stellar network, embodying the
* interface of the contract. See
* [Contracts](https://soroban.stellar.org/docs/learn/interacting-with-contracts)
* for more information about how contracts work in Stellar.
*

@@ -29,3 +30,3 @@ * @constructor

*/
// TODO: Support contract deployment, maybe
// TODO: Support contract deployment, maybe?
var Contract = /*#__PURE__*/function () {

@@ -51,5 +52,24 @@ // TODO: Figure out contract owner/id stuff here. How should we represent that?

/**
* Returns an operation that will invoke this contract call.
*
* @todo Allow easily building `Operation`s that invoke multiple contract
* calls at once via this abstraction layer. For example, something like
*
* ```js
* let [ a, b ] = [someId1, someId2].map(id => { new Contract(id) });
*
* let combinedOp = Operation.invokeHostFunctions({
* source: undefined, // optional
* functions: [
* a.partialCall("hello"),
* a.partialCall("transfer", ...),
* b.partialCall("increment"),
* ]
* });
* ```
*
* @param {string} method - name of the method to call
* @param {...xdr.ScVal} params - arguments to pass to the function call
* @returns {xdr.Operation} Build a InvokeHostFunctionOp operation to call the contract.
* @returns {xdr.Operation} Build a InvokeHostFunctionOp operation to call the
* contract.
*/

@@ -64,14 +84,23 @@ }, {

return _operation.Operation.invokeHostFunction({
"function": _xdr["default"].HostFunction.hostFunctionTypeInvokeContract([_xdr["default"].ScVal.scvBytes(contractId), _xdr["default"].ScVal.scvSymbol(method)].concat(params)),
// TODO: Figure out how to calculate this or get it from the user?
footprint: new _xdr["default"].LedgerFootprint({
readOnly: [_xdr["default"].LedgerKey.contractData(new _xdr["default"].LedgerKeyContractData({
contractId: contractId,
key: _xdr["default"].ScVal.scvLedgerKeyContractExecutable()
}))],
readWrite: []
}),
args: _xdr["default"].HostFunctionArgs.hostFunctionTypeInvokeContract([_xdr["default"].ScVal.scvBytes(contractId), _xdr["default"].ScVal.scvSymbol(method)].concat(params)),
auth: []
});
}
/**
* Returns the read-only footprint entry necessary for any invocations to this
* contract, for convenience when adding it to your transaction's overall
* footprint.
*
* @returns {xdr.LedgerKey} the contract's executable data ledger key
*/
}, {
key: "getFootprint",
value: function getFootprint() {
var contractId = Buffer.from(this._id, 'hex');
return _xdr["default"].LedgerKey.contractData(new _xdr["default"].LedgerKeyContractData({
contractId: contractId,
key: _xdr["default"].ScVal.scvLedgerKeyContractExecutable()
}));
}
}]);

@@ -78,0 +107,0 @@ return Contract;

@@ -75,3 +75,6 @@ "use strict";

/**
* `Operation` class represents [operations](https://developers.stellar.org/docs/glossary/operations/) in Stellar network.
* `Operation` class represents
* [operations](https://developers.stellar.org/docs/glossary/operations/) in
* Stellar network.
*
* Use one of static methods to create operations:

@@ -109,2 +112,3 @@ * * `{@link Operation.createAccount}`

* * `{@link Operation.invokeHostFunction}`
* * `{@link Operation.invokeHostFunctions}`
*

@@ -409,5 +413,5 @@ * @class Operation

result.type = 'invokeHostFunction';
result["function"] = attrs["function"]();
result.footprint = attrs.footprint();
result.auth = attrs.auth();
// TODO: Unpack each of the xdr.HostFunction instances into friendlier
// objects?
result.functions = attrs.functions();
break;

@@ -686,2 +690,3 @@ }

Operation.liquidityPoolWithdraw = ops.liquidityPoolWithdraw;
Operation.invokeHostFunction = ops.invokeHostFunction;
Operation.invokeHostFunction = ops.invokeHostFunction;
Operation.invokeHostFunctions = ops.invokeHostFunctions;

@@ -90,2 +90,8 @@ "use strict";

});
Object.defineProperty(exports, "invokeHostFunctions", {
enumerable: true,
get: function get() {
return _invoke_host_function.invokeHostFunctions;
}
});
Object.defineProperty(exports, "liquidityPoolDeposit", {

@@ -92,0 +98,0 @@ enumerable: true,

@@ -7,6 +7,7 @@ "use strict";

exports.invokeHostFunction = invokeHostFunction;
exports.invokeHostFunctions = invokeHostFunctions;
var _xdr = _interopRequireDefault(require("../xdr"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Invokes a smart contract function
* Invokes a single smart contract function.
*

@@ -17,16 +18,43 @@ * @function

* @param {object} opts - options object
* @param {xdr.HostFunction} opts.function - host function to invoke
* @param {xdr.LedgerFootprint} [opts.footprint] - footprint of the ledger state accessed by this call
* @param {xdr.ContractAuth[]} [opts.auth] - authorizations for the call
* @param {xdr.HostFunctionArgs} opts.args - parameters to pass to the host
* function being invoked
* @param {xdr.ContractAuth[]} [opts.auth] - list of authorizations for the call
* @param {string} [opts.source] - an optional source account
*
* @returns {xdr.Operation} an Invoke Host Function operation (xdr.InvokeHostFunctionOp)
* @returns {xdr.Operation} an Invoke Host Function operation
* (xdr.InvokeHostFunctionOp)
*/
function invokeHostFunction(opts) {
if (!opts["function"]) {
throw new TypeError('function argument is required');
if (!opts.args) {
throw new TypeError("function arguments ('args') required (got ".concat(JSON.stringify(opts), ")"));
}
var hostFn = new _xdr["default"].HostFunction({
args: opts.args,
auth: opts.auth || []
});
return this.invokeHostFunctions({
source: opts.source,
functions: [hostFn]
});
}
/**
* Invokes multiple smart contract functions via a single operation.
*
* @function
* @alias Operation.invokeHostFunctions
*
* @param {object} opts - options for the operation
* @param {xdr.HostFunction[]} opts.functions - a list of contract functions to
* invoke in this operation.
* @param {string} [opts.source] - an optional source account
*
* @returns {xdr.Operation} an Invoke Host Function operation
* (xdr.InvokeHostFunctionOp) with xdr.HostFunction instances corresponding
* to each invocation
*
*/
function invokeHostFunctions(opts) {
var invokeHostFunctionOp = new _xdr["default"].InvokeHostFunctionOp({
"function": opts["function"],
footprint: opts.footprint,
auth: opts.auth
functions: opts.functions
});

@@ -33,0 +61,0 @@ var opAttributes = {

@@ -90,4 +90,6 @@ "use strict";

var requiresContractSignatures = (this.operations || []).some(function (op) {
return op.type === 'invokeHostFunction' && op.auth.some(function (a) {
return a.addressWithNonce();
return op.type === 'invokeHostFunction' && op.functions.some(function (fn) {
return fn.auth().some(function (a) {
return a.addressWithNonce();
});
});

@@ -94,0 +96,0 @@ });

@@ -126,2 +126,8 @@ "use strict";

* 2015" for the pubnet)
* @param {xdr.SorobanTransactionData | string} [opts.sorobanData] - an optional xdr instance of SorobanTransactionData
* to be set as .Transaction.Ext.SorobanData. It can be xdr object or base64 string.
* For non-contract(non-Soroban) transactions, this has no effect.
* In the case of Soroban transactions, SorobanTransactionData can be obtained from a prior simulation of
* the transaction with a contract invocation and provides necessary resource estimations.
*
*/

@@ -150,2 +156,3 @@ exports.TimeoutInfinite = TimeoutInfinite;

this.networkPassphrase = opts.networkPassphrase || null;
this.sorobanData = unmarshalSorobanData(opts.sorobanData);
}

@@ -451,2 +458,22 @@

/**
* Set the {SorobanTransactionData}. For non-contract(non-Soroban) transactions,
* this setting has no effect.
* In the case of Soroban transactions, set to an instance of
* SorobanTransactionData. This can typically be obtained from the simulation
* response based on a transaction with a InvokeHostFunctionOp.
* It provides necessary resource estimations for contract invocation.
*
* @param {xdr.SorobanTransactionData | string} sorobanData the SorobanTransactionData as xdr object or base64 string
* to be set as Transaction.Ext.SorobanData.
*
* @returns {TransactionBuilder}
*/
}, {
key: "setSorobanData",
value: function setSorobanData(sorobanData) {
this.sorobanData = unmarshalSorobanData(sorobanData);
return this;
}
/**
* This will build the transaction.

@@ -500,3 +527,13 @@ * It will also increment the source account's sequence number by 1.

attrs.sourceAccount = (0, _decode_encode_muxed_account.decodeAddressToMuxedAccount)(this.source.accountId());
attrs.ext = new _xdr["default"].TransactionExt(0);
// TODO - remove this workaround for TransactionExt ts constructor
// and use the typescript generated static factory method once fixed
// https://github.com/stellar/dts-xdr/issues/5
if (this.sorobanData) {
// @ts-ignore
attrs.ext = new _xdr["default"].TransactionExt(1, this.sorobanData);
} else {
// @ts-ignore
attrs.ext = new _xdr["default"].TransactionExt(0, _xdr["default"].Void);
}
var xtx = new _xdr["default"].Transaction(attrs);

@@ -631,2 +668,16 @@ xtx.operations(this.operations);

return d instanceof Date && !isNaN(d);
}
/**
* local helper function to convert SorobanTransactionData from
* base64 string or xdr object.
* @param {string | xdr.SorobanTransactionData} sorobanData the soroban transaction data
* @returns {xdr.SorobanTransactionData}
*/
function unmarshalSorobanData(sorobanData) {
if (typeof sorobanData === 'string') {
var buffer = Buffer.from(sorobanData, 'base64');
sorobanData = _xdr["default"].SorobanTransactionData.fromXDR(buffer);
}
return sorobanData;
}
{
"name": "stellar-base",
"version": "9.0.0-soroban.0",
"version": "9.0.0-soroban.1",
"description": "Low-level support library for the Stellar network.",

@@ -71,12 +71,12 @@ "main": "./lib/index.js",

"devDependencies": {
"@babel/cli": "^7.21.0",
"@babel/core": "^7.12.0",
"@babel/eslint-parser": "^7.21.3",
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.8",
"@babel/eslint-parser": "^7.21.8",
"@babel/eslint-plugin": "^7.19.1",
"@babel/preset-env": "^7.21.4",
"@babel/preset-env": "^7.21.5",
"@babel/register": "^7.21.0",
"@definitelytyped/dtslint": "^0.0.159",
"@istanbuljs/nyc-config-babel": "3.0.0",
"@types/node": "^18.15.11",
"@typescript-eslint/parser": "^5.57.1",
"@types/node": "^20.1.1",
"@typescript-eslint/parser": "^5.59.5",
"babel-loader": "^9.1.2",

@@ -87,3 +87,3 @@ "babel-plugin-istanbul": "^6.1.1",

"cross-env": "^7.0.3",
"eslint": "^8.37.0",
"eslint": "^8.40.0",
"eslint-config-airbnb-base": "^15.0.0",

@@ -99,3 +99,3 @@ "eslint-config-prettier": "^8.8.0",

"jsdoc": "^4.0.2",
"karma": "^6.4.1",
"karma": "^6.4.2",
"karma-chrome-launcher": "^3.1.0",

@@ -107,3 +107,3 @@ "karma-coverage": "^2.2.0",

"karma-webpack": "^5.0.0",
"lint-staged": "^13.2.0",
"lint-staged": "^13.2.2",
"minami": "^1.1.1",

@@ -113,3 +113,3 @@ "mocha": "^10.2.0",

"nyc": "^15.1.0",
"prettier": "^2.8.7",
"prettier": "^2.8.8",
"randombytes": "^2.1.0",

@@ -119,7 +119,7 @@ "sinon": "^15.0.3",

"taffydb": "^2.7.3",
"terser-webpack-plugin": "^5.3.7",
"terser-webpack-plugin": "^5.3.8",
"ts-node": "^10.9.1",
"typescript": "^5.0.3",
"webpack": "^5.77.0",
"webpack-cli": "^5.0.1"
"webpack": "^5.82.0",
"webpack-cli": "^5.1.0"
},

@@ -131,3 +131,3 @@ "dependencies": {

"crypto-browserify": "^3.12.0",
"js-xdr": "^1.3.0",
"js-xdr": "^2.0.0",
"lodash": "^4.17.21",

@@ -134,0 +134,0 @@ "sha.js": "^2.3.6",

@@ -541,7 +541,8 @@ // TypeScript Version: 2.9

interface InvokeHostFunction extends BaseOptions {
function: xdr.HostFunction;
parameters: xdr.ScVal[];
footprint: xdr.LedgerFootprint;
args: xdr.HostFunctionArgs;
auth: xdr.ContractAuth[];
}
interface InvokeHostFunctions extends BaseOptions {
functions: xdr.HostFunction[];
}
}

@@ -860,6 +861,3 @@ export type OperationOptions =

interface InvokeHostFunction extends BaseOperation<OperationType.InvokeHostFunction> {
function: xdr.HostFunction;
parameters: xdr.ScVal[];
footprint: xdr.LedgerFootprint;
auth: xdr.ContractAuth[];
functions: xdr.HostFunction[];
}

@@ -869,2 +867,5 @@ function invokeHostFunction(

): xdr.Operation<InvokeHostFunction>;
function invokeHostFunctions(
options: OperationOptions.InvokeHostFunctions
): xdr.Operation<InvokeHostFunction>;

@@ -1007,2 +1008,3 @@ function fromXDRObject<T extends Operation = Operation>(

setExtraSigners(extraSigners: string[]): this;
setSorobanData(sorobanData: string | xdr.SorobanTransactionData): this;
build(): Transaction;

@@ -1040,2 +1042,3 @@ setNetworkPassphrase(networkPassphrase: string): this;

extraSigners?: string[];
sorobanData?: string | xdr.SorobanTransactionData;
}

@@ -1042,0 +1045,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc