0.1.27 • Published 12 months ago

@phi-hub/sdk v0.1.27

Weekly downloads
-
License
MIT
Repository
github
Last release
12 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.27

12 months ago

0.1.23

1 year ago

0.1.24

1 year ago

0.1.25

1 year ago

0.1.26

12 months ago

0.1.20

1 year ago

0.1.21

1 year ago

0.1.22

1 year ago

0.1.17

1 year ago

0.1.18

1 year ago

0.1.19

1 year ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.1.16

2 years ago

0.1.8

2 years ago

0.1.9

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.30

2 years ago

0.0.14

2 years ago

0.1.0

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago