Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@multiversx/sdk-core

Package Overview
Dependencies
Maintainers
10
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@multiversx/sdk-core - npm Package Compare versions

Comparing version 13.2.1 to 13.3.0-beta.0

8

out/converters/transactionsConverter.js

@@ -25,2 +25,6 @@ "use strict";

guardianSignature: this.toHexOrUndefined(transaction.guardianSignature),
relayer: transaction.relayer ? transaction.relayer : undefined,
innerTransactions: transaction.innerTransactions.length
? transaction.innerTransactions.map((tx) => this.transactionToPlainObject(tx))
: undefined,
};

@@ -52,2 +56,6 @@ return plainObject;

guardianSignature: this.bufferFromHex(object.guardianSignature),
relayer: object.relayer,
innerTransactions: object.innerTransactions
? object.innerTransactions.map((tx) => this.plainObjectToTransaction(tx))
: undefined,
});

@@ -54,0 +62,0 @@ return transaction;

@@ -237,1 +237,8 @@ /**

}
/**
* Signals an error when querying a smart contract.
*/
export declare class ErrSmartContractQuery extends Err {
returnCode: string;
constructor(returnCode: string, message: string);
}

12

out/errors.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrParseTransactionOutcome = exports.ErrInvalidInnerTransaction = exports.ErrBadUsage = exports.ErrInvalidTokenIdentifier = exports.ErrIsCompletedFieldIsMissingOnTransaction = exports.ErrGasLimitShouldBe0ForInnerTransaction = exports.ErrInvalidRelayedV2BuilderArguments = exports.ErrInvalidRelayedV1BuilderArguments = exports.ErrNotImplemented = exports.ErrContractInteraction = exports.ErrCodec = exports.ErrCannotParseTransactionOutcome = exports.ErrCannotParseContractResults = exports.ErrMissingFieldOnEnum = exports.ErrMissingFieldOnStruct = exports.ErrTypingSystem = exports.ErrMock = exports.ErrContractHasNoAddress = exports.ErrContract = exports.ErrExpectedTransactionEventsNotFound = exports.ErrExpectedTransactionStatusNotReached = exports.ErrTransactionWatcherTimeout = exports.ErrAsyncTimerAborted = exports.ErrAsyncTimerAlreadyRunning = exports.ErrInvalidFunctionName = exports.ErrSignatureCannotCreate = exports.ErrTransactionOptionsInvalid = exports.ErrTransactionVersionInvalid = exports.ErrNonceInvalid = exports.ErrNotEnoughGas = exports.ErrAddressEmpty = exports.ErrAddressBadHrp = exports.ErrAddressCannotCreate = exports.ErrUnexpectedCondition = exports.ErrInvariantFailed = exports.ErrBadType = exports.ErrUnsupportedOperation = exports.ErrInvalidArgument = exports.Err = void 0;
exports.ErrSmartContractQuery = exports.ErrParseTransactionOutcome = exports.ErrInvalidInnerTransaction = exports.ErrBadUsage = exports.ErrInvalidTokenIdentifier = exports.ErrIsCompletedFieldIsMissingOnTransaction = exports.ErrGasLimitShouldBe0ForInnerTransaction = exports.ErrInvalidRelayedV2BuilderArguments = exports.ErrInvalidRelayedV1BuilderArguments = exports.ErrNotImplemented = exports.ErrContractInteraction = exports.ErrCodec = exports.ErrCannotParseTransactionOutcome = exports.ErrCannotParseContractResults = exports.ErrMissingFieldOnEnum = exports.ErrMissingFieldOnStruct = exports.ErrTypingSystem = exports.ErrMock = exports.ErrContractHasNoAddress = exports.ErrContract = exports.ErrExpectedTransactionEventsNotFound = exports.ErrExpectedTransactionStatusNotReached = exports.ErrTransactionWatcherTimeout = exports.ErrAsyncTimerAborted = exports.ErrAsyncTimerAlreadyRunning = exports.ErrInvalidFunctionName = exports.ErrSignatureCannotCreate = exports.ErrTransactionOptionsInvalid = exports.ErrTransactionVersionInvalid = exports.ErrNonceInvalid = exports.ErrNotEnoughGas = exports.ErrAddressEmpty = exports.ErrAddressBadHrp = exports.ErrAddressCannotCreate = exports.ErrUnexpectedCondition = exports.ErrInvariantFailed = exports.ErrBadType = exports.ErrUnsupportedOperation = exports.ErrInvalidArgument = exports.Err = void 0;
/**

@@ -372,2 +372,12 @@ * The base class for exceptions (errors).

exports.ErrParseTransactionOutcome = ErrParseTransactionOutcome;
/**
* Signals an error when querying a smart contract.
*/
class ErrSmartContractQuery extends Err {
constructor(returnCode, message) {
super(message);
this.returnCode = returnCode;
}
}
exports.ErrSmartContractQuery = ErrSmartContractQuery;
//# sourceMappingURL=errors.js.map

