@@ -4,31 +4,46 @@ import { Client } from "../../client/index.js";
44import { Signer , SignerSignType , SignerType } from "../signer/index.js" ;
55
66/**
7- * A class extending Signer that provides read-only access to a CKB script.
8- * This class does not support signing operations.
7+ * A read-only signer for a CKB script. It can be used to get addresses,
8+ * but not to sign transactions. This is useful when you want to watch an address
9+ * without having the private key.
10+ *
911 * @public
1012 */
1113export class SignerCkbScriptReadonly extends Signer {
14+ /**
15+ * The type of the signer.
16+ */
1217 get type ( ) : SignerType {
1318 return SignerType . CKB ;
1419 }
1520
21+ /**
22+ * The sign type of the signer.
23+ * As this is a read-only signer, the sign type is {@link SignerSignType.Unknown}.
24+ */
1625 get signType ( ) : SignerSignType {
1726 return SignerSignType . Unknown ;
1827 }
1928
20- private readonly script : Script ;
29+ /**
30+ * The scripts associated with the signer.
31+ */
32+ public readonly scripts : Script [ ] ;
2133
2234 /**
2335 * Creates an instance of SignerCkbScriptReadonly.
2436 *
2537 * @param client - The client instance used for communication.
26- * @param script - The script associated with the signer.
38+ * @param scripts - The scripts associated with the signer. Can be a single script, an array of scripts, or multiple script arguments .
2739 */
28- constructor ( client : Client , script : ScriptLike ) {
40+ constructor ( client : Client , ... scripts : ( ScriptLike | ScriptLike [ ] ) [ ] ) {
2941 super ( client ) ;
3042
31- this . script = Script . from ( script ) ;
43+ this . scripts = scripts . flat ( ) . map ( Script . from ) ;
44+ if ( this . scripts . length === 0 ) {
45+ throw new Error ( "SignerCkbScriptReadonly requires at least one script." ) ;
46+ }
3247 }
3348
3449 /**
@@ -71,8 +86,9 @@ export class SignerCkbScriptReadonly extends Signer {
7186 * const addressObjs = await signer.getAddressObjs(); // Outputs the array of Address objects
7287 * ```
7388 */
74-
7589 async getAddressObjs ( ) : Promise < Address [ ] > {
76- return [ Address . fromScript ( this . script , this . client ) ] ;
90+ return this . scripts . map ( ( script ) =>
91+ Address . fromScript ( script , this . client ) ,
92+ ) ;
7793 }
7894}
0 commit comments