biketrack-app/node_modules/@ethersphere/bee-js/dist/mjs/feed/topic.js

21 lines
725 B
JavaScript
Raw Normal View History

2022-07-11 10:27:11 +02:00
import { keccak256Hash } from "../utils/hash.js";
import { assertBytes } from "../utils/bytes.js";
import { makeHexString, bytesToHex } from "../utils/hex.js";
import { TOPIC_BYTES_LENGTH, TOPIC_HEX_LENGTH } from "../types/index.js";
export function makeTopic(topic) {
if (typeof topic === 'string') {
return makeHexString(topic, TOPIC_HEX_LENGTH);
} else if (topic instanceof Uint8Array) {
assertBytes(topic, TOPIC_BYTES_LENGTH);
return bytesToHex(topic, TOPIC_HEX_LENGTH);
}
throw new TypeError('invalid topic');
}
export function makeTopicFromString(s) {
if (typeof s !== 'string') {
throw new TypeError('topic has to be string!');
}
return bytesToHex(keccak256Hash(s), TOPIC_HEX_LENGTH);
}