@@ -26,2 +26,4 @@ /// <reference types="node" />

guardianSignature?: string;
relayer?: string;
innerTransactions?: IPlainTransactionObject[];
}

@@ -93,2 +95,4 @@ export interface ISignature {

guardianSignature: Uint8Array;
relayer: string;
innerTransactions: ITransaction[];
}

@@ -41,2 +41,4 @@ "use strict";

* @property {Uint8Array|null} [GuardianSignature] Transaction GuardianSignature
* @property {Uint8Array|null} [Relayer] Transaction Relayer
* @property {Array.<proto.ITransaction>|null} [InnerTransactions] Transaction InnerTransactions
*/

@@ -52,2 +54,3 @@ /**

function Transaction(properties) {
this.InnerTransactions = [];
if (properties)

@@ -164,2 +167,16 @@ for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)

/**
* Transaction Relayer.
* @member {Uint8Array} Relayer
* @memberof proto.Transaction
* @instance
*/
Transaction.prototype.Relayer = $util.newBuffer([]);
/**
* Transaction InnerTransactions.
* @member {Array.<proto.ITransaction>} InnerTransactions
* @memberof proto.Transaction
* @instance
*/
Transaction.prototype.InnerTransactions = $util.emptyArray;
/**
* Creates a new Transaction instance using the specified properties.

@@ -217,2 +234,7 @@ * @function create

writer.uint32(/* id 15, wireType 2 =*/ 122).bytes(message.GuardianSignature);
if (message.Relayer != null && Object.hasOwnProperty.call(message, "Relayer"))
writer.uint32(/* id 16, wireType 2 =*/ 130).bytes(message.Relayer);
if (message.InnerTransactions != null && message.InnerTransactions.length)
for (var i = 0; i < message.InnerTransactions.length; ++i)
$root.proto.Transaction.encode(message.InnerTransactions[i], writer.uint32(/* id 17, wireType 2 =*/ 138).fork()).ldelim();
return writer;

@@ -310,2 +332,12 @@ };

}
case 16: {
message.Relayer = reader.bytes();
break;
}
case 17: {
if (!(message.InnerTransactions && message.InnerTransactions.length))
message.InnerTransactions = [];
message.InnerTransactions.push($root.proto.Transaction.decode(reader, reader.uint32()));
break;
}
default:

@@ -389,2 +421,14 @@ reader.skipType(tag & 7);

return "GuardianSignature: buffer expected";
if (message.Relayer != null && message.hasOwnProperty("Relayer"))
if (!(message.Relayer && typeof message.Relayer.length === "number" || $util.isString(message.Relayer)))
return "Relayer: buffer expected";
if (message.InnerTransactions != null && message.hasOwnProperty("InnerTransactions")) {
if (!Array.isArray(message.InnerTransactions))
return "InnerTransactions: array expected";
for (var i = 0; i < message.InnerTransactions.length; ++i) {
var error = $root.proto.Transaction.verify(message.InnerTransactions[i]);
if (error)
return "InnerTransactions." + error;
}
}
return null;

@@ -485,2 +529,17 @@ };

