@bsv/wallet-toolbox-client
Version:
Client only Wallet Storage
71 lines • 2.76 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageSyncReader = void 0;
const sdk = __importStar(require("../sdk/index"));
/**
* The `StorageSyncReader` non-abstract class must be used when authentication checking access to the methods of a `StorageBaseReader` is required.
*
* Constructed from an `auth` object that must minimally include the authenticated user's identityKey,
* and the `StorageBaseReader` to be protected.
*/
class StorageSyncReader {
constructor(auth, storage) {
this.auth = auth;
this.storage = storage;
}
async makeAvailable() {
await this.storage.makeAvailable();
if (this.auth.userId === undefined) {
const user = await this.storage.findUserByIdentityKey(this.auth.identityKey);
if (!user)
throw new sdk.WERR_UNAUTHORIZED();
this.auth.userId = user.userId;
}
return this.storage.getSettings();
}
destroy() {
return this.storage.destroy();
}
async getSyncChunk(args) {
if (!this.auth.userId)
await this.makeAvailable();
if (args.identityKey !== this.auth.identityKey)
throw new sdk.WERR_UNAUTHORIZED();
return await this.storage.getSyncChunk(args);
}
}
exports.StorageSyncReader = StorageSyncReader;
//# sourceMappingURL=StorageSyncReader.js.map