Add isWasm util (#673)

This commit is contained in:
Jaco Greeff
2020-08-28 14:12:22 +02:00
committed by GitHub
parent 701bd9335d
commit 92cc8fc4e3
3 changed files with 19 additions and 0 deletions
+1
View File
@@ -27,3 +27,4 @@ export { default as isToBn } from './toBn';
export { default as isU8a } from './u8a';
export { default as isUndefined } from './undefined';
export { default as isUtf8 } from './utf8';
export { default as isWasm } from './wasm';
+17
View File
@@ -0,0 +1,17 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import u8aEq from '../u8a/eq';
const WASM_MAGIC = new Uint8Array([0, 97, 115, 109]); // \0asm
/**
* @name isWasm
* @summary Tests if the input has a WASM header
* @description
* Checks to see if the input Uint8Array contains a valid WASM header
*/
export default function isWasm (value?: Uint8Array): boolean {
return !!value && u8aEq(value.subarray(0, 4), WASM_MAGIC);
}