Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tkey/security-questions

Package Overview
Dependencies
Maintainers
0
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tkey/security-questions - npm Package Compare versions

Comparing version 13.0.1-alpha.0 to 14.0.0

dist/lib.cjs/errors.js

106

dist/securityQuestions.cjs.js

@@ -57,4 +57,3 @@ /******/ (() => { // webpackBootstrap

SecurityQuestionsError: () => (/* reexport */ errors),
SecurityQuestionsModule: () => (/* reexport */ src_SecurityQuestionsModule),
"default": () => (/* reexport */ src_SecurityQuestionsModule)
SecurityQuestionsModule: () => (/* reexport */ src_SecurityQuestionsModule)
});

@@ -80,4 +79,3 @@

}
static fromCode(code) {
let extraMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
static fromCode(code, extraMessage = "") {
return new SecurityQuestionsError(code, `${SecurityQuestionsError.messages[code]}${extraMessage}`);

@@ -87,16 +85,12 @@ }

// Custom methods
static unavailable() {
let extraMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
static unavailable(extraMessage = "") {
return SecurityQuestionsError.fromCode(2101, extraMessage);
}
static unableToReplace() {
let extraMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
static unableToReplace(extraMessage = "") {
return SecurityQuestionsError.fromCode(2102, extraMessage);
}
static incorrectAnswer() {
let extraMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
static incorrectAnswer(extraMessage = "") {
return SecurityQuestionsError.fromCode(2103, extraMessage);
}
static noPasswordSaved() {
let extraMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
static noPasswordSaved(extraMessage = "") {
return SecurityQuestionsError.fromCode(2104, extraMessage);

@@ -118,7 +112,7 @@ }

if (!Number.isSafeInteger(n) || n < 0)
throw new Error(`Wrong positive integer: ${n}`);
throw new Error(`positive integer expected, not ${n}`);
}
function bool(b) {
if (typeof b !== 'boolean')
throw new Error(`Expected boolean, not ${b}`);
throw new Error(`boolean expected, not ${b}`);
}

@@ -132,11 +126,11 @@ // copied from utils

if (!isBytes(b))
throw new Error('Expected Uint8Array');
throw new Error('Uint8Array expected');
if (lengths.length > 0 && !lengths.includes(b.length))
throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
}
function hash(hash) {
if (typeof hash !== 'function' || typeof hash.create !== 'function')
function hash(h) {
if (typeof h !== 'function' || typeof h.create !== 'function')
throw new Error('Hash should be wrapped by utils.wrapConstructor');
number(hash.outputLen);
number(hash.blockLen);
number(h.outputLen);
number(h.blockLen);
}

@@ -232,5 +226,5 @@ function exists(instance, checkFinished = true) {

// Cast array to different type
const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
// export { isBytes } from './_assert.js';
// We can't reuse isBytes from _assert, because somehow this causes huge perf issues
function utils_isBytes(a) {

@@ -240,2 +234,5 @@ return (a instanceof Uint8Array ||

}
// Cast array to different type
const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
// Cast array to view

@@ -245,9 +242,18 @@ const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);

const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
// big-endian hardware is rare. Just in case someone still decides to run hashes:
// early-throw an error because we don't support BE yet.
// Other libraries would silently corrupt the data instead of throwing an error,
// when they don't support it.
// The rotate left (circular left shift) operation for uint32
const rotl = (word, shift) => (word << shift) | ((word >>> (32 - shift)) >>> 0);
const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
if (!isLE)
throw new Error('Non little-endian hardware is not supported');
// The byte swap operation for uint32
const byteSwap = (word) => ((word << 24) & 0xff000000) |
((word << 8) & 0xff0000) |
((word >>> 8) & 0xff00) |
((word >>> 24) & 0xff);
// Conditionally byte swap if on a big-endian platform
const byteSwapIfBE = (/* unused pure expression or super */ null && (isLE ? (n) => n : (n) => byteSwap(n)));
// In place byte swap for Uint32Array
function byteSwap32(arr) {
for (let i = 0; i < arr.length; i++) {
arr[i] = byteSwap(arr[i]);
}
}
// Array where index 0xf0 (240) is mapped to string 'f0'

@@ -259,4 +265,3 @@ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));

function bytesToHex(bytes) {
if (!utils_isBytes(bytes))
throw new Error('Uint8Array expected');
abytes(bytes);
// pre-caching improves the speed 6x

@@ -335,4 +340,3 @@ let hex = '';

data = utf8ToBytes(data);
if (!utils_isBytes(data))
throw new Error(`expected Uint8Array, got ${typeof data}`);
bytes(data);
return data;

@@ -347,4 +351,3 @@ }

const a = arrays[i];
if (!utils_isBytes(a))
throw new Error('Uint8Array expected');
abytes(a);
sum += a.length;

@@ -415,3 +418,5 @@ }

// Various per round constants calculations
const [SHA3_PI, SHA3_ROTL, _SHA3_IOTA] = [[], [], []];
const SHA3_PI = [];
const SHA3_ROTL = [];
const _SHA3_IOTA = [];
const _0n = /* @__PURE__ */ BigInt(0);

@@ -510,3 +515,7 @@ const _1n = /* @__PURE__ */ BigInt(1);

keccak() {
if (!isLE)
byteSwap32(this.state32);
keccakP(this.state32, this.rounds);
if (!isLE)
byteSwap32(this.state32);
this.posOut = 0;

@@ -685,10 +694,9 @@ this.pos = 0;

class SecurityQuestionStore {
constructor(_ref) {
let {
nonce,
shareIndex,
sqPublicShare,
polynomialID,
questions
} = _ref;
constructor({
nonce,
shareIndex,
sqPublicShare,
polynomialID,
questions
}) {
defineProperty_default()(this, "nonce", void 0);

@@ -726,3 +734,3 @@ defineProperty_default()(this, "shareIndex", void 0);

sqPublicShare: this.sqPublicShare,
polynomialID: this.polynomialID,
polynomialID: this.polynomialID.toString(),
questions: this.questions

@@ -764,3 +772,3 @@ };

let newNonce = newShareStores[sqIndex].share.share.sub(sqAnswer);
newNonce = newNonce.umod(common_types_namespaceObject.secp256k1.curve.n);
newNonce = newNonce.umod(common_types_namespaceObject.ecCurve.curve.n);
return new src_SecurityQuestionStore({

@@ -791,3 +799,3 @@ nonce: newNonce,

let nonce = newShareStore.share.share.sub(userInputHash);
nonce = nonce.umod(common_types_namespaceObject.secp256k1.curve.n);
nonce = nonce.umod(common_types_namespaceObject.ecCurve.curve.n);
const sqStore = new src_SecurityQuestionStore({

@@ -824,3 +832,3 @@ nonce,

let share = sqStore.nonce.add(userInputHash);
share = share.umod(common_types_namespaceObject.secp256k1.curve.n);
share = share.umod(common_types_namespaceObject.ecCurve.curve.n);
const shareStore = new common_types_namespaceObject.ShareStore(new common_types_namespaceObject.Share(sqStore.shareIndex, share), sqStore.polynomialID);

@@ -848,3 +856,3 @@ // validate if share is correct

let nonce = sqShare.share.share.sub(userInputHash);
nonce = nonce.umod(common_types_namespaceObject.secp256k1.curve.n);
nonce = nonce.umod(common_types_namespaceObject.ecCurve.curve.n);
const newSqStore = new src_SecurityQuestionStore({

@@ -851,0 +859,0 @@ nonce,

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { TkeyError, PublicShare, isEmptyObject, secp256k1, ShareStore, Share } from '@tkey/common-types';
import { TkeyError, PublicShare, isEmptyObject, ecCurve, ShareStore, Share } from '@tkey/common-types';
import BN from 'bn.js';

@@ -16,4 +16,3 @@ import { keccak256 } from 'ethereum-cryptography/keccak';

}
static fromCode(code) {
let extraMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
static fromCode(code, extraMessage = "") {
return new SecurityQuestionsError(code, `${SecurityQuestionsError.messages[code]}${extraMessage}`);

@@ -23,16 +22,12 @@ }

// Custom methods
static unavailable() {
let extraMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
static unavailable(extraMessage = "") {
return SecurityQuestionsError.fromCode(2101, extraMessage);
}
static unableToReplace() {
let extraMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
static unableToReplace(extraMessage = "") {
return SecurityQuestionsError.fromCode(2102, extraMessage);
}
static incorrectAnswer() {
let extraMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
static incorrectAnswer(extraMessage = "") {
return SecurityQuestionsError.fromCode(2103, extraMessage);
}
static noPasswordSaved() {
let extraMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
static noPasswordSaved(extraMessage = "") {
return SecurityQuestionsError.fromCode(2104, extraMessage);

@@ -47,12 +42,12 @@ }

});
var SecurityQuestionsError$1 = SecurityQuestionsError;
class SecurityQuestionStore {
constructor(_ref) {
let {
nonce,
shareIndex,
sqPublicShare,
polynomialID,
questions
} = _ref;
constructor({
nonce,
shareIndex,
sqPublicShare,
polynomialID,
questions
}) {
_defineProperty(this, "nonce", void 0);

@@ -90,3 +85,3 @@ _defineProperty(this, "shareIndex", void 0);

sqPublicShare: this.sqPublicShare,
polynomialID: this.polynomialID,
polynomialID: this.polynomialID.toString(),
questions: this.questions

@@ -96,2 +91,3 @@ };

}
var SecurityQuestionStore$1 = SecurityQuestionStore;

@@ -115,3 +111,3 @@ function answerToUserInputHashBN(answerString) {

}
const sqStore = new SecurityQuestionStore(generalStore);
const sqStore = new SecurityQuestionStore$1(generalStore);
const sqIndex = sqStore.shareIndex.toString("hex");

@@ -123,4 +119,4 @@

let newNonce = newShareStores[sqIndex].share.share.sub(sqAnswer);
newNonce = newNonce.umod(secp256k1.curve.n);
return new SecurityQuestionStore({
newNonce = newNonce.umod(ecCurve.curve.n);
return new SecurityQuestionStore$1({
nonce: newNonce,

@@ -145,3 +141,3 @@ polynomialID: newShareStores[Object.keys(newShareStores)[0]].polynomialID,

const rawSqStore = metadata.getGeneralStoreDomain(this.moduleName);
if (rawSqStore) throw SecurityQuestionsError.unableToReplace();
if (rawSqStore) throw SecurityQuestionsError$1.unableToReplace();
const newSharesDetails = await this.tbSDK.generateNewShare();

@@ -151,4 +147,4 @@ const newShareStore = newSharesDetails.newShareStores[newSharesDetails.newShareIndex.toString("hex")];

let nonce = newShareStore.share.share.sub(userInputHash);
nonce = nonce.umod(secp256k1.curve.n);
const sqStore = new SecurityQuestionStore({
nonce = nonce.umod(ecCurve.curve.n);
const sqStore = new SecurityQuestionStore$1({
nonce,

@@ -174,3 +170,3 @@ questions,

const metadata = this.tbSDK.getMetadata();
const sqStore = new SecurityQuestionStore(metadata.getGeneralStoreDomain(this.moduleName));
const sqStore = new SecurityQuestionStore$1(metadata.getGeneralStoreDomain(this.moduleName));
return sqStore.questions;

@@ -181,7 +177,7 @@ }

const rawSqStore = metadata.getGeneralStoreDomain(this.moduleName);
if (!rawSqStore) throw SecurityQuestionsError.unavailable();
const sqStore = new SecurityQuestionStore(rawSqStore);
if (!rawSqStore) throw SecurityQuestionsError$1.unavailable();
const sqStore = new SecurityQuestionStore$1(rawSqStore);
const userInputHash = answerToUserInputHashBN(answerString);
let share = sqStore.nonce.add(userInputHash);
share = share.umod(secp256k1.curve.n);
share = share.umod(ecCurve.curve.n);
const shareStore = new ShareStore(new Share(sqStore.shareIndex, share), sqStore.polynomialID);

@@ -191,3 +187,3 @@ // validate if share is correct

if (derivedPublicShare.shareCommitment.x.cmp(sqStore.sqPublicShare.shareCommitment.x) !== 0) {
throw SecurityQuestionsError.incorrectAnswer();
throw SecurityQuestionsError$1.incorrectAnswer();
}

@@ -205,9 +201,9 @@ const latestShareDetails = await this.tbSDK.catchupToLatestShare({

const rawSqStore = metadata.getGeneralStoreDomain(this.moduleName);
if (!rawSqStore) throw SecurityQuestionsError.unavailable();
const sqStore = new SecurityQuestionStore(rawSqStore);
if (!rawSqStore) throw SecurityQuestionsError$1.unavailable();
const sqStore = new SecurityQuestionStore$1(rawSqStore);
const userInputHash = answerToUserInputHashBN(newAnswerString);
const sqShare = this.tbSDK.outputShareStore(sqStore.shareIndex);
let nonce = sqShare.share.share.sub(userInputHash);
nonce = nonce.umod(secp256k1.curve.n);
const newSqStore = new SecurityQuestionStore({
nonce = nonce.umod(ecCurve.curve.n);
const newSqStore = new SecurityQuestionStore$1({
nonce,

@@ -237,6 +233,7 @@ polynomialID: sqStore.polynomialID,

}
throw SecurityQuestionsError.noPasswordSaved();
throw SecurityQuestionsError$1.noPasswordSaved();
}
}
var SecurityQuestionsModule$1 = SecurityQuestionsModule;
export { SECURITY_QUESTIONS_MODULE_NAME, SecurityQuestionStore, SecurityQuestionsError, SecurityQuestionsModule, SecurityQuestionsModule as default };
export { SECURITY_QUESTIONS_MODULE_NAME, SecurityQuestionStore$1 as SecurityQuestionStore, SecurityQuestionsError$1 as SecurityQuestionsError, SecurityQuestionsModule$1 as SecurityQuestionsModule };
export { default as SecurityQuestionsError } from "./errors";
export { default, SECURITY_QUESTIONS_MODULE_NAME, default as SecurityQuestionsModule } from "./SecurityQuestionsModule";
export { SECURITY_QUESTIONS_MODULE_NAME, default as SecurityQuestionsModule } from "./SecurityQuestionsModule";
export { default as SecurityQuestionStore } from "./SecurityQuestionStore";
{
"name": "@tkey/security-questions",
"version": "13.0.1-alpha.0",
"version": "14.0.0",
"description": "TKey Security Questions Module",

@@ -8,7 +8,8 @@ "author": "Torus Labs",

"license": "MIT",
"main": "dist/securityQuestions.cjs.js",
"module": "dist/securityQuestions.esm.js",
"main": "dist/lib.cjs/index.js",
"module": "dist/lib.esm/index.js",
"unpkg": "dist/securityQuestions.umd.min.js",
"jsdelivr": "dist/securityQuestions.umd.min.js",
"types": "dist/types/index.d.ts",
"sideEffects": false,
"files": [

@@ -29,3 +30,3 @@ "dist"

"test-development": "cross-env MOCKED=false METADATA=http://localhost:5051 mocha --config ../../.mocharc.json ",
"test-production": "cross-env MOCKED=false METADATA=https://metadata.tor.us mocha --config ../../.mocharc.json ",
"test-production": "cross-env MOCKED=false METADATA=https://metadata.web3auth.io mocha --config ../../.mocharc.json ",
"test-debugger": "mocha --config ../../.mocharc.json --inspect-brk",

@@ -45,5 +46,5 @@ "dev": "rimraf dist/ && cross-env NODE_ENV=development torus-scripts build",

"dependencies": {
"@tkey/common-types": "^13.0.1-alpha.0",
"@tkey/common-types": "^14.0.0",
"bn.js": "^5.2.1",
"ethereum-cryptography": "^2.1.3"
"ethereum-cryptography": "^2.2.1"
},

@@ -63,3 +64,3 @@ "devDependencies": {

},
"gitHead": "220ed7208bfd0ee7c414d21b83b48ed3b880807a"
"gitHead": "c387cab5a1b53823bf0903c3b729625adc8960ac"
}

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc