Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v1 source pure

Package qrcsigner derives the one-time keys of a Quantum Recovery Commit from 32 bytes of entropy and signs with them.

Overview

Package qrcsigner derives the one-time keys of a Quantum Recovery Commit from 32 bytes of entropy and signs with them.

It is the reference signer: the key derivation written as running code, used by the tests of the registry, and by anyone who wants to check another implementation against it. Run it off-chain, with `gno test` or `gno run`. Never call it from a transaction: everything a transaction computes is public, and so would be the entropy.

Nothing on chain depends on how secrets are derived. A commit made by any other signer verifies just the same, as long as its keys are Lamport keys arranged as package qrc describes.

Key derivation

Each of the two trees first gets a seed of its own, computed with the hash function of the other tree:

Example
1seed(SHA256)    = Keccak256("QuantumRecoveryCommit/v1/seed/sha256"    || 0x00 || entropy)
2seed(Keccak256) = SHA256(   "QuantumRecoveryCommit/v1/seed/keccak256" || 0x00 || entropy)

Each seed thus rests on the function of the other tree. Should one function ever be broken badly enough to walk back from the published hashes of its tree to that tree's seed, the entropy still sits behind the other function, and with it the seed of the other tree.

From there on a tree only uses its own function. The secret number side (0 or 1) of digest bit number bit, in the one-time key number leaf, is

Example
1info              = "QuantumRecoveryCommit/v1/secret" || 0x00 || id.Bytes()
2                    || uint32 leaf || uint16 bit || uint8 side
3secret(SHA256)    = HMAC-SHA256(key = seed, message = info)
4secret(Keccak256) = Keccak256(seed || info)

with big-endian integers. Because info holds the commit ID, two commits never share a key, whatever the chain, registry, account or generation. The height is not part of info: a commit ID goes with a single height, since a kit derived for the same ID at another height shares its keys. A generation's keys are derived with the chain ID in force when the generation began; its messages carry the chain ID in force when they are sent.

Constants 1

const EntropySize

1const EntropySize = 32
source

EntropySize is the size, in bytes, of the entropy a kit is derived from.

Functions 2

func New

1func New(entropy []byte, id qrc.ID, height int) *Kit
source

New derives both trees of commit id from the kit entropy.

func NewTree

1func NewTree(h qrc.Hash, entropy []byte, id qrc.ID, height int) *Tree
source

NewTree derives the tree of commit id built on hash function h. It computes every public key of the tree, 512 hashes per leaf.

Types 2

type Kit

struct
1type Kit struct {
2	sha256    *Tree
3	keccak256 *Tree
4}
source

Kit holds both trees of a Quantum Recovery Commit.

Methods on Kit

func Roots

method on Kit
1func (k *Kit) Roots() (rootSHA256, rootKeccak256 [qrc.HashSize]byte)
source

Roots returns the two commits to register.

func Sign

method on Kit
1func (k *Kit) Sign(leaf int, msg []byte) (proofSHA256, proofKeccak256 []byte)
source

Sign signs msg with one-time key number leaf of both trees and returns the two proofs. See Tree.Sign about never signing twice with one leaf.

type Tree

struct
 1type Tree struct {
 2	h      qrc.Hash
 3	height int
 4
 5	// Input buffers of the secret derivation. The last tailSize bytes of
 6	// inner change with every secret, everything before them is fixed.
 7	//   SHA256:    inner = (seed ^ ipad) || info, outer = (seed ^ opad) || inner digest
 8	//   Keccak256: inner = seed || info
 9	inner []byte
10	outer []byte
11
12	// levels[0] holds the leaf hashes side by side, levels[height] the root.
13	levels [][]byte
14}
source

Tree holds the one-time keys of one of the two commits of an account.

Methods on Tree

func Hash

method on Tree
1func (t *Tree) Hash() qrc.Hash
source

Hash returns the hash function the tree is built on.

func Height

method on Tree
1func (t *Tree) Height() int
source

Height returns the height of the tree.

func Root

method on Tree
1func (t *Tree) Root() [qrc.HashSize]byte
source

Root returns the commit: the root of the tree.

func Sign

method on Tree
1func (t *Tree) Sign(leaf int, msg []byte) []byte
source

Sign signs msg with one-time key number leaf and returns the proof qrc.Verify expects.

A one-time key must sign a single message. Signing two different messages with the same leaf weakens the key, and a few more signatures give it away.

Dependencies

Source Files 3