Publickey of the signer of the message signature and owner of the storage account
location
String
URL of the file you want to delete
{"message": String,"error": String or not passed if no error}
add-storage
POSThttps://shadow-storage.genesysgo.net
Adds storage
Request content type: application/json
Request Body
Name
Type
Description
transaction *
String
Serialized add storage transaction that is partially signed by the ShdwDrive network
{ message: String, transaction_signature: String, error: String or not provided if no error}
reduce-storage (updated)
POSThttps://shadow-storage.genesysgo.net
Reduces storage
Request content type: application/json
Request Body
Name
Type
Description
transaction *
String
Serialized reduce storage transaction that is partially signed by the ShdwDrive network
{ message: String, transaction_signature: String, error: String or not provided if no error}
make-immutable (updated)
POSThttps://shadow-storage.genesysgo.net
Makes file immutable
Request content type: application/json
Request Body
Name
Type
Description
transaction
String
Serialized make immutable transaction that is partially signed by the ShdwDrive network
{ message: String, transaction_signature: String, error: String or not provided if no error}
Example - Secure Sign and Upload File to ShdwDrive using API
This example demonstrates how to securely upload files to the ShdwDrive using the provided API. It includes the process of hashing file names, creating a signed message, and sending the files along with the necessary information to the ShdwDrive endpoint.
import bs58 from'bs58'import nacl from'tweetnacl'import crypto from'crypto'// `files` is an array of each file passed in.constallFileNames=files.map(file =>file.fileName)consthashSum=crypto.createHash("sha256")// `allFileNames.toString()` creates a comma-separated list of all the file names.consthashedFileNames=hashSum.update(allFileNames.toString())constfileNamesHashed=hashSum.digest("hex")// `storageAccount` is the string representation of a storage account pubkeylet msg =`Shadow Drive Signed Message:\nStorage Account: ${storageAccount}\nUpload files with hash: ${fileNamesHashed}`;constfd=newFormData();// `files` is an array of each file passed infor (let j =0; j <files.length; j++) {fd.append("file", files[j].data, { contentType: files[j].contentType asstring, filename: files[j].fileName, });}// Expect the final message string to look something like this if you were to output it// ShdwDrive Signed Message:// Storage Acount: ABC123// Upload files with hash: hash1// If the message is not formatted like above exactly, it will fail message signature verification// on the ShdwDrive Network side.constencodedMessage=newTextEncoder().encode(message);// Uses https://github.com/dchest/tweetnacl-js to sign the message. If it's not signed in the same manor,// the message will fail signature verification on the ShdwNetwork side.// This will return a base58 byte array of the signature.constsignedMessage=nacl.sign.detached(encodedMessage,keypair.secretKey);// Convert the byte array to a bs58-encoded stringconstsignature=bs58.encode(signedMessage)fd.append("message", signature);fd.append("signer",keypair.publicKey.toString());fd.append("storage_account",storageAccount.toString());fd.append("fileNames",allFileNames.toString());constrequest=awaitfetch(`${SHDW_DRIVE_ENDPOINT}/upload`, { method:"POST", body: fd,});
Example - Editing a File in ShdwDrive using API and Message Signature Verification
In this example, we demonstrate how to edit a file in ShdwDrive using the API and message signature verification. The code imports necessary libraries, constructs a message to be signed, encodes and signs the message, and sends an API request to edit the file on ShdwDrive.
import bs58 from'bs58'import nacl from'tweetnacl'// `storageAccount` is the string representation of a storage account pubkey// `fileName` is the name of the file to be edited// `sha256Hash` is the sha256 hash of the new file's contentsconstmessage=`ShdwDrive Signed Message:\n StorageAccount: ${storageAccount}\nFile to edit: ${fileName}\nNew file hash: ${sha256Hash}`// Expect the final message string to look something like this if you were to output it// ShdwDrive Signed Message:// Storage Acount: ABC123// File to delete: https://shadow-drive.genesysgo.net/ABC123/file.png// If the message is not formatted like above exactly, it will fail message signature verification// on the ShdwDrive Network side.constencodedMessage=newTextEncoder().encode(message);// Uses https://github.com/dchest/tweetnacl-js to sign the message. If it's not signed in the same manor,// the message will fail signature verification on the Shdw Network side.// This will return a base58 byte array of the signature.constsignedMessage=nacl.sign.detached(encodedMessage,keypair.secretKey);// Convert the byte array to a bs58-encoded stringconstsignature=bs58.encode(signedMessage)constfd=newFormData();fd.append("file", fileData, { contentType: fileContentType asstring, filename: fileName,});fd.append("signer",keypair.publicKey.toString())fd.append("message", signature)fd.append("storage_account", storageAccount)constuploadResponse=awaitfetch(`${SHDW_DRIVE_ENDPOINT}/edit`, { method:"POST", body: fd,});
Example - Deleting a File from ShdwDrive using Signed Message and API
In this example, we demonstrate how to delete a file from the ShdwDrive using a signed message and the ShdwDrive API. The code first constructs a message containing the storage account and the file URL to be deleted. It then encodes and signs the message using the tweetnacl library. The signed message is then converted to a bs58-encoded string. Finally, a POST request is sent to the ShdwDrive API endpoint to delete the file.
import bs58 from'bs58'import nacl from'tweetnacl'// `storageAccount` is the string representation of a storage account pubkey// `url` is the link to the ShdwDrive file, just like the previous implementation needed the url inputconstmessage=`ShdwDrive Signed Message:\nStorageAccount: ${storageAccount}\nFile to delete: ${url}`// Expect the final message string to look something like this if you were to output it// ShdwDrive Signed Message:// Storage Acount: ABC123// File to delete: https://shadow-drive.genesysgo.net/ABC123/file.png// If the message is not formatted like above exactly, it will fail message signature verification// on the ShdwDrive Network side.constencodedMessage=newTextEncoder().encode(message);// Uses https://github.com/dchest/tweetnacl-js to sign the message. If it's not signed in the same manor,// the message will fail signature verification on the Shdw Network side.// This will return a base58 byte array of the signature.constsignedMessage=nacl.sign.detached(encodedMessage,keypair.secretKey);// Convert the byte array to a bs58-encoded stringconstsignature=bs58.encode(signedMessage)constdeleteRequestBody= { signer:keypair.publicKey.toString(), message: signature, location:options.url}constdeleteRequest=awaitfetch(`${SHDW_DRIVE_ENDPOINT}/delete-file`, { method:"POST", headers: {"Content-Type":"application/json" }, body:JSON.stringify(deleteRequestBody)})