Enabling Seamless In-App Crypto Micro-Transactions with Sessions Keys
By: Jason Goldberg
Tags: Technology, Payments, Ethereum, Cryptocurrency, Blockchain

Building Blocks

There are several building blocks that make transaction signing with session keys possible. First, users hold tokens in a non-custodial crypto wallet on their mobile device. The crypto wallet is integrated into apps using the OST Wallet SDK.

Access to tokens is managed via a Token Holder contract. Each user has one TH contract per token. For example, if Uber launched a token, a user holding UBER tokens would have an UBER Token Holder contract. The TH contract is owned and controlled by a users Device Manager contract. This is a multisig contract based on GnosisSafe and enables support for multiple devices; the public addresses of device keys are whitelisted in the DM contract. Device keys are set as the owners of the DM contract. Session keys are generated on the device for the purpose of signing messages that act as a carrier of transaction information. These messages are sent to a user’s TH contract where the signature is verified and a Token Rule execution request is initiated. The fact that an active and authorised session key exists allows the Token Holder to execute transactions on the user’s behalf, as per EIP-1077 Executable Signed Messages. Note: For a session key to be valid and its signed messages accepted, it’s public key must first be whitelisted in a users TH contract. This is done by the DM contract using an authorized device key.

Mobile-First Approach

We opted for a mobile-first approach to leverage the security features of modern mobile devices such as biometrics (fingerprint and facial recognition), Android Keystore and iOS Secure Enclave to securely generate and store cryptographic keys. Device and session keys are encrypted using Secure Enclave and Keystore and securely stored on the device. Device keys cannot be shared across apps.

*The non-custodial wallet is secured via a 6-digit PIN or biometrics. A user needs to use either to unencrypt device private keys on device. The 6-digit PIN is one of three inputs that is used to recover a wallet in the case that a users device is lost or stolen. There is no need for a user to remember her 12-word mnemonic seed phrase.

Token Holder contract

Each user is represented by a smart contract, the Token Holder contract. The TH contract

Holds the tokens for the user on blockchain

Has a configured owner, the Device Manager multisig contact

Can have multiple session keys whitelisted (each with different blockheights and maximum amount per transaction)

Device Manager Contract

Device Manager enables support for multiple devices. The DM contract whitelists session keys in a users TH contract using an authorised device key. Once whitelisted, those session keys can be used to sign messages that are sent to a user’s Token Holder contact.

Session Keys

Session keys own the operations of the Token Holder contract and are authorized by a user’s Device Manager contract to sign messages. Session keys are created and stored on a device in the same way as device keys. In theory, session keys could be managed less securely because of limited spending power and expiration time. However, OST Wallet SDK doesn’t do that and stores them in the most secure way possible.

Session keys are defined for a predetermined amount of time (blockheight) and with a defined maximum spend per transaction. Once the time limit is reached, user authorizes a new session key with biometrics or 6-digit PIN.

Executing Transactions

Whenever a user does an action, a message signed by an authorized session key is sent from the user’s device to the Token Holder and a Token Rule execution request is initialized. The TH contract

Verifies the message signature, i.e. that the request is initiated by an authorized session key

Approves Token Rule for spending

Calls Custom Rule method, if applicable

Signs the transaction on the user’s behalf

Signed transactions are picked up by facilitators and submitted to OST Platform side chains. The facilitators calculate and pay for the cost (gas) of the transaction. As such, the user does not need to hold the base currency of the chain to pay for fees.

Advanced users can manually revoke active sessions, revoke other authorized devices and sign out of the Token Holder thereby revoking all sessions.

How to Experience the OST Platform Session Keys