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

@phi-hub/sdk

v0.1.23

Published

A powerful toolkit for interacting with the Phi Protocol

Downloads

85

Readme

Phi SDK

Phi Lib is a powerful, developer-friendly toolkit designed for seamless interaction with the Phi Protocol. It allows developers to create and manage credentials (Creds), issue artworks as non-fungible tokens (NFTs) tied to these credentials, and verify minting eligibility across multiple blockchain networks.

Features

  • Create Merkle-based Creds from CSV file
  • Create Signature-based Creds with customizable verification endpoints
  • Buy/Sell shares for Cred
  • Issue Phi NFT Arts based on Creds

SDK

Installation

To install the Phi SDK, run the following command:

bun add @phi-hub/sdk

Usage

Importing the SDK

import { CredManager, ArtManager, VerifierManager } from "@phi-hub/sdk";
import { CredRequest, ArtCreateInput, AddVerifierInput, VerifierResponse } from "@phi-hub/sdk/types";
import { ArtChainId } from "@phi/protocol/supported-chain";
import { ArtType, CredType } from "@phi/protocol/types";
import { Address, Chain } from "viem";

Creating a Merkle-based Cred

const credManager = new CredManager(privateKey, chainId);

const merkleInput: CredRequest = {
  executor: "0xYourAddress" as `0x${string}`,
  creator: "0xCreatorAddress" as `0x${string}`,
  credType: "BASIC" as CredType, // Or other valid CredType
  requirement: "YourRequirement",
  imageData: "Base64EncodedImageData",
  verificationSource: "https://verificationsource.com",
  title: "Your Cred Title",
  description: "Your Cred Description",
  networks: [1, 4] as Chain["id"][],
  project: "Your Project Name",
  tags: ["tag1", "tag2"],
  relatedLinks: ["https://example.com"],
  quantity: BigInt(1),
  buyShareRoyalty: 100,
  sellShareRoyalty: 100,
  verificationType: "MERKLE",
  addressList: "YourAddressListCSVData",
};

const credId = await credManager.createCred(merkleInput, chainId);
console.log(`Merkle-based Credential created successfully with ID: ${credId}`);

Creating a Signature-based Cred

const signatureInput: CredRequest = {
  executor: "0xYourAddress" as `0x${string}`,
  creator: "0xCreatorAddress" as `0x${string}`,
  credType: "ADVANCED" as CredType, // Or other valid CredType
  requirement: "YourRequirement",
  imageData: "Base64EncodedImageData",
  verificationSource: "https://verificationsource.com",
  title: "Your Signature Cred Title",
  description: "Your Signature Cred Description",
  networks: [1, 4] as Chain["id"][],
  project: "Your Signature Project Name",
  tags: ["tag1", "tag2"],
  relatedLinks: ["https://example.com"],
  quantity: BigInt(1),
  buyShareRoyalty: 100,
  sellShareRoyalty: 100,
  verificationType: "SIGNATURE",
  method: "API", // or "EAS"
  verifier: {
    address: "0xVerifierAddress" as `0x${string}`,
    endpoint: "https://verifier.endpoint.com",
  },
};

const signatureCredId = await credManager.createCred(signatureInput, chainId);
console.log(`Signature-based Cred created successfully with ID: ${signatureCredId}`);

Uploading an art for a cred

Arts are of two types:

  1. IMAGE - static image
  2. API_ENDPOINT - dynamic image which can be fetched from an external source

Use the ArtManager to create and upload art. The inputs will vary according to the artType

const artManager = new ArtManager(privateKey, artChainId, credChainId);

const imageArtInput: ArtCreateInput = {
  executor: "0xYourAddress" as `0x${string}`,
  title: "Awesome Image Art Title",
  network: 84532 as ArtChainId, // Assuming this is a valid ArtChainId
  artist: "0xArtistAddress" as `0x${string}`,
  receiver: "0xReceiverAddress" as `0x${string}`,
  description: "Your Image Art Description",
  externalURL: "https://example.com",
  start: 1724681692,
  end: 4880355292,
  maxSupply: 100,
  price: BigInt("1000000000000000000"), // 1 ETH in wei
  soulbound: false,
  tags: ["tag1", "tag2"],
  artType: "IMAGE" as ArtType,
  imageData: "Base64EncodedImageData",
};

const imageArtId = await artManager.createArt(imageArtInput, credId);
console.log(`Image Art created successfully with ID: ${imageArtId}`);

const apiArtInput: ArtCreateInput = {
  executor: "0xYourAddress" as `0x${string}`,
  title: "Awesome API Art Title",
  network: 84532 as ArtChainId, // Assuming this is a valid ArtChainId
  artist: "0xArtistAddress" as `0x${string}`,
  receiver: "0xReceiverAddress" as `0x${string}`,
  description: "Your API Art Description",
  externalURL: "https://example.com",
  start: 1724681692,
  end: 4880355292,
  maxSupply: 100,
  price: BigInt("1000000000000000000"), // 1 ETH in wei
  soulbound: false,
  tags: ["tag1", "tag2"],
  artType: "API_ENDPOINT" as ArtType,
  endpoint: "https://api.example.com",
  previewInput: {
    address: "0xPreviewAddress",
    data: "PreviewData",
  },
};

const apiArtId = await artManager.createArt(apiArtInput, credId);
console.log(`API Art created successfully with ID: ${apiArtId}`);

Creating a verifier for a cred

const verifierManager = new VerifierManager(credChainId);

const verifierInput: AddVerifierInput = {
  address: "0xVerifierAddress" as `0x${string}`,
  endpoint: "https://verifier.endpoint.com",
  verificationSource: "https://github.com/verifier-source",
};

const arweaveId = await verifierManager.createVerifier(verifierInput, credId);
console.log(`Verifier added successfully: ${arweaveId}`);

License

The Phi SDK is released under the MIT License.

Support

For questions or issues, please contact our support team at [email protected].