forked from cryptape/ckb-auth
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ckb-auth-cli support dogecoin * Add dogecoin doc
- Loading branch information
Showing
7 changed files
with
234 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# [Dogecoin](../README.md) | ||
|
||
To work with Dogecoin, utilize the official command-line tool: [DogecoinCore](https://github.com/dogecoin/dogecoin/tree/v1.14.6). | ||
|
||
Dogecoin shares many similarities with [Bitcoin](./bitcoin.md), including its signature algorithm and command-line tools. Here, we will focus on the distinctive aspects that set Dogecoin apart. | ||
|
||
## Installation and Configuration | ||
[Download](https://github.com/dogecoin/dogecoin/releases/tag/v1.14.6) | ||
- It's essential to note that, much like `BitcoinCore` on Mac, Dogecoin provides GUI tools exclusively. | ||
- For configuration, you can use the official default settings. If you prefer not to synchronize with online nodes, you can add `proxy=127.0.0.1:12345` to the configuration, using a non-existent proxy. | ||
|
||
Start Dogecoin with the following command: | ||
``` | ||
./dogecoind -daemonwait | ||
``` | ||
|
||
## Generate a Key | ||
|
||
When using dogecoin-cli for the first time, the `getaddressesbyaccount` command will automatically generate a new key group. Account information is stored in `wallet.dat`. | ||
|
||
```bash | ||
./dogecoin-cli getaddressesbyaccount "" | ||
``` | ||
|
||
``` | ||
[ | ||
"DNF59P3dX2S2i188aPfBfL4aecs9gWtBt8" | ||
] | ||
``` | ||
|
||
A Dogecoin address always begins with the letter `D`, followed by content encoded in Base58, which includes the `public key hash` and a `checksum`. [You can find the code to parse and check addresses here](../tools/ckb-auth-cli/src/chain_command/dogecoin.rs#L52). | ||
|
||
## Sign | ||
|
||
Dogecoin Core supports signing and verifying messages. | ||
|
||
```bash | ||
./dogecoin-cli signmessage DNF59P3dX2S2i188aPfBfL4aecs9gWtBt8 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff | ||
``` | ||
|
||
Output: | ||
``` | ||
IIu/kxASl/W/5o3bjTD4KKBCQKcsDPUdp0+1Xu4vy0FhcpSfsIPu5Mi90VV0FGsN2gdlUvQFswTI886CeKNp7So= | ||
``` | ||
|
||
The output signature data is Base58 encoded and can be used directly in ckb-auth. | ||
|
||
To verify with `Dogecoin Core`: | ||
|
||
```bash | ||
./dogecoin-cli verifymessage DNF59P3dX2S2i188aPfBfL4aecs9gWtBt8 IIu/kxASl/W/5o3bjTD4KKBCQKcsDPUdp0+1Xu4vy0FhcpSfsIPu5Mi90VV0FGsN2gdlUvQFswTI886CeKNp7So= 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff | ||
``` | ||
|
||
Output: | ||
``` | ||
true | ||
``` | ||
|
||
## Verify | ||
|
||
To verify in ckb-auth-cli: | ||
|
||
```bash | ||
ckb-auth-cli dogecoin verify -a DNF59P3dX2S2i188aPfBfL4aecs9gWtBt8 -s IIu/kxASl/W/5o3bjTD4KKBCQKcsDPUdp0+1Xu4vy0FhcpSfsIPu5Mi90VV0FGsN2gdlUvQFswTI886CeKNp7So= -m 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff | ||
``` | ||
|
||
Verification in Dogecoin is quite similar to Bitcoin, with the exception of address handling. For the most part, Bitcoin code can be used. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use crate::{ | ||
auth_script::run_auth_exec, | ||
utils::{calculate_sha256, decode_string}, | ||
}; | ||
use crate::{BlockChain, BlockChainArgs}; | ||
use anyhow::{anyhow, Error}; | ||
use ckb_auth_rs::AuthAlgorithmIdType; | ||
use clap::{arg, ArgMatches, Command}; | ||
|
||
pub struct DogecoinLockArgs {} | ||
|
||
impl BlockChainArgs for DogecoinLockArgs { | ||
fn block_chain_name(&self) -> &'static str { | ||
"dogecoin" | ||
} | ||
|
||
fn reg_parse_args(&self, cmd: Command) -> Command { | ||
cmd | ||
} | ||
fn reg_generate_args(&self, cmd: Command) -> Command { | ||
cmd | ||
} | ||
fn reg_verify_args(&self, cmd: Command) -> Command { | ||
cmd.arg(arg!(-a --address <PUBKEYHASH> "The dogecoin address")) | ||
.arg(arg!(-s --signature <SIGNATURE> "The signature to verify")) | ||
.arg(arg!(-m --message <MESSAGE> "The signature message")) | ||
} | ||
|
||
fn get_block_chain(&self) -> Box<dyn BlockChain> { | ||
Box::new(DogecoinLock {}) | ||
} | ||
} | ||
|
||
pub struct DogecoinLock {} | ||
|
||
impl BlockChain for DogecoinLock { | ||
fn parse(&self, _operate_mathches: &ArgMatches) -> Result<(), Error> { | ||
Err(anyhow!("dogecoin does not parse")) | ||
} | ||
|
||
fn generate(&self, _operate_mathches: &ArgMatches) -> Result<(), Error> { | ||
Err(anyhow!("dogecoin does not generate")) | ||
} | ||
|
||
fn verify(&self, operate_mathches: &ArgMatches) -> Result<(), Error> { | ||
let address = operate_mathches | ||
.get_one::<String>("address") | ||
.expect("Get address from args"); | ||
let address = bs58::decode(&address).into_vec().expect("get base58"); | ||
|
||
// https://github.com/dogecoin/dogecoin/blob/v1.14.6/src/chainparams.cpp#L167 | ||
if address[0] != 30 { | ||
return Err(anyhow!("The first byte of address is not 30")); | ||
} | ||
|
||
let checksum = calculate_sha256(&calculate_sha256(&address[..21])); | ||
if checksum[..4] != address[21..] { | ||
return Err(anyhow!("Address Checksum failed,")); | ||
} | ||
|
||
let signature = decode_string( | ||
operate_mathches | ||
.get_one::<String>("signature") | ||
.expect("Get signature from args"), | ||
"base64", | ||
) | ||
.expect("decode signature from base64 string"); | ||
|
||
let message = hex::decode( | ||
operate_mathches | ||
.get_one::<String>("message") | ||
.expect("Get message from args"), | ||
) | ||
.expect("decode message"); | ||
|
||
if address.len() < 21 { | ||
return Err(anyhow!("dogecoin address invalidate")); | ||
} | ||
if signature.len() != 65 { | ||
return Err(anyhow!("dogecoin signature size is not 65")); | ||
} | ||
if message.len() != 32 { | ||
return Err(anyhow!("dogecoin message size is not 32")); | ||
} | ||
|
||
let pubkey_hash = &address[1..21]; | ||
|
||
run_auth_exec( | ||
AuthAlgorithmIdType::Dogecoin, | ||
pubkey_hash, | ||
&message, | ||
&signature, | ||
)?; | ||
|
||
println!("Success"); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters