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

@4everland/content-id-registry-sdk

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@4everland/content-id-registry-sdk - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

188

lib/index.js

@@ -11,7 +11,34 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentIDRegistrySDK = void 0;
const content_id_registry_contracts_1 = require("@4everland/content-id-registry-contracts");
class ContentIDRegistrySDK {
constructor(resgistry, ipfs, signer) {
var content_id_registry_contracts_1 = require("@4everland/content-id-registry-contracts");
var ContentIDRegistrySDK = /** @class */ (function () {
function ContentIDRegistrySDK(resgistry, ipfs, signer) {
this.ipfs = ipfs;

@@ -21,69 +48,108 @@ this.signer = signer;

}
filesStat(cid, options) {
return __awaiter(this, void 0, void 0, function* () {
return this.ipfs.files.stat(cid, options);
ContentIDRegistrySDK.prototype.filesStat = function (cid, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ipfs.files.stat(cid, options)];
});
});
}
pin(token, cid, expiration, ipfsOptions) {
return __awaiter(this, void 0, void 0, function* () {
const isTokenExist = yield this.contract.tokenExists(token);
if (!isTokenExist) {
throw new Error('nonexistent token');
}
const files = yield this.filesStat(cid, ipfsOptions);
let size = 0;
if (files.type == 'directory') {
size = files.cumulativeSize;
}
else if (files.type == 'file') {
size = files.size;
}
else {
throw new Error('unknown cid type');
}
return this.contract.insert(token, cid.toString(), size, expiration);
};
ContentIDRegistrySDK.prototype.pin = function (token, cid, expiration, ipfsOptions) {
return __awaiter(this, void 0, void 0, function () {
var isTokenExist, files, size;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.contract.tokenExists(token)];
case 1:
isTokenExist = _a.sent();
if (!isTokenExist) {
throw new Error('nonexistent token');
}
return [4 /*yield*/, this.filesStat(cid, ipfsOptions)];
case 2:
files = _a.sent();
size = 0;
if (files.type == 'directory') {
size = files.cumulativeSize;
}
else if (files.type == 'file') {
size = files.size;
}
else {
throw new Error('unknown cid type');
}
return [2 /*return*/, this.contract.insert(token, cid.toString(), size, expiration)];
}
});
});
}
unpin(cid) {
return __awaiter(this, void 0, void 0, function* () {
return this.contract.remove(cid.toString());
};
ContentIDRegistrySDK.prototype.unpin = function (cid) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.contract.remove(cid.toString())];
});
});
}
getSizeInContract(address, cid) {
return __awaiter(this, void 0, void 0, function* () {
return this.contract.getSize(address, cid.toString());
};
ContentIDRegistrySDK.prototype.getSizeInContract = function (address, cid) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.contract.getSize(address, cid.toString())];
});
});
}
getExpirationInContract(address, cid) {
return __awaiter(this, void 0, void 0, function* () {
return this.contract.getExpiration(address, cid.toString());
};
ContentIDRegistrySDK.prototype.getExpirationInContract = function (address, cid) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.contract.getExpiration(address, cid.toString())];
});
});
}
extentExpiration(token, cid, extent) {
return __awaiter(this, void 0, void 0, function* () {
return this.contract.updateExpiration(token, cid.toString(), extent);
};
ContentIDRegistrySDK.prototype.extentExpiration = function (token, cid, extent) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.contract.updateExpiration(token, cid.toString(), extent)];
});
});
}
getValue(token, size, expiration) {
return __awaiter(this, void 0, void 0, function* () {
return this.contract.getValue(token, size, expiration);
};
ContentIDRegistrySDK.prototype.getValue = function (token, size, expiration) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.contract.getValue(token, size, expiration)];
});
});
}
exists(address, cid) {
return __awaiter(this, void 0, void 0, function* () {
return this.contract.exists(address, cid.toString());
};
ContentIDRegistrySDK.prototype.exists = function (address, cid) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.contract.exists(address, cid.toString())];
});
});
}
tokens() {
return __awaiter(this, void 0, void 0, function* () {
const len = yield this.contract.tokenLength();
const tokens = [];
for (let i = 0; i < len.toNumber(); i++) {
const token = yield this.contract.tokens(i);
tokens.push(token);
}
return tokens;
};
ContentIDRegistrySDK.prototype.tokens = function () {
return __awaiter(this, void 0, void 0, function () {
var len, tokens, i, token;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.contract.tokenLength()];
case 1:
len = _a.sent();
tokens = [];
i = 0;
_a.label = 2;
case 2:
if (!(i < len.toNumber())) return [3 /*break*/, 5];
return [4 /*yield*/, this.contract.tokens(i)];
case 3:
token = _a.sent();
tokens.push(token);
_a.label = 4;
case 4:
i++;
return [3 /*break*/, 2];
case 5: return [2 /*return*/, tokens];
}
});
});
}
}
};
return ContentIDRegistrySDK;
}());
exports.ContentIDRegistrySDK = ContentIDRegistrySDK;
{
"name": "@4everland/content-id-registry-sdk",
"version": "0.1.5",
"version": "0.1.6",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

{
"compilerOptions": {
"target": "es6",
"target": "ES5",
"module": "commonjs",

@@ -5,0 +5,0 @@ "declaration": true,

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