@ckb-ccc/joy-id 0.0.12-alpha.1 → 0.0.12
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/CHANGELOG.md +8 -0
- package/README.md +5 -5
- package/dist/btc/index.d.ts +9 -12
- package/dist/btc/index.d.ts.map +1 -1
- package/dist/btc/index.js +9 -12
- package/dist/ckb/index.d.ts +26 -33
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +26 -33
- package/dist/common/index.d.ts +3 -4
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +3 -3
- package/dist/connectionsStorage/index.d.ts +31 -26
- package/dist/connectionsStorage/index.d.ts.map +1 -1
- package/dist/connectionsStorage/index.js +11 -13
- package/dist/evm/index.d.ts +11 -16
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +11 -16
- package/dist/nostr/index.d.ts +9 -14
- package/dist/nostr/index.d.ts.map +1 -1
- package/dist/nostr/index.js +9 -14
- package/dist/signerFactory/index.d.ts +6 -4
- package/dist/signerFactory/index.d.ts.map +1 -1
- package/dist/signerFactory/index.js +6 -4
- package/dist.commonjs/btc/index.d.ts +9 -12
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +9 -12
- package/dist.commonjs/ckb/index.d.ts +26 -33
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +26 -33
- package/dist.commonjs/common/index.d.ts +3 -4
- package/dist.commonjs/common/index.d.ts.map +1 -1
- package/dist.commonjs/common/index.js +3 -3
- package/dist.commonjs/connectionsStorage/index.d.ts +31 -26
- package/dist.commonjs/connectionsStorage/index.d.ts.map +1 -1
- package/dist.commonjs/connectionsStorage/index.js +11 -13
- package/dist.commonjs/evm/index.d.ts +11 -16
- package/dist.commonjs/evm/index.d.ts.map +1 -1
- package/dist.commonjs/evm/index.js +11 -16
- package/dist.commonjs/nostr/index.d.ts +9 -14
- package/dist.commonjs/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/nostr/index.js +9 -14
- package/dist.commonjs/signerFactory/index.d.ts +6 -4
- package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
- package/dist.commonjs/signerFactory/index.js +6 -4
- package/package.json +9 -10
- package/src/btc/index.ts +9 -12
- package/src/ckb/index.ts +26 -33
- package/src/common/index.ts +3 -4
- package/src/connectionsStorage/index.ts +31 -26
- package/src/evm/index.ts +11 -16
- package/src/nostr/index.ts +9 -14
- package/src/signerFactory/index.ts +6 -4
- package/typedoc.json +6 -0
package/src/common/index.ts
CHANGED
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Interface representing the return type for various Dapp request types.
|
|
21
|
-
* @interface
|
|
22
21
|
*/
|
|
23
22
|
export interface PopupReturnType {
|
|
24
23
|
[DappRequestType.Auth]: AuthResponseData;
|
|
@@ -42,9 +41,9 @@ export interface PopupReturnType {
|
|
|
42
41
|
|
|
43
42
|
/**
|
|
44
43
|
* Creates a popup window for JoyID Dapp requests.
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
-
* @returns
|
|
44
|
+
* @param url - The URL to open in the popup.
|
|
45
|
+
* @param config - The popup configuration options.
|
|
46
|
+
* @returns A promise that resolves to the response data of the requested type.
|
|
48
47
|
* @throws {PopupNotSupportedError} If popups are not supported in the current browser.
|
|
49
48
|
* @throws {PopupCancelledError} If the popup is closed by the user.
|
|
50
49
|
* @throws {PopupTimeoutError} If the popup operation times out.
|
|
@@ -2,20 +2,23 @@ import { ccc } from "@ckb-ccc/core";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Type representing an account selector with a URI and address type.
|
|
5
|
-
* @typedef {Object} AccountSelector
|
|
6
|
-
* @property {string} uri - The URI of the account.
|
|
7
|
-
* @property {string} addressType - The address type of the account.
|
|
8
5
|
*/
|
|
9
6
|
export type AccountSelector = {
|
|
7
|
+
/**
|
|
8
|
+
* The URI of the account.
|
|
9
|
+
*/
|
|
10
10
|
uri: string;
|
|
11
|
+
/**
|
|
12
|
+
* The address type of the account.
|
|
13
|
+
*/
|
|
11
14
|
addressType: string;
|
|
12
15
|
};
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
|
-
* Checks if
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @returns
|
|
18
|
+
* Checks if a AccountSelector matches the filter
|
|
19
|
+
* @param a - The first account selector.
|
|
20
|
+
* @param filter - The account selector filter.
|
|
21
|
+
* @returns True if the selector matches the filter
|
|
19
22
|
*/
|
|
20
23
|
export function isSelectorMatch(
|
|
21
24
|
a: AccountSelector,
|
|
@@ -26,34 +29,38 @@ export function isSelectorMatch(
|
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* Type representing a connection with an address, public key, and key type.
|
|
29
|
-
* @typedef {Object} Connection
|
|
30
|
-
* @property {string} address - The address of the connection.
|
|
31
|
-
* @property {ccc.Hex} publicKey - The public key of the connection.
|
|
32
|
-
* @property {string} keyType - The key type of the connection.
|
|
33
32
|
*/
|
|
34
33
|
export type Connection = {
|
|
34
|
+
/**
|
|
35
|
+
* The address of the connection.
|
|
36
|
+
*/
|
|
35
37
|
readonly address: string;
|
|
38
|
+
/**
|
|
39
|
+
* The public key of the connection.
|
|
40
|
+
*/
|
|
36
41
|
readonly publicKey: ccc.Hex;
|
|
42
|
+
/**
|
|
43
|
+
* The key type of the connection.
|
|
44
|
+
*/
|
|
37
45
|
readonly keyType: string;
|
|
38
46
|
};
|
|
39
47
|
|
|
40
48
|
/**
|
|
41
49
|
* Interface representing a repository for managing connections.
|
|
42
|
-
* @interface
|
|
43
50
|
*/
|
|
44
51
|
export interface ConnectionsRepo {
|
|
45
52
|
/**
|
|
46
53
|
* Gets a connection for the given selector.
|
|
47
|
-
* @param
|
|
48
|
-
* @returns
|
|
54
|
+
* @param selector - The account selector.
|
|
55
|
+
* @returns A promise that resolves to the connection, if found.
|
|
49
56
|
*/
|
|
50
57
|
get(selector: AccountSelector): Promise<Connection | undefined>;
|
|
51
58
|
|
|
52
59
|
/**
|
|
53
60
|
* Sets a connection for the given selector.
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* @returns
|
|
61
|
+
* @param selector - The account selector.
|
|
62
|
+
* @param connection - The connection to set.
|
|
63
|
+
* @returns A promise that resolves when the connection is set.
|
|
57
64
|
*/
|
|
58
65
|
set(
|
|
59
66
|
selector: AccountSelector,
|
|
@@ -63,19 +70,17 @@ export interface ConnectionsRepo {
|
|
|
63
70
|
|
|
64
71
|
/**
|
|
65
72
|
* Class representing a local storage-based repository for managing connections.
|
|
66
|
-
* @class
|
|
67
|
-
* @implements {ConnectionsRepo}
|
|
68
73
|
*/
|
|
69
74
|
export class ConnectionsRepoLocalStorage implements ConnectionsRepo {
|
|
70
75
|
/**
|
|
71
76
|
* Creates an instance of ConnectionsRepoLocalStorage.
|
|
72
|
-
* @param
|
|
77
|
+
* @param [storageKey="ccc-joy-id-signer"] - The local storage key.
|
|
73
78
|
*/
|
|
74
79
|
constructor(private readonly storageKey = "ccc-joy-id-signer") {}
|
|
75
80
|
|
|
76
81
|
/**
|
|
77
82
|
* Reads all connections from local storage.
|
|
78
|
-
* @returns
|
|
83
|
+
* @returns A promise that resolves to an array of selectors and connections.
|
|
79
84
|
*/
|
|
80
85
|
async readConnections(): Promise<[AccountSelector, Connection][]> {
|
|
81
86
|
return JSON.parse(window.localStorage.getItem(this.storageKey) ?? "[]");
|
|
@@ -83,8 +88,8 @@ export class ConnectionsRepoLocalStorage implements ConnectionsRepo {
|
|
|
83
88
|
|
|
84
89
|
/**
|
|
85
90
|
* Gets a connection for the given selector.
|
|
86
|
-
* @param
|
|
87
|
-
* @returns
|
|
91
|
+
* @param selector - The account selector.
|
|
92
|
+
* @returns A promise that resolves to the connection, if found.
|
|
88
93
|
*/
|
|
89
94
|
async get(selector: AccountSelector): Promise<Connection | undefined> {
|
|
90
95
|
return (await this.readConnections()).find(([s]) =>
|
|
@@ -94,9 +99,9 @@ export class ConnectionsRepoLocalStorage implements ConnectionsRepo {
|
|
|
94
99
|
|
|
95
100
|
/**
|
|
96
101
|
* Sets a connection for the given selector.
|
|
97
|
-
* @param
|
|
98
|
-
* @param
|
|
99
|
-
* @returns
|
|
102
|
+
* @param selector - The account selector.
|
|
103
|
+
* @param connection - The connection to set.
|
|
104
|
+
* @returns
|
|
100
105
|
*/
|
|
101
106
|
async set(
|
|
102
107
|
selector: AccountSelector,
|
package/src/evm/index.ts
CHANGED
|
@@ -8,18 +8,16 @@ import {
|
|
|
8
8
|
} from "../connectionsStorage/index.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Class representing an EVM signer that extends SignerEvm
|
|
12
|
-
* @
|
|
13
|
-
* @extends {ccc.SignerEvm}
|
|
11
|
+
* Class representing an EVM signer that extends SignerEvm
|
|
12
|
+
* @public
|
|
14
13
|
*/
|
|
15
14
|
export class EvmSigner extends ccc.SignerEvm {
|
|
16
15
|
private connection?: Connection;
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Ensures that the signer is connected and returns the connection.
|
|
20
|
-
* @private
|
|
21
19
|
* @throws Will throw an error if not connected.
|
|
22
|
-
* @returns
|
|
20
|
+
* @returns The current connection.
|
|
23
21
|
*/
|
|
24
22
|
private assertConnection(): Connection {
|
|
25
23
|
if (!this.isConnected() || !this.connection) {
|
|
@@ -34,7 +32,7 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
34
32
|
* @param client - The client instance.
|
|
35
33
|
* @param name - The name of the signer.
|
|
36
34
|
* @param icon - The icon URL of the signer.
|
|
37
|
-
* @param
|
|
35
|
+
* @param _appUri - The application URI.
|
|
38
36
|
* @param connectionsRepo - The connections repository.
|
|
39
37
|
*/
|
|
40
38
|
constructor(
|
|
@@ -49,8 +47,7 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
49
47
|
|
|
50
48
|
/**
|
|
51
49
|
* Gets the configuration for JoyID.
|
|
52
|
-
* @
|
|
53
|
-
* @returns {object} The configuration object.
|
|
50
|
+
* @returns The configuration object.
|
|
54
51
|
*/
|
|
55
52
|
private getConfig() {
|
|
56
53
|
return {
|
|
@@ -75,7 +72,7 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
75
72
|
|
|
76
73
|
/**
|
|
77
74
|
* Connects to the provider by requesting authentication.
|
|
78
|
-
* @returns
|
|
75
|
+
* @returns A promise that resolves when the connection is established.
|
|
79
76
|
*/
|
|
80
77
|
async connect(): Promise<void> {
|
|
81
78
|
const config = this.getConfig();
|
|
@@ -102,7 +99,7 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
102
99
|
|
|
103
100
|
/**
|
|
104
101
|
* Checks if the signer is connected.
|
|
105
|
-
* @returns
|
|
102
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
106
103
|
*/
|
|
107
104
|
async isConnected(): Promise<boolean> {
|
|
108
105
|
if (this.connection) {
|
|
@@ -114,8 +111,8 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
114
111
|
|
|
115
112
|
/**
|
|
116
113
|
* Signs a raw message with the EVM account.
|
|
117
|
-
* @param
|
|
118
|
-
* @returns
|
|
114
|
+
* @param message - The message to sign.
|
|
115
|
+
* @returns A promise that resolves to the signed message.
|
|
119
116
|
*/
|
|
120
117
|
async signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex> {
|
|
121
118
|
const { address } = this.assertConnection();
|
|
@@ -142,8 +139,7 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
142
139
|
|
|
143
140
|
/**
|
|
144
141
|
* Saves the current connection.
|
|
145
|
-
* @
|
|
146
|
-
* @returns {Promise<void>}
|
|
142
|
+
* @returns
|
|
147
143
|
*/
|
|
148
144
|
private async saveConnection(): Promise<void> {
|
|
149
145
|
return this.connectionsRepo.set(
|
|
@@ -157,8 +153,7 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
157
153
|
|
|
158
154
|
/**
|
|
159
155
|
* Restores the previous connection.
|
|
160
|
-
* @
|
|
161
|
-
* @returns {Promise<void>}
|
|
156
|
+
* @returns
|
|
162
157
|
*/
|
|
163
158
|
private async restoreConnection(): Promise<void> {
|
|
164
159
|
this.connection = await this.connectionsRepo.get({
|
package/src/nostr/index.ts
CHANGED
|
@@ -8,18 +8,16 @@ import {
|
|
|
8
8
|
} from "../connectionsStorage/index.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Class representing a Nostr signer that extends SignerNostr
|
|
12
|
-
* @
|
|
13
|
-
* @extends {ccc.SignerNostr}
|
|
11
|
+
* Class representing a Nostr signer that extends SignerNostr
|
|
12
|
+
* @public
|
|
14
13
|
*/
|
|
15
14
|
export class NostrSigner extends ccc.SignerNostr {
|
|
16
15
|
private connection?: Connection;
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Ensures that the signer is connected and returns the connection.
|
|
20
|
-
* @private
|
|
21
19
|
* @throws Will throw an error if not connected.
|
|
22
|
-
* @returns
|
|
20
|
+
* @returns The current connection.
|
|
23
21
|
*/
|
|
24
22
|
private assertConnection(): Connection {
|
|
25
23
|
if (!this.isConnected() || !this.connection) {
|
|
@@ -34,7 +32,7 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
34
32
|
* @param client - The client instance.
|
|
35
33
|
* @param name - The name of the signer.
|
|
36
34
|
* @param icon - The icon URL of the signer.
|
|
37
|
-
* @param
|
|
35
|
+
* @param _appUri - The application URI.
|
|
38
36
|
* @param connectionsRepo - The connections repository.
|
|
39
37
|
*/
|
|
40
38
|
constructor(
|
|
@@ -49,8 +47,7 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
49
47
|
|
|
50
48
|
/**
|
|
51
49
|
* Gets the configuration for JoyID.
|
|
52
|
-
* @
|
|
53
|
-
* @returns {object} The configuration object.
|
|
50
|
+
* @returns The configuration object.
|
|
54
51
|
*/
|
|
55
52
|
private getConfig() {
|
|
56
53
|
return {
|
|
@@ -67,7 +64,7 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
67
64
|
|
|
68
65
|
/**
|
|
69
66
|
* Connects to the provider by requesting authentication.
|
|
70
|
-
* @returns
|
|
67
|
+
* @returns A promise that resolves when the connection is established.
|
|
71
68
|
*/
|
|
72
69
|
async connect(): Promise<void> {
|
|
73
70
|
const config = this.getConfig();
|
|
@@ -93,7 +90,7 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
93
90
|
|
|
94
91
|
/**
|
|
95
92
|
* Checks if the signer is connected.
|
|
96
|
-
* @returns
|
|
93
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
97
94
|
*/
|
|
98
95
|
async isConnected(): Promise<boolean> {
|
|
99
96
|
if (this.connection) {
|
|
@@ -124,8 +121,7 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
124
121
|
|
|
125
122
|
/**
|
|
126
123
|
* Saves the current connection.
|
|
127
|
-
* @
|
|
128
|
-
* @returns {Promise<void>}
|
|
124
|
+
* @returns
|
|
129
125
|
*/
|
|
130
126
|
private async saveConnection(): Promise<void> {
|
|
131
127
|
return this.connectionsRepo.set(
|
|
@@ -139,8 +135,7 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
139
135
|
|
|
140
136
|
/**
|
|
141
137
|
* Restores the previous connection.
|
|
142
|
-
* @
|
|
143
|
-
* @returns {Promise<void>}
|
|
138
|
+
* @returns
|
|
144
139
|
*/
|
|
145
140
|
private async restoreConnection(): Promise<void> {
|
|
146
141
|
this.connection = await this.connectionsRepo.get({
|
|
@@ -9,10 +9,12 @@ import { NostrSigner } from "../nostr/index.js";
|
|
|
9
9
|
* Gets the JoyID signers based on the client, name, and icon.
|
|
10
10
|
* If the browser is standalone or a webview, returns SignerAlwaysError instances.
|
|
11
11
|
* Otherwise, returns instances of CkbSigner, BitcoinSigner, and EvmSigner.
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
14
|
-
* @param
|
|
15
|
-
* @
|
|
12
|
+
* @public
|
|
13
|
+
*
|
|
14
|
+
* @param client - The client instance.
|
|
15
|
+
* @param name - The name of the signer.
|
|
16
|
+
* @param icon - The icon URL of the signer.
|
|
17
|
+
* @returns An array of signer information objects.
|
|
16
18
|
*/
|
|
17
19
|
export function getJoyIdSigners(
|
|
18
20
|
client: ccc.Client,
|