显示软件包…

1 个不稳定版本

0.1.0 2020年1月9日

#49#decentralized-identity

MIT 许可证

6KB
79

oin

doc Crates.io Crates.io LICENSE

每个用户在 oin 中都有一个 ed25519 密钥对,验证签名而不是用户名/密码。

授权模式

use ed25519_dalek::{Keypair, PublicKey, SecretKey, PUBLIC_KEY_LENGTH};
use oin::Identity;

fn main() {
    // sk is for client
    // id if for server
    let (mut id, sk) = Identity::new();
    let client = Keypair {
        secret: SecretKey::from_bytes(&sk).unwrap(),
        public: PublicKey::from_bytes(&id.pkey).unwrap(),
    };

    // 1. client send auth request
    // 2. server receive the request and response a token
    let token = Identity::token();
    let sig = client.sign(&token).to_bytes();

    // 3. client sign the token and send it back to the server
    let dev = [0; PUBLIC_KEY_LENGTH];
    assert!(id.auth(dev, token, sig).is_ok());

    // 4. login successfully.

    // more checks
    let tk2 = Identity::token();
    assert!(id.state(dev, token).is_ok());
    assert!(id.update(dev, tk2).is_ok());
    assert!(id.state(dev, tk2).is_ok());
}

待办事项

  • ser && de

依赖项

~4MB
~76K SLoC