Composables

Framework-agnostic functions for when you want full control over the UI. These are the same functions the Web Components use internally.

💡
Same engine, your UI. The composables expose the verification and signing pipeline as plain functions. Use them to build custom interfaces, integrate into existing forms, or run verification in a Web Worker.

Installation

Import
 import { hashFile, signWithBrowserKey, signWithWallet } from '@attestto/verify/composables' 

hashFile

Compute the SHA-256 hash of a File or Blob. Returns a hex-encoded string.

hashFile
 import { hashFile } from '@attestto/verify/composables'

const input = document.querySelector('input[type="file"]')

input.addEventListener('change', async (e) => {
  const file = e.target.files[0]
  const hash = await hashFile(file)

  console.log('SHA-256:', hash)
  // e3b0c44298fc1c149afbf4c8996fb924...
}) 
Parameter Type Description
file File | Blob The file to hash.

Returns: Promise<string> — hex-encoded SHA-256 hash.

signWithBrowserKey

Generate an Ed25519 key pair in the browser and sign a hash with it. Useful for quick proofs or anonymous attestations where a DID wallet is not available.

signWithBrowserKey
 import { hashFile, signWithBrowserKey } from '@attestto/verify/composables'

const file = /* a File from input or drop */
const hash = await hashFile(file)

const result = await signWithBrowserKey(hash)

console.log(result.publicKey)  // base58-encoded Ed25519 public key
console.log(result.signature)  // base64-encoded signature
console.log(result.algorithm)  // "Ed25519" 
Parameter Type Description
hash string Hex-encoded SHA-256 hash to sign.

Returns: Promise<{ publicKey: string, signature: string, algorithm: string }>

⚠️
Ephemeral keys. Browser-generated keys are not persisted across sessions unless you store them yourself. For production signing, use signWithWallet with a proper DID wallet.

signWithWallet

Sign a hash using a connected DID wallet via @attestto/id-wallet-adapter. The wallet handles key management and user approval.

signWithWallet
 import { hashFile, signWithWallet } from '@attestto/verify/composables'
import { connectWallet } from '@attestto/id-wallet-adapter'

// Connect to a wallet
const wallet = await connectWallet()

// Hash the document
const file = /* a File from input or drop */
const hash = await hashFile(file)

// Sign with the wallet — user sees approval prompt
const credential = await signWithWallet(wallet, hash, {
  fileName: file.name,
  credentialType: 'DocumentSignature'
})

console.log('Signer DID:', credential.issuer)
console.log('Credential:', credential) 
Parameter Type Description
wallet WalletConnection Connected wallet from @attestto/id-wallet-adapter.
hash string Hex-encoded SHA-256 hash to sign.
options object Optional. fileName (string) and credentialType (string).

Returns: Promise<VerifiableCredential> — a W3C Verifiable Credential.

See also