Comparing version 0.0.1 to 0.0.2
@@ -1,1 +0,1 @@ | ||
var phog=function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n,t){const r=t(1),o="SHA-256",c={sign:{algo:{name:"ECDSA",namedCurve:"P-256"},usage:["sign","verify"],export:{public:"spki",private:"pkcs8"}},derive:{algo:{name:"ECDH",namedCurve:"P-256"},usage:["deriveKey"],export:{public:"spki",private:"pkcs8"}},encrypt:{algo:{name:"AES-GCM",length:256},usage:["encrypt","decrypt"],export:{public:"raw",private:"raw"},ivFunc:()=>window.crypto.getRandomValues(new Uint8Array(12))}};function u(e){const n=String.fromCharCode.apply(null,new Uint8Array(e));return r.base58.encode(n)}function i(e){for(var n=r.base58.decode(e),t=new ArrayBuffer(n.length),o=new Uint8Array(t),c=0;c<n.length;c++)o[c]=n.charCodeAt(c);return t}e.exports={hash_function:o,configs:c,keyGen:function(e){return crypto.subtle.generateKey(e.algo,!0,e.usage)},deriveKey:async function(e,n){return crypto.subtle.deriveKey({name:c.derive.algo.name,public:n},e,c.encrypt.algo,!0,c.encrypt.usage)},hash:async function(e){const n=new TextEncoder("utf-8").encode(e);return u(await window.crypto.subtle.digest(o,n))},encrypt:async function(e,n){const t=c.encrypt.ivFunc(),r=await window.crypto.subtle.encrypt({...c.encrypt.algo,iv:t},n,new TextEncoder("utf-8").encode(e));return u(t)+"_"+u(r)},decrypt:async function(e,n){const t=e.split("_"),r=await window.crypto.subtle.decrypt({...c.encrypt.algo,iv:i(t[0])},n,i(t[1]));return new TextDecoder("utf-8").decode(r)},sign:async function(e,n){return u(await window.crypto.subtle.sign({name:c.sign.algo.name,hash:{name:o}},n,new TextEncoder("utf-8").encode(e)))},verify:async function(e,n,t){return await window.crypto.subtle.verify({name:c.sign.algo.name,hash:{name:o}},t,i(n),new TextEncoder("utf-8").encode(e))},importKey:async function(e,n,t){const r=t||"public";return await window.crypto.subtle.importKey(n.export[r],i(e),n.algo,!0,["public"===r?"verify":"sign"])},exportKey:async function(e,n,t){const r=t||"public";return u(await window.crypto.subtle.exportKey(n.export[r],e))}}},function(e,n,t){e.exports=function(){"use strict";function e(e,n){return function(t){return e(t,n)}}var n={36:"0123456789abcdefghijklmnopqrstuvwxyz",58:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"},t=function(e,t){if(""===e)return"";for(var r,o,c=e.split("").map(function(e){return e.charCodeAt(0)}),u=[0],i=0;i<c.length;){for(o=0;o<u.length;)u[o]<<=8,o++;for(u[0]+=c[i],r=0,o=0;o<u.length;)u[o]+=r,r=u[o]/t|0,u[o]%=t,o++;for(;r;)u.push(r%t),r=r/t|0;i++}for(i=0;0===c[i]&&i<c.length-1;)u.push(0),i++;return u.reverse().map(function(e){return n[t][e]}).join("")},r={};Object.keys(n).forEach(function(e){r[e]={},n[e].split("").forEach(function(n,t){r[e][n]=t})});var o=function(e,n){var t,o,c,u=[0],i=0;if(0===e.length)return"";for(;i<e.length;){if(!((t=e[i])in r[n]))return"";for(c=0;c<u.length;)u[c]*=n,c++;for(u[0]+=r[n][t],o=0,c=0;c<u.length;)u[c]+=o,o=u[c]>>8,u[c]&=255,++c;for(;o;)u.push(255&o),o>>=8;i++}for(i=0;"1"===e[i]&&i<e.length-1;)u.push(0),i++;return String.fromCharCode.apply(String,u.reverse())},c={encode:t,decode:o};return Object.keys(n).forEach(function(n){c["base"+n]={encode:e(t,parseInt(n,10)),decode:e(o,parseInt(n,10))}}),c}()}]); | ||
var phog=function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n,t){const r=t(1),o="SHA-256",c={sign:{algo:{name:"ECDSA",namedCurve:"P-256"},usage:["sign","verify"],format:{public:"spki",private:"pkcs8"}},derive:{algo:{name:"ECDH",namedCurve:"P-256"},usage:["deriveKey"],format:{public:"spki",private:"pkcs8"}},encrypt:{algo:{name:"AES-GCM",length:256},usage:["encrypt","decrypt"],format:{public:"raw",private:"raw"},ivFunc:()=>window.crypto.getRandomValues(new Uint8Array(12))}};function u(e){const n=String.fromCharCode.apply(null,new Uint8Array(e));return r.base58.encode(n)}function i(e){for(var n=r.base58.decode(e),t=new ArrayBuffer(n.length),o=new Uint8Array(t),c=0;c<n.length;c++)o[c]=n.charCodeAt(c);return t}e.exports={hash_function:o,configs:c,keyGen:function(e){return crypto.subtle.generateKey(e.algo,!0,e.usage)},deriveKey:async function(e,n){return crypto.subtle.deriveKey({name:c.derive.algo.name,public:n},e,c.encrypt.algo,!0,c.encrypt.usage)},hash:async function(e){const n=new TextEncoder("utf-8").encode(e);return u(await window.crypto.subtle.digest(o,n))},encrypt:async function(e,n){const t=c.encrypt.ivFunc(),r=await window.crypto.subtle.encrypt({...c.encrypt.algo,iv:t},n,new TextEncoder("utf-8").encode(e));return u(t)+"_"+u(r)},decrypt:async function(e,n){const t=e.split("_"),r=await window.crypto.subtle.decrypt({...c.encrypt.algo,iv:i(t[0])},n,i(t[1]));return new TextDecoder("utf-8").decode(r)},sign:async function(e,n){return u(await window.crypto.subtle.sign({name:c.sign.algo.name,hash:{name:o}},n,new TextEncoder("utf-8").encode(e)))},verify:async function(e,n,t){return await window.crypto.subtle.verify({name:c.sign.algo.name,hash:{name:o}},t,i(n),new TextEncoder("utf-8").encode(e))},importKey:async function(e,n,t){const r=t||"public";return await window.crypto.subtle.importKey(n.format[r],i(e),n.algo,!0,["public"===r?"verify":"sign"])},exportKey:async function(e,n,t){const r=t||"public";return u(await window.crypto.subtle.exportKey(n.format[r],e))}}},function(e,n,t){e.exports=function(){"use strict";function e(e,n){return function(t){return e(t,n)}}var n={36:"0123456789abcdefghijklmnopqrstuvwxyz",58:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"},t=function(e,t){if(""===e)return"";for(var r,o,c=e.split("").map(function(e){return e.charCodeAt(0)}),u=[0],i=0;i<c.length;){for(o=0;o<u.length;)u[o]<<=8,o++;for(u[0]+=c[i],r=0,o=0;o<u.length;)u[o]+=r,r=u[o]/t|0,u[o]%=t,o++;for(;r;)u.push(r%t),r=r/t|0;i++}for(i=0;0===c[i]&&i<c.length-1;)u.push(0),i++;return u.reverse().map(function(e){return n[t][e]}).join("")},r={};Object.keys(n).forEach(function(e){r[e]={},n[e].split("").forEach(function(n,t){r[e][n]=t})});var o=function(e,n){var t,o,c,u=[0],i=0;if(0===e.length)return"";for(;i<e.length;){if(!((t=e[i])in r[n]))return"";for(c=0;c<u.length;)u[c]*=n,c++;for(u[0]+=r[n][t],o=0,c=0;c<u.length;)u[c]+=o,o=u[c]>>8,u[c]&=255,++c;for(;o;)u.push(255&o),o>>=8;i++}for(i=0;"1"===e[i]&&i<e.length-1;)u.push(0),i++;return String.fromCharCode.apply(String,u.reverse())},c={encode:t,decode:o};return Object.keys(n).forEach(function(n){c["base"+n]={encode:e(t,parseInt(n,10)),decode:e(o,parseInt(n,10))}}),c}()}]); |
40
index.js
@@ -13,3 +13,3 @@ const SimpleBase = require('simple-base') | ||
usage: ['sign', 'verify'], | ||
export: {public:'spki', private:'pkcs8'} | ||
format: {public:'spki', private:'pkcs8'} | ||
}, | ||
@@ -19,3 +19,3 @@ derive: { | ||
usage: ['deriveKey'], | ||
export: {public:'spki', private:'pkcs8'} | ||
format: {public:'spki', private:'pkcs8'} | ||
}, | ||
@@ -25,3 +25,3 @@ encrypt: { | ||
usage: ['encrypt', 'decrypt'], | ||
export: {public:'raw', private:'raw'}, | ||
format: {public:'raw', private:'raw'}, | ||
ivFunc: () => window.crypto.getRandomValues(new Uint8Array(12)) | ||
@@ -35,2 +35,19 @@ } | ||
async function exportKey(key, config, mode){ | ||
const m = mode || 'public' | ||
const keyData = await window.crypto.subtle.exportKey(config.format[m], key) | ||
return ab_to_base58(keyData) | ||
} | ||
async function importKey(key, config, mode){ | ||
const m = mode || 'public' | ||
return await window.crypto.subtle.importKey( | ||
config.format[m], | ||
base58_to_ab(key), | ||
config.algo, | ||
true, | ||
[m==='public'?'verify':'sign'] | ||
) | ||
} | ||
async function deriveKey(privKey, pubKey) { | ||
@@ -91,19 +108,2 @@ return crypto.subtle.deriveKey( | ||
async function exportKey(key, config, mode){ | ||
const m = mode || 'public' | ||
const keyData = await window.crypto.subtle.exportKey(config.export[m], key) | ||
return ab_to_base58(keyData) | ||
} | ||
async function importKey(key, config, mode){ | ||
const m = mode || 'public' | ||
return await window.crypto.subtle.importKey( | ||
config.export[m], | ||
base58_to_ab(key), | ||
config.algo, | ||
true, | ||
[m==='public'?'verify':'sign'] | ||
) | ||
} | ||
function ab_to_base58(buf) { | ||
@@ -110,0 +110,0 @@ const s = String.fromCharCode.apply(null, new Uint8Array(buf)) |
{ | ||
"name": "phog", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Dead simple crypto module for Fognet", | ||
@@ -5,0 +5,0 @@ "author": "Evan Feenstra <evan@evan.cool>", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
15420
6
1
77