@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
package/src/nostr/index.ts
CHANGED
|
@@ -31,31 +31,28 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Creates an instance of NostrSigner.
|
|
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
|
-
static isValidClient(client: ccc.Client): boolean {
|
|
51
|
-
return client.addressPrefix === "ckt";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
50
|
async replaceClient(client: ccc.Client): Promise<boolean> {
|
|
55
|
-
if (!
|
|
51
|
+
if (!(await super.replaceClient(client))) {
|
|
56
52
|
return false;
|
|
57
53
|
}
|
|
58
|
-
|
|
54
|
+
this.connection = undefined;
|
|
55
|
+
return true;
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
/**
|
|
@@ -66,7 +63,10 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
66
63
|
private getConfig() {
|
|
67
64
|
return {
|
|
68
65
|
redirectURL: location.href,
|
|
69
|
-
joyidAppURL:
|
|
66
|
+
joyidAppURL:
|
|
67
|
+
this._appUri ?? this.client.addressPrefix === "ckb"
|
|
68
|
+
? "https://app.joy.id"
|
|
69
|
+
: "https://testnet.joyid.dev",
|
|
70
70
|
requestNetwork: "nostr",
|
|
71
71
|
name: this.name,
|
|
72
72
|
logo: this.icon,
|
|
@@ -89,10 +89,14 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
89
89
|
publicKey: ccc.hexFrom(res.nostrPubkey),
|
|
90
90
|
keyType: res.keyType,
|
|
91
91
|
};
|
|
92
|
-
await this.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
await this.saveConnection();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async disconnect(): Promise<void> {
|
|
96
|
+
await super.disconnect();
|
|
97
|
+
|
|
98
|
+
this.connection = undefined;
|
|
99
|
+
await this.saveConnection();
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
/**
|
|
@@ -104,10 +108,7 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
104
108
|
return true;
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
|
|
108
|
-
uri: this.appUri,
|
|
109
|
-
addressType: "nostr",
|
|
110
|
-
});
|
|
111
|
+
await this.restoreConnection();
|
|
111
112
|
return this.connection !== undefined;
|
|
112
113
|
}
|
|
113
114
|
|
|
@@ -128,4 +129,31 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
128
129
|
);
|
|
129
130
|
return res.event;
|
|
130
131
|
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Saves the current connection.
|
|
135
|
+
* @private
|
|
136
|
+
* @returns {Promise<void>}
|
|
137
|
+
*/
|
|
138
|
+
private async saveConnection(): Promise<void> {
|
|
139
|
+
return this.connectionsRepo.set(
|
|
140
|
+
{
|
|
141
|
+
uri: this.getConfig().joyidAppURL,
|
|
142
|
+
addressType: "nostr",
|
|
143
|
+
},
|
|
144
|
+
this.connection,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Restores the previous connection.
|
|
150
|
+
* @private
|
|
151
|
+
* @returns {Promise<void>}
|
|
152
|
+
*/
|
|
153
|
+
private async restoreConnection(): Promise<void> {
|
|
154
|
+
this.connection = await this.connectionsRepo.get({
|
|
155
|
+
uri: this.getConfig().joyidAppURL,
|
|
156
|
+
addressType: "nostr",
|
|
157
|
+
});
|
|
158
|
+
}
|
|
131
159
|
}
|
|
@@ -18,6 +18,7 @@ export function getJoyIdSigners(
|
|
|
18
18
|
client: ccc.Client,
|
|
19
19
|
name: string,
|
|
20
20
|
icon: string,
|
|
21
|
+
preferredNetworks: ccc.NetworkPreference[],
|
|
21
22
|
): ccc.SignerInfo[] {
|
|
22
23
|
if (isStandaloneBrowser() || ccc.isWebview(window.navigator.userAgent)) {
|
|
23
24
|
return [ccc.SignerType.CKB, ccc.SignerType.EVM, ccc.SignerType.BTC].map(
|
|
@@ -39,7 +40,7 @@ export function getJoyIdSigners(
|
|
|
39
40
|
},
|
|
40
41
|
{
|
|
41
42
|
name: "BTC",
|
|
42
|
-
signer: new BitcoinSigner(client, name, icon),
|
|
43
|
+
signer: new BitcoinSigner(client, name, icon, preferredNetworks),
|
|
43
44
|
},
|
|
44
45
|
{
|
|
45
46
|
name: "Nostr",
|
|
@@ -51,11 +52,17 @@ export function getJoyIdSigners(
|
|
|
51
52
|
},
|
|
52
53
|
{
|
|
53
54
|
name: "BTC (P2WPKH)",
|
|
54
|
-
signer: new BitcoinSigner(
|
|
55
|
+
signer: new BitcoinSigner(
|
|
56
|
+
client,
|
|
57
|
+
name,
|
|
58
|
+
icon,
|
|
59
|
+
preferredNetworks,
|
|
60
|
+
"p2wpkh",
|
|
61
|
+
),
|
|
55
62
|
},
|
|
56
63
|
{
|
|
57
64
|
name: "BTC (P2TR)",
|
|
58
|
-
signer: new BitcoinSigner(client, name, icon, "p2tr"),
|
|
65
|
+
signer: new BitcoinSigner(client, name, icon, preferredNetworks, "p2tr"),
|
|
59
66
|
},
|
|
60
67
|
];
|
|
61
68
|
}
|