New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ckb-lumos/config-manager

Package Overview
Dependencies
Maintainers
3
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckb-lumos/config-manager - npm Package Compare versions

Comparing version 0.0.0-canary-54f8aff-20230815035108 to 0.0.0-canary-58ff5e4-20240712061301

lib/genesis.d.ts

6

lib/index.d.ts
export * from "./types";
export { initializeConfig, getConfig, validateConfig } from "./manager";
/**
* @deprecated use the {@link nameOfScript} and {@link findConfigByScript} function instead
*/
export * as helpers from "./helpers";
export { nameOfScript, findConfigByScript } from "./helpers";
export { predefined, createConfig } from "./predefined";
export { generateGenesisScriptConfigs } from "./genesis";
export { refreshScriptConfigs, createRpcResolver, createLatestTypeIdResolver, } from "./refresh";
//# sourceMappingURL=index.d.ts.map

50

lib/index.js

@@ -10,5 +10,11 @@ "use strict";

validateConfig: true,
nameOfScript: true,
findConfigByScript: true,
helpers: true,
predefined: true,
createConfig: true
createConfig: true,
generateGenesisScriptConfigs: true,
refreshScriptConfigs: true,
createRpcResolver: true,
createLatestTypeIdResolver: true
};

@@ -21,2 +27,26 @@ Object.defineProperty(exports, "createConfig", {

});
Object.defineProperty(exports, "createLatestTypeIdResolver", {
enumerable: true,
get: function () {
return _refresh.createLatestTypeIdResolver;
}
});
Object.defineProperty(exports, "createRpcResolver", {
enumerable: true,
get: function () {
return _refresh.createRpcResolver;
}
});
Object.defineProperty(exports, "findConfigByScript", {
enumerable: true,
get: function () {
return _helpers.findConfigByScript;
}
});
Object.defineProperty(exports, "generateGenesisScriptConfigs", {
enumerable: true,
get: function () {
return _genesis.generateGenesisScriptConfigs;
}
});
Object.defineProperty(exports, "getConfig", {

@@ -35,2 +65,8 @@ enumerable: true,

});
Object.defineProperty(exports, "nameOfScript", {
enumerable: true,
get: function () {
return _helpers.nameOfScript;
}
});
Object.defineProperty(exports, "predefined", {

@@ -42,2 +78,8 @@ enumerable: true,

});
Object.defineProperty(exports, "refreshScriptConfigs", {
enumerable: true,
get: function () {
return _refresh.refreshScriptConfigs;
}
});
Object.defineProperty(exports, "validateConfig", {

@@ -65,4 +107,6 @@ enumerable: true,

var _predefined = require("./predefined");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var _genesis = require("./genesis");
var _refresh = require("./refresh");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
//# sourceMappingURL=index.js.map

3

lib/manager.d.ts
import { Config } from "./types";
export declare function assertHashType(debugPath: string, hashType: string): void;
export declare function validateConfig(config: Config): void;
export declare function getConfig(): Config;
export declare function initializeConfig(inputConfig?: Config): void;
export declare function initializeConfig(inputConfig: Config): void;
//# sourceMappingURL=manager.d.ts.map

@@ -6,2 +6,3 @@ "use strict";

});
exports.assertHashType = assertHashType;
exports.getConfig = getConfig;

@@ -11,3 +12,2 @@ exports.initializeConfig = initializeConfig;

var _deepFreezeStrict = _interopRequireDefault(require("deep-freeze-strict"));
var _base = require("@ckb-lumos/base");
var _predefined = require("./predefined");

@@ -22,4 +22,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

