@ckb-ccc/joy-id 0.0.9-alpha.2 → 0.0.10-alpha.4
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 +0 -1
- package/dist/btc/index.d.ts.map +1 -1
- package/dist/btc/index.js +0 -7
- package/dist/ckb/index.d.ts +0 -1
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +0 -7
- package/dist/evm/index.d.ts +2 -3
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +1 -8
- package/dist/nostr/index.d.ts +0 -1
- package/dist/nostr/index.d.ts.map +1 -1
- package/dist/nostr/index.js +0 -7
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +40 -19
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +30 -14
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +30 -14
- package/dist.commonjs/btc/index.d.ts +67 -60
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +176 -148
- package/dist.commonjs/ckb/index.d.ts +122 -116
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +312 -262
- package/dist.commonjs/common/index.d.ts +34 -21
- package/dist.commonjs/common/index.js +50 -45
- package/dist.commonjs/connectionsStorage/index.d.ts +53 -44
- package/dist.commonjs/connectionsStorage/index.js +49 -44
- package/dist.commonjs/evm/index.d.ts +68 -63
- package/dist.commonjs/evm/index.d.ts.map +1 -1
- package/dist.commonjs/evm/index.js +143 -127
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +40 -19
- package/dist.commonjs/nostr/index.d.ts +59 -54
- package/dist.commonjs/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/nostr/index.js +127 -114
- package/dist.commonjs/signerFactory/index.d.ts +7 -2
- package/dist.commonjs/signerFactory/index.js +54 -31
- package/package.json +3 -3
- package/src/btc/index.ts +0 -8
- package/src/ckb/index.ts +0 -8
- package/src/evm/index.ts +3 -11
- package/src/nostr/index.ts +0 -8
|
@@ -11,121 +11,134 @@ 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
|
-
|
|
23
|
-
}
|
|
24
|
-
return this.connection;
|
|
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");
|
|
25
23
|
}
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
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
|
-
});
|
|
24
|
+
return this.connection;
|
|
25
|
+
}
|
|
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(
|
|
35
|
+
client,
|
|
36
|
+
name,
|
|
37
|
+
icon,
|
|
38
|
+
_appUri,
|
|
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
|
+
/**
|
|
48
|
+
* Gets the configuration for JoyID.
|
|
49
|
+
* @private
|
|
50
|
+
* @returns {object} The configuration object.
|
|
51
|
+
*/
|
|
52
|
+
getConfig() {
|
|
53
|
+
return {
|
|
54
|
+
redirectURL: location.href,
|
|
55
|
+
joyidAppURL:
|
|
56
|
+
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)(
|
|
71
|
+
(0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
|
|
72
|
+
{
|
|
73
|
+
...config,
|
|
74
|
+
type: common_1.DappRequestType.Auth,
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
this.connection = {
|
|
78
|
+
address: "",
|
|
79
|
+
publicKey: core_1.ccc.hexFrom(res.nostrPubkey),
|
|
80
|
+
keyType: res.keyType,
|
|
81
|
+
};
|
|
82
|
+
await this.saveConnection();
|
|
83
|
+
}
|
|
84
|
+
async disconnect() {
|
|
85
|
+
await super.disconnect();
|
|
86
|
+
this.connection = undefined;
|
|
87
|
+
await this.saveConnection();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Checks if the signer is connected.
|
|
91
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
92
|
+
*/
|
|
93
|
+
async isConnected() {
|
|
94
|
+
if (this.connection) {
|
|
95
|
+
return true;
|
|
129
96
|
}
|
|
97
|
+
await this.restoreConnection();
|
|
98
|
+
return this.connection !== undefined;
|
|
99
|
+
}
|
|
100
|
+
async getNostrPublicKey() {
|
|
101
|
+
return this.assertConnection().publicKey;
|
|
102
|
+
}
|
|
103
|
+
async signNostrEvent(event) {
|
|
104
|
+
const config = this.getConfig();
|
|
105
|
+
const res = await (0, common_2.createPopup)(
|
|
106
|
+
(0, common_1.buildJoyIDURL)(
|
|
107
|
+
{ ...config, event },
|
|
108
|
+
"popup",
|
|
109
|
+
"/sign-nostr-event",
|
|
110
|
+
),
|
|
111
|
+
{
|
|
112
|
+
...config,
|
|
113
|
+
type: common_1.DappRequestType.SignNostrEvent,
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
return res.event;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Saves the current connection.
|
|
120
|
+
* @private
|
|
121
|
+
* @returns {Promise<void>}
|
|
122
|
+
*/
|
|
123
|
+
async saveConnection() {
|
|
124
|
+
return this.connectionsRepo.set(
|
|
125
|
+
{
|
|
126
|
+
uri: this.getConfig().joyidAppURL,
|
|
127
|
+
addressType: "nostr",
|
|
128
|
+
},
|
|
129
|
+
this.connection,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Restores the previous connection.
|
|
134
|
+
* @private
|
|
135
|
+
* @returns {Promise<void>}
|
|
136
|
+
*/
|
|
137
|
+
async restoreConnection() {
|
|
138
|
+
this.connection = await this.connectionsRepo.get({
|
|
139
|
+
uri: this.getConfig().joyidAppURL,
|
|
140
|
+
addressType: "nostr",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
130
143
|
}
|
|
131
144
|
exports.NostrSigner = NostrSigner;
|
|
@@ -8,5 +8,10 @@ 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
|
-
|
|
11
|
+
export declare function getJoyIdSigners(
|
|
12
|
+
client: ccc.Client,
|
|
13
|
+
name: string,
|
|
14
|
+
icon: string,
|
|
15
|
+
preferredNetworks: ccc.NetworkPreference[],
|
|
16
|
+
): ccc.SignerInfo[];
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -17,37 +17,60 @@ const nostr_1 = require("../nostr");
|
|
|
17
17
|
* @returns {ccc.SignerInfo[]} An array of signer information objects.
|
|
18
18
|
*/
|
|
19
19
|
function getJoyIdSigners(client, name, icon, preferredNetworks) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}));
|
|
25
|
-
}
|
|
20
|
+
if (
|
|
21
|
+
(0, common_1.isStandaloneBrowser)() ||
|
|
22
|
+
core_1.ccc.isWebview(window.navigator.userAgent)
|
|
23
|
+
) {
|
|
26
24
|
return [
|
|
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
|
-
|
|
25
|
+
core_1.ccc.SignerType.CKB,
|
|
26
|
+
core_1.ccc.SignerType.EVM,
|
|
27
|
+
core_1.ccc.SignerType.BTC,
|
|
28
|
+
].map((type) => ({
|
|
29
|
+
name: type,
|
|
30
|
+
signer: new core_1.ccc.SignerAlwaysError(
|
|
31
|
+
client,
|
|
32
|
+
type,
|
|
33
|
+
"JoyID can only be used with standard browsers",
|
|
34
|
+
),
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
name: "CKB",
|
|
40
|
+
signer: new ckb_1.CkbSigner(client, name, icon),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "BTC",
|
|
44
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, preferredNetworks),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "Nostr",
|
|
48
|
+
signer: new nostr_1.NostrSigner(client, name, icon),
|
|
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(
|
|
57
|
+
client,
|
|
58
|
+
name,
|
|
59
|
+
icon,
|
|
60
|
+
preferredNetworks,
|
|
61
|
+
"p2wpkh",
|
|
62
|
+
),
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "BTC (P2TR)",
|
|
66
|
+
signer: new btc_1.BitcoinSigner(
|
|
67
|
+
client,
|
|
68
|
+
name,
|
|
69
|
+
icon,
|
|
70
|
+
preferredNetworks,
|
|
71
|
+
"p2tr",
|
|
72
|
+
),
|
|
73
|
+
},
|
|
74
|
+
];
|
|
52
75
|
}
|
|
53
76
|
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.10-alpha.4",
|
|
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.10-alpha.4",
|
|
42
42
|
"@joyid/ckb": "^1.0.0",
|
|
43
43
|
"@joyid/common": "^0.2.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "61228337bbf4bdc0bc082e3c9530f843c2182106"
|
|
46
46
|
}
|
package/src/btc/index.ts
CHANGED
|
@@ -62,14 +62,6 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
62
62
|
super(client);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
async replaceClient(client: ccc.Client): Promise<boolean> {
|
|
66
|
-
if (!(await super.replaceClient(client))) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
this.connection = undefined;
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
65
|
/**
|
|
74
66
|
* Gets the configuration for JoyID.
|
|
75
67
|
* @private
|
package/src/ckb/index.ts
CHANGED
|
@@ -66,14 +66,6 @@ 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
|
-
|
|
77
69
|
/**
|
|
78
70
|
* Gets the configuration for JoyID.
|
|
79
71
|
* @private
|
package/src/evm/index.ts
CHANGED
|
@@ -47,14 +47,6 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
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
|
-
|
|
58
50
|
/**
|
|
59
51
|
* Gets the configuration for JoyID.
|
|
60
52
|
* @private
|
|
@@ -75,10 +67,10 @@ export class EvmSigner extends ccc.SignerEvm {
|
|
|
75
67
|
|
|
76
68
|
/**
|
|
77
69
|
* Gets the EVM account address.
|
|
78
|
-
* @returns
|
|
70
|
+
* @returns A promise that resolves to the EVM account address.
|
|
79
71
|
*/
|
|
80
|
-
async getEvmAccount(): Promise<
|
|
81
|
-
return this.assertConnection().address;
|
|
72
|
+
async getEvmAccount(): Promise<ccc.Hex> {
|
|
73
|
+
return this.assertConnection().address as ccc.Hex;
|
|
82
74
|
}
|
|
83
75
|
|
|
84
76
|
/**
|
package/src/nostr/index.ts
CHANGED
|
@@ -47,14 +47,6 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
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
|
-
|
|
58
50
|
/**
|
|
59
51
|
* Gets the configuration for JoyID.
|
|
60
52
|
* @private
|