@ckb-ccc/uni-sat 1.0.32 → 1.1.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/advanced.d.mts +2 -0
  3. package/dist/advanced.mjs +1 -0
  4. package/dist/advancedBarrel-6fyDO_pc.d.mts +100 -0
  5. package/dist/advancedBarrel-6fyDO_pc.d.mts.map +1 -0
  6. package/dist/advancedBarrel.d.mts +2 -0
  7. package/dist/advancedBarrel.mjs +2 -0
  8. package/dist/advancedBarrel.mjs.map +1 -0
  9. package/dist/barrel.d.mts +81 -0
  10. package/dist/barrel.d.mts.map +1 -0
  11. package/dist/barrel.mjs +2 -0
  12. package/dist/barrel.mjs.map +1 -0
  13. package/dist/index.d.mts +2 -0
  14. package/dist/index.mjs +1 -0
  15. package/dist/rolldown-runtime-DK3Fl9T5.mjs +1 -0
  16. package/dist.commonjs/advanced.d.ts +2 -2
  17. package/dist.commonjs/advanced.js +1 -37
  18. package/dist.commonjs/advancedBarrel-C8SL2uu7.d.ts +100 -0
  19. package/dist.commonjs/advancedBarrel-C8SL2uu7.d.ts.map +1 -0
  20. package/dist.commonjs/advancedBarrel.d.ts +2 -77
  21. package/dist.commonjs/advancedBarrel.js +2 -2
  22. package/dist.commonjs/advancedBarrel.js.map +1 -0
  23. package/dist.commonjs/barrel.d.ts +80 -2
  24. package/dist.commonjs/barrel.d.ts.map +1 -1
  25. package/dist.commonjs/barrel.js +2 -18
  26. package/dist.commonjs/barrel.js.map +1 -0
  27. package/dist.commonjs/index.d.ts +2 -2
  28. package/dist.commonjs/index.js +1 -37
  29. package/dist.commonjs/rolldown-runtime-BIInC43l.js +1 -0
  30. package/package.json +26 -29
  31. package/src/advancedBarrel.ts +19 -0
  32. package/src/signer.ts +30 -0
  33. package/tsdown.config.mts +43 -0
  34. package/dist/advanced.d.ts +0 -2
  35. package/dist/advanced.d.ts.map +0 -1
  36. package/dist/advanced.js +0 -1
  37. package/dist/advancedBarrel.d.ts +0 -77
  38. package/dist/advancedBarrel.d.ts.map +0 -1
  39. package/dist/advancedBarrel.js +0 -1
  40. package/dist/barrel.d.ts +0 -3
  41. package/dist/barrel.d.ts.map +0 -1
  42. package/dist/barrel.js +0 -2
  43. package/dist/index.d.ts +0 -2
  44. package/dist/index.d.ts.map +0 -1
  45. package/dist/index.js +0 -1
  46. package/dist/signer.d.ts +0 -49
  47. package/dist/signer.d.ts.map +0 -1
  48. package/dist/signer.js +0 -127
  49. package/dist/signersFactory.d.ts +0 -10
  50. package/dist/signersFactory.d.ts.map +0 -1
  51. package/dist/signersFactory.js +0 -20
  52. package/dist.commonjs/advanced.d.ts.map +0 -1
  53. package/dist.commonjs/advancedBarrel.d.ts.map +0 -1
  54. package/dist.commonjs/index.d.ts.map +0 -1
  55. package/dist.commonjs/signer.d.ts +0 -49
  56. package/dist.commonjs/signer.d.ts.map +0 -1
  57. package/dist.commonjs/signer.js +0 -131
  58. package/dist.commonjs/signersFactory.d.ts +0 -10
  59. package/dist.commonjs/signersFactory.d.ts.map +0 -1
  60. package/dist.commonjs/signersFactory.js +0 -23
