1.5.0 • Published 10 months ago

improbable-sdk v1.5.0

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

Improbable SDK

This SDK is still being developed, use it as your own risk and consider every implemenation as BETA

Installation

npm install improbable-sdk

Usage

Interoperable Registry

You can create a provider with chain ID or an RPC URL

import { getProvider } from 'improbable-sdk';

const provider = await getProvider({ chainId: 80001 });
const provider = await getProvider({ rpcUrl: 'https://...' });

If chain ID is used it will use a default rpcUrl if it exist. Currently supported networks are Ethereum mainnet, Ethereum Sepolia and Mumbai.

You can create a signer in a similar way

import { getSigner } from 'improbable-sdk';

const signer = await getSigner(privateKey, { chainId: 80001 });
const signer = await getSigner(privateKey, { rpcUrl: 'https://...' });

You can get the ethers contract object with the signer or provider, and also with a custom contract address

import { getObjectRegistry } from 'improbable-sdk';

const registry = await getObjectRegistry(signerOrProvider);
const registry = await getObjectRegistry(signerOrProvider, '0x...');

If no address is provided it will return the ObjectRegistry asociated to the network used in the provider if the address is known.

Once you have the registry object you can interact with all the methods of the contracts same way it is normally done with ethersjs. E.g registry.addAttestation(<PARAMETERS>)

You can generate a signature for an attestation with the following method

import { generateAttestationSignature } from 'improbable-sdk';

const signature = await generateAttestationSignature(
  chainId: number,
  contractAddress: string,
  tokenId: number,
  message: string,
  nonce: number,
  signer: ethers.Signer
)

See examples/interoperable.ts for more detailed usage

WalletLinking

The WalletLinking module offers an easy-to-use interface for checking wallet delegations across delegate.cash V1, V2, and warm.xyz. It also enables writing delegations through delegate.cash V2, providing comprehensive support for managing wallet relationships in a decentralized environment.

How to Instantiate

To create an instance of the WalletLinking, you need to provide the following parameters:

  • RPC_URL: The URL of the RPC provider.
  • chain: value from viem/chains (or define your own)
  • account: A wallet client
  • hotWalletProxy (optional): An instance of ethers.Contract for the HotWalletProxy. If not provided, it will be created internally using the address from the chain provided if the address is known.
import { WalletLinking } from 'improbable-sdk';
import { privateKeyToAccount, Chain, Account } from 'viem';
import { mainnet } from 'viem/chains';

const RPC_URL = 'https://...'; // Provide RPC URL
const chain: Chain = mainnet; // Replace with your desired chain from veim
const PK = '<PRIVATE_KEY>'; // get the private key from dotenv
const account: Account = privateKeyToAccount(PK); // Example account creation using privateKeyToAccount

const walletLinking = new WalletLinking(RPC_URL, chain, account);

To verify if two wallets are linked simple use

walletLinking.isWalletLinked(<HOT_WALLET>, <COLD_WALLET>)

Additionally it supports a 3rd parameter to do more complex verifications using delegate.cash multiple linking options. Check isWalletLinkedInDelegate for implementation details

delegate.cash SDK v1 and v2 are accessisble in case some delegations needs to be done. Use walletLinking.delegateV1 and walletLinking.delegateV2 respectively. Check delegate.cash docs for usage information.

See examples/WalletLinking.ts for detailed usage

Playground

The playground module allows interaction with the Improbable Playground API. Currently supported endpoints are Object and Worlds creation, listing, update and deletion.

To create a Playground instance the apiKey and apiUrl are needed

import { Plauground } from 'improbable-sdk';

const playground = new Playground(<API_KEY>, <API_URL>);

The playground object has a function for each of the supported methods. Each fuction receive an object given the API Specs.

You can check all the objects from the spec defined here

See examples/playground.ts for detailed usage

IPFS/Gateway Providers

IPFS module provides different ways to push and fetch data from IPFS. Currently supported solutions are:

Web3 Storage is planned to be added as well

The SDK provides an utility function to instantiate any of this providers

import {createIPFSService} from "improbable-sdk";

const ipfsProvider = createIPFSService(<CONFIG>);

This config will be a JS object which should contains the name of the provider and parameters needed for creating it. Check factory for usage details.

Every provider is meant to implement the following interface

  • fetchContent(cid: string): Promise<IPFSContent> for retrieving IPFS files
  • pushContent(name: string, content: any, type?: string): Promise<string> for publishing contents to IPFS.
  • listPinnedFiles(): Promise<any[]> for listing pinned files
  • unpinFile(cid: string): Promise<boolean> for unpinning files

Check IPFSService interface for more details