ranuts 0.1.0-alpha.8 → 0.2.0-alpha.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.
Files changed (179) hide show
  1. package/CLAUDE.md +164 -0
  2. package/README.md +116 -0
  3. package/{readme.md → README.zh-CN.md} +43 -12
  4. package/dist/bin/generate-api-docs.d.ts +1 -0
  5. package/dist/build/build.es.d.ts +2 -0
  6. package/dist/build/build.umd.d.ts +2 -0
  7. package/dist/build/build.umd.node.d.ts +2 -0
  8. package/dist/build/build.umd.utils.d.ts +2 -0
  9. package/dist/color-CRdlaDqQ.js +1 -0
  10. package/dist/examples/clone-deep-example.d.ts +1 -0
  11. package/dist/examples/is-equal-example.d.ts +1 -0
  12. package/dist/index.d.ts +5 -21
  13. package/dist/index.js +1 -2484
  14. package/dist/plugins/vite-plugins-banner.d.ts +2 -0
  15. package/dist/rolldown-runtime-I3TIJKkN.js +1 -0
  16. package/dist/src/node/appendFile.d.ts +7 -0
  17. package/dist/src/node/body.d.ts +9 -0
  18. package/dist/src/node/color.d.ts +7 -0
  19. package/dist/src/node/command.d.ts +8 -0
  20. package/dist/src/node/ctx2req.d.ts +5 -0
  21. package/dist/src/node/fileInfo.d.ts +7 -0
  22. package/dist/src/node/fs.d.ts +7 -0
  23. package/dist/src/node/get.d.ts +10 -0
  24. package/dist/src/node/getIPAdress.d.ts +1 -0
  25. package/dist/src/node/index.d.ts +25 -0
  26. package/dist/src/node/index.js +1 -0
  27. package/dist/src/node/isColorSupported.d.ts +2 -0
  28. package/dist/src/node/paresUrl.d.ts +19 -0
  29. package/dist/src/node/readDir.d.ts +6 -0
  30. package/dist/src/node/readFile.d.ts +9 -0
  31. package/dist/src/node/router.d.ts +42 -0
  32. package/dist/src/node/send.d.ts +7 -0
  33. package/dist/src/node/server.d.ts +18 -0
  34. package/dist/src/node/startTask.d.ts +2 -0
  35. package/dist/src/node/stream.d.ts +15 -0
  36. package/dist/src/node/taskEnd.d.ts +2 -0
  37. package/dist/src/node/traverse.d.ts +17 -0
  38. package/dist/src/node/watchFile.d.ts +8 -0
  39. package/dist/src/node/writeFile.d.ts +8 -0
  40. package/dist/src/node/ws.d.ts +8 -0
  41. package/dist/src/utils/audioRecorder.d.ts +16 -0
  42. package/dist/src/utils/behavior.d.ts +15 -0
  43. package/dist/src/utils/bom.d.ts +294 -0
  44. package/dist/src/utils/color.d.ts +71 -0
  45. package/dist/src/utils/compose.d.ts +10 -0
  46. package/dist/src/utils/console.d.ts +1 -0
  47. package/dist/src/utils/debounce.d.ts +7 -0
  48. package/dist/src/utils/device.d.ts +25 -0
  49. package/dist/src/utils/dom.d.ts +105 -0
  50. package/dist/src/utils/error.d.ts +1 -0
  51. package/dist/src/utils/func.d.ts +1 -0
  52. package/dist/src/utils/img.d.ts +16 -0
  53. package/dist/src/utils/index.d.ts +35 -0
  54. package/dist/src/utils/index.js +1 -0
  55. package/dist/src/utils/memoize.d.ts +7 -0
  56. package/dist/src/utils/mimeType.d.ts +9 -0
  57. package/dist/src/utils/monitor.d.ts +38 -0
  58. package/dist/src/utils/network.d.ts +39 -0
  59. package/dist/src/utils/noop.d.ts +2 -0
  60. package/dist/src/utils/number.d.ts +45 -0
  61. package/dist/src/utils/obj.d.ts +83 -0
  62. package/dist/src/utils/performance.d.ts +21 -0
  63. package/dist/src/utils/queue.d.ts +33 -0
  64. package/dist/src/utils/report.d.ts +8 -0
  65. package/dist/src/utils/request.d.ts +17 -0
  66. package/dist/src/utils/script.d.ts +7 -0
  67. package/dist/src/utils/signal.d.ts +6 -0
  68. package/dist/src/utils/storage.d.ts +2 -0
  69. package/dist/src/utils/str.d.ts +212 -0
  70. package/dist/src/utils/subscribe.d.ts +46 -0
  71. package/dist/src/utils/throttle.d.ts +15 -0
  72. package/dist/src/utils/time.d.ts +20 -0
  73. package/dist/src/utils/totp/sha/common.d.ts +151 -0
  74. package/dist/src/utils/totp/sha/converters.d.ts +88 -0
  75. package/dist/src/utils/totp/sha/custom_types.d.ts +60 -0
  76. package/dist/src/utils/totp/sha/primitives_32.d.ts +98 -0
  77. package/dist/src/utils/totp/sha/primitives_64.d.ts +116 -0
  78. package/dist/src/utils/totp/sha/sha.d.ts +103 -0
  79. package/dist/src/utils/totp/sha/sha1.d.ts +18 -0
  80. package/dist/src/utils/totp/sha/sha256.d.ts +20 -0
  81. package/dist/src/utils/totp/sha/sha3.d.ts +53 -0
  82. package/dist/src/utils/totp/sha/sha512.d.ts +21 -0
  83. package/dist/src/utils/totp/totp.d.ts +23 -0
  84. package/dist/src/utils/visual/application.d.ts +27 -0
  85. package/dist/src/utils/visual/enums.d.ts +27 -0
  86. package/dist/src/utils/visual/event/boundary.d.ts +22 -0
  87. package/dist/src/utils/visual/event/event.d.ts +14 -0
  88. package/dist/src/utils/visual/event/index.d.ts +6 -0
  89. package/dist/src/utils/visual/event/types.d.ts +32 -0
  90. package/dist/src/utils/visual/graphics/graphics.d.ts +81 -0
  91. package/dist/src/utils/visual/graphics/graphicsData.d.ts +13 -0
  92. package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +35 -0
  93. package/dist/src/utils/visual/graphics/index.d.ts +4 -0
  94. package/dist/src/utils/visual/index.d.ts +7 -0
  95. package/dist/src/utils/visual/index.js +1 -0
  96. package/dist/src/utils/visual/math/bezier.d.ts +2 -0
  97. package/dist/src/utils/visual/math/enums.d.ts +3 -0
  98. package/dist/src/utils/visual/math/index.d.ts +5 -0
  99. package/dist/src/utils/visual/math/matrix.d.ts +113 -0
  100. package/dist/src/utils/visual/math/transform.d.ts +29 -0
  101. package/dist/src/utils/visual/render/batchRenderer.d.ts +78 -0
  102. package/dist/src/utils/visual/render/canvasRenderer.d.ts +10 -0
  103. package/dist/src/utils/visual/render/index.d.ts +3 -0
  104. package/dist/src/utils/visual/render/render.d.ts +11 -0
  105. package/dist/src/utils/visual/render/utils/batch/index.d.ts +90 -0
  106. package/dist/src/utils/visual/render/utils/batch/index.test.d.ts +1 -0
  107. package/dist/src/utils/visual/render/utils/float.d.ts +63 -0
  108. package/dist/src/utils/visual/render/utils/index.d.ts +3 -0
  109. package/dist/src/utils/visual/render/utils/index.test.d.ts +1 -0
  110. package/dist/src/utils/visual/render/utils/verticy.d.ts +13 -0
  111. package/dist/src/utils/visual/render/utils/webgl/initShader.d.ts +7 -0
  112. package/dist/src/utils/visual/render/utils/webgl/shaders.d.ts +2 -0
  113. package/dist/src/utils/visual/render/utils/webgpu/shaders.d.ts +8 -0
  114. package/dist/src/utils/visual/render/webGPURenderer.d.ts +49 -0
  115. package/dist/src/utils/visual/render/webGlRenderer.d.ts +14 -0
  116. package/dist/src/utils/visual/shape/circle.d.ts +11 -0
  117. package/dist/src/utils/visual/shape/ellipse.d.ts +12 -0
  118. package/dist/src/utils/visual/shape/index.d.ts +7 -0
  119. package/dist/src/utils/visual/shape/polygon.d.ts +11 -0
  120. package/dist/src/utils/visual/shape/rectangle.d.ts +12 -0
  121. package/dist/src/utils/visual/shape/roundedRectangle.d.ts +13 -0
  122. package/dist/src/utils/visual/shape/shape.d.ts +6 -0
  123. package/dist/src/utils/visual/style/fill.d.ts +8 -0
  124. package/dist/src/utils/visual/style/index.d.ts +3 -0
  125. package/dist/src/utils/visual/style/line.d.ts +10 -0
  126. package/dist/src/utils/visual/types.d.ts +18 -0
  127. package/dist/src/utils/visual/vertex/container.d.ts +74 -0
  128. package/dist/src/utils/visual/vertex/point.d.ts +18 -0
  129. package/dist/src/utils/visual/vertex/vertex.d.ts +36 -0
  130. package/dist/src/vnode/chainDom.d.ts +47 -0
  131. package/dist/src/vnode/h.d.ts +6 -0
  132. package/dist/src/vnode/hooks.d.ts +23 -0
  133. package/dist/src/vnode/htmlDomApi.d.ts +33 -0
  134. package/dist/src/vnode/index.d.ts +18 -0
  135. package/dist/src/vnode/index.js +1 -0
  136. package/dist/src/vnode/init.d.ts +2 -0
  137. package/dist/src/vnode/is.d.ts +5 -0
  138. package/dist/src/vnode/modules/attributes.d.ts +8 -0
  139. package/dist/src/vnode/modules/class.d.ts +8 -0
  140. package/dist/src/vnode/modules/index.d.ts +3 -0
  141. package/dist/src/vnode/modules/listeners.d.ts +12 -0
  142. package/dist/src/vnode/modules/props.d.ts +8 -0
  143. package/dist/src/vnode/modules/style.d.ts +14 -0
  144. package/dist/src/vnode/vnode.d.ts +31 -0
  145. package/dist/subscribe-CINWsor3.js +1 -0
  146. package/dist/test/bridge.test.d.ts +1 -0
  147. package/dist/test/clearBr.test.d.ts +1 -0
  148. package/dist/test/cloneDeep.test.d.ts +1 -0
  149. package/dist/test/command.test.d.ts +1 -0
  150. package/dist/test/encodeUrl.test.d.ts +1 -0
  151. package/dist/test/escapeHtml.test.d.ts +1 -0
  152. package/dist/test/is-equal.test.d.ts +1 -0
  153. package/dist/test/mimeType.test.d.ts +1 -0
  154. package/dist/test/package-exports.test.d.ts +1 -0
  155. package/dist/test/server.test.d.ts +1 -0
  156. package/dist/test/status.test.d.ts +1 -0
  157. package/dist/test/totp.test.d.ts +1 -0
  158. package/dist/test/utils/compose.test.d.ts +1 -0
  159. package/dist/test/utils/mergeObj.test.d.ts +1 -0
  160. package/dist/test/visual/math.test.d.ts +1 -0
  161. package/dist/test/visual-application.test.d.ts +1 -0
  162. package/dist/test/visual-batch.test.d.ts +1 -0
  163. package/dist/test/visual-math.test.d.ts +1 -0
  164. package/dist/test/vnode/index.d.ts +1 -0
  165. package/dist/test/vnode/server.d.ts +2 -0
  166. package/dist/test/vnode/vnode.d.ts +1 -0
  167. package/dist/test/vnode.test.d.ts +1 -0
  168. package/dist/test/websocket.test.d.ts +1 -0
  169. package/dist/test/writeFile.test.d.ts +1 -0
  170. package/dist/umd/index.umd.cjs +1 -0
  171. package/dist/umd/node/node.umd.cjs +1 -0
  172. package/dist/umd/utils/utils.umd.cjs +1 -0
  173. package/dist/utils-_OxsVZmz.js +1 -0
  174. package/dist/vite.config.d.ts +8 -0
  175. package/dist/vitest.config.d.ts +2 -0
  176. package/docs/API.md +305 -0
  177. package/package.json +49 -12
  178. package/typings.d.ts +28 -0
  179. package/dist/index.umd.cjs +0 -1
