dcl_crypto/lib.rs
1/*!
2 * This crate is a port of the original [`@dcl/crypto`](https://github.com/decentraland/decentraland-crypto)
3 * implemented on javascript and provides the necessary tools to create and validate
4 * Decentraland's Authentication Chains.
5 *
6 * ## Usage
7 *
8 * This crate is [on crates.io](https://crates.io/crates/dcl_crypto) and can be
9 * used by adding `dcl_crypto` to your dependencies in your project's `Cargo.toml`.
10 *
11 * ```toml
12 * [dependencies]
13 * dcl_crypto = "0"
14 * ```
15 *
16 * ## Verify a signature
17 *
18 * To verify a signature using a authentication chain, you need the [`Authenticator`](authenticator/struct.Authenticator.html)
19 * and the [`AuthChain`](chain/struct.AuthChain.html) structs.
20 *
21 * The `Authenticator` is the one that will verify the two types of signatures that
22 * can be present on an authchain:
23 * - The signature of the wallet's owner, also referred as personal signature.
24 * - The signature of the smart contract wallet, described on the [EIP-1271](https://eips.ethereum.org/EIPS/eip-1271).
25 *
26 * In order to verify the signature of the smart contract wallet, the `Authenticator`
27 * needs a web3 provider to call the contract.
28 *
29 * ```rust
30 * use dcl_crypto::Authenticator;
31 *
32 * let endpoint = std::env::var("ETHEREUM_MAINNET_RPC").unwrap();
33 * let transport = web3::transports::Http::new(&endpoint).unwrap();
34 * let authenticator = Authenticator::with_transport(&transport);
35 * ```
36 *
37 * If you don't need to verify the signature of the smart contract wallet, you can create
38 * an `Authenticator` without a web3 provider using the [`Authenticator::new()`](authenticator/struct.Authenticator.html#method.new)
39 * method.
40 *
41 * ```rust
42 * use dcl_crypto::Authenticator;
43 *
44 * let authenticator = Authenticator::new();
45 * ```
46 *
47 * Once you have an `Authenticator` you can verify if a given message was signed by the `AuthChain` using the [`verify_signature`](authenticator/struct.Authenticator.html#method.verify_signature) method.
48 *
49 * ```rust
50 * use dcl_crypto::{Authenticator, AuthChain};
51 *
52 * let authenticator = Authenticator::new();
53 * let auth_chain = AuthChain::from_json(r#"[
54 * {
55 * "type": "SIGNER",
56 * "payload": "0x84452bbfa4ca14b7828e2f3bbd106a2bd495cd34",
57 * "signature": ""
58 * },
59 * {
60 * "type": "ECDSA_EPHEMERAL",
61 * "payload": "Decentraland Login\nEphemeral address: 0xB80549D339DCe9834271EcF5F1F1bb141C70AbC2\nExpiration: 2123-03-20T12:36:25.522Z",
62 * "signature": "0x76bf8d3c8ee6798bd488c4bc7ac1298d0ad78759669be39876e63ccfd9af81e31b8c6d8000b892ed2d17eb2f5a2b56fc3edbbf33c6089d3e5148d83cc70ce9001c"
63 * },
64 * {
65 * "type": "ECDSA_SIGNED_ENTITY",
66 * "payload": "QmUsqJaHc5HQaBrojhBdjF4fr5MQc6CqhwZjqwhVRftNAo",
67 * "signature": "0xd71fb5511f7d9116d171a12754b2c6f4c795240bee982511049a14aba57f18684b48a08413ab00176801d773eab0436fff5d0c978877b6d05f483ee2ae36efb41b"
68 * }
69 * ]"#).unwrap();
70 *
71 * authenticator.verify_signature(&auth_chain, "QmUsqJaHc5HQaBrojhBdjF4fr5MQc6CqhwZjqwhVRftNAo"); // future
72 * ```
73 */
74pub mod account;
75pub mod authenticator;
76pub mod chain;
77pub mod identity;
78pub mod util;
79
80pub use account::{Account, Address, Expiration, Signer};
81pub use authenticator::Authenticator;
82pub use chain::{AuthChain, AuthLink};
83pub use identity::Identity;
84pub use web3::Transport as Web3Transport;