UNPKG

mazzaroth-js

Version:

Library that facilitates interaction with Mazzaroth nodes from both the browser and node-js

68 lines (53 loc) 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _mazzarothXdr = require("mazzaroth-xdr"); var types = _interopRequireWildcard(_mazzarothXdr); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } class CallBuilder { Call(crypto, sender, channel, nonce, blockExpirationNumber) { this._crypto = crypto; this._sender = sender; this._channel = channel; this._nonce = nonce; this._blockExpirationNumber = blockExpirationNumber; this._functionName = ''; // default function this._arguments = []; // default args return this; } Function(name) { this._functionName = name; return this; } Arguments(args) { this._arguments = args; return this; } Sign(privateKey) { let data = { channelID: this._channel, nonce: this._nonce, blockExpirationNumber: this._blockExpirationNumber, category: { type: 1, data: { function: this._functionName, arguments: this._arguments } } }; let xdrData = types.Data(); xdrData.fromJSON(data); const signer = this._crypto.NewEd25519Signer(privateKey); const signature = signer.Sign(xdrData.toXDR('hex')); let transaction = { sender: this._sender, signature: signature, data: data }; return transaction; } } exports.default = CallBuilder;