@ckb-ccc/uni-sat 0.0.10-alpha.4 → 0.0.10-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  export * as UniSatA from "./advancedBarrel";
2
- //# sourceMappingURL=advanced.d.ts.map
2
+ //# sourceMappingURL=advanced.d.ts.map
@@ -1,48 +1,27 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __setModuleDefault =
26
- (this && this.__setModuleDefault) ||
27
- (Object.create
28
- ? function (o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }
31
- : function (o, v) {
32
- o["default"] = v;
33
- });
34
- var __importStar =
35
- (this && this.__importStar) ||
36
- function (mod) {
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
37
19
  if (mod && mod.__esModule) return mod;
38
20
  var result = {};
39
- if (mod != null)
40
- for (var k in mod)
41
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
42
- __createBinding(result, mod, k);
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
22
  __setModuleDefault(result, mod);
44
23
  return result;
45
- };
24
+ };
46
25
  Object.defineProperty(exports, "__esModule", { value: true });
47
26
  exports.UniSatA = void 0;
48
27
  exports.UniSatA = __importStar(require("./advancedBarrel"));
@@ -3,81 +3,78 @@
3
3
  * @interface
4
4
  */
5
5
  export interface Provider {
6
- /**
7
- * Requests user accounts.
8
- * @returns {Promise<string[]>} A promise that resolves to an array of account addresses.
9
- */
10
- requestAccounts(): Promise<string[]>;
11
- /**
12
- * Gets the current network.
13
- * @returns current network.
14
- */
15
- getNetwork(): Promise<"livenet" | "testnet">;
16
- /**
17
- * Switch the current network.
18
- */
19
- switchNetwork(chain: "livenet" | "testnet"): Promise<void>;
20
- /**
21
- * Gets the current chain.
22
- * @returns current chain.
23
- */
24
- getChain?(): Promise<{
25
- enum: string;
26
- name: string;
27
- network: string;
28
- }>;
29
- /**
30
- * Switch the current chain.
31
- */
32
- switchChain?(chain: string): Promise<{
33
- enum: string;
34
- name: string;
35
- network: string;
36
- }>;
37
- /**
38
- * Gets the current accounts.
39
- * @returns {Promise<string[]>} A promise that resolves to an array of account addresses.
40
- */
41
- getAccounts(): Promise<string[]>;
42
- /**
43
- * Gets the public key of the account.
44
- * @returns {Promise<string>} A promise that resolves to the public key.
45
- */
46
- getPublicKey(): Promise<string>;
47
- /**
48
- * Signs a message with the specified type.
49
- * @param {string} msg - The message to sign.
50
- * @param {"ecdsa" | "bip322-simple"} type - The type of signature.
51
- * @returns {Promise<string>} A promise that resolves to the signed message.
52
- */
53
- signMessage(msg: string, type: "ecdsa" | "bip322-simple"): Promise<string>;
54
- /**
55
- * Adds an event listener to the provider.
56
- * @type {OnMethod}
57
- */
58
- on: OnMethod;
59
- /**
60
- * Removes an event listener from the provider.
61
- * @param {string} eventName - The name of the event to remove the listener from.
62
- * @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
63
- * @returns {Provider} The provider instance.
64
- */
65
- removeListener(
66
- eventName: string,
67
- listener: (...args: unknown[]) => unknown,
68
- ): Provider;
6
+ /**
7
+ * Requests user accounts.
8
+ * @returns {Promise<string[]>} A promise that resolves to an array of account addresses.
9
+ */
10
+ requestAccounts(): Promise<string[]>;
11
+ /**
12
+ * Gets the current network.
13
+ * @returns current network.
14
+ */
15
+ getNetwork(): Promise<"livenet" | "testnet">;
16
+ /**
17
+ * Switch the current network.
18
+ */
19
+ switchNetwork(chain: "livenet" | "testnet"): Promise<void>;
20
+ /**
21
+ * Gets the current chain.
22
+ * @returns current chain.
23
+ */
24
+ getChain?(): Promise<{
25
+ enum: string;
26
+ name: string;
27
+ network: string;
28
+ }>;
29
+ /**
30
+ * Switch the current chain.
31
+ */
32
+ switchChain?(chain: string): Promise<{
33
+ enum: string;
34
+ name: string;
35
+ network: string;
36
+ }>;
37
+ /**
38
+ * Gets the current accounts.
39
+ * @returns {Promise<string[]>} A promise that resolves to an array of account addresses.
40
+ */
41
+ getAccounts(): Promise<string[]>;
42
+ /**
43
+ * Gets the public key of the account.
44
+ * @returns {Promise<string>} A promise that resolves to the public key.
45
+ */
46
+ getPublicKey(): Promise<string>;
47
+ /**
48
+ * Signs a message with the specified type.
49
+ * @param {string} msg - The message to sign.
50
+ * @param {"ecdsa" | "bip322-simple"} type - The type of signature.
51
+ * @returns {Promise<string>} A promise that resolves to the signed message.
52
+ */
53
+ signMessage(msg: string, type: "ecdsa" | "bip322-simple"): Promise<string>;
54
+ /**
55
+ * Adds an event listener to the provider.
56
+ * @type {OnMethod}
57
+ */
58
+ on: OnMethod;
59
+ /**
60
+ * Removes an event listener from the provider.
61
+ * @param {string} eventName - The name of the event to remove the listener from.
62
+ * @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
63
+ * @returns {Provider} The provider instance.
64
+ */
65
+ removeListener(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
69
66
  }
70
67
  /**
71
68
  * Interface representing a method to add event listeners to the provider.
72
69
  * @interface
73
70
  */
74
71
  export interface OnMethod {
75
- /**
76
- * Adds an event listener to the provider.
77
- * @param {string} eventName - The name of the event.
78
- * @param {(...args: unknown[]) => unknown} listener - The listener function.
79
- * @returns {Provider} The provider instance.
80
- */
81
- (eventName: string, listener: (...args: unknown[]) => unknown): Provider;
72
+ /**
73
+ * Adds an event listener to the provider.
74
+ * @param {string} eventName - The name of the event.
75
+ * @param {(...args: unknown[]) => unknown} listener - The listener function.
76
+ * @returns {Provider} The provider instance.
77
+ */
78
+ (eventName: string, listener: (...args: unknown[]) => unknown): Provider;
82
79
  }
83
- //# sourceMappingURL=advancedBarrel.d.ts.map
80
+ //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -1,3 +1,3 @@
1
1
  export * from "./signer";
2
2
  export * from "./signersFactory";
3
- //# sourceMappingURL=barrel.d.ts.map
3
+ //# sourceMappingURL=barrel.d.ts.map
@@ -1,34 +1,18 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __exportStar =
26
- (this && this.__exportStar) ||
27
- function (m, exports) {
28
- for (var p in m)
29
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
- __createBinding(exports, m, p);
31
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
32
16
  Object.defineProperty(exports, "__esModule", { value: true });
33
17
  __exportStar(require("./signer"), exports);
34
18
  __exportStar(require("./signersFactory"), exports);
@@ -1,2 +1,2 @@
1
1
  export * as UniSat from "./barrel";
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=index.d.ts.map
@@ -1,48 +1,27 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __setModuleDefault =
26
- (this && this.__setModuleDefault) ||
27
- (Object.create
28
- ? function (o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }
31
- : function (o, v) {
32
- o["default"] = v;
33
- });
34
- var __importStar =
35
- (this && this.__importStar) ||
36
- function (mod) {
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
37
19
  if (mod && mod.__esModule) return mod;
38
20
  var result = {};
39
- if (mod != null)
40
- for (var k in mod)
41
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
42
- __createBinding(result, mod, k);
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
22
  __setModuleDefault(result, mod);
44
23
  return result;
45
- };
24
+ };
46
25
  Object.defineProperty(exports, "__esModule", { value: true });
47
26
  exports.UniSat = void 0;
48
27
  exports.UniSat = __importStar(require("./barrel"));
@@ -6,49 +6,45 @@ import { Provider } from "./advancedBarrel";
6
6
  * @extends {ccc.SignerBtc}
7
7
  */
8
8
  export declare class Signer extends ccc.SignerBtc {
9
- readonly provider: Provider;
10
- private readonly preferredNetworks;
11
- /**
12
- * Creates an instance of Signer.
13
- * @param {ccc.Client} client - The client instance.
14
- * @param {Provider} provider - The provider instance.
15
- */
16
- constructor(
17
- client: ccc.Client,
18
- provider: Provider,
19
- preferredNetworks?: ccc.NetworkPreference[],
20
- );
21
- _getNetworkToChange(): Promise<string | undefined>;
22
- /**
23
- * Ensure the BTC network is the same as CKB network.
24
- */
25
- ensureNetwork(): Promise<void>;
26
- /**
27
- * Gets the Bitcoin account address.
28
- * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
29
- */
30
- getBtcAccount(): Promise<string>;
31
- /**
32
- * Gets the Bitcoin public key.
33
- * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
34
- */
35
- getBtcPublicKey(): Promise<ccc.Hex>;
36
- /**
37
- * Connects to the provider by requesting accounts.
38
- * @returns {Promise<void>} A promise that resolves when the connection is established.
39
- */
40
- connect(): Promise<void>;
41
- onReplaced(listener: () => void): () => void;
42
- /**
43
- * Checks if the signer is connected.
44
- * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
45
- */
46
- isConnected(): Promise<boolean>;
47
- /**
48
- * Signs a raw message with the Bitcoin account.
49
- * @param {string | ccc.BytesLike} message - The message to sign.
50
- * @returns {Promise<string>} A promise that resolves to the signed message.
51
- */
52
- signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
9
+ readonly provider: Provider;
10
+ private readonly preferredNetworks;
11
+ /**
12
+ * Creates an instance of Signer.
13
+ * @param {ccc.Client} client - The client instance.
14
+ * @param {Provider} provider - The provider instance.
15
+ */
16
+ constructor(client: ccc.Client, provider: Provider, preferredNetworks?: ccc.NetworkPreference[]);
17
+ _getNetworkToChange(): Promise<string | undefined>;
18
+ /**
19
+ * Ensure the BTC network is the same as CKB network.
20
+ */
21
+ ensureNetwork(): Promise<void>;
22
+ /**
23
+ * Gets the Bitcoin account address.
24
+ * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
25
+ */
26
+ getBtcAccount(): Promise<string>;
27
+ /**
28
+ * Gets the Bitcoin public key.
29
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
30
+ */
31
+ getBtcPublicKey(): Promise<ccc.Hex>;
32
+ /**
33
+ * Connects to the provider by requesting accounts.
34
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
35
+ */
36
+ connect(): Promise<void>;
37
+ onReplaced(listener: () => void): () => void;
38
+ /**
39
+ * Checks if the signer is connected.
40
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
41
+ */
42
+ isConnected(): Promise<boolean>;
43
+ /**
44
+ * Signs a raw message with the Bitcoin account.
45
+ * @param {string | ccc.BytesLike} message - The message to sign.
46
+ * @returns {Promise<string>} A promise that resolves to the signed message.
47
+ */
48
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
53
49
  }
54
- //# sourceMappingURL=signer.d.ts.map
50
+ //# sourceMappingURL=signer.d.ts.map
@@ -8,140 +8,125 @@ const core_1 = require("@ckb-ccc/core");
8
8
  * @extends {ccc.SignerBtc}
9
9
  */
10
10
  class Signer extends core_1.ccc.SignerBtc {
11
- /**
12
- * Creates an instance of Signer.
13
- * @param {ccc.Client} client - The client instance.
14
- * @param {Provider} provider - The provider instance.
15
- */
16
- constructor(
17
- client,
18
- provider,
19
- preferredNetworks = [
20
- {
21
- addressPrefix: "ckb",
22
- signerType: core_1.ccc.SignerType.BTC,
23
- network: "btc",
24
- },
25
- {
26
- addressPrefix: "ckt",
27
- signerType: core_1.ccc.SignerType.BTC,
28
- network: "btcTestnet",
29
- },
30
- ],
31
- ) {
32
- super(client);
33
- this.provider = provider;
34
- this.preferredNetworks = preferredNetworks;
35
- }
36
- async _getNetworkToChange() {
37
- const currentNetwork = await (async () => {
38
- if (this.provider.getChain) {
39
- return (
40
- {
41
- BITCOIN_MAINNET: "btc",
42
- BITCOIN_TESTNET: "btcTestnet",
43
- FRACTAL_BITCOIN_MAINNET: "fractalBtc",
44
- }[(await this.provider.getChain()).enum] ?? ""
45
- );
46
- }
47
- return (await this.provider.getNetwork()) === "livenet"
48
- ? "btc"
49
- : "btcTestnet";
50
- })();
51
- const { network } = this.matchNetworkPreference(
52
- this.preferredNetworks,
53
- currentNetwork,
54
- ) ?? { network: currentNetwork };
55
- if (network === currentNetwork) {
56
- return;
11
+ /**
12
+ * Creates an instance of Signer.
13
+ * @param {ccc.Client} client - The client instance.
14
+ * @param {Provider} provider - The provider instance.
15
+ */
16
+ constructor(client, provider, preferredNetworks = [
17
+ {
18
+ addressPrefix: "ckb",
19
+ signerType: core_1.ccc.SignerType.BTC,
20
+ network: "btc",
21
+ },
22
+ {
23
+ addressPrefix: "ckt",
24
+ signerType: core_1.ccc.SignerType.BTC,
25
+ network: "btcTestnet",
26
+ },
27
+ ]) {
28
+ super(client);
29
+ this.provider = provider;
30
+ this.preferredNetworks = preferredNetworks;
57
31
  }
58
- return network;
59
- }
60
- /**
61
- * Ensure the BTC network is the same as CKB network.
62
- */
63
- async ensureNetwork() {
64
- const network = await this._getNetworkToChange();
65
- if (!network) {
66
- return;
32
+ async _getNetworkToChange() {
33
+ const currentNetwork = await (async () => {
34
+ if (this.provider.getChain) {
35
+ return ({
36
+ BITCOIN_MAINNET: "btc",
37
+ BITCOIN_TESTNET: "btcTestnet",
38
+ FRACTAL_BITCOIN_MAINNET: "fractalBtc",
39
+ }[(await this.provider.getChain()).enum] ?? "");
40
+ }
41
+ return (await this.provider.getNetwork()) === "livenet"
42
+ ? "btc"
43
+ : "btcTestnet";
44
+ })();
45
+ const { network } = this.matchNetworkPreference(this.preferredNetworks, currentNetwork) ?? { network: currentNetwork };
46
+ if (network === currentNetwork) {
47
+ return;
48
+ }
49
+ return network;
67
50
  }
68
- if (this.provider.switchChain) {
69
- const chain = {
70
- btc: "BITCOIN_MAINNET",
71
- btcTestnet: "BITCOIN_TESTNET",
72
- fractalBtc: "FRACTAL_BITCOIN_MAINNET",
73
- }[network];
74
- if (chain) {
75
- await this.provider.switchChain(chain);
76
- return;
77
- }
78
- } else if (network === "btc" || network === "btcTestnet") {
79
- await this.provider.switchNetwork(
80
- network === "btc" ? "livenet" : "testnet",
81
- );
82
- return;
51
+ /**
52
+ * Ensure the BTC network is the same as CKB network.
53
+ */
54
+ async ensureNetwork() {
55
+ const network = await this._getNetworkToChange();
56
+ if (!network) {
57
+ return;
58
+ }
59
+ if (this.provider.switchChain) {
60
+ const chain = {
61
+ btc: "BITCOIN_MAINNET",
62
+ btcTestnet: "BITCOIN_TESTNET",
63
+ fractalBtc: "FRACTAL_BITCOIN_MAINNET",
64
+ }[network];
65
+ if (chain) {
66
+ await this.provider.switchChain(chain);
67
+ return;
68
+ }
69
+ }
70
+ else if (network === "btc" || network === "btcTestnet") {
71
+ await this.provider.switchNetwork(network === "btc" ? "livenet" : "testnet");
72
+ return;
73
+ }
74
+ throw new Error(`UniSat wallet doesn't support the requested chain ${network}`);
83
75
  }
84
- throw new Error(
85
- `UniSat wallet doesn't support the requested chain ${network}`,
86
- );
87
- }
88
- /**
89
- * Gets the Bitcoin account address.
90
- * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
91
- */
92
- async getBtcAccount() {
93
- return (await this.provider.getAccounts())[0];
94
- }
95
- /**
96
- * Gets the Bitcoin public key.
97
- * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
98
- */
99
- async getBtcPublicKey() {
100
- return core_1.ccc.hexFrom(await this.provider.getPublicKey());
101
- }
102
- /**
103
- * Connects to the provider by requesting accounts.
104
- * @returns {Promise<void>} A promise that resolves when the connection is established.
105
- */
106
- async connect() {
107
- await this.provider.requestAccounts();
108
- await this.ensureNetwork();
109
- }
110
- onReplaced(listener) {
111
- const stop = [];
112
- const replacer = async () => {
113
- listener();
114
- stop[0]?.();
115
- };
116
- stop.push(() => {
117
- this.provider.removeListener("accountsChanged", replacer);
118
- this.provider.removeListener("networkChanged", replacer);
119
- });
120
- this.provider.on("accountsChanged", replacer);
121
- this.provider.on("networkChanged", replacer);
122
- return stop[0];
123
- }
124
- /**
125
- * Checks if the signer is connected.
126
- * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
127
- */
128
- async isConnected() {
129
- if (await this._getNetworkToChange()) {
130
- return false;
76
+ /**
77
+ * Gets the Bitcoin account address.
78
+ * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
79
+ */
80
+ async getBtcAccount() {
81
+ return (await this.provider.getAccounts())[0];
82
+ }
83
+ /**
84
+ * Gets the Bitcoin public key.
85
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
86
+ */
87
+ async getBtcPublicKey() {
88
+ return core_1.ccc.hexFrom(await this.provider.getPublicKey());
89
+ }
90
+ /**
91
+ * Connects to the provider by requesting accounts.
92
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
93
+ */
94
+ async connect() {
95
+ await this.provider.requestAccounts();
96
+ await this.ensureNetwork();
97
+ }
98
+ onReplaced(listener) {
99
+ const stop = [];
100
+ const replacer = async () => {
101
+ listener();
102
+ stop[0]?.();
103
+ };
104
+ stop.push(() => {
105
+ this.provider.removeListener("accountsChanged", replacer);
106
+ this.provider.removeListener("networkChanged", replacer);
107
+ });
108
+ this.provider.on("accountsChanged", replacer);
109
+ this.provider.on("networkChanged", replacer);
110
+ return stop[0];
111
+ }
112
+ /**
113
+ * Checks if the signer is connected.
114
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
115
+ */
116
+ async isConnected() {
117
+ if (await this._getNetworkToChange()) {
118
+ return false;
119
+ }
120
+ return (await this.provider.getAccounts()).length !== 0;
121
+ }
122
+ /**
123
+ * Signs a raw message with the Bitcoin account.
124
+ * @param {string | ccc.BytesLike} message - The message to sign.
125
+ * @returns {Promise<string>} A promise that resolves to the signed message.
126
+ */
127
+ async signMessageRaw(message) {
128
+ const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
129
+ return this.provider.signMessage(challenge, "ecdsa");
131
130
  }
132
- return (await this.provider.getAccounts()).length !== 0;
133
- }
134
- /**
135
- * Signs a raw message with the Bitcoin account.
136
- * @param {string | ccc.BytesLike} message - The message to sign.
137
- * @returns {Promise<string>} A promise that resolves to the signed message.
138
- */
139
- async signMessageRaw(message) {
140
- const challenge =
141
- typeof message === "string"
142
- ? message
143
- : core_1.ccc.hexFrom(message).slice(2);
144
- return this.provider.signMessage(challenge, "ecdsa");
145
- }
146
131
  }
147
132
  exports.Signer = Signer;
@@ -5,8 +5,5 @@ import { Signer } from "./signer";
5
5
  * @param {ccc.Client} client - The client instance.
6
6
  * @returns {Signer | undefined} The Signer instance if the UniSat provider is available, otherwise undefined.
7
7
  */
8
- export declare function getUniSatSigner(
9
- client: ccc.Client,
10
- preferredNetworks: ccc.NetworkPreference[],
11
- ): Signer | undefined;
12
- //# sourceMappingURL=signersFactory.d.ts.map
8
+ export declare function getUniSatSigner(client: ccc.Client, preferredNetworks: ccc.NetworkPreference[]): Signer | undefined;
9
+ //# sourceMappingURL=signersFactory.d.ts.map
@@ -8,10 +8,10 @@ const signer_1 = require("./signer");
8
8
  * @returns {Signer | undefined} The Signer instance if the UniSat provider is available, otherwise undefined.
9
9
  */
10
10
  function getUniSatSigner(client, preferredNetworks) {
11
- const windowRef = window;
12
- if (typeof windowRef.unisat === "undefined") {
13
- return undefined;
14
- }
15
- return new signer_1.Signer(client, windowRef.unisat, preferredNetworks);
11
+ const windowRef = window;
12
+ if (typeof windowRef.unisat === "undefined") {
13
+ return undefined;
14
+ }
15
+ return new signer_1.Signer(client, windowRef.unisat, preferredNetworks);
16
16
  }
17
17
  exports.getUniSatSigner = getUniSatSigner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/uni-sat",
3
- "version": "0.0.10-alpha.4",
3
+ "version": "0.0.10-alpha.6",
4
4
  "description": "CCC - CKBer's Codebase. Common Chains Connector's support for UniSat",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -50,7 +50,7 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@ckb-ccc/core": "0.0.10-alpha.4"
53
+ "@ckb-ccc/core": "0.0.10-alpha.6"
54
54
  },
55
- "gitHead": "61228337bbf4bdc0bc082e3c9530f843c2182106"
55
+ "gitHead": "16cf49da60cb01f0f0903fccc0d597d8de54f905"
56
56
  }