Skip to content

Instantly share code, notes, and snippets.

@tracy-codes
Created June 30, 2022 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracy-codes/e4597e6fb71733b93e540ef4c14431c9 to your computer and use it in GitHub Desktop.
Save tracy-codes/e4597e6fb71733b93e540ef4c14431c9 to your computer and use it in GitHub Desktop.
Javascript example of deleting a shadow drive 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 shadow drive file, just like the previous implementation needed the url input
const message = `Shadow Drive Signed Message:\nStorageAccount: ${storageAccount}\nFile to delete: ${url}`
// Expect the final message string to look something like this if you were to output it
// Shadow Drive 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 Shadow Drive Network side.
const encodedMessage = new TextEncoder().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 Shadow Network side.
// This will return a base58 byte array of the signature.
const signedMessage = nacl.sign.detached(encodedMessage, keypair.secretKey);
// Convert the byte array to a bs58-encoded string
const signature = bs58.encode(signedMessage)
const deleteRequestBody = {
signer: keypair.publicKey.toString(),
message: signature,
location: options.url
}
const deleteRequest = await fetch(`${SHDW_DRIVE_ENDPOINT}/delete-file`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(deleteRequestBody)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment