Skip to content

feat: @ckb-ccc/molecule #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/core/src/molecule/predefined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export const Bool: Codec<boolean> = Codec.from({
export const BoolOpt = option(Bool);
export const BoolVec = vector(Bool);

export const Byte: Codec<HexLike, Hex> = Codec.from({
byteLength: 1,
encode: (value) => bytesFrom(value),
decode: (buffer) => hexFrom(buffer),
});
export const ByteOpt = option(Byte);

export const Byte4: Codec<HexLike, Hex> = Codec.from({
byteLength: 4,
encode: (value) => bytesFrom(value),
Expand Down
21 changes: 21 additions & 0 deletions packages/molecule/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
node_modules/
misc/

*test.js
*test.ts
*test.d.ts
*test.d.ts.map
*spec.js
*spec.ts
*spec.d.ts
*spec.d.ts.map

tsconfig.json
tsconfig.*.json
eslint.config.mjs
.prettierrc
.prettierignore

tsconfig.tsbuildinfo
tsconfig.*.tsbuildinfo
.github/
13 changes: 13 additions & 0 deletions packages/molecule/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules/

dist/
dist.commonjs/

.npmignore
.prettierrc
tsconfig.json
eslint.config.mjs
.prettierrc

tsconfig.tsbuildinfo
.github/
5 changes: 5 additions & 0 deletions packages/molecule/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": false,
"trailingComma": "all",
"plugins": ["prettier-plugin-organize-imports"]
}
43 changes: 43 additions & 0 deletions packages/molecule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<p align="center">
<a href="https://app.ckbccc.com/">
<img alt="Logo" src="https://raw.githubusercontent.com/ckb-devrel/ccc/master/assets/logoAndText.svg" style="height: 8rem; max-width: 90%; padding: 0.5rem 0;" />
</a>
</p>

<h1 align="center" style="font-size: 48px;">
CCC's Support for Molecule
</h1>

<p align="center">
<a href="https://www.npmjs.com/package/@ckb-ccc/ssri"><img
alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Fssri"
/></a>
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-devrel/ccc" />
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-devrel/ccc/master" />
<img alt="GitHub branch check runs" src="https://img.shields.io/github/check-runs/ckb-devrel/ccc/master" />
<a href="https://live.ckbccc.com/"><img
alt="Playground" src="https://img.shields.io/website?url=https%3A%2F%2Flive.ckbccc.com%2F&label=Playground"
/></a>
<a href="https://app.ckbccc.com/"><img
alt="App" src="https://img.shields.io/website?url=https%3A%2F%2Fapp.ckbccc.com%2F&label=App"
/></a>
<a href="https://docs.ckbccc.com/"><img
alt="Docs" src="https://img.shields.io/website?url=https%3A%2F%2Fdocs.ckbccc.com%2F&label=Docs"
/></a>
</p>

<p align="center">
CCC - CKBers' Codebase is a one-stop solution for your CKB JS/TS ecosystem development.
<br />
Empower yourself with CCC to discover the unlimited potential of CKB.
<br />
Interoperate with wallets from different chain ecosystems.
<br />
Fully enabling CKB's Turing completeness and cryptographic freedom power.
</p>

Get `CodecMap` from Molecule schema.

<h3 align="center">
Read more about CCC on <a href="https://docs.ckbccc.com">our website</a> or <a href="https://github.com/ckb-devrel/ccc">GitHub Repo</a>.
</h3>
50 changes: 50 additions & 0 deletions packages/molecule/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// @ts-check

import eslint from "@eslint/js";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import tseslint from "typescript-eslint";

import { dirname } from "path";
import { fileURLToPath } from "url";

export default [
{
ignores: ["**/grammar.js"],
},
...tseslint.config({
files: ["**/*.ts"],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
],
rules: {
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
"@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/require-await": "off",
"no-empty": "off",
"prefer-const": [
"error",
{ ignoreReadBeforeAssign: true, destructuring: "all" },
],
},
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: dirname(fileURLToPath(import.meta.url)),
},
},
}),
eslintPluginPrettierRecommended,
];
14 changes: 14 additions & 0 deletions packages/molecule/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testMatch: ["**/*.spec.ts"],
moduleFileExtensions: ["ts", "js", "json", "peggy", "node"],
transform: {
"^.+\\.ts$": ["ts-jest", { tsconfig: "tsconfig.json" }],
"^.+\\.peggy$": [
"<rootDir>/peggy-transformer.js",
{ tsconfig: "tsconfig.json" },
],
},
};
60 changes: 60 additions & 0 deletions packages/molecule/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "@ckb-ccc/molecule",
"version": "0.0.1",
"description": "Molecule parser for CKB",
"author": "Alive24 <xct24@live.com>",
"homepage": "https://github.com/ckb-devrel/ccc",
"license": "MIT",
"main": "./dist.commonjs/index.js",
"module": "./dist/index.js",
"exports": {
".": {
"import": "./dist/index.js",
"default": "./dist.commonjs/index.js"
},
"./barrel": {
"import": "./dist/barrel.js",
"default": "./dist.commonjs/barrel.js"
}
},
"private": false,
"engines": {
"node": ">=12.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ckb-devrel/ccc.git"
},
"bugs": {
"url": "https://github.com/ckb-devrel/ccc/issues"
},
"scripts": {
"test": "jest",
"fmt": "prettier --write \"{src,tests,examples}/**/*.ts\" package.json",
"lint": "eslint ./src",
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
"clean": "rm -rf lib"
},
"dependencies": {
"@ckb-ccc/core": "workspace:*",
"glob": "^10.3.10",
"relative": "^3.0.2"
},
"devDependencies": {
"@eslint/js": "^9.1.1",
"eslint": "^9.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"typescript-eslint": "^7.7.0",
"@types/js-yaml": "^4.0.9",
"copyfiles": "^2.4.1",
"js-yaml": "^4.1.0",
"jsbi": "^4.1.0",
"peggy": "^4.0.3",
"rimraf": "^5.0.5",
"prettier-plugin-organize-imports": "^3.2.4"
},
"publishConfig": {
"access": "public"
}
}
14 changes: 14 additions & 0 deletions packages/molecule/peggy-transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const peggy = require("peggy");

module.exports = {
process(sourceText) {
const parser = peggy.generate(sourceText, {
output: "source",
format: "commonjs",
});

return {
code: parser,
};
},
};
2 changes: 2 additions & 0 deletions packages/molecule/src/barrel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./molecule";
export * from "./type";
Loading
Loading