Code Monkey home page Code Monkey logo

cover-sdk's Introduction

โœ… Cover SDK

Cover SDK is JavaScript and TypeScript client library for integrating the Cover protocol into applications.

Cover's SDK makes it easy to:

  • Manage build configs
  • Submit new builds
  • Check a canister's verified status
  • Query data from the Cover canister

... And more!


Contents Table

Installation

  • Install from npm
npm i @psychedelic/cover

Import

  • For CommonJS
const {Cover} = require('@psychedelic/cover');
  • For JavaScript Modules
import {Cover} from '@psychedelic/cover';

API

  • Construct a new Cover object with your identity
const cover = new Cover(identity: SignIdentity);
  • Verify a canister
cover.verify(canisterId: Principal): Promise<boolean>;
  • Get wasm hash
// wasm hash in Cover verification
cover.getCoverHash(canisterId: Principal): Promise<string | undefined>;

// wasm hash on IC network
cover.getICHash(canisterId: Principal): Promise<string | undefined>;
  • Get Cover verification
// provide a pagination info to get all verifications
// PaginationInfo {
//   items_per_page has Min value = 10 & Max = 120
//   page_index is start from 1
// }
cover.getAllVerifications(paginationInfo: PaginationInfo): Promise<VerificationPagination>;

// get verification by canister id
cover.getVerificationByCanisterId(canisterId: Principal): Promise<Verification | undefined>;

// get verification statistics
cover.getVerificationStats(): Promise<Stats>;

cover.getMyVerificationStats(): Promise<Stats>;
  • APIs with pagination info parameter will return an object like this
interface Pagination {
  page_index: bigint;
  data: Array<T>;
  total_pages: bigint;
  total_items: bigint;
  is_first_page: boolean;
  items_per_page: bigint;
  is_last_page: boolean;
}
  • Interact with build configs of given identity (the identity passed in the Cover constructor)
// get all build configs
cover.getMyBuildConfigs(): Promise<Array<BuildConfig>>;

// get build config by canister id
cover.getMyBuildConfigById(canisterId: Principal): Promise<BuildConfig | undefined>;

// delete a build config
cover.deleteMyBuildConfig(canisterId: Principal): Promise<void>;
  • Get recent activities from Cover
// provide a pagination info to get activities
// PaginationInfo {
//   items_per_page has Min value = 10 & Max = 120
//   page_index is start from 1
// }
cover.getActivities(paginationInfo: PaginationInfo): Promise<ActivityPagination>;
cover.getMyActivities(paginationInfo: PaginationInfo): Promise<MyActivityPagination>;
  • Get Cover Metadata information
// from Cover's instance
cover.coverMetadata(canisterId: Principal): Promise<CoverMetadata>;

// without Cover's instance
Cover.anonymousCoverMetadata(canisterId: Principal): Promise<CoverMetadata>;
  • Interact with Cover Validator, more info about the validator and the parameters used below, see here
  • Cover SDK will get public key and signature from your identity and send to Cover Validator
// save a build config
cover.saveBuildConfig(buildConfigRequest: BuildConfigRequest): Promise<void>;

// build a config
cover.build(buildRequest: BuildRequest): Promise<void>;

// build a saved config
cover.buildWithConfig(buildWithConfigRequest: BuildWithConfigRequest): Promise<void>;

// save a build config without create a Cover instance
Cover.anonymousSaveBuildConfig(buildConfigRequest: AnonymousBuildConfigRequest, coverConfig?: CoverConfig): Promise<void>;

// build a config without create a Cover instance
Cover.anonymousBuild(buildRequest: AnonymousBuildRequest, coverConfig?: CoverConfig): Promise<void>;

// build a saved config without create a Cover instance
Cover.anonymousBuildWithConfig(buildWithConfigRequest: AnonymousBuildWithConfigRequest, coverConfig?: CoverConfig): Promise<void>;

// build with metadata
Cover.buildWithCoverMetadata(coverMetadataRequest: CoverMetadataRequest, coverConfig?: CoverConfig): Promise<void>;
  • Get public key and sign a signature with your identity and current timestamp
// get public key
getPublicKey: (identity: SignIdentity) => string;

// sign a signature, return a hex string
sign: (identity: SignIdentity, timestamp: number) => Promise<string>;
  • Error code with Validator's APIs above
// error codes from the validator side(wrong format, missing arguments, internal error,...)
ERR_XXX;

// error codes from the sdk side(can't connect to the Validator, ...)
SDK_ERR_XXX;

// the error object will include these fields
{
  code: string;
  message: string;
  details: unknown;
}

Typescript Example

Example extract identity from PEM using SDK

import {Cover, getPublicKey, sign} from '@psychedelic/cover';
import {Ed25519KeyIdentity} from '@dfinity/identity';
import {Principal} from '@dfinity/principal';
import {SignIdentity} from '@dfinity/agent';

// create new identity
const identity = Ed25519KeyIdentity.generate() as SignIdentity;

const cover = new Cover(identity);

// verify a canister
const isVerified = await cover.verify(Principal.fromText('iftvq-niaaa-aaaai-qasga-cai'));

// get wasm hash from IC network
const icHash = await cover.getICHash(Principal.fromText('iftvq-niaaa-aaaai-qasga-cai'));

// get wasm hash from Cover verification
const coverHash = await cover.getCoverHash(Principal.fromText('iftvq-niaaa-aaaai-qasga-cai'));

// get Cover verification by canister ID
const verification = await cover.getVerificationByCanisterId(Principal.fromText('iftvq-niaaa-aaaai-qasga-cai'));

// get public key
const publicKey = getPublicKey(identity);

// sign a signature
const timestamp = new Date().getTime();
const signature = await sign(identity, timestamp);

cover-sdk's People

Contributors

michaelmoriarty67 avatar nicolaspoggi avatar scott-dn avatar tnht95 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cover-sdk's Issues

Type mismatch error when getting verification

Hi, I'm trying to fetch verification info.

const verification = await cover.getVerificationByCanisterId(Principal.fromText("lj532-6iaaa-aaaah-qcc7a-cai"));

But this fails with :

Uncaught Error: type mismatch: type on the wire rec_23, expect type text
    at TextClass.checkType (/node_modules/@dfinity/candid/lib/cjs/idl.js:152:19)
    at TextClass.decodeValue (/node_modules/@dfinity/candid/lib/cjs/idl.js:371:14)
    at RecordClass.decodeValue (/node_modules/@dfinity/candid/lib/cjs/idl.js:839:39)
    at OptClass.decodeValue (/node_modules/@dfinity/candid/lib/cjs/idl.js:743:36)

SDK version is 0.0.17.

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.