message.GuardianSignature = object.GuardianSignature;
if (object.Relayer != null)
if (typeof object.Relayer === "string")
$util.base64.decode(object.Relayer, message.Relayer = $util.newBuffer($util.base64.length(object.Relayer)), 0);
else if (object.Relayer.length >= 0)
message.Relayer = object.Relayer;
if (object.InnerTransactions) {
if (!Array.isArray(object.InnerTransactions))
throw TypeError(".proto.Transaction.InnerTransactions: array expected");
message.InnerTransactions = [];
for (var i = 0; i < object.InnerTransactions.length; ++i) {
if (typeof object.InnerTransactions[i] !== "object")
throw TypeError(".proto.Transaction.InnerTransactions: object expected");
message.InnerTransactions[i] = $root.proto.Transaction.fromObject(object.InnerTransactions[i]);
}
}
return message;

@@ -501,2 +560,4 @@ };

var object = {};
if (options.arrays || options.defaults)
object.InnerTransactions = [];
if (options.defaults) {

@@ -593,2 +654,9 @@ if ($util.Long) {

}
if (options.bytes === String)
object.Relayer = "";
else {
object.Relayer = [];
if (options.bytes !== Array)
object.Relayer = $util.newBuffer(object.Relayer);
}
}

@@ -634,2 +702,9 @@ if (message.Nonce != null && message.hasOwnProperty("Nonce"))

object.GuardianSignature = options.bytes === String ? $util.base64.encode(message.GuardianSignature, 0, message.GuardianSignature.length) : options.bytes === Array ? Array.prototype.slice.call(message.GuardianSignature) : message.GuardianSignature;
if (message.Relayer != null && message.hasOwnProperty("Relayer"))
object.Relayer = options.bytes === String ? $util.base64.encode(message.Relayer, 0, message.Relayer.length) : options.bytes === Array ? Array.prototype.slice.call(message.Relayer) : message.Relayer;
if (message.InnerTransactions && message.InnerTransactions.length) {
object.InnerTransactions = [];
for (var j = 0; j < message.InnerTransactions.length; ++j)
object.InnerTransactions[j] = $root.proto.Transaction.toObject(message.InnerTransactions[j], options);
}
return object;

@@ -636,0 +711,0 @@ };

@@ -13,2 +13,3 @@ /// <reference types="node" />

