@ckb-ccc/uni-sat 0.0.5-alpha.8 → 0.0.6-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.
- package/dist/advancedBarrel.d.ts +42 -0
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/signer.d.ts +31 -1
- package/dist/signer.d.ts.map +1 -1
- package/dist/signer.js +31 -3
- package/dist/signersFactory.d.ts +5 -0
- package/dist/signersFactory.d.ts.map +1 -1
- package/dist/signersFactory.js +6 -1
- package/dist.commonjs/advancedBarrel.d.ts +42 -0
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
- package/dist.commonjs/signer.d.ts +31 -1
- package/dist.commonjs/signer.d.ts.map +1 -1
- package/dist.commonjs/signer.js +31 -3
- package/dist.commonjs/signersFactory.d.ts +5 -0
- package/dist.commonjs/signersFactory.d.ts.map +1 -1
- package/dist.commonjs/signersFactory.js +6 -1
- package/package.json +3 -3
- package/src/advancedBarrel.ts +46 -0
- package/src/signer.ts +32 -5
- package/src/signersFactory.ts +6 -1
package/dist/advancedBarrel.d.ts
CHANGED
|
@@ -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;
|
|
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
|
-
|
|
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
|
package/dist/signer.d.ts.map
CHANGED
|
@@ -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;
|
|
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
|
-
|
|
8
|
-
|
|
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");
|
package/dist/signersFactory.d.ts
CHANGED
|
@@ -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"}
|
package/dist/signersFactory.js
CHANGED
|
@@ -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,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;
|
|
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,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
|
-
|
|
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;
|
|
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.commonjs/signer.js
CHANGED
|
@@ -2,26 +2,54 @@
|
|
|
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 {
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of Signer.
|
|
13
|
+
* @param {ccc.Client} client - The client instance.
|
|
14
|
+
* @param {Provider} provider - The provider instance.
|
|
15
|
+
*/
|
|
6
16
|
constructor(client, provider) {
|
|
7
17
|
super(client);
|
|
8
18
|
this.provider = provider;
|
|
9
19
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Gets the Bitcoin account address.
|
|
22
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
23
|
+
*/
|
|
13
24
|
async getBtcAccount() {
|
|
14
25
|
return (await this.provider.getAccounts())[0];
|
|
15
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Gets the Bitcoin public key.
|
|
29
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
30
|
+
*/
|
|
16
31
|
async getBtcPublicKey() {
|
|
17
32
|
return core_1.ccc.hexFrom(await this.provider.getPublicKey());
|
|
18
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Connects to the provider by requesting accounts.
|
|
36
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
37
|
+
*/
|
|
19
38
|
async connect() {
|
|
20
39
|
await this.provider.requestAccounts();
|
|
21
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the signer is connected.
|
|
43
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
44
|
+
*/
|
|
22
45
|
async isConnected() {
|
|
23
46
|
return (await this.provider.getAccounts()).length !== 0;
|
|
24
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
|
+
*/
|
|
25
53
|
async signMessageRaw(message) {
|
|
26
54
|
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
27
55
|
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"}
|
|
@@ -2,10 +2,15 @@
|
|
|
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
11
|
const windowRef = window;
|
|
7
12
|
if (typeof windowRef.unisat === "undefined") {
|
|
8
|
-
return;
|
|
13
|
+
return undefined;
|
|
9
14
|
}
|
|
10
15
|
return new signer_1.Signer(client, windowRef.unisat);
|
|
11
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/uni-sat",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6-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.
|
|
53
|
+
"@ckb-ccc/core": "0.0.6-alpha.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "2cbb4f450ed88e773a353a13ad006dbe6208f67f"
|
|
56
56
|
}
|
package/src/advancedBarrel.ts
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
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);
|
package/src/signersFactory.ts
CHANGED
|
@@ -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);
|