npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@psychedelic/cover

v0.0.36

Published

Cover Software Development Kit

Downloads

5

Readme

✅ 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);