1 | import { u8aEq } from '../u8a/eq.js';
|
2 | import { isU8a } from './u8a.js';
|
3 | const ELF_MAGIC = new Uint8Array([0x7f, 0x45, 0x4c, 0x46]); // ELF magic bytes: 0x7f, 'E', 'L', 'F'
|
4 | const PVM_MAGIC = new Uint8Array([0x50, 0x56, 0x4d, 0x00]); // 'P', 'V', 'M', 0x00
|
5 | /**
|
6 | * @name isRiscV
|
7 | * @summary Tests if the input has a RISC-V header
|
8 | * @description
|
9 | * Checks to see if the input Uint8Array contains a valid RISC-V header
|
10 | */
|
11 | export function isRiscV(bytes) {
|
12 | if (isU8a(bytes)) {
|
13 | const start = bytes.subarray(0, 4);
|
14 | return u8aEq(start, PVM_MAGIC) || u8aEq(start, ELF_MAGIC);
|
15 | }
|
16 | return false;
|
17 | }
|