Download the PHP package marzsv/sv-dte-signer without Composer
On this page you can find all versions of the php package marzsv/sv-dte-signer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marzsv/sv-dte-signer
More information about marzsv/sv-dte-signer
Files in marzsv/sv-dte-signer
Package sv-dte-signer
Short Description PHP SDK for signing Documentos Tributarios Electrónicos (DTE) for El Salvador using JWS RS512
License MIT
Informations about the package sv-dte-signer
DTE Signer PHP SDK
A PHP SDK for signing and verifying Documentos Tributarios Electrónicos (DTE) for El Salvador using JWS RS512 digital signatures.
Project Status
✅ Production Ready - All core features implemented and tested ✅ MH Certificate Support - Full support for Ministerio de Hacienda certificate format ✅ Standards Compliant - Follows El Salvador DTE specifications ✅ Working Examples - Ready-to-run examples with test certificates ✅ Test Coverage - 37 tests, 90+ assertions, 100% pass rate 🔒 Security - Secure memory handling and input validation
Features
- ✅ Local signing: No external servers or JVM required
- ✅ Signature verification: Verify and extract content from signed DTEs
- ✅ JWS RS512: Compliant with El Salvador DTE specifications
- ✅ MH Certificate Support: Full support for Ministerio de Hacienda XML format
- ✅ Standards Compliant: Follows El Salvador DTE specifications
- ✅ Flexible input: Accept JSON directly or from files
- ✅ Certificate validation: XML certificate parsing and validation
- ✅ Error handling: Standardized error codes (COD_803, COD_812, etc.)
- ✅ Security: Secure memory handling and input validation
- ✅ Performance: <500ms signing time for typical DTEs
- ✅ Modern PHP: 8.1+ with full type safety and PSR-12 compliance
- ✅ Easy testing: Includes mock certificate generator for development
Quick Test Setup
For Testing and Development
-
Clone and install:
-
Generate test certificates:
-
Run signing example:
-
Run verification example:
- Run all tests:
For Production Use
Install via Composer:
Requirements
- PHP 8.1 or higher
- OpenSSL extension
- libxml extension
Quick Start
Basic Usage
Using JSON Files
Custom Certificate Directory
DTE Verification
The SDK also provides functionality to verify signed DTEs and extract their original content.
Basic Verification
Extract Payload Without Verification
Custom Certificate Directory for Verification
Certificate Setup
-
Certificate Format: Certificates must be XML files with the following structure:
-
File Naming: Certificate files must be named
{NIT}.crt(e.g.,12345678901234.crt) - Directory: Place certificates in the
certificates/directory or specify a custom path
API Reference
DteSigner Class
Constructor
Parameters:
$certificateDirectory: Path to the directory containing certificate files
sign()
Parameters:
$input: Either an associative array with signing data or a file path to JSON
Returns:
- Success response:
{'success': true, 'message': '...', 'data': 'signed_jws'} - Error response:
{'success': false, 'message': '...', 'errorCode': 'COD_XXX', 'errors': [...]}
DteVerifier Class
Constructor
Parameters:
$certificateDirectory: Path to the directory containing certificate files
verify()
Parameters:
$jwsToken: The JWS token to verify$nit: The 14-digit NIT of the certificate used for signing
Returns:
- Success response:
{'success': true, 'message': '...', 'data': array} - Error response:
{'success': false, 'message': '...', 'errorCode': 'COD_XXX', 'errors': [...]}
extractPayload()
Parameters:
$jwsToken: The JWS token to extract payload from
Returns:
- Success response:
{'success': true, 'message': '...', 'data': array} - Error response:
{'success': false, 'message': '...', 'errorCode': 'COD_XXX', 'errors': [...]}
⚠️ Warning: This method does not verify the signature. Use only when signature verification is not required.
Request Format
Error Codes
| Code | Description |
|---|---|
| COD_803 | Validation error |
| COD_812 | Certificate not found |
| COD_813 | Invalid certificate |
| COD_814 | Password mismatch |
| COD_815 | Signing error |
| COD_816 | JSON encoding error |
| COD_820 | Verification error |
| COD_500 | Unexpected error |
Example Response
Successful Signing Response
JWS Token Structure
The signed JWS token follows the standard format: header.payload.signature
- Header:
{"typ":"JWT","alg":"RS512"}(Base64URL encoded) - Payload: DTE JSON data as pretty-printed string (Base64URL encoded)
- Signature: RSA-SHA512 signature (Base64URL encoded)
Error Response Example
Successful Verification Response
Verification Error Response
Examples
See the examples/ directory for working examples:
- Basic Usage:
examples/basic_usage.php - File Usage:
examples/file_usage.php - Verification Usage:
examples/verification_usage.php - Error Handling:
examples/error_handling.php
Running Examples
Prerequisites: Make sure you have generated test certificates first:
Then run any example:
Expected output: Examples will demonstrate signing, verification, and error handling with detailed output showing the complete process.
Testing
Test Results
✅ 37 tests | ✅ 90+ assertions | ✅ 100% pass rate | ⚡ <100ms execution time
Run the test suite:
Run with coverage:
Run static analysis:
Run all checks (tests + analysis):
Test Coverage
- Unit tests for all core components (signing and verification)
- Integration tests with mock certificates
- Signature verification and payload extraction tests
- Error handling validation
- Request/response format verification
Security Considerations
- 🔐 Certificates: Store certificates securely with proper file permissions
- 🔒 Passwords: Use strong passwords and secure password management
- 🚫 Logging: Never log passwords or private keys
- ✅ Validation: Always validate input data
- 🧹 Memory: Sensitive data is cleared from memory after use
Production Readiness
✅ Ready for Production
- [x] El Salvador DTE specification compliance
- [x] JWS RS512 signing and verification implementation
- [x] Input validation and error handling
- [x] Security best practices implemented
- [x] Performance requirements met (<500ms)
- [x] Comprehensive unit and integration tests
- [x] PSR-12 code standards
🔧 Production Setup Checklist
- [ ] Use real certificates from Ministro de Hacienda de El Salvador
- [ ] Secure certificate storage with proper permissions (600/700)
- [ ] Environment-specific configuration
- [ ] Production logging setup (without sensitive data)
- [ ] Error monitoring and alerting
- [ ] Performance monitoring
- [ ] Regular security updates
📋 Dependencies
- Runtime: PHP 8.1+, OpenSSL, libxml
- Library: firebase/php-jwt v6.11+ for JWS implementation
- Compatible: Tested with PHP 8.4.11
- Development: PHPUnit 10.5+, PHPStan 2 (level 10) + strict-rules for quality assurance
Development
Project Structure
Code Style
This project follows PSR-12 coding standards and uses:
- English naming conventions
- Type hints for all parameters and return values
- Constants for magic numbers
- Dependency injection pattern
Contributing
- Fork the repository
- Create a feature branch
- Make your changes following PSR-12
- Add tests for new functionality
- Submit a pull request
License
MIT License. See LICENSE file for details.
Support
For issues and questions:
- GitHub Issues: Report a bug
- Documentation: See
examples/directory
Disclaimer
This SDK implements the complete DTE signing specification and is production-ready from a technical standpoint. However:
- Ensure compliance with current El Salvador Ministro de Hacienda de El Salvador regulations
- Use official certificates provided by the Ministro de Hacienda de El Salvador for production
- Perform additional security audits as required by your organization
- The examples use mock certificates for demonstration purposes only
For production deployment, review all security considerations and follow the production setup checklist above.
All versions of sv-dte-signer with dependencies
ext-libxml Version *
ext-openssl Version *
firebase/php-jwt Version ^6.11
psr/log Version ^3.0