assertHexString(debugPath, hash);
if (hash.length != 66) {
throw new Error(`${debugPath} must be a hex string of 66 bytes long!`);
// 2 for 0x
// 64 for 32 bytes in hex format
const hashHexLength = 66;
if (hash.length !== hashHexLength) {
throw new Error(`${debugPath} must be a hex string of 66 characters long!`);
}

@@ -35,2 +38,7 @@ }

}
function assertHashType(debugPath, hashType) {
if (hashType !== "type" && hashType !== "data" && hashType !== "data1" && hashType !== "data2") {
throw new Error(`${debugPath} must one of type, data, data1, data2!`);
}
}
function assert(condition, debugPath = "variable") {

@@ -45,6 +53,3 @@ if (!condition) throw new Error(`${debugPath} is not valid`);

assertHash(`SCRIPTS.${scriptName}.CODE_HASH`, scriptConfig.CODE_HASH);
const hashType = scriptConfig.HASH_TYPE;
if (hashType !== "type" && hashType !== "data" && hashType !== "data1") {
throw new Error(`SCRIPTS.${scriptName}.HASH_TYPE must be type, data or data1!`);
}
assertHashType(`SCRIPTS.${scriptName}.HASH_TYPE`, scriptConfig.HASH_TYPE);
assertHash(`SCRIPTS.${scriptName}.TX_HASH`, scriptConfig.TX_HASH);

@@ -69,43 +74,6 @@ assertInteger(`SCRIPTS.${scriptName}.INDEX`, scriptConfig.INDEX);

}
/**
* Initialize current app with a config. The initializaton steps work as follows:
* 1. If `LUMOS_CONFIG_NAME` environment variable is set to a predefined config,
* the predefined config is loaded;
* 2. If `LUMOS_CONFIG_FILE` environment variable is set, it will be used as the
* name of a file containing the Config to use.
* 3. A file named `config.json` in current running directory will be used as the
* file containing the Config to use.
* @deprecated
* @returns void
*/
function initializeConfigLegacy() {
var _process;
const env = (_process = process) === null || _process === void 0 ? void 0 : _process.env;
const configName = env === null || env === void 0 ? void 0 : env.LUMOS_CONFIG_NAME;
if ((configName === "LINA" || configName === "AGGRON4") && _predefined.predefined[configName]) {
config = _predefined.predefined[configName];
return;
}
const configFile = env === null || env === void 0 ? void 0 : env.LUMOS_CONFIG_FILE;
const configFilename = configFile || "config.json";
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const data = require("fs").readFileSync(configFilename);
const loadedConfig = JSON.parse(data);
validateConfig(loadedConfig);
config = (0, _deepFreezeStrict.default)(loadedConfig);
} catch (e) {
throw new Error(`Error loading config from file ${configFilename}: ${e}`);
}
}
function initializeConfig(inputConfig) {
if (!inputConfig) {
_base.logger.deprecated("initializeConfig with env will be deprecated, please migrate to initializeConfig(...)");
initializeConfigLegacy();
} else {
validateConfig(inputConfig);
config = (0, _deepFreezeStrict.default)(inputConfig);
}
validateConfig(inputConfig);
config = (0, _deepFreezeStrict.default)(inputConfig);
}
//# sourceMappingURL=manager.js.map

@@ -60,2 +60,9 @@ import { ScriptConfig } from "./types";

};
XUDT: {
CODE_HASH: string;
HASH_TYPE: "data1";
TX_HASH: string;
INDEX: string;
DEP_TYPE: "code";
};
};

@@ -111,2 +118,9 @@ };

};
XUDT: {
CODE_HASH: string;
HASH_TYPE: "type";
TX_HASH: string;
INDEX: string;
DEP_TYPE: "code";
};
};

@@ -113,0 +127,0 @@ };

@@ -61,5 +61,12 @@ "use strict";

HASH_TYPE: "type",
TX_HASH: "0xdfdb40f5d229536915f2d5403c66047e162e25dedd70a79ef5164356e1facdc8",
TX_HASH: "0xc76edf469816aa22f416503c38d0b533d2a018e253e379f134c3985b3472c842",
INDEX: "0x0",
DEP_TYPE: "code"
},
XUDT: {
CODE_HASH: "0x50bd8d6680b8b9cf98b73f3c08faf8b2a21914311954118ad6609be6e78a1b95",
HASH_TYPE: "data1",
TX_HASH: "0xc07844ce21b38e4b071dd0e1ee3b0e27afd8d7532491327f39b786343f558ab7",
INDEX: "0x0",
DEP_TYPE: "code"
}

@@ -112,13 +119,19 @@ }