serializeTransaction(transaction: Transaction): Buffer;
private convertToProtoMessage;
/**

@@ -18,3 +19,5 @@ * Custom serialization, compatible with mx-chain-go.

private serializeTransactionValue;
private isGuardedTransaction;
private isWithGuardian;
deserializeTransaction(_buffer: Buffer): Transaction;
}

62

out/proto/serializer.js

@@ -42,30 +42,42 @@ "use strict";

const proto = require("./compiled").proto;
const receiverPubkey = new address_1.Address(transaction.getReceiver().bech32()).pubkey();
const senderPubkey = new address_1.Address(transaction.getSender().bech32()).pubkey();
const protoTransaction = this.convertToProtoMessage(transaction);
const encoded = proto.Transaction.encode(protoTransaction).finish();
const buffer = Buffer.from(encoded);
return buffer;
}
convertToProtoMessage(transaction) {
const proto = require("./compiled").proto;
const receiverPubkey = new address_1.Address(transaction.receiver).getPublicKey();
const senderPubkey = new address_1.Address(transaction.sender).getPublicKey();
let protoTransaction = new proto.Transaction({
// mx-chain-go's serializer handles nonce == 0 differently, thus we treat 0 as "undefined".
Nonce: transaction.getNonce().valueOf() ? transaction.getNonce().valueOf() : undefined,
Value: this.serializeTransactionValue(transaction.getValue()),
Nonce: Number(transaction.nonce) ? Number(transaction.nonce) : undefined,
Value: this.serializeTransactionValue(transaction.value),
RcvAddr: receiverPubkey,
RcvUserName: transaction.getReceiverUsername() ? Buffer.from(transaction.getReceiverUsername()).toString("base64") : undefined,
RcvUserName: transaction.receiverUsername
? Buffer.from(transaction.receiverUsername).toString("base64")
: undefined,
SndAddr: senderPubkey,
SndUserName: transaction.getSenderUsername() ? Buffer.from(transaction.getSenderUsername()).toString("base64") : undefined,
GasPrice: transaction.getGasPrice().valueOf(),
GasLimit: transaction.getGasLimit().valueOf(),
Data: transaction.getData().length() == 0 ? null : transaction.getData().valueOf(),
ChainID: Buffer.from(transaction.getChainID().valueOf()),
Version: transaction.getVersion().valueOf(),
Signature: transaction.getSignature()
SndUserName: transaction.senderUsername
? Buffer.from(transaction.senderUsername).toString("base64")
: undefined,
GasPrice: Number(transaction.gasPrice),
GasLimit: Number(transaction.gasLimit),
Data: transaction.data.length == 0 ? null : transaction.data,
ChainID: Buffer.from(transaction.chainID),
Version: transaction.version,
Signature: transaction.signature,
});
if (transaction.getOptions().valueOf() !== constants_1.TRANSACTION_OPTIONS_DEFAULT) {
protoTransaction.Options = transaction.getOptions().valueOf();
if (transaction.options !== constants_1.TRANSACTION_OPTIONS_DEFAULT) {
protoTransaction.Options = transaction.options;
}
if (transaction.isGuardedTransaction()) {
const guardianAddress = transaction.getGuardian();
protoTransaction.GuardianAddr = new address_1.Address(guardianAddress.bech32()).pubkey();
protoTransaction.GuardianSignature = transaction.getGuardianSignature();
if (this.isGuardedTransaction(transaction)) {
protoTransaction.GuardianAddr = new address_1.Address(transaction.guardian).getPublicKey();
protoTransaction.GuardianSignature = transaction.guardianSignature;
}
const encoded = proto.Transaction.encode(protoTransaction).finish();
const buffer = Buffer.from(encoded);
return buffer;
if (transaction.relayer) {
protoTransaction.Relayer = new address_1.Address(transaction.relayer).getPublicKey();
}
protoTransaction.InnerTransactions = transaction.innerTransactions.map((tx) => this.convertToProtoMessage(tx));
return protoTransaction;
}

@@ -86,2 +98,10 @@ /**

}
isGuardedTransaction(transaction) {
const hasGuardian = transaction.guardian.length > 0;
const hasGuardianSignature = transaction.guardianSignature.length > 0;
return this.isWithGuardian(transaction) && hasGuardian && hasGuardianSignature;
}
isWithGuardian(transaction) {
return (transaction.options & constants_1.TRANSACTION_OPTIONS_TX_GUARDED) == constants_1.TRANSACTION_OPTIONS_TX_GUARDED;
}
deserializeTransaction(_buffer) {

@@ -88,0 +108,0 @@ // Not needed (yet).

@@ -17,2 +17,10 @@ import { SmartContractQuery, SmartContractQueryResponse } from "./smartContractQuery";

});
query(options: {
contract: string;
caller?: string;
value?: bigint;
function: string;
arguments: any[];
}): Promise<any[]>;
private raiseForStatus;
createQuery(options: {

@@ -19,0 +27,0 @@ contract: string;

@@ -14,2 +14,14 @@ "use strict";

}
async query(options) {
const query = this.createQuery(options);
const queryResponse = await this.runQuery(query);
this.raiseForStatus(queryResponse);
return this.parseQueryResponse(queryResponse);
}
raiseForStatus(queryResponse) {
const isOk = queryResponse.returnCode === "ok";
if (!isOk) {
throw new errors_1.ErrSmartContractQuery(queryResponse.returnCode, queryResponse.returnMessage);
}
}
createQuery(options) {

@@ -16,0 +28,0 @@ const preparedArguments = this.encodeArguments(options.function, options.arguments);

/// <reference types="node" />
import BigNumber from "bignumber.js";
import { IAddress } from "../interface";

@@ -13,2 +14,3 @@ import { ArgumentErrorContext } from "./argumentErrorContext";

};
type NativeBigNumber = BigNumber.Value | bigint;
}

@@ -15,0 +17,0 @@ export declare namespace NativeSerializer {

@@ -130,3 +130,3 @@ "use strict";

function toOptionValue(native, type, errorContext) {
if (native == null || native === undefined) {
if (native == null) {
return typesystem_1.OptionValue.newMissing();

@@ -138,3 +138,3 @@ }

function toOptionalValue(native, type, errorContext) {
if (native == null || native === undefined) {
if (native == null) {
return new typesystem_1.OptionalValue(type);

@@ -201,3 +201,3 @@ }

if (type instanceof typesystem_1.NumericalType) {
let number = new bignumber_js_1.default(native);
const number = new bignumber_js_1.default(native);
return convertNumericalType(number, type, errorContext);

@@ -204,0 +204,0 @@ }

@@ -63,3 +63,3 @@ "use strict";

valueOf() {
return this.items.map(item => item.valueOf());
return this.items.map((item) => item.valueOf());
}

@@ -66,0 +66,0 @@ equals(other) {

/// <reference types="node" />
import { BigNumber } from "bignumber.js";
import { Hash } from "./hash";
import { IAddress, IChainID, IGasLimit, IGasPrice, INonce, IPlainTransactionObject, ISignature, ITransactionOptions, ITransactionPayload, ITransactionValue, ITransactionVersion } from "./interface";
import { IAddress, IChainID, IGasLimit, IGasPrice, INonce, IPlainTransactionObject, ISignature, ITransaction, ITransactionOptions, ITransactionPayload, ITransactionValue, ITransactionVersion } from "./interface";
import { INetworkConfig } from "./interfaceOfNetwork";

@@ -72,2 +72,10 @@ import { TransactionOptions, TransactionVersion } from "./networkParams";

/**
* The relayer in case it is a relayedV3 Transaction.
*/
relayer: string;
/**
* The inner transactions in case it is a relayedV3 Transaction.
*/
innerTransactions: ITransaction[];
/**
* Creates a new Transaction object.

@@ -91,2 +99,4 @@ */

