From 7fba400a76c4bd82db21b358ff67330014c6c440 Mon Sep 17 00:00:00 2001 From: Hanssen0 Date: Sun, 17 Aug 2025 21:23:02 +0800 Subject: [PATCH] feat(core): multiple scripts for `SignerCkbScriptReadonly` --- .changeset/ten-ties-kiss.md | 6 ++++ .../src/signer/ckb/signerCkbScriptReadonly.ts | 32 ++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 .changeset/ten-ties-kiss.md diff --git a/.changeset/ten-ties-kiss.md b/.changeset/ten-ties-kiss.md new file mode 100644 index 00000000..163263fc --- /dev/null +++ b/.changeset/ten-ties-kiss.md @@ -0,0 +1,6 @@ +--- +"@ckb-ccc/core": minor +--- + +feat(core): multiple scripts for `SignerCkbScriptReadonly` + \ No newline at end of file diff --git a/packages/core/src/signer/ckb/signerCkbScriptReadonly.ts b/packages/core/src/signer/ckb/signerCkbScriptReadonly.ts index fa9df8b1..57d170bb 100644 --- a/packages/core/src/signer/ckb/signerCkbScriptReadonly.ts +++ b/packages/core/src/signer/ckb/signerCkbScriptReadonly.ts @@ -4,31 +4,46 @@ import { Client } from "../../client/index.js"; import { Signer, SignerSignType, SignerType } from "../signer/index.js"; /** - * A class extending Signer that provides read-only access to a CKB script. - * This class does not support signing operations. + * A read-only signer for a CKB script. It can be used to get addresses, + * but not to sign transactions. This is useful when you want to watch an address + * without having the private key. + * * @public */ export class SignerCkbScriptReadonly extends Signer { + /** + * The type of the signer. + */ get type(): SignerType { return SignerType.CKB; } + /** + * The sign type of the signer. + * As this is a read-only signer, the sign type is {@link SignerSignType.Unknown}. + */ get signType(): SignerSignType { return SignerSignType.Unknown; } - private readonly script: Script; + /** + * The scripts associated with the signer. + */ + public readonly scripts: Script[]; /** * Creates an instance of SignerCkbScriptReadonly. * * @param client - The client instance used for communication. - * @param script - The script associated with the signer. + * @param scripts - The scripts associated with the signer. Can be a single script, an array of scripts, or multiple script arguments. */ - constructor(client: Client, script: ScriptLike) { + constructor(client: Client, ...scripts: (ScriptLike | ScriptLike[])[]) { super(client); - this.script = Script.from(script); + this.scripts = scripts.flat().map(Script.from); + if (this.scripts.length === 0) { + throw new Error("SignerCkbScriptReadonly requires at least one script."); + } } /** @@ -71,8 +86,9 @@ export class SignerCkbScriptReadonly extends Signer { * const addressObjs = await signer.getAddressObjs(); // Outputs the array of Address objects * ``` */ - async getAddressObjs(): Promise { - return [Address.fromScript(this.script, this.client)]; + return this.scripts.map((script) => + Address.fromScript(script, this.client), + ); } }