UNPKG

@ethersphere/swarm-cli

Version:
139 lines (138 loc) 5.08 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Send = void 0; const bee_js_1 = require("@ethersphere/bee-js"); const fs_1 = require("fs"); const furious_commander_1 = require("furious-commander"); const process_1 = require("process"); const stamp_1 = require("../../service/stamp"); const utils_1 = require("../../utils"); const option_1 = require("../../utils/option"); const pss_command_1 = require("./pss-command"); class Send extends pss_command_1.PssCommand { constructor() { super(...arguments); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'send' }); Object.defineProperty(this, "description", { enumerable: true, configurable: true, writable: true, value: 'Send a message to a target Bee node with Postage Service for Swarm' }); Object.defineProperty(this, "stamp", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "target", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "message", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "path", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "recipient", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "sendable", { enumerable: true, configurable: true, writable: true, value: void 0 }); } async run() { await super.init(); if (this.path) { if (!(0, utils_1.fileExists)(this.path)) { this.console.error('There is no file at the specified path'); (0, process_1.exit)(1); } this.sendable = (0, fs_1.readFileSync)(this.path); } else { this.sendable = this.message; } const length = (0, utils_1.getByteSize)(this.sendable); if (length > 4000) { this.console.error('Maximum payload size is 4000 bytes.'); this.console.error('You tried sending ' + length + ' bytes.'); (0, process_1.exit)(1); } if (!this.stamp) { this.stamp = await (0, stamp_1.pickStamp)(this.bee, this.console); } this.console.log('Sending PSS message on topic ' + this.topic); await this.bee.pssSend(this.stamp, new bee_js_1.Topic(this.topic), this.target, this.sendable, this.recipient); this.console.log('Message sent successfully.'); } } __decorate([ (0, furious_commander_1.Option)(option_1.stampProperties), __metadata("design:type", String) ], Send.prototype, "stamp", void 0); __decorate([ (0, furious_commander_1.Option)({ key: 'target', description: 'Overlay address prefix of the target Bee node', required: true, type: 'hex-string', }), __metadata("design:type", String) ], Send.prototype, "target", void 0); __decorate([ (0, furious_commander_1.Option)({ key: 'message', description: 'Text message to send', required: true, conflicts: 'path', }), __metadata("design:type", String) ], Send.prototype, "message", void 0); __decorate([ (0, furious_commander_1.Option)({ key: 'path', description: 'Send raw data from file', required: true, conflicts: 'message', autocompletePath: true, }), __metadata("design:type", String) ], Send.prototype, "path", void 0); __decorate([ (0, furious_commander_1.Option)({ key: 'recipient', description: 'PSS public key of the target Bee node for encryption', }), __metadata("design:type", String) ], Send.prototype, "recipient", void 0); exports.Send = Send;