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

Commit 55f7f5e

Browse files
authored
Merge pull request #102 from ckb-cell/develop
Merge `develop` into `main` branch
2 parents dcf7a50 + 97d4367 commit 55f7f5e

File tree

108 files changed

+6139
-1233
lines changed

Some content is hidden

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

108 files changed

+6139
-1233
lines changed

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3-
"changelog": "@changesets/cli/changelog",
3+
"changelog": ["@changesets/changelog-github", { "repo": "ckb-cell/rgbpp-sdk" }],
44
"commit": false,
55
"fixed": [["@rgbpp-sdk/*"]],
66
"linked": [],

.eslintrc.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/recommended"
9+
],
10+
"parser": "@typescript-eslint/parser",
11+
"parserOptions": {
12+
"ecmaVersion": "latest",
13+
"sourceType": "module"
14+
},
15+
"plugins": [
16+
"@typescript-eslint"
17+
],
18+
"rules": {
19+
}
20+
}

.github/workflows/release.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ name: Release
44

55
on:
66
workflow_dispatch:
7+
push:
8+
branches:
9+
- main
710

811
concurrency: ${{ github.workflow }}-${{ github.ref }}
912

@@ -12,6 +15,7 @@ jobs:
1215
runs-on: ubuntu-latest
1316
permissions:
1417
contents: write
18+
pull-requests: write
1519
steps:
1620
- name: Checkout repo
1721
uses: actions/checkout@v4
@@ -43,11 +47,13 @@ jobs:
4347
- name: Install dependencies
4448
run: pnpm i
4549

46-
- name: Create Release Pull Request or Publish to npm
50+
- name: Create bump PR or release version
4751
id: changesets
4852
uses: changesets/action@v1
4953
with:
5054
publish: pnpm run release:packages
55+
title: "bump: assumable rgbpp-sdk version"
56+
commit: "bump: assumable rgbpp-sdk version"
5157
env:
5258
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5359
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/snapshot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
name: Release Snapshots
44

55
on:
6+
workflow_dispatch:
67
push:
78
branches:
89
- main
@@ -54,6 +55,8 @@ jobs:
5455

5556
- name: Version packages
5657
run: npx changeset version --snapshot snap
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5760

5861
- name: Publish to npm (ignore GitHub)
5962
id: changesets

.github/workflows/test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ jobs:
4545

4646
- name: Build packages
4747
run: pnpm run build:packages
48+
49+
- name: Lint packages
50+
run: pnpm run lint:packages
4851

4952
- name: Run tests for packages
5053
run: pnpm run test:packages

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@
3636
npm-debug.log*
3737
yarn-debug.log*
3838
yarn-error.log*
39+
40+
devbox.json
41+
devbox.lock
42+
.envrc

.husky/pre-commit

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
4-
npx lint-staged
1+
pnpm exec lint-staged

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,65 @@
11
# RGB++ SDK
22

3-
## Packages
3+
This repository offers utilities for Bitcoin and RGB++ asset integration.
4+
5+
### Packages in this repository
46

