HashVerificationStrategy
Overview
The HashVerificationStrategy
verifies data integrity by comparing SHA-256 hashes of fetched data against trusted gateway digest headers. This strategy provides fast, cryptographically secure verification for high-throughput applications.
How It Works
- Fetch Data: Retrieve content from the selected gateway
- Request Digest: Get the digest from trusted gateways via HTTP headers using HEAD/GET requests from a trusted gatweay
- Compute Hash: Calculate the SHA-256 hash of the received data
- Compare: Verify that both hashes match exactly
- Result: Pass or fail based on hash comparison
Basic Usage
import { HashVerificationStrategy, Wayfinder } from '@ar.io/wayfinder-core'
const wayfinder = new Wayfinder({ /* ...global wayfinder configuration */ });
const verificationStrategy = new HashVerificationStrategy({
trustedGateways: [new URL('https://arweave.net')],
})
// use it in a request
const verifiedData = await wayfinder.request('ar://<some-tx-id', {
verificationSettings: {
enabled: true,
strategy: verificationStrategy,
strict: true // block the flow of bytes until verification has passed
events: {
onVerificationProgress: (e) => {
console.debug('Verification progress: ${ e.processBytes / e.totalBytes * 100}%)
},
onVerificationFailed: (e) => {
console.error('Verification failed!, e)
},
onVerificationSucceeded: (e) => {
console.log('Verification succeeded!, e)
}
}
}
})
Related
- Signature Verification: Understand authenticity validation
- Data Root Verification: Explore maximum security verification