1.2.8 • Published 5 months ago

@scobru/mogu v1.2.8

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

MOGU

inspired by this post

API Usage

Description: Mogu is a TypeScript-based system that integrates a local database with the InterPlanetary File System (IPFS) and Ethereum blockchain. It enables secure storage, management, and retrieval of encrypted data nodes, leveraging blockchain and IPFS for enhanced data integrity and decentralization.

Features

  • Encrypted local database management.
  • IPFS integration via PinataAPI for decentralized storage.
  • Ethereum blockchain interaction for Content Identifier (CID) management.
  • Flexible and customizable node queries.

Modules

  • db.ts: Logic for local database management.
  • api.ts: API endpoint definitions for database and IPFS interaction.
  • sdk.ts: Software Development Kit for interacting with the Mogu system.
  • pinataAPI.ts: Interface with the Pinata service for IPFS operations.
  • CIDRegistry.sol: Ethereum smart contract for managing CIDs.

Installation

Via NPM

npm install @scobru/mogu

Via GitHub

  1. Clone the repository:

    git clone https://github.com/scobru/mogu.git
  2. Install dependencies:

    npm install
  3. Start the server:

    npm start

Usage

Initializing Mogu

import { Mogu } from "@scobru/mogu";
const mogu = new Mogu("your-key", "pinataApiKey", "pinataApiSecret", "dbName");

Adding a Node

const newNode: EncryptedNode = {
  id: "0",
  type: "FILE",
  name: "my-file",
  parent: "",
  children: [],
  content: "Hello World!",
};

const newNode: EncryptedNode = {
  id: "0",
  type: "DIRECTORY",
  name: "my-directory",
  parent: "",
  children: [],
  content: "",
};

mogu.addNode(newNode);

Querying Nodes

// Query by name
const nodesByName = mogu.queryByName("nodeName");

// Query by type
const nodesByType = mogu.queryByType(NodeType.FILE);

Loading a Database

// Load from local storage
mogu.load("cid");

Saving a Database

// Save to local storage
mogu.store();

Blockchain Integration

import { MoguOnChain } from "@scobru/mogu";
const moguOnChain = new MoguOnChain("contractAddress", signer);

API Reference

  • Add Node: Send a POST request to /api/addNode with the node data in the request body. The node data should be an object that matches the EncryptedNode type.

  • Update Node: Send a POST request to /api/updateNode with the updated node data in the request body.

  • Remove Node: Send a POST request to /api/removeNode with the ID of the node to remove in the request body.

  • Save Database: Send a POST request to /api/save with the encryption key in the request body.

  • Save Database On Chain: Send a POST request to /api/saveOnChain with the encryption key and the contract address in the request body.

  • Load Database From Chain: Send a POST request to /api/loadOnChain with the contract address in the request body.

  • Load Database: Send a POST request to /api/load/:cid with the encryption key in the request body and the CID in the URL.

  • Serialize Database: Send a POST request to /api/serialize with the encryption key in the request body.

  • Query By Name: Send a POST request to /api/queryByName with the name to query in the request body.

  • Query By Type: Send a POST request to /api/queryByType with the type to query in the request body.

  • Query By Content: Send a POST request to /api/queryByContent with the content to query in the request body.

  • Query By Children: Send a POST request to /api/queryByChildren with the children to query in the request body.

  • Query By Parent: Send a POST request to /api/queryByParent with the parent to query in the request body.

  • Get All Nodes: Send a GET request to /api/getAllNodes to retrieve all nodes in the database.

  • Unpin CID: Send a POST request to /api/unPinCID/:cid to unpin a CID from IPFS.

Remember to replace :cid with the actual CID when making requests to /api/load/:cid and /api/unPinCID/:cid.

Contributing

  • Guidelines for contributing to the Mogu project.

License

  • Information about the project's licensing.
1.2.8

5 months ago

1.2.7

5 months ago

1.2.6

6 months ago

1.2.5

6 months ago

1.2.4

6 months ago

1.2.3

6 months ago

1.2.2

6 months ago

1.2.1

6 months ago

1.2.0

6 months ago

1.1.19

6 months ago

1.1.18

6 months ago

1.1.17

6 months ago

1.1.16

6 months ago

1.1.15

6 months ago

1.1.14

6 months ago

1.1.13

6 months ago

1.1.12

6 months ago

1.1.11

6 months ago

1.1.10

6 months ago

1.1.9

6 months ago

1.1.8

6 months ago

1.1.7

6 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.26

6 months ago

1.0.25

6 months ago

1.0.24

6 months ago

1.0.23

6 months ago

1.0.22

6 months ago

1.0.21

6 months ago

1.0.20

6 months ago

1.0.19

6 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago