0x4007 / ubiquity-rpc-provider

0 stars 0 forks source link

Deterministic Signing Key Generation - Using GitHub User ID with a Server-Side Secret #1

Open 0x4007 opened 6 days ago

0x4007 commented 6 days ago

Using GitHub User ID with a Server-Side Secret

Overview:

Approach:

Steps:

  1. Server-Side Secret: Generate a random secret key (app_secret) for your application.
  2. Salt Derivation: On the server, compute a salt using HMAC with app_secret and the user's GitHub User ID.
    • salt = HMAC_SHA256(app_secret, github_user_id)
  3. Provide Salt to Client: Send the derived salt securely to the client upon authentication.
  4. Key Generation on Client: Use the salt to derive the private key in the browser.

Security Considerations:

Advantages:

Implementing Device-Specific Keys:

Conclusion:

Implementation Steps

  1. Server-Side Setup:

    • Generate and securely store an app_secret.
    • Implement an API endpoint for authentication that:
      • Authenticates the user via GitHub OAuth.
      • Retrieves the user's GitHub User ID.
  2. Salt Derivation:

    • Compute salt = HMAC_SHA256(app_secret, github_user_id) on the server.
    • Send the salt to the client securely over HTTPS.
  3. Client-Side Key Generation:

    • Device Identifier:
      • Generate a persistent device_id on the client (e.g., UUID stored in local storage).
      • Optionally, allow users to name their devices for easier management.
    • Device-Specific Salt:
      • Compute device_salt = HMAC_SHA256(salt, device_id)
    • Private Key Derivation:
      • Use a KDF like Argon2 or PBKDF2 with device_salt to derive the private key.
      • Ensure the derived key is suitable for ECDSA on the secp256k1 curve used by Ethereum.
  4. Gnosis Safe Integration:

    • Initial Setup:
      • On first login, create a Gnosis Safe wallet for the user if they don't already have one.
      • Set the master owner as a key derived from salt without the device_id (i.e., the master key).
    • Adding Device Keys:
      • Add the device-specific public keys as additional owners/signers to the Gnosis Safe.
      • Set the threshold according to your security model.
  5. Claiming Rewards:

    • When a user completes a task and a payment permit is generated:
      • The user logs in with GitHub on their device.
      • The device-specific key is used to sign the transaction to claim the reward.
      • The transaction is executed via the Gnosis Safe, ensuring funds are securely managed.
  6. User Experience Enhancements:

    • Seamless Authentication: Users only need to log in with GitHub; key generation happens behind the scenes.
    • Device Management: Provide a dashboard where users can see and manage their devices (e.g., revoke access if a device is lost).
    • Recovery Options: Since the master key is derived from salt, users can recover access by logging in with GitHub on a new device.

Security Considerations

0x4007 commented 6 days ago

@whilefoo maybe you can set up a Cloudflare Worker to be the backend for this idea? I have the client code almost ready

whilefoo commented 5 days ago

Since we know the app_secret and the user's ID, I think an additional password would ensure that even we can't access their wallet. For example the user calls the API endpoint which generates a salt (hash), then the user's browser/app derives a new salt using the previous salt and user's password. Using this method also ensures that if the app_secret ever gets leaked, the attackers can't access the users' wallets.

Protecting app_secret:

  • Must remain confidential on the server.
  • Rotate the secret periodically and manage salts accordingly.

We can't rotate the secret otherwise we will effectively generate a new wallet for all users and they will lose access to their previous wallet.

  • Compute salt = HMAC_SHA256(app_secret, github_user_id) on the server.

HMAC_SHA256 is not suitable for this since it's meant to be used for message signature and verification, a plain SHA256 will do.

What's the intended flow after the user claims the reward? Since this is intended for users that are not familiar with crypto, how will they off-ramp the reward?

0x4007 commented 5 days ago

Off ramp in the near future: payment cards

Mid term: some hacks using stripe/paypal etc

In the long term: we can offer fiat banking, leveraging a partnership of some sort, but it seems like that comes with a ton of strings attached so we will see where we are at connections wise and financially.

whilefoo commented 4 days ago

Do you have a repo for it? This issue seems to be in the wrong repo

0x4007 commented 4 days ago

https://github.com/0x4007/ubiquity-rpc-provider/pull/2