@a-drowned-fish/om-utils 1.0.28 → 1.0.29
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.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e,n,r,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e,i,n,r,s,o,a,c,l,h,f,d,u,p=require("@fingerprintjs/fingerprintjs"),w=require("sm-crypto"),m=require("node-forge");function v(t,e,i,n){return new(i||(i=Promise))(function(r,s){function o(t){try{c(n.next(t))}catch(t){s(t)}}function a(t){try{c(n.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,a)}c((n=n.apply(t,e||[])).next())})}function y(t,e,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(t):n?n.value:e.get(t)}function g(t,e,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(t,i):r?r.value=i:e.set(t,i),i}"function"==typeof SuppressedError&&SuppressedError;const{sm2:E,sm4:M}=w;function b(t){return v(this,void 0,void 0,function*(){return new Promise(e=>setTimeout(e,t))})}function k(t,e={}){const{allowLeadingZero:i=!1,type:n="number"}=e;if(!Number.isInteger(t))throw new Error("长度必须是整数");const r={number:"0123456789",alphanumeric:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"},s=r[n]||r.number;let o="";o+=i||"number"!==n?s[Math.floor(Math.random()*s.length)]:s[Math.floor(9*Math.random()+1)];for(let e=1;e<t;e++)o+=s[Math.floor(Math.random()*s.length)];return o}class P{constructor(w,m={}){t.set(this,""),e.set(this,""),i.set(this,""),n.set(this,""),r.set(this,!1),s.set(this,""),o.set(this,()=>y(this,a,"f").call(this,y(this,e,"f"))),a.set(this,t=>{const e=new Uint8Array(t.length/2);for(let i=0;i<e.length;i++)e[i]=parseInt(t.substring(2*i,2*i+2),16);return Array.from(e)}),c.set(this,t=>Array.from(t).map(t=>t.toString(16).padStart(2,"0")).join("")),l.set(this,()=>"undefined"!=typeof window&&"undefined"!=typeof document),h.set(this,()=>y(this,l,"f").call(this)?window.crypto||window.msCrypto:null),f.set(this,()=>{var t,e;return null===(e=null===(t=y(this,h,"f").call(this))||void 0===t?void 0:t.getRandomValues)||void 0===e?void 0:e.call(t,new Uint8Array(16))}),d.set(this,t=>{var e,i,n,r,s;if(!t)return"";const c=y(this,o,"f").call(this),l=y(this,a,"f").call(this,t),h=l.slice(0,16),f=l.slice(16);let d=null===(i=null===(e=M.decrypt(f,c,{mode:"cbc",iv:h}))||void 0===e?void 0:e.trim)||void 0===i?void 0:i.call(e);if(/^[0-9A-Fa-f]{64}$/.test(d))d=d.toUpperCase();else{const t=null===(n=null==d?void 0:d.match)||void 0===n?void 0:n.call(d,/0201010420([0-9A-Fa-f]{64})/i);if(t&&(null==t?void 0:t[1]))d=null===(s=null===(r=t[1])||void 0===r?void 0:r.toUpperCase)||void 0===s?void 0:s.call(r);else{const t=d.match(/04([0-9A-Fa-f]{64})/i);t&&t[1]&&(d=t[1].toUpperCase())}}return d}),u.set(this,()=>v(this,void 0,void 0,function*(){return y(this,i,"f")?y(this,i,"f"):y(this,r,"f")?(yield b(100),yield y(this,u,"f").call(this)):(g(this,r,!0,"f"),p.load().then(t=>t.get()).then(t=>(g(this,r,!1,"f"),g(this,i,y(this,n,"f")+t.visitorId,"f"),y(this,i,"f"))))})),this.setAccessToken=t=>{t&&g(this,s,y(this,d,"f").call(this,t),"f")},this.getRegisterBody=()=>v(this,void 0,void 0,function*(){y(this,i,"f")||(yield y(this,u,"f").call(this));const t={d:y(this,i,"f"),n:k(32,{type:"alphanumeric"}),t:Date.now().toString(),s:""},e=t.d+t.t+t.n,n=y(this,o,"f").call(this),r=y(this,f,"f").call(this);return t.s=y(this,c,"f").call(this,r)+M.encrypt(e,n,{mode:"cbc",iv:r}),t}),this.getPublicHeaders=()=>v(this,void 0,void 0,function*(){var n,r;if(y(this,i,"f")||(yield y(this,u,"f").call(this)),!y(this,s,"f"))return yield b(100),yield this.getPublicHeaders();const o={"X-T":Date.now().toString(),"X-N":k(32,{type:"alphanumeric"}),"X-DI":y(this,i,"f"),"X-S":""},a=y(this,e,"f")+y(this,i,"f")+o["X-N"]+o["X-T"];return o["X-S"]=null===(r=null===(n=E.doSignature(a,y(this,s,"f"),{hash:!0,der:!1,mode:0,userId:y(this,t,"f")}))||void 0===n?void 0:n.toUpperCase)||void 0===r?void 0:r.call(n),o});const{uId:P="1234567812345678",deviceId:S,deviceIdPrefix:I=""}=m;g(this,e,w,"f"),g(this,t,P,"f"),g(this,n,I,"f"),S?g(this,i,S,"f"):"undefined"!=typeof window&&"undefined"!=typeof document&&y(this,u,"f").call(this)}}t=new WeakMap,e=new WeakMap,i=new WeakMap,n=new WeakMap,r=new WeakMap,s=new WeakMap,o=new WeakMap,a=new WeakMap,c=new WeakMap,l=new WeakMap,h=new WeakMap,f=new WeakMap,d=new WeakMap,u=new WeakMap;const S=function(t){let e=null;const i=new Proxy(t,{construct:(t,i)=>e||(e="undefined"!=typeof Reflect&&Reflect.construct?Reflect.construct(t,i):new t(...i),e)});return i.prototype.constructor=i,i}(P);exports.BaseOmUtils=P,exports.OmUtils=S,exports.default=S,exports.rsaOaepEncrypt=function(t,e,i={}){const{outputEncoding:n="hex",oaepHash:r="SHA-256",mgf1Hash:s=r}=i,o=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");let a;try{a=m.pki.publicKeyFromPem(o)}catch(t){try{const t=`-----BEGIN PUBLIC KEY-----\n${o}\n-----END PUBLIC KEY-----`;a=m.pki.publicKeyFromPem(t)}catch(t){throw new Error(`Invalid public key: ${t instanceof Error?t.message:String(t)}`)}}const c="SHA-256"===r?m.md.sha256.create():m.md.sha1.create(),l="SHA-256"===s?m.md.sha256.create():m.md.sha1.create();let h;try{h=a.encrypt(t,"RSA-OAEP",{md:c,mgf1Md:l})}catch(t){throw new Error(`RSA encryption failed: ${t instanceof Error?t.message:String(t)}`)}if("hex"===n)return m.util.bytesToHex(h);if("base64"===n)return m.util.encode64(h);throw new Error(`Unsupported output encoding: ${n}`)};
|
package/dist/index.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"@fingerprintjs/fingerprintjs";import e from"sm-crypto";import
|
|
1
|
+
import t from"@fingerprintjs/fingerprintjs";import e from"sm-crypto";import i from"node-forge";function n(t,e,i,n){return new(i||(i=Promise))(function(r,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(s,a)}c((n=n.apply(t,e||[])).next())})}function r(t,e,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(t):n?n.value:e.get(t)}function o(t,e,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(t,i):r?r.value=i:e.set(t,i),i}function s(t,e,n={}){const{outputEncoding:r="hex",oaepHash:o="SHA-256",mgf1Hash:s=o}=n,a=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");let c;try{c=i.pki.publicKeyFromPem(a)}catch(t){try{const t=`-----BEGIN PUBLIC KEY-----\n${a}\n-----END PUBLIC KEY-----`;c=i.pki.publicKeyFromPem(t)}catch(t){throw new Error(`Invalid public key: ${t instanceof Error?t.message:String(t)}`)}}const l="SHA-256"===o?i.md.sha256.create():i.md.sha1.create(),h="SHA-256"===s?i.md.sha256.create():i.md.sha1.create();let f;try{f=c.encrypt(t,"RSA-OAEP",{md:l,mgf1Md:h})}catch(t){throw new Error(`RSA encryption failed: ${t instanceof Error?t.message:String(t)}`)}if("hex"===r)return i.util.bytesToHex(f);if("base64"===r)return i.util.encode64(f);throw new Error(`Unsupported output encoding: ${r}`)}var a,c,l,h,f,d,u,p,w,m,v,y,g,E;"function"==typeof SuppressedError&&SuppressedError;const{sm2:M,sm4:b}=e;function k(t){return n(this,void 0,void 0,function*(){return new Promise(e=>setTimeout(e,t))})}function P(t,e={}){const{allowLeadingZero:i=!1,type:n="number"}=e;if(!Number.isInteger(t))throw new Error("长度必须是整数");const r={number:"0123456789",alphanumeric:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"},o=r[n]||r.number;let s="";s+=i||"number"!==n?o[Math.floor(Math.random()*o.length)]:o[Math.floor(9*Math.random()+1)];for(let e=1;e<t;e++)s+=o[Math.floor(Math.random()*o.length)];return s}class S{constructor(e,i={}){a.set(this,""),c.set(this,""),l.set(this,""),h.set(this,""),f.set(this,!1),d.set(this,""),u.set(this,()=>r(this,p,"f").call(this,r(this,c,"f"))),p.set(this,t=>{const e=new Uint8Array(t.length/2);for(let i=0;i<e.length;i++)e[i]=parseInt(t.substring(2*i,2*i+2),16);return Array.from(e)}),w.set(this,t=>Array.from(t).map(t=>t.toString(16).padStart(2,"0")).join("")),m.set(this,()=>"undefined"!=typeof window&&"undefined"!=typeof document),v.set(this,()=>r(this,m,"f").call(this)?window.crypto||window.msCrypto:null),y.set(this,()=>{var t,e;return null===(e=null===(t=r(this,v,"f").call(this))||void 0===t?void 0:t.getRandomValues)||void 0===e?void 0:e.call(t,new Uint8Array(16))}),g.set(this,t=>{var e,i,n,o,s;if(!t)return"";const a=r(this,u,"f").call(this),c=r(this,p,"f").call(this,t),l=c.slice(0,16),h=c.slice(16);let f=null===(i=null===(e=b.decrypt(h,a,{mode:"cbc",iv:l}))||void 0===e?void 0:e.trim)||void 0===i?void 0:i.call(e);if(/^[0-9A-Fa-f]{64}$/.test(f))f=f.toUpperCase();else{const t=null===(n=null==f?void 0:f.match)||void 0===n?void 0:n.call(f,/0201010420([0-9A-Fa-f]{64})/i);if(t&&(null==t?void 0:t[1]))f=null===(s=null===(o=t[1])||void 0===o?void 0:o.toUpperCase)||void 0===s?void 0:s.call(o);else{const t=f.match(/04([0-9A-Fa-f]{64})/i);t&&t[1]&&(f=t[1].toUpperCase())}}return f}),E.set(this,()=>n(this,void 0,void 0,function*(){return r(this,l,"f")?r(this,l,"f"):r(this,f,"f")?(yield k(100),yield r(this,E,"f").call(this)):(o(this,f,!0,"f"),t.load().then(t=>t.get()).then(t=>(o(this,f,!1,"f"),o(this,l,r(this,h,"f")+t.visitorId,"f"),r(this,l,"f"))))})),this.setAccessToken=t=>{t&&o(this,d,r(this,g,"f").call(this,t),"f")},this.getRegisterBody=()=>n(this,void 0,void 0,function*(){r(this,l,"f")||(yield r(this,E,"f").call(this));const t={d:r(this,l,"f"),n:P(32,{type:"alphanumeric"}),t:Date.now().toString(),s:""},e=t.d+t.t+t.n,i=r(this,u,"f").call(this),n=r(this,y,"f").call(this);return t.s=r(this,w,"f").call(this,n)+b.encrypt(e,i,{mode:"cbc",iv:n}),t}),this.getPublicHeaders=()=>n(this,void 0,void 0,function*(){var t,e;if(r(this,l,"f")||(yield r(this,E,"f").call(this)),!r(this,d,"f"))return yield k(100),yield this.getPublicHeaders();const i={"X-T":Date.now().toString(),"X-N":P(32,{type:"alphanumeric"}),"X-DI":r(this,l,"f"),"X-S":""},n=r(this,c,"f")+r(this,l,"f")+i["X-N"]+i["X-T"];return i["X-S"]=null===(e=null===(t=M.doSignature(n,r(this,d,"f"),{hash:!0,der:!1,mode:0,userId:r(this,a,"f")}))||void 0===t?void 0:t.toUpperCase)||void 0===e?void 0:e.call(t),i});const{uId:s="1234567812345678",deviceId:S,deviceIdPrefix:I=""}=i;o(this,c,e,"f"),o(this,a,s,"f"),o(this,h,I,"f"),S?o(this,l,S,"f"):"undefined"!=typeof window&&"undefined"!=typeof document&&r(this,E,"f").call(this)}}a=new WeakMap,c=new WeakMap,l=new WeakMap,h=new WeakMap,f=new WeakMap,d=new WeakMap,u=new WeakMap,p=new WeakMap,w=new WeakMap,m=new WeakMap,v=new WeakMap,y=new WeakMap,g=new WeakMap,E=new WeakMap;const I=function(t){let e=null;const i=new Proxy(t,{construct:(t,i)=>e||(e="undefined"!=typeof Reflect&&Reflect.construct?Reflect.construct(t,i):new t(...i),e)});return i.prototype.constructor=i,i}(S);export{S as BaseOmUtils,I as OmUtils,I as default,s as rsaOaepEncrypt};
|
package/dist/index.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var omUtils=function(t,e,n
|
|
1
|
+
var omUtils=function(t,e,i,n){"use strict";function r(t,e,i,n){return new(i||(i=Promise))(function(r,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(s,a)}c((n=n.apply(t,e||[])).next())})}function o(t,e,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(t):n?n.value:e.get(t)}function s(t,e,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(t,i):r?r.value=i:e.set(t,i),i}var a,c,l,h,f,d,u,p,w,m,v,y,g,E;"function"==typeof SuppressedError&&SuppressedError;const{sm2:M,sm4:b}=i;function k(t){return r(this,void 0,void 0,function*(){return new Promise(e=>setTimeout(e,t))})}function S(t,e={}){const{allowLeadingZero:i=!1,type:n="number"}=e;if(!Number.isInteger(t))throw new Error("长度必须是整数");const r={number:"0123456789",alphanumeric:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"},o=r[n]||r.number;let s="";s+=i||"number"!==n?o[Math.floor(Math.random()*o.length)]:o[Math.floor(9*Math.random()+1)];for(let e=1;e<t;e++)s+=o[Math.floor(Math.random()*o.length)];return s}class P{constructor(t,i={}){a.set(this,""),c.set(this,""),l.set(this,""),h.set(this,""),f.set(this,!1),d.set(this,""),u.set(this,()=>o(this,p,"f").call(this,o(this,c,"f"))),p.set(this,t=>{const e=new Uint8Array(t.length/2);for(let i=0;i<e.length;i++)e[i]=parseInt(t.substring(2*i,2*i+2),16);return Array.from(e)}),w.set(this,t=>Array.from(t).map(t=>t.toString(16).padStart(2,"0")).join("")),m.set(this,()=>"undefined"!=typeof window&&"undefined"!=typeof document),v.set(this,()=>o(this,m,"f").call(this)?window.crypto||window.msCrypto:null),y.set(this,()=>{var t,e;return null===(e=null===(t=o(this,v,"f").call(this))||void 0===t?void 0:t.getRandomValues)||void 0===e?void 0:e.call(t,new Uint8Array(16))}),g.set(this,t=>{var e,i,n,r,s;if(!t)return"";const a=o(this,u,"f").call(this),c=o(this,p,"f").call(this,t),l=c.slice(0,16),h=c.slice(16);let f=null===(i=null===(e=b.decrypt(h,a,{mode:"cbc",iv:l}))||void 0===e?void 0:e.trim)||void 0===i?void 0:i.call(e);if(/^[0-9A-Fa-f]{64}$/.test(f))f=f.toUpperCase();else{const t=null===(n=null==f?void 0:f.match)||void 0===n?void 0:n.call(f,/0201010420([0-9A-Fa-f]{64})/i);if(t&&(null==t?void 0:t[1]))f=null===(s=null===(r=t[1])||void 0===r?void 0:r.toUpperCase)||void 0===s?void 0:s.call(r);else{const t=f.match(/04([0-9A-Fa-f]{64})/i);t&&t[1]&&(f=t[1].toUpperCase())}}return f}),E.set(this,()=>r(this,void 0,void 0,function*(){return o(this,l,"f")?o(this,l,"f"):o(this,f,"f")?(yield k(100),yield o(this,E,"f").call(this)):(s(this,f,!0,"f"),e.load().then(t=>t.get()).then(t=>(s(this,f,!1,"f"),s(this,l,o(this,h,"f")+t.visitorId,"f"),o(this,l,"f"))))})),this.setAccessToken=t=>{t&&s(this,d,o(this,g,"f").call(this,t),"f")},this.getRegisterBody=()=>r(this,void 0,void 0,function*(){o(this,l,"f")||(yield o(this,E,"f").call(this));const t={d:o(this,l,"f"),n:S(32,{type:"alphanumeric"}),t:Date.now().toString(),s:""},e=t.d+t.t+t.n,i=o(this,u,"f").call(this),n=o(this,y,"f").call(this);return t.s=o(this,w,"f").call(this,n)+b.encrypt(e,i,{mode:"cbc",iv:n}),t}),this.getPublicHeaders=()=>r(this,void 0,void 0,function*(){var t,e;if(o(this,l,"f")||(yield o(this,E,"f").call(this)),!o(this,d,"f"))return yield k(100),yield this.getPublicHeaders();const i={"X-T":Date.now().toString(),"X-N":S(32,{type:"alphanumeric"}),"X-DI":o(this,l,"f"),"X-S":""},n=o(this,c,"f")+o(this,l,"f")+i["X-N"]+i["X-T"];return i["X-S"]=null===(e=null===(t=M.doSignature(n,o(this,d,"f"),{hash:!0,der:!1,mode:0,userId:o(this,a,"f")}))||void 0===t?void 0:t.toUpperCase)||void 0===e?void 0:e.call(t),i});const{uId:n="1234567812345678",deviceId:P,deviceIdPrefix:I=""}=i;s(this,c,t,"f"),s(this,a,n,"f"),s(this,h,I,"f"),P?s(this,l,P,"f"):"undefined"!=typeof window&&"undefined"!=typeof document&&o(this,E,"f").call(this)}}a=new WeakMap,c=new WeakMap,l=new WeakMap,h=new WeakMap,f=new WeakMap,d=new WeakMap,u=new WeakMap,p=new WeakMap,w=new WeakMap,m=new WeakMap,v=new WeakMap,y=new WeakMap,g=new WeakMap,E=new WeakMap;const I=function(t){let e=null;const i=new Proxy(t,{construct:(t,i)=>e||(e="undefined"!=typeof Reflect&&Reflect.construct?Reflect.construct(t,i):new t(...i),e)});return i.prototype.constructor=i,i}(P);return t.BaseOmUtils=P,t.OmUtils=I,t.default=I,t.rsaOaepEncrypt=function(t,e,i={}){const{outputEncoding:r="hex",oaepHash:o="SHA-256",mgf1Hash:s=o}=i,a=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");let c;try{c=n.pki.publicKeyFromPem(a)}catch(t){try{const t=`-----BEGIN PUBLIC KEY-----\n${a}\n-----END PUBLIC KEY-----`;c=n.pki.publicKeyFromPem(t)}catch(t){throw new Error(`Invalid public key: ${t instanceof Error?t.message:String(t)}`)}}const l="SHA-256"===o?n.md.sha256.create():n.md.sha1.create(),h="SHA-256"===s?n.md.sha256.create():n.md.sha1.create();let f;try{f=c.encrypt(t,"RSA-OAEP",{md:l,mgf1Md:h})}catch(t){throw new Error(`RSA encryption failed: ${t instanceof Error?t.message:String(t)}`)}if("hex"===r)return n.util.bytesToHex(f);if("base64"===r)return n.util.encode64(f);throw new Error(`Unsupported output encoding: ${r}`)},Object.defineProperty(t,"__esModule",{value:!0}),t}({},FingerprintJS,SMCrypto,forge);
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@fingerprintjs/fingerprintjs"),require("sm-crypto"),require("node-forge")):"function"==typeof define&&define.amd?define(["exports","@fingerprintjs/fingerprintjs","sm-crypto","node-forge"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).omUtils={},t.FingerprintJS,t.SMCrypto,t.forge)}(this,function(t,e,n
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@fingerprintjs/fingerprintjs"),require("sm-crypto"),require("node-forge")):"function"==typeof define&&define.amd?define(["exports","@fingerprintjs/fingerprintjs","sm-crypto","node-forge"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).omUtils={},t.FingerprintJS,t.SMCrypto,t.forge)}(this,function(t,e,i,n){"use strict";function r(t,e,i,n){return new(i||(i=Promise))(function(r,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(s,a)}c((n=n.apply(t,e||[])).next())})}function o(t,e,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(t):n?n.value:e.get(t)}function s(t,e,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(t,i):r?r.value=i:e.set(t,i),i}var a,c,l,f,h,d,u,p,w,m,y,v,g,b;"function"==typeof SuppressedError&&SuppressedError;const{sm2:E,sm4:M}=i;function k(t){return r(this,void 0,void 0,function*(){return new Promise(e=>setTimeout(e,t))})}function S(t,e={}){const{allowLeadingZero:i=!1,type:n="number"}=e;if(!Number.isInteger(t))throw new Error("长度必须是整数");const r={number:"0123456789",alphanumeric:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"},o=r[n]||r.number;let s="";s+=i||"number"!==n?o[Math.floor(Math.random()*o.length)]:o[Math.floor(9*Math.random()+1)];for(let e=1;e<t;e++)s+=o[Math.floor(Math.random()*o.length)];return s}class P{constructor(t,i={}){a.set(this,""),c.set(this,""),l.set(this,""),f.set(this,""),h.set(this,!1),d.set(this,""),u.set(this,()=>o(this,p,"f").call(this,o(this,c,"f"))),p.set(this,t=>{const e=new Uint8Array(t.length/2);for(let i=0;i<e.length;i++)e[i]=parseInt(t.substring(2*i,2*i+2),16);return Array.from(e)}),w.set(this,t=>Array.from(t).map(t=>t.toString(16).padStart(2,"0")).join("")),m.set(this,()=>"undefined"!=typeof window&&"undefined"!=typeof document),y.set(this,()=>o(this,m,"f").call(this)?window.crypto||window.msCrypto:null),v.set(this,()=>{var t,e;return null===(e=null===(t=o(this,y,"f").call(this))||void 0===t?void 0:t.getRandomValues)||void 0===e?void 0:e.call(t,new Uint8Array(16))}),g.set(this,t=>{var e,i,n,r,s;if(!t)return"";const a=o(this,u,"f").call(this),c=o(this,p,"f").call(this,t),l=c.slice(0,16),f=c.slice(16);let h=null===(i=null===(e=M.decrypt(f,a,{mode:"cbc",iv:l}))||void 0===e?void 0:e.trim)||void 0===i?void 0:i.call(e);if(/^[0-9A-Fa-f]{64}$/.test(h))h=h.toUpperCase();else{const t=null===(n=null==h?void 0:h.match)||void 0===n?void 0:n.call(h,/0201010420([0-9A-Fa-f]{64})/i);if(t&&(null==t?void 0:t[1]))h=null===(s=null===(r=t[1])||void 0===r?void 0:r.toUpperCase)||void 0===s?void 0:s.call(r);else{const t=h.match(/04([0-9A-Fa-f]{64})/i);t&&t[1]&&(h=t[1].toUpperCase())}}return h}),b.set(this,()=>r(this,void 0,void 0,function*(){return o(this,l,"f")?o(this,l,"f"):o(this,h,"f")?(yield k(100),yield o(this,b,"f").call(this)):(s(this,h,!0,"f"),e.load().then(t=>t.get()).then(t=>(s(this,h,!1,"f"),s(this,l,o(this,f,"f")+t.visitorId,"f"),o(this,l,"f"))))})),this.setAccessToken=t=>{t&&s(this,d,o(this,g,"f").call(this,t),"f")},this.getRegisterBody=()=>r(this,void 0,void 0,function*(){o(this,l,"f")||(yield o(this,b,"f").call(this));const t={d:o(this,l,"f"),n:S(32,{type:"alphanumeric"}),t:Date.now().toString(),s:""},e=t.d+t.t+t.n,i=o(this,u,"f").call(this),n=o(this,v,"f").call(this);return t.s=o(this,w,"f").call(this,n)+M.encrypt(e,i,{mode:"cbc",iv:n}),t}),this.getPublicHeaders=()=>r(this,void 0,void 0,function*(){var t,e;if(o(this,l,"f")||(yield o(this,b,"f").call(this)),!o(this,d,"f"))return yield k(100),yield this.getPublicHeaders();const i={"X-T":Date.now().toString(),"X-N":S(32,{type:"alphanumeric"}),"X-DI":o(this,l,"f"),"X-S":""},n=o(this,c,"f")+o(this,l,"f")+i["X-N"]+i["X-T"];return i["X-S"]=null===(e=null===(t=E.doSignature(n,o(this,d,"f"),{hash:!0,der:!1,mode:0,userId:o(this,a,"f")}))||void 0===t?void 0:t.toUpperCase)||void 0===e?void 0:e.call(t),i});const{uId:n="1234567812345678",deviceId:P,deviceIdPrefix:I=""}=i;s(this,c,t,"f"),s(this,a,n,"f"),s(this,f,I,"f"),P?s(this,l,P,"f"):"undefined"!=typeof window&&"undefined"!=typeof document&&o(this,b,"f").call(this)}}a=new WeakMap,c=new WeakMap,l=new WeakMap,f=new WeakMap,h=new WeakMap,d=new WeakMap,u=new WeakMap,p=new WeakMap,w=new WeakMap,m=new WeakMap,y=new WeakMap,v=new WeakMap,g=new WeakMap,b=new WeakMap;const I=function(t){let e=null;const i=new Proxy(t,{construct:(t,i)=>e||(e="undefined"!=typeof Reflect&&Reflect.construct?Reflect.construct(t,i):new t(...i),e)});return i.prototype.constructor=i,i}(P);t.BaseOmUtils=P,t.OmUtils=I,t.default=I,t.rsaOaepEncrypt=function(t,e,i={}){const{outputEncoding:r="hex",oaepHash:o="SHA-256",mgf1Hash:s=o}=i,a=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,"");let c;try{c=n.pki.publicKeyFromPem(a)}catch(t){try{const t=`-----BEGIN PUBLIC KEY-----\n${a}\n-----END PUBLIC KEY-----`;c=n.pki.publicKeyFromPem(t)}catch(t){throw new Error(`Invalid public key: ${t instanceof Error?t.message:String(t)}`)}}const l="SHA-256"===o?n.md.sha256.create():n.md.sha1.create(),f="SHA-256"===s?n.md.sha256.create():n.md.sha1.create();let h;try{h=c.encrypt(t,"RSA-OAEP",{md:l,mgf1Md:f})}catch(t){throw new Error(`RSA encryption failed: ${t instanceof Error?t.message:String(t)}`)}if("hex"===r)return n.util.bytesToHex(h);if("base64"===r)return n.util.encode64(h);throw new Error(`Unsupported output encoding: ${r}`)},Object.defineProperty(t,"__esModule",{value:!0})});
|