guardianSignature?: Uint8Array;
relayer?: string;
innerTransactions?: ITransaction[];
});

@@ -93,0 +103,0 @@ private addressAsBech32;

@@ -38,2 +38,4 @@ "use strict";

this.guardianSignature = options.guardianSignature || Buffer.from([]);
this.relayer = options.relayer || "";
this.innerTransactions = options.innerTransactions || [];
}

@@ -40,0 +42,0 @@ addressAsBech32(address) {

@@ -21,5 +21,6 @@ import { ITransaction } from "./interface";

applyOptionsForHashSigning(transaction: ITransaction): void;
private toPlainObjectForSigning;
private toPlainObject;
private toHexOrUndefined;
private toBase64OrUndefined;
private ensureValidTransactionFields;
}

@@ -56,3 +56,3 @@ "use strict";

this.ensureValidTransactionFields(transaction);
const plainTransaction = this.toPlainObjectForSigning(transaction);
const plainTransaction = this.toPlainObject(transaction);
const serialized = JSON.stringify(plainTransaction);

@@ -69,3 +69,3 @@ return new Uint8Array(Buffer.from(serialized));

computeHashForSigning(transaction) {
const plainTransaction = this.toPlainObjectForSigning(transaction);
const plainTransaction = this.toPlainObject(transaction);
const signable = Buffer.from(JSON.stringify(plainTransaction));

@@ -99,4 +99,4 @@ return createKeccakHash("keccak256").update(signable).digest();

}
toPlainObjectForSigning(transaction) {
return {
toPlainObject(transaction, withSignature) {
let obj = {
nonce: Number(transaction.nonce),

@@ -111,8 +111,19 @@ value: transaction.value.toString(),

data: this.toBase64OrUndefined(transaction.data),
chainID: transaction.chainID,
version: transaction.version,
options: transaction.options ? transaction.options : undefined,
guardian: transaction.guardian ? transaction.guardian : undefined,
};
if (withSignature) {
obj.signature = this.toHexOrUndefined(transaction.signature);
}
obj.chainID = transaction.chainID;
obj.version = transaction.version;
obj.options = transaction.options ? transaction.options : undefined;
obj.guardian = transaction.guardian ? transaction.guardian : undefined;
obj.relayer = transaction.relayer ? transaction.relayer : undefined;
obj.innerTransactions = transaction.innerTransactions.length
? transaction.innerTransactions.map((tx) => this.toPlainObject(tx, true))
: undefined;
return obj;
}
toHexOrUndefined(value) {
return value && value.length ? Buffer.from(value).toString("hex") : undefined;
}
toBase64OrUndefined(value) {

@@ -119,0 +130,0 @@ return value && value.length ? Buffer.from(value).toString("base64") : undefined;

@@ -65,2 +65,3 @@ import { IAddress } from "../interface";

publicKeys: IValidatorPublicKey[];
amount: bigint;
}): Transaction;

@@ -67,0 +68,0 @@ createTransactionForChangingServiceFee(options: {

@@ -138,2 +138,3 @@ "use strict";

addDataMovementGas: true,
amount: options.amount,
}).build();

@@ -140,0 +141,0 @@ }

