@qilin-agent/util-crypto 0.0.0-stage → 3.1.3

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) 2026 kkutysllb
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.
@@ -0,0 +1,34 @@
1
+ # Bilingual-pair consistency record for README.md (docs/i18n/README.md): per heading
2
+ # section, a hash of its English and Chinese blocks outside code blocks and generated regions.
3
+ # After editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write packages/util/crypto/README.md
5
+ /:
6
+ en: c3004d7d489da8f1
7
+ zh: 8b6af2f3f48d5544
8
+ /qilin-util-crypto:
9
+ en: 97c00d05b84bfb0f
10
+ zh: 48d47a48c3ba76d6
11
+ /qilin-util-crypto/summary:
12
+ en: 55f117af7ba9f8fe
13
+ zh: 2cde7f6b69dc4bf8
14
+ /qilin-util-crypto/table-of-contents:
15
+ en: cd2a60a905c978d6
16
+ zh: cc71d387d0cbd442
17
+ /qilin-util-crypto/use-this-package:
18
+ en: 594d34627be8618a
19
+ zh: 68723dfafb88ac84
20
+ /qilin-util-crypto/api:
21
+ en: 21d8f33a1c652edb
22
+ zh: 07a3629d66301d85
23
+ /qilin-util-crypto/model-experience:
24
+ en: beb00a2635b78870
25
+ zh: d93b828c08217472
26
+ /qilin-util-crypto/model-experience/kv-cache-effect:
27
+ en: 3f396619298fe1ae
28
+ zh: d46e51c86231d485
29
+ /qilin-util-crypto/known-limitations-and-deferred-work:
30
+ en: 2c79cf7c12f39ab1
31
+ zh: c6f2ad3e53a62473
32
+ /qilin-util-crypto/known-limitations-and-deferred-work/dev-note:
33
+ en: e67f633dc6fe7773
34
+ zh: e88aeb617ffb74ea
package/README.md CHANGED
@@ -1,3 +1,69 @@
1
- # Temporary Holding Version
1
+ ---
2
+ description: "Cross-runtime UUID generation for maintainers replacing secure-context-only crypto.randomUUID calls."
3
+ kind: "package-library"
4
+ ---
2
5
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
6
+ # qilin-util-crypto
7
+
8
+ English | [中文](README.zh.md)
9
+
10
+ ## Summary
11
+
12
+ Zero-dependency browser-safe UUID and byte-encoding helpers. UUID minting uses `crypto.getRandomValues`, the one random primitive every shipped context provides. `crypto.randomUUID` is a secure-context Web API: a page or worker served over plain HTTP on a LAN address (the browser preview deployment) has no such method, so code that must run there cannot call it. The repository-wide `no-restricted-properties` lint rule points `crypto.randomUUID` callers here; Node-only code importing `randomUUID` from `node:crypto` stays as it is.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Use this package](#use-this-package)
17
+ - [API](#api)
18
+ - [Model Experience](#model-experience)
19
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
20
+ - [Dev Note](#dev-note)
21
+
22
+ -----
23
+
24
+ <a id="use-this-package"></a>
25
+ ## Use this package
26
+
27
+ It is a **library, not a service or plugin**: no `ctx`, registers nothing, holds no state.
28
+
29
+ -----
30
+
31
+ <a id="api"></a>
32
+ ## API
33
+
34
+ ```ts
35
+ import { bytesToBase64, randomUUID, type Uuid } from '@qilin-agent/util-crypto'
36
+ ```
37
+
38
+ | Export | Role |
39
+ |---|---|
40
+ | `bytesToBase64(data)` | Canonical base64 for a byte array, encoded in bounded chunks. |
41
+ | `randomUUID()` | Random RFC 9562 v4 UUID string, minted from `crypto.getRandomValues`. Drop-in for `crypto.randomUUID()`. |
42
+ | `Uuid` | The five-group UUID string type, matching `crypto.randomUUID`'s declared return shape. |
43
+
44
+ <a id="model-experience"></a>
45
+ ## Model Experience
46
+
47
+ Indirectly, through consumers that mint request, session, and attachment identifiers with it, none of which enter prompts as semantic content.
48
+
49
+ #### KV Cache effect
50
+
51
+ No direct invalidation; identifier-minting consumers own any request changes.
52
+
53
+ ## Known Limitations and Deferred Work
54
+
55
+ <a id="known-limitations-and-deferred-work"></a>
56
+
57
+ - **v4 only** — no other UUID versions, namespaces, or parsing; consumers needing more should take a real UUID dependency.
58
+ - **Uniqueness is probabilistic** — 122 random bits, the same guarantee `crypto.randomUUID` gives; nothing here detects collisions.
59
+
60
+
61
+ <a id="dev-note"></a>
62
+ ### Dev Note
63
+
64
+ <details>
65
+ <summary>Working context for maintainers — click to expand</summary>
66
+
67
+ None.
68
+
69
+ </details>
package/README.zh.md ADDED
@@ -0,0 +1,69 @@
1
+ ---
2
+ description: "面向替换仅安全上下文可用的 crypto.randomUUID 调用的维护者,说明跨运行时 UUID 生成。"
3
+ kind: "package-library"
4
+ ---
5
+
6
+ # qilin-util-crypto
7
+
8
+ [English](README.md) | 中文
9
+
10
+ ## 概述
11
+
12
+ 零依赖、可在浏览器使用的 UUID 与字节编码辅助函数。UUID 铸造基于 `crypto.getRandomValues`——所有发布上下文都提供的那个随机原语。`crypto.randomUUID` 是安全上下文限定的 Web API:经普通 HTTP 在局域网地址上提供的页面或 worker(浏览器预览部署)根本没有这个方法,必须在那里运行的代码不能调它。全仓 `no-restricted-properties` lint 规则把 `crypto.randomUUID` 的调用者指到这里;只跑在 Node 的代码从 `node:crypto` 导入 `randomUUID` 维持原样。
13
+
14
+ ## 目录
15
+
16
+ - [使用本包](#use-this-package)
17
+ - [API](#api)
18
+ - [模型体验](#model-experience)
19
+ - [已知限制与延期工作](#known-limitations-and-deferred-work)
20
+ - [开发备注](#dev-note)
21
+
22
+ -----
23
+
24
+ <a id="use-this-package"></a>
25
+ ## 使用本包
26
+
27
+ 它是**库,不是服务也不是插件**:无 `ctx`、不注册任何东西、不持有状态。
28
+
29
+ -----
30
+
31
+ <a id="api"></a>
32
+ ## API
33
+
34
+ ```ts
35
+ import { bytesToBase64, randomUUID, type Uuid } from '@qilin-agent/util-crypto'
36
+ ```
37
+
38
+ | 导出 | 角色 |
39
+ |---|---|
40
+ | `bytesToBase64(data)` | 以有界分片把字节数组编码为标准 base64。 |
41
+ | `randomUUID()` | 随机 RFC 9562 v4 UUID 字符串,由 `crypto.getRandomValues` 铸造。可原位替换 `crypto.randomUUID()`。 |
42
+ | `Uuid` | 五段式 UUID 字符串类型,与 `crypto.randomUUID` 声明的返回形状一致。 |
43
+
44
+ <a id="model-experience"></a>
45
+ ## 模型体验
46
+
47
+ 间接地,经由用它铸造请求、会话与附件标识符的消费方,这些标识符均不作为语义内容进入提示词。
48
+
49
+ #### KV Cache 影响
50
+
51
+ 无直接失效;铸造标识符的消费方自行负责其请求变化。
52
+
53
+ ## 已知限制与延期工作
54
+
55
+ <a id="known-limitations-and-deferred-work"></a>
56
+
57
+ - **仅 v4**——不提供其他 UUID 版本、命名空间或解析;需要更多能力的消费方应引入真正的 UUID 依赖。
58
+ - **唯一性是概率性的**——122 位随机,与 `crypto.randomUUID` 同级保证;此处不做碰撞检测。
59
+
60
+
61
+ <a id="dev-note"></a>
62
+ ### 开发备注
63
+
64
+ <details>
65
+ <summary>维护者工作上下文——点击展开</summary>
66
+
67
+ 无。
68
+
69
+ </details>
package/lib/index.js ADDED
@@ -0,0 +1,35 @@
1
+ //#region lib/types/index.js
2
+ /**
3
+ * UUID minting that works in every JavaScript context this repository ships
4
+ * to. `crypto.randomUUID` is a secure-context Web API — a page or worker
5
+ * served over plain HTTP on a LAN address has no such method — while
6
+ * `crypto.getRandomValues` is unrestricted everywhere (browsers, workers,
7
+ * Node ≥ 19). One implementation here replaces per-caller polyfills; the
8
+ * `no-restricted-properties` lint rule points `crypto.randomUUID` callers at
9
+ * this module.
10
+ * @module @qilin-agent/util-crypto
11
+ */
12
+ /**
13
+ * Encode bytes as canonical base64 without overflowing function argument limits.
14
+ * @param data - Bytes to encode.
15
+ * @returns base64 text.
16
+ */
17
+ function bytesToBase64(data) {
18
+ let binary = "";
19
+ const chunk = 32768;
20
+ for (let offset = 0; offset < data.length; offset += chunk) binary += String.fromCharCode(...data.subarray(offset, offset + chunk));
21
+ return btoa(binary);
22
+ }
23
+ /**
24
+ * Random v4 UUID, minted from `crypto.getRandomValues`.
25
+ * @returns the UUID string.
26
+ */
27
+ function randomUUID() {
28
+ const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
29
+ const hex = Array.from(bytes, (byte, index) => {
30
+ return (index === 6 ? byte & 15 | 64 : index === 8 ? byte & 63 | 128 : byte).toString(16).padStart(2, "0");
31
+ }).join("");
32
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
33
+ }
34
+ //#endregion
35
+ export { bytesToBase64, randomUUID };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * UUID minting that works in every JavaScript context this repository ships
3
+ * to. `crypto.randomUUID` is a secure-context Web API — a page or worker
4
+ * served over plain HTTP on a LAN address has no such method — while
5
+ * `crypto.getRandomValues` is unrestricted everywhere (browsers, workers,
6
+ * Node ≥ 19). One implementation here replaces per-caller polyfills; the
7
+ * `no-restricted-properties` lint rule points `crypto.randomUUID` callers at
8
+ * this module.
9
+ * @module @qilin-agent/util-crypto
10
+ */
11
+ /** RFC 9562 UUID string, the shape `crypto.randomUUID` declares. */
12
+ export type Uuid = `${string}-${string}-${string}-${string}-${string}`;
13
+ /**
14
+ * Encode bytes as canonical base64 without overflowing function argument limits.
15
+ * @param data - Bytes to encode.
16
+ * @returns base64 text.
17
+ */
18
+ export declare function bytesToBase64(data: Uint8Array): string;
19
+ /**
20
+ * Random v4 UUID, minted from `crypto.getRandomValues`.
21
+ * @returns the UUID string.
22
+ */
23
+ export declare function randomUUID(): Uuid;
24
+ //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@qilin-agent/util-crypto",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "description": "Zero-dependency browser-safe UUID and byte-encoding helpers",
4
+ "version": "3.1.3",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/kkutysllb/QiLin.git",
11
+ "directory": "packages/util/crypto"
12
+ },
13
+ "engines": {
14
+ "node": "^22.19.0 || >=24.0.0"
15
+ },
16
+ "type": "module",
17
+ "main": "lib/index.js",
18
+ "types": "lib/types/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./lib/types/index.d.ts",
22
+ "default": "./lib/index.js"
23
+ },
24
+ "./src/*": "./src/*",
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "lib/index.js",
29
+ "lib/types/**/*.d.ts"
30
+ ],
31
+ "license": "MIT",
32
+ "peerDependencies": {
33
+ "@qilin-agent/kylin": "~4.0.3"
34
+ },
35
+ "devDependencies": {
36
+ "@qilin-agent/kylin": "~4.0.3"
37
+ }
6
38
  }