Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit aac6b82

Browse files
authored
Merge pull request #246 from ckb-cell/ref/support-esm
refactor(rgbpp-sdk): Support ESM package
2 parents 2cf54a0 + a70fee4 commit aac6b82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1080
-584
lines changed

.changeset/old-poems-guess.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@rgbpp-sdk/service": minor
3+
"rgbpp": minor
4+
"@rgbpp-sdk/btc": minor
5+
"@rgbpp-sdk/ckb": minor
6+
---
7+
8+
feat: Export ESM packages

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"browser": true,
44
"es2021": true
55
},
6+
"ignorePatterns": ["dist/"],
67
"extends": [
78
"eslint:recommended",
89
"plugin:@typescript-eslint/recommended"

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: pnpm run build:packages
4848

4949
- name: Lint packages
50-
run: pnpm run lint:packages
50+
run: pnpm run lint
5151

5252
- name: Run tests for packages
5353
run: pnpm run test:packages

apps/service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"convert-keys": "^1.3.4",
2929
"json-rpc-2.0": "^1.7.0",
3030
"reflect-metadata": "^0.2.0",
31-
"rgbpp": "workspace:*",
31+
"rgbpp": "^0.5.0",
3232
"rxjs": "^7.8.1",
3333
"zod": "^3.23.8"
3434
},

apps/service/src/json-rpc/json-rpc.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class JsonRpcServer {
5050
}
5151
const name = metadata.name
5252
? `${metadata.name}.${methodMetadata.name ?? methodName}`
53-
: methodMetadata.name ?? methodName;
53+
: (methodMetadata.name ?? methodName);
5454
const handler = (params: unknown) => {
5555
const instanceRef = this.moduleRef.get(instance.constructor, { strict: false });
5656
return instanceRef[methodName](params);

examples/rgbpp/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ VITE_BTC_SERVICE_ORIGIN=https://btc-test.app
7979
8080
```shell
8181
# Create a CKB empty rgbpp lock cell to launch RGB++ xUDT assets later
82-
npx ts-node xudt/launch/1-prepare-launch.ts
82+
npx tsx xudt/launch/1-prepare-launch.ts
8383
```
8484
#### 2. Launch RGB++ xUDT on BTC
8585

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

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

105105
### RGB++ xUDT Transfer and Leap
106106

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

109109
```shell
110-
npx ts-node xudt/1-ckb-leap-btc.ts
110+
npx tsx xudt/1-ckb-leap-btc.ts
111111
```
112112

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

115115
```shell
116-
npx ts-node xudt/2-btc-transfer.ts
116+
npx tsx xudt/2-btc-transfer.ts
117117
```
118118

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

121121
```shell
122-
npx ts-node xudt/3-btc-leap-ckb.ts
122+
npx tsx xudt/3-btc-leap-ckb.ts
123123
```
124124

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

133133
```shell
134-
npx ts-node xudt/4-unlock-btc-time.ts
134+
npx tsx xudt/4-unlock-btc-time.ts
135135
```
136136

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

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

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

167167
### Transfer and Leap Spore
168168

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

171171
```shell
172-
npx ts-node spore/4-transfer-spore.ts
172+
npx tsx spore/4-transfer-spore.ts
173173
```
174174

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

177177
```shell
178-
npx ts-node spore/5-leap-spore-to-ckb.ts
178+
npx tsx spore/5-leap-spore-to-ckb.ts
179179
```
180180

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

189189
```shell
190-
npx ts-node spore/6-unlock-btc-time-cell.ts
190+
npx tsx spore/6-unlock-btc-time-cell.ts
191191
```
192192

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

195195
```shell
196-
npx ts-node spore/7-leap-spore-to-btc.ts
196+
npx tsx spore/7-leap-spore-to-btc.ts
197197
```
198198

199199
## FAQ

examples/rgbpp/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
"lint:fix": "tsc && eslint --fix --ext .js,.ts . && prettier --write '**/*.{js,ts}'"
1111
},
1212
"dependencies": {
13-
"@nervosnetwork/ckb-sdk-utils": "0.109.1",
13+
"@nervosnetwork/ckb-sdk-utils": "0.109.2",
1414
"rgbpp": "workspace:*"
1515
},
1616
"devDependencies": {
17-
"@types/node": "^20.11.28",
18-
"typescript": "^5.4.2",
1917
"dotenv": "^16.4.5",
2018
"@types/dotenv": "^8.2.0"
2119
}

