npm.io
1.0.7 • Published 4 years ago

quorum-sdk-electron-renderer

Licence
ISC
Version
1.0.7
Deps
4
Size
308 kB
Vulns
0
Weekly
0

Quorum-sdk-electron-renderer

Quorum-sdk includes two npm packages:

  1. Quorum-sdk-electron-renderer
  2. Quorum-sdk-electron-main

Quorum-sdk-electron-renderer is the package for your Electron renderer process to interact with Quorum.

Install

$ yarn add quorum-sdk-electron-renderer

QuorumClient

** Note: Make sure you have installed and setup Quorum-sdk-electron-main in Electron main process. **

import QuorumSDK from 'quorum-sdk-electron-renderer';

(async () => {
  const QuorumClient = new QuorumSDK();

  await QuorumClient.up();

  console.log('Quorum client started !');
})();

Node

fetch node status
const status = await QuorumClient.Node.status();
console.log(status);
fetch node info
const info = await QuorumClient.Node.info();
console.log(info);
fetch node network
const network = await QuorumClient.Node.network();
console.log(network);

Group

create group
const group = await QuorumClient.Group.create({
  group_name: 'test',
  consensus_type: 'poa',
  encryption_type: 'public',
  app_key: 'group_note',
});
console.log(group);
list groups
const groups = await QuorumClient.Group.list() || [];
console.log(groups);
leave group
await QuorumClient.Group.leave(group.group_id);

Object

create object
const objectId = '1';
const object = await QuorumClient.Object.put(group.user_pubkey, {
  type: 'Add',
  object: {
    id: objectId,
    type: 'Note',
    content: 'test',
  },
  target: {
    id: group.group_id,
    type: 'Group',
  },
});
console.log(object);
get object
await QuorumClient.Object.get(object.Content.id);
get object by TrxId
await QuorumClient.Object.getByTrxId(object.TrxId);
update object
const updatedObject = await QuorumClient.Object.put(group.user_pubkey, {
  type: 'Add',
  object: {
    id: object.Content.id, // pass the object id that you want to update
    type: 'Note',
    content: 'test',
  },
  target: {
    id: group.group_id,
    type: 'Group',
  },
});
console.log(updatedObject);
delete object
await QuorumClient.Object.delete(group.group_id, object.Content.id);
list objects
const objects = await QuorumClient.Object.list();
console.log(objects);

Auth

For more detail, you can check Quorum auth protocol explained

get following rule
const followingRule = await QuorumClient.Auth.getFollowingRule(groupId, 'POST');
console.log(followingRule);
update following rule
await QuorumClient.Auth.updateFollowingRule({
  group_id: groupId,
  type: 'set_trx_auth_mode',
  config: {
    trx_type: 'POST',
    trx_auth_mode: 'FOLLOW_DNY_LIST',
    memo: '',
  },
});
add a publisher to allow list
await QuorumClient.Auth.updateAuthList({
  group_id: groupId,
  type: 'upd_alw_list',
  config: {
    action: 'add',
    pubkey: publisher,
    trx_type: ['POST'],
    memo: '',
  },
});
remove a publisher from allow list
await QuorumClient.Auth.updateAuthList({
  group_id: groupId,
  type: 'upd_alw_list',
  config: {
    action: 'remove',
    pubkey: publisher,
    trx_type: ['POST'],
    memo: '',
  },
});
add a publisher to deny list
await QuorumClient.Auth.updateAuthList({
  group_id: groupId,
  type: 'upd_dny_list',
  config: {
    action: 'add',
    pubkey: publisher,
    trx_type: ['POST'],
    memo: '',
  },
})
remove a publisher from deny list
await QuorumClient.Auth.updateAuthList({
  group_id: groupId,
  type: 'upd_dny_list',
  config: {
    action: 'remove',
    pubkey: publisher,
    trx_type: ['POST'],
    memo: '',
  },
});
get allow list
const allowList = await QuorumClient.Auth.getAllowList(groupId);
console.log(allowList);
get deny list
const denyList = await QuorumClient.Auth.getDenyList(groupId);
console.log(denyList);

Run testing script

import { QuorumClientTest } from 'quorum-sdk-electron-renderer';

QuorumClientTest.start();

// open devTool console and check out testing process and logs.

Full testing file: test.ts