Crates.io | ic_siwe |
lib.rs | ic_siwe |
version | 0.1.1 |
source | src |
created_at | 2024-01-23 22:41:14.808376 |
updated_at | 2024-08-28 06:21:02.007508 |
description | Integrate Ethereum wallet-based authentication (SIWE) with applications on the Internet Computer (ICP) platform. |
homepage | https://github.com/kristoferlund/ic-siwe |
repository | https://github.com/kristoferlund/ic-siwe |
max_upload_size | |
id | 1111290 |
size | 426,595 |
ic_siwe
is a Rust library that facilitates the integration of Ethereum wallet-based authentication with applications on the Internet Computer (ICP) platform. The library provides all necessary tools for integrating Sign-In with Ethereum (SIWE) into ICP canisters, from generating SIWE messages to creating delegate identities.
ic_siwe
is part of the ic-siwe project. The goal of the project is to enhance the interoperability between Ethereum and the Internet Computer platform, enabling developers to build applications that leverage the strengths of both platforms.
https://youtu.be/lQV4Otp6Y_s?si=pcDgTenV98JabV9r&t=95
ic_siwe_provider
canisteric_siwe_provider
canisterWhile the ic_siwe
library can be integrated with any Rust based ICP project, using the pre built ic-siwe-provider canister is the easiest way to integrate Ethereum wallet authentication into your application.
The canister is designed as a plug-and-play solution for developers, enabling easy integration into existing ICP applications with minimal coding requirements. By adding the pre built ic_siwe_provider
canister to the dfx.json
of an ICP project, developers can quickly enable Ethereum wallet-based authentication for their applications. The canister simplifies the authentication flow by managing the creation and verification of SIWE messages and handling user session management.
A demo application that uses the ic_siwe_provider
canister to demonstrate the full login flow is available at ic-siwe-react-demo-rust. The demo uses another package from the ic-siwe
project, ic-use-siwe-identity, a React hook and context provider for easy frontend integration with SIWE enabled Internet Computer canisters.
ERC-4361: Sign-In with Ethereum - Off-chain authentication for Ethereum accounts to establish sessions
The SIWE standard defines a protocol for off-chain authentication of Ethereum accounts. The protocol is designed to enable Ethereum wallet-based authentication for applications on other platforms, such as the Internet Computer. At the core of the protocol is the SIWE message, which is a signed message that contains the Ethereum address of the user and some additional metadata. The SIWE message is signed by the user's Ethereum wallet and then sent to the application's backend. The backend verifies the signature and Ethereum address and then creates a session for the user.
ic_siwe
implements most parts of the Sign In with Ethereum (SIWE standard,
EIP-4361 with some notable exceptions:
not-before
, request-id
, resources
- Not implemented. These fields are marked as OPTIONAL in the SIWE standard and are not required for current implementation.Creating a delegate identity using ic_siwe
is a three-step process that consists of the following steps:
An implementing canister is free to implement these steps in any way it sees fit. It is recommended though that implementing canisters follow the login flow described below and implement the SIWE canister interface. Doing so ensures that the canister is compatible with the ic-use-siwe-identity React hook and context provider.
The login flow is illustrated in the following diagram:
┌────────┐ ┌────────┐ ┌─────────┐
│Frontend│ │Canister│ │EthWallet│
User └───┬────┘ └───┬────┘ └────┬────┘
│ Push login button ┌┴┐ │ │
│ ────────────────────────────>│ │ │ │
│ │ │ │ │
│ │ │ siwe_prepare_login(eth_address) ┌┴┐ │
│ │ │ ─────────────────────────────────────────────>│ │ │
│ │ │ └┬┘ │
│ │ │ OK, siwe_message │ │
│ │ │ <─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │
│ │ │ │ │
│ │ │ Sign siwe_message ┌┴┐
│ │ │ ──────────────────────────────────────────────────────────────────────────────────────>│ │
│ │ │ │ │ │
│ │ │ Ask user to confirm │ │ │
│ <───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│ │
│ │ │ │ │ │
│ │ │ OK │ │ │
│ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ >│ │
│ │ │ │ └┬┘
│ │ │ OK, signature │
│ │ │ <─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
│ │ │ │ │
│ │ │────┐ │ │
│ │ │ │ Generate random session_identity │ │
│ │ │<───┘ │ │
│ │ │ │ │
│ │ │ siwe_login(eth_address, │ │
│ │ │ signature, session_identity) ┌┴┐ │
│ │ │ ─────────────────────────────────────────────>│ │ │
│ │ │ │ │ │
│ │ │ │ │────┐ │
│ │ │ │ │ │ Verify signature and eth_address │
│ │ │ │ │<───┘ │
│ │ │ │ │ │
│ │ │ │ │────┐ │
│ │ │ │ │ │ Prepare delegation │
│ │ │ │ │<───┘ │
│ │ │ └┬┘ │
│ │ │ OK, canister_pubkey, delegation_expires │ │
│ │ │ <─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │
│ │ │ │ │
│ │ │ siwe_get_delegation(delegation_expires) ┌┴┐ │
│ │ │ ─────────────────────────────────────────────>│ │ │
│ │ │ └┬┘ │
│ │ │ OK, delegation │ │
│ │ │ <─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │
│ │ │ │ │
│ │ │────┐ │ │
│ │ │ │ Create delegation identity │ │
│ │ │<───┘ │ │
│ └┬┘ │ │
│ OK, logged in with │ │ │
│ Principal niuiu-iuhbi...-oiu │ │ │
│ <─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ │
User ┌───┴────┐ ┌───┴────┐ ┌────┴────┐
│Frontend│ │Canister│ │EthWallet│
└────────┘ └────────┘ └─────────┘
siwe_prepare_login
siwe_prepare_login
method is called by the frontend application to initiate the login flow. The method takes the user's Ethereum address as a parameter and returns a SIWE message together with a nonce. The frontend application uses the SIWE message to prompt the user to sign the message with their Ethereum wallet.login::prepare_login
siwe_login
siwe_login
method is called by the frontend application after the user has signed the SIWE message. The method takes the user's Ethereum address, signature, session identity and nonce as parameters. The method verifies the signature and Ethereum address and prepares the delegation to be fetched in the next step, the siwe_get_delegation
function.login::login
siwe_get_delegation
siwe_get_delegation
method is called by the frontend application after a successful login. The method takes the delegation expiration time as a parameter and returns a delegation.siwe_get_delegation
method is not mirrored by one function in the ic_siwe
library. The creation of delegate identities requires setting the certified data of the canister. This should not be done by the library, but by the implementing canister.ic_siwe
functions: delegation::generate_seed
,delegation::create_delegation
, delegation::create_delegation_hash
, delegation::witness
, delegation::create_certified_signature
.ic_siwe_provider
canister.See the CHANGELOG for details on updates.
Contributions are welcome. Please submit your pull requests or open issues to propose changes or report bugs.
This project is licensed under the MIT License. See the LICENSE file for more details.