UNPKG

2.82 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
8 };
9 return function (d, b) {
10 extendStatics(d, b);
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13 };
14})();
15Object.defineProperty(exports, "__esModule", { value: true });
16var ethereumjs_util_1 = require("ethereumjs-util");
17var buffer_1 = require("buffer");
18var transaction_1 = require("./transaction");
19/**
20 * Creates a new transaction object that doesn't need to be signed.
21 *
22 * @param data - A transaction can be initialized with its rlp representation, an array containing
23 * the value of its fields in order, or an object containing them by name.
24 *
25 * @param opts - The transaction's options, used to indicate the chain and hardfork the
26 * transactions belongs to.
27 *
28 * @see Transaction
29 */
30var FakeTransaction = /** @class */ (function (_super) {
31 __extends(FakeTransaction, _super);
32 function FakeTransaction(data, opts) {
33 if (data === void 0) { data = {}; }
34 if (opts === void 0) { opts = {}; }
35 var _this = _super.call(this, data, opts) || this;
36 Object.defineProperty(_this, 'from', {
37 enumerable: true,
38 configurable: true,
39 get: function () { return _this.getSenderAddress(); },
40 set: function (val) {
41 if (val) {
42 _this._from = ethereumjs_util_1.toBuffer(val);
43 }
44 },
45 });
46 var txData = data;
47 if (txData.from) {
48 _this.from = ethereumjs_util_1.toBuffer(txData.from);
49 }
50 return _this;
51 }
52 /**
53 * Computes a sha3-256 hash of the serialized tx, using the sender address to generate a fake
54 * signature.
55 *
56 * @param includeSignature - Whether or not to include the signature
57 */
58 FakeTransaction.prototype.hash = function (includeSignature) {
59 if (includeSignature === void 0) { includeSignature = true; }
60 if (includeSignature && this._from && this._from.toString('hex') !== '') {
61 // include a fake signature using the from address as a private key
62 var fakeKey = buffer_1.Buffer.concat([this._from, this._from.slice(0, 12)]);
63 this.sign(fakeKey);
64 }
65 return _super.prototype.hash.call(this, includeSignature);
66 };
67 return FakeTransaction;
68}(transaction_1.default));
69exports.default = FakeTransaction;
70//# sourceMappingURL=fake.js.map
\No newline at end of file