Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const storageFn = (arg?: any): Uint8Array => {
let key = rawKey;
if (meta.type.isMap) {
assert(!isUndefined(arg) && !isNull(arg), `${meta.name} expects one argument`);
const type = meta.type.asMap.key.toString();
const param = createType(type, arg).toU8a(false);
key = u8aConcat(key, param);
}
// StorageKey is a Bytes, so is length-prefixed
return Compact.addLengthPrefix(
options.isUnhashed
? key
: xxhashAsU8a(key, 128)
);
};
const param = createType(type, arg).toU8a(false);
key = u8aConcat(key, param);
}
// StorageKey is a Bytes, so is length-prefixed
return Compact.addLengthPrefix(
options.isUnhashed
? key
: xxhashAsU8a(key, 128)
);
};
if (meta.type.isMap && meta.type.asMap.isLinked) {
// TODO: there needs some better way to do this
const keyHash = new U8a(xxhashAsU8a(`head of ${stringKey}`, 128));
const keyFn: any = () => keyHash;
keyFn.meta = new StorageFunctionMetadata({
name: meta.name,
modifier: new StorageFunctionModifier('Required'),
type: new StorageFunctionType(new PlainType(meta.type.asMap.key), 0),
fallback: new Bytes(),
documentation: meta.documentation
});
storageFn.headKey = new StorageKey(keyFn);
}
storageFn.meta = meta;
storageFn.method = stringLowerFirst(method.toString());
storageFn.section = stringLowerFirst(section.toString());
storageFn.toJSON = (): any => meta.toJSON();
it('matches the foo test from Rust', (): void => {
const hasher = getHasher(new StorageHasher(registry, 'Twox64Concat'));
const hash = hasher('foo');
const xxhash = xxhashAsU8a('foo', 128);
expect([
hash.subarray(0, 8),
hash.subarray(8)
]).toEqual([
xxhash.subarray(0, 8),
stringToU8a('foo')
]);
});
});
const twox = (bitLength: number, dataPtr: Pointer, dataLen: number, outPtr: Pointer): void => {
const data = heap.get(dataPtr, dataLen);
const hash = xxhashAsU8a(data, bitLength);
l.debug((): any[] => [`twox_${bitLength}`, [dataPtr, dataLen, outPtr], '<-', u8aDisplay(data), '->', u8aToHex(hash)]);
heap.set(outPtr, hash);
};
isTwox64Concat: (data: HasherInput): Uint8Array => u8aConcat(xxhashAsU8a(data, 64), u8aToU8a(data))
};
isTwox128: (data: HasherInput): Uint8Array => xxhashAsU8a(data, 128),
isTwox256: (data: HasherInput): Uint8Array => xxhashAsU8a(data, 256),
isTwox256: (data: HasherInput): Uint8Array => xxhashAsU8a(data, 256),
isTwox64Concat: (data: HasherInput): Uint8Array => u8aConcat(xxhashAsU8a(data, 64), u8aToU8a(data))