-
Notifications
You must be signed in to change notification settings - Fork 36
For RGB++ features preview purpose #332
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
Open
fghdotio
wants to merge
95
commits into
ckb-devrel:rgbpp-sdk
Choose a base branch
from
fghdotio:feat/rgbpp-iteration
base: rgbpp-sdk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
65f3506
chore: publish canary by pr comment
Hanssen0 705b27d
fix(core): avoid circular dependency
Hanssen0 b8a07c1
feat(core): `Signer.findCellsOnChain`
Hanssen0 7cd7696
feat(core): auto capacity completion
Hanssen0 e900c59
perf(core): optimize Transaction.completeFee
Hanssen0 4393803
feat(udt): `Udt.complete*` methods
Hanssen0 1c51782
docs: CONTRIBUTING.md
Hanssen0 2bfc53e
docs: pull request template
Hanssen0 eb1fdb3
fix(playground): some messages are not displyed
Hanssen0 b4f64ce
feat(core): multiple scripts for `SignerCkbScriptReadonly`
Hanssen0 e496560
feat(core): add `CellAny`
Hanssen0 5530fa9
feat(core): `reduce` and `reduceAsync` for `Iterable`
Hanssen0 b90cd5b
feat(mol): add support for fixed-size Union (#174)
phroi 265af7d
fix: `prettier-vscode` doesn't work with `import`
Hanssen0 4675e6f
chore: move release branch from `master` to `release`
Hanssen0 5c24eb9
Merge branch 'release'
Hanssen0 698df9a
Merge branch 'releases/joy-id'
Hanssen0 638e5dc
fix(core)!: `getFeeRateStatistics` may returns `null` on devnet
Hanssen0 f547718
docs: fix images in README.md
Hanssen0 f82f9af
feat(core): default `Signer.prepareTransaction`
Hanssen0 d3695d1
Merge pull request #285 from ckb-devrel/release
Hanssen0 f52d761
Merge pull request #289 from ckb-devrel/release
Hanssen0 a789668
Merge pull request #300 from ckb-devrel/release
Hanssen0 99a2036
Revert "feat(udt): `Udt.complete*` methods"
Hanssen0 b96b7a6
Revert "feat: add RGB++ known scripts (RgbppLock, BtcTimeLock)"
Hanssen0 e2ce0a2
Merge branch 'release'
Hanssen0 f642cc5
feat(core): improve hex utils (#268)
phroi e413333
fix(core): Invalid Uint64 0x00: with redundant leading zeros.
Hanssen0 1070a7e
Merge branch `release` into `master`
Hanssen0 98e06ca
Merge branch `release` into `master`
Hanssen0 78f8588
Merge branch `release` into `master`
Hanssen0 3aa4425
chore: search manual proxy lock when signer isn't the proxy provider
ashuralyk d0af061
chore(release): bump packages version
github-actions[bot] 5d4ad4e
feat(app): signature textarea for signing
Hanssen0 792ecc0
feat(rgbpp): implement network-aware JWT authentication for BTC Asset…
fghdotio a25497f
feat(rgbpp): add BTC address balance query interface to `RgbppBtcWallet`
fghdotio fef3e24
feat(playground): add RGB++ UDT issuance support
fghdotio f9b52fb
feat(playground): add RGB++ UDT issuance example and comprehensive guide
fghdotio fce9a70
refactor(rgbpp): migrate from shell to core dependencies and fix imports
fghdotio 90b9290
fix(connector): resolve ESLint no-misused-promises error in setTimeou…
fghdotio 28dfab1
feat(shell): integrate RGB++ protocol into shell package
fghdotio 470b473
refactor(playground): update RGB++ integration
fghdotio 3358203
chore: update pnpm-lock.yaml after rgbpp dependency changes
fghdotio b7392d8
fix(playground): correct mainnet address prefix check in RGB++ examples
fghdotio 1480322
fix(rgbpp): fix typo
fghdotio ee04a44
fix(playground): update reference to CkbRgbppUnlockSigner
fghdotio 0375cc3
refactor(playground): remove direct rgbpp dependency from execution e…
fghdotio ce15f60
fix(demo): correct CkbRgbppUnlockSigner class name spelling
fghdotio 2221d9c
fix(playground): correct typo in RGB++ wallet creation error message
fghdotio ec1f097
fix(demo): resolve variable name shadowing in RGB++ UDT issuance
fghdotio 83de9e3
refactor(rgbpp): enhance prepareUtxoSeal with robust retry mechanism
fghdotio 9129f44
feat(btc): add SignPsbtOptions support for PSBT signing
fghdotio 685b44c
feat(rgbpp): add SignPsbtOptions support and refactor to composition …
fghdotio 9e97f88
refactor(btc): standardize PSBT API and improve type safety
fghdotio d335656
fix(rgbpp): resolve build errors and variable naming consistency
fghdotio c114284
fix(rgbpp): use duck typing instead of constructor.name for wallet de…
fghdotio 7be409a
feat(rgbpp): add Xverse wallet support with automatic PSBT input dete…
fghdotio d03798e
refactor(xverse): extract psbt logic
fghdotio 3379252
refactor(psbt): add unified sign+push flow and combined-wallet support
fghdotio a926111
refactor(rgbpp): use signAndBroadcast
fghdotio eab4987
docs(playground): update supported wallets
fghdotio ea7e626
chore: bump version of react
Hanssen0 f458ad0
chore(release): bump packages version
github-actions[bot] ef72b27
Merge branch `release` into `master`
Hanssen0 ca5514c
feat(rgbpp): add PublicKeyProvider system for P2TR PSBT inputs
fghdotio 115e653
fix(rgbpp): add UTXO deduplication to prevent duplicate inputs
fghdotio 585781f
refactor: migrate script management to use ccc.KnownScript
fghdotio d775270
refactor(rgbpp): remove signet network support
fghdotio 9df1343
feat(rgbpp): add getRgbppScriptInfos method and fix async calls
fghdotio f179154
refactor(rgbpp): make transaction confirmation polling interval confi…
fghdotio a4b2ab5
refactor(rgbpp): refactor CkbRgbppUnlockSigner to use object paramete…
fghdotio c74aeca
Merge remote-tracking branch 'upstream/release' into feat/rgbpp-itera…
208fa66
feat(rgbpp): add linting and formatting support
15e8a28
refactor(rgbpp): refactor script management with provider pattern
1d98ace
feat(core): update RGB++ script configurations and remove Bitcoin Sig…
e50bb0e
feat(demo): add RGB++ xUDT transfer functionality
fghdotio 2a24c87
refactor(rgbpp): reorganize bitcoin module directory structure
fghdotio 88b6033
refactor(rgbpp): update import paths in rgbpp utils
fghdotio e89141d
fix(rgbpp): remove empty witness fields in CkbRgbppUnlockSigner
fghdotio 22f3d51
feat(joy-id): address info in identity
Hanssen0 ef882bd
feat(core): `Signer.fromSignature`
Hanssen0 b3b3914
refactor(rgbpp): improve UDT example functions flexibility
fghdotio 28c6673
fix(playground): remove `raw-loader` in `require.context` for turbopack
Hanssen0 6a3be47
fix: wrong capacity completion while deserializing transaction
Hanssen0 093fc3e
chore(release): bump packages version
github-actions[bot] f048ad8
Merge remote-tracking branch 'origin/release' into 'master'
Hanssen0 b4aa99f
fix(core): circular dependency due to btc.verify
Hanssen0 68b7147
chore(release): bump packages version
github-actions[bot] 66ae81b
feat(core): Add `bytesLen` and `bytesLenUnsafe` utilities (#353)
phroi a96dec6
chore(core): bump nostr-lock mainnet cell deps
RetricSu 3d11c1e
chore(release): bump packages version
github-actions[bot] 99f815a
refactor(psbt): standardize btc signer interface and update dependencies
fghdotio a8d5cf3
feat(rgbpp): add playground RGB++ UDT issuance example, normalize BTC…
fghdotio 50d657b
Merge remote-tracking branch 'origin/release'
Hanssen0 0113acc
Merge remote-tracking branch 'upstream/master' into feat/rgbpp-iteration
fghdotio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # `@ckb-ccc/rgbpp` Development Guide | ||
|
|
||
| ## Overview | ||
|
|
||
| This guide demonstrates how to use the `@ckb-ccc/rgbpp` package to build RGB++ applications on Bitcoin and CKB. We'll walk through a complete RGB++ [xUDT](https://docs.nervos.org/docs/tech-explanation/xudt) issuance example to showcase the key concepts and development patterns on the interactive playground environment. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before running this example, ensure you have: | ||
|
|
||
| 1. **Supported Wallet**: UniSat, JoyID | ||
| 2. **Testnet Environment**: Currently only Bitcoin Testnet3 and CKB Testnet are supported on the playground environment | ||
| 3. **Test Funds**: | ||
| - Bitcoin Testnet3 funds from [Bitcoin Faucet](https://bitcoinfaucet.uo1.net/) | ||
| - CKB Testnet funds from [Nervos Faucet](https://faucet.nervos.org/) | ||
|
|
||
| Basic understanding of the RGB++ protocol is also desired. Learn more at [RGB++ Protocol](https://rgbpp.com/). | ||
|
|
||
| ## RGB++ xUDT Issuance Example | ||
|
|
||
| Let's walk through a complete RGB++ xUDT issuance example using `@ckb-ccc/rgbpp`: | ||
|
|
||
| ### Step 1: Basic Setup | ||
|
|
||
| Environment validation and network configuration: | ||
|
|
||
| ```typescript | ||
| // Basic wallet and network validation | ||
| if (!signer || !(signer instanceof ccc.SignerBtc)) { | ||
| throw new Error("Wallet not supported"); | ||
| } | ||
| if (client.addressPrefix !== "ckt") { | ||
| throw new Error("Only Testnet is supported for now"); | ||
| } | ||
|
|
||
| // Initialize RGB++ network configuration | ||
| const networkConfig = ccc.rgbpp.buildNetworkConfig( | ||
| ccc.rgbpp.PredefinedNetwork.BitcoinTestnet3, | ||
| { cellDeps: { /* ... */ } } | ||
| ); | ||
| ``` | ||
|
|
||
| `buildNetworkConfig` sets up the essential RGB++ network configuration with proper cell dependencies for isomorphic binding, among other configurations. | ||
|
|
||
| ### Step 2: RGB++ Wallet and Client Setup | ||
|
|
||
| ```typescript | ||
| const btcRgbppSigner = await ccc.rgbpp.createBrowserRgbppBtcWallet( | ||
| signer, | ||
| networkConfig, | ||
| { | ||
| url: "https://api-testnet.rgbpp.com", | ||
| isMainnet: signer.client.addressPrefix === "ckt", | ||
| }, | ||
| ); | ||
|
|
||
| const rgbppUdtClient = new ccc.rgbpp.RgbppUdtClient(networkConfig, signer.client); | ||
| const ckbRgbppUnlockSinger = new ccc.rgbpp.CkbRgbppUnlockSinger(...); | ||
| ``` | ||
|
|
||
| `https://api-testnet.rgbpp.com` here is the testnet btc-assets-api URL. It's a service that retrieves BTC/RGB++ information/assets and processes transactions with these assets. It serves as the critical infrastructure component that connects Bitcoin and CKB networks for RGB++ operations. | ||
|
|
||
| **Key Components**: | ||
| - `createBrowserRgbppBtcWallet`: Creates RGB++ Bitcoin wallet for cross-chain operations | ||
| - `RgbppUdtClient`: High-level APIs for xUDT operations | ||
| - `CkbRgbppUnlockSinger`: Handles RGB++ lock script unlock logic | ||
|
|
||
| ### Step 3: UTXO Seal and Issuance Cell | ||
|
|
||
| ```typescript | ||
| const utxoSeal = await btcRgbppSigner.prepareUtxoSeal(); | ||
|
|
||
| const rgbppIssuanceCells = await rgbppUdtClient.createRgbppUdtIssuanceCells( | ||
| signer, | ||
| utxoSeal, | ||
| ); | ||
| ``` | ||
|
|
||
| The `prepareUtxoSeal` method creates the foundation for **isomorphic binding** - a one-to-one mapping between Bitcoin UTXOs and CKB Cells. This UTXO becomes cryptographically "sealed" to the CKB Cell containing xUDT data. | ||
|
|
||
| `rgbppIssuanceCells` is a CKB cell with its lock script set to the RGB++ lock script, using the UTXO as its argument. This configuration represents the user's intent to issue a RGB++ xUDT token, which will only be fulfilled after the initial UTXO is spent. | ||
|
|
||
| ### Step 4: Partial CKB Transaction and RGB++ Bitcoin Transaction | ||
|
|
||
| ```typescript | ||
| const ckbPartialTx = await rgbppUdtClient.issuanceCkbPartialTx({ | ||
| token: { | ||
| name: "Just UDT", | ||
| symbol: "jUDT", | ||
| decimal: 8, | ||
| }, | ||
| amount: 2100_0000n, | ||
| rgbppLiveCells: rgbppIssuanceCells, | ||
| udtScriptInfo: {/* ... */}, | ||
| }); | ||
|
|
||
| const { psbt, indexedCkbPartialTx } = await btcRgbppSigner.buildPsbt({ | ||
| ckbPartialTx, | ||
| ckbClient: signer.client, | ||
| rgbppUdtClient, | ||
| btcChangeAddress: btcAddress, | ||
| receiverBtcAddresses: [btcAddress], | ||
| }); | ||
|
|
||
| const btcTxId = await btcRgbppSigner.signAndBroadcast(psbt); | ||
| ``` | ||
|
|
||
| A partial CKB transaction is constructed using the CKB cell and xUDT script information, initially containing a placeholder for the corresponding Bitcoin transaction ID. Based on this, the commitment is calculated and the BTC transaction is assembled, which is then submitted to the network. | ||
|
|
||
| ### Step 5: Final RGB++ CKB Transaction | ||
|
|
||
| ```typescript | ||
| const ckbPartialTxInjected = await rgbppUdtClient.injectTxIdToRgbppCkbTx( | ||
| indexedCkbPartialTx, | ||
| btcTxId, | ||
| ); | ||
|
|
||
| const rgbppSignedCkbTx = await ckbRgbppUnlockSinger.signTransaction(ckbPartialTxInjected); | ||
| await rgbppSignedCkbTx.completeFeeBy(signer); | ||
| const ckbFinalTx = await signer.signTransaction(rgbppSignedCkbTx); | ||
| const txHash = await signer.client.sendTransaction(ckbFinalTx); | ||
| ``` | ||
|
|
||
| In `ckbRgbppUnlockSinger.signTransaction`, the BTC transaction's confirmation status is periodically checked through the SPV service. Upon confirmation, we acquire the new single-use seal which represents ownership of the issued RGB++ xUDT token. The transaction ID of this UTXO is used to replace the placeholder value in the RGB++ lock script, enabling the assembly of the final CKB transaction. | ||
|
|
||
| The final CKB transaction is then submitted to the network, completing the token issuance process. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,4 +47,4 @@ | |
| "tailwindcss": "^4.1.12" | ||
| }, | ||
| "packageManager": "pnpm@10.8.1" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,128 @@ await render(tx); | |
| await tx.completeFeeBy(signer, 1000); | ||
| await render(tx); | ||
| `; | ||
|
|
||
| export const RGBPP_UDT_ISSUANCE = `import { ccc } from "@ckb-ccc/ccc"; | ||
| import { render, signer, client } from "@ckb-ccc/playground"; | ||
|
|
||
| // ensure supported wallet is connected | ||
| if (!signer || !(signer instanceof ccc.SignerBtc)) { | ||
| throw new Error("Wallet not supported"); | ||
| } | ||
|
|
||
| // only support Testnet for now | ||
| if (client.addressPrefix !== "ckt") { | ||
| throw new Error("Only Testnet is supported for now"); | ||
| } | ||
|
|
||
| const btcAddress = await signer.getBtcAccount(); | ||
|
|
||
| // initialize RGB++ env | ||
| const networkConfig = ccc.rgbpp.buildNetworkConfig( | ||
| ccc.rgbpp.PredefinedNetwork.BitcoinTestnet3, | ||
| // TODO: remove the following 2 configs after updating RGB++ cell deps in ccc | ||
| { | ||
| cellDeps: { | ||
| [ccc.rgbpp.PredefinedScriptName.RgbppLock]: ccc.CellDep.from({ | ||
| outPoint: { | ||
| txHash: | ||
| "0x0d1567da0979f78b297d5311442669fbd1bd853c8be324c5ab6da41e7a1ed6e5", | ||
| index: "0x0", | ||
| }, | ||
| depType: "code", | ||
| }), | ||
| [ccc.rgbpp.PredefinedScriptName.BtcTimeLock]: ccc.CellDep.from({ | ||
| outPoint: { | ||
| txHash: | ||
| "0x8fb747ff0416a43e135c583b028f98c7b81d3770551b196eb7ba1062dd9acc94", | ||
| index: "0x0", | ||
| }, | ||
| depType: "code", | ||
| }), | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| const btcRgbppSigner = await ccc.rgbpp.createBrowserRgbppBtcWallet( | ||
| signer, | ||
| networkConfig, | ||
| { | ||
| url: "https://api-testnet.rgbpp.com", | ||
| isMainnet: signer.client.addressPrefix === "ckt", | ||
|
fghdotio marked this conversation as resolved.
Outdated
|
||
| }, | ||
| ); | ||
| if (!btcRgbppSigner) { | ||
| throw new Error("Failed to create browser RGBPP BTC singer"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| const rgbppUdtClient = new ccc.rgbpp.RgbppUdtClient(networkConfig, signer.client); | ||
| const ckbRgbppUnlockSinger = new ccc.rgbpp.CkbRgbppUnlockSinger( | ||
| signer.client, | ||
| await btcRgbppSigner.getAddress(), | ||
| btcRgbppSigner, | ||
| btcRgbppSigner, | ||
| rgbppUdtClient.getRgbppScriptInfos(), | ||
| ); | ||
|
|
||
| const utxos = await btcRgbppSigner.getUtxos(await btcRgbppSigner.getAddress()); | ||
| if (!utxos.length) { | ||
| throw new Error( | ||
| "No Testnet3 BTC available. Go to a Testnet3 faucet (https://bitcoinfaucet.uo1.net/) to get some.", | ||
| ); | ||
| } | ||
|
|
||
| const ckbBalance = await signer.getBalance(); | ||
| if (ckbBalance === BigInt(0)) { | ||
| throw new Error( | ||
| "No Testnet CKB available. Go to https://faucet.nervos.org/ to get some.", | ||
| ); | ||
| } | ||
| const utxoSeal = await btcRgbppSigner.prepareUtxoSeal({ feeRate: 7 }); | ||
|
|
||
| const rgbppIssuanceCells = await rgbppUdtClient.createRgbppUdtIssuanceCells( | ||
| signer, | ||
| utxoSeal, | ||
| ); | ||
| const ckbPartialTx = await rgbppUdtClient.issuanceCkbPartialTx({ | ||
| token: { | ||
| name: "Just UDT", | ||
| symbol: "jUDT", | ||
| decimal: 8, | ||
| }, | ||
| amount: 2100_0000n, | ||
| rgbppLiveCells: rgbppIssuanceCells, | ||
| udtScriptInfo: { | ||
| name: ccc.KnownScript.XUdt, | ||
| script: await ccc.Script.fromKnownScript(client, ccc.KnownScript.XUdt, ""), | ||
| cellDep: (await client.getKnownScript(ccc.KnownScript.XUdt)).cellDeps[0] | ||
| .cellDep, | ||
| }, | ||
| }); | ||
|
|
||
| const { psbt, indexedCkbPartialTx } = await btcRgbppSigner.buildPsbt({ | ||
| ckbPartialTx, | ||
| ckbClient: signer.client, | ||
| rgbppUdtClient, | ||
| btcChangeAddress: btcAddress, | ||
| receiverBtcAddresses: [btcAddress], | ||
| feeRate: 7, | ||
| }); | ||
| await render("Partial RGB++ CKB tx", indexedCkbPartialTx); | ||
|
|
||
| const btcTxId = await btcRgbppSigner.signAndBroadcast(psbt); | ||
| await render("RGB++ BTC tx id", btcTxId); | ||
|
|
||
| const ckbPartialTxInjected = await rgbppUdtClient.injectTxIdToRgbppCkbTx( | ||
| indexedCkbPartialTx, | ||
| btcTxId, | ||
| ); | ||
| const rgbppSignedCkbTx = | ||
| await ckbRgbppUnlockSinger.signTransaction(ckbPartialTxInjected); | ||
| await rgbppSignedCkbTx.completeFeeBy(signer); | ||
| const ckbFinalTx = await signer.signTransaction(rgbppSignedCkbTx); | ||
| await render("Final RGB++ CKB tx", ckbFinalTx); | ||
|
|
||
| const txHash = await signer.client.sendTransaction(ckbFinalTx); | ||
| await ckbRgbppUnlockSinger.client.waitTransaction(txHash); | ||
| await render("RGB++ CKB tx", txHash); | ||
| `; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.