You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7 lines
23 KiB

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
3 years ago
var X=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var at=(h,e)=>{for(var t in e)X(h,t,{get:e[t],enumerable:!0})},ct=(h,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of rt(e))!ot.call(h,s)&&s!==t&&X(h,s,{get:()=>e[s],enumerable:!(n=it(e,s))||n.enumerable});return h};var lt=h=>ct(X({},"__esModule",{value:!0}),h);var ft={};at(ft,{default:()=>G});module.exports=lt(ft);var st=require("obsidian");var S=require("obsidian");var O=class{constructor(){this.values=new Map}put(e,t){this.values.set(e,t)}get(e,t){var n;return(n=this.values.get(e))!=null?n:t}getFirst(e,t){for(let n=0;n<e.length;n++){let s=e[n];if(this.containsKey(s))return this.get(s,t)}return t}containsKey(e){return this.values.has(e)}getKeys(){return Array.from(this.values.keys())}clear(){this.values.clear()}};var g=class{static setActive(e){g.isActive=e,g.isActive||this.clear()}static setAutoExpire(e){g.baseMinutesToExpire=e!=null?e:0,g.updateExpiryTime()}static updateExpiryTime(){g.baseMinutesToExpire==0||g.baseMinutesToExpire==null?g.expiryTime=null:g.expiryTime=Date.now()+g.baseMinutesToExpire*1e3*60}static put(e,t){!g.isActive||(this.cache.put(t.path,e),this.cache.put(t.parent.path,e),this.cache.put(t.basename,e),g.updateExpiryTime())}static getExact(e){return g.isActive?(this.clearIfExpired(),g.updateExpiryTime(),this.cache.get(e.path,g.blankPasswordAndHint)):g.blankPasswordAndHint}static getBestGuess(e){return g.isActive?(this.clearIfExpired(),g.updateExpiryTime(),this.cache.getFirst([e.path,e.parent.path,e.basename],g.blankPasswordAndHint)):g.blankPasswordAndHint}static clearIfExpired(){g.expiryTime!=null&&(Date.now()<g.expiryTime||this.clear())}static clear(){this.cache.clear()}},f=g;f.isActive=!0,f.blankPasswordAndHint={password:"",hint:""},f.cache=new O,f.baseMinutesToExpire=0,f.expiryTime=null;var N=class extends S.PluginSettingTab{constructor(t,n,s,i){super(t,n);this.plugin=n,this.settings=s,this.features=i}display(){let{containerEl:t}=this;t.empty(),t.createEl("h1",{text:"Settings for Meld Encrypt"}),new S.Setting(t).setHeading().setName("Common Settings"),new S.Setting(t).setName("Confirm password?").setDesc("Confirm password when encrypting.").addToggle(i=>{i.setValue(this.settings.confirmPassword).onChange(async r=>{this.settings.confirmPassword=r,await this.plugin.saveSettings()})});let n=()=>{if(!this.settings.rememberPassword){s.settingEl.hide();return}s.settingEl.show();let i=this.settings.rememberPasswordTimeout,r=`${i} minutes`;i==0&&(r="Never forget"),s.setName(`Remember Password Timeout (${r})`)};new S.Setting(t).setName("Remember password?").setDesc("Remember the last used passwords when encrypting or decrypting.").addToggle(i=>{i.setValue(this.settings.rememberPassword).onChange(async r=>{this.settings.rememberPassword=r,await this.plugin.saveSettings(),f.setActive(this.settings.rememberPassword),n()})});let s=new S.Setting(t).setDesc("The number of minutes to remember passwords.").addSlider(i=>{i.setLimits(0,120,5).setValue(this.settings.rememberPasswordTimeout).onChange(async r=>{this.settings.rememberPasswordTimeout=r,await this.plugin.saveSettings(),f.setAutoExpire(this.settings.rememberPasswordTimeout),n()})});n(),this.features.forEach(i=>{i.buildSettingsUi(t,async()=>await this.plugin.saveSettings())})}};var v=require("obsidian");var q=new TextEncoder,pt=new TextDecoder,dt=1e3,ut=q.encode("XHWnDAT6ehMVY2zD"),C=class{async deriveKey(e){let t=q.encode(e),n=await crypto.subtle.importKey("raw",t,{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",hash:{name:"SHA-256"},iterations:dt,salt:ut},n,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async encryptToBytes(e,t){let n=await this.deriveKey(t),s=q.encode(e),i=crypto.getRandomValues(new Uint8Array(16)),r=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:i},n,s)),o=new Uint8Array(i.byteLength+r.byteLength);return o.set(i,0),o.set(r,i.byteLength),o}convertToString(e){let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);retur