Skip to content

Commit

Permalink
Merge pull request #246 from ckb-cell/ref/support-esm
Browse files Browse the repository at this point in the history
refactor(rgbpp-sdk): Support ESM package
  • Loading branch information
duanyytop authored Aug 5, 2024
2 parents 2cf54a0 + a70fee4 commit aac6b82
Show file tree
Hide file tree
Showing 57 changed files with 1,080 additions and 584 deletions.
8 changes: 8 additions & 0 deletions .changeset/old-poems-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@rgbpp-sdk/service": minor
"rgbpp": minor
"@rgbpp-sdk/btc": minor
"@rgbpp-sdk/ckb": minor
---

feat: Export ESM packages
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"browser": true,
"es2021": true
},
"ignorePatterns": ["dist/"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: pnpm run build:packages

- name: Lint packages
run: pnpm run lint:packages
run: pnpm run lint

- name: Run tests for packages
run: pnpm run test:packages
Expand Down
2 changes: 1 addition & 1 deletion apps/service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"convert-keys": "^1.3.4",
"json-rpc-2.0": "^1.7.0",
"reflect-metadata": "^0.2.0",
"rgbpp": "workspace:*",
"rgbpp": "^0.5.0",
"rxjs": "^7.8.1",
"zod": "^3.23.8"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/service/src/json-rpc/json-rpc.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class JsonRpcServer {
}
const name = metadata.name
? `${metadata.name}.${methodMetadata.name ?? methodName}`
: methodMetadata.name ?? methodName;
: (methodMetadata.name ?? methodName);
const handler = (params: unknown) => {
const instanceRef = this.moduleRef.get(instance.constructor, { strict: false });
return instanceRef[methodName](params);
Expand Down
28 changes: 14 additions & 14 deletions examples/rgbpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ VITE_BTC_SERVICE_ORIGIN=https://btc-test.app
```shell
# Create a CKB empty rgbpp lock cell to launch RGB++ xUDT assets later
npx ts-node xudt/launch/1-prepare-launch.ts
npx tsx xudt/launch/1-prepare-launch.ts
```
#### 2. Launch RGB++ xUDT on BTC

> [!TIP]
> Please make sure the `1-prepare-launch.ts` has been run and the corresponding CKB transaction has been committed.
```shell
npx ts-node xudt/launch/2-launch-rgbpp.ts
npx tsx xudt/launch/2-launch-rgbpp.ts
```

When the command is executed successfully, the **RGB++ Asset type script args** will appear in the output log
Expand All @@ -99,27 +99,27 @@ When the command is executed successfully, the **RGB++ Asset type script args**
> The **RGB++ Asset type script args** in the above should be set to the `xudtTypeArgs`.
```shell
npx ts-node xudt/launch/3-distribute-rgbpp.ts
npx tsx xudt/launch/3-distribute-rgbpp.ts
```

### RGB++ xUDT Transfer and Leap

#### 1. Leap xUDT from CKB to BTC

```shell
npx ts-node xudt/1-ckb-leap-btc.ts
npx tsx xudt/1-ckb-leap-btc.ts
```

#### 2. Transfer RGB++ xUDT on BTC with Queue Service

```shell
npx ts-node xudt/2-btc-transfer.ts
npx tsx xudt/2-btc-transfer.ts
```

#### 3. Leap RGB++ xUDT from BTC to CKB with Queue Service

```shell
npx ts-node xudt/3-btc-leap-ckb.ts
npx tsx xudt/3-btc-leap-ckb.ts
```

#### 4. Unlock xUDT BTC time cells on CKB
Expand All @@ -131,7 +131,7 @@ However, you can still manually unlock the spore BTC time cell through the follo
Warning: Wait at least 6 BTC confirmation blocks to unlock the BTC time cells after 3-btc-leap-ckb.ts

```shell
npx ts-node xudt/4-unlock-btc-time.ts
npx tsx xudt/4-unlock-btc-time.ts
```

## RGB++ Spore Examples
Expand All @@ -146,10 +146,10 @@ npx ts-node xudt/4-unlock-btc-time.ts
```shell
# Create a CKB empty rgbpp lock cell to create cluster later
npx ts-node spore/launch/1-prepare-cluster.ts
npx tsx spore/launch/1-prepare-cluster.ts

# Create a cluster cell with rgbpp lock
npx ts-node spore/launch/2-create-cluster.ts
npx tsx spore/launch/2-create-cluster.ts
```

When the commands are executed successfully, the **clusterId** and **cluster rgbpp lock args** will appear in the output log
Expand All @@ -161,21 +161,21 @@ When the commands are executed successfully, the **clusterId** and **cluster rgb
> The **clusterId** in the above should be set to the `clusterId` and the **cluster rgbpp lock args** should be set to the `clusterRgbppLockArgs`.
```shell
npx ts-node spore/launch/3-create-spores.ts
npx tsx spore/launch/3-create-spores.ts
```

### Transfer and Leap Spore

#### 1. Transfer RGB++ Spore on BTC with Queue Service

```shell
npx ts-node spore/4-transfer-spore.ts
npx tsx spore/4-transfer-spore.ts
```

#### 2. Leap RGB++ Spore from BTC to CKB

```shell
npx ts-node spore/5-leap-spore-to-ckb.ts
npx tsx spore/5-leap-spore-to-ckb.ts
```

#### 3. Unlock Spore BTC time cells on CKB
Expand All @@ -187,13 +187,13 @@ However, you can still manually unlock the spore BTC time cell through the follo
**Warning: Wait at least 6 BTC confirmation blocks to unlock the BTC time cells after 5-leap-spore-to-ckb.ts**

```shell
npx ts-node spore/6-unlock-btc-time-cell.ts
npx tsx spore/6-unlock-btc-time-cell.ts
```

#### 4. Leap Spore from CKB to BTC

```shell
npx ts-node spore/7-leap-spore-to-btc.ts
npx tsx spore/7-leap-spore-to-btc.ts
```

## FAQ
Expand Down
4 changes: 1 addition & 3 deletions examples/rgbpp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
"lint:fix": "tsc && eslint --fix --ext .js,.ts . && prettier --write '**/*.{js,ts}'"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-utils": "0.109.1",
"@nervosnetwork/ckb-sdk-utils": "0.109.2",
"rgbpp": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.11.28",
"typescript": "^5.4.2",
"dotenv": "^16.4.5",
"@types/dotenv": "^8.2.0"
}
Expand Down
6 changes: 3 additions & 3 deletions examples/rgbpp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "ES2015",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "NodeNext",
"lib": ["esnext"],
"module": "ES2015",
"composite": false,
"resolveJsonModule": true,
"strictNullChecks": true,
Expand All @@ -14,7 +14,7 @@
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"moduleResolution": "NodeNext",
"moduleResolution": "Bundler",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
Expand Down
4 changes: 2 additions & 2 deletions examples/xudt-on-ckb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ CKB_INDEXER_URL=https://testnet.ckb.dev/indexer
### Issue xUDT on CKB

```shell
npx ts-node 1-issue-xudt.ts
npx tsx 1-issue-xudt.ts
```

### Mint/Transfer xUDT on CKB

You can use this command to mint or transfer xUDT assets

```shell
npx ts-node 2-transfer-xudt.ts
npx tsx 2-transfer-xudt.ts
```
4 changes: 2 additions & 2 deletions examples/xudt-on-ckb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"lint:fix": "tsc && eslint --fix --ext .ts . && prettier --write '**/*.ts'"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-utils": "0.109.1",
"rgbpp": "^0.3.0"
"@nervosnetwork/ckb-sdk-utils": "0.109.2",
"rgbpp": "workspace:*"
},
"devDependencies": {
"dotenv": "^16.4.5",
Expand Down
7 changes: 3 additions & 4 deletions examples/xudt-on-ckb/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "ES2015",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "NodeNext",
"lib": ["dom", "esnext"],
"module": "ES2015",
"composite": false,
"resolveJsonModule": true,
"strictNullChecks": true,
Expand All @@ -14,7 +13,7 @@
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"moduleResolution": "NodeNext",
"moduleResolution": "Bundler",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
Expand Down
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
],
"scripts": {
"prepare": "husky",
"build": "turbo run build",
"test:packages": "turbo run test --filter=./packages/*",
"build:packages": "turbo run build --filter=./packages/*",
"dev:service": "turbo run dev --filter=./apps/service",
"lint:fix": "turbo run lint:fix",
"lint:packages": "turbo run lint --filter=./{packages,examples,tests}/*",
"build": "pnpm run --r --filter \"./{packages,apps,examples,tests}/**\" build",
"test:packages": "pnpm run --r --filter \"./packages/**\" test",
"build:packages": "pnpm run --r --filter \"./packages/**\" build",
"dev:service": "pnpm run --r --filter=./apps/service dev",
"lint": "eslint {packages,apps,examples,tests}/**/*.ts && prettier --check '{packages,apps,examples,tests}/**/*.ts'",
"lint:fix": "eslint --fix {packages,apps,examples,tests}/**/*.ts",
"format": "prettier --write '{packages,apps,examples,tests}/**/*.{js,jsx,ts,tsx}'",
"clean": "turbo run clean",
"clean:packages": "turbo run clean --filter=./packages/*",
"clean:dependencies": "pnpm clean:sub-dependencies && rimraf node_modules",
"clean:sub-dependencies": "rimraf packages/**/node_modules apps/**/node_modules",
"release:packages": "pnpm run build:packages && changeset publish"
Expand All @@ -23,16 +21,17 @@
"@changesets/cli": "^2.27.1",
"@changesets/get-github-info": "^0.6.0",
"@changesets/types": "^6.0.0",
"@types/lodash": "^4.17.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^8.56.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
"turbo": "^1.13.0",
"typescript": "^5.4.3"
"tsx": "4.16.3",
"tsup": "^8.1.0",
"typescript": "^5.4.3",
"vitest": "1.6.0"
},
"lint-staged": {
"{packages,apps,examples,tests}/**/*.{js,jsx,ts,tsx}": [
Expand Down
34 changes: 21 additions & 13 deletions packages/btc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@
"version": "0.5.0",
"scripts": {
"test": "vitest",
"build": "tsc -p tsconfig.build.json",
"build": "tsup",
"lint": "tsc && eslint '{src,tests}/**/*.{js,ts}' && prettier --check '{src,tests}/**/*.{js,ts}'",
"lint:fix": "tsc && eslint --fix '{src,tests}/**/*.{js,ts}' && prettier --write '{src,tests}/**/*.{js,ts}'",
"clean": "pnpm run clean:cache & pnpm run clean:build",
"clean:build": "rimraf lib && pnpm run clean:buildinfo",
"clean:buildinfo": "rimraf tsconfig.*tsbuildinfo",
"clean:cache": "rimraf .turbo"
"lint:fix": "tsc && eslint --fix '{src,tests}/**/*.{js,ts}' && prettier --write '{src,tests}/**/*.{js,ts}'"
},
"sideEffects": false,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.js",
"default": "./dist/index.js"
}
},
"./package.json": "./package.json"
},
"main": "lib",
"files": [
"lib"
"src",
"dist"
],
"dependencies": {
"@bitcoinerlab/secp256k1": "^1.1.1",
"@ckb-lumos/codec": "0.22.2",
"@nervosnetwork/ckb-types": "0.109.1",
"@nervosnetwork/ckb-types": "0.109.2",
"@rgbpp-sdk/ckb": "workspace:^",
"@rgbpp-sdk/service": "workspace:^",
"bip32": "^4.0.0",
Expand All @@ -27,10 +39,6 @@
"lodash": "^4.17.21",
"p-limit": "^3.1.0"
},
"devDependencies": {
"@types/lodash": "^4.17.0",
"vitest": "^1.4.0"
},
"publishConfig": {
"access": "public"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/btc/src/bitcoin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ECPairFactory, { ECPairInterface } from 'ecpair';
import ecc from '@bitcoinerlab/secp256k1';
import * as bitcoin from 'bitcoinjs-lib';
import { isTaprootInput } from 'bitcoinjs-lib/src/psbt/bip371';
import { isP2TR, isP2WPKH, isP2PKH } from 'bitcoinjs-lib/src/psbt/psbtutils';
import { ECPairFactory, ECPairInterface } from 'ecpair';
import { isTaprootInput } from 'bitcoinjs-lib/src/psbt/bip371.js';
import { isP2TR, isP2WPKH, isP2PKH } from 'bitcoinjs-lib/src/psbt/psbtutils.js';

bitcoin.initEccLib(ecc);

Expand Down
2 changes: 1 addition & 1 deletion packages/btc/src/preset/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cloneDeep from 'lodash/cloneDeep';
import cloneDeep from 'lodash/cloneDeep.js';
import { bitcoin } from '../bitcoin';
import { ErrorCodes, TxBuildError } from '../error';
import { NetworkType, RgbppBtcConfig } from './types';
Expand Down
Loading

1 comment on commit aac6b82

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New snapshot version of the rgbpp-sdk packages have been released:

Name Version
@rgbpp-sdk/btc 0.0.0-snap-20240805011316
@rgbpp-sdk/ckb 0.0.0-snap-20240805011316
rgbpp 0.0.0-snap-20240805011316
@rgbpp-sdk/service 0.0.0-snap-20240805011316

Please sign in to comment.