@@ -1,49 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { Provider } from "./advancedBarrel.js";
3
- /**
4
- * Class representing a Bitcoin signer that extends SignerBtc
5
- * @public
6
- */
7
- export declare class Signer extends ccc.SignerBtc {
8
- readonly provider: Provider;
9
- private readonly preferredNetworks;
10
- /**
11
- * Creates an instance of Signer.
12
- * @param client - The client instance.
13
- * @param provider - The provider instance.
14
- */
15
- constructor(client: ccc.Client, provider: Provider, preferredNetworks?: ccc.NetworkPreference[]);
16
- _getNetworkToChange(): Promise<string | undefined>;
17
- /**
18
- * Ensure the BTC network is the same as CKB network.
19
- */
20
- ensureNetwork(): Promise<void>;
21
- /**
22
- * Gets the Bitcoin account address.
23
- * @returns A promise that resolves to the Bitcoin account address.
24
- */
25
- getBtcAccount(): Promise<string>;
26
- /**
27
- * Gets the Bitcoin public key.
28
- * @returns A promise that resolves to the Bitcoin public key.
29
- */
30
- getBtcPublicKey(): Promise<ccc.Hex>;
31
- /**
32
- * Connects to the provider by requesting accounts.
33
- * @returns A promise that resolves when the connection is established.
34
- */
35
- connect(): Promise<void>;
36
- onReplaced(listener: () => void): () => void;
37
- /**
38
- * Checks if the signer is connected.
39
- * @returns A promise that resolves to true if connected, false otherwise.
40
- */
41
- isConnected(): Promise<boolean>;
42
- /**
43
- * Signs a raw message with the Bitcoin account.
44
- * @param message - The message to sign.
45
- * @returns A promise that resolves to the signed message.
46
- */
47
- signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
48
- }
49
- //# sourceMappingURL=signer.d.ts.map
@@ -1 +0,0 @@
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,qBAAqB,CAAC;AAE/C;;;GAGG;AACH,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAQrB,QAAQ,EAAE,QAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IARpC;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ,EACjB,iBAAiB,GAAE,GAAG,CAAC,iBAAiB,EAWxD;IAKG,mBAAmB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA0BxD;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IA2BpC;;;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;IAK9B,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAiB5C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAOrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAMvE"}
@@ -1,131 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Signer = void 0;
4
- const core_1 = require("@ckb-ccc/core");
5
- /**
6
- * Class representing a Bitcoin signer that extends SignerBtc
7
- * @public
8
- */
9
- class Signer extends core_1.ccc.SignerBtc {
10
- /**
11
- * Creates an instance of Signer.
12
- * @param client - The client instance.
13
- * @param provider - The provider instance.
14
- */
15
- constructor(client, provider, preferredNetworks = [
16
- {
17
- addressPrefix: "ckb",
18
- signerType: core_1.ccc.SignerType.BTC,
19
- network: "btc",
20
- },
21
- {
22
- addressPrefix: "ckt",
23
- signerType: core_1.ccc.SignerType.BTC,
24
- network: "btcTestnet",
25
- },
26
- ]) {
27
- super(client);
28
- this.provider = provider;
29
- this.preferredNetworks = preferredNetworks;
30
- }
31
- async _getNetworkToChange() {
32
- const currentNetwork = await (async () => {
33
- if (this.provider.getChain) {
34
- return ({
35
- BITCOIN_MAINNET: "btc",
36
- BITCOIN_TESTNET: "btcTestnet",
37
- FRACTAL_BITCOIN_MAINNET: "fractalBtc",
38
- }[(await this.provider.getChain()).enum] ?? "");
39
- }
40
- return (await this.provider.getNetwork()) === "livenet"
41
- ? "btc"
42
- : "btcTestnet";
43
- })();
44
- const { network } = this.matchNetworkPreference(this.preferredNetworks, currentNetwork) ?? { network: currentNetwork };
45
- if (network === currentNetwork) {
46
- return;
47
- }
48
- return network;
49
- }
50
- /**
51
- * Ensure the BTC network is the same as CKB network.
52
- */
53
- async ensureNetwork() {
54
- const network = await this._getNetworkToChange();
55
- if (!network) {
56
- return;
57
- }
58
- if (this.provider.switchChain) {
59
- const chain = {
60
- btc: "BITCOIN_MAINNET",
61
- btcTestnet: "BITCOIN_TESTNET",
62
- fractalBtc: "FRACTAL_BITCOIN_MAINNET",
63
- }[network];
64
- if (chain) {
65
- await this.provider.switchChain(chain);
66
- return;
67
- }
68
- }
69
- else if (network === "btc" || network === "btcTestnet") {
70
- await this.provider.switchNetwork(network === "btc" ? "livenet" : "testnet");
71
- return;
72
- }
73
- throw new Error(`UniSat wallet doesn't support the requested chain ${network}`);
74
- }
75
- /**
76
- * Gets the Bitcoin account address.
77
- * @returns A promise that resolves to the Bitcoin account address.
78
- */
79
- async getBtcAccount() {
80
- return (await this.provider.getAccounts())[0];
81
- }
82
- /**
83
- * Gets the Bitcoin public key.
84
- * @returns A promise that resolves to the Bitcoin public key.
85
- */
86
- async getBtcPublicKey() {
87
- return core_1.ccc.hexFrom(await this.provider.getPublicKey());
88
- }
89
- /**
90
- * Connects to the provider by requesting accounts.
91
- * @returns A promise that resolves when the connection is established.
92
- */
93
- async connect() {
94
- await this.provider.requestAccounts();
95
- await this.ensureNetwork();
96
- }
97
- onReplaced(listener) {
98
- const stop = [];
99
- const replacer = async () => {
100
- listener();
101
- stop[0]?.();
102
- };
103
- stop.push(() => {
104
- this.provider.removeListener("accountsChanged", replacer);
105
- this.provider.removeListener("networkChanged", replacer);
106
- });
107
- this.provider.on("accountsChanged", replacer);
108
- this.provider.on("networkChanged", replacer);
109
- return stop[0];
110
- }
111
- /**
112
- * Checks if the signer is connected.
113
- * @returns A promise that resolves to true if connected, false otherwise.
114
- */
115
- async isConnected() {
116
- if (await this._getNetworkToChange()) {
117
- return false;
118
- }
119
- return (await this.provider.getAccounts()).length !== 0;
120
- }
121
- /**
122
- * Signs a raw message with the Bitcoin account.
123
- * @param message - The message to sign.
124
- * @returns A promise that resolves to the signed message.
125
- */
126
- async signMessageRaw(message) {
127
- const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
128
- return this.provider.signMessage(challenge, "ecdsa");
129
- }
130
- }
131
- exports.Signer = Signer;
@@ -1,10 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- /**
3
- * Retrieves the UniSat signer if available.
4
- * @public
5
- *
6
- * @param client - The client instance.
7
- * @returns The Signer instance if the UniSat provider is available, otherwise undefined.
8
- */
9
- export declare function getUniSatSigners(client: ccc.Client, preferredNetworks?: ccc.NetworkPreference[]): ccc.SignerInfo[];
10
- //# sourceMappingURL=signersFactory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,iBAAiB,CAAC,EAAE,GAAG,CAAC,iBAAiB,EAAE,GAC1C,GAAG,CAAC,UAAU,EAAE,CAalB"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUniSatSigners = getUniSatSigners;
4
- const signer_js_1 = require("./signer.js");
5
- /**
6
- * Retrieves the UniSat signer if available.
7
- * @public
8
- *
9
- * @param client - The client instance.
10
- * @returns The Signer instance if the UniSat provider is available, otherwise undefined.
11
- */
12
- function getUniSatSigners(client, preferredNetworks) {
13
- const windowRef = window;
14
- if (typeof windowRef.unisat === "undefined") {
15
- return [];
16
- }
17
- return [
18
- {
19
- signer: new signer_js_1.Signer(client, windowRef.unisat, preferredNetworks),
20
- name: "BTC",
21
- },
22
- ];
23
- }