Skip to content

πŸ•³πŸ₯ŠπŸ˜€ An auto-slimming, shared user, invite-only, registration, login and recovery - profile database - self-writer network

License

Notifications You must be signed in to change notification settings

benzmuircroft/userbase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

52f5069 Β· Feb 17, 2025

History

65 Commits
Dec 25, 2023
Feb 17, 2025
Mar 4, 2024
Feb 13, 2025
Jan 1, 2024
Jan 1, 2024

Repository files navigation

πŸ•³πŸ₯Š userbase πŸ˜€

An auto-slimming, shared user, optional invite-only, registration, login and recovery - profile database - self-writer network

Installation

npm i "github:benzmuircroft/userbase"

Usage

;(async function() {

  const Keychain = (await import('keypear')).default; // https://github.com/holepunchto/keypear
  const b4a = require('b4a');
  
  const userbase = await require('userbase')({
    folderName: 'folderName',
    testFolder: 'user1' // only needed if testing multiple instances in the same script
  });

  // initiate root
  await userbase.register('root', 'root');

  const kpAlice = new Keychain({
    scalar: b4a.from('684e14316d8f379829ee5d1b883dffd2cf123f2987b8658353ae740ed8758565', 'hex'),
    publicKey: b4a.from('09f9cb2e6097bab4936696c7fb2e80c52ecc7e7a0dfe67274d93198e785c1558', 'hex')
  }).get();

  let user1 = {
    reffereeUserName: 'root',
    referralUserName: 'alice',
    referralpublicKey: kpAlice
  };

  let success = await userbase.register(user1.reffereeUserName, user1.referralUserName, user1.referralpublicKey);
  console.log(success); // bool (the reffereeUserName must first exist and the referralUserName must not exist);
  
  const kpBob = new Keychain({
    scalar: b4a.from('b0cf93c3f3589ea5e7a09b752e7b6492e6e331661da8fe88854d692aec59114f', 'hex'),
    publicKey: b4a.from('4cce6d17f4000b19b9f752fb7c185a56cff16d86f0cda8673e5ab6baed9e7171', 'hex')
  }).get();
  
  let user2 = {
    reffereeUserName: 'alice',
    referralUserName: 'bob',
    referralpublicKey: kpBob
  };
  
  let success = await userbase.register(user1.reffereeUserName, user1.referralUserName, user1.referralpublicKey);
  console.log(success); // bool (the reffereeUserName must first exist and the referralUserName must not exist);
  
  console.log(await userbase.lookup('alice')); // should return a publicKey
  
  // handle errors
  
  let success = await userbase.register('noneExitsUser', user1.referralUserName, user1.referralpublicKey); // false
  
  let success = await userbase.register(user1.reffereeUserName, 'bob', user1.referralpublicKey); // username bob already exists
  
  console.log(await userbase.lookup('noneExitsUser')); // null
  
})();

TODO

  • document switching user roles (it is ether this module or another that lets you write to cores with a role)

About

πŸ•³πŸ₯ŠπŸ˜€ An auto-slimming, shared user, invite-only, registration, login and recovery - profile database - self-writer network

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published