HASH_TYPE: "type",
TX_HASH: "0x27b62d8be8ed80b9f56ee0fe41355becdb6f6a40aeba82d3900434f43b1c8b60",
TX_HASH: "0xec18bf0d857c981c3d1f4e17999b9b90c484b303378e94de1a57b0872f5d4602",
INDEX: "0x0",
DEP_TYPE: "code"
},
XUDT: {
CODE_HASH: "0x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb",
HASH_TYPE: "type",
TX_HASH: "0xbf6fb538763efec2a70a6a3dcb7242787087e1030c4e7d86585bc63a9d337f5f",
INDEX: "0x0",
DEP_TYPE: "code"
}
}
});
const predefined = {
const predefined = exports.predefined = {
LINA,
AGGRON4
};
exports.predefined = predefined;
//# sourceMappingURL=predefined.js.map

@@ -0,5 +1,6 @@

import { HashType } from "@ckb-lumos/base";
/** Deployed script on chain */
export interface ScriptConfig {
CODE_HASH: string;
HASH_TYPE: "type" | "data" | "data1";
HASH_TYPE: HashType;
TX_HASH: string;

@@ -6,0 +7,0 @@ INDEX: string;

{
"name": "@ckb-lumos/config-manager",
"version": "0.0.0-canary-54f8aff-20230815035108",
"version": "0.0.0-canary-58ff5e4-20240712061301",
"description": "Config manager for lumos",

@@ -28,15 +28,28 @@ "author": "Xuejie Xiao <xxuejie@gmail.com>",

"dependencies": {
"@ckb-lumos/base": "0.0.0-canary-54f8aff-20230815035108",
"@ckb-lumos/bi": "0.0.0-canary-54f8aff-20230815035108",
"@ckb-lumos/codec": "0.0.0-canary-54f8aff-20230815035108",
"@ckb-lumos/base": "0.0.0-canary-58ff5e4-20240712061301",
"@ckb-lumos/bi": "0.0.0-canary-58ff5e4-20240712061301",
"@ckb-lumos/codec": "0.0.0-canary-58ff5e4-20240712061301",
"@ckb-lumos/rpc": "0.0.0-canary-58ff5e4-20240712061301",
"@types/deep-freeze-strict": "^1.1.0",
"deep-freeze-strict": "^1.1.1"
},
"devDependencies": {
"@ckb-lumos/crypto": "0.0.0-canary-58ff5e4-20240712061301"
},
"publishConfig": {
"access": "public"
},
"ava": {
"extensions": [
"ts",
"js"
],
"require": [
"ts-node/register"
]
},
"scripts": {
"fmt": "prettier --write \"{src,tests}/**/*.ts\" package.json",
"lint": "eslint -c ../../.eslintrc.js \"{src,tests}/**/*.ts\"",
"test": "ava --timeout=2m",
"test": "ava **/*.test.{js,ts} --timeout=2m",
"build": "pnpm run build:types && pnpm run build:js",

@@ -43,0 +56,0 @@ "build:types": "tsc --declaration --emitDeclarationOnly",

@@ -6,11 +6,28 @@ # @ckb-lumos/config-manager

```ts
import { initializeConfig, predefined } from '@ckb-lumos/config';
import { generateAddress } from '@ckb-lumos/helper'
import { initializeConfig, predefined } from "@ckb-lumos/config-manager"
// or import from the entry package
import { initializeConfig, predefined } from "@ckb-lumos/lumos/config"
import { encodeToAddress } from '@ckb-lumos/helper'
initializeConfig(predefined.AGGRON);
generateAddress({...}) // ckt1...
encodeToAddress({...}) // ckt1...
initializeConfig(predefined.LINA);
generateAddress({...}) // ckb1...
encodeToAddress({...}) // ckb1...
```
## Refreshing Config
```ts
import { refreshScriptConfigs } from "@ckb-lumos/config-manager"
// or import from the entry package
import { refreshScriptConfigs } from "@ckb-lumos/lumos/config"
import { RPC } from "@ckb-lumos/rpc";
const rpc = new RPC("http://localhost:8114");
const refreshed = await refreshScriptConfigs(predefined.AGGRON4.SCRIPTS, {
resolve: createRpcResolver(rpc),
});
```
export * from "./types";
export { initializeConfig, getConfig, validateConfig } from "./manager";
/**
* @deprecated use the {@link nameOfScript} and {@link findConfigByScript} function instead
*/
export * as helpers from "./helpers";
export { nameOfScript, findConfigByScript } from "./helpers";
export { predefined, createConfig } from "./predefined";
export { generateGenesisScriptConfigs } from "./genesis";
export {
refreshScriptConfigs,
createRpcResolver,
createLatestTypeIdResolver,
} from "./refresh";
import deepFreeze from "deep-freeze-strict";
import { logger } from "@ckb-lumos/base";
import { Config } from "./types";

@@ -14,4 +13,7 @@ import { predefined } from "./predefined";

assertHexString(debugPath, hash);
if (hash.length != 66) {
throw new Error(`${debugPath} must be a hex string of 66 bytes long!`);
// 2 for 0x
// 64 for 32 bytes in hex format
const hashHexLength = 66;
if (hash.length !== hashHexLength) {
throw new Error(`${debugPath} must be a hex string of 66 characters long!`);
}

@@ -29,2 +31,13 @@ }

export function assertHashType(debugPath: string, hashType: string): void {
if (
hashType !== "type" &&
hashType !== "data" &&
hashType !== "data1" &&
hashType !== "data2"
) {
throw new Error(`${debugPath} must one of type, data, data1, data2!`);
}
}
function assert(condition: unknown, debugPath = "variable"): asserts condition {

@@ -46,8 +59,3 @@ if (!condition) throw new Error(`${debugPath} is not valid`);

assertHash(`SCRIPTS.${scriptName}.CODE_HASH`, scriptConfig.CODE_HASH);
const hashType = scriptConfig.HASH_TYPE;
if (hashType !== "type" && hashType !== "data" && hashType !== "data1") {
throw new Error(
`SCRIPTS.${scriptName}.HASH_TYPE must be type, data or data1!`
);
}
assertHashType(`SCRIPTS.${scriptName}.HASH_TYPE`, scriptConfig.HASH_TYPE);
assertHash(`SCRIPTS.${scriptName}.TX_HASH`, scriptConfig.TX_HASH);

@@ -77,48 +85,5 @@ assertInteger(`SCRIPTS.${scriptName}.INDEX`, scriptConfig.INDEX);

/**
* Initialize current app with a config. The initializaton steps work as follows:
* 1. If `LUMOS_CONFIG_NAME` environment variable is set to a predefined config,
* the predefined config is loaded;
* 2. If `LUMOS_CONFIG_FILE` environment variable is set, it will be used as the
* name of a file containing the Config to use.
* 3. A file named `config.json` in current running directory will be used as the
* file containing the Config to use.
* @deprecated
* @returns void
*/
function initializeConfigLegacy() {
const env = process?.env;
const configName = env?.LUMOS_CONFIG_NAME;
if (
(configName === "LINA" || configName === "AGGRON4") &&
predefined[configName]
) {
config = predefined[configName];
return;
}
const configFile = env?.LUMOS_CONFIG_FILE;
const configFilename = configFile || "config.json";
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const data = require("fs").readFileSync(configFilename);
const loadedConfig = JSON.parse(data);
validateConfig(loadedConfig);
config = deepFreeze(loadedConfig);
} catch (e) {
throw new Error(`Error loading config from file ${configFilename}: ${e}`);
}
export function initializeConfig(inputConfig: Config): void {
validateConfig(inputConfig);
config = deepFreeze(inputConfig);
}
export function initializeConfig(inputConfig?: Config): void {
if (!inputConfig) {
logger.deprecated(
"initializeConfig with env will be deprecated, please migrate to initializeConfig(...)"
);
initializeConfigLegacy();
} else {
validateConfig(inputConfig);
config = deepFreeze(inputConfig);
}
}

@@ -73,6 +73,15 @@ import deepFreeze from "deep-freeze-strict";

TX_HASH:
"0xdfdb40f5d229536915f2d5403c66047e162e25dedd70a79ef5164356e1facdc8",
"0xc76edf469816aa22f416503c38d0b533d2a018e253e379f134c3985b3472c842",
INDEX: "0x0",
DEP_TYPE: "code",
},
XUDT: {
CODE_HASH:
"0x50bd8d6680b8b9cf98b73f3c08faf8b2a21914311954118ad6609be6e78a1b95",
HASH_TYPE: "data1",
TX_HASH:
"0xc07844ce21b38e4b071dd0e1ee3b0e27afd8d7532491327f39b786343f558ab7",
INDEX: "0x0",
DEP_TYPE: "code",
},
},

@@ -137,6 +146,15 @@ });

TX_HASH:
"0x27b62d8be8ed80b9f56ee0fe41355becdb6f6a40aeba82d3900434f43b1c8b60",
"0xec18bf0d857c981c3d1f4e17999b9b90c484b303378e94de1a57b0872f5d4602",
INDEX: "0x0",
DEP_TYPE: "code",
},
XUDT: {
CODE_HASH:
"0x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb",
HASH_TYPE: "type",
TX_HASH:
"0xbf6fb538763efec2a70a6a3dcb7242787087e1030c4e7d86585bc63a9d337f5f",
INDEX: "0x0",
DEP_TYPE: "code",
},
},

@@ -143,0 +161,0 @@ });

@@ -0,5 +1,7 @@

import { HashType } from "@ckb-lumos/base";
/** Deployed script on chain */
export interface ScriptConfig {
CODE_HASH: string;
HASH_TYPE: "type" | "data" | "data1";
HASH_TYPE: HashType;
TX_HASH: string;

@@ -6,0 +8,0 @@ INDEX: string;

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

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

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