@welshare/sdk
    Preparing search index...

    Function submitBinaryData

    • Submit binary file metadata to Nillion storage.

      This function stores encrypted file metadata in Nillion, granting the builder read/execute access to the data. The actual encrypted file should be uploaded separately to S3 using fetchS3WriteDelegation.

      Parameters

      • keypair: SessionKeypair

        The user's session keypair for authentication

      • submission: {
            controller_did: string;
            encryption_key: string;
            file_name: string;
            file_size: number;
            file_type: string;
            reference: string;
            url: string;
        }

        The binary file submission data containing encryption key, file metadata, and storage URL

        • controller_did: string
        • encryption_key: string
        • file_name: string
        • file_size: number
        • file_type: string
        • reference: string

          Not part of official FHIR Binary spec. Used for legacy questionnaire attachment references. For new implementations, create a DocumentReference resource that links to this Binary via content.attachment.url.

        • url: string
      • environment: WelshareApiEnvironment | "production" | "staging" | "preview" | "development"

        The Welshare API environment (name or config object)

      • _applicationId: string

        The application ID (reserved for future use)

      Returns Promise<{ insertedUid: string }>

      Promise containing insertedUid (the Nillion document ID)

      Error if the submission fails or no document ID is returned

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

      const { insertedUid } = await WelshareApi.submitBinaryData(
      keypair,
      {
      encryption_key: JSON.stringify({ algorithm: "AES-GCM", key: "...", iv: "..." }),
      reference: "questionnaire/abc-123/photo",
      file_name: "profile.jpg",
      file_size: 102400,
      file_type: "image/jpeg",
      controller_did: Keypair.keypairKeyDid(keypair).didString, //Nillion 2.0 requires did:key as a method
      url: `welshare://${uploadKey}`,
      },
      "production",
      "my-app-id"
      );

      Side effects:

      • Calls fetchDelegation() to obtain a NUC delegation from the Welshare API
      • Creates a new document in the Nillion binary files collection
      • Grants the environment's builder DID read/execute access to the document

      The encryption key is stored with %allot modifier, making it secret-shared and only accessible to authorized parties.