@multiversx/sdk-core
Advanced tools
Comparing version 13.3.0-beta.0 to 13.3.0
@@ -25,6 +25,2 @@ "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, | ||
}; | ||
@@ -56,6 +52,2 @@ return plainObject; | ||
guardianSignature: this.bufferFromHex(object.guardianSignature), | ||
relayer: object.relayer, | ||
innerTransactions: object.innerTransactions | ||
? object.innerTransactions.map((tx) => this.plainObjectToTransaction(tx)) | ||
: undefined, | ||
}); | ||
@@ -62,0 +54,0 @@ return transaction; |
@@ -26,4 +26,2 @@ /// <reference types="node" /> | ||
guardianSignature?: string; | ||
relayer?: string; | ||
innerTransactions?: IPlainTransactionObject[]; | ||
} | ||
@@ -95,4 +93,2 @@ export interface ISignature { | ||
guardianSignature: Uint8Array; | ||
relayer: string; | ||
innerTransactions: ITransaction[]; | ||
} |
@@ -41,4 +41,2 @@ "use strict"; | ||
* @property {Uint8Array|null} [GuardianSignature] Transaction GuardianSignature | ||
* @property {Uint8Array|null} [Relayer] Transaction Relayer | ||
* @property {Array.<proto.ITransaction>|null} [InnerTransactions] Transaction InnerTransactions | ||
*/ | ||
@@ -54,3 +52,2 @@ /** | ||
function Transaction(properties) { | ||
this.InnerTransactions = []; | ||
if (properties) | ||
@@ -167,16 +164,2 @@ 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. | ||
@@ -234,7 +217,2 @@ * @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; | ||
@@ -332,12 +310,2 @@ }; | ||
} | ||
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: | ||
@@ -421,14 +389,2 @@ 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; | ||
@@ -529,17 +485,2 @@ }; | ||
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; | ||
@@ -560,4 +501,2 @@ }; | ||
var object = {}; | ||
if (options.arrays || options.defaults) | ||
object.InnerTransactions = []; | ||
if (options.defaults) { | ||
@@ -654,9 +593,2 @@ if ($util.Long) { | ||
} | ||
if (options.bytes === String) | ||
object.Relayer = ""; | ||
else { | ||
object.Relayer = []; | ||
if (options.bytes !== Array) | ||
object.Relayer = $util.newBuffer(object.Relayer); | ||
} | ||
} | ||
@@ -702,9 +634,2 @@ 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; | ||
@@ -711,0 +636,0 @@ }; |
@@ -13,3 +13,2 @@ /// <reference types="node" /> | ||
serializeTransaction(transaction: Transaction): Buffer; | ||
private convertToProtoMessage; | ||
/** | ||
@@ -19,5 +18,3 @@ * Custom serialization, compatible with mx-chain-go. | ||
private serializeTransactionValue; | ||
private isGuardedTransaction; | ||
private isWithGuardian; | ||
deserializeTransaction(_buffer: Buffer): Transaction; | ||
} |
@@ -42,42 +42,34 @@ "use strict"; | ||
const proto = require("./compiled").proto; | ||
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(); | ||
const receiverPubkey = new address_1.Address(transaction.getReceiver().bech32()).pubkey(); | ||
const senderPubkey = new address_1.Address(transaction.getSender().bech32()).pubkey(); | ||
let protoTransaction = new proto.Transaction({ | ||
// mx-chain-go's serializer handles nonce == 0 differently, thus we treat 0 as "undefined". | ||
Nonce: Number(transaction.nonce) ? Number(transaction.nonce) : undefined, | ||
Value: this.serializeTransactionValue(transaction.value), | ||
Nonce: transaction.getNonce().valueOf() ? transaction.getNonce().valueOf() : undefined, | ||
Value: this.serializeTransactionValue(transaction.getValue()), | ||
RcvAddr: receiverPubkey, | ||
RcvUserName: transaction.receiverUsername | ||
? Buffer.from(transaction.receiverUsername).toString("base64") | ||
RcvUserName: transaction.getReceiverUsername() | ||
? Buffer.from(transaction.getReceiverUsername()).toString("base64") | ||
: undefined, | ||
SndAddr: senderPubkey, | ||
SndUserName: transaction.senderUsername | ||
? Buffer.from(transaction.senderUsername).toString("base64") | ||
SndUserName: transaction.getSenderUsername() | ||
? Buffer.from(transaction.getSenderUsername()).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, | ||
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(), | ||
}); | ||
if (transaction.options !== constants_1.TRANSACTION_OPTIONS_DEFAULT) { | ||
protoTransaction.Options = transaction.options; | ||
if (transaction.getOptions().valueOf() !== constants_1.TRANSACTION_OPTIONS_DEFAULT) { | ||
protoTransaction.Options = transaction.getOptions().valueOf(); | ||
} | ||
if (this.isGuardedTransaction(transaction)) { | ||
protoTransaction.GuardianAddr = new address_1.Address(transaction.guardian).getPublicKey(); | ||
protoTransaction.GuardianSignature = transaction.guardianSignature; | ||
if (transaction.isGuardedTransaction()) { | ||
const guardianAddress = transaction.getGuardian(); | ||
protoTransaction.GuardianAddr = new address_1.Address(guardianAddress.bech32()).pubkey(); | ||
protoTransaction.GuardianSignature = transaction.getGuardianSignature(); | ||
} | ||
if (transaction.relayer) { | ||
protoTransaction.Relayer = new address_1.Address(transaction.relayer).getPublicKey(); | ||
} | ||
protoTransaction.InnerTransactions = transaction.innerTransactions.map((tx) => this.convertToProtoMessage(tx)); | ||
return protoTransaction; | ||
const encoded = proto.Transaction.encode(protoTransaction).finish(); | ||
const buffer = Buffer.from(encoded); | ||
return buffer; | ||
} | ||
@@ -98,10 +90,2 @@ /** | ||
} | ||
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) { | ||
@@ -108,0 +92,0 @@ // Not needed (yet). |
@@ -209,3 +209,4 @@ "use strict"; | ||
if (type instanceof typesystem_1.BooleanType) { | ||
return new typesystem_1.BooleanValue(native); | ||
const boolValue = native.toString().toLowerCase() === "true" || native.toString() === "1"; | ||
return new typesystem_1.BooleanValue(boolValue); | ||
} | ||
@@ -212,0 +213,0 @@ if (type instanceof typesystem_1.TokenIdentifierType) { |
/// <reference types="node" /> | ||
import { BigNumber } from "bignumber.js"; | ||
import { Hash } from "./hash"; | ||
import { IAddress, IChainID, IGasLimit, IGasPrice, INonce, IPlainTransactionObject, ISignature, ITransaction, ITransactionOptions, ITransactionPayload, ITransactionValue, ITransactionVersion } from "./interface"; | ||
import { IAddress, IChainID, IGasLimit, IGasPrice, INonce, IPlainTransactionObject, ISignature, ITransactionOptions, ITransactionPayload, ITransactionValue, ITransactionVersion } from "./interface"; | ||
import { INetworkConfig } from "./interfaceOfNetwork"; | ||
@@ -72,10 +72,2 @@ 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. | ||
@@ -99,4 +91,2 @@ */ | ||
guardianSignature?: Uint8Array; | ||
relayer?: string; | ||
innerTransactions?: ITransaction[]; | ||
}); | ||
@@ -103,0 +93,0 @@ private addressAsBech32; |
@@ -38,4 +38,2 @@ "use strict"; | ||
this.guardianSignature = options.guardianSignature || Buffer.from([]); | ||
this.relayer = options.relayer || ""; | ||
this.innerTransactions = options.innerTransactions || []; | ||
} | ||
@@ -42,0 +40,0 @@ addressAsBech32(address) { |
@@ -21,6 +21,5 @@ import { ITransaction } from "./interface"; | ||
applyOptionsForHashSigning(transaction: ITransaction): void; | ||
private toPlainObject; | ||
private toHexOrUndefined; | ||
private toPlainObjectForSigning; | ||
private toBase64OrUndefined; | ||
private ensureValidTransactionFields; | ||
} |
@@ -56,3 +56,3 @@ "use strict"; | ||
this.ensureValidTransactionFields(transaction); | ||
const plainTransaction = this.toPlainObject(transaction); | ||
const plainTransaction = this.toPlainObjectForSigning(transaction); | ||
const serialized = JSON.stringify(plainTransaction); | ||
@@ -69,3 +69,3 @@ return new Uint8Array(Buffer.from(serialized)); | ||
computeHashForSigning(transaction) { | ||
const plainTransaction = this.toPlainObject(transaction); | ||
const plainTransaction = this.toPlainObjectForSigning(transaction); | ||
const signable = Buffer.from(JSON.stringify(plainTransaction)); | ||
@@ -99,4 +99,4 @@ return createKeccakHash("keccak256").update(signable).digest(); | ||
} | ||
toPlainObject(transaction, withSignature) { | ||
let obj = { | ||
toPlainObjectForSigning(transaction) { | ||
return { | ||
nonce: Number(transaction.nonce), | ||
@@ -111,19 +111,8 @@ 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) { | ||
@@ -130,0 +119,0 @@ return value && value.length ? Buffer.from(value).toString("base64") : undefined; |
@@ -65,3 +65,2 @@ import { IAddress } from "../interface"; | ||
publicKeys: IValidatorPublicKey[]; | ||
amount: bigint; | ||
}): Transaction; | ||
@@ -68,0 +67,0 @@ createTransactionForChangingServiceFee(options: { |
@@ -138,3 +138,2 @@ "use strict"; | ||
addDataMovementGas: true, | ||
amount: options.amount, | ||
}).build(); | ||
@@ -141,0 +140,0 @@ } |
@@ -25,8 +25,4 @@ import { IAddress, ITransaction } from "../interface"; | ||
}): Transaction; | ||
createRelayedV3Transaction(options: { | ||
relayerAddress: IAddress; | ||
innerTransactions: ITransaction[]; | ||
}): Transaction; | ||
private prepareInnerTransactionForRelayedV1; | ||
} | ||
export {}; |
@@ -66,31 +66,7 @@ "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.newFromBech32(innerTransaction.sender).getPublicKey().toString("base64"), | ||
receiver: address_1.Address.newFromBech32(innerTransaction.receiver).getPublicKey().toString("base64"), | ||
sender: address_1.Address.fromBech32(innerTransaction.sender).pubkey().toString("base64"), | ||
receiver: address_1.Address.fromBech32(innerTransaction.receiver).pubkey().toString("base64"), | ||
value: innerTransaction.value, | ||
@@ -105,3 +81,3 @@ gasPrice: innerTransaction.gasPrice, | ||
guardian: innerTransaction.guardian | ||
? address_1.Address.newFromBech32(innerTransaction.guardian).getPublicKey().toString("base64") | ||
? address_1.Address.fromBech32(innerTransaction.guardian).pubkey().toString("base64") | ||
: undefined, | ||
@@ -108,0 +84,0 @@ guardianSignature: innerTransaction.guardianSignature.length |
{ | ||
"name": "@multiversx/sdk-core", | ||
"version": "13.3.0-beta.0", | ||
"version": "13.3.0", | ||
"description": "MultiversX SDK for JavaScript and TypeScript", | ||
@@ -47,3 +47,2 @@ "main": "out/index.js", | ||
"chai": "4.2.0", | ||
"esmify": "2.1.1", | ||
"mocha": "9.2.2", | ||
@@ -50,0 +49,0 @@ "protobufjs-cli": "1.1.2", |
@@ -28,6 +28,7 @@ # MultiversX SDK for JavaScript and TypeScript | ||
`browserify` is required to compile the browser-friendly versions of `sdk-core`. It can be installed as follows: | ||
`browserify` and `esmify` are required to compile the browser-friendly versions of `sdk-core`. They can be installed as follows: | ||
``` | ||
npm install --global browserify | ||
npm install esmify | ||
``` | ||
@@ -34,0 +35,0 @@ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19
1
69
995251
16568