examples/rgbpp/tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"compilerOptions": {
44
"target": "ES2015",
5-
"lib": ["dom", "dom.iterable", "esnext"],
6-
"module": "NodeNext",
5+
"lib": ["esnext"],
6+
"module": "ES2015",
77
"composite": false,
88
"resolveJsonModule": true,
99
"strictNullChecks": true,
@@ -14,7 +14,7 @@
1414
"forceConsistentCasingInFileNames": true,
1515
"inlineSources": false,
1616
"isolatedModules": true,
17-
"moduleResolution": "NodeNext",
17+
"moduleResolution": "Bundler",
1818
"noUnusedLocals": false,
1919
"noUnusedParameters": false,
2020
"preserveWatchOutput": true,

examples/xudt-on-ckb/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ CKB_INDEXER_URL=https://testnet.ckb.dev/indexer
3030
### Issue xUDT on CKB
3131

3232
```shell
33-
npx ts-node 1-issue-xudt.ts
33+
npx tsx 1-issue-xudt.ts
3434
```
3535

3636
### Mint/Transfer xUDT on CKB
3737

3838
You can use this command to mint or transfer xUDT assets
3939

4040
```shell
41-
npx ts-node 2-transfer-xudt.ts
41+
npx tsx 2-transfer-xudt.ts
4242
```

examples/xudt-on-ckb/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"lint:fix": "tsc && eslint --fix --ext .ts . && prettier --write '**/*.ts'"
1111
},
1212
"dependencies": {
13-
"@nervosnetwork/ckb-sdk-utils": "0.109.1",
14-
"rgbpp": "^0.3.0"
13+
"@nervosnetwork/ckb-sdk-utils": "0.109.2",
14+
"rgbpp": "workspace:*"
1515
},
1616
"devDependencies": {
1717
"dotenv": "^16.4.5",

examples/xudt-on-ckb/tsconfig.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
2-
"$schema": "https://json.schemastore.org/tsconfig",
32
"compilerOptions": {
43
"target": "ES2015",
5-
"lib": ["dom", "dom.iterable", "esnext"],
6-
"module": "NodeNext",
4+
"lib": ["dom", "esnext"],
5+
"module": "ES2015",
76
"composite": false,
87
"resolveJsonModule": true,
98
"strictNullChecks": true,
@@ -14,7 +13,7 @@
1413
"forceConsistentCasingInFileNames": true,
1514
"inlineSources": false,
1615
"isolatedModules": true,
17-
"moduleResolution": "NodeNext",
16+
"moduleResolution": "Bundler",
1817
"noUnusedLocals": false,
1918
"noUnusedParameters": false,
2019
"preserveWatchOutput": true,

package.json

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
],
77
"scripts": {
88
"prepare": "husky",
9-
"build": "turbo run build",
10-
"test:packages": "turbo run test --filter=./packages/*",
11-
"build:packages": "turbo run build --filter=./packages/*",
12-
"dev:service": "turbo run dev --filter=./apps/service",
13-
"lint:fix": "turbo run lint:fix",
14-
"lint:packages": "turbo run lint --filter=./{packages,examples,tests}/*",
9+
"build": "pnpm run --r --filter \"./{packages,apps,examples,tests}/**\" build",
10+
"test:packages": "pnpm run --r --filter \"./packages/**\" test",
11+
"build:packages": "pnpm run --r --filter \"./packages/**\" build",
12+
"dev:service": "pnpm run --r --filter=./apps/service dev",
13+
"lint": "eslint {packages,apps,examples,tests}/**/*.ts && prettier --check '{packages,apps,examples,tests}/**/*.ts'",
14+
"lint:fix": "eslint --fix {packages,apps,examples,tests}/**/*.ts",
1515
"format": "prettier --write '{packages,apps,examples,tests}/**/*.{js,jsx,ts,tsx}'",
16-
"clean": "turbo run clean",
17-
"clean:packages": "turbo run clean --filter=./packages/*",
1816
"clean:dependencies": "pnpm clean:sub-dependencies && rimraf node_modules",
1917
"clean:sub-dependencies": "rimraf packages/**/node_modules apps/**/node_modules",
2018
"release:packages": "pnpm run build:packages && changeset publish"
@@ -23,16 +21,17 @@
2321
"@changesets/cli": "^2.27.1",
2422
"@changesets/get-github-info": "^0.6.0",
2523
"@changesets/types": "^6.0.0",
24+
"@types/lodash": "^4.17.0",
2625
"@typescript-eslint/eslint-plugin": "^7.8.0",
2726
"@typescript-eslint/parser": "^7.8.0",
2827
"eslint": "^8.56.0",
2928
"husky": "^9.0.11",
3029
"lint-staged": "^15.2.2",
3130
"prettier": "^3.2.5",
32-
"rimraf": "^5.0.5",
33-
"ts-node": "^10.9.2",
34-
"turbo": "^1.13.0",
35-
"typescript": "^5.4.3"
31+
"tsx": "4.16.3",
32+
"tsup": "^8.1.0",
33+
"typescript": "^5.4.3",
34+
"vitest": "1.6.0"
3635
},
3736
"lint-staged": {
3837
"{packages,apps,examples,tests}/**/*.{js,jsx,ts,tsx}": [

packages/btc/package.json

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,34 @@
33
"version": "0.5.0",
44
"scripts": {
55
"test": "vitest",
6-
"build": "tsc -p tsconfig.build.json",
6+
"build": "tsup",
77
"lint": "tsc && eslint '{src,tests}/**/*.{js,ts}' && prettier --check '{src,tests}/**/*.{js,ts}'",
8-
"lint:fix": "tsc && eslint --fix '{src,tests}/**/*.{js,ts}' && prettier --write '{src,tests}/**/*.{js,ts}'",
9-
"clean": "pnpm run clean:cache & pnpm run clean:build",
10-
"clean:build": "rimraf lib && pnpm run clean:buildinfo",
11-
"clean:buildinfo": "rimraf tsconfig.*tsbuildinfo",
12-
"clean:cache": "rimraf .turbo"
8+
"lint:fix": "tsc && eslint --fix '{src,tests}/**/*.{js,ts}' && prettier --write '{src,tests}/**/*.{js,ts}'"
9+
},
10+
"sideEffects": false,
11+
"main": "./dist/index.js",
12+
"types": "./dist/index.d.ts",
13+
"exports": {
14+
".": {
15+
"import": {
16+
"types": "./dist/index.d.mts",
17+
"default": "./dist/index.mjs"
18+
},
19+
"require": {
20+
"types": "./dist/index.d.js",
21+
"default": "./dist/index.js"
22+
}
23+
},
24+
"./package.json": "./package.json"
1325
},
14-
"main": "lib",
1526
"files": [
16-
"lib"
27+
"src",
28+
"dist"
1729
],
1830
"dependencies": {
1931
"@bitcoinerlab/secp256k1": "^1.1.1",
2032
"@ckb-lumos/codec": "0.22.2",
21-
"@nervosnetwork/ckb-types": "0.109.1",
33+
"@nervosnetwork/ckb-types": "0.109.2",
2234
"@rgbpp-sdk/ckb": "workspace:^",
2335
"@rgbpp-sdk/service": "workspace:^",
2436
"bip32": "^4.0.0",
@@ -27,10 +39,6 @@
2739
"lodash": "^4.17.21",
2840
"p-limit": "^3.1.0"
2941
},
30-
"devDependencies": {
31-
"@types/lodash": "^4.17.0",
32-
"vitest": "^1.4.0"
33-
},
3442
"publishConfig": {
3543
"access": "public"
3644
}

packages/btc/src/bitcoin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import ECPairFactory, { ECPairInterface } from 'ecpair';
21
import ecc from '@bitcoinerlab/secp256k1';
32
import * as bitcoin from 'bitcoinjs-lib';
4-
import { isTaprootInput } from 'bitcoinjs-lib/src/psbt/bip371';
5-
import { isP2TR, isP2WPKH, isP2PKH } from 'bitcoinjs-lib/src/psbt/psbtutils';
3+
import { ECPairFactory, ECPairInterface } from 'ecpair';
4+
import { isTaprootInput } from 'bitcoinjs-lib/src/psbt/bip371.js';
5+
import { isP2TR, isP2WPKH, isP2PKH } from 'bitcoinjs-lib/src/psbt/psbtutils.js';
66

77
bitcoin.initEccLib(ecc);
88

packages/btc/src/preset/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cloneDeep from 'lodash/cloneDeep';
1+
import cloneDeep from 'lodash/cloneDeep.js';
22
import { bitcoin } from '../bitcoin';
33
import { ErrorCodes, TxBuildError } from '../error';
44
import { NetworkType, RgbppBtcConfig } from './types';

0 commit comments

Comments
 (0)