{address,u8a}Eq functions (#606)
* {addres,u8a}Eq functions
* Remove mnemonicToSeed
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// 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 u8aToU8a from './toU8a';
|
||||
|
||||
function equals (a: Uint8Array, b: Uint8Array): boolean {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name u8aEq
|
||||
* @summary Compares two Uint8Arrays.
|
||||
* @description
|
||||
* For `UInt8Array` (or hex string) input values true if there is a match.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { u8aEq } from '@polkadot/util';
|
||||
*
|
||||
* u8aEq(new Uint8Array([0x68, 0x65]), new Uint8Array([0x68, 0x65])); // true
|
||||
* ```
|
||||
*/
|
||||
export default function u8aEq (a: Uint8Array | string, b: Uint8Array | string): boolean {
|
||||
return equals(u8aToU8a(a), u8aToU8a(b));
|
||||
}
|
||||
Reference in New Issue
Block a user