@aidc-toolkit/utility 1.0.46 → 1.0.47-beta
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/dist/character-set.d.ts +242 -0
- package/dist/character-set.d.ts.map +1 -0
- package/dist/character-set.js +542 -0
- package/dist/character-set.js.map +1 -0
- package/dist/exclusion.d.ts +26 -0
- package/dist/exclusion.d.ts.map +1 -0
- package/dist/exclusion.js +18 -0
- package/dist/exclusion.js.map +1 -0
- package/dist/index.d.ts +26 -699
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -0
- package/dist/iterable-utility.d.ts +39 -0
- package/dist/iterable-utility.d.ts.map +1 -0
- package/dist/iterable-utility.js +35 -0
- package/dist/iterable-utility.js.map +1 -0
- package/dist/locale/en/locale-resources.d.ts +33 -0
- package/dist/locale/en/locale-resources.d.ts.map +1 -0
- package/dist/locale/en/locale-resources.js +32 -0
- package/dist/locale/en/locale-resources.js.map +1 -0
- package/dist/locale/fr/locale-resources.d.ts +33 -0
- package/dist/locale/fr/locale-resources.d.ts.map +1 -0
- package/dist/locale/fr/locale-resources.js +32 -0
- package/dist/locale/fr/locale-resources.js.map +1 -0
- package/dist/locale/i18n.d.ts +27 -0
- package/dist/locale/i18n.d.ts.map +1 -0
- package/dist/locale/i18n.js +34 -0
- package/dist/locale/i18n.js.map +1 -0
- package/dist/record.d.ts +37 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +58 -0
- package/dist/record.js.map +1 -0
- package/dist/reg-exp.d.ts +40 -0
- package/dist/reg-exp.d.ts.map +1 -0
- package/dist/reg-exp.js +55 -0
- package/dist/reg-exp.js.map +1 -0
- package/dist/sequence.d.ts +45 -0
- package/dist/sequence.d.ts.map +1 -0
- package/dist/sequence.js +96 -0
- package/dist/sequence.js.map +1 -0
- package/dist/string.d.ts +25 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +2 -0
- package/dist/string.js.map +1 -0
- package/dist/transformer.d.ts +191 -0
- package/dist/transformer.d.ts.map +1 -0
- package/dist/transformer.js +459 -0
- package/dist/transformer.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +3 -3
- package/src/version.ts +1 -1
- package/tsconfig-src.tsbuildinfo +1 -1
- package/dist/index.cjs +0 -17
- package/dist/index.d.cts +0 -699
package/dist/reg-exp.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { i18nextUtility } from "./locale/i18n.js";
|
|
2
|
+
/**
|
|
3
|
+
* Regular expression validator. The regular expression applies to the full string only if constructed as such. For
|
|
4
|
+
* example, <code>/\d*/</code> (0 or more digits) matches every string, <code>/\d+/</code> (1
|
|
5
|
+
* or more digits) matches strings with at least one digit, <code>/^\d*$/</code> matches strings that are
|
|
6
|
+
* all digits or empty, and <code>/^\d+$/</code> matches strings that are all digits and not empty.
|
|
7
|
+
*
|
|
8
|
+
* Clients of this class are recommended to override the {@linkcode createErrorMessage | createErrorMessage()} method
|
|
9
|
+
* to create a more suitable error message for their use case.
|
|
10
|
+
*/
|
|
11
|
+
export class RegExpValidator {
|
|
12
|
+
/**
|
|
13
|
+
* Regular expression.
|
|
14
|
+
*/
|
|
15
|
+
#regExp;
|
|
16
|
+
/**
|
|
17
|
+
* Constructor.
|
|
18
|
+
*
|
|
19
|
+
* @param regExp
|
|
20
|
+
* Regular expression. See {@link RegExpValidator | class documentation} for notes.
|
|
21
|
+
*/
|
|
22
|
+
constructor(regExp) {
|
|
23
|
+
this.#regExp = regExp;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the regular expression.
|
|
27
|
+
*/
|
|
28
|
+
get regExp() {
|
|
29
|
+
return this.#regExp;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create an error message for a string. The generic error message is sufficient for many use cases but a more
|
|
33
|
+
* domain-specific error message, possibly including the pattern itself, is often required.
|
|
34
|
+
*
|
|
35
|
+
* @param s
|
|
36
|
+
* String.
|
|
37
|
+
*
|
|
38
|
+
* @returns
|
|
39
|
+
* Error message.
|
|
40
|
+
*/
|
|
41
|
+
createErrorMessage(s) {
|
|
42
|
+
return i18nextUtility.t("RegExpValidator.stringDoesNotMatchPattern", {
|
|
43
|
+
s
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @inheritDoc
|
|
48
|
+
*/
|
|
49
|
+
validate(s) {
|
|
50
|
+
if (!this.#regExp.test(s)) {
|
|
51
|
+
throw new RangeError(this.createErrorMessage(s));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=reg-exp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reg-exp.js","sourceRoot":"","sources":["../src/reg-exp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAe;IACxB;;OAEG;IACM,OAAO,CAAS;IAEzB;;;;;OAKG;IACH,YAAY,MAAc;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED;;;;;;;;;OASG;IACO,kBAAkB,CAAC,CAAS;QAClC,OAAO,cAAc,CAAC,CAAC,CAAC,2CAA2C,EAAE;YACjE,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,CAAS;QACd,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sequence. Defines an ascending or descending sequence of big integers implemented as an iterable.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Sequence implements Iterable<bigint> {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* Constructor.
|
|
8
|
+
*
|
|
9
|
+
* @param startValue
|
|
10
|
+
* Start value.
|
|
11
|
+
*
|
|
12
|
+
* @param count
|
|
13
|
+
* Count of values. If count is zero or positive, iteration ascends from start value, otherwise it descends from
|
|
14
|
+
* start value.
|
|
15
|
+
*/
|
|
16
|
+
constructor(startValue: number | bigint, count: number);
|
|
17
|
+
/**
|
|
18
|
+
* Get the start value (inclusive).
|
|
19
|
+
*/
|
|
20
|
+
get startValue(): bigint;
|
|
21
|
+
/**
|
|
22
|
+
* Get the end value (exclusive).
|
|
23
|
+
*/
|
|
24
|
+
get endValue(): bigint;
|
|
25
|
+
/**
|
|
26
|
+
* Get the count of values.
|
|
27
|
+
*/
|
|
28
|
+
get count(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Get the minimum value (inclusive).
|
|
31
|
+
*/
|
|
32
|
+
get minimumValue(): bigint;
|
|
33
|
+
/**
|
|
34
|
+
* Get the maximum value (inclusive).
|
|
35
|
+
*/
|
|
36
|
+
get maximumValue(): bigint;
|
|
37
|
+
/**
|
|
38
|
+
* Iterable implementation.
|
|
39
|
+
*
|
|
40
|
+
* @yields
|
|
41
|
+
* Next value in sequence.
|
|
42
|
+
*/
|
|
43
|
+
[Symbol.iterator](): Generator<bigint>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=sequence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,QAAS,YAAW,QAAQ,CAAC,MAAM,CAAC;;IA+B7C;;;;;;;;;OASG;gBACS,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM;IAgBtD;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;;;;OAKG;IACD,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC;CAK3C"}
|
package/dist/sequence.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sequence. Defines an ascending or descending sequence of big integers implemented as an iterable.
|
|
3
|
+
*/
|
|
4
|
+
export class Sequence {
|
|
5
|
+
/**
|
|
6
|
+
* Start value (inclusive).
|
|
7
|
+
*/
|
|
8
|
+
#startValue;
|
|
9
|
+
/**
|
|
10
|
+
* End value (exclusive).
|
|
11
|
+
*/
|
|
12
|
+
#endValue;
|
|
13
|
+
/**
|
|
14
|
+
* Count of values.
|
|
15
|
+
*/
|
|
16
|
+
#count;
|
|
17
|
+
/**
|
|
18
|
+
* Delta to the next value; equal to the sign of the count.
|
|
19
|
+
*/
|
|
20
|
+
#nextDelta;
|
|
21
|
+
/**
|
|
22
|
+
* Minimum value (inclusive).
|
|
23
|
+
*/
|
|
24
|
+
#minimumValue;
|
|
25
|
+
/**
|
|
26
|
+
* Maximum value (inclusive).
|
|
27
|
+
*/
|
|
28
|
+
#maximumValue;
|
|
29
|
+
/**
|
|
30
|
+
* Constructor.
|
|
31
|
+
*
|
|
32
|
+
* @param startValue
|
|
33
|
+
* Start value.
|
|
34
|
+
*
|
|
35
|
+
* @param count
|
|
36
|
+
* Count of values. If count is zero or positive, iteration ascends from start value, otherwise it descends from
|
|
37
|
+
* start value.
|
|
38
|
+
*/
|
|
39
|
+
constructor(startValue, count) {
|
|
40
|
+
this.#startValue = BigInt(startValue);
|
|
41
|
+
this.#endValue = this.#startValue + BigInt(count);
|
|
42
|
+
this.#count = count;
|
|
43
|
+
if (count >= 0) {
|
|
44
|
+
this.#nextDelta = 1n;
|
|
45
|
+
this.#minimumValue = this.#startValue;
|
|
46
|
+
this.#maximumValue = this.#endValue - 1n;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.#nextDelta = -1n;
|
|
50
|
+
this.#minimumValue = this.#endValue + 1n;
|
|
51
|
+
this.#maximumValue = this.#startValue;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get the start value (inclusive).
|
|
56
|
+
*/
|
|
57
|
+
get startValue() {
|
|
58
|
+
return this.#startValue;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the end value (exclusive).
|
|
62
|
+
*/
|
|
63
|
+
get endValue() {
|
|
64
|
+
return this.#endValue;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the count of values.
|
|
68
|
+
*/
|
|
69
|
+
get count() {
|
|
70
|
+
return this.#count;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the minimum value (inclusive).
|
|
74
|
+
*/
|
|
75
|
+
get minimumValue() {
|
|
76
|
+
return this.#minimumValue;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the maximum value (inclusive).
|
|
80
|
+
*/
|
|
81
|
+
get maximumValue() {
|
|
82
|
+
return this.#maximumValue;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Iterable implementation.
|
|
86
|
+
*
|
|
87
|
+
* @yields
|
|
88
|
+
* Next value in sequence.
|
|
89
|
+
*/
|
|
90
|
+
*[Symbol.iterator]() {
|
|
91
|
+
for (let value = this.#startValue; value !== this.#endValue; value += this.#nextDelta) {
|
|
92
|
+
yield value;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
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,CAAC;IAED;;OAEG;IACH,IAAI,YAAY;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAI,YAAY;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACH,CAAE,CAAC,MAAM,CAAC,QAAQ,CAAC;QACf,KAAK,IAAI,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,IAAI,CAAC,SAAS,EAAE,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpF,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ"}
|
package/dist/string.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String validation interface. To ensure signature compatibility in implementing classes, string validation is
|
|
3
|
+
* controlled by validation interfaces specific to each validator type.
|
|
4
|
+
*/
|
|
5
|
+
export interface StringValidation {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* String validator interface.
|
|
9
|
+
*
|
|
10
|
+
* @template TStringValidation
|
|
11
|
+
* String validation type.
|
|
12
|
+
*/
|
|
13
|
+
export interface StringValidator<TStringValidation extends StringValidation = StringValidation> {
|
|
14
|
+
/**
|
|
15
|
+
* Validate a string and throw an error if validation fails.
|
|
16
|
+
*
|
|
17
|
+
* @param s
|
|
18
|
+
* String.
|
|
19
|
+
*
|
|
20
|
+
* @param validation
|
|
21
|
+
* String validation parameters.
|
|
22
|
+
*/
|
|
23
|
+
validate: (s: string, validation?: TStringValidation) => void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,gBAAgB;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,iBAAiB,SAAS,gBAAgB,GAAG,gBAAgB;IAC1F;;;;;;;;OAQG;IACH,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;CACjE"}
|
package/dist/string.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { type IndexedCallback } from "./iterable-utility.js";
|
|
2
|
+
/**
|
|
3
|
+
* Transformer that transforms values in a numeric domain to values in a range equal to the domain or to another range
|
|
4
|
+
* defined by a callback function. In other words, the domain determines valid input values and, without a callback, the
|
|
5
|
+
* range of valid output values.
|
|
6
|
+
*
|
|
7
|
+
* The concept is similar to {@link https://en.wikipedia.org/wiki/Format-preserving_encryption | format-preserving
|
|
8
|
+
* encryption}, where input values within a specified domain (e.g., {@link
|
|
9
|
+
* https://en.wikipedia.org/wiki/Payment_card_number | payment card numbers} ranging from 8-19 digits) are transformed
|
|
10
|
+
* into values in the same domain, typically for storage in a database where the data type and length are already fixed
|
|
11
|
+
* and exfiltration of the data can have significant repercussions.
|
|
12
|
+
*
|
|
13
|
+
* Two subclasses are supported directly by this class: {@linkcode IdentityTransformer} (which operates based on a
|
|
14
|
+
* domain only) and {@linkcode EncryptionTransformer} (which operates based on a domain and a tweak). If an application
|
|
15
|
+
* is expected to make repeated use of a transformer with the same domain and (optional) tweak and can't manage the
|
|
16
|
+
* transformer object, an in-memory cache is available via the {@linkcode get | get()} method. Properties in {@linkcode
|
|
17
|
+
* IdentityTransformer} and {@linkcode EncryptionTransformer} are read-only once constructed, so there is no issue with
|
|
18
|
+
* their shared use.
|
|
19
|
+
*/
|
|
20
|
+
export declare abstract class Transformer {
|
|
21
|
+
#private;
|
|
22
|
+
/**
|
|
23
|
+
* Constructor.
|
|
24
|
+
*
|
|
25
|
+
* @param domain
|
|
26
|
+
* Domain.
|
|
27
|
+
*/
|
|
28
|
+
constructor(domain: number | bigint);
|
|
29
|
+
/**
|
|
30
|
+
* Get a transformer, constructing it if necessary. The type returned is {@linkcode IdentityTransformer} if tweak is
|
|
31
|
+
* undefined, {@linkcode EncryptionTransformer} if tweak is defined. Note that although an {@linkcode
|
|
32
|
+
* EncryptionTransformer} with a zero tweak operates as an {@linkcode IdentityTransformer}, {@linkcode
|
|
33
|
+
* EncryptionTransformer} is still the type returned if a zero tweak is explicitly specified.
|
|
34
|
+
*
|
|
35
|
+
* @param domain
|
|
36
|
+
* Domain.
|
|
37
|
+
*
|
|
38
|
+
* @param tweak
|
|
39
|
+
* Tweak.
|
|
40
|
+
*
|
|
41
|
+
* @returns
|
|
42
|
+
* Transformer.
|
|
43
|
+
*/
|
|
44
|
+
static get(domain: number | bigint, tweak?: number | bigint): Transformer;
|
|
45
|
+
/**
|
|
46
|
+
* Get the domain.
|
|
47
|
+
*/
|
|
48
|
+
get domain(): bigint;
|
|
49
|
+
/**
|
|
50
|
+
* Do the work of transforming a value forward.
|
|
51
|
+
*
|
|
52
|
+
* @param value
|
|
53
|
+
* Value.
|
|
54
|
+
*
|
|
55
|
+
* @returns
|
|
56
|
+
* Transformed value.
|
|
57
|
+
*/
|
|
58
|
+
protected abstract doForward(value: bigint): bigint;
|
|
59
|
+
/**
|
|
60
|
+
* Transform a value forward.
|
|
61
|
+
*
|
|
62
|
+
* @param value
|
|
63
|
+
* Value.
|
|
64
|
+
*
|
|
65
|
+
* @returns
|
|
66
|
+
* Transformed value.
|
|
67
|
+
*/
|
|
68
|
+
forward(value: number | bigint): bigint;
|
|
69
|
+
/**
|
|
70
|
+
* Transform a value forward and apply another transformation.
|
|
71
|
+
*
|
|
72
|
+
* @template TOutput
|
|
73
|
+
* Transformer callback output type.
|
|
74
|
+
*
|
|
75
|
+
* @param value
|
|
76
|
+
* Value.
|
|
77
|
+
*
|
|
78
|
+
* @param transformerCallback
|
|
79
|
+
* Called with interim transformed value to transform it to its final value.
|
|
80
|
+
*
|
|
81
|
+
* @returns
|
|
82
|
+
* Transformed value.
|
|
83
|
+
*/
|
|
84
|
+
forward<TOutput>(value: number | bigint, transformerCallback: IndexedCallback<bigint, TOutput>): TOutput;
|
|
85
|
+
/**
|
|
86
|
+
* Transform values forward.
|
|
87
|
+
*
|
|
88
|
+
* @param values
|
|
89
|
+
* Values. If this is an instance of {@linkcode Sequence}, the minimum and maximum values are validated prior to
|
|
90
|
+
* transformation. Otherwise, the individual values are validated at the time of each transformation.
|
|
91
|
+
*
|
|
92
|
+
* @returns
|
|
93
|
+
* Transformed values.
|
|
94
|
+
*/
|
|
95
|
+
forward(values: Iterable<number | bigint>): Iterable<bigint>;
|
|
96
|
+
/**
|
|
97
|
+
* Transform values forward and apply another transformation to each.
|
|
98
|
+
*
|
|
99
|
+
* @template TOutput
|
|
100
|
+
* Transformer callback output type.
|
|
101
|
+
*
|
|
102
|
+
* @param values
|
|
103
|
+
* Values. If this is an instance of {@linkcode Sequence}, the minimum and maximum values are validated prior to
|
|
104
|
+
* transformation. Otherwise, the individual values are validated at the time of each transformation.
|
|
105
|
+
*
|
|
106
|
+
* @param transformerCallback
|
|
107
|
+
* Called with each interim transformed value to transform it to its final value.
|
|
108
|
+
*
|
|
109
|
+
* @returns
|
|
110
|
+
* Transformed values.
|
|
111
|
+
*/
|
|
112
|
+
forward<TOutput>(values: Iterable<number | bigint>, transformerCallback: IndexedCallback<bigint, TOutput>): Iterable<TOutput>;
|
|
113
|
+
forward<TInput extends number | bigint | Iterable<number | bigint>>(valueOrValues: TInput extends Iterable<number | bigint> ? TInput : number | bigint): TInput extends Iterable<number | bigint> ? Iterable<bigint> : bigint;
|
|
114
|
+
forward<TInput extends number | bigint | Iterable<number | bigint>, TOutput>(valueOrValues: TInput extends Iterable<number | bigint> ? TInput : number | bigint, transformerCallback: IndexedCallback<bigint, TOutput>): TInput extends Iterable<number | bigint> ? Iterable<TOutput> : TOutput;
|
|
115
|
+
/**
|
|
116
|
+
* Do the work of transforming a value in reverse.
|
|
117
|
+
*
|
|
118
|
+
* @param transformedValue
|
|
119
|
+
* Transformed value.
|
|
120
|
+
*
|
|
121
|
+
* @returns
|
|
122
|
+
* Value.
|
|
123
|
+
*/
|
|
124
|
+
protected abstract doReverse(transformedValue: bigint): bigint;
|
|
125
|
+
/**
|
|
126
|
+
* Transform a value in reverse.
|
|
127
|
+
*
|
|
128
|
+
* @param transformedValue
|
|
129
|
+
* Transformed value.
|
|
130
|
+
*
|
|
131
|
+
* @returns
|
|
132
|
+
* Value.
|
|
133
|
+
*/
|
|
134
|
+
reverse(transformedValue: number | bigint): bigint;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Identity transformer. Values are transformed to themselves.
|
|
138
|
+
*/
|
|
139
|
+
export declare class IdentityTransformer extends Transformer {
|
|
140
|
+
/**
|
|
141
|
+
* @inheritDoc
|
|
142
|
+
*/
|
|
143
|
+
protected doForward(value: bigint): bigint;
|
|
144
|
+
/**
|
|
145
|
+
* @inheritDoc
|
|
146
|
+
*/
|
|
147
|
+
protected doReverse(transformedValue: bigint): bigint;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Encryption transformer. Values are transformed using repeated shuffle and xor operations, similar to those found in
|
|
151
|
+
* many cryptography algorithms, particularly AES. While sufficient for obfuscation of numeric sequences (e.g., serial
|
|
152
|
+
* number generation, below), if true format-preserving encryption is required, a more robust algorithm such as {@link
|
|
153
|
+
* https://doi.org/10.6028/NIST.SP.800-38Gr1.2pd | FF1} is recommended. Furthermore, no work has been done to mitigate
|
|
154
|
+
* {@link https://timing.attacks.cr.yp.to/index.html | timing attacks} for key detection.
|
|
155
|
+
*
|
|
156
|
+
* The purpose of the encryption transformer is to generate pseudo-random values in a deterministic manner to obscure
|
|
157
|
+
* the sequence of values generated over time. A typical example is for serial number generation, where knowledge of the
|
|
158
|
+
* sequence can infer production volumes (e.g., serial number 1000 implies that at least 1,000 units have been
|
|
159
|
+
* manufactured) or can be used in counterfeiting (e.g., a counterfeiter can generate serial numbers 1001, 1002, ...
|
|
160
|
+
* with reasonable confidence that they would be valid if queried).
|
|
161
|
+
*
|
|
162
|
+
* The domain and the tweak together determine the encryption key, which in turn determines the number of rounds of
|
|
163
|
+
* shuffle and xor operations. The minimum number of rounds is 4, except where the domain is less than or equal to 256,
|
|
164
|
+
* which results in single-byte operations. To ensure that the operations are effective for single-byte domains, the
|
|
165
|
+
* number of rounds is 1 and only the xor operation is applied (shuffling a single byte is an identity operation).
|
|
166
|
+
*
|
|
167
|
+
* Another exception is when there is a tweak value of 0; this results in identity operations where the output value is
|
|
168
|
+
* identical to the input value, as no shuffle or xor takes place.
|
|
169
|
+
*/
|
|
170
|
+
export declare class EncryptionTransformer extends Transformer {
|
|
171
|
+
#private;
|
|
172
|
+
/**
|
|
173
|
+
* Constructor.
|
|
174
|
+
*
|
|
175
|
+
* @param domain
|
|
176
|
+
* Domain.
|
|
177
|
+
*
|
|
178
|
+
* @param tweak
|
|
179
|
+
* Tweak.
|
|
180
|
+
*/
|
|
181
|
+
constructor(domain: number | bigint, tweak: number | bigint);
|
|
182
|
+
/**
|
|
183
|
+
* @inheritDoc
|
|
184
|
+
*/
|
|
185
|
+
protected doForward(value: bigint): bigint;
|
|
186
|
+
/**
|
|
187
|
+
* @inheritDoc
|
|
188
|
+
*/
|
|
189
|
+
protected doReverse(transformedValue: bigint): bigint;
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=transformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAe,MAAM,uBAAuB,CAAC;AAI1E;;;;;;;;;;;;;;;;;GAiBG;AACH,8BAAsB,WAAW;;IAW7B;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,GAAG,MAAM;IAUnC;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,GAAG,CAAC,MAA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