Skip to content

Commit 7fba400

Browse files
committed
feat(core): multiple scripts for SignerCkbScriptReadonly
1 parent eb1fdb3 commit 7fba400

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

.changeset/ten-ties-kiss.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ckb-ccc/core": minor
3+
---
4+
5+
feat(core): multiple scripts for `SignerCkbScriptReadonly`
6+

packages/core/src/signer/ckb/signerCkbScriptReadonly.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,46 @@ import { Client } from "../../client/index.js";
44
import { 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
*/
1113
export 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

Comments
 (0)