0.3.16 • Published 1 year ago

@arcana/storage v0.3.16

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Arcana Storage

Installation

Using npm/yarn

npm i @arcana/storage
yarn add @arcana/storage

You can use the standalone module which includes the polyfills.

<script src="./dist/standalone/storage.umd.js"></script>
import { StorageProvider } from '@arcana/storage/dist/standalone/storage.umd';

Storage SDK Usage

Initialize

// address: Smart contract address of app
// provider: Web3provider (Eg: If you have installed metamask then window.ethereum will work)
//           Default value of provider is window.ethereum
// appId: This field is optional. If you want to download a file with just did then you won't require this field
const arcanaInstance = new arcana.storage.StorageProvider({ appId, provider, email });

Get Uploader

const Uploader = arcanaInstance.getUploader();
// file: Blob format
Uploader.upload(file);

Get Downloader

const Downloader = arcanaInstance.getDownloader();
// did: DID of file which you want to download
Downloader.download(did);

Get Access

const Access = arcanaInstance.getAccess();

Share a File

// did: DID of file to be shared, can be a hexadecimal string or an array of such strings
// address: recipients address, similar type as "did"
// validity (optional): For how long will be the user able to download the file, e.g. [400] would mean 400 seconds.
Access.share(did, address);

Revoke File Sharing

// did: DID of file from which access is removed
// address: Address of the user who's access is getting revoked
Access.revoke(did, address);

Transfer File Ownership

// address: new owner's address
Access.changeFileOwner(did, address);

Delete a File

Access.deleteFile(did);

Storage Usage Metrics

Get Upload Limit

//Get consumed and total storage of the current user
let [consumed, total] = await Access.getUploadLimit();

Get Download Limit

//Get consumed and total bandwidth of the current user
let [consumed, total] = await Access.getDownloadLimit();

List Shared Files

List files that are shared with the current user.

let files = await arcanaInstance.sharedFiles();

List Uploaded files

List files that are uploaded by the current user.

let files = await arcanaInstance.myFiles();

Download File by DID

Note: No appID is required to download a file using the file DID. The file DID is returned at the time of file upload and uniquely identifies the file.

// Pass the provider if required otherwise it will choose window.ethereum by default
let arcanaInstance = new arcana.storage.StorageProvider();
await arcanaInstance.downloadDID('<did of the file>');

NFT

Create Metdata URL

Note: This is typically used for NFT use case.

let metadata = await arcanaInstance.makeMetadataURL(
  title,
  description,
  did,
  file,
);
console.log(metadata)
// https://test-storage.arcana.network:9000/api/v1/metadata/0x129d1438ff3bf014e9b9094b3a5d410f691c208ed5305b0844307b761c0e295e

You can use this URL to mint your NFT

Link NFT with did

Note: After minting NFT inorder to use this NFT as a private NFT you need to link it with did

let chainId = 80001,tokenId  = 3, nftContract = "0xE80FCAD702b72777f5036eF1a76086FD3f882E29"
    await arcanaInstance.linkNft(did, tokenId, nftContract, chainId); 

CallBack Functions

1. Upload

1.1 On Success
Uploader.onSuccess = () => {
  console.log('Completed file upload');
};
1.2 On Progress
Uploader.onProgress = (bytesUploaded, bytesTotal) => {
  console.log("Percentage completed", (100*bytesUploaded)/bytesTotal)
};

2. Download

2.1 On Success
Downloader.onSuccess = () => {
  console.log('Completed file download');
};
2.2 On Progress
Downloader.onProgress = (bytesDownloaded, bytesTotal) => {
  console.log("Percentage completed", (100*bytesDownloaded)/bytesTotal)
};

Basic Error Handling

During file upload or file download operations, if there are any errors, dApp developers can address those by catching the exception raised by the Storage SDK:

import { StorageProvider } from '@arcana/storage/dist/standalone/storage.umd';

dAppStorageProvider = new StorageProvider({
        appId: ARCANA_APP_ID,
        provider: window.ethereum,
        email: user_email_string,
      });

const uploader = await dAppStorageProvider.getUploader();

