0.1.22 • Published 9 months ago

@phi-hub/sdk v0.1.22

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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 contact@philand.xyz.

0.1.20

9 months ago

0.1.21

9 months ago

0.1.22

9 months ago

0.1.17

9 months ago

0.1.18

9 months ago

0.1.19

9 months ago

0.1.11

9 months ago

0.1.12

9 months ago

0.1.13

9 months ago

0.1.14

9 months ago

0.1.15

9 months ago

0.1.16

9 months ago

0.1.8

9 months ago

0.1.9

9 months ago

0.1.7

9 months ago

0.1.6

9 months ago

0.1.5

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.4

9 months ago

0.1.3

9 months ago

0.0.20

10 months ago

0.0.21

10 months ago

0.0.22

10 months ago

0.0.23

10 months ago

0.0.24

10 months ago

0.0.25

9 months ago

0.0.16

10 months ago

0.0.17

10 months ago

0.0.18

10 months ago

0.0.19

10 months ago

0.0.30

9 months ago

0.0.14

10 months ago

0.1.0

9 months ago

0.0.26

9 months ago

0.0.27

9 months ago

0.0.28

9 months ago

0.0.29

9 months ago

0.0.10

10 months ago

0.0.11

10 months ago

0.0.12

10 months ago

0.0.13

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago