langchain 0.0.195 → 0.0.196

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 (216) hide show
  1. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
  2. package/dist/base_language/count_tokens.cjs +5 -70
  3. package/dist/base_language/count_tokens.d.ts +1 -10
  4. package/dist/base_language/count_tokens.js +1 -65
  5. package/dist/base_language/index.cjs +6 -196
  6. package/dist/base_language/index.d.ts +1 -111
  7. package/dist/base_language/index.js +1 -191
  8. package/dist/cache/base.cjs +15 -37
  9. package/dist/cache/base.d.ts +1 -20
  10. package/dist/cache/base.js +1 -33
  11. package/dist/cache/index.cjs +2 -46
  12. package/dist/cache/index.d.ts +1 -29
  13. package/dist/cache/index.js +1 -45
  14. package/dist/callbacks/base.cjs +3 -139
  15. package/dist/callbacks/base.d.ts +1 -266
  16. package/dist/callbacks/base.js +1 -126
  17. package/dist/callbacks/handlers/console.cjs +14 -221
  18. package/dist/callbacks/handlers/console.d.ts +1 -117
  19. package/dist/callbacks/handlers/console.js +1 -217
  20. package/dist/callbacks/handlers/initialize.cjs +15 -30
  21. package/dist/callbacks/handlers/initialize.d.ts +1 -16
  22. package/dist/callbacks/handlers/initialize.js +1 -27
  23. package/dist/callbacks/handlers/log_stream.cjs +15 -293
  24. package/dist/callbacks/handlers/log_stream.d.ts +1 -100
  25. package/dist/callbacks/handlers/log_stream.js +1 -289
  26. package/dist/callbacks/handlers/run_collector.cjs +15 -48
  27. package/dist/callbacks/handlers/run_collector.d.ts +1 -26
  28. package/dist/callbacks/handlers/run_collector.js +1 -46
  29. package/dist/callbacks/handlers/tracer.cjs +15 -375
  30. package/dist/callbacks/handlers/tracer.d.ts +1 -70
  31. package/dist/callbacks/handlers/tracer.js +1 -373
  32. package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
  33. package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
  34. package/dist/callbacks/handlers/tracer_langchain.js +1 -102
  35. package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
  36. package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
  37. package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
  38. package/dist/callbacks/manager.cjs +15 -676
  39. package/dist/callbacks/manager.d.ts +1 -180
  40. package/dist/callbacks/manager.js +1 -666
  41. package/dist/callbacks/promises.cjs +14 -42
  42. package/dist/callbacks/promises.d.ts +1 -11
  43. package/dist/callbacks/promises.js +1 -37
  44. package/dist/chains/graph_qa/prompts.d.ts +1 -1
  45. package/dist/chains/openai_functions/structured_output.cjs +2 -2
  46. package/dist/chains/openai_functions/structured_output.d.ts +1 -1
  47. package/dist/chains/openai_functions/structured_output.js +1 -1
  48. package/dist/chat_models/baiduwenxin.d.ts +1 -1
  49. package/dist/chat_models/base.cjs +15 -296
  50. package/dist/chat_models/base.d.ts +1 -122
  51. package/dist/chat_models/base.js +1 -292
  52. package/dist/chat_models/bedrock/web.d.ts +1 -1
  53. package/dist/chat_models/fireworks.d.ts +1 -1
  54. package/dist/document.cjs +2 -24
  55. package/dist/document.d.ts +1 -12
  56. package/dist/document.js +1 -23
  57. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
  58. package/dist/document_loaders/web/s3.d.ts +1 -1
  59. package/dist/embeddings/base.cjs +15 -22
  60. package/dist/embeddings/base.d.ts +1 -33
  61. package/dist/embeddings/base.js +1 -20
  62. package/dist/embeddings/cache_backed.cjs +2 -2
  63. package/dist/embeddings/cache_backed.js +1 -1
  64. package/dist/evaluation/agents/trajectory.d.ts +1 -1
  65. package/dist/evaluation/criteria/prompt.d.ts +2 -2
  66. package/dist/evaluation/qa/prompt.d.ts +2 -2
  67. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
  68. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
  69. package/dist/llms/base.cjs +15 -278
  70. package/dist/llms/base.d.ts +1 -115
  71. package/dist/llms/base.js +1 -275
  72. package/dist/llms/bedrock/web.d.ts +1 -1
  73. package/dist/llms/fireworks.d.ts +1 -1
  74. package/dist/load/import_map.cjs +2 -1
  75. package/dist/load/import_map.d.ts +1 -0
  76. package/dist/load/import_map.js +1 -0
  77. package/dist/load/index.cjs +7 -148
  78. package/dist/load/index.js +7 -148
  79. package/dist/load/map_keys.cjs +0 -24
  80. package/dist/load/map_keys.d.ts +0 -6
  81. package/dist/load/map_keys.js +1 -17
  82. package/dist/load/serializable.cjs +15 -178
  83. package/dist/load/serializable.d.ts +1 -66
  84. package/dist/load/serializable.js +1 -175
  85. package/dist/memory/base.cjs +17 -92
  86. package/dist/memory/base.d.ts +2 -68
  87. package/dist/memory/base.js +2 -87
  88. package/dist/output_parsers/openai_functions.cjs +2 -2
  89. package/dist/output_parsers/openai_functions.d.ts +1 -1
  90. package/dist/output_parsers/openai_functions.js +1 -1
  91. package/dist/output_parsers/regex.d.ts +1 -1
  92. package/dist/output_parsers/structured.d.ts +1 -1
  93. package/dist/prompts/base.cjs +8 -183
  94. package/dist/prompts/base.d.ts +3 -132
  95. package/dist/prompts/base.js +3 -178
  96. package/dist/prompts/chat.cjs +15 -477
  97. package/dist/prompts/chat.d.ts +1 -219
  98. package/dist/prompts/chat.js +1 -466
  99. package/dist/prompts/few_shot.cjs +15 -353
  100. package/dist/prompts/few_shot.d.ts +1 -192
  101. package/dist/prompts/few_shot.js +1 -350
  102. package/dist/prompts/index.cjs +3 -2
  103. package/dist/prompts/index.d.ts +2 -1
  104. package/dist/prompts/index.js +2 -1
  105. package/dist/prompts/pipeline.cjs +15 -142
  106. package/dist/prompts/pipeline.d.ts +1 -98
  107. package/dist/prompts/pipeline.js +1 -140
  108. package/dist/prompts/prompt.cjs +15 -146
  109. package/dist/prompts/prompt.d.ts +1 -92
  110. package/dist/prompts/prompt.js +1 -144
  111. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
  112. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
  113. package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
  114. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
  115. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
  116. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
  117. package/dist/prompts/selectors/conditional.cjs +15 -74
  118. package/dist/prompts/selectors/conditional.d.ts +1 -63
  119. package/dist/prompts/selectors/conditional.js +1 -69
  120. package/dist/prompts/serde.cjs +15 -0
  121. package/dist/prompts/serde.d.ts +1 -43
  122. package/dist/prompts/serde.js +1 -1
  123. package/dist/prompts/template.cjs +14 -88
  124. package/dist/prompts/template.d.ts +1 -36
  125. package/dist/prompts/template.js +1 -83
  126. package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
  127. package/dist/runnables/index.d.ts +1 -0
  128. package/dist/runnables/index.js +1 -0
  129. package/dist/schema/document.cjs +3 -34
  130. package/dist/schema/document.d.ts +2 -29
  131. package/dist/schema/document.js +2 -32
  132. package/dist/schema/index.cjs +37 -612
  133. package/dist/schema/index.d.ts +11 -311
  134. package/dist/schema/index.js +8 -583
  135. package/dist/schema/output_parser.cjs +15 -309
  136. package/dist/schema/output_parser.d.ts +1 -173
  137. package/dist/schema/output_parser.js +1 -301
  138. package/dist/schema/retriever.cjs +15 -77
  139. package/dist/schema/retriever.d.ts +1 -43
  140. package/dist/schema/retriever.js +1 -75
  141. package/dist/schema/runnable/base.cjs +10 -1072
  142. package/dist/schema/runnable/base.d.ts +1 -356
  143. package/dist/schema/runnable/base.js +1 -1060
  144. package/dist/schema/runnable/branch.cjs +2 -131
  145. package/dist/schema/runnable/branch.d.ts +1 -94
  146. package/dist/schema/runnable/branch.js +1 -130
  147. package/dist/schema/runnable/config.cjs +0 -6
  148. package/dist/schema/runnable/config.d.ts +1 -3
  149. package/dist/schema/runnable/config.js +1 -4
  150. package/dist/schema/runnable/index.cjs +15 -16
  151. package/dist/schema/runnable/index.d.ts +1 -5
  152. package/dist/schema/runnable/index.js +1 -4
  153. package/dist/schema/runnable/passthrough.cjs +3 -113
  154. package/dist/schema/runnable/passthrough.d.ts +1 -72
  155. package/dist/schema/runnable/passthrough.js +1 -111
  156. package/dist/schema/runnable/router.cjs +2 -71
  157. package/dist/schema/runnable/router.d.ts +1 -29
  158. package/dist/schema/runnable/router.js +1 -70
  159. package/dist/schema/storage.cjs +15 -8
  160. package/dist/schema/storage.d.ts +1 -57
  161. package/dist/schema/storage.js +1 -6
  162. package/dist/tools/bingserpapi.d.ts +1 -1
  163. package/dist/tools/searchapi.d.ts +1 -1
  164. package/dist/tools/serpapi.d.ts +1 -1
  165. package/dist/tools/serper.d.ts +1 -1
  166. package/dist/util/async_caller.cjs +14 -128
  167. package/dist/util/async_caller.d.ts +1 -45
  168. package/dist/util/async_caller.js +1 -124
  169. package/package.json +11 -5
  170. package/runnables.cjs +1 -0
  171. package/runnables.d.ts +1 -0
  172. package/runnables.js +1 -0
  173. package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
  174. package/dist/util/@cfworker/json-schema/index.js +0 -1
  175. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
  176. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
  177. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
  178. package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
  179. package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
  180. package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
  181. package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
  182. package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
  183. package/dist/util/@cfworker/json-schema/src/format.js +0 -136
  184. package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
  185. package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
  186. package/dist/util/@cfworker/json-schema/src/index.js +0 -8
  187. package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
  188. package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
  189. package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
  190. package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
  191. package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
  192. package/dist/util/@cfworker/json-schema/src/types.js +0 -1
  193. package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
  194. package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
  195. package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
  196. package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
  197. package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
  198. package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
  199. package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
  200. package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
  201. package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
  202. package/dist/util/fast-json-patch/index.cjs +0 -49
  203. package/dist/util/fast-json-patch/index.d.ts +0 -22
  204. package/dist/util/fast-json-patch/index.js +0 -16
  205. package/dist/util/fast-json-patch/src/core.cjs +0 -469
  206. package/dist/util/fast-json-patch/src/core.d.ts +0 -111
  207. package/dist/util/fast-json-patch/src/core.js +0 -459
  208. package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
  209. package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
  210. package/dist/util/fast-json-patch/src/duplex.js +0 -230
  211. package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
  212. package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
  213. package/dist/util/fast-json-patch/src/helpers.js +0 -181
  214. package/dist/util/js-sha1/hash.cjs +0 -358
  215. package/dist/util/js-sha1/hash.d.ts +0 -1
  216. package/dist/util/js-sha1/hash.js +0 -355
