🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@lit-protocol/misc

Package Overview
Dependencies
Maintainers
8
Versions
534
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lit-protocol/misc - npm Package Compare versions

Comparing version

to
8.0.0-alpha.0

14

package.json

@@ -24,3 +24,3 @@ {

],
"version": "7.1.0",
"version": "8.0.0-alpha.0",
"dependencies": {

@@ -30,14 +30,14 @@ "@ethersproject/abstract-provider": "5.7.0",

"@ethersproject/providers": "5.7.2",
"@lit-protocol/accs-schemas": "^0.0.24",
"@lit-protocol/contracts": "^0.0.74",
"@lit-protocol/accs-schemas": "^0.0.22",
"@lit-protocol/contracts": "^0.1.10",
"@openagenda/verror": "^3.1.4",
"ajv": "^8.12.0",
"bech32": "^2.0.0",
"depd": "^2.0.0",
"ethers": "^5.7.1",
"siwe": "^2.3.2",
"util": "0.12.5",
"@lit-protocol/constants": "7.1.0",
"@lit-protocol/logger": "7.1.0",
"@lit-protocol/types": "7.1.0",
"zod": "^3.24.1",
"@lit-protocol/constants": "8.0.0-alpha.0",
"@lit-protocol/logger": "8.0.0-alpha.0",
"@lit-protocol/types": "8.0.0-alpha.0",
"tslib": "1.14.1"

@@ -44,0 +44,0 @@ },

@@ -1,5 +0,4 @@

import { LitNodeClientConfig } from '@lit-protocol/types';
import { JSONSchemaType } from 'ajv';
import { LIT_NETWORK_VALUES, LOG_LEVEL_VALUES } from '@lit-protocol/constants';
import { Chain, AuthSig, MintCallback, RelayClaimProcessor } from '@lit-protocol/types';
import { Chain, AuthSig, Hex, LitNodeClientConfig, MintCallback, RelayClaimProcessor } from '@lit-protocol/types';
export declare const setMiscLitConfig: (config: LitNodeClientConfig | undefined) => void;

@@ -22,10 +21,18 @@ /**

export declare const mostCommonString: <T>(arr: T[]) => T | undefined;
export declare const findMostCommonResponse: (responses: object[]) => object;
/**
* Recursively finds the most common value for each key across an array of response objects.
*
* For each key found in any response object, the function aggregates all non-empty values (ignoring
* `undefined` and empty strings) and determines the most frequently occurring value. If the value is an object
* (and not an array), the function recurses into that object.
*
* @template T - The shape of the input objects in the array.
* @param {T[]} responses - An array of response objects.
* @returns {T} An object with each key set to its most common value across all responses.
*/
export declare const findMostCommonResponse: <T extends Record<string, any>>(responses: T[]) => T;
declare global {
var wasmExport: any;
var wasmECDSA: any;
var logger: any;
var logManager: any;
}
export declare const throwRemovedFunctionError: (functionName: string) => never;
export declare const bootstrapLogManager: (id: string, level?: LOG_LEVEL_VALUES) => void;

@@ -155,2 +162,3 @@ export declare const getLoggerbyId: (id: string) => any;