@@ -0,0 +1,212 @@
1
+ /**
2
+ * @description: 将字符串转对象,比如
3
+ * @param {string} url 'a=1&b=2&c=3'
4
+ * @param {string} sep &
5
+ * @param {string} eq =
6
+ * @return {object} {a:1,b:2,c:3}
7
+ */
8
+ export declare const strParse: (str?: string, sep?: string | RegExp, eq?: string | RegExp) => Record<string, string>;
9
+ /**
10
+ * @description: 清除字符串中的空格、换行和 HTML 标签
11
+ * @param {string} str 要清理的字符串
12
+ * @return {string} 清理后的纯文本
13
+ */
14
+ export declare const clearBr: (str?: string) => string;
15
+ /**
16
+ * @description: 传入字符串和指定的格式,将字符串转成 xml
17
+ * @param {string} xmlStr
18
+ * @param {DOMParserSupportedType} format
19
+ * @return {Document}
20
+ */
21
+ export declare const str2Xml: (xmlStr: string, format?: DOMParserSupportedType) => HTMLElement | undefined;
22
+ export declare const isString: (obj: unknown) => boolean;
23
+ export declare function randomString(len?: number): string;
24
+ export declare function changeHumpToLowerCase(str: string): string;
25
+ interface ClearStrOption {
26
+ urlencoded?: boolean;
27
+ }
28
+ /**
29
+ * @description: 去除字符串首尾的空格,encode 编码,首尾的引号
30
+ * @param {string} str
31
+ * @return {string}
32
+ */
33
+ export declare const clearStr: (str: string, options?: ClearStrOption) => string;
34
+ /**
35
+ * 获取文本中包含搜索关键词的完整句子,对于重复的句子只保留最长的一个
36
+ * @param text 原文本
37
+ * @param searchValue 搜索关键词
38
+ * @returns 包含关键词的完整句子数组(已去重)
39
+ */
40
+ export declare function getMatchingSentences(text: string, searchValue: string): string[];
41
+ export declare const toString: (value: string | number) => string;
42
+ export declare const checkEncoding: (uint8Array: Uint8Array) => string;
43
+ export interface TransformText {
44
+ encoding: string;
45
+ content: string;
46
+ }
47
+ export declare const transformText: (content: string | ArrayBuffer) => TransformText | undefined;
48
+ /**
49
+ * MD5 hash function implementation
50
+ * @param str The string to hash
51
+ * @returns The MD5 hash as a hexadecimal string
52
+ */
53
+ export declare const md5: (str: string) => string;
54
+ export declare const getRandomString: (len?: number) => string;
55
+ type FileChunk = {
56
+ name: string;
57
+ type: string;
58
+ size: number;
59
+ lastModified: number;
60
+ totalChunks: number;
61
+ chunkIndex: number;
62
+ data: string;
63
+ };
64
+ /**
65
+ * 消息编解码工具
66
+ * 正确处理所有 Unicode 字符,包括中文、emoji 等
67
+ * 编码后的字符串只包含 A-Z, a-z, 0-9, +, /, = 这些安全字符
68
+ * 适合在 URL、Cookie 等场景使用
69
+ * 编码解码过程是双向的,不会丢失数据,不会出现编码解码不一致的问题
70
+ */
71
+ export declare const MessageCodec: {
72
+ /**
73
+ * 编码消息
74
+ * @param data 要编码的数据
75
+ * @returns 编码后的字符串
76
+ */
77
+ encode(data: any): string;
78
+ /**
79
+ * 解码消息
80
+ * @param encodedStr 编码后的字符串
81
+ * @returns 解码后的数据
82
+ */
83
+ decode<T = any>(encodedStr: string): T | null;
84
+ /**
85
+ * 编码文件对象
86
+ * @param file File对象
87
+ * @returns 编码后的字符串
88
+ * @throws {MessageCodecError} 当文件编码失败时抛出
89
+ */
90
+ encodeFile(file: File): Promise<string>;
91
+ /**
92
+ * 解码文件对象
93
+ * @param encoded 编码后的字符串
94
+ * @returns 解码后的 File 对象
95
+ * @throws {MessageCodecError} 当解码失败或类型不匹配时抛出
96
+ */
97
+ decodeFile(encoded: string): File;
98
+ /**
99
+ * 编码 Blob 对象
100
+ * @param blob Blob 对象
101
+ * @returns 编码后的字符串
102
+ * @throws {MessageCodecError} 当编码失败时抛出
103
+ */
104
+ encodeBlob(blob: Blob): Promise<string>;
105
+ /**
106
+ * 解码 Blob 对象
107
+ * @param encoded 编码后的字符串
108
+ * @returns 解码后的 Blob 对象
109
+ * @throws {MessageCodecError} 当解码失败或类型不匹配时抛出
110
+ */
111
+ decodeBlob(encoded: string): Blob;
112
+ /**
113
+ * 编码 Date 对象
114
+ * @param date Date 对象
115
+ * @returns 编码后的字符串
116
+ */
117
+ encodeDate(date: Date): string;
118
+ /**
119
+ * 解码 Date 对象
120
+ * @param encodedStr 编码后的字符串
121
+ * @returns 解码后的 Date 对象
122
+ */
123
+ decodeDate(encodedStr: string): Date;
124
+ /**
125
+ * 编码 RegExp 对象
126
+ * @param regexp RegExp 对象
127
+ * @returns 编码后的字符串
128
+ */
129
+ encodeRegExp(regexp: RegExp): string;
130
+ /**
131
+ * 解码 RegExp 对象
132
+ * @param encodedStr 编码后的字符串
133
+ * @returns 解码后的 RegExp 对象
134
+ */
135
+ decodeRegExp(encodedStr: string): RegExp;
136
+ /**
137
+ * 编码 Map 对象
138
+ * @param map Map 对象
139
+ * @returns 编码后的字符串
140
+ */
141
+ encodeMap<K, V>(map: Map<K, V>): string;
142
+ /**
143
+ * 解码 Map 对象
144
+ * @param encodedStr 编码后的字符串
145
+ * @returns 解码后的 Map 对象
146
+ */
147
+ decodeMap<K, V>(encodedStr: string): Map<K, V>;
148
+ /**
149
+ * 编码 Set 对象
150
+ * @param set Set 对象
151
+ * @returns 编码后的字符串
152
+ */
153
+ encodeSet<T>(set: Set<T>): string;
154
+ /**
155
+ * 解码 Set 对象
156
+ * @param encodedStr 编码后的字符串
157
+ * @returns 解码后的 Set 对象
158
+ */
159
+ decodeSet<T>(encodedStr: string): Set<T>;
160
+ /**
161
+ * 编码 Error 对象
162
+ * @param error Error 对象
163
+ * @returns 编码后的字符串
164
+ */
165
+ encodeError(error: Error): string;
166
+ /**
167
+ * 解码 Error 对象
168
+ * @param encodedStr 编码后的字符串
169
+ * @returns 解码后的 Error 对象
170
+ */
171
+ decodeError(encodedStr: string): Error;
172
+ /**
173
+ * 编码 ArrayBuffer 对象
174
+ * @param buffer ArrayBuffer 对象
175
+ * @returns 编码后的字符串
176
+ */
177
+ encodeArrayBuffer(buffer: ArrayBuffer): string;
178
+ /**
179
+ * 解码 ArrayBuffer 对象
180
+ * @param encodedStr 编码后的字符串
181
+ * @returns 解码后的 ArrayBuffer 对象
182
+ */
183
+ decodeArrayBuffer(encodedStr: string): ArrayBuffer;
184
+ /**
185
+ * 编码 TypedArray 对象
186
+ * @param typedArray TypedArray 对象
187
+ * @returns 编码后的字符串
188
+ */
189
+ encodeTypedArray(typedArray: ArrayBufferView): string;
190
+ /**
191
+ * 解码 TypedArray 对象
192
+ * @param encodedStr 编码后的字符串
193
+ * @returns 解码后的 TypedArray 对象
194
+ */
195
+ decodeTypedArray(encodedStr: string): ArrayBufferView;
196
+ /**
197
+ * 分片编码文件对象
198
+ * @param file File 对象
199
+ * @param chunkSize 分片大小,默认 1MB
200
+ * @returns 包含文件信息和分片数据的可传输对象数组
201
+ * @throws {MessageCodecError} 当分片编码失败时抛出
202
+ */
203
+ encodeFileChunked(file: File, chunkSize?: number): Promise<FileChunk[]>;
204
+ /**
205
+ * 解码分片文件对象
206
+ * @param chunks 编码后的文件分片数组
207
+ * @returns 重建的File对象
208
+ * @throws {MessageCodecError} 当分片解码失败或分片不完整时抛出
209
+ */
210
+ decodeFileChunked(chunks: FileChunk[]): Promise<File>;
211
+ };
212
+ export {};
@@ -0,0 +1,46 @@
1
+ export type Callback = Function;
2
+ export type EventName = string | symbol;
3
+ export type EventItem = {
4
+ name?: string | symbol;
5
+ callback: Callback;
6
+ initialCallback?: Callback;
7
+ };
8
+ export declare const NEW_LISTENER = "NEW_LISTENER";
9
+ export declare class SyncHook {
10
+ readonly _events: Map<EventName, Set<EventItem>>;
11
+ /**
12
+ * @description: 订阅事件
13
+ * @param {EventName} eventName
14
+ * @param {EventItem} eventItem
15
+ * @return {void}
16
+ */
17
+ tap: (eventName: EventName, eventItem: EventItem | Callback) => this;
18
+ /**
19
+ * @description: 触发事件
20
+ * @param {EventName} eventName
21
+ * @param {array} args
22
+ * @return {void}
23
+ */
24
+ call: (eventName: EventName, ...args: Array<unknown>) => this;
25
+ /**
26
+ * @description: 同步触发事件
27
+ * @param {EventName} eventName
28
+ * @param {array} args
29
+ * @return {Promise<void>}
30
+ */
31
+ callSync: (eventName: EventName, ...args: Array<unknown>) => Promise<this>;
32
+ /**
33
+ * @description: 只订阅一次事件,触发后就移除事件
34
+ * @param {EventName} eventName
35
+ * @param {EventItem} eventItem
36
+ * @return {void}
37
+ */
38
+ once: (eventName: EventName, eventItem: EventItem | Callback) => this;
39
+ /**
40
+ * @description: 移除订阅的事件
41
+ * @param {EventName} eventName
42
+ * @param {EventItem} eventItem
43
+ * @return {void}
44
+ */
45
+ off: (eventName: EventName, eventItem: EventItem | Callback) => this;
46
+ }
@@ -0,0 +1,15 @@
1
+ type ThrottleFunc<T extends (...args: any[]) => void> = (...args: Parameters<T>) => any;
2
+ /**
3
+ * @description: 节流
4
+ * @param {any} fn
5
+ * @param {*} wait
6
+ * @return {*}
7
+ */
8
+ export declare function throttle<T extends (...args: any[]) => any>(func: T, delay?: number): ThrottleFunc<T>;
9
+ /**
10
+ * @description: 生成节流函数
11
+ * @param {*} Function
12
+ * @return {*}
13
+ */
14
+ export declare const generateThrottle: () => Function;
15
+ export {};
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @description: 时间戳转日期
3
+ * @param {*} timestamp
4
+ * @param {*} returnType
5
+ * @return {*}
6
+ */
7
+ export declare function timestampToTime(timestamp?: number | string): Date & {
8
+ format?: Function;
9
+ };
10
+ /**
11
+ * @description: 时间秒,转化成:分割的时间
12
+ * @param {number} time
13
+ * @return {*}
14
+ */
15
+ export declare const timeFormat: (time: number) => string;
16
+ /**
17
+ * @description: 获取当前时间戳
18
+ * @return {*}
19
+ */
20
+ export declare const performanceTime: () => number;
@@ -0,0 +1,151 @@
1
+ import type { EncodingType, FixedLengthOptionsEncodingType, FixedLengthOptionsNoEncodingType, FormatNoTextType, FormatType, GenericInputType, packedValue } from './custom_types';
2
+ export declare const TWO_PWR_32 = 4294967296;
3
+ export declare const K_sha2: number[];
4
+ export declare const H_trunc: number[];
5
+ export declare const H_full: number[];
6
+ export declare const sha_variant_error = "Chosen SHA variant is not supported";
7
+ export declare const mac_rounds_error = "Cannot set numRounds with MAC";
8
+ /**
9
+ * Concatenates 2 packed arrays. Clobbers array `a`.
10
+ *
11
+ * @param a First array to concatenate.
12
+ * @param b Second array to concatenate.
13
+ * @returns The concatentation of `a` + `b`.
14
+ */
15
+ export declare function packedLEConcat(a: packedValue, b: packedValue): packedValue;
16
+ /**
17
+ * Validate hash list containing output formatting options, ensuring presence of every option or adding the default
18
+ * value.
19
+ *
20
+ * @param options Hashmap of output formatting options from user.
21
+ * @returns Validated hashmap containing output formatting options.
22
+ */
23
+ export declare function getOutputOpts(options?: {
24
+ outputUpper?: boolean;
25
+ b64Pad?: string;
26
+ shakeLen?: number;
27
+ outputLen?: number;
28
+ }): {
29
+ outputUpper: boolean;
30
+ b64Pad: string;
31
+ outputLen: number;
32
+ };
33
+ /**
34
+ * Parses an external constructor object and returns a packed number, if possible.
35
+ *
36
+ * @param key The human-friendly key name to prefix any errors with
37
+ * @param value The input value object to parse
38
+ * @param bigEndianMod Modifier for whether hash function is big or small endian.
39
+ * @param fallback Fallback value if `value` is undefined. If not present and `value` is undefined, an Error is thrown
40
+ */
41
+ export declare function parseInputOption(key: string, value: GenericInputType | undefined, bigEndianMod: -1 | 1, fallback?: packedValue): packedValue;
42
+ export declare abstract class jsSHABase<StateT, VariantT> {
43
+ /**
44
+ * @param variant The desired SHA variant.
45
+ * @param inputFormat The input format to be used in future `update` calls.
46
+ * @param options Hashmap of extra input options.
47
+ */
48
+ protected readonly shaVariant: VariantT;
49
+ protected readonly inputFormat: FormatType;
50
+ protected readonly utfType: EncodingType;
51
+ protected readonly numRounds: number;
52
+ protected abstract intermediateState: StateT;
53
+ protected keyWithIPad: number[];
54
+ protected keyWithOPad: number[];
55
+ protected remainder: number[];
56
+ protected remainderLen: number;
57
+ protected updateCalled: boolean;
58
+ protected processedLen: number;
59
+ protected macKeySet: boolean;
60
+ protected abstract readonly variantBlockSize: number;
61
+ protected abstract readonly bigEndianMod: -1 | 1;
62
+ protected abstract readonly outputBinLen: number;
63
+ protected abstract readonly isVariableLen: boolean;
64
+ protected abstract readonly HMACSupported: boolean;
65
+ protected abstract readonly converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;
66
+ protected abstract readonly roundFunc: (block: number[], H: StateT) => StateT;
67
+ protected abstract readonly finalizeFunc: (remainder: number[], remainderBinLen: number, processedBinLen: number, H: StateT, outputLen: number) => number[];
68
+ protected abstract readonly stateCloneFunc: (state: StateT) => StateT;
69
+ protected abstract readonly newStateFunc: (variant: VariantT) => StateT;
70
+ protected abstract readonly getMAC: ((options: {
71
+ outputLen: number;
72
+ }) => number[]) | null;
73
+ protected constructor(variant: VariantT, inputFormat: 'TEXT', options?: FixedLengthOptionsEncodingType);
74
+ protected constructor(variant: VariantT, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);
75
+ /**
76
+ * Hashes as many blocks as possible. Stores the rest for either a future update or getHash call.
77
+ *
78
+ * @param srcString The input to be hashed.
79
+ * @returns A reference to the object.
80
+ */
81
+ update(srcString: string | ArrayBuffer | Uint8Array): this;
82
+ /**
83
+ * Returns the desired SHA hash of the input fed in via `update` calls.
84
+ *
85
+ * @param format The desired output formatting
86
+ * @param options Hashmap of output formatting options. `outputLen` must be specified for variable length hashes.
87
+ * `outputLen` replaces the now deprecated `shakeLen` key.
88
+ * @returns The hash in the format specified.
89
+ */
90
+ getHash(format: 'HEX', options?: {
91
+ outputUpper?: boolean;
92
+ outputLen?: number;
93
+ shakeLen?: number;
94
+ }): string;
95
+ getHash(format: 'B64', options?: {
96
+ b64Pad?: string;
97
+ outputLen?: number;
98
+ shakeLen?: number;
99
+ }): string;
100
+ getHash(format: 'BYTES', options?: {
101
+ outputLen?: number;
102
+ shakeLen?: number;
103
+ }): string;
104
+ getHash(format: 'UINT8ARRAY', options?: {
105
+ outputLen?: number;
106
+ shakeLen?: number;
107
+ }): Uint8Array;
108
+ getHash(format: 'ARRAYBUFFER', options?: {
109
+ outputLen?: number;
110
+ shakeLen?: number;
111
+ }): ArrayBuffer;
112
+ /**
113
+ * Sets the HMAC key for an eventual `getHMAC` call. Must be called immediately after jsSHA object instantiation.
114
+ *
115
+ * @param key The key used to calculate the HMAC
116
+ * @param inputFormat The format of key.
117
+ * @param options Hashmap of extra input options.
118
+ */
119
+ setHMACKey(key: string, inputFormat: 'TEXT', options?: {
120
+ encoding?: EncodingType;
121
+ }): void;
122
+ setHMACKey(key: string, inputFormat: 'B64' | 'HEX' | 'BYTES'): void;
123
+ setHMACKey(key: ArrayBuffer, inputFormat: 'ARRAYBUFFER'): void;
124
+ setHMACKey(key: Uint8Array, inputFormat: 'UINT8ARRAY'): void;
125
+ /**
126
+ * Internal function that sets the MAC key.
127
+ *
128
+ * @param key The packed MAC key to use
129
+ */
130
+ protected _setHMACKey(key: packedValue): void;
131
+ /**
132
+ * Returns the the HMAC in the specified format using the key given by a previous `setHMACKey` call.
133
+ *
134
+ * @param format The desired output formatting.
135
+ * @param options Hashmap of extra outputs options.
136
+ * @returns The HMAC in the format specified.
137
+ */
138
+ getHMAC(format: 'HEX', options?: {
139
+ outputUpper?: boolean;
140
+ }): string;
141
+ getHMAC(format: 'B64', options?: {
142
+ b64Pad?: string;
143
+ }): string;
144
+ getHMAC(format: 'BYTES'): string;
145
+ getHMAC(format: 'UINT8ARRAY'): Uint8Array;
146
+ getHMAC(format: 'ARRAYBUFFER'): ArrayBuffer;
147
+ /**
148
+ * Internal function that returns the "raw" HMAC
149
+ */
150
+ protected _getHMAC(): number[];
151
+ }
@@ -0,0 +1,88 @@
1
+ import type { EncodingType, FormatType, packedValue } from './custom_types';
2
+ /**
3
+ * Function that takes an input format and UTF encoding and returns the appropriate function used to convert the input.
4
+ *
5
+ * @param format The format of the input to be converted
6
+ * @param utfType The string encoding to use for TEXT inputs.
7
+ * @param bigEndianMod Modifier for whether hash function is big or small endian
8
+ * @returns Function that will convert an input to a packed int array.
9
+ */
10
+ export declare function getStrConverter(format: FormatType, utfType: EncodingType, bigEndianMod: -1 | 1): (input: any, existingBin?: number[], existingBinLen?: number) => packedValue;
11
+ /**
12
+ * Convert an array of words to a hexadecimal string.
13
+ *
14
+ * toString() won't work here because it removes preceding zeros (e.g. 0x00000001.toString === "1" rather than
15
+ * "00000001" and 0.toString(16) === "0" rather than "00").
16
+ *
17
+ * @param packed Array of integers to be converted.
18
+ * @param outputLength Length of output in bits.
19
+ * @param bigEndianMod Modifier for whether hash function is big or small endian.
20
+ * @param formatOpts Hashmap containing validated output formatting options.
21
+ * @returns Hexadecimal representation of `packed`.
22
+ */
23
+ export declare function packed2hex(packed: number[], outputLength: number, bigEndianMod: -1 | 1, formatOpts: {
24
+ outputUpper: boolean;
25
+ b64Pad: string;
26
+ }): string;
27
+ /**
28
+ * Convert an array of words to a base-64 string.
29
+ *
30
+ * @param packed Array of integers to be converted.
31
+ * @param outputLength Length of output in bits.
32
+ * @param bigEndianMod Modifier for whether hash function is big or small endian.
33
+ * @param formatOpts Hashmap containing validated output formatting options.
34
+ * @returns Base64-encoded representation of `packed`.
35
+ */
36
+ export declare function packed2b64(packed: number[], outputLength: number, bigEndianMod: -1 | 1, formatOpts: {
37
+ outputUpper: boolean;
38
+ b64Pad: string;
39
+ }): string;
40
+ /**
41
+ * Convert an array of words to raw bytes string.
42
+ *
43
+ * @param packed Array of integers to be converted.
44
+ * @param outputLength Length of output in bits.
45
+ * @param bigEndianMod Modifier for whether hash function is big or small endian.
46
+ * @returns Raw bytes representation of `packed`.
47
+ */
48
+ export declare function packed2bytes(packed: number[], outputLength: number, bigEndianMod: -1 | 1): string;
49
+ /**
50
+ * Convert an array of words to an ArrayBuffer.
51
+ *
52
+ * @param packed Array of integers to be converted.
53
+ * @param outputLength Length of output in bits.
54
+ * @param bigEndianMod Modifier for whether hash function is big or small endian.
55
+ * @returns An ArrayBuffer containing bytes from `packed.
56
+ */
57
+ export declare function packed2arraybuffer(packed: number[], outputLength: number, bigEndianMod: -1 | 1): ArrayBuffer;
58
+ /**
59
+ * Convert an array of words to an Uint8Array.
60
+ *
61
+ * @param packed Array of integers to be converted.
62
+ * @param outputLength Length of output in bits.
63
+ * @param bigEndianMod Modifier for whether hash function is big or small endian.
64
+ * @returns An Uint8Array containing bytes from `packed.
65
+ */
66
+ export declare function packed2uint8array(packed: number[], outputLength: number, bigEndianMod: -1 | 1): Uint8Array;
67
+ /**
68
+ * Function that takes an output format and associated parameters and returns a function that converts packed integers
69
+ * to that format.
70
+ *
71
+ * @param format The desired output formatting.
72
+ * @param outputBinLen Output length in bits.
73
+ * @param bigEndianMod Modifier for whether hash function is big or small endian.
74
+ * @param outputOptions Hashmap of output formatting options
75
+ * @returns Function that will convert a packed integer array to desired format.
76
+ */
77
+ export declare function getOutputConverter(format: 'HEX' | 'B64' | 'BYTES', outputBinLen: number, bigEndianMod: -1 | 1, outputOptions: {
78
+ outputUpper: boolean;
79
+ b64Pad: string;
80
+ }): (binarray: number[]) => string;
81
+ export declare function getOutputConverter(format: 'ARRAYBUFFER', outputBinLen: number, bigEndianMod: -1 | 1, outputOptions: {
82
+ outputUpper: boolean;
83
+ b64Pad: string;
84
+ }): (binarray: number[]) => ArrayBuffer;
85
+ export declare function getOutputConverter(format: 'UINT8ARRAY', outputBinLen: number, bigEndianMod: -1 | 1, outputOptions: {
86
+ outputUpper: boolean;
87
+ b64Pad: string;
88
+ }): (binarray: number[]) => Uint8Array;
@@ -0,0 +1,60 @@
1
+ export type EncodingType = 'UTF8' | 'UTF16BE' | 'UTF16LE';
2
+ export type FormatNoTextType = 'HEX' | 'B64' | 'BYTES' | 'ARRAYBUFFER' | 'UINT8ARRAY';
3
+ export type FormatType = 'TEXT' | FormatNoTextType;
4
+ export type GenericInputType = {
5
+ value: string;
6
+ format: 'TEXT';
7
+ encoding?: EncodingType;
8
+ } | {
9
+ value: string;
10
+ format: 'B64' | 'HEX' | 'BYTES';
11
+ } | {
12
+ value: ArrayBuffer;
13
+ format: 'ARRAYBUFFER';
14
+ } | {
15
+ value: Uint8Array;
16
+ format: 'UINT8ARRAY';
17
+ };
18
+ export type FixedLengthOptionsNoEncodingType = {
19
+ hmacKey?: GenericInputType;
20
+ } | {
21
+ numRounds?: number;
22
+ };
23
+ export type FixedLengthOptionsEncodingType = {
24
+ hmacKey?: GenericInputType;
25
+ encoding?: EncodingType;
26
+ } | {
27
+ numRounds?: number;
28
+ encoding?: EncodingType;
29
+ };
30
+ export interface packedValue {
31
+ value: number[];
32
+ binLen: number;
33
+ }
34
+ export interface SHAKEOptionsNoEncodingType {
35
+ numRounds?: number;
36
+ }
37
+ export interface SHAKEOptionsEncodingType extends SHAKEOptionsNoEncodingType {
38
+ encoding?: EncodingType;
39
+ }
40
+ export interface CSHAKEOptionsNoEncodingType {
41
+ customization?: GenericInputType;
42
+ funcName?: GenericInputType;
43
+ }
44
+ export interface CSHAKEOptionsEncodingType extends CSHAKEOptionsNoEncodingType {
45
+ encoding?: EncodingType;
46
+ }
47
+ export interface KMACOptionsNoEncodingType {
48
+ kmacKey: GenericInputType;
49
+ customization?: GenericInputType;
50
+ }
51
+ export interface KMACOptionsEncodingType extends KMACOptionsNoEncodingType {
52
+ encoding?: EncodingType;
53
+ }
54
+ export interface ResolvedCSHAKEOptionsNoEncodingType {
55
+ funcName: packedValue;
56
+ customization: packedValue;
57
+ }
58
+ export interface ResolvedKMACOptionsNoEncodingType extends ResolvedCSHAKEOptionsNoEncodingType {
59
+ kmacKey: packedValue;
60
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The 32-bit implementation of circular rotate left.
3
+ *
4
+ * @param x The 32-bit integer argument.
5
+ * @param n The number of bits to shift.
6
+ * @returns `x` shifted left circularly by `n` bits
7
+ */
8
+ export declare function rotl_32(x: number, n: number): number;
9
+ /**
10
+ * The 32-bit implementation of the NIST specified Parity function.
11
+ *
12
+ * @param x The first 32-bit integer argument.
13
+ * @param y The second 32-bit integer argument.
14
+ * @param z The third 32-bit integer argument.
15
+ * @returns The NIST specified output of the function.
16
+ */
17
+ export declare function parity_32(x: number, y: number, z: number): number;
18
+ /**
19
+ * The 32-bit implementation of the NIST specified Ch function.
20
+ *
21
+ * @param x The first 32-bit integer argument.
22
+ * @param y The second 32-bit integer argument.
23
+ * @param z The third 32-bit integer argument.
24
+ * @returns The NIST specified output of the function.
25
+ */
26
+ export declare function ch_32(x: number, y: number, z: number): number;
27
+ /**
28
+ * The 32-bit implementation of the NIST specified Maj function.
29
+ *
30
+ * @param x The first 32-bit integer argument.
31
+ * @param y The second 32-bit integer argument.
32
+ * @param z The third 32-bit integer argument.
33
+ * @returns The NIST specified output of the function.
34
+ */
35
+ export declare function maj_32(x: number, y: number, z: number): number;
36
+ /**
37
+ * The 32-bit implementation of the NIST specified Sigma0 function.
38
+ *
39
+ * @param x The 32-bit integer argument.
40
+ * @returns The NIST specified output of the function.
41
+ */
42
+ export declare function sigma0_32(x: number): number;
43
+ /**
44
+ * Add two 32-bit integers.
45
+ *
46
+ * This uses 16-bit operations internally to work around sign problems due to JavaScript's lack of uint32 support.
47
+ *
48
+ * @param a The first 32-bit integer argument to be added.
49
+ * @param b The second 32-bit integer argument to be added.
50
+ * @returns The sum of `a` + `b`.
51
+ */
52
+ export declare function safeAdd_32_2(a: number, b: number): number;
53
+ /**
54
+ * Add four 32-bit integers.
55
+ *
56
+ * This uses 16-bit operations internally to work around sign problems due to JavaScript's lack of uint32 support.
57
+ *
58
+ * @param a The first 32-bit integer argument to be added.
59
+ * @param b The second 32-bit integer argument to be added.
60
+ * @param c The third 32-bit integer argument to be added.
61
+ * @param d The fourth 32-bit integer argument to be added.
62
+ * @returns The sum of `a` + `b` + `c` + `d`.
63
+ */
64
+ export declare function safeAdd_32_4(a: number, b: number, c: number, d: number): number;
65
+ /**
66
+ * Add five 32-bit integers.
67
+ *
68
+ * This uses 16-bit operations internally to work around sign problems due to JavaScript's lack of uint32 support.
69
+ *
70
+ * @param a The first 32-bit integer argument to be added.
71
+ * @param b The second 32-bit integer argument to be added.
72
+ * @param c The third 32-bit integer argument to be added.
73
+ * @param d The fourth 32-bit integer argument to be added.
74
+ * @param e The fifth 32-bit integer argument to be added.
75
+ * @returns The sum of `a` + `b` + `c` + `d` + `e`.
76
+ */
77
+ export declare function safeAdd_32_5(a: number, b: number, c: number, d: number, e: number): number;
78
+ /**
79
+ * The 32-bit implementation of the NIST specified Gamma1 function.
80
+ *
81
+ * @param x The 32-bit integer argument.
82
+ * @returns The NIST specified output of the function.
83
+ */
84
+ export declare function gamma1_32(x: number): number;
85
+ /**
86
+ * The 32-bit implementation of the NIST specified Gamma0 function.
87
+ *
88
+ * @param x The 32-bit integer argument.
89
+ * @returns The NIST specified output of the function.
90
+ */
91
+ export declare function gamma0_32(x: number): number;
92
+ /**
93
+ * The 32-bit implementation of the NIST specified Sigma1 function.
94
+ *
95
+ * @param x The 32-bit integer argument.
96
+ * @returns The NIST specified output of the function.
97
+ */
98
+ export declare function sigma1_32(x: number): number;