@@ -25,4 +25,8 @@ import { IAddress, ITransaction } from "../interface";

}): Transaction;
createRelayedV3Transaction(options: {
relayerAddress: IAddress;
innerTransactions: ITransaction[];
}): Transaction;
private prepareInnerTransactionForRelayedV1;
}
export {};

@@ -66,7 +66,31 @@ "use strict";

}
createRelayedV3Transaction(options) {
if (!options.innerTransactions.length) {
throw new errors_1.ErrInvalidInnerTransaction("No inner transctions provided");
}
let innerTransactionsGasLimit = 0n;
for (const innerTx of options.innerTransactions) {
if (!innerTx.signature.length) {
throw new errors_1.ErrInvalidInnerTransaction("Inner transaction is not signed");
}
if (innerTx.relayer !== options.relayerAddress.bech32()) {
throw new errors_1.ErrInvalidInnerTransaction("The inner transaction has an incorrect relayer address");
}
innerTransactionsGasLimit += innerTx.gasLimit;
}
const moveBalanceGas = this.config.minGasLimit * BigInt(options.innerTransactions.length);
const gasLimit = moveBalanceGas + innerTransactionsGasLimit;
return new transaction_1.Transaction({
sender: options.relayerAddress.bech32(),
receiver: options.relayerAddress.bech32(),
chainID: this.config.chainID,
gasLimit: gasLimit,
innerTransactions: options.innerTransactions,
});
}
prepareInnerTransactionForRelayedV1(innerTransaction) {
const txObject = {
nonce: innerTransaction.nonce,
sender: address_1.Address.fromBech32(innerTransaction.sender).pubkey().toString("base64"),
receiver: address_1.Address.fromBech32(innerTransaction.receiver).pubkey().toString("base64"),
sender: address_1.Address.newFromBech32(innerTransaction.sender).getPublicKey().toString("base64"),
receiver: address_1.Address.newFromBech32(innerTransaction.receiver).getPublicKey().toString("base64"),
value: innerTransaction.value,

@@ -81,3 +105,3 @@ gasPrice: innerTransaction.gasPrice,

guardian: innerTransaction.guardian
? address_1.Address.fromBech32(innerTransaction.guardian).pubkey().toString("base64")
? address_1.Address.newFromBech32(innerTransaction.guardian).getPublicKey().toString("base64")
: undefined,

@@ -84,0 +108,0 @@ guardianSignature: innerTransaction.guardianSignature.length

{
"name": "@multiversx/sdk-core",
"version": "13.2.1",
"version": "13.3.0-beta.0",
"description": "MultiversX SDK for JavaScript and TypeScript",

@@ -5,0 +5,0 @@ "main": "out/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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