ranuts 0.1.0-alpha → 0.1.0-alpha-22
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 +21 -0
- package/dist/build/build.es.d.ts +2 -0
- package/dist/build/build.umd.d.ts +2 -0
- package/dist/build/build.umd.ml.d.ts +2 -0
- package/dist/build/build.umd.node.d.ts +2 -0
- package/dist/build/build.umd.react.d.ts +2 -0
- package/dist/build/build.umd.utils.d.ts +2 -0
- package/dist/build/build.umd.wasm.d.ts +2 -0
- package/dist/color-48RIDBG4.js +82262 -0
- package/dist/examples/clone-deep-example.d.ts +1 -0
- package/dist/examples/is-equal-example.d.ts +1 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.js +151 -84
- package/dist/plugins/vite-plugins-banner.d.ts +2 -0
- package/dist/reactify-Z-V9Vblb.js +83 -0
- package/dist/src/arithmetic/index.d.ts +186 -0
- package/dist/src/cache/expires.d.ts +1 -0
- package/dist/src/ml/index.d.ts +2 -0
- package/dist/src/ml/index.js +1243 -0
- package/dist/src/ml/ocr.d.ts +11 -0
- package/dist/src/node/appendFile.d.ts +7 -0
- package/dist/src/node/body.d.ts +9 -0
- package/dist/src/node/color.d.ts +7 -0
- package/dist/src/node/command.d.ts +8 -0
- package/dist/src/node/ctx2req.d.ts +5 -0
- package/dist/src/node/fileInfo.d.ts +7 -0
- package/dist/src/node/fs.d.ts +7 -0
- package/dist/src/node/get.d.ts +10 -0
- package/dist/src/node/getIPAdress.d.ts +1 -0
- package/dist/src/node/index.d.ts +25 -0
- package/dist/src/node/index.js +54 -0
- package/dist/src/node/isColorSupported.d.ts +2 -0
- package/dist/src/node/paresUrl.d.ts +19 -0
- package/dist/src/node/readDir.d.ts +6 -0
- package/dist/src/node/readFile.d.ts +9 -0
- package/dist/src/node/router.d.ts +42 -0
- package/dist/src/node/send.d.ts +7 -0
- package/dist/src/node/server.d.ts +18 -0
- package/dist/src/node/startTask.d.ts +2 -0
- package/dist/src/node/stream.d.ts +15 -0
- package/dist/src/node/taskEnd.d.ts +2 -0
- package/dist/src/node/traverse.d.ts +17 -0
- package/dist/src/node/watchFile.d.ts +8 -0
- package/dist/src/node/websocket.d.ts +57 -0
- package/dist/src/node/writeFile.d.ts +8 -0
- package/dist/src/node/ws.d.ts +8 -0
- package/dist/src/optimize/index.d.ts +36 -0
- package/dist/src/optimize/promise.d.ts +0 -0
- package/dist/src/ran/commit.d.ts +0 -0
- package/dist/src/ran/dom.d.ts +0 -0
- package/dist/src/ran/hooks.d.ts +0 -0
- package/dist/src/ran/index.d.ts +20 -0
- package/dist/src/ran/min.d.ts +32 -0
- package/dist/src/ran/reconcile.d.ts +0 -0
- package/dist/src/ran/schedule.d.ts +0 -0
- package/dist/src/react/index.d.ts +2 -0
- package/dist/src/react/index.js +4 -0
- package/dist/src/react/reactify.d.ts +2 -0
- package/dist/src/sort/bubble.d.ts +7 -0
- package/dist/src/sort/bucket.d.ts +7 -0
- package/dist/src/sort/count.d.ts +7 -0
- package/dist/src/sort/heap.d.ts +7 -0
- package/dist/src/sort/index.d.ts +0 -0
- package/dist/src/sort/insert.d.ts +7 -0
- package/dist/src/sort/merge.d.ts +7 -0
- package/dist/src/sort/quick.d.ts +7 -0
- package/dist/src/sort/radix.d.ts +7 -0
- package/dist/src/sort/randomArray.d.ts +9 -0
- package/dist/src/sort/select.d.ts +7 -0
- package/dist/src/sort/shell.d.ts +7 -0
- package/dist/src/utils/audioRecorder.d.ts +16 -0
- package/dist/src/utils/behavior.d.ts +15 -0
- package/dist/src/utils/bom.d.ts +230 -0
- package/dist/src/utils/color.d.ts +71 -0
- package/dist/src/utils/compose.d.ts +10 -0
- package/dist/src/utils/console.d.ts +1 -0
- package/dist/src/utils/debounce.d.ts +7 -0
- package/dist/src/utils/device.d.ts +25 -0
- package/dist/src/utils/dom.d.ts +105 -0
- package/dist/src/utils/error.d.ts +1 -0
- package/dist/src/utils/func.d.ts +1 -0
- package/dist/src/utils/img.d.ts +16 -0
- package/dist/src/utils/index.d.ts +35 -0
- package/dist/src/utils/index.js +4551 -0
- package/dist/src/utils/memoize.d.ts +7 -0
- package/dist/src/utils/mimeType.d.ts +9 -0
- package/dist/src/utils/monitor.d.ts +38 -0
- package/dist/src/utils/network.d.ts +39 -0
- package/dist/src/utils/noop.d.ts +2 -0
- package/dist/src/utils/number.d.ts +45 -0
- package/dist/src/utils/obj.d.ts +83 -0
- package/dist/src/utils/performance.d.ts +21 -0
- package/dist/src/utils/queue.d.ts +33 -0
- package/dist/src/utils/report.d.ts +8 -0
- package/dist/src/utils/request.d.ts +17 -0
- package/dist/src/utils/script.d.ts +7 -0
- package/dist/src/utils/signal.d.ts +6 -0
- package/dist/src/utils/storage.d.ts +2 -0
- package/dist/src/utils/str.d.ts +212 -0
- package/dist/src/utils/subscribe.d.ts +46 -0
- package/dist/src/utils/throttle.d.ts +15 -0
- package/dist/src/utils/time.d.ts +20 -0
- package/dist/src/utils/totp/sha/common.d.ts +151 -0
- package/dist/src/utils/totp/sha/converters.d.ts +88 -0
- package/dist/src/utils/totp/sha/custom_types.d.ts +60 -0
- package/dist/src/utils/totp/sha/primitives_32.d.ts +98 -0
- package/dist/src/utils/totp/sha/primitives_64.d.ts +116 -0
- package/dist/src/utils/totp/sha/sha.d.ts +103 -0
- package/dist/src/utils/totp/sha/sha1.d.ts +18 -0
- package/dist/src/utils/totp/sha/sha256.d.ts +20 -0
- package/dist/src/utils/totp/sha/sha3.d.ts +53 -0
- package/dist/src/utils/totp/sha/sha512.d.ts +21 -0
- package/dist/src/utils/totp/totp.d.ts +23 -0
- package/dist/src/utils/visual/application.d.ts +14 -0
- package/dist/src/utils/visual/demo/index.d.ts +1 -0
- package/dist/src/utils/visual/demo/sankey.d.ts +2 -0
- package/dist/src/utils/visual/enums.d.ts +27 -0
- package/dist/src/utils/visual/event/boundary.d.ts +22 -0
- package/dist/src/utils/visual/event/event.d.ts +14 -0
- package/dist/src/utils/visual/event/index.d.ts +6 -0
- package/dist/src/utils/visual/event/types.d.ts +32 -0
- package/dist/src/utils/visual/graphics/graphics.d.ts +81 -0
- package/dist/src/utils/visual/graphics/graphicsData.d.ts +13 -0
- package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +35 -0
- package/dist/src/utils/visual/graphics/index.d.ts +4 -0
- package/dist/src/utils/visual/index.d.ts +7 -0
- package/dist/src/utils/visual/math/bezier.d.ts +2 -0
- package/dist/src/utils/visual/math/enums.d.ts +3 -0
- package/dist/src/utils/visual/math/index.d.ts +5 -0
- package/dist/src/utils/visual/math/matrix.d.ts +113 -0
- package/dist/src/utils/visual/math/transform.d.ts +29 -0
- package/dist/src/utils/visual/render/batchRenderer.d.ts +72 -0
- package/dist/src/utils/visual/render/canvasRenderer.d.ts +10 -0
- package/dist/src/utils/visual/render/index.d.ts +3 -0
- package/dist/src/utils/visual/render/render.d.ts +15 -0
- package/dist/src/utils/visual/render/utils/batch/index.d.ts +90 -0
- package/dist/src/utils/visual/render/utils/float.d.ts +63 -0
- package/dist/src/utils/visual/render/utils/index.d.ts +3 -0
- package/dist/src/utils/visual/render/utils/verticy.d.ts +13 -0
- package/dist/src/utils/visual/render/utils/webgl/batchPool.d.ts +28 -0
- package/dist/src/utils/visual/render/utils/webgl/initShader.d.ts +2 -0
- package/dist/src/utils/visual/render/utils/webgl/shaders.d.ts +2 -0
- package/dist/src/utils/visual/render/utils/webgpu/shaders.d.ts +8 -0
- package/dist/src/utils/visual/render/webGPURenderer.d.ts +49 -0
- package/dist/src/utils/visual/render/webGlRenderer.d.ts +17 -0
- package/dist/src/utils/visual/shape/circle.d.ts +11 -0
- package/dist/src/utils/visual/shape/ellipse.d.ts +12 -0
- package/dist/src/utils/visual/shape/index.d.ts +7 -0
- package/dist/src/utils/visual/shape/polygon.d.ts +11 -0
- package/dist/src/utils/visual/shape/rectangle.d.ts +12 -0
- package/dist/src/utils/visual/shape/roundedRectangle.d.ts +13 -0
- package/dist/src/utils/visual/shape/shape.d.ts +6 -0
- package/dist/src/utils/visual/style/fill.d.ts +8 -0
- package/dist/src/utils/visual/style/index.d.ts +3 -0
- package/dist/src/utils/visual/style/line.d.ts +10 -0
- package/dist/src/utils/visual/types.d.ts +17 -0
- package/dist/src/utils/visual/vertex/container.d.ts +73 -0
- package/dist/src/utils/visual/vertex/index.d.ts +5 -0
- package/dist/src/utils/visual/vertex/point.d.ts +18 -0
- package/dist/src/utils/visual/vertex/vertex.d.ts +36 -0
- package/dist/src/vnode/chainDom.d.ts +47 -0
- package/dist/src/vnode/h.d.ts +6 -0
- package/dist/src/vnode/hooks.d.ts +23 -0
- package/dist/src/vnode/htmlDomApi.d.ts +33 -0
- package/dist/src/vnode/init.d.ts +2 -0
- package/dist/src/vnode/is.d.ts +5 -0
- package/dist/src/vnode/modules/attributes.d.ts +8 -0
- package/dist/src/vnode/modules/class.d.ts +8 -0
- package/dist/src/vnode/modules/index.d.ts +3 -0
- package/dist/src/vnode/modules/listeners.d.ts +12 -0
- package/dist/src/vnode/modules/props.d.ts +8 -0
- package/dist/src/vnode/modules/style.d.ts +14 -0
- package/dist/src/vnode/vnode.d.ts +31 -0
- package/dist/src/wasm/index.d.ts +2 -0
- package/dist/src/wasm/index.js +346 -0
- package/dist/src/wasm/word.d.ts +17 -0
- package/dist/src/wicket/bridge.d.ts +4 -0
- package/dist/src/wicket/index.d.ts +29 -0
- package/dist/test/arithmetic.test.d.ts +1 -0
- package/dist/test/cloneDeep.test.d.ts +1 -0
- package/dist/test/encodeUrl.test.d.ts +1 -0
- package/dist/test/escapeHtml.test.d.ts +1 -0
- package/dist/test/is-equal.test.d.ts +1 -0
- package/dist/test/mimeType.test.d.ts +1 -0
- package/dist/test/server.test.d.ts +1 -0
- package/dist/test/sort.test.d.ts +1 -0
- package/dist/test/status.test.d.ts +1 -0
- package/dist/test/totp.test.d.ts +1 -0
- package/dist/test/utils/compose.test.d.ts +1 -0
- package/dist/test/utils/mergeObj.test.d.ts +1 -0
- package/dist/test/utils/ocr.test.d.ts +1 -0
- package/dist/test/visual/math.test.d.ts +1 -0
- package/dist/test/vnode/index.d.ts +1 -0
- package/dist/test/vnode/server.d.ts +2 -0
- package/dist/test/vnode/vnode.d.ts +1 -0
- package/dist/test/websocket.test.d.ts +1 -0
- package/dist/test/writeFile.test.d.ts +1 -0
- package/dist/umd/index.umd.cjs +1 -0
- package/dist/umd/ml/ml.umd.cjs +1 -0
- package/dist/umd/node/node.umd.cjs +1 -0
- package/dist/umd/react/react.umd.cjs +1 -0
- package/dist/umd/utils/utils.umd.cjs +1 -0
- package/dist/umd/wasm/wasm.umd.cjs +1 -0
- package/dist/vite.config.d.ts +11 -0
- package/dist/ws-CUTzWNwq.js +703 -0
- package/package.json +70 -13
- package/readme.md +91 -0
- package/typings.d.ts +28 -0
- package/dist/index.js.map +0 -1
- package/dist/index.umd.cjs +0 -2
- package/dist/index.umd.cjs.map +0 -1
|
@@ -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;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Int_64 is a object for 2 32-bit numbers emulating a 64-bit number.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Int_64 {
|
|
5
|
+
/**
|
|
6
|
+
* @param msint_32 The most significant 32-bits of a 64-bit number.
|
|
7
|
+
* @param lsint_32 The least significant 32-bits of a 64-bit number.
|
|
8
|
+
*/
|
|
9
|
+
readonly highOrder: number;
|
|
10
|
+
readonly lowOrder: number;
|
|
11
|
+
constructor(msint_32: number, lsint_32: number);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The 64-bit implementation of circular rotate left.
|
|
15
|
+
*
|
|
16
|
+
* This does not work for n >= 64 or n == 32 but those are never done.
|
|
17
|
+
*
|
|
18
|
+
* @param x The 64-bit integer argument.
|
|
19
|
+
* @param n The number of bits to shift.
|
|
20
|
+
* @returns `x` shifted left circularly by `n` bits.
|
|
21
|
+
*/
|
|
22
|
+
export declare function rotl_64(x: Int_64, n: number): Int_64;
|
|
23
|
+
/**
|
|
24
|
+
* The 64-bit implementation of the NIST specified Ch function.
|
|
25
|
+
*
|
|
26
|
+
* @param x The first 64-bit integer argument.
|
|
27
|
+
* @param y The second 64-bit integer argument.
|
|
28
|
+
* @param z The third 64-bit integer argument.
|
|
29
|
+
* @returns The NIST specified output of the function.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ch_64(x: Int_64, y: Int_64, z: Int_64): Int_64;
|
|
32
|
+
/**
|
|
33
|
+
* The 64-bit implementation of the NIST specified Maj function.
|
|
34
|
+
*
|
|
35
|
+
* @param x The first 64-bit integer argument.
|
|
36
|
+
* @param y The second 64-bit integer argument.
|
|
37
|
+
* @param z The third 64-bit integer argument.
|
|
38
|
+
* @returns The NIST specified output of the function.
|
|
39
|
+
*/
|
|
40
|
+
export declare function maj_64(x: Int_64, y: Int_64, z: Int_64): Int_64;
|
|
41
|
+
/**
|
|
42
|
+
* The 64-bit implementation of the NIST specified Sigma0 function.
|
|
43
|
+
*
|
|
44
|
+
* @param x The 64-bit integer argument.
|
|
45
|
+
* @returns The NIST specified output of the function.
|
|
46
|
+
*/
|
|
47
|
+
export declare function sigma0_64(x: Int_64): Int_64;
|
|
48
|
+
/**
|
|
49
|
+
* Add two 64-bit integers.
|
|
50
|
+
*
|
|
51
|
+
* @param x The first 64-bit integer argument to be added.
|
|
52
|
+
* @param y The second 64-bit integer argument to be added.
|
|
53
|
+
* @returns The sum of `x` + `y`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function safeAdd_64_2(x: Int_64, y: Int_64): Int_64;
|
|
56
|
+
/**
|
|
57
|
+
* Add four 64-bit integers.
|
|
58
|
+
*
|
|
59
|
+
* @param a The first 64-bit integer argument to be added.
|
|
60
|
+
* @param b The second 64-bit integer argument to be added.
|
|
61
|
+
* @param c The third 64-bit integer argument to be added.
|
|
62
|
+
* @param d The fouth 64-bit integer argument to be added.
|
|
63
|
+
* @returns The sum of `a` + `b` + `c` + `d`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function safeAdd_64_4(a: Int_64, b: Int_64, c: Int_64, d: Int_64): Int_64;
|
|
66
|
+
/**
|
|
67
|
+
* Add five 64-bit integers.
|
|
68
|
+
*
|
|
69
|
+
* @param a The first 64-bit integer argument to be added.
|
|
70
|
+
* @param b The second 64-bit integer argument to be added.
|
|
71
|
+
* @param c The third 64-bit integer argument to be added.
|
|
72
|
+
* @param d The fouth 64-bit integer argument to be added.
|
|
73
|
+
* @param e The fifth 64-bit integer argument to be added.
|
|
74
|
+
* @returns The sum of `a` + `b` + `c` + `d` + `e`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function safeAdd_64_5(a: Int_64, b: Int_64, c: Int_64, d: Int_64, e: Int_64): Int_64;
|
|
77
|
+
/**
|
|
78
|
+
* XORs two given arguments.
|
|
79
|
+
*
|
|
80
|
+
* @param a The first argument to be XORed.
|
|
81
|
+
* @param b The second argument to be XORed.
|
|
82
|
+
* @returns The The XOR `a` and `b`
|
|
83
|
+
*/
|
|
84
|
+
export declare function xor_64_2(a: Int_64, b: Int_64): Int_64;
|
|
85
|
+
/**
|
|
86
|
+
* XORs five given arguments.
|
|
87
|
+
*
|
|
88
|
+
* @param a The first argument to be XORed.
|
|
89
|
+
* @param b The second argument to be XORed.
|
|
90
|
+
* @param c The third argument to be XORed.
|
|
91
|
+
* @param d The fourth argument to be XORed.
|
|
92
|
+
* @param e The fifth argument to be XORed.
|
|
93
|
+
* @returns The XOR of `a`, `b`, `c`, `d`, and `e`.
|
|
94
|
+
*/
|
|
95
|
+
export declare function xor_64_5(a: Int_64, b: Int_64, c: Int_64, d: Int_64, e: Int_64): Int_64;
|
|
96
|
+
/**
|
|
97
|
+
* The 64-bit implementation of the NIST specified Gamma1 function.
|
|
98
|
+
*
|
|
99
|
+
* @param x The 64-bit integer argument.
|
|
100
|
+
* @returns The NIST specified output of the function.
|
|
101
|
+
*/
|
|
102
|
+
export declare function gamma1_64(x: Int_64): Int_64;
|
|
103
|
+
/**
|
|
104
|
+
* The 64-bit implementation of the NIST specified Gamma0 function.
|
|
105
|
+
*
|
|
106
|
+
* @param x The 64-bit integer argument.
|
|
107
|
+
* @returns The NIST specified output of the function.
|
|
108
|
+
*/
|
|
109
|
+
export declare function gamma0_64(x: Int_64): Int_64;
|
|
110
|
+
/**
|
|
111
|
+
* The 64-bit implementation of the NIST specified Sigma1 function.
|
|
112
|
+
*
|
|
113
|
+
* @param x The 64-bit integer argument.
|
|
114
|
+
* @returns The NIST specified output of the function.
|
|
115
|
+
*/
|
|
116
|
+
export declare function sigma1_64(x: Int_64): Int_64;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { CSHAKEOptionsEncodingType, CSHAKEOptionsNoEncodingType, EncodingType, FixedLengthOptionsEncodingType, FixedLengthOptionsNoEncodingType, FormatNoTextType, KMACOptionsEncodingType, KMACOptionsNoEncodingType, SHAKEOptionsEncodingType, SHAKEOptionsNoEncodingType } from './custom_types';
|
|
2
|
+
type FixedLengthVariantType = 'SHA-1' | 'SHA-224' | 'SHA-256' | 'SHA-384' | 'SHA-512' | 'SHA3-224' | 'SHA3-256' | 'SHA3-384' | 'SHA3-512';
|
|
3
|
+
export default class jsSHA {
|
|
4
|
+
private readonly shaObj;
|
|
5
|
+
/**
|
|
6
|
+
* @param variant The desired SHA variant (SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA3-224, SHA3-256, SHA3-256,
|
|
7
|
+
* SHA3-384, SHA3-512, SHAKE128, SHAKE256, CSHAKE128, CSHAKE256, KMAC128, or KMAC256) as a string.
|
|
8
|
+
* @param inputFormat The input format to be used in future `update` calls (TEXT, HEX, B64, BYTES, ARRAYBUFFER,
|
|
9
|
+
* or UINT8ARRAY) as a string.
|
|
10
|
+
* @param options Options in the form of { encoding?: "UTF8" | "UTF16BE" | "UTF16LE"; numRounds?: number }.
|
|
11
|
+
* `encoding` is for only TEXT input (defaults to UTF8) and `numRounds` defaults to 1.
|
|
12
|
+
* `numRounds` is not valid for any of the MAC or CSHAKE variants.
|
|
13
|
+
* * If the variant supports HMAC, `options` may have an additional `hmacKey` key which must be in the form of
|
|
14
|
+
* {value: <INPUT>, format: <FORMAT>, encoding?: "UTF8" | "UTF16BE" | "UTF16LE"} where <FORMAT> takes the same
|
|
15
|
+
* values as `inputFormat` and <INPUT> can be a `string | ArrayBuffer | Uint8Array` depending on <FORMAT>.
|
|
16
|
+
* Supplying this key switches to HMAC calculation and replaces the now deprecated call to `setHMACKey`.
|
|
17
|
+
* * If the variant is CSHAKE128 or CSHAKE256, `options` may have two additional keys, `customization` and `funcName`,
|
|
18
|
+
* which are the NIST customization and function-name strings. Both must be in the same form as `hmacKey`.
|
|
19
|
+
* * If the variant is KMAC128 or KMAC256, `options` can include the `customization` key from CSHAKE variants and
|
|
20
|
+
* *must* have a `kmacKey` key that takes the same form as the `customization` key.
|
|
21
|
+
*/
|
|
22
|
+
constructor(variant: FixedLengthVariantType, inputFormat: 'TEXT', options?: FixedLengthOptionsEncodingType);
|
|
23
|
+
constructor(variant: FixedLengthVariantType, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);
|
|
24
|
+
constructor(variant: 'SHAKE128' | 'SHAKE256', inputFormat: 'TEXT', options?: SHAKEOptionsEncodingType);
|
|
25
|
+
constructor(variant: 'SHAKE128' | 'SHAKE256', inputFormat: FormatNoTextType, options?: SHAKEOptionsNoEncodingType);
|
|
26
|
+
constructor(variant: 'CSHAKE128' | 'CSHAKE256', inputFormat: 'TEXT', options?: CSHAKEOptionsEncodingType);
|
|
27
|
+
constructor(variant: 'CSHAKE128' | 'CSHAKE256', inputFormat: FormatNoTextType, options?: CSHAKEOptionsNoEncodingType);
|
|
28
|
+
constructor(variant: 'KMAC128' | 'KMAC256', inputFormat: 'TEXT', options: KMACOptionsEncodingType);
|
|
29
|
+
constructor(variant: 'KMAC128' | 'KMAC256', inputFormat: FormatNoTextType, options: KMACOptionsNoEncodingType);
|
|
30
|
+
/**
|
|
31
|
+
* Takes `input` and hashes as many blocks as possible. Stores the rest for either a future `update` or `getHash` call.
|
|
32
|
+
*
|
|
33
|
+
* @param input The input to be hashed.
|
|
34
|
+
* @returns A reference to the object.
|
|
35
|
+
*/
|
|
36
|
+
update(input: string | ArrayBuffer | Uint8Array): this;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the desired SHA or MAC (if a HMAC/KMAC key was specified) hash of the input fed in via `update` calls.
|
|
39
|
+
*
|
|
40
|
+
* @param format The desired output formatting (B64, HEX, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.
|
|
41
|
+
* @param options Options in the form of { outputUpper?: boolean; b64Pad?: string; outputLen?: number; }.
|
|
42
|
+
* `outputLen` is required for variable length output variants (this option was previously called `shakeLen` which
|
|
43
|
+
* is now deprecated).
|
|
44
|
+
* `outputUpper` is only for HEX output (defaults to false) and b64pad is only for B64 output (defaults to "=").
|
|
45
|
+
* @returns The hash in the format specified.
|
|
46
|
+
*/
|
|
47
|
+
getHash(format: 'HEX', options?: {
|
|
48
|
+
outputUpper?: boolean;
|
|
49
|
+
outputLen?: number;
|
|
50
|
+
shakeLen?: number;
|
|
51
|
+
}): string;
|
|
52
|
+
getHash(format: 'B64', options?: {
|
|
53
|
+
b64Pad?: string;
|
|
54
|
+
outputLen?: number;
|
|
55
|
+
shakeLen?: number;
|
|
56
|
+
}): string;
|
|
57
|
+
getHash(format: 'BYTES', options?: {
|
|
58
|
+
outputLen?: number;
|
|
59
|
+
shakeLen?: number;
|
|
60
|
+
}): string;
|
|
61
|
+
getHash(format: 'UINT8ARRAY', options?: {
|
|
62
|
+
outputLen?: number;
|
|
63
|
+
shakeLen?: number;
|
|
64
|
+
}): Uint8Array;
|
|
65
|
+
getHash(format: 'ARRAYBUFFER', options?: {
|
|
66
|
+
outputLen?: number;
|
|
67
|
+
shakeLen?: number;
|
|
68
|
+
}): ArrayBuffer;
|
|
69
|
+
/**
|
|
70
|
+
* Sets the HMAC key for an eventual `getHMAC` call. Must be called immediately after jsSHA object instantiation.
|
|
71
|
+
* Now deprecated in favor of setting the `hmacKey` at object instantiation.
|
|
72
|
+
*
|
|
73
|
+
* @param key The key used to calculate the HMAC
|
|
74
|
+
* @param inputFormat The format of key (HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.
|
|
75
|
+
* @param options Options in the form of { encoding?: "UTF8" | "UTF16BE" | "UTF16LE }. `encoding` is only for TEXT
|
|
76
|
+
* and defaults to UTF8.
|
|
77
|
+
*/
|
|
78
|
+
setHMACKey(key: string, inputFormat: 'TEXT', options?: {
|
|
79
|
+
encoding?: EncodingType;
|
|
80
|
+
}): void;
|
|
81
|
+
setHMACKey(key: string, inputFormat: 'B64' | 'HEX' | 'BYTES'): void;
|
|
82
|
+
setHMACKey(key: ArrayBuffer, inputFormat: 'ARRAYBUFFER'): void;
|
|
83
|
+
setHMACKey(key: Uint8Array, inputFormat: 'UINT8ARRAY'): void;
|
|
84
|
+
/**
|
|
85
|
+
* Returns the the HMAC in the specified format using the key given by a previous `setHMACKey` call. Now deprecated
|
|
86
|
+
* in favor of just calling `getHash`.
|
|
87
|
+
*
|
|
88
|
+
* @param format The desired output formatting (B64, HEX, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.
|
|
89
|
+
* @param options Options in the form of { outputUpper?: boolean; b64Pad?: string }. `outputUpper` is only for HEX
|
|
90
|
+
* output (defaults to false) and `b64pad` is only for B64 output (defaults to "=").
|
|
91
|
+
* @returns The HMAC in the format specified.
|
|
92
|
+
*/
|
|
93
|
+
getHMAC(format: 'HEX', options?: {
|
|
94
|
+
outputUpper?: boolean;
|
|
95
|
+
}): string;
|
|
96
|
+
getHMAC(format: 'B64', options?: {
|
|
97
|
+
b64Pad?: string;
|
|
98
|
+
}): string;
|
|
99
|
+
getHMAC(format: 'BYTES'): string;
|
|
100
|
+
getHMAC(format: 'UINT8ARRAY'): Uint8Array;
|
|
101
|
+
getHMAC(format: 'ARRAYBUFFER'): ArrayBuffer;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsSHABase } from './common';
|
|
2
|
+
import type { FixedLengthOptionsEncodingType, FixedLengthOptionsNoEncodingType, FormatNoTextType, packedValue } from './custom_types';
|
|
3
|
+
export default class jsSHA extends jsSHABase<number[], 'SHA-1'> {
|
|
4
|
+
intermediateState: number[];
|
|
5
|
+
variantBlockSize: number;
|
|
6
|
+
bigEndianMod: -1 | 1;
|
|
7
|
+
outputBinLen: number;
|
|
8
|
+
isVariableLen: boolean;
|
|
9
|
+
HMACSupported: boolean;
|
|
10
|
+
converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;
|
|
11
|
+
roundFunc: (block: number[], H: number[]) => number[];
|
|
12
|
+
finalizeFunc: (remainder: number[], remainderBinLen: number, processedBinLen: number, H: number[]) => number[];
|
|
13
|
+
stateCloneFunc: (state: number[]) => number[];
|
|
14
|
+
newStateFunc: (variant: 'SHA-1') => number[];
|
|
15
|
+
getMAC: () => number[];
|
|
16
|
+
constructor(variant: 'SHA-1', inputFormat: 'TEXT', options?: FixedLengthOptionsEncodingType);
|
|
17
|
+
constructor(variant: 'SHA-1', inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsSHABase } from './common';
|
|
2
|
+
import type { FixedLengthOptionsEncodingType, FixedLengthOptionsNoEncodingType, FormatNoTextType, packedValue } from './custom_types';
|
|
3
|
+
type VariantType = 'SHA-224' | 'SHA-256';
|
|
4
|
+
export default class jsSHA extends jsSHABase<number[], VariantType> {
|
|
5
|
+
intermediateState: number[];
|
|
6
|
+
variantBlockSize: number;
|
|
7
|
+
bigEndianMod: -1 | 1;
|
|
8
|
+
outputBinLen: number;
|
|
9
|
+
isVariableLen: boolean;
|
|
10
|
+
HMACSupported: boolean;
|
|
11
|
+
converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;
|
|
12
|
+
roundFunc: (block: number[], H: number[]) => number[];
|
|
13
|
+
finalizeFunc: (remainder: number[], remainderBinLen: number, processedBinLen: number, H: number[]) => number[];
|
|
14
|
+
stateCloneFunc: (state: number[]) => number[];
|
|
15
|
+
newStateFunc: (variant: VariantType) => number[];
|
|
16
|
+
getMAC: () => number[];
|
|
17
|
+
constructor(variant: VariantType, inputFormat: 'TEXT', options?: FixedLengthOptionsEncodingType);
|
|
18
|
+
constructor(variant: VariantType, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);
|
|
19
|
+
}
|
|
20
|
+
export {};
|