--- tags: spec --- This document is a technical description of Web3Auth’s User Key Architecture in our full MPC solution. Its a high-level document, Web3Auth reserves the right to make changes to this document as needed. It is part of a set of documents that describes Web3Auth, others that maybe helpful include: - [Overview of Web3Auth and Application Interactions](https://hackmd.io/@torus/Syyt3oqic) - [MPC Infra Architecture Questionaire](https://hackmd.io/@torus/S1ZaIETic) ## Introduction Many existing non-custodial key management solutions present users with trade-offs between security, convenience, and redundancy. For example, backing up your key increases redundancy during key loss, but reduces security if that backup is stolen. Multisig wallets provide a balance of all three, but are more costly to deploy, are less private, and are not cross-chain. We propose a key architecture, tKey v2, (or just tKey further in this document) that uses MPC to solve the trilemma. Not sacrificing user experience, while retaining end-user autonomy, improving security and control over the private key. We describe the architecture of tKey and detail several core user flows for onboarding, key recovery, and device management. ## Technical Overview tKey manages its user keys in a distributed manner utilizing different factors(or shares) that users manage including user's devices, private inputs, backup locations and cloud service providers. As long as a user has access to 2 out of n (2/n) of these shares, they will be able to access their key. This distributedly secure key is called the $TSSKey$. One of the lost functionalities of a distributedly secure key is the loss of efficient encryption/decryption capabilities. As such the $TSSKey$ is supported by another cryptographic key that's main purpose is to manage metadata pertaining to the user's account, the $metadataKey$. User metadata is strictly supplementary and only helps to facilitate and govern user flows. In particular, metadata does not leak information about the shares of the $TSSKey$ being used to sign transactions. While tKey supports 2/n, 2/2 flows or m/n flows, for the sake of succient illlustration the rest of this document assumes a 2/3 setup. ### The TSS Key ![](https://hackmd.io/_uploads/HJWdw3tLo.png) The user's setup starts by distributedly key generating (DKG) a 2 out of 3 (2/3) 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(z_1)$ "ShareA" 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. 2. **$f_0(1)$ "ShareB" is managed by Web3Auth infrastructure**: This share is kept and managed by OAuth authentication flows in a distributed security model. 3. **$f_0(z_2)$ "ShareC" is a backup 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.). ### The Metadata Key The $metadataKey$ closely mimics the storage of the $TSSKey$, the only difference is that the $metadataKey$ is always reconstructed and used for its encryption/decryption capabilities. It utilizes basic Shamir's Secret Sharing and is initially generated on a users's front-end. The $metadataKey$ utilizes tKey v1 flows which readers can further [reference here](https://docs.tor.us/key-infrastructure/technical-architecture). ### Factor Keys $factorKeys$ enable refresh, multiple key setups, deletion and rotational capabilities on the $tssKey$. $factorKeys$ are randomly generated on different locations or factors that users own, for example their phone, chrome extension, on their cloud, assisting third parties and so on so forth. They are mostly used for data encryption/decryption and as it represents a point of storage, a public address which we can encrypt blobs for that point of storage. As shares to the $tssKey$ and/or $metadataKey$ may rotate, $factorKeys$ allow for a consistant secret to be saved in these different locations. ### Architecture properties Similar to existing web2 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** | Using tKey, since the Web3Auth Infra 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 Web3Auth entity. The user can always reconstruct their private key using $f_0(z_1)$ (device share) and $f_0(z_2)$ (recovery share). - **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** | tKey's base user flow for key usage is indistinguishable from Web2.0 login flow where they'd simply use their OAuth share in combination with their device share. - **Native signatures** | tKey can be used to generate normal private keys to sign messages compatible with all exisiting standards. ## Technical Architecture This segment goes through some of the interactions on a deeper level. Note that these interactions do not cover the cryptographic schemes themselves, those would be found in the Full MPC interaction document. ### Components #### Web3Auth Infrastructure Web3Auth infrasturcture provides a user-specific share/factor 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. It also serves as a persistent data store for storing encrypted metadata, we also call this the metadata layer in following diagrams. #### 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. #### Backup factor/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 trigger a Distributed Key Generation Scheme between the user device and Web3Auth. This generates 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, giving the ability for us to display it to the user. #### 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/HyjENTOLj.png) ShareA is stored on the user's device, ShareB stored on Web3Auth Infrastructure, and ShareC dependent on user input or handled as a recovery share. #### Key usage and access ![](https://hackmd.io/_uploads/HyL54TdIs.png) If a user has logged in previously, he/she access their key by accessing ShareB via a session token handshake and utilzing it with ShareA on the user's current device using to sign Threshold Signaures. ### Expanding the number of shares (adding a device) In the case of a new device the user needs to conduct a Proactive Secret Sharing, a refresh scheme to generate a new factor in a distributed manner. This example goes through the setup on a new user's device with an existing device in hand. This can also be conducted with a user's backup factor, ie.e ShareC. ![](https://hackmd.io/_uploads/HyJVnpOUs.png) On reconstruction of $f(z)$ on the new device we set ShareD to $f(z_4)$. ### Share resharing and revokability Utilizing the metadata 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 after a refresh/PSS. 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 metadata 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 gets access to their key on device A via session token. We utilize a public key based encryption scheme (eg. ECIES). Via the PSS scheme 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 metadata 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. ### Design The design of the metadata data structures minimizes assumptions on the metadata layer. In particular, we only assume that the metadata 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 metadata 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.