feat: Add signature functionality to ContractSigner
- Add `signature_data` field to `ContractSigner` to store base64 encoded signature image data. Allows for storing visual signatures alongside electronic ones. - Implement `sign` method for `ContractSigner` to handle signing with optional signature data and comments. Improves the flexibility and expressiveness of the signing process. - Add Rhai functions for signature management, including signing with/without data and clearing signature data. Extends the Rhai scripting capabilities for contract management. - Add comprehensive unit tests to cover the new signature functionality. Ensures correctness and robustness of the implementation. - Update examples to demonstrate the new signature functionality. Provides clear usage examples for developers.
This commit is contained in:
@@ -159,5 +159,66 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Demonstrate signature functionality
|
||||
println!("\n--- Signature Functionality Demo ---");
|
||||
|
||||
// Simulate signing with signature data
|
||||
if let Some(signer_to_sign) = contract.signers.get_mut(1) {
|
||||
println!("\nBefore signing:");
|
||||
println!(
|
||||
" Signer: {} ({})",
|
||||
signer_to_sign.name, signer_to_sign.email
|
||||
);
|
||||
println!(" Status: {:?}", signer_to_sign.status);
|
||||
println!(" Signed at: {:?}", signer_to_sign.signed_at);
|
||||
println!(" Signature data: {:?}", signer_to_sign.signature_data);
|
||||
|
||||
// Example base64 signature data (1x1 transparent PNG)
|
||||
let signature_data = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==".to_string();
|
||||
|
||||
// Sign the contract with signature data
|
||||
signer_to_sign.sign(
|
||||
Some(signature_data.clone()),
|
||||
Some("I agree to all terms and conditions.".to_string()),
|
||||
);
|
||||
|
||||
println!("\nAfter signing:");
|
||||
println!(" Status: {:?}", signer_to_sign.status);
|
||||
println!(" Signed at: {:?}", signer_to_sign.signed_at);
|
||||
println!(" Comments: {:?}", signer_to_sign.comments);
|
||||
println!(
|
||||
" Signature data length: {} characters",
|
||||
signer_to_sign
|
||||
.signature_data
|
||||
.as_ref()
|
||||
.map_or(0, |s| s.len())
|
||||
);
|
||||
println!(
|
||||
" Signature data preview: {}...",
|
||||
signer_to_sign
|
||||
.signature_data
|
||||
.as_ref()
|
||||
.map_or("None".to_string(), |s| s
|
||||
.chars()
|
||||
.take(50)
|
||||
.collect::<String>())
|
||||
);
|
||||
}
|
||||
|
||||
// Demonstrate signing without signature data
|
||||
if let Some(first_signer) = contract.signers.get_mut(0) {
|
||||
println!("\nSigning without signature data:");
|
||||
println!(" Signer: {}", first_signer.name);
|
||||
|
||||
first_signer.sign(
|
||||
None,
|
||||
Some("Signed electronically without visual signature.".to_string()),
|
||||
);
|
||||
|
||||
println!(" Status after signing: {:?}", first_signer.status);
|
||||
println!(" Signature data: {:?}", first_signer.signature_data);
|
||||
println!(" Comments: {:?}", first_signer.comments);
|
||||
}
|
||||
|
||||
println!("\nLegal Contract Model demonstration complete.");
|
||||
}
|
||||
|
Reference in New Issue
Block a user