@ckb-ccc/uni-sat 0.0.5-alpha.8 → 0.0.7-alpha.0

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,12 +1,54 @@
1
+ /**
2
+ * Interface representing a provider for interacting with accounts and signing messages.
3
+ * @interface
4
+ */
1
5
  export interface Provider {
6
+ /**
7
+ * Requests user accounts.
8
+ * @returns {Promise<string[]>} A promise that resolves to an array of account addresses.
9
+ */
2
10
  requestAccounts(): Promise<string[]>;
11
+ /**
12
+ * Gets the current accounts.
13
+ * @returns {Promise<string[]>} A promise that resolves to an array of account addresses.
14
+ */
3
15
  getAccounts(): Promise<string[]>;
16
+ /**
17
+ * Gets the public key of the account.
18
+ * @returns {Promise<string>} A promise that resolves to the public key.
19
+ */
4
20
  getPublicKey(): Promise<string>;
21
+ /**
22
+ * Signs a message with the specified type.
23
+ * @param {string} msg - The message to sign.
24
+ * @param {"ecdsa" | "bip322-simple"} type - The type of signature.
25
+ * @returns {Promise<string>} A promise that resolves to the signed message.
26
+ */
5
27
  signMessage(msg: string, type: "ecdsa" | "bip322-simple"): Promise<string>;
28
+ /**
29
+ * Adds an event listener to the provider.
30
+ * @type {OnMethod}
31
+ */
6
32
  on: OnMethod;
33
+ /**
34
+ * Removes an event listener from the provider.
35
+ * @param {string} eventName - The name of the event to remove the listener from.
36
+ * @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
37
+ * @returns {Provider} The provider instance.
38
+ */
7
39
  removeListener(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
8
40
  }
41
+ /**
42
+ * Interface representing a method to add event listeners to the provider.
43
+ * @interface
44
+ */
9
45
  export interface OnMethod {
46
+ /**
47
+ * Adds an event listener to the provider.
48
+ * @param {string} eventName - The name of the event.
49
+ * @param {(...args: unknown[]) => unknown} listener - The listener function.
50
+ * @returns {Provider} The provider instance.
51
+ */
10
52
  (eventName: string, listener: (...args: unknown[]) => unknown): Provider;
11
53
  }
12
54
  //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACjC,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3E,EAAE,EAAE,QAAQ,CAAC;IACb,cAAc,CACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,QAAQ,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,QAAQ,CAAC;CAC1E"}
1
+ {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAErC;;;OAGG;IACH,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEjC;;;OAGG;IACH,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEhC;;;;;OAKG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3E;;;OAGG;IACH,EAAE,EAAE,QAAQ,CAAC;IAEb;;;;;OAKG;IACH,cAAc,CACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,QAAQ,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,QAAQ,CAAC;CAC1E"}
package/dist/signer.d.ts CHANGED
@@ -1,13 +1,43 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { Provider } from "./advancedBarrel";
3
+ /**
4
+ * Class representing a Bitcoin signer that extends SignerBtc from @ckb-ccc/core.
5
+ * @class
6
+ * @extends {ccc.SignerBtc}
7
+ */
3
8
  export declare class Signer extends ccc.SignerBtc {
4
9
  readonly provider: Provider;
10
+ /**
11
+ * Creates an instance of Signer.
12
+ * @param {ccc.Client} client - The client instance.
13
+ * @param {Provider} provider - The provider instance.
14
+ */
5
15
  constructor(client: ccc.Client, provider: Provider);
6
- replaceClient(client: ccc.Client): Promise<Signer>;
16
+ /**
17
+ * Gets the Bitcoin account address.
18
+ * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
19
+ */
7
20
  getBtcAccount(): Promise<string>;
21
+ /**
22
+ * Gets the Bitcoin public key.
23
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
24
+ */
8
25
  getBtcPublicKey(): Promise<ccc.Hex>;
26
+ /**
27
+ * Connects to the provider by requesting accounts.
28
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
29
+ */
9
30
  connect(): Promise<void>;
31
+ /**
32
+ * Checks if the signer is connected.
33
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
34
+ */
10
35
  isConnected(): Promise<boolean>;
36
+ /**
37
+ * Signs a raw message with the Bitcoin account.
38
+ * @param {string | ccc.BytesLike} message - The message to sign.
39
+ * @returns {Promise<string>} A promise that resolves to the signed message.
40
+ */
11
41
  signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
12
42
  }
13
43
  //# sourceMappingURL=signer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAGrB,QAAQ,EAAE,QAAQ;gBADlC,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAK9B,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlD,aAAa;IAIb,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAInC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAMvE"}
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAQrB,QAAQ,EAAE,QAAQ;IAPpC;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAKpC;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAIzC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAMvE"}
package/dist/signer.js CHANGED
@@ -1,24 +1,52 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
+ /**
3
+ * Class representing a Bitcoin signer that extends SignerBtc from @ckb-ccc/core.
4
+ * @class
5
+ * @extends {ccc.SignerBtc}
6
+ */
2
7
  export class Signer extends ccc.SignerBtc {
8
+ /**
9
+ * Creates an instance of Signer.
10
+ * @param {ccc.Client} client - The client instance.
11
+ * @param {Provider} provider - The provider instance.
12
+ */
3
13
  constructor(client, provider) {
4
14
  super(client);
5
15
  this.provider = provider;
6
16
  }
7
- async replaceClient(client) {
8
- return new Signer(client, this.provider);
9
- }
17
+ /**
18
+ * Gets the Bitcoin account address.
19
+ * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
20
+ */
10
21
  async getBtcAccount() {
11
22
  return (await this.provider.getAccounts())[0];
12
23
  }
24
+ /**
25
+ * Gets the Bitcoin public key.
26
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
27
+ */
13
28
  async getBtcPublicKey() {
14
29
  return ccc.hexFrom(await this.provider.getPublicKey());
15
30
  }
31
+ /**
32
+ * Connects to the provider by requesting accounts.
33
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
34
+ */
16
35
  async connect() {
17
36
  await this.provider.requestAccounts();
18
37
  }
38
+ /**
39
+ * Checks if the signer is connected.
40
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
41
+ */
19
42
  async isConnected() {
20
43
  return (await this.provider.getAccounts()).length !== 0;
21
44
  }
45
+ /**
46
+ * Signs a raw message with the Bitcoin account.
47
+ * @param {string | ccc.BytesLike} message - The message to sign.
48
+ * @returns {Promise<string>} A promise that resolves to the signed message.
49
+ */
22
50
  async signMessageRaw(message) {
23
51
  const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
24
52
  return this.provider.signMessage(challenge, "ecdsa");
@@ -1,4 +1,9 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { Signer } from "./signer";
3
+ /**
4
+ * Retrieves the UniSat signer if available.
5
+ * @param {ccc.Client} client - The client instance.
6
+ * @returns {Signer | undefined} The Signer instance if the UniSat provider is available, otherwise undefined.
7
+ */
3
8
  export declare function getUniSatSigner(client: ccc.Client): Signer | undefined;
4
9
  //# sourceMappingURL=signersFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAQtE"}
1
+ {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAQtE"}
@@ -1,8 +1,13 @@
1
1
  import { Signer } from "./signer";
2
+ /**
3
+ * Retrieves the UniSat signer if available.
4
+ * @param {ccc.Client} client - The client instance.
5
+ * @returns {Signer | undefined} The Signer instance if the UniSat provider is available, otherwise undefined.
6
+ */
2
7
  export function getUniSatSigner(client) {
3
8
  const windowRef = window;
4
9
  if (typeof windowRef.unisat === "undefined") {
5
- return;
10
+ return undefined;
6
11
  }
7
12
  return new Signer(client, windowRef.unisat);
8
13
  }
@@ -1,2 +1,2 @@
1
1
  export * as UniSatA from "./advancedBarrel";
2
- //# sourceMappingURL=advanced.d.ts.map
2
+ //# sourceMappingURL=advanced.d.ts.map
@@ -1,27 +1,48 @@
1
1
  "use strict";
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) {
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) {
19
37
  if (mod && mod.__esModule) return mod;
20
38
  var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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);
22
43
  __setModuleDefault(result, mod);
23
44
  return result;
24
- };
45
+ };
25
46
  Object.defineProperty(exports, "__esModule", { value: true });
26
47
  exports.UniSatA = void 0;
27
48
  exports.UniSatA = __importStar(require("./advancedBarrel"));
@@ -1,12 +1,57 @@
1
+ /**
2
+ * Interface representing a provider for interacting with accounts and signing messages.
3
+ * @interface
4
+ */
1
5
  export interface Provider {
2
- requestAccounts(): Promise<string[]>;
3
- getAccounts(): Promise<string[]>;
4
- getPublicKey(): Promise<string>;
5
- signMessage(msg: string, type: "ecdsa" | "bip322-simple"): Promise<string>;
6
- on: OnMethod;
7
- removeListener(eventName: string, listener: (...args: unknown[]) => unknown): 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 accounts.
13
+ * @returns {Promise<string[]>} A promise that resolves to an array of account addresses.
14
+ */
15
+ getAccounts(): Promise<string[]>;
16
+ /**
17
+ * Gets the public key of the account.
18
+ * @returns {Promise<string>} A promise that resolves to the public key.
19
+ */
20
+ getPublicKey(): Promise<string>;
21
+ /**
22
+ * Signs a message with the specified type.
23
+ * @param {string} msg - The message to sign.
24
+ * @param {"ecdsa" | "bip322-simple"} type - The type of signature.
25
+ * @returns {Promise<string>} A promise that resolves to the signed message.
26
+ */
27
+ signMessage(msg: string, type: "ecdsa" | "bip322-simple"): Promise<string>;
28
+ /**
29
+ * Adds an event listener to the provider.
30
+ * @type {OnMethod}
31
+ */
32
+ on: OnMethod;
33
+ /**
34
+ * Removes an event listener from the provider.
35
+ * @param {string} eventName - The name of the event to remove the listener from.
36
+ * @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
37
+ * @returns {Provider} The provider instance.
38
+ */
39
+ removeListener(
40
+ eventName: string,
41
+ listener: (...args: unknown[]) => unknown,
42
+ ): Provider;
8
43
  }
44
+ /**
45
+ * Interface representing a method to add event listeners to the provider.
46
+ * @interface
47
+ */
9
48
  export interface OnMethod {
10
- (eventName: string, listener: (...args: unknown[]) => unknown): Provider;
49
+ /**
50
+ * Adds an event listener to the provider.
51
+ * @param {string} eventName - The name of the event.
52
+ * @param {(...args: unknown[]) => unknown} listener - The listener function.
53
+ * @returns {Provider} The provider instance.
54
+ */
55
+ (eventName: string, listener: (...args: unknown[]) => unknown): Provider;
11
56
  }
12
- //# sourceMappingURL=advancedBarrel.d.ts.map
57
+ //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACjC,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3E,EAAE,EAAE,QAAQ,CAAC;IACb,cAAc,CACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,QAAQ,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,QAAQ,CAAC;CAC1E"}
1
+ {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAErC;;;OAGG;IACH,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEjC;;;OAGG;IACH,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEhC;;;;;OAKG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3E;;;OAGG;IACH,EAAE,EAAE,QAAQ,CAAC;IAEb;;;;;OAKG;IACH,cAAc,CACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,QAAQ,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,QAAQ,CAAC;CAC1E"}
@@ -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,18 +1,34 @@
1
1
  "use strict";
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
- };
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
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./signer"), exports);
18
34
  __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,27 +1,48 @@
1
1
  "use strict";
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) {
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) {
19
37
  if (mod && mod.__esModule) return mod;
20
38
  var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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);
22
43
  __setModuleDefault(result, mod);
23
44
  return result;
24
- };
45
+ };
25
46
  Object.defineProperty(exports, "__esModule", { value: true });
