@ckb-ccc/joy-id 0.0.8-alpha.4 → 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 +13 -1
- 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 -7
- package/dist/nostr/index.d.ts.map +1 -1
- package/dist/nostr/index.js +44 -14
- 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/btc/index.d.ts +16 -12
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +38 -13
- package/dist.commonjs/ckb/index.d.ts +3 -1
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +13 -1
- package/dist.commonjs/connectionsStorage/index.d.ts +1 -1
- package/dist.commonjs/connectionsStorage/index.d.ts.map +1 -1
- package/dist.commonjs/connectionsStorage/index.js +7 -7
- package/dist.commonjs/evm/index.d.ts +9 -7
- package/dist.commonjs/evm/index.d.ts.map +1 -1
- package/dist.commonjs/evm/index.js +22 -8
- package/dist.commonjs/nostr/index.d.ts +20 -7
- package/dist.commonjs/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/nostr/index.js +44 -14
- package/dist.commonjs/signerFactory/index.d.ts +1 -1
- package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
- package/dist.commonjs/signerFactory/index.js +4 -4
- package/package.json +3 -3
- package/src/btc/index.ts +53 -15
- package/src/ckb/index.ts +16 -1
- package/src/connectionsStorage/index.ts +10 -5
- package/src/evm/index.ts +25 -7
- package/src/nostr/index.ts +51 -16
- package/src/signerFactory/index.ts +10 -3
|
@@ -25,35 +25,60 @@ class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Creates an instance of BitcoinSigner.
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
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 addressType - The address type.
|
|
32
|
+
* @param _appUri - The application URI.
|
|
33
|
+
* @param connectionsRepo - The connections repository.
|
|
34
34
|
*/
|
|
35
|
-
constructor(client, name, icon, addressType = "auto",
|
|
35
|
+
constructor(client, name, icon, preferredNetworks, addressType = "auto", _appUri, connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
|
|
36
36
|
super(client);
|
|
37
37
|
this.name = name;
|
|
38
38
|
this.icon = icon;
|
|
39
|
+
this.preferredNetworks = preferredNetworks;
|
|
39
40
|
this.addressType = addressType;
|
|
40
|
-
this.
|
|
41
|
+
this._appUri = _appUri;
|
|
41
42
|
this.connectionsRepo = connectionsRepo;
|
|
43
|
+
this.network = "btcTestnet";
|
|
44
|
+
}
|
|
45
|
+
async replaceClient(client) {
|
|
46
|
+
if (!(await super.replaceClient(client))) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
this.connection = undefined;
|
|
50
|
+
return true;
|
|
42
51
|
}
|
|
43
52
|
/**
|
|
44
53
|
* Gets the configuration for JoyID.
|
|
45
54
|
* @private
|
|
46
|
-
* @returns
|
|
55
|
+
* @returns The configuration object.
|
|
47
56
|
*/
|
|
48
57
|
getConfig() {
|
|
58
|
+
const { network } = this.matchNetworkPreference(this.preferredNetworks, this.network) ?? { network: this.network };
|
|
59
|
+
if (this.network !== network) {
|
|
60
|
+
this.connection = undefined;
|
|
61
|
+
}
|
|
62
|
+
this.network = network;
|
|
63
|
+
const url = {
|
|
64
|
+
btc: "https://app.joy.id",
|
|
65
|
+
btcTestnet: "https://testnet.joyid.dev",
|
|
66
|
+
}[network];
|
|
67
|
+
if (!url) {
|
|
68
|
+
throw new Error(`JoyID wallet doesn't support the requested chain ${this.network}`);
|
|
69
|
+
}
|
|
49
70
|
return {
|
|
50
71
|
redirectURL: location.href,
|
|
51
|
-
joyidAppURL: this.
|
|
72
|
+
joyidAppURL: this._appUri ?? url,
|
|
52
73
|
requestNetwork: `btc-${this.addressType}`,
|
|
53
74
|
name: this.name,
|
|
54
75
|
logo: this.icon,
|
|
55
76
|
};
|
|
56
77
|
}
|
|
78
|
+
async disconnect() {
|
|
79
|
+
await super.disconnect();
|
|
80
|
+
await this.connectionsRepo.set({ uri: this.getConfig().joyidAppURL, addressType: "btc" }, undefined);
|
|
81
|
+
}
|
|
57
82
|
/**
|
|
58
83
|
* Gets the Bitcoin account address.
|
|
59
84
|
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
@@ -92,8 +117,8 @@ class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
|
92
117
|
keyType: res.keyType,
|
|
93
118
|
};
|
|
94
119
|
await Promise.all([
|
|
95
|
-
this.connectionsRepo.set({ uri:
|
|
96
|
-
this.connectionsRepo.set({ uri:
|
|
120
|
+
this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: `btc-${res.btcAddressType}` }, this.connection),
|
|
121
|
+
this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: "btc-auto" }, this.connection),
|
|
97
122
|
]);
|
|
98
123
|
}
|
|
99
124
|
/**
|
|
@@ -105,7 +130,7 @@ class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
|
105
130
|
return true;
|
|
106
131
|
}
|
|
107
132
|
this.connection = await this.connectionsRepo.get({
|
|
108
|
-
uri: this.
|
|
133
|
+
uri: this.getConfig().joyidAppURL,
|
|
109
134
|
addressType: `btc-${this.addressType}`,
|
|
110
135
|
});
|
|
111
136
|
return this.connection !== undefined;
|
|
@@ -39,10 +39,11 @@ export declare class CkbSigner extends ccc.Signer {
|
|
|
39
39
|
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
40
40
|
*/
|
|
41
41
|
constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, _aggregatorUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
42
|
+
replaceClient(client: ccc.Client): Promise<boolean>;
|
|
42
43
|
/**
|
|
43
44
|
* Gets the configuration for JoyID.
|
|
44
45
|
* @private
|
|
45
|
-
* @returns
|
|
46
|
+
* @returns The configuration object.
|
|
46
47
|
*/
|
|
47
48
|
private getConfig;
|
|
48
49
|
/**
|
|
@@ -56,6 +57,7 @@ export declare class CkbSigner extends ccc.Signer {
|
|
|
56
57
|
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
57
58
|
*/
|
|
58
59
|
connect(): Promise<void>;
|
|
60
|
+
disconnect(): Promise<void>;
|
|
59
61
|
/**
|
|
60
62
|
* Checks if the signer is connected.
|
|
61
63
|
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ckb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;IA4CrC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC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Q,EACvB,eAAe,GAAE,eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQzD;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAYjB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAUxB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAQrC;;;OAGG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAQpC;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IAO3C;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAI9C;;;;OAIG;IACG,kBAAkB,CACtB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAmB3B;;;;;;OAMG;YACW,2BAA2B;IAuCzC;;;;OAIG;IACG,mBAAmB,CACvB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IA8C3B;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IA2BtE;;;;OAIG;YACW,cAAc;IAU5B;;;;OAIG;YACW,iBAAiB;CAMhC"}
|
|
@@ -55,10 +55,17 @@ class CkbSigner extends core_1.ccc.Signer {
|
|
|
55
55
|
this._aggregatorUri = _aggregatorUri;
|
|
56
56
|
this.connectionsRepo = connectionsRepo;
|
|
57
57
|
}
|
|
58
|
+
async replaceClient(client) {
|
|
59
|
+
if (!(await super.replaceClient(client))) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
this.connection = undefined;
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
58
65
|
/**
|
|
59
66
|
* Gets the configuration for JoyID.
|
|
60
67
|
* @private
|
|
61
|
-
* @returns
|
|
68
|
+
* @returns The configuration object.
|
|
62
69
|
*/
|
|
63
70
|
getConfig() {
|
|
64
71
|
return {
|
|
@@ -100,6 +107,11 @@ class CkbSigner extends core_1.ccc.Signer {
|
|
|
100
107
|
};
|
|
101
108
|
await this.saveConnection();
|
|
102
109
|
}
|
|
110
|
+
async disconnect() {
|
|
111
|
+
await super.disconnect();
|
|
112
|
+
this.connection = undefined;
|
|
113
|
+
await this.saveConnection();
|
|
114
|
+
}
|
|
103
115
|
/**
|
|
104
116
|
* Checks if the signer is connected.
|
|
105
117
|
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
@@ -15,7 +15,7 @@ export type AccountSelector = {
|
|
|
15
15
|
* @param {AccountSelector} b - The second account selector.
|
|
16
16
|
* @returns {boolean} True if the selectors are equal, false otherwise.
|
|
17
17
|
*/
|
|
18
|
-
export declare function
|
|
18
|
+
export declare function isSelectorMatch(a: AccountSelector, filter: AccountSelector): boolean;
|
|
19
19
|
/**
|
|
20
20
|
* Type representing a connection with an address, public key, and key type.
|
|
21
21
|
* @typedef {Object} Connection
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectionsStorage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectionsStorage/index.ts"],"names":[],"mappings":"A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
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConnectionsRepoLocalStorage = exports.
|
|
3
|
+
exports.ConnectionsRepoLocalStorage = exports.isSelectorMatch = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Checks if two AccountSelectors are equal.
|
|
6
6
|
* @param {AccountSelector} a - The first account selector.
|
|
7
7
|
* @param {AccountSelector} b - The second account selector.
|
|
8
8
|
* @returns {boolean} True if the selectors are equal, false otherwise.
|
|
9
9
|
*/
|
|
10
|
-
function
|
|
11
|
-
return a.uri ===
|
|
10
|
+
function isSelectorMatch(a, filter) {
|
|
11
|
+
return a.uri === filter.uri && a.addressType.startsWith(filter.addressType);
|
|
12
12
|
}
|
|
13
|
-
exports.
|
|
13
|
+
exports.isSelectorMatch = isSelectorMatch;
|
|
14
14
|
/**
|
|
15
15
|
* Class representing a local storage-based repository for managing connections.
|
|
16
16
|
* @class
|
|
@@ -37,7 +37,7 @@ class ConnectionsRepoLocalStorage {
|
|
|
37
37
|
* @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
|
|
38
38
|
*/
|
|
39
39
|
async get(selector) {
|
|
40
|
-
return (await this.readConnections()).find(([s]) =>
|
|
40
|
+
return (await this.readConnections()).find(([s]) => isSelectorMatch(selector, s))?.[1];
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Sets a connection for the given selector.
|
|
@@ -48,7 +48,7 @@ class ConnectionsRepoLocalStorage {
|
|
|
48
48
|
async set(selector, connection) {
|
|
49
49
|
const connections = await this.readConnections();
|
|
50
50
|
if (connection) {
|
|
51
|
-
const existed = connections.find(([s]) =>
|
|
51
|
+
const existed = connections.find(([s]) => isSelectorMatch(s, selector));
|
|
52
52
|
if (existed) {
|
|
53
53
|
existed[1] = connection;
|
|
54
54
|
}
|
|
@@ -58,7 +58,7 @@ class ConnectionsRepoLocalStorage {
|
|
|
58
58
|
window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
|
-
window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !
|
|
61
|
+
window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !isSelectorMatch(s, selector))));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -8,7 +8,7 @@ import { ConnectionsRepo } from "../connectionsStorage";
|
|
|
8
8
|
export declare class EvmSigner extends ccc.SignerEvm {
|
|
9
9
|
private readonly name;
|
|
10
10
|
private readonly icon;
|
|
11
|
-
private readonly
|
|
11
|
+
private readonly _appUri?;
|
|
12
12
|
private readonly connectionsRepo;
|
|
13
13
|
private connection?;
|
|
14
14
|
/**
|
|
@@ -20,13 +20,14 @@ export declare class EvmSigner extends ccc.SignerEvm {
|
|
|
20
20
|
private assertConnection;
|
|
21
21
|
/**
|
|
22
22
|
* Creates an instance of EvmSigner.
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
23
|
+
* @param client - The client instance.
|
|
24
|
+
* @param name - The name of the signer.
|
|
25
|
+
* @param icon - The icon URL of the signer.
|
|
26
|
+
* @param appUri - The application URI.
|
|
27
|
+
* @param connectionsRepo - The connections repository.
|
|
28
28
|
*/
|
|
29
|
-
constructor(client: ccc.Client, name: string, icon: string,
|
|
29
|
+
constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
30
|
+
replaceClient(client: ccc.Client): Promise<boolean>;
|
|
30
31
|
/**
|
|
31
32
|
* Gets the configuration for JoyID.
|
|
32
33
|
* @private
|
|
@@ -43,6 +44,7 @@ export declare class EvmSigner extends ccc.SignerEvm {
|
|
|
43
44
|
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
44
45
|
*/
|
|
45
46
|
connect(): Promise<void>;
|
|
47
|
+
disconnect(): Promise<void>;
|
|
46
48
|
/**
|
|
47
49
|
* Checks if the signer is connected.
|
|
48
50
|
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,GAAG,CAAC,SAAS;IA2BxC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,GAAG,CAAC,SAAS;IA2BxC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IA7BlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;OAOG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,oBAAQ,EAChB,eAAe,GAAE,eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQzD;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAajB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAQrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAuBvE;;;;OAIG;YACW,cAAc;IAU5B;;;;OAIG;YACW,iBAAiB;CAMhC"}
|
|
@@ -25,19 +25,26 @@ class EvmSigner extends core_1.ccc.SignerEvm {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Creates an instance of EvmSigner.
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
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
33
|
*/
|
|
34
|
-
constructor(client, name, icon,
|
|
34
|
+
constructor(client, name, icon, _appUri, connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
|
|
35
35
|
super(client);
|
|
36
36
|
this.name = name;
|
|
37
37
|
this.icon = icon;
|
|
38
|
-
this.
|
|
38
|
+
this._appUri = _appUri;
|
|
39
39
|
this.connectionsRepo = connectionsRepo;
|
|
40
40
|
}
|
|
41
|
+
async replaceClient(client) {
|
|
42
|
+
if (!(await super.replaceClient(client))) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
this.connection = undefined;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
41
48
|
/**
|
|
42
49
|
* Gets the configuration for JoyID.
|
|
43
50
|
* @private
|
|
@@ -46,7 +53,9 @@ class EvmSigner extends core_1.ccc.SignerEvm {
|
|
|
46
53
|
getConfig() {
|
|
47
54
|
return {
|
|
48
55
|
redirectURL: location.href,
|
|
49
|
-
joyidAppURL: this.
|
|
56
|
+
joyidAppURL: this._appUri ?? this.client.addressPrefix === "ckb"
|
|
57
|
+
? "https://app.joy.id"
|
|
58
|
+
: "https://testnet.joyid.dev",
|
|
50
59
|
requestNetwork: `ethereum`,
|
|
51
60
|
name: this.name,
|
|
52
61
|
logo: this.icon,
|
|
@@ -76,6 +85,11 @@ class EvmSigner extends core_1.ccc.SignerEvm {
|
|
|
76
85
|
};
|
|
77
86
|
await this.saveConnection();
|
|
78
87
|
}
|
|
88
|
+
async disconnect() {
|
|
89
|
+
await super.disconnect();
|
|
90
|
+
this.connection = undefined;
|
|
91
|
+
await this.saveConnection();
|
|
92
|
+
}
|
|
79
93
|
/**
|
|
80
94
|
* Checks if the signer is connected.
|
|
81
95
|
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
@@ -8,7 +8,7 @@ import { ConnectionsRepo } from "../connectionsStorage";
|
|
|
8
8
|
export declare class NostrSigner extends ccc.SignerNostr {
|
|
9
9
|
private readonly name;
|
|
10
10
|
private readonly icon;
|
|
11
|
-
private readonly
|
|
11
|
+
private readonly _appUri?;
|
|
12
12
|
private readonly connectionsRepo;
|
|
13
13
|
private connection?;
|
|
14
14
|
/**
|
|
@@ -20,13 +20,13 @@ export declare class NostrSigner extends ccc.SignerNostr {
|
|
|
20
20
|
private assertConnection;
|
|
21
21
|
/**
|
|
22
22
|
* Creates an instance of NostrSigner.
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
23
|
+
* @param client - The client instance.
|
|
24
|
+
* @param name - The name of the signer.
|
|
25
|
+
* @param icon - The icon URL of the signer.
|
|
26
|
+
* @param appUri - The application URI.
|
|
27
|
+
* @param connectionsRepo - The connections repository.
|
|
28
28
|
*/
|
|
29
|
-
constructor(client: ccc.Client, name: string, icon: string,
|
|
29
|
+
constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
30
30
|
replaceClient(client: ccc.Client): Promise<boolean>;
|
|
31
31
|
/**
|
|
32
32
|
* Gets the configuration for JoyID.
|
|
@@ -39,6 +39,7 @@ export declare class NostrSigner extends ccc.SignerNostr {
|
|
|
39
39
|
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
40
40
|
*/
|
|
41
41
|
connect(): Promise<void>;
|
|
42
|
+
disconnect(): Promise<void>;
|
|
42
43
|
/**
|
|
43
44
|
* Checks if the signer is connected.
|
|
44
45
|
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
@@ -46,5 +47,17 @@ export declare class NostrSigner extends ccc.SignerNostr {
|
|
|
46
47
|
isConnected(): Promise<boolean>;
|
|
47
48
|
getNostrPublicKey(): Promise<ccc.Hex>;
|
|
48
49
|
signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
|
|
50
|
+
/**
|
|
51
|
+
* Saves the current connection.
|
|
52
|
+
* @private
|
|
53
|
+
* @returns {Promise<void>}
|
|
54
|
+
*/
|
|
55
|
+
private saveConnection;
|
|
56
|
+
/**
|
|
57
|
+
* Restores the previous connection.
|
|
58
|
+
* @private
|
|
59
|
+
* @returns {Promise<void>}
|
|
60
|
+
*/
|
|
61
|
+
private restoreConnection;
|
|
49
62
|
}
|
|
50
63
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;IA2B5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAA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Signer extends core_1.ccc.SignerNostr {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Creates an instance of NostrSigner.
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
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
33
|
*/
|
|
34
|
-
constructor(client, name, icon,
|
|
34
|
+
constructor(client, name, icon, _appUri, connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
|
|
35
35
|
super(client);
|
|
36
36
|
this.name = name;
|
|
37
37
|
this.icon = icon;
|
|
38
|
-
this.
|
|
38
|
+
this._appUri = _appUri;
|
|
39
39
|
this.connectionsRepo = connectionsRepo;
|
|
40
40
|
}
|
|
41
41
|
async replaceClient(client) {
|
|
42
|
-
|
|
42
|
+
if (!(await super.replaceClient(client))) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
this.connection = undefined;
|
|
46
|
+
return true;
|
|
43
47
|
}
|
|
44
48
|
/**
|
|
45
49
|
* Gets the configuration for JoyID.
|
|
@@ -49,7 +53,9 @@ class NostrSigner extends core_1.ccc.SignerNostr {
|
|
|
49
53
|
getConfig() {
|
|
50
54
|
return {
|
|
51
55
|
redirectURL: location.href,
|
|
52
|
-
joyidAppURL: this.
|
|
56
|
+
joyidAppURL: this._appUri ?? this.client.addressPrefix === "ckb"
|
|
57
|
+
? "https://app.joy.id"
|
|
58
|
+
: "https://testnet.joyid.dev",
|
|
53
59
|
requestNetwork: "nostr",
|
|
54
60
|
name: this.name,
|
|
55
61
|
logo: this.icon,
|
|
@@ -70,7 +76,12 @@ class NostrSigner extends core_1.ccc.SignerNostr {
|
|
|
70
76
|
publicKey: core_1.ccc.hexFrom(res.nostrPubkey),
|
|
71
77
|
keyType: res.keyType,
|
|
72
78
|
};
|
|
73
|
-
await this.
|
|
79
|
+
await this.saveConnection();
|
|
80
|
+
}
|
|
81
|
+
async disconnect() {
|
|
82
|
+
await super.disconnect();
|
|
83
|
+
this.connection = undefined;
|
|
84
|
+
await this.saveConnection();
|
|
74
85
|
}
|
|
75
86
|
/**
|
|
76
87
|
* Checks if the signer is connected.
|
|
@@ -80,10 +91,7 @@ class NostrSigner extends core_1.ccc.SignerNostr {
|
|
|
80
91
|
if (this.connection) {
|
|
81
92
|
return true;
|
|
82
93
|
}
|
|
83
|
-
|
|
84
|
-
uri: this.appUri,
|
|
85
|
-
addressType: "nostr",
|
|
86
|
-
});
|
|
94
|
+
await this.restoreConnection();
|
|
87
95
|
return this.connection !== undefined;
|
|
88
96
|
}
|
|
89
97
|
async getNostrPublicKey() {
|
|
@@ -97,5 +105,27 @@ class NostrSigner extends core_1.ccc.SignerNostr {
|
|
|
97
105
|
});
|
|
98
106
|
return res.event;
|
|
99
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
|
+
});
|
|
129
|
+
}
|
|
100
130
|
}
|
|
101
131
|
exports.NostrSigner = NostrSigner;
|
|
@@ -8,5 +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(client: ccc.Client, name: string, icon: string): ccc.SignerInfo[];
|
|
11
|
+
export declare function getJoyIdSigners(client: ccc.Client, name: string, icon: string, preferredNetworks: ccc.NetworkPreference[]): ccc.SignerInfo[];
|
|
12
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,7 +16,7 @@ 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) {
|
|
19
|
+
function getJoyIdSigners(client, name, icon, preferredNetworks) {
|
|
20
20
|
if ((0, common_1.isStandaloneBrowser)() || core_1.ccc.isWebview(window.navigator.userAgent)) {
|
|
21
21
|
return [core_1.ccc.SignerType.CKB, core_1.ccc.SignerType.EVM, core_1.ccc.SignerType.BTC].map((type) => ({
|
|
22
22
|
name: type,
|
|
@@ -30,7 +30,7 @@ function getJoyIdSigners(client, name, icon) {
|
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
name: "BTC",
|
|
33
|
-
signer: new btc_1.BitcoinSigner(client, name, icon),
|
|
33
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, preferredNetworks),
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
name: "Nostr",
|
|
@@ -42,11 +42,11 @@ function getJoyIdSigners(client, name, icon) {
|
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
name: "BTC (P2WPKH)",
|
|
45
|
-
signer: new btc_1.BitcoinSigner(client, name, icon, "p2wpkh"),
|
|
45
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, preferredNetworks, "p2wpkh"),
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
name: "BTC (P2TR)",
|
|
49
|
-
signer: new btc_1.BitcoinSigner(client, name, icon, "p2tr"),
|
|
49
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, preferredNetworks, "p2tr"),
|
|
50
50
|
},
|
|
51
51
|
];
|
|
52
52
|
}
|
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
|
}
|