57
- [@rgbpp-sdk/btc](./packages/btc): Bitcoin part of the SDK
68
- [@rgbpp-sdk/ckb](./packages/ckb): Nervos CKB part of the SDK
9+
- [@rgbpp-sdk/service](./packages/service): A wrapped class to interact with `Bitcoin/RGB++ Assets Service`
10+
11+
## RGB++ Code Examples
12+
13+
- Find code examples at https://github.com/ckb-cell/rgbpp-sdk/tree/develop/examples/rgbpp
14+
15+
## Related CKB Scripts (Contracts)
16+
- [CKB Bitcoin SPV Type Script](https://github.com/ckb-cell/ckb-bitcoin-spv-contracts/tree/master/contracts/ckb-bitcoin-spv-type-lock): A [type script](https://docs.nervos.org/docs/basics/glossary#type-script) for [Bitcoin SPV](https://bitcoinwiki.org/wiki/simplified-payment-verification) clients which synchronize [Bitcoin](https://bitcoin.org) state into [CKB](https://github.com/nervosnetwork/ckb)
17+
18+
- [RgbppLockScript and BtcTimeLockScript](https://github.com/ckb-cell/rgbpp-sdk/blob/cf25ea014d4e0fc24723df8eea8bd61f59e1060a/packages/ckb/src/constants/index.ts#L11-L121)
19+
* design: https://github.com/ckb-cell/RGBPlusPlus-design/blob/main/docs/light-paper-en.md
20+
* testnet: https://pudge.explorer.nervos.org/scripts#RGB++
21+
* mainnet: https://explorer.nervos.org/scripts#RGB++
22+
23+
## RGB++ Asset Workflow Overview
24+
25+
1. **Creation of `rgbpp_ckb_tx_virtual` using [@rgbpp-sdk/ckb](https://github.com/ckb-cell/rgbpp-sdk/tree/develop/packages/ckb)**
26+
27+
- xUDT
28+
29+
1. **[BTC → BTC](https://github.com/ckb-cell/rgbpp-sdk/tree/develop/packages/ckb#rgb-xudt-transfer-on-btc)**
30+
2. **[BTC → CKB](https://github.com/ckb-cell/rgbpp-sdk/tree/develop/packages/ckb#rgb-xudt-leap-from-btc-to-ckb)**
31+
3. **[CKB → BTC](https://github.com/ckb-cell/rgbpp-sdk/tree/develop/packages/ckb#rgb-xudt-leap-from-ckb-to-btc)** *(isomorphic rgbpp_btc_tx is not required in this workflow)*
32+
33+
- Spore
34+
35+
1. **[BTC → BTC](https://github.com/ckb-cell/rgbpp-sdk/blob/develop/packages/ckb/README.md#rgb-spore-transfer-on-btc)**
36+
2. **[BTC → CKB](https://github.com/ckb-cell/rgbpp-sdk/blob/develop/packages/ckb/README.md#rgb-spore-leap-from-btc-to-ckb)**
37+
3. **[CKB → BTC](https://github.com/ckb-cell/rgbpp-sdk/blob/develop/packages/ckb/README.md#rgb-spore-leap-from-ckb-to-btc)** *(isomorphic rgbpp_btc_tx is not required in this workflow)*
38+
39+
> [!IMPORTANT]
40+
> It's recommended to save the `rgbpp_ckb_tx_virtual` locally in case you need it in the future.
41+
42+
2. **Creation of `rgbpp_btc_tx` through [@rgbpp-sdk/btc](https://github.com/ckb-cell/rgbpp-sdk/tree/develop/packages/btc)**
43+
1. construct isomorphic rgbpp_btc_tx based on rgbpp_ckb_tx_virtual and rgbpp commitment
44+
2. sign and broadcast rgbpp_btc_tx to obtain `rgbpp_btc_txid`
45+
46+
3. JoyID or dApp sends `rgbpp_btc_txid` and `rgbpp_ckb_tx_virtual` to RGB++ CKB transaction Queue (API Endpoint: `/rgbpp/v1/transaction/ckb-tx`)
47+
48+
4. `RGB++ CKB transaction Queue` will process the following things:
49+
1. **verify** the received requests
50+
2. continuously fetch request from the queue through a **cron job**
51+
3. check whether the **confirmations** of req.rgbpp_btc_txid is sufficient
52+
4. generate the **witnesses for RgbppLocks** in the rgbpp_ckb_tx_virtual
53+
5. add a **paymaster cell** into rgbpp_ckb_tx_virtual.inputs if the CKB capacity is insufficient
54+
1. need to **verify the existence of paymaster UTXO** in the rgbpp_btc_tx
55+
2. sign the paymaster cell and the entire transaction if needed
56+
6. **finalize** the rgbpp_ckb_tx_virtual to a rgbpp_ckb_tx
57+
7. **broadcast** rgbpp_ckb_tx and mark the job as completed upon tx-confirmation
58+
59+
### Notes
60+
61+
- The RGB++ CKB transaction Queue is designed to streamline the transaction workflow. Developers have the option to implement its features by themselves without limitation.
62+
763

864
## License
965

examples/rgbpp/README.md

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# RGB++ Examples
22

3-
**All examples are just to demonstrate the use of RGB++ SDK. SPV proof is not ready yet, so these examples do not involve the verification of SPV proof.**
3+
**All examples are just to demonstrate the use of RGB++ SDK.**
4+
5+
- Local and Queue directories: The examples for RGB++ UDT issuance, transfer, and leap
6+
- Spore directory: The examples for RGB++ spore creation, transfer and leap
7+
- xUDT directory: The examples for xUDT issuance, mint and transfer on CKB
48

59
## What you must know about BTC transaction id
610

@@ -25,70 +29,119 @@ But when you're searching for this transaction in [Bitcoin Core](https://bitcoin
2529
018025fb6989eed484774170eefa2bef1074b0c24537f992a64dbc138277bc4a
2630
```
2731

28-
## Examples with Queue service(Recommended)
32+
## xUDT on CKB Examples
33+
34+
### Issue xUDT on CKB
35+
36+
```shell
37+
npx ts-node examples/rgbpp/xudt/1-issue-xudt.ts
38+
```
39+
40+
### Mint/Transfer xUDT on CKB
2941

30-
### Mint XUDT
31-
As a simple example, Omiga protocol is reused for a quick demonstration of XUDT asset insurance.
32-
Developers have the option to utilize an existing XUDT (User-Defined Token) on CKB.
42+
You can use this command to mint or transfer xUDT assets
3343

3444
```shell
35-
npx ts-node examples/rgbpp/queue/1-mint-xudt.ts
45+
npx ts-node examples/rgbpp/xudt/2-transfer-xudt.ts
3646
```
3747

38-
### Jump XUDT from CKB to BTC
48+
## RGB++ xUDT Examples with Queue service(Recommended)
49+
50+
### Leap xUDT from CKB to BTC
3951

4052
```shell
41-
npx ts-node examples/rgbpp/queue/2-ckb-jump-btc.ts
53+
npx ts-node examples/rgbpp/queue/1-ckb-jump-btc.ts
4254
```
4355

44-
### Transfer RGB++ asset on BTC
56+
### Transfer RGB++ xUDT on BTC
4557

4658
```shell
47-
npx ts-node examples/rgbpp/queue/3-btc-transfer.ts
59+
npx ts-node examples/rgbpp/queue/2-btc-transfer.ts
4860
```
4961

50-
### Jump RGB++ asset from BTC to CKB
62+
### Leap RGB++ xUDT from BTC to CKB
5163

5264
```shell
53-
npx ts-node examples/rgbpp/queue/4-btc-jump-ckb.ts
65+
npx ts-node examples/rgbpp/queue/3-btc-jump-ckb.ts
5466
```
5567

56-
### Unlock BTC time cells on CKB
68+
### Unlock xUDT BTC time cells on CKB
5769

5870
A cron job in RGB++ Queue service will construct a transaction unlocking the mature BTC time cells to the their `target_ckb_address`.
5971

60-
## Local Examples
6172

62-
### Mint XUDT
63-
As a simple example, Omiga protocol is reused for a quick demonstration of XUDT asset insurance.
64-
Developers have the option to utilize an existing XUDT (User-Defined Token) on CKB.
73+
## RGB++ xUDT Local Examples
74+
75+
### Leap RGB++ xUDT from CKB to BTC
6576

6677
```shell
67-
npx ts-node examples/rgbpp/local/1-mint-xudt.ts
78+
npx ts-node examples/rgbpp/local/1-ckb-jump-btc.ts
6879
```
6980

70-
### Jump XUDT from CKB to BTC
81+
### Transfer RGB++ xUDT on BTC
7182

7283
```shell
73-
npx ts-node examples/rgbpp/local/2-ckb-jump-btc.ts
84+
npx ts-node examples/rgbpp/local/2-btc-transfer.ts
7485
```
7586

76-
### Transfer RGB++ asset on BTC
87+
### Leap RGB++ xUDT from BTC to CKB
7788

7889
```shell
79-
npx ts-node examples/rgbpp/local/3-btc-transfer.ts
90+
npx ts-node examples/rgbpp/local/3-btc-jump-ckb.ts
8091
```
8192

82-
### Jump RGB++ asset from BTC to CKB
93+
### Unlock xUDT BTC time cells on CKB
94+
95+
**Warning: Wait at least 6 BTC confirmation blocks to unlock the BTC time cells after 4-btc-jump-ckb.ts**
8396

8497
```shell
85-
npx ts-node examples/rgbpp/local/4-btc-jump-ckb.ts
98+
npx ts-node examples/rgbpp/local/4-spend-btc-time-cell.ts
8699
```
87100

88-
### Unlock BTC time cells on CKB
101+
## RGB++ Spore Examples
89102

90-
**Warning: Wait at least 6 BTC confirmation blocks to unlock the BTC time cells after 4-btc-jump-ckb.ts**
103+
**You can use RGB++ Queue service to complete spore transfer and leap, and the examples can be found in `examples/rgbpp/spore/queue`**
104+
105+
### Create RGB++ Cluster Cell
106+
107+
```shell
108+
npx ts-node examples/rgbpp/spore/1-prepare-cluster.ts
109+
110+
npx ts-node examples/rgbpp/spore/2-create-cluster.ts
111+
```
112+
113+
### Create RGB++ Spores with Cluster on BTC
114+
115+
```shell
116+
npx ts-node examples/rgbpp/spore/3-create-spores.ts
117+
```
118+
119+
### Transfer RGB++ Spore on BTC
120+
121+
```shell
122+
npx ts-node examples/rgbpp/spore/4-transfer-spore.ts
123+
```
124+
125+
### Leap RGB++ Spore from BTC to CKB
126+
127+
```shell
128+
npx ts-node examples/rgbpp/spore/5-leap-spore-to-ckb.ts
129+
```
130+
131+
### Unlock Spore BTC time cells on CKB
132+
133+
A cron job in RGB++ Queue service will construct a transaction unlocking the mature BTC time cells to the their `target_ckb_address`.
134+
135+
However, you can still manually unlock the spore btc time cell through the following command
136+
137+
**Warning: Wait at least 6 BTC confirmation blocks to unlock the BTC time cells after 5-leap-spore-to-ckb.ts**
138+
139+
```shell
140+
npx ts-node examples/rgbpp/spore/6-unlock-btc-time-cell.ts
141+
```
142+
143+
### Leap Spore from CKB to BTC
91144

92145
```shell
93-
npx ts-node examples/rgbpp/local/5-spend-btc-time-cell.ts
146+
npx ts-node examples/rgbpp/spore/7-leap-spore-to-btc.ts
94147
```

examples/rgbpp/local/2-ckb-jump-btc.ts renamed to examples/rgbpp/local/1-ckb-jump-btc.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { AddressPrefix, privateKeyToAddress, serializeScript } from '@nervosnetwork/ckb-sdk-utils';
2-
import { genCkbJumpBtcVirtualTx, Collector, getSecp256k1CellDep, buildRgbppLockArgs } from '@rgbpp-sdk/ckb';
2+
import {
3+
genCkbJumpBtcVirtualTx,
4+
Collector,
5+
getSecp256k1CellDep,
6+
buildRgbppLockArgs,
7+
getXudtTypeScript,
8+
} from '@rgbpp-sdk/ckb';
39

410
// CKB SECP256K1 private key
511
const CKB_TEST_PRIVATE_KEY = '0x0000000000000000000000000000000000000000000000000000000000000001';
@@ -11,15 +17,15 @@ const jumpFromCkbToBtc = async ({ outIndex, btcTxId }: { outIndex: number; btcTx
1117
});
1218
const isMainnet = false;
1319
const address = privateKeyToAddress(CKB_TEST_PRIVATE_KEY, {
14-
prefix: isMainnet ? AddressPrefix.Mainnet : AddressPrefix.Testnet,
15-
});
20+
prefix: isMainnet ? AddressPrefix.Mainnet : AddressPrefix.Testnet,
21+
});
1622
console.log('ckb address: ', address);
1723

1824
const toRgbppLockArgs = buildRgbppLockArgs(outIndex, btcTxId);
1925

26+
// Warning: Please replace with your real xUDT type script here
2027
const xudtType: CKBComponents.Script = {
21-
codeHash: '0x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb',
22-
hashType: 'type',
28+
...getXudtTypeScript(isMainnet),
2329
args: '0x1ba116c119d1cfd98a53e9d1a615cf2af2bb87d95515c9d217d367054cfc696b',
2430
};
2531

@@ -29,19 +35,18 @@ const jumpFromCkbToBtc = async ({ outIndex, btcTxId }: { outIndex: number; btcTx
2935
toRgbppLockArgs,
3036
xudtTypeBytes: serializeScript(xudtType),
3137
transferAmount: BigInt(800_0000_0000),
32-
witnessLockPlaceholderSize: 1000
3338
});
3439

3540
const emptyWitness = { lock: '', inputType: '', outputType: '' };
36-
let unsignedTx: CKBComponents.RawTransactionToSign = {
41+
const unsignedTx: CKBComponents.RawTransactionToSign = {
3742
...ckbRawTx,
38-
cellDeps: [...ckbRawTx.cellDeps, getSecp256k1CellDep(false)],
43+
cellDeps: [...ckbRawTx.cellDeps, getSecp256k1CellDep(isMainnet)],
3944
witnesses: [emptyWitness, ...ckbRawTx.witnesses.slice(1)],
4045
};
4146

4247
const signedTx = collector.getCkb().signTransaction(CKB_TEST_PRIVATE_KEY)(unsignedTx);
4348

44-
let txHash = await collector.getCkb().rpc.sendTransaction(signedTx, 'passthrough');
49+
const txHash = await collector.getCkb().rpc.sendTransaction(signedTx, 'passthrough');
4550
console.info(`Rgbpp asset has been jumped from CKB to BTC and tx hash is ${txHash}`);
4651
};
4752

@@ -50,4 +55,3 @@ jumpFromCkbToBtc({
5055
outIndex: 1,
5156
btcTxId: '4ff1855b64b309afa19a8b9be3d4da99dcb18b083b65d2d851662995c7d99e7a',
5257
});
53-

0 commit comments

Comments
 (0)