From 00b245cf5dd3c302bd13a587c636bd54ced8dd38 Mon Sep 17 00:00:00 2001 From: Alive24 Date: Wed, 11 Dec 2024 00:03:26 +0000 Subject: [PATCH] feat: SSRI & UDT SDK --- .changeset/large-points-obey.md | 7 + .changeset/swift-stingrays-remain.md | 7 + README.md | 4 +- packages/ccc/package.json | 2 +- packages/ccc/src/advancedBarrel.ts | 2 +- packages/ccc/src/barrel.ts | 2 +- packages/ccc/src/signersController.ts | 2 +- packages/core/src/ckb/transaction.ts | 9 +- packages/core/src/jsonRpc/requestor.ts | 5 +- packages/demo/package.json | 1 + .../connected/(tools)/TransferUdt/page.tsx | 121 +++++ .../connected/(tools)/TransferXUdt/page.tsx | 100 ---- packages/demo/src/app/connected/page.tsx | 2 +- packages/examples/src/transferUdt.ts | 39 +- packages/playground/src/app/execute/index.ts | 4 - packages/shell/.npmignore | 21 + packages/shell/.prettierignore | 13 + packages/shell/.prettierrc | 5 + packages/shell/README.md | 41 ++ packages/shell/eslint.config.mjs | 45 ++ .../misc/basedirs/dist.commonjs/package.json | 3 + .../shell/misc/basedirs/dist/package.json | 3 + packages/shell/package.json | 64 +++ packages/shell/src/advanced.ts | 2 + packages/shell/src/advancedBarrel.ts | 2 + packages/shell/src/barrel.ts | 4 + packages/shell/src/index.ts | 2 + packages/shell/tsconfig.base.json | 22 + packages/shell/tsconfig.commonjs.json | 8 + packages/shell/tsconfig.json | 8 + packages/shell/typedoc.json | 6 + packages/spore/package.json | 10 + packages/spore/src/advanced.ts | 6 +- packages/spore/src/advancedBarrel.ts | 4 + packages/spore/src/barrel.ts | 4 + packages/spore/src/index.ts | 6 +- packages/ssri/.npmignore | 21 + packages/ssri/.prettierignore | 13 + packages/ssri/.prettierrc | 5 + packages/ssri/README.md | 54 ++ packages/ssri/eslint.config.mjs | 45 ++ packages/ssri/jest.config.js | 5 + .../misc/basedirs/dist.commonjs/package.json | 3 + packages/ssri/misc/basedirs/dist/package.json | 3 + packages/ssri/package.json | 53 ++ packages/ssri/src/barrel.ts | 3 + packages/ssri/src/executor.ts | 184 +++++++ packages/ssri/src/index.ts | 1 + packages/ssri/src/trait.ts | 83 +++ packages/ssri/src/utils.ts | 5 + packages/ssri/tsconfig.base.json | 22 + packages/ssri/tsconfig.commonjs.json | 8 + packages/ssri/tsconfig.json | 8 + packages/ssri/typedoc.json | 6 + packages/udt/.npmignore | 21 + packages/udt/.prettierignore | 13 + packages/udt/.prettierrc | 5 + packages/udt/README.md | 101 ++++ packages/udt/eslint.config.mjs | 45 ++ packages/udt/jest.config.js | 5 + .../misc/basedirs/dist.commonjs/package.json | 3 + packages/udt/misc/basedirs/dist/package.json | 3 + packages/udt/package.json | 54 ++ packages/udt/src/barrel.ts | 2 + packages/udt/src/index.ts | 2 + packages/udt/src/udt/index.ts | 306 +++++++++++ packages/udt/src/udtPausable/index.ts | 136 +++++ packages/udt/tsconfig.base.json | 22 + packages/udt/tsconfig.commonjs.json | 8 + packages/udt/tsconfig.json | 8 + packages/udt/typedoc.json | 6 + pnpm-lock.yaml | 481 +++++++++++++++--- typedoc.json | 4 +- 73 files changed, 2123 insertions(+), 210 deletions(-) create mode 100644 .changeset/large-points-obey.md create mode 100644 .changeset/swift-stingrays-remain.md create mode 100644 packages/demo/src/app/connected/(tools)/TransferUdt/page.tsx delete mode 100644 packages/demo/src/app/connected/(tools)/TransferXUdt/page.tsx create mode 100644 packages/shell/.npmignore create mode 100644 packages/shell/.prettierignore create mode 100644 packages/shell/.prettierrc create mode 100644 packages/shell/README.md create mode 100644 packages/shell/eslint.config.mjs create mode 100644 packages/shell/misc/basedirs/dist.commonjs/package.json create mode 100644 packages/shell/misc/basedirs/dist/package.json create mode 100644 packages/shell/package.json create mode 100644 packages/shell/src/advanced.ts create mode 100644 packages/shell/src/advancedBarrel.ts create mode 100644 packages/shell/src/barrel.ts create mode 100644 packages/shell/src/index.ts create mode 100644 packages/shell/tsconfig.base.json create mode 100644 packages/shell/tsconfig.commonjs.json create mode 100644 packages/shell/tsconfig.json create mode 100644 packages/shell/typedoc.json create mode 100644 packages/spore/src/advancedBarrel.ts create mode 100644 packages/spore/src/barrel.ts create mode 100644 packages/ssri/.npmignore create mode 100644 packages/ssri/.prettierignore create mode 100644 packages/ssri/.prettierrc create mode 100644 packages/ssri/README.md create mode 100644 packages/ssri/eslint.config.mjs create mode 100644 packages/ssri/jest.config.js create mode 100644 packages/ssri/misc/basedirs/dist.commonjs/package.json create mode 100644 packages/ssri/misc/basedirs/dist/package.json create mode 100644 packages/ssri/package.json create mode 100644 packages/ssri/src/barrel.ts create mode 100644 packages/ssri/src/executor.ts create mode 100644 packages/ssri/src/index.ts create mode 100644 packages/ssri/src/trait.ts create mode 100644 packages/ssri/src/utils.ts create mode 100644 packages/ssri/tsconfig.base.json create mode 100644 packages/ssri/tsconfig.commonjs.json create mode 100644 packages/ssri/tsconfig.json create mode 100644 packages/ssri/typedoc.json create mode 100644 packages/udt/.npmignore create mode 100644 packages/udt/.prettierignore create mode 100644 packages/udt/.prettierrc create mode 100644 packages/udt/README.md create mode 100644 packages/udt/eslint.config.mjs create mode 100644 packages/udt/jest.config.js create mode 100644 packages/udt/misc/basedirs/dist.commonjs/package.json create mode 100644 packages/udt/misc/basedirs/dist/package.json create mode 100644 packages/udt/package.json create mode 100644 packages/udt/src/barrel.ts create mode 100644 packages/udt/src/index.ts create mode 100644 packages/udt/src/udt/index.ts create mode 100644 packages/udt/src/udtPausable/index.ts create mode 100644 packages/udt/tsconfig.base.json create mode 100644 packages/udt/tsconfig.commonjs.json create mode 100644 packages/udt/tsconfig.json create mode 100644 packages/udt/typedoc.json diff --git a/.changeset/large-points-obey.md b/.changeset/large-points-obey.md new file mode 100644 index 00000000..34ad023f --- /dev/null +++ b/.changeset/large-points-obey.md @@ -0,0 +1,7 @@ +--- +"@ckb-ccc/spore": minor +"@ckb-ccc/shell": minor +"@ckb-ccc/ccc": minor +--- + +feat: export backend packages in @ckb-ccc/shell diff --git a/.changeset/swift-stingrays-remain.md b/.changeset/swift-stingrays-remain.md new file mode 100644 index 00000000..eaf41e8e --- /dev/null +++ b/.changeset/swift-stingrays-remain.md @@ -0,0 +1,7 @@ +--- +"@ckb-ccc/core": minor +"@ckb-ccc/ssri": minor +"@ckb-ccc/udt": minor +--- + +feat: SSRI & UDT SDK diff --git a/README.md b/README.md index 84b7afe3..e209b7e4 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ For non-developers, you can [try CCC's app now here](https://app.ckbccc.com/) ([ - [Sign and verify any message.]() ([Playground](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/sign.ts)) - [Transfer native CKB token.]() ([Playground](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/transfer.ts)) -- [Transfer xUDT token.]() ([Playground](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/transferUdt.ts)) +- [Transfer UDT token.]() ([Playground](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/transferUdt.ts)) - See [Misc: Single-Use-Seals](https://talk.nervos.org/t/en-cn-misc-single-use-seals/8279) to learn how token issuing works in the cell model. - [Issue xUDT token with the Single-Use Lock.]() - [Issue xUDT token controlled by a Type ID cell.]() @@ -131,7 +131,7 @@ Follow the prompts to select your preferred framework template and start buildin We design CCC for both front-end and back-end developers. You need only one package to fulfil all your needs: -- [NodeJS](https://www.npmjs.com/package/@ckb-ccc/core): `npm install @ckb-ccc/core` +- [NodeJS](https://www.npmjs.com/package/@ckb-ccc/shell): `npm install @ckb-ccc/shell` - [Custom UI](https://www.npmjs.com/package/@ckb-ccc/ccc): `npm install @ckb-ccc/ccc` - [Web Component](https://www.npmjs.com/package/@ckb-ccc/connector): `npm install @ckb-ccc/connector` - [React](https://www.npmjs.com/package/@ckb-ccc/connector-react) ([Docs](https://docs.ckbccc.com/modules/_ckb_ccc_connector_react.html)): `npm install @ckb-ccc/connector-react` diff --git a/packages/ccc/package.json b/packages/ccc/package.json index bf27f49f..41cdef12 100644 --- a/packages/ccc/package.json +++ b/packages/ccc/package.json @@ -56,7 +56,7 @@ "access": "public" }, "dependencies": { - "@ckb-ccc/core": "workspace:*", + "@ckb-ccc/shell": "workspace:*", "@ckb-ccc/eip6963": "workspace:*", "@ckb-ccc/joy-id": "workspace:*", "@ckb-ccc/nip07": "workspace:*", diff --git a/packages/ccc/src/advancedBarrel.ts b/packages/ccc/src/advancedBarrel.ts index e971a818..cc735949 100644 --- a/packages/ccc/src/advancedBarrel.ts +++ b/packages/ccc/src/advancedBarrel.ts @@ -1,7 +1,7 @@ -export * from "@ckb-ccc/core/advancedBarrel"; export * from "@ckb-ccc/eip6963/advanced"; export * from "@ckb-ccc/nip07/advanced"; export * from "@ckb-ccc/okx/advanced"; +export * from "@ckb-ccc/shell/advancedBarrel"; export * from "@ckb-ccc/uni-sat/advanced"; export * from "@ckb-ccc/utxo-global/advanced"; export * from "@ckb-ccc/xverse/advanced"; diff --git a/packages/ccc/src/barrel.ts b/packages/ccc/src/barrel.ts index 9720265f..8b46c112 100644 --- a/packages/ccc/src/barrel.ts +++ b/packages/ccc/src/barrel.ts @@ -1,9 +1,9 @@ -export * from "@ckb-ccc/core/barrel"; export * from "@ckb-ccc/eip6963"; export * from "@ckb-ccc/joy-id"; export * from "@ckb-ccc/nip07"; export * from "@ckb-ccc/okx"; export * from "@ckb-ccc/rei"; +export * from "@ckb-ccc/shell/barrel"; export * from "@ckb-ccc/uni-sat"; export * from "@ckb-ccc/utxo-global"; export * from "@ckb-ccc/xverse"; diff --git a/packages/ccc/src/signersController.ts b/packages/ccc/src/signersController.ts index 55171e33..05e58dea 100644 --- a/packages/ccc/src/signersController.ts +++ b/packages/ccc/src/signersController.ts @@ -1,9 +1,9 @@ -import { ccc } from "@ckb-ccc/core"; import { Eip6963 } from "@ckb-ccc/eip6963"; import { JoyId } from "@ckb-ccc/joy-id"; import { Nip07 } from "@ckb-ccc/nip07"; import { Okx } from "@ckb-ccc/okx"; import { Rei } from "@ckb-ccc/rei"; +import { ccc } from "@ckb-ccc/shell"; import { UniSat } from "@ckb-ccc/uni-sat"; import { UtxoGlobal } from "@ckb-ccc/utxo-global"; import { Xverse } from "@ckb-ccc/xverse"; diff --git a/packages/core/src/ckb/transaction.ts b/packages/core/src/ckb/transaction.ts index 68f2c13c..9926382a 100644 --- a/packages/core/src/ckb/transaction.ts +++ b/packages/core/src/ckb/transaction.ts @@ -1487,8 +1487,13 @@ export class Transaction extends mol.Entity.Base< return addedCount; } - async completeInputsByUdt(from: Signer, type: ScriptLike): Promise { - const exceptedBalance = this.getOutputsUdtBalance(type); + async completeInputsByUdt( + from: Signer, + type: ScriptLike, + balanceTweak?: NumLike, + ): Promise { + const exceptedBalance = + this.getOutputsUdtBalance(type) + numFrom(balanceTweak ?? 0); const inputsBalance = await this.getInputsUdtBalance(from.client, type); if (inputsBalance >= exceptedBalance) { return 0; diff --git a/packages/core/src/jsonRpc/requestor.ts b/packages/core/src/jsonRpc/requestor.ts index af7a2c37..bb12785e 100644 --- a/packages/core/src/jsonRpc/requestor.ts +++ b/packages/core/src/jsonRpc/requestor.ts @@ -102,7 +102,10 @@ export class RequestorJsonRpc { outTransformer, ); } catch (err: unknown) { - await this.onError?.(err); + if (!this.onError) { + throw err; + } + await this.onError(err); } } diff --git a/packages/demo/package.json b/packages/demo/package.json index ed50074f..6afbc559 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -24,6 +24,7 @@ "devDependencies": { "@ckb-ccc/connector-react": "workspace:*", "@ckb-ccc/lumos-patches": "workspace:*", + "@ckb-ccc/udt": "workspace:*", "@ckb-lumos/ckb-indexer": "^0.24.0-next.1", "@ckb-lumos/common-scripts": "^0.24.0-next.1", "@ckb-lumos/config-manager": "^0.24.0-next.1", diff --git a/packages/demo/src/app/connected/(tools)/TransferUdt/page.tsx b/packages/demo/src/app/connected/(tools)/TransferUdt/page.tsx new file mode 100644 index 00000000..69c052af --- /dev/null +++ b/packages/demo/src/app/connected/(tools)/TransferUdt/page.tsx @@ -0,0 +1,121 @@ +"use client"; + +import React, { useEffect, useState } from "react"; +import { TextInput } from "@/src/components/Input"; +import { Button } from "@/src/components/Button"; +import { ccc } from "@ckb-ccc/connector-react"; +import { Textarea } from "@/src/components/Textarea"; +import { useGetExplorerLink } from "@/src/utils"; +import { useApp } from "@/src/context"; +import { ButtonsPanel } from "@/src/components/ButtonsPanel"; + +export default function TransferUdt() { + const { client } = ccc.useCcc(); + const { signer, createSender } = useApp(); + const { log } = createSender("Transfer xUDT"); + + const { explorerTransaction } = useGetExplorerLink(); + + const [udtTxHash, setUdtTxHash] = useState(""); + const [udtIndex, setUdtIndex] = useState(""); + const [udtCodeHash, setUdtCodeHash] = useState(""); + const [udtHashType, setUdtHashType] = useState(""); + const [udtArgs, setUdtArgs] = useState(""); + const [transferTo, setTransferTo] = useState(""); + const [amount, setAmount] = useState(""); + + useEffect(() => { + (async () => { + const script = await client.getKnownScript(ccc.KnownScript.XUdt); + setUdtCodeHash(script.codeHash); + setUdtHashType(script.hashType); + setUdtTxHash(script.cellDeps[0].cellDep.outPoint.txHash); + setUdtIndex(script.cellDeps[0].cellDep.outPoint.index.toString()); + })(); + }, [client]); + + return ( +
+