Giter Site home page Giter Site logo

-project's Introduction

CyberConnect

The JavaScript library provides CyberConnect class which includes functions to allows users to control their decentralized identity(DIDs) and social graph data. The library encapsulates the complex authentication logic (authenticate to Ceramic Network) into easy-to-use functions. CyberConnect API.

Getting started

Installation

npm install @cyberlab/cyberconnect
or
yarn add @cyberlab/cyberconnect

Basic usage

Init CyberConnect

import CyberConnect, {
  Env,
  Blockchain,
} from '@cyberlab/cyberconnect';

const cyberConnect = new CyberConnect({
  namespace: 'CyberConnect',
  env: Env.Production,
  chain: Blockchain.ETH,
  provider: provider,
  signingMessageEntity: 'CyberConnect' || your entity,
});
  • namespace - Your applciation name.
  • env - (optional) Env decides the endpoints. Now we have staging and production. (The default value is Env.Production).
  • chain - (optional) The blockchain you want to connect with. Now we support ethereum and solana. (The default is Blockchain.ETH).
  • provider - The corresponding provider of the given chain.
  • signingMessageEntity - (optional) Use to describe the entity users sign their message with. Users will see it when authorizing in the wallet I authorize ${signingMessageEntity} from this device using signing key:. The default entity is CyberConnect.

See Solana for Solana demo.

Authenticate

The authenticate() includes two signs for AuthProvider and Capi10Link.

All users should sign for AuthProvider every session.

Only first time users need to sign for Capi10Link and it may takes 5-10 seconds.

Only authenticate once if call cyberconnect.authenticate() multiple time.

You can run cyberconnect.authenticate() somewhere before doing connect to do the authentication first, then the user doesn't need to sign when calling connect.

You can also call connect directly, then the user have to sign during the function call.

await cyberConnect.authenticate();

Connect

cyberConnect.connect(targetAddr, alias, connectionType);
  • targetAddr - The target wallet address to connect.
  • alias - (optional) Alias for the target address.
  • connectionType - (optional) The type of the connection. The default value is Connection.FOLLOW. See Connection Type for more details.

Disconnect

cyberConnect.disconnect(targetAddr);
  • targetAddr - The target wallet address to disconnect.

BatchConnect

cyberConnect.batchConnect(targetAddrs, connectionType);
  • targetAddrs - A list of wallet addresses to connect.
  • connectionType - (optional) The type of the connection. The default value is Connection.FOLLOW. See Connection Type for more details.

SetAlias

cyberConnect.setAlias(targetAddr, alias);
  • targetAddr - The target wallet address to disconnect.
  • alias - The alias for the target address.

BidirectionalConnect

cyberConnect.bidirectionalConnect(targetAddr, biConnectionType);
  • targetAddr - The target wallet address to disconnect.
  • biConnectionType - The type of the bidirectional connection. See BiConnection Type for more details.

Learn more about bidirectional Connection here

AckNotifications

cyberConnect.ackNotifications(notificationIds);
  • notificationIds - A list of notificationId .

Learn more about notification here.

AckAllNotifications

cyberConnect.ackAllNotifications();

Learn more about notification here.

Connection Type

You can create different types of connections for different purposes.

E.g: You can like a NFT by creating a "LIKE" connection from you to the NFT.

import { ConnectionType } from '@cyberlab/cyberconnect';

cyberConnect.connect(targetAddr, alias, ConnectionType.LIKE);

Those types we support: FOLLOW, LIKE, REPORT, WATCH and VOTE

Note: Only one type connection can be created from one to another, which means you can't create both "FOLLOW" connection and "LIKE" connection from you to "Ryan".

BiConnection Type

You can create different types of bi-connections for different purposes (e.g. you can send a request by using INIT type or accept a request by using ACCEPT type).

import { BiConnectionType } from '@cyberlab/cyberconnect';

cyberConnect.bidirectionalConnect(targetAddr, BiConnectionType.INIT);

The types we support: INIT, ACCEPT, REJECT, TERMINATE, BLOCK and UNBLOCK.

Solana

You can get Solana provider from @solana/wallet-adapter-react

import { useWallet } from '@solana/wallet-adapter-react';
const solanaProvider = useWallet();

Note: chainRef is depreciated and will be removed in the future. You can pass empty string for chainRef for now.

import CyberConnect, {
  Env,
  Blockchain,
  Solana,
} from 'npm install @cyberlab/cyberconnect';

const cyberConnect = new CyberConnect({
  namespace: 'CyberConnect',
  env: Env.Production,
  chain: Blockchain.SOLANA,
  provider: solanaProvider,
  chainRef: '',
});

Contributing

We are happy to accept small and large contributions, feel free to make a suggestion or submit a pull request.

-project's People

Contributors

yang2045 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.