26
47
  exports.UniSat = void 0;
27
48
  exports.UniSat = __importStar(require("./barrel"));
@@ -1,13 +1,43 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { Provider } from "./advancedBarrel";
3
+ /**
4
+ * Class representing a Bitcoin signer that extends SignerBtc from @ckb-ccc/core.
5
+ * @class
6
+ * @extends {ccc.SignerBtc}
7
+ */
3
8
  export declare class Signer extends ccc.SignerBtc {
4
- readonly provider: Provider;
5
- constructor(client: ccc.Client, provider: Provider);
6
- replaceClient(client: ccc.Client): Promise<Signer>;
7
- getBtcAccount(): Promise<string>;
8
- getBtcPublicKey(): Promise<ccc.Hex>;
9
- connect(): Promise<void>;
10
- isConnected(): Promise<boolean>;
11
- signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
9
+ readonly provider: Provider;
10
+ /**
11
+ * Creates an instance of Signer.
12
+ * @param {ccc.Client} client - The client instance.
13
+ * @param {Provider} provider - The provider instance.
14
+ */
15
+ constructor(client: ccc.Client, provider: Provider);
16
+ /**
17
+ * Gets the Bitcoin account address.
18
+ * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
19
+ */
20
+ getBtcAccount(): Promise<string>;
21
+ /**
22
+ * Gets the Bitcoin public key.
23
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
24
+ */
25
+ getBtcPublicKey(): Promise<ccc.Hex>;
26
+ /**
27
+ * Connects to the provider by requesting accounts.
28
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
29
+ */
30
+ connect(): Promise<void>;
31
+ /**
32
+ * Checks if the signer is connected.
33
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
34
+ */
35
+ isConnected(): Promise<boolean>;
36
+ /**
37
+ * Signs a raw message with the Bitcoin account.
38
+ * @param {string | ccc.BytesLike} message - The message to sign.
39
+ * @returns {Promise<string>} A promise that resolves to the signed message.
40
+ */
41
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
12
42
  }
