@chikawa222224/testchikawa222224_2 2026.8.22-1-1
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 +45 -0
- package/bin/_chikawa222224_testchikawa222224_2.bin +0 -0
- package/index.js +59 -0
- package/package.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @chikawa222224/testchikawa222224_2
|
|
2
|
+
|
|
3
|
+
A Node.js hash library for the bundled `_chikawa222224_testchikawa222224_2.bin` binary file.
|
|
4
|
+
|
|
5
|
+
## Hash calculation
|
|
6
|
+
|
|
7
|
+
The library calculates the hash of these bytes in order:
|
|
8
|
+
|
|
9
|
+
1. The complete bundled file bytes.
|
|
10
|
+
2. The binary attachment decoded from the Base64 argument.
|
|
11
|
+
|
|
12
|
+
In other words: `hash(fileBytes + Base64Decode(base64Attachment))`.
|
|
13
|
+
|
|
14
|
+
The default algorithm is SHA-256 and the result is returned as a lowercase hexadecimal string.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
const { calculateHash } = require("@chikawa222224/testchikawa222224_2");
|
|
20
|
+
|
|
21
|
+
const attachmentBase64 = Buffer.from("attachment bytes").toString("base64");
|
|
22
|
+
calculateHash(attachmentBase64).then(console.log);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Calculate only the bundled file hash by omitting the attachment:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
calculateHash().then(console.log);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Use another algorithm supported by Node.js:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
calculateHash(attachmentBase64, "sha512").then(console.log);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
### `calculateHash(base64Attachment = "", algorithm = "sha256")`
|
|
40
|
+
|
|
41
|
+
Returns a `Promise<string>` containing the calculated hash. Invalid Base64 input or an unsupported algorithm rejects the promise.
|
|
42
|
+
|
|
43
|
+
### `binaryPath`
|
|
44
|
+
|
|
45
|
+
Contains the absolute path of the bundled binary file.
|
|
Binary file
|
package/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { createHash } = require("node:crypto");
|
|
4
|
+
const { createReadStream } = require("node:fs");
|
|
5
|
+
const { join } = require("node:path");
|
|
6
|
+
|
|
7
|
+
const binaryPath = join(__dirname, "bin", "_chikawa222224_testchikawa222224_2.bin");
|
|
8
|
+
|
|
9
|
+
function decodeBase64(value) {
|
|
10
|
+
if (typeof value !== "string") {
|
|
11
|
+
throw new TypeError("base64Attachment must be a string");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const compact = value.replace(/\s+/g, "");
|
|
15
|
+
if (compact.length === 0) {
|
|
16
|
+
return Buffer.alloc(0);
|
|
17
|
+
}
|
|
18
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(compact)) {
|
|
19
|
+
throw new TypeError("base64Attachment is not valid Base64");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const unpadded = compact.replace(/=+$/, "");
|
|
23
|
+
if (unpadded.length % 4 === 1) {
|
|
24
|
+
throw new TypeError("base64Attachment is not valid Base64");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const decoded = Buffer.from(unpadded, "base64");
|
|
28
|
+
if (decoded.toString("base64").replace(/=+$/, "") !== unpadded) {
|
|
29
|
+
throw new TypeError("base64Attachment is not valid Base64");
|
|
30
|
+
}
|
|
31
|
+
return decoded;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function calculateHash(base64Attachment = "", algorithm = "sha256") {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
let hash;
|
|
37
|
+
let attachment;
|
|
38
|
+
try {
|
|
39
|
+
hash = createHash(algorithm);
|
|
40
|
+
attachment = decodeBase64(base64Attachment);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
reject(error);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const input = createReadStream(binaryPath);
|
|
48
|
+
input.on("error", reject);
|
|
49
|
+
input.on("data", (chunk) => hash.update(chunk));
|
|
50
|
+
input.on("end", () => {
|
|
51
|
+
hash.update(attachment);
|
|
52
|
+
resolve(hash.digest("hex"));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = calculateHash;
|
|
58
|
+
module.exports.calculateHash = calculateHash;
|
|
59
|
+
module.exports.binaryPath = binaryPath;
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chikawa222224/testchikawa222224_2",
|
|
3
|
+
"version": "2026.8.22-1-1",
|
|
4
|
+
"description": "Hash utility for the bundled binary release asset",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": "./index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js",
|
|
10
|
+
"bin/_chikawa222224_testchikawa222224_2.bin"
|
|
11
|
+
],
|
|
12
|
+
"os": [
|
|
13
|
+
"win32"
|
|
14
|
+
],
|
|
15
|
+
"cpu": [
|
|
16
|
+
"x64"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": "\u003e=14.18.0"
|
|
20
|
+
},
|
|
21
|
+
"license": "UNLICENSED"
|
|
22
|
+
}
|