@mobile-wallet-protocol/client
Version:
Client SDK for the Mobile Wallet Protocol
37 lines (36 loc) • 1.41 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScopedAsyncStorage = void 0;
const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
const types_1 = require("./types");
class ScopedAsyncStorage extends types_1.ScopedStorage {
constructor(scope, module) {
super(scope, module);
}
async storeObject(key, item) {
await this.setItem(key, JSON.stringify(item));
}
async loadObject(key) {
const item = await this.getItem(key);
return item ? JSON.parse(item) : undefined;
}
async setItem(key, value) {
await async_storage_1.default.setItem(this.scopedKey(key), value);
}
async getItem(key) {
return async_storage_1.default.getItem(this.scopedKey(key));
}
async removeItem(key) {
await async_storage_1.default.removeItem(this.scopedKey(key));
}
async clear() {
const prefix = this.scopedKey('');
const keys = await async_storage_1.default.getAllKeys();
const keysToRemove = keys.filter((key) => typeof key === 'string' && key.startsWith(prefix));
await async_storage_1.default.multiRemove(keysToRemove);
}
}
exports.ScopedAsyncStorage = ScopedAsyncStorage;