zatca 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/bin/console +0 -0
- data/bin/setup +0 -0
- data/einvoicing-sdk/Apps/fatoora +12 -0
- data/einvoicing-sdk/Apps/fatoora.bat +16 -0
- data/einvoicing-sdk/Apps/global.json +1 -0
- data/einvoicing-sdk/Apps/jq.exe +0 -0
- data/einvoicing-sdk/Apps/zatca-einvoicing-sdk-238-R3.2.7.jar +0 -0
- data/einvoicing-sdk/Configuration/config.json +11 -0
- data/einvoicing-sdk/Configuration/defaults.json +11 -0
- data/einvoicing-sdk/Configuration/jq.exe +0 -0
- data/einvoicing-sdk/Configuration/usage.txt +16 -0
- data/einvoicing-sdk/Data/Certificates/cert.pem +1 -0
- data/einvoicing-sdk/Data/Certificates/ec-secp256k1-priv-key.pem +1 -0
- data/einvoicing-sdk/Data/Input/csr-config-example-AR-VAT-Group.properties +9 -0
- data/einvoicing-sdk/Data/Input/csr-config-example-AR.properties +9 -0
- data/einvoicing-sdk/Data/Input/csr-config-example-EN-VAT-group.properties +9 -0
- data/einvoicing-sdk/Data/Input/csr-config-example-EN.properties +9 -0
- data/einvoicing-sdk/Data/Input/csr-config-template.properties +9 -0
- data/einvoicing-sdk/Data/PIH/pih.txt +1 -0
- data/einvoicing-sdk/Data/Rules/schematrons/20210819_ZATCA_E-invoice_Validation_Rules.xsl +2844 -0
- data/einvoicing-sdk/Data/Rules/schematrons/CEN-EN16931-UBL.xsl +1973 -0
- data/einvoicing-sdk/Data/Samples/PDF-A3/Simplified Debit Note.pdf +0 -0
- data/einvoicing-sdk/Data/Samples/PDF-A3/Standard Credit Note.pdf +0 -0
- data/einvoicing-sdk/Data/Samples/PDF-A3/Standard Debit Note.pdf +0 -0
- data/einvoicing-sdk/Data/Samples/PDF-A3/Standard Invoice.pdf +0 -0
- data/einvoicing-sdk/Data/Samples/PDF-A3/Tax_Invoice_USD.pdf +0 -0
- data/einvoicing-sdk/Data/Samples/Simplified/Credit/Simplified_Credit_Note.xml +300 -0
- data/einvoicing-sdk/Data/Samples/Simplified/Credit/Simplified_Credit_Note_Error.xml +225 -0
- data/einvoicing-sdk/Data/Samples/Simplified/Debit/Simplified_Debit_Note.xml +211 -0
- data/einvoicing-sdk/Data/Samples/Simplified/Debit/Simplified_Debit_Note_Error.xml +226 -0
- data/einvoicing-sdk/Data/Samples/Simplified/Invoice/Additional_Simplified_Invoices/Out_Of_Scope_Simplified_Invoice.xml +207 -0
- data/einvoicing-sdk/Data/Samples/Simplified/Invoice/Additional_Simplified_Invoices/Simplified_Invoice_USD.xml +246 -0
- data/einvoicing-sdk/Data/Samples/Simplified/Invoice/Simplified_Invoice.xml +246 -0
- data/einvoicing-sdk/Data/Samples/Simplified/Invoice/Simplified_Invoice_Error.xml +228 -0
- data/einvoicing-sdk/Data/Samples/Standard/Credit/Standard_Credit_Note.xml +227 -0
- data/einvoicing-sdk/Data/Samples/Standard/Credit/Standard_Credit_Note_Error.xml +224 -0
- data/einvoicing-sdk/Data/Samples/Standard/Debit/Standard_Debit_Note.xml +227 -0
- data/einvoicing-sdk/Data/Samples/Standard/Debit/Standard_Debit_Note_Error.xml +226 -0
- data/einvoicing-sdk/Data/Samples/Standard/Invoice/Additional_Standard_Invoices/Exempt_Standard_Invoice.xml +227 -0
- data/einvoicing-sdk/Data/Samples/Standard/Invoice/Additional_Standard_Invoices/Standard_Invoice_USD.xml +227 -0
- data/einvoicing-sdk/Data/Samples/Standard/Invoice/Additional_Standard_Invoices/Zero_Rate_Standard_Invoice.xml +227 -0
- data/einvoicing-sdk/Data/Samples/Standard/Invoice/Sample Invoice[Advance Payements] - 1.xml +294 -0
- data/einvoicing-sdk/Data/Samples/Standard/Invoice/Sample Invoice[Advance Payements] - 2.xml +432 -0
- data/einvoicing-sdk/Data/Samples/Standard/Invoice/Standard_Invoice.xml +222 -0
- data/einvoicing-sdk/Data/Samples/Standard/Invoice/Standard_Invoice_Error.xml +228 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/CCTS_CCT_SchemaModule-2.1.xsd +731 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-CommonAggregateComponents-2.1.xsd +44365 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-CommonBasicComponents-2.1.xsd +5389 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-CommonExtensionComponents-2.1.xsd +223 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-CommonSignatureComponents-2.1.xsd +101 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-CoreComponentParameters-2.1.xsd +63 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-ExtensionContentDataType-2.1.xsd +89 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-QualifiedDataTypes-2.1.xsd +69 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-SignatureAggregateComponents-2.1.xsd +138 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-SignatureBasicComponents-2.1.xsd +78 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-UnqualifiedDataTypes-2.1.xsd +553 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-XAdESv132-2.1.xsd +476 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-XAdESv141-2.1.xsd +25 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-xmldsig-core-schema-2.1.xsd +330 -0
- data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/maindoc/UBL-Invoice-2.1.xsd +1002 -0
- data/einvoicing-sdk/Dockerfile +26 -0
- data/einvoicing-sdk/LICENSE.txt +56 -0
- data/einvoicing-sdk/Lib/.Net/DLL/BouncyCastle.Crypto.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/IKVM.OpenJDK.Core.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/IKVM.OpenJDK.Text.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/IKVM.OpenJDK.Util.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/IKVM.OpenJDK.XML.API.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/IKVM.Runtime.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/SDKNETFrameWorkLib.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/SDKNETFrameWorkLib.dll.config +43 -0
- data/einvoicing-sdk/Lib/.Net/DLL/SDKNETFrameWorkLib.pdb +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/System.Net.Http.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/saxon-he-10.8.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/saxon-he-api-10.8.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/DLL/saxon-he-api-10.8.xml +11759 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/.vs/SDKNETFrameworkTest/FileContentIndex/3f204b7a-faba-42d8-8288-8b6fe516555c.vsidx +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/.vs/SDKNETFrameworkTest/FileContentIndex/f95b6f91-c110-4b7a-bb49-3fc6bde85b13.vsidx +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/.vs/SDKNETFrameworkTest/FileContentIndex/read.lock +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/.vs/SDKNETFrameworkTest/v17/.suo +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/App.config +14 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/BouncyCastle.Crypto.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/CSRGeneratorOpenSSL.cs +58 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/IKVM.OpenJDK.Core.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/IKVM.OpenJDK.Text.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/IKVM.OpenJDK.Util.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/IKVM.OpenJDK.XML.API.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/IKVM.Runtime.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/Program.cs +194 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/Properties/AssemblyInfo.cs +36 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/Readme.txt +8 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameWorkLib.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameWorkLib.dll.config +43 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameWorkLib.pdb +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameworkTest.csproj +120 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameworkTest.exe +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameworkTest.exe.config +20 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameworkTest.pdb +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameworkTest.sln +25 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/BouncyCastle.Crypto.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/Data/certificate.txt +1 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/Data/pih.txt +1 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/Data/privateKey.txt +1 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/IKVM.OpenJDK.Core.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/IKVM.OpenJDK.Text.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/IKVM.OpenJDK.Util.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/IKVM.OpenJDK.XML.API.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/IKVM.Runtime.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameWorkLib.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameWorkLib.dll.config +43 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameWorkLib.pdb +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameworkTest.exe +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameworkTest.exe.config +20 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameworkTest.pdb +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/System.Net.Http.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/saxon-he-10.8.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/saxon-he-api-10.8.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/saxon-he-api-10.8.xml +11759 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs +4 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/DesignTimeResolveAssemblyReferences.cache +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.csproj.AssemblyReference.cache +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.csproj.CopyComplete +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.csproj.CoreCompileInputs.cache +1 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.csproj.FileListAbsolute.txt +22 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.csproj.SuggestedBindingRedirects.cache +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.exe +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.pdb +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/saxon-he-10.8.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/saxon-he-api-10.8.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/saxon-he-api-10.8.xml +11759 -0
- data/einvoicing-sdk/Lib/.Net/Test/BouncyCastle.Crypto.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/IKVM.OpenJDK.Core.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/IKVM.OpenJDK.Text.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/IKVM.OpenJDK.Util.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/IKVM.OpenJDK.XML.API.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/IKVM.Runtime.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameWorkLib.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameWorkLib.dll.config +43 -0
- data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameWorkLib.pdb +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameworkTest.exe +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameworkTest.exe.config +20 -0
- data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameworkTest.pdb +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/saxon-he-10.8.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/saxon-he-api-10.8.dll +0 -0
- data/einvoicing-sdk/Lib/.Net/Test/saxon-he-api-10.8.xml +11759 -0
- data/einvoicing-sdk/README.md +15 -0
- data/einvoicing-sdk/Readme/readme.docx +0 -0
- data/einvoicing-sdk/Readme/readme.md +674 -0
- data/einvoicing-sdk/Readme/readme.pdf +0 -0
- data/einvoicing-sdk/Readme/~$readme.docx +0 -0
- data/einvoicing-sdk/docker-compose.yml +12 -0
- data/einvoicing-sdk/install.bat +74 -0
- data/einvoicing-sdk/install.sh +74 -0
- data/lib/zatca/client.rb +173 -0
- data/lib/zatca/hacks.rb +45 -0
- data/lib/zatca/hashing.rb +18 -0
- data/lib/zatca/qr_code_extractor.rb +31 -0
- data/lib/zatca/qr_code_generator.rb +9 -2
- data/lib/zatca/signing/certificate.rb +78 -0
- data/lib/zatca/signing/csr.rb +220 -0
- data/lib/zatca/signing/ecdsa.rb +59 -0
- data/lib/zatca/tag.rb +18 -8
- data/lib/zatca/tags.rb +5 -1
- data/lib/zatca/tags_schema.rb +5 -5
- data/lib/zatca/types.rb +7 -0
- data/lib/zatca/ubl/base_component.rb +142 -0
- data/lib/zatca/ubl/builder.rb +166 -0
- data/lib/zatca/ubl/common_aggregate_components/allowance_charge.rb +64 -0
- data/lib/zatca/ubl/common_aggregate_components/classified_tax_category.rb +25 -0
- data/lib/zatca/ubl/common_aggregate_components/delivery.rb +27 -0
- data/lib/zatca/ubl/common_aggregate_components/invoice_line.rb +63 -0
- data/lib/zatca/ubl/common_aggregate_components/item.rb +21 -0
- data/lib/zatca/ubl/common_aggregate_components/legal_monetary_total.rb +59 -0
- data/lib/zatca/ubl/common_aggregate_components/party.rb +28 -0
- data/lib/zatca/ubl/common_aggregate_components/party_identification.rb +25 -0
- data/lib/zatca/ubl/common_aggregate_components/party_legal_entity.rb +19 -0
- data/lib/zatca/ubl/common_aggregate_components/party_tax_scheme.rb +30 -0
- data/lib/zatca/ubl/common_aggregate_components/postal_address.rb +59 -0
- data/lib/zatca/ubl/common_aggregate_components/price.rb +20 -0
- data/lib/zatca/ubl/common_aggregate_components/tax_category.rb +56 -0
- data/lib/zatca/ubl/common_aggregate_components/tax_total.rb +58 -0
- data/lib/zatca/ubl/common_aggregate_components.rb +2 -0
- data/lib/zatca/ubl/invoice.rb +481 -0
- data/lib/zatca/ubl/invoice_subtype_builder.rb +50 -0
- data/lib/zatca/ubl/signing/cert.rb +48 -0
- data/lib/zatca/ubl/signing/invoice_signed_data_reference.rb +44 -0
- data/lib/zatca/ubl/signing/key_info.rb +25 -0
- data/lib/zatca/ubl/signing/object.rb +20 -0
- data/lib/zatca/ubl/signing/qualifying_properties.rb +27 -0
- data/lib/zatca/ubl/signing/signature.rb +50 -0
- data/lib/zatca/ubl/signing/signature_information.rb +19 -0
- data/lib/zatca/ubl/signing/signature_properties_reference.rb +26 -0
- data/lib/zatca/ubl/signing/signed_info.rb +21 -0
- data/lib/zatca/ubl/signing/signed_properties.rb +81 -0
- data/lib/zatca/ubl/signing/signed_signature_properties.rb +23 -0
- data/lib/zatca/ubl/signing/ubl_document_signatures.rb +25 -0
- data/lib/zatca/ubl/signing/ubl_extension.rb +22 -0
- data/lib/zatca/ubl/signing/ubl_extensions.rb +17 -0
- data/lib/zatca/ubl/signing.rb +2 -0
- data/lib/zatca/ubl.rb +2 -0
- data/lib/zatca/version.rb +1 -1
- data/lib/zatca.rb +27 -3
- data/zatca.gemspec +52 -0
- metadata +318 -10
- data/Gemfile.lock +0 -100
@@ -0,0 +1,50 @@
|
|
1
|
+
class ZATCA::UBL::Signing::Signature < ZATCA::UBL::BaseComponent
|
2
|
+
attr_reader :signing_time, :cert_digest_value, :cert_issuer_name, :cert_serial_number
|
3
|
+
|
4
|
+
def initialize(
|
5
|
+
invoice_hash:, signed_properties_hash:, signature_value:,
|
6
|
+
certificate:, signing_time:, cert_digest_value:, cert_issuer_name:,
|
7
|
+
cert_serial_number:
|
8
|
+
)
|
9
|
+
super()
|
10
|
+
|
11
|
+
@invoice_digest = invoice_hash
|
12
|
+
@signed_properties_hash = signed_properties_hash
|
13
|
+
@signature_value = signature_value
|
14
|
+
@certificate = certificate
|
15
|
+
@signing_time = signing_time
|
16
|
+
@cert_digest_value = cert_digest_value
|
17
|
+
@cert_issuer_name = cert_issuer_name
|
18
|
+
@cert_serial_number = cert_serial_number
|
19
|
+
end
|
20
|
+
|
21
|
+
def attributes
|
22
|
+
{
|
23
|
+
"xmlns:ds" => "http://www.w3.org/2000/09/xmldsig#",
|
24
|
+
"Id" => "signature"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def name
|
29
|
+
"ds:Signature"
|
30
|
+
end
|
31
|
+
|
32
|
+
def elements
|
33
|
+
[
|
34
|
+
ZATCA::UBL::Signing::SignedInfo.new(
|
35
|
+
invoice_digest: @invoice_digest,
|
36
|
+
signed_properties_hash: @signed_properties_hash
|
37
|
+
),
|
38
|
+
|
39
|
+
ZATCA::UBL::BaseComponent.new(name: "ds:SignatureValue", value: @signature_value),
|
40
|
+
ZATCA::UBL::Signing::KeyInfo.new(certificate: @certificate),
|
41
|
+
|
42
|
+
ZATCA::UBL::Signing::Object.new(
|
43
|
+
signing_time: @signing_time,
|
44
|
+
cert_digest_value: @cert_digest_value,
|
45
|
+
cert_issuer_name: @cert_issuer_name,
|
46
|
+
cert_serial_number: @cert_serial_number
|
47
|
+
)
|
48
|
+
]
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class ZATCA::UBL::Signing::SignatureInformation < ZATCA::UBL::BaseComponent
|
2
|
+
def initialize(signature:)
|
3
|
+
super()
|
4
|
+
|
5
|
+
@signature = signature
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
"sac:SignatureInformation"
|
10
|
+
end
|
11
|
+
|
12
|
+
def elements
|
13
|
+
[
|
14
|
+
ZATCA::UBL::BaseComponent.new(name: "cbc:ID", value: "urn:oasis:names:specification:ubl:signature:1"),
|
15
|
+
ZATCA::UBL::BaseComponent.new(name: "sbc:ReferencedSignatureID", value: "urn:oasis:names:specification:ubl:signature:Invoice"),
|
16
|
+
@signature
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class ZATCA::UBL::Signing::SignaturePropertiesReference < ZATCA::UBL::BaseComponent
|
2
|
+
attr_accessor :digest_value
|
3
|
+
|
4
|
+
def initialize(digest_value:)
|
5
|
+
super()
|
6
|
+
@digest_value = digest_value
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
"ds:Reference"
|
11
|
+
end
|
12
|
+
|
13
|
+
def attributes
|
14
|
+
{
|
15
|
+
"Type" => "http://www.w3.org/2000/09/xmldsig#SignatureProperties",
|
16
|
+
"URI" => "#xadesSignedProperties"
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def elements
|
21
|
+
[
|
22
|
+
ZATCA::UBL::BaseComponent.new(name: "ds:DigestMethod", attributes: {"Algorithm" => "http://www.w3.org/2001/04/xmlenc#sha256"}),
|
23
|
+
ZATCA::UBL::BaseComponent.new(name: "ds:DigestValue", value: @digest_value)
|
24
|
+
]
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class ZATCA::UBL::Signing::SignedInfo < ZATCA::UBL::BaseComponent
|
2
|
+
def initialize(invoice_digest:, signed_properties_hash:)
|
3
|
+
super()
|
4
|
+
|
5
|
+
@invoice_digest = invoice_digest
|
6
|
+
@signed_properties_hash = signed_properties_hash
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
"ds:SignedInfo"
|
11
|
+
end
|
12
|
+
|
13
|
+
def elements
|
14
|
+
[
|
15
|
+
ZATCA::UBL::BaseComponent.new(name: "ds:CanonicalizationMethod", attributes: {"Algorithm" => "http://www.w3.org/2006/12/xml-c14n11"}),
|
16
|
+
ZATCA::UBL::BaseComponent.new(name: "ds:SignatureMethod", attributes: {"Algorithm" => "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"}),
|
17
|
+
ZATCA::UBL::Signing::InvoiceSignedDataReference.new(digest_value: @invoice_digest),
|
18
|
+
ZATCA::UBL::Signing::SignaturePropertiesReference.new(digest_value: @signed_properties_hash)
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
class ZATCA::UBL::Signing::SignedProperties < ZATCA::UBL::BaseComponent
|
2
|
+
def initialize(
|
3
|
+
signing_time:,
|
4
|
+
cert_digest_value:,
|
5
|
+
cert_issuer_name:,
|
6
|
+
cert_serial_number:
|
7
|
+
)
|
8
|
+
super()
|
9
|
+
|
10
|
+
@signing_time = signing_time
|
11
|
+
@cert_digest_value = cert_digest_value
|
12
|
+
@cert_issuer_name = cert_issuer_name
|
13
|
+
@cert_serial_number = cert_serial_number
|
14
|
+
end
|
15
|
+
|
16
|
+
def name
|
17
|
+
"xades:SignedProperties"
|
18
|
+
end
|
19
|
+
|
20
|
+
def attributes
|
21
|
+
{
|
22
|
+
"Id" => "xadesSignedProperties"
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def elements
|
27
|
+
[
|
28
|
+
ZATCA::UBL::Signing::SignedSignatureProperties.new(
|
29
|
+
signing_time: @signing_time,
|
30
|
+
cert_digest_value: @cert_digest_value,
|
31
|
+
cert_issuer_name: @cert_issuer_name,
|
32
|
+
cert_serial_number: @cert_serial_number
|
33
|
+
)
|
34
|
+
]
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_hash
|
38
|
+
ZATCA::Hashing.generate_hashes(zatca_whitespaced_xml_for_hashing)[:hexdigest_base64]
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# rubocop:disable Layout/HeredocIndentation
|
44
|
+
# rubocop:disable Layout/ClosingHeredocIndentation
|
45
|
+
#
|
46
|
+
# We need this version of the XML with this exact whitespacing because ZATCA
|
47
|
+
# did not opt for canonicalization before hashing (unlike the invoice hash),
|
48
|
+
# and also because they have XML attributes that are only added the moment you
|
49
|
+
# generate the hash but are expected to be removed in all other instances.
|
50
|
+
#
|
51
|
+
# We will use this version of the XML to generate the hash only, and expect
|
52
|
+
# the output of `build_xml` to generate the non-signing version of the XML.
|
53
|
+
# See:
|
54
|
+
# - https://zatca1.discourse.group/t/what-do-signed-properties-look-like-when-hashing
|
55
|
+
# - https://web.archive.org/web/20230925182417/https://zatca1.discourse.group/t/what-do-signed-properties-look-like-when-hashing/717
|
56
|
+
|
57
|
+
def zatca_whitespaced_xml_for_hashing
|
58
|
+
# Note: chomp is used to get rid of the final newline character
|
59
|
+
<<-XML.chomp
|
60
|
+
<xades:SignedProperties xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" Id="xadesSignedProperties">
|
61
|
+
<xades:SignedSignatureProperties>
|
62
|
+
<xades:SigningTime>#{@signing_time}</xades:SigningTime>
|
63
|
+
<xades:SigningCertificate>
|
64
|
+
<xades:Cert>
|
65
|
+
<xades:CertDigest>
|
66
|
+
<ds:DigestMethod xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
|
67
|
+
<ds:DigestValue xmlns:ds="http://www.w3.org/2000/09/xmldsig#">#{@cert_digest_value}</ds:DigestValue>
|
68
|
+
</xades:CertDigest>
|
69
|
+
<xades:IssuerSerial>
|
70
|
+
<ds:X509IssuerName xmlns:ds="http://www.w3.org/2000/09/xmldsig#">#{@cert_issuer_name}</ds:X509IssuerName>
|
71
|
+
<ds:X509SerialNumber xmlns:ds="http://www.w3.org/2000/09/xmldsig#">#{@cert_serial_number}</ds:X509SerialNumber>
|
72
|
+
</xades:IssuerSerial>
|
73
|
+
</xades:Cert>
|
74
|
+
</xades:SigningCertificate>
|
75
|
+
</xades:SignedSignatureProperties>
|
76
|
+
</xades:SignedProperties>
|
77
|
+
XML
|
78
|
+
end
|
79
|
+
# rubocop:enable Layout/HeredocIndentation
|
80
|
+
# rubocop:enable Layout/ClosingHeredocIndentation
|
81
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class ZATCA::UBL::Signing::SignedSignatureProperties < ZATCA::UBL::BaseComponent
|
2
|
+
def initialize(signing_time:, cert_digest_value:, cert_issuer_name:, cert_serial_number:)
|
3
|
+
super()
|
4
|
+
|
5
|
+
@signing_time = signing_time
|
6
|
+
@cert_digest_value = cert_digest_value
|
7
|
+
@cert_issuer_name = cert_issuer_name
|
8
|
+
@cert_serial_number = cert_serial_number
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
"xades:SignedSignatureProperties"
|
13
|
+
end
|
14
|
+
|
15
|
+
def elements
|
16
|
+
[
|
17
|
+
ZATCA::UBL::BaseComponent.new(name: "xades:SigningTime", value: @signing_time),
|
18
|
+
ZATCA::UBL::BaseComponent.new(name: "xades:SigningCertificate", elements: [
|
19
|
+
ZATCA::UBL::Signing::Cert.new(cert_digest_value: @cert_digest_value, cert_issuer_name: @cert_issuer_name, cert_serial_number: @cert_serial_number)
|
20
|
+
])
|
21
|
+
]
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ZATCA::UBL::Signing::UBLDocumentSignatures < ZATCA::UBL::BaseComponent
|
2
|
+
def initialize(signature:)
|
3
|
+
super()
|
4
|
+
|
5
|
+
@signature = signature
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
"sig:UBLDocumentSignatures"
|
10
|
+
end
|
11
|
+
|
12
|
+
def attributes
|
13
|
+
{
|
14
|
+
"xmlns:sig" => "urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2",
|
15
|
+
"xmlns:sac" => "urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2",
|
16
|
+
"xmlns:sbc" => "urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2"
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def elements
|
21
|
+
[
|
22
|
+
ZATCA::UBL::Signing::SignatureInformation.new(signature: @signature)
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class ZATCA::UBL::Signing::UBLExtension < ZATCA::UBL::BaseComponent
|
2
|
+
def initialize(signature:)
|
3
|
+
super()
|
4
|
+
|
5
|
+
@signature = signature
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
"ext:UBLExtension"
|
10
|
+
end
|
11
|
+
|
12
|
+
def elements
|
13
|
+
[
|
14
|
+
ZATCA::UBL::BaseComponent.new(name: "ext:ExtensionURI", value: "urn:oasis:names:specification:ubl:dsig:enveloped:xades"),
|
15
|
+
ZATCA::UBL::BaseComponent.new(name: "ext:ExtensionContent", elements: [
|
16
|
+
ZATCA::UBL::Signing::UBLDocumentSignatures.new(signature: @signature)
|
17
|
+
])
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ZATCA::UBL::Signing::UBLExtensions < ZATCA::UBL::BaseComponent
|
2
|
+
def initialize(signature:)
|
3
|
+
super()
|
4
|
+
|
5
|
+
@signature = signature
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
"ext:UBLExtensions"
|
10
|
+
end
|
11
|
+
|
12
|
+
def elements
|
13
|
+
[
|
14
|
+
ZATCA::UBL::Signing::UBLExtension.new(signature: @signature)
|
15
|
+
]
|
16
|
+
end
|
17
|
+
end
|
data/lib/zatca/ubl.rb
ADDED
data/lib/zatca/version.rb
CHANGED
data/lib/zatca.rb
CHANGED
@@ -1,13 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "zatca/version"
|
4
|
+
require_relative "zatca/types"
|
4
5
|
|
6
|
+
require "active_support/all"
|
5
7
|
require "zeitwerk"
|
8
|
+
require "dry-initializer"
|
9
|
+
require "dry-types"
|
6
10
|
|
7
11
|
loader = Zeitwerk::Loader.for_gem
|
8
12
|
loader.inflector.inflect(
|
9
13
|
"zatca" => "ZATCA",
|
10
|
-
"qr_code_generator" => "QRCodeGenerator"
|
14
|
+
"qr_code_generator" => "QRCodeGenerator",
|
15
|
+
"qr_code_extractor" => "QRCodeExtractor",
|
16
|
+
"ubl" => "UBL",
|
17
|
+
"csr" => "CSR",
|
18
|
+
"ubl_document_signature" => "UBLDocumentSignature",
|
19
|
+
"ubl_document_signatures" => "UBLDocumentSignatures",
|
20
|
+
"ubl_extension" => "UBLExtension",
|
21
|
+
"ubl_extensions" => "UBLExtensions",
|
22
|
+
"id" => "ID",
|
23
|
+
"ecdsa" => "ECDSA"
|
11
24
|
)
|
12
25
|
loader.setup
|
13
26
|
|
@@ -16,8 +29,19 @@ module ZATCA
|
|
16
29
|
|
17
30
|
class Error < StandardError; end
|
18
31
|
|
19
|
-
def self.
|
20
|
-
|
32
|
+
def self.extract_qr_base64_from_base64_invoice(base64_invoice)
|
33
|
+
QRCodeExtractor.new(invoice_base64: base64_invoice).extract
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.render_qr_code(tags: nil, base64: nil)
|
37
|
+
if tags.present?
|
38
|
+
tags = ZATCA::Tags.new(tags) if tags.is_a?(Hash)
|
39
|
+
QRCodeGenerator.new(tags: tags).render
|
40
|
+
elsif base64.present?
|
41
|
+
QRCodeGenerator.new(base64: base64).render
|
42
|
+
else
|
43
|
+
raise ArgumentError, "Either tags or base64 must be provided"
|
44
|
+
end
|
21
45
|
end
|
22
46
|
end
|
23
47
|
|
data/zatca.gemspec
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/zatca/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "zatca"
|
7
|
+
spec.version = ZATCA::VERSION
|
8
|
+
spec.authors = ["Omar Bahareth"]
|
9
|
+
spec.email = ["obahareth@mrsool.co"]
|
10
|
+
|
11
|
+
spec.summary = "A library for generating QR Codes for the e-invoice standard by ZATCA in Saudi Arabia."
|
12
|
+
spec.description = "A library for generating QR Codes for the e-invoice standard by ZATCA in Saudi Arabia."
|
13
|
+
spec.homepage = "https://github.com/mrsool/zatca"
|
14
|
+
spec.required_ruby_version = ">= 2.5.0"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/mrsool/zatca"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/mrsool/zatca/releases"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# Dependencies
|
34
|
+
spec.add_dependency "zeitwerk", "~> 2.4"
|
35
|
+
spec.add_dependency "dry-schema", ">= 1.5"
|
36
|
+
spec.add_dependency "rqrcode", "~> 2.1.0"
|
37
|
+
spec.add_dependency "httpx", "~> 0.21.0"
|
38
|
+
spec.add_dependency "nokogiri", ">= 1.12"
|
39
|
+
spec.add_dependency "activesupport", ">= 5.2"
|
40
|
+
spec.add_dependency "dry-initializer", ">= 3.0"
|
41
|
+
spec.add_dependency "starkbank-ecdsa", "~> 2.0"
|
42
|
+
|
43
|
+
# Development Dependencies
|
44
|
+
spec.add_development_dependency "standard", "~> 1.3"
|
45
|
+
spec.add_development_dependency "byebug", "~> 9.0"
|
46
|
+
spec.add_development_dependency "rspec", "~> 3.10"
|
47
|
+
spec.add_development_dependency "vcr", "~> 6.0.0"
|
48
|
+
spec.add_development_dependency "webmock", "~> 3.18.1"
|
49
|
+
spec.add_development_dependency "amazing_print", "~> 1.4.0"
|
50
|
+
# For more information and examples about making a new gem, checkout our
|
51
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
52
|
+
end
|