@toruslabs/metadata-helpers
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -376,8 +376,8 @@ module.exports = | ||
function getData(_x, _x2, _x3) { | ||
return _getData.apply(this, arguments); | ||
function getAndDecryptData(_x, _x2, _x3) { | ||
return _getAndDecryptData.apply(this, arguments); | ||
} | ||
function _getData() { | ||
_getData = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee(m, webAuthnKeyHex, namespace) { | ||
function _getAndDecryptData() { | ||
_getAndDecryptData = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee(m, privKeyHex, namespace) { | ||
var keyPair, privKey, pubKey, serializedData, encParamsHex, encParams, serializedBuf, serializedDec, data; | ||
@@ -388,3 +388,3 @@ return regenerator_default.a.wrap(function _callee$(_context) { | ||
case 0: | ||
keyPair = ec.keyFromPrivate(webAuthnKeyHex); | ||
keyPair = ec.keyFromPrivate(privKeyHex); | ||
privKey = keyPair.getPrivate(); | ||
@@ -427,12 +427,12 @@ pubKey = keyPair.getPublic(); | ||
})); | ||
return _getData.apply(this, arguments); | ||
return _getAndDecryptData.apply(this, arguments); | ||
} | ||
function setTorusShare(_x4, _x5, _x6, _x7, _x8) { | ||
return _setTorusShare.apply(this, arguments); | ||
function encryptAndSetData(_x4, _x5, _x6, _x7) { | ||
return _encryptAndSetData.apply(this, arguments); | ||
} | ||
function _setTorusShare() { | ||
_setTorusShare = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee2(m, webAuthnPubKey, webAuthnRefHex, subspace, subspaceData) { | ||
var refKeyPair, privKey, pubKey, data, d, serializedSubspaceData, serializedSubspaceDataBuf, encSubspaceData, encSubspaceDataHex, serializedDec, serializedBuf, encParams, encParamsHex, sData, metadataParams; | ||
function _encryptAndSetData() { | ||
_encryptAndSetData = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee2(m, privKeyHex, d, namespace) { | ||
var serializedDec, serializedBuf, encParams, encParamsHex, sData, metadataParams; | ||
return regenerator_default.a.wrap(function _callee2$(_context2) { | ||
@@ -442,2 +442,36 @@ while (1) { | ||
case 0: | ||
serializedDec = JSON.stringify(d); | ||
serializedBuf = Buffer.from(serializedDec, "utf-8"); | ||
_context2.next = 4; | ||
return Object(eccrypto_["encrypt"])(Object(eccrypto_["getPublic"])(Buffer.from(privKeyHex, "hex")), serializedBuf); | ||
case 4: | ||
encParams = _context2.sent; | ||
encParamsHex = encParamsBufToHex(encParams); | ||
sData = JSON.stringify(encParamsHex); | ||
metadataParams = m.generateMetadataParams(sData, privKeyHex); | ||
_context2.next = 10; | ||
return m.setMetadata(metadataParams, namespace); | ||
case 10: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
})); | ||
return _encryptAndSetData.apply(this, arguments); | ||
} | ||
function setTorusShare(_x8, _x9, _x10, _x11, _x12) { | ||
return _setTorusShare.apply(this, arguments); | ||
} | ||
function _setTorusShare() { | ||
_setTorusShare = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee3(m, webAuthnPubKey, webAuthnRefHex, subspace, subspaceData) { | ||
var refKeyPair, privKey, pubKey, data, d, serializedSubspaceData, serializedSubspaceDataBuf, encSubspaceData, encSubspaceDataHex; | ||
return regenerator_default.a.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
refKeyPair = ec.keyFromPrivate(webAuthnRefHex); | ||
@@ -449,7 +483,7 @@ privKey = refKeyPair.getPrivate(); | ||
}); | ||
_context2.next = 5; | ||
return getData(m, webAuthnRefHex, WEBAUTHN_TORUS_SHARE); | ||
_context3.next = 5; | ||
return getAndDecryptData(m, webAuthnRefHex, WEBAUTHN_TORUS_SHARE); | ||
case 5: | ||
data = _context2.sent; | ||
data = _context3.sent; | ||
d = {}; | ||
@@ -459,28 +493,18 @@ if (data) d = data; | ||
serializedSubspaceDataBuf = Buffer.from(serializedSubspaceData, "utf-8"); | ||
_context2.next = 12; | ||
_context3.next = 12; | ||
return Object(eccrypto_["encrypt"])(Buffer.from(pubKey.getPublic("hex"), "hex"), serializedSubspaceDataBuf); | ||
case 12: | ||
encSubspaceData = _context2.sent; | ||
encSubspaceData = _context3.sent; | ||
encSubspaceDataHex = encParamsBufToHex(encSubspaceData); | ||
d[subspace] = encSubspaceDataHex; | ||
serializedDec = JSON.stringify(d); | ||
serializedBuf = Buffer.from(serializedDec, "utf-8"); | ||
_context2.next = 19; | ||
return Object(eccrypto_["encrypt"])(Object(eccrypto_["getPublic"])(Buffer.from(privKey.toString("hex", 64), "hex")), serializedBuf); | ||
_context3.next = 17; | ||
return encryptAndSetData(m, privKey.toString("hex"), d, WEBAUTHN_TORUS_SHARE); | ||
case 19: | ||
encParams = _context2.sent; | ||
encParamsHex = encParamsBufToHex(encParams); | ||
sData = JSON.stringify(encParamsHex); | ||
metadataParams = m.generateMetadataParams(sData, privKey.toString(16)); | ||
_context2.next = 25; | ||
return m.setMetadata(metadataParams, WEBAUTHN_TORUS_SHARE); | ||
case 25: | ||
case 17: | ||
case "end": | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
}, _callee3); | ||
})); | ||
@@ -490,3 +514,3 @@ return _setTorusShare.apply(this, arguments); | ||
function setDeviceShare(_x9, _x10, _x11, _x12) { | ||
function setDeviceShare(_x13, _x14, _x15, _x16) { | ||
return _setDeviceShare.apply(this, arguments); | ||
@@ -496,37 +520,27 @@ } | ||
function _setDeviceShare() { | ||
_setDeviceShare = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee3(m, webAuthnRefHex, subspace, subspaceData) { | ||
var keyPair, privKey, data, d, serializedDec, serializedBuf, encParams, encParamsHex, sData, metadataParams; | ||
return regenerator_default.a.wrap(function _callee3$(_context3) { | ||
_setDeviceShare = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee4(m, webAuthnRefHex, subspace, subspaceData) { | ||
var keyPair, privKey, data, d; | ||
return regenerator_default.a.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
keyPair = ec.keyFromPrivate(webAuthnRefHex); | ||
privKey = keyPair.getPrivate(); | ||
_context3.next = 4; | ||
return getData(m, webAuthnRefHex, WEBAUTHN_DEVICE_SHARE); | ||
_context4.next = 4; | ||
return getAndDecryptData(m, webAuthnRefHex, WEBAUTHN_DEVICE_SHARE); | ||
case 4: | ||
data = _context3.sent; | ||
data = _context4.sent; | ||
d = {}; | ||
if (data) d = data; | ||
d[subspace] = subspaceData; | ||
serializedDec = JSON.stringify(d); | ||
serializedBuf = Buffer.from(serializedDec, "utf-8"); | ||
_context3.next = 12; | ||
return Object(eccrypto_["encrypt"])(Object(eccrypto_["getPublic"])(Buffer.from(privKey.toString("hex", 64), "hex")), serializedBuf); | ||
_context4.next = 10; | ||
return encryptAndSetData(m, privKey.toString("hex"), d, WEBAUTHN_DEVICE_SHARE); | ||
case 12: | ||
encParams = _context3.sent; | ||
encParamsHex = encParamsBufToHex(encParams); | ||
sData = JSON.stringify(encParamsHex); | ||
metadataParams = m.generateMetadataParams(sData, privKey.toString(16)); | ||
_context3.next = 18; | ||
return m.setMetadata(metadataParams, WEBAUTHN_DEVICE_SHARE); | ||
case 18: | ||
case 10: | ||
case "end": | ||
return _context3.stop(); | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee3); | ||
}, _callee4); | ||
})); | ||
@@ -536,3 +550,3 @@ return _setDeviceShare.apply(this, arguments); | ||
function getTorusShare(_x13, _x14, _x15, _x16) { | ||
function getTorusShare(_x17, _x18, _x19, _x20) { | ||
return _getTorusShare.apply(this, arguments); | ||
@@ -542,20 +556,20 @@ } | ||
function _getTorusShare() { | ||
_getTorusShare = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee4(m, webAuthnKeyHex, webAuthnRefHex, subspace) { | ||
_getTorusShare = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee5(m, webAuthnKeyHex, webAuthnRefHex, subspace) { | ||
var data, encParamsHex, encParams, serializedSubspaceDataBuf, serializedSubspaceData, subspaceData; | ||
return regenerator_default.a.wrap(function _callee4$(_context4) { | ||
return regenerator_default.a.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context4.next = 2; | ||
return getData(m, webAuthnRefHex, WEBAUTHN_TORUS_SHARE); | ||
_context5.next = 2; | ||
return getAndDecryptData(m, webAuthnRefHex, WEBAUTHN_TORUS_SHARE); | ||
case 2: | ||
data = _context4.sent; | ||
data = _context5.sent; | ||
if (data) { | ||
_context4.next = 5; | ||
_context5.next = 5; | ||
break; | ||
} | ||
return _context4.abrupt("return", null); | ||
return _context5.abrupt("return", null); | ||
@@ -565,17 +579,17 @@ case 5: | ||
encParams = encParamsHexToBuf(encParamsHex); | ||
_context4.next = 9; | ||
_context5.next = 9; | ||
return Object(eccrypto_["decrypt"])(Buffer.from(webAuthnKeyHex, "hex"), encParams); | ||
case 9: | ||
serializedSubspaceDataBuf = _context4.sent; | ||
serializedSubspaceDataBuf = _context5.sent; | ||
serializedSubspaceData = serializedSubspaceDataBuf.toString("utf-8"); | ||
subspaceData = JSON.parse(serializedSubspaceData); | ||
return _context4.abrupt("return", subspaceData); | ||
return _context5.abrupt("return", subspaceData); | ||
case 13: | ||
case "end": | ||
return _context4.stop(); | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee4); | ||
}, _callee5); | ||
})); | ||
@@ -585,3 +599,3 @@ return _getTorusShare.apply(this, arguments); | ||
function getDeviceShare(_x17, _x18, _x19) { | ||
function getDeviceShare(_x21, _x22, _x23) { | ||
return _getDeviceShare.apply(this, arguments); | ||
@@ -591,30 +605,30 @@ } | ||
function _getDeviceShare() { | ||
_getDeviceShare = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee5(m, webAuthnRefHex, subspace) { | ||
_getDeviceShare = asyncToGenerator_default()( /*#__PURE__*/regenerator_default.a.mark(function _callee6(m, webAuthnRefHex, subspace) { | ||
var data; | ||
return regenerator_default.a.wrap(function _callee5$(_context5) { | ||
return regenerator_default.a.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return getData(m, webAuthnRefHex, WEBAUTHN_DEVICE_SHARE); | ||
_context6.next = 2; | ||
return getAndDecryptData(m, webAuthnRefHex, WEBAUTHN_DEVICE_SHARE); | ||
case 2: | ||
data = _context5.sent; | ||
data = _context6.sent; | ||
if (!data) { | ||
_context5.next = 5; | ||
_context6.next = 5; | ||
break; | ||
} | ||
return _context5.abrupt("return", data[subspace]); | ||
return _context6.abrupt("return", data[subspace]); | ||
case 5: | ||
return _context5.abrupt("return", null); | ||
return _context6.abrupt("return", null); | ||
case 6: | ||
case "end": | ||
return _context5.stop(); | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee5); | ||
}, _callee6); | ||
})); | ||
@@ -621,0 +635,0 @@ return _getDeviceShare.apply(this, arguments); |
{ | ||
"name": "@toruslabs/metadata-helpers", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Helper methods for metadata", | ||
@@ -32,10 +32,10 @@ "main": "dist/metadataHelpers.cjs.js", | ||
"devDependencies": { | ||
"@babel/cli": "^7.13.10", | ||
"@babel/core": "^7.13.10", | ||
"@babel/cli": "^7.13.14", | ||
"@babel/core": "^7.13.14", | ||
"@babel/plugin-proposal-class-properties": "^7.13.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.13.8", | ||
"@babel/plugin-transform-runtime": "^7.13.10", | ||
"@babel/preset-env": "^7.13.10", | ||
"@babel/preset-env": "^7.13.12", | ||
"@babel/preset-typescript": "^7.13.0", | ||
"@babel/register": "^7.13.8", | ||
"@babel/register": "^7.13.14", | ||
"@babel/runtime-corejs3": "^7.13.10", | ||
@@ -46,4 +46,4 @@ "@types/elliptic": "^6.4.12", | ||
"@types/mocha": "^8.2.2", | ||
"@typescript-eslint/eslint-plugin": "^4.18.0", | ||
"@typescript-eslint/parser": "^4.18.0", | ||
"@typescript-eslint/eslint-plugin": "^4.21.0", | ||
"@typescript-eslint/parser": "^4.21.0", | ||
"assert": "^2.0.0", | ||
@@ -55,3 +55,3 @@ "atob": "^2.1.2", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^7.22.0", | ||
"eslint": "^7.23.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
@@ -67,5 +67,5 @@ "eslint-config-prettier": "^8.1.0", | ||
"eslint-plugin-simple-import-sort": "^7.0.0", | ||
"eslint-webpack-plugin": "^2.5.2", | ||
"eslint-webpack-plugin": "^2.5.3", | ||
"husky": "^4.3.8", | ||
"jsdom": "^16.5.1", | ||
"jsdom": "^16.5.2", | ||
"lint-staged": "^10.5.4", | ||
@@ -78,3 +78,3 @@ "mocha": "^8.3.2", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.2.3", | ||
"typescript": "^4.2.4", | ||
"webpack": "^4.44.1", | ||
@@ -81,0 +81,0 @@ "webpack-cli": "^3.3.12" |
import { Ecies } from "@toruslabs/eccrypto"; | ||
import MetadataStorageLayer, { PubKeyParams } from "./MetadataStorageLayer"; | ||
declare type EciesHex = { | ||
export declare type EciesHex = { | ||
iv: string; | ||
@@ -15,2 +15,1 @@ ephemPublicKey: string; | ||
export declare function getDeviceShare<T>(m: MetadataStorageLayer, webAuthnRefHex: string, subspace: string): Promise<T | null>; | ||
export {}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
907353
4625