@ckb-ccc/joy-id 1.0.33 → 1.1.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/CHANGELOG.md +13 -0
- package/dist/advanced.d.mts +2 -0
- package/dist/advanced.mjs +1 -0
- package/dist/advancedBarrel.d.mts +44 -0
- package/dist/advancedBarrel.d.mts.map +1 -0
- package/dist/advancedBarrel.mjs +2 -0
- package/dist/advancedBarrel.mjs.map +1 -0
- package/dist/barrel.d.mts +339 -0
- package/dist/barrel.d.mts.map +1 -0
- package/dist/barrel.mjs +2 -0
- package/dist/barrel.mjs.map +1 -0
- package/dist/connectionsStorage-BloUSPun.mjs +2 -0
- package/dist/connectionsStorage-BloUSPun.mjs.map +1 -0
- package/dist/index-DGqAOLbu.d.mts +91 -0
- package/dist/index-DGqAOLbu.d.mts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/rolldown-runtime-DK3Fl9T5.mjs +1 -0
- package/dist.commonjs/advanced.d.ts +2 -2
- package/dist.commonjs/advanced.js +1 -37
- package/dist.commonjs/advancedBarrel.d.ts +43 -2
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
- package/dist.commonjs/advancedBarrel.js +2 -18
- package/dist.commonjs/advancedBarrel.js.map +1 -0
- package/dist.commonjs/barrel.d.ts +338 -5
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +2 -21
- package/dist.commonjs/barrel.js.map +1 -0
- package/dist.commonjs/connectionsStorage-CQE3XNWI.js +2 -0
- package/dist.commonjs/connectionsStorage-CQE3XNWI.js.map +1 -0
- package/dist.commonjs/index-CJeW3ePH.d.ts +93 -0
- package/dist.commonjs/index-CJeW3ePH.d.ts.map +1 -0
- package/dist.commonjs/index.d.ts +2 -2
- package/dist.commonjs/index.js +1 -37
- package/package.json +32 -20
- package/tsdown.config.mts +43 -0
- package/dist/advanced.d.ts +0 -2
- package/dist/advanced.d.ts.map +0 -1
- package/dist/advanced.js +0 -1
- package/dist/advancedBarrel.d.ts +0 -3
- package/dist/advancedBarrel.d.ts.map +0 -1
- package/dist/advancedBarrel.js +0 -2
- package/dist/barrel.d.ts +0 -6
- package/dist/barrel.d.ts.map +0 -1
- package/dist/barrel.js +0 -5
- package/dist/btc/index.d.ts +0 -81
- package/dist/btc/index.d.ts.map +0 -1
- package/dist/btc/index.js +0 -197
- package/dist/ckb/index.d.ts +0 -117
- package/dist/ckb/index.d.ts.map +0 -1
- package/dist/ckb/index.js +0 -267
- package/dist/common/index.d.ts +0 -36
- package/dist/common/index.d.ts.map +0 -1
- package/dist/common/index.js +0 -61
- package/dist/connectionsStorage/index.d.ts +0 -87
- package/dist/connectionsStorage/index.d.ts.map +0 -1
- package/dist/connectionsStorage/index.js +0 -65
- package/dist/evm/index.d.ts +0 -66
- package/dist/evm/index.d.ts.map +0 -1
- package/dist/evm/index.js +0 -129
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -1
- package/dist/nostr/index.d.ts +0 -57
- package/dist/nostr/index.d.ts.map +0 -1
- package/dist/nostr/index.js +0 -116
- package/dist/signerFactory/index.d.ts +0 -14
- package/dist/signerFactory/index.d.ts.map +0 -1
- package/dist/signerFactory/index.js +0 -51
- package/dist.commonjs/advanced.d.ts.map +0 -1
- package/dist.commonjs/btc/index.d.ts +0 -81
- package/dist.commonjs/btc/index.d.ts.map +0 -1
- package/dist.commonjs/btc/index.js +0 -201
- package/dist.commonjs/ckb/index.d.ts +0 -117
- package/dist.commonjs/ckb/index.d.ts.map +0 -1
- package/dist.commonjs/ckb/index.js +0 -271
- package/dist.commonjs/common/index.d.ts +0 -36
- package/dist.commonjs/common/index.d.ts.map +0 -1
- package/dist.commonjs/common/index.js +0 -64
- package/dist.commonjs/connectionsStorage/index.d.ts +0 -87
- package/dist.commonjs/connectionsStorage/index.d.ts.map +0 -1
- package/dist.commonjs/connectionsStorage/index.js +0 -70
- package/dist.commonjs/evm/index.d.ts +0 -66
- package/dist.commonjs/evm/index.d.ts.map +0 -1
- package/dist.commonjs/evm/index.js +0 -133
- package/dist.commonjs/index.d.ts.map +0 -1
- package/dist.commonjs/nostr/index.d.ts +0 -57
- package/dist.commonjs/nostr/index.d.ts.map +0 -1
- package/dist.commonjs/nostr/index.js +0 -120
- package/dist.commonjs/signerFactory/index.d.ts +0 -14
- package/dist.commonjs/signerFactory/index.d.ts.map +0 -1
- package/dist.commonjs/signerFactory/index.js +0 -54
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
/**
|
|
3
|
-
* Type representing an account selector with a URI and address type.
|
|
4
|
-
*/
|
|
5
|
-
export type AccountSelector = {
|
|
6
|
-
/**
|
|
7
|
-
* The URI of the account.
|
|
8
|
-
*/
|
|
9
|
-
uri: string;
|
|
10
|
-
/**
|
|
11
|
-
* The address type of the account.
|
|
12
|
-
*/
|
|
13
|
-
addressType: string;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Checks if a AccountSelector matches the filter
|
|
17
|
-
* @param a - The first account selector.
|
|
18
|
-
* @param filter - The account selector filter.
|
|
19
|
-
* @returns True if the selector matches the filter
|
|
20
|
-
*/
|
|
21
|
-
export declare function isSelectorMatch(a: AccountSelector, filter: AccountSelector): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Type representing a connection with an address, public key, and key type.
|
|
24
|
-
*/
|
|
25
|
-
export type Connection = {
|
|
26
|
-
/**
|
|
27
|
-
* The address of the connection.
|
|
28
|
-
*/
|
|
29
|
-
readonly address: string;
|
|
30
|
-
/**
|
|
31
|
-
* The public key of the connection.
|
|
32
|
-
*/
|
|
33
|
-
readonly publicKey: ccc.Hex;
|
|
34
|
-
/**
|
|
35
|
-
* The key type of the connection.
|
|
36
|
-
*/
|
|
37
|
-
readonly keyType: string;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Interface representing a repository for managing connections.
|
|
41
|
-
*/
|
|
42
|
-
export interface ConnectionsRepo {
|
|
43
|
-
/**
|
|
44
|
-
* Gets a connection for the given selector.
|
|
45
|
-
* @param selector - The account selector.
|
|
46
|
-
* @returns A promise that resolves to the connection, if found.
|
|
47
|
-
*/
|
|
48
|
-
get(selector: AccountSelector): Promise<Connection | undefined>;
|
|
49
|
-
/**
|
|
50
|
-
* Sets a connection for the given selector.
|
|
51
|
-
* @param selector - The account selector.
|
|
52
|
-
* @param connection - The connection to set.
|
|
53
|
-
* @returns A promise that resolves when the connection is set.
|
|
54
|
-
*/
|
|
55
|
-
set(selector: AccountSelector, connection: Connection | undefined): Promise<void>;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Class representing a local storage-based repository for managing connections.
|
|
59
|
-
*/
|
|
60
|
-
export declare class ConnectionsRepoLocalStorage implements ConnectionsRepo {
|
|
61
|
-
private readonly storageKey;
|
|
62
|
-
private operationLock;
|
|
63
|
-
/**
|
|
64
|
-
* Creates an instance of ConnectionsRepoLocalStorage.
|
|
65
|
-
* @param [storageKey="ccc-joy-id-signer"] - The local storage key.
|
|
66
|
-
*/
|
|
67
|
-
constructor(storageKey?: string);
|
|
68
|
-
/**
|
|
69
|
-
* Reads all connections from local storage.
|
|
70
|
-
* @returns A promise that resolves to an array of selectors and connections.
|
|
71
|
-
*/
|
|
72
|
-
readConnections(): Promise<[AccountSelector, Connection][]>;
|
|
73
|
-
/**
|
|
74
|
-
* Gets a connection for the given selector.
|
|
75
|
-
* @param selector - The account selector.
|
|
76
|
-
* @returns A promise that resolves to the connection, if found.
|
|
77
|
-
*/
|
|
78
|
-
get(selector: AccountSelector): Promise<Connection | undefined>;
|
|
79
|
-
/**
|
|
80
|
-
* Sets a connection for the given selector.
|
|
81
|
-
* @param selector - The account selector.
|
|
82
|
-
* @param connection - The connection to set.
|
|
83
|
-
* @returns
|
|
84
|
-
*/
|
|
85
|
-
set(selector: AccountSelector, connection: Connection | undefined): Promise<void>;
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectionsStorage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,CAAC,EAAE,eAAe,EAClB,MAAM,EAAE,eAAe,GACtB,OAAO,CAET;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC;IAC5B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,GAAG,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAEhE;;;;;OAKG;IACH,GAAG,CACD,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,2BAA4B,YAAW,eAAe;IAOrD,OAAO,CAAC,QAAQ,CAAC,UAAU;IANvC,OAAO,CAAC,aAAa,CAAoC;IAEzD;;;OAGG;gBAC0B,UAAU,SAAsB;IAE7D;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,CAAC,eAAe,EAAE,UAAU,CAAC,EAAE,CAAC;IAOjE;;;;OAIG;IACG,GAAG,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAMrE;;;;;OAKG;IACG,GAAG,CACP,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC;CAgCjB"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a AccountSelector matches the filter
|
|
3
|
-
* @param a - The first account selector.
|
|
4
|
-
* @param filter - The account selector filter.
|
|
5
|
-
* @returns True if the selector matches the filter
|
|
6
|
-
*/
|
|
7
|
-
export function isSelectorMatch(a, filter) {
|
|
8
|
-
return a.uri === filter.uri && a.addressType.startsWith(filter.addressType);
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Class representing a local storage-based repository for managing connections.
|
|
12
|
-
*/
|
|
13
|
-
export class ConnectionsRepoLocalStorage {
|
|
14
|
-
/**
|
|
15
|
-
* Creates an instance of ConnectionsRepoLocalStorage.
|
|
16
|
-
* @param [storageKey="ccc-joy-id-signer"] - The local storage key.
|
|
17
|
-
*/
|
|
18
|
-
constructor(storageKey = "ccc-joy-id-signer") {
|
|
19
|
-
this.storageKey = storageKey;
|
|
20
|
-
this.operationLock = Promise.resolve();
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Reads all connections from local storage.
|
|
24
|
-
* @returns A promise that resolves to an array of selectors and connections.
|
|
25
|
-
*/
|
|
26
|
-
async readConnections() {
|
|
27
|
-
return JSON.parse(window.localStorage.getItem(this.storageKey) ?? "[]");
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Gets a connection for the given selector.
|
|
31
|
-
* @param selector - The account selector.
|
|
32
|
-
* @returns A promise that resolves to the connection, if found.
|
|
33
|
-
*/
|
|
34
|
-
async get(selector) {
|
|
35
|
-
return (await this.readConnections()).find(([s]) => isSelectorMatch(selector, s))?.[1];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Sets a connection for the given selector.
|
|
39
|
-
* @param selector - The account selector.
|
|
40
|
-
* @param connection - The connection to set.
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
async set(selector, connection) {
|
|
44
|
-
const operation = this.operationLock
|
|
45
|
-
.catch(() => undefined)
|
|
46
|
-
.then(async () => {
|
|
47
|
-
const connections = await this.readConnections();
|
|
48
|
-
if (connection) {
|
|
49
|
-
const existed = connections.find(([s]) => isSelectorMatch(s, selector));
|
|
50
|
-
if (existed) {
|
|
51
|
-
existed[1] = connection;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
connections.push([selector, connection]);
|
|
55
|
-
}
|
|
56
|
-
window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !isSelectorMatch(s, selector))));
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
this.operationLock = operation;
|
|
63
|
-
await operation;
|
|
64
|
-
}
|
|
65
|
-
}
|
package/dist/evm/index.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import { ConnectionsRepo } from "../connectionsStorage/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Class representing an EVM signer that extends SignerEvm
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export declare class EvmSigner extends ccc.SignerEvm {
|
|
8
|
-
private readonly name;
|
|
9
|
-
private readonly icon;
|
|
10
|
-
private readonly _appUri?;
|
|
11
|
-
private readonly connectionsRepo;
|
|
12
|
-
private connection?;
|
|
13
|
-
/**
|
|
14
|
-
* Ensures that the signer is connected and returns the connection.
|
|
15
|
-
* @throws Will throw an error if not connected.
|
|
16
|
-
* @returns The current connection.
|
|
17
|
-
*/
|
|
18
|
-
private assertConnection;
|
|
19
|
-
/**
|
|
20
|
-
* Creates an instance of EvmSigner.
|
|
21
|
-
* @param client - The client instance.
|
|
22
|
-
* @param name - The name of the signer.
|
|
23
|
-
* @param icon - The icon URL of the signer.
|
|
24
|
-
* @param _appUri - The application URI.
|
|
25
|
-
* @param connectionsRepo - The connections repository.
|
|
26
|
-
*/
|
|
27
|
-
constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
28
|
-
/**
|
|
29
|
-
* Gets the configuration for JoyID.
|
|
30
|
-
* @returns The configuration object.
|
|
31
|
-
*/
|
|
32
|
-
private getConfig;
|
|
33
|
-
/**
|
|
34
|
-
* Gets the EVM account address.
|
|
35
|
-
* @returns A promise that resolves to the EVM account address.
|
|
36
|
-
*/
|
|
37
|
-
getEvmAccount(): Promise<ccc.Hex>;
|
|
38
|
-
/**
|
|
39
|
-
* Connects to the provider by requesting authentication.
|
|
40
|
-
* @returns A promise that resolves when the connection is established.
|
|
41
|
-
*/
|
|
42
|
-
connect(): Promise<void>;
|
|
43
|
-
disconnect(): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Checks if the signer is connected.
|
|
46
|
-
* @returns A promise that resolves to true if connected, false otherwise.
|
|
47
|
-
*/
|
|
48
|
-
isConnected(): Promise<boolean>;
|
|
49
|
-
/**
|
|
50
|
-
* Signs a raw message with the EVM account.
|
|
51
|
-
* @param message - The message to sign.
|
|
52
|
-
* @returns A promise that resolves to the signed message.
|
|
53
|
-
*/
|
|
54
|
-
signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex>;
|
|
55
|
-
/**
|
|
56
|
-
* Saves the current connection.
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
private saveConnection;
|
|
60
|
-
/**
|
|
61
|
-
* Restores the previous connection.
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
private restoreConnection;
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/evm/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,gCAAgC,CAAC;AAExC;;;GAGG;AACH,qBAAa,SAAU,SAAQ,GAAG,CAAC,SAAS;IA0BxC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IA5BlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;OAIG;YACW,gBAAgB;IAQ9B;;;;;;;OAOG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,YAAA,EAChB,eAAe,GAAE,eAAmD;IAKvF;;;OAGG;IACH,OAAO,CAAC,SAAS;IAcjB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAIvC;;;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;;;OAGG;YACW,cAAc;IAU5B;;;OAGG;YACW,iBAAiB;CAMhC"}
|
package/dist/evm/index.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import { DappRequestType, buildJoyIDURL } from "@joyid/common";
|
|
3
|
-
import { createPopup } from "../common/index.js";
|
|
4
|
-
import { ConnectionsRepoLocalStorage, } from "../connectionsStorage/index.js";
|
|
5
|
-
/**
|
|
6
|
-
* Class representing an EVM signer that extends SignerEvm
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export class EvmSigner extends ccc.SignerEvm {
|
|
10
|
-
/**
|
|
11
|
-
* Ensures that the signer is connected and returns the connection.
|
|
12
|
-
* @throws Will throw an error if not connected.
|
|
13
|
-
* @returns The current connection.
|
|
14
|
-
*/
|
|
15
|
-
async assertConnection() {
|
|
16
|
-
if (!(await this.isConnected()) || !this.connection) {
|
|
17
|
-
throw new Error("Not connected");
|
|
18
|
-
}
|
|
19
|
-
return this.connection;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Creates an instance of EvmSigner.
|
|
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
|
-
*/
|
|
29
|
-
constructor(client, name, icon, _appUri, connectionsRepo = new ConnectionsRepoLocalStorage()) {
|
|
30
|
-
super(client);
|
|
31
|
-
this.name = name;
|
|
32
|
-
this.icon = icon;
|
|
33
|
-
this._appUri = _appUri;
|
|
34
|
-
this.connectionsRepo = connectionsRepo;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Gets the configuration for JoyID.
|
|
38
|
-
* @returns The configuration object.
|
|
39
|
-
*/
|
|
40
|
-
getConfig() {
|
|
41
|
-
return {
|
|
42
|
-
redirectURL: location.href,
|
|
43
|
-
joyidAppURL: this._appUri ??
|
|
44
|
-
(this.client.addressPrefix === "ckb"
|
|
45
|
-
? "https://app.joy.id"
|
|
46
|
-
: "https://testnet.joyid.dev"),
|
|
47
|
-
requestNetwork: `ethereum`,
|
|
48
|
-
name: this.name,
|
|
49
|
-
logo: this.icon,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Gets the EVM account address.
|
|
54
|
-
* @returns A promise that resolves to the EVM account address.
|
|
55
|
-
*/
|
|
56
|
-
async getEvmAccount() {
|
|
57
|
-
return (await this.assertConnection()).address;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Connects to the provider by requesting authentication.
|
|
61
|
-
* @returns A promise that resolves when the connection is established.
|
|
62
|
-
*/
|
|
63
|
-
async connect() {
|
|
64
|
-
const config = this.getConfig();
|
|
65
|
-
const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
|
|
66
|
-
...config,
|
|
67
|
-
type: DappRequestType.Auth,
|
|
68
|
-
});
|
|
69
|
-
this.connection = {
|
|
70
|
-
address: res.ethAddress,
|
|
71
|
-
publicKey: ccc.hexFrom(res.pubkey),
|
|
72
|
-
keyType: res.keyType,
|
|
73
|
-
};
|
|
74
|
-
await this.saveConnection();
|
|
75
|
-
}
|
|
76
|
-
async disconnect() {
|
|
77
|
-
await super.disconnect();
|
|
78
|
-
this.connection = undefined;
|
|
79
|
-
await this.saveConnection();
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Checks if the signer is connected.
|
|
83
|
-
* @returns A promise that resolves to true if connected, false otherwise.
|
|
84
|
-
*/
|
|
85
|
-
async isConnected() {
|
|
86
|
-
if (this.connection) {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
await this.restoreConnection();
|
|
90
|
-
return this.connection !== undefined;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Signs a raw message with the EVM account.
|
|
94
|
-
* @param message - The message to sign.
|
|
95
|
-
* @returns A promise that resolves to the signed message.
|
|
96
|
-
*/
|
|
97
|
-
async signMessageRaw(message) {
|
|
98
|
-
const { address } = await this.assertConnection();
|
|
99
|
-
const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
|
|
100
|
-
const config = this.getConfig();
|
|
101
|
-
const { signature } = await createPopup(buildJoyIDURL({
|
|
102
|
-
...config,
|
|
103
|
-
challenge,
|
|
104
|
-
isData: typeof message !== "string",
|
|
105
|
-
address,
|
|
106
|
-
}, "popup", "/sign-message"), { ...config, type: DappRequestType.SignMessage });
|
|
107
|
-
return ccc.hexFrom(signature);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Saves the current connection.
|
|
111
|
-
* @returns
|
|
112
|
-
*/
|
|
113
|
-
async saveConnection() {
|
|
114
|
-
return this.connectionsRepo.set({
|
|
115
|
-
uri: this.getConfig().joyidAppURL,
|
|
116
|
-
addressType: "ethereum",
|
|
117
|
-
}, this.connection);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Restores the previous connection.
|
|
121
|
-
* @returns
|
|
122
|
-
*/
|
|
123
|
-
async restoreConnection() {
|
|
124
|
-
this.connection = await this.connectionsRepo.get({
|
|
125
|
-
uri: this.getConfig().joyidAppURL,
|
|
126
|
-
addressType: "ethereum",
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as JoyId from "./barrel.js";
|
package/dist/nostr/index.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import { ConnectionsRepo } from "../connectionsStorage/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Class representing a Nostr signer that extends SignerNostr
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export declare class NostrSigner extends ccc.SignerNostr {
|
|
8
|
-
private readonly name;
|
|
9
|
-
private readonly icon;
|
|
10
|
-
private readonly _appUri?;
|
|
11
|
-
private readonly connectionsRepo;
|
|
12
|
-
private connection?;
|
|
13
|
-
/**
|
|
14
|
-
* Ensures that the signer is connected and returns the connection.
|
|
15
|
-
* @throws Will throw an error if not connected.
|
|
16
|
-
* @returns The current connection.
|
|
17
|
-
*/
|
|
18
|
-
private assertConnection;
|
|
19
|
-
/**
|
|
20
|
-
* Creates an instance of NostrSigner.
|
|
21
|
-
* @param client - The client instance.
|
|
22
|
-
* @param name - The name of the signer.
|
|
23
|
-
* @param icon - The icon URL of the signer.
|
|
24
|
-
* @param _appUri - The application URI.
|
|
25
|
-
* @param connectionsRepo - The connections repository.
|
|
26
|
-
*/
|
|
27
|
-
constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
28
|
-
/**
|
|
29
|
-
* Gets the configuration for JoyID.
|
|
30
|
-
* @returns The configuration object.
|
|
31
|
-
*/
|
|
32
|
-
private getConfig;
|
|
33
|
-
/**
|
|
34
|
-
* Connects to the provider by requesting authentication.
|
|
35
|
-
* @returns A promise that resolves when the connection is established.
|
|
36
|
-
*/
|
|
37
|
-
connect(): Promise<void>;
|
|
38
|
-
disconnect(): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Checks if the signer is connected.
|
|
41
|
-
* @returns A promise that resolves to true if connected, false otherwise.
|
|
42
|
-
*/
|
|
43
|
-
isConnected(): Promise<boolean>;
|
|
44
|
-
getNostrPublicKey(): Promise<ccc.Hex>;
|
|
45
|
-
signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
|
|
46
|
-
/**
|
|
47
|
-
* Saves the current connection.
|
|
48
|
-
* @returns
|
|
49
|
-
*/
|
|
50
|
-
private saveConnection;
|
|
51
|
-
/**
|
|
52
|
-
* Restores the previous connection.
|
|
53
|
-
* @returns
|
|
54
|
-
*/
|
|
55
|
-
private restoreConnection;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,gCAAgC,CAAC;AAExC;;;GAGG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;IA0B5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IA5BlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;OAIG;YACW,gBAAgB;IAQ9B;;;;;;;OAOG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,YAAA,EAChB,eAAe,GAAE,eAAmD;IAKvF;;;OAGG;IACH,OAAO,CAAC,SAAS;IAcjB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAexB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAS/B,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAIrC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAYpC;;;OAGG;YACW,cAAc;IAU5B;;;OAGG;YACW,iBAAiB;CAMhC"}
|
package/dist/nostr/index.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import { DappRequestType, buildJoyIDURL } from "@joyid/common";
|
|
3
|
-
import { createPopup } from "../common/index.js";
|
|
4
|
-
import { ConnectionsRepoLocalStorage, } from "../connectionsStorage/index.js";
|
|
5
|
-
/**
|
|
6
|
-
* Class representing a Nostr signer that extends SignerNostr
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export class NostrSigner extends ccc.SignerNostr {
|
|
10
|
-
/**
|
|
11
|
-
* Ensures that the signer is connected and returns the connection.
|
|
12
|
-
* @throws Will throw an error if not connected.
|
|
13
|
-
* @returns The current connection.
|
|
14
|
-
*/
|
|
15
|
-
async assertConnection() {
|
|
16
|
-
if (!(await this.isConnected()) || !this.connection) {
|
|
17
|
-
throw new Error("Not connected");
|
|
18
|
-
}
|
|
19
|
-
return this.connection;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Creates an instance of NostrSigner.
|
|
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
|
-
*/
|
|
29
|
-
constructor(client, name, icon, _appUri, connectionsRepo = new ConnectionsRepoLocalStorage()) {
|
|
30
|
-
super(client);
|
|
31
|
-
this.name = name;
|
|
32
|
-
this.icon = icon;
|
|
33
|
-
this._appUri = _appUri;
|
|
34
|
-
this.connectionsRepo = connectionsRepo;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Gets the configuration for JoyID.
|
|
38
|
-
* @returns The configuration object.
|
|
39
|
-
*/
|
|
40
|
-
getConfig() {
|
|
41
|
-
return {
|
|
42
|
-
redirectURL: location.href,
|
|
43
|
-
joyidAppURL: this._appUri ??
|
|
44
|
-
(this.client.addressPrefix === "ckb"
|
|
45
|
-
? "https://app.joy.id"
|
|
46
|
-
: "https://testnet.joyid.dev"),
|
|
47
|
-
requestNetwork: "nostr",
|
|
48
|
-
name: this.name,
|
|
49
|
-
logo: this.icon,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Connects to the provider by requesting authentication.
|
|
54
|
-
* @returns A promise that resolves when the connection is established.
|
|
55
|
-
*/
|
|
56
|
-
async connect() {
|
|
57
|
-
const config = this.getConfig();
|
|
58
|
-
const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
|
|
59
|
-
...config,
|
|
60
|
-
type: DappRequestType.Auth,
|
|
61
|
-
});
|
|
62
|
-
this.connection = {
|
|
63
|
-
address: "",
|
|
64
|
-
publicKey: ccc.hexFrom(res.nostrPubkey),
|
|
65
|
-
keyType: res.keyType,
|
|
66
|
-
};
|
|
67
|
-
await this.saveConnection();
|
|
68
|
-
}
|
|
69
|
-
async disconnect() {
|
|
70
|
-
await super.disconnect();
|
|
71
|
-
this.connection = undefined;
|
|
72
|
-
await this.saveConnection();
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Checks if the signer is connected.
|
|
76
|
-
* @returns A promise that resolves to true if connected, false otherwise.
|
|
77
|
-
*/
|
|
78
|
-
async isConnected() {
|
|
79
|
-
if (this.connection) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
await this.restoreConnection();
|
|
83
|
-
return this.connection !== undefined;
|
|
84
|
-
}
|
|
85
|
-
async getNostrPublicKey() {
|
|
86
|
-
return (await this.assertConnection()).publicKey;
|
|
87
|
-
}
|
|
88
|
-
async signNostrEvent(event) {
|
|
89
|
-
const config = this.getConfig();
|
|
90
|
-
const res = await createPopup(buildJoyIDURL({ ...config, event }, "popup", "/sign-nostr-event"), {
|
|
91
|
-
...config,
|
|
92
|
-
type: DappRequestType.SignNostrEvent,
|
|
93
|
-
});
|
|
94
|
-
return res.event;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Saves the current connection.
|
|
98
|
-
* @returns
|
|
99
|
-
*/
|
|
100
|
-
async saveConnection() {
|
|
101
|
-
return this.connectionsRepo.set({
|
|
102
|
-
uri: this.getConfig().joyidAppURL,
|
|
103
|
-
addressType: "nostr",
|
|
104
|
-
}, this.connection);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Restores the previous connection.
|
|
108
|
-
* @returns
|
|
109
|
-
*/
|
|
110
|
-
async restoreConnection() {
|
|
111
|
-
this.connection = await this.connectionsRepo.get({
|
|
112
|
-
uri: this.getConfig().joyidAppURL,
|
|
113
|
-
addressType: "nostr",
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
/**
|
|
3
|
-
* Gets the JoyID signers based on the client, name, and icon.
|
|
4
|
-
* If the browser is standalone or a webview, returns SignerAlwaysError instances.
|
|
5
|
-
* Otherwise, returns instances of CkbSigner, BitcoinSigner, and EvmSigner.
|
|
6
|
-
* @public
|
|
7
|
-
*
|
|
8
|
-
* @param client - The client instance.
|
|
9
|
-
* @param name - The name of the signer.
|
|
10
|
-
* @param icon - The icon URL of the signer.
|
|
11
|
-
* @returns An array of signer information objects.
|
|
12
|
-
*/
|
|
13
|
-
export declare function getJoyIdSigners(client: ccc.Client, name: string, icon: string, preferredNetworks?: ccc.NetworkPreference[]): ccc.SignerInfo[];
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signerFactory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAOpC;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,iBAAiB,CAAC,EAAE,GAAG,CAAC,iBAAiB,EAAE,GAC1C,GAAG,CAAC,UAAU,EAAE,CA8ClB"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import { isStandaloneBrowser } from "@joyid/common";
|
|
3
|
-
import { BitcoinSigner } from "../btc/index.js";
|
|
4
|
-
import { CkbSigner } from "../ckb/index.js";
|
|
5
|
-
import { EvmSigner } from "../evm/index.js";
|
|
6
|
-
import { NostrSigner } from "../nostr/index.js";
|
|
7
|
-
/**
|
|
8
|
-
* Gets the JoyID signers based on the client, name, and icon.
|
|
9
|
-
* If the browser is standalone or a webview, returns SignerAlwaysError instances.
|
|
10
|
-
* Otherwise, returns instances of CkbSigner, BitcoinSigner, and EvmSigner.
|
|
11
|
-
* @public
|
|
12
|
-
*
|
|
13
|
-
* @param client - The client instance.
|
|
14
|
-
* @param name - The name of the signer.
|
|
15
|
-
* @param icon - The icon URL of the signer.
|
|
16
|
-
* @returns An array of signer information objects.
|
|
17
|
-
*/
|
|
18
|
-
export function getJoyIdSigners(client, name, icon, preferredNetworks) {
|
|
19
|
-
if (isStandaloneBrowser() || ccc.isWebview(window.navigator.userAgent)) {
|
|
20
|
-
return [ccc.SignerType.CKB, ccc.SignerType.EVM, ccc.SignerType.BTC].map((type) => ({
|
|
21
|
-
name: type,
|
|
22
|
-
signer: new ccc.SignerAlwaysError(client, type, "JoyID can only be used with standard browsers"),
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
return [
|
|
26
|
-
{
|
|
27
|
-
name: "CKB",
|
|
28
|
-
signer: new CkbSigner(client, name, icon),
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: "BTC",
|
|
32
|
-
signer: new BitcoinSigner(client, name, icon, preferredNetworks),
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: "Nostr",
|
|
36
|
-
signer: new NostrSigner(client, name, icon),
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "EVM",
|
|
40
|
-
signer: new EvmSigner(client, name, icon),
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "BTC (P2WPKH)",
|
|
44
|
-
signer: new BitcoinSigner(client, name, icon, preferredNetworks, "p2wpkh"),
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: "BTC (P2TR)",
|
|
48
|
-
signer: new BitcoinSigner(client, name, icon, preferredNetworks, "p2tr"),
|
|
49
|
-
},
|
|
50
|
-
];
|
|
51
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAC"}
|