@tpmjs/official-hash-text 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2025 TPMJS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @tpmjs/official-hash-text
2
+
3
+ Hash text using cryptographic algorithms (MD5, SHA-1, SHA-256, SHA-512).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @tpmjs/official-hash-text
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { hashTextTool } from '@tpmjs/official-hash-text';
15
+ import { generateText } from 'ai';
16
+
17
+ const result = await generateText({
18
+ model: yourModel,
19
+ tools: {
20
+ hashText: hashTextTool,
21
+ },
22
+ prompt: 'Hash "Hello, World!" using SHA-256',
23
+ });
24
+ ```
25
+
26
+ ## Parameters
27
+
28
+ - `text` (string, required): The text to hash
29
+ - `algorithm` (string, required): Hash algorithm to use
30
+ - Options: `'md5'`, `'sha1'`, `'sha256'`, `'sha512'`
31
+
32
+ ## Returns
33
+
34
+ ```typescript
35
+ {
36
+ hash: string; // The hexadecimal hash digest
37
+ algorithm: string; // The algorithm used
38
+ inputLength: number; // The length of the input text
39
+ }
40
+ ```
41
+
42
+ ## Examples
43
+
44
+ ### SHA-256 hash
45
+
46
+ ```typescript
47
+ const result = await hashTextTool.execute({
48
+ text: 'Hello, World!',
49
+ algorithm: 'sha256',
50
+ });
51
+ // {
52
+ // hash: 'dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f',
53
+ // algorithm: 'sha256',
54
+ // inputLength: 13
55
+ // }
56
+ ```
57
+
58
+ ### MD5 hash
59
+
60
+ ```typescript
61
+ const result = await hashTextTool.execute({
62
+ text: 'Hello, World!',
63
+ algorithm: 'md5',
64
+ });
65
+ // {
66
+ // hash: '65a8e27d8879283831b664bd8b7f0ad4',
67
+ // algorithm: 'md5',
68
+ // inputLength: 13
69
+ // }
70
+ ```
71
+
72
+ ### SHA-512 hash
73
+
74
+ ```typescript
75
+ const result = await hashTextTool.execute({
76
+ text: 'password123',
77
+ algorithm: 'sha512',
78
+ });
79
+ // Returns 128-character hexadecimal hash
80
+ ```
81
+
82
+ ## Use Cases
83
+
84
+ - Generating content fingerprints for deduplication
85
+ - Creating checksums for data integrity verification
86
+ - Hashing user input for comparison (note: use proper password hashing for credentials)
87
+ - Generating cache keys
88
+ - Creating unique identifiers from content
89
+ - File integrity checks
90
+
91
+ ## Algorithm Guide
92
+
93
+ | Algorithm | Output Length | Use Case |
94
+ |-----------|--------------|----------|
95
+ | `md5` | 32 hex chars (128 bits) | Legacy systems, checksums (not cryptographically secure) |
96
+ | `sha1` | 40 hex chars (160 bits) | Git commits, legacy systems (weakened security) |
97
+ | `sha256` | 64 hex chars (256 bits) | General purpose, recommended for most use cases |
98
+ | `sha512` | 128 hex chars (512 bits) | High security requirements, larger hash space |
99
+
100
+ **Note:** MD5 and SHA-1 are not recommended for security-critical applications. Use SHA-256 or SHA-512 for cryptographic purposes.
101
+
102
+ ## License
103
+
104
+ MIT
@@ -0,0 +1,32 @@
1
+ import * as ai from 'ai';
2
+
3
+ /**
4
+ * Hash Text Tool for TPMJS
5
+ * Hash text using various cryptographic algorithms
6
+ */
7
+ /**
8
+ * Supported hash algorithms
9
+ */
10
+ type HashAlgorithm = 'md5' | 'sha1' | 'sha256' | 'sha512';
11
+ /**
12
+ * Input interface for text hashing
13
+ */
14
+ interface HashTextInput {
15
+ text: string;
16
+ algorithm: HashAlgorithm;
17
+ }
18
+ /**
19
+ * Output interface for hash text result
20
+ */
21
+ interface HashTextResult {
22
+ hash: string;
23
+ algorithm: string;
24
+ inputLength: number;
25
+ }
26
+ /**
27
+ * Hash Text Tool
28
+ * Creates cryptographic hashes from text input
29
+ */
30
+ declare const hashTextTool: ai.Tool<HashTextInput, HashTextResult>;
31
+
32
+ export { type HashTextResult, hashTextTool as default, hashTextTool };
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ import { createHash } from 'crypto';
2
+ import { tool, jsonSchema } from 'ai';
3
+
4
+ // src/index.ts
5
+ var hashTextTool = tool({
6
+ description: "Hash text using cryptographic algorithms (MD5, SHA-1, SHA-256, SHA-512). Returns the hexadecimal hash digest, the algorithm used, and the input text length. Useful for generating checksums, content fingerprints, or data integrity verification.",
7
+ inputSchema: jsonSchema({
8
+ type: "object",
9
+ properties: {
10
+ text: {
11
+ type: "string",
12
+ description: "The text to hash"
13
+ },
14
+ algorithm: {
15
+ type: "string",
16
+ enum: ["md5", "sha1", "sha256", "sha512"],
17
+ description: "Hash algorithm to use"
18
+ }
19
+ },
20
+ required: ["text", "algorithm"],
21
+ additionalProperties: false
22
+ }),
23
+ execute: async ({ text, algorithm }) => {
24
+ if (typeof text !== "string") {
25
+ throw new Error("Text must be a string");
26
+ }
27
+ const validAlgorithms = ["md5", "sha1", "sha256", "sha512"];
28
+ if (!validAlgorithms.includes(algorithm)) {
29
+ throw new Error(
30
+ `Invalid algorithm: ${algorithm}. Must be one of: ${validAlgorithms.join(", ")}`
31
+ );
32
+ }
33
+ try {
34
+ const hash = createHash(algorithm);
35
+ hash.update(text, "utf8");
36
+ const digest = hash.digest("hex");
37
+ return {
38
+ hash: digest,
39
+ algorithm,
40
+ inputLength: text.length
41
+ };
42
+ } catch (error) {
43
+ throw new Error(
44
+ `Failed to hash text: ${error instanceof Error ? error.message : String(error)}`
45
+ );
46
+ }
47
+ }
48
+ });
49
+ var index_default = hashTextTool;
50
+
51
+ export { index_default as default, hashTextTool };
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@tpmjs/official-hash-text",
3
+ "version": "0.1.0",
4
+ "description": "Hash text using cryptographic algorithms (MD5, SHA-1, SHA-256, SHA-512)",
5
+ "type": "module",
6
+ "keywords": [
7
+ "tpmjs",
8
+ "data",
9
+ "hash",
10
+ "crypto",
11
+ "md5",
12
+ "sha256"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "devDependencies": {
24
+ "tsup": "^8.3.5",
25
+ "typescript": "^5.9.3",
26
+ "@tpmjs/tsconfig": "0.0.0"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/anthropics/tpmjs.git",
34
+ "directory": "packages/tools/official/hash-text"
35
+ },
36
+ "homepage": "https://tpmjs.com",
37
+ "license": "MIT",
38
+ "tpmjs": {
39
+ "category": "data",
40
+ "frameworks": [
41
+ "vercel-ai"
42
+ ],
43
+ "tools": [
44
+ {
45
+ "name": "hashTextTool",
46
+ "description": "Hash text using cryptographic algorithms (MD5, SHA-1, SHA-256, SHA-512)",
47
+ "parameters": [
48
+ {
49
+ "name": "text",
50
+ "type": "string",
51
+ "description": "The text to hash",
52
+ "required": true
53
+ },
54
+ {
55
+ "name": "algorithm",
56
+ "type": "string",
57
+ "description": "Hash algorithm (md5, sha1, sha256, sha512)",
58
+ "required": true
59
+ }
60
+ ],
61
+ "returns": {
62
+ "type": "HashTextResult",
63
+ "description": "Object with hash digest, algorithm used, and input length"
64
+ }
65
+ }
66
+ ]
67
+ },
68
+ "dependencies": {
69
+ "ai": "6.0.0-beta.124"
70
+ },
71
+ "scripts": {
72
+ "build": "tsup",
73
+ "dev": "tsup --watch",
74
+ "type-check": "tsc --noEmit",
75
+ "clean": "rm -rf dist .turbo"
76
+ }
77
+ }