UNPKG

merkle-tree-lib

Version:

Merkle Tree implementation with BIP340 tagged hash support.

39 lines (38 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HashStrategyFactory = exports.HashStrategyType = void 0; const Sha256Strategy_1 = require("./strategies/Sha256Strategy"); const TaggedSha256Strategy_1 = require("./strategies/TaggedSha256Strategy"); /** * HashStrategyType - Enumeration of available hash strategy types */ var HashStrategyType; (function (HashStrategyType) { HashStrategyType["SHA256"] = "sha256"; HashStrategyType["TAGGED_SHA256"] = "tagged-sha256"; })(HashStrategyType || (exports.HashStrategyType = HashStrategyType = {})); /** * HashStrategyFactory - Factory for creating hash strategy instances */ class HashStrategyFactory { /** * Create a hash strategy of the specified type * * @param type - The type of strategy to create * @param options - Additional options (like tag for tagged hashing) * @returns A HashStrategy instance */ static createStrategy(type, options) { switch (type) { case HashStrategyType.SHA256: return new Sha256Strategy_1.Sha256Strategy(); case HashStrategyType.TAGGED_SHA256: // Use provided tag or default to "Bitcoin_Transaction" const tag = options?.tag || "Bitcoin_Transaction"; return new TaggedSha256Strategy_1.TaggedSha256Strategy(tag); default: throw new Error(`Unsupported hash strategy type: ${type}`); } } } exports.HashStrategyFactory = HashStrategyFactory;