message-verify 0.0.46-beta.0 → 0.0.48-beta.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/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export declare const getFingerprint: () => Promise<string>;
1
2
  export type ModalConfig = {
2
3
  data: string;
3
4
  onClose?: () => void;
package/dist/index.js CHANGED
@@ -1,6 +1,20 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import ReactDOM from 'react-dom/client';
3
3
  import VerifyModal from './verify-modal.js';
4
+ import Fingerprint2 from 'fingerprintjs2';
5
+ export const getFingerprint = () => {
6
+ return new Promise((resolve) => {
7
+ Fingerprint2.get(function (components) {
8
+ const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
9
+ const values = components
10
+ .filter(component => includeKeys.includes(component.key))
11
+ .map(component => component.value)
12
+ .join('###');
13
+ const fingerprint = Fingerprint2.x64hash128(values, 31);
14
+ resolve(fingerprint);
15
+ });
16
+ });
17
+ };
4
18
  let modalRoot = null;
5
19
  export const createMessageVerifyModal = (modalProps) => {
6
20
  const container = document.createElement('div');
@@ -37,9 +37,6 @@ const CreateMessageVerifyModal = ({ props }) => {
37
37
  clearInterval(timer);
38
38
  };
39
39
  }, [visible, countdown]);
40
- // useEffect(() => {
41
- // console.log('mobile', mobile);
42
- // }, [mobile])
43
40
  const handleResend = async () => {
44
41
  setCountdown(60);
45
42
  const res = await Api.reSendCode({ captchaKey, captcha: captchCode });
@@ -57,7 +54,7 @@ const CreateMessageVerifyModal = ({ props }) => {
57
54
  http(config);
58
55
  setVisible(false);
59
56
  }
60
- } }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, style: { padding: '10px' }, children: countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang) })] }), countdown > 0 ? null :
57
+ } }), _jsx(Button, { disabled: countdown > 0 || !captchCode, onClick: handleResend, style: { padding: '8px' }, children: countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang) })] }), countdown > 0 ? null :
61
58
  _jsxs("div", { style: { marginTop: 12, display: 'flex', alignItems: 'center' }, children: [_jsx(Input, { placeholder: t('pleaseEnterPicVerifyCode', lang), onChange: (e) => {
62
59
  setCaptchCode(e);
63
60
  }, style: { width: 300 } }), captchaImage && _jsx("img", { src: captchaImage, alt: t('verifyCode', lang), style: { width: 100, height: 30, marginLeft: 8 }, onClick: getKey })] }), (countdown > 0 || captchCode) ? null : _jsx("div", { style: { fontSize: 14, color: 'red' }, children: t('pleaseEnterAndSend', lang) })] }));
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "0.0.46-beta.0",
3
+ "version": "0.0.48-beta.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {
7
7
  "@yqg/resource": "^1.3.8",
8
+ "fingerprintjs2": "^2.1.4",
8
9
  "react": "^19.0.0",
9
10
  "react-dom": "^19.0.0"
10
11
  },
11
12
  "devDependencies": {
12
13
  "@eslint/js": "^9.22.0",
14
+ "@types/fingerprintjs2": "^2.0.0",
13
15
  "@types/react": "^19.0.10",
14
16
  "@types/react-dom": "^19.0.4",
15
17
  "@vitejs/plugin-react": "^4.3.4",
package/src/index.tsx CHANGED
@@ -1,5 +1,20 @@
1
1
  import ReactDOM from 'react-dom/client'
2
2
  import VerifyModal from './verify-modal.js'
3
+ import Fingerprint2 from 'fingerprintjs2';
4
+
5
+ export const getFingerprint = (): Promise<string> => {
6
+ return new Promise((resolve) => {
7
+ Fingerprint2.get(function (components) {
8
+ const includeKeys = ['userAgent', 'deviceMemory', 'cpuClass', 'hardwareConcurrency', 'platform'];
9
+ const values = components
10
+ .filter(component => includeKeys.includes(component.key))
11
+ .map(component => component.value)
12
+ .join('###');
13
+ const fingerprint = Fingerprint2.x64hash128(values, 31);
14
+ resolve(fingerprint);
15
+ });
16
+ });
17
+ };
3
18
 
4
19
  export type ModalConfig = {
5
20
  data: string;
@@ -20,6 +20,7 @@ type ModalConfig = {
20
20
  };
21
21
  }
22
22
  const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
23
+
23
24
  const [visible, setVisible] = useState(true);
24
25
  const [countdown, setCountdown] = useState(3);
25
26
  const [otp, setOtp] = useState('');
@@ -34,7 +35,7 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
34
35
  const res = await Api.getCaptchaKey();
35
36
  const { body: key } = res.data || {};
36
37
  setCaptchaKey(key);
37
- if(key) {
38
+ if (key) {
38
39
  const image = Api.getCaptchaImgUrl(key) as unknown;
39
40
  setCaptchaImage(image as string);
40
41
  }
@@ -55,64 +56,60 @@ const CreateMessageVerifyModal = ({ props }: { props: ModalConfig }) => {
55
56
  };
56
57
  }, [visible, countdown]);
