The user's session keypair for authentication
The DocumentReference containing metadata about the binary file (type, category, description, subject, author, etc.)
Optionalauthor?: {Who and/or what authored the document
Optionalcategory?: {Categorization of document - use DOCUMENT_CATEGORY_CONCEPTS
Document content - array of content elements. Each element has an attachment that references the Binary resource via url (e.g., "binary/{id}") and includes metadata like contentType, size, title.
Optionaldate?: stringWhen this document reference was created
Optionaldescription?: stringHuman-readable description (title/summary)
Optionalmeta?: { lastUpdated?: string; profile?: string[]; versionId?: string }OptionalsecurityLabel?: {Document security labels
Document status: current | superseded | entered-in-error
Optionalsubject?: {Who/what is the subject of the document (typically patient reference)
Optionaltype?: {Kind of document (LOINC code) - use DOCUMENT_TYPE_CONCEPTS
The Welshare API environment (name or config object)
Promise containing insertedUid (the Nillion document ID)
import {
WelshareApi,
Keypair,
DocumentReferenceHelpers,
DOCUMENT_TYPE_CONCEPTS,
} from "@welshare/sdk";
// After uploading a binary file
const docRef = DocumentReferenceHelpers.createDocumentReference({
binaryId: binaryUploadResult.insertedUid,
fileName: file.name,
fileType: file.type,
fileSize: file.size,
subjectDid: Keypair.keypairKeyDid(keypair).didString, //Nillion 2.0 requires did:key as a method
description: "My document",
type: DOCUMENT_TYPE_CONCEPTS.PHOTO_DOCUMENT,
});
const { insertedUid } = await WelshareApi.submitDocumentReference(
keypair,
docRef,
"production"
);
Side effects:
fetchDelegation() to obtain a NUC delegation from the Welshare APIThe DocumentReference is linked to a Binary resource but does not contain any secret data itself - the encryption key remains in the Binary record.
Submit a DocumentReference to Nillion storage.
This function stores searchable metadata for binary files in Nillion, granting the builder read/execute access to the data. The DocumentReference links to a Binary resource via content.attachment.url using the format "binary/{id}".