@welshare/sdk
    Preparing search index...

    Function fetchS3ReadDelegation

    • Fetch a presigned URL for downloading encrypted files from S3 storage.

      Parameters

      • keypair: SessionKeypair

        The user's session keypair for authentication

      • fileStorageKey: string

        The storage key (without welshare:// prefix). Use resolveStorageKey() to convert from URL format.

      • environment: WelshareApiEnvironment

        The Welshare API environment configuration

      Returns Promise<ReadDelegationResponse>

      Promise containing presignedUrl (S3 GET URL)

      import { WelshareApi, resolveEnvironment } from "@welshare/sdk";

      const storageKey = WelshareApi.resolveStorageKey(binaryFile.url);
      const { presignedUrl } = await WelshareApi.fetchS3ReadDelegation(
      keypair,
      storageKey,
      resolveEnvironment("production")
      );

      // Download encrypted file
      const response = await fetch(presignedUrl);
      const encryptedData = await response.arrayBuffer();

      Side effects:

      • Makes HTTP POST to {apiUrl}/auth/delegate/storage?requestType=read
      • Creates a self-signed JWT using the keypair for authentication

      Security notes:

      • Presigned URLs expire after 15 seconds
      • Only the file owner (controller_did) or authorized parties can download