Socket
Socket
Sign inDemoInstall

@walletconnect/keyvaluestorage

Package Overview
Dependencies
Maintainers
10
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@walletconnect/keyvaluestorage - npm Package Compare versions

Comparing version 1.1.0-canary-1 to 1.1.0-canary-2

26

dist/index.cjs.js

@@ -5,3 +5,2 @@ 'use strict';

var safeJson = require('@walletconnect/safe-json');
var fs = require('fs');

@@ -13,2 +12,19 @@

const s = (n) => JSON.stringify(n, (r, t) => typeof t == "bigint" ? t.toString() + "n" : t), o = (n) => {
const r = /([\[:])?(\d{17,}|(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))([,\}\]])/g, t = n.replace(r, '$1"$2n"$3');
return JSON.parse(t, (g, e) => typeof e == "string" && e.match(/^\d+n$/) ? BigInt(e.substring(0, e.length - 1)) : e);
};
function i(n) {
if (typeof n != "string")
throw new Error(`Cannot safe json parse value of type ${typeof n}`);
try {
return o(n);
} catch (e) {
return n;
}
}
function f(n) {
return typeof n == "string" ? n : s(n) || "";
}
function importLib() {

@@ -90,3 +106,3 @@ try {

await this.database.setItem(key);
await this.database.setItem(key, safeJson.safeJsonStringify(value));
await this.database.setItem(key, f(value));
break;

@@ -139,3 +155,3 @@ case "removeItem":

}
const contents = safeJson.safeJsonParse(rawContents);
const contents = i(rawContents);
if (!contents) {

@@ -157,3 +173,3 @@ onCompleteCallback();

const { id, value } = item;
await toStore.setItem(id, safeJson.safeJsonParse(value));
await toStore.setItem(id, i(value));
}

@@ -244,3 +260,3 @@ await toStore.setItem(versionKey, DB_VERSION);

var _a;
return [entry[0], safeJson.safeJsonParse((_a = entry[1]) != null ? _a : "")];
return [entry[0], i((_a = entry[1]) != null ? _a : "")];
}

@@ -247,0 +263,0 @@

62

dist/index.es.js
import { createStorage } from 'unstorage';
import { createStore, get, set, del, keys, clear } from 'idb-keyval';
import { safeJsonStringify, safeJsonParse } from '@walletconnect/safe-json';
import indexedDbDriver from 'unstorage/drivers/indexedb';
function defineDriver(factory) {
return factory;
const s = (n) => JSON.stringify(n, (r, t) => typeof t == "bigint" ? t.toString() + "n" : t), o = (n) => {
const r = /([\[:])?(\d{17,}|(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))([,\}\]])/g, t = n.replace(r, '$1"$2n"$3');
return JSON.parse(t, (g, e) => typeof e == "string" && e.match(/^\d+n$/) ? BigInt(e.substring(0, e.length - 1)) : e);
};
function i(n) {
if (typeof n != "string")
throw new Error(`Cannot safe json parse value of type ${typeof n}`);
try {
return o(n);
} catch (e) {
return n;
}
}
function f(n) {
return typeof n == "string" ? n : s(n) || "";
}
const DRIVER_NAME = "idb-keyval";
var indexedDbDriver = defineDriver((opts = {}) => {
const base = opts.base && opts.base.length > 0 ? `${opts.base}:` : "";
const makeKey = (key) => base + key;
let customStore;
if (opts.dbName && opts.storeName) {
customStore = createStore(opts.dbName, opts.storeName);
}
return {
name: DRIVER_NAME,
options: opts,
async hasItem(key) {
const item = await get(makeKey(key), customStore);
return typeof item === "undefined" ? false : true;
},
async getItem(key) {
const item = await get(makeKey(key), customStore);
return item ?? null;
},
setItem(key, value) {
return set(makeKey(key), value, customStore);
},
removeItem(key) {
return del(makeKey(key), customStore);
},
getKeys() {
return keys(customStore);
},
clear() {
return clear(customStore);
}
};
});
const DB_NAME = "WALLET_CONNECT_V2_INDEXED_DB";

@@ -66,3 +44,3 @@ const DB_STORE_NAME = "keyvaluestorage";

async setItem(key, value) {
await this.indexedDb.setItem(key, safeJsonStringify(value));
await this.indexedDb.setItem(key, f(value));
}

@@ -120,3 +98,3 @@ async removeItem(key) {

var _a;
return [entry[0], safeJsonParse((_a = entry[1]) != null ? _a : "")];
return [entry[0], i((_a = entry[1]) != null ? _a : "")];
}

@@ -139,6 +117,6 @@

}
return safeJsonParse(item);
return i(item);
}
async setItem(key, value) {
this.localStorage.setItem(key, safeJsonStringify(value));
this.localStorage.setItem(key, f(value));
}

