Skip to content

Commit

Permalink
Rename some interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
XuJiandong committed Jan 10, 2024
1 parent 5031600 commit 917f0ed
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion c/ckb_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int ckb_auth_prepare(CkbEntryType *entry, uint8_t algorithm_id,
}
}

int ckb_auth(uint8_t *prefilled_data, CkbEntryType *entry, CkbAuthType *id,
int ckb_auth(CkbEntryType *entry, uint8_t *prefilled_data, CkbAuthType *id,
const uint8_t *signature, uint32_t signature_size,
const uint8_t *message32) {
int err = 0;
Expand Down
4 changes: 2 additions & 2 deletions ckb-auth-rs/src/ckb_auth_dl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ pub fn ckb_auth_dl(
}
}

pub fn ckb_auth_load_prefilled_data(
pub fn ckb_auth_prepare(
entry: &CkbEntryType,
algorithm_id: AuthAlgorithmIdType,
prefilled_data: &mut [u8],
algorithm_id: AuthAlgorithmIdType,
len: &mut usize,
) -> Result<(), CkbAuthError> {
let func: Symbol<CkbLoadPrefilledData> = CKBDLLoader::get().get_validate_func(
Expand Down
4 changes: 2 additions & 2 deletions ckb-auth-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ mod generate_sighash_all;
#[cfg(target_arch = "riscv64")]
pub use ckb_auth::ckb_auth;

#[cfg(target_arch = "riscv64")]
pub use ckb_auth_dl::{ckb_auth_load_prefilled_data, RECOMMEND_PREFILLED_LEN};
#[cfg(all(feature = "enable-dynamic-library", target_arch = "riscv64"))]
pub use ckb_auth_dl::{ckb_auth_prepare, RECOMMEND_PREFILLED_LEN};

#[cfg(target_arch = "riscv64")]
pub use crate::generate_sighash_all::generate_sighash_all;
Expand Down
8 changes: 4 additions & 4 deletions docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ The invocation method is the same as that of `Spawn`.
### High Level APIs
The following API can combine the low level APIs together:
```C
int ckb_auth_load_prefilled_data(uint8_t auth_algorithm_id, uint8_t *prefilled_data, size_t *len);
int ckb_auth(EntryType* entry, CkbAuthType *id, uint8_t *signature, uint32_t signature_size, const uint8_t *message32)
int ckb_auth_prepare(uint8_t auth_algorithm_id, uint8_t *prefilled_data, size_t *len);
int ckb_auth(EntryType* entry, uint8_t* prefilled_data, CkbAuthType *id, uint8_t *signature, uint32_t signature_size, const uint8_t *message32)
```
Most of developers only need to use these functions without knowing the low level APIs.
Expand All @@ -263,10 +263,10 @@ Dependencies name: `ckb-auth-rs`
#### API Description
``` rust
pub fn ckb_auth_load_prefilled_data(auth_algorithm_id: u8, prefilled_data: &mut[u8]);
pub fn ckb_auth_prepare(entry: &CkbEntryType, auth_algorithm_id: u8, prefilled_data: &mut[u8]);
pub fn ckb_auth(
prefilled_data: &[u8],
entry: &CkbEntryType,
prefilled_data: &[u8],
id: &CkbAuthType,
signature: &[u8],
message: &[u8; 32],
Expand Down
4 changes: 2 additions & 2 deletions tests/auth-c-lock/auth_c_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ int main() {
}
// ckb_auth can be invoked multiple times for different signatures.
// Here we use the same one to demo the usages.
ret = ckb_auth(g_secp_data, &entry, &auth, lock_bytes_seg.ptr,
ret = ckb_auth(&entry, g_secp_data, &auth, lock_bytes_seg.ptr,
lock_bytes_seg.size, msg32);
if (ret) {
return ret;
}
ret = ckb_auth(g_secp_data, &entry, &auth, lock_bytes_seg.ptr,
ret = ckb_auth(&entry, g_secp_data, &auth, lock_bytes_seg.ptr,
lock_bytes_seg.size, msg32);
if (ret) {
return ret;
Expand Down
27 changes: 20 additions & 7 deletions tests/auth-rust-lock/contracts/auth-rust-demo/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ use crate::error::Error;

use ckb_auth_rs::{
ckb_auth, generate_sighash_all, AuthAlgorithmIdType, CkbAuthError, CkbAuthType, CkbEntryType,
EntryCategoryType, RECOMMEND_PREFILLED_LEN, ckb_auth_load_prefilled_data,
EntryCategoryType,
};
#[cfg(feature = "enable-dynamic-library")]
use ckb_auth_rs::{ckb_auth_prepare, RECOMMEND_PREFILLED_LEN};
use ckb_std::{
ckb_constants::Source,
ckb_types::{bytes::Bytes, core::ScriptHashType, prelude::*},
high_level::{load_script, load_witness_args},
};

// use ckb_std::debug;
#[cfg(feature = "enable-dynamic-library")]
static mut SECP_DATA: [u8; RECOMMEND_PREFILLED_LEN] = [0u8; RECOMMEND_PREFILLED_LEN];


pub fn main() -> Result<(), Error> {
let mut pubkey_hash = [0u8; 20];
let auth_id: u8;
Expand Down Expand Up @@ -85,12 +86,24 @@ pub fn main() -> Result<(), Error> {
.map_err(|f| CkbAuthError::from(f))
.unwrap(),
};
let mut len: usize = RECOMMEND_PREFILLED_LEN;
ckb_auth_load_prefilled_data(&entry, id.algorithm_id.clone(), unsafe { &mut SECP_DATA }, &mut len)?;
ckb_auth(&entry, unsafe { &mut SECP_DATA } , &id, &signature, &message)?;
#[cfg(feature = "enable-dynamic-library")]
let secp_data = {
let mut len: usize = RECOMMEND_PREFILLED_LEN;
ckb_auth_prepare(
&entry,
unsafe { &mut SECP_DATA },
id.algorithm_id.clone(),
&mut len,
)?;
unsafe { &mut SECP_DATA }
};
#[cfg(not(feature = "enable-dynamic-library"))]
let secp_data = &mut [0u8; 1];

ckb_auth(&entry, secp_data, &id, &signature, &message)?;
// ckb_auth can be invoked multiple times for different signatures. Here we
// use the same one to demo the usage.
ckb_auth(&entry, unsafe { &mut SECP_DATA }, &id, &signature, &message)?;
ckb_auth(&entry, secp_data, &id, &signature, &message)?;

Ok(())
}

0 comments on commit 917f0ed

Please sign in to comment.