GithubHelp home page GithubHelp logo

torch3333 / scalardl-web-client-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scalar-labs/scalardl-web-client-sdk

0.0 1.0 0.0 1.02 MB

License: Other

Makefile 0.11% HTML 7.63% JavaScript 90.84% Java 1.43%

scalardl-web-client-sdk's Introduction

Scalar DL Web Client SDK

This is a library for web applications by which the applications can interact with a Scalar DL network.

Install

We can use package manager to install this library. For example, to install with NPM:

NPM

npm install @scalar-labs/scalardl-web-client-sdk

You can also find a bundle scalardl-web-client-sdk.bundle.js which can be imported statically in @scalar-labs/scalardl-web-client-sdk/dist.

HOWTO

Create ClientService instance

ClientService class is the main class of this package. It provides following functions to request Scalar DL network.

Name use
registerCertificate To register a client's certificate to a Scalar DL network
registerContract To register the contracts to the registered client of the Scalar DL network
listContracts To list all registered contracts of the client
executeContract To execute a registered contract of the client
validateLedger To validate an asset of the Scalar DL network to determine if it is tampered

Use the code snippet below to create a ClientService instance.

import { ClientService } from '@scalar-labs/scalardl-web-client-sdk';
const clientService = new ClientService(clientProperties);

Or, if you use the static release, try following

<head>
    <meta charset="utf-8">
    <script src="scalardl-web-client-sdk.bundle.js"></script>
</head>

<script>
    const clientService = new Scalar.ClientService(clientProperties);
</script>

The clientProperties argument is mandatory for the constructor. This is a properties example that a user [email protected] would use to try to connect to the server scalardl.example.com:50051 of the Scalar DL network.

{
    'scalar.ledger.client.server_host': 'scalardl.example.com',
    'scalar.ledger.client.server_port': 50051,
    'scalar.ledger.client.server_privileged_port': 50052,
    'scalar.ledger.client.cert_holder_id': '[email protected]',
    'scalar.ledger.client.private_key_pem': "-----BEGIN EC PRIVATE KEY-----\nMHc...",
    'scalar.ledger.client.cert_pem': "-----BEGIN CERTIFICATE-----\nMIICjTCCAj...n",
    'scalar.ledger.client.cert_version': 1,
    'scalar.ledger.client.tls.enabled': false,
}

In what follows assume that we have a clientService instance.

Register the certificate

Use the registerCertificate function to register a certificate on the Scalar DL network.

const response = await clientService.registerCertificate();
const status = response.getStatus();
const message = response.getMessage();

Please refer to the Status code section below for the details of status.

Register contracts

Use the registerContract function to register a contract.

const response = await clientService.registerContract('contractId', 'com.example.contract.contractName', contractUint8Array, propertiesObject);
const status = response.getStatus();
const message = response.getMessage();

List registered contracts

Use listContracts function to list all registered contracts.

const response = await clientService.listContracts();
const message = response.getMessage();
const contracts = JSON.parse(message);

Execute a contract

Use executeContract function to execute a registered contract.

const response = await clientService.executeContract('contractId', argumentObject);
const status = response.getStatus();
const result = JSON.parse(response.getResult());

Validate an asset

Use the validateLedger function to validate an asset in the Scalar DL network.

const response = await clientService.validateLedger('assetId');
const status = response.getStatus();
const message = response.getMessage();

Status code

Enumeration StatusCode enumerates all the possible status of a Scalar DL response.

StatusCode = {
  OK: 200,
  INVALID_HASH: 300,
  INVALID_PREV_HASH: 301,
  INVALID_CONTRACT: 302,
  INVALID_OUTPUT: 303,
  INVALID_NONCE: 304,
  INCONSISTENT_STATES: 305,
  INVALID_SIGNATURE: 400,
  UNLOADABLE_KEY: 401,
  UNLOADABLE_CONTRACT: 402,
  CERTIFICATE_NOT_FOUND: 403,
  CONTRACT_NOT_FOUND: 404,
  CERTIFICATE_ALREADY_REGISTERED: 405,
  CONTRACT_ALREADY_REGISTERED: 406,
  INVALID_REQUEST: 407,
  CONTRACT_CONTEXTUAL_ERROR: 408,
  ASSET_NOT_FOUND: 409,
  DATABASE_ERROR: 500,
  UNKNOWN_TRANSACTION_STATUS: 501,
  RUNTIME_ERROR: 502,
  CLIENT_IO_ERROR: 600,
  CLIENT_DATABASE_ERROR: 601,
  CLIENT_RUNTIME_ERROR: 602,
};

Contributing

This library is mainly maintained by the Scalar Engineering Team, but of course we appreciate any help.

  • For asking questions, finding answers and helping other users, please go to scalardl-user.
  • For filing bugs, suggesting improvements, or requesting new features, help us out by opening an issue.

License

Scalar DL client SDK is dual-licensed under both the AGPL (found in the LICENSE file in the root directory) and a commercial license. You may select, at your option, one of the above-listed licenses. Regarding the commercial license, please contact us for more information.

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.