SfeFirmador.Core 1.2.9

dotnet add package SfeFirmador.Core --version 1.2.9
                    
NuGet\Install-Package SfeFirmador.Core -Version 1.2.9
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SfeFirmador.Core" Version="1.2.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SfeFirmador.Core" Version="1.2.9" />
                    
Directory.Packages.props
<PackageReference Include="SfeFirmador.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SfeFirmador.Core --version 1.2.9
                    
#r "nuget: SfeFirmador.Core, 1.2.9"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SfeFirmador.Core@1.2.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SfeFirmador.Core&version=1.2.9
                    
Install as a Cake Addin
#tool nuget:?package=SfeFirmador.Core&version=1.2.9
                    
Install as a Cake Tool

SfeFirmador

NuGet SfeFirmador.Core NuGet SfeFirmador.Domain

Libreria .NET para la generacion, validacion y firma digital de documentos fiscales electronicos del Sistema de Facturacion Electronica (SFE) del Servicio de Impuestos Nacionales (SIN) de Bolivia.

Instalacion

dotnet add package SfeFirmador.Core

El paquete SfeFirmador.Domain (interfaces) se instala automaticamente como dependencia.

Requisitos

Estructura del proyecto

SfeFirmadorSolution.sln
|
|-- SfeFirmador.Domain        # Interfaces y contratos (ICabecera, IDetalle, IDocumentoSector, etc.)
|-- SfeFirmador.Core           # Logica de negocio, entidades, generacion XML y firma digital
|-- SfeFirmador.Client         # Aplicacion de consola de ejemplo
|-- SfeFirmador.Test           # Tests unitarios (MSTest)

Configuracion

Las credenciales (clave privada RSA, certificado digital, CUIS, CUFD y codigo de control) se manejan via archivos appsettings.json que estan excluidos del repositorio por seguridad.

1. Crear el archivo de configuracion

Copiar la plantilla y completar con sus credenciales:

cp SfeFirmador.Client/appsettings.example.json SfeFirmador.Client/appsettings.json

Estructura del archivo:

{
  "Firmador": {
    "ClavePrivada": "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----",
    "CertificadoDigital": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----",
    "Cuis": "SU_CUIS",
    "Cufd": "SU_CUFD",
    "CodigoControl": "SU_CODIGO_CONTROL"
  }
}

2. Para los tests

Crear SfeFirmador.Test/appsettings.test.json con la misma estructura usando credenciales de prueba.

Compilar

dotnet build SfeFirmadorSolution.sln

Ejecutar tests

dotnet test SfeFirmador.Test/SfeFirmador.Test.csproj

Uso basico

using Microsoft.Extensions.Configuration;
using SfeFirmador.Core.Core;
using SfeFirmador.Core.Enum;
using System.Text.Json;

// Cargar configuracion
var configuration = new ConfigurationBuilder()
    .SetBasePath(AppContext.BaseDirectory)
    .AddJsonFile("appsettings.json")
    .Build();

var section = configuration.GetSection("Firmador");
string clavePrivada = section["ClavePrivada"];
string certificadoDigital = section["CertificadoDigital"];

// Serializar la factura a JSON
string jsonData = JsonSerializer.Serialize(factura);

// Generar documento fiscal (XML firmado o sin firmar segun modalidad)
var respuesta = DocumentoFiscal.ObtenerDocumentoFiscal(
    jsonData,
    certificadoDigital,
    clavePrivada,
    TipoDocumentoSectorEnum.FacturaCompraVenta,
    TipoModalidadEnum.FacturaElectronicaLinea
);

// Resultado
byte[] archivo = respuesta.Archivo;       // XML como byte array
string hashArchivo = respuesta.HashArchivo; // Hash SHA-256
string xml = respuesta.Xml;               // XML como string

Tipos de documento soportados

La libreria soporta 53 tipos de documento fiscal en modalidad computarizada y electronica:

Categoria Documentos
Compra/Venta CompraVenta, CompraVentaBon, CompraVentaTasas
Exportacion ComercialExportacion, ExportacionMinera, ExportacionHidro, ExportacionPVenta, ExportacionServicio
Servicios ServicioBasico, ServicioBasicoZf, ServicioTuristicoHospedaje, SuministroEnergia, Telecomunicacion, TelecomunicacionZF
Hidrocarburos Hidrocarburo, HidrocarburoNoAlcanzadaIehd, ComercializacionHidrocarburo, ComercializacionGnv, ComercializacionGnGlp, ImportacionComercializacionLubricantes, ImportacionComercializacionLubricantesIEHD
Sector especifico EntidadFinanciera, Hotel, HospitalClinica, HospitalClinicaZF, JuegoAzar, SectorEducativo, SectorEducativoZF, Seguros, SeguridadAlimentaria
Otros AlquilerBienInmueble, AlquilerZF, BoletoAereo, DuttyFree, Engarrafadoras, IceZonaFranca, LibreConsignacion, MonedaExtranjera, Prevalorada, PrevaloradaSD, TasaCero, VentaMineral, VentaMineralBCB, ZonaFranca, AlcanzadaIce
Notas CreditoDebito, CreditoDebitoDescuento, CreditoDebitoIce, Conciliacion

Arquitectura

DocumentoFiscal

Punto de entrada principal. Utiliza un registro de tipos (diccionario) para mapear la combinacion (TipoDocumentoSector, TipoModalidad) al tipo de entidad concreto, eliminando la necesidad de metodos individuales por tipo de documento.

Tres flujos de procesamiento:

  • Estandar - Documentos con cabecera + List<detalle> (la mayoria)
  • Boleto Aereo - Solo cabecera (sin detalle)
  • Conciliacion - cabecera + List<detalleOriginal> + List<detalleConciliacion>

Modalidades

  • Factura Electronica - Genera XML, firma digital con certificado X.509 y valida la firma
  • Factura Computarizada - Genera XML sin firma digital

Validacion

Los objetos se validan automaticamente usando DataAnnotations antes de generar el XML.

Paquetes NuGet utilizados

Paquete Uso
BouncyCastle.Cryptography Firma digital RSA
System.Security.Cryptography.Xml Procesamiento XML firmado
SharpZipLib Compresion de archivos
Microsoft.Extensions.Configuration.Json Lectura de appsettings.json
Newtonsoft.Json Serializacion JSON (Client)

Autor

Deyvi Josue Ortiz Vidaurre

Licencia

Proyecto privado. Todos los derechos reservados.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.9 115 2/18/2026
1.2.8 100 2/18/2026
1.2.7 109 2/18/2026
1.2.6 111 2/18/2026