@ckb-ccc/joy-id 0.0.8-alpha.3 → 0.0.9-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/btc/index.d.ts +16 -12
- package/dist/btc/index.d.ts.map +1 -1
- package/dist/btc/index.js +38 -13
- package/dist/ckb/index.d.ts +3 -1
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +14 -2
- package/dist/connectionsStorage/index.d.ts +1 -1
- package/dist/connectionsStorage/index.d.ts.map +1 -1
- package/dist/connectionsStorage/index.js +5 -5
- package/dist/evm/index.d.ts +9 -7
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +22 -8
- package/dist/nostr/index.d.ts +20 -8
- package/dist/nostr/index.d.ts.map +1 -1
- package/dist/nostr/index.js +42 -18
- package/dist/signerFactory/index.d.ts +1 -1
- package/dist/signerFactory/index.d.ts.map +1 -1
- package/dist/signerFactory/index.js +4 -4
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +19 -40
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +14 -30
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +14 -30
- package/dist.commonjs/btc/index.d.ts +60 -63
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +139 -140
- package/dist.commonjs/ckb/index.d.ts +116 -121
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +262 -307
- package/dist.commonjs/common/index.d.ts +21 -34
- package/dist.commonjs/common/index.js +45 -50
- package/dist.commonjs/connectionsStorage/index.d.ts +44 -53
- package/dist.commonjs/connectionsStorage/index.d.ts.map +1 -1
- package/dist.commonjs/connectionsStorage/index.js +47 -50
- package/dist.commonjs/evm/index.d.ts +63 -67
- package/dist.commonjs/evm/index.d.ts.map +1 -1
- package/dist.commonjs/evm/index.js +127 -135
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +19 -40
- package/dist.commonjs/nostr/index.d.ts +54 -48
- package/dist.commonjs/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/nostr/index.js +113 -108
- package/dist.commonjs/signerFactory/index.d.ts +2 -6
- package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
- package/dist.commonjs/signerFactory/index.js +32 -43
- package/package.json +3 -3
- package/src/btc/index.ts +53 -15
- package/src/ckb/index.ts +17 -2
- package/src/connectionsStorage/index.ts +10 -5
- package/src/evm/index.ts +25 -7
- package/src/nostr/index.ts +49 -21
- package/src/signerFactory/index.ts +10 -3
|
@@ -11,116 +11,121 @@ const connectionsStorage_1 = require("../connectionsStorage");
|
|
|
11
11
|
* @extends {ccc.SignerNostr}
|
|
12
12
|
*/
|
|
13
13
|
class NostrSigner extends core_1.ccc.SignerNostr {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Ensures that the signer is connected and returns the connection.
|
|
16
|
+
* @private
|
|
17
|
+
* @throws Will throw an error if not connected.
|
|
18
|
+
* @returns {Connection} The current connection.
|
|
19
|
+
*/
|
|
20
|
+
assertConnection() {
|
|
21
|
+
if (!this.isConnected() || !this.connection) {
|
|
22
|
+
throw new Error("Not connected");
|
|
23
|
+
}
|
|
24
|
+
return this.connection;
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
appUri = "https://app.joy.id",
|
|
39
|
-
connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage(),
|
|
40
|
-
) {
|
|
41
|
-
super(client);
|
|
42
|
-
this.name = name;
|
|
43
|
-
this.icon = icon;
|
|
44
|
-
this.appUri = appUri;
|
|
45
|
-
this.connectionsRepo = connectionsRepo;
|
|
46
|
-
}
|
|
47
|
-
static isValidClient(client) {
|
|
48
|
-
return client.addressPrefix === "ckt";
|
|
49
|
-
}
|
|
50
|
-
async replaceClient(client) {
|
|
51
|
-
if (!NostrSigner.isValidClient(client)) {
|
|
52
|
-
return false;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of NostrSigner.
|
|
28
|
+
* @param client - The client instance.
|
|
29
|
+
* @param name - The name of the signer.
|
|
30
|
+
* @param icon - The icon URL of the signer.
|
|
31
|
+
* @param appUri - The application URI.
|
|
32
|
+
* @param connectionsRepo - The connections repository.
|
|
33
|
+
*/
|
|
34
|
+
constructor(client, name, icon, _appUri, connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
|
|
35
|
+
super(client);
|
|
36
|
+
this.name = name;
|
|
37
|
+
this.icon = icon;
|
|
38
|
+
this._appUri = _appUri;
|
|
39
|
+
this.connectionsRepo = connectionsRepo;
|
|
53
40
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
41
|
+
async replaceClient(client) {
|
|
42
|
+
if (!(await super.replaceClient(client))) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
this.connection = undefined;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the configuration for JoyID.
|
|
50
|
+
* @private
|
|
51
|
+
* @returns {object} The configuration object.
|
|
52
|
+
*/
|
|
53
|
+
getConfig() {
|
|
54
|
+
return {
|
|
55
|
+
redirectURL: location.href,
|
|
56
|
+
joyidAppURL: this._appUri ?? this.client.addressPrefix === "ckb"
|
|
57
|
+
? "https://app.joy.id"
|
|
58
|
+
: "https://testnet.joyid.dev",
|
|
59
|
+
requestNetwork: "nostr",
|
|
60
|
+
name: this.name,
|
|
61
|
+
logo: this.icon,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Connects to the provider by requesting authentication.
|
|
66
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
67
|
+
*/
|
|
68
|
+
async connect() {
|
|
69
|
+
const config = this.getConfig();
|
|
70
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
|
|
71
|
+
...config,
|
|
72
|
+
type: common_1.DappRequestType.Auth,
|
|
73
|
+
});
|
|
74
|
+
this.connection = {
|
|
75
|
+
address: "",
|
|
76
|
+
publicKey: core_1.ccc.hexFrom(res.nostrPubkey),
|
|
77
|
+
keyType: res.keyType,
|
|
78
|
+
};
|
|
79
|
+
await this.saveConnection();
|
|
80
|
+
}
|
|
81
|
+
async disconnect() {
|
|
82
|
+
await super.disconnect();
|
|
83
|
+
this.connection = undefined;
|
|
84
|
+
await this.saveConnection();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Checks if the signer is connected.
|
|
88
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
89
|
+
*/
|
|
90
|
+
async isConnected() {
|
|
91
|
+
if (this.connection) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
await this.restoreConnection();
|
|
95
|
+
return this.connection !== undefined;
|
|
96
|
+
}
|
|
97
|
+
async getNostrPublicKey() {
|
|
98
|
+
return this.assertConnection().publicKey;
|
|
99
|
+
}
|
|
100
|
+
async signNostrEvent(event) {
|
|
101
|
+
const config = this.getConfig();
|
|
102
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({ ...config, event }, "popup", "/sign-nostr-event"), {
|
|
103
|
+
...config,
|
|
104
|
+
type: common_1.DappRequestType.SignNostrEvent,
|
|
105
|
+
});
|
|
106
|
+
return res.event;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Saves the current connection.
|
|
110
|
+
* @private
|
|
111
|
+
* @returns {Promise<void>}
|
|
112
|
+
*/
|
|
113
|
+
async saveConnection() {
|
|
114
|
+
return this.connectionsRepo.set({
|
|
115
|
+
uri: this.getConfig().joyidAppURL,
|
|
116
|
+
addressType: "nostr",
|
|
117
|
+
}, this.connection);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Restores the previous connection.
|
|
121
|
+
* @private
|
|
122
|
+
* @returns {Promise<void>}
|
|
123
|
+
*/
|
|
124
|
+
async restoreConnection() {
|
|
125
|
+
this.connection = await this.connectionsRepo.get({
|
|
126
|
+
uri: this.getConfig().joyidAppURL,
|
|
127
|
+
addressType: "nostr",
|
|
128
|
+
});
|
|
100
129
|
}
|
|
101
|
-
this.connection = await this.connectionsRepo.get({
|
|
102
|
-
uri: this.appUri,
|
|
103
|
-
addressType: "nostr",
|
|
104
|
-
});
|
|
105
|
-
return this.connection !== undefined;
|
|
106
|
-
}
|
|
107
|
-
async getNostrPublicKey() {
|
|
108
|
-
return this.assertConnection().publicKey;
|
|
109
|
-
}
|
|
110
|
-
async signNostrEvent(event) {
|
|
111
|
-
const config = this.getConfig();
|
|
112
|
-
const res = await (0, common_2.createPopup)(
|
|
113
|
-
(0, common_1.buildJoyIDURL)(
|
|
114
|
-
{ ...config, event },
|
|
115
|
-
"popup",
|
|
116
|
-
"/sign-nostr-event",
|
|
117
|
-
),
|
|
118
|
-
{
|
|
119
|
-
...config,
|
|
120
|
-
type: common_1.DappRequestType.SignNostrEvent,
|
|
121
|
-
},
|
|
122
|
-
);
|
|
123
|
-
return res.event;
|
|
124
|
-
}
|
|
125
130
|
}
|
|
126
131
|
exports.NostrSigner = NostrSigner;
|
|
@@ -8,9 +8,5 @@ import { ccc } from "@ckb-ccc/core";
|
|
|
8
8
|
* @param {string} icon - The icon URL of the signer.
|
|
9
9
|
* @returns {ccc.SignerInfo[]} An array of signer information objects.
|
|
10
10
|
*/
|
|
11
|
-
export declare function getJoyIdSigners(
|
|
12
|
-
|
|
13
|
-
name: string,
|
|
14
|
-
icon: string,
|
|
15
|
-
): ccc.SignerInfo[];
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
|
11
|
+
export declare function getJoyIdSigners(client: ccc.Client, name: string, icon: string, preferredNetworks: ccc.NetworkPreference[]): ccc.SignerInfo[];
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signerFactory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAOpC;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signerFactory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAOpC;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,EAAE,GACzC,GAAG,CAAC,UAAU,EAAE,CA8ClB"}
|
|
@@ -16,49 +16,38 @@ const nostr_1 = require("../nostr");
|
|
|
16
16
|
* @param {string} icon - The icon URL of the signer.
|
|
17
17
|
* @returns {ccc.SignerInfo[]} An array of signer information objects.
|
|
18
18
|
*/
|
|
19
|
-
function getJoyIdSigners(client, name, icon) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
function getJoyIdSigners(client, name, icon, preferredNetworks) {
|
|
20
|
+
if ((0, common_1.isStandaloneBrowser)() || core_1.ccc.isWebview(window.navigator.userAgent)) {
|
|
21
|
+
return [core_1.ccc.SignerType.CKB, core_1.ccc.SignerType.EVM, core_1.ccc.SignerType.BTC].map((type) => ({
|
|
22
|
+
name: type,
|
|
23
|
+
signer: new core_1.ccc.SignerAlwaysError(client, type, "JoyID can only be used with standard browsers"),
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
24
26
|
return [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
name: "EVM",
|
|
52
|
-
signer: new evm_1.EvmSigner(client, name, icon),
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: "BTC (P2WPKH)",
|
|
56
|
-
signer: new btc_1.BitcoinSigner(client, name, icon, "p2wpkh"),
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: "BTC (P2TR)",
|
|
60
|
-
signer: new btc_1.BitcoinSigner(client, name, icon, "p2tr"),
|
|
61
|
-
},
|
|
62
|
-
];
|
|
27
|
+
{
|
|
28
|
+
name: "CKB",
|
|
29
|
+
signer: new ckb_1.CkbSigner(client, name, icon),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "BTC",
|
|
33
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, preferredNetworks),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "Nostr",
|
|
37
|
+
signer: new nostr_1.NostrSigner(client, name, icon),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "EVM",
|
|
41
|
+
signer: new evm_1.EvmSigner(client, name, icon),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "BTC (P2WPKH)",
|
|
45
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, preferredNetworks, "p2wpkh"),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "BTC (P2TR)",
|
|
49
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, preferredNetworks, "p2tr"),
|
|
50
|
+
},
|
|
51
|
+
];
|
|
63
52
|
}
|
|
64
53
|
exports.getJoyIdSigners = getJoyIdSigners;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/joy-id",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9-alpha.0",
|
|
4
4
|
"description": "Connector's support for JoyID",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@ckb-ccc/core": "0.0.
|
|
41
|
+
"@ckb-ccc/core": "0.0.9-alpha.0",
|
|
42
42
|
"@joyid/ckb": "^1.0.0",
|
|
43
43
|
"@joyid/common": "^0.2.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "ac4435006da9c9e48b3b66fc329e6f539156b252"
|
|
46
46
|
}
|
package/src/btc/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
*/
|
|
15
15
|
export class BitcoinSigner extends ccc.SignerBtc {
|
|
16
16
|
private connection?: Connection;
|
|
17
|
+
private network = "btcTestnet";
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Ensures that the signer is connected and returns the connection.
|
|
@@ -31,39 +32,76 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* Creates an instance of BitcoinSigner.
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
35
|
+
* @param client - The client instance.
|
|
36
|
+
* @param name - The name of the signer.
|
|
37
|
+
* @param icon - The icon URL of the signer.
|
|
38
|
+
* @param addressType - The address type.
|
|
39
|
+
* @param _appUri - The application URI.
|
|
40
|
+
* @param connectionsRepo - The connections repository.
|
|
40
41
|
*/
|
|
41
42
|
constructor(
|
|
42
43
|
client: ccc.Client,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
private readonly
|
|
46
|
-
|
|
44
|
+
public readonly name: string,
|
|
45
|
+
public readonly icon: string,
|
|
46
|
+
private readonly preferredNetworks: ccc.NetworkPreference[],
|
|
47
|
+
public readonly addressType: "auto" | "p2wpkh" | "p2tr" = "auto",
|
|
48
|
+
private readonly _appUri?: string,
|
|
47
49
|
private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),
|
|
48
50
|
) {
|
|
49
51
|
super(client);
|
|
50
52
|
}
|
|
51
53
|
|
|
54
|
+
async replaceClient(client: ccc.Client): Promise<boolean> {
|
|
55
|
+
if (!(await super.replaceClient(client))) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
this.connection = undefined;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
52
62
|
/**
|
|
53
63
|
* Gets the configuration for JoyID.
|
|
54
64
|
* @private
|
|
55
|
-
* @returns
|
|
65
|
+
* @returns The configuration object.
|
|
56
66
|
*/
|
|
57
67
|
private getConfig() {
|
|
68
|
+
const { network } = this.matchNetworkPreference(
|
|
69
|
+
this.preferredNetworks,
|
|
70
|
+
this.network,
|
|
71
|
+
) ?? { network: this.network };
|
|
72
|
+
if (this.network !== network) {
|
|
73
|
+
this.connection = undefined;
|
|
74
|
+
}
|
|
75
|
+
this.network = network;
|
|
76
|
+
|
|
77
|
+
const url = {
|
|
78
|
+
btc: "https://app.joy.id",
|
|
79
|
+
btcTestnet: "https://testnet.joyid.dev",
|
|
80
|
+
}[network];
|
|
81
|
+
if (!url) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`JoyID wallet doesn't support the requested chain ${this.network}`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
58
87
|
return {
|
|
59
88
|
redirectURL: location.href,
|
|
60
|
-
joyidAppURL: this.
|
|
89
|
+
joyidAppURL: this._appUri ?? url,
|
|
61
90
|
requestNetwork: `btc-${this.addressType}`,
|
|
62
91
|
name: this.name,
|
|
63
92
|
logo: this.icon,
|
|
64
93
|
};
|
|
65
94
|
}
|
|
66
95
|
|
|
96
|
+
async disconnect(): Promise<void> {
|
|
97
|
+
await super.disconnect();
|
|
98
|
+
|
|
99
|
+
await this.connectionsRepo.set(
|
|
100
|
+
{ uri: this.getConfig().joyidAppURL, addressType: "btc" },
|
|
101
|
+
undefined,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
67
105
|
/**
|
|
68
106
|
* Gets the Bitcoin account address.
|
|
69
107
|
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
@@ -107,11 +145,11 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
107
145
|
};
|
|
108
146
|
await Promise.all([
|
|
109
147
|
this.connectionsRepo.set(
|
|
110
|
-
{ uri:
|
|
148
|
+
{ uri: config.joyidAppURL, addressType: `btc-${res.btcAddressType}` },
|
|
111
149
|
this.connection,
|
|
112
150
|
),
|
|
113
151
|
this.connectionsRepo.set(
|
|
114
|
-
{ uri:
|
|
152
|
+
{ uri: config.joyidAppURL, addressType: "btc-auto" },
|
|
115
153
|
this.connection,
|
|
116
154
|
),
|
|
117
155
|
]);
|
|
@@ -127,7 +165,7 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
127
165
|
}
|
|
128
166
|
|
|
129
167
|
this.connection = await this.connectionsRepo.get({
|
|
130
|
-
uri: this.
|
|
168
|
+
uri: this.getConfig().joyidAppURL,
|
|
131
169
|
addressType: `btc-${this.addressType}`,
|
|
132
170
|
});
|
|
133
171
|
return this.connection !== undefined;
|
package/src/ckb/index.ts
CHANGED
|
@@ -66,10 +66,18 @@ export class CkbSigner extends ccc.Signer {
|
|
|
66
66
|
super(client);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
async replaceClient(client: ccc.Client): Promise<boolean> {
|
|
70
|
+
if (!(await super.replaceClient(client))) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
this.connection = undefined;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
69
77
|
/**
|
|
70
78
|
* Gets the configuration for JoyID.
|
|
71
79
|
* @private
|
|
72
|
-
* @returns
|
|
80
|
+
* @returns The configuration object.
|
|
73
81
|
*/
|
|
74
82
|
private getConfig() {
|
|
75
83
|
return {
|
|
@@ -118,6 +126,13 @@ export class CkbSigner extends ccc.Signer {
|
|
|
118
126
|
await this.saveConnection();
|
|
119
127
|
}
|
|
120
128
|
|
|
129
|
+
async disconnect(): Promise<void> {
|
|
130
|
+
await super.disconnect();
|
|
131
|
+
|
|
132
|
+
this.connection = undefined;
|
|
133
|
+
await this.saveConnection();
|
|
134
|
+
}
|
|
135
|
+
|
|
121
136
|
/**
|
|
122
137
|
* Checks if the signer is connected.
|
|
123
138
|
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
@@ -210,7 +225,7 @@ export class CkbSigner extends ccc.Signer {
|
|
|
210
225
|
return [];
|
|
211
226
|
}
|
|
212
227
|
|
|
213
|
-
const pubkeyHash = ccc.
|
|
228
|
+
const pubkeyHash = ccc.hashCkb(this.connection.publicKey).substring(0, 42);
|
|
214
229
|
const lock = (await this.getAddressObj()).script;
|
|
215
230
|
const aggregator = new Aggregator(this.getAggregatorUri());
|
|
216
231
|
const { unlock_entry: unlockEntry } =
|
|
@@ -17,8 +17,11 @@ export type AccountSelector = {
|
|
|
17
17
|
* @param {AccountSelector} b - The second account selector.
|
|
18
18
|
* @returns {boolean} True if the selectors are equal, false otherwise.
|
|
19
19
|
*/
|
|
20
|
-
export function
|
|
21
|
-
|
|
20
|
+
export function isSelectorMatch(
|
|
21
|
+
a: AccountSelector,
|
|
22
|
+
filter: AccountSelector,
|
|
23
|
+
): boolean {
|
|
24
|
+
return a.uri === filter.uri && a.addressType.startsWith(filter.addressType);
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
/**
|
|
@@ -85,7 +88,7 @@ export class ConnectionsRepoLocalStorage implements ConnectionsRepo {
|
|
|
85
88
|
*/
|
|
86
89
|
async get(selector: AccountSelector): Promise<Connection | undefined> {
|
|
87
90
|
return (await this.readConnections()).find(([s]) =>
|
|
88
|
-
|
|
91
|
+
isSelectorMatch(selector, s),
|
|
89
92
|
)?.[1];
|
|
90
93
|
}
|
|
91
94
|
|
|
@@ -102,7 +105,7 @@ export class ConnectionsRepoLocalStorage implements ConnectionsRepo {
|
|
|
102
105
|
const connections = await this.readConnections();
|
|
103
106
|
|
|
104
107
|
if (connection) {
|
|
105
|
-
const existed = connections.find(([s]) =>
|
|
108
|
+
const existed = connections.find(([s]) => isSelectorMatch(s, selector));
|
|
106
109
|
if (existed) {
|
|
107
110
|
existed[1] = connection;
|
|
108
111
|
} else {
|
|
@@ -112,7 +115,9 @@ export class ConnectionsRepoLocalStorage implements ConnectionsRepo {
|
|
|
112
115
|
} else {
|
|
113
116
|
window.localStorage.setItem(
|
|
114
117
|
this.storageKey,
|
|
115
|
-
JSON.stringify(
|
|
118
|
+
JSON.stringify(
|
|
119
|
+
connections.filter(([s]) => !isSelectorMatch(s, selector)),
|
|
120
|
+
),
|
|
116
121
|
);
|
|
117
122
|
}
|
|
118
123
|
}
|
package/src/evm/index.ts
CHANGED
|
@@ -31,22 +31,30 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Creates an instance of EvmSigner.
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
34
|
+
* @param client - The client instance.
|
|
35
|
+
* @param name - The name of the signer.
|
|
36
|
+
* @param icon - The icon URL of the signer.
|
|
37
|
+
* @param appUri - The application URI.
|
|
38
|
+
* @param connectionsRepo - The connections repository.
|
|
39
39
|
*/
|
|
40
40
|
constructor(
|
|
41
41
|
client: ccc.Client,
|
|
42
42
|
private readonly name: string,
|
|
43
43
|
private readonly icon: string,
|
|
44
|
-
private readonly
|
|
44
|
+
private readonly _appUri?: string,
|
|
45
45
|
private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),
|
|
46
46
|
) {
|
|
47
47
|
super(client);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
async replaceClient(client: ccc.Client): Promise<boolean> {
|
|
51
|
+
if (!(await super.replaceClient(client))) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
this.connection = undefined;
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
50
58
|
/**
|
|
51
59
|
* Gets the configuration for JoyID.
|
|
52
60
|
* @private
|
|
@@ -55,7 +63,10 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
55
63
|
private getConfig() {
|
|
56
64
|
return {
|
|
57
65
|
redirectURL: location.href,
|
|
58
|
-
joyidAppURL:
|
|
66
|
+
joyidAppURL:
|
|
67
|
+
this._appUri ?? this.client.addressPrefix === "ckb"
|
|
68
|
+
? "https://app.joy.id"
|
|
69
|
+
: "https://testnet.joyid.dev",
|
|
59
70
|
requestNetwork: `ethereum`,
|
|
60
71
|
name: this.name,
|
|
61
72
|
logo: this.icon,
|
|
@@ -90,6 +101,13 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
90
101
|
await this.saveConnection();
|
|
91
102
|
}
|
|
92
103
|
|
|
104
|
+
async disconnect(): Promise<void> {
|
|
105
|
+
await super.disconnect();
|
|
106
|
+
|
|
107
|
+
this.connection = undefined;
|
|
108
|
+
await this.saveConnection();
|
|
109
|
+
}
|
|
110
|
+
|
|
93
111
|
/**
|
|
94
112
|
* Checks if the signer is connected.
|
|
95
113
|
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|