--- tags: spec --- # tKey - User-centric threshold key management Existing private key management solutions have come a long way in terms of user experience. However, many of these solutions make tradeoffs with reduced guarantees on custody and censorship-resistance. For example, password-manager key management solutions can restrict user access by refusing to return the encrypted key from their servers. Which then ultimately derives down to resorting to the usual approach of protecting private keys via redundant backups. We propose a model of key management, tKey, that uses [Shamir Secret Sharing](https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing) to achieve this without sacrificing user experience, while retaining end-user autonomy and control over the private key. tKey manages private keys using the user's device, private input, and wallet service provider. As long as a user has access to 2 out of 3 (2/3) of these shares, they will be able to retrieve their private key. We describe the architecture of tKey and detail several core user flows for onboarding, key recovery, and device management. To achieve these flows, tKey leverages heavily on its service provider and its properties, which could be a centralized provider or something distributed, such as the [Torus Network](https://medium.com/toruslabs/what-distributed-key-generation-is-866adc79620). tKey also depends on a persistent storage layer (e.g. IPFS, Arweave, Sia) to store encrypted metadata. ## tKey Overview The user starts by generating (client-side) a 2 out of 3 (2/3) Shamir secret sharing, $f_0(x) = a_0 + a_1x$, with three shares: $f_0(1), f_0(z_1), f_0(z_2)$ where $z_1,z_2 \in \mathbb{Z}_q$ 1. **$f_0(1)$ is managed by a service provider**: This share is kept and managed by a wallet service provider via their own authentication flows. 2. **$f_0(z_1)$ is stored on the user's device**: Implementation is device and system specific. For example, on mobile devices, the share could be stored in device storage secured via biometrics. 3. **$f_0(z_2)$ is a recovery share**: An extra share to be kept by the user, possibly kept on a seperate device, downloaded or based on user input with enough entropy (eg. password, security questions, hardware device etc.). Similar to existing 2FA systems, a user needs to prove ownership of at least 2 out of 3 (2/3) shares, in order to retrieve his private key. This initial setup provides several benefits. ### Self-custodial In existing systems, even if wallet service providers have high levels of security in terms of private key storage, a user could still lose their authentication credentials and have their private key stolen. Using tKey, since the wallet service provider only has access to one share, it's not possible for the wallet service provider to retrieve the user's private key on their own. ### Censorship resistance Using a 2/3 threshold also prevents censorship by the wallet service provider. In the case that a wallet service provider refuses to return the user's private key even after the user has authenticated successfully, the user can still reconstruct their private key using $f_0(z_1)$ (device share) and $f_0(z_2)$ (recovery share). Users can then choose a different wallet service provider, which helps to prevent vendor lock-in. ### Improvements to key recovery In the event of a lost device/share, there is redundancy built into the share threshold such that a user can still recover their key. It is also possible to refresh shares such that lost shares are revoked. This is an improvement over writing down a seed phrase on a piece of paper, since losing the seed phrase gives complete access to the private key. Losing a share, however, is acceptable as long as the user does not lose more than one share without refreshing his existing shares. ### Incremental security Users can increase security on their key by increasing the 2/3 threshold to a higher threshold. For example, a user can increase the threshold from 2/3 to 3/4 and add yet another authentication factor like a hardware device. This might be necessary if the user's has high amounts of cryptocurrency on his private key. ### Compatible with existing user flows Many wallet service providers have streamlined user access to a point where private key retrieval has become indistinguishable from Web2.0 logins. This has greatly improved user experience in this space, and tKey does not detract from this goal. By using user device storage for one of the shares, the main user flows for existing wallet service providers remain unaffected and these service providers can continue to use any form of attestation/authentication (eg. traditional user based accounts, OAuth, biometrics). ### Native signatures Unlike traditional smart contract wallets which require additional setup and can be expensive to deploy and manage, tKey can be used to generate normal private keys to sign messages. Secret sharing and share refresh is also done completely off-chain, which makes tKey usable on blockchains with limited smart contract functionality. ## Technical Architecture ![](https://hackmd.io/_uploads/BySGvhPzD.png) ### Components #### Service provider Service providers provide a user-specific key based on some form of attestation from the user. This attestation could come in the form of an OAuth login from an existing account, a traditional email account login, or even biometrics. Service providers need not return a private key, but need to fufill the interface: - $retrievePubKey()$ - $encrypt(msg, pubKey)$ - $decrypt(msg)$ - $sign(msg)$ For ease of illustration the rest of this document assumes that this is implemented with secp256k1 keys and ECIES. The key retrieved from the service provider is refered to as an encryption key or $encKey$. #### Storage layer The storage layer serves as a persistent data store for storing encrypted metadata. Examples of such systems include IPFS, Arweave, Sia, or even BFT layers. Data availability and cost are the main factors to consider but the choice of storage layer is ultimately up to the implementer. tKey utilizes $encKey$ from the service provider as an entry point to retrieve the private key. $encKey$ is used to retrieve encrypted user-specific data from the storage layer, refered to as metadata. This data includes a user's threshold, polynomial commitments, associated devices, and so on. #### User device tKey is dependent on user devices to store shares. The base flow accomodates a single device, but users can use multiple devices to increase the threshold once they have an initial setup. Access to device storage on the user's device is implementation specific. For example, for native applications on mobile, they can make use of the device keychain. #### Recovery share This is generally *not* used during normal operation, and is intended for use in key recovery / share refresh if the user loses his/her device or shares. ### Key initialization and reconstruction A key is initialized upon a user-triggered action (eg. login to service provider). We then attempt to retrieve associated metadata for the user. If none exists, the user is a new one and we generate a corresponding SSS 2/3 polynomial with its respective key and shares. If it exists, we decrypt the metadata using the service provider $encKey$ and read the metadata to verify user information and associated secret sharing parameters. #### Initialization We select a polynomial $f(z)$ over $Z_q$ where: $$ f(z) = a_1z + \sigma $$ * $f(0) = \sigma$ denotes the private key scalar to be used by the user * $a_1$ is a coefficient to $z$ * $f(z_1),f(1)$ and $f(z_2)$ are ShareA, ShareB and ShareC respectively ![](https://hackmd.io/_uploads/SJU6kNwa8.png) ShareA is stored on the user's device, ShareB is encrypted with the $encKey$ and stored on the storage layer for future retrieval, and ShareC dependent on user input or handled as a recovery share. #### Reconstruction ![](https://hackmd.io/_uploads/BkQMlVvaU.png) If a user has logged in previously, he/she reconstructs their key by decrypting ShareB (retrieved through the storage layer) and combining it with ShareA on the user's current device using [Lagrange interpolation](https://brilliant.org/wiki/lagrange-interpolation/#:~:text=Lagrange%20Interpolation,proof%20of%20the%20theorem%20below). #### Key generation with deterministic share Provided with a user input, $input$, we can pre-determine a single share in the generation of the SSS polynomial, where we peg ShareC or $f(z_3)$ to a users input. Let $H$ be a cryptographically secure hash function. $$\text{Given} \, f(z_3)= H(input)\\ \text{Select } \sigma \text{ over } Z_q \text{ and solve } a_1= \frac{f(z_3) - \sigma}{z_3}$$ In the case of secret resharing, we can also conduct the deterministic generation of the $f(z)$ polynomial with a given $\sigma$ and $input$. We are able to peg $n$ given values to the key or shares as long as $n\le d + 1$ where $d$ is the degree of the SSS polynomial $f(z)$. It is important that $input$ has sufficent entropy in its generation. A potential way to guarentee this is via using several security questions (for example three of them) with answers $A,B,C$ to derive $input = A|B|C$. This can be implemented with a repository of questions, of which order and index can be defined in metadata. Candidate qualified questions are suggested to be ones with deterministic answers (i.e. "your parent's birthday" or "your city of birth"), rather than "what's your favorite singer?". To accomodate for cases that users tend to forget their answers. There is a further potential of splitting the answers themselves via SSS such that the user can answer 3/5 questions, giving redundancy. ### Expanding the number of shares (adding a device) In the case of a new device the user needs to migrate a share to the device to reconstruct their key. This can be done user input or through a login to a current device. ![](https://hackmd.io/_uploads/SJpLgEvaL.png) On reconstruction of $f(z)$ on the new device we set ShareD to $f(z_4)$. ### Share resharing and revokability Utilizing the storage layer, we are able to generate new shares for all devices, regardless if they are online or offline. This allows us to remove devices from the sharing, allow the user to change their security questions and/or adjust their security threshold. The key concept here is utilizing published Share commitments as encryption keys to retrieve shares on the most updated SSS polynomial. This is illustrated from a 2/4 SSS sharing $f(z)$ with shares $s_a, s_b, s_c, s_d$ kept on 3 user devices and the service provider. Let $g$ be a generator of a multiplicative subgroup where the discrete log problem is assumed hard to solve. During initialization of the key we create share commitments $g^{s_a}, g^{s_b}, g^{s_c}, g^{s_d}$ to be stored on the storage layer. These share commitments are analgous to public keys derived from the share scalars. Given the user loses device D holding $s_d$, and wants to make that share redundant. He/she first reconstructs their key on device A. We utilize a public key based encryption scheme (eg. ECIES). The user generates a new 2/3 SSS polynomial $h(z)$ on the same $\sigma$ with shares $s_1, s_2, s_3$ and encrypts the newly generated shares for each respective share commitment, except for the lost $g^{s_d}$ commitment. $$\text{for }i = \{1,2,3\} \text{ and } v = \{a,b,c\} \\ encrypt(s_iu,g^{s_v}) \Rightarrow c_{nv} \\ \text{where } nv = \{1a,2b,2c\}$$ $c_{nv}$, the resulting ciphertext from the encryption, is then stored on the storage layer for retrieval on other devices. On login to device B, the user retrieves $c_{2b}$ is able to use $s_b$ to decrypt the new $s_2$ and reconstruct their key with $s_1$ derived from the service provider in a similar fashion. Using the $h(z)$ allows $s^d$ to also be deprecated as a share. Resharing allows us to share a key on a new polynomial with a different degree/threshold, allowing us to also increase a user's security/factor devices or inputs to reconstruct thier key as they require it. This can be incrementally done as needed. ## Metadata In order to provide functionality and ease of use beyond simple reconstruction, we need to hold commitments, threshold and other forms of metadata along with the shares. ### Storage layer While we can store metadata locally with shares on devices, using a storage layer that can replicate and update metadata allows for a user's share stores to be in sync. It also enables shares to be refreshed while offline, removing a large inconvenience to end users. Given the prolifiration of decentralized persistant storage layers (e.g. IPFS, Arweave, Sia) as well as formerly centralized alternatives there are many options to use as the storage layer. Metadata kept on these platforms are encrypted with a share and the encrypted data can be replicated as much as wanted. The main considerations when considering the storage layer here are data availablity and cost. We expand on data availablity concerns futher below[]. ### Design The design of the metadata data structures minimizes assumptions on the storage layer. In particular, we only assume that the storage layer is indexable and has data availability. Other guarantees like privacy, verifiability, replication, are achieved through the data structures. For ease of implementation, we only use conventional cryptographic schemes like ECIES and ECDSA for encryption and signing respectively. We represent metadata data structure as a JSON, which is associated with each individual share on the Shamir secret sharing. The metadata is encrypted with the share before being stored on the storage layer, and is decrypted before being read. Common information across shares (eg. thresholds), is stored on a field (i.e. GeneralStore) on the metadata of each share (i.e. replicated). Each copy of valid metadata contains a valid signature on the data by the tKey, ensuring that only clients with full access can write valid metadata's. #### PolynomialIDs Each SSS uses a polynomial which has a public identifier derived through two parts - together they provide information necessary for the verification, reconstruction and refreshing of shares. The first half is a concatenation of their co-efficient commitments. In specific, only the $x$ point is used in the concatenation in hexadecimal format: $$ Given\space f(x) = a_0x^0 + a_1x^1 +...a_{t-1}x^{t-1} \\ firstHalf = g^{a_0} | g^{a_1}|...g^{a_{t-1}} $$ And the second half is a concatenation of share indexes with respect to the polynomial. $$ secondHalf = z_0 |z_1|z_2|...z_n$$ The final polynomialID consists of them joined by a seperator. Similarly in a hexadecimal format: $$ polyID = firstHalf|0x0|secondHalf$$ #### PolynomialID List For any adjustment in the configuration of the sharing (either $t$ or $n$) we refresh shares and reconstruct a new polynomial. On the technical level this is only strictly necessary for an adjustment on $t$, but as; it generally is good practice to refresh, we want to maintain a log of previous configurations and refreshing is negligable in cost - we propose to also refresh on adjustments to $n$. We keep a list of polynomial IDs on metadata: $$ polyIDList = [polyID(f_0),polyID(f_1)...] $$ #### Stores Stores on metadata are key value maps that live on metadata. They are used both for core flows, and as a space for extensions or modules to use. There are currently three which are defined and each are differenciated by their access structures: * **General Store** - Readable by any share and only writable by the reconstructed tKey * **Scoped Store** - Readable by a specific share, and only writable by the reconstructed tKey * **tKey Store** - Readable and writable by only the reconstructed tKey Each of the stores have these properties by specific encryption and decryption schemes which we further expand on. Note that metadata is encrypted and replicated for each individual share. With the metadata encrypted and replicated above, data in external fields of metadata and the General Store share the same permission properties. The Scoped Store requires an additional encrytion on the store's data, only for the respective share its made readable to. Likewise the tKey Store requires additional encryption on its data by the tKey itself, to give it read properties only by the tKey. Stores in metadata are designed to be extendable by nature to incorporate as much data necessary for smooth user flows. The extendability allows for modules to be built around the core infrastructure of metadata where needed. #### Serialization/Deserialization Summerizing, metadata is represented by a JSON with the following fields: | Field | Description | Example | | -------- | -------- | -------- | | pubKey | the $x$ value from $g^s$ |```"429519635c8130e1398c94246c2d64e92c7440fa24ab70f9868ff06b02b0f3f4"``` | | polyIDList | list of polyIDs | ```["429519635c8130e1398c94246c2d64e92c7440fa24ab70f9868ff06b02b0f3f4|f3c5a4c339a8fcdb848a0262d0c4c0c7804164307588e388bdcc52c573aa0ad4|0x0|41c900a05135a69012b0be44a1b3fbbd2d22aeb41f84b0f13d14d89d6e25bffe|bf60d4ea3a03c094d96e6aebe48e8f245f55af22c9e15235c3f2863374a03b19"]``` | |generalStore| key value map of data readable by any share|```{"shareDescriptions":{"2":["{\"module\":\"webStorage\",\"userAgent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36\",\"dateAdded\":1600052849609}","{\"module\":\"webStorage\",\"userAgent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36\",\"dateAdded\":1600846590812}"],"7087bef077dc156afa0903dbaf83144aeb53b701591c84b85427d0cd40ce4343":["{\"module\":\"securityQuestions\",\"questions\":\"whats your password?\",\"dateAdded\":1600835960674}"]},"shareTransfer":{"pointer":"230ff5590f4280072f54de288fce7fcb961f86279fcb12aaffba8cbdf5894088"}}```| |scopedStore|key value map of data readable by only specific shares |```{"bf60d4ea3a03c094d96e6aebe48e8f245f55af22c9e15235c3f2863374a03b19":{"ciphertext":"a37a489bbc6aa2e458ab8917e8ae31fc44abb51ad21abc5c1b34d98c738eb2d6b03ce66c23045ade83a1c9da9287dc21cf20d3de3d8bce6af9b2389029192ac8989bac3d1ab2365126f440ffb3af72f18e239e271cf6bf02f0a2742972a3aa0706ef320562d46408c453942dc540771dab7644cc272bd50b174f9fc2f5c057e347ba8dcd5f3c3137dd86eb775504e9b3060576f1aa4b0a84826a7dc0c3c7146a9c4aaaf8d7f1c0f70d0b4a83b79fe378aebff8486f8a98667f58a4b51c6cdd42bf62162026b0f79c3ded6f4e6d8cb6d20be89e4cde2cb7a6725bea48a6a3a00d5f345b2302549554e24609687275d3951e2cd963e8e44d72f3f2bbdff07a37d6","ephemPublicKey":"0477522b2b2d41b2d96f547cd1b11f2477b8a82c9670374661d42fa1720b5f879d396d38dd023bd5986d965ec17275fb49442c2d9829f3b8a84d39ab84c12b40ef","iv":"dd003d7582516f81e3b8627dbadff3ab","mac":"b9cf4cea565ada89a25acb593cb4da54b9fe475fb92535b7da2abb1044f2e181"}}``` | |tKeyStore|key value map of data readable by only tKey| {"ciphertext":"0f1db0bed90a48bd82ac16c043ceb346e0fdbc99e6ffb519c3ac54f7c2000488","ephemPublicKey":"04b3913d61f3fbb824331ecb2d315938707ea6976426c79aaeb1f9cc540b353314eff55097a8dbd31b86278fce995ae05a030dc14a81223776d3dc90ba6b7b4ac5","iv":"f85a2caffaa561270db13aa7f4400df8","mac":"69aafb4619cb5bb4a0f1466a6f2c6931dc4766f88325476e09426cf05c930154"}| We provide a full example below: ``` { "pubKey": "429519635c8130e1398c94246c2d64e92c7440fa24ab70f9868ff06b02b0f3f4", "polyIDList": ["429519635c8130e1398c94246c2d64e92c7440fa24ab70f9868ff06b02b0f3f4|f3c5a4c339a8fcdb848a0262d0c4c0c7804164307588e388bdcc52c573aa0ad4|0x0|41c900a05135a69012b0be44a1b3fbbd2d22aeb41f84b0f13d14d89d6e25bffe|bf60d4ea3a03c094d96e6aebe48e8f245f55af22c9e15235c3f2863374a03b19"], "generalStore": {"shareDescriptions":{"2":["{\"module\":\"webStorage\",\"userAgent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36\",\"dateAdded\":1600052849609}","{\"module\":\"webStorage\",\"userAgent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36\",\"dateAdded\":1600846590812}"],"7087bef077dc156afa0903dbaf83144aeb53b701591c84b85427d0cd40ce4343":["{\"module\":\"securityQuestions\",\"questions\":\"whats your password?\",\"dateAdded\":1600835960674}"]},"shareTransfer":{"pointer":"230ff5590f4280072f54de288fce7fcb961f86279fcb12aaffba8cbdf5894088"}}, "scopedStore": {"bf60d4ea3a03c094d96e6aebe48e8f245f55af22c9e15235c3f2863374a03b19":{"ciphertext":"a37a489bbc6aa2e458ab8917e8ae31fc44abb51ad21abc5c1b34d98c738eb2d6b03ce66c23045ade83a1c9da9287dc21cf20d3de3d8bce6af9b2389029192ac8989bac3d1ab2365126f440ffb3af72f18e239e271cf6bf02f0a2742972a3aa0706ef320562d46408c453942dc540771dab7644cc272bd50b174f9fc2f5c057e347ba8dcd5f3c3137dd86eb775504e9b3060576f1aa4b0a84826a7dc0c3c7146a9c4aaaf8d7f1c0f70d0b4a83b79fe378aebff8486f8a98667f58a4b51c6cdd42bf62162026b0f79c3ded6f4e6d8cb6d20be89e4cde2cb7a6725bea48a6a3a00d5f345b2302549554e24609687275d3951e2cd963e8e44d72f3f2bbdff07a37d6","ephemPublicKey":"0477522b2b2d41b2d96f547cd1b11f2477b8a82c9670374661d42fa1720b5f879d396d38dd023bd5986d965ec17275fb49442c2d9829f3b8a84d39ab84c12b40ef","iv":"dd003d7582516f81e3b8627dbadff3ab","mac":"b9cf4cea565ada89a25acb593cb4da54b9fe475fb92535b7da2abb1044f2e181"}}, "tKeyStore": {"ciphertext":"0f1db0bed90a48bd82ac16c043ceb346e0fdbc99e6ffb519c3ac54f7c2000488","ephemPublicKey":"04b3913d61f3fbb824331ecb2d315938707ea6976426c79aaeb1f9cc540b353314eff55097a8dbd31b86278fce995ae05a030dc14a81223776d3dc90ba6b7b4ac5","iv":"f85a2caffaa561270db13aa7f4400df8","mac":"69aafb4619cb5bb4a0f1466a6f2c6931dc4766f88325476e09426cf05c930154"} } ``` ### Modules The extendability of metadata allows for unique modules to be built upon its core data structure. Enabling functionality such as storing more detailed descriptions on shares, syncing data for share transfers, and passwords/user inputs. These modules each take a domain or namespace on each of the stores they interact with and need to be spec-ed out for intropebility across applications. ## Comparisons to existing key/asset management systems Compared to traditional key management, tKey improves on recoverability, usability, and flexibility. It also allows revocability of shares and edits of access structures to a user's key. Today, we do have multi-sigs and smart contract wallets (SCW) that hold assets which provide similar properties. They work well and tKey can be used as an external key to these contructions. Relative to these tools, because tKey revolves around managing a native private key it is far more composable. While an onchain multi-sig/SCW can fufill most functions, there are nuances to consider implementation-wise. For example, being on-chain, they are limited to the layer-1 chain they are implemented on, limiting interoperability with other layer-2 scalability solutions or other blockchains. Deployment fees for smart contract wallets can also be expensive and slow, which increases user-friction. The model is also flexible, and different configurations of SSS thresholds can help to balance convenience, security, and redundancy, according to the user's needs. ### Dark Crystal Compared to Dark Crystal's SSS library/interface, tKey leverages on metadata/ data availble storage layers to allow functionality such as offline updating of thresholds, refreshing and revokablity of shares. ## Future direction ### Proactive Secret Sharing with Threshold Signature Schemes tKey can be implemented with threshold signature schemes such that the key need not be constructed in an existing front-end when signing transactions, which helps to improve security. The initial private key can also be generated via distributed key generation, to ensure that the private key is never reconstructed at all. In this case resharing of shares for a new polynomial could be done through proactive secret sharing schemes with dynamic participants.