@ckb-ccc/joy-id 1.0.32 → 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 +29 -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/src/btc/index.ts +76 -0
- 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 -65
- package/dist/btc/index.d.ts.map +0 -1
- package/dist/btc/index.js +0 -153
- 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 -65
- package/dist.commonjs/btc/index.d.ts.map +0 -1
- package/dist.commonjs/btc/index.js +0 -157
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @ckb-ccc/joy-id
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
### Minor Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#381](https://github.com/ckb-devrel/ccc/pull/381) [`46cc045`](https://github.com/ckb-devrel/ccc/commit/46cc045a3eefe9ba6625482dc7f740a0c59c99d4) Thanks [@Hanssen0](https://github.com/Hanssen0)! - chore: bump packages
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`46cc045`](https://github.com/ckb-devrel/ccc/commit/46cc045a3eefe9ba6625482dc7f740a0c59c99d4)]:
|
|
14
|
+
- @ckb-ccc/core@1.14.0
|
|
15
|
+
|
|
16
|
+
## 1.0.33
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
- [#346](https://github.com/ckb-devrel/ccc/pull/346) [`a803d5f`](https://github.com/ckb-devrel/ccc/commit/a803d5fba8d0e082c6aba14db156856025402e72) Thanks [@fghdotio](https://github.com/fghdotio)! - feat(core): add BTC PSBT signing support
|
|
22
|
+
|
|
23
|
+
- Add `SignerBtc.signPsbt()`, `signAndBroadcastPsbt()`, and `broadcastPsbt()` for signing and broadcasting PSBTs
|
|
24
|
+
- Add `SignPsbtOptions` and `InputToSign` for configuring PSBT signing
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
- [#379](https://github.com/ckb-devrel/ccc/pull/379) [`f01a05b`](https://github.com/ckb-devrel/ccc/commit/f01a05bab332d9f4e0cf7f84aecfd688f8e9f346) Thanks [@Hanssen0](https://github.com/Hanssen0)! - chore: bump pnpm to v11.8.0
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [[`1148a5c`](https://github.com/ckb-devrel/ccc/commit/1148a5c403cde985fb4ba713ccfa0c163d287174), [`bf0f8d8`](https://github.com/ckb-devrel/ccc/commit/bf0f8d8ca011e627821445a10bc38519510e5b9d), [`a803d5f`](https://github.com/ckb-devrel/ccc/commit/a803d5fba8d0e082c6aba14db156856025402e72), [`bf0f8d8`](https://github.com/ckb-devrel/ccc/commit/bf0f8d8ca011e627821445a10bc38519510e5b9d), [`6727ffe`](https://github.com/ckb-devrel/ccc/commit/6727ffe05f60e6bfb2060a565c19acb0fd0f375e), [`f01a05b`](https://github.com/ckb-devrel/ccc/commit/f01a05bab332d9f4e0cf7f84aecfd688f8e9f346), [`a526890`](https://github.com/ckb-devrel/ccc/commit/a5268909ea9d61c4e2f5187a43e2318327b27cae), [`4bb3d9d`](https://github.com/ckb-devrel/ccc/commit/4bb3d9d2ef36b3ee8820036625abd9befb1980c4), [`9f7ecb6`](https://github.com/ckb-devrel/ccc/commit/9f7ecb6ab8db9c6866dad029f2888e1e5cfcbe7d)]:
|
|
30
|
+
- @ckb-ccc/core@1.13.0
|
|
31
|
+
|
|
3
32
|
## 1.0.32
|
|
4
33
|
### Patch Changes
|
|
5
34
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./advancedBarrel.mjs";export{e as JoyIdA};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { a as isSelectorMatch, i as ConnectionsRepoLocalStorage, n as Connection, r as ConnectionsRepo, t as AccountSelector } from "./index-DGqAOLbu.mjs";
|
|
2
|
+
import { AuthResponseData, DappRequestType, EvmWeb2LoginResponse, PopupConfigOptions, SignCkbTxResponseData, SignCotaNFTResponseData, SignEvmTxResponseData, SignMessageResponseData, SignNostrEventData } from "@joyid/common";
|
|
3
|
+
|
|
4
|
+
//#region src/common/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Interface representing the return type for various Dapp request types.
|
|
7
|
+
*/
|
|
8
|
+
interface PopupReturnType {
|
|
9
|
+
[DappRequestType.Auth]: AuthResponseData;
|
|
10
|
+
[DappRequestType.SignMessage]: SignMessageResponseData;
|
|
11
|
+
[DappRequestType.SignEvm]: SignEvmTxResponseData;
|
|
12
|
+
[DappRequestType.SignPsbt]: SignEvmTxResponseData;
|
|
13
|
+
[DappRequestType.BatchSignPsbt]: {
|
|
14
|
+
psbts: string[];
|
|
15
|
+
};
|
|
16
|
+
[DappRequestType.SignCkbTx]: SignCkbTxResponseData;
|
|
17
|
+
[DappRequestType.SignCotaNFT]: SignCotaNFTResponseData;
|
|
18
|
+
[DappRequestType.SignCkbRawTx]: SignCkbTxResponseData;
|
|
19
|
+
[DappRequestType.SignNostrEvent]: SignNostrEventData;
|
|
20
|
+
[DappRequestType.EncryptNostrMessage]: unknown;
|
|
21
|
+
[DappRequestType.DecryptNostrMessage]: unknown;
|
|
22
|
+
[DappRequestType.AuthMiniApp]: unknown;
|
|
23
|
+
[DappRequestType.SignMiniAppEvm]: unknown;
|
|
24
|
+
[DappRequestType.SignMiniAppMessage]: unknown;
|
|
25
|
+
[DappRequestType.EvmWeb2Login]: EvmWeb2LoginResponse;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a popup window for JoyID Dapp requests.
|
|
29
|
+
* @param url - The URL to open in the popup.
|
|
30
|
+
* @param config - The popup configuration options.
|
|
31
|
+
* @returns A promise that resolves to the response data of the requested type.
|
|
32
|
+
* @throws {PopupNotSupportedError} If popups are not supported in the current browser.
|
|
33
|
+
* @throws {PopupCancelledError} If the popup is closed by the user.
|
|
34
|
+
* @throws {PopupTimeoutError} If the popup operation times out.
|
|
35
|
+
*/
|
|
36
|
+
declare function createPopup<T extends DappRequestType>(url: string, config: PopupConfigOptions<T> & {
|
|
37
|
+
joyidAppURL: string;
|
|
38
|
+
}): Promise<PopupReturnType[T]>;
|
|
39
|
+
declare namespace advancedBarrel_d_exports {
|
|
40
|
+
export { AccountSelector, Connection, ConnectionsRepo, ConnectionsRepoLocalStorage, PopupReturnType, createPopup, isSelectorMatch };
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { AccountSelector, Connection, ConnectionsRepo, ConnectionsRepoLocalStorage, PopupReturnType, createPopup, isSelectorMatch, advancedBarrel_d_exports as t };
|
|
44
|
+
//# sourceMappingURL=advancedBarrel.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel.d.mts","names":[],"sources":["../src/common/index.ts","../src/advancedBarrel.ts"],"mappings":";;;;;;;UAuBiB,eAAA;EAAA,CACd,eAAA,CAAgB,IAAA,GAAO,gBAAA;EAAA,CACvB,eAAA,CAAgB,WAAA,GAAc,uBAAA;EAAA,CAC9B,eAAA,CAAgB,OAAA,GAAU,qBAAA;EAAA,CAC1B,eAAA,CAAgB,QAAA,GAAW,qBAAA;EAAA,CAC3B,eAAA,CAAgB,aAAA;IACf,KAAA;EAAA;EAAA,CAED,eAAA,CAAgB,SAAA,GAAY,qBAAA;EAAA,CAC5B,eAAA,CAAgB,WAAA,GAAc,uBAAA;EAAA,CAC9B,eAAA,CAAgB,YAAA,GAAe,qBAAA;EAAA,CAC/B,eAAA,CAAgB,cAAA,GAAiB,kBAAA;EAAA,CACjC,eAAA,CAAgB,mBAAA;EAAA,CAChB,eAAA,CAAgB,mBAAA;EAAA,CAChB,eAAA,CAAgB,WAAA;EAAA,CAChB,eAAA,CAAgB,cAAA;EAAA,CAChB,eAAA,CAAgB,kBAAA;EAAA,CAChB,eAAA,CAAgB,YAAA,GAAe,oBAAA;AAAA;;;;;;;;;;iBAYZ,WAAA,WAAsB,eAAA,EAC1C,GAAA,UACA,MAAA,EAAQ,kBAAA,CAAmB,CAAA;EAAO,WAAA;AAAA,IACjC,OAAA,CAAQ,eAAA,CAAgB,CAAA;AAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.mjs";import{n as t,r as n,t as r}from"./connectionsStorage-BloUSPun.mjs";var i=e({ConnectionsRepoLocalStorage:()=>r,createPopup:()=>n,isSelectorMatch:()=>t});export{r as ConnectionsRepoLocalStorage,n as createPopup,t as isSelectorMatch,i as t};
|
|
2
|
+
//# sourceMappingURL=advancedBarrel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel.mjs","names":[],"sources":["../src/advancedBarrel.ts"],"sourcesContent":["export * from \"./common/index.js\";\nexport * from \"./connectionsStorage/index.js\";\n"],"mappings":""}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { r as ConnectionsRepo } from "./index-DGqAOLbu.mjs";
|
|
2
|
+
import { ccc } from "@ckb-ccc/core";
|
|
3
|
+
|
|
4
|
+
//#region src/btc/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a Bitcoin signer that extends SignerBtc
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
declare class BitcoinSigner extends ccc.SignerBtc {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly icon: string;
|
|
12
|
+
private readonly preferredNetworks;
|
|
13
|
+
readonly addressType: "auto" | "p2wpkh" | "p2tr";
|
|
14
|
+
private readonly _appUri?;
|
|
15
|
+
private readonly connectionsRepo;
|
|
16
|
+
private connection?;
|
|
17
|
+
private network;
|
|
18
|
+
/**
|
|
19
|
+
* Ensures that the signer is connected and returns the connection.
|
|
20
|
+
* @throws Will throw an error if not connected.
|
|
21
|
+
* @returns The current connection.
|
|
22
|
+
*/
|
|
23
|
+
private assertConnection;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an instance of BitcoinSigner.
|
|
26
|
+
* @param client - The client instance.
|
|
27
|
+
* @param name - The name of the signer.
|
|
28
|
+
* @param icon - The icon URL of the signer.
|
|
29
|
+
* @param addressType - The address type.
|
|
30
|
+
* @param _appUri - The application URI.
|
|
31
|
+
* @param connectionsRepo - The connections repository.
|
|
32
|
+
*/
|
|
33
|
+
constructor(client: ccc.Client, name: string, icon: string, preferredNetworks?: ccc.NetworkPreference[], addressType?: "auto" | "p2wpkh" | "p2tr", _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
34
|
+
/**
|
|
35
|
+
* Gets the configuration for JoyID.
|
|
36
|
+
* @returns The configuration object.
|
|
37
|
+
*/
|
|
38
|
+
private getConfig;
|
|
39
|
+
disconnect(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the Bitcoin account address.
|
|
42
|
+
* @returns A promise that resolves to the Bitcoin account address.
|
|
43
|
+
*/
|
|
44
|
+
getBtcAccount(): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the Bitcoin public key.
|
|
47
|
+
* @returns A promise that resolves to the Bitcoin public key.
|
|
48
|
+
*/
|
|
49
|
+
getBtcPublicKey(): Promise<ccc.Hex>;
|
|
50
|
+
/**
|
|
51
|
+
* Connects to the provider by requesting authentication.
|
|
52
|
+
* @returns A promise that resolves when the connection is established.
|
|
53
|
+
*/
|
|
54
|
+
connect(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if the signer is connected.
|
|
57
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
58
|
+
*/
|
|
59
|
+
isConnected(): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Signs a raw message with the Bitcoin account.
|
|
62
|
+
* @param message - The message to sign.
|
|
63
|
+
* @returns A promise that resolves to the signed message.
|
|
64
|
+
*/
|
|
65
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Signs a PSBT using JoyID wallet.
|
|
68
|
+
*
|
|
69
|
+
* @param psbtHex - The hex string of PSBT to sign.
|
|
70
|
+
* @returns A promise that resolves to the signed PSBT as a Hex string.
|
|
71
|
+
*/
|
|
72
|
+
signPsbt(psbtHex: ccc.HexLike, options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
|
|
73
|
+
/**
|
|
74
|
+
* Broadcasts a PSBT to the Bitcoin network.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* JoyID does not support broadcasting a signed PSBT directly.
|
|
78
|
+
* It only supports "Sign and Broadcast" as a single atomic operation via `signAndBroadcastPsbt`.
|
|
79
|
+
*/
|
|
80
|
+
broadcastPsbt(_psbtHex: ccc.HexLike, _options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
|
|
81
|
+
signAndBroadcastPsbt(psbtHex: ccc.HexLike, options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/ckb/index.d.ts
|
|
85
|
+
/**
|
|
86
|
+
* Class representing a CKB signer that extends Signer
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
declare class CkbSigner extends ccc.Signer {
|
|
90
|
+
private readonly name;
|
|
91
|
+
private readonly icon;
|
|
92
|
+
private readonly _appUri?;
|
|
93
|
+
private readonly _aggregatorUri?;
|
|
94
|
+
private readonly connectionsRepo;
|
|
95
|
+
/**
|
|
96
|
+
* Gets the signer type.
|
|
97
|
+
* @returns The type of the signer.
|
|
98
|
+
*/
|
|
99
|
+
get type(): ccc.SignerType;
|
|
100
|
+
/**
|
|
101
|
+
* Gets the sign type.
|
|
102
|
+
* @returns The sign type.
|
|
103
|
+
*/
|
|
104
|
+
get signType(): ccc.SignerSignType;
|
|
105
|
+
private connection?;
|
|
106
|
+
/**
|
|
107
|
+
* Ensures that the signer is connected and returns the connection.
|
|
108
|
+
* @throws Will throw an error if not connected.
|
|
109
|
+
* @returns A promise that resolves to the current connection.
|
|
110
|
+
*/
|
|
111
|
+
private assertConnection;
|
|
112
|
+
/**
|
|
113
|
+
* Creates an instance of CkbSigner.
|
|
114
|
+
* @param client - The client instance.
|
|
115
|
+
* @param name - The name of the signer.
|
|
116
|
+
* @param icon - The icon URL of the signer.
|
|
117
|
+
* @param _appUri - The application URI.
|
|
118
|
+
* @param _aggregatorUri - The aggregator URI.
|
|
119
|
+
* @param connectionsRepo - The connections repository.
|
|
120
|
+
*/
|
|
121
|
+
constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, _aggregatorUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
122
|
+
/**
|
|
123
|
+
* Gets the configuration for JoyID.
|
|
124
|
+
* @returns The configuration object.
|
|
125
|
+
*/
|
|
126
|
+
private getConfig;
|
|
127
|
+
/**
|
|
128
|
+
* Gets the aggregator URI.
|
|
129
|
+
* @returns The aggregator URI.
|
|
130
|
+
*/
|
|
131
|
+
private getAggregatorUri;
|
|
132
|
+
/**
|
|
133
|
+
* Connects to the provider by requesting authentication.
|
|
134
|
+
* @returns A promise that resolves when the connection is established.
|
|
135
|
+
*/
|
|
136
|
+
connect(): Promise<void>;
|
|
137
|
+
disconnect(): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Checks if the signer is connected.
|
|
140
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
141
|
+
*/
|
|
142
|
+
isConnected(): Promise<boolean>;
|
|
143
|
+
/**
|
|
144
|
+
* Gets the internal address.
|
|
145
|
+
* @returns A promise that resolves to the internal address.
|
|
146
|
+
*/
|
|
147
|
+
getInternalAddress(): Promise<string>;
|
|
148
|
+
/**
|
|
149
|
+
* Gets the identity of the signer.
|
|
150
|
+
* @returns A promise that resolves to the identity.
|
|
151
|
+
*/
|
|
152
|
+
getIdentity(): Promise<string>;
|
|
153
|
+
/**
|
|
154
|
+
* Gets the address object.
|
|
155
|
+
* @returns A promise that resolves to the address object.
|
|
156
|
+
*/
|
|
157
|
+
getAddressObj(): Promise<ccc.Address>;
|
|
158
|
+
/**
|
|
159
|
+
* Gets the address objects.
|
|
160
|
+
* @returns A promise that resolves to an array of address objects.
|
|
161
|
+
*/
|
|
162
|
+
getAddressObjs(): Promise<ccc.Address[]>;
|
|
163
|
+
/**
|
|
164
|
+
* Prepares a transaction.
|
|
165
|
+
* @param txLike - The transaction-like object.
|
|
166
|
+
* @returns A promise that resolves to the prepared transaction.
|
|
167
|
+
*/
|
|
168
|
+
prepareTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
|
|
169
|
+
/**
|
|
170
|
+
* Prepares a transaction for a sub key.
|
|
171
|
+
* @param tx - The transaction object.
|
|
172
|
+
* @param witness - The witness arguments.
|
|
173
|
+
* @throws Will throw an error if no COTA cells are found for the sub key wallet.
|
|
174
|
+
*/
|
|
175
|
+
private prepareTransactionForSubKey;
|
|
176
|
+
/**
|
|
177
|
+
* Signs a transaction.
|
|
178
|
+
* @param txLike - The transaction-like object.
|
|
179
|
+
* @returns A promise that resolves to the signed transaction.
|
|
180
|
+
*/
|
|
181
|
+
signOnlyTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
|
|
182
|
+
/**
|
|
183
|
+
* Signs a raw message with the account.
|
|
184
|
+
* @param message - The message to sign.
|
|
185
|
+
* @returns A promise that resolves to the signed message.
|
|
186
|
+
*/
|
|
187
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
188
|
+
/**
|
|
189
|
+
* Saves the current connection.
|
|
190
|
+
* @returns
|
|
191
|
+
*/
|
|
192
|
+
private saveConnection;
|
|
193
|
+
/**
|
|
194
|
+
* Restores the previous connection.
|
|
195
|
+
* @returns
|
|
196
|
+
*/
|
|
197
|
+
private restoreConnection;
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/evm/index.d.ts
|
|
201
|
+
/**
|
|
202
|
+
* Class representing an EVM signer that extends SignerEvm
|
|
203
|
+
* @public
|
|
204
|
+
*/
|
|
205
|
+
declare class EvmSigner extends ccc.SignerEvm {
|
|
206
|
+
private readonly name;
|
|
207
|
+
private readonly icon;
|
|
208
|
+
private readonly _appUri?;
|
|
209
|
+
private readonly connectionsRepo;
|
|
210
|
+
private connection?;
|
|
211
|
+
/**
|
|
212
|
+
* Ensures that the signer is connected and returns the connection.
|
|
213
|
+
* @throws Will throw an error if not connected.
|
|
214
|
+
* @returns The current connection.
|
|
215
|
+
*/
|
|
216
|
+
private assertConnection;
|
|
217
|
+
/**
|
|
218
|
+
* Creates an instance of EvmSigner.
|
|
219
|
+
* @param client - The client instance.
|
|
220
|
+
* @param name - The name of the signer.
|
|
221
|
+
* @param icon - The icon URL of the signer.
|
|
222
|
+
* @param _appUri - The application URI.
|
|
223
|
+
* @param connectionsRepo - The connections repository.
|
|
224
|
+
*/
|
|
225
|
+
constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
226
|
+
/**
|
|
227
|
+
* Gets the configuration for JoyID.
|
|
228
|
+
* @returns The configuration object.
|
|
229
|
+
*/
|
|
230
|
+
private getConfig;
|
|
231
|
+
/**
|
|
232
|
+
* Gets the EVM account address.
|
|
233
|
+
* @returns A promise that resolves to the EVM account address.
|
|
234
|
+
*/
|
|
235
|
+
getEvmAccount(): Promise<ccc.Hex>;
|
|
236
|
+
/**
|
|
237
|
+
* Connects to the provider by requesting authentication.
|
|
238
|
+
* @returns A promise that resolves when the connection is established.
|
|
239
|
+
*/
|
|
240
|
+
connect(): Promise<void>;
|
|
241
|
+
disconnect(): Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* Checks if the signer is connected.
|
|
244
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
245
|
+
*/
|
|
246
|
+
isConnected(): Promise<boolean>;
|
|
247
|
+
/**
|
|
248
|
+
* Signs a raw message with the EVM account.
|
|
249
|
+
* @param message - The message to sign.
|
|
250
|
+
* @returns A promise that resolves to the signed message.
|
|
251
|
+
*/
|
|
252
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex>;
|
|
253
|
+
/**
|
|
254
|
+
* Saves the current connection.
|
|
255
|
+
* @returns
|
|
256
|
+
*/
|
|
257
|
+
private saveConnection;
|
|
258
|
+
/**
|
|
259
|
+
* Restores the previous connection.
|
|
260
|
+
* @returns
|
|
261
|
+
*/
|
|
262
|
+
private restoreConnection;
|
|
263
|
+
}
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/nostr/index.d.ts
|
|
266
|
+
/**
|
|
267
|
+
* Class representing a Nostr signer that extends SignerNostr
|
|
268
|
+
* @public
|
|
269
|
+
*/
|
|
270
|
+
declare class NostrSigner extends ccc.SignerNostr {
|
|
271
|
+
private readonly name;
|
|
272
|
+
private readonly icon;
|
|
273
|
+
private readonly _appUri?;
|
|
274
|
+
private readonly connectionsRepo;
|
|
275
|
+
private connection?;
|
|
276
|
+
/**
|
|
277
|
+
* Ensures that the signer is connected and returns the connection.
|
|
278
|
+
* @throws Will throw an error if not connected.
|
|
279
|
+
* @returns The current connection.
|
|
280
|
+
*/
|
|
281
|
+
private assertConnection;
|
|
282
|
+
/**
|
|
283
|
+
* Creates an instance of NostrSigner.
|
|
284
|
+
* @param client - The client instance.
|
|
285
|
+
* @param name - The name of the signer.
|
|
286
|
+
* @param icon - The icon URL of the signer.
|
|
287
|
+
* @param _appUri - The application URI.
|
|
288
|
+
* @param connectionsRepo - The connections repository.
|
|
289
|
+
*/
|
|
290
|
+
constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
291
|
+
/**
|
|
292
|
+
* Gets the configuration for JoyID.
|
|
293
|
+
* @returns The configuration object.
|
|
294
|
+
*/
|
|
295
|
+
private getConfig;
|
|
296
|
+
/**
|
|
297
|
+
* Connects to the provider by requesting authentication.
|
|
298
|
+
* @returns A promise that resolves when the connection is established.
|
|
299
|
+
*/
|
|
300
|
+
connect(): Promise<void>;
|
|
301
|
+
disconnect(): Promise<void>;
|
|
302
|
+
/**
|
|
303
|
+
* Checks if the signer is connected.
|
|
304
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
305
|
+
*/
|
|
306
|
+
isConnected(): Promise<boolean>;
|
|
307
|
+
getNostrPublicKey(): Promise<ccc.Hex>;
|
|
308
|
+
signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
|
|
309
|
+
/**
|
|
310
|
+
* Saves the current connection.
|
|
311
|
+
* @returns
|
|
312
|
+
*/
|
|
313
|
+
private saveConnection;
|
|
314
|
+
/**
|
|
315
|
+
* Restores the previous connection.
|
|
316
|
+
* @returns
|
|
317
|
+
*/
|
|
318
|
+
private restoreConnection;
|
|
319
|
+
}
|
|
320
|
+
//#endregion
|
|
321
|
+
//#region src/signerFactory/index.d.ts
|
|
322
|
+
/**
|
|
323
|
+
* Gets the JoyID signers based on the client, name, and icon.
|
|
324
|
+
* If the browser is standalone or a webview, returns SignerAlwaysError instances.
|
|
325
|
+
* Otherwise, returns instances of CkbSigner, BitcoinSigner, and EvmSigner.
|
|
326
|
+
* @public
|
|
327
|
+
*
|
|
328
|
+
* @param client - The client instance.
|
|
329
|
+
* @param name - The name of the signer.
|
|
330
|
+
* @param icon - The icon URL of the signer.
|
|
331
|
+
* @returns An array of signer information objects.
|
|
332
|
+
*/
|
|
333
|
+
declare function getJoyIdSigners(client: ccc.Client, name: string, icon: string, preferredNetworks?: ccc.NetworkPreference[]): ccc.SignerInfo[];
|
|
334
|
+
declare namespace barrel_d_exports {
|
|
335
|
+
export { BitcoinSigner, CkbSigner, EvmSigner, NostrSigner, getJoyIdSigners };
|
|
336
|
+
}
|
|
337
|
+
//#endregion
|
|
338
|
+
export { BitcoinSigner, CkbSigner, EvmSigner, NostrSigner, getJoyIdSigners, barrel_d_exports as t };
|
|
339
|
+
//# sourceMappingURL=barrel.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.d.mts","names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BIKgB,eAAA,CACd,MAAA,EAAQ,GAAA,CAAI,MAAA,EACZ,IAAA,UACA,IAAA,UACA,iBAAA,GAAoB,GAAA,CAAI,iBAAA,KACvB,GAAA,CAAI,UAAA;AAAA"}
|
package/dist/barrel.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.mjs";import{r as t,t as n}from"./connectionsStorage-BloUSPun.mjs";import{ccc as r}from"@ckb-ccc/core";import{DappRequestType as i,buildJoyIDURL as a,isStandaloneBrowser as o}from"@joyid/common";import{Aggregator as s}from"@joyid/ckb";var c=class extends r.SignerBtc{async assertConnection(){if(!await this.isConnected()||!this.connection)throw Error(`Not connected`);return this.connection}constructor(e,t,i,a=[{addressPrefix:`ckb`,signerType:r.SignerType.BTC,network:`btc`},{addressPrefix:`ckt`,signerType:r.SignerType.BTC,network:`btcTestnet`}],o=`auto`,s,c=new n){super(e),this.name=t,this.icon=i,this.preferredNetworks=a,this.addressType=o,this._appUri=s,this.connectionsRepo=c,this.network=`btcTestnet`}getConfig(){let{network:e}=this.matchNetworkPreference(this.preferredNetworks,this.network)??{network:this.network};this.network!==e&&(this.connection=void 0),this.network=e;let t={btc:`https://app.joy.id`,btcTestnet:`https://testnet.joyid.dev`}[e];if(!t)throw Error(`JoyID wallet doesn't support the requested chain ${this.network}`);return{redirectURL:location.href,joyidAppURL:this._appUri??t,requestNetwork:`btc-${this.addressType}`,name:this.name,logo:this.icon}}async disconnect(){await super.disconnect(),await this.connectionsRepo.set({uri:this.getConfig().joyidAppURL,addressType:`btc`},void 0)}async getBtcAccount(){let{address:e}=await this.assertConnection();return e}async getBtcPublicKey(){let{publicKey:e}=await this.assertConnection();return e}async connect(){let e=this.getConfig(),n=await t(a(e,`popup`,`/auth`),{...e,type:i.Auth}),{address:o,pubkey:s}=this.addressType===`auto`?n.btcAddressType===`p2wpkh`?n.nativeSegwit:n.taproot:this.addressType===`p2wpkh`?n.nativeSegwit:n.taproot;this.connection={address:o,publicKey:r.hexFrom(s),keyType:n.keyType},await Promise.all([this.connectionsRepo.set({uri:e.joyidAppURL,addressType:`btc-${this.addressType}`},this.connection),this.connectionsRepo.set({uri:e.joyidAppURL,addressType:`btc-auto`},this.connection)])}async isConnected(){return this.connection?!0:(this.connection=await this.connectionsRepo.get({uri:this.getConfig().joyidAppURL,addressType:`btc-${this.addressType}`}),this.connection!==void 0)}async signMessageRaw(e){let{address:n}=await this.assertConnection(),o=typeof e==`string`?e:r.hexFrom(e).slice(2),s=this.getConfig(),{signature:c}=await t(a({...s,challenge:o,address:n,signMessageType:`ecdsa`},`popup`,`/sign-message`),{...s,type:i.SignMessage});return c}async signPsbt(e,n){let{address:o}=await this.assertConnection(),s=r.SignPsbtOptions.from(n),c=this.getConfig(),{tx:l}=await t(a({...c,tx:r.hexFrom(e).slice(2),options:s,signerAddress:o,autoFinalized:s.autoFinalized},`popup`,`/sign-psbt`),{...c,type:i.SignPsbt});return r.hexFrom(l)}async broadcastPsbt(e,t){throw Error(`JoyID does not support broadcasting signed PSBTs directly. Use signAndBroadcastPsbt instead.`)}async signAndBroadcastPsbt(e,n){let{address:o}=await this.assertConnection(),s=r.SignPsbtOptions.from(n),c=this.getConfig(),{tx:l}=await t(a({...c,tx:r.hexFrom(e).slice(2),options:s,signerAddress:o,autoFinalized:!0,isSend:!0},`popup`,`/sign-psbt`),{...c,type:i.SignPsbt});return r.hexFrom(l)}},l=class extends r.Signer{get type(){return r.SignerType.CKB}get signType(){return r.SignerSignType.JoyId}async assertConnection(){if(!await this.isConnected()||!this.connection)throw Error(`Not connected`);return this.connection}constructor(e,t,r,i,a,o=new n){super(e),this.name=t,this.icon=r,this._appUri=i,this._aggregatorUri=a,this.connectionsRepo=o}getConfig(){return{redirectURL:location.href,joyidAppURL:this._appUri??(this.client.addressPrefix===`ckb`?`https://app.joy.id`:`https://testnet.joyid.dev`),name:this.name,logo:this.icon}}getAggregatorUri(){return this._aggregatorUri??(this.client.addressPrefix===`ckb`?`https://cota.nervina.dev/mainnet-aggregator`:`https://cota.nervina.dev/aggregator`)}async connect(){let e=this.getConfig(),n=await t(a(e,`popup`,`/auth`),{...e,type:i.Auth});this.connection={address:n.address,publicKey:r.hexFrom(n.pubkey),keyType:n.keyType},await this.saveConnection()}async disconnect(){await super.disconnect(),this.connection=void 0,await this.saveConnection()}async isConnected(){return this.connection?!0:(await this.restoreConnection(),this.connection!==void 0)}async getInternalAddress(){return(await this.assertConnection()).address}async getIdentity(){let e=await this.assertConnection();return JSON.stringify({keyType:e.keyType,publicKey:e.publicKey.slice(2)})}async getAddressObj(){return await r.Address.fromString(await this.getInternalAddress(),this.client)}async getAddressObjs(){return[await this.getAddressObj()]}async prepareTransaction(e){let t=r.Transaction.from(e);await t.addCellDepsOfKnownScripts(this.client,r.KnownScript.JoyId);let n=await t.findInputIndexByLock((await this.getAddressObj()).script,this.client);if(n===void 0)return t;let i=t.getWitnessArgsAt(n)??r.WitnessArgs.from({});return i.lock=r.hexFrom(`00`.repeat(1e3)),await this.prepareTransactionForSubKey(t,i),t.setWitnessArgsAt(n,i),t}async prepareTransactionForSubKey(e,t){if(this.connection?.keyType!==`sub_key`||(t.outputType??`0x`)!==`0x`)return;let n=r.hashCkb(this.connection.publicKey).substring(0,42),i=(await this.getAddressObj()).script,{unlock_entry:a}=await new s(this.getAggregatorUri()).generateSubkeyUnlockSmt({alg_index:1,pubkey_hash:n,lock_script:r.hexFrom(i.toBytes())});t.outputType=r.hexFrom(a);let o=[];for await(let e of this.client.findCellsByLock(i,await r.Script.fromKnownScript(this.client,r.KnownScript.COTA,`0x`)))o.push(r.CellDep.from({depType:`code`,outPoint:e.outPoint}));if(o.length===0)throw Error(`No COTA cells for sub key wallet`);e.addCellDepsAtStart(o)}async signOnlyTransaction(e){let n=r.Transaction.from(e),{script:o}=await this.getAddressObj(),s=await r.reduceAsync(n.inputs,async(e,t,n)=>{let{cellOutput:r}=await t.getCell(this.client);r.lock.eq(o)&&e.push(n)},[]);await n.prepareSighashAllWitness(o,0,this.client),n.inputs.forEach(e=>{e.cellOutput=void 0,e.outputData=void 0});let c=this.getConfig(),l=await t(a({...c,tx:JSON.parse(n.stringify()),signerAddress:(await this.assertConnection()).address,witnessIndexes:s},`popup`,`/sign-ckb-raw-tx`),{...c,type:i.SignCkbRawTx});return r.Transaction.from(l.tx)}async signMessageRaw(e){let{address:n}=await this.assertConnection(),o=typeof e==`string`?e:r.hexFrom(e).slice(2),s=this.getConfig(),c=await t(a({...s,challenge:o,isData:typeof e!=`string`,address:n},`popup`,`/sign-message`),{...s,type:i.SignMessage});return JSON.stringify({signature:c.signature,alg:c.alg,message:c.message})}async saveConnection(){return this.connectionsRepo.set({uri:this.getConfig().joyidAppURL,addressType:`ckb`},this.connection)}async restoreConnection(){this.connection=await this.connectionsRepo.get({uri:this.getConfig().joyidAppURL,addressType:`ckb`})}},u=class extends r.SignerEvm{async assertConnection(){if(!await this.isConnected()||!this.connection)throw Error(`Not connected`);return this.connection}constructor(e,t,r,i,a=new n){super(e),this.name=t,this.icon=r,this._appUri=i,this.connectionsRepo=a}getConfig(){return{redirectURL:location.href,joyidAppURL:this._appUri??(this.client.addressPrefix===`ckb`?`https://app.joy.id`:`https://testnet.joyid.dev`),requestNetwork:`ethereum`,name:this.name,logo:this.icon}}async getEvmAccount(){return(await this.assertConnection()).address}async connect(){let e=this.getConfig(),n=await t(a(e,`popup`,`/auth`),{...e,type:i.Auth});this.connection={address:n.ethAddress,publicKey:r.hexFrom(n.pubkey),keyType:n.keyType},await this.saveConnection()}async disconnect(){await super.disconnect(),this.connection=void 0,await this.saveConnection()}async isConnected(){return this.connection?!0:(await this.restoreConnection(),this.connection!==void 0)}async signMessageRaw(e){let{address:n}=await this.assertConnection(),o=typeof e==`string`?e:r.hexFrom(e).slice(2),s=this.getConfig(),{signature:c}=await t(a({...s,challenge:o,isData:typeof e!=`string`,address:n},`popup`,`/sign-message`),{...s,type:i.SignMessage});return r.hexFrom(c)}async saveConnection(){return this.connectionsRepo.set({uri:this.getConfig().joyidAppURL,addressType:`ethereum`},this.connection)}async restoreConnection(){this.connection=await this.connectionsRepo.get({uri:this.getConfig().joyidAppURL,addressType:`ethereum`})}},d=class extends r.SignerNostr{async assertConnection(){if(!await this.isConnected()||!this.connection)throw Error(`Not connected`);return this.connection}constructor(e,t,r,i,a=new n){super(e),this.name=t,this.icon=r,this._appUri=i,this.connectionsRepo=a}getConfig(){return{redirectURL:location.href,joyidAppURL:this._appUri??(this.client.addressPrefix===`ckb`?`https://app.joy.id`:`https://testnet.joyid.dev`),requestNetwork:`nostr`,name:this.name,logo:this.icon}}async connect(){let e=this.getConfig(),n=await t(a(e,`popup`,`/auth`),{...e,type:i.Auth});this.connection={address:``,publicKey:r.hexFrom(n.nostrPubkey),keyType:n.keyType},await this.saveConnection()}async disconnect(){await super.disconnect(),this.connection=void 0,await this.saveConnection()}async isConnected(){return this.connection?!0:(await this.restoreConnection(),this.connection!==void 0)}async getNostrPublicKey(){return(await this.assertConnection()).publicKey}async signNostrEvent(e){let n=this.getConfig();return(await t(a({...n,event:e},`popup`,`/sign-nostr-event`),{...n,type:i.SignNostrEvent})).event}async saveConnection(){return this.connectionsRepo.set({uri:this.getConfig().joyidAppURL,addressType:`nostr`},this.connection)}async restoreConnection(){this.connection=await this.connectionsRepo.get({uri:this.getConfig().joyidAppURL,addressType:`nostr`})}};function f(e,t,n,i){return o()||r.isWebview(window.navigator.userAgent)?[r.SignerType.CKB,r.SignerType.EVM,r.SignerType.BTC].map(t=>({name:t,signer:new r.SignerAlwaysError(e,t,`JoyID can only be used with standard browsers`)})):[{name:`CKB`,signer:new l(e,t,n)},{name:`BTC`,signer:new c(e,t,n,i)},{name:`Nostr`,signer:new d(e,t,n)},{name:`EVM`,signer:new u(e,t,n)},{name:`BTC (P2WPKH)`,signer:new c(e,t,n,i,`p2wpkh`)},{name:`BTC (P2TR)`,signer:new c(e,t,n,i,`p2tr`)}]}var p=e({BitcoinSigner:()=>c,CkbSigner:()=>l,EvmSigner:()=>u,NostrSigner:()=>d,getJoyIdSigners:()=>f});export{c as BitcoinSigner,l as CkbSigner,u as EvmSigner,d as NostrSigner,f as getJoyIdSigners,p as t};
|
|
2
|
+
//# sourceMappingURL=barrel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.mjs","names":[],"sources":["../src/btc/index.ts","../src/ckb/index.ts","../src/evm/index.ts","../src/nostr/index.ts","../src/signerFactory/index.ts","../src/barrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\nimport { DappRequestType, buildJoyIDURL } from \"@joyid/common\";\nimport { createPopup } from \"../common/index.js\";\nimport {\n Connection,\n ConnectionsRepo,\n ConnectionsRepoLocalStorage,\n} from \"../connectionsStorage/index.js\";\n\n/**\n * Class representing a Bitcoin signer that extends SignerBtc\n * @public\n */\nexport class BitcoinSigner extends ccc.SignerBtc {\n private connection?: Connection;\n private network = \"btcTestnet\";\n\n /**\n * Ensures that the signer is connected and returns the connection.\n * @throws Will throw an error if not connected.\n * @returns The current connection.\n */\n private async assertConnection(): Promise<Connection> {\n if (!(await this.isConnected()) || !this.connection) {\n throw new Error(\"Not connected\");\n }\n\n return this.connection;\n }\n\n /**\n * Creates an instance of BitcoinSigner.\n * @param client - The client instance.\n * @param name - The name of the signer.\n * @param icon - The icon URL of the signer.\n * @param addressType - The address type.\n * @param _appUri - The application URI.\n * @param connectionsRepo - The connections repository.\n */\n constructor(\n client: ccc.Client,\n public readonly name: string,\n public readonly icon: string,\n private readonly preferredNetworks: ccc.NetworkPreference[] = [\n {\n addressPrefix: \"ckb\",\n signerType: ccc.SignerType.BTC,\n network: \"btc\",\n },\n {\n addressPrefix: \"ckt\",\n signerType: ccc.SignerType.BTC,\n network: \"btcTestnet\",\n },\n ],\n public readonly addressType: \"auto\" | \"p2wpkh\" | \"p2tr\" = \"auto\",\n private readonly _appUri?: string,\n private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),\n ) {\n super(client);\n }\n\n /**\n * Gets the configuration for JoyID.\n * @returns The configuration object.\n */\n private getConfig() {\n const { network } = this.matchNetworkPreference(\n this.preferredNetworks,\n this.network,\n ) ?? { network: this.network };\n if (this.network !== network) {\n this.connection = undefined;\n }\n this.network = network;\n\n const url = {\n btc: \"https://app.joy.id\",\n btcTestnet: \"https://testnet.joyid.dev\",\n }[network];\n if (!url) {\n throw new Error(\n `JoyID wallet doesn't support the requested chain ${this.network}`,\n );\n }\n\n return {\n redirectURL: location.href,\n joyidAppURL: this._appUri ?? url,\n requestNetwork: `btc-${this.addressType}`,\n name: this.name,\n logo: this.icon,\n };\n }\n\n async disconnect(): Promise<void> {\n await super.disconnect();\n\n await this.connectionsRepo.set(\n { uri: this.getConfig().joyidAppURL, addressType: \"btc\" },\n undefined,\n );\n }\n\n /**\n * Gets the Bitcoin account address.\n * @returns A promise that resolves to the Bitcoin account address.\n */\n async getBtcAccount(): Promise<string> {\n const { address } = await this.assertConnection();\n return address;\n }\n\n /**\n * Gets the Bitcoin public key.\n * @returns A promise that resolves to the Bitcoin public key.\n */\n async getBtcPublicKey(): Promise<ccc.Hex> {\n const { publicKey } = await this.assertConnection();\n return publicKey;\n }\n\n /**\n * Connects to the provider by requesting authentication.\n * @returns A promise that resolves when the connection is established.\n */\n async connect(): Promise<void> {\n const config = this.getConfig();\n const res = await createPopup(buildJoyIDURL(config, \"popup\", \"/auth\"), {\n ...config,\n type: DappRequestType.Auth,\n });\n\n const { address, pubkey } = (() => {\n if (this.addressType === \"auto\") {\n return res.btcAddressType === \"p2wpkh\" ? res.nativeSegwit : res.taproot;\n }\n return this.addressType === \"p2wpkh\" ? res.nativeSegwit : res.taproot;\n })();\n\n this.connection = {\n address,\n publicKey: ccc.hexFrom(pubkey),\n keyType: res.keyType,\n };\n await Promise.all([\n this.connectionsRepo.set(\n { uri: config.joyidAppURL, addressType: `btc-${this.addressType}` },\n this.connection,\n ),\n this.connectionsRepo.set(\n { uri: config.joyidAppURL, addressType: \"btc-auto\" },\n this.connection,\n ),\n ]);\n }\n\n /**\n * Checks if the signer is connected.\n * @returns A promise that resolves to true if connected, false otherwise.\n */\n async isConnected(): Promise<boolean> {\n if (this.connection) {\n return true;\n }\n\n this.connection = await this.connectionsRepo.get({\n uri: this.getConfig().joyidAppURL,\n addressType: `btc-${this.addressType}`,\n });\n return this.connection !== undefined;\n }\n\n /**\n * Signs a raw message with the Bitcoin account.\n * @param message - The message to sign.\n * @returns A promise that resolves to the signed message.\n */\n async signMessageRaw(message: string | ccc.BytesLike): Promise<string> {\n const { address } = await this.assertConnection();\n\n const challenge =\n typeof message === \"string\" ? message : ccc.hexFrom(message).slice(2);\n\n const config = this.getConfig();\n const { signature } = await createPopup(\n buildJoyIDURL(\n {\n ...config,\n challenge,\n address,\n signMessageType: \"ecdsa\",\n },\n \"popup\",\n \"/sign-message\",\n ),\n { ...config, type: DappRequestType.SignMessage },\n );\n return signature;\n }\n\n /**\n * Signs a PSBT using JoyID wallet.\n *\n * @param psbtHex - The hex string of PSBT to sign.\n * @returns A promise that resolves to the signed PSBT as a Hex string.\n */\n async signPsbt(\n psbtHex: ccc.HexLike,\n options?: ccc.SignPsbtOptionsLike,\n ): Promise<ccc.Hex> {\n const { address } = await this.assertConnection();\n const formattedOptions = ccc.SignPsbtOptions.from(options);\n\n const config = this.getConfig();\n const { tx: signedPsbtHex } = await createPopup(\n buildJoyIDURL(\n {\n ...config,\n tx: ccc.hexFrom(psbtHex).slice(2),\n options: formattedOptions,\n signerAddress: address,\n autoFinalized: formattedOptions.autoFinalized,\n },\n \"popup\",\n \"/sign-psbt\",\n ),\n { ...config, type: DappRequestType.SignPsbt },\n );\n\n return ccc.hexFrom(signedPsbtHex);\n }\n\n /**\n * Broadcasts a PSBT to the Bitcoin network.\n *\n * @remarks\n * JoyID does not support broadcasting a signed PSBT directly.\n * It only supports \"Sign and Broadcast\" as a single atomic operation via `signAndBroadcastPsbt`.\n */\n async broadcastPsbt(\n _psbtHex: ccc.HexLike,\n _options?: ccc.SignPsbtOptionsLike,\n ): Promise<ccc.Hex> {\n throw new Error(\n \"JoyID does not support broadcasting signed PSBTs directly. Use signAndBroadcastPsbt instead.\",\n );\n }\n\n async signAndBroadcastPsbt(\n psbtHex: ccc.HexLike,\n options?: ccc.SignPsbtOptionsLike,\n ): Promise<ccc.Hex> {\n const { address } = await this.assertConnection();\n const formattedOptions = ccc.SignPsbtOptions.from(options);\n\n const config = this.getConfig();\n // ccc.hexFrom adds 0x prefix, but BTC expects non-0x\n const { tx: txid } = await createPopup(\n buildJoyIDURL(\n {\n ...config,\n tx: ccc.hexFrom(psbtHex).slice(2),\n options: formattedOptions,\n signerAddress: address,\n autoFinalized: true, // sendPsbt always finalizes\n isSend: true,\n },\n \"popup\",\n \"/sign-psbt\",\n ),\n { ...config, type: DappRequestType.SignPsbt }, // Use SignPsbt type for both operations\n );\n\n return ccc.hexFrom(txid);\n }\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { Aggregator } from \"@joyid/ckb\";\nimport { DappRequestType, buildJoyIDURL } from \"@joyid/common\";\nimport { createPopup } from \"../common/index.js\";\nimport {\n Connection,\n ConnectionsRepo,\n ConnectionsRepoLocalStorage,\n} from \"../connectionsStorage/index.js\";\n\n/**\n * Class representing a CKB signer that extends Signer\n * @public\n */\nexport class CkbSigner extends ccc.Signer {\n /**\n * Gets the signer type.\n * @returns The type of the signer.\n */\n get type(): ccc.SignerType {\n return ccc.SignerType.CKB;\n }\n\n /**\n * Gets the sign type.\n * @returns The sign type.\n */\n get signType(): ccc.SignerSignType {\n return ccc.SignerSignType.JoyId;\n }\n\n private connection?: Connection;\n\n /**\n * Ensures that the signer is connected and returns the connection.\n * @throws Will throw an error if not connected.\n * @returns A promise that resolves to the current connection.\n */\n private async assertConnection(): Promise<Connection> {\n if (!(await this.isConnected()) || !this.connection) {\n throw new Error(\"Not connected\");\n }\n\n return this.connection;\n }\n\n /**\n * Creates an instance of CkbSigner.\n * @param client - The client instance.\n * @param name - The name of the signer.\n * @param icon - The icon URL of the signer.\n * @param _appUri - The application URI.\n * @param _aggregatorUri - The aggregator URI.\n * @param connectionsRepo - The connections repository.\n */\n constructor(\n client: ccc.Client,\n private readonly name: string,\n private readonly icon: string,\n private readonly _appUri?: string,\n private readonly _aggregatorUri?: string,\n private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),\n ) {\n super(client);\n }\n\n /**\n * Gets the configuration for JoyID.\n * @returns The configuration object.\n */\n private getConfig() {\n return {\n redirectURL: location.href,\n joyidAppURL:\n this._appUri ??\n (this.client.addressPrefix === \"ckb\"\n ? \"https://app.joy.id\"\n : \"https://testnet.joyid.dev\"),\n name: this.name,\n logo: this.icon,\n };\n }\n\n /**\n * Gets the aggregator URI.\n * @returns The aggregator URI.\n */\n private getAggregatorUri(): string {\n return (\n this._aggregatorUri ??\n (this.client.addressPrefix === \"ckb\"\n ? \"https://cota.nervina.dev/mainnet-aggregator\"\n : \"https://cota.nervina.dev/aggregator\")\n );\n }\n\n /**\n * Connects to the provider by requesting authentication.\n * @returns A promise that resolves when the connection is established.\n */\n async connect(): Promise<void> {\n const config = this.getConfig();\n\n const res = await createPopup(buildJoyIDURL(config, \"popup\", \"/auth\"), {\n ...config,\n type: DappRequestType.Auth,\n });\n\n this.connection = {\n address: res.address,\n publicKey: ccc.hexFrom(res.pubkey),\n keyType: res.keyType,\n };\n await this.saveConnection();\n }\n\n async disconnect(): Promise<void> {\n await super.disconnect();\n\n this.connection = undefined;\n await this.saveConnection();\n }\n\n /**\n * Checks if the signer is connected.\n * @returns A promise that resolves to true if connected, false otherwise.\n */\n async isConnected(): Promise<boolean> {\n if (this.connection) {\n return true;\n }\n await this.restoreConnection();\n return this.connection !== undefined;\n }\n\n /**\n * Gets the internal address.\n * @returns A promise that resolves to the internal address.\n */\n async getInternalAddress(): Promise<string> {\n return (await this.assertConnection()).address;\n }\n\n /**\n * Gets the identity of the signer.\n * @returns A promise that resolves to the identity.\n */\n async getIdentity(): Promise<string> {\n const connection = await this.assertConnection();\n return JSON.stringify({\n keyType: connection.keyType,\n publicKey: connection.publicKey.slice(2),\n });\n }\n\n /**\n * Gets the address object.\n * @returns A promise that resolves to the address object.\n */\n async getAddressObj(): Promise<ccc.Address> {\n return await ccc.Address.fromString(\n await this.getInternalAddress(),\n this.client,\n );\n }\n\n /**\n * Gets the address objects.\n * @returns A promise that resolves to an array of address objects.\n */\n async getAddressObjs(): Promise<ccc.Address[]> {\n return [await this.getAddressObj()];\n }\n\n /**\n * Prepares a transaction.\n * @param txLike - The transaction-like object.\n * @returns A promise that resolves to the prepared transaction.\n */\n async prepareTransaction(\n txLike: ccc.TransactionLike,\n ): Promise<ccc.Transaction> {\n const tx = ccc.Transaction.from(txLike);\n await tx.addCellDepsOfKnownScripts(this.client, ccc.KnownScript.JoyId);\n const position = await tx.findInputIndexByLock(\n (await this.getAddressObj()).script,\n this.client,\n );\n if (position === undefined) {\n return tx;\n }\n\n const witness = tx.getWitnessArgsAt(position) ?? ccc.WitnessArgs.from({});\n witness.lock = ccc.hexFrom(\"00\".repeat(1000));\n await this.prepareTransactionForSubKey(tx, witness);\n tx.setWitnessArgsAt(position, witness);\n\n return tx;\n }\n\n /**\n * Prepares a transaction for a sub key.\n * @param tx - The transaction object.\n * @param witness - The witness arguments.\n * @throws Will throw an error if no COTA cells are found for the sub key wallet.\n */\n private async prepareTransactionForSubKey(\n tx: ccc.Transaction,\n witness: ccc.WitnessArgs,\n ) {\n if (\n this.connection?.keyType !== \"sub_key\" ||\n (witness.outputType ?? \"0x\") !== \"0x\"\n ) {\n return;\n }\n\n const pubkeyHash = ccc.hashCkb(this.connection.publicKey).substring(0, 42);\n const lock = (await this.getAddressObj()).script;\n const aggregator = new Aggregator(this.getAggregatorUri());\n const { unlock_entry: unlockEntry } =\n await aggregator.generateSubkeyUnlockSmt({\n alg_index: 1,\n pubkey_hash: pubkeyHash,\n lock_script: ccc.hexFrom(lock.toBytes()),\n });\n witness.outputType = ccc.hexFrom(unlockEntry);\n\n const cotaDeps: ccc.CellDep[] = [];\n for await (const cell of this.client.findCellsByLock(\n lock,\n await ccc.Script.fromKnownScript(this.client, ccc.KnownScript.COTA, \"0x\"),\n )) {\n cotaDeps.push(\n ccc.CellDep.from({\n depType: \"code\",\n outPoint: cell.outPoint,\n }),\n );\n }\n\n if (cotaDeps.length === 0) {\n throw new Error(\"No COTA cells for sub key wallet\");\n }\n\n tx.addCellDepsAtStart(cotaDeps);\n }\n\n /**\n * Signs a transaction.\n * @param txLike - The transaction-like object.\n * @returns A promise that resolves to the signed transaction.\n */\n async signOnlyTransaction(\n txLike: ccc.TransactionLike,\n ): Promise<ccc.Transaction> {\n const tx = ccc.Transaction.from(txLike);\n const { script } = await this.getAddressObj();\n const witnessIndexes = await ccc.reduceAsync(\n tx.inputs,\n async (acc, input, i) => {\n const { cellOutput } = await input.getCell(this.client);\n\n if (cellOutput.lock.eq(script)) {\n acc.push(i);\n }\n },\n [] as number[],\n );\n\n // Trim unnecessary fields to reduce tx size\n await tx.prepareSighashAllWitness(script, 0, this.client);\n tx.inputs.forEach((i) => {\n i.cellOutput = undefined;\n i.outputData = undefined;\n });\n\n const config = this.getConfig();\n const res = await createPopup(\n buildJoyIDURL(\n {\n ...config,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n tx: JSON.parse(tx.stringify()),\n signerAddress: (await this.assertConnection()).address,\n witnessIndexes,\n },\n \"popup\",\n \"/sign-ckb-raw-tx\",\n ),\n {\n ...config,\n type: DappRequestType.SignCkbRawTx,\n },\n );\n\n return ccc.Transaction.from(res.tx);\n }\n\n /**\n * Signs a raw message with the account.\n * @param message - The message to sign.\n * @returns A promise that resolves to the signed message.\n */\n async signMessageRaw(message: string | ccc.BytesLike): Promise<string> {\n const { address } = await this.assertConnection();\n\n const challenge =\n typeof message === \"string\" ? message : ccc.hexFrom(message).slice(2);\n\n const config = this.getConfig();\n const res = await createPopup(\n buildJoyIDURL(\n {\n ...config,\n challenge,\n isData: typeof message !== \"string\",\n address,\n },\n \"popup\",\n \"/sign-message\",\n ),\n { ...config, type: DappRequestType.SignMessage },\n );\n return JSON.stringify({\n signature: res.signature,\n alg: res.alg,\n message: res.message,\n });\n }\n\n /**\n * Saves the current connection.\n * @returns\n */\n private async saveConnection(): Promise<void> {\n return this.connectionsRepo.set(\n {\n uri: this.getConfig().joyidAppURL,\n addressType: \"ckb\",\n },\n this.connection,\n );\n }\n\n /**\n * Restores the previous connection.\n * @returns\n */\n private async restoreConnection(): Promise<void> {\n this.connection = await this.connectionsRepo.get({\n uri: this.getConfig().joyidAppURL,\n addressType: \"ckb\",\n });\n }\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { DappRequestType, buildJoyIDURL } from \"@joyid/common\";\nimport { createPopup } from \"../common/index.js\";\nimport {\n Connection,\n ConnectionsRepo,\n ConnectionsRepoLocalStorage,\n} from \"../connectionsStorage/index.js\";\n\n/**\n * Class representing an EVM signer that extends SignerEvm\n * @public\n */\nexport class EvmSigner extends ccc.SignerEvm {\n private connection?: Connection;\n\n /**\n * Ensures that the signer is connected and returns the connection.\n * @throws Will throw an error if not connected.\n * @returns The current connection.\n */\n private async assertConnection(): Promise<Connection> {\n if (!(await this.isConnected()) || !this.connection) {\n throw new Error(\"Not connected\");\n }\n\n return this.connection;\n }\n\n /**\n * Creates an instance of EvmSigner.\n * @param client - The client instance.\n * @param name - The name of the signer.\n * @param icon - The icon URL of the signer.\n * @param _appUri - The application URI.\n * @param connectionsRepo - The connections repository.\n */\n constructor(\n client: ccc.Client,\n private readonly name: string,\n private readonly icon: string,\n private readonly _appUri?: string,\n private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),\n ) {\n super(client);\n }\n\n /**\n * Gets the configuration for JoyID.\n * @returns The configuration object.\n */\n private getConfig() {\n return {\n redirectURL: location.href,\n joyidAppURL:\n this._appUri ??\n (this.client.addressPrefix === \"ckb\"\n ? \"https://app.joy.id\"\n : \"https://testnet.joyid.dev\"),\n requestNetwork: `ethereum`,\n name: this.name,\n logo: this.icon,\n };\n }\n\n /**\n * Gets the EVM account address.\n * @returns A promise that resolves to the EVM account address.\n */\n async getEvmAccount(): Promise<ccc.Hex> {\n return (await this.assertConnection()).address as ccc.Hex;\n }\n\n /**\n * Connects to the provider by requesting authentication.\n * @returns A promise that resolves when the connection is established.\n */\n async connect(): Promise<void> {\n const config = this.getConfig();\n\n const res = await createPopup(buildJoyIDURL(config, \"popup\", \"/auth\"), {\n ...config,\n type: DappRequestType.Auth,\n });\n\n this.connection = {\n address: res.ethAddress,\n publicKey: ccc.hexFrom(res.pubkey),\n keyType: res.keyType,\n };\n await this.saveConnection();\n }\n\n async disconnect(): Promise<void> {\n await super.disconnect();\n\n this.connection = undefined;\n await this.saveConnection();\n }\n\n /**\n * Checks if the signer is connected.\n * @returns A promise that resolves to true if connected, false otherwise.\n */\n async isConnected(): Promise<boolean> {\n if (this.connection) {\n return true;\n }\n await this.restoreConnection();\n return this.connection !== undefined;\n }\n\n /**\n * Signs a raw message with the EVM account.\n * @param message - The message to sign.\n * @returns A promise that resolves to the signed message.\n */\n async signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex> {\n const { address } = await this.assertConnection();\n\n const challenge =\n typeof message === \"string\" ? message : ccc.hexFrom(message).slice(2);\n\n const config = this.getConfig();\n const { signature } = await createPopup(\n buildJoyIDURL(\n {\n ...config,\n challenge,\n isData: typeof message !== \"string\",\n address,\n },\n \"popup\",\n \"/sign-message\",\n ),\n { ...config, type: DappRequestType.SignMessage },\n );\n return ccc.hexFrom(signature);\n }\n\n /**\n * Saves the current connection.\n * @returns\n */\n private async saveConnection(): Promise<void> {\n return this.connectionsRepo.set(\n {\n uri: this.getConfig().joyidAppURL,\n addressType: \"ethereum\",\n },\n this.connection,\n );\n }\n\n /**\n * Restores the previous connection.\n * @returns\n */\n private async restoreConnection(): Promise<void> {\n this.connection = await this.connectionsRepo.get({\n uri: this.getConfig().joyidAppURL,\n addressType: \"ethereum\",\n });\n }\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { DappRequestType, buildJoyIDURL } from \"@joyid/common\";\nimport { createPopup } from \"../common/index.js\";\nimport {\n Connection,\n ConnectionsRepo,\n ConnectionsRepoLocalStorage,\n} from \"../connectionsStorage/index.js\";\n\n/**\n * Class representing a Nostr signer that extends SignerNostr\n * @public\n */\nexport class NostrSigner extends ccc.SignerNostr {\n private connection?: Connection;\n\n /**\n * Ensures that the signer is connected and returns the connection.\n * @throws Will throw an error if not connected.\n * @returns The current connection.\n */\n private async assertConnection(): Promise<Connection> {\n if (!(await this.isConnected()) || !this.connection) {\n throw new Error(\"Not connected\");\n }\n\n return this.connection;\n }\n\n /**\n * Creates an instance of NostrSigner.\n * @param client - The client instance.\n * @param name - The name of the signer.\n * @param icon - The icon URL of the signer.\n * @param _appUri - The application URI.\n * @param connectionsRepo - The connections repository.\n */\n constructor(\n client: ccc.Client,\n private readonly name: string,\n private readonly icon: string,\n private readonly _appUri?: string,\n private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),\n ) {\n super(client);\n }\n\n /**\n * Gets the configuration for JoyID.\n * @returns The configuration object.\n */\n private getConfig() {\n return {\n redirectURL: location.href,\n joyidAppURL:\n this._appUri ??\n (this.client.addressPrefix === \"ckb\"\n ? \"https://app.joy.id\"\n : \"https://testnet.joyid.dev\"),\n requestNetwork: \"nostr\",\n name: this.name,\n logo: this.icon,\n };\n }\n\n /**\n * Connects to the provider by requesting authentication.\n * @returns A promise that resolves when the connection is established.\n */\n async connect(): Promise<void> {\n const config = this.getConfig();\n const res = await createPopup(buildJoyIDURL(config, \"popup\", \"/auth\"), {\n ...config,\n type: DappRequestType.Auth,\n });\n\n this.connection = {\n address: \"\",\n publicKey: ccc.hexFrom(res.nostrPubkey),\n keyType: res.keyType,\n };\n await this.saveConnection();\n }\n\n async disconnect(): Promise<void> {\n await super.disconnect();\n\n this.connection = undefined;\n await this.saveConnection();\n }\n\n /**\n * Checks if the signer is connected.\n * @returns A promise that resolves to true if connected, false otherwise.\n */\n async isConnected(): Promise<boolean> {\n if (this.connection) {\n return true;\n }\n\n await this.restoreConnection();\n return this.connection !== undefined;\n }\n\n async getNostrPublicKey(): Promise<ccc.Hex> {\n return (await this.assertConnection()).publicKey;\n }\n\n async signNostrEvent(\n event: ccc.NostrEvent,\n ): Promise<Required<ccc.NostrEvent>> {\n const config = this.getConfig();\n const res = await createPopup(\n buildJoyIDURL({ ...config, event }, \"popup\", \"/sign-nostr-event\"),\n {\n ...config,\n type: DappRequestType.SignNostrEvent,\n },\n );\n return res.event;\n }\n\n /**\n * Saves the current connection.\n * @returns\n */\n private async saveConnection(): Promise<void> {\n return this.connectionsRepo.set(\n {\n uri: this.getConfig().joyidAppURL,\n addressType: \"nostr\",\n },\n this.connection,\n );\n }\n\n /**\n * Restores the previous connection.\n * @returns\n */\n private async restoreConnection(): Promise<void> {\n this.connection = await this.connectionsRepo.get({\n uri: this.getConfig().joyidAppURL,\n addressType: \"nostr\",\n });\n }\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { isStandaloneBrowser } from \"@joyid/common\";\nimport { BitcoinSigner } from \"../btc/index.js\";\nimport { CkbSigner } from \"../ckb/index.js\";\nimport { EvmSigner } from \"../evm/index.js\";\nimport { NostrSigner } from \"../nostr/index.js\";\n\n/**\n * Gets the JoyID signers based on the client, name, and icon.\n * If the browser is standalone or a webview, returns SignerAlwaysError instances.\n * Otherwise, returns instances of CkbSigner, BitcoinSigner, and EvmSigner.\n * @public\n *\n * @param client - The client instance.\n * @param name - The name of the signer.\n * @param icon - The icon URL of the signer.\n * @returns An array of signer information objects.\n */\nexport function getJoyIdSigners(\n client: ccc.Client,\n name: string,\n icon: string,\n preferredNetworks?: ccc.NetworkPreference[],\n): ccc.SignerInfo[] {\n if (isStandaloneBrowser() || ccc.isWebview(window.navigator.userAgent)) {\n return [ccc.SignerType.CKB, ccc.SignerType.EVM, ccc.SignerType.BTC].map(\n (type) => ({\n name: type,\n signer: new ccc.SignerAlwaysError(\n client,\n type,\n \"JoyID can only be used with standard browsers\",\n ),\n }),\n );\n }\n\n return [\n {\n name: \"CKB\",\n signer: new CkbSigner(client, name, icon),\n },\n {\n name: \"BTC\",\n signer: new BitcoinSigner(client, name, icon, preferredNetworks),\n },\n {\n name: \"Nostr\",\n signer: new NostrSigner(client, name, icon),\n },\n {\n name: \"EVM\",\n signer: new EvmSigner(client, name, icon),\n },\n {\n name: \"BTC (P2WPKH)\",\n signer: new BitcoinSigner(\n client,\n name,\n icon,\n preferredNetworks,\n \"p2wpkh\",\n ),\n },\n {\n name: \"BTC (P2TR)\",\n signer: new BitcoinSigner(client, name, icon, preferredNetworks, \"p2tr\"),\n },\n ];\n}\n","export * from \"./btc/index.js\";\nexport * from \"./ckb/index.js\";\nexport * from \"./evm/index.js\";\nexport * from \"./nostr/index.js\";\nexport * from \"./signerFactory/index.js\";\n"],"mappings":"yRAaA,IAAa,EAAb,cAAmC,EAAI,SAAU,CAS/C,MAAc,kBAAwC,CACpD,GAAI,CAAE,MAAM,KAAK,YAAY,GAAM,CAAC,KAAK,WACvC,MAAU,MAAM,eAAe,EAGjC,OAAO,KAAK,UACd,CAWA,YACE,EACA,EACA,EACA,EAA8D,CAC5D,CACE,cAAe,MACf,WAAY,EAAI,WAAW,IAC3B,QAAS,KACX,EACA,CACE,cAAe,MACf,WAAY,EAAI,WAAW,IAC3B,QAAS,YACX,CACF,EACA,EAA0D,OAC1D,EACA,EAAoD,IAAI,EACxD,CACA,MAAM,CAAM,EAlBI,KAAA,KAAA,EACA,KAAA,KAAA,EACC,KAAA,kBAAA,EAYD,KAAA,YAAA,EACC,KAAA,QAAA,EACA,KAAA,gBAAA,eA1CD,YA6ClB,CAMA,WAAoB,CAClB,GAAM,CAAE,WAAY,KAAK,uBACvB,KAAK,kBACL,KAAK,OACP,GAAK,CAAE,QAAS,KAAK,OAAQ,EACzB,KAAK,UAAY,IACnB,KAAK,WAAa,IAAA,IAEpB,KAAK,QAAU,EAEf,IAAM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ACN,OAAQ,IAAI,EAAI,kBACd,EACA,EACA,+CACF,CACF,EACF,EAGK,CACL,CACE,KAAM,MACN,OAAQ,IAAI,EAAU,EAAQ,EAAM,CAAI,CAC1C,EACA,CACE,KAAM,MACN,OAAQ,IAAI,EAAc,EAAQ,EAAM,EAAM,CAAiB,CACjE,EACA,CACE,KAAM,QACN,OAAQ,IAAI,EAAY,EAAQ,EAAM,CAAI,CAC5C,EACA,CACE,KAAM,MACN,OAAQ,IAAI,EAAU,EAAQ,EAAM,CAAI,CAC1C,EACA,CACE,KAAM,eACN,OAAQ,IAAI,EACV,EACA,EACA,EACA,EACA,QACF,CACF,EACA,CACE,KAAM,aACN,OAAQ,IAAI,EAAc,EAAQ,EAAM,EAAM,EAAmB,MAAM,CACzE,CACF,CACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{PopupCancelledError as e,PopupNotSupportedError as t,PopupTimeoutError as n,createBlockDialog as r,isStandaloneBrowser as i,openPopup as a}from"@joyid/common";async function o(s,c){return c.popup==null&&(c.popup=a(``),c.popup==null)?r(async()=>o(s,c)):(c.popup.location.href=s,new Promise((r,a)=>{i()&&a(new t(c.popup));let o,s,l=setInterval(()=>{c.popup?.closed&&(clearInterval(l),clearTimeout(s),window.removeEventListener(`message`,o,!1),a(new e(c.popup)))},1e3);s=setTimeout(()=>{clearInterval(l),a(new n(c.popup)),window.removeEventListener(`message`,o,!1)},(c.timeoutInSeconds??3e3)*1e3),o=e=>{let{joyidAppURL:t}=c,n=new URL(t);e.origin===n.origin&&(!e.data||e.data?.type!==c.type||(clearTimeout(s),clearInterval(l),window.removeEventListener(`message`,o,!1),c.popup.close(),e.data.error&&a(Error(e.data.error)),r(e.data.data)))},window.addEventListener(`message`,o)}))}function s(e,t){return e.uri===t.uri&&e.addressType.startsWith(t.addressType)}var c=class{constructor(e=`ccc-joy-id-signer`){this.storageKey=e,this.operationLock=Promise.resolve()}async readConnections(){return JSON.parse(window.localStorage.getItem(this.storageKey)??`[]`)}async get(e){return(await this.readConnections()).find(([t])=>s(e,t))?.[1]}async set(e,t){let n=this.operationLock.catch(()=>void 0).then(async()=>{let n=await this.readConnections();if(t){let r=n.find(([t])=>s(t,e));r?r[1]=t:n.push([e,t]),window.localStorage.setItem(this.storageKey,JSON.stringify(n))}else window.localStorage.setItem(this.storageKey,JSON.stringify(n.filter(([t])=>!s(t,e))))});this.operationLock=n,await n}};export{s as n,o as r,c as t};
|
|
2
|
+
//# sourceMappingURL=connectionsStorage-BloUSPun.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectionsStorage-BloUSPun.mjs","names":[],"sources":["../src/common/index.ts","../src/connectionsStorage/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\nimport {\n AuthResponseData,\n DappRequestType,\n EvmWeb2LoginResponse,\n PopupCancelledError,\n PopupConfigOptions,\n PopupNotSupportedError,\n PopupTimeoutError,\n SignCkbTxResponseData,\n SignCotaNFTResponseData,\n SignEvmTxResponseData,\n SignMessageResponseData,\n SignNostrEventData,\n createBlockDialog,\n isStandaloneBrowser,\n openPopup,\n} from \"@joyid/common\";\n\n/**\n * Interface representing the return type for various Dapp request types.\n */\nexport interface PopupReturnType {\n [DappRequestType.Auth]: AuthResponseData;\n [DappRequestType.SignMessage]: SignMessageResponseData;\n [DappRequestType.SignEvm]: SignEvmTxResponseData;\n [DappRequestType.SignPsbt]: SignEvmTxResponseData;\n [DappRequestType.BatchSignPsbt]: {\n psbts: string[];\n };\n [DappRequestType.SignCkbTx]: SignCkbTxResponseData;\n [DappRequestType.SignCotaNFT]: SignCotaNFTResponseData;\n [DappRequestType.SignCkbRawTx]: SignCkbTxResponseData;\n [DappRequestType.SignNostrEvent]: SignNostrEventData;\n [DappRequestType.EncryptNostrMessage]: unknown;\n [DappRequestType.DecryptNostrMessage]: unknown;\n [DappRequestType.AuthMiniApp]: unknown;\n [DappRequestType.SignMiniAppEvm]: unknown;\n [DappRequestType.SignMiniAppMessage]: unknown;\n [DappRequestType.EvmWeb2Login]: EvmWeb2LoginResponse;\n}\n\n/**\n * Creates a popup window for JoyID Dapp requests.\n * @param url - The URL to open in the popup.\n * @param config - The popup configuration options.\n * @returns A promise that resolves to the response data of the requested type.\n * @throws {PopupNotSupportedError} If popups are not supported in the current browser.\n * @throws {PopupCancelledError} If the popup is closed by the user.\n * @throws {PopupTimeoutError} If the popup operation times out.\n */\nexport async function createPopup<T extends DappRequestType>(\n url: string,\n config: PopupConfigOptions<T> & { joyidAppURL: string },\n): Promise<PopupReturnType[T]> {\n if (config.popup == null) {\n config.popup = openPopup(\"\");\n\n if (config.popup == null) {\n return createBlockDialog(async () => createPopup(url, config));\n }\n }\n\n config.popup.location.href = url;\n\n return new Promise((resolve, reject) => {\n if (isStandaloneBrowser()) {\n reject(new PopupNotSupportedError(config.popup));\n }\n let popupEventListener: (e: MessageEvent) => void;\n let timeoutId: undefined | ReturnType<typeof setTimeout>;\n // Check each second if the popup is closed triggering a PopupCancelledError\n const popupTimer = setInterval(() => {\n if (config.popup?.closed) {\n clearInterval(popupTimer);\n clearTimeout(timeoutId);\n window.removeEventListener(\"message\", popupEventListener, false);\n reject(new PopupCancelledError(config.popup));\n }\n }, 1000);\n\n timeoutId = setTimeout(\n () => {\n clearInterval(popupTimer);\n reject(new PopupTimeoutError(config.popup));\n window.removeEventListener(\"message\", popupEventListener, false);\n },\n (config.timeoutInSeconds ?? 3000) * 1000,\n );\n\n popupEventListener = (e: MessageEvent) => {\n const { joyidAppURL } = config;\n const appURL = new URL(joyidAppURL);\n if (e.origin !== appURL.origin) {\n return;\n }\n if (!e.data || e.data?.type !== config.type) {\n return;\n }\n\n clearTimeout(timeoutId);\n clearInterval(popupTimer);\n window.removeEventListener(\"message\", popupEventListener, false);\n config.popup.close();\n if (e.data.error) {\n reject(new Error(e.data.error));\n }\n resolve(e.data.data);\n };\n\n window.addEventListener(\"message\", popupEventListener);\n });\n}\n","import { ccc } from \"@ckb-ccc/core\";\n\n/**\n * Type representing an account selector with a URI and address type.\n */\nexport type AccountSelector = {\n /**\n * The URI of the account.\n */\n uri: string;\n /**\n * The address type of the account.\n */\n addressType: string;\n};\n\n/**\n * Checks if a AccountSelector matches the filter\n * @param a - The first account selector.\n * @param filter - The account selector filter.\n * @returns True if the selector matches the filter\n */\nexport function isSelectorMatch(\n a: AccountSelector,\n filter: AccountSelector,\n): boolean {\n return a.uri === filter.uri && a.addressType.startsWith(filter.addressType);\n}\n\n/**\n * Type representing a connection with an address, public key, and key type.\n */\nexport type Connection = {\n /**\n * The address of the connection.\n */\n readonly address: string;\n /**\n * The public key of the connection.\n */\n readonly publicKey: ccc.Hex;\n /**\n * The key type of the connection.\n */\n readonly keyType: string;\n};\n\n/**\n * Interface representing a repository for managing connections.\n */\nexport interface ConnectionsRepo {\n /**\n * Gets a connection for the given selector.\n * @param selector - The account selector.\n * @returns A promise that resolves to the connection, if found.\n */\n get(selector: AccountSelector): Promise<Connection | undefined>;\n\n /**\n * Sets a connection for the given selector.\n * @param selector - The account selector.\n * @param connection - The connection to set.\n * @returns A promise that resolves when the connection is set.\n */\n set(\n selector: AccountSelector,\n connection: Connection | undefined,\n ): Promise<void>;\n}\n\n/**\n * Class representing a local storage-based repository for managing connections.\n */\nexport class ConnectionsRepoLocalStorage implements ConnectionsRepo {\n private operationLock: Promise<void> = Promise.resolve();\n\n /**\n * Creates an instance of ConnectionsRepoLocalStorage.\n * @param [storageKey=\"ccc-joy-id-signer\"] - The local storage key.\n */\n constructor(private readonly storageKey = \"ccc-joy-id-signer\") {}\n\n /**\n * Reads all connections from local storage.\n * @returns A promise that resolves to an array of selectors and connections.\n */\n async readConnections(): Promise<[AccountSelector, Connection][]> {\n return JSON.parse(window.localStorage.getItem(this.storageKey) ?? \"[]\") as [\n AccountSelector,\n Connection,\n ][];\n }\n\n /**\n * Gets a connection for the given selector.\n * @param selector - The account selector.\n * @returns A promise that resolves to the connection, if found.\n */\n async get(selector: AccountSelector): Promise<Connection | undefined> {\n return (await this.readConnections()).find(([s]) =>\n isSelectorMatch(selector, s),\n )?.[1];\n }\n\n /**\n * Sets a connection for the given selector.\n * @param selector - The account selector.\n * @param connection - The connection to set.\n * @returns\n */\n async set(\n selector: AccountSelector,\n connection: Connection | undefined,\n ): Promise<void> {\n const operation = this.operationLock\n .catch(() => undefined)\n .then(async () => {\n const connections = await this.readConnections();\n\n if (connection) {\n const existed = connections.find(([s]) =>\n isSelectorMatch(s, selector),\n );\n if (existed) {\n existed[1] = connection;\n } else {\n connections.push([selector, connection]);\n }\n window.localStorage.setItem(\n this.storageKey,\n JSON.stringify(connections),\n );\n } else {\n window.localStorage.setItem(\n this.storageKey,\n JSON.stringify(\n connections.filter(([s]) => !isSelectorMatch(s, selector)),\n ),\n );\n }\n });\n\n this.operationLock = operation;\n await operation;\n }\n}\n"],"mappings":"sKAoDA,eAAsB,EACpB,EACA,EAC6B,CAW7B,OAVI,EAAO,OAAS,OAClB,EAAO,MAAQ,EAAU,EAAE,EAEvB,EAAO,OAAS,MACX,EAAkB,SAAY,EAAY,EAAK,CAAM,CAAC,GAIjE,EAAO,MAAM,SAAS,KAAO,EAEtB,IAAI,SAAS,EAAS,IAAW,CAClC,EAAoB,GACtB,EAAO,IAAI,EAAuB,EAAO,KAAK,CAAC,EAEjD,IAAI,EACA,EAEE,EAAa,gBAAkB,CAC/B,EAAO,OAAO,SAChB,cAAc,CAAU,EACxB,aAAa,CAAS,EACtB,OAAO,oBAAoB,UAAW,EAAoB,EAAK,EAC/D,EAAO,IAAI,EAAoB,EAAO,KAAK,CAAC,EAEhD,EAAG,GAAI,EAEP,EAAY,eACJ,CACJ,cAAc,CAAU,EACxB,EAAO,IAAI,EAAkB,EAAO,KAAK,CAAC,EAC1C,OAAO,oBAAoB,UAAW,EAAoB,EAAK,CACjE,GACC,EAAO,kBAAoB,KAAQ,GACtC,EAEA,EAAsB,GAAoB,CACxC,GAAM,CAAE,eAAgB,EACl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