@ckb-ccc/joy-id 0.0.7-alpha.0 → 0.0.7-alpha.2
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/ckb/index.js +1 -1
- 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 +56 -63
- package/dist.commonjs/btc/index.js +114 -140
- package/dist.commonjs/ckb/index.d.ts +114 -121
- package/dist.commonjs/ckb/index.js +250 -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.js +44 -47
- package/dist.commonjs/evm/index.d.ts +61 -67
- package/dist.commonjs/evm/index.js +113 -135
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +19 -40
- package/dist.commonjs/nostr/index.d.ts +42 -48
- package/dist.commonjs/nostr/index.js +91 -110
- package/dist.commonjs/signerFactory/index.d.ts +2 -6
- package/dist.commonjs/signerFactory/index.js +31 -42
- package/package.json +3 -3
- package/src/ckb/index.ts +1 -1
|
@@ -11,142 +11,120 @@ const connectionsStorage_1 = require("../connectionsStorage");
|
|
|
11
11
|
* @extends {ccc.SignerEvm}
|
|
12
12
|
*/
|
|
13
13
|
class EvmSigner extends core_1.ccc.SignerEvm {
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of EvmSigner.
|
|
28
|
+
* @param {ccc.Client} client - The client instance.
|
|
29
|
+
* @param {string} name - The name of the signer.
|
|
30
|
+
* @param {string} icon - The icon URL of the signer.
|
|
31
|
+
* @param {string} [appUri="https://app.joy.id"] - The application URI.
|
|
32
|
+
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
33
|
+
*/
|
|
34
|
+
constructor(client, name, icon, appUri = "https://app.joy.id", connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
|
|
35
|
+
super(client);
|
|
36
|
+
this.name = name;
|
|
37
|
+
this.icon = icon;
|
|
38
|
+
this.appUri = appUri;
|
|
39
|
+
this.connectionsRepo = connectionsRepo;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets the configuration for JoyID.
|
|
43
|
+
* @private
|
|
44
|
+
* @returns {object} The configuration object.
|
|
45
|
+
*/
|
|
46
|
+
getConfig() {
|
|
47
|
+
return {
|
|
48
|
+
redirectURL: location.href,
|
|
49
|
+
joyidAppURL: this.appUri,
|
|
50
|
+
requestNetwork: `ethereum`,
|
|
51
|
+
name: this.name,
|
|
52
|
+
logo: this.icon,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Gets the EVM account address.
|
|
57
|
+
* @returns {Promise<string>} A promise that resolves to the EVM account address.
|
|
58
|
+
*/
|
|
59
|
+
async getEvmAccount() {
|
|
60
|
+
return this.assertConnection().address;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Connects to the provider by requesting authentication.
|
|
64
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
65
|
+
*/
|
|
66
|
+
async connect() {
|
|
67
|
+
const config = this.getConfig();
|
|
68
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
|
|
69
|
+
...config,
|
|
70
|
+
type: common_1.DappRequestType.Auth,
|
|
71
|
+
});
|
|
72
|
+
this.connection = {
|
|
73
|
+
address: res.ethAddress,
|
|
74
|
+
publicKey: core_1.ccc.hexFrom(res.pubkey),
|
|
75
|
+
keyType: res.keyType,
|
|
76
|
+
};
|
|
77
|
+
await this.saveConnection();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Checks if the signer is connected.
|
|
81
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
82
|
+
*/
|
|
83
|
+
async isConnected() {
|
|
84
|
+
if (this.connection) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
await this.restoreConnection();
|
|
88
|
+
return this.connection !== undefined;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Signs a raw message with the EVM account.
|
|
92
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
93
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
|
|
94
|
+
*/
|
|
95
|
+
async signMessageRaw(message) {
|
|
96
|
+
const { address } = this.assertConnection();
|
|
97
|
+
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
98
|
+
const config = this.getConfig();
|
|
99
|
+
const { signature } = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
|
|
100
|
+
...config,
|
|
101
|
+
challenge,
|
|
102
|
+
isData: typeof message !== "string",
|
|
103
|
+
address,
|
|
104
|
+
}, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
|
|
105
|
+
return core_1.ccc.hexFrom(signature);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Saves the current connection.
|
|
109
|
+
* @private
|
|
110
|
+
* @returns {Promise<void>}
|
|
111
|
+
*/
|
|
112
|
+
async saveConnection() {
|
|
113
|
+
return this.connectionsRepo.set({
|
|
114
|
+
uri: this.getConfig().joyidAppURL,
|
|
115
|
+
addressType: "ethereum",
|
|
116
|
+
}, this.connection);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Restores the previous connection.
|
|
120
|
+
* @private
|
|
121
|
+
* @returns {Promise<void>}
|
|
122
|
+
*/
|
|
123
|
+
async restoreConnection() {
|
|
124
|
+
this.connection = await this.connectionsRepo.get({
|
|
125
|
+
uri: this.getConfig().joyidAppURL,
|
|
126
|
+
addressType: "ethereum",
|
|
127
|
+
});
|
|
95
128
|
}
|
|
96
|
-
await this.restoreConnection();
|
|
97
|
-
return this.connection !== undefined;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Signs a raw message with the EVM account.
|
|
101
|
-
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
102
|
-
* @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
|
|
103
|
-
*/
|
|
104
|
-
async signMessageRaw(message) {
|
|
105
|
-
const { address } = this.assertConnection();
|
|
106
|
-
const challenge =
|
|
107
|
-
typeof message === "string"
|
|
108
|
-
? message
|
|
109
|
-
: core_1.ccc.hexFrom(message).slice(2);
|
|
110
|
-
const config = this.getConfig();
|
|
111
|
-
const { signature } = await (0, common_2.createPopup)(
|
|
112
|
-
(0, common_1.buildJoyIDURL)(
|
|
113
|
-
{
|
|
114
|
-
...config,
|
|
115
|
-
challenge,
|
|
116
|
-
isData: typeof message !== "string",
|
|
117
|
-
address,
|
|
118
|
-
},
|
|
119
|
-
"popup",
|
|
120
|
-
"/sign-message",
|
|
121
|
-
),
|
|
122
|
-
{ ...config, type: common_1.DappRequestType.SignMessage },
|
|
123
|
-
);
|
|
124
|
-
return core_1.ccc.hexFrom(signature);
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Saves the current connection.
|
|
128
|
-
* @private
|
|
129
|
-
* @returns {Promise<void>}
|
|
130
|
-
*/
|
|
131
|
-
async saveConnection() {
|
|
132
|
-
return this.connectionsRepo.set(
|
|
133
|
-
{
|
|
134
|
-
uri: this.getConfig().joyidAppURL,
|
|
135
|
-
addressType: "ethereum",
|
|
136
|
-
},
|
|
137
|
-
this.connection,
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Restores the previous connection.
|
|
142
|
-
* @private
|
|
143
|
-
* @returns {Promise<void>}
|
|
144
|
-
*/
|
|
145
|
-
async restoreConnection() {
|
|
146
|
-
this.connection = await this.connectionsRepo.get({
|
|
147
|
-
uri: this.getConfig().joyidAppURL,
|
|
148
|
-
addressType: "ethereum",
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
129
|
}
|
|
152
130
|
exports.EvmSigner = EvmSigner;
|
package/dist.commonjs/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * as JoyId from "./barrel";
|
|
2
|
-
//# sourceMappingURL=index.d.ts.map
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist.commonjs/index.js
CHANGED
|
@@ -1,48 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}
|
|
21
|
-
: function (o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
});
|
|
25
|
-
var __setModuleDefault =
|
|
26
|
-
(this && this.__setModuleDefault) ||
|
|
27
|
-
(Object.create
|
|
28
|
-
? function (o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}
|
|
31
|
-
: function (o, v) {
|
|
32
|
-
o["default"] = v;
|
|
33
|
-
});
|
|
34
|
-
var __importStar =
|
|
35
|
-
(this && this.__importStar) ||
|
|
36
|
-
function (mod) {
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
37
19
|
if (mod && mod.__esModule) return mod;
|
|
38
20
|
var result = {};
|
|
39
|
-
if (mod != null)
|
|
40
|
-
for (var k in mod)
|
|
41
|
-
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
-
__createBinding(result, mod, k);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
43
22
|
__setModuleDefault(result, mod);
|
|
44
23
|
return result;
|
|
45
|
-
|
|
24
|
+
};
|
|
46
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
26
|
exports.JoyId = void 0;
|
|
48
27
|
exports.JoyId = __importStar(require("./barrel"));
|
|
@@ -6,52 +6,46 @@ import { ConnectionsRepo } from "../connectionsStorage";
|
|
|
6
6
|
* @extends {ccc.SignerNostr}
|
|
7
7
|
*/
|
|
8
8
|
export declare class NostrSigner extends ccc.SignerNostr {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
client: ccc.Client
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* Checks if the signer is connected.
|
|
51
|
-
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
52
|
-
*/
|
|
53
|
-
isConnected(): Promise<boolean>;
|
|
54
|
-
getNostrPublicKey(): Promise<ccc.Hex>;
|
|
55
|
-
signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
|
|
9
|
+
private readonly name;
|
|
10
|
+
private readonly icon;
|
|
11
|
+
private readonly appUri;
|
|
12
|
+
private readonly connectionsRepo;
|
|
13
|
+
private 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
|
+
private assertConnection;
|
|
21
|
+
/**
|
|
22
|
+
* Creates an instance of NostrSigner.
|
|
23
|
+
* @param {ccc.Client} client - The client instance.
|
|
24
|
+
* @param {string} name - The name of the signer.
|
|
25
|
+
* @param {string} icon - The icon URL of the signer.
|
|
26
|
+
* @param {string} [appUri="https://app.joy.id"] - The application URI.
|
|
27
|
+
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
28
|
+
*/
|
|
29
|
+
constructor(client: ccc.Client, name: string, icon: string, appUri?: string, connectionsRepo?: ConnectionsRepo);
|
|
30
|
+
static isValidClient(client: ccc.Client): boolean;
|
|
31
|
+
replaceClient(client: ccc.Client): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the configuration for JoyID.
|
|
34
|
+
* @private
|
|
35
|
+
* @returns {object} The configuration object.
|
|
36
|
+
*/
|
|
37
|
+
private getConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Connects to the provider by requesting authentication.
|
|
40
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
41
|
+
*/
|
|
42
|
+
connect(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if the signer is connected.
|
|
45
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
46
|
+
*/
|
|
47
|
+
isConnected(): Promise<boolean>;
|
|
48
|
+
getNostrPublicKey(): Promise<ccc.Hex>;
|
|
49
|
+
signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
|
|
56
50
|
}
|
|
57
|
-
//# sourceMappingURL=index.d.ts.map
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -11,119 +11,100 @@ 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 {ccc.Client} client - The client instance.
|
|
29
|
+
* @param {string} name - The name of the signer.
|
|
30
|
+
* @param {string} icon - The icon URL of the signer.
|
|
31
|
+
* @param {string} [appUri="https://app.joy.id"] - The application URI.
|
|
32
|
+
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
33
|
+
*/
|
|
34
|
+
constructor(client, name, icon, appUri = "https://app.joy.id", 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
|
-
* Gets the configuration for JoyID.
|
|
58
|
-
* @private
|
|
59
|
-
* @returns {object} The configuration object.
|
|
60
|
-
*/
|
|
61
|
-
getConfig() {
|
|
62
|
-
return {
|
|
63
|
-
redirectURL: location.href,
|
|
64
|
-
joyidAppURL: this.appUri,
|
|
65
|
-
requestNetwork: "nostr",
|
|
66
|
-
name: this.name,
|
|
67
|
-
logo: this.icon,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Connects to the provider by requesting authentication.
|
|
72
|
-
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
73
|
-
*/
|
|
74
|
-
async connect() {
|
|
75
|
-
const config = this.getConfig();
|
|
76
|
-
const res = await (0, common_2.createPopup)(
|
|
77
|
-
(0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
|
|
78
|
-
{
|
|
79
|
-
...config,
|
|
80
|
-
type: common_1.DappRequestType.Auth,
|
|
81
|
-
},
|
|
82
|
-
);
|
|
83
|
-
this.connection = {
|
|
84
|
-
address: "",
|
|
85
|
-
publicKey: core_1.ccc.hexFrom(res.nostrPubkey),
|
|
86
|
-
keyType: res.keyType,
|
|
87
|
-
};
|
|
88
|
-
await this.connectionsRepo.set(
|
|
89
|
-
{ uri: this.appUri, addressType: "nostr" },
|
|
90
|
-
this.connection,
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Checks if the signer is connected.
|
|
95
|
-
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
96
|
-
*/
|
|
97
|
-
async isConnected() {
|
|
98
|
-
if (this.connection) {
|
|
99
|
-
return true;
|
|
41
|
+
static isValidClient(client) {
|
|
42
|
+
return client.addressPrefix === "ckt";
|
|
100
43
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
44
|
+
async replaceClient(client) {
|
|
45
|
+
if (!NostrSigner.isValidClient(client)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return super.replaceClient(client);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Gets the configuration for JoyID.
|
|
52
|
+
* @private
|
|
53
|
+
* @returns {object} The configuration object.
|
|
54
|
+
*/
|
|
55
|
+
getConfig() {
|
|
56
|
+
return {
|
|
57
|
+
redirectURL: location.href,
|
|
58
|
+
joyidAppURL: this.appUri,
|
|
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.connectionsRepo.set({ uri: this.appUri, addressType: "nostr" }, this.connection);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Checks if the signer is connected.
|
|
83
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
84
|
+
*/
|
|
85
|
+
async isConnected() {
|
|
86
|
+
if (this.connection) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
this.connection = await this.connectionsRepo.get({
|
|
90
|
+
uri: this.appUri,
|
|
91
|
+
addressType: "nostr",
|
|
92
|
+
});
|
|
93
|
+
return this.connection !== undefined;
|
|
94
|
+
}
|
|
95
|
+
async getNostrPublicKey() {
|
|
96
|
+
if (!this.connection) {
|
|
97
|
+
throw new Error("Not connected");
|
|
98
|
+
}
|
|
99
|
+
return this.connection.publicKey;
|
|
100
|
+
}
|
|
101
|
+
async signNostrEvent(event) {
|
|
102
|
+
const config = this.getConfig();
|
|
103
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({ ...config, event }, "popup", "/sign-nostr-event"), {
|
|
104
|
+
...config,
|
|
105
|
+
type: common_1.DappRequestType.SignNostrEvent,
|
|
106
|
+
});
|
|
107
|
+
return res.event;
|
|
110
108
|
}
|
|
111
|
-
return this.connection.publicKey;
|
|
112
|
-
}
|
|
113
|
-
async signNostrEvent(event) {
|
|
114
|
-
const config = this.getConfig();
|
|
115
|
-
const res = await (0, common_2.createPopup)(
|
|
116
|
-
(0, common_1.buildJoyIDURL)(
|
|
117
|
-
{ ...config, event },
|
|
118
|
-
"popup",
|
|
119
|
-
"/sign-nostr-event",
|
|
120
|
-
),
|
|
121
|
-
{
|
|
122
|
-
...config,
|
|
123
|
-
type: common_1.DappRequestType.SignNostrEvent,
|
|
124
|
-
},
|
|
125
|
-
);
|
|
126
|
-
return res.event;
|
|
127
|
-
}
|
|
128
109
|
}
|
|
129
110
|
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): ccc.SignerInfo[];
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|