13
- //# sourceMappingURL=signer.d.ts.map
43
+ //# sourceMappingURL=signer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAGrB,QAAQ,EAAE,QAAQ;gBADlC,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAK9B,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlD,aAAa;IAIb,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAInC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAMvE"}
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAQrB,QAAQ,EAAE,QAAQ;IAPpC;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAKpC;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAIzC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAMvE"}
@@ -2,29 +2,60 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Signer = void 0;
4
4
  const core_1 = require("@ckb-ccc/core");
5
+ /**
6
+ * Class representing a Bitcoin signer that extends SignerBtc from @ckb-ccc/core.
7
+ * @class
8
+ * @extends {ccc.SignerBtc}
9
+ */
5
10
  class Signer extends core_1.ccc.SignerBtc {
6
- constructor(client, provider) {
7
- super(client);
8
- this.provider = provider;
9
- }
10
- async replaceClient(client) {
11
- return new Signer(client, this.provider);
12
- }
13
- async getBtcAccount() {
14
- return (await this.provider.getAccounts())[0];
15
- }
16
- async getBtcPublicKey() {
17
- return core_1.ccc.hexFrom(await this.provider.getPublicKey());
18
- }
19
- async connect() {
20
- await this.provider.requestAccounts();
21
- }
22
- async isConnected() {
23
- return (await this.provider.getAccounts()).length !== 0;
24
- }
25
- async signMessageRaw(message) {
26
- const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
27
- return this.provider.signMessage(challenge, "ecdsa");
28
- }
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) {
17
+ super(client);
18
+ this.provider = provider;
19
+ }
20
+ /**
21
+ * Gets the Bitcoin account address.
22
+ * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
23
+ */
24
+ async getBtcAccount() {
25
+ return (await this.provider.getAccounts())[0];
26
+ }
27
+ /**
28
+ * Gets the Bitcoin public key.
29
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
30
+ */
31
+ async getBtcPublicKey() {
32
+ return core_1.ccc.hexFrom(await this.provider.getPublicKey());
33
+ }
34
+ /**
35
+ * Connects to the provider by requesting accounts.
36
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
37
+ */
38
+ async connect() {
39
+ await this.provider.requestAccounts();
40
+ }
41
+ /**
42
+ * Checks if the signer is connected.
43
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
44
+ */
45
+ async isConnected() {
46
+ return (await this.provider.getAccounts()).length !== 0;
47
+ }
48
+ /**
49
+ * Signs a raw message with the Bitcoin account.
50
+ * @param {string | ccc.BytesLike} message - The message to sign.
51
+ * @returns {Promise<string>} A promise that resolves to the signed message.
52
+ */
53
+ async signMessageRaw(message) {
54
+ const challenge =
55
+ typeof message === "string"
56
+ ? message
57
+ : core_1.ccc.hexFrom(message).slice(2);
58
+ return this.provider.signMessage(challenge, "ecdsa");
59
+ }
29
60
  }
