"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const network_1 = require("../network");
const proto_1 = require("./proto");
/**
 * RPC to talk with the personhood service. This is only a partial implementation of the
 * personhood service to enable email signups.
 */
class PersonhoodRPC {
    constructor(node) {
        this.timeout = 10 * 1000;
        this.conn = new network_1.WebSocketConnection(node.getWebSocketAddress(), PersonhoodRPC.serviceName);
    }
    /**
     * Set a new timeout value for the next requests
     * @param value Timeout in ms
     */
    setTimeout(value) {
        this.timeout = value;
    }
    /**
     * Signs up the new user with the given email and alias. If the new user doesn't exist yet, it will be created,
     * and an email with signup instructions is sent to the given address.
     * Additionally, the id of the user will be added to the configured DARC.
     * @param email of the new user
     * @param alias of the new user
     */
    signup(email, alias) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            return this.conn.send(new proto_1.EmailSignup({ email, alias }), proto_1.EmailSignupReply);
        });
    }
    /**
     * Sends the given email for recovery to the service. The service searches for a user with the given email, but
     * only in all created users with 'signup'. If exactly one match is found, a recovery device is created, and the
     * instructions to recover that device are sent to the email given.
     * @param email of an existing user.
     */
    recover(email) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            return this.conn.send(new proto_1.EmailRecover({ email }), proto_1.EmailRecoverReply);
        });
    }
}
exports.default = PersonhoodRPC;
PersonhoodRPC.serviceName = "Personhood";