@@ -145,0 +123,0 @@ async removeItem(key) {

@@ -5,320 +5,28 @@ 'use strict';

var safeJson = require('@walletconnect/safe-json');
var AsyncStorage = require('@react-native-async-storage/async-storage');
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var isPlainObj = value => {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
}
var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.prototype;
const s = (n) => JSON.stringify(n, (r, t) => typeof t == "bigint" ? t.toString() + "n" : t), o = (n) => {
const r = /([\[:])?(\d{17,}|(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))([,\}\]])/g, t = n.replace(r, '$1"$2n"$3');
return JSON.parse(t, (g, e) => typeof e == "string" && e.match(/^\d+n$/) ? BigInt(e.substring(0, e.length - 1)) : e);
};
const isOptionObject = isPlainObj;
const {hasOwnProperty} = Object.prototype;
const {propertyIsEnumerable} = Object;
const defineProperty = (object, name, value) => Object.defineProperty(object, name, {
value,
writable: true,
enumerable: true,
configurable: true
});
const globalThis$1 = commonjsGlobal;
const defaultMergeOptions = {
concatArrays: false,
ignoreUndefined: false
};
const getEnumerableOwnPropertyKeys = value => {
const keys = [];
for (const key in value) {
if (hasOwnProperty.call(value, key)) {
keys.push(key);
}
}
/* istanbul ignore else */
if (Object.getOwnPropertySymbols) {
const symbols = Object.getOwnPropertySymbols(value);
for (const symbol of symbols) {
if (propertyIsEnumerable.call(value, symbol)) {
keys.push(symbol);
}
}
}
return keys;
};
function clone(value) {
if (Array.isArray(value)) {
return cloneArray(value);
}
if (isOptionObject(value)) {
return cloneOptionObject(value);
}
return value;
}
function cloneArray(array) {
const result = array.slice(0, 0);
getEnumerableOwnPropertyKeys(array).forEach(key => {
defineProperty(result, key, clone(array[key]));
});
return result;
}
function cloneOptionObject(object) {
const result = Object.getPrototypeOf(object) === null ? Object.create(null) : {};
getEnumerableOwnPropertyKeys(object).forEach(key => {
defineProperty(result, key, clone(object[key]));
});
return result;
}
/**
* @param {*} merged already cloned
* @param {*} source something to merge
* @param {string[]} keys keys to merge
* @param {Object} config Config Object
* @returns {*} cloned Object
*/
const mergeKeys = (merged, source, keys, config) => {
keys.forEach(key => {
if (typeof source[key] === 'undefined' && config.ignoreUndefined) {
return;
}
// Do not recurse into prototype chain of merged
if (key in merged && merged[key] !== Object.getPrototypeOf(merged)) {
defineProperty(merged, key, merge$1(merged[key], source[key], config));
} else {
defineProperty(merged, key, clone(source[key]));
}
});
return merged;
};
/**
* @param {*} merged already cloned
* @param {*} source something to merge
* @param {Object} config Config Object
* @returns {*} cloned Object
*
* see [Array.prototype.concat ( ...arguments )](http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.concat)
*/
const concatArrays = (merged, source, config) => {
let result = merged.slice(0, 0);
let resultIndex = 0;
[merged, source].forEach(array => {
const indices = [];
// `result.concat(array)` with cloning
for (let k = 0; k < array.length; k++) {
if (!hasOwnProperty.call(array, k)) {
continue;
}
indices.push(String(k));
if (array === merged) {
// Already cloned
defineProperty(result, resultIndex++, array[k]);
} else {
defineProperty(result, resultIndex++, clone(array[k]));
}
}
// Merge non-index keys
result = mergeKeys(result, array, getEnumerableOwnPropertyKeys(array).filter(key => !indices.includes(key)), config);
});
return result;
};
/**
* @param {*} merged already cloned
* @param {*} source something to merge
* @param {Object} config Config Object
* @returns {*} cloned Object
*/
function merge$1(merged, source, config) {
if (config.concatArrays && Array.isArray(merged) && Array.isArray(source)) {
return concatArrays(merged, source, config);
}
if (!isOptionObject(source) || !isOptionObject(merged)) {
return clone(source);
}
return mergeKeys(merged, source, getEnumerableOwnPropertyKeys(source), config);
}
var mergeOptions = function (...options) {
const config = merge$1(clone(defaultMergeOptions), (this !== globalThis$1 && this) || {}, defaultMergeOptions);
let merged = {_: {}};
for (const option of options) {
if (option === undefined) {
continue;
}
if (!isOptionObject(option)) {
throw new TypeError('`' + option + '` is not an Option Object');
}
merged = merge$1(merged, {_: option}, config);
}
return merged._;
};
/**
* Copyright (c) Nicolas Gallagher.
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const merge = mergeOptions.bind({
concatArrays: true,
ignoreUndefined: true
});
function mergeLocalStorageItem(key, value) {
const oldValue = window.localStorage.getItem(key);
if (oldValue) {
const oldObject = JSON.parse(oldValue);
const newObject = JSON.parse(value);
const nextValue = JSON.stringify(merge(oldObject, newObject));
window.localStorage.setItem(key, nextValue);
} else {
window.localStorage.setItem(key, value);
function i(n) {
if (typeof n != "string")
throw new Error(`Cannot safe json parse value of type ${typeof n}`);
try {
return o(n);
} catch (e) {
return n;
}
}
function createPromise(getValue, callback) {
return new Promise((resolve, reject) => {
try {
const value = getValue();
callback === null || callback === void 0 ? void 0 : callback(null, value);
resolve(value);
} catch (err) {
callback === null || callback === void 0 ? void 0 : callback(err);
reject(err);
}
});
function f(n) {
return typeof n == "string" ? n : s(n) || "";
}
function createPromiseAll(promises, callback, processResult) {
return Promise.all(promises).then(result => {
const value = (processResult === null || processResult === void 0 ? void 0 : processResult(result)) ?? null;
callback === null || callback === void 0 ? void 0 : callback(null, value);
return Promise.resolve(value);
}, errors => {
callback === null || callback === void 0 ? void 0 : callback(errors);
return Promise.reject(errors);
});
}
const AsyncStorage = {
/**
* Fetches `key` value.
*/
getItem: (key, callback) => {
return createPromise(() => window.localStorage.getItem(key), callback);
},
/**
* Sets `value` for `key`.
*/
setItem: (key, value, callback) => {
return createPromise(() => window.localStorage.setItem(key, value), callback);
},
/**
* Removes a `key`
*/
removeItem: (key, callback) => {
return createPromise(() => window.localStorage.removeItem(key), callback);
},
/**
* Merges existing value with input value, assuming they are stringified JSON.
*/
mergeItem: (key, value, callback) => {
return createPromise(() => mergeLocalStorageItem(key, value), callback);
},
/**
* Erases *all* AsyncStorage for the domain.
*/
clear: callback => {
return createPromise(() => window.localStorage.clear(), callback);
},
/**
* Gets *all* keys known to the app, for all callers, libraries, etc.
*/
getAllKeys: callback => {
return createPromise(() => {
const numberOfKeys = window.localStorage.length;
const keys = [];
for (let i = 0; i < numberOfKeys; i += 1) {
const key = window.localStorage.key(i) || "";
keys.push(key);
}
return keys;
}, callback);
},
/**
* (stub) Flushes any pending requests using a single batch call to get the data.
*/
flushGetRequests: () => undefined,
/**
* multiGet resolves to an array of key-value pair arrays that matches the
* input format of multiSet.
*
* multiGet(['k1', 'k2']) -> [['k1', 'val1'], ['k2', 'val2']]
*/
multiGet: (keys, callback) => {
const promises = keys.map(key => AsyncStorage.getItem(key));
const processResult = result => result.map((value, i) => [keys[i], value]);
return createPromiseAll(promises, callback, processResult);
},
/**
* Takes an array of key-value array pairs.
* multiSet([['k1', 'val1'], ['k2', 'val2']])
*/
multiSet: (keyValuePairs, callback) => {
const promises = keyValuePairs.map(item => AsyncStorage.setItem(item[0], item[1]));
return createPromiseAll(promises, callback);
},
/**
* Delete all the keys in the `keys` array.
*/
multiRemove: (keys, callback) => {
const promises = keys.map(key => AsyncStorage.removeItem(key));
return createPromiseAll(promises, callback);
},
/**
* Takes an array of key-value array pairs and merges them with existing
* values, assuming they are stringified JSON.
*
* multiMerge([['k1', 'val1'], ['k2', 'val2']])
*/
multiMerge: (keyValuePairs, callback) => {
const promises = keyValuePairs.map(item => AsyncStorage.mergeItem(item[0], item[1]));
return createPromiseAll(promises, callback);
}
};
function parseEntry(entry) {
var _a;
return [entry[0], safeJson.safeJsonParse((_a = entry[1]) != null ? _a : "")];
return [entry[0], i((_a = entry[1]) != null ? _a : "")];
}

@@ -328,3 +36,3 @@

constructor() {
this.asyncStorage = AsyncStorage;
this.asyncStorage = AsyncStorage__default["default"];
}

@@ -344,6 +52,6 @@ async getKeys() {

}
return safeJson.safeJsonParse(item);
return i(item);
}
async setItem(key, value) {
await this.asyncStorage.setItem(key, safeJson.safeJsonStringify(value));
await this.asyncStorage.setItem(key, f(value));
}

@@ -350,0 +58,0 @@ async removeItem(key) {

{
"name": "@walletconnect/keyvaluestorage",
"description": "Isomorphic Key-Value Storage",
"version": "1.1.0-canary-1",
"version": "1.1.0-canary-2",
"author": "WalletConnect, Inc. <walletconnect.com>",

@@ -6,0 +6,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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