Skip to main content

Storage Provider Client

The API related to storage providers is troublesome.

AuthType

SDK support two authentication type:

  • ECDSA: It is usually used on Node.js(Because it need to use a private key)
  • EDDSA: It is usually used in a browser
AuthType
/**
* ECDSA Signature
*/
export type ECDSA = {
type: 'ECDSA',
privateKey: string,
};
/**
* EDDSA Signature
*/
export type EDDSA = {
type: 'EDDSA',
seed: string,
domain: string,
address: string,
};
export type AuthType = ECDSA | EDDSA;

Sp Api Example

Take getBucketReadQuota as a complete example:

offchainAuth
const getAllSps = async () => {
const sps = await getSps();

return sps.map((sp) => {
return {
address: sp.operatorAddress,
endpoint: sp.endpoint,
name: sp.description?.moniker,
};
});
};

// generate seed:
const allSps = await getAllSps();
const offchainAuthRes = await client.offchainauth.genOffChainAuthKeyPairAndUpload(
{
sps: allSps,
chainId: GREEN_CHAIN_ID,
expirationMs: 5 * 24 * 60 * 60 * 1000,
domain: window.location.origin,
address: 'your address',
},
provider: 'wallet provider',
);
browser
// request sp api
const bucketQuota = await client.bucket.getBucketReadQuota(
{
bucketName,
},
{
type: 'EDDSA',
seed: offchainAuthRes.seedString,
domain: window.location.origin,
address: '0x...',
},
);