57
58
 
58
- // useEffect(() => {
59
- // console.log('mobile', mobile);
60
- // }, [mobile])
61
-
62
- const handleResend = async() => {
59
+ const handleResend = async () => {
63
60
  setCountdown(60);
64
- const res = await Api.reSendCode({captchaKey, captcha: captchCode});
61
+ const res = await Api.reSendCode({ captchaKey, captcha: captchCode });
65
62
  console.log('handleResend=>res', res);
66
63
  message.success(t('sendSuccess', lang));
67
64
  }
68
-
65
+
69
66
  return (
70
- <Modal
71
- width={420}
72
- visible={visible}
73
- onClose={() => {
74
- setVisible(false);
75
- props.onClose?.();
76
- }}
77
- >
78
- <div style={{ fontSize: 14, color: '#666' }}>{t('alreadySend', lang, { phone: mobile})}</div>
79
-
80
- <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 12 }}>
81
- <Input.OTP
82
- length={6}
83
- value={otp}
84
- onChange={(val) => {
85
- setOtp(val);
86
- if(val.length === 6) {
87
- http.defaults.headers.common['sms-code'] = val as string;
88
- http.defaults.headers.common['sms-code-key'] = verifyCodeKey as string;
89
- http(config);
90
- setVisible(false);
91
- }
92
- }} />
93
- <Button
94
- disabled={countdown > 0 || !captchCode}
95
- onClick={handleResend}
96
- style={{ padding: '10px' }}
97
- >
98
- {countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang)}
99
- </Button>
100
- </div>
101
- {countdown > 0 ? null :
102
- <div style={{ marginTop: 12, display: 'flex', alignItems: 'center' }}>
103
- <Input
104
- placeholder={t('pleaseEnterPicVerifyCode', lang)}
105
- onChange={(e) => {
106
- setCaptchCode(e as string)
107
- }}
108
- style={{ width: 300 }}
109
- />
110
-
111
- {captchaImage && <img src={captchaImage} alt={t('verifyCode', lang)} style={{ width: 100, height: 30, marginLeft: 8 }} onClick={getKey} />}
112
- </div>}
113
- {(countdown > 0 || captchCode) ? null : <div style={{ fontSize: 14, color: 'red' }}>{t('pleaseEnterAndSend', lang)}</div>}
114
- </Modal>
67
+ <Modal
68
+ width={420}
69
+ visible={visible}
70
+ onClose={() => {
71
+ setVisible(false);
72
+ props.onClose?.();
73
+ }}
74
+ >
75
+ <div style={{ fontSize: 14, color: '#666' }}>{t('alreadySend', lang, { phone: mobile })}</div>
76
+
77
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 12 }}>
78
+ <Input.OTP
79
+ length={6}
80
+ value={otp}
81
+ onChange={(val) => {
82
+ setOtp(val);
83
+ if (val.length === 6) {
84
+ http.defaults.headers.common['sms-code'] = val as string;
85
+ http.defaults.headers.common['sms-code-key'] = verifyCodeKey as string;
86
+ http(config);
87
+ setVisible(false);
88
+ }
89
+ }} />
90
+ <Button
91
+ disabled={countdown > 0 || !captchCode}
92
+ onClick={handleResend}
93
+ style={{ padding: '8px' }}
94
+ >
95
+ {countdown > 0 ? t('countDownSecound', lang, { countdown }) : t('reSend', lang)}
96
+ </Button>
97
+ </div>
98
+ {countdown > 0 ? null :
99
+ <div style={{ marginTop: 12, display: 'flex', alignItems: 'center' }}>
100
+ <Input
101
+ placeholder={t('pleaseEnterPicVerifyCode', lang)}
102
+ onChange={(e) => {
103
+ setCaptchCode(e as string)
104
+ }}
105
+ style={{ width: 300 }}
106
+ />
107
+
108
+ {captchaImage && <img src={captchaImage} alt={t('verifyCode', lang)} style={{ width: 100, height: 30, marginLeft: 8 }} onClick={getKey} />}
109
+ </div>}
110
+ {(countdown > 0 || captchCode) ? null : <div style={{ fontSize: 14, color: 'red' }}>{t('pleaseEnterAndSend', lang)}</div>}
111
+ </Modal>
115
112
  );
116
- };
113
+ };
117
114
 
118
115
  export default CreateMessageVerifyModal;