30
61
  exports.Signer = Signer;
@@ -1,4 +1,9 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { Signer } from "./signer";
3
+ /**
4
+ * Retrieves the UniSat signer if available.
5
+ * @param {ccc.Client} client - The client instance.
6
+ * @returns {Signer | undefined} The Signer instance if the UniSat provider is available, otherwise undefined.
7
+ */
3
8
  export declare function getUniSatSigner(client: ccc.Client): Signer | undefined;
4
- //# sourceMappingURL=signersFactory.d.ts.map
9
+ //# sourceMappingURL=signersFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAQtE"}
1
+ {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAQtE"}
@@ -2,11 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getUniSatSigner = void 0;
4
4
  const signer_1 = require("./signer");
5
+ /**
6
+ * Retrieves the UniSat signer if available.
7
+ * @param {ccc.Client} client - The client instance.
8
+ * @returns {Signer | undefined} The Signer instance if the UniSat provider is available, otherwise undefined.
9
+ */
5
10
  function getUniSatSigner(client) {
6
- const windowRef = window;
7
- if (typeof windowRef.unisat === "undefined") {
8
- return;
9
- }
10
- return new signer_1.Signer(client, windowRef.unisat);
11
+ const windowRef = window;
12
+ if (typeof windowRef.unisat === "undefined") {
13
+ return undefined;
14
+ }
15
+ return new signer_1.Signer(client, windowRef.unisat);
11
16
  }
12
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.5-alpha.8",
3
+ "version": "0.0.7-alpha.0",
4
4
  "description": "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.5-alpha.8"
53
+ "@ckb-ccc/core": "0.0.7-alpha.0"
54
54
  },
