2.1.0 • Published 12 months ago

iris-protocol v2.1.0

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
12 months ago

Iris Protocol

Welcome to the IrisProtocol, attempting to make P2P communication better thanks to HyperCore Protocol and more.

Install

npm i iris-protocol@latest

Example Server

const { password } = require("@inquirer/prompts");
const { User, Network, Constants } = require("..");
const figlet = require("figlet");
const gradient = require("gradient-string");

(async () => {
  console.log(gradient.passion(figlet.textSync("IrisProtocol")));

  const user = new User("connor-davis");

  if (!user.password) {
    let newPassword = await password({
      message: "What is the password for " + user.username + "?",
      theme: {
        prefix: "",
      },
      mask: "*",
    });

    user.setPassword(newPassword);

    user.save();
  }

  let confirmPassword = await password({
    message: "Confirm the password for " + user.username + "?",
    theme: {
      prefix: "",
    },
    mask: "*",
  });

  if (!user.verifyPassword(confirmPassword))
    return console.log("🔥 Failed to verify password.");

  console.log(" Welcome to IrisProtocol! ❤️");
  console.log(" Starting your users session");

  const session = user.session;

  const network = new Network(session.keyPair, user);

  network.events.subscribe((event) => {
    switch (event.type) {
      case Constants.LISTENING:
        console.log(
          "🚀 Session listening on public key: " +
            session.keyPair.publicKey.toString("hex")
        );

        break;
      default:
        break;
    }
  });

  await network.listen();
})();

Example Client

const { input, password } = require("@inquirer/prompts");
const { Network, User, Constants } = require("..");
const figlet = require("figlet");
const gradient = require("gradient-string");

(async () => {
  console.log(gradient.passion(figlet.textSync("IrisProtocol")));

  const user = new User("connor-test");

  if (!user.password) {
    let newPassword = await password({
      message: "What is the password for " + user.username + "?",
      theme: {
        prefix: "",
      },
      mask: "*",
    });

    user.setPassword(newPassword);

    user.save();
  }

  let confirmPassword = await password({
    message: "Confirm the password for " + user.username + "?",
    theme: {
      prefix: "",
    },
    mask: "*",
  });

  if (!user.verifyPassword(confirmPassword))
    return console.log("🔥 Failed to verify password.");

  console.log(" Welcome to IrisProtocol! ❤️");

  const publicKey = await input({
    message: "What is the sessions public key?",
  });

  console.log(" Joining session with public key: " + publicKey);

  const network = new Network();

  network.connect(publicKey);

  network.events.subscribe((event) => {
    switch (event.type) {
      case Constants.LISTENING:
        console.log(" Joined session with public key: " + publicKey);

        break;
      default:
        break;
    }
  });

  network.in.subscribe((packet) => {
    switch (packet.type) {
      case Constants.NETWORK_INFORMATION:
        const data = packet.data;

        user.saveSession(data.metadata.username, { publicKey });

        break;
      default:
        break;
    }
  });
})();
2.1.0

12 months ago

2.0.1

12 months ago

2.0.0

12 months ago

1.2.7

12 months ago

1.2.6

12 months ago

1.2.5

12 months ago

1.2.4

12 months ago

1.2.3

12 months ago

1.2.2

12 months ago

1.2.1

12 months ago

1.2.0

12 months ago

1.1.9

12 months ago

1.1.8

12 months ago

1.1.7

12 months ago

1.1.6

12 months ago

1.1.5

12 months ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago