Skip to main content

Class: HypercertsStorage

A class that provides storage functionality for Hypercerts.

This class implements the HypercertStorageInterface and provides methods for storing and retrieving Hypercerts.

Example

const storage = new HypercertsStorage();
const metadata = await storage.getMetadata('your-hypercert-id');

Implements

Constructors

constructor

new HypercertsStorage(): HypercertsStorage

Returns

HypercertsStorage

Methods

getData

getData(cidOrIpfsUri, config?): Promise<unknown>

Retrieves data from IPFS using the provided CID or IPFS URI.

This method first retrieves the data from IPFS using the getFromIPFS function. It then parses the retrieved data as JSON and returns it.

Parameters

NameTypeDescription
cidOrIpfsUristringThe CID or IPFS URI of the data to retrieve.
config?StorageConfigOverridesAn optional configuration object.

Returns

Promise<unknown>

A promise that resolves to the retrieved data.

Throws

Will throw a FetchError if the retrieval operation fails.

Throws

Will throw a MalformedDataError if the retrieved data is not a single file.

Remarkts

Note: The original implementation using the Web3 Storage client is currently commented out due to issues with upstream repos. This will be replaced once those issues are resolved.

Implementation of

HypercertStorageInterface.getData

Defined in

sdk/src/storage.ts:145


getMetadata

getMetadata(cidOrIpfsUri, config?): Promise<HypercertMetadata>

Retrieves Hypercert metadata from IPFS using the provided CID or IPFS URI.

This method first retrieves the data from IPFS using the getFromIPFS function. It then validates the retrieved data using the validateMetaData function. If the data is invalid, it throws a MalformedDataError. If the data is valid, it returns the data as a HypercertMetadata object.

Parameters

NameTypeDescription
cidOrIpfsUristringThe CID or IPFS URI of the metadata to retrieve.
config?StorageConfigOverridesAn optional configuration object.

Returns

Promise<HypercertMetadata>

A promise that resolves to the retrieved metadata.

Throws

Will throw a MalformedDataError if the retrieved data is invalid.

Implementation of

HypercertStorageInterface.getMetadata

Defined in

sdk/src/storage.ts:118


storeAllowList

storeAllowList(allowList, totalUnits, config?): Promise<string>

Stores hypercerts allowlist on IPFS.

First it validates the provided metadata using the validateMetaData function. If the metadata is invalid, it throws a MalformedDataError. If the metadata is valid, it creates a new Blob from the metadata and stores it using the hypercerts API. If the storage operation fails, it throws a StorageError.

Parameters

NameTypeDescription
allowListAllowlistEntry[]The allowList to store.
totalUnitsbigintThe total number of units in the allowlist.
config?StorageConfigOverridesAn optional configuration object.

Returns

Promise<string>

A promise that resolves to the CID of the stored metadata.

Throws

Will throw a StorageError if the storage operation fails.

Throws

Will throw a MalformedDataError if the provided metadata is invalid.

Implementation of

HypercertStorageInterface.storeAllowList

Defined in

sdk/src/storage.ts:36


storeMetadata

storeMetadata(metadata, config?): Promise<string>

Stores Hypercert metadata using the hypercerts API.

It then validates the provided metadata using the validateMetaData function. If the metadata is invalid, it throws a MalformedDataError. If the metadata is valid, it creates a new Blob from the metadata and stores it using the hypercerts API. If the storage operation fails, it throws a StorageError.

Parameters

NameTypeDescription
metadataHypercertMetadata-
config?StorageConfigOverridesAn optional configuration object.

Returns

Promise<string>

A promise that resolves to the CID of the stored metadata.

Throws

Will throw a StorageError if the storage operation fails.

Throws

Will throw a MalformedDataError if the provided metadata is invalid.

Implementation of

HypercertStorageInterface.storeMetadata

Defined in

sdk/src/storage.ts:83