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
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
Name | Type | Description |
---|---|---|
cidOrIpfsUri | string | The CID or IPFS URI of the data to retrieve. |
config? | StorageConfigOverrides | An 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
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
Name | Type | Description |
---|---|---|
cidOrIpfsUri | string | The CID or IPFS URI of the metadata to retrieve. |
config? | StorageConfigOverrides | An 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
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
Name | Type | Description |
---|---|---|
allowList | AllowlistEntry [] | The allowList to store. |
totalUnits | bigint | The total number of units in the allowlist. |
config? | StorageConfigOverrides | An 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
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
Name | Type | Description |
---|---|---|
metadata | HypercertMetadata | - |
config? | StorageConfigOverrides | An 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