@digitaldefiance/node-ecies-lib 4.12.5 → 4.12.8
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/package.json +4 -2
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +2 -0
- package/src/index.js.map +1 -1
- package/src/services/crc.d.ts +87 -0
- package/src/services/crc.d.ts.map +1 -0
- package/src/services/crc.js +198 -0
- package/src/services/crc.js.map +1 -0
- package/src/transforms/checksumTransform.d.ts +8 -0
- package/src/transforms/checksumTransform.d.ts.map +1 -0
- package/src/transforms/checksumTransform.js +23 -0
- package/src/transforms/checksumTransform.js.map +1 -0
- package/src/transforms/eciesDecryptTransform.d.ts +14 -0
- package/src/transforms/eciesDecryptTransform.d.ts.map +1 -0
- package/src/transforms/eciesDecryptTransform.js +80 -0
- package/src/transforms/eciesDecryptTransform.js.map +1 -0
- package/src/transforms/eciesEncryptTransform.d.ts +17 -0
- package/src/transforms/eciesEncryptTransform.d.ts.map +1 -0
- package/src/transforms/eciesEncryptTransform.js +93 -0
- package/src/transforms/eciesEncryptTransform.js.map +1 -0
- package/src/transforms/index.d.ts +6 -0
- package/src/transforms/index.d.ts.map +1 -0
- package/src/transforms/index.js +9 -0
- package/src/transforms/index.js.map +1 -0
- package/src/transforms/xorMultipleTransform.d.ts +13 -0
- package/src/transforms/xorMultipleTransform.d.ts.map +1 -0
- package/src/transforms/xorMultipleTransform.js +56 -0
- package/src/transforms/xorMultipleTransform.js.map +1 -0
- package/src/transforms/xorTransform.d.ts +9 -0
- package/src/transforms/xorTransform.d.ts.map +1 -0
- package/src/transforms/xorTransform.js +31 -0
- package/src/transforms/xorTransform.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/node-ecies-lib",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.8",
|
|
4
4
|
"description": "Digital Defiance Node ECIES Library",
|
|
5
5
|
"homepage": "https://github.com/Digital-Defiance/node-ecies-lib",
|
|
6
6
|
"repository": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"license": "MIT",
|
|
63
63
|
"packageManager": "yarn@4.10.3",
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@digitaldefiance/ecies-lib": "4.12.
|
|
65
|
+
"@digitaldefiance/ecies-lib": "4.12.8",
|
|
66
66
|
"@digitaldefiance/express-suite-test-utils": "1.0.14",
|
|
67
67
|
"@digitaldefiance/i18n-lib": "3.8.16",
|
|
68
68
|
"@ethereumjs/wallet": "^10.0.0",
|
|
@@ -70,7 +70,9 @@
|
|
|
70
70
|
"@noble/hashes": "1.8.0",
|
|
71
71
|
"@scure/bip32": "1.7.0",
|
|
72
72
|
"bson": "^6.10.4",
|
|
73
|
+
"crc": "^4.3.2",
|
|
73
74
|
"ethereum-cryptography": "^3.2.0",
|
|
75
|
+
"js-sha3": "^0.9.3",
|
|
74
76
|
"paillier-bigint": "^3.4.1",
|
|
75
77
|
"ts-brand": "^0.2.0"
|
|
76
78
|
},
|
package/src/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './interfaces';
|
|
|
8
8
|
export * from './member';
|
|
9
9
|
export * from './types';
|
|
10
10
|
export * from './secure-buffer';
|
|
11
|
+
export * from './transforms';
|
|
11
12
|
export { AESGCMService } from './services/aes-gcm';
|
|
12
13
|
export { ChunkProcessor } from './services/chunk-processor';
|
|
13
14
|
export * from './services/ecies';
|
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-ecies-lib/src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AAGtB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ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AE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,cAAc,2BAA2B,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,YAAY,EACV,UAAU,EACV,SAAS,EACT,OAAO,IAAI,eAAe,GAC3B,MAAM,iBAAiB,CAAC;AAGzB,cAAc,uBAAuB,CAAC"}
|
package/src/index.js
CHANGED
|
@@ -14,6 +14,8 @@ tslib_1.__exportStar(require("./interfaces"), exports);
|
|
|
14
14
|
tslib_1.__exportStar(require("./member"), exports);
|
|
15
15
|
tslib_1.__exportStar(require("./types"), exports);
|
|
16
16
|
tslib_1.__exportStar(require("./secure-buffer"), exports);
|
|
17
|
+
// Transforms - stream transforms for encryption/decryption
|
|
18
|
+
tslib_1.__exportStar(require("./transforms"), exports);
|
|
17
19
|
// Services - explicit exports to avoid conflicts
|
|
18
20
|
var aes_gcm_1 = require("./services/aes-gcm");
|
|
19
21
|
Object.defineProperty(exports, "AESGCMService", { enumerable: true, get: function () { return aes_gcm_1.AESGCMService; } });
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-ecies-lib/src/index.ts"],"names":[],"mappings":";;;;AAAA,0BAA0B;AAC1B,qDAA2B;AAC3B,iDAAuB;AACvB,gDAAsB;AAEtB,4CAA4C;AAC5C,sDAA4B;AAC5B,yDAA+B;AAC/B,iDAAuB;AACvB,uDAA6B;AAC7B,mDAAyB;AACzB,kDAAwB;AACxB,0DAAgC;AAEhC,iDAAiD;AACjD,8CAAmD;AAA1C,wGAAA,aAAa,OAAA;AACtB,8DAA4D;AAAnD,iHAAA,cAAc,OAAA;AACvB,2DAAiC;AACjC,kEAAgE;AAAvD,qHAAA,gBAAgB,OAAA;AACzB,kFAA+E;AAAtE,oIAAA,uBAAuB,OAAA;AAChC,4CAAkD;AAAzC,uGAAA,aAAa,OAAA;AACtB,gEAA8D;AAArD,mHAAA,eAAe,OAAA;AACxB,oEAA0C;AAE1C,kCAAkC;AAClC,qDAAsD;AAA7C,oHAAA,iBAAiB,OAAA;AAC1B,uDAAwD;AAA/C,sHAAA,kBAAkB,OAAA;AAS3B,iEAAiE;AACjE,gEAAsC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-ecies-lib/src/index.ts"],"names":[],"mappings":";;;;AAAA,0BAA0B;AAC1B,qDAA2B;AAC3B,iDAAuB;AACvB,gDAAsB;AAEtB,4CAA4C;AAC5C,sDAA4B;AAC5B,yDAA+B;AAC/B,iDAAuB;AACvB,uDAA6B;AAC7B,mDAAyB;AACzB,kDAAwB;AACxB,0DAAgC;AAEhC,2DAA2D;AAC3D,uDAA6B;AAE7B,iDAAiD;AACjD,8CAAmD;AAA1C,wGAAA,aAAa,OAAA;AACtB,8DAA4D;AAAnD,iHAAA,cAAc,OAAA;AACvB,2DAAiC;AACjC,kEAAgE;AAAvD,qHAAA,gBAAgB,OAAA;AACzB,kFAA+E;AAAtE,oIAAA,uBAAuB,OAAA;AAChC,4CAAkD;AAAzC,uGAAA,aAAa,OAAA;AACtB,gEAA8D;AAArD,mHAAA,eAAe,OAAA;AACxB,oEAA0C;AAE1C,kCAAkC;AAClC,qDAAsD;AAA7C,oHAAA,iBAAiB,OAAA;AAC1B,uDAAwD;AAA/C,sHAAA,kBAAkB,OAAA;AAS3B,iEAAiE;AACjE,gEAAsC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
export declare class CrcService {
|
|
3
|
+
/**
|
|
4
|
+
* Perform a CRC8 checksum on the data
|
|
5
|
+
* @param data - The data to checksum
|
|
6
|
+
* @returns The CRC8 checksum as a Buffer
|
|
7
|
+
*/
|
|
8
|
+
crc8(data: Buffer): Buffer;
|
|
9
|
+
/**
|
|
10
|
+
* Calculates the CRC8 of a buffer or readable stream
|
|
11
|
+
* @param input - The buffer or readable stream to calculate the CRC8 of
|
|
12
|
+
* @returns The CRC8 as a Buffer
|
|
13
|
+
*/
|
|
14
|
+
crc8Async(input: Buffer | Readable): Promise<Buffer>;
|
|
15
|
+
/**
|
|
16
|
+
* Verify a CRC8 checksum on the data
|
|
17
|
+
* @param data - The data to verify
|
|
18
|
+
* @param expectedCrc - The expected CRC8 checksum
|
|
19
|
+
* @returns True if the checksum matches, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
verifyCrc8(data: Buffer, expectedCrc: Buffer | number): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Validates a CRC8 against a buffer or readable stream
|
|
24
|
+
* @param data The data to validate
|
|
25
|
+
* @param expectedCrc8 The CRC8 to validate against
|
|
26
|
+
* @returns True if the CRC8 is valid, false otherwise
|
|
27
|
+
*/
|
|
28
|
+
verifyCrc8Async(data: Buffer | Readable, expectedCrc8: Buffer): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Perform a CRC16 checksum on the data
|
|
31
|
+
* @param data - The data to checksum
|
|
32
|
+
* @returns The CRC16 checksum as a Buffer
|
|
33
|
+
*/
|
|
34
|
+
crc16(data: Buffer): Buffer;
|
|
35
|
+
/**
|
|
36
|
+
* Calculates the CRC16 of a buffer or readable stream
|
|
37
|
+
* @param input - The buffer or readable stream to calculate the CRC16 of
|
|
38
|
+
* @returns The CRC16 as a Buffer
|
|
39
|
+
*/
|
|
40
|
+
crc16Async(input: Buffer | Readable): Promise<Buffer>;
|
|
41
|
+
/**
|
|
42
|
+
* Verify a CRC16 checksum on the data
|
|
43
|
+
* @param data - The data to verify
|
|
44
|
+
* @param expectedCrc - The expected CRC16 checksum
|
|
45
|
+
* @returns True if the checksum matches, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
verifyCrc16(data: Buffer, expectedCrc: Buffer | number): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Validates a CRC16 against a buffer or readable stream
|
|
50
|
+
* @param data The data to validate
|
|
51
|
+
* @param expectedCrc16 The CRC16 to validate against
|
|
52
|
+
* @returns True if the CRC16 is valid, false otherwise
|
|
53
|
+
*/
|
|
54
|
+
verifyCrc16Async(data: Buffer | Readable, expectedCrc16: Buffer): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Perform a CRC32 checksum on the data
|
|
57
|
+
* @param data - The data to checksum
|
|
58
|
+
* @returns The CRC32 checksum as a Buffer
|
|
59
|
+
*/
|
|
60
|
+
crc32(data: Buffer): Buffer;
|
|
61
|
+
/**
|
|
62
|
+
* Calculates the CRC32 of a buffer or readable stream
|
|
63
|
+
* @param input - The buffer or readable stream to calculate the CRC32 of
|
|
64
|
+
* @returns The CRC32 as a number
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* Calculates the CRC32 of a buffer or readable stream
|
|
68
|
+
* @param input - The buffer or readable stream to calculate the CRC32 of
|
|
69
|
+
* @returns The CRC32 as a Buffer
|
|
70
|
+
*/
|
|
71
|
+
crc32Async(input: Buffer | Readable): Promise<Buffer>;
|
|
72
|
+
/**
|
|
73
|
+
* Verify a CRC32 checksum on the data
|
|
74
|
+
* @param data - The data to verify
|
|
75
|
+
* @param expectedCrc - The expected CRC32 checksum
|
|
76
|
+
* @returns True if the checksum matches, false otherwise
|
|
77
|
+
*/
|
|
78
|
+
verifyCrc32(data: Buffer, expectedCrc: Buffer | number): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Validates a CRC32 against a buffer or readable stream
|
|
81
|
+
* @param data The data to validate
|
|
82
|
+
* @param expectedCrc32 The CRC32 to validate against
|
|
83
|
+
* @returns True if the CRC32 is valid, false otherwise
|
|
84
|
+
*/
|
|
85
|
+
verifyCrc32Async(data: Buffer | Readable, expectedCrc32: Buffer): Promise<boolean>;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=crc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crc.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/services/crc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAIlC,qBAAa,UAAU;IACrB;;;;OAIG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMjC;;;;OAIG;IACU,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAwBjE;;;;;OAKG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IAStE;;;;;OAKG;IACU,eAAe,CAC1B,IAAI,EAAE,MAAM,GAAG,QAAQ,EACvB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,OAAO,CAAC;IAInB;;;;OAIG;IACI,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMlC;;;;OAIG;IACU,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAwBlE;;;;;OAKG;IACI,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IASvE;;;;;OAKG;IACU,gBAAgB,CAC3B,IAAI,EAAE,MAAM,GAAG,QAAQ,EACvB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,OAAO,CAAC;IAInB;;;;OAIG;IACI,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMlC;;;;OAIG;IACH;;;;OAIG;IACU,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBlE;;;;;OAKG;IACI,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IASvE;;;;;OAKG;IACU,gBAAgB,CAC3B,IAAI,EAAE,MAAM,GAAG,QAAQ,EACvB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,OAAO,CAAC;CAIpB"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CrcService = void 0;
|
|
4
|
+
const crc_1 = require("crc");
|
|
5
|
+
class CrcService {
|
|
6
|
+
/**
|
|
7
|
+
* Perform a CRC8 checksum on the data
|
|
8
|
+
* @param data - The data to checksum
|
|
9
|
+
* @returns The CRC8 checksum as a Buffer
|
|
10
|
+
*/
|
|
11
|
+
crc8(data) {
|
|
12
|
+
const crc8buf = Buffer.alloc(1);
|
|
13
|
+
const crc8value = (0, crc_1.crc8)(data);
|
|
14
|
+
crc8buf.writeUInt8(crc8value);
|
|
15
|
+
return crc8buf;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Calculates the CRC8 of a buffer or readable stream
|
|
19
|
+
* @param input - The buffer or readable stream to calculate the CRC8 of
|
|
20
|
+
* @returns The CRC8 as a Buffer
|
|
21
|
+
*/
|
|
22
|
+
async crc8Async(input) {
|
|
23
|
+
if (Buffer.isBuffer(input)) {
|
|
24
|
+
return Promise.resolve(this.crc8(input));
|
|
25
|
+
}
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
let crc8value = (0, crc_1.crc8)(Buffer.alloc(0)); // Initialize with empty buffer
|
|
28
|
+
input.on('data', (chunk) => {
|
|
29
|
+
const tempBuf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
30
|
+
crc8value = (0, crc_1.crc8)(tempBuf, crc8value);
|
|
31
|
+
});
|
|
32
|
+
input.on('end', () => {
|
|
33
|
+
const crc8buf = Buffer.alloc(1);
|
|
34
|
+
crc8buf.writeUInt8(crc8value);
|
|
35
|
+
resolve(crc8buf);
|
|
36
|
+
});
|
|
37
|
+
input.on('error', (error) => {
|
|
38
|
+
reject(error);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Verify a CRC8 checksum on the data
|
|
44
|
+
* @param data - The data to verify
|
|
45
|
+
* @param expectedCrc - The expected CRC8 checksum
|
|
46
|
+
* @returns True if the checksum matches, false otherwise
|
|
47
|
+
*/
|
|
48
|
+
verifyCrc8(data, expectedCrc) {
|
|
49
|
+
const crc8value = (0, crc_1.crc8)(data);
|
|
50
|
+
if (typeof expectedCrc === 'number') {
|
|
51
|
+
return crc8value === expectedCrc;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const expectedCrc8 = expectedCrc.readUInt8();
|
|
55
|
+
return crc8value === expectedCrc8;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Validates a CRC8 against a buffer or readable stream
|
|
60
|
+
* @param data The data to validate
|
|
61
|
+
* @param expectedCrc8 The CRC8 to validate against
|
|
62
|
+
* @returns True if the CRC8 is valid, false otherwise
|
|
63
|
+
*/
|
|
64
|
+
async verifyCrc8Async(data, expectedCrc8) {
|
|
65
|
+
const calculatedCrc8 = await this.crc8Async(data);
|
|
66
|
+
return calculatedCrc8.equals(expectedCrc8);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Perform a CRC16 checksum on the data
|
|
70
|
+
* @param data - The data to checksum
|
|
71
|
+
* @returns The CRC16 checksum as a Buffer
|
|
72
|
+
*/
|
|
73
|
+
crc16(data) {
|
|
74
|
+
const crc16buf = Buffer.alloc(2);
|
|
75
|
+
const crc16value = (0, crc_1.crc16ccitt)(data); // For CRC16-CCITT-FALSE
|
|
76
|
+
crc16buf.writeUInt16BE(crc16value);
|
|
77
|
+
return crc16buf;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Calculates the CRC16 of a buffer or readable stream
|
|
81
|
+
* @param input - The buffer or readable stream to calculate the CRC16 of
|
|
82
|
+
* @returns The CRC16 as a Buffer
|
|
83
|
+
*/
|
|
84
|
+
async crc16Async(input) {
|
|
85
|
+
if (Buffer.isBuffer(input)) {
|
|
86
|
+
return Promise.resolve(this.crc16(input));
|
|
87
|
+
}
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
let crc16value = (0, crc_1.crc16ccitt)(Buffer.alloc(0)); // Initialize with empty buffer
|
|
90
|
+
input.on('data', (chunk) => {
|
|
91
|
+
const tempBuf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
92
|
+
crc16value = (0, crc_1.crc16ccitt)(tempBuf, crc16value);
|
|
93
|
+
});
|
|
94
|
+
input.on('end', () => {
|
|
95
|
+
const crc16buf = Buffer.alloc(2);
|
|
96
|
+
crc16buf.writeUInt16BE(crc16value);
|
|
97
|
+
resolve(crc16buf);
|
|
98
|
+
});
|
|
99
|
+
input.on('error', (error) => {
|
|
100
|
+
reject(error);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Verify a CRC16 checksum on the data
|
|
106
|
+
* @param data - The data to verify
|
|
107
|
+
* @param expectedCrc - The expected CRC16 checksum
|
|
108
|
+
* @returns True if the checksum matches, false otherwise
|
|
109
|
+
*/
|
|
110
|
+
verifyCrc16(data, expectedCrc) {
|
|
111
|
+
const crc16value = (0, crc_1.crc16ccitt)(data); // For CRC16-CCITT-FALSE
|
|
112
|
+
if (typeof expectedCrc === 'number') {
|
|
113
|
+
return crc16value === expectedCrc;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const expectedCrc16 = expectedCrc.readUInt16BE();
|
|
117
|
+
return crc16value === expectedCrc16;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Validates a CRC16 against a buffer or readable stream
|
|
122
|
+
* @param data The data to validate
|
|
123
|
+
* @param expectedCrc16 The CRC16 to validate against
|
|
124
|
+
* @returns True if the CRC16 is valid, false otherwise
|
|
125
|
+
*/
|
|
126
|
+
async verifyCrc16Async(data, expectedCrc16) {
|
|
127
|
+
const calculatedCrc16 = await this.crc16Async(data);
|
|
128
|
+
return calculatedCrc16.equals(expectedCrc16);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Perform a CRC32 checksum on the data
|
|
132
|
+
* @param data - The data to checksum
|
|
133
|
+
* @returns The CRC32 checksum as a Buffer
|
|
134
|
+
*/
|
|
135
|
+
crc32(data) {
|
|
136
|
+
const crc32value = (0, crc_1.crc32)(data);
|
|
137
|
+
const crc32buf = Buffer.alloc(4);
|
|
138
|
+
crc32buf.writeUInt32BE(crc32value);
|
|
139
|
+
return crc32buf;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Calculates the CRC32 of a buffer or readable stream
|
|
143
|
+
* @param input - The buffer or readable stream to calculate the CRC32 of
|
|
144
|
+
* @returns The CRC32 as a number
|
|
145
|
+
*/
|
|
146
|
+
/**
|
|
147
|
+
* Calculates the CRC32 of a buffer or readable stream
|
|
148
|
+
* @param input - The buffer or readable stream to calculate the CRC32 of
|
|
149
|
+
* @returns The CRC32 as a Buffer
|
|
150
|
+
*/
|
|
151
|
+
async crc32Async(input) {
|
|
152
|
+
if (Buffer.isBuffer(input)) {
|
|
153
|
+
return Promise.resolve(this.crc32(input));
|
|
154
|
+
}
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
const chunks = [];
|
|
157
|
+
input.on('data', (chunk) => {
|
|
158
|
+
const tempBuf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
159
|
+
chunks.push(tempBuf);
|
|
160
|
+
});
|
|
161
|
+
input.on('end', () => {
|
|
162
|
+
const fullBuffer = Buffer.concat(chunks);
|
|
163
|
+
resolve(this.crc32(fullBuffer));
|
|
164
|
+
});
|
|
165
|
+
input.on('error', (error) => {
|
|
166
|
+
reject(error);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Verify a CRC32 checksum on the data
|
|
172
|
+
* @param data - The data to verify
|
|
173
|
+
* @param expectedCrc - The expected CRC32 checksum
|
|
174
|
+
* @returns True if the checksum matches, false otherwise
|
|
175
|
+
*/
|
|
176
|
+
verifyCrc32(data, expectedCrc) {
|
|
177
|
+
const crc32value = (0, crc_1.crc32)(data);
|
|
178
|
+
if (typeof expectedCrc === 'number') {
|
|
179
|
+
return crc32value === (expectedCrc >>> 0);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const expectedCrc32 = expectedCrc.readUInt32BE();
|
|
183
|
+
return crc32value === expectedCrc32;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Validates a CRC32 against a buffer or readable stream
|
|
188
|
+
* @param data The data to validate
|
|
189
|
+
* @param expectedCrc32 The CRC32 to validate against
|
|
190
|
+
* @returns True if the CRC32 is valid, false otherwise
|
|
191
|
+
*/
|
|
192
|
+
async verifyCrc32Async(data, expectedCrc32) {
|
|
193
|
+
const calculatedCrc32 = await this.crc32Async(data);
|
|
194
|
+
return calculatedCrc32.equals(expectedCrc32);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.CrcService = CrcService;
|
|
198
|
+
//# sourceMappingURL=crc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crc.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/services/crc.ts"],"names":[],"mappings":";;;AAEA,6BAA8C;AAE9C,MAAa,UAAU;IACrB;;;;OAIG;IACI,IAAI,CAAC,IAAY;QACtB,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,SAAS,GAAG,IAAA,UAAI,EAAC,IAAI,CAAC,CAAC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C3D,MAAM,UAAU,GAAG,IAAA,WAAK,EAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,OAAO,UAAU,KAAK,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,aAAa,GAAG,WAAW,CAAC,YAAY,EAAE,CAAC;YACjD,OAAO,UAAU,KAAK,aAAa,CAAC;QACtC,CAAC;IACH,CAAC;IACD;;;;;OAKG;IACI,KAAK,CAAC,gBAAgB,CAC3B,IAAuB,EACvB,aAAqB;QAErB,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACpD,OAAO,eAAe,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAC/C,CAAC;CACF;AAjND,gCAiNC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Transform, TransformCallback } from 'stream';
|
|
2
|
+
export declare class ChecksumTransform extends Transform {
|
|
3
|
+
private sha3;
|
|
4
|
+
constructor();
|
|
5
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
6
|
+
_flush(callback: TransformCallback): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=checksumTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checksumTransform.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/checksumTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAMtD,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,OAAO,CAAC,IAAI,CAAS;;IAML,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,iBAAiB;IAMb,MAAM,CAAC,QAAQ,EAAE,iBAAiB;CAKnD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChecksumTransform = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const js_sha3_1 = require("js-sha3");
|
|
6
|
+
class ChecksumTransform extends stream_1.Transform {
|
|
7
|
+
sha3;
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.sha3 = js_sha3_1.sha3_512.create();
|
|
11
|
+
}
|
|
12
|
+
_transform(chunk, encoding, callback) {
|
|
13
|
+
this.sha3.update(chunk);
|
|
14
|
+
callback(null, chunk);
|
|
15
|
+
}
|
|
16
|
+
_flush(callback) {
|
|
17
|
+
const checksum = this.sha3.digest();
|
|
18
|
+
this.emit('checksum', Buffer.from(checksum));
|
|
19
|
+
callback();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ChecksumTransform = ChecksumTransform;
|
|
23
|
+
//# sourceMappingURL=checksumTransform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checksumTransform.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/checksumTransform.ts"],"names":[],"mappings":";;;AAAA,mCAAsD;AAEtD,qCAA2C;AAI3C,MAAa,iBAAkB,SAAQ,kBAAS;IACtC,IAAI,CAAS;IACrB;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,kBAAQ,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;IAEe,UAAU,CACxB,KAAa,EACb,QAAwB,EACxB,QAA2B;QAE3B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;IAEe,MAAM,CAAC,QAA2B;QAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAA8B,CAAC,CAAC;QAC1E,QAAQ,EAAE,CAAC;IACb,CAAC;CACF;AArBD,8CAqBC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Transform, TransformCallback, TransformOptions } from 'stream';
|
|
2
|
+
import { PlatformID } from '../interfaces';
|
|
3
|
+
import { ECIESService } from '../services';
|
|
4
|
+
export declare class EciesDecryptionTransform<TID extends PlatformID = Buffer> extends Transform {
|
|
5
|
+
private readonly blockSize;
|
|
6
|
+
private readonly privateKey;
|
|
7
|
+
private buffer;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
private readonly eciesService;
|
|
10
|
+
constructor(eciesService: ECIESService<TID>, privateKey: Buffer, blockSize: number, options?: TransformOptions, logger?: Console);
|
|
11
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
12
|
+
_flush(callback: TransformCallback): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=eciesDecryptTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eciesDecryptTransform.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/eciesDecryptTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAExE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,qBAAa,wBAAwB,CACnC,GAAG,SAAS,UAAU,GAAG,MAAM,CAC/B,SAAQ,SAAS;IACjB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAoB;gBAG/C,YAAY,EAAE,YAAY,CAAC,GAAG,CAAC,EAC/B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,gBAAgB,EAC1B,MAAM,GAAE,OAAiB;IAYX,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,iBAAiB,GAC1B,IAAI;IAkDS,MAAM,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;CAoB1D"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EciesDecryptionTransform = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
class EciesDecryptionTransform extends stream_1.Transform {
|
|
6
|
+
blockSize;
|
|
7
|
+
privateKey;
|
|
8
|
+
buffer;
|
|
9
|
+
logger;
|
|
10
|
+
eciesService;
|
|
11
|
+
constructor(eciesService, privateKey, blockSize, options, logger = console) {
|
|
12
|
+
super(options);
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
this.privateKey = privateKey;
|
|
15
|
+
this.blockSize = blockSize;
|
|
16
|
+
this.buffer = Buffer.alloc(0);
|
|
17
|
+
// Use provided service or create one with GuidV4Provider config
|
|
18
|
+
this.eciesService = eciesService;
|
|
19
|
+
}
|
|
20
|
+
_transform(chunk, encoding, callback) {
|
|
21
|
+
try {
|
|
22
|
+
if (chunk.length === 0) {
|
|
23
|
+
callback();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// Add new chunk to buffer
|
|
27
|
+
this.buffer = Buffer.concat([this.buffer, chunk]);
|
|
28
|
+
// Process complete blocks
|
|
29
|
+
while (this.buffer.length >= this.blockSize) {
|
|
30
|
+
const encryptedBlock = this.buffer.subarray(0, this.blockSize);
|
|
31
|
+
this.buffer = this.buffer.subarray(this.blockSize);
|
|
32
|
+
try {
|
|
33
|
+
const decryptedBlock = this.eciesService.decryptSimpleOrSingleWithHeader(true, // decryptSimple = true
|
|
34
|
+
this.privateKey, encryptedBlock);
|
|
35
|
+
this.push(decryptedBlock);
|
|
36
|
+
}
|
|
37
|
+
catch (decryptError) {
|
|
38
|
+
console.error('Block decryption error:', {
|
|
39
|
+
error: decryptError,
|
|
40
|
+
blockSize: this.blockSize,
|
|
41
|
+
encryptedBlockLength: encryptedBlock.length,
|
|
42
|
+
privateKeyLength: this.privateKey.length,
|
|
43
|
+
});
|
|
44
|
+
throw decryptError;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
callback();
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
this.logger.error('Transform error details:', {
|
|
51
|
+
error,
|
|
52
|
+
blockSize: this.blockSize,
|
|
53
|
+
bufferLength: this.buffer.length,
|
|
54
|
+
chunkLength: chunk.length,
|
|
55
|
+
privateKeyLength: this.privateKey.length,
|
|
56
|
+
});
|
|
57
|
+
const finalError = error instanceof Error ? error : new Error('Decryption failed');
|
|
58
|
+
this.logger.error('Transform error:', finalError);
|
|
59
|
+
callback(finalError);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
_flush(callback) {
|
|
63
|
+
try {
|
|
64
|
+
// Handle any remaining data in buffer
|
|
65
|
+
if (this.buffer.length > 0) {
|
|
66
|
+
const decryptedBlock = this.eciesService.decryptSimpleOrSingleWithHeader(true, // decryptSimple = true
|
|
67
|
+
this.privateKey, this.buffer);
|
|
68
|
+
this.push(decryptedBlock);
|
|
69
|
+
}
|
|
70
|
+
callback();
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
const finalError = error instanceof Error ? error : new Error('Decryption failed');
|
|
74
|
+
this.logger.error('Flush error:', finalError);
|
|
75
|
+
callback(finalError);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.EciesDecryptionTransform = EciesDecryptionTransform;
|
|
80
|
+
//# sourceMappingURL=eciesDecryptTransform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eciesDecryptTransform.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/eciesDecryptTransform.ts"],"names":[],"mappings":";;;AAAA,mCAAwE;AAKxE,MAAa,wBAEX,SAAQ,kBAAS;IACA,SAAS,CAAS;IAClB,UAAU,CAAS;IAC5B,MAAM,CAAS;IACN,MAAM,CAAU;IAChB,YAAY,CAAoB;IAEjD,YACE,YAA+B,EAC/B,UAAkB,EAClB,SAAiB,EACjB,OAA0B,EAC1B,SAAkB,OAAO;QAEzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAmB,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE9B,gEAAgE;QAChE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAEe,UAAU,CACxB,KAAa,EACb,QAAwB,EACxB,QAA2B;QAE3B,IAAI,CAAC;YACH,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvB,QAAQ,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YAED,0BAA0B;YAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;YAElD,0BAA0B;YAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBAC5C,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,C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D,IAAI,CAAC;YACH,sCAAsC;YACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC3B,MAAM,cAAc,GAClB,IAAI,CAAC,YAAY,CAAC,+BAA+B,CAC/C,IAAI,EAAE,uBAAuB;gBAC7B,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,MAAM,CACZ,CAAC;gBACJ,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAC5B,CAAC;YACD,QAAQ,EAAE,CAAC;QACb,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,UAAU,GACd,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAClE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;YAC9C,QAAQ,CAAC,UAAU,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;CACF;AApGD,4DAoGC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Transform, TransformCallback } from 'stream';
|
|
2
|
+
import { ECIESService } from '../services';
|
|
3
|
+
/**
|
|
4
|
+
* Transform stream that encrypts data using ECIES encryption
|
|
5
|
+
*/
|
|
6
|
+
export declare class EciesEncryptTransform extends Transform {
|
|
7
|
+
private readonly blockSize;
|
|
8
|
+
private readonly receiverPublicKey;
|
|
9
|
+
private buffer;
|
|
10
|
+
private readonly capacityPerBlock;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private readonly eciesService;
|
|
13
|
+
constructor(eciesService: ECIESService, blockSize: number, receiverPublicKey: Buffer, logger?: Console);
|
|
14
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
15
|
+
_flush(callback: TransformCallback): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=eciesEncryptTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eciesEncryptTransform.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/eciesEncryptTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,SAAS;IAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;gBAG1C,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,MAAM,EACzB,MAAM,GAAE,OAAiB;IA4BX,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,iBAAiB,GAC1B,IAAI;IAsDS,MAAM,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;CAmB1D"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EciesEncryptTransform = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
/**
|
|
6
|
+
* Transform stream that encrypts data using ECIES encryption
|
|
7
|
+
*/
|
|
8
|
+
class EciesEncryptTransform extends stream_1.Transform {
|
|
9
|
+
blockSize;
|
|
10
|
+
receiverPublicKey;
|
|
11
|
+
buffer;
|
|
12
|
+
capacityPerBlock;
|
|
13
|
+
logger;
|
|
14
|
+
eciesService;
|
|
15
|
+
constructor(eciesService, blockSize, receiverPublicKey, logger = console) {
|
|
16
|
+
super();
|
|
17
|
+
this.logger = logger;
|
|
18
|
+
this.blockSize = blockSize;
|
|
19
|
+
// Validate public key size (should be 33 bytes for compressed or 65 bytes for uncompressed secp256k1 public key)
|
|
20
|
+
if (receiverPublicKey.length !== 33 && receiverPublicKey.length !== 65) {
|
|
21
|
+
throw new Error(`Invalid public key length: expected 33 or 65 bytes, got ${receiverPublicKey.length}`);
|
|
22
|
+
}
|
|
23
|
+
this.receiverPublicKey = receiverPublicKey;
|
|
24
|
+
this.buffer = Buffer.alloc(0);
|
|
25
|
+
this.eciesService = eciesService;
|
|
26
|
+
// Calculate how much data we can encrypt per block
|
|
27
|
+
const encryptedLength = this.eciesService.computeEncryptedLengthFromDataLength(this.blockSize, 'simple');
|
|
28
|
+
// For Simple encryption, capacity = blockSize - overhead
|
|
29
|
+
this.capacityPerBlock = this.blockSize - (encryptedLength - this.blockSize);
|
|
30
|
+
}
|
|
31
|
+
_transform(chunk, encoding, callback) {
|
|
32
|
+
try {
|
|
33
|
+
if (chunk.length === 0) {
|
|
34
|
+
callback();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// Add new chunk to buffer by creating a new Uint8Array with combined length
|
|
38
|
+
const newBuffer = Buffer.alloc(this.buffer.length + chunk.length);
|
|
39
|
+
newBuffer.set(this.buffer);
|
|
40
|
+
newBuffer.set(chunk, this.buffer.length);
|
|
41
|
+
this.buffer = newBuffer;
|
|
42
|
+
// Process complete blocks
|
|
43
|
+
while (this.buffer.length >= this.capacityPerBlock) {
|
|
44
|
+
const blockData = this.buffer.subarray(0, this.capacityPerBlock);
|
|
45
|
+
this.buffer = this.buffer.subarray(this.capacityPerBlock);
|
|
46
|
+
const encryptedBlock = this.eciesService.encryptSimpleOrSingle(true, // encryptSimple = true
|
|
47
|
+
this.receiverPublicKey, blockData);
|
|
48
|
+
this.push(encryptedBlock);
|
|
49
|
+
}
|
|
50
|
+
callback();
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
// Create final error with message
|
|
54
|
+
const finalError = error instanceof Error
|
|
55
|
+
? new Error(`Encryption failed: ${error.message}`)
|
|
56
|
+
: new Error('Encryption failed');
|
|
57
|
+
// Log errors before emitting
|
|
58
|
+
this.logger.error('Encryption error:', finalError);
|
|
59
|
+
this.logger.error('Error details:', {
|
|
60
|
+
error,
|
|
61
|
+
publicKeyLength: this.receiverPublicKey.length,
|
|
62
|
+
publicKeyPrefix: this.receiverPublicKey.subarray(0, 4),
|
|
63
|
+
dataLength: chunk.length,
|
|
64
|
+
blockSize: this.blockSize,
|
|
65
|
+
bufferLength: this.buffer.length,
|
|
66
|
+
capacityPerBlock: this.capacityPerBlock,
|
|
67
|
+
});
|
|
68
|
+
// Emit error event and call callback
|
|
69
|
+
setImmediate(() => {
|
|
70
|
+
this.emit('error', finalError);
|
|
71
|
+
callback(finalError);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
_flush(callback) {
|
|
76
|
+
try {
|
|
77
|
+
// Handle any remaining data in buffer
|
|
78
|
+
if (this.buffer.length > 0) {
|
|
79
|
+
const encryptedBlock = this.eciesService.encryptSimpleOrSingle(true, // encryptSimple = true
|
|
80
|
+
this.receiverPublicKey, this.buffer);
|
|
81
|
+
this.push(encryptedBlock);
|
|
82
|
+
}
|
|
83
|
+
callback();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
const finalError = error instanceof Error ? error : new Error('Encryption failed');
|
|
87
|
+
this.logger.error('Flush error:', finalError);
|
|
88
|
+
callback(finalError);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.EciesEncryptTransform = EciesEncryptTransform;
|
|
93
|
+
//# sourceMappingURL=eciesEncryptTransform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eciesEncryptTransform.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/eciesEncryptTransform.ts"],"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BAAiB,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;gBACtD,UAAU,EAAE,KAAK,CAAC,MAAM;gBACxB,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAChC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;aACxC,CAAC,CAAC;YAEH,qCAAqC;YACrC,YAAY,CAAC,GAAG,EAAE;gBAChB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;gBAC/B,QAAQ,CAAC,UAAU,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEe,MAAM,CAAC,QAA2B;QAChD,IAAI,CAAC;YACH,sCAAsC;YACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC3B,MAAM,cAAc,GAAG,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAC5D,IAAI,EAAE,uBAAuB;gBAC7B,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,MAAM,CACZ,CAAC;gBACF,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAC5B,CAAC;YACD,QAAQ,EAAE,CAAC;QACb,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,UAAU,GACd,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAClE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;YAC9C,QAAQ,CAAC,UAAU,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;CACF;AArHD,sDAqHC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./checksumTransform"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./eciesDecryptTransform"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./eciesEncryptTransform"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./xorMultipleTransform"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./xorTransform"), exports);
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC;AACpC,kEAAwC;AACxC,kEAAwC;AACxC,iEAAuC;AACvC,yDAA+B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Readable, Transform, TransformCallback } from 'stream';
|
|
2
|
+
export declare class XorMultipleTransformStream extends Transform {
|
|
3
|
+
private sources;
|
|
4
|
+
private buffers;
|
|
5
|
+
private readonly streamEnded;
|
|
6
|
+
constructor(sources: Readable[]);
|
|
7
|
+
processData(): void;
|
|
8
|
+
checkEndCondition(): void;
|
|
9
|
+
_transform(chunk: Buffer, encoding: string, callback: TransformCallback): void;
|
|
10
|
+
_flush(callback: TransformCallback): void;
|
|
11
|
+
}
|
|
12
|
+
export default XorMultipleTransformStream;
|
|
13
|
+
//# sourceMappingURL=xorMultipleTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xorMultipleTransform.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/xorMultipleTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEhE,qBAAa,0BAA2B,SAAQ,SAAS;IACvD,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAY;gBAE5B,OAAO,EAAE,QAAQ,EAAE;IAmB/B,WAAW,IAAI,IAAI;IAoCnB,iBAAiB,IAAI,IAAI;IAMhB,UAAU,CACjB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,iBAAiB,GAC1B,IAAI;IAKE,MAAM,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;CAGnD;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XorMultipleTransformStream = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
class XorMultipleTransformStream extends stream_1.Transform {
|
|
6
|
+
sources;
|
|
7
|
+
buffers;
|
|
8
|
+
streamEnded;
|
|
9
|
+
constructor(sources) {
|
|
10
|
+
super();
|
|
11
|
+
this.sources = sources;
|
|
12
|
+
this.buffers = new Array(sources.length).fill(null);
|
|
13
|
+
this.streamEnded = new Array(sources.length).fill(false);
|
|
14
|
+
this.sources.forEach((source, index) => {
|
|
15
|
+
source.on('data', (chunk) => {
|
|
16
|
+
this.buffers[index] = chunk;
|
|
17
|
+
this.processData();
|
|
18
|
+
});
|
|
19
|
+
source.on('end', () => {
|
|
20
|
+
this.streamEnded[index] = true;
|
|
21
|
+
this.checkEndCondition();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
processData() {
|
|
26
|
+
if (this.buffers.every((buffer, index) => buffer !== null || this.streamEnded[index])) {
|
|
27
|
+
const minLength = Math.min(...this.buffers.map((buffer, index) => this.streamEnded[index] ? 0 : buffer.length));
|
|
28
|
+
if (minLength === 0) {
|
|
29
|
+
this.end();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const xorResult = Buffer.alloc(minLength);
|
|
33
|
+
for (let i = 0; i < minLength; i++) {
|
|
34
|
+
xorResult[i] = this.buffers.reduce((acc, buffer, index) => this.streamEnded[index] ? acc : acc ^ buffer[i], 0);
|
|
35
|
+
}
|
|
36
|
+
this.push(xorResult);
|
|
37
|
+
// Update buffers
|
|
38
|
+
this.buffers = this.buffers.map((buffer, index) => this.streamEnded[index] ? buffer : buffer.subarray(minLength));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
checkEndCondition() {
|
|
42
|
+
if (this.streamEnded.every((ended) => ended)) {
|
|
43
|
+
this.end();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
_transform(chunk, encoding, callback) {
|
|
47
|
+
// This transform does not use the incoming chunk directly
|
|
48
|
+
callback();
|
|
49
|
+
}
|
|
50
|
+
_flush(callback) {
|
|
51
|
+
callback();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.XorMultipleTransformStream = XorMultipleTransformStream;
|
|
55
|
+
exports.default = XorMultipleTransformStream;
|
|
56
|
+
//# sourceMappingURL=xorMultipleTransform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xorMultipleTransform.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/xorMultipleTransform.ts"],"names":[],"mappings":";;;AAAA,mCAAgE;AAEhE,MAAa,0BAA2B,SAAQ,kBAAS;IAC/C,OAAO,CAAa;IACpB,OAAO,CAAW;IACT,WAAW,CAAY;IAExC,YAAY,OAAmB;QAC7B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAA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unk;
|
|
4
|
+
private xorChunk;
|
|
5
|
+
constructor();
|
|
6
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
7
|
+
_flush(callback: TransformCallback): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=xorTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xorTransform.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/xorTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEtD,qBAAa,YAAa,SAAQ,SAAS;IACzC,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,QAAQ,CAAS;;IAOT,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,iBAAiB;IAab,MAAM,CAAC,QAAQ,EAAE,iBAAiB;CAInD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XorTransform = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
class XorTransform extends stream_1.Transform {
|
|
6
|
+
firstChunk;
|
|
7
|
+
xorChunk;
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.firstChunk = true;
|
|
11
|
+
this.xorChunk = Buffer.alloc(0);
|
|
12
|
+
}
|
|
13
|
+
_transform(chunk, encoding, callback) {
|
|
14
|
+
if (this.firstChunk) {
|
|
15
|
+
this.xorChunk = chunk;
|
|
16
|
+
this.firstChunk = false;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
20
|
+
this.xorChunk[i] ^= chunk[i];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
callback();
|
|
24
|
+
}
|
|
25
|
+
_flush(callback) {
|
|
26
|
+
this.push(this.xorChunk);
|
|
27
|
+
callback();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.XorTransform = XorTransform;
|
|
31
|
+
//# sourceMappingURL=xorTransform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xorTransform.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/transforms/xorTransform.ts"],"names":[],"mappings":";;;AAAA,mCAAsD;AAEtD,MAAa,YAAa,SAAQ,kBAAS;IACjC,UAAU,CAAU;IACpB,QAAQ,CAAS;IACzB;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;IAEe,UAAU,CACxB,KAAa,EACb,QAAwB,EACxB,QAA2B;QAE3B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;YACtB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QACD,QAAQ,EAAE,CAAC;IACb,CAAC;IAEe,MAAM,CAAC,QAA2B;QAChD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzB,QAAQ,EAAE,CAAC;IACb,CAAC;CACF;AA7BD,oCA6BC"}
|