UNPKG

@axiom-crypto/tools

Version:

Useful data, field, and byte manipulation tools for Axiom.

26 lines (25 loc) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeQuery = void 0; const byteStringReader_1 = require("../../utils/byteStringReader"); const decoder_1 = require("../v1/decoder"); const v2_1 = require("../v2"); /** * Decodes a queryString into a Query object. You can typecast the result to the appropriate Query * type (i.e. QueryV1, QueryV2). * @param query The query as bytes in hex string format * @returns A Query object conforming to the decoded Query version */ function decodeQuery(query) { const reader = new byteStringReader_1.ByteStringReader(query); const version = reader.readInt(1); switch (version) { case 1: return (0, decoder_1.decodeQueryV1)(reader.byteString.slice(reader.currentIdx)); case 2: return (0, v2_1.decodeQueryV2)(reader.byteString.slice(reader.currentIdx)); default: throw new Error(`Unsupported version: ${version}`); } } exports.decodeQuery = decodeQuery;