UNPKG

airgap-coin-lib

Version:

The airgap-coin-lib is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.

85 lines 3.17 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var validate_1 = require("../../dependencies/src/validate.js-0.13.1/validate"); var transactions_validator_1 = require("../validators/transactions.validator"); var validators_1 = require("../validators/validators"); var unsignedTransactionConstraints = { nonce: { presence: { allowEmpty: false }, type: 'String', isHexStringWithPrefix: true }, gasPrice: { presence: { allowEmpty: false }, type: 'String', isHexStringWithPrefix: true }, gasLimit: { presence: { allowEmpty: false }, type: 'String', isHexStringWithPrefix: true }, to: { presence: { allowEmpty: false }, type: 'String', isHexStringWithPrefix: true, format: { pattern: '^0x[a-fA-F0-9]{40}$', flags: 'i', message: 'is not a valid ethereum address' } }, value: { presence: { allowEmpty: false }, type: 'String', isHexStringWithPrefix: true }, chainId: { presence: { allowEmpty: false }, numericality: { noStrings: true, onlyInteger: true, greaterThanOrEqualTo: 0 } }, data: { presence: { allowEmpty: false }, type: 'String', isHexStringWithPrefix: true } }; var signedTransactionConstraints = { transaction: { presence: { allowEmpty: false }, type: 'String', isValidEthereumTransactionString: true } }; var success = function () { return undefined; }; var error = function (errors) { return errors; }; var EthereumTransactionValidator = /** @class */ (function (_super) { __extends(EthereumTransactionValidator, _super); function EthereumTransactionValidator() { return _super !== null && _super.apply(this, arguments) || this; } EthereumTransactionValidator.prototype.validateUnsignedTransaction = function (unsignedTx) { var rawTx = unsignedTx.transaction; validators_1.validateSyncScheme({}); return validate_1.async(rawTx, unsignedTransactionConstraints).then(success, error); }; EthereumTransactionValidator.prototype.validateSignedTransaction = function (signedTx) { return validate_1.async(signedTx, signedTransactionConstraints).then(success, error); }; return EthereumTransactionValidator; }(transactions_validator_1.TransactionValidator)); exports.EthereumTransactionValidator = EthereumTransactionValidator; //# sourceMappingURL=ethereum-transactions.validator.js.map