bysquare 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -29
- package/lib/cjs/cli.js +3 -5
- package/lib/cjs/generate.d.ts +11 -9
- package/lib/cjs/generate.js +114 -86
- package/lib/cjs/package.json +22 -25
- package/lib/cjs/parse.d.ts +12 -3
- package/lib/cjs/parse.js +189 -128
- package/lib/cjs/types.d.ts +18 -0
- package/lib/mjs/cli.js +3 -5
- package/lib/mjs/generate.d.ts +11 -9
- package/lib/mjs/generate.js +88 -83
- package/lib/mjs/package.json +22 -25
- package/lib/mjs/parse.d.ts +12 -3
- package/lib/mjs/parse.js +164 -124
- package/lib/mjs/types.d.ts +18 -0
- package/package.json +22 -25
package/README.md
CHANGED
|
@@ -2,18 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
![version][version] ![build][build]
|
|
4
4
|
|
|
5
|
-
Simple
|
|
5
|
+
Simple JavaScript library to generate and parse "PAY by square" string.
|
|
6
6
|
|
|
7
7
|
**What is `PAY by square`?**
|
|
8
8
|
|
|
9
|
-
It's a national standard for
|
|
10
|
-
Association in 2013. It is
|
|
11
|
-
other payment regulations.
|
|
9
|
+
It's a national standard for QR code payments that was adopted by the Slovak
|
|
10
|
+
Banking Association in 2013. It is incorporated into a variety of invoices,
|
|
11
|
+
reminders and other payment regulations.
|
|
12
12
|
|
|
13
13
|
**Can I generate an image?**
|
|
14
14
|
|
|
15
|
-
This library
|
|
16
|
-
|
|
15
|
+
This library doesn't have a specific opinion and how the QR code string is
|
|
16
|
+
transformed into images depends on how you implement it. See
|
|
17
|
+
[examples](examples).
|
|
17
18
|
|
|
18
19
|
## Install
|
|
19
20
|
|
|
@@ -31,6 +32,9 @@ npm install xseman/bysquare#master
|
|
|
31
32
|
|
|
32
33
|
# latest unreleased changes
|
|
33
34
|
npm install xseman/bysquare#develop
|
|
35
|
+
|
|
36
|
+
# specific tag version, e.g. v2.1.0
|
|
37
|
+
npm install xseman/bysquare#v2.1.0
|
|
34
38
|
```
|
|
35
39
|
|
|
36
40
|
**CLI**
|
|
@@ -39,6 +43,12 @@ npm install xseman/bysquare#develop
|
|
|
39
43
|
npm install --global bysquare
|
|
40
44
|
```
|
|
41
45
|
|
|
46
|
+
**Deno** `v1.28+`, just import `npm:bysquare` `v2.1.0+`
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
import { generate, parse } from "npm:bysquare@2.1.0"
|
|
50
|
+
```
|
|
51
|
+
|
|
42
52
|
## How it works
|
|
43
53
|
|
|
44
54
|
### Encoding sequence
|
|
@@ -53,49 +63,75 @@ parse(qr: string): DataModel
|
|
|
53
63
|
detect(qr: string): Boolean
|
|
54
64
|
```
|
|
55
65
|
|
|
56
|
-
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
Generate
|
|
57
69
|
|
|
58
70
|
```ts
|
|
59
|
-
import {
|
|
71
|
+
import { DataModel, generate, PaymentOptions } from "bysquare"
|
|
60
72
|
|
|
61
|
-
|
|
73
|
+
// long string ready to be encoded to QR
|
|
74
|
+
const qrString = generate({
|
|
62
75
|
invoiceId: "random-id",
|
|
63
76
|
payments: [
|
|
64
77
|
{
|
|
65
78
|
type: PaymentOptions.PaymentOrder,
|
|
66
79
|
amount: 100.0,
|
|
67
80
|
bankAccounts: [
|
|
68
|
-
{ iban: "SK9611000000002918599669" }
|
|
81
|
+
{ iban: "SK9611000000002918599669" }
|
|
69
82
|
],
|
|
70
83
|
currencyCode: "EUR",
|
|
71
|
-
variableSymbol: "123"
|
|
84
|
+
variableSymbol: "123"
|
|
72
85
|
}
|
|
73
86
|
]
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const qr = generate(model)
|
|
87
|
+
})
|
|
77
88
|
```
|
|
78
89
|
|
|
79
|
-
|
|
90
|
+
Parse
|
|
80
91
|
|
|
81
92
|
```ts
|
|
82
93
|
import { parse } from "bysquare"
|
|
83
94
|
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
const model =
|
|
96
|
+
parse("0405QH8090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6CB54HSI0KH9FCRASHNQBSKAQD2LJ4AU400UVKDNDPFRKLOBEVVVU0QJ000")
|
|
97
|
+
|
|
98
|
+
// {
|
|
99
|
+
// invoiceId: "random-id",
|
|
100
|
+
// payments: [
|
|
101
|
+
// {
|
|
102
|
+
// type: 1,
|
|
103
|
+
// amount: 100.0,
|
|
104
|
+
// bankAccounts: [
|
|
105
|
+
// { iban: "SK9611000000002918599669" },
|
|
106
|
+
// ],
|
|
107
|
+
// currencyCode: "EUR",
|
|
108
|
+
// variableSymbol: "123",
|
|
109
|
+
// }
|
|
110
|
+
// ]
|
|
111
|
+
// }
|
|
112
|
+
//
|
|
113
|
+
const qr =
|
|
114
|
+
"0004A00090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6CB54HSI0KH9FCRASHNQBSKAQD2LJ4AU400UVKDNDPFRKLOBEVVVU0QJ000"
|
|
87
115
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
const model = parse(qr)
|
|
117
|
+
/**
|
|
118
|
+
* {
|
|
119
|
+
* invoiceId: "random-id",
|
|
120
|
+
* payments: [
|
|
121
|
+
* {
|
|
122
|
+
* type: PaymentOptions.PaymentOrder,
|
|
123
|
+
* amount: 100.0,
|
|
124
|
+
* bankAccounts: [
|
|
125
|
+
* { iban: "SK9611000000002918599669" },
|
|
126
|
+
* ],
|
|
127
|
+
* currencyCode: "EUR",
|
|
128
|
+
* variableSymbol: "123",
|
|
129
|
+
* }
|
|
130
|
+
* ]
|
|
131
|
+
* }
|
|
132
|
+
*/
|
|
95
133
|
```
|
|
96
134
|
|
|
97
|
-
## CLI
|
|
98
|
-
|
|
99
135
|
You can use json file with valid model to generate qr-string.
|
|
100
136
|
|
|
101
137
|
```sh
|
|
@@ -114,7 +150,7 @@ You can use json file with valid model to generate qr-string.
|
|
|
114
150
|
# }
|
|
115
151
|
|
|
116
152
|
$ npx bysquare ./example.json
|
|
117
|
-
$
|
|
153
|
+
$ 0405QH8090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6CB54HSI0KH9FCRASHNQBSKAQD2LJ4AU400UVKDNDPFRKLOBEVVVU0QJ000
|
|
118
154
|
```
|
|
119
155
|
|
|
120
156
|
You can also use stdin.
|
|
@@ -133,7 +169,7 @@ $ npx bysquare <<< '{
|
|
|
133
169
|
]
|
|
134
170
|
}'
|
|
135
171
|
|
|
136
|
-
$
|
|
172
|
+
$ 0405QH8090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6CB54HSI0KH9FCRASHNQBSKAQD2LJ4AU400UVKDNDPFRKLOBEVVVU0QJ000
|
|
137
173
|
```
|
|
138
174
|
|
|
139
175
|
## Related
|
package/lib/cjs/cli.js
CHANGED
|
@@ -8,12 +8,10 @@ const node_fs_1 = require("node:fs");
|
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const node_readline_1 = require("node:readline");
|
|
10
10
|
const generate_js_1 = require("./generate.js");
|
|
11
|
-
if (process.stdin.isTTY) {
|
|
12
|
-
// bysquare "file"
|
|
11
|
+
if /** bysquare "file" */ (process.stdin.isTTY) {
|
|
13
12
|
handleInput(process.argv[2]);
|
|
14
|
-
}
|
|
13
|
+
} /** bysquare <<< "data" */
|
|
15
14
|
else {
|
|
16
|
-
// echo "data" | bysquare
|
|
17
15
|
;
|
|
18
16
|
(async () => {
|
|
19
17
|
const stdin = await handleStdin();
|
|
@@ -85,6 +83,6 @@ function help() {
|
|
|
85
83
|
" \"variableSymbol\": \"123\"",
|
|
86
84
|
" }",
|
|
87
85
|
" ]",
|
|
88
|
-
" }\""
|
|
86
|
+
" }\""
|
|
89
87
|
].join("\n");
|
|
90
88
|
}
|
package/lib/cjs/generate.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { DataModel } from "./types.js";
|
|
3
2
|
/**
|
|
4
3
|
* Returns a 2 byte buffer that represents the header of the bysquare
|
|
@@ -13,31 +12,34 @@ import { DataModel } from "./types.js";
|
|
|
13
12
|
* | Reserved | 4 | 0-15 | bits reserved for future needs
|
|
14
13
|
* ```
|
|
15
14
|
*
|
|
16
|
-
* @see 3.5.
|
|
15
|
+
* @see 3.5.
|
|
17
16
|
*/
|
|
18
|
-
export declare function
|
|
17
|
+
export declare function headerBysquare(
|
|
18
|
+
/** dprint-ignore */
|
|
19
|
+
header?: [
|
|
19
20
|
bySquareType: number,
|
|
20
21
|
version: number,
|
|
21
22
|
documentType: number,
|
|
22
23
|
reserved: number
|
|
23
24
|
]): Uint8Array;
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
+
* Creates a one-byte array that represents the length of compressed data in
|
|
27
|
+
* combination with CRC32 in bytes.
|
|
26
28
|
*/
|
|
27
|
-
export declare function
|
|
29
|
+
export declare function headerDataLength(length: number): Uint8Array;
|
|
28
30
|
/**
|
|
29
31
|
* Transfer object to a tabbed string and append a CRC32 checksum
|
|
30
32
|
*
|
|
31
|
-
* @see 3.10.
|
|
33
|
+
* @see 3.10.
|
|
32
34
|
*/
|
|
33
|
-
export declare function addChecksum(
|
|
35
|
+
export declare function addChecksum(serialized: string): Uint8Array;
|
|
34
36
|
/**
|
|
35
37
|
* Transform data to ordered tab-separated intermediate representation ready for
|
|
36
38
|
* encoding
|
|
37
39
|
*
|
|
38
|
-
* @see Table 15
|
|
40
|
+
* @see Table 15.
|
|
39
41
|
*/
|
|
40
|
-
export declare function
|
|
42
|
+
export declare function serialize(data: DataModel): string;
|
|
41
43
|
type Options = {
|
|
42
44
|
/**
|
|
43
45
|
* Many banking apps do not support diacritics, which results in errors when
|
package/lib/cjs/generate.js
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generate = exports.
|
|
29
|
+
exports.generate = exports.serialize = exports.addChecksum = exports.headerDataLength = exports.headerBysquare = void 0;
|
|
7
30
|
const crc_32_1 = __importDefault(require("crc-32"));
|
|
8
31
|
const lodash_deburr_1 = __importDefault(require("lodash.deburr"));
|
|
32
|
+
const lzma = __importStar(require("lzma1"));
|
|
9
33
|
const rfc4648_1 = require("rfc4648");
|
|
10
34
|
const types_js_1 = require("./types.js");
|
|
11
|
-
// @ts-ignore: missing types
|
|
12
|
-
const lzma_1 = __importDefault(require("lzma"));
|
|
13
35
|
/**
|
|
14
36
|
* Returns a 2 byte buffer that represents the header of the bysquare
|
|
15
37
|
* specification
|
|
@@ -23,63 +45,69 @@ const lzma_1 = __importDefault(require("lzma"));
|
|
|
23
45
|
* | Reserved | 4 | 0-15 | bits reserved for future needs
|
|
24
46
|
* ```
|
|
25
47
|
*
|
|
26
|
-
* @see 3.5.
|
|
48
|
+
* @see 3.5.
|
|
27
49
|
*/
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
50
|
+
function headerBysquare(
|
|
51
|
+
/** dprint-ignore */
|
|
52
|
+
header = [
|
|
53
|
+
0x00, 0x00,
|
|
54
|
+
0x00, 0x00
|
|
31
55
|
]) {
|
|
32
56
|
const isValid = header.every((nibble) => 0 <= nibble && nibble <= 15);
|
|
33
57
|
if (!isValid) {
|
|
34
|
-
throw new Error(
|
|
58
|
+
throw new Error("Invalid header byte value, valid range <0,15>");
|
|
35
59
|
}
|
|
36
60
|
const [bySquareType, version, documentType, reserved] = header;
|
|
37
61
|
// Combine 4-nibbles to 2-bytes
|
|
38
62
|
const mergedNibbles = Uint8Array.from([
|
|
39
63
|
(bySquareType << 4) | (version << 0),
|
|
40
|
-
(documentType << 4) | (reserved << 0)
|
|
64
|
+
(documentType << 4) | (reserved << 0)
|
|
41
65
|
]);
|
|
42
66
|
return mergedNibbles;
|
|
43
67
|
}
|
|
44
|
-
exports.
|
|
68
|
+
exports.headerBysquare = headerBysquare;
|
|
45
69
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
70
|
+
* The function first sets default values for the lc, lp, and pb properties,
|
|
71
|
+
* which represent the number of literal context bits, literal position bits,
|
|
72
|
+
* and position bits, respectively. These values are then used to calculate the
|
|
73
|
+
* properties value, which is a single byte that encodes all three properties.
|
|
50
74
|
*
|
|
51
|
-
* @see 3.11.
|
|
75
|
+
* @see 3.11.
|
|
52
76
|
*/
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
header
|
|
59
|
-
|
|
77
|
+
function headerLzmaProps() {
|
|
78
|
+
const lc = 3;
|
|
79
|
+
const lp = 0;
|
|
80
|
+
const pb = 2;
|
|
81
|
+
const properties = (((pb * 5) + lp) * 9) + lc;
|
|
82
|
+
const header = new ArrayBuffer(1);
|
|
83
|
+
new DataView(header).setUint8(0, properties);
|
|
84
|
+
return new Uint8Array(header);
|
|
60
85
|
}
|
|
61
86
|
/**
|
|
62
|
-
*
|
|
87
|
+
* Creates a one-byte array that represents the length of compressed data in
|
|
88
|
+
* combination with CRC32 in bytes.
|
|
63
89
|
*/
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
90
|
+
function headerDataLength(length) {
|
|
91
|
+
if (length >= 2 ** 16) {
|
|
92
|
+
throw new Error("The maximum compressed data size has been reached");
|
|
93
|
+
}
|
|
94
|
+
const header = new ArrayBuffer(1);
|
|
95
|
+
new DataView(header).setUint8(0, length);
|
|
96
|
+
return new Uint8Array(header);
|
|
69
97
|
}
|
|
70
|
-
exports.
|
|
98
|
+
exports.headerDataLength = headerDataLength;
|
|
71
99
|
/**
|
|
72
100
|
* Transfer object to a tabbed string and append a CRC32 checksum
|
|
73
101
|
*
|
|
74
|
-
* @see 3.10.
|
|
102
|
+
* @see 3.10.
|
|
75
103
|
*/
|
|
76
|
-
function addChecksum(
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
const
|
|
104
|
+
function addChecksum(serialized) {
|
|
105
|
+
const checksum = new ArrayBuffer(4);
|
|
106
|
+
new DataView(checksum).setUint32(0, crc_32_1.default.str(serialized), true);
|
|
107
|
+
const byteArray = new TextEncoder().encode(serialized);
|
|
80
108
|
return Uint8Array.from([
|
|
81
|
-
...new Uint8Array(checksum
|
|
82
|
-
...Uint8Array.from(
|
|
109
|
+
...new Uint8Array(checksum),
|
|
110
|
+
...Uint8Array.from(byteArray)
|
|
83
111
|
]);
|
|
84
112
|
}
|
|
85
113
|
exports.addChecksum = addChecksum;
|
|
@@ -87,62 +115,62 @@ exports.addChecksum = addChecksum;
|
|
|
87
115
|
* Transform data to ordered tab-separated intermediate representation ready for
|
|
88
116
|
* encoding
|
|
89
117
|
*
|
|
90
|
-
* @see Table 15
|
|
118
|
+
* @see Table 15.
|
|
91
119
|
*/
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
120
|
+
function serialize(data) {
|
|
121
|
+
const serialized = new Array();
|
|
122
|
+
serialized.push(data.invoiceId?.toString());
|
|
123
|
+
serialized.push(data.payments.length.toString());
|
|
96
124
|
for (const p of data.payments) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
125
|
+
serialized.push(p.type.toString());
|
|
126
|
+
serialized.push(p.amount?.toString());
|
|
127
|
+
serialized.push(p.currencyCode);
|
|
128
|
+
serialized.push(p.paymentDueDate);
|
|
129
|
+
serialized.push(p.variableSymbol);
|
|
130
|
+
serialized.push(p.constantSymbol);
|
|
131
|
+
serialized.push(p.specificSymbol);
|
|
132
|
+
serialized.push(p.originatorRefInfo);
|
|
133
|
+
serialized.push(p.paymentNote);
|
|
134
|
+
serialized.push(p.bankAccounts.length.toString());
|
|
107
135
|
for (const ba of p.bankAccounts) {
|
|
108
|
-
|
|
109
|
-
|
|
136
|
+
serialized.push(ba.iban);
|
|
137
|
+
serialized.push(ba.bic);
|
|
110
138
|
}
|
|
111
139
|
if (p.type === types_js_1.PaymentOptions.StandingOrder) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
140
|
+
serialized.push("1");
|
|
141
|
+
serialized.push(p.day?.toString());
|
|
142
|
+
serialized.push(p.month?.toString());
|
|
143
|
+
serialized.push(p.periodicity);
|
|
144
|
+
serialized.push(p.lastDate);
|
|
117
145
|
}
|
|
118
146
|
else {
|
|
119
|
-
|
|
147
|
+
serialized.push("0");
|
|
120
148
|
}
|
|
121
149
|
if (p.type === types_js_1.PaymentOptions.DirectDebit) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
150
|
+
serialized.push("1");
|
|
151
|
+
serialized.push(p.directDebitScheme?.toString());
|
|
152
|
+
serialized.push(p.directDebitType?.toString());
|
|
153
|
+
serialized.push(p.variableSymbol?.toString());
|
|
154
|
+
serialized.push(p.specificSymbol?.toString());
|
|
155
|
+
serialized.push(p.originatorRefInfo?.toString());
|
|
156
|
+
serialized.push(p.mandateId?.toString());
|
|
157
|
+
serialized.push(p.creditorId?.toString());
|
|
158
|
+
serialized.push(p.contractId?.toString());
|
|
159
|
+
serialized.push(p.maxAmount?.toString());
|
|
160
|
+
serialized.push(p.validTillDate?.toString());
|
|
133
161
|
}
|
|
134
162
|
else {
|
|
135
|
-
|
|
163
|
+
serialized.push("0");
|
|
136
164
|
}
|
|
137
165
|
}
|
|
138
166
|
for (const p of data.payments) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
167
|
+
serialized.push(p.beneficiary?.name);
|
|
168
|
+
serialized.push(p.beneficiary?.street);
|
|
169
|
+
serialized.push(p.beneficiary?.city);
|
|
142
170
|
}
|
|
143
|
-
return
|
|
171
|
+
return serialized.join("\t");
|
|
144
172
|
}
|
|
145
|
-
exports.
|
|
173
|
+
exports.serialize = serialize;
|
|
146
174
|
function removeDiacritics(model) {
|
|
147
175
|
for (const payment of model.payments) {
|
|
148
176
|
if (payment.paymentNote) {
|
|
@@ -166,17 +194,17 @@ function generate(model, options = { deburr: true }) {
|
|
|
166
194
|
if (options.deburr) {
|
|
167
195
|
removeDiacritics(model);
|
|
168
196
|
}
|
|
169
|
-
const payload =
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
const data = Uint8Array.from(compressed.subarray(13));
|
|
197
|
+
const payload = serialize(model);
|
|
198
|
+
const withChecksum = addChecksum(payload);
|
|
199
|
+
const compressed = Uint8Array.from(lzma.compress(withChecksum));
|
|
200
|
+
/** Exclude the LZMA header and retain raw compressed data */
|
|
201
|
+
const _headerLzma = Uint8Array.from(compressed.subarray(0, 13));
|
|
202
|
+
const compressedPayload = Uint8Array.from(compressed.subarray(13));
|
|
176
203
|
const output = Uint8Array.from([
|
|
177
|
-
...
|
|
178
|
-
...
|
|
179
|
-
...
|
|
204
|
+
...headerBysquare([0x00, 1 /* Version["1.1.0"] */, 0x00, 0x00]),
|
|
205
|
+
...headerLzmaProps(),
|
|
206
|
+
...headerDataLength(withChecksum.byteLength),
|
|
207
|
+
...compressedPayload
|
|
180
208
|
]);
|
|
181
209
|
return rfc4648_1.base32hex.stringify(output, {
|
|
182
210
|
pad: false
|
package/lib/cjs/package.json
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bysquare",
|
|
3
3
|
"description": "It's a national standard for payment QR codes adopted by Slovak Banking Association (SBA)",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"type": "commonjs",
|
|
7
6
|
"funding": "https://github.com/sponsors/xseman",
|
|
8
7
|
"homepage": "https://github.com/xseman/bysquare#readme",
|
|
9
|
-
"author":
|
|
10
|
-
|
|
11
|
-
"
|
|
8
|
+
"author": "Filip Seman <filip.seman@pm.me>",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"pay by square",
|
|
11
|
+
"by square",
|
|
12
|
+
"paybysquare",
|
|
13
|
+
"bysquare",
|
|
14
|
+
"payments",
|
|
15
|
+
"qr-string",
|
|
16
|
+
"generate",
|
|
17
|
+
"parse"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/xseman/bysquare.git"
|
|
12
22
|
},
|
|
13
23
|
"scripts": {
|
|
14
24
|
"prebuild": "rm -rf ./lib || :",
|
|
@@ -27,17 +37,18 @@
|
|
|
27
37
|
"dependencies": {
|
|
28
38
|
"crc-32": "~1.2.0",
|
|
29
39
|
"lodash.deburr": "~4.1.0",
|
|
30
|
-
"
|
|
40
|
+
"lzma1": "~0.0.1",
|
|
31
41
|
"rfc4648": "~1.5.0"
|
|
32
42
|
},
|
|
33
43
|
"devDependencies": {
|
|
34
44
|
"@types/lodash.deburr": "~4.1.0",
|
|
35
|
-
"@types/
|
|
36
|
-
"
|
|
45
|
+
"@types/node": ">=16.14",
|
|
46
|
+
"dprint": "~0.35.0",
|
|
37
47
|
"tsx": "~3.12.0",
|
|
38
|
-
"typescript": "~
|
|
48
|
+
"typescript": "~5.0.0",
|
|
39
49
|
"xv": "~2.1.0"
|
|
40
50
|
},
|
|
51
|
+
"type": "commonjs",
|
|
41
52
|
"bin": "lib/mjs/cli.js",
|
|
42
53
|
"types": "lib/mjs/index.d.ts",
|
|
43
54
|
"exports": {
|
|
@@ -51,21 +62,7 @@
|
|
|
51
62
|
"!lib/*.test.*"
|
|
52
63
|
],
|
|
53
64
|
"engines": {
|
|
54
|
-
"node": ">=16.
|
|
65
|
+
"node": ">=16.14",
|
|
55
66
|
"npm": ">=7.0"
|
|
56
|
-
}
|
|
57
|
-
"repository": {
|
|
58
|
-
"type": "git",
|
|
59
|
-
"url": "git+https://github.com/xseman/bysquare.git"
|
|
60
|
-
},
|
|
61
|
-
"keywords": [
|
|
62
|
-
"pay by square",
|
|
63
|
-
"by square",
|
|
64
|
-
"paybysquare",
|
|
65
|
-
"bysquare",
|
|
66
|
-
"payments",
|
|
67
|
-
"qr-string",
|
|
68
|
-
"qr",
|
|
69
|
-
"cli"
|
|
70
|
-
]
|
|
67
|
+
}
|
|
71
68
|
}
|
package/lib/cjs/parse.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { DataModel } from "./index.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Generating by square Code
|
|
4
|
+
*
|
|
5
|
+
* @see 3.14.
|
|
4
6
|
*/
|
|
5
|
-
export declare function
|
|
7
|
+
export declare function deserialize(qr: string): DataModel;
|
|
8
|
+
export declare class DecodeError extends Error {
|
|
9
|
+
cause: Error;
|
|
10
|
+
name: string;
|
|
11
|
+
constructor(cause: Error, msg?: string);
|
|
12
|
+
}
|
|
6
13
|
/**
|
|
7
|
-
*
|
|
14
|
+
* Decoding client data from QR Code 2005 symbol
|
|
15
|
+
*
|
|
16
|
+
* @see 3.16.
|
|
8
17
|
*/
|
|
9
18
|
export declare function parse(qr: string): DataModel;
|
|
10
19
|
/**
|