55
- "gitHead": "f12b8758d8581bfae0c9a00abbb5f7d2c6d03147"
55
+ "gitHead": "99d88c6179e7af6f592b1b39f8df6f6968cc0df3"
56
56
  }
@@ -1,16 +1,62 @@
1
+ /**
2
+ * Interface representing a provider for interacting with accounts and signing messages.
3
+ * @interface
4
+ */
1
5
  export interface Provider {
6
+ /**
7
+ * Requests user accounts.
8
+ * @returns {Promise<string[]>} A promise that resolves to an array of account addresses.
9
+ */
2
10
  requestAccounts(): Promise<string[]>;
11
+
12
+ /**
13
+ * Gets the current accounts.
14
+ * @returns {Promise<string[]>} A promise that resolves to an array of account addresses.
15
+ */
3
16
  getAccounts(): Promise<string[]>;
17
+
18
+ /**
19
+ * Gets the public key of the account.
20
+ * @returns {Promise<string>} A promise that resolves to the public key.
21
+ */
4
22
  getPublicKey(): Promise<string>;
23
+
24
+ /**
25
+ * Signs a message with the specified type.
26
+ * @param {string} msg - The message to sign.
27
+ * @param {"ecdsa" | "bip322-simple"} type - The type of signature.
28
+ * @returns {Promise<string>} A promise that resolves to the signed message.
29
+ */
5
30
  signMessage(msg: string, type: "ecdsa" | "bip322-simple"): Promise<string>;
6
31
 
32
+ /**
33
+ * Adds an event listener to the provider.
34
+ * @type {OnMethod}
35
+ */
7
36
  on: OnMethod;
37
+
38
+ /**
39
+ * Removes an event listener from the provider.
40
+ * @param {string} eventName - The name of the event to remove the listener from.
41
+ * @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
42
+ * @returns {Provider} The provider instance.
43
+ */
8
44
  removeListener(
9
45
  eventName: string,
10
46
  listener: (...args: unknown[]) => unknown,
11
47
  ): Provider;
12
48
  }
