andreashuber69/verify-coldcard-dice-seed

View on GitHub
src/package/getKey.ts

Summary

Maintainability
A
0 mins
Test Coverage
// https://github.com/andreashuber69/verify-coldcard-dice-seed/blob/develop/README.md#----verify-coldcard-dice-seed
import { once } from "node:events";

import { AbortError } from "./AbortError.js";
import type { In } from "./InOut.js";

export const getKey = async (stdin: In) => {
    stdin.resume();

    try {
        const key = `${await once(stdin, "data")}`;

        if (key === "\u0003") {
            throw new AbortError();
        }

        return key;
    } finally {
        stdin.pause();
    }
};