- Added SRI hash injection during frontend build to improve security. - Updated ESLint configuration to include 'navigator' as a global variable. - Introduced a new `settingsStore` to manage user preferences for asset verification. - Enhanced `SoftwareCard` and `VerificationModal` components to display contributor information and security checks. - Updated `verificationStore` to handle expanded toast notifications for detailed verification steps. - Implemented a new `CodeBlock` component for displaying code snippets with syntax highlighting. - Improved API documentation and added new endpoints for fetching software and asset details.
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
//go:build js && wasm
|
|
// +build js,wasm
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall/js"
|
|
)
|
|
|
|
// verifySHA256 verifies that the SHA256 hash of the input data matches the provided expected hash.
|
|
func verifySHA256(this js.Value, args []js.Value) any {
|
|
if len(args) < 2 {
|
|
return js.ValueOf(map[string]any{
|
|
"valid": false,
|
|
"error": "invalid arguments: expected (data []uint8, expectedHash string)",
|
|
})
|
|
}
|
|
|
|
dataLen := args[0].Get("length").Int()
|
|
data := make([]byte, dataLen)
|
|
|
|
steps := []any{}
|
|
|
|
js.CopyBytesToGo(data, args[0])
|
|
steps = append(steps, map[string]any{
|
|
"name": "Data Loading",
|
|
"status": "success",
|
|
"details": fmt.Sprintf("Successfully read %d bytes into WASM memory", dataLen),
|
|
})
|
|
|
|
expectedHash := args[1].String()
|
|
actualHash := computeSHA256(data)
|
|
|
|
steps = append(steps, map[string]any{
|
|
"name": "Checksum Calculation",
|
|
"status": "success",
|
|
"details": fmt.Sprintf("Computed SHA256: %s", actualHash),
|
|
})
|
|
|
|
if actualHash == expectedHash {
|
|
steps = append(steps, map[string]any{
|
|
"name": "Identity Verification",
|
|
"status": "success",
|
|
"details": "Computed hash matches the signed manifest",
|
|
})
|
|
return js.ValueOf(map[string]any{
|
|
"valid": true,
|
|
"steps": steps,
|
|
})
|
|
}
|
|
|
|
steps = append(steps, map[string]any{
|
|
"name": "Identity Verification",
|
|
"status": "error",
|
|
"details": fmt.Sprintf("Hash mismatch! Got %s, expected %s", actualHash, expectedHash),
|
|
})
|
|
|
|
return js.ValueOf(map[string]any{
|
|
"valid": false,
|
|
"steps": steps,
|
|
"error": fmt.Sprintf("hash mismatch: got %s, expected %s", actualHash, expectedHash),
|
|
})
|
|
}
|
|
|
|
// main initializes the WebAssembly module and exposes verifySHA256 to the JavaScript global scope.
|
|
func main() {
|
|
c := make(chan struct{})
|
|
fmt.Println("Software Verifier WASM Initialized")
|
|
js.Global().Set("verifySHA256", js.FuncOf(verifySHA256))
|
|
<-c
|
|
}
|