Function generateDeterministicEntropy

  • Generate deterministic entropy by seeding SHA-256 with a list of random events like coin flips or dice rolls. For coin flips, use 0 ("heads") and 1 ("tails"); for dice, use the visible number.

    Warning: this function's validation assumes that the provided events are truly random ("unbiased"). If the events are biased, e.g. by a weighted dice or a human attempting to type random numbers, the entropy of this function's result will be degraded. Using insufficiently random results will compromise the security of systems relying on the result, making it possible for an attacker to, e.g. guess secret keys and steal funds.

    This method of entropy generation is designed to be easily auditable: the list of results are simply concatenated (without any spaces or separating characters), and the UTF8 encoding of the resulting string of digits is hashed with SHA-256.

    For example, if a 20-sided dice (D20) is rolled 3 times with results 13, 4, and 10, the UTF8 encoding of 13410 (0x3133343130) is hashed with SHA-256, producing a result of 6dd4f2758287be9f38e0e93c71146c76e90f83f0b8c9b49760fc0b594494607b. This can be verified in most command line environments with the command: echo -n 13410 | sha256sum.

    Note that this function is compatible with Coldcard's deterministic key generation workflow when used with six-sided dice (D6).

    Parameters

    • possibleResults: number

      the number of equally-likely results per event; e.g. for a coin, 2, for dice, the number of faces (for a standard die, 6)

    • events: number[]

      an array of numbers encoding the random events; for coin flips, use 0 ("heads") and 1 ("tails"); for dice, use the exposed number (e.g. 1 through 6 for 6-sided dice)

    • __namedParameters: {
          crypto?: {
              sha256: {
                  hash: ((input) => Uint8Array) & ((input) => Uint8Array);
              };
          };
          requiredEntropyBits?: number;
      } = {}
      • Optional crypto?: {
            sha256: {
                hash: ((input) => Uint8Array) & ((input) => Uint8Array);
            };
        }
        • sha256: {
              hash: ((input) => Uint8Array) & ((input) => Uint8Array);
          }
          • hash: ((input) => Uint8Array) & ((input) => Uint8Array)
      • Optional requiredEntropyBits?: number

    Returns string | Uint8Array

Generated using TypeDoc