uploader.upload(fileToUpload)
  .catch((error) => {
    if (error.message === NO_SPACE) {
      ...
    } else if (error.code === UNAUTHORIZED) {
      ...
    } else {
      ...
    }
  });

Advanced Error Handling

This advanced error handling section is only meant for file upload to address special dApp use cases. It is recommended that dApp developers using Exception handling - catch mechanism, for handling file upload errors.

Every user action to upload a file internally results in the Storage SDK splitting the file into multiple parts according to the tus protocol. These parts are uploaded to the Arcana Store. If any of the file segment fails to transmit, it is automatically retried until all file segments are transferred. The automatic retry counter is hard coded to '5' in the beta release and the dApp developer cannot change this configuration.

If the dApp developer is required to handle file upload error in case the retries fail, use onError() mechanism. After retrying for four times, in case of any segment upload fails for the fifth time, the Storage SDK invokes onError() callback to enable dApp developer to take appropriate action or delay file transfer to deal with intermittent network failures.

Uploader.onError = (err) => {
  console.log('Error', err);
};

Changing Network and Wallet Account

Change Network
// Below is default function, which can be modified by the developers
arcanaInstance.onNetworkChange = (oldNetwork, newNetwork) => {
  window.location.reload()
}
Change Account
// Below is default function, which can be modified by the developers
arcanaInstance.onAccountChange = (accounts) => {
  window.location.reload()
}

Storage SDK Error Messages

CodeMessageReason
UNAUTHORIZEDYou can't download this fileTrying to download a file which is neither owned by you nor shared with you
TRANSACTIONThis function can only be called by file ownerOnly owner of the file have access to the function i.e, either to delete, revoke or transfer file
TRANSACTIONUser is not activeYour account is either disabled or deleted
TRANSACTIONUser not registered for the appYour account is not registered for the app
TRANSACTIONOnly factory contract can call this functionOnly factory contract can set the app level limit i.e, storage and bandwidth
TRANSACTIONNo space left for appYour current app's storage or bandwidth limit has been consumed
TRANSACTIONNo space left for userYou have already consumed your storage or bandwidth limit
TRANSACTIONNot a trusted forwarder nor factory contractFor meta transaction, transaction should happen from valid factory or forwarder contract
TRANSACTIONOwner already exist for this fileYou cannot upload a file that is already uploaded by different user address
TRANSACTIONShould not be 0Your file size must not be null while uploading
TRANSACTIONFunction can only be called by the assigned storage nodeOnly assigned storage node has access to the function
TRANSACTIONNot file ownerYou are not the file owner thus action cannot be done. Kindly verify your account address
TRANSACTIONValidity must be non zeroValidity is the access specifier and cannot be zero while sharing a file
TRANSACTIONUser was not deleted to reactivateYour account was not deleted to reactivate
TRANSACTIONAn app already created with this IdUse a valid app ID. Try configuring the app at https://dashboard.arcana.network/ to get app ID
TRANSACTIONApp calling the function is not registeredconfigure the app at https://dashboard.arcana.network/
TRANSACTIONPlease add some nodes to authenticate user
TRANSACTIONFunction can only called by nodes
TRANSACTIONAlready voted
TRANSACTIONOnly gateway node can call this functionOnly gateway node has access to the function
TRANSACTIONFile must be uploaded before downloading itFile not found
TRANSACTIONMinimalForwarder: signature does not match requestMeta transaction failed. The function you are trying to call does not exists. check the function signature
WRONG_NETWORKWrong NetworkYou need to change the network/RPC URL in your wallet
0.3.18

1 year ago

0.3.8

2 years ago

0.3.9

2 years ago

0.3.17

1 year ago

0.3.16

2 years ago

0.3.15

2 years ago

0.3.14

2 years ago

0.3.13

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.3.6

2 years ago

0.3.7

2 years ago

0.3.0

2 years ago

0.3.5

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.1.10

2 years 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.2.1

2 years ago

0.2.0

2 years ago

0.1.16

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.9

2 years ago

0.1.4

2 years ago

0.1.5

2 years ago

0.1.1

2 years ago

0.1.3

2 years ago

0.1.0

2 years ago

0.0.11

2 years ago

0.0.10

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