5个版本
0.1.4 | 2023年11月15日 |
---|---|
0.1.3 | 2023年11月8日 |
0.1.2 | 2023年11月8日 |
0.1.1 | 2023年11月7日 |
0.1.0 | 2023年11月7日 |
356 in 密码学
每月29次下载
130KB
2.5K SLoC
loopring_sign
loopring_sign
是一个基于Rust的工具,用于生成与Loopring API交互的EdDSA签名。它补充了官方Python参考实现,该实现可在Loopring仓库中的 loopring-v3
分支下找到,位于 hello_loopring/sdk/ethsnarks。
此工具使用Poseidon散列函数和Baby Jubjub椭圆曲线(由EIP-2494指定)生成与Loopring协议兼容的EdDSA签名。
⚠️ 开发状态 & 安全注意事项
🚧 积极开发中:此crate目前正在积极开发中。因此,它可能包含错误或不完整的特性。请自行承担风险使用。
🔒 安全警告:此crate需要使用您的私钥。请确保您了解相关的风险,并且永远不要将您的私钥与不受信任的第三方共享。
安装
将其添加到您的Cargo.toml中
[dependencies]
loopring_sign = "0.1.4"
示例1:生成EdDSA签名
use loopring_sign::poseidon::eddsa::generate_eddsa_signature;
fn main() {
// private key of loopring layer 2
let l2_key = "0x087d254d02a857d215c4c14d72521f8ab6a81ec8f0107eaf16093ebb7c70dc50";
// request params
let data: &[(&str, &str)] = &[("accountId", "12345")];
// GET, DELETE, POST or PUT
let request_type = "POST";
// API-endpoint
let url: &str = "https://api3.loopring.io/api/v3/apiKey";
let sig = generate_eddsa_signature(request_type, url, data, l2_key);
// 0x15fdcda3ca2965d2ae43739cc6740e50c08d3f756c6161bcedb10fbc05290e000f3bc31e2293ba91ca7ac55cd20a86ae3541d3dfed63896cd474015ec60b8d40274f98b2d0a87ebf8cd0ee16dc9ec953a229cf0d6b2b61867ca80ba6e8ae1ed3
println!("{}", &sig);
// Do something with the sig
}
示例2:计算L2私钥
use loopring_sign::poseidon::keygen::generate_l2_keys;
fn main() {
// 1. The user must retrieve a keyseed from the Loopring API endpoint /api/v3/account.
// 2. The user must sign the keyseed using their L1 (Layer 1) key to generate an ECDSA signature.
// 3. The user can then derive their L2 (Layer 2) key from the ECDSA signature and therefore interacting with the L2 Protocol
let signed_message_ecdsa = String::from("0xf8214f068c55d1bebf1fbefced91eba5f4bbe14315e1ad71f61f21e094f5853a12eba239aeaa77538ae458eebe49ca2b732d211bf0943095b3502a3b0e6a08cd1c");
let account = generate_l2_keys(signed_message_ecdsa).unwrap();
assert_eq!(
account.private_key.as_str(),
"0x001fa186947c8c644cd11078f67e0bb21656432f55c4df76997b6acab2abda7f"
);
assert_eq!(
account.public_key_x.as_str(),
"0x29d178cdd6a40cd900c41565b6057a1d12c00a8c41ad367e2fe0100aab00fbe3"
);
assert_eq!(
account.public_key_y.as_str(),
"0x29e339a045af33d5729eab3b64c617e6a78dcfd0988f95f215d443d77a864b9c"
);
}
许可证
本项目受
鸣谢
特别感谢leppaludi和fudgey。他们在Go和C#中的实现提供了额外的视角,并为 loopring_sign
提供了灵感。查看他们的仓库以获取Go和C#实现
- Go实现:go-loopring-sig
- C#实现:PoseidonSharp
依赖关系
~3–4MB
~104K SLoC