From cfa0d5c3d8da5f1e1f5b014ce1f279a9cd35a9d1 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 11 Dec 2024 22:43:18 +0200 Subject: [PATCH 1/6] Add relayer support --- src/converters/transactionsConverter.ts | 5 + src/converters/transactionsConverters.spec.ts | 6 +- src/interface.ts | 5 + src/proto/compiled.js | 683 ++++++++++++------ src/proto/serializer.ts | 5 + src/proto/transaction.proto | 2 + src/transaction.spec.ts | 42 +- src/transaction.ts | 17 +- src/transactionComputer.ts | 13 + 9 files changed, 543 insertions(+), 235 deletions(-) diff --git a/src/converters/transactionsConverter.ts b/src/converters/transactionsConverter.ts index 966ec86e4..d97c2be05 100644 --- a/src/converters/transactionsConverter.ts +++ b/src/converters/transactionsConverter.ts @@ -1,3 +1,4 @@ +import { Address } from "../address"; import { IPlainTransactionObject, ITransaction } from "../interface"; import { IContractResultItem, ITransactionEvent, ITransactionOnNetwork } from "../interfaceOfNetwork"; import { ResultsParser } from "../smartcontracts"; @@ -25,9 +26,11 @@ export class TransactionsConverter { chainID: transaction.chainID.valueOf(), version: transaction.version, options: transaction.options == 0 ? undefined : transaction.options, + relayer: !transaction.relayer || transaction.relayer.isEmpty() ? undefined : transaction.relayer.toBech32(), guardian: transaction.guardian ? transaction.guardian : undefined, signature: this.toHexOrUndefined(transaction.signature), guardianSignature: this.toHexOrUndefined(transaction.guardianSignature), + relayerSignature: this.toHexOrUndefined(transaction.relayerSignature), }; return plainObject; @@ -46,6 +49,7 @@ export class TransactionsConverter { nonce: BigInt(object.nonce), value: BigInt(object.value || ""), receiver: object.receiver, + relayer: object.relayer ? Address.newFromBech32(object.relayer) : Address.empty(), receiverUsername: this.bufferFromBase64(object.receiverUsername).toString(), sender: object.sender, senderUsername: this.bufferFromBase64(object.senderUsername).toString(), @@ -58,6 +62,7 @@ export class TransactionsConverter { options: Number(object.options), signature: this.bufferFromHex(object.signature), guardianSignature: this.bufferFromHex(object.guardianSignature), + relayerSignature: this.bufferFromHex(object.relayerSignature), }); return transaction; diff --git a/src/converters/transactionsConverters.spec.ts b/src/converters/transactionsConverters.spec.ts index e491ab57a..ed143f248 100644 --- a/src/converters/transactionsConverters.spec.ts +++ b/src/converters/transactionsConverters.spec.ts @@ -1,3 +1,5 @@ +import { assert } from "chai"; +import { Address } from "../address"; import { ContractResultItem, ContractResults, @@ -7,8 +9,6 @@ import { TransactionLogsOnNetwork, TransactionOnNetwork, } from "../networkProviders"; -import { assert } from "chai"; -import { Address } from "../address"; import { Transaction } from "../transaction"; import { SmartContractCallOutcome, @@ -58,7 +58,9 @@ describe("test transactions converter", async () => { options: undefined, guardian: undefined, signature: undefined, + relayer: undefined, guardianSignature: undefined, + relayerSignature: undefined, }); }); diff --git a/src/interface.ts b/src/interface.ts index 97c86a54f..dc7d3f234 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -1,4 +1,5 @@ import BigNumber from "bignumber.js"; +import { Address } from "./address"; import { ITransactionOnNetwork } from "./interfaceOfNetwork"; export interface ITransactionFetcher { @@ -16,6 +17,7 @@ export interface IPlainTransactionObject { receiverUsername?: string; senderUsername?: string; guardian?: string; + relayer?: string; gasPrice: number; gasLimit: number; data?: string; @@ -24,6 +26,7 @@ export interface IPlainTransactionObject { options?: number; signature?: string; guardianSignature?: string; + relayerSignature?: string; } export interface ISignature { @@ -102,6 +105,8 @@ export interface ITransaction { version: number; options: number; guardian: string; + relayer?: Address; signature: Uint8Array; guardianSignature: Uint8Array; + relayerSignature?: Uint8Array; } diff --git a/src/proto/compiled.js b/src/proto/compiled.js index feed796f9..c0424d789 100644 --- a/src/proto/compiled.js +++ b/src/proto/compiled.js @@ -1,32 +1,30 @@ /*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ -(function(global, factory) { /* global define, require, module */ +(function (global, factory) { + /* global define, require, module */ - /* AMD */ if (typeof define === 'function' && define.amd) - define(["protobufjs/minimal"], factory); - - /* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports) + /* AMD */ if (typeof define === "function" && define.amd) define(["protobufjs/minimal"], factory); + /* CommonJS */ else if (typeof require === "function" && typeof module === "object" && module && module.exports) module.exports = factory(require("protobufjs/minimal")); - -})(this, function($protobuf) { +})(this, function ($protobuf) { "use strict"; // Common aliases - var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; - + var $Reader = $protobuf.Reader, + $Writer = $protobuf.Writer, + $util = $protobuf.util; + // Exported root namespace var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); - - $root.proto = (function() { - + + $root.proto = (function () { /** * Namespace proto. * @exports proto * @namespace */ var proto = {}; - - proto.Transaction = (function() { - + + proto.Transaction = (function () { /** * Properties of a Transaction. * @memberof proto @@ -46,8 +44,10 @@ * @property {number|null} [Options] Transaction Options * @property {Uint8Array|null} [GuardianAddr] Transaction GuardianAddr * @property {Uint8Array|null} [GuardianSignature] Transaction GuardianSignature + * @property {Uint8Array|null} [Relayer] Transaction RelayerAddr + * @property {Uint8Array|null} [RelayerSignature] Transaction RelayerSignature */ - + /** * Constructs a new Transaction. * @memberof proto @@ -59,18 +59,17 @@ function Transaction(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) - if (properties[keys[i]] != null) - this[keys[i]] = properties[keys[i]]; + if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } - + /** * Transaction Nonce. * @member {number|Long} Nonce * @memberof proto.Transaction * @instance */ - Transaction.prototype.Nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; - + Transaction.prototype.Nonce = $util.Long ? $util.Long.fromBits(0, 0, true) : 0; + /** * Transaction Value. * @member {Uint8Array} Value @@ -78,7 +77,7 @@ * @instance */ Transaction.prototype.Value = $util.newBuffer([]); - + /** * Transaction RcvAddr. * @member {Uint8Array} RcvAddr @@ -86,7 +85,7 @@ * @instance */ Transaction.prototype.RcvAddr = $util.newBuffer([]); - + /** * Transaction RcvUserName. * @member {Uint8Array} RcvUserName @@ -94,7 +93,7 @@ * @instance */ Transaction.prototype.RcvUserName = $util.newBuffer([]); - + /** * Transaction SndAddr. * @member {Uint8Array} SndAddr @@ -102,7 +101,7 @@ * @instance */ Transaction.prototype.SndAddr = $util.newBuffer([]); - + /** * Transaction SndUserName. * @member {Uint8Array} SndUserName @@ -110,23 +109,23 @@ * @instance */ Transaction.prototype.SndUserName = $util.newBuffer([]); - + /** * Transaction GasPrice. * @member {number|Long} GasPrice * @memberof proto.Transaction * @instance */ - Transaction.prototype.GasPrice = $util.Long ? $util.Long.fromBits(0,0,true) : 0; - + Transaction.prototype.GasPrice = $util.Long ? $util.Long.fromBits(0, 0, true) : 0; + /** * Transaction GasLimit. * @member {number|Long} GasLimit * @memberof proto.Transaction * @instance */ - Transaction.prototype.GasLimit = $util.Long ? $util.Long.fromBits(0,0,true) : 0; - + Transaction.prototype.GasLimit = $util.Long ? $util.Long.fromBits(0, 0, true) : 0; + /** * Transaction Data. * @member {Uint8Array} Data @@ -134,7 +133,7 @@ * @instance */ Transaction.prototype.Data = $util.newBuffer([]); - + /** * Transaction ChainID. * @member {Uint8Array} ChainID @@ -142,7 +141,7 @@ * @instance */ Transaction.prototype.ChainID = $util.newBuffer([]); - + /** * Transaction Version. * @member {number} Version @@ -150,7 +149,7 @@ * @instance */ Transaction.prototype.Version = 0; - + /** * Transaction Signature. * @member {Uint8Array} Signature @@ -158,7 +157,7 @@ * @instance */ Transaction.prototype.Signature = $util.newBuffer([]); - + /** * Transaction Options. * @member {number} Options @@ -166,7 +165,7 @@ * @instance */ Transaction.prototype.Options = 0; - + /** * Transaction GuardianAddr. * @member {Uint8Array} GuardianAddr @@ -174,7 +173,7 @@ * @instance */ Transaction.prototype.GuardianAddr = $util.newBuffer([]); - + /** * Transaction GuardianSignature. * @member {Uint8Array} GuardianSignature @@ -182,7 +181,22 @@ * @instance */ Transaction.prototype.GuardianSignature = $util.newBuffer([]); - + + /** + * Transaction Relayer. + * @member {Uint8Array} Relayer + * @instance + */ + Transaction.prototype.Relayer = $util.newBuffer([]); + + /** + * Transaction RelayerSignature. + * @member {Uint8Array} RelayerSignature + * @memberof proto.Transaction + * @instance + */ + Transaction.prototype.RelayerSignature = $util.newBuffer([]); + /** * Creates a new Transaction instance using the specified properties. * @function create @@ -194,7 +208,7 @@ Transaction.create = function create(properties) { return new Transaction(properties); }; - + /** * Encodes the specified Transaction message. Does not implicitly {@link proto.Transaction.verify|verify} messages. * @function encode @@ -205,41 +219,44 @@ * @returns {$protobuf.Writer} Writer */ Transaction.encode = function encode(message, writer) { - if (!writer) - writer = $Writer.create(); + if (!writer) writer = $Writer.create(); if (message.Nonce != null && Object.hasOwnProperty.call(message, "Nonce")) - writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.Nonce); + writer.uint32(/* id 1, wireType 0 =*/ 8).uint64(message.Nonce); if (message.Value != null && Object.hasOwnProperty.call(message, "Value")) - writer.uint32(/* id 2, wireType 2 =*/18).bytes(message.Value); + writer.uint32(/* id 2, wireType 2 =*/ 18).bytes(message.Value); if (message.RcvAddr != null && Object.hasOwnProperty.call(message, "RcvAddr")) - writer.uint32(/* id 3, wireType 2 =*/26).bytes(message.RcvAddr); + writer.uint32(/* id 3, wireType 2 =*/ 26).bytes(message.RcvAddr); if (message.RcvUserName != null && Object.hasOwnProperty.call(message, "RcvUserName")) - writer.uint32(/* id 4, wireType 2 =*/34).bytes(message.RcvUserName); + writer.uint32(/* id 4, wireType 2 =*/ 34).bytes(message.RcvUserName); if (message.SndAddr != null && Object.hasOwnProperty.call(message, "SndAddr")) - writer.uint32(/* id 5, wireType 2 =*/42).bytes(message.SndAddr); + writer.uint32(/* id 5, wireType 2 =*/ 42).bytes(message.SndAddr); if (message.SndUserName != null && Object.hasOwnProperty.call(message, "SndUserName")) - writer.uint32(/* id 6, wireType 2 =*/50).bytes(message.SndUserName); + writer.uint32(/* id 6, wireType 2 =*/ 50).bytes(message.SndUserName); if (message.GasPrice != null && Object.hasOwnProperty.call(message, "GasPrice")) - writer.uint32(/* id 7, wireType 0 =*/56).uint64(message.GasPrice); + writer.uint32(/* id 7, wireType 0 =*/ 56).uint64(message.GasPrice); if (message.GasLimit != null && Object.hasOwnProperty.call(message, "GasLimit")) - writer.uint32(/* id 8, wireType 0 =*/64).uint64(message.GasLimit); + writer.uint32(/* id 8, wireType 0 =*/ 64).uint64(message.GasLimit); if (message.Data != null && Object.hasOwnProperty.call(message, "Data")) - writer.uint32(/* id 9, wireType 2 =*/74).bytes(message.Data); + writer.uint32(/* id 9, wireType 2 =*/ 74).bytes(message.Data); if (message.ChainID != null && Object.hasOwnProperty.call(message, "ChainID")) - writer.uint32(/* id 10, wireType 2 =*/82).bytes(message.ChainID); + writer.uint32(/* id 10, wireType 2 =*/ 82).bytes(message.ChainID); if (message.Version != null && Object.hasOwnProperty.call(message, "Version")) - writer.uint32(/* id 11, wireType 0 =*/88).uint32(message.Version); + writer.uint32(/* id 11, wireType 0 =*/ 88).uint32(message.Version); if (message.Signature != null && Object.hasOwnProperty.call(message, "Signature")) - writer.uint32(/* id 12, wireType 2 =*/98).bytes(message.Signature); + writer.uint32(/* id 12, wireType 2 =*/ 98).bytes(message.Signature); if (message.Options != null && Object.hasOwnProperty.call(message, "Options")) - writer.uint32(/* id 13, wireType 0 =*/104).uint32(message.Options); + writer.uint32(/* id 13, wireType 0 =*/ 104).uint32(message.Options); if (message.GuardianAddr != null && Object.hasOwnProperty.call(message, "GuardianAddr")) - writer.uint32(/* id 14, wireType 2 =*/114).bytes(message.GuardianAddr); + writer.uint32(/* id 14, wireType 2 =*/ 114).bytes(message.GuardianAddr); if (message.GuardianSignature != null && Object.hasOwnProperty.call(message, "GuardianSignature")) - writer.uint32(/* id 15, wireType 2 =*/122).bytes(message.GuardianSignature); + writer.uint32(/* id 15, wireType 2 =*/ 122).bytes(message.GuardianSignature); + if (message.Relayer != null && Object.hasOwnProperty.call(message, "Relayer")) + writer.uint32(/* id 14, wireType 2 =*/ 114).bytes(message.Relayer); + if (message.RelayerSignature != null && Object.hasOwnProperty.call(message, "RelayerSignature")) + writer.uint32(/* id 15, wireType 2 =*/ 122).bytes(message.RelayerSignature); return writer; }; - + /** * Encodes the specified Transaction message, length delimited. Does not implicitly {@link proto.Transaction.verify|verify} messages. * @function encodeDelimited @@ -252,7 +269,7 @@ Transaction.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; - + /** * Decodes a Transaction message from the specified reader or buffer. * @function decode @@ -265,80 +282,88 @@ * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Transaction.decode = function decode(reader, length) { - if (!(reader instanceof $Reader)) - reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.proto.Transaction(); + if (!(reader instanceof $Reader)) reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, + message = new $root.proto.Transaction(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { - case 1: { + case 1: { message.Nonce = reader.uint64(); break; } - case 2: { + case 2: { message.Value = reader.bytes(); break; } - case 3: { + case 3: { message.RcvAddr = reader.bytes(); break; } - case 4: { + case 4: { message.RcvUserName = reader.bytes(); break; } - case 5: { + case 5: { message.SndAddr = reader.bytes(); break; } - case 6: { + case 6: { message.SndUserName = reader.bytes(); break; } - case 7: { + case 7: { message.GasPrice = reader.uint64(); break; } - case 8: { + case 8: { message.GasLimit = reader.uint64(); break; } - case 9: { + case 9: { message.Data = reader.bytes(); break; } - case 10: { + case 10: { message.ChainID = reader.bytes(); break; } - case 11: { + case 11: { message.Version = reader.uint32(); break; } - case 12: { + case 12: { message.Signature = reader.bytes(); break; } - case 13: { + case 13: { message.Options = reader.uint32(); break; } - case 14: { + case 14: { message.GuardianAddr = reader.bytes(); break; } - case 15: { + case 15: { message.GuardianSignature = reader.bytes(); break; } - default: - reader.skipType(tag & 7); - break; + case 16: { + message.Relayer = reader.bytes(); + break; + } + case 17: { + message.RelayerSignature = reader.bytes(); + break; + } + default: + reader.skipType(tag & 7); + break; } } return message; }; - + /** * Decodes a Transaction message from the specified reader or buffer, length delimited. * @function decodeDelimited @@ -350,11 +375,10 @@ * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Transaction.decodeDelimited = function decodeDelimited(reader) { - if (!(reader instanceof $Reader)) - reader = new $Reader(reader); + if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; - + /** * Verifies a Transaction message. * @function verify @@ -364,56 +388,126 @@ * @returns {string|null} `null` if valid, otherwise the reason why it is not */ Transaction.verify = function verify(message) { - if (typeof message !== "object" || message === null) - return "object expected"; + if (typeof message !== "object" || message === null) return "object expected"; if (message.Nonce != null && message.hasOwnProperty("Nonce")) - if (!$util.isInteger(message.Nonce) && !(message.Nonce && $util.isInteger(message.Nonce.low) && $util.isInteger(message.Nonce.high))) + if ( + !$util.isInteger(message.Nonce) && + !(message.Nonce && $util.isInteger(message.Nonce.low) && $util.isInteger(message.Nonce.high)) + ) return "Nonce: integer|Long expected"; if (message.Value != null && message.hasOwnProperty("Value")) - if (!(message.Value && typeof message.Value.length === "number" || $util.isString(message.Value))) + if (!((message.Value && typeof message.Value.length === "number") || $util.isString(message.Value))) return "Value: buffer expected"; if (message.RcvAddr != null && message.hasOwnProperty("RcvAddr")) - if (!(message.RcvAddr && typeof message.RcvAddr.length === "number" || $util.isString(message.RcvAddr))) + if ( + !( + (message.RcvAddr && typeof message.RcvAddr.length === "number") || + $util.isString(message.RcvAddr) + ) + ) return "RcvAddr: buffer expected"; if (message.RcvUserName != null && message.hasOwnProperty("RcvUserName")) - if (!(message.RcvUserName && typeof message.RcvUserName.length === "number" || $util.isString(message.RcvUserName))) + if ( + !( + (message.RcvUserName && typeof message.RcvUserName.length === "number") || + $util.isString(message.RcvUserName) + ) + ) return "RcvUserName: buffer expected"; if (message.SndAddr != null && message.hasOwnProperty("SndAddr")) - if (!(message.SndAddr && typeof message.SndAddr.length === "number" || $util.isString(message.SndAddr))) + if ( + !( + (message.SndAddr && typeof message.SndAddr.length === "number") || + $util.isString(message.SndAddr) + ) + ) return "SndAddr: buffer expected"; if (message.SndUserName != null && message.hasOwnProperty("SndUserName")) - if (!(message.SndUserName && typeof message.SndUserName.length === "number" || $util.isString(message.SndUserName))) + if ( + !( + (message.SndUserName && typeof message.SndUserName.length === "number") || + $util.isString(message.SndUserName) + ) + ) return "SndUserName: buffer expected"; if (message.GasPrice != null && message.hasOwnProperty("GasPrice")) - if (!$util.isInteger(message.GasPrice) && !(message.GasPrice && $util.isInteger(message.GasPrice.low) && $util.isInteger(message.GasPrice.high))) + if ( + !$util.isInteger(message.GasPrice) && + !( + message.GasPrice && + $util.isInteger(message.GasPrice.low) && + $util.isInteger(message.GasPrice.high) + ) + ) return "GasPrice: integer|Long expected"; if (message.GasLimit != null && message.hasOwnProperty("GasLimit")) - if (!$util.isInteger(message.GasLimit) && !(message.GasLimit && $util.isInteger(message.GasLimit.low) && $util.isInteger(message.GasLimit.high))) + if ( + !$util.isInteger(message.GasLimit) && + !( + message.GasLimit && + $util.isInteger(message.GasLimit.low) && + $util.isInteger(message.GasLimit.high) + ) + ) return "GasLimit: integer|Long expected"; if (message.Data != null && message.hasOwnProperty("Data")) - if (!(message.Data && typeof message.Data.length === "number" || $util.isString(message.Data))) + if (!((message.Data && typeof message.Data.length === "number") || $util.isString(message.Data))) return "Data: buffer expected"; if (message.ChainID != null && message.hasOwnProperty("ChainID")) - if (!(message.ChainID && typeof message.ChainID.length === "number" || $util.isString(message.ChainID))) + if ( + !( + (message.ChainID && typeof message.ChainID.length === "number") || + $util.isString(message.ChainID) + ) + ) return "ChainID: buffer expected"; if (message.Version != null && message.hasOwnProperty("Version")) - if (!$util.isInteger(message.Version)) - return "Version: integer expected"; + if (!$util.isInteger(message.Version)) return "Version: integer expected"; if (message.Signature != null && message.hasOwnProperty("Signature")) - if (!(message.Signature && typeof message.Signature.length === "number" || $util.isString(message.Signature))) + if ( + !( + (message.Signature && typeof message.Signature.length === "number") || + $util.isString(message.Signature) + ) + ) return "Signature: buffer expected"; if (message.Options != null && message.hasOwnProperty("Options")) - if (!$util.isInteger(message.Options)) - return "Options: integer expected"; + if (!$util.isInteger(message.Options)) return "Options: integer expected"; if (message.GuardianAddr != null && message.hasOwnProperty("GuardianAddr")) - if (!(message.GuardianAddr && typeof message.GuardianAddr.length === "number" || $util.isString(message.GuardianAddr))) + if ( + !( + (message.GuardianAddr && typeof message.GuardianAddr.length === "number") || + $util.isString(message.GuardianAddr) + ) + ) return "GuardianAddr: buffer expected"; if (message.GuardianSignature != null && message.hasOwnProperty("GuardianSignature")) - if (!(message.GuardianSignature && typeof message.GuardianSignature.length === "number" || $util.isString(message.GuardianSignature))) + if ( + !( + (message.GuardianSignature && typeof message.GuardianSignature.length === "number") || + $util.isString(message.GuardianSignature) + ) + ) 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.RelayerSignature != null && message.hasOwnProperty("RelayerSignature")) + if ( + !( + (message.RelayerSignature && typeof message.RelayerSignature.length === "number") || + $util.isString(message.RelayerSignature) + ) + ) + return "RelayerSignature: buffer expected"; return null; }; - + /** * Creates a Transaction message from a plain object. Also converts values to their respective internal types. * @function fromObject @@ -423,93 +517,137 @@ * @returns {proto.Transaction} Transaction */ Transaction.fromObject = function fromObject(object) { - if (object instanceof $root.proto.Transaction) - return object; + if (object instanceof $root.proto.Transaction) return object; var message = new $root.proto.Transaction(); if (object.Nonce != null) - if ($util.Long) - (message.Nonce = $util.Long.fromValue(object.Nonce)).unsigned = true; - else if (typeof object.Nonce === "string") - message.Nonce = parseInt(object.Nonce, 10); - else if (typeof object.Nonce === "number") - message.Nonce = object.Nonce; + if ($util.Long) (message.Nonce = $util.Long.fromValue(object.Nonce)).unsigned = true; + else if (typeof object.Nonce === "string") message.Nonce = parseInt(object.Nonce, 10); + else if (typeof object.Nonce === "number") message.Nonce = object.Nonce; else if (typeof object.Nonce === "object") - message.Nonce = new $util.LongBits(object.Nonce.low >>> 0, object.Nonce.high >>> 0).toNumber(true); + message.Nonce = new $util.LongBits(object.Nonce.low >>> 0, object.Nonce.high >>> 0).toNumber( + true, + ); if (object.Value != null) if (typeof object.Value === "string") - $util.base64.decode(object.Value, message.Value = $util.newBuffer($util.base64.length(object.Value)), 0); - else if (object.Value.length >= 0) - message.Value = object.Value; + $util.base64.decode( + object.Value, + (message.Value = $util.newBuffer($util.base64.length(object.Value))), + 0, + ); + else if (object.Value.length >= 0) message.Value = object.Value; if (object.RcvAddr != null) if (typeof object.RcvAddr === "string") - $util.base64.decode(object.RcvAddr, message.RcvAddr = $util.newBuffer($util.base64.length(object.RcvAddr)), 0); - else if (object.RcvAddr.length >= 0) - message.RcvAddr = object.RcvAddr; + $util.base64.decode( + object.RcvAddr, + (message.RcvAddr = $util.newBuffer($util.base64.length(object.RcvAddr))), + 0, + ); + else if (object.RcvAddr.length >= 0) message.RcvAddr = object.RcvAddr; if (object.RcvUserName != null) if (typeof object.RcvUserName === "string") - $util.base64.decode(object.RcvUserName, message.RcvUserName = $util.newBuffer($util.base64.length(object.RcvUserName)), 0); - else if (object.RcvUserName.length >= 0) - message.RcvUserName = object.RcvUserName; + $util.base64.decode( + object.RcvUserName, + (message.RcvUserName = $util.newBuffer($util.base64.length(object.RcvUserName))), + 0, + ); + else if (object.RcvUserName.length >= 0) message.RcvUserName = object.RcvUserName; if (object.SndAddr != null) if (typeof object.SndAddr === "string") - $util.base64.decode(object.SndAddr, message.SndAddr = $util.newBuffer($util.base64.length(object.SndAddr)), 0); - else if (object.SndAddr.length >= 0) - message.SndAddr = object.SndAddr; + $util.base64.decode( + object.SndAddr, + (message.SndAddr = $util.newBuffer($util.base64.length(object.SndAddr))), + 0, + ); + else if (object.SndAddr.length >= 0) message.SndAddr = object.SndAddr; if (object.SndUserName != null) if (typeof object.SndUserName === "string") - $util.base64.decode(object.SndUserName, message.SndUserName = $util.newBuffer($util.base64.length(object.SndUserName)), 0); - else if (object.SndUserName.length >= 0) - message.SndUserName = object.SndUserName; + $util.base64.decode( + object.SndUserName, + (message.SndUserName = $util.newBuffer($util.base64.length(object.SndUserName))), + 0, + ); + else if (object.SndUserName.length >= 0) message.SndUserName = object.SndUserName; if (object.GasPrice != null) - if ($util.Long) - (message.GasPrice = $util.Long.fromValue(object.GasPrice)).unsigned = true; - else if (typeof object.GasPrice === "string") - message.GasPrice = parseInt(object.GasPrice, 10); - else if (typeof object.GasPrice === "number") - message.GasPrice = object.GasPrice; + if ($util.Long) (message.GasPrice = $util.Long.fromValue(object.GasPrice)).unsigned = true; + else if (typeof object.GasPrice === "string") message.GasPrice = parseInt(object.GasPrice, 10); + else if (typeof object.GasPrice === "number") message.GasPrice = object.GasPrice; else if (typeof object.GasPrice === "object") - message.GasPrice = new $util.LongBits(object.GasPrice.low >>> 0, object.GasPrice.high >>> 0).toNumber(true); + message.GasPrice = new $util.LongBits( + object.GasPrice.low >>> 0, + object.GasPrice.high >>> 0, + ).toNumber(true); if (object.GasLimit != null) - if ($util.Long) - (message.GasLimit = $util.Long.fromValue(object.GasLimit)).unsigned = true; - else if (typeof object.GasLimit === "string") - message.GasLimit = parseInt(object.GasLimit, 10); - else if (typeof object.GasLimit === "number") - message.GasLimit = object.GasLimit; + if ($util.Long) (message.GasLimit = $util.Long.fromValue(object.GasLimit)).unsigned = true; + else if (typeof object.GasLimit === "string") message.GasLimit = parseInt(object.GasLimit, 10); + else if (typeof object.GasLimit === "number") message.GasLimit = object.GasLimit; else if (typeof object.GasLimit === "object") - message.GasLimit = new $util.LongBits(object.GasLimit.low >>> 0, object.GasLimit.high >>> 0).toNumber(true); + message.GasLimit = new $util.LongBits( + object.GasLimit.low >>> 0, + object.GasLimit.high >>> 0, + ).toNumber(true); if (object.Data != null) if (typeof object.Data === "string") - $util.base64.decode(object.Data, message.Data = $util.newBuffer($util.base64.length(object.Data)), 0); - else if (object.Data.length >= 0) - message.Data = object.Data; + $util.base64.decode( + object.Data, + (message.Data = $util.newBuffer($util.base64.length(object.Data))), + 0, + ); + else if (object.Data.length >= 0) message.Data = object.Data; if (object.ChainID != null) if (typeof object.ChainID === "string") - $util.base64.decode(object.ChainID, message.ChainID = $util.newBuffer($util.base64.length(object.ChainID)), 0); - else if (object.ChainID.length >= 0) - message.ChainID = object.ChainID; - if (object.Version != null) - message.Version = object.Version >>> 0; + $util.base64.decode( + object.ChainID, + (message.ChainID = $util.newBuffer($util.base64.length(object.ChainID))), + 0, + ); + else if (object.ChainID.length >= 0) message.ChainID = object.ChainID; + if (object.Version != null) message.Version = object.Version >>> 0; if (object.Signature != null) if (typeof object.Signature === "string") - $util.base64.decode(object.Signature, message.Signature = $util.newBuffer($util.base64.length(object.Signature)), 0); - else if (object.Signature.length >= 0) - message.Signature = object.Signature; - if (object.Options != null) - message.Options = object.Options >>> 0; + $util.base64.decode( + object.Signature, + (message.Signature = $util.newBuffer($util.base64.length(object.Signature))), + 0, + ); + else if (object.Signature.length >= 0) message.Signature = object.Signature; + if (object.Options != null) message.Options = object.Options >>> 0; if (object.GuardianAddr != null) if (typeof object.GuardianAddr === "string") - $util.base64.decode(object.GuardianAddr, message.GuardianAddr = $util.newBuffer($util.base64.length(object.GuardianAddr)), 0); - else if (object.GuardianAddr.length >= 0) - message.GuardianAddr = object.GuardianAddr; + $util.base64.decode( + object.GuardianAddr, + (message.GuardianAddr = $util.newBuffer($util.base64.length(object.GuardianAddr))), + 0, + ); + else if (object.GuardianAddr.length >= 0) message.GuardianAddr = object.GuardianAddr; if (object.GuardianSignature != null) if (typeof object.GuardianSignature === "string") - $util.base64.decode(object.GuardianSignature, message.GuardianSignature = $util.newBuffer($util.base64.length(object.GuardianSignature)), 0); - else if (object.GuardianSignature.length >= 0) - message.GuardianSignature = object.GuardianSignature; + $util.base64.decode( + object.GuardianSignature, + (message.GuardianSignature = $util.newBuffer( + $util.base64.length(object.GuardianSignature), + )), + 0, + ); + else if (object.GuardianSignature.length >= 0) 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.RelayerSignature != null) + if (typeof object.RelayerSignature === "string") + $util.base64.decode( + object.RelayerSignature, + (message.RelayerSignature = $util.newBuffer($util.base64.length(object.RelayerSignature))), + 0, + ); + else if (object.RelayerSignature.length >= 0) message.RelayerSignature = object.RelayerSignature; return message; }; - + /** * Creates a plain object from a Transaction message. Also converts values to other types if specified. * @function toObject @@ -520,140 +658,225 @@ * @returns {Object.} Plain object */ Transaction.toObject = function toObject(message, options) { - if (!options) - options = {}; + if (!options) options = {}; var object = {}; if (options.defaults) { if ($util.Long) { var long = new $util.Long(0, 0, true); - object.Nonce = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; - } else - object.Nonce = options.longs === String ? "0" : 0; - if (options.bytes === String) - object.Value = ""; + object.Nonce = + options.longs === String + ? long.toString() + : options.longs === Number + ? long.toNumber() + : long; + } else object.Nonce = options.longs === String ? "0" : 0; + if (options.bytes === String) object.Value = ""; else { object.Value = []; - if (options.bytes !== Array) - object.Value = $util.newBuffer(object.Value); + if (options.bytes !== Array) object.Value = $util.newBuffer(object.Value); } - if (options.bytes === String) - object.RcvAddr = ""; + if (options.bytes === String) object.RcvAddr = ""; else { object.RcvAddr = []; - if (options.bytes !== Array) - object.RcvAddr = $util.newBuffer(object.RcvAddr); + if (options.bytes !== Array) object.RcvAddr = $util.newBuffer(object.RcvAddr); } - if (options.bytes === String) - object.RcvUserName = ""; + if (options.bytes === String) object.RcvUserName = ""; else { object.RcvUserName = []; - if (options.bytes !== Array) - object.RcvUserName = $util.newBuffer(object.RcvUserName); + if (options.bytes !== Array) object.RcvUserName = $util.newBuffer(object.RcvUserName); } - if (options.bytes === String) - object.SndAddr = ""; + if (options.bytes === String) object.SndAddr = ""; else { object.SndAddr = []; - if (options.bytes !== Array) - object.SndAddr = $util.newBuffer(object.SndAddr); + if (options.bytes !== Array) object.SndAddr = $util.newBuffer(object.SndAddr); } - if (options.bytes === String) - object.SndUserName = ""; + if (options.bytes === String) object.SndUserName = ""; else { object.SndUserName = []; - if (options.bytes !== Array) - object.SndUserName = $util.newBuffer(object.SndUserName); + if (options.bytes !== Array) object.SndUserName = $util.newBuffer(object.SndUserName); } if ($util.Long) { var long = new $util.Long(0, 0, true); - object.GasPrice = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; - } else - object.GasPrice = options.longs === String ? "0" : 0; + object.GasPrice = + options.longs === String + ? long.toString() + : options.longs === Number + ? long.toNumber() + : long; + } else object.GasPrice = options.longs === String ? "0" : 0; if ($util.Long) { var long = new $util.Long(0, 0, true); - object.GasLimit = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; - } else - object.GasLimit = options.longs === String ? "0" : 0; - if (options.bytes === String) - object.Data = ""; + object.GasLimit = + options.longs === String + ? long.toString() + : options.longs === Number + ? long.toNumber() + : long; + } else object.GasLimit = options.longs === String ? "0" : 0; + if (options.bytes === String) object.Data = ""; else { object.Data = []; - if (options.bytes !== Array) - object.Data = $util.newBuffer(object.Data); + if (options.bytes !== Array) object.Data = $util.newBuffer(object.Data); } - if (options.bytes === String) - object.ChainID = ""; + if (options.bytes === String) object.ChainID = ""; else { object.ChainID = []; - if (options.bytes !== Array) - object.ChainID = $util.newBuffer(object.ChainID); + if (options.bytes !== Array) object.ChainID = $util.newBuffer(object.ChainID); } object.Version = 0; - if (options.bytes === String) - object.Signature = ""; + if (options.bytes === String) object.Signature = ""; else { object.Signature = []; - if (options.bytes !== Array) - object.Signature = $util.newBuffer(object.Signature); + if (options.bytes !== Array) object.Signature = $util.newBuffer(object.Signature); } object.Options = 0; - if (options.bytes === String) - object.GuardianAddr = ""; + if (options.bytes === String) object.GuardianAddr = ""; else { object.GuardianAddr = []; - if (options.bytes !== Array) - object.GuardianAddr = $util.newBuffer(object.GuardianAddr); + if (options.bytes !== Array) object.GuardianAddr = $util.newBuffer(object.GuardianAddr); } - if (options.bytes === String) - object.GuardianSignature = ""; + if (options.bytes === String) object.GuardianSignature = ""; else { object.GuardianSignature = []; if (options.bytes !== Array) object.GuardianSignature = $util.newBuffer(object.GuardianSignature); } + if (options.bytes === String) object.Relayer = ""; + else { + object.Relayer = []; + if (options.bytes !== Array) object.Relayer = $util.newBuffer(object.Relayer); + } + if (options.bytes === String) object.RelayerSignature = ""; + else { + object.RelayerSignature = []; + if (options.bytes !== Array) object.RelayerSignature = $util.newBuffer(object.RelayerSignature); + } } if (message.Nonce != null && message.hasOwnProperty("Nonce")) if (typeof message.Nonce === "number") object.Nonce = options.longs === String ? String(message.Nonce) : message.Nonce; else - object.Nonce = options.longs === String ? $util.Long.prototype.toString.call(message.Nonce) : options.longs === Number ? new $util.LongBits(message.Nonce.low >>> 0, message.Nonce.high >>> 0).toNumber(true) : message.Nonce; + object.Nonce = + options.longs === String + ? $util.Long.prototype.toString.call(message.Nonce) + : options.longs === Number + ? new $util.LongBits(message.Nonce.low >>> 0, message.Nonce.high >>> 0).toNumber(true) + : message.Nonce; if (message.Value != null && message.hasOwnProperty("Value")) - object.Value = options.bytes === String ? $util.base64.encode(message.Value, 0, message.Value.length) : options.bytes === Array ? Array.prototype.slice.call(message.Value) : message.Value; + object.Value = + options.bytes === String + ? $util.base64.encode(message.Value, 0, message.Value.length) + : options.bytes === Array + ? Array.prototype.slice.call(message.Value) + : message.Value; if (message.RcvAddr != null && message.hasOwnProperty("RcvAddr")) - object.RcvAddr = options.bytes === String ? $util.base64.encode(message.RcvAddr, 0, message.RcvAddr.length) : options.bytes === Array ? Array.prototype.slice.call(message.RcvAddr) : message.RcvAddr; + object.RcvAddr = + options.bytes === String + ? $util.base64.encode(message.RcvAddr, 0, message.RcvAddr.length) + : options.bytes === Array + ? Array.prototype.slice.call(message.RcvAddr) + : message.RcvAddr; if (message.RcvUserName != null && message.hasOwnProperty("RcvUserName")) - object.RcvUserName = options.bytes === String ? $util.base64.encode(message.RcvUserName, 0, message.RcvUserName.length) : options.bytes === Array ? Array.prototype.slice.call(message.RcvUserName) : message.RcvUserName; + object.RcvUserName = + options.bytes === String + ? $util.base64.encode(message.RcvUserName, 0, message.RcvUserName.length) + : options.bytes === Array + ? Array.prototype.slice.call(message.RcvUserName) + : message.RcvUserName; if (message.SndAddr != null && message.hasOwnProperty("SndAddr")) - object.SndAddr = options.bytes === String ? $util.base64.encode(message.SndAddr, 0, message.SndAddr.length) : options.bytes === Array ? Array.prototype.slice.call(message.SndAddr) : message.SndAddr; + object.SndAddr = + options.bytes === String + ? $util.base64.encode(message.SndAddr, 0, message.SndAddr.length) + : options.bytes === Array + ? Array.prototype.slice.call(message.SndAddr) + : message.SndAddr; if (message.SndUserName != null && message.hasOwnProperty("SndUserName")) - object.SndUserName = options.bytes === String ? $util.base64.encode(message.SndUserName, 0, message.SndUserName.length) : options.bytes === Array ? Array.prototype.slice.call(message.SndUserName) : message.SndUserName; + object.SndUserName = + options.bytes === String + ? $util.base64.encode(message.SndUserName, 0, message.SndUserName.length) + : options.bytes === Array + ? Array.prototype.slice.call(message.SndUserName) + : message.SndUserName; if (message.GasPrice != null && message.hasOwnProperty("GasPrice")) if (typeof message.GasPrice === "number") object.GasPrice = options.longs === String ? String(message.GasPrice) : message.GasPrice; else - object.GasPrice = options.longs === String ? $util.Long.prototype.toString.call(message.GasPrice) : options.longs === Number ? new $util.LongBits(message.GasPrice.low >>> 0, message.GasPrice.high >>> 0).toNumber(true) : message.GasPrice; + object.GasPrice = + options.longs === String + ? $util.Long.prototype.toString.call(message.GasPrice) + : options.longs === Number + ? new $util.LongBits( + message.GasPrice.low >>> 0, + message.GasPrice.high >>> 0, + ).toNumber(true) + : message.GasPrice; if (message.GasLimit != null && message.hasOwnProperty("GasLimit")) if (typeof message.GasLimit === "number") object.GasLimit = options.longs === String ? String(message.GasLimit) : message.GasLimit; else - object.GasLimit = options.longs === String ? $util.Long.prototype.toString.call(message.GasLimit) : options.longs === Number ? new $util.LongBits(message.GasLimit.low >>> 0, message.GasLimit.high >>> 0).toNumber(true) : message.GasLimit; + object.GasLimit = + options.longs === String + ? $util.Long.prototype.toString.call(message.GasLimit) + : options.longs === Number + ? new $util.LongBits( + message.GasLimit.low >>> 0, + message.GasLimit.high >>> 0, + ).toNumber(true) + : message.GasLimit; if (message.Data != null && message.hasOwnProperty("Data")) - object.Data = options.bytes === String ? $util.base64.encode(message.Data, 0, message.Data.length) : options.bytes === Array ? Array.prototype.slice.call(message.Data) : message.Data; + object.Data = + options.bytes === String + ? $util.base64.encode(message.Data, 0, message.Data.length) + : options.bytes === Array + ? Array.prototype.slice.call(message.Data) + : message.Data; if (message.ChainID != null && message.hasOwnProperty("ChainID")) - object.ChainID = options.bytes === String ? $util.base64.encode(message.ChainID, 0, message.ChainID.length) : options.bytes === Array ? Array.prototype.slice.call(message.ChainID) : message.ChainID; - if (message.Version != null && message.hasOwnProperty("Version")) - object.Version = message.Version; + object.ChainID = + options.bytes === String + ? $util.base64.encode(message.ChainID, 0, message.ChainID.length) + : options.bytes === Array + ? Array.prototype.slice.call(message.ChainID) + : message.ChainID; + if (message.Version != null && message.hasOwnProperty("Version")) object.Version = message.Version; if (message.Signature != null && message.hasOwnProperty("Signature")) - object.Signature = options.bytes === String ? $util.base64.encode(message.Signature, 0, message.Signature.length) : options.bytes === Array ? Array.prototype.slice.call(message.Signature) : message.Signature; - if (message.Options != null && message.hasOwnProperty("Options")) - object.Options = message.Options; + object.Signature = + options.bytes === String + ? $util.base64.encode(message.Signature, 0, message.Signature.length) + : options.bytes === Array + ? Array.prototype.slice.call(message.Signature) + : message.Signature; + if (message.Options != null && message.hasOwnProperty("Options")) object.Options = message.Options; if (message.GuardianAddr != null && message.hasOwnProperty("GuardianAddr")) - object.GuardianAddr = options.bytes === String ? $util.base64.encode(message.GuardianAddr, 0, message.GuardianAddr.length) : options.bytes === Array ? Array.prototype.slice.call(message.GuardianAddr) : message.GuardianAddr; + object.GuardianAddr = + options.bytes === String + ? $util.base64.encode(message.GuardianAddr, 0, message.GuardianAddr.length) + : options.bytes === Array + ? Array.prototype.slice.call(message.GuardianAddr) + : message.GuardianAddr; if (message.GuardianSignature != null && message.hasOwnProperty("GuardianSignature")) - 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; + 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.RelayerSignature != null && message.hasOwnProperty("RelayerSignature")) + object.RelayerSignature = + options.bytes === String + ? $util.base64.encode(message.RelayerSignature, 0, message.RelayerSignature.length) + : options.bytes === Array + ? Array.prototype.slice.call(message.RelayerSignature) + : message.RelayerSignature; return object; }; - + /** * Converts this Transaction to JSON. * @function toJSON @@ -664,7 +887,7 @@ Transaction.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; - + /** * Gets the default type url for Transaction * @function getTypeUrl @@ -679,10 +902,10 @@ } return typeUrlPrefix + "/proto.Transaction"; }; - + return Transaction; })(); - + return proto; })(); diff --git a/src/proto/serializer.ts b/src/proto/serializer.ts index 2f46ee425..8cb95a299 100644 --- a/src/proto/serializer.ts +++ b/src/proto/serializer.ts @@ -60,6 +60,11 @@ export class ProtoSerializer { protoTransaction.GuardianSignature = transaction.guardianSignature; } + if (transaction.relayer && !transaction.relayer.isEmpty()) { + protoTransaction.Relayer = transaction.relayer.getPublicKey(); + protoTransaction.RelayerSignature = transaction.relayerSignature; + } + return protoTransaction; } diff --git a/src/proto/transaction.proto b/src/proto/transaction.proto index b3b7dfd1f..efc8ad04b 100644 --- a/src/proto/transaction.proto +++ b/src/proto/transaction.proto @@ -25,4 +25,6 @@ message Transaction { uint32 Options = 13; bytes GuardianAddr = 14; bytes GuardianSignature = 15; + bytes Relayer = 16; + bytes RelayerSignature = 17; } diff --git a/src/transaction.spec.ts b/src/transaction.spec.ts index ecf98d5c0..7e4eefffd 100644 --- a/src/transaction.spec.ts +++ b/src/transaction.spec.ts @@ -1,4 +1,3 @@ -import { UserPublicKey, UserVerifier } from "./wallet"; import BigNumber from "bignumber.js"; import { assert } from "chai"; import { Address } from "./address"; @@ -10,6 +9,7 @@ import { TokenTransfer } from "./tokens"; import { Transaction } from "./transaction"; import { TransactionComputer } from "./transactionComputer"; import { TransactionPayload } from "./transactionPayload"; +import { UserPublicKey, UserVerifier } from "./wallet"; describe("test transaction", async () => { let wallets: Record; @@ -751,4 +751,44 @@ describe("test transaction", async () => { assert.equal(isSignedByAlice, true); assert.equal(isSignedByBob, false); }); + + it("should serialize transaction with relayer", async () => { + const transaction = new Transaction({ + chainID: networkConfig.ChainID, + sender: wallets.alice.address.bech32(), + receiver: wallets.alice.address.bech32(), + relayer: wallets.bob.address, + gasLimit: 50000n, + value: 0n, + version: 2, + nonce: 89n, + }); + + const serializedTransactionBytes = transactionComputer.computeBytesForSigning(transaction); + const serializedTransaction = Buffer.from(serializedTransactionBytes).toString(); + + assert.equal( + serializedTransaction, + `{"nonce":89,"value":"0","receiver":"erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th","sender":"erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th","gasPrice":1000000000,"gasLimit":50000,"chainID":"D","version":2,"relayer":"erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"}`, + ); + }); + + it("should test relayed v3", async () => { + const transaction = new Transaction({ + chainID: networkConfig.ChainID, + sender: wallets.alice.address.bech32(), + receiver: wallets.alice.address.bech32(), + senderUsername: "alice", + receiverUsername: "bob", + gasLimit: 80000n, + value: 0n, + version: 2, + nonce: 89n, + data: Buffer.from("hello"), + }); + + assert.isFalse(transactionComputer.isRelayedV3Transaction(transaction)); + transaction.relayer = wallets.carol.address; + assert.isTrue(transactionComputer.isRelayedV3Transaction(transaction)); + }); }); diff --git a/src/transaction.ts b/src/transaction.ts index a8fad0a9d..9bf6cdd29 100644 --- a/src/transaction.ts +++ b/src/transaction.ts @@ -11,7 +11,6 @@ import { INonce, IPlainTransactionObject, ISignature, - ITransaction, ITransactionOptions, ITransactionPayload, ITransactionValue, @@ -20,8 +19,8 @@ import { import { INetworkConfig } from "./interfaceOfNetwork"; import { TransactionOptions, TransactionVersion } from "./networkParams"; import { interpretSignatureAsBuffer } from "./signature"; -import { TransactionPayload } from "./transactionPayload"; import { TransactionComputer } from "./transactionComputer"; +import { TransactionPayload } from "./transactionPayload"; /** * An abstraction for creating and signing transactions. @@ -92,6 +91,11 @@ export class Transaction { */ public guardian: string; + /** + * The relayer, in address format, next version all the other addresses will not be string anymore. + */ + public relayer?: Address; + /** * The signature. */ @@ -102,6 +106,11 @@ export class Transaction { */ public guardianSignature: Uint8Array; + /** + * The signature of the guardian. + */ + public relayerSignature: Uint8Array; + /** * Creates a new Transaction object. */ @@ -110,6 +119,7 @@ export class Transaction { value?: ITransactionValue | bigint; sender: IAddress | string; receiver: IAddress | string; + relayer?: Address; senderUsername?: string; receiverUsername?: string; gasPrice?: IGasPrice | bigint; @@ -121,6 +131,7 @@ export class Transaction { guardian?: IAddress | string; signature?: Uint8Array; guardianSignature?: Uint8Array; + relayerSignature?: Uint8Array; }) { this.nonce = BigInt(options.nonce?.valueOf() || 0n); // We still rely on "bigNumber" for value, because client code might be passing a BigNumber object as a legacy "ITransactionValue", @@ -137,9 +148,11 @@ export class Transaction { this.version = Number(options.version?.valueOf() || TRANSACTION_VERSION_DEFAULT); this.options = Number(options.options?.valueOf() || TRANSACTION_OPTIONS_DEFAULT); this.guardian = options.guardian ? this.addressAsBech32(options.guardian) : ""; + this.relayer = options.relayer?.isEmpty() ? undefined : options.relayer; this.signature = options.signature || Buffer.from([]); this.guardianSignature = options.guardianSignature || Buffer.from([]); + this.relayerSignature = options.relayerSignature || Buffer.from([]); } private addressAsBech32(address: IAddress | string): string { diff --git a/src/transactionComputer.ts b/src/transactionComputer.ts index da365e7b2..7e4370568 100644 --- a/src/transactionComputer.ts +++ b/src/transactionComputer.ts @@ -1,4 +1,5 @@ import BigNumber from "bignumber.js"; +import { Address } from "./address"; import { MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS, TRANSACTION_OPTIONS_TX_GUARDED, @@ -94,6 +95,17 @@ export class TransactionComputer { transaction.guardian = guardian; } + applyRelayer(transaction: ITransaction, relayer: Address) { + transaction.relayer = relayer; + } + + isRelayedV3Transaction(transaction: ITransaction) { + if (transaction.relayer && !transaction.relayer.isEmpty()) { + return true; + } + return false; + } + applyOptionsForHashSigning(transaction: ITransaction) { if (transaction.version < MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS) { transaction.version = MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS; @@ -122,6 +134,7 @@ export class TransactionComputer { obj.version = transaction.version; obj.options = transaction.options ? transaction.options : undefined; obj.guardian = transaction.guardian ? transaction.guardian : undefined; + obj.relayer = transaction.relayer?.isEmpty() ? undefined : transaction.relayer?.toBech32(); return obj; } From a97184933520111c32080fbc7af28c5e6d213f53 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 11 Dec 2024 22:47:20 +0200 Subject: [PATCH 2/6] Bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8d9c32d73..75b731163 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@multiversx/sdk-core", - "version": "13.15.0", + "version": "13.16.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@multiversx/sdk-core", - "version": "13.15.0", + "version": "13.16.0", "license": "MIT", "dependencies": { "@multiversx/sdk-transaction-decoder": "1.0.2", diff --git a/package.json b/package.json index abe0b1d31..8d91ddebc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-core", - "version": "13.15.0", + "version": "13.16.0", "description": "MultiversX SDK for JavaScript and TypeScript", "author": "MultiversX", "homepage": "https://multiversx.com", From 642b00a48e583e6d0c4072132296020834f7fc95 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 12 Dec 2024 10:20:19 +0200 Subject: [PATCH 3/6] Generate proto file --- src/proto/compiled.js | 671 ++++++++++++++++-------------------------- 1 file changed, 256 insertions(+), 415 deletions(-) diff --git a/src/proto/compiled.js b/src/proto/compiled.js index c0424d789..5677d7077 100644 --- a/src/proto/compiled.js +++ b/src/proto/compiled.js @@ -1,30 +1,32 @@ /*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ -(function (global, factory) { - /* global define, require, module */ +(function(global, factory) { /* global define, require, module */ - /* AMD */ if (typeof define === "function" && define.amd) define(["protobufjs/minimal"], factory); - /* CommonJS */ else if (typeof require === "function" && typeof module === "object" && module && module.exports) + /* AMD */ if (typeof define === 'function' && define.amd) + define(["protobufjs/minimal"], factory); + + /* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports) module.exports = factory(require("protobufjs/minimal")); -})(this, function ($protobuf) { + +})(this, function($protobuf) { "use strict"; // Common aliases - var $Reader = $protobuf.Reader, - $Writer = $protobuf.Writer, - $util = $protobuf.util; - + var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + // Exported root namespace var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); - - $root.proto = (function () { + + $root.proto = (function() { + /** * Namespace proto. * @exports proto * @namespace */ var proto = {}; - - proto.Transaction = (function () { + + proto.Transaction = (function() { + /** * Properties of a Transaction. * @memberof proto @@ -44,10 +46,10 @@ * @property {number|null} [Options] Transaction Options * @property {Uint8Array|null} [GuardianAddr] Transaction GuardianAddr * @property {Uint8Array|null} [GuardianSignature] Transaction GuardianSignature - * @property {Uint8Array|null} [Relayer] Transaction RelayerAddr + * @property {Uint8Array|null} [Relayer] Transaction Relayer * @property {Uint8Array|null} [RelayerSignature] Transaction RelayerSignature */ - + /** * Constructs a new Transaction. * @memberof proto @@ -59,17 +61,18 @@ function Transaction(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) - if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; } - + /** * Transaction Nonce. * @member {number|Long} Nonce * @memberof proto.Transaction * @instance */ - Transaction.prototype.Nonce = $util.Long ? $util.Long.fromBits(0, 0, true) : 0; - + Transaction.prototype.Nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + /** * Transaction Value. * @member {Uint8Array} Value @@ -77,7 +80,7 @@ * @instance */ Transaction.prototype.Value = $util.newBuffer([]); - + /** * Transaction RcvAddr. * @member {Uint8Array} RcvAddr @@ -85,7 +88,7 @@ * @instance */ Transaction.prototype.RcvAddr = $util.newBuffer([]); - + /** * Transaction RcvUserName. * @member {Uint8Array} RcvUserName @@ -93,7 +96,7 @@ * @instance */ Transaction.prototype.RcvUserName = $util.newBuffer([]); - + /** * Transaction SndAddr. * @member {Uint8Array} SndAddr @@ -101,7 +104,7 @@ * @instance */ Transaction.prototype.SndAddr = $util.newBuffer([]); - + /** * Transaction SndUserName. * @member {Uint8Array} SndUserName @@ -109,23 +112,23 @@ * @instance */ Transaction.prototype.SndUserName = $util.newBuffer([]); - + /** * Transaction GasPrice. * @member {number|Long} GasPrice * @memberof proto.Transaction * @instance */ - Transaction.prototype.GasPrice = $util.Long ? $util.Long.fromBits(0, 0, true) : 0; - + Transaction.prototype.GasPrice = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + /** * Transaction GasLimit. * @member {number|Long} GasLimit * @memberof proto.Transaction * @instance */ - Transaction.prototype.GasLimit = $util.Long ? $util.Long.fromBits(0, 0, true) : 0; - + Transaction.prototype.GasLimit = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + /** * Transaction Data. * @member {Uint8Array} Data @@ -133,7 +136,7 @@ * @instance */ Transaction.prototype.Data = $util.newBuffer([]); - + /** * Transaction ChainID. * @member {Uint8Array} ChainID @@ -141,7 +144,7 @@ * @instance */ Transaction.prototype.ChainID = $util.newBuffer([]); - + /** * Transaction Version. * @member {number} Version @@ -149,7 +152,7 @@ * @instance */ Transaction.prototype.Version = 0; - + /** * Transaction Signature. * @member {Uint8Array} Signature @@ -157,7 +160,7 @@ * @instance */ Transaction.prototype.Signature = $util.newBuffer([]); - + /** * Transaction Options. * @member {number} Options @@ -165,7 +168,7 @@ * @instance */ Transaction.prototype.Options = 0; - + /** * Transaction GuardianAddr. * @member {Uint8Array} GuardianAddr @@ -173,7 +176,7 @@ * @instance */ Transaction.prototype.GuardianAddr = $util.newBuffer([]); - + /** * Transaction GuardianSignature. * @member {Uint8Array} GuardianSignature @@ -181,14 +184,15 @@ * @instance */ Transaction.prototype.GuardianSignature = $util.newBuffer([]); - + /** * Transaction Relayer. * @member {Uint8Array} Relayer + * @memberof proto.Transaction * @instance */ Transaction.prototype.Relayer = $util.newBuffer([]); - + /** * Transaction RelayerSignature. * @member {Uint8Array} RelayerSignature @@ -196,7 +200,7 @@ * @instance */ Transaction.prototype.RelayerSignature = $util.newBuffer([]); - + /** * Creates a new Transaction instance using the specified properties. * @function create @@ -208,7 +212,7 @@ Transaction.create = function create(properties) { return new Transaction(properties); }; - + /** * Encodes the specified Transaction message. Does not implicitly {@link proto.Transaction.verify|verify} messages. * @function encode @@ -219,44 +223,45 @@ * @returns {$protobuf.Writer} Writer */ Transaction.encode = function encode(message, writer) { - if (!writer) writer = $Writer.create(); + if (!writer) + writer = $Writer.create(); if (message.Nonce != null && Object.hasOwnProperty.call(message, "Nonce")) - writer.uint32(/* id 1, wireType 0 =*/ 8).uint64(message.Nonce); + writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.Nonce); if (message.Value != null && Object.hasOwnProperty.call(message, "Value")) - writer.uint32(/* id 2, wireType 2 =*/ 18).bytes(message.Value); + writer.uint32(/* id 2, wireType 2 =*/18).bytes(message.Value); if (message.RcvAddr != null && Object.hasOwnProperty.call(message, "RcvAddr")) - writer.uint32(/* id 3, wireType 2 =*/ 26).bytes(message.RcvAddr); + writer.uint32(/* id 3, wireType 2 =*/26).bytes(message.RcvAddr); if (message.RcvUserName != null && Object.hasOwnProperty.call(message, "RcvUserName")) - writer.uint32(/* id 4, wireType 2 =*/ 34).bytes(message.RcvUserName); + writer.uint32(/* id 4, wireType 2 =*/34).bytes(message.RcvUserName); if (message.SndAddr != null && Object.hasOwnProperty.call(message, "SndAddr")) - writer.uint32(/* id 5, wireType 2 =*/ 42).bytes(message.SndAddr); + writer.uint32(/* id 5, wireType 2 =*/42).bytes(message.SndAddr); if (message.SndUserName != null && Object.hasOwnProperty.call(message, "SndUserName")) - writer.uint32(/* id 6, wireType 2 =*/ 50).bytes(message.SndUserName); + writer.uint32(/* id 6, wireType 2 =*/50).bytes(message.SndUserName); if (message.GasPrice != null && Object.hasOwnProperty.call(message, "GasPrice")) - writer.uint32(/* id 7, wireType 0 =*/ 56).uint64(message.GasPrice); + writer.uint32(/* id 7, wireType 0 =*/56).uint64(message.GasPrice); if (message.GasLimit != null && Object.hasOwnProperty.call(message, "GasLimit")) - writer.uint32(/* id 8, wireType 0 =*/ 64).uint64(message.GasLimit); + writer.uint32(/* id 8, wireType 0 =*/64).uint64(message.GasLimit); if (message.Data != null && Object.hasOwnProperty.call(message, "Data")) - writer.uint32(/* id 9, wireType 2 =*/ 74).bytes(message.Data); + writer.uint32(/* id 9, wireType 2 =*/74).bytes(message.Data); if (message.ChainID != null && Object.hasOwnProperty.call(message, "ChainID")) - writer.uint32(/* id 10, wireType 2 =*/ 82).bytes(message.ChainID); + writer.uint32(/* id 10, wireType 2 =*/82).bytes(message.ChainID); if (message.Version != null && Object.hasOwnProperty.call(message, "Version")) - writer.uint32(/* id 11, wireType 0 =*/ 88).uint32(message.Version); + writer.uint32(/* id 11, wireType 0 =*/88).uint32(message.Version); if (message.Signature != null && Object.hasOwnProperty.call(message, "Signature")) - writer.uint32(/* id 12, wireType 2 =*/ 98).bytes(message.Signature); + writer.uint32(/* id 12, wireType 2 =*/98).bytes(message.Signature); if (message.Options != null && Object.hasOwnProperty.call(message, "Options")) - writer.uint32(/* id 13, wireType 0 =*/ 104).uint32(message.Options); + writer.uint32(/* id 13, wireType 0 =*/104).uint32(message.Options); if (message.GuardianAddr != null && Object.hasOwnProperty.call(message, "GuardianAddr")) - writer.uint32(/* id 14, wireType 2 =*/ 114).bytes(message.GuardianAddr); + writer.uint32(/* id 14, wireType 2 =*/114).bytes(message.GuardianAddr); if (message.GuardianSignature != null && Object.hasOwnProperty.call(message, "GuardianSignature")) - writer.uint32(/* id 15, wireType 2 =*/ 122).bytes(message.GuardianSignature); + writer.uint32(/* id 15, wireType 2 =*/122).bytes(message.GuardianSignature); if (message.Relayer != null && Object.hasOwnProperty.call(message, "Relayer")) - writer.uint32(/* id 14, wireType 2 =*/ 114).bytes(message.Relayer); + writer.uint32(/* id 16, wireType 2 =*/130).bytes(message.Relayer); if (message.RelayerSignature != null && Object.hasOwnProperty.call(message, "RelayerSignature")) - writer.uint32(/* id 15, wireType 2 =*/ 122).bytes(message.RelayerSignature); + writer.uint32(/* id 17, wireType 2 =*/138).bytes(message.RelayerSignature); return writer; }; - + /** * Encodes the specified Transaction message, length delimited. Does not implicitly {@link proto.Transaction.verify|verify} messages. * @function encodeDelimited @@ -269,7 +274,7 @@ Transaction.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; - + /** * Decodes a Transaction message from the specified reader or buffer. * @function decode @@ -282,88 +287,88 @@ * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Transaction.decode = function decode(reader, length) { - if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, - message = new $root.proto.Transaction(); + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.proto.Transaction(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { - case 1: { + case 1: { message.Nonce = reader.uint64(); break; } - case 2: { + case 2: { message.Value = reader.bytes(); break; } - case 3: { + case 3: { message.RcvAddr = reader.bytes(); break; } - case 4: { + case 4: { message.RcvUserName = reader.bytes(); break; } - case 5: { + case 5: { message.SndAddr = reader.bytes(); break; } - case 6: { + case 6: { message.SndUserName = reader.bytes(); break; } - case 7: { + case 7: { message.GasPrice = reader.uint64(); break; } - case 8: { + case 8: { message.GasLimit = reader.uint64(); break; } - case 9: { + case 9: { message.Data = reader.bytes(); break; } - case 10: { + case 10: { message.ChainID = reader.bytes(); break; } - case 11: { + case 11: { message.Version = reader.uint32(); break; } - case 12: { + case 12: { message.Signature = reader.bytes(); break; } - case 13: { + case 13: { message.Options = reader.uint32(); break; } - case 14: { + case 14: { message.GuardianAddr = reader.bytes(); break; } - case 15: { + case 15: { message.GuardianSignature = reader.bytes(); break; } - case 16: { + case 16: { message.Relayer = reader.bytes(); break; } - case 17: { + case 17: { message.RelayerSignature = reader.bytes(); break; } - default: - reader.skipType(tag & 7); - break; + default: + reader.skipType(tag & 7); + break; } } return message; }; - + /** * Decodes a Transaction message from the specified reader or buffer, length delimited. * @function decodeDelimited @@ -375,10 +380,11 @@ * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Transaction.decodeDelimited = function decodeDelimited(reader) { - if (!(reader instanceof $Reader)) reader = new $Reader(reader); + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; - + /** * Verifies a Transaction message. * @function verify @@ -388,126 +394,62 @@ * @returns {string|null} `null` if valid, otherwise the reason why it is not */ Transaction.verify = function verify(message) { - if (typeof message !== "object" || message === null) return "object expected"; + if (typeof message !== "object" || message === null) + return "object expected"; if (message.Nonce != null && message.hasOwnProperty("Nonce")) - if ( - !$util.isInteger(message.Nonce) && - !(message.Nonce && $util.isInteger(message.Nonce.low) && $util.isInteger(message.Nonce.high)) - ) + if (!$util.isInteger(message.Nonce) && !(message.Nonce && $util.isInteger(message.Nonce.low) && $util.isInteger(message.Nonce.high))) return "Nonce: integer|Long expected"; if (message.Value != null && message.hasOwnProperty("Value")) - if (!((message.Value && typeof message.Value.length === "number") || $util.isString(message.Value))) + if (!(message.Value && typeof message.Value.length === "number" || $util.isString(message.Value))) return "Value: buffer expected"; if (message.RcvAddr != null && message.hasOwnProperty("RcvAddr")) - if ( - !( - (message.RcvAddr && typeof message.RcvAddr.length === "number") || - $util.isString(message.RcvAddr) - ) - ) + if (!(message.RcvAddr && typeof message.RcvAddr.length === "number" || $util.isString(message.RcvAddr))) return "RcvAddr: buffer expected"; if (message.RcvUserName != null && message.hasOwnProperty("RcvUserName")) - if ( - !( - (message.RcvUserName && typeof message.RcvUserName.length === "number") || - $util.isString(message.RcvUserName) - ) - ) + if (!(message.RcvUserName && typeof message.RcvUserName.length === "number" || $util.isString(message.RcvUserName))) return "RcvUserName: buffer expected"; if (message.SndAddr != null && message.hasOwnProperty("SndAddr")) - if ( - !( - (message.SndAddr && typeof message.SndAddr.length === "number") || - $util.isString(message.SndAddr) - ) - ) + if (!(message.SndAddr && typeof message.SndAddr.length === "number" || $util.isString(message.SndAddr))) return "SndAddr: buffer expected"; if (message.SndUserName != null && message.hasOwnProperty("SndUserName")) - if ( - !( - (message.SndUserName && typeof message.SndUserName.length === "number") || - $util.isString(message.SndUserName) - ) - ) + if (!(message.SndUserName && typeof message.SndUserName.length === "number" || $util.isString(message.SndUserName))) return "SndUserName: buffer expected"; if (message.GasPrice != null && message.hasOwnProperty("GasPrice")) - if ( - !$util.isInteger(message.GasPrice) && - !( - message.GasPrice && - $util.isInteger(message.GasPrice.low) && - $util.isInteger(message.GasPrice.high) - ) - ) + if (!$util.isInteger(message.GasPrice) && !(message.GasPrice && $util.isInteger(message.GasPrice.low) && $util.isInteger(message.GasPrice.high))) return "GasPrice: integer|Long expected"; if (message.GasLimit != null && message.hasOwnProperty("GasLimit")) - if ( - !$util.isInteger(message.GasLimit) && - !( - message.GasLimit && - $util.isInteger(message.GasLimit.low) && - $util.isInteger(message.GasLimit.high) - ) - ) + if (!$util.isInteger(message.GasLimit) && !(message.GasLimit && $util.isInteger(message.GasLimit.low) && $util.isInteger(message.GasLimit.high))) return "GasLimit: integer|Long expected"; if (message.Data != null && message.hasOwnProperty("Data")) - if (!((message.Data && typeof message.Data.length === "number") || $util.isString(message.Data))) + if (!(message.Data && typeof message.Data.length === "number" || $util.isString(message.Data))) return "Data: buffer expected"; if (message.ChainID != null && message.hasOwnProperty("ChainID")) - if ( - !( - (message.ChainID && typeof message.ChainID.length === "number") || - $util.isString(message.ChainID) - ) - ) + if (!(message.ChainID && typeof message.ChainID.length === "number" || $util.isString(message.ChainID))) return "ChainID: buffer expected"; if (message.Version != null && message.hasOwnProperty("Version")) - if (!$util.isInteger(message.Version)) return "Version: integer expected"; + if (!$util.isInteger(message.Version)) + return "Version: integer expected"; if (message.Signature != null && message.hasOwnProperty("Signature")) - if ( - !( - (message.Signature && typeof message.Signature.length === "number") || - $util.isString(message.Signature) - ) - ) + if (!(message.Signature && typeof message.Signature.length === "number" || $util.isString(message.Signature))) return "Signature: buffer expected"; if (message.Options != null && message.hasOwnProperty("Options")) - if (!$util.isInteger(message.Options)) return "Options: integer expected"; + if (!$util.isInteger(message.Options)) + return "Options: integer expected"; if (message.GuardianAddr != null && message.hasOwnProperty("GuardianAddr")) - if ( - !( - (message.GuardianAddr && typeof message.GuardianAddr.length === "number") || - $util.isString(message.GuardianAddr) - ) - ) + if (!(message.GuardianAddr && typeof message.GuardianAddr.length === "number" || $util.isString(message.GuardianAddr))) return "GuardianAddr: buffer expected"; if (message.GuardianSignature != null && message.hasOwnProperty("GuardianSignature")) - if ( - !( - (message.GuardianSignature && typeof message.GuardianSignature.length === "number") || - $util.isString(message.GuardianSignature) - ) - ) + if (!(message.GuardianSignature && typeof message.GuardianSignature.length === "number" || $util.isString(message.GuardianSignature))) return "GuardianSignature: buffer expected"; if (message.Relayer != null && message.hasOwnProperty("Relayer")) - if ( - !( - (message.Relayer && typeof message.Relayer.length === "number") || - $util.isString(message.Relayer) - ) - ) + if (!(message.Relayer && typeof message.Relayer.length === "number" || $util.isString(message.Relayer))) return "Relayer: buffer expected"; if (message.RelayerSignature != null && message.hasOwnProperty("RelayerSignature")) - if ( - !( - (message.RelayerSignature && typeof message.RelayerSignature.length === "number") || - $util.isString(message.RelayerSignature) - ) - ) + if (!(message.RelayerSignature && typeof message.RelayerSignature.length === "number" || $util.isString(message.RelayerSignature))) return "RelayerSignature: buffer expected"; return null; }; - + /** * Creates a Transaction message from a plain object. Also converts values to their respective internal types. * @function fromObject @@ -517,137 +459,103 @@ * @returns {proto.Transaction} Transaction */ Transaction.fromObject = function fromObject(object) { - if (object instanceof $root.proto.Transaction) return object; + if (object instanceof $root.proto.Transaction) + return object; var message = new $root.proto.Transaction(); if (object.Nonce != null) - if ($util.Long) (message.Nonce = $util.Long.fromValue(object.Nonce)).unsigned = true; - else if (typeof object.Nonce === "string") message.Nonce = parseInt(object.Nonce, 10); - else if (typeof object.Nonce === "number") message.Nonce = object.Nonce; + if ($util.Long) + (message.Nonce = $util.Long.fromValue(object.Nonce)).unsigned = true; + else if (typeof object.Nonce === "string") + message.Nonce = parseInt(object.Nonce, 10); + else if (typeof object.Nonce === "number") + message.Nonce = object.Nonce; else if (typeof object.Nonce === "object") - message.Nonce = new $util.LongBits(object.Nonce.low >>> 0, object.Nonce.high >>> 0).toNumber( - true, - ); + message.Nonce = new $util.LongBits(object.Nonce.low >>> 0, object.Nonce.high >>> 0).toNumber(true); if (object.Value != null) if (typeof object.Value === "string") - $util.base64.decode( - object.Value, - (message.Value = $util.newBuffer($util.base64.length(object.Value))), - 0, - ); - else if (object.Value.length >= 0) message.Value = object.Value; + $util.base64.decode(object.Value, message.Value = $util.newBuffer($util.base64.length(object.Value)), 0); + else if (object.Value.length >= 0) + message.Value = object.Value; if (object.RcvAddr != null) if (typeof object.RcvAddr === "string") - $util.base64.decode( - object.RcvAddr, - (message.RcvAddr = $util.newBuffer($util.base64.length(object.RcvAddr))), - 0, - ); - else if (object.RcvAddr.length >= 0) message.RcvAddr = object.RcvAddr; + $util.base64.decode(object.RcvAddr, message.RcvAddr = $util.newBuffer($util.base64.length(object.RcvAddr)), 0); + else if (object.RcvAddr.length >= 0) + message.RcvAddr = object.RcvAddr; if (object.RcvUserName != null) if (typeof object.RcvUserName === "string") - $util.base64.decode( - object.RcvUserName, - (message.RcvUserName = $util.newBuffer($util.base64.length(object.RcvUserName))), - 0, - ); - else if (object.RcvUserName.length >= 0) message.RcvUserName = object.RcvUserName; + $util.base64.decode(object.RcvUserName, message.RcvUserName = $util.newBuffer($util.base64.length(object.RcvUserName)), 0); + else if (object.RcvUserName.length >= 0) + message.RcvUserName = object.RcvUserName; if (object.SndAddr != null) if (typeof object.SndAddr === "string") - $util.base64.decode( - object.SndAddr, - (message.SndAddr = $util.newBuffer($util.base64.length(object.SndAddr))), - 0, - ); - else if (object.SndAddr.length >= 0) message.SndAddr = object.SndAddr; + $util.base64.decode(object.SndAddr, message.SndAddr = $util.newBuffer($util.base64.length(object.SndAddr)), 0); + else if (object.SndAddr.length >= 0) + message.SndAddr = object.SndAddr; if (object.SndUserName != null) if (typeof object.SndUserName === "string") - $util.base64.decode( - object.SndUserName, - (message.SndUserName = $util.newBuffer($util.base64.length(object.SndUserName))), - 0, - ); - else if (object.SndUserName.length >= 0) message.SndUserName = object.SndUserName; + $util.base64.decode(object.SndUserName, message.SndUserName = $util.newBuffer($util.base64.length(object.SndUserName)), 0); + else if (object.SndUserName.length >= 0) + message.SndUserName = object.SndUserName; if (object.GasPrice != null) - if ($util.Long) (message.GasPrice = $util.Long.fromValue(object.GasPrice)).unsigned = true; - else if (typeof object.GasPrice === "string") message.GasPrice = parseInt(object.GasPrice, 10); - else if (typeof object.GasPrice === "number") message.GasPrice = object.GasPrice; + if ($util.Long) + (message.GasPrice = $util.Long.fromValue(object.GasPrice)).unsigned = true; + else if (typeof object.GasPrice === "string") + message.GasPrice = parseInt(object.GasPrice, 10); + else if (typeof object.GasPrice === "number") + message.GasPrice = object.GasPrice; else if (typeof object.GasPrice === "object") - message.GasPrice = new $util.LongBits( - object.GasPrice.low >>> 0, - object.GasPrice.high >>> 0, - ).toNumber(true); + message.GasPrice = new $util.LongBits(object.GasPrice.low >>> 0, object.GasPrice.high >>> 0).toNumber(true); if (object.GasLimit != null) - if ($util.Long) (message.GasLimit = $util.Long.fromValue(object.GasLimit)).unsigned = true; - else if (typeof object.GasLimit === "string") message.GasLimit = parseInt(object.GasLimit, 10); - else if (typeof object.GasLimit === "number") message.GasLimit = object.GasLimit; + if ($util.Long) + (message.GasLimit = $util.Long.fromValue(object.GasLimit)).unsigned = true; + else if (typeof object.GasLimit === "string") + message.GasLimit = parseInt(object.GasLimit, 10); + else if (typeof object.GasLimit === "number") + message.GasLimit = object.GasLimit; else if (typeof object.GasLimit === "object") - message.GasLimit = new $util.LongBits( - object.GasLimit.low >>> 0, - object.GasLimit.high >>> 0, - ).toNumber(true); + message.GasLimit = new $util.LongBits(object.GasLimit.low >>> 0, object.GasLimit.high >>> 0).toNumber(true); if (object.Data != null) if (typeof object.Data === "string") - $util.base64.decode( - object.Data, - (message.Data = $util.newBuffer($util.base64.length(object.Data))), - 0, - ); - else if (object.Data.length >= 0) message.Data = object.Data; + $util.base64.decode(object.Data, message.Data = $util.newBuffer($util.base64.length(object.Data)), 0); + else if (object.Data.length >= 0) + message.Data = object.Data; if (object.ChainID != null) if (typeof object.ChainID === "string") - $util.base64.decode( - object.ChainID, - (message.ChainID = $util.newBuffer($util.base64.length(object.ChainID))), - 0, - ); - else if (object.ChainID.length >= 0) message.ChainID = object.ChainID; - if (object.Version != null) message.Version = object.Version >>> 0; + $util.base64.decode(object.ChainID, message.ChainID = $util.newBuffer($util.base64.length(object.ChainID)), 0); + else if (object.ChainID.length >= 0) + message.ChainID = object.ChainID; + if (object.Version != null) + message.Version = object.Version >>> 0; if (object.Signature != null) if (typeof object.Signature === "string") - $util.base64.decode( - object.Signature, - (message.Signature = $util.newBuffer($util.base64.length(object.Signature))), - 0, - ); - else if (object.Signature.length >= 0) message.Signature = object.Signature; - if (object.Options != null) message.Options = object.Options >>> 0; + $util.base64.decode(object.Signature, message.Signature = $util.newBuffer($util.base64.length(object.Signature)), 0); + else if (object.Signature.length >= 0) + message.Signature = object.Signature; + if (object.Options != null) + message.Options = object.Options >>> 0; if (object.GuardianAddr != null) if (typeof object.GuardianAddr === "string") - $util.base64.decode( - object.GuardianAddr, - (message.GuardianAddr = $util.newBuffer($util.base64.length(object.GuardianAddr))), - 0, - ); - else if (object.GuardianAddr.length >= 0) message.GuardianAddr = object.GuardianAddr; + $util.base64.decode(object.GuardianAddr, message.GuardianAddr = $util.newBuffer($util.base64.length(object.GuardianAddr)), 0); + else if (object.GuardianAddr.length >= 0) + message.GuardianAddr = object.GuardianAddr; if (object.GuardianSignature != null) if (typeof object.GuardianSignature === "string") - $util.base64.decode( - object.GuardianSignature, - (message.GuardianSignature = $util.newBuffer( - $util.base64.length(object.GuardianSignature), - )), - 0, - ); - else if (object.GuardianSignature.length >= 0) message.GuardianSignature = object.GuardianSignature; + $util.base64.decode(object.GuardianSignature, message.GuardianSignature = $util.newBuffer($util.base64.length(object.GuardianSignature)), 0); + else if (object.GuardianSignature.length >= 0) + 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; + $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.RelayerSignature != null) if (typeof object.RelayerSignature === "string") - $util.base64.decode( - object.RelayerSignature, - (message.RelayerSignature = $util.newBuffer($util.base64.length(object.RelayerSignature))), - 0, - ); - else if (object.RelayerSignature.length >= 0) message.RelayerSignature = object.RelayerSignature; + $util.base64.decode(object.RelayerSignature, message.RelayerSignature = $util.newBuffer($util.base64.length(object.RelayerSignature)), 0); + else if (object.RelayerSignature.length >= 0) + message.RelayerSignature = object.RelayerSignature; return message; }; - + /** * Creates a plain object from a Transaction message. Also converts values to other types if specified. * @function toObject @@ -658,225 +566,158 @@ * @returns {Object.} Plain object */ Transaction.toObject = function toObject(message, options) { - if (!options) options = {}; + if (!options) + options = {}; var object = {}; if (options.defaults) { if ($util.Long) { var long = new $util.Long(0, 0, true); - object.Nonce = - options.longs === String - ? long.toString() - : options.longs === Number - ? long.toNumber() - : long; - } else object.Nonce = options.longs === String ? "0" : 0; - if (options.bytes === String) object.Value = ""; + object.Nonce = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.Nonce = options.longs === String ? "0" : 0; + if (options.bytes === String) + object.Value = ""; else { object.Value = []; - if (options.bytes !== Array) object.Value = $util.newBuffer(object.Value); + if (options.bytes !== Array) + object.Value = $util.newBuffer(object.Value); } - if (options.bytes === String) object.RcvAddr = ""; + if (options.bytes === String) + object.RcvAddr = ""; else { object.RcvAddr = []; - if (options.bytes !== Array) object.RcvAddr = $util.newBuffer(object.RcvAddr); + if (options.bytes !== Array) + object.RcvAddr = $util.newBuffer(object.RcvAddr); } - if (options.bytes === String) object.RcvUserName = ""; + if (options.bytes === String) + object.RcvUserName = ""; else { object.RcvUserName = []; - if (options.bytes !== Array) object.RcvUserName = $util.newBuffer(object.RcvUserName); + if (options.bytes !== Array) + object.RcvUserName = $util.newBuffer(object.RcvUserName); } - if (options.bytes === String) object.SndAddr = ""; + if (options.bytes === String) + object.SndAddr = ""; else { object.SndAddr = []; - if (options.bytes !== Array) object.SndAddr = $util.newBuffer(object.SndAddr); + if (options.bytes !== Array) + object.SndAddr = $util.newBuffer(object.SndAddr); } - if (options.bytes === String) object.SndUserName = ""; + if (options.bytes === String) + object.SndUserName = ""; else { object.SndUserName = []; - if (options.bytes !== Array) object.SndUserName = $util.newBuffer(object.SndUserName); + if (options.bytes !== Array) + object.SndUserName = $util.newBuffer(object.SndUserName); } if ($util.Long) { var long = new $util.Long(0, 0, true); - object.GasPrice = - options.longs === String - ? long.toString() - : options.longs === Number - ? long.toNumber() - : long; - } else object.GasPrice = options.longs === String ? "0" : 0; + object.GasPrice = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.GasPrice = options.longs === String ? "0" : 0; if ($util.Long) { var long = new $util.Long(0, 0, true); - object.GasLimit = - options.longs === String - ? long.toString() - : options.longs === Number - ? long.toNumber() - : long; - } else object.GasLimit = options.longs === String ? "0" : 0; - if (options.bytes === String) object.Data = ""; + object.GasLimit = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.GasLimit = options.longs === String ? "0" : 0; + if (options.bytes === String) + object.Data = ""; else { object.Data = []; - if (options.bytes !== Array) object.Data = $util.newBuffer(object.Data); + if (options.bytes !== Array) + object.Data = $util.newBuffer(object.Data); } - if (options.bytes === String) object.ChainID = ""; + if (options.bytes === String) + object.ChainID = ""; else { object.ChainID = []; - if (options.bytes !== Array) object.ChainID = $util.newBuffer(object.ChainID); + if (options.bytes !== Array) + object.ChainID = $util.newBuffer(object.ChainID); } object.Version = 0; - if (options.bytes === String) object.Signature = ""; + if (options.bytes === String) + object.Signature = ""; else { object.Signature = []; - if (options.bytes !== Array) object.Signature = $util.newBuffer(object.Signature); + if (options.bytes !== Array) + object.Signature = $util.newBuffer(object.Signature); } object.Options = 0; - if (options.bytes === String) object.GuardianAddr = ""; + if (options.bytes === String) + object.GuardianAddr = ""; else { object.GuardianAddr = []; - if (options.bytes !== Array) object.GuardianAddr = $util.newBuffer(object.GuardianAddr); + if (options.bytes !== Array) + object.GuardianAddr = $util.newBuffer(object.GuardianAddr); } - if (options.bytes === String) object.GuardianSignature = ""; + if (options.bytes === String) + object.GuardianSignature = ""; else { object.GuardianSignature = []; if (options.bytes !== Array) object.GuardianSignature = $util.newBuffer(object.GuardianSignature); } - if (options.bytes === String) object.Relayer = ""; + if (options.bytes === String) + object.Relayer = ""; else { object.Relayer = []; - if (options.bytes !== Array) object.Relayer = $util.newBuffer(object.Relayer); + if (options.bytes !== Array) + object.Relayer = $util.newBuffer(object.Relayer); } - if (options.bytes === String) object.RelayerSignature = ""; + if (options.bytes === String) + object.RelayerSignature = ""; else { object.RelayerSignature = []; - if (options.bytes !== Array) object.RelayerSignature = $util.newBuffer(object.RelayerSignature); + if (options.bytes !== Array) + object.RelayerSignature = $util.newBuffer(object.RelayerSignature); } } if (message.Nonce != null && message.hasOwnProperty("Nonce")) if (typeof message.Nonce === "number") object.Nonce = options.longs === String ? String(message.Nonce) : message.Nonce; else - object.Nonce = - options.longs === String - ? $util.Long.prototype.toString.call(message.Nonce) - : options.longs === Number - ? new $util.LongBits(message.Nonce.low >>> 0, message.Nonce.high >>> 0).toNumber(true) - : message.Nonce; + object.Nonce = options.longs === String ? $util.Long.prototype.toString.call(message.Nonce) : options.longs === Number ? new $util.LongBits(message.Nonce.low >>> 0, message.Nonce.high >>> 0).toNumber(true) : message.Nonce; if (message.Value != null && message.hasOwnProperty("Value")) - object.Value = - options.bytes === String - ? $util.base64.encode(message.Value, 0, message.Value.length) - : options.bytes === Array - ? Array.prototype.slice.call(message.Value) - : message.Value; + object.Value = options.bytes === String ? $util.base64.encode(message.Value, 0, message.Value.length) : options.bytes === Array ? Array.prototype.slice.call(message.Value) : message.Value; if (message.RcvAddr != null && message.hasOwnProperty("RcvAddr")) - object.RcvAddr = - options.bytes === String - ? $util.base64.encode(message.RcvAddr, 0, message.RcvAddr.length) - : options.bytes === Array - ? Array.prototype.slice.call(message.RcvAddr) - : message.RcvAddr; + object.RcvAddr = options.bytes === String ? $util.base64.encode(message.RcvAddr, 0, message.RcvAddr.length) : options.bytes === Array ? Array.prototype.slice.call(message.RcvAddr) : message.RcvAddr; if (message.RcvUserName != null && message.hasOwnProperty("RcvUserName")) - object.RcvUserName = - options.bytes === String - ? $util.base64.encode(message.RcvUserName, 0, message.RcvUserName.length) - : options.bytes === Array - ? Array.prototype.slice.call(message.RcvUserName) - : message.RcvUserName; + object.RcvUserName = options.bytes === String ? $util.base64.encode(message.RcvUserName, 0, message.RcvUserName.length) : options.bytes === Array ? Array.prototype.slice.call(message.RcvUserName) : message.RcvUserName; if (message.SndAddr != null && message.hasOwnProperty("SndAddr")) - object.SndAddr = - options.bytes === String - ? $util.base64.encode(message.SndAddr, 0, message.SndAddr.length) - : options.bytes === Array - ? Array.prototype.slice.call(message.SndAddr) - : message.SndAddr; + object.SndAddr = options.bytes === String ? $util.base64.encode(message.SndAddr, 0, message.SndAddr.length) : options.bytes === Array ? Array.prototype.slice.call(message.SndAddr) : message.SndAddr; if (message.SndUserName != null && message.hasOwnProperty("SndUserName")) - object.SndUserName = - options.bytes === String - ? $util.base64.encode(message.SndUserName, 0, message.SndUserName.length) - : options.bytes === Array - ? Array.prototype.slice.call(message.SndUserName) - : message.SndUserName; + object.SndUserName = options.bytes === String ? $util.base64.encode(message.SndUserName, 0, message.SndUserName.length) : options.bytes === Array ? Array.prototype.slice.call(message.SndUserName) : message.SndUserName; if (message.GasPrice != null && message.hasOwnProperty("GasPrice")) if (typeof message.GasPrice === "number") object.GasPrice = options.longs === String ? String(message.GasPrice) : message.GasPrice; else - object.GasPrice = - options.longs === String - ? $util.Long.prototype.toString.call(message.GasPrice) - : options.longs === Number - ? new $util.LongBits( - message.GasPrice.low >>> 0, - message.GasPrice.high >>> 0, - ).toNumber(true) - : message.GasPrice; + object.GasPrice = options.longs === String ? $util.Long.prototype.toString.call(message.GasPrice) : options.longs === Number ? new $util.LongBits(message.GasPrice.low >>> 0, message.GasPrice.high >>> 0).toNumber(true) : message.GasPrice; if (message.GasLimit != null && message.hasOwnProperty("GasLimit")) if (typeof message.GasLimit === "number") object.GasLimit = options.longs === String ? String(message.GasLimit) : message.GasLimit; else - object.GasLimit = - options.longs === String - ? $util.Long.prototype.toString.call(message.GasLimit) - : options.longs === Number - ? new $util.LongBits( - message.GasLimit.low >>> 0, - message.GasLimit.high >>> 0, - ).toNumber(true) - : message.GasLimit; + object.GasLimit = options.longs === String ? $util.Long.prototype.toString.call(message.GasLimit) : options.longs === Number ? new $util.LongBits(message.GasLimit.low >>> 0, message.GasLimit.high >>> 0).toNumber(true) : message.GasLimit; if (message.Data != null && message.hasOwnProperty("Data")) - object.Data = - options.bytes === String - ? $util.base64.encode(message.Data, 0, message.Data.length) - : options.bytes === Array - ? Array.prototype.slice.call(message.Data) - : message.Data; + object.Data = options.bytes === String ? $util.base64.encode(message.Data, 0, message.Data.length) : options.bytes === Array ? Array.prototype.slice.call(message.Data) : message.Data; if (message.ChainID != null && message.hasOwnProperty("ChainID")) - object.ChainID = - options.bytes === String - ? $util.base64.encode(message.ChainID, 0, message.ChainID.length) - : options.bytes === Array - ? Array.prototype.slice.call(message.ChainID) - : message.ChainID; - if (message.Version != null && message.hasOwnProperty("Version")) object.Version = message.Version; + object.ChainID = options.bytes === String ? $util.base64.encode(message.ChainID, 0, message.ChainID.length) : options.bytes === Array ? Array.prototype.slice.call(message.ChainID) : message.ChainID; + if (message.Version != null && message.hasOwnProperty("Version")) + object.Version = message.Version; if (message.Signature != null && message.hasOwnProperty("Signature")) - object.Signature = - options.bytes === String - ? $util.base64.encode(message.Signature, 0, message.Signature.length) - : options.bytes === Array - ? Array.prototype.slice.call(message.Signature) - : message.Signature; - if (message.Options != null && message.hasOwnProperty("Options")) object.Options = message.Options; + object.Signature = options.bytes === String ? $util.base64.encode(message.Signature, 0, message.Signature.length) : options.bytes === Array ? Array.prototype.slice.call(message.Signature) : message.Signature; + if (message.Options != null && message.hasOwnProperty("Options")) + object.Options = message.Options; if (message.GuardianAddr != null && message.hasOwnProperty("GuardianAddr")) - object.GuardianAddr = - options.bytes === String - ? $util.base64.encode(message.GuardianAddr, 0, message.GuardianAddr.length) - : options.bytes === Array - ? Array.prototype.slice.call(message.GuardianAddr) - : message.GuardianAddr; + object.GuardianAddr = options.bytes === String ? $util.base64.encode(message.GuardianAddr, 0, message.GuardianAddr.length) : options.bytes === Array ? Array.prototype.slice.call(message.GuardianAddr) : message.GuardianAddr; if (message.GuardianSignature != null && message.hasOwnProperty("GuardianSignature")) - 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; + 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; + 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.RelayerSignature != null && message.hasOwnProperty("RelayerSignature")) - object.RelayerSignature = - options.bytes === String - ? $util.base64.encode(message.RelayerSignature, 0, message.RelayerSignature.length) - : options.bytes === Array - ? Array.prototype.slice.call(message.RelayerSignature) - : message.RelayerSignature; + object.RelayerSignature = options.bytes === String ? $util.base64.encode(message.RelayerSignature, 0, message.RelayerSignature.length) : options.bytes === Array ? Array.prototype.slice.call(message.RelayerSignature) : message.RelayerSignature; return object; }; - + /** * Converts this Transaction to JSON. * @function toJSON @@ -887,7 +728,7 @@ Transaction.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; - + /** * Gets the default type url for Transaction * @function getTypeUrl @@ -902,10 +743,10 @@ } return typeUrlPrefix + "/proto.Transaction"; }; - + return Transaction; })(); - + return proto; })(); From b810a2aef50a4bac48a475ca3fe715a756ac7b56 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 12 Dec 2024 12:43:11 +0200 Subject: [PATCH 4/6] Update Relayer not to be optional --- src/converters/transactionsConverter.ts | 2 +- src/interface.ts | 4 ++-- src/proto/serializer.ts | 8 ++++++-- src/transaction.spec.ts | 8 ++++---- src/transaction.ts | 7 ++++--- src/transactionComputer.ts | 10 +--------- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/converters/transactionsConverter.ts b/src/converters/transactionsConverter.ts index d97c2be05..c3798fbef 100644 --- a/src/converters/transactionsConverter.ts +++ b/src/converters/transactionsConverter.ts @@ -26,7 +26,7 @@ export class TransactionsConverter { chainID: transaction.chainID.valueOf(), version: transaction.version, options: transaction.options == 0 ? undefined : transaction.options, - relayer: !transaction.relayer || transaction.relayer.isEmpty() ? undefined : transaction.relayer.toBech32(), + relayer: transaction.relayer.isEmpty() ? undefined : transaction.relayer.toBech32(), guardian: transaction.guardian ? transaction.guardian : undefined, signature: this.toHexOrUndefined(transaction.signature), guardianSignature: this.toHexOrUndefined(transaction.guardianSignature), diff --git a/src/interface.ts b/src/interface.ts index dc7d3f234..f91d4b0af 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -105,8 +105,8 @@ export interface ITransaction { version: number; options: number; guardian: string; - relayer?: Address; + relayer: Address; signature: Uint8Array; guardianSignature: Uint8Array; - relayerSignature?: Uint8Array; + relayerSignature: Uint8Array; } diff --git a/src/proto/serializer.ts b/src/proto/serializer.ts index 8cb95a299..f1693c848 100644 --- a/src/proto/serializer.ts +++ b/src/proto/serializer.ts @@ -60,14 +60,18 @@ export class ProtoSerializer { protoTransaction.GuardianSignature = transaction.guardianSignature; } - if (transaction.relayer && !transaction.relayer.isEmpty()) { - protoTransaction.Relayer = transaction.relayer.getPublicKey(); + if (this.isRelayedTransaction(transaction)) { + protoTransaction.Relayer = transaction.relayer?.getPublicKey(); protoTransaction.RelayerSignature = transaction.relayerSignature; } return protoTransaction; } + private isRelayedTransaction(transaction: ITransaction) { + return !transaction.relayer.isEmpty(); + } + /** * Custom serialization, compatible with mx-chain-go. */ diff --git a/src/transaction.spec.ts b/src/transaction.spec.ts index 7e4eefffd..dfce314ea 100644 --- a/src/transaction.spec.ts +++ b/src/transaction.spec.ts @@ -755,8 +755,8 @@ describe("test transaction", async () => { it("should serialize transaction with relayer", async () => { const transaction = new Transaction({ chainID: networkConfig.ChainID, - sender: wallets.alice.address.bech32(), - receiver: wallets.alice.address.bech32(), + sender: wallets.alice.address.toBech32(), + receiver: wallets.alice.address.toBech32(), relayer: wallets.bob.address, gasLimit: 50000n, value: 0n, @@ -776,8 +776,8 @@ describe("test transaction", async () => { it("should test relayed v3", async () => { const transaction = new Transaction({ chainID: networkConfig.ChainID, - sender: wallets.alice.address.bech32(), - receiver: wallets.alice.address.bech32(), + sender: wallets.alice.address.toBech32(), + receiver: wallets.alice.address.toBech32(), senderUsername: "alice", receiverUsername: "bob", gasLimit: 80000n, diff --git a/src/transaction.ts b/src/transaction.ts index 9bf6cdd29..5b0b7a962 100644 --- a/src/transaction.ts +++ b/src/transaction.ts @@ -92,9 +92,10 @@ export class Transaction { public guardian: string; /** - * The relayer, in address format, next version all the other addresses will not be string anymore. + * The relayer address. + * Note: in the next major version, `sender`, `receiver` and `guardian` will also have the type `Address`, instead of `string`. */ - public relayer?: Address; + public relayer: Address; /** * The signature. @@ -148,7 +149,7 @@ export class Transaction { this.version = Number(options.version?.valueOf() || TRANSACTION_VERSION_DEFAULT); this.options = Number(options.options?.valueOf() || TRANSACTION_OPTIONS_DEFAULT); this.guardian = options.guardian ? this.addressAsBech32(options.guardian) : ""; - this.relayer = options.relayer?.isEmpty() ? undefined : options.relayer; + this.relayer = options.relayer ? options.relayer : Address.empty(); this.signature = options.signature || Buffer.from([]); this.guardianSignature = options.guardianSignature || Buffer.from([]); diff --git a/src/transactionComputer.ts b/src/transactionComputer.ts index 7e4370568..a9690b2fa 100644 --- a/src/transactionComputer.ts +++ b/src/transactionComputer.ts @@ -1,5 +1,4 @@ import BigNumber from "bignumber.js"; -import { Address } from "./address"; import { MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS, TRANSACTION_OPTIONS_TX_GUARDED, @@ -95,15 +94,8 @@ export class TransactionComputer { transaction.guardian = guardian; } - applyRelayer(transaction: ITransaction, relayer: Address) { - transaction.relayer = relayer; - } - isRelayedV3Transaction(transaction: ITransaction) { - if (transaction.relayer && !transaction.relayer.isEmpty()) { - return true; - } - return false; + return !transaction.relayer.isEmpty(); } applyOptionsForHashSigning(transaction: ITransaction) { From d1327067e989506cb2915b240c95e3e6cd362af8 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 12 Dec 2024 12:45:17 +0200 Subject: [PATCH 5/6] FIx typo --- src/transaction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transaction.ts b/src/transaction.ts index 5b0b7a962..04aaa92f4 100644 --- a/src/transaction.ts +++ b/src/transaction.ts @@ -108,7 +108,7 @@ export class Transaction { public guardianSignature: Uint8Array; /** - * The signature of the guardian. + * The signature of the relayer. */ public relayerSignature: Uint8Array; From 684e44d388aa4a0b74c761f5116c8d4934c4994b Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 12 Dec 2024 12:49:37 +0200 Subject: [PATCH 6/6] Fix compile errors --- src/networkProviders/providers.dev.net.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/networkProviders/providers.dev.net.spec.ts b/src/networkProviders/providers.dev.net.spec.ts index d08e5b4f7..e8a4804ab 100644 --- a/src/networkProviders/providers.dev.net.spec.ts +++ b/src/networkProviders/providers.dev.net.spec.ts @@ -452,6 +452,8 @@ describe("test network providers on devnet: Proxy and API", function () { guardian: "", guardianSignature: new Uint8Array(), options: 0, + relayer: Address.empty(), + relayerSignature: new Uint8Array(), }; const apiLegacyTxHash = await apiProvider.sendTransaction(transaction);