13
49
 
50
+ /**
51
+ * Interface representing a method to add event listeners to the provider.
52
+ * @interface
53
+ */
14
54
  export interface OnMethod {
55
+ /**
56
+ * Adds an event listener to the provider.
57
+ * @param {string} eventName - The name of the event.
58
+ * @param {(...args: unknown[]) => unknown} listener - The listener function.
59
+ * @returns {Provider} The provider instance.
60
+ */
15
61
  (eventName: string, listener: (...args: unknown[]) => unknown): Provider;
16
62
  }
package/src/signer.ts CHANGED
@@ -1,7 +1,17 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { Provider } from "./advancedBarrel";
3
3
 
4
+ /**
5
+ * Class representing a Bitcoin signer that extends SignerBtc from @ckb-ccc/core.
6
+ * @class
7
+ * @extends {ccc.SignerBtc}
8
+ */
4
9
  export class Signer extends ccc.SignerBtc {
10
+ /**
11
+ * Creates an instance of Signer.
12
+ * @param {ccc.Client} client - The client instance.
13
+ * @param {Provider} provider - The provider instance.
14
+ */
5
15
  constructor(
6
16
  client: ccc.Client,
7
17
  public readonly provider: Provider,
@@ -9,26 +19,43 @@ export class Signer extends ccc.SignerBtc {
9
19
  super(client);
10
20
  }
11
21
 
12
- async replaceClient(client: ccc.Client): Promise<Signer> {
13
- return new Signer(client, this.provider);
14
- }
15
-
16
- async getBtcAccount() {
22
+ /**
23
+ * Gets the Bitcoin account address.
24
+ * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
25
+ */
26
+ async getBtcAccount(): Promise<string> {
17
27
  return (await this.provider.getAccounts())[0];
18
28
  }
19
29
 
30
+ /**
31
+ * Gets the Bitcoin public key.
32
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
33
+ */
20
34
  async getBtcPublicKey(): Promise<ccc.Hex> {
21
35
  return ccc.hexFrom(await this.provider.getPublicKey());
22
36
  }
23
37
 
38
+ /**
39
+ * Connects to the provider by requesting accounts.
40
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
41
+ */
24
42
  async connect(): Promise<void> {
25
43
  await this.provider.requestAccounts();
26
44
  }
27
45
 
46
+ /**
47
+ * Checks if the signer is connected.
48
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
49
+ */
28
50
  async isConnected(): Promise<boolean> {
29
51
  return (await this.provider.getAccounts()).length !== 0;
30
52
  }
31
53
 
54
+ /**
55
+ * Signs a raw message with the Bitcoin account.
56
+ * @param {string | ccc.BytesLike} message - The message to sign.
57
+ * @returns {Promise<string>} A promise that resolves to the signed message.
58
+ */
32
59
  async signMessageRaw(message: string | ccc.BytesLike): Promise<string> {
33
60
  const challenge =
34
61
  typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
@@ -2,11 +2,16 @@ import { ccc } from "@ckb-ccc/core";
2
2
  import { Provider } from "./advancedBarrel";
3
3
  import { Signer } from "./signer";
4
4
 
5
+ /**
6
+ * Retrieves the UniSat signer if available.
7
+ * @param {ccc.Client} client - The client instance.
8
+ * @returns {Signer | undefined} The Signer instance if the UniSat provider is available, otherwise undefined.
9
+ */
5
10
  export function getUniSatSigner(client: ccc.Client): Signer | undefined {
6
11
  const windowRef = window as { unisat?: Provider };
7
12
 
8
13
  if (typeof windowRef.unisat === "undefined") {
9
- return;
14
+ return undefined;
10
15
  }
11
16
 
12
17
  return new Signer(client, windowRef.unisat);