@wfrog/vc-ui 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -0
- package/dist/es/chunk/-EkpfdcW.mjs +1100 -0
- package/dist/es/chunk/8rLUmOVR.mjs +29 -0
- package/dist/es/chunk/B-rxnVJv.mjs +3 -0
- package/dist/es/chunk/BAGoDD49.mjs +36 -0
- package/dist/es/chunk/BAtns-Mc.mjs +96 -0
- package/dist/es/chunk/BJS5Pdfp.mjs +55 -0
- package/dist/es/chunk/BMzd-IS6.mjs +900 -0
- package/dist/es/chunk/BWcCXRRK.mjs +229 -0
- package/dist/es/chunk/BX-Ogf7p.mjs +3743 -0
- package/dist/es/chunk/B_tU9Nax.mjs +49 -0
- package/dist/es/chunk/BdDihk0t.mjs +3420 -0
- package/dist/es/chunk/C2LgraHx.mjs +489 -0
- package/dist/es/chunk/C5hWsUfD.mjs +64 -0
- package/dist/es/chunk/C7iSSBUr.mjs +303 -0
- package/dist/es/chunk/CD98REcR.mjs +666 -0
- package/dist/es/chunk/CEClY-_T.mjs +445 -0
- package/dist/es/chunk/CEm0brzD.mjs +35 -0
- package/dist/es/chunk/CMABHk8B.mjs +1942 -0
- package/dist/es/chunk/CS4VKsqy.mjs +19 -0
- package/dist/es/chunk/CVlj9F0I.mjs +291 -0
- package/dist/es/chunk/CZ4ggqDE.mjs +140 -0
- package/dist/es/chunk/CaTfZePA.mjs +533 -0
- package/dist/es/chunk/Ce9ApjrT.mjs +201 -0
- package/dist/es/chunk/ClZGuAIb.mjs +10 -0
- package/dist/es/chunk/Coex0GxM.mjs +450 -0
- package/dist/es/chunk/Ct6q2FXg.mjs +5 -0
- package/dist/es/chunk/CyxEcbcy.mjs +29 -0
- package/dist/es/chunk/D389hx_T.mjs +35 -0
- package/dist/es/chunk/D3DXeVfC.mjs +1171 -0
- package/dist/es/chunk/D3uV7vm-.mjs +45 -0
- package/dist/es/chunk/D5259bwd.mjs +50 -0
- package/dist/es/chunk/DMHNh_tw.mjs +49 -0
- package/dist/es/chunk/DVNTpOBR.mjs +4 -0
- package/dist/es/chunk/DZACQ9LT.mjs +95 -0
- package/dist/es/chunk/De_EXLIy.mjs +22 -0
- package/dist/es/chunk/Dh4jaUSg.mjs +89 -0
- package/dist/es/chunk/DhhdKtyu.mjs +439 -0
- package/dist/es/chunk/DqUIKX7f.mjs +2039 -0
- package/dist/es/chunk/Dqz1zvKN.mjs +59 -0
- package/dist/es/chunk/Dvi7RsXg.mjs +727 -0
- package/dist/es/chunk/DyDMGLoF.mjs +123 -0
- package/dist/es/chunk/E_WRn0OP.mjs +449 -0
- package/dist/es/chunk/Fo0dZYnz.mjs +128 -0
- package/dist/es/chunk/HSv8BL8o.mjs +72 -0
- package/dist/es/chunk/JCIyOUEY.mjs +105 -0
- package/dist/es/chunk/O-uhUKF4.mjs +43 -0
- package/dist/es/chunk/Spa-JKB4.mjs +1046 -0
- package/dist/es/chunk/VAdRxe-1.mjs +16 -0
- package/dist/es/chunk/VCrtRnxt.mjs +1477 -0
- package/dist/es/chunk/ViP2SEY4.mjs +211 -0
- package/dist/es/chunk/aibQ9WSZ.mjs +249 -0
- package/dist/es/chunk/nWBcrYxV.mjs +690 -0
- package/dist/es/chunk/pcqpp-6-.mjs +9 -0
- package/dist/es/chunk/qY9OvNHY.mjs +283 -0
- package/dist/es/chunk/su2Zrql0.mjs +53 -0
- package/dist/es/chunk/zfg5SOj1.mjs +138 -0
- package/dist/es/components/awesome-icon/awesome-icon.d.ts +6 -0
- package/dist/es/components/awesome-icon/awesome-icon.mjs +41 -0
- package/dist/es/components/awesome-icon/awesome-icon.vue.d.ts +5 -0
- package/dist/es/components/awesome-icon/index.d.ts +4 -0
- package/dist/es/components/awesome-icon/index.mjs +6 -0
- package/dist/es/components/backbottom/backbottom.d.ts +7 -0
- package/dist/es/components/backbottom/backbottom.mjs +172 -0
- package/dist/es/components/backbottom/backbottom.vue.d.ts +7 -0
- package/dist/es/components/backbottom/components/child.vue.d.ts +30 -0
- package/dist/es/components/backbottom/index.d.ts +4 -0
- package/dist/es/components/backbottom/index.mjs +6 -0
- package/dist/es/components/button/button.d.ts +18 -0
- package/dist/es/components/button/button.mjs +313 -0
- package/dist/es/components/button/button.vue.d.ts +33 -0
- package/dist/es/components/button/index.css +9 -0
- package/dist/es/components/button/index.d.ts +4 -0
- package/dist/es/components/button/index.mjs +6 -0
- package/dist/es/components/cdn-tag.vue.d.ts +5 -0
- package/dist/es/components/chat-container/chat-container.d.ts +9 -0
- package/dist/es/components/chat-container/chat-container.mjs +77 -0
- package/dist/es/components/chat-container/chat-container.vue.d.ts +29 -0
- package/dist/es/components/chat-container/index.css +9 -0
- package/dist/es/components/chat-container/index.d.ts +4 -0
- package/dist/es/components/chat-container/index.mjs +6 -0
- package/dist/es/components/choice/choice.d.ts +6 -0
- package/dist/es/components/choice/choice.mjs +53 -0
- package/dist/es/components/choice/choice.vue.d.ts +5 -0
- package/dist/es/components/choice/index.css +7 -0
- package/dist/es/components/choice/index.d.ts +4 -0
- package/dist/es/components/choice/index.mjs +6 -0
- package/dist/es/components/choice-boolean/choice-boolean.d.ts +5 -0
- package/dist/es/components/choice-boolean/choice-boolean.mjs +32 -0
- package/dist/es/components/choice-boolean/choice-boolean.vue.d.ts +10 -0
- package/dist/es/components/choice-boolean/index.d.ts +4 -0
- package/dist/es/components/choice-boolean/index.mjs +6 -0
- package/dist/es/components/config-provider/config-provider.d.ts +16 -0
- package/dist/es/components/config-provider/config-provider.mjs +29 -0
- package/dist/es/components/config-provider/config-provider.vue.d.ts +18 -0
- package/dist/es/components/config-provider/config-provider2.mjs +6 -0
- package/dist/es/components/config-provider/index.d.ts +4 -0
- package/dist/es/components/config-provider/index.mjs +6 -0
- package/dist/es/components/cropper/cropper.d.ts +12 -0
- package/dist/es/components/cropper/cropper.mjs +333 -0
- package/dist/es/components/cropper/cropper.vue.d.ts +32 -0
- package/dist/es/components/cropper/index.css +4 -0
- package/dist/es/components/cropper/index.d.ts +4 -0
- package/dist/es/components/cropper/index.mjs +6 -0
- package/dist/es/components/currency/currency.d.ts +21 -0
- package/dist/es/components/currency/currency.mjs +185 -0
- package/dist/es/components/currency/currency.vue.d.ts +14 -0
- package/dist/es/components/currency/index.css +8 -0
- package/dist/es/components/currency/index.d.ts +4 -0
- package/dist/es/components/currency/index.mjs +6 -0
- package/dist/es/components/daterange-picker/daterange-picker.d.ts +6 -0
- package/dist/es/components/daterange-picker/daterange-picker.mjs +5550 -0
- package/dist/es/components/daterange-picker/daterange-picker.vue.d.ts +13 -0
- package/dist/es/components/daterange-picker/index.d.ts +4 -0
- package/dist/es/components/daterange-picker/index.mjs +6 -0
- package/dist/es/components/dialog/dialog.d.ts +13 -0
- package/dist/es/components/dialog/dialog.mjs +537 -0
- package/dist/es/components/dialog/dialog.vue.d.ts +38 -0
- package/dist/es/components/dialog/index.css +87 -0
- package/dist/es/components/dialog/index.d.ts +4 -0
- package/dist/es/components/dialog/index.mjs +6 -0
- package/dist/es/components/dialog-camera-upload/dialog-camera-upload.d.ts +33 -0
- package/dist/es/components/dialog-camera-upload/dialog-camera-upload.mjs +412 -0
- package/dist/es/components/dialog-camera-upload/dialog-camera-upload.vue.d.ts +23 -0
- package/dist/es/components/dialog-camera-upload/index.css +66 -0
- package/dist/es/components/dialog-camera-upload/index.d.ts +4 -0
- package/dist/es/components/dialog-camera-upload/index.mjs +6 -0
- package/dist/es/components/dialog-map-point/dialog-map-point.d.ts +9 -0
- package/dist/es/components/dialog-map-point/dialog-map-point.mjs +183 -0
- package/dist/es/components/dialog-map-point/dialog-map-point.vue.d.ts +22 -0
- package/dist/es/components/dialog-map-point/index.css +11 -0
- package/dist/es/components/dialog-map-point/index.d.ts +4 -0
- package/dist/es/components/dialog-map-point/index.mjs +6 -0
- package/dist/es/components/dialog-upload-images/dialog-upload-images.d.ts +16 -0
- package/dist/es/components/dialog-upload-images/dialog-upload-images.mjs +1391 -0
- package/dist/es/components/dialog-upload-images/dialog-upload-images.vue.d.ts +19 -0
- package/dist/es/components/dialog-upload-images/index.css +62 -0
- package/dist/es/components/dialog-upload-images/index.d.ts +4 -0
- package/dist/es/components/dialog-upload-images/index.mjs +6 -0
- package/dist/es/components/document.vue.d.ts +14 -0
- package/dist/es/components/drawer/drawer.d.ts +7 -0
- package/dist/es/components/drawer/drawer.mjs +412 -0
- package/dist/es/components/drawer/drawer.vue.d.ts +31 -0
- package/dist/es/components/drawer/index.css +56 -0
- package/dist/es/components/drawer/index.d.ts +4 -0
- package/dist/es/components/drawer/index.mjs +6 -0
- package/dist/es/components/easy-pagination/easy-pagination.d.ts +8 -0
- package/dist/es/components/easy-pagination/easy-pagination.mjs +74 -0
- package/dist/es/components/easy-pagination/easy-pagination.vue.d.ts +19 -0
- package/dist/es/components/easy-pagination/index.css +10 -0
- package/dist/es/components/easy-pagination/index.d.ts +4 -0
- package/dist/es/components/easy-pagination/index.mjs +6 -0
- package/dist/es/components/el-icon/el-icon.d.ts +6 -0
- package/dist/es/components/el-icon/el-icon.mjs +46 -0
- package/dist/es/components/el-icon/el-icon.vue.d.ts +6 -0
- package/dist/es/components/el-icon/index.css +7 -0
- package/dist/es/components/el-icon/index.d.ts +4 -0
- package/dist/es/components/el-icon/index.mjs +6 -0
- package/dist/es/components/example-wrapper.vue.d.ts +19 -0
- package/dist/es/components/flag/flag.mjs +44 -0
- package/dist/es/components/flag/flag.vue.d.ts +5 -0
- package/dist/es/components/flag/flags.d.ts +8 -0
- package/dist/es/components/flag/index.d.ts +4 -0
- package/dist/es/components/flag/index.mjs +6 -0
- package/dist/es/components/icon/icon.d.ts +6 -0
- package/dist/es/components/icon/icon.mjs +54 -0
- package/dist/es/components/icon/icon.vue.d.ts +3 -0
- package/dist/es/components/icon/icon2.mjs +27 -0
- package/dist/es/components/icon/index.css +9 -0
- package/dist/es/components/icon/index.d.ts +4 -0
- package/dist/es/components/icon/index.mjs +6 -0
- package/dist/es/components/image/image.d.ts +16 -0
- package/dist/es/components/image/image.mjs +167 -0
- package/dist/es/components/image/image.vue.d.ts +206 -0
- package/dist/es/components/image/index.css +20 -0
- package/dist/es/components/image/index.d.ts +4 -0
- package/dist/es/components/image/index.mjs +6 -0
- package/dist/es/components/input/index.css +9 -0
- package/dist/es/components/input/index.d.ts +4 -0
- package/dist/es/components/input/index.mjs +6 -0
- package/dist/es/components/input/input.d.ts +4 -0
- package/dist/es/components/input/input.mjs +85 -0
- package/dist/es/components/input/input.vue.d.ts +1232 -0
- package/dist/es/components/input-number/index.css +24 -0
- package/dist/es/components/input-number/index.d.ts +4 -0
- package/dist/es/components/input-number/index.mjs +6 -0
- package/dist/es/components/input-number/input-number.d.ts +8 -0
- package/dist/es/components/input-number/input-number.mjs +137 -0
- package/dist/es/components/input-number/input-number.vue.d.ts +35 -0
- package/dist/es/components/pca-picker/components/c.vue.d.ts +123 -0
- package/dist/es/components/pca-picker/components/elevator-item.vue.d.ts +7 -0
- package/dist/es/components/pca-picker/components/filter.vue.d.ts +2 -0
- package/dist/es/components/pca-picker/components/history.vue.d.ts +2 -0
- package/dist/es/components/pca-picker/components/hot.vue.d.ts +2 -0
- package/dist/es/components/pca-picker/components/p.vue.d.ts +2 -0
- package/dist/es/components/pca-picker/components/pca.vue.d.ts +9 -0
- package/dist/es/components/pca-picker/index.css +107 -0
- package/dist/es/components/pca-picker/index.d.ts +4 -0
- package/dist/es/components/pca-picker/index.mjs +6 -0
- package/dist/es/components/pca-picker/pca-picker.d.ts +78 -0
- package/dist/es/components/pca-picker/pca-picker.mjs +1667 -0
- package/dist/es/components/pca-picker/pca-picker.vue.d.ts +583 -0
- package/dist/es/components/qr-code/index.d.ts +4 -0
- package/dist/es/components/qr-code/index.mjs +6 -0
- package/dist/es/components/qr-code/qr-code.d.ts +9 -0
- package/dist/es/components/qr-code/qr-code.mjs +69 -0
- package/dist/es/components/qr-code/qr-code.vue.d.ts +13 -0
- package/dist/es/components/screenfull/index.css +14 -0
- package/dist/es/components/screenfull/index.d.ts +4 -0
- package/dist/es/components/screenfull/index.mjs +6 -0
- package/dist/es/components/screenfull/screenfull.d.ts +4 -0
- package/dist/es/components/screenfull/screenfull.mjs +91 -0
- package/dist/es/components/screenfull/screenfull.vue.d.ts +20 -0
- package/dist/es/components/select/index.css +9 -0
- package/dist/es/components/select/index.d.ts +4 -0
- package/dist/es/components/select/index.mjs +6 -0
- package/dist/es/components/select/select.d.ts +6 -0
- package/dist/es/components/select/select.mjs +63 -0
- package/dist/es/components/select/select.vue.d.ts +6 -0
- package/dist/es/components/single-player/index.css +45 -0
- package/dist/es/components/single-player/index.d.ts +4 -0
- package/dist/es/components/single-player/index.mjs +6 -0
- package/dist/es/components/single-player/single-player.d.ts +4 -0
- package/dist/es/components/single-player/single-player.mjs +1172 -0
- package/dist/es/components/single-player/single-player.vue.d.ts +13 -0
- package/dist/es/components/svg-icon/index.css +9 -0
- package/dist/es/components/svg-icon/index.d.ts +4 -0
- package/dist/es/components/svg-icon/index.mjs +6 -0
- package/dist/es/components/svg-icon/svg-icon.d.ts +5 -0
- package/dist/es/components/svg-icon/svg-icon.mjs +46 -0
- package/dist/es/components/svg-icon/svg-icon.vue.d.ts +18 -0
- package/dist/es/components/switch/index.css +15 -0
- package/dist/es/components/switch/index.d.ts +4 -0
- package/dist/es/components/switch/index.mjs +6 -0
- package/dist/es/components/switch/switch.d.ts +9 -0
- package/dist/es/components/switch/switch.mjs +82 -0
- package/dist/es/components/switch/switch.vue.d.ts +14 -0
- package/dist/es/components/sync-scroll-container/index.css +82 -0
- package/dist/es/components/sync-scroll-container/index.d.ts +4 -0
- package/dist/es/components/sync-scroll-container/index.mjs +6 -0
- package/dist/es/components/sync-scroll-container/sync-scroll-container.d.ts +6 -0
- package/dist/es/components/sync-scroll-container/sync-scroll-container.mjs +157 -0
- package/dist/es/components/sync-scroll-container/sync-scroll-container.vue.d.ts +36 -0
- package/dist/es/components/tags/index.css +17 -0
- package/dist/es/components/tags/index.d.ts +4 -0
- package/dist/es/components/tags/index.mjs +6 -0
- package/dist/es/components/tags/tags.d.ts +9 -0
- package/dist/es/components/tags/tags.mjs +296 -0
- package/dist/es/components/tags/tags.vue.d.ts +20 -0
- package/dist/es/components/text-ellipsis/index.css +15 -0
- package/dist/es/components/text-ellipsis/index.d.ts +4 -0
- package/dist/es/components/text-ellipsis/index.mjs +6 -0
- package/dist/es/components/text-ellipsis/text-ellipsis.d.ts +12 -0
- package/dist/es/components/text-ellipsis/text-ellipsis.mjs +137 -0
- package/dist/es/components/text-ellipsis/text-ellipsis.vue.d.ts +41 -0
- package/dist/es/components/thousand-input/index.css +4 -0
- package/dist/es/components/thousand-input/index.d.ts +4 -0
- package/dist/es/components/thousand-input/index.mjs +6 -0
- package/dist/es/components/thousand-input/thousand-input.d.ts +11 -0
- package/dist/es/components/thousand-input/thousand-input.mjs +159 -0
- package/dist/es/components/thousand-input/thousand-input.vue.d.ts +2558 -0
- package/dist/es/components/tinymce/config.d.ts +25 -0
- package/dist/es/components/tinymce/index.css +9 -0
- package/dist/es/components/tinymce/index.d.ts +4 -0
- package/dist/es/components/tinymce/index.mjs +6 -0
- package/dist/es/components/tinymce/tinymce.d.ts +9 -0
- package/dist/es/components/tinymce/tinymce.mjs +176 -0
- package/dist/es/components/tinymce/tinymce.vue.d.ts +20 -0
- package/dist/es/components/tree-picker/components/popover-cascader.d.ts +8 -0
- package/dist/es/components/tree-picker/components/popover-cascader.vue.d.ts +1361 -0
- package/dist/es/components/tree-picker/docs/data.d.ts +2 -0
- package/dist/es/components/tree-picker/index.css +41 -0
- package/dist/es/components/tree-picker/index.d.ts +4 -0
- package/dist/es/components/tree-picker/index.mjs +6 -0
- package/dist/es/components/tree-picker/popover-cascader.css +23 -0
- package/dist/es/components/tree-picker/tree-picker.d.ts +14 -0
- package/dist/es/components/tree-picker/tree-picker.mjs +173 -0
- package/dist/es/components/tree-picker/tree-picker.vue.d.ts +575 -0
- package/dist/es/components/upload-file/index.css +30 -0
- package/dist/es/components/upload-file/index.d.ts +4 -0
- package/dist/es/components/upload-file/index.mjs +6 -0
- package/dist/es/components/upload-file/upload-file.d.ts +39 -0
- package/dist/es/components/upload-file/upload-file.mjs +202 -0
- package/dist/es/components/upload-file/upload-file.vue.d.ts +30 -0
- package/dist/es/directives/cleave/index.d.ts +3 -0
- package/dist/es/directives/focus/index.d.ts +4 -0
- package/dist/es/directives/index.d.ts +3 -0
- package/dist/es/directives/thousand/index.d.ts +3 -0
- package/dist/es/index.d.ts +42 -0
- package/dist/es/index.mjs +122 -0
- package/dist/es/use/useSmallScreen/index.d.ts +4 -0
- package/dist/es/use/useSmallScreen/index.mjs +10 -0
- package/dist/es/use/useStore/index.d.ts +3 -0
- package/dist/es/use/useStore/index.mjs +22 -0
- package/dist/es/utils/index.d.ts +6 -0
- package/dist/es/utils/resolver.d.ts +3 -0
- package/dist/es/utils/resolver.mjs +24 -0
- package/dist/es/utils/typescript.d.ts +6 -0
- package/dist/global.d.ts +42 -0
- package/dist/index.css +869 -0
- package/package.json +58 -0
|
@@ -0,0 +1,3420 @@
|
|
|
1
|
+
import { a as getAugmentedNamespace, c as commonjsGlobal, g as getDefaultExportFromCjs } from './BAGoDD49.mjs';
|
|
2
|
+
import { i as isObjectLike, b as baseGetTag } from './Fo0dZYnz.mjs';
|
|
3
|
+
import { b as baseUnary, n as nodeUtil } from './O-uhUKF4.mjs';
|
|
4
|
+
|
|
5
|
+
/** `Object#toString` result references. */
|
|
6
|
+
var dateTag = '[object Date]';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The base implementation of `_.isDate` without Node.js optimizations.
|
|
10
|
+
*
|
|
11
|
+
* @private
|
|
12
|
+
* @param {*} value The value to check.
|
|
13
|
+
* @returns {boolean} Returns `true` if `value` is a date object, else `false`.
|
|
14
|
+
*/
|
|
15
|
+
function baseIsDate(value) {
|
|
16
|
+
return isObjectLike(value) && baseGetTag(value) == dateTag;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* Node.js helper references. */
|
|
20
|
+
var nodeIsDate = nodeUtil && nodeUtil.isDate;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Checks if `value` is classified as a `Date` object.
|
|
24
|
+
*
|
|
25
|
+
* @static
|
|
26
|
+
* @memberOf _
|
|
27
|
+
* @since 0.1.0
|
|
28
|
+
* @category Lang
|
|
29
|
+
* @param {*} value The value to check.
|
|
30
|
+
* @returns {boolean} Returns `true` if `value` is a date object, else `false`.
|
|
31
|
+
* @example
|
|
32
|
+
*
|
|
33
|
+
* _.isDate(new Date);
|
|
34
|
+
* // => true
|
|
35
|
+
*
|
|
36
|
+
* _.isDate('Mon April 23 2012');
|
|
37
|
+
* // => false
|
|
38
|
+
*/
|
|
39
|
+
var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
|
|
40
|
+
|
|
41
|
+
/** `Object#toString` result references. */
|
|
42
|
+
var numberTag = '[object Number]';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Checks if `value` is classified as a `Number` primitive or object.
|
|
46
|
+
*
|
|
47
|
+
* **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
|
|
48
|
+
* classified as numbers, use the `_.isFinite` method.
|
|
49
|
+
*
|
|
50
|
+
* @static
|
|
51
|
+
* @memberOf _
|
|
52
|
+
* @since 0.1.0
|
|
53
|
+
* @category Lang
|
|
54
|
+
* @param {*} value The value to check.
|
|
55
|
+
* @returns {boolean} Returns `true` if `value` is a number, else `false`.
|
|
56
|
+
* @example
|
|
57
|
+
*
|
|
58
|
+
* _.isNumber(3);
|
|
59
|
+
* // => true
|
|
60
|
+
*
|
|
61
|
+
* _.isNumber(Number.MIN_VALUE);
|
|
62
|
+
* // => true
|
|
63
|
+
*
|
|
64
|
+
* _.isNumber(Infinity);
|
|
65
|
+
* // => true
|
|
66
|
+
*
|
|
67
|
+
* _.isNumber('3');
|
|
68
|
+
* // => false
|
|
69
|
+
*/
|
|
70
|
+
function isNumber(value) {
|
|
71
|
+
return typeof value == 'number' ||
|
|
72
|
+
(isObjectLike(value) && baseGetTag(value) == numberTag);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
var aes$1 = {exports: {}};
|
|
76
|
+
|
|
77
|
+
function commonjsRequire(path) {
|
|
78
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var core$1 = {exports: {}};
|
|
82
|
+
|
|
83
|
+
const __viteBrowserExternal = {};
|
|
84
|
+
|
|
85
|
+
const __viteBrowserExternal$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
86
|
+
__proto__: null,
|
|
87
|
+
default: __viteBrowserExternal
|
|
88
|
+
}, Symbol.toStringTag, { value: 'Module' }));
|
|
89
|
+
|
|
90
|
+
const require$$0 = /*@__PURE__*/getAugmentedNamespace(__viteBrowserExternal$1);
|
|
91
|
+
|
|
92
|
+
var core = core$1.exports;
|
|
93
|
+
|
|
94
|
+
var hasRequiredCore;
|
|
95
|
+
|
|
96
|
+
function requireCore () {
|
|
97
|
+
if (hasRequiredCore) return core$1.exports;
|
|
98
|
+
hasRequiredCore = 1;
|
|
99
|
+
(function (module, exports$1) {
|
|
100
|
+
(function (root, factory) {
|
|
101
|
+
{
|
|
102
|
+
// CommonJS
|
|
103
|
+
module.exports = factory();
|
|
104
|
+
}
|
|
105
|
+
}(core, function () {
|
|
106
|
+
|
|
107
|
+
/*globals window, global, require*/
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* CryptoJS core components.
|
|
111
|
+
*/
|
|
112
|
+
var CryptoJS = CryptoJS || (function (Math, undefined$1) {
|
|
113
|
+
|
|
114
|
+
var crypto;
|
|
115
|
+
|
|
116
|
+
// Native crypto from window (Browser)
|
|
117
|
+
if (typeof window !== 'undefined' && window.crypto) {
|
|
118
|
+
crypto = window.crypto;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Native crypto in web worker (Browser)
|
|
122
|
+
if (typeof self !== 'undefined' && self.crypto) {
|
|
123
|
+
crypto = self.crypto;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Native crypto from worker
|
|
127
|
+
if (typeof globalThis !== 'undefined' && globalThis.crypto) {
|
|
128
|
+
crypto = globalThis.crypto;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Native (experimental IE 11) crypto from window (Browser)
|
|
132
|
+
if (!crypto && typeof window !== 'undefined' && window.msCrypto) {
|
|
133
|
+
crypto = window.msCrypto;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Native crypto from global (NodeJS)
|
|
137
|
+
if (!crypto && typeof commonjsGlobal !== 'undefined' && commonjsGlobal.crypto) {
|
|
138
|
+
crypto = commonjsGlobal.crypto;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Native crypto import via require (NodeJS)
|
|
142
|
+
if (!crypto && typeof commonjsRequire === 'function') {
|
|
143
|
+
try {
|
|
144
|
+
crypto = require$$0;
|
|
145
|
+
} catch (err) {}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/*
|
|
149
|
+
* Cryptographically secure pseudorandom number generator
|
|
150
|
+
*
|
|
151
|
+
* As Math.random() is cryptographically not safe to use
|
|
152
|
+
*/
|
|
153
|
+
var cryptoSecureRandomInt = function () {
|
|
154
|
+
if (crypto) {
|
|
155
|
+
// Use getRandomValues method (Browser)
|
|
156
|
+
if (typeof crypto.getRandomValues === 'function') {
|
|
157
|
+
try {
|
|
158
|
+
return crypto.getRandomValues(new Uint32Array(1))[0];
|
|
159
|
+
} catch (err) {}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Use randomBytes method (NodeJS)
|
|
163
|
+
if (typeof crypto.randomBytes === 'function') {
|
|
164
|
+
try {
|
|
165
|
+
return crypto.randomBytes(4).readInt32LE();
|
|
166
|
+
} catch (err) {}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
throw new Error('Native crypto module could not be used to get secure random number.');
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/*
|
|
174
|
+
* Local polyfill of Object.create
|
|
175
|
+
|
|
176
|
+
*/
|
|
177
|
+
var create = Object.create || (function () {
|
|
178
|
+
function F() {}
|
|
179
|
+
|
|
180
|
+
return function (obj) {
|
|
181
|
+
var subtype;
|
|
182
|
+
|
|
183
|
+
F.prototype = obj;
|
|
184
|
+
|
|
185
|
+
subtype = new F();
|
|
186
|
+
|
|
187
|
+
F.prototype = null;
|
|
188
|
+
|
|
189
|
+
return subtype;
|
|
190
|
+
};
|
|
191
|
+
}());
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* CryptoJS namespace.
|
|
195
|
+
*/
|
|
196
|
+
var C = {};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Library namespace.
|
|
200
|
+
*/
|
|
201
|
+
var C_lib = C.lib = {};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Base object for prototypal inheritance.
|
|
205
|
+
*/
|
|
206
|
+
var Base = C_lib.Base = (function () {
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
/**
|
|
211
|
+
* Creates a new object that inherits from this object.
|
|
212
|
+
*
|
|
213
|
+
* @param {Object} overrides Properties to copy into the new object.
|
|
214
|
+
*
|
|
215
|
+
* @return {Object} The new object.
|
|
216
|
+
*
|
|
217
|
+
* @static
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
*
|
|
221
|
+
* var MyType = CryptoJS.lib.Base.extend({
|
|
222
|
+
* field: 'value',
|
|
223
|
+
*
|
|
224
|
+
* method: function () {
|
|
225
|
+
* }
|
|
226
|
+
* });
|
|
227
|
+
*/
|
|
228
|
+
extend: function (overrides) {
|
|
229
|
+
// Spawn
|
|
230
|
+
var subtype = create(this);
|
|
231
|
+
|
|
232
|
+
// Augment
|
|
233
|
+
if (overrides) {
|
|
234
|
+
subtype.mixIn(overrides);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Create default initializer
|
|
238
|
+
if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
|
|
239
|
+
subtype.init = function () {
|
|
240
|
+
subtype.$super.init.apply(this, arguments);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Initializer's prototype is the subtype object
|
|
245
|
+
subtype.init.prototype = subtype;
|
|
246
|
+
|
|
247
|
+
// Reference supertype
|
|
248
|
+
subtype.$super = this;
|
|
249
|
+
|
|
250
|
+
return subtype;
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Extends this object and runs the init method.
|
|
255
|
+
* Arguments to create() will be passed to init().
|
|
256
|
+
*
|
|
257
|
+
* @return {Object} The new object.
|
|
258
|
+
*
|
|
259
|
+
* @static
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
*
|
|
263
|
+
* var instance = MyType.create();
|
|
264
|
+
*/
|
|
265
|
+
create: function () {
|
|
266
|
+
var instance = this.extend();
|
|
267
|
+
instance.init.apply(instance, arguments);
|
|
268
|
+
|
|
269
|
+
return instance;
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Initializes a newly created object.
|
|
274
|
+
* Override this method to add some logic when your objects are created.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
*
|
|
278
|
+
* var MyType = CryptoJS.lib.Base.extend({
|
|
279
|
+
* init: function () {
|
|
280
|
+
* // ...
|
|
281
|
+
* }
|
|
282
|
+
* });
|
|
283
|
+
*/
|
|
284
|
+
init: function () {
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Copies properties into this object.
|
|
289
|
+
*
|
|
290
|
+
* @param {Object} properties The properties to mix in.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
*
|
|
294
|
+
* MyType.mixIn({
|
|
295
|
+
* field: 'value'
|
|
296
|
+
* });
|
|
297
|
+
*/
|
|
298
|
+
mixIn: function (properties) {
|
|
299
|
+
for (var propertyName in properties) {
|
|
300
|
+
if (properties.hasOwnProperty(propertyName)) {
|
|
301
|
+
this[propertyName] = properties[propertyName];
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// IE won't copy toString using the loop above
|
|
306
|
+
if (properties.hasOwnProperty('toString')) {
|
|
307
|
+
this.toString = properties.toString;
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Creates a copy of this object.
|
|
313
|
+
*
|
|
314
|
+
* @return {Object} The clone.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
*
|
|
318
|
+
* var clone = instance.clone();
|
|
319
|
+
*/
|
|
320
|
+
clone: function () {
|
|
321
|
+
return this.init.prototype.extend(this);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
}());
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* An array of 32-bit words.
|
|
328
|
+
*
|
|
329
|
+
* @property {Array} words The array of 32-bit words.
|
|
330
|
+
* @property {number} sigBytes The number of significant bytes in this word array.
|
|
331
|
+
*/
|
|
332
|
+
var WordArray = C_lib.WordArray = Base.extend({
|
|
333
|
+
/**
|
|
334
|
+
* Initializes a newly created word array.
|
|
335
|
+
*
|
|
336
|
+
* @param {Array} words (Optional) An array of 32-bit words.
|
|
337
|
+
* @param {number} sigBytes (Optional) The number of significant bytes in the words.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
*
|
|
341
|
+
* var wordArray = CryptoJS.lib.WordArray.create();
|
|
342
|
+
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
|
|
343
|
+
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
|
|
344
|
+
*/
|
|
345
|
+
init: function (words, sigBytes) {
|
|
346
|
+
words = this.words = words || [];
|
|
347
|
+
|
|
348
|
+
if (sigBytes != undefined$1) {
|
|
349
|
+
this.sigBytes = sigBytes;
|
|
350
|
+
} else {
|
|
351
|
+
this.sigBytes = words.length * 4;
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Converts this word array to a string.
|
|
357
|
+
*
|
|
358
|
+
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
|
|
359
|
+
*
|
|
360
|
+
* @return {string} The stringified word array.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
*
|
|
364
|
+
* var string = wordArray + '';
|
|
365
|
+
* var string = wordArray.toString();
|
|
366
|
+
* var string = wordArray.toString(CryptoJS.enc.Utf8);
|
|
367
|
+
*/
|
|
368
|
+
toString: function (encoder) {
|
|
369
|
+
return (encoder || Hex).stringify(this);
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Concatenates a word array to this word array.
|
|
374
|
+
*
|
|
375
|
+
* @param {WordArray} wordArray The word array to append.
|
|
376
|
+
*
|
|
377
|
+
* @return {WordArray} This word array.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
*
|
|
381
|
+
* wordArray1.concat(wordArray2);
|
|
382
|
+
*/
|
|
383
|
+
concat: function (wordArray) {
|
|
384
|
+
// Shortcuts
|
|
385
|
+
var thisWords = this.words;
|
|
386
|
+
var thatWords = wordArray.words;
|
|
387
|
+
var thisSigBytes = this.sigBytes;
|
|
388
|
+
var thatSigBytes = wordArray.sigBytes;
|
|
389
|
+
|
|
390
|
+
// Clamp excess bits
|
|
391
|
+
this.clamp();
|
|
392
|
+
|
|
393
|
+
// Concat
|
|
394
|
+
if (thisSigBytes % 4) {
|
|
395
|
+
// Copy one byte at a time
|
|
396
|
+
for (var i = 0; i < thatSigBytes; i++) {
|
|
397
|
+
var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
|
398
|
+
thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
|
|
399
|
+
}
|
|
400
|
+
} else {
|
|
401
|
+
// Copy one word at a time
|
|
402
|
+
for (var j = 0; j < thatSigBytes; j += 4) {
|
|
403
|
+
thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2];
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
this.sigBytes += thatSigBytes;
|
|
407
|
+
|
|
408
|
+
// Chainable
|
|
409
|
+
return this;
|
|
410
|
+
},
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Removes insignificant bits.
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
*
|
|
417
|
+
* wordArray.clamp();
|
|
418
|
+
*/
|
|
419
|
+
clamp: function () {
|
|
420
|
+
// Shortcuts
|
|
421
|
+
var words = this.words;
|
|
422
|
+
var sigBytes = this.sigBytes;
|
|
423
|
+
|
|
424
|
+
// Clamp
|
|
425
|
+
words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
|
|
426
|
+
words.length = Math.ceil(sigBytes / 4);
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Creates a copy of this word array.
|
|
431
|
+
*
|
|
432
|
+
* @return {WordArray} The clone.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
*
|
|
436
|
+
* var clone = wordArray.clone();
|
|
437
|
+
*/
|
|
438
|
+
clone: function () {
|
|
439
|
+
var clone = Base.clone.call(this);
|
|
440
|
+
clone.words = this.words.slice(0);
|
|
441
|
+
|
|
442
|
+
return clone;
|
|
443
|
+
},
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Creates a word array filled with random bytes.
|
|
447
|
+
*
|
|
448
|
+
* @param {number} nBytes The number of random bytes to generate.
|
|
449
|
+
*
|
|
450
|
+
* @return {WordArray} The random word array.
|
|
451
|
+
*
|
|
452
|
+
* @static
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
*
|
|
456
|
+
* var wordArray = CryptoJS.lib.WordArray.random(16);
|
|
457
|
+
*/
|
|
458
|
+
random: function (nBytes) {
|
|
459
|
+
var words = [];
|
|
460
|
+
|
|
461
|
+
for (var i = 0; i < nBytes; i += 4) {
|
|
462
|
+
words.push(cryptoSecureRandomInt());
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return new WordArray.init(words, nBytes);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Encoder namespace.
|
|
471
|
+
*/
|
|
472
|
+
var C_enc = C.enc = {};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Hex encoding strategy.
|
|
476
|
+
*/
|
|
477
|
+
var Hex = C_enc.Hex = {
|
|
478
|
+
/**
|
|
479
|
+
* Converts a word array to a hex string.
|
|
480
|
+
*
|
|
481
|
+
* @param {WordArray} wordArray The word array.
|
|
482
|
+
*
|
|
483
|
+
* @return {string} The hex string.
|
|
484
|
+
*
|
|
485
|
+
* @static
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
*
|
|
489
|
+
* var hexString = CryptoJS.enc.Hex.stringify(wordArray);
|
|
490
|
+
*/
|
|
491
|
+
stringify: function (wordArray) {
|
|
492
|
+
// Shortcuts
|
|
493
|
+
var words = wordArray.words;
|
|
494
|
+
var sigBytes = wordArray.sigBytes;
|
|
495
|
+
|
|
496
|
+
// Convert
|
|
497
|
+
var hexChars = [];
|
|
498
|
+
for (var i = 0; i < sigBytes; i++) {
|
|
499
|
+
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
|
500
|
+
hexChars.push((bite >>> 4).toString(16));
|
|
501
|
+
hexChars.push((bite & 0x0f).toString(16));
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return hexChars.join('');
|
|
505
|
+
},
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Converts a hex string to a word array.
|
|
509
|
+
*
|
|
510
|
+
* @param {string} hexStr The hex string.
|
|
511
|
+
*
|
|
512
|
+
* @return {WordArray} The word array.
|
|
513
|
+
*
|
|
514
|
+
* @static
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
*
|
|
518
|
+
* var wordArray = CryptoJS.enc.Hex.parse(hexString);
|
|
519
|
+
*/
|
|
520
|
+
parse: function (hexStr) {
|
|
521
|
+
// Shortcut
|
|
522
|
+
var hexStrLength = hexStr.length;
|
|
523
|
+
|
|
524
|
+
// Convert
|
|
525
|
+
var words = [];
|
|
526
|
+
for (var i = 0; i < hexStrLength; i += 2) {
|
|
527
|
+
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
return new WordArray.init(words, hexStrLength / 2);
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Latin1 encoding strategy.
|
|
536
|
+
*/
|
|
537
|
+
var Latin1 = C_enc.Latin1 = {
|
|
538
|
+
/**
|
|
539
|
+
* Converts a word array to a Latin1 string.
|
|
540
|
+
*
|
|
541
|
+
* @param {WordArray} wordArray The word array.
|
|
542
|
+
*
|
|
543
|
+
* @return {string} The Latin1 string.
|
|
544
|
+
*
|
|
545
|
+
* @static
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
*
|
|
549
|
+
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
|
|
550
|
+
*/
|
|
551
|
+
stringify: function (wordArray) {
|
|
552
|
+
// Shortcuts
|
|
553
|
+
var words = wordArray.words;
|
|
554
|
+
var sigBytes = wordArray.sigBytes;
|
|
555
|
+
|
|
556
|
+
// Convert
|
|
557
|
+
var latin1Chars = [];
|
|
558
|
+
for (var i = 0; i < sigBytes; i++) {
|
|
559
|
+
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
|
560
|
+
latin1Chars.push(String.fromCharCode(bite));
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return latin1Chars.join('');
|
|
564
|
+
},
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Converts a Latin1 string to a word array.
|
|
568
|
+
*
|
|
569
|
+
* @param {string} latin1Str The Latin1 string.
|
|
570
|
+
*
|
|
571
|
+
* @return {WordArray} The word array.
|
|
572
|
+
*
|
|
573
|
+
* @static
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
*
|
|
577
|
+
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
|
|
578
|
+
*/
|
|
579
|
+
parse: function (latin1Str) {
|
|
580
|
+
// Shortcut
|
|
581
|
+
var latin1StrLength = latin1Str.length;
|
|
582
|
+
|
|
583
|
+
// Convert
|
|
584
|
+
var words = [];
|
|
585
|
+
for (var i = 0; i < latin1StrLength; i++) {
|
|
586
|
+
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return new WordArray.init(words, latin1StrLength);
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* UTF-8 encoding strategy.
|
|
595
|
+
*/
|
|
596
|
+
var Utf8 = C_enc.Utf8 = {
|
|
597
|
+
/**
|
|
598
|
+
* Converts a word array to a UTF-8 string.
|
|
599
|
+
*
|
|
600
|
+
* @param {WordArray} wordArray The word array.
|
|
601
|
+
*
|
|
602
|
+
* @return {string} The UTF-8 string.
|
|
603
|
+
*
|
|
604
|
+
* @static
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
*
|
|
608
|
+
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
|
|
609
|
+
*/
|
|
610
|
+
stringify: function (wordArray) {
|
|
611
|
+
try {
|
|
612
|
+
return decodeURIComponent(escape(Latin1.stringify(wordArray)));
|
|
613
|
+
} catch (e) {
|
|
614
|
+
throw new Error('Malformed UTF-8 data');
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Converts a UTF-8 string to a word array.
|
|
620
|
+
*
|
|
621
|
+
* @param {string} utf8Str The UTF-8 string.
|
|
622
|
+
*
|
|
623
|
+
* @return {WordArray} The word array.
|
|
624
|
+
*
|
|
625
|
+
* @static
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
*
|
|
629
|
+
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
|
|
630
|
+
*/
|
|
631
|
+
parse: function (utf8Str) {
|
|
632
|
+
return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Abstract buffered block algorithm template.
|
|
638
|
+
*
|
|
639
|
+
* The property blockSize must be implemented in a concrete subtype.
|
|
640
|
+
*
|
|
641
|
+
* @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
|
|
642
|
+
*/
|
|
643
|
+
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
|
|
644
|
+
/**
|
|
645
|
+
* Resets this block algorithm's data buffer to its initial state.
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
*
|
|
649
|
+
* bufferedBlockAlgorithm.reset();
|
|
650
|
+
*/
|
|
651
|
+
reset: function () {
|
|
652
|
+
// Initial values
|
|
653
|
+
this._data = new WordArray.init();
|
|
654
|
+
this._nDataBytes = 0;
|
|
655
|
+
},
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Adds new data to this block algorithm's buffer.
|
|
659
|
+
*
|
|
660
|
+
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
*
|
|
664
|
+
* bufferedBlockAlgorithm._append('data');
|
|
665
|
+
* bufferedBlockAlgorithm._append(wordArray);
|
|
666
|
+
*/
|
|
667
|
+
_append: function (data) {
|
|
668
|
+
// Convert string to WordArray, else assume WordArray already
|
|
669
|
+
if (typeof data == 'string') {
|
|
670
|
+
data = Utf8.parse(data);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// Append
|
|
674
|
+
this._data.concat(data);
|
|
675
|
+
this._nDataBytes += data.sigBytes;
|
|
676
|
+
},
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Processes available data blocks.
|
|
680
|
+
*
|
|
681
|
+
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
|
|
682
|
+
*
|
|
683
|
+
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
|
|
684
|
+
*
|
|
685
|
+
* @return {WordArray} The processed data.
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
*
|
|
689
|
+
* var processedData = bufferedBlockAlgorithm._process();
|
|
690
|
+
* var processedData = bufferedBlockAlgorithm._process(!!'flush');
|
|
691
|
+
*/
|
|
692
|
+
_process: function (doFlush) {
|
|
693
|
+
var processedWords;
|
|
694
|
+
|
|
695
|
+
// Shortcuts
|
|
696
|
+
var data = this._data;
|
|
697
|
+
var dataWords = data.words;
|
|
698
|
+
var dataSigBytes = data.sigBytes;
|
|
699
|
+
var blockSize = this.blockSize;
|
|
700
|
+
var blockSizeBytes = blockSize * 4;
|
|
701
|
+
|
|
702
|
+
// Count blocks ready
|
|
703
|
+
var nBlocksReady = dataSigBytes / blockSizeBytes;
|
|
704
|
+
if (doFlush) {
|
|
705
|
+
// Round up to include partial blocks
|
|
706
|
+
nBlocksReady = Math.ceil(nBlocksReady);
|
|
707
|
+
} else {
|
|
708
|
+
// Round down to include only full blocks,
|
|
709
|
+
// less the number of blocks that must remain in the buffer
|
|
710
|
+
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// Count words ready
|
|
714
|
+
var nWordsReady = nBlocksReady * blockSize;
|
|
715
|
+
|
|
716
|
+
// Count bytes ready
|
|
717
|
+
var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
|
|
718
|
+
|
|
719
|
+
// Process blocks
|
|
720
|
+
if (nWordsReady) {
|
|
721
|
+
for (var offset = 0; offset < nWordsReady; offset += blockSize) {
|
|
722
|
+
// Perform concrete-algorithm logic
|
|
723
|
+
this._doProcessBlock(dataWords, offset);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// Remove processed words
|
|
727
|
+
processedWords = dataWords.splice(0, nWordsReady);
|
|
728
|
+
data.sigBytes -= nBytesReady;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// Return processed words
|
|
732
|
+
return new WordArray.init(processedWords, nBytesReady);
|
|
733
|
+
},
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Creates a copy of this object.
|
|
737
|
+
*
|
|
738
|
+
* @return {Object} The clone.
|
|
739
|
+
*
|
|
740
|
+
* @example
|
|
741
|
+
*
|
|
742
|
+
* var clone = bufferedBlockAlgorithm.clone();
|
|
743
|
+
*/
|
|
744
|
+
clone: function () {
|
|
745
|
+
var clone = Base.clone.call(this);
|
|
746
|
+
clone._data = this._data.clone();
|
|
747
|
+
|
|
748
|
+
return clone;
|
|
749
|
+
},
|
|
750
|
+
|
|
751
|
+
_minBufferSize: 0
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Abstract hasher template.
|
|
756
|
+
*
|
|
757
|
+
* @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
|
|
758
|
+
*/
|
|
759
|
+
C_lib.Hasher = BufferedBlockAlgorithm.extend({
|
|
760
|
+
/**
|
|
761
|
+
* Configuration options.
|
|
762
|
+
*/
|
|
763
|
+
cfg: Base.extend(),
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Initializes a newly created hasher.
|
|
767
|
+
*
|
|
768
|
+
* @param {Object} cfg (Optional) The configuration options to use for this hash computation.
|
|
769
|
+
*
|
|
770
|
+
* @example
|
|
771
|
+
*
|
|
772
|
+
* var hasher = CryptoJS.algo.SHA256.create();
|
|
773
|
+
*/
|
|
774
|
+
init: function (cfg) {
|
|
775
|
+
// Apply config defaults
|
|
776
|
+
this.cfg = this.cfg.extend(cfg);
|
|
777
|
+
|
|
778
|
+
// Set initial values
|
|
779
|
+
this.reset();
|
|
780
|
+
},
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Resets this hasher to its initial state.
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
*
|
|
787
|
+
* hasher.reset();
|
|
788
|
+
*/
|
|
789
|
+
reset: function () {
|
|
790
|
+
// Reset data buffer
|
|
791
|
+
BufferedBlockAlgorithm.reset.call(this);
|
|
792
|
+
|
|
793
|
+
// Perform concrete-hasher logic
|
|
794
|
+
this._doReset();
|
|
795
|
+
},
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Updates this hasher with a message.
|
|
799
|
+
*
|
|
800
|
+
* @param {WordArray|string} messageUpdate The message to append.
|
|
801
|
+
*
|
|
802
|
+
* @return {Hasher} This hasher.
|
|
803
|
+
*
|
|
804
|
+
* @example
|
|
805
|
+
*
|
|
806
|
+
* hasher.update('message');
|
|
807
|
+
* hasher.update(wordArray);
|
|
808
|
+
*/
|
|
809
|
+
update: function (messageUpdate) {
|
|
810
|
+
// Append
|
|
811
|
+
this._append(messageUpdate);
|
|
812
|
+
|
|
813
|
+
// Update the hash
|
|
814
|
+
this._process();
|
|
815
|
+
|
|
816
|
+
// Chainable
|
|
817
|
+
return this;
|
|
818
|
+
},
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Finalizes the hash computation.
|
|
822
|
+
* Note that the finalize operation is effectively a destructive, read-once operation.
|
|
823
|
+
*
|
|
824
|
+
* @param {WordArray|string} messageUpdate (Optional) A final message update.
|
|
825
|
+
*
|
|
826
|
+
* @return {WordArray} The hash.
|
|
827
|
+
*
|
|
828
|
+
* @example
|
|
829
|
+
*
|
|
830
|
+
* var hash = hasher.finalize();
|
|
831
|
+
* var hash = hasher.finalize('message');
|
|
832
|
+
* var hash = hasher.finalize(wordArray);
|
|
833
|
+
*/
|
|
834
|
+
finalize: function (messageUpdate) {
|
|
835
|
+
// Final message update
|
|
836
|
+
if (messageUpdate) {
|
|
837
|
+
this._append(messageUpdate);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
// Perform concrete-hasher logic
|
|
841
|
+
var hash = this._doFinalize();
|
|
842
|
+
|
|
843
|
+
return hash;
|
|
844
|
+
},
|
|
845
|
+
|
|
846
|
+
blockSize: 512/32,
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* Creates a shortcut function to a hasher's object interface.
|
|
850
|
+
*
|
|
851
|
+
* @param {Hasher} hasher The hasher to create a helper for.
|
|
852
|
+
*
|
|
853
|
+
* @return {Function} The shortcut function.
|
|
854
|
+
*
|
|
855
|
+
* @static
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
*
|
|
859
|
+
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
|
|
860
|
+
*/
|
|
861
|
+
_createHelper: function (hasher) {
|
|
862
|
+
return function (message, cfg) {
|
|
863
|
+
return new hasher.init(cfg).finalize(message);
|
|
864
|
+
};
|
|
865
|
+
},
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* Creates a shortcut function to the HMAC's object interface.
|
|
869
|
+
*
|
|
870
|
+
* @param {Hasher} hasher The hasher to use in this HMAC helper.
|
|
871
|
+
*
|
|
872
|
+
* @return {Function} The shortcut function.
|
|
873
|
+
*
|
|
874
|
+
* @static
|
|
875
|
+
*
|
|
876
|
+
* @example
|
|
877
|
+
*
|
|
878
|
+
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
|
|
879
|
+
*/
|
|
880
|
+
_createHmacHelper: function (hasher) {
|
|
881
|
+
return function (message, key) {
|
|
882
|
+
return new C_algo.HMAC.init(hasher, key).finalize(message);
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Algorithm namespace.
|
|
889
|
+
*/
|
|
890
|
+
var C_algo = C.algo = {};
|
|
891
|
+
|
|
892
|
+
return C;
|
|
893
|
+
}(Math));
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
return CryptoJS;
|
|
897
|
+
|
|
898
|
+
}));
|
|
899
|
+
} (core$1));
|
|
900
|
+
return core$1.exports;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
var encBase64$1 = {exports: {}};
|
|
904
|
+
|
|
905
|
+
var encBase64 = encBase64$1.exports;
|
|
906
|
+
|
|
907
|
+
var hasRequiredEncBase64;
|
|
908
|
+
|
|
909
|
+
function requireEncBase64 () {
|
|
910
|
+
if (hasRequiredEncBase64) return encBase64$1.exports;
|
|
911
|
+
hasRequiredEncBase64 = 1;
|
|
912
|
+
(function (module, exports$1) {
|
|
913
|
+
(function (root, factory) {
|
|
914
|
+
{
|
|
915
|
+
// CommonJS
|
|
916
|
+
module.exports = factory(requireCore());
|
|
917
|
+
}
|
|
918
|
+
}(encBase64, function (CryptoJS) {
|
|
919
|
+
|
|
920
|
+
(function () {
|
|
921
|
+
// Shortcuts
|
|
922
|
+
var C = CryptoJS;
|
|
923
|
+
var C_lib = C.lib;
|
|
924
|
+
var WordArray = C_lib.WordArray;
|
|
925
|
+
var C_enc = C.enc;
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* Base64 encoding strategy.
|
|
929
|
+
*/
|
|
930
|
+
C_enc.Base64 = {
|
|
931
|
+
/**
|
|
932
|
+
* Converts a word array to a Base64 string.
|
|
933
|
+
*
|
|
934
|
+
* @param {WordArray} wordArray The word array.
|
|
935
|
+
*
|
|
936
|
+
* @return {string} The Base64 string.
|
|
937
|
+
*
|
|
938
|
+
* @static
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
*
|
|
942
|
+
* var base64String = CryptoJS.enc.Base64.stringify(wordArray);
|
|
943
|
+
*/
|
|
944
|
+
stringify: function (wordArray) {
|
|
945
|
+
// Shortcuts
|
|
946
|
+
var words = wordArray.words;
|
|
947
|
+
var sigBytes = wordArray.sigBytes;
|
|
948
|
+
var map = this._map;
|
|
949
|
+
|
|
950
|
+
// Clamp excess bits
|
|
951
|
+
wordArray.clamp();
|
|
952
|
+
|
|
953
|
+
// Convert
|
|
954
|
+
var base64Chars = [];
|
|
955
|
+
for (var i = 0; i < sigBytes; i += 3) {
|
|
956
|
+
var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
|
957
|
+
var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
|
|
958
|
+
var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
|
|
959
|
+
|
|
960
|
+
var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
|
|
961
|
+
|
|
962
|
+
for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
|
|
963
|
+
base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// Add padding
|
|
968
|
+
var paddingChar = map.charAt(64);
|
|
969
|
+
if (paddingChar) {
|
|
970
|
+
while (base64Chars.length % 4) {
|
|
971
|
+
base64Chars.push(paddingChar);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
return base64Chars.join('');
|
|
976
|
+
},
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Converts a Base64 string to a word array.
|
|
980
|
+
*
|
|
981
|
+
* @param {string} base64Str The Base64 string.
|
|
982
|
+
*
|
|
983
|
+
* @return {WordArray} The word array.
|
|
984
|
+
*
|
|
985
|
+
* @static
|
|
986
|
+
*
|
|
987
|
+
* @example
|
|
988
|
+
*
|
|
989
|
+
* var wordArray = CryptoJS.enc.Base64.parse(base64String);
|
|
990
|
+
*/
|
|
991
|
+
parse: function (base64Str) {
|
|
992
|
+
// Shortcuts
|
|
993
|
+
var base64StrLength = base64Str.length;
|
|
994
|
+
var map = this._map;
|
|
995
|
+
var reverseMap = this._reverseMap;
|
|
996
|
+
|
|
997
|
+
if (!reverseMap) {
|
|
998
|
+
reverseMap = this._reverseMap = [];
|
|
999
|
+
for (var j = 0; j < map.length; j++) {
|
|
1000
|
+
reverseMap[map.charCodeAt(j)] = j;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// Ignore padding
|
|
1005
|
+
var paddingChar = map.charAt(64);
|
|
1006
|
+
if (paddingChar) {
|
|
1007
|
+
var paddingIndex = base64Str.indexOf(paddingChar);
|
|
1008
|
+
if (paddingIndex !== -1) {
|
|
1009
|
+
base64StrLength = paddingIndex;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
// Convert
|
|
1014
|
+
return parseLoop(base64Str, base64StrLength, reverseMap);
|
|
1015
|
+
|
|
1016
|
+
},
|
|
1017
|
+
|
|
1018
|
+
_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
function parseLoop(base64Str, base64StrLength, reverseMap) {
|
|
1022
|
+
var words = [];
|
|
1023
|
+
var nBytes = 0;
|
|
1024
|
+
for (var i = 0; i < base64StrLength; i++) {
|
|
1025
|
+
if (i % 4) {
|
|
1026
|
+
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
|
|
1027
|
+
var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
|
|
1028
|
+
var bitsCombined = bits1 | bits2;
|
|
1029
|
+
words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
|
|
1030
|
+
nBytes++;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
return WordArray.create(words, nBytes);
|
|
1034
|
+
}
|
|
1035
|
+
}());
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
return CryptoJS.enc.Base64;
|
|
1039
|
+
|
|
1040
|
+
}));
|
|
1041
|
+
} (encBase64$1));
|
|
1042
|
+
return encBase64$1.exports;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
var md5$1 = {exports: {}};
|
|
1046
|
+
|
|
1047
|
+
var md5 = md5$1.exports;
|
|
1048
|
+
|
|
1049
|
+
var hasRequiredMd5;
|
|
1050
|
+
|
|
1051
|
+
function requireMd5 () {
|
|
1052
|
+
if (hasRequiredMd5) return md5$1.exports;
|
|
1053
|
+
hasRequiredMd5 = 1;
|
|
1054
|
+
(function (module, exports$1) {
|
|
1055
|
+
(function (root, factory) {
|
|
1056
|
+
{
|
|
1057
|
+
// CommonJS
|
|
1058
|
+
module.exports = factory(requireCore());
|
|
1059
|
+
}
|
|
1060
|
+
}(md5, function (CryptoJS) {
|
|
1061
|
+
|
|
1062
|
+
(function (Math) {
|
|
1063
|
+
// Shortcuts
|
|
1064
|
+
var C = CryptoJS;
|
|
1065
|
+
var C_lib = C.lib;
|
|
1066
|
+
var WordArray = C_lib.WordArray;
|
|
1067
|
+
var Hasher = C_lib.Hasher;
|
|
1068
|
+
var C_algo = C.algo;
|
|
1069
|
+
|
|
1070
|
+
// Constants table
|
|
1071
|
+
var T = [];
|
|
1072
|
+
|
|
1073
|
+
// Compute constants
|
|
1074
|
+
(function () {
|
|
1075
|
+
for (var i = 0; i < 64; i++) {
|
|
1076
|
+
T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
|
|
1077
|
+
}
|
|
1078
|
+
}());
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* MD5 hash algorithm.
|
|
1082
|
+
*/
|
|
1083
|
+
var MD5 = C_algo.MD5 = Hasher.extend({
|
|
1084
|
+
_doReset: function () {
|
|
1085
|
+
this._hash = new WordArray.init([
|
|
1086
|
+
0x67452301, 0xefcdab89,
|
|
1087
|
+
0x98badcfe, 0x10325476
|
|
1088
|
+
]);
|
|
1089
|
+
},
|
|
1090
|
+
|
|
1091
|
+
_doProcessBlock: function (M, offset) {
|
|
1092
|
+
// Swap endian
|
|
1093
|
+
for (var i = 0; i < 16; i++) {
|
|
1094
|
+
// Shortcuts
|
|
1095
|
+
var offset_i = offset + i;
|
|
1096
|
+
var M_offset_i = M[offset_i];
|
|
1097
|
+
|
|
1098
|
+
M[offset_i] = (
|
|
1099
|
+
(((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
|
|
1100
|
+
(((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
|
|
1101
|
+
);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
// Shortcuts
|
|
1105
|
+
var H = this._hash.words;
|
|
1106
|
+
|
|
1107
|
+
var M_offset_0 = M[offset + 0];
|
|
1108
|
+
var M_offset_1 = M[offset + 1];
|
|
1109
|
+
var M_offset_2 = M[offset + 2];
|
|
1110
|
+
var M_offset_3 = M[offset + 3];
|
|
1111
|
+
var M_offset_4 = M[offset + 4];
|
|
1112
|
+
var M_offset_5 = M[offset + 5];
|
|
1113
|
+
var M_offset_6 = M[offset + 6];
|
|
1114
|
+
var M_offset_7 = M[offset + 7];
|
|
1115
|
+
var M_offset_8 = M[offset + 8];
|
|
1116
|
+
var M_offset_9 = M[offset + 9];
|
|
1117
|
+
var M_offset_10 = M[offset + 10];
|
|
1118
|
+
var M_offset_11 = M[offset + 11];
|
|
1119
|
+
var M_offset_12 = M[offset + 12];
|
|
1120
|
+
var M_offset_13 = M[offset + 13];
|
|
1121
|
+
var M_offset_14 = M[offset + 14];
|
|
1122
|
+
var M_offset_15 = M[offset + 15];
|
|
1123
|
+
|
|
1124
|
+
// Working varialbes
|
|
1125
|
+
var a = H[0];
|
|
1126
|
+
var b = H[1];
|
|
1127
|
+
var c = H[2];
|
|
1128
|
+
var d = H[3];
|
|
1129
|
+
|
|
1130
|
+
// Computation
|
|
1131
|
+
a = FF(a, b, c, d, M_offset_0, 7, T[0]);
|
|
1132
|
+
d = FF(d, a, b, c, M_offset_1, 12, T[1]);
|
|
1133
|
+
c = FF(c, d, a, b, M_offset_2, 17, T[2]);
|
|
1134
|
+
b = FF(b, c, d, a, M_offset_3, 22, T[3]);
|
|
1135
|
+
a = FF(a, b, c, d, M_offset_4, 7, T[4]);
|
|
1136
|
+
d = FF(d, a, b, c, M_offset_5, 12, T[5]);
|
|
1137
|
+
c = FF(c, d, a, b, M_offset_6, 17, T[6]);
|
|
1138
|
+
b = FF(b, c, d, a, M_offset_7, 22, T[7]);
|
|
1139
|
+
a = FF(a, b, c, d, M_offset_8, 7, T[8]);
|
|
1140
|
+
d = FF(d, a, b, c, M_offset_9, 12, T[9]);
|
|
1141
|
+
c = FF(c, d, a, b, M_offset_10, 17, T[10]);
|
|
1142
|
+
b = FF(b, c, d, a, M_offset_11, 22, T[11]);
|
|
1143
|
+
a = FF(a, b, c, d, M_offset_12, 7, T[12]);
|
|
1144
|
+
d = FF(d, a, b, c, M_offset_13, 12, T[13]);
|
|
1145
|
+
c = FF(c, d, a, b, M_offset_14, 17, T[14]);
|
|
1146
|
+
b = FF(b, c, d, a, M_offset_15, 22, T[15]);
|
|
1147
|
+
|
|
1148
|
+
a = GG(a, b, c, d, M_offset_1, 5, T[16]);
|
|
1149
|
+
d = GG(d, a, b, c, M_offset_6, 9, T[17]);
|
|
1150
|
+
c = GG(c, d, a, b, M_offset_11, 14, T[18]);
|
|
1151
|
+
b = GG(b, c, d, a, M_offset_0, 20, T[19]);
|
|
1152
|
+
a = GG(a, b, c, d, M_offset_5, 5, T[20]);
|
|
1153
|
+
d = GG(d, a, b, c, M_offset_10, 9, T[21]);
|
|
1154
|
+
c = GG(c, d, a, b, M_offset_15, 14, T[22]);
|
|
1155
|
+
b = GG(b, c, d, a, M_offset_4, 20, T[23]);
|
|
1156
|
+
a = GG(a, b, c, d, M_offset_9, 5, T[24]);
|
|
1157
|
+
d = GG(d, a, b, c, M_offset_14, 9, T[25]);
|
|
1158
|
+
c = GG(c, d, a, b, M_offset_3, 14, T[26]);
|
|
1159
|
+
b = GG(b, c, d, a, M_offset_8, 20, T[27]);
|
|
1160
|
+
a = GG(a, b, c, d, M_offset_13, 5, T[28]);
|
|
1161
|
+
d = GG(d, a, b, c, M_offset_2, 9, T[29]);
|
|
1162
|
+
c = GG(c, d, a, b, M_offset_7, 14, T[30]);
|
|
1163
|
+
b = GG(b, c, d, a, M_offset_12, 20, T[31]);
|
|
1164
|
+
|
|
1165
|
+
a = HH(a, b, c, d, M_offset_5, 4, T[32]);
|
|
1166
|
+
d = HH(d, a, b, c, M_offset_8, 11, T[33]);
|
|
1167
|
+
c = HH(c, d, a, b, M_offset_11, 16, T[34]);
|
|
1168
|
+
b = HH(b, c, d, a, M_offset_14, 23, T[35]);
|
|
1169
|
+
a = HH(a, b, c, d, M_offset_1, 4, T[36]);
|
|
1170
|
+
d = HH(d, a, b, c, M_offset_4, 11, T[37]);
|
|
1171
|
+
c = HH(c, d, a, b, M_offset_7, 16, T[38]);
|
|
1172
|
+
b = HH(b, c, d, a, M_offset_10, 23, T[39]);
|
|
1173
|
+
a = HH(a, b, c, d, M_offset_13, 4, T[40]);
|
|
1174
|
+
d = HH(d, a, b, c, M_offset_0, 11, T[41]);
|
|
1175
|
+
c = HH(c, d, a, b, M_offset_3, 16, T[42]);
|
|
1176
|
+
b = HH(b, c, d, a, M_offset_6, 23, T[43]);
|
|
1177
|
+
a = HH(a, b, c, d, M_offset_9, 4, T[44]);
|
|
1178
|
+
d = HH(d, a, b, c, M_offset_12, 11, T[45]);
|
|
1179
|
+
c = HH(c, d, a, b, M_offset_15, 16, T[46]);
|
|
1180
|
+
b = HH(b, c, d, a, M_offset_2, 23, T[47]);
|
|
1181
|
+
|
|
1182
|
+
a = II(a, b, c, d, M_offset_0, 6, T[48]);
|
|
1183
|
+
d = II(d, a, b, c, M_offset_7, 10, T[49]);
|
|
1184
|
+
c = II(c, d, a, b, M_offset_14, 15, T[50]);
|
|
1185
|
+
b = II(b, c, d, a, M_offset_5, 21, T[51]);
|
|
1186
|
+
a = II(a, b, c, d, M_offset_12, 6, T[52]);
|
|
1187
|
+
d = II(d, a, b, c, M_offset_3, 10, T[53]);
|
|
1188
|
+
c = II(c, d, a, b, M_offset_10, 15, T[54]);
|
|
1189
|
+
b = II(b, c, d, a, M_offset_1, 21, T[55]);
|
|
1190
|
+
a = II(a, b, c, d, M_offset_8, 6, T[56]);
|
|
1191
|
+
d = II(d, a, b, c, M_offset_15, 10, T[57]);
|
|
1192
|
+
c = II(c, d, a, b, M_offset_6, 15, T[58]);
|
|
1193
|
+
b = II(b, c, d, a, M_offset_13, 21, T[59]);
|
|
1194
|
+
a = II(a, b, c, d, M_offset_4, 6, T[60]);
|
|
1195
|
+
d = II(d, a, b, c, M_offset_11, 10, T[61]);
|
|
1196
|
+
c = II(c, d, a, b, M_offset_2, 15, T[62]);
|
|
1197
|
+
b = II(b, c, d, a, M_offset_9, 21, T[63]);
|
|
1198
|
+
|
|
1199
|
+
// Intermediate hash value
|
|
1200
|
+
H[0] = (H[0] + a) | 0;
|
|
1201
|
+
H[1] = (H[1] + b) | 0;
|
|
1202
|
+
H[2] = (H[2] + c) | 0;
|
|
1203
|
+
H[3] = (H[3] + d) | 0;
|
|
1204
|
+
},
|
|
1205
|
+
|
|
1206
|
+
_doFinalize: function () {
|
|
1207
|
+
// Shortcuts
|
|
1208
|
+
var data = this._data;
|
|
1209
|
+
var dataWords = data.words;
|
|
1210
|
+
|
|
1211
|
+
var nBitsTotal = this._nDataBytes * 8;
|
|
1212
|
+
var nBitsLeft = data.sigBytes * 8;
|
|
1213
|
+
|
|
1214
|
+
// Add padding
|
|
1215
|
+
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
|
1216
|
+
|
|
1217
|
+
var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
|
|
1218
|
+
var nBitsTotalL = nBitsTotal;
|
|
1219
|
+
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
|
|
1220
|
+
(((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
|
|
1221
|
+
(((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
|
|
1222
|
+
);
|
|
1223
|
+
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
|
|
1224
|
+
(((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
|
|
1225
|
+
(((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
|
|
1226
|
+
);
|
|
1227
|
+
|
|
1228
|
+
data.sigBytes = (dataWords.length + 1) * 4;
|
|
1229
|
+
|
|
1230
|
+
// Hash final blocks
|
|
1231
|
+
this._process();
|
|
1232
|
+
|
|
1233
|
+
// Shortcuts
|
|
1234
|
+
var hash = this._hash;
|
|
1235
|
+
var H = hash.words;
|
|
1236
|
+
|
|
1237
|
+
// Swap endian
|
|
1238
|
+
for (var i = 0; i < 4; i++) {
|
|
1239
|
+
// Shortcut
|
|
1240
|
+
var H_i = H[i];
|
|
1241
|
+
|
|
1242
|
+
H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
|
|
1243
|
+
(((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// Return final computed hash
|
|
1247
|
+
return hash;
|
|
1248
|
+
},
|
|
1249
|
+
|
|
1250
|
+
clone: function () {
|
|
1251
|
+
var clone = Hasher.clone.call(this);
|
|
1252
|
+
clone._hash = this._hash.clone();
|
|
1253
|
+
|
|
1254
|
+
return clone;
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
|
|
1258
|
+
function FF(a, b, c, d, x, s, t) {
|
|
1259
|
+
var n = a + ((b & c) | (~b & d)) + x + t;
|
|
1260
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
function GG(a, b, c, d, x, s, t) {
|
|
1264
|
+
var n = a + ((b & d) | (c & ~d)) + x + t;
|
|
1265
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
function HH(a, b, c, d, x, s, t) {
|
|
1269
|
+
var n = a + (b ^ c ^ d) + x + t;
|
|
1270
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
function II(a, b, c, d, x, s, t) {
|
|
1274
|
+
var n = a + (c ^ (b | ~d)) + x + t;
|
|
1275
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* Shortcut function to the hasher's object interface.
|
|
1280
|
+
*
|
|
1281
|
+
* @param {WordArray|string} message The message to hash.
|
|
1282
|
+
*
|
|
1283
|
+
* @return {WordArray} The hash.
|
|
1284
|
+
*
|
|
1285
|
+
* @static
|
|
1286
|
+
*
|
|
1287
|
+
* @example
|
|
1288
|
+
*
|
|
1289
|
+
* var hash = CryptoJS.MD5('message');
|
|
1290
|
+
* var hash = CryptoJS.MD5(wordArray);
|
|
1291
|
+
*/
|
|
1292
|
+
C.MD5 = Hasher._createHelper(MD5);
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* Shortcut function to the HMAC's object interface.
|
|
1296
|
+
*
|
|
1297
|
+
* @param {WordArray|string} message The message to hash.
|
|
1298
|
+
* @param {WordArray|string} key The secret key.
|
|
1299
|
+
*
|
|
1300
|
+
* @return {WordArray} The HMAC.
|
|
1301
|
+
*
|
|
1302
|
+
* @static
|
|
1303
|
+
*
|
|
1304
|
+
* @example
|
|
1305
|
+
*
|
|
1306
|
+
* var hmac = CryptoJS.HmacMD5(message, key);
|
|
1307
|
+
*/
|
|
1308
|
+
C.HmacMD5 = Hasher._createHmacHelper(MD5);
|
|
1309
|
+
}(Math));
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
return CryptoJS.MD5;
|
|
1313
|
+
|
|
1314
|
+
}));
|
|
1315
|
+
} (md5$1));
|
|
1316
|
+
return md5$1.exports;
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
var evpkdf$1 = {exports: {}};
|
|
1320
|
+
|
|
1321
|
+
var sha1$1 = {exports: {}};
|
|
1322
|
+
|
|
1323
|
+
var sha1 = sha1$1.exports;
|
|
1324
|
+
|
|
1325
|
+
var hasRequiredSha1;
|
|
1326
|
+
|
|
1327
|
+
function requireSha1 () {
|
|
1328
|
+
if (hasRequiredSha1) return sha1$1.exports;
|
|
1329
|
+
hasRequiredSha1 = 1;
|
|
1330
|
+
(function (module, exports$1) {
|
|
1331
|
+
(function (root, factory) {
|
|
1332
|
+
{
|
|
1333
|
+
// CommonJS
|
|
1334
|
+
module.exports = factory(requireCore());
|
|
1335
|
+
}
|
|
1336
|
+
}(sha1, function (CryptoJS) {
|
|
1337
|
+
|
|
1338
|
+
(function () {
|
|
1339
|
+
// Shortcuts
|
|
1340
|
+
var C = CryptoJS;
|
|
1341
|
+
var C_lib = C.lib;
|
|
1342
|
+
var WordArray = C_lib.WordArray;
|
|
1343
|
+
var Hasher = C_lib.Hasher;
|
|
1344
|
+
var C_algo = C.algo;
|
|
1345
|
+
|
|
1346
|
+
// Reusable object
|
|
1347
|
+
var W = [];
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
* SHA-1 hash algorithm.
|
|
1351
|
+
*/
|
|
1352
|
+
var SHA1 = C_algo.SHA1 = Hasher.extend({
|
|
1353
|
+
_doReset: function () {
|
|
1354
|
+
this._hash = new WordArray.init([
|
|
1355
|
+
0x67452301, 0xefcdab89,
|
|
1356
|
+
0x98badcfe, 0x10325476,
|
|
1357
|
+
0xc3d2e1f0
|
|
1358
|
+
]);
|
|
1359
|
+
},
|
|
1360
|
+
|
|
1361
|
+
_doProcessBlock: function (M, offset) {
|
|
1362
|
+
// Shortcut
|
|
1363
|
+
var H = this._hash.words;
|
|
1364
|
+
|
|
1365
|
+
// Working variables
|
|
1366
|
+
var a = H[0];
|
|
1367
|
+
var b = H[1];
|
|
1368
|
+
var c = H[2];
|
|
1369
|
+
var d = H[3];
|
|
1370
|
+
var e = H[4];
|
|
1371
|
+
|
|
1372
|
+
// Computation
|
|
1373
|
+
for (var i = 0; i < 80; i++) {
|
|
1374
|
+
if (i < 16) {
|
|
1375
|
+
W[i] = M[offset + i] | 0;
|
|
1376
|
+
} else {
|
|
1377
|
+
var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
|
|
1378
|
+
W[i] = (n << 1) | (n >>> 31);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
var t = ((a << 5) | (a >>> 27)) + e + W[i];
|
|
1382
|
+
if (i < 20) {
|
|
1383
|
+
t += ((b & c) | (~b & d)) + 0x5a827999;
|
|
1384
|
+
} else if (i < 40) {
|
|
1385
|
+
t += (b ^ c ^ d) + 0x6ed9eba1;
|
|
1386
|
+
} else if (i < 60) {
|
|
1387
|
+
t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
|
|
1388
|
+
} else /* if (i < 80) */ {
|
|
1389
|
+
t += (b ^ c ^ d) - 0x359d3e2a;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
e = d;
|
|
1393
|
+
d = c;
|
|
1394
|
+
c = (b << 30) | (b >>> 2);
|
|
1395
|
+
b = a;
|
|
1396
|
+
a = t;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
// Intermediate hash value
|
|
1400
|
+
H[0] = (H[0] + a) | 0;
|
|
1401
|
+
H[1] = (H[1] + b) | 0;
|
|
1402
|
+
H[2] = (H[2] + c) | 0;
|
|
1403
|
+
H[3] = (H[3] + d) | 0;
|
|
1404
|
+
H[4] = (H[4] + e) | 0;
|
|
1405
|
+
},
|
|
1406
|
+
|
|
1407
|
+
_doFinalize: function () {
|
|
1408
|
+
// Shortcuts
|
|
1409
|
+
var data = this._data;
|
|
1410
|
+
var dataWords = data.words;
|
|
1411
|
+
|
|
1412
|
+
var nBitsTotal = this._nDataBytes * 8;
|
|
1413
|
+
var nBitsLeft = data.sigBytes * 8;
|
|
1414
|
+
|
|
1415
|
+
// Add padding
|
|
1416
|
+
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
|
1417
|
+
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
|
|
1418
|
+
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
|
|
1419
|
+
data.sigBytes = dataWords.length * 4;
|
|
1420
|
+
|
|
1421
|
+
// Hash final blocks
|
|
1422
|
+
this._process();
|
|
1423
|
+
|
|
1424
|
+
// Return final computed hash
|
|
1425
|
+
return this._hash;
|
|
1426
|
+
},
|
|
1427
|
+
|
|
1428
|
+
clone: function () {
|
|
1429
|
+
var clone = Hasher.clone.call(this);
|
|
1430
|
+
clone._hash = this._hash.clone();
|
|
1431
|
+
|
|
1432
|
+
return clone;
|
|
1433
|
+
}
|
|
1434
|
+
});
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* Shortcut function to the hasher's object interface.
|
|
1438
|
+
*
|
|
1439
|
+
* @param {WordArray|string} message The message to hash.
|
|
1440
|
+
*
|
|
1441
|
+
* @return {WordArray} The hash.
|
|
1442
|
+
*
|
|
1443
|
+
* @static
|
|
1444
|
+
*
|
|
1445
|
+
* @example
|
|
1446
|
+
*
|
|
1447
|
+
* var hash = CryptoJS.SHA1('message');
|
|
1448
|
+
* var hash = CryptoJS.SHA1(wordArray);
|
|
1449
|
+
*/
|
|
1450
|
+
C.SHA1 = Hasher._createHelper(SHA1);
|
|
1451
|
+
|
|
1452
|
+
/**
|
|
1453
|
+
* Shortcut function to the HMAC's object interface.
|
|
1454
|
+
*
|
|
1455
|
+
* @param {WordArray|string} message The message to hash.
|
|
1456
|
+
* @param {WordArray|string} key The secret key.
|
|
1457
|
+
*
|
|
1458
|
+
* @return {WordArray} The HMAC.
|
|
1459
|
+
*
|
|
1460
|
+
* @static
|
|
1461
|
+
*
|
|
1462
|
+
* @example
|
|
1463
|
+
*
|
|
1464
|
+
* var hmac = CryptoJS.HmacSHA1(message, key);
|
|
1465
|
+
*/
|
|
1466
|
+
C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
|
|
1467
|
+
}());
|
|
1468
|
+
|
|
1469
|
+
|
|
1470
|
+
return CryptoJS.SHA1;
|
|
1471
|
+
|
|
1472
|
+
}));
|
|
1473
|
+
} (sha1$1));
|
|
1474
|
+
return sha1$1.exports;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
var hmac$1 = {exports: {}};
|
|
1478
|
+
|
|
1479
|
+
var hmac = hmac$1.exports;
|
|
1480
|
+
|
|
1481
|
+
var hasRequiredHmac;
|
|
1482
|
+
|
|
1483
|
+
function requireHmac () {
|
|
1484
|
+
if (hasRequiredHmac) return hmac$1.exports;
|
|
1485
|
+
hasRequiredHmac = 1;
|
|
1486
|
+
(function (module, exports$1) {
|
|
1487
|
+
(function (root, factory) {
|
|
1488
|
+
{
|
|
1489
|
+
// CommonJS
|
|
1490
|
+
module.exports = factory(requireCore());
|
|
1491
|
+
}
|
|
1492
|
+
}(hmac, function (CryptoJS) {
|
|
1493
|
+
|
|
1494
|
+
(function () {
|
|
1495
|
+
// Shortcuts
|
|
1496
|
+
var C = CryptoJS;
|
|
1497
|
+
var C_lib = C.lib;
|
|
1498
|
+
var Base = C_lib.Base;
|
|
1499
|
+
var C_enc = C.enc;
|
|
1500
|
+
var Utf8 = C_enc.Utf8;
|
|
1501
|
+
var C_algo = C.algo;
|
|
1502
|
+
|
|
1503
|
+
/**
|
|
1504
|
+
* HMAC algorithm.
|
|
1505
|
+
*/
|
|
1506
|
+
C_algo.HMAC = Base.extend({
|
|
1507
|
+
/**
|
|
1508
|
+
* Initializes a newly created HMAC.
|
|
1509
|
+
*
|
|
1510
|
+
* @param {Hasher} hasher The hash algorithm to use.
|
|
1511
|
+
* @param {WordArray|string} key The secret key.
|
|
1512
|
+
*
|
|
1513
|
+
* @example
|
|
1514
|
+
*
|
|
1515
|
+
* var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
|
|
1516
|
+
*/
|
|
1517
|
+
init: function (hasher, key) {
|
|
1518
|
+
// Init hasher
|
|
1519
|
+
hasher = this._hasher = new hasher.init();
|
|
1520
|
+
|
|
1521
|
+
// Convert string to WordArray, else assume WordArray already
|
|
1522
|
+
if (typeof key == 'string') {
|
|
1523
|
+
key = Utf8.parse(key);
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
// Shortcuts
|
|
1527
|
+
var hasherBlockSize = hasher.blockSize;
|
|
1528
|
+
var hasherBlockSizeBytes = hasherBlockSize * 4;
|
|
1529
|
+
|
|
1530
|
+
// Allow arbitrary length keys
|
|
1531
|
+
if (key.sigBytes > hasherBlockSizeBytes) {
|
|
1532
|
+
key = hasher.finalize(key);
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
// Clamp excess bits
|
|
1536
|
+
key.clamp();
|
|
1537
|
+
|
|
1538
|
+
// Clone key for inner and outer pads
|
|
1539
|
+
var oKey = this._oKey = key.clone();
|
|
1540
|
+
var iKey = this._iKey = key.clone();
|
|
1541
|
+
|
|
1542
|
+
// Shortcuts
|
|
1543
|
+
var oKeyWords = oKey.words;
|
|
1544
|
+
var iKeyWords = iKey.words;
|
|
1545
|
+
|
|
1546
|
+
// XOR keys with pad constants
|
|
1547
|
+
for (var i = 0; i < hasherBlockSize; i++) {
|
|
1548
|
+
oKeyWords[i] ^= 0x5c5c5c5c;
|
|
1549
|
+
iKeyWords[i] ^= 0x36363636;
|
|
1550
|
+
}
|
|
1551
|
+
oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
|
|
1552
|
+
|
|
1553
|
+
// Set initial values
|
|
1554
|
+
this.reset();
|
|
1555
|
+
},
|
|
1556
|
+
|
|
1557
|
+
/**
|
|
1558
|
+
* Resets this HMAC to its initial state.
|
|
1559
|
+
*
|
|
1560
|
+
* @example
|
|
1561
|
+
*
|
|
1562
|
+
* hmacHasher.reset();
|
|
1563
|
+
*/
|
|
1564
|
+
reset: function () {
|
|
1565
|
+
// Shortcut
|
|
1566
|
+
var hasher = this._hasher;
|
|
1567
|
+
|
|
1568
|
+
// Reset
|
|
1569
|
+
hasher.reset();
|
|
1570
|
+
hasher.update(this._iKey);
|
|
1571
|
+
},
|
|
1572
|
+
|
|
1573
|
+
/**
|
|
1574
|
+
* Updates this HMAC with a message.
|
|
1575
|
+
*
|
|
1576
|
+
* @param {WordArray|string} messageUpdate The message to append.
|
|
1577
|
+
*
|
|
1578
|
+
* @return {HMAC} This HMAC instance.
|
|
1579
|
+
*
|
|
1580
|
+
* @example
|
|
1581
|
+
*
|
|
1582
|
+
* hmacHasher.update('message');
|
|
1583
|
+
* hmacHasher.update(wordArray);
|
|
1584
|
+
*/
|
|
1585
|
+
update: function (messageUpdate) {
|
|
1586
|
+
this._hasher.update(messageUpdate);
|
|
1587
|
+
|
|
1588
|
+
// Chainable
|
|
1589
|
+
return this;
|
|
1590
|
+
},
|
|
1591
|
+
|
|
1592
|
+
/**
|
|
1593
|
+
* Finalizes the HMAC computation.
|
|
1594
|
+
* Note that the finalize operation is effectively a destructive, read-once operation.
|
|
1595
|
+
*
|
|
1596
|
+
* @param {WordArray|string} messageUpdate (Optional) A final message update.
|
|
1597
|
+
*
|
|
1598
|
+
* @return {WordArray} The HMAC.
|
|
1599
|
+
*
|
|
1600
|
+
* @example
|
|
1601
|
+
*
|
|
1602
|
+
* var hmac = hmacHasher.finalize();
|
|
1603
|
+
* var hmac = hmacHasher.finalize('message');
|
|
1604
|
+
* var hmac = hmacHasher.finalize(wordArray);
|
|
1605
|
+
*/
|
|
1606
|
+
finalize: function (messageUpdate) {
|
|
1607
|
+
// Shortcut
|
|
1608
|
+
var hasher = this._hasher;
|
|
1609
|
+
|
|
1610
|
+
// Compute HMAC
|
|
1611
|
+
var innerHash = hasher.finalize(messageUpdate);
|
|
1612
|
+
hasher.reset();
|
|
1613
|
+
var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
|
|
1614
|
+
|
|
1615
|
+
return hmac;
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
}());
|
|
1619
|
+
|
|
1620
|
+
|
|
1621
|
+
}));
|
|
1622
|
+
} (hmac$1));
|
|
1623
|
+
return hmac$1.exports;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
var evpkdf = evpkdf$1.exports;
|
|
1627
|
+
|
|
1628
|
+
var hasRequiredEvpkdf;
|
|
1629
|
+
|
|
1630
|
+
function requireEvpkdf () {
|
|
1631
|
+
if (hasRequiredEvpkdf) return evpkdf$1.exports;
|
|
1632
|
+
hasRequiredEvpkdf = 1;
|
|
1633
|
+
(function (module, exports$1) {
|
|
1634
|
+
(function (root, factory, undef) {
|
|
1635
|
+
{
|
|
1636
|
+
// CommonJS
|
|
1637
|
+
module.exports = factory(requireCore(), requireSha1(), requireHmac());
|
|
1638
|
+
}
|
|
1639
|
+
}(evpkdf, function (CryptoJS) {
|
|
1640
|
+
|
|
1641
|
+
(function () {
|
|
1642
|
+
// Shortcuts
|
|
1643
|
+
var C = CryptoJS;
|
|
1644
|
+
var C_lib = C.lib;
|
|
1645
|
+
var Base = C_lib.Base;
|
|
1646
|
+
var WordArray = C_lib.WordArray;
|
|
1647
|
+
var C_algo = C.algo;
|
|
1648
|
+
var MD5 = C_algo.MD5;
|
|
1649
|
+
|
|
1650
|
+
/**
|
|
1651
|
+
* This key derivation function is meant to conform with EVP_BytesToKey.
|
|
1652
|
+
* www.openssl.org/docs/crypto/EVP_BytesToKey.html
|
|
1653
|
+
*/
|
|
1654
|
+
var EvpKDF = C_algo.EvpKDF = Base.extend({
|
|
1655
|
+
/**
|
|
1656
|
+
* Configuration options.
|
|
1657
|
+
*
|
|
1658
|
+
* @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
|
|
1659
|
+
* @property {Hasher} hasher The hash algorithm to use. Default: MD5
|
|
1660
|
+
* @property {number} iterations The number of iterations to perform. Default: 1
|
|
1661
|
+
*/
|
|
1662
|
+
cfg: Base.extend({
|
|
1663
|
+
keySize: 128/32,
|
|
1664
|
+
hasher: MD5,
|
|
1665
|
+
iterations: 1
|
|
1666
|
+
}),
|
|
1667
|
+
|
|
1668
|
+
/**
|
|
1669
|
+
* Initializes a newly created key derivation function.
|
|
1670
|
+
*
|
|
1671
|
+
* @param {Object} cfg (Optional) The configuration options to use for the derivation.
|
|
1672
|
+
*
|
|
1673
|
+
* @example
|
|
1674
|
+
*
|
|
1675
|
+
* var kdf = CryptoJS.algo.EvpKDF.create();
|
|
1676
|
+
* var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
|
|
1677
|
+
* var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
|
|
1678
|
+
*/
|
|
1679
|
+
init: function (cfg) {
|
|
1680
|
+
this.cfg = this.cfg.extend(cfg);
|
|
1681
|
+
},
|
|
1682
|
+
|
|
1683
|
+
/**
|
|
1684
|
+
* Derives a key from a password.
|
|
1685
|
+
*
|
|
1686
|
+
* @param {WordArray|string} password The password.
|
|
1687
|
+
* @param {WordArray|string} salt A salt.
|
|
1688
|
+
*
|
|
1689
|
+
* @return {WordArray} The derived key.
|
|
1690
|
+
*
|
|
1691
|
+
* @example
|
|
1692
|
+
*
|
|
1693
|
+
* var key = kdf.compute(password, salt);
|
|
1694
|
+
*/
|
|
1695
|
+
compute: function (password, salt) {
|
|
1696
|
+
var block;
|
|
1697
|
+
|
|
1698
|
+
// Shortcut
|
|
1699
|
+
var cfg = this.cfg;
|
|
1700
|
+
|
|
1701
|
+
// Init hasher
|
|
1702
|
+
var hasher = cfg.hasher.create();
|
|
1703
|
+
|
|
1704
|
+
// Initial values
|
|
1705
|
+
var derivedKey = WordArray.create();
|
|
1706
|
+
|
|
1707
|
+
// Shortcuts
|
|
1708
|
+
var derivedKeyWords = derivedKey.words;
|
|
1709
|
+
var keySize = cfg.keySize;
|
|
1710
|
+
var iterations = cfg.iterations;
|
|
1711
|
+
|
|
1712
|
+
// Generate key
|
|
1713
|
+
while (derivedKeyWords.length < keySize) {
|
|
1714
|
+
if (block) {
|
|
1715
|
+
hasher.update(block);
|
|
1716
|
+
}
|
|
1717
|
+
block = hasher.update(password).finalize(salt);
|
|
1718
|
+
hasher.reset();
|
|
1719
|
+
|
|
1720
|
+
// Iterations
|
|
1721
|
+
for (var i = 1; i < iterations; i++) {
|
|
1722
|
+
block = hasher.finalize(block);
|
|
1723
|
+
hasher.reset();
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
derivedKey.concat(block);
|
|
1727
|
+
}
|
|
1728
|
+
derivedKey.sigBytes = keySize * 4;
|
|
1729
|
+
|
|
1730
|
+
return derivedKey;
|
|
1731
|
+
}
|
|
1732
|
+
});
|
|
1733
|
+
|
|
1734
|
+
/**
|
|
1735
|
+
* Derives a key from a password.
|
|
1736
|
+
*
|
|
1737
|
+
* @param {WordArray|string} password The password.
|
|
1738
|
+
* @param {WordArray|string} salt A salt.
|
|
1739
|
+
* @param {Object} cfg (Optional) The configuration options to use for this computation.
|
|
1740
|
+
*
|
|
1741
|
+
* @return {WordArray} The derived key.
|
|
1742
|
+
*
|
|
1743
|
+
* @static
|
|
1744
|
+
*
|
|
1745
|
+
* @example
|
|
1746
|
+
*
|
|
1747
|
+
* var key = CryptoJS.EvpKDF(password, salt);
|
|
1748
|
+
* var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
|
|
1749
|
+
* var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
|
|
1750
|
+
*/
|
|
1751
|
+
C.EvpKDF = function (password, salt, cfg) {
|
|
1752
|
+
return EvpKDF.create(cfg).compute(password, salt);
|
|
1753
|
+
};
|
|
1754
|
+
}());
|
|
1755
|
+
|
|
1756
|
+
|
|
1757
|
+
return CryptoJS.EvpKDF;
|
|
1758
|
+
|
|
1759
|
+
}));
|
|
1760
|
+
} (evpkdf$1));
|
|
1761
|
+
return evpkdf$1.exports;
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
var cipherCore$1 = {exports: {}};
|
|
1765
|
+
|
|
1766
|
+
var cipherCore = cipherCore$1.exports;
|
|
1767
|
+
|
|
1768
|
+
var hasRequiredCipherCore;
|
|
1769
|
+
|
|
1770
|
+
function requireCipherCore () {
|
|
1771
|
+
if (hasRequiredCipherCore) return cipherCore$1.exports;
|
|
1772
|
+
hasRequiredCipherCore = 1;
|
|
1773
|
+
(function (module, exports$1) {
|
|
1774
|
+
(function (root, factory, undef) {
|
|
1775
|
+
{
|
|
1776
|
+
// CommonJS
|
|
1777
|
+
module.exports = factory(requireCore(), requireEvpkdf());
|
|
1778
|
+
}
|
|
1779
|
+
}(cipherCore, function (CryptoJS) {
|
|
1780
|
+
|
|
1781
|
+
/**
|
|
1782
|
+
* Cipher core components.
|
|
1783
|
+
*/
|
|
1784
|
+
CryptoJS.lib.Cipher || (function (undefined$1) {
|
|
1785
|
+
// Shortcuts
|
|
1786
|
+
var C = CryptoJS;
|
|
1787
|
+
var C_lib = C.lib;
|
|
1788
|
+
var Base = C_lib.Base;
|
|
1789
|
+
var WordArray = C_lib.WordArray;
|
|
1790
|
+
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
|
|
1791
|
+
var C_enc = C.enc;
|
|
1792
|
+
C_enc.Utf8;
|
|
1793
|
+
var Base64 = C_enc.Base64;
|
|
1794
|
+
var C_algo = C.algo;
|
|
1795
|
+
var EvpKDF = C_algo.EvpKDF;
|
|
1796
|
+
|
|
1797
|
+
/**
|
|
1798
|
+
* Abstract base cipher template.
|
|
1799
|
+
*
|
|
1800
|
+
* @property {number} keySize This cipher's key size. Default: 4 (128 bits)
|
|
1801
|
+
* @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
|
|
1802
|
+
* @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
|
|
1803
|
+
* @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
|
|
1804
|
+
*/
|
|
1805
|
+
var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
|
|
1806
|
+
/**
|
|
1807
|
+
* Configuration options.
|
|
1808
|
+
*
|
|
1809
|
+
* @property {WordArray} iv The IV to use for this operation.
|
|
1810
|
+
*/
|
|
1811
|
+
cfg: Base.extend(),
|
|
1812
|
+
|
|
1813
|
+
/**
|
|
1814
|
+
* Creates this cipher in encryption mode.
|
|
1815
|
+
*
|
|
1816
|
+
* @param {WordArray} key The key.
|
|
1817
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
1818
|
+
*
|
|
1819
|
+
* @return {Cipher} A cipher instance.
|
|
1820
|
+
*
|
|
1821
|
+
* @static
|
|
1822
|
+
*
|
|
1823
|
+
* @example
|
|
1824
|
+
*
|
|
1825
|
+
* var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
|
|
1826
|
+
*/
|
|
1827
|
+
createEncryptor: function (key, cfg) {
|
|
1828
|
+
return this.create(this._ENC_XFORM_MODE, key, cfg);
|
|
1829
|
+
},
|
|
1830
|
+
|
|
1831
|
+
/**
|
|
1832
|
+
* Creates this cipher in decryption mode.
|
|
1833
|
+
*
|
|
1834
|
+
* @param {WordArray} key The key.
|
|
1835
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
1836
|
+
*
|
|
1837
|
+
* @return {Cipher} A cipher instance.
|
|
1838
|
+
*
|
|
1839
|
+
* @static
|
|
1840
|
+
*
|
|
1841
|
+
* @example
|
|
1842
|
+
*
|
|
1843
|
+
* var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
|
|
1844
|
+
*/
|
|
1845
|
+
createDecryptor: function (key, cfg) {
|
|
1846
|
+
return this.create(this._DEC_XFORM_MODE, key, cfg);
|
|
1847
|
+
},
|
|
1848
|
+
|
|
1849
|
+
/**
|
|
1850
|
+
* Initializes a newly created cipher.
|
|
1851
|
+
*
|
|
1852
|
+
* @param {number} xformMode Either the encryption or decryption transormation mode constant.
|
|
1853
|
+
* @param {WordArray} key The key.
|
|
1854
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
1855
|
+
*
|
|
1856
|
+
* @example
|
|
1857
|
+
*
|
|
1858
|
+
* var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
|
|
1859
|
+
*/
|
|
1860
|
+
init: function (xformMode, key, cfg) {
|
|
1861
|
+
// Apply config defaults
|
|
1862
|
+
this.cfg = this.cfg.extend(cfg);
|
|
1863
|
+
|
|
1864
|
+
// Store transform mode and key
|
|
1865
|
+
this._xformMode = xformMode;
|
|
1866
|
+
this._key = key;
|
|
1867
|
+
|
|
1868
|
+
// Set initial values
|
|
1869
|
+
this.reset();
|
|
1870
|
+
},
|
|
1871
|
+
|
|
1872
|
+
/**
|
|
1873
|
+
* Resets this cipher to its initial state.
|
|
1874
|
+
*
|
|
1875
|
+
* @example
|
|
1876
|
+
*
|
|
1877
|
+
* cipher.reset();
|
|
1878
|
+
*/
|
|
1879
|
+
reset: function () {
|
|
1880
|
+
// Reset data buffer
|
|
1881
|
+
BufferedBlockAlgorithm.reset.call(this);
|
|
1882
|
+
|
|
1883
|
+
// Perform concrete-cipher logic
|
|
1884
|
+
this._doReset();
|
|
1885
|
+
},
|
|
1886
|
+
|
|
1887
|
+
/**
|
|
1888
|
+
* Adds data to be encrypted or decrypted.
|
|
1889
|
+
*
|
|
1890
|
+
* @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
|
|
1891
|
+
*
|
|
1892
|
+
* @return {WordArray} The data after processing.
|
|
1893
|
+
*
|
|
1894
|
+
* @example
|
|
1895
|
+
*
|
|
1896
|
+
* var encrypted = cipher.process('data');
|
|
1897
|
+
* var encrypted = cipher.process(wordArray);
|
|
1898
|
+
*/
|
|
1899
|
+
process: function (dataUpdate) {
|
|
1900
|
+
// Append
|
|
1901
|
+
this._append(dataUpdate);
|
|
1902
|
+
|
|
1903
|
+
// Process available blocks
|
|
1904
|
+
return this._process();
|
|
1905
|
+
},
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* Finalizes the encryption or decryption process.
|
|
1909
|
+
* Note that the finalize operation is effectively a destructive, read-once operation.
|
|
1910
|
+
*
|
|
1911
|
+
* @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
|
|
1912
|
+
*
|
|
1913
|
+
* @return {WordArray} The data after final processing.
|
|
1914
|
+
*
|
|
1915
|
+
* @example
|
|
1916
|
+
*
|
|
1917
|
+
* var encrypted = cipher.finalize();
|
|
1918
|
+
* var encrypted = cipher.finalize('data');
|
|
1919
|
+
* var encrypted = cipher.finalize(wordArray);
|
|
1920
|
+
*/
|
|
1921
|
+
finalize: function (dataUpdate) {
|
|
1922
|
+
// Final data update
|
|
1923
|
+
if (dataUpdate) {
|
|
1924
|
+
this._append(dataUpdate);
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
// Perform concrete-cipher logic
|
|
1928
|
+
var finalProcessedData = this._doFinalize();
|
|
1929
|
+
|
|
1930
|
+
return finalProcessedData;
|
|
1931
|
+
},
|
|
1932
|
+
|
|
1933
|
+
keySize: 128/32,
|
|
1934
|
+
|
|
1935
|
+
ivSize: 128/32,
|
|
1936
|
+
|
|
1937
|
+
_ENC_XFORM_MODE: 1,
|
|
1938
|
+
|
|
1939
|
+
_DEC_XFORM_MODE: 2,
|
|
1940
|
+
|
|
1941
|
+
/**
|
|
1942
|
+
* Creates shortcut functions to a cipher's object interface.
|
|
1943
|
+
*
|
|
1944
|
+
* @param {Cipher} cipher The cipher to create a helper for.
|
|
1945
|
+
*
|
|
1946
|
+
* @return {Object} An object with encrypt and decrypt shortcut functions.
|
|
1947
|
+
*
|
|
1948
|
+
* @static
|
|
1949
|
+
*
|
|
1950
|
+
* @example
|
|
1951
|
+
*
|
|
1952
|
+
* var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
|
|
1953
|
+
*/
|
|
1954
|
+
_createHelper: (function () {
|
|
1955
|
+
function selectCipherStrategy(key) {
|
|
1956
|
+
if (typeof key == 'string') {
|
|
1957
|
+
return PasswordBasedCipher;
|
|
1958
|
+
} else {
|
|
1959
|
+
return SerializableCipher;
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
return function (cipher) {
|
|
1964
|
+
return {
|
|
1965
|
+
encrypt: function (message, key, cfg) {
|
|
1966
|
+
return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
|
|
1967
|
+
},
|
|
1968
|
+
|
|
1969
|
+
decrypt: function (ciphertext, key, cfg) {
|
|
1970
|
+
return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
};
|
|
1974
|
+
}())
|
|
1975
|
+
});
|
|
1976
|
+
|
|
1977
|
+
/**
|
|
1978
|
+
* Abstract base stream cipher template.
|
|
1979
|
+
*
|
|
1980
|
+
* @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
|
|
1981
|
+
*/
|
|
1982
|
+
C_lib.StreamCipher = Cipher.extend({
|
|
1983
|
+
_doFinalize: function () {
|
|
1984
|
+
// Process partial blocks
|
|
1985
|
+
var finalProcessedBlocks = this._process(true);
|
|
1986
|
+
|
|
1987
|
+
return finalProcessedBlocks;
|
|
1988
|
+
},
|
|
1989
|
+
|
|
1990
|
+
blockSize: 1
|
|
1991
|
+
});
|
|
1992
|
+
|
|
1993
|
+
/**
|
|
1994
|
+
* Mode namespace.
|
|
1995
|
+
*/
|
|
1996
|
+
var C_mode = C.mode = {};
|
|
1997
|
+
|
|
1998
|
+
/**
|
|
1999
|
+
* Abstract base block cipher mode template.
|
|
2000
|
+
*/
|
|
2001
|
+
var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
|
|
2002
|
+
/**
|
|
2003
|
+
* Creates this mode for encryption.
|
|
2004
|
+
*
|
|
2005
|
+
* @param {Cipher} cipher A block cipher instance.
|
|
2006
|
+
* @param {Array} iv The IV words.
|
|
2007
|
+
*
|
|
2008
|
+
* @static
|
|
2009
|
+
*
|
|
2010
|
+
* @example
|
|
2011
|
+
*
|
|
2012
|
+
* var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
|
|
2013
|
+
*/
|
|
2014
|
+
createEncryptor: function (cipher, iv) {
|
|
2015
|
+
return this.Encryptor.create(cipher, iv);
|
|
2016
|
+
},
|
|
2017
|
+
|
|
2018
|
+
/**
|
|
2019
|
+
* Creates this mode for decryption.
|
|
2020
|
+
*
|
|
2021
|
+
* @param {Cipher} cipher A block cipher instance.
|
|
2022
|
+
* @param {Array} iv The IV words.
|
|
2023
|
+
*
|
|
2024
|
+
* @static
|
|
2025
|
+
*
|
|
2026
|
+
* @example
|
|
2027
|
+
*
|
|
2028
|
+
* var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
|
|
2029
|
+
*/
|
|
2030
|
+
createDecryptor: function (cipher, iv) {
|
|
2031
|
+
return this.Decryptor.create(cipher, iv);
|
|
2032
|
+
},
|
|
2033
|
+
|
|
2034
|
+
/**
|
|
2035
|
+
* Initializes a newly created mode.
|
|
2036
|
+
*
|
|
2037
|
+
* @param {Cipher} cipher A block cipher instance.
|
|
2038
|
+
* @param {Array} iv The IV words.
|
|
2039
|
+
*
|
|
2040
|
+
* @example
|
|
2041
|
+
*
|
|
2042
|
+
* var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
|
|
2043
|
+
*/
|
|
2044
|
+
init: function (cipher, iv) {
|
|
2045
|
+
this._cipher = cipher;
|
|
2046
|
+
this._iv = iv;
|
|
2047
|
+
}
|
|
2048
|
+
});
|
|
2049
|
+
|
|
2050
|
+
/**
|
|
2051
|
+
* Cipher Block Chaining mode.
|
|
2052
|
+
*/
|
|
2053
|
+
var CBC = C_mode.CBC = (function () {
|
|
2054
|
+
/**
|
|
2055
|
+
* Abstract base CBC mode.
|
|
2056
|
+
*/
|
|
2057
|
+
var CBC = BlockCipherMode.extend();
|
|
2058
|
+
|
|
2059
|
+
/**
|
|
2060
|
+
* CBC encryptor.
|
|
2061
|
+
*/
|
|
2062
|
+
CBC.Encryptor = CBC.extend({
|
|
2063
|
+
/**
|
|
2064
|
+
* Processes the data block at offset.
|
|
2065
|
+
*
|
|
2066
|
+
* @param {Array} words The data words to operate on.
|
|
2067
|
+
* @param {number} offset The offset where the block starts.
|
|
2068
|
+
*
|
|
2069
|
+
* @example
|
|
2070
|
+
*
|
|
2071
|
+
* mode.processBlock(data.words, offset);
|
|
2072
|
+
*/
|
|
2073
|
+
processBlock: function (words, offset) {
|
|
2074
|
+
// Shortcuts
|
|
2075
|
+
var cipher = this._cipher;
|
|
2076
|
+
var blockSize = cipher.blockSize;
|
|
2077
|
+
|
|
2078
|
+
// XOR and encrypt
|
|
2079
|
+
xorBlock.call(this, words, offset, blockSize);
|
|
2080
|
+
cipher.encryptBlock(words, offset);
|
|
2081
|
+
|
|
2082
|
+
// Remember this block to use with next block
|
|
2083
|
+
this._prevBlock = words.slice(offset, offset + blockSize);
|
|
2084
|
+
}
|
|
2085
|
+
});
|
|
2086
|
+
|
|
2087
|
+
/**
|
|
2088
|
+
* CBC decryptor.
|
|
2089
|
+
*/
|
|
2090
|
+
CBC.Decryptor = CBC.extend({
|
|
2091
|
+
/**
|
|
2092
|
+
* Processes the data block at offset.
|
|
2093
|
+
*
|
|
2094
|
+
* @param {Array} words The data words to operate on.
|
|
2095
|
+
* @param {number} offset The offset where the block starts.
|
|
2096
|
+
*
|
|
2097
|
+
* @example
|
|
2098
|
+
*
|
|
2099
|
+
* mode.processBlock(data.words, offset);
|
|
2100
|
+
*/
|
|
2101
|
+
processBlock: function (words, offset) {
|
|
2102
|
+
// Shortcuts
|
|
2103
|
+
var cipher = this._cipher;
|
|
2104
|
+
var blockSize = cipher.blockSize;
|
|
2105
|
+
|
|
2106
|
+
// Remember this block to use with next block
|
|
2107
|
+
var thisBlock = words.slice(offset, offset + blockSize);
|
|
2108
|
+
|
|
2109
|
+
// Decrypt and XOR
|
|
2110
|
+
cipher.decryptBlock(words, offset);
|
|
2111
|
+
xorBlock.call(this, words, offset, blockSize);
|
|
2112
|
+
|
|
2113
|
+
// This block becomes the previous block
|
|
2114
|
+
this._prevBlock = thisBlock;
|
|
2115
|
+
}
|
|
2116
|
+
});
|
|
2117
|
+
|
|
2118
|
+
function xorBlock(words, offset, blockSize) {
|
|
2119
|
+
var block;
|
|
2120
|
+
|
|
2121
|
+
// Shortcut
|
|
2122
|
+
var iv = this._iv;
|
|
2123
|
+
|
|
2124
|
+
// Choose mixing block
|
|
2125
|
+
if (iv) {
|
|
2126
|
+
block = iv;
|
|
2127
|
+
|
|
2128
|
+
// Remove IV for subsequent blocks
|
|
2129
|
+
this._iv = undefined$1;
|
|
2130
|
+
} else {
|
|
2131
|
+
block = this._prevBlock;
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
// XOR blocks
|
|
2135
|
+
for (var i = 0; i < blockSize; i++) {
|
|
2136
|
+
words[offset + i] ^= block[i];
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
return CBC;
|
|
2141
|
+
}());
|
|
2142
|
+
|
|
2143
|
+
/**
|
|
2144
|
+
* Padding namespace.
|
|
2145
|
+
*/
|
|
2146
|
+
var C_pad = C.pad = {};
|
|
2147
|
+
|
|
2148
|
+
/**
|
|
2149
|
+
* PKCS #5/7 padding strategy.
|
|
2150
|
+
*/
|
|
2151
|
+
var Pkcs7 = C_pad.Pkcs7 = {
|
|
2152
|
+
/**
|
|
2153
|
+
* Pads data using the algorithm defined in PKCS #5/7.
|
|
2154
|
+
*
|
|
2155
|
+
* @param {WordArray} data The data to pad.
|
|
2156
|
+
* @param {number} blockSize The multiple that the data should be padded to.
|
|
2157
|
+
*
|
|
2158
|
+
* @static
|
|
2159
|
+
*
|
|
2160
|
+
* @example
|
|
2161
|
+
*
|
|
2162
|
+
* CryptoJS.pad.Pkcs7.pad(wordArray, 4);
|
|
2163
|
+
*/
|
|
2164
|
+
pad: function (data, blockSize) {
|
|
2165
|
+
// Shortcut
|
|
2166
|
+
var blockSizeBytes = blockSize * 4;
|
|
2167
|
+
|
|
2168
|
+
// Count padding bytes
|
|
2169
|
+
var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
|
|
2170
|
+
|
|
2171
|
+
// Create padding word
|
|
2172
|
+
var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
|
|
2173
|
+
|
|
2174
|
+
// Create padding
|
|
2175
|
+
var paddingWords = [];
|
|
2176
|
+
for (var i = 0; i < nPaddingBytes; i += 4) {
|
|
2177
|
+
paddingWords.push(paddingWord);
|
|
2178
|
+
}
|
|
2179
|
+
var padding = WordArray.create(paddingWords, nPaddingBytes);
|
|
2180
|
+
|
|
2181
|
+
// Add padding
|
|
2182
|
+
data.concat(padding);
|
|
2183
|
+
},
|
|
2184
|
+
|
|
2185
|
+
/**
|
|
2186
|
+
* Unpads data that had been padded using the algorithm defined in PKCS #5/7.
|
|
2187
|
+
*
|
|
2188
|
+
* @param {WordArray} data The data to unpad.
|
|
2189
|
+
*
|
|
2190
|
+
* @static
|
|
2191
|
+
*
|
|
2192
|
+
* @example
|
|
2193
|
+
*
|
|
2194
|
+
* CryptoJS.pad.Pkcs7.unpad(wordArray);
|
|
2195
|
+
*/
|
|
2196
|
+
unpad: function (data) {
|
|
2197
|
+
// Get number of padding bytes from last byte
|
|
2198
|
+
var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
|
|
2199
|
+
|
|
2200
|
+
// Remove padding
|
|
2201
|
+
data.sigBytes -= nPaddingBytes;
|
|
2202
|
+
}
|
|
2203
|
+
};
|
|
2204
|
+
|
|
2205
|
+
/**
|
|
2206
|
+
* Abstract base block cipher template.
|
|
2207
|
+
*
|
|
2208
|
+
* @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
|
|
2209
|
+
*/
|
|
2210
|
+
C_lib.BlockCipher = Cipher.extend({
|
|
2211
|
+
/**
|
|
2212
|
+
* Configuration options.
|
|
2213
|
+
*
|
|
2214
|
+
* @property {Mode} mode The block mode to use. Default: CBC
|
|
2215
|
+
* @property {Padding} padding The padding strategy to use. Default: Pkcs7
|
|
2216
|
+
*/
|
|
2217
|
+
cfg: Cipher.cfg.extend({
|
|
2218
|
+
mode: CBC,
|
|
2219
|
+
padding: Pkcs7
|
|
2220
|
+
}),
|
|
2221
|
+
|
|
2222
|
+
reset: function () {
|
|
2223
|
+
var modeCreator;
|
|
2224
|
+
|
|
2225
|
+
// Reset cipher
|
|
2226
|
+
Cipher.reset.call(this);
|
|
2227
|
+
|
|
2228
|
+
// Shortcuts
|
|
2229
|
+
var cfg = this.cfg;
|
|
2230
|
+
var iv = cfg.iv;
|
|
2231
|
+
var mode = cfg.mode;
|
|
2232
|
+
|
|
2233
|
+
// Reset block mode
|
|
2234
|
+
if (this._xformMode == this._ENC_XFORM_MODE) {
|
|
2235
|
+
modeCreator = mode.createEncryptor;
|
|
2236
|
+
} else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
|
|
2237
|
+
modeCreator = mode.createDecryptor;
|
|
2238
|
+
// Keep at least one block in the buffer for unpadding
|
|
2239
|
+
this._minBufferSize = 1;
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
if (this._mode && this._mode.__creator == modeCreator) {
|
|
2243
|
+
this._mode.init(this, iv && iv.words);
|
|
2244
|
+
} else {
|
|
2245
|
+
this._mode = modeCreator.call(mode, this, iv && iv.words);
|
|
2246
|
+
this._mode.__creator = modeCreator;
|
|
2247
|
+
}
|
|
2248
|
+
},
|
|
2249
|
+
|
|
2250
|
+
_doProcessBlock: function (words, offset) {
|
|
2251
|
+
this._mode.processBlock(words, offset);
|
|
2252
|
+
},
|
|
2253
|
+
|
|
2254
|
+
_doFinalize: function () {
|
|
2255
|
+
var finalProcessedBlocks;
|
|
2256
|
+
|
|
2257
|
+
// Shortcut
|
|
2258
|
+
var padding = this.cfg.padding;
|
|
2259
|
+
|
|
2260
|
+
// Finalize
|
|
2261
|
+
if (this._xformMode == this._ENC_XFORM_MODE) {
|
|
2262
|
+
// Pad data
|
|
2263
|
+
padding.pad(this._data, this.blockSize);
|
|
2264
|
+
|
|
2265
|
+
// Process final blocks
|
|
2266
|
+
finalProcessedBlocks = this._process(true);
|
|
2267
|
+
} else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
|
|
2268
|
+
// Process final blocks
|
|
2269
|
+
finalProcessedBlocks = this._process(true);
|
|
2270
|
+
|
|
2271
|
+
// Unpad data
|
|
2272
|
+
padding.unpad(finalProcessedBlocks);
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
return finalProcessedBlocks;
|
|
2276
|
+
},
|
|
2277
|
+
|
|
2278
|
+
blockSize: 128/32
|
|
2279
|
+
});
|
|
2280
|
+
|
|
2281
|
+
/**
|
|
2282
|
+
* A collection of cipher parameters.
|
|
2283
|
+
*
|
|
2284
|
+
* @property {WordArray} ciphertext The raw ciphertext.
|
|
2285
|
+
* @property {WordArray} key The key to this ciphertext.
|
|
2286
|
+
* @property {WordArray} iv The IV used in the ciphering operation.
|
|
2287
|
+
* @property {WordArray} salt The salt used with a key derivation function.
|
|
2288
|
+
* @property {Cipher} algorithm The cipher algorithm.
|
|
2289
|
+
* @property {Mode} mode The block mode used in the ciphering operation.
|
|
2290
|
+
* @property {Padding} padding The padding scheme used in the ciphering operation.
|
|
2291
|
+
* @property {number} blockSize The block size of the cipher.
|
|
2292
|
+
* @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
|
|
2293
|
+
*/
|
|
2294
|
+
var CipherParams = C_lib.CipherParams = Base.extend({
|
|
2295
|
+
/**
|
|
2296
|
+
* Initializes a newly created cipher params object.
|
|
2297
|
+
*
|
|
2298
|
+
* @param {Object} cipherParams An object with any of the possible cipher parameters.
|
|
2299
|
+
*
|
|
2300
|
+
* @example
|
|
2301
|
+
*
|
|
2302
|
+
* var cipherParams = CryptoJS.lib.CipherParams.create({
|
|
2303
|
+
* ciphertext: ciphertextWordArray,
|
|
2304
|
+
* key: keyWordArray,
|
|
2305
|
+
* iv: ivWordArray,
|
|
2306
|
+
* salt: saltWordArray,
|
|
2307
|
+
* algorithm: CryptoJS.algo.AES,
|
|
2308
|
+
* mode: CryptoJS.mode.CBC,
|
|
2309
|
+
* padding: CryptoJS.pad.PKCS7,
|
|
2310
|
+
* blockSize: 4,
|
|
2311
|
+
* formatter: CryptoJS.format.OpenSSL
|
|
2312
|
+
* });
|
|
2313
|
+
*/
|
|
2314
|
+
init: function (cipherParams) {
|
|
2315
|
+
this.mixIn(cipherParams);
|
|
2316
|
+
},
|
|
2317
|
+
|
|
2318
|
+
/**
|
|
2319
|
+
* Converts this cipher params object to a string.
|
|
2320
|
+
*
|
|
2321
|
+
* @param {Format} formatter (Optional) The formatting strategy to use.
|
|
2322
|
+
*
|
|
2323
|
+
* @return {string} The stringified cipher params.
|
|
2324
|
+
*
|
|
2325
|
+
* @throws Error If neither the formatter nor the default formatter is set.
|
|
2326
|
+
*
|
|
2327
|
+
* @example
|
|
2328
|
+
*
|
|
2329
|
+
* var string = cipherParams + '';
|
|
2330
|
+
* var string = cipherParams.toString();
|
|
2331
|
+
* var string = cipherParams.toString(CryptoJS.format.OpenSSL);
|
|
2332
|
+
*/
|
|
2333
|
+
toString: function (formatter) {
|
|
2334
|
+
return (formatter || this.formatter).stringify(this);
|
|
2335
|
+
}
|
|
2336
|
+
});
|
|
2337
|
+
|
|
2338
|
+
/**
|
|
2339
|
+
* Format namespace.
|
|
2340
|
+
*/
|
|
2341
|
+
var C_format = C.format = {};
|
|
2342
|
+
|
|
2343
|
+
/**
|
|
2344
|
+
* OpenSSL formatting strategy.
|
|
2345
|
+
*/
|
|
2346
|
+
var OpenSSLFormatter = C_format.OpenSSL = {
|
|
2347
|
+
/**
|
|
2348
|
+
* Converts a cipher params object to an OpenSSL-compatible string.
|
|
2349
|
+
*
|
|
2350
|
+
* @param {CipherParams} cipherParams The cipher params object.
|
|
2351
|
+
*
|
|
2352
|
+
* @return {string} The OpenSSL-compatible string.
|
|
2353
|
+
*
|
|
2354
|
+
* @static
|
|
2355
|
+
*
|
|
2356
|
+
* @example
|
|
2357
|
+
*
|
|
2358
|
+
* var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
|
|
2359
|
+
*/
|
|
2360
|
+
stringify: function (cipherParams) {
|
|
2361
|
+
var wordArray;
|
|
2362
|
+
|
|
2363
|
+
// Shortcuts
|
|
2364
|
+
var ciphertext = cipherParams.ciphertext;
|
|
2365
|
+
var salt = cipherParams.salt;
|
|
2366
|
+
|
|
2367
|
+
// Format
|
|
2368
|
+
if (salt) {
|
|
2369
|
+
wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
|
|
2370
|
+
} else {
|
|
2371
|
+
wordArray = ciphertext;
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2374
|
+
return wordArray.toString(Base64);
|
|
2375
|
+
},
|
|
2376
|
+
|
|
2377
|
+
/**
|
|
2378
|
+
* Converts an OpenSSL-compatible string to a cipher params object.
|
|
2379
|
+
*
|
|
2380
|
+
* @param {string} openSSLStr The OpenSSL-compatible string.
|
|
2381
|
+
*
|
|
2382
|
+
* @return {CipherParams} The cipher params object.
|
|
2383
|
+
*
|
|
2384
|
+
* @static
|
|
2385
|
+
*
|
|
2386
|
+
* @example
|
|
2387
|
+
*
|
|
2388
|
+
* var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
|
|
2389
|
+
*/
|
|
2390
|
+
parse: function (openSSLStr) {
|
|
2391
|
+
var salt;
|
|
2392
|
+
|
|
2393
|
+
// Parse base64
|
|
2394
|
+
var ciphertext = Base64.parse(openSSLStr);
|
|
2395
|
+
|
|
2396
|
+
// Shortcut
|
|
2397
|
+
var ciphertextWords = ciphertext.words;
|
|
2398
|
+
|
|
2399
|
+
// Test for salt
|
|
2400
|
+
if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
|
|
2401
|
+
// Extract salt
|
|
2402
|
+
salt = WordArray.create(ciphertextWords.slice(2, 4));
|
|
2403
|
+
|
|
2404
|
+
// Remove salt from ciphertext
|
|
2405
|
+
ciphertextWords.splice(0, 4);
|
|
2406
|
+
ciphertext.sigBytes -= 16;
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
return CipherParams.create({ ciphertext: ciphertext, salt: salt });
|
|
2410
|
+
}
|
|
2411
|
+
};
|
|
2412
|
+
|
|
2413
|
+
/**
|
|
2414
|
+
* A cipher wrapper that returns ciphertext as a serializable cipher params object.
|
|
2415
|
+
*/
|
|
2416
|
+
var SerializableCipher = C_lib.SerializableCipher = Base.extend({
|
|
2417
|
+
/**
|
|
2418
|
+
* Configuration options.
|
|
2419
|
+
*
|
|
2420
|
+
* @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
|
|
2421
|
+
*/
|
|
2422
|
+
cfg: Base.extend({
|
|
2423
|
+
format: OpenSSLFormatter
|
|
2424
|
+
}),
|
|
2425
|
+
|
|
2426
|
+
/**
|
|
2427
|
+
* Encrypts a message.
|
|
2428
|
+
*
|
|
2429
|
+
* @param {Cipher} cipher The cipher algorithm to use.
|
|
2430
|
+
* @param {WordArray|string} message The message to encrypt.
|
|
2431
|
+
* @param {WordArray} key The key.
|
|
2432
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
2433
|
+
*
|
|
2434
|
+
* @return {CipherParams} A cipher params object.
|
|
2435
|
+
*
|
|
2436
|
+
* @static
|
|
2437
|
+
*
|
|
2438
|
+
* @example
|
|
2439
|
+
*
|
|
2440
|
+
* var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
|
|
2441
|
+
* var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
|
|
2442
|
+
* var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
|
|
2443
|
+
*/
|
|
2444
|
+
encrypt: function (cipher, message, key, cfg) {
|
|
2445
|
+
// Apply config defaults
|
|
2446
|
+
cfg = this.cfg.extend(cfg);
|
|
2447
|
+
|
|
2448
|
+
// Encrypt
|
|
2449
|
+
var encryptor = cipher.createEncryptor(key, cfg);
|
|
2450
|
+
var ciphertext = encryptor.finalize(message);
|
|
2451
|
+
|
|
2452
|
+
// Shortcut
|
|
2453
|
+
var cipherCfg = encryptor.cfg;
|
|
2454
|
+
|
|
2455
|
+
// Create and return serializable cipher params
|
|
2456
|
+
return CipherParams.create({
|
|
2457
|
+
ciphertext: ciphertext,
|
|
2458
|
+
key: key,
|
|
2459
|
+
iv: cipherCfg.iv,
|
|
2460
|
+
algorithm: cipher,
|
|
2461
|
+
mode: cipherCfg.mode,
|
|
2462
|
+
padding: cipherCfg.padding,
|
|
2463
|
+
blockSize: cipher.blockSize,
|
|
2464
|
+
formatter: cfg.format
|
|
2465
|
+
});
|
|
2466
|
+
},
|
|
2467
|
+
|
|
2468
|
+
/**
|
|
2469
|
+
* Decrypts serialized ciphertext.
|
|
2470
|
+
*
|
|
2471
|
+
* @param {Cipher} cipher The cipher algorithm to use.
|
|
2472
|
+
* @param {CipherParams|string} ciphertext The ciphertext to decrypt.
|
|
2473
|
+
* @param {WordArray} key The key.
|
|
2474
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
2475
|
+
*
|
|
2476
|
+
* @return {WordArray} The plaintext.
|
|
2477
|
+
*
|
|
2478
|
+
* @static
|
|
2479
|
+
*
|
|
2480
|
+
* @example
|
|
2481
|
+
*
|
|
2482
|
+
* var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
|
|
2483
|
+
* var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
|
|
2484
|
+
*/
|
|
2485
|
+
decrypt: function (cipher, ciphertext, key, cfg) {
|
|
2486
|
+
// Apply config defaults
|
|
2487
|
+
cfg = this.cfg.extend(cfg);
|
|
2488
|
+
|
|
2489
|
+
// Convert string to CipherParams
|
|
2490
|
+
ciphertext = this._parse(ciphertext, cfg.format);
|
|
2491
|
+
|
|
2492
|
+
// Decrypt
|
|
2493
|
+
var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
|
|
2494
|
+
|
|
2495
|
+
return plaintext;
|
|
2496
|
+
},
|
|
2497
|
+
|
|
2498
|
+
/**
|
|
2499
|
+
* Converts serialized ciphertext to CipherParams,
|
|
2500
|
+
* else assumed CipherParams already and returns ciphertext unchanged.
|
|
2501
|
+
*
|
|
2502
|
+
* @param {CipherParams|string} ciphertext The ciphertext.
|
|
2503
|
+
* @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
|
|
2504
|
+
*
|
|
2505
|
+
* @return {CipherParams} The unserialized ciphertext.
|
|
2506
|
+
*
|
|
2507
|
+
* @static
|
|
2508
|
+
*
|
|
2509
|
+
* @example
|
|
2510
|
+
*
|
|
2511
|
+
* var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
|
|
2512
|
+
*/
|
|
2513
|
+
_parse: function (ciphertext, format) {
|
|
2514
|
+
if (typeof ciphertext == 'string') {
|
|
2515
|
+
return format.parse(ciphertext, this);
|
|
2516
|
+
} else {
|
|
2517
|
+
return ciphertext;
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
});
|
|
2521
|
+
|
|
2522
|
+
/**
|
|
2523
|
+
* Key derivation function namespace.
|
|
2524
|
+
*/
|
|
2525
|
+
var C_kdf = C.kdf = {};
|
|
2526
|
+
|
|
2527
|
+
/**
|
|
2528
|
+
* OpenSSL key derivation function.
|
|
2529
|
+
*/
|
|
2530
|
+
var OpenSSLKdf = C_kdf.OpenSSL = {
|
|
2531
|
+
/**
|
|
2532
|
+
* Derives a key and IV from a password.
|
|
2533
|
+
*
|
|
2534
|
+
* @param {string} password The password to derive from.
|
|
2535
|
+
* @param {number} keySize The size in words of the key to generate.
|
|
2536
|
+
* @param {number} ivSize The size in words of the IV to generate.
|
|
2537
|
+
* @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
|
|
2538
|
+
*
|
|
2539
|
+
* @return {CipherParams} A cipher params object with the key, IV, and salt.
|
|
2540
|
+
*
|
|
2541
|
+
* @static
|
|
2542
|
+
*
|
|
2543
|
+
* @example
|
|
2544
|
+
*
|
|
2545
|
+
* var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
|
|
2546
|
+
* var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
|
|
2547
|
+
*/
|
|
2548
|
+
execute: function (password, keySize, ivSize, salt) {
|
|
2549
|
+
// Generate random salt
|
|
2550
|
+
if (!salt) {
|
|
2551
|
+
salt = WordArray.random(64/8);
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
// Derive key and IV
|
|
2555
|
+
var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
|
|
2556
|
+
|
|
2557
|
+
// Separate key and IV
|
|
2558
|
+
var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
|
|
2559
|
+
key.sigBytes = keySize * 4;
|
|
2560
|
+
|
|
2561
|
+
// Return params
|
|
2562
|
+
return CipherParams.create({ key: key, iv: iv, salt: salt });
|
|
2563
|
+
}
|
|
2564
|
+
};
|
|
2565
|
+
|
|
2566
|
+
/**
|
|
2567
|
+
* A serializable cipher wrapper that derives the key from a password,
|
|
2568
|
+
* and returns ciphertext as a serializable cipher params object.
|
|
2569
|
+
*/
|
|
2570
|
+
var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
|
|
2571
|
+
/**
|
|
2572
|
+
* Configuration options.
|
|
2573
|
+
*
|
|
2574
|
+
* @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
|
|
2575
|
+
*/
|
|
2576
|
+
cfg: SerializableCipher.cfg.extend({
|
|
2577
|
+
kdf: OpenSSLKdf
|
|
2578
|
+
}),
|
|
2579
|
+
|
|
2580
|
+
/**
|
|
2581
|
+
* Encrypts a message using a password.
|
|
2582
|
+
*
|
|
2583
|
+
* @param {Cipher} cipher The cipher algorithm to use.
|
|
2584
|
+
* @param {WordArray|string} message The message to encrypt.
|
|
2585
|
+
* @param {string} password The password.
|
|
2586
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
2587
|
+
*
|
|
2588
|
+
* @return {CipherParams} A cipher params object.
|
|
2589
|
+
*
|
|
2590
|
+
* @static
|
|
2591
|
+
*
|
|
2592
|
+
* @example
|
|
2593
|
+
*
|
|
2594
|
+
* var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
|
|
2595
|
+
* var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
|
|
2596
|
+
*/
|
|
2597
|
+
encrypt: function (cipher, message, password, cfg) {
|
|
2598
|
+
// Apply config defaults
|
|
2599
|
+
cfg = this.cfg.extend(cfg);
|
|
2600
|
+
|
|
2601
|
+
// Derive key and other params
|
|
2602
|
+
var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
|
|
2603
|
+
|
|
2604
|
+
// Add IV to config
|
|
2605
|
+
cfg.iv = derivedParams.iv;
|
|
2606
|
+
|
|
2607
|
+
// Encrypt
|
|
2608
|
+
var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
|
|
2609
|
+
|
|
2610
|
+
// Mix in derived params
|
|
2611
|
+
ciphertext.mixIn(derivedParams);
|
|
2612
|
+
|
|
2613
|
+
return ciphertext;
|
|
2614
|
+
},
|
|
2615
|
+
|
|
2616
|
+
/**
|
|
2617
|
+
* Decrypts serialized ciphertext using a password.
|
|
2618
|
+
*
|
|
2619
|
+
* @param {Cipher} cipher The cipher algorithm to use.
|
|
2620
|
+
* @param {CipherParams|string} ciphertext The ciphertext to decrypt.
|
|
2621
|
+
* @param {string} password The password.
|
|
2622
|
+
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
|
2623
|
+
*
|
|
2624
|
+
* @return {WordArray} The plaintext.
|
|
2625
|
+
*
|
|
2626
|
+
* @static
|
|
2627
|
+
*
|
|
2628
|
+
* @example
|
|
2629
|
+
*
|
|
2630
|
+
* var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
|
|
2631
|
+
* var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
|
|
2632
|
+
*/
|
|
2633
|
+
decrypt: function (cipher, ciphertext, password, cfg) {
|
|
2634
|
+
// Apply config defaults
|
|
2635
|
+
cfg = this.cfg.extend(cfg);
|
|
2636
|
+
|
|
2637
|
+
// Convert string to CipherParams
|
|
2638
|
+
ciphertext = this._parse(ciphertext, cfg.format);
|
|
2639
|
+
|
|
2640
|
+
// Derive key and other params
|
|
2641
|
+
var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
|
|
2642
|
+
|
|
2643
|
+
// Add IV to config
|
|
2644
|
+
cfg.iv = derivedParams.iv;
|
|
2645
|
+
|
|
2646
|
+
// Decrypt
|
|
2647
|
+
var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
|
|
2648
|
+
|
|
2649
|
+
return plaintext;
|
|
2650
|
+
}
|
|
2651
|
+
});
|
|
2652
|
+
}());
|
|
2653
|
+
|
|
2654
|
+
|
|
2655
|
+
}));
|
|
2656
|
+
} (cipherCore$1));
|
|
2657
|
+
return cipherCore$1.exports;
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
var aes = aes$1.exports;
|
|
2661
|
+
|
|
2662
|
+
var hasRequiredAes;
|
|
2663
|
+
|
|
2664
|
+
function requireAes () {
|
|
2665
|
+
if (hasRequiredAes) return aes$1.exports;
|
|
2666
|
+
hasRequiredAes = 1;
|
|
2667
|
+
(function (module, exports$1) {
|
|
2668
|
+
(function (root, factory, undef) {
|
|
2669
|
+
{
|
|
2670
|
+
// CommonJS
|
|
2671
|
+
module.exports = factory(requireCore(), requireEncBase64(), requireMd5(), requireEvpkdf(), requireCipherCore());
|
|
2672
|
+
}
|
|
2673
|
+
}(aes, function (CryptoJS) {
|
|
2674
|
+
|
|
2675
|
+
(function () {
|
|
2676
|
+
// Shortcuts
|
|
2677
|
+
var C = CryptoJS;
|
|
2678
|
+
var C_lib = C.lib;
|
|
2679
|
+
var BlockCipher = C_lib.BlockCipher;
|
|
2680
|
+
var C_algo = C.algo;
|
|
2681
|
+
|
|
2682
|
+
// Lookup tables
|
|
2683
|
+
var SBOX = [];
|
|
2684
|
+
var INV_SBOX = [];
|
|
2685
|
+
var SUB_MIX_0 = [];
|
|
2686
|
+
var SUB_MIX_1 = [];
|
|
2687
|
+
var SUB_MIX_2 = [];
|
|
2688
|
+
var SUB_MIX_3 = [];
|
|
2689
|
+
var INV_SUB_MIX_0 = [];
|
|
2690
|
+
var INV_SUB_MIX_1 = [];
|
|
2691
|
+
var INV_SUB_MIX_2 = [];
|
|
2692
|
+
var INV_SUB_MIX_3 = [];
|
|
2693
|
+
|
|
2694
|
+
// Compute lookup tables
|
|
2695
|
+
(function () {
|
|
2696
|
+
// Compute double table
|
|
2697
|
+
var d = [];
|
|
2698
|
+
for (var i = 0; i < 256; i++) {
|
|
2699
|
+
if (i < 128) {
|
|
2700
|
+
d[i] = i << 1;
|
|
2701
|
+
} else {
|
|
2702
|
+
d[i] = (i << 1) ^ 0x11b;
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2706
|
+
// Walk GF(2^8)
|
|
2707
|
+
var x = 0;
|
|
2708
|
+
var xi = 0;
|
|
2709
|
+
for (var i = 0; i < 256; i++) {
|
|
2710
|
+
// Compute sbox
|
|
2711
|
+
var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
|
|
2712
|
+
sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
|
|
2713
|
+
SBOX[x] = sx;
|
|
2714
|
+
INV_SBOX[sx] = x;
|
|
2715
|
+
|
|
2716
|
+
// Compute multiplication
|
|
2717
|
+
var x2 = d[x];
|
|
2718
|
+
var x4 = d[x2];
|
|
2719
|
+
var x8 = d[x4];
|
|
2720
|
+
|
|
2721
|
+
// Compute sub bytes, mix columns tables
|
|
2722
|
+
var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
|
|
2723
|
+
SUB_MIX_0[x] = (t << 24) | (t >>> 8);
|
|
2724
|
+
SUB_MIX_1[x] = (t << 16) | (t >>> 16);
|
|
2725
|
+
SUB_MIX_2[x] = (t << 8) | (t >>> 24);
|
|
2726
|
+
SUB_MIX_3[x] = t;
|
|
2727
|
+
|
|
2728
|
+
// Compute inv sub bytes, inv mix columns tables
|
|
2729
|
+
var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
|
|
2730
|
+
INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
|
|
2731
|
+
INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
|
|
2732
|
+
INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
|
|
2733
|
+
INV_SUB_MIX_3[sx] = t;
|
|
2734
|
+
|
|
2735
|
+
// Compute next counter
|
|
2736
|
+
if (!x) {
|
|
2737
|
+
x = xi = 1;
|
|
2738
|
+
} else {
|
|
2739
|
+
x = x2 ^ d[d[d[x8 ^ x2]]];
|
|
2740
|
+
xi ^= d[d[xi]];
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
}());
|
|
2744
|
+
|
|
2745
|
+
// Precomputed Rcon lookup
|
|
2746
|
+
var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
|
|
2747
|
+
|
|
2748
|
+
/**
|
|
2749
|
+
* AES block cipher algorithm.
|
|
2750
|
+
*/
|
|
2751
|
+
var AES = C_algo.AES = BlockCipher.extend({
|
|
2752
|
+
_doReset: function () {
|
|
2753
|
+
var t;
|
|
2754
|
+
|
|
2755
|
+
// Skip reset of nRounds has been set before and key did not change
|
|
2756
|
+
if (this._nRounds && this._keyPriorReset === this._key) {
|
|
2757
|
+
return;
|
|
2758
|
+
}
|
|
2759
|
+
|
|
2760
|
+
// Shortcuts
|
|
2761
|
+
var key = this._keyPriorReset = this._key;
|
|
2762
|
+
var keyWords = key.words;
|
|
2763
|
+
var keySize = key.sigBytes / 4;
|
|
2764
|
+
|
|
2765
|
+
// Compute number of rounds
|
|
2766
|
+
var nRounds = this._nRounds = keySize + 6;
|
|
2767
|
+
|
|
2768
|
+
// Compute number of key schedule rows
|
|
2769
|
+
var ksRows = (nRounds + 1) * 4;
|
|
2770
|
+
|
|
2771
|
+
// Compute key schedule
|
|
2772
|
+
var keySchedule = this._keySchedule = [];
|
|
2773
|
+
for (var ksRow = 0; ksRow < ksRows; ksRow++) {
|
|
2774
|
+
if (ksRow < keySize) {
|
|
2775
|
+
keySchedule[ksRow] = keyWords[ksRow];
|
|
2776
|
+
} else {
|
|
2777
|
+
t = keySchedule[ksRow - 1];
|
|
2778
|
+
|
|
2779
|
+
if (!(ksRow % keySize)) {
|
|
2780
|
+
// Rot word
|
|
2781
|
+
t = (t << 8) | (t >>> 24);
|
|
2782
|
+
|
|
2783
|
+
// Sub word
|
|
2784
|
+
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
|
2785
|
+
|
|
2786
|
+
// Mix Rcon
|
|
2787
|
+
t ^= RCON[(ksRow / keySize) | 0] << 24;
|
|
2788
|
+
} else if (keySize > 6 && ksRow % keySize == 4) {
|
|
2789
|
+
// Sub word
|
|
2790
|
+
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2793
|
+
keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
// Compute inv key schedule
|
|
2798
|
+
var invKeySchedule = this._invKeySchedule = [];
|
|
2799
|
+
for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
|
|
2800
|
+
var ksRow = ksRows - invKsRow;
|
|
2801
|
+
|
|
2802
|
+
if (invKsRow % 4) {
|
|
2803
|
+
var t = keySchedule[ksRow];
|
|
2804
|
+
} else {
|
|
2805
|
+
var t = keySchedule[ksRow - 4];
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2808
|
+
if (invKsRow < 4 || ksRow <= 4) {
|
|
2809
|
+
invKeySchedule[invKsRow] = t;
|
|
2810
|
+
} else {
|
|
2811
|
+
invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
|
|
2812
|
+
INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
},
|
|
2816
|
+
|
|
2817
|
+
encryptBlock: function (M, offset) {
|
|
2818
|
+
this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
|
|
2819
|
+
},
|
|
2820
|
+
|
|
2821
|
+
decryptBlock: function (M, offset) {
|
|
2822
|
+
// Swap 2nd and 4th rows
|
|
2823
|
+
var t = M[offset + 1];
|
|
2824
|
+
M[offset + 1] = M[offset + 3];
|
|
2825
|
+
M[offset + 3] = t;
|
|
2826
|
+
|
|
2827
|
+
this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
|
|
2828
|
+
|
|
2829
|
+
// Inv swap 2nd and 4th rows
|
|
2830
|
+
var t = M[offset + 1];
|
|
2831
|
+
M[offset + 1] = M[offset + 3];
|
|
2832
|
+
M[offset + 3] = t;
|
|
2833
|
+
},
|
|
2834
|
+
|
|
2835
|
+
_doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
|
|
2836
|
+
// Shortcut
|
|
2837
|
+
var nRounds = this._nRounds;
|
|
2838
|
+
|
|
2839
|
+
// Get input, add round key
|
|
2840
|
+
var s0 = M[offset] ^ keySchedule[0];
|
|
2841
|
+
var s1 = M[offset + 1] ^ keySchedule[1];
|
|
2842
|
+
var s2 = M[offset + 2] ^ keySchedule[2];
|
|
2843
|
+
var s3 = M[offset + 3] ^ keySchedule[3];
|
|
2844
|
+
|
|
2845
|
+
// Key schedule row counter
|
|
2846
|
+
var ksRow = 4;
|
|
2847
|
+
|
|
2848
|
+
// Rounds
|
|
2849
|
+
for (var round = 1; round < nRounds; round++) {
|
|
2850
|
+
// Shift rows, sub bytes, mix columns, add round key
|
|
2851
|
+
var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
|
|
2852
|
+
var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
|
|
2853
|
+
var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
|
|
2854
|
+
var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
|
|
2855
|
+
|
|
2856
|
+
// Update state
|
|
2857
|
+
s0 = t0;
|
|
2858
|
+
s1 = t1;
|
|
2859
|
+
s2 = t2;
|
|
2860
|
+
s3 = t3;
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
// Shift rows, sub bytes, add round key
|
|
2864
|
+
var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
|
|
2865
|
+
var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
|
|
2866
|
+
var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
|
|
2867
|
+
var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
|
|
2868
|
+
|
|
2869
|
+
// Set output
|
|
2870
|
+
M[offset] = t0;
|
|
2871
|
+
M[offset + 1] = t1;
|
|
2872
|
+
M[offset + 2] = t2;
|
|
2873
|
+
M[offset + 3] = t3;
|
|
2874
|
+
},
|
|
2875
|
+
|
|
2876
|
+
keySize: 256/32
|
|
2877
|
+
});
|
|
2878
|
+
|
|
2879
|
+
/**
|
|
2880
|
+
* Shortcut functions to the cipher's object interface.
|
|
2881
|
+
*
|
|
2882
|
+
* @example
|
|
2883
|
+
*
|
|
2884
|
+
* var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
|
|
2885
|
+
* var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
|
|
2886
|
+
*/
|
|
2887
|
+
C.AES = BlockCipher._createHelper(AES);
|
|
2888
|
+
}());
|
|
2889
|
+
|
|
2890
|
+
|
|
2891
|
+
return CryptoJS.AES;
|
|
2892
|
+
|
|
2893
|
+
}));
|
|
2894
|
+
} (aes$1));
|
|
2895
|
+
return aes$1.exports;
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
var aesExports = requireAes();
|
|
2899
|
+
const AES = /*@__PURE__*/getDefaultExportFromCjs(aesExports);
|
|
2900
|
+
|
|
2901
|
+
var encUtf8$2 = {exports: {}};
|
|
2902
|
+
|
|
2903
|
+
var encUtf8$1 = encUtf8$2.exports;
|
|
2904
|
+
|
|
2905
|
+
var hasRequiredEncUtf8;
|
|
2906
|
+
|
|
2907
|
+
function requireEncUtf8 () {
|
|
2908
|
+
if (hasRequiredEncUtf8) return encUtf8$2.exports;
|
|
2909
|
+
hasRequiredEncUtf8 = 1;
|
|
2910
|
+
(function (module, exports$1) {
|
|
2911
|
+
(function (root, factory) {
|
|
2912
|
+
{
|
|
2913
|
+
// CommonJS
|
|
2914
|
+
module.exports = factory(requireCore());
|
|
2915
|
+
}
|
|
2916
|
+
}(encUtf8$1, function (CryptoJS) {
|
|
2917
|
+
|
|
2918
|
+
return CryptoJS.enc.Utf8;
|
|
2919
|
+
|
|
2920
|
+
}));
|
|
2921
|
+
} (encUtf8$2));
|
|
2922
|
+
return encUtf8$2.exports;
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2925
|
+
var encUtf8Exports = requireEncUtf8();
|
|
2926
|
+
const encUtf8 = /*@__PURE__*/getDefaultExportFromCjs(encUtf8Exports);
|
|
2927
|
+
|
|
2928
|
+
const defaultImageOption = {
|
|
2929
|
+
format: 'image/png',
|
|
2930
|
+
quality: 1,
|
|
2931
|
+
};
|
|
2932
|
+
// canvas转dataURL,todo:测试
|
|
2933
|
+
const canvasToDataURL = (canvas, option) => {
|
|
2934
|
+
const myOption = { ...defaultImageOption, ...option };
|
|
2935
|
+
return canvas.toDataURL(myOption.format, myOption.quality);
|
|
2936
|
+
};
|
|
2937
|
+
// img转canvas,可以是dataurl/src,todo:测试
|
|
2938
|
+
const imageToCanvas = (data) => new Promise((resolve, reject) => {
|
|
2939
|
+
const canvas = document.createElement('CANVAS');
|
|
2940
|
+
const ctx = canvas.getContext('2d');
|
|
2941
|
+
const img = new Image();
|
|
2942
|
+
img.onload = () => {
|
|
2943
|
+
if (!ctx) {
|
|
2944
|
+
return;
|
|
2945
|
+
}
|
|
2946
|
+
canvas.width = img.width;
|
|
2947
|
+
canvas.height = img.height;
|
|
2948
|
+
ctx.drawImage(img, 0, 0);
|
|
2949
|
+
resolve(canvas);
|
|
2950
|
+
};
|
|
2951
|
+
img.onerror = () => {
|
|
2952
|
+
reject(new Error('图片加载错误'));
|
|
2953
|
+
};
|
|
2954
|
+
img.src = data;
|
|
2955
|
+
});
|
|
2956
|
+
// canvas转image,todo:测试
|
|
2957
|
+
const canvasToImage = (canvas, option) => {
|
|
2958
|
+
const img = new Image();
|
|
2959
|
+
img.src = canvasToDataURL(canvas, option);
|
|
2960
|
+
return img;
|
|
2961
|
+
};
|
|
2962
|
+
// File/Blob对象转DataURL,todo:测试
|
|
2963
|
+
const fileOrBlobToDataURL = (obj) => new Promise((resolve, reject) => {
|
|
2964
|
+
const file = new FileReader();
|
|
2965
|
+
file.readAsDataURL(obj);
|
|
2966
|
+
file.onload = e => {
|
|
2967
|
+
if (e.target && e.target.result) {
|
|
2968
|
+
resolve(e.target.result);
|
|
2969
|
+
}
|
|
2970
|
+
else {
|
|
2971
|
+
reject(new Error('文件加载失败'));
|
|
2972
|
+
}
|
|
2973
|
+
};
|
|
2974
|
+
file.onerror = () => {
|
|
2975
|
+
reject(new Error('文件加载错误'));
|
|
2976
|
+
};
|
|
2977
|
+
});
|
|
2978
|
+
const dataURLtoUint8Array = (dataurl) => {
|
|
2979
|
+
const arr = dataurl.split(',');
|
|
2980
|
+
const match = arr[0].match(/:(.*?);/);
|
|
2981
|
+
if (!match) {
|
|
2982
|
+
throw new Error('dataURL数据错误');
|
|
2983
|
+
}
|
|
2984
|
+
const mime = match[1];
|
|
2985
|
+
const bstr = atob(arr[1]);
|
|
2986
|
+
let n = bstr.length;
|
|
2987
|
+
const u8arr = new Uint8Array(n);
|
|
2988
|
+
while (n--) {
|
|
2989
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
2990
|
+
}
|
|
2991
|
+
return { uint8Array: u8arr, type: mime };
|
|
2992
|
+
};
|
|
2993
|
+
// DataURL转Blob对象,todo:测试
|
|
2994
|
+
const dataURLToBlob = (dataurl) => {
|
|
2995
|
+
const data = dataURLtoUint8Array(dataurl);
|
|
2996
|
+
return new Blob([data.uint8Array], { type: data.type });
|
|
2997
|
+
};
|
|
2998
|
+
// DataURL转File对象,todo:测试
|
|
2999
|
+
const dataURLToFile = (dataurl, fileName) => {
|
|
3000
|
+
const data = dataURLtoUint8Array(dataurl);
|
|
3001
|
+
return new File([data.uint8Array], fileName, { type: data.type });
|
|
3002
|
+
};
|
|
3003
|
+
const blobToFile = (blob, fileName) => new File([blob], fileName, { type: blob.type, lastModified: Date.now() });
|
|
3004
|
+
// Blob转image,todo:测试
|
|
3005
|
+
const blobToImage = (blob) => new Promise((resolve, reject) => {
|
|
3006
|
+
fileOrBlobToDataURL(blob).then(dataurl => {
|
|
3007
|
+
const img = new Image();
|
|
3008
|
+
img.src = dataurl;
|
|
3009
|
+
resolve(img);
|
|
3010
|
+
}).then(e => reject(e));
|
|
3011
|
+
});
|
|
3012
|
+
// image转Blob,todo:测试
|
|
3013
|
+
const imageToBlob = (data) => new Promise((resolve, reject) => {
|
|
3014
|
+
imageToCanvas(data).then(canvas => {
|
|
3015
|
+
resolve(dataURLToBlob(canvasToDataURL(canvas)));
|
|
3016
|
+
}).catch(e => reject(e));
|
|
3017
|
+
});
|
|
3018
|
+
// Blob图片转canvas,todo:测试
|
|
3019
|
+
const blobToCanvas = (blob) => new Promise((resolve, reject) => {
|
|
3020
|
+
fileOrBlobToDataURL(blob).then(dataurl => {
|
|
3021
|
+
imageToCanvas(dataurl)
|
|
3022
|
+
.then(canvas => resolve(canvas))
|
|
3023
|
+
.catch(e => reject(e));
|
|
3024
|
+
}).catch(e => reject(e));
|
|
3025
|
+
});
|
|
3026
|
+
// canvas图片转Blob,todo:测试
|
|
3027
|
+
const canvasToBlob = (canvas) => dataURLToBlob(canvasToDataURL(canvas));
|
|
3028
|
+
// image(url/dataurl)转dataURL,todo:测试
|
|
3029
|
+
const imageToDataURL = (data) => new Promise((resolve, reject) => {
|
|
3030
|
+
imageToCanvas(data)
|
|
3031
|
+
.then(canvas => resolve(canvasToDataURL(canvas)))
|
|
3032
|
+
.catch(e => reject(e));
|
|
3033
|
+
});
|
|
3034
|
+
// dataURL转image,todo:测试
|
|
3035
|
+
const dataURLToImage = (dataurl) => {
|
|
3036
|
+
const img = new Image();
|
|
3037
|
+
img.src = dataurl;
|
|
3038
|
+
return img;
|
|
3039
|
+
};
|
|
3040
|
+
// 字符串转ArrayBuffer,todo:测试
|
|
3041
|
+
const stringToArrayBuffer = (s) => {
|
|
3042
|
+
const buf = new ArrayBuffer(s.length);
|
|
3043
|
+
const view = new Uint8Array(buf);
|
|
3044
|
+
for (let i = 0; i !== s.length; i += 1) {
|
|
3045
|
+
view[i] = s.charCodeAt(i) & 0xFF;
|
|
3046
|
+
}
|
|
3047
|
+
return buf;
|
|
3048
|
+
};
|
|
3049
|
+
var file = {
|
|
3050
|
+
canvasToDataURL,
|
|
3051
|
+
imageToCanvas,
|
|
3052
|
+
canvasToImage,
|
|
3053
|
+
fileOrBlobToDataURL,
|
|
3054
|
+
dataURLtoUint8Array,
|
|
3055
|
+
dataURLToBlob,
|
|
3056
|
+
dataURLToFile,
|
|
3057
|
+
blobToImage,
|
|
3058
|
+
imageToBlob,
|
|
3059
|
+
blobToCanvas,
|
|
3060
|
+
blobToFile,
|
|
3061
|
+
canvasToBlob,
|
|
3062
|
+
imageToDataURL,
|
|
3063
|
+
dataURLToImage,
|
|
3064
|
+
stringToArrayBuffer,
|
|
3065
|
+
};
|
|
3066
|
+
|
|
3067
|
+
const isClient = typeof window !== 'undefined';
|
|
3068
|
+
const defaultWindow = isClient ? window : undefined;
|
|
3069
|
+
|
|
3070
|
+
const SECRET_KEY = 'THIS_IS_SECRET';
|
|
3071
|
+
// 带有效期的localStorage
|
|
3072
|
+
// 删除指定的localStorge
|
|
3073
|
+
function remove(key, option) {
|
|
3074
|
+
const { instance = localStorage } = option || {};
|
|
3075
|
+
instance.removeItem(key);
|
|
3076
|
+
}
|
|
3077
|
+
// 设置localStorge
|
|
3078
|
+
function set(key, value, option) {
|
|
3079
|
+
const { expires, encrypt, secret, instance = localStorage } = option || {};
|
|
3080
|
+
let type = 'undefined';
|
|
3081
|
+
isNumber(expires) && (type = 'number');
|
|
3082
|
+
isDate(expires) && (type = 'date');
|
|
3083
|
+
const createAt = new Date().getTime();
|
|
3084
|
+
const val = encrypt ? AES.encrypt(JSON.stringify(value), secret || SECRET_KEY).toString() : value;
|
|
3085
|
+
const item = {
|
|
3086
|
+
val,
|
|
3087
|
+
type,
|
|
3088
|
+
createAt,
|
|
3089
|
+
encrypt: !!encrypt,
|
|
3090
|
+
};
|
|
3091
|
+
const handle = {
|
|
3092
|
+
date: () => { item.expires = new Date(expires).getTime(); },
|
|
3093
|
+
number: () => { item.expires = expires ? +expires : 99999; },
|
|
3094
|
+
};
|
|
3095
|
+
handle[type] && handle[type]();
|
|
3096
|
+
instance.setItem(key, JSON.stringify(item));
|
|
3097
|
+
}
|
|
3098
|
+
// 获取localStorge
|
|
3099
|
+
function get(key, option) {
|
|
3100
|
+
const { secret, instance = localStorage } = option || {};
|
|
3101
|
+
const val = instance.getItem(key);
|
|
3102
|
+
if (val === null) {
|
|
3103
|
+
return undefined;
|
|
3104
|
+
}
|
|
3105
|
+
const item = JSON.parse(val); // 未做类型转换
|
|
3106
|
+
let result = undefined;
|
|
3107
|
+
const handle = {
|
|
3108
|
+
date() {
|
|
3109
|
+
if (new Date() > new Date(item.expires)) { // 过期
|
|
3110
|
+
remove(key);
|
|
3111
|
+
result = undefined;
|
|
3112
|
+
}
|
|
3113
|
+
else {
|
|
3114
|
+
result = item.val;
|
|
3115
|
+
}
|
|
3116
|
+
},
|
|
3117
|
+
number() {
|
|
3118
|
+
const ss = (new Date().getTime() - item.createAt) / 1000;
|
|
3119
|
+
if (ss > +item.expires) { // 过期
|
|
3120
|
+
remove(key);
|
|
3121
|
+
result = undefined;
|
|
3122
|
+
}
|
|
3123
|
+
else {
|
|
3124
|
+
result = item.val;
|
|
3125
|
+
}
|
|
3126
|
+
},
|
|
3127
|
+
undefined() {
|
|
3128
|
+
result = item.val;
|
|
3129
|
+
},
|
|
3130
|
+
};
|
|
3131
|
+
handle[item.type] && handle[item.type]();
|
|
3132
|
+
if (!result) {
|
|
3133
|
+
return undefined;
|
|
3134
|
+
}
|
|
3135
|
+
try {
|
|
3136
|
+
result = item.encrypt ? JSON.parse(AES.decrypt(result, secret || SECRET_KEY).toString(encUtf8)) : result;
|
|
3137
|
+
}
|
|
3138
|
+
catch (err) {
|
|
3139
|
+
console.warn(err);
|
|
3140
|
+
result = undefined;
|
|
3141
|
+
}
|
|
3142
|
+
return result;
|
|
3143
|
+
}
|
|
3144
|
+
const info = () => {
|
|
3145
|
+
const count = (instance) => {
|
|
3146
|
+
let size = 0;
|
|
3147
|
+
for (const item in instance) {
|
|
3148
|
+
if (Object.prototype.hasOwnProperty.call(instance, item)) {
|
|
3149
|
+
size += instance.getItem(item)?.length || 0;
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
return `${(size / 1024).toFixed(2)} KB`;
|
|
3153
|
+
};
|
|
3154
|
+
const totalSpace = () => new Promise(resolve => {
|
|
3155
|
+
let test = '0123456789';
|
|
3156
|
+
do {
|
|
3157
|
+
test += test;
|
|
3158
|
+
} while (test.length < 10240);
|
|
3159
|
+
let sum = test;
|
|
3160
|
+
const timer = setInterval(() => {
|
|
3161
|
+
sum += test;
|
|
3162
|
+
try {
|
|
3163
|
+
if (defaultWindow) {
|
|
3164
|
+
defaultWindow.localStorage.removeItem('test-storage-space');
|
|
3165
|
+
defaultWindow.localStorage.setItem('test-storage-space', sum);
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
catch {
|
|
3169
|
+
resolve(`${sum.length / 1024} KB`);
|
|
3170
|
+
clearInterval(timer);
|
|
3171
|
+
}
|
|
3172
|
+
}, 0);
|
|
3173
|
+
});
|
|
3174
|
+
return {
|
|
3175
|
+
sessionSpace: count(sessionStorage),
|
|
3176
|
+
localSpace: count(localStorage),
|
|
3177
|
+
totalSpace,
|
|
3178
|
+
};
|
|
3179
|
+
};
|
|
3180
|
+
var storage = {
|
|
3181
|
+
set,
|
|
3182
|
+
get,
|
|
3183
|
+
remove,
|
|
3184
|
+
info,
|
|
3185
|
+
};
|
|
3186
|
+
|
|
3187
|
+
const baseCdnUrl = {
|
|
3188
|
+
jsdelivr: '//cdn.jsdelivr.net/npm',
|
|
3189
|
+
defaultBase: defaultWindow ? (defaultWindow.h_utils?.cdn?.host || '//cdn.staticfile.org') : '',
|
|
3190
|
+
localCDN: defaultWindow ? (defaultWindow.h_utils?.cdn?.path || '/local-cdn') : '',
|
|
3191
|
+
};
|
|
3192
|
+
const cdnMapping = {
|
|
3193
|
+
// 全屏
|
|
3194
|
+
screenfull: (version = '5.2.0') => ({
|
|
3195
|
+
version,
|
|
3196
|
+
instance: () => defaultWindow ? defaultWindow.screenfull : undefined,
|
|
3197
|
+
source: {
|
|
3198
|
+
jsdelivr: { js: [`${baseCdnUrl.jsdelivr}/screenfull@${version}`] },
|
|
3199
|
+
defaultBase: { js: [`${baseCdnUrl.defaultBase}/screenfull.js/${version}/screenfull.min.js`] },
|
|
3200
|
+
localCDN: { js: [`${baseCdnUrl.localCDN}/screenfull/${version}/screenfull.min.js`] },
|
|
3201
|
+
},
|
|
3202
|
+
}),
|
|
3203
|
+
// 复制黏贴
|
|
3204
|
+
clipboard: (version = '2.0.8') => ({
|
|
3205
|
+
version,
|
|
3206
|
+
instance: () => defaultWindow ? defaultWindow.ClipboardJS : undefined,
|
|
3207
|
+
source: {
|
|
3208
|
+
jsdelivr: { js: [`${baseCdnUrl.jsdelivr}/clipboard@${version}`] },
|
|
3209
|
+
defaultBase: { js: [`${baseCdnUrl.defaultBase}/clipboard.js/${version}/clipboard.min.js`] },
|
|
3210
|
+
localCDN: { js: [`${baseCdnUrl.localCDN}/clipboard/${version}/clipboard.min.js`] },
|
|
3211
|
+
},
|
|
3212
|
+
}),
|
|
3213
|
+
// 富文本编辑器
|
|
3214
|
+
tinymce: (version = '5.8.1') => ({
|
|
3215
|
+
version,
|
|
3216
|
+
instance: () => defaultWindow ? defaultWindow.tinyMCE : undefined,
|
|
3217
|
+
source: {
|
|
3218
|
+
jsdelivr: { js: [`${baseCdnUrl.jsdelivr}/tinymce@${version}`] },
|
|
3219
|
+
defaultBase: { js: [`${baseCdnUrl.defaultBase}/tinymce/${version}/tinymce.min.js`] },
|
|
3220
|
+
localCDN: { js: [`${baseCdnUrl.localCDN}/tinymce/${version}/tinymce.min.js`] },
|
|
3221
|
+
},
|
|
3222
|
+
}),
|
|
3223
|
+
// 二维码生成
|
|
3224
|
+
qrcodeGe: (version = '1.4.4') => ({
|
|
3225
|
+
version,
|
|
3226
|
+
instance: () => defaultWindow ? defaultWindow.qrcode : undefined,
|
|
3227
|
+
source: {
|
|
3228
|
+
jsdelivr: { js: [`${baseCdnUrl.jsdelivr}/qrcode-generator@${version}`] },
|
|
3229
|
+
defaultBase: { js: [`${baseCdnUrl.defaultBase}/qrcode-generator/${version}/qrcode.min.js`] },
|
|
3230
|
+
localCDN: { js: [`${baseCdnUrl.localCDN}/qrcode-generator/${version}/qrcode.min.js`] },
|
|
3231
|
+
},
|
|
3232
|
+
}),
|
|
3233
|
+
// 二维码生成
|
|
3234
|
+
QRCode: (version = '1.5.1') => ({
|
|
3235
|
+
version,
|
|
3236
|
+
instance: () => defaultWindow ? defaultWindow.QRCode : undefined,
|
|
3237
|
+
source: {
|
|
3238
|
+
jsdelivr: { js: [`${baseCdnUrl.jsdelivr}/qrcode@${version}/build/qrcode.min.js`] },
|
|
3239
|
+
defaultBase: { js: [`${baseCdnUrl.defaultBase}/qrcodejs/${version}/qrcode.min.js`] },
|
|
3240
|
+
localCDN: { js: [`${baseCdnUrl.localCDN}/qrcode/${version}/qrcode.min.js`] },
|
|
3241
|
+
},
|
|
3242
|
+
}),
|
|
3243
|
+
// 千分位
|
|
3244
|
+
cleave: (version = '1.6.0') => ({
|
|
3245
|
+
version,
|
|
3246
|
+
instance: () => defaultWindow ? defaultWindow.Cleave : undefined,
|
|
3247
|
+
source: {
|
|
3248
|
+
jsdelivr: { js: [`${baseCdnUrl.jsdelivr}/cleave.js@${version}`] },
|
|
3249
|
+
defaultBase: { js: [`${baseCdnUrl.defaultBase}/cleave.js/${version}/cleave.min.js`] },
|
|
3250
|
+
localCDN: { js: [`${baseCdnUrl.localCDN}/cleave/${version}/cleave.min.js`] },
|
|
3251
|
+
},
|
|
3252
|
+
}),
|
|
3253
|
+
// fontawesome 全量css版本
|
|
3254
|
+
fontawesomeCss: (version = '6.1.2') => ({
|
|
3255
|
+
version,
|
|
3256
|
+
instance: () => defaultWindow,
|
|
3257
|
+
source: {
|
|
3258
|
+
jsdelivr: { js: [], css: [`${baseCdnUrl.jsdelivr}/@fortawesome/fontawesome-free@${version}/css/all.min.css`] },
|
|
3259
|
+
defaultBase: { js: [], css: [`${baseCdnUrl.defaultBase}/font-awesome/${version}/css/all.min.css`] },
|
|
3260
|
+
localCDN: { js: [], css: [`${baseCdnUrl.localCDN}/font-awesome/${version}/css/all.min.css`] },
|
|
3261
|
+
},
|
|
3262
|
+
}),
|
|
3263
|
+
// fontawesome 全量js版本
|
|
3264
|
+
fontawesomeJs: (version = '6.1.2') => ({
|
|
3265
|
+
version,
|
|
3266
|
+
instance: () => defaultWindow,
|
|
3267
|
+
source: {
|
|
3268
|
+
jsdelivr: { js: [`${baseCdnUrl.jsdelivr}/@fortawesome/fontawesome-free@${version}/js/all.min.js`] },
|
|
3269
|
+
defaultBase: { js: [`${baseCdnUrl.defaultBase}/font-awesome/${version}/js/all.min.js`] },
|
|
3270
|
+
localCDN: { js: [`${baseCdnUrl.localCDN}/font-awesome/${version}/js/all.min.js`] },
|
|
3271
|
+
},
|
|
3272
|
+
}),
|
|
3273
|
+
cropper: (version = '1.5.12') => ({
|
|
3274
|
+
version,
|
|
3275
|
+
instance: () => defaultWindow ? defaultWindow.Cropper : undefined,
|
|
3276
|
+
source: {
|
|
3277
|
+
jsdelivr: { js: [`${baseCdnUrl.jsdelivr}/cropperjs@${version}`], css: [`${baseCdnUrl.jsdelivr}/cropperjs@${version}/dist/cropper.min.css`] },
|
|
3278
|
+
defaultBase: { js: [`${baseCdnUrl.defaultBase}/cropperjs/${version}/cropper.min.js`], css: [`${baseCdnUrl.defaultBase}/cropperjs/${version}/cropper.min.css`] },
|
|
3279
|
+
localCDN: { js: [`${baseCdnUrl.localCDN}/cropperjs/${version}/cropper.min.js`], css: [`${baseCdnUrl.localCDN}/cropperjs/${version}/cropper.min.css`] },
|
|
3280
|
+
},
|
|
3281
|
+
}),
|
|
3282
|
+
// flagIcons
|
|
3283
|
+
flagIcons: (version = '6.6.6') => ({
|
|
3284
|
+
version,
|
|
3285
|
+
instance: () => defaultWindow,
|
|
3286
|
+
source: {
|
|
3287
|
+
jsdelivr: { js: [], css: [`${baseCdnUrl.jsdelivr}/flag-icons@${version}/css/flag-icons.min.css`] },
|
|
3288
|
+
defaultBase: { js: [], css: [`${baseCdnUrl.defaultBase}/flag-icons/${version}/css/flag-icons.min.css`] },
|
|
3289
|
+
localCDN: { js: [], css: [`${baseCdnUrl.localCDN}/flag-icons/${version}/css/flag-icons.min.css`] },
|
|
3290
|
+
},
|
|
3291
|
+
}),
|
|
3292
|
+
};
|
|
3293
|
+
const cdnSource = (name, version) => {
|
|
3294
|
+
if (!defaultWindow) {
|
|
3295
|
+
return;
|
|
3296
|
+
}
|
|
3297
|
+
const cdnName = (window.h_utils?.cdn?.name || 'jsdelivr');
|
|
3298
|
+
const resource = cdnMapping[name];
|
|
3299
|
+
if (!resource) {
|
|
3300
|
+
const defaultResource = {
|
|
3301
|
+
instance: () => ({}),
|
|
3302
|
+
js: [`${baseCdnUrl.defaultBase}/${cdnName}.js/${version}/${cdnName}.min.js`],
|
|
3303
|
+
css: [`${baseCdnUrl.defaultBase}/${cdnName}/${version}/${cdnName}.min.css`],
|
|
3304
|
+
};
|
|
3305
|
+
return defaultResource;
|
|
3306
|
+
}
|
|
3307
|
+
const item = resource(version);
|
|
3308
|
+
return Object.assign({ instance: undefined, js: [], css: [], version: '' }, { ...item.source[cdnName], instance: item.instance, version: item.version });
|
|
3309
|
+
};
|
|
3310
|
+
|
|
3311
|
+
// 动态加载js文件和css文件
|
|
3312
|
+
const FLAG_LOADEED = 'yes';
|
|
3313
|
+
// 指定url的js是否已加载
|
|
3314
|
+
const isScriptLoaded = (url) => {
|
|
3315
|
+
const script = url && document.querySelector(`script[src="${url}"]`);
|
|
3316
|
+
return !!(script && script.dataset.loader === FLAG_LOADEED);
|
|
3317
|
+
};
|
|
3318
|
+
// 获取指定url正在加载中的的js,如还未加载返回null
|
|
3319
|
+
const getScript = (url) => {
|
|
3320
|
+
const script = url && document.querySelector(`script[src="${url}"]`);
|
|
3321
|
+
return script && !script.dataset.loader ? script : null;
|
|
3322
|
+
};
|
|
3323
|
+
// 指定url的css是否已加载
|
|
3324
|
+
const isCssLoaded = (url) => !!(url && document.querySelector(`link[href="${url}"]`));
|
|
3325
|
+
// 加载单个js
|
|
3326
|
+
const loadScriptSingle = (url) => new Promise((resolve, reject) => {
|
|
3327
|
+
// 如果已经加载,直接返回
|
|
3328
|
+
if (isScriptLoaded(url)) {
|
|
3329
|
+
resolve(true);
|
|
3330
|
+
}
|
|
3331
|
+
else {
|
|
3332
|
+
const myScript = getScript(url);
|
|
3333
|
+
// (非)多个程序同时加载同一个cdn资源
|
|
3334
|
+
if (!myScript) {
|
|
3335
|
+
const head = document.getElementsByTagName('head')[0];
|
|
3336
|
+
const script = document.createElement('script');
|
|
3337
|
+
script.type = 'text/javascript';
|
|
3338
|
+
script.src = url;
|
|
3339
|
+
script.onload = () => {
|
|
3340
|
+
script.dataset.loaded = FLAG_LOADEED;
|
|
3341
|
+
resolve(true);
|
|
3342
|
+
};
|
|
3343
|
+
// 加载失败删除标签,并返回reject
|
|
3344
|
+
script.onerror = () => {
|
|
3345
|
+
head.removeChild(script);
|
|
3346
|
+
reject(new Error('load failed'));
|
|
3347
|
+
};
|
|
3348
|
+
head.appendChild(script);
|
|
3349
|
+
}
|
|
3350
|
+
else { // 多个程序同时加载同一个cdn资源,则用计时器检测loader状态
|
|
3351
|
+
const timeout = 10000; // 检测超时上限
|
|
3352
|
+
const interval = 10; // 检测频率
|
|
3353
|
+
let times = 0; // 已用时
|
|
3354
|
+
const timer = setInterval(() => {
|
|
3355
|
+
times += interval;
|
|
3356
|
+
// 加载超时
|
|
3357
|
+
if (times >= timeout) {
|
|
3358
|
+
clearInterval(timer);
|
|
3359
|
+
reject(new Error('time out!'));
|
|
3360
|
+
}
|
|
3361
|
+
if (myScript.dataset.loaded === FLAG_LOADEED) {
|
|
3362
|
+
clearInterval(timer);
|
|
3363
|
+
resolve(true);
|
|
3364
|
+
}
|
|
3365
|
+
}, interval);
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
});
|
|
3369
|
+
// 加载js
|
|
3370
|
+
const loadScript = async (urls, options = { sequence: true }) => {
|
|
3371
|
+
// 按顺序加载
|
|
3372
|
+
if (options.sequence) {
|
|
3373
|
+
try {
|
|
3374
|
+
for (let i = 0; i < urls.length; i += 1) {
|
|
3375
|
+
await loadScriptSingle(urls[i]);
|
|
3376
|
+
}
|
|
3377
|
+
return Promise.resolve(true);
|
|
3378
|
+
}
|
|
3379
|
+
catch (e) {
|
|
3380
|
+
return Promise.reject(e);
|
|
3381
|
+
}
|
|
3382
|
+
}
|
|
3383
|
+
return Promise.all(urls.map(url => loadScriptSingle(url)));
|
|
3384
|
+
};
|
|
3385
|
+
// 加载css
|
|
3386
|
+
const loadCss = (urls) => {
|
|
3387
|
+
const head = document.getElementsByTagName('head')[0];
|
|
3388
|
+
urls.filter(url => !isCssLoaded(url))
|
|
3389
|
+
.forEach(url => {
|
|
3390
|
+
const link = document.createElement('link');
|
|
3391
|
+
link.type = 'text/css';
|
|
3392
|
+
link.rel = 'stylesheet';
|
|
3393
|
+
link.href = url;
|
|
3394
|
+
head.appendChild(link);
|
|
3395
|
+
});
|
|
3396
|
+
};
|
|
3397
|
+
// 按库名加载cdn资源
|
|
3398
|
+
const loadCdnSingle = (name, version) => {
|
|
3399
|
+
const { js = [], css, instance } = cdnSource(name, version) || {};
|
|
3400
|
+
Array.isArray(css) && css.length > 0 && loadCss(css);
|
|
3401
|
+
return new Promise((resolve, reject) => {
|
|
3402
|
+
loadScript(js)
|
|
3403
|
+
.then(() => resolve(instance?.()))
|
|
3404
|
+
.catch(() => reject(new Error(`加载 ${name} 失败`)));
|
|
3405
|
+
});
|
|
3406
|
+
};
|
|
3407
|
+
// 按库名批量加载cdn资源
|
|
3408
|
+
const loadCdn = (names) => Promise.all(names.map(name => loadCdnSingle(name)));
|
|
3409
|
+
var index = {
|
|
3410
|
+
loadScriptSingle,
|
|
3411
|
+
loadScript,
|
|
3412
|
+
loadCss,
|
|
3413
|
+
loadCdnSingle,
|
|
3414
|
+
loadCdn,
|
|
3415
|
+
baseCdnUrl,
|
|
3416
|
+
cdnMapping,
|
|
3417
|
+
cdnSource,
|
|
3418
|
+
};
|
|
3419
|
+
|
|
3420
|
+
export { defaultWindow as d, file as f, index as i, storage as s };
|