From c3811ee6e9faeaba9445ddf5ed6bbc18dadc449e Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 23 Jul 2019 16:10:36 +0200 Subject: [PATCH] feat: Implement twox64concat (#1166) * feat: Implement twox64concat * Import order * use u8aToU8a --- packages/api-metadata/src/storage/fromMetadata/getHasher.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/api-metadata/src/storage/fromMetadata/getHasher.ts b/packages/api-metadata/src/storage/fromMetadata/getHasher.ts index d24a502b44..4859e54810 100644 --- a/packages/api-metadata/src/storage/fromMetadata/getHasher.ts +++ b/packages/api-metadata/src/storage/fromMetadata/getHasher.ts @@ -3,6 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { StorageHasher } from '@polkadot/types/primitive'; +import { u8aConcat, u8aToU8a } from '@polkadot/util'; import { blake2AsU8a, xxhashAsU8a } from '@polkadot/util-crypto'; type HasherInput = string | Buffer | Uint8Array; @@ -31,7 +32,9 @@ export default function getHasher (hasher?: StorageHasher): HasherFunction { return (data: HasherInput): Uint8Array => xxhashAsU8a(data, 256); } - // FIXME Add Twox128Concat + if (hasher.isTwox64Concat) { + return (data: HasherInput): Uint8Array => u8aConcat(xxhashAsU8a(data, 64), u8aToU8a(data)); + } // All cases should be handled above, but if not, return Twox128 for // backwards-compatbility