export declare const defaultMintClaimCallback: MintCallback<RelayClaimProcessor>;
export declare const isHexableString: (str: string) => boolean;
/**

@@ -161,3 +169,3 @@ * Adds a '0x' prefix to a string if it doesn't already have one.

*/
export declare const hexPrefixed: (str: string) => `0x${string}`;
export declare const hexPrefixed: (str: string) => Hex;
/**

@@ -199,2 +207,48 @@ * Removes the '0x' prefix from a hexadecimal string if it exists.

/**
* Converts a snake_case string to camelCase.
* @param s The snake_case string to convert.
* @returns The camelCase version of the input string.
*
* @example
* snakeToCamel('hello_world') // 'helloWorld'
*/
export declare const snakeToCamel: (s: string) => string;
export type Transformation = (target: Record<string, unknown>) => Record<string, unknown>;
/**
* Converts the keys of an object from snake_case to camelCase.
*
* @param obj - The object whose keys need to be converted.
* @returns The object with keys converted to camelCase.
*/
export declare const convertKeysToCamelCase: Transformation;
/**
* Removes values that are received as a two element array (tuple) by just leaving the second one
*
* @param obj - The object that can have tupled elements
* @returns The object with tupled elements removed, keeping only the second element
*/
export declare const cleanArrayValues: Transformation;
/**
* Converts number arrays to Uint8Arrays in an object.
*
* @param obj - The object that can have number arrays.
* @returns A new object with number arrays converted to Uint8Arrays.
*/
export declare const convertNumberArraysToUint8Arrays: Transformation;
/**
* Removes double quotes from string values in an object.
*
* @param obj - The object to clean string values from.
* @returns A new object with string values cleaned.
*/
export declare const cleanStringValues: Transformation;
/**
* Asserts hex values have a prefix of 0x.
*
* @param obj - The object to hex string values from.
* @returns A new object with string values hexed.
*/
export declare const hexifyStringValues: Transformation;
export declare const applyTransformations: (target: Record<string, unknown>, transformations: Transformation[]) => Record<string, unknown>;
/**
* Attempts to normalize a string by unescaping it until it can be parsed as a JSON object,

@@ -201,0 +255,0 @@ * then stringifies it exactly once. If the input is a regular string that does not represent

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeHexPrefix = exports.hexPrefixed = exports.defaultMintClaimCallback = exports.genRandomPath = exports.decimalPlaces = exports.isBrowser = exports.isNode = exports.is = exports.numberToHex = exports.sortedObject = exports.checkIfAuthSigRequiresChainParam = exports.checkSchema = exports.checkType = exports.getVarType = exports.logError = exports.logErrorWithRequestId = exports.logWithRequestId = exports.log = exports.getLoggerbyId = exports.bootstrapLogManager = exports.throwRemovedFunctionError = exports.findMostCommonResponse = exports.mostCommonString = exports.printError = exports.setMiscLitConfig = void 0;
exports.applyTransformations = exports.hexifyStringValues = exports.cleanStringValues = exports.convertNumberArraysToUint8Arrays = exports.cleanArrayValues = exports.convertKeysToCamelCase = exports.snakeToCamel = exports.removeHexPrefix = exports.hexPrefixed = exports.isHexableString = exports.defaultMintClaimCallback = exports.genRandomPath = exports.decimalPlaces = exports.isBrowser = exports.isNode = exports.is = exports.numberToHex = exports.sortedObject = exports.checkIfAuthSigRequiresChainParam = exports.checkSchema = exports.checkType = exports.getVarType = exports.logError = exports.logErrorWithRequestId = exports.logWithRequestId = exports.log = exports.getLoggerbyId = exports.bootstrapLogManager = exports.findMostCommonResponse = exports.mostCommonString = exports.printError = exports.setMiscLitConfig = void 0;
exports.isSupportedLitNetwork = isSupportedLitNetwork;

@@ -50,3 +50,17 @@ exports.getEnv = getEnv;

exports.mostCommonString = mostCommonString;
/**
* Recursively finds the most common value for each key across an array of response objects.
*
* For each key found in any response object, the function aggregates all non-empty values (ignoring
* `undefined` and empty strings) and determines the most frequently occurring value. If the value is an object
* (and not an array), the function recurses into that object.
*
* @template T - The shape of the input objects in the array.
* @param {T[]} responses - An array of response objects.
* @returns {T} An object with each key set to its most common value across all responses.
*/
const findMostCommonResponse = (responses) => {
if (responses.length === 0) {
throw new Error('findMostCommonResponse requires at least one response object');
}
const result = {};

@@ -57,14 +71,14 @@ // Aggregate all values for each key across all responses

const values = responses.map((response) => response[key]);
// Filter out undefined values before processing
// Filter out undefined and empty string values before processing
const filteredValues = values.filter((value) => value !== undefined && value !== '');
if (filteredValues.length === 0) {
result[key] = undefined; // or set a default value if needed
result[key] = undefined;
}
else if (typeof filteredValues[0] === 'object' &&
!Array.isArray(filteredValues[0])) {
// Recursive case for objects
// Recursive case for nested objects
result[key] = (0, exports.findMostCommonResponse)(filteredValues);
}
else {
// Most common element from filtered values
// Determine the most common element from filtered values
result[key] = (0, exports.mostCommonString)(filteredValues);

@@ -76,10 +90,2 @@ }

exports.findMostCommonResponse = findMostCommonResponse;
const throwRemovedFunctionError = (functionName) => {
throw new constants_1.RemovedFunctionError({
info: {
functionName,
},
}, `This function "${functionName}" has been removed. Please use the old SDK.`);
};
exports.throwRemovedFunctionError = throwRemovedFunctionError;
const bootstrapLogManager = (id, level = constants_1.LOG_LEVEL.DEBUG) => {

@@ -120,3 +126,3 @@ if (!globalThis.logManager) {

}
// if there are there are logs in buffer, print them first and empty the buffer.
// if there are logs in buffer, print them first and empty the buffer.
while (logBuffer.length > 0) {

@@ -431,3 +437,3 @@ const log = logBuffer.shift() ?? '';

}
const defaultMintClaimCallback = async (params, network = constants_1.LIT_NETWORK.DatilDev) => {
const defaultMintClaimCallback = async (params, network = constants_1.LIT_NETWORK.NagaDev) => {
isSupportedLitNetwork(network);

@@ -470,2 +476,6 @@ const AUTH_CLAIM_PATH = '/auth/claim';

exports.defaultMintClaimCallback = defaultMintClaimCallback;
const isHexableString = (str) => {
return /^(0x|0X)?[0-9a-fA-F]+$/.test(str);
};
exports.isHexableString = isHexableString;
/**

@@ -552,2 +562,77 @@ * Adds a '0x' prefix to a string if it doesn't already have one.

/**
* Converts a snake_case string to camelCase.
* @param s The snake_case string to convert.
* @returns The camelCase version of the input string.
*
* @example
* snakeToCamel('hello_world') // 'helloWorld'
*/
const snakeToCamel = (s) => s.replace(/(_\w)/g, (m) => m[1].toUpperCase());
exports.snakeToCamel = snakeToCamel;
/**
* Converts the keys of an object from snake_case to camelCase.
*
* @param obj - The object whose keys need to be converted.
* @returns The object with keys converted to camelCase.
*/
const convertKeysToCamelCase = (obj) => Object.keys(obj).reduce((acc, key) => ({
...acc,
[(0, exports.snakeToCamel)(key)]: obj[key],
}), {});
exports.convertKeysToCamelCase = convertKeysToCamelCase;
/**
* Removes values that are received as a two element array (tuple) by just leaving the second one
*
* @param obj - The object that can have tupled elements
* @returns The object with tupled elements removed, keeping only the second element
*/
const cleanArrayValues = (obj) => Object.keys(obj).reduce((acc, key) => ({
...acc,
[key]: typeof obj[key] === 'string' && obj[key].charAt(0) === '['
? JSON.parse(obj[key])[1]
: obj[key],
}), {});
exports.cleanArrayValues = cleanArrayValues;
/**
* Converts number arrays to Uint8Arrays in an object.
*
* @param obj - The object that can have number arrays.
* @returns A new object with number arrays converted to Uint8Arrays.
*/
const convertNumberArraysToUint8Arrays = (obj) => Object.keys(obj).reduce((acc, key) => ({
...acc,
[key]: Array.isArray(obj[key]) && typeof obj[key][0] === 'number'
? new Uint8Array(obj[key])
: obj[key],
}), {});
exports.convertNumberArraysToUint8Arrays = convertNumberArraysToUint8Arrays;
/**
* Removes double quotes from string values in an object.
*
* @param obj - The object to clean string values from.
* @returns A new object with string values cleaned.
*/
const cleanStringValues = (obj) => Object.keys(obj).reduce((acc, key) => ({
...acc,
[key]: typeof obj[key] === 'string' ? obj[key].replace(/"/g, '') : obj[key],
}), {});
exports.cleanStringValues = cleanStringValues;
/**
* Asserts hex values have a prefix of 0x.
*
* @param obj - The object to hex string values from.
* @returns A new object with string values hexed.
*/
const hexifyStringValues = (obj) => Object.keys(obj).reduce((acc, key) => ({
...acc,
[key]: typeof obj[key] === 'string' && (0, exports.isHexableString)(obj[key])
? (0, exports.hexPrefixed)(obj[key])
: obj[key],
}), {});
exports.hexifyStringValues = hexifyStringValues;
const applyTransformations = (target, transformations) => {
return transformations.reduce((acc, transform) => transform(acc), target);
};
exports.applyTransformations = applyTransformations;
/**
* Attempts to normalize a string by unescaping it until it can be parsed as a JSON object,

@@ -554,0 +639,0 @@ * then stringifies it exactly once. If the input is a regular string that does not represent

@@ -6,3 +6,3 @@ /**

import { IEither } from '@lit-protocol/constants';
import { AccessControlConditions, EvmContractConditions, SessionSigsOrAuthSig, SolRpcConditions, UnifiedAccessControlConditions } from '@lit-protocol/types';
import { AccessControlConditions, EvmContractConditions, SolRpcConditions, UnifiedAccessControlConditions, AuthSig, AuthenticationContext } from '@lit-protocol/types';
export declare const safeParams: ({ functionName, params, }: {

@@ -17,4 +17,6 @@ functionName: string;

}
export interface AuthMaterialValidatorProps extends SessionSigsOrAuthSig {
export interface AuthMaterialValidatorProps {
chain?: string;
authSig?: AuthSig;
authContext?: AuthenticationContext;
}

@@ -21,0 +23,0 @@ export interface AccessControlConditionsValidatorProps {

@@ -175,27 +175,2 @@ "use strict";

}
class AuthMethodValidator {
constructor(fnName, authMethods) {
this.fnName = fnName;
this.authMethods = authMethods;
}
validate() {
const { authMethods } = this;
if (authMethods &&
authMethods.length > 0 &&
!(0, misc_1.checkType)({
value: authMethods,
allowedTypes: ['Array'],
paramName: 'authMethods',
functionName: this.fnName,
}))
return (0, constants_1.ELeft)(new constants_1.InvalidParamType({
info: {
param: 'authMethods',
value: authMethods,
functionName: this.fnName,
},
}, 'authMethods is not an array'));
return (0, constants_1.ERight)(undefined);
}
}
class ExecuteJsValidator {

@@ -267,3 +242,3 @@ constructor(fnName, params) {

validate() {
const { authSig, sessionSigs } = this.authMaterial;
const { authSig } = this.authMaterial;
if (authSig && !(0, misc_1.is)(authSig, 'Object', 'authSig', this.fnName))

@@ -295,27 +270,2 @@ return (0, constants_1.ELeft)(new constants_1.InvalidParamType({

}
if (sessionSigs && !(0, misc_1.is)(sessionSigs, 'Object', 'sessionSigs', this.fnName))
return (0, constants_1.ELeft)(new constants_1.InvalidParamType({
info: {
param: 'sessionSigs',
value: sessionSigs,
functionName: this.fnName,
},
}, 'sessionSigs is not an object'));
if (!sessionSigs && !authSig)
return (0, constants_1.ELeft)(new constants_1.InvalidArgumentException({
info: {
functionName: this.fnName,
sessionSigs,
authSig,
},
}, 'You must pass either authSig or sessionSigs'));
// -- validate: if sessionSig and authSig exists
if (sessionSigs && authSig)
return (0, constants_1.ELeft)(new constants_1.InvalidArgumentException({
info: {
functionName: this.fnName,
sessionSigs,
authSig,
},
}, 'You cannot have both authSig and sessionSigs'));
return (0, constants_1.ERight)(undefined);

@@ -322,0 +272,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet