Skip to content

Commit 41a2c7d

Browse files
authored
Merge pull request #20 from wes4m/dev
v0.1.9 Fixes
2 parents e8ca61b + 8aeadea commit 41a2c7d

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div align="center">
22
<br/>
33
<img src="./docs/logo.png"/>
4-
<p>v0.1.8 (experimental)</p>
4+
<p>v0.1.9 (experimental)</p>
55
<br/>
66
<br/>
77
<p>
@@ -17,7 +17,7 @@
1717
<img src="https://img.shields.io/badge/maintainer-wes4m-blue"/>
1818
</a>
1919
<a href="https://badge.fury.io/js/zatca-xml-js">
20-
<img src="https://badge.fury.io/js/zatca-xml-js.svg/?v=0.1.8"/>
20+
<img src="https://badge.fury.io/js/zatca-xml-js.svg/?v=0.1.9"/>
2121
</a>
2222
</p>
2323

package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "zatca-xml-js",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"description": "An implementation of Saudi Arabia ZATCA's E-Invoicing requirements, processes, and standards.",
55
"main": "lib/index.js",
6-
"files": ["lib/**/*"],
6+
"files": [
7+
"lib/**/*"
8+
],
79
"scripts": {
810
"build": "tsc --project tsconfig.build.json",
911
"test": "tsc && node testing_lib/tests/test.js",

src/examples/full.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ const invoice = new ZATCASimplifiedTaxInvoice({
6060
const main = async () => {
6161
try {
6262

63+
// TEMP_FOLDER: Use .env or set directly here (Default: /tmp/)
64+
// Enable for windows
65+
// process.env.TEMP_FOLDER = `${require("os").tmpdir()}\\`;
66+
6367
// Init a new EGS
6468
const egs = new EGS(egsunit);
6569

src/zatca/egs/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ const generateCSR = async (egs_info: EGSUnitInfo, production: boolean, solution_
8484
// This creates a temporary private file, and csr config file to pass to OpenSSL in order to create and sign the CSR.
8585
// * In terms of security, this is very bad as /tmp can be accessed by all users. a simple watcher by unauthorized user can retrieve the keys.
8686
// Better change it to some protected dir.
87-
const private_key_file = `/tmp/${uuidv4()}.pem`;
88-
const csr_config_file = `/tmp/${uuidv4()}.cnf`;
87+
const private_key_file = `${process.env.TEMP_FOLDER ?? "/tmp/"}${uuidv4()}.pem`;
88+
const csr_config_file = `${process.env.TEMP_FOLDER ?? "/tmp/"}${uuidv4()}.cnf`;
8989
fs.writeFileSync(private_key_file, egs_info.private_key);
9090
fs.writeFileSync(csr_config_file, defaultCSRConfig({
9191
egs_model: egs_info.model,

src/zatca/qr/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ export const generateQR = ({invoice_xml, digital_signature, public_key, certific
9292
const TLV = (tags: any[]): Buffer => {
9393
const tlv_tags: Buffer[] = []
9494
tags.forEach((tag, i) => {
95-
const current_tlv_value: Buffer = Buffer.from([i+1, tag.length, ...Buffer.from(tag)]);
95+
const tagValueBuffer: Buffer = Buffer.from(tag);
96+
const current_tlv_value: Buffer = Buffer.from([i+1, tagValueBuffer.byteLength, ...tagValueBuffer]);
9697
tlv_tags.push(current_tlv_value)
9798
});
9899
return Buffer.concat(tlv_tags);

src/zatca/signing/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ export const getCertificateInfo = (certificate_string: string): {hash: string, i
118118
* @returns String base64 encoded certificate body.
119119
*/
120120
export const cleanUpCertificateString = (certificate_string: string): string => {
121-
const r = process.platform === "win32" ? "\r" : "";
122-
return certificate_string.replace(`-----BEGIN CERTIFICATE-----${r}\n`, "").replace("-----END CERTIFICATE-----", "").trim()
121+
return certificate_string.replace(`-----BEGIN CERTIFICATE-----\n`, "").replace("-----END CERTIFICATE-----", "").trim()
123122
}
124123

125124
/**
@@ -128,8 +127,7 @@ export const cleanUpCertificateString = (certificate_string: string): string =>
128127
* @returns String base64 encoded private key body.
129128
*/
130129
export const cleanUpPrivateKeyString = (certificate_string: string): string => {
131-
const r = process.platform === "win32" ? "\r" : "";
132-
return certificate_string.replace(`-----BEGIN EC PRIVATE KEY-----${r}\n`, "").replace("-----END EC PRIVATE KEY-----", "").trim()
130+
return certificate_string.replace(`-----BEGIN EC PRIVATE KEY-----\n`, "").replace("-----END EC PRIVATE KEY-----", "").trim()
133131
}
134132

135133

0 commit comments

Comments
 (0)