@@ -1,36 +0,0 @@
1
- export declare function hasOwnProperty(obj: any, key: any): boolean;
2
- export declare function _objectKeys(obj: any): any[];
3
- /**
4
- * Deeply clone the object.
5
- * https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
6
- * @param {any} obj value to clone
7
- * @return {any} cloned obj
8
- */
9
- export declare function _deepClone(obj: any): any;
10
- export declare function isInteger(str: string): boolean;
11
- /**
12
- * Escapes a json pointer path
13
- * @param path The raw pointer
14
- * @return the Escaped path
15
- */
16
- export declare function escapePathComponent(path: string): string;
17
- /**
18
- * Unescapes a json pointer path
19
- * @param path The escaped pointer
20
- * @return The unescaped path
21
- */
22
- export declare function unescapePathComponent(path: string): string;
23
- export declare function _getPathRecursive(root: Object, obj: Object): string;
24
- export declare function getPath(root: Object, obj: Object): string;
25
- /**
26
- * Recursively checks whether an object has any undefined values inside.
27
- */
28
- export declare function hasUndefined(obj: any): boolean;
29
- export type JsonPatchErrorName = "SEQUENCE_NOT_AN_ARRAY" | "OPERATION_NOT_AN_OBJECT" | "OPERATION_OP_INVALID" | "OPERATION_PATH_INVALID" | "OPERATION_FROM_REQUIRED" | "OPERATION_VALUE_REQUIRED" | "OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED" | "OPERATION_PATH_CANNOT_ADD" | "OPERATION_PATH_UNRESOLVABLE" | "OPERATION_FROM_UNRESOLVABLE" | "OPERATION_PATH_ILLEGAL_ARRAY_INDEX" | "OPERATION_VALUE_OUT_OF_BOUNDS" | "TEST_OPERATION_FAILED";
30
- export declare class PatchError extends Error {
31
- name: JsonPatchErrorName;
32
- index?: number | undefined;
33
- operation?: any;
34
- tree?: any;
35
- constructor(message: string, name: JsonPatchErrorName, index?: number | undefined, operation?: any, tree?: any);
36
- }
@@ -1,181 +0,0 @@
1
- // @ts-nocheck
2
- // Inlined because of ESM import issues
3
- /*!
4
- * https://github.com/Starcounter-Jack/JSON-Patch
5
- * (c) 2017-2022 Joachim Wester
6
- * MIT licensed
7
- */
8
- const _hasOwnProperty = Object.prototype.hasOwnProperty;
9
- export function hasOwnProperty(obj, key) {
10
- return _hasOwnProperty.call(obj, key);
11
- }
12
- export function _objectKeys(obj) {
13
- if (Array.isArray(obj)) {
14
- const keys = new Array(obj.length);
15
- for (let k = 0; k < keys.length; k++) {
16
- keys[k] = "" + k;
17
- }
18
- return keys;
19
- }
20
- if (Object.keys) {
21
- return Object.keys(obj);
22
- }
23
- let keys = [];
24
- for (let i in obj) {
25
- if (hasOwnProperty(obj, i)) {
26
- keys.push(i);
27
- }
28
- }
29
- return keys;
30
- }
31
- /**
32
- * Deeply clone the object.
33
- * https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
34
- * @param {any} obj value to clone
35
- * @return {any} cloned obj
36
- */
37
- export function _deepClone(obj) {
38
- switch (typeof obj) {
39
- case "object":
40
- return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
41
- case "undefined":
42
- return null; //this is how JSON.stringify behaves for array items
43
- default:
44
- return obj; //no need to clone primitives
45
- }
46
- }
47
- //3x faster than cached /^\d+$/.test(str)
48
- export function isInteger(str) {
49
- let i = 0;
50
- const len = str.length;
51
- let charCode;
52
- while (i < len) {
53
- charCode = str.charCodeAt(i);
54
- if (charCode >= 48 && charCode <= 57) {
55
- i++;
56
- continue;
57
- }
58
- return false;
59
- }
60
- return true;
61
- }
62
- /**
63
- * Escapes a json pointer path
64
- * @param path The raw pointer
65
- * @return the Escaped path
66
- */
67
- export function escapePathComponent(path) {
68
- if (path.indexOf("/") === -1 && path.indexOf("~") === -1)
69
- return path;
70
- return path.replace(/~/g, "~0").replace(/\//g, "~1");
71
- }
72
- /**
73
- * Unescapes a json pointer path
74
- * @param path The escaped pointer
75
- * @return The unescaped path
76
- */
77
- export function unescapePathComponent(path) {
78
- return path.replace(/~1/g, "/").replace(/~0/g, "~");
79
- }
80
- export function _getPathRecursive(root, obj) {
81
- let found;
82
- for (let key in root) {
83
- if (hasOwnProperty(root, key)) {
84
- if (root[key] === obj) {
85
- return escapePathComponent(key) + "/";
86
- }
87
- else if (typeof root[key] === "object") {
88
- found = _getPathRecursive(root[key], obj);
89
- if (found != "") {
90
- return escapePathComponent(key) + "/" + found;
91
- }
92
- }
93
- }
94
- }
95
- return "";
96
- }
97
- export function getPath(root, obj) {
98
- if (root === obj) {
99
- return "/";
100
- }
101
- const path = _getPathRecursive(root, obj);
102
- if (path === "") {
103
- throw new Error("Object not found in root");
104
- }
105
- return `/${path}`;
106
- }
107
- /**
108
- * Recursively checks whether an object has any undefined values inside.
109
- */
110
- export function hasUndefined(obj) {
111
- if (obj === undefined) {
112
- return true;
113
- }
114
- if (obj) {
115
- if (Array.isArray(obj)) {
116
- for (let i = 0, len = obj.length; i < len; i++) {
117
- if (hasUndefined(obj[i])) {
118
- return true;
119
- }
120
- }
121
- }
122
- else if (typeof obj === "object") {
123
- const objKeys = _objectKeys(obj);
124
- const objKeysLength = objKeys.length;
125
- for (var i = 0; i < objKeysLength; i++) {
126
- if (hasUndefined(obj[objKeys[i]])) {
127
- return true;
128
- }
129
- }
130
- }
131
- }
132
- return false;
133
- }
134
- function patchErrorMessageFormatter(message, args) {
135
- const messageParts = [message];
136
- for (const key in args) {
137
- const value = typeof args[key] === "object"
138
- ? JSON.stringify(args[key], null, 2)
139
- : args[key]; // pretty print
140
- if (typeof value !== "undefined") {
141
- messageParts.push(`${key}: ${value}`);
142
- }
143
- }
144
- return messageParts.join("\n");
145
- }
146
- export class PatchError extends Error {
147
- constructor(message, name, index, operation, tree) {
148
- super(patchErrorMessageFormatter(message, { name, index, operation, tree }));
149
- Object.defineProperty(this, "name", {
150
- enumerable: true,
151
- configurable: true,
152
- writable: true,
153
- value: name
154
- });
155
- Object.defineProperty(this, "index", {
156
- enumerable: true,
157
- configurable: true,
158
- writable: true,
159
- value: index
160
- });
161
- Object.defineProperty(this, "operation", {
162
- enumerable: true,
163
- configurable: true,
164
- writable: true,
165
- value: operation
166
- });
167
- Object.defineProperty(this, "tree", {
168
- enumerable: true,
169
- configurable: true,
170
- writable: true,
171
- value: tree
172
- });
173
- Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
174
- this.message = patchErrorMessageFormatter(message, {
175
- name,
176
- index,
177
- operation,
178
- tree,
179
- });
180
- }
181
- }
@@ -1,358 +0,0 @@
1
- // @ts-nocheck
2
- // Inlined to deal with portability issues with importing crypto module
3
- /*
4
- * [js-sha1]{@link https://github.com/emn178/js-sha1}
5
- *
6
- * @version 0.6.0
7
- * @author Chen, Yi-Cyuan [emn178@gmail.com]
8
- * @copyright Chen, Yi-Cyuan 2014-2017
9
- * @license MIT
10
- */
11
- /*jslint bitwise: true */
12
- "use strict";
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.insecureHash = void 0;
15
- var root = typeof window === "object" ? window : {};
16
- var HEX_CHARS = "0123456789abcdef".split("");
17
- var EXTRA = [-2147483648, 8388608, 32768, 128];
18
- var SHIFT = [24, 16, 8, 0];
19
- var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"];
20
- var blocks = [];
21
- function Sha1(sharedMemory) {
22
- if (sharedMemory) {
23
- blocks[0] =
24
- blocks[16] =
25
- blocks[1] =
26
- blocks[2] =
27
- blocks[3] =
28
- blocks[4] =
29
- blocks[5] =
30
- blocks[6] =
31
- blocks[7] =
32
- blocks[8] =
33
- blocks[9] =
34
- blocks[10] =
35
- blocks[11] =
36
- blocks[12] =
37
- blocks[13] =
38
- blocks[14] =
39
- blocks[15] =
40
- 0;
41
- this.blocks = blocks;
42
- }
43
- else {
44
- this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
45
- }
46
- this.h0 = 0x67452301;
47
- this.h1 = 0xefcdab89;
48
- this.h2 = 0x98badcfe;
49
- this.h3 = 0x10325476;
50
- this.h4 = 0xc3d2e1f0;
51
- this.block = this.start = this.bytes = this.hBytes = 0;
52
- this.finalized = this.hashed = false;
53
- this.first = true;
54
- }
55
- Sha1.prototype.update = function (message) {
56
- if (this.finalized) {
57
- return;
58
- }
59
- var notString = typeof message !== "string";
60
- if (notString && message.constructor === root.ArrayBuffer) {
61
- message = new Uint8Array(message);
62
- }
63
- var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
64
- while (index < length) {
65
- if (this.hashed) {
66
- this.hashed = false;
67
- blocks[0] = this.block;
68
- blocks[16] =
69
- blocks[1] =
70
- blocks[2] =
71
- blocks[3] =
72
- blocks[4] =
73
- blocks[5] =
74
- blocks[6] =
75
- blocks[7] =
76
- blocks[8] =
77
- blocks[9] =
78
- blocks[10] =
79
- blocks[11] =
80
- blocks[12] =
81
- blocks[13] =
82
- blocks[14] =
83
- blocks[15] =
84
- 0;
85
- }
86
- if (notString) {
87
- for (i = this.start; index < length && i < 64; ++index) {
88
- blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
89
- }
90
- }
91
- else {
92
- for (i = this.start; index < length && i < 64; ++index) {
93
- code = message.charCodeAt(index);
94
- if (code < 0x80) {
95
- blocks[i >> 2] |= code << SHIFT[i++ & 3];
96
- }
97
- else if (code < 0x800) {
98
- blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
99
- blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
100
- }
101
- else if (code < 0xd800 || code >= 0xe000) {
102
- blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
103
- blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
104
- blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
105
- }
106
- else {
107
- code =
108
- 0x10000 +
109
- (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
110
- blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
111
- blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
112
- blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
113
- blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
114
- }
115
- }
116
- }
117
- this.lastByteIndex = i;
118
- this.bytes += i - this.start;
119
- if (i >= 64) {
120
- this.block = blocks[16];
121
- this.start = i - 64;
122
- this.hash();
123
- this.hashed = true;
124
- }
125
- else {
126
- this.start = i;
127
- }
128
- }
129
- if (this.bytes > 4294967295) {
130
- this.hBytes += (this.bytes / 4294967296) << 0;
131
- this.bytes = this.bytes % 4294967296;
132
- }
133
- return this;
134
- };
135
- Sha1.prototype.finalize = function () {
136
- if (this.finalized) {
137
- return;
138
- }
139
- this.finalized = true;
140
- var blocks = this.blocks, i = this.lastByteIndex;
141
- blocks[16] = this.block;
142
- blocks[i >> 2] |= EXTRA[i & 3];
143
- this.block = blocks[16];
144
- if (i >= 56) {
145
- if (!this.hashed) {
146
- this.hash();
147
- }
148
- blocks[0] = this.block;
149
- blocks[16] =
150
- blocks[1] =
151
- blocks[2] =
152
- blocks[3] =
153
- blocks[4] =
154
- blocks[5] =
155
- blocks[6] =
156
- blocks[7] =
157
- blocks[8] =
158
- blocks[9] =
159
- blocks[10] =
160
- blocks[11] =
161
- blocks[12] =
162
- blocks[13] =
163
- blocks[14] =
164
- blocks[15] =
165
- 0;
166
- }
167
- blocks[14] = (this.hBytes << 3) | (this.bytes >>> 29);
168
- blocks[15] = this.bytes << 3;
169
- this.hash();
170
- };
171
- Sha1.prototype.hash = function () {
172
- var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4;
173
- var f, j, t, blocks = this.blocks;
174
- for (j = 16; j < 80; ++j) {
175
- t = blocks[j - 3] ^ blocks[j - 8] ^ blocks[j - 14] ^ blocks[j - 16];
176
- blocks[j] = (t << 1) | (t >>> 31);
177
- }
178
- for (j = 0; j < 20; j += 5) {
179
- f = (b & c) | (~b & d);
180
- t = (a << 5) | (a >>> 27);
181
- e = (t + f + e + 1518500249 + blocks[j]) << 0;
182
- b = (b << 30) | (b >>> 2);
183
- f = (a & b) | (~a & c);
184
- t = (e << 5) | (e >>> 27);
185
- d = (t + f + d + 1518500249 + blocks[j + 1]) << 0;
186
- a = (a << 30) | (a >>> 2);
187
- f = (e & a) | (~e & b);
188
- t = (d << 5) | (d >>> 27);
189
- c = (t + f + c + 1518500249 + blocks[j + 2]) << 0;
190
- e = (e << 30) | (e >>> 2);
191
- f = (d & e) | (~d & a);
192
- t = (c << 5) | (c >>> 27);
193
- b = (t + f + b + 1518500249 + blocks[j + 3]) << 0;
194
- d = (d << 30) | (d >>> 2);
195
- f = (c & d) | (~c & e);
196
- t = (b << 5) | (b >>> 27);
197
- a = (t + f + a + 1518500249 + blocks[j + 4]) << 0;
198
- c = (c << 30) | (c >>> 2);
199
- }
200
- for (; j < 40; j += 5) {
201
- f = b ^ c ^ d;
202
- t = (a << 5) | (a >>> 27);
203
- e = (t + f + e + 1859775393 + blocks[j]) << 0;
204
- b = (b << 30) | (b >>> 2);
205
- f = a ^ b ^ c;
206
- t = (e << 5) | (e >>> 27);
207
- d = (t + f + d + 1859775393 + blocks[j + 1]) << 0;
208
- a = (a << 30) | (a >>> 2);
209
- f = e ^ a ^ b;
210
- t = (d << 5) | (d >>> 27);
211
- c = (t + f + c + 1859775393 + blocks[j + 2]) << 0;
212
- e = (e << 30) | (e >>> 2);
213
- f = d ^ e ^ a;
214
- t = (c << 5) | (c >>> 27);
215
- b = (t + f + b + 1859775393 + blocks[j + 3]) << 0;
216
- d = (d << 30) | (d >>> 2);
217
- f = c ^ d ^ e;
218
- t = (b << 5) | (b >>> 27);
219
- a = (t + f + a + 1859775393 + blocks[j + 4]) << 0;
220
- c = (c << 30) | (c >>> 2);
221
- }
222
- for (; j < 60; j += 5) {
223
- f = (b & c) | (b & d) | (c & d);
224
- t = (a << 5) | (a >>> 27);
225
- e = (t + f + e - 1894007588 + blocks[j]) << 0;
226
- b = (b << 30) | (b >>> 2);
227
- f = (a & b) | (a & c) | (b & c);
228
- t = (e << 5) | (e >>> 27);
229
- d = (t + f + d - 1894007588 + blocks[j + 1]) << 0;
230
- a = (a << 30) | (a >>> 2);
231
- f = (e & a) | (e & b) | (a & b);
232
- t = (d << 5) | (d >>> 27);
233
- c = (t + f + c - 1894007588 + blocks[j + 2]) << 0;
234
- e = (e << 30) | (e >>> 2);
235
- f = (d & e) | (d & a) | (e & a);
236
- t = (c << 5) | (c >>> 27);
237
- b = (t + f + b - 1894007588 + blocks[j + 3]) << 0;
238
- d = (d << 30) | (d >>> 2);
239
- f = (c & d) | (c & e) | (d & e);
240
- t = (b << 5) | (b >>> 27);
241
- a = (t + f + a - 1894007588 + blocks[j + 4]) << 0;
242
- c = (c << 30) | (c >>> 2);
243
- }
244
- for (; j < 80; j += 5) {
245
- f = b ^ c ^ d;
246
- t = (a << 5) | (a >>> 27);
247
- e = (t + f + e - 899497514 + blocks[j]) << 0;
248
- b = (b << 30) | (b >>> 2);
249
- f = a ^ b ^ c;
250
- t = (e << 5) | (e >>> 27);
251
- d = (t + f + d - 899497514 + blocks[j + 1]) << 0;
252
- a = (a << 30) | (a >>> 2);
253
- f = e ^ a ^ b;
254
- t = (d << 5) | (d >>> 27);
255
- c = (t + f + c - 899497514 + blocks[j + 2]) << 0;
256
- e = (e << 30) | (e >>> 2);
257
- f = d ^ e ^ a;
258
- t = (c << 5) | (c >>> 27);
259
- b = (t + f + b - 899497514 + blocks[j + 3]) << 0;
260
- d = (d << 30) | (d >>> 2);
261
- f = c ^ d ^ e;
262
- t = (b << 5) | (b >>> 27);
263
- a = (t + f + a - 899497514 + blocks[j + 4]) << 0;
264
- c = (c << 30) | (c >>> 2);
265
- }
266
- this.h0 = (this.h0 + a) << 0;
267
- this.h1 = (this.h1 + b) << 0;
268
- this.h2 = (this.h2 + c) << 0;
269
- this.h3 = (this.h3 + d) << 0;
270
- this.h4 = (this.h4 + e) << 0;
271
- };
272
- Sha1.prototype.hex = function () {
273
- this.finalize();
274
- var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4;
275
- return (HEX_CHARS[(h0 >> 28) & 0x0f] +
276
- HEX_CHARS[(h0 >> 24) & 0x0f] +
277
- HEX_CHARS[(h0 >> 20) & 0x0f] +
278
- HEX_CHARS[(h0 >> 16) & 0x0f] +
279
- HEX_CHARS[(h0 >> 12) & 0x0f] +
280
- HEX_CHARS[(h0 >> 8) & 0x0f] +
281
- HEX_CHARS[(h0 >> 4) & 0x0f] +
282
- HEX_CHARS[h0 & 0x0f] +
283
- HEX_CHARS[(h1 >> 28) & 0x0f] +
284
- HEX_CHARS[(h1 >> 24) & 0x0f] +
285
- HEX_CHARS[(h1 >> 20) & 0x0f] +
286
- HEX_CHARS[(h1 >> 16) & 0x0f] +
287
- HEX_CHARS[(h1 >> 12) & 0x0f] +
288
- HEX_CHARS[(h1 >> 8) & 0x0f] +
289
- HEX_CHARS[(h1 >> 4) & 0x0f] +
290
- HEX_CHARS[h1 & 0x0f] +
291
- HEX_CHARS[(h2 >> 28) & 0x0f] +
292
- HEX_CHARS[(h2 >> 24) & 0x0f] +
293
- HEX_CHARS[(h2 >> 20) & 0x0f] +
294
- HEX_CHARS[(h2 >> 16) & 0x0f] +
295
- HEX_CHARS[(h2 >> 12) & 0x0f] +
296
- HEX_CHARS[(h2 >> 8) & 0x0f] +
297
- HEX_CHARS[(h2 >> 4) & 0x0f] +
298
- HEX_CHARS[h2 & 0x0f] +
299
- HEX_CHARS[(h3 >> 28) & 0x0f] +
300
- HEX_CHARS[(h3 >> 24) & 0x0f] +
301
- HEX_CHARS[(h3 >> 20) & 0x0f] +
302
- HEX_CHARS[(h3 >> 16) & 0x0f] +
303
- HEX_CHARS[(h3 >> 12) & 0x0f] +
304
- HEX_CHARS[(h3 >> 8) & 0x0f] +
305
- HEX_CHARS[(h3 >> 4) & 0x0f] +
306
- HEX_CHARS[h3 & 0x0f] +
307
- HEX_CHARS[(h4 >> 28) & 0x0f] +
308
- HEX_CHARS[(h4 >> 24) & 0x0f] +
309
- HEX_CHARS[(h4 >> 20) & 0x0f] +
310
- HEX_CHARS[(h4 >> 16) & 0x0f] +
311
- HEX_CHARS[(h4 >> 12) & 0x0f] +
312
- HEX_CHARS[(h4 >> 8) & 0x0f] +
313
- HEX_CHARS[(h4 >> 4) & 0x0f] +
314
- HEX_CHARS[h4 & 0x0f]);
315
- };
316
- Sha1.prototype.toString = Sha1.prototype.hex;
317
- Sha1.prototype.digest = function () {
318
- this.finalize();
319
- var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4;
320
- return [
321
- (h0 >> 24) & 0xff,
322
- (h0 >> 16) & 0xff,
323
- (h0 >> 8) & 0xff,
324
- h0 & 0xff,
325
- (h1 >> 24) & 0xff,
326
- (h1 >> 16) & 0xff,
327
- (h1 >> 8) & 0xff,
328
- h1 & 0xff,
329
- (h2 >> 24) & 0xff,
330
- (h2 >> 16) & 0xff,
331
- (h2 >> 8) & 0xff,
332
- h2 & 0xff,
333
- (h3 >> 24) & 0xff,
334
- (h3 >> 16) & 0xff,
335
- (h3 >> 8) & 0xff,
336
- h3 & 0xff,
337
- (h4 >> 24) & 0xff,
338
- (h4 >> 16) & 0xff,
339
- (h4 >> 8) & 0xff,
340
- h4 & 0xff,
341
- ];
342
- };
343
- Sha1.prototype.array = Sha1.prototype.digest;
344
- Sha1.prototype.arrayBuffer = function () {
345
- this.finalize();
346
- var buffer = new ArrayBuffer(20);
347
- var dataView = new DataView(buffer);
348
- dataView.setUint32(0, this.h0);
349
- dataView.setUint32(4, this.h1);
350
- dataView.setUint32(8, this.h2);
351
- dataView.setUint32(12, this.h3);
352
- dataView.setUint32(16, this.h4);
353
- return buffer;
354
- };
355
- const insecureHash = (message) => {
356
- return new Sha1(true).update(message)["hex"]();
357
- };
358
- exports.insecureHash = insecureHash;
@@ -1 +0,0 @@
1
- export declare const insecureHash: (message: any) => any;