UNPKG

@pixelfactory/privatebin

Version:
3 lines (2 loc) 2.38 kB
"use strict";var t=require("pako"),e=require("axios"),s=require("isomorphic-webcrypto"),a=require("byte-base64");class n{constructor(t){this.axios=e.create(t)}get(t,e){return this.axios.get(t,e)}post(t,e,s){return this.axios.post(t,e,s)}success(t){return t.data}}function r(t){return s.subtle.importKey("raw",t,"PBKDF2",!1,["deriveBits","deriveKey"])}function i(t,e,a,n){return s.subtle.deriveKey({name:"PBKDF2",salt:e,iterations:a,hash:"SHA-256"},t,{name:"AES-GCM",length:n},!1,["encrypt","decrypt"])}function o(t){return(new TextEncoder).encode(t)}async function c(e,n,c){const{burnafterreading:u,opendiscussion:p,compression:d,textformat:y}=c,g={algo:"aes",mode:"gcm",ks:256,ts:128,iter:1e5,textformat:y,compression:d,burnafterreading:u,opendiscussion:p};let b=o(JSON.stringify({paste:e}));return"zlib"===d&&(b=t.deflateRaw(b)),async function(t,e,n){const c=await r(e),u=s.getRandomValues(new Uint8Array(16)),p=s.getRandomValues(new Uint8Array(8)),d=await i(c,p,n.iter,n.ks),y=[[a.bytesToBase64(u),a.bytesToBase64(p),n.iter,n.ks,n.ts,n.algo,n.mode,n.compression],n.textformat,n.opendiscussion,n.burnafterreading],g=await s.subtle.encrypt({name:"AES-GCM",iv:u,additionalData:o(JSON.stringify(y)),tagLength:n.ts},d,t);return{ct:a.bytesToBase64(new Uint8Array(g)),adata:y}}(b,n,g)}async function u(e,n,c){const u=await async function(t,e,n){const c=a.base64ToBytes(t),u=n[0],p=a.base64ToBytes(u[0]),d=a.base64ToBytes(u[1]),y=u[2],g=u[4],b=await r(e),h=await i(b,d,y,256),l=await s.subtle.decrypt({name:"AES-GCM",iv:p,additionalData:o(JSON.stringify(n)),tagLength:g},h,c);return new Uint8Array(l)}(e,n,c);return"zlib"===c[0][7]?JSON.parse(t.inflateRaw(u,{to:"string"})):JSON.parse(function(t){return(new TextDecoder).decode(t)}(u))}exports.PrivatebinClient=class extends n{constructor(t="https://privatebin.net"){super({baseURL:t,headers:{"Content-Type":"application/json","X-Requested-With":"JSONHttpRequest"}})}async sendText(t,e,s){const a=await c(t,e,s);return this.postPaste(a,s)}async getText(t,e){const{status:s,message:a,ct:n,adata:r}=await this.getPaste(t);if(0==s)return u(n,e,r);throw new Error(a)}getPaste(t){return this.get(`/?pasteid=${t}`).then(this.success)}postPaste(t,e){const{expire:s}=e,{ct:a,adata:n}=t;return this.post("/",{v:2,ct:a,adata:n,meta:{expire:s}}).then(this.success)}},exports.decryptText=u,exports.encryptText=c; //# sourceMappingURL=index.min.js.map