UNPKG

@bsv/wallet-toolbox

Version:

BRC100 conforming wallet, wallet storage and wallet signer components

51 lines 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseBrc114ActionTimeLabels = parseBrc114ActionTimeLabels; exports.makeBrc114ActionTimeLabel = makeBrc114ActionTimeLabel; const WERR_errors_1 = require("../sdk/WERR_errors"); function parseBrc114ActionTimeLabels(labels) { let from = undefined; let to = undefined; const remainingLabels = []; let timeFilterRequested = false; for (const label of labels || []) { if (label.startsWith('action time from ')) { timeFilterRequested = true; if (from !== undefined) throw new WERR_errors_1.WERR_INVALID_PARAMETER('labels', 'valid. Duplicate action time from label.'); const v = label.slice('action time from '.length); if (!/^[0-9]+$/.test(v)) throw new WERR_errors_1.WERR_INVALID_PARAMETER('labels', 'valid. Invalid action time from timestamp value.'); const n = Number(v); if (!Number.isSafeInteger(n) || n < 0) throw new WERR_errors_1.WERR_INVALID_PARAMETER('labels', 'valid. Invalid action time from timestamp value.'); if (Number.isNaN(new Date(n).getTime())) throw new WERR_errors_1.WERR_INVALID_PARAMETER('labels', 'valid. Invalid action time from timestamp value.'); from = n; continue; } if (label.startsWith('action time to ')) { timeFilterRequested = true; if (to !== undefined) throw new WERR_errors_1.WERR_INVALID_PARAMETER('labels', 'valid. Duplicate action time to label.'); const v = label.slice('action time to '.length); if (!/^[0-9]+$/.test(v)) throw new WERR_errors_1.WERR_INVALID_PARAMETER('labels', 'valid. Invalid action time to timestamp value.'); const n = Number(v); if (!Number.isSafeInteger(n) || n < 0) throw new WERR_errors_1.WERR_INVALID_PARAMETER('labels', 'valid. Invalid action time to timestamp value.'); if (Number.isNaN(new Date(n).getTime())) throw new WERR_errors_1.WERR_INVALID_PARAMETER('labels', 'valid. Invalid action time to timestamp value.'); to = n; continue; } remainingLabels.push(label); } if (from !== undefined && to !== undefined && from >= to) throw new WERR_errors_1.WERR_INVALID_PARAMETER('labels', 'valid. action time from must be less than action time to.'); return { from, to, timeFilterRequested, remainingLabels }; } function makeBrc114ActionTimeLabel(unixMillis) { return `action time ${unixMillis}`; } //# sourceMappingURL=brc114ActionTimeLabels.js.map