@ckb-ccc/joy-id 0.0.5-alpha.1 → 0.0.5-alpha.10

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.
Files changed (41) hide show
  1. package/dist/btc/index.d.ts +1 -2
  2. package/dist/btc/index.d.ts.map +1 -1
  3. package/dist/btc/index.js +1 -4
  4. package/dist/ckb/index.d.ts +4 -1
  5. package/dist/ckb/index.d.ts.map +1 -1
  6. package/dist/ckb/index.js +41 -15
  7. package/dist/evm/index.d.ts +1 -2
  8. package/dist/evm/index.d.ts.map +1 -1
  9. package/dist/evm/index.js +1 -4
  10. package/dist/signerFactory/index.d.ts.map +1 -1
  11. package/dist/signerFactory/index.js +7 -5
  12. package/dist.commonjs/advanced.d.ts +1 -1
  13. package/dist.commonjs/advanced.js +40 -19
  14. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  15. package/dist.commonjs/advancedBarrel.js +30 -14
  16. package/dist.commonjs/barrel.d.ts +1 -1
  17. package/dist.commonjs/barrel.js +30 -14
  18. package/dist.commonjs/btc/index.d.ts +22 -16
  19. package/dist.commonjs/btc/index.d.ts.map +1 -1
  20. package/dist.commonjs/btc/index.js +99 -76
  21. package/dist.commonjs/ckb/index.d.ts +33 -23
  22. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  23. package/dist.commonjs/ckb/index.js +204 -135
  24. package/dist.commonjs/common/index.d.ts +34 -21
  25. package/dist.commonjs/common/index.js +50 -45
  26. package/dist.commonjs/connectionsStorage/index.d.ts +23 -14
  27. package/dist.commonjs/connectionsStorage/index.js +28 -25
  28. package/dist.commonjs/evm/index.d.ts +21 -16
  29. package/dist.commonjs/evm/index.d.ts.map +1 -1
  30. package/dist.commonjs/evm/index.js +89 -70
  31. package/dist.commonjs/index.d.ts +1 -1
  32. package/dist.commonjs/index.js +40 -19
  33. package/dist.commonjs/signerFactory/index.d.ts +6 -2
  34. package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
  35. package/dist.commonjs/signerFactory/index.js +39 -26
  36. package/package.json +3 -3
  37. package/src/btc/index.ts +1 -12
  38. package/src/ckb/index.ts +55 -22
  39. package/src/evm/index.ts +1 -11
  40. package/src/signerFactory/index.ts +14 -5
  41. package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
@@ -1,24 +1,37 @@
1
- import { AuthResponseData, DappRequestType, EvmWeb2LoginResponse, PopupConfigOptions, SignCkbTxResponseData, SignCotaNFTResponseData, SignEvmTxResponseData, SignMessageResponseData, SignNostrEventData } from "@joyid/common";
1
+ import {
2
+ AuthResponseData,
3
+ DappRequestType,
4
+ EvmWeb2LoginResponse,
5
+ PopupConfigOptions,
6
+ SignCkbTxResponseData,
7
+ SignCotaNFTResponseData,
8
+ SignEvmTxResponseData,
9
+ SignMessageResponseData,
10
+ SignNostrEventData,
11
+ } from "@joyid/common";
2
12
  export interface PopupReturnType {
3
- [DappRequestType.Auth]: AuthResponseData;
4
- [DappRequestType.SignMessage]: SignMessageResponseData;
5
- [DappRequestType.SignEvm]: SignEvmTxResponseData;
6
- [DappRequestType.SignPsbt]: SignEvmTxResponseData;
7
- [DappRequestType.BatchSignPsbt]: {
8
- psbts: string[];
9
- };
10
- [DappRequestType.SignCkbTx]: SignCkbTxResponseData;
11
- [DappRequestType.SignCotaNFT]: SignCotaNFTResponseData;
12
- [DappRequestType.SignCkbRawTx]: SignCkbTxResponseData;
13
- [DappRequestType.SignNostrEvent]: SignNostrEventData;
14
- [DappRequestType.EncryptNostrMessage]: any;
15
- [DappRequestType.DecryptNostrMessage]: any;
16
- [DappRequestType.AuthMiniApp]: any;
17
- [DappRequestType.SignMiniAppEvm]: any;
18
- [DappRequestType.SignMiniAppMessage]: any;
19
- [DappRequestType.EvmWeb2Login]: EvmWeb2LoginResponse;
13
+ [DappRequestType.Auth]: AuthResponseData;
14
+ [DappRequestType.SignMessage]: SignMessageResponseData;
15
+ [DappRequestType.SignEvm]: SignEvmTxResponseData;
16
+ [DappRequestType.SignPsbt]: SignEvmTxResponseData;
17
+ [DappRequestType.BatchSignPsbt]: {
18
+ psbts: string[];
19
+ };
20
+ [DappRequestType.SignCkbTx]: SignCkbTxResponseData;
21
+ [DappRequestType.SignCotaNFT]: SignCotaNFTResponseData;
22
+ [DappRequestType.SignCkbRawTx]: SignCkbTxResponseData;
23
+ [DappRequestType.SignNostrEvent]: SignNostrEventData;
24
+ [DappRequestType.EncryptNostrMessage]: any;
25
+ [DappRequestType.DecryptNostrMessage]: any;
26
+ [DappRequestType.AuthMiniApp]: any;
27
+ [DappRequestType.SignMiniAppEvm]: any;
28
+ [DappRequestType.SignMiniAppMessage]: any;
29
+ [DappRequestType.EvmWeb2Login]: EvmWeb2LoginResponse;
20
30
  }
21
- export declare function createPopup<T extends DappRequestType>(url: string, config: PopupConfigOptions<T> & {
31
+ export declare function createPopup<T extends DappRequestType>(
32
+ url: string,
33
+ config: PopupConfigOptions<T> & {
22
34
  joyidAppURL: string;
23
- }): Promise<PopupReturnType[T]>;
24
- //# sourceMappingURL=index.d.ts.map
35
+ },
36
+ ): Promise<PopupReturnType[T]>;
37
+ //# sourceMappingURL=index.d.ts.map
@@ -3,52 +3,57 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPopup = void 0;
4
4
  const common_1 = require("@joyid/common");
5
5
  async function createPopup(url, config) {
6
+ if (config.popup == null) {
7
+ config.popup = (0, common_1.openPopup)("");
6
8
  if (config.popup == null) {
7
- config.popup = (0, common_1.openPopup)("");
8
- if (config.popup == null) {
9
- return (0, common_1.createBlockDialog)(async () => createPopup(url, config));
10
- }
9
+ return (0, common_1.createBlockDialog)(async () =>
10
+ createPopup(url, config),
11
+ );
11
12
  }
12
- config.popup.location.href = url;
13
- return new Promise((resolve, reject) => {
14
- if ((0, common_1.isStandaloneBrowser)()) {
15
- reject(new common_1.PopupNotSupportedError(config.popup));
16
- }
17
- let popupEventListener;
18
- let timeoutId;
19
- // Check each second if the popup is closed triggering a PopupCancelledError
20
- const popupTimer = setInterval(() => {
21
- if (config.popup?.closed) {
22
- clearInterval(popupTimer);
23
- clearTimeout(timeoutId);
24
- window.removeEventListener("message", popupEventListener, false);
25
- reject(new common_1.PopupCancelledError(config.popup));
26
- }
27
- }, 1000);
28
- timeoutId = setTimeout(() => {
29
- clearInterval(popupTimer);
30
- reject(new common_1.PopupTimeoutError(config.popup));
31
- window.removeEventListener("message", popupEventListener, false);
32
- }, (config.timeoutInSeconds ?? 3000) * 1000);
33
- popupEventListener = (e) => {
34
- const { joyidAppURL } = config;
35
- const appURL = new URL(joyidAppURL);
36
- if (e.origin !== appURL.origin) {
37
- return;
38
- }
39
- if (!e.data || e.data?.type !== config.type) {
40
- return;
41
- }
42
- clearTimeout(timeoutId);
43
- clearInterval(popupTimer);
44
- window.removeEventListener("message", popupEventListener, false);
45
- config.popup.close();
46
- if (e.data.error) {
47
- reject(new Error(e.data.error));
48
- }
49
- resolve(e.data.data);
50
- };
51
- window.addEventListener("message", popupEventListener);
52
- });
13
+ }
14
+ config.popup.location.href = url;
15
+ return new Promise((resolve, reject) => {
16
+ if ((0, common_1.isStandaloneBrowser)()) {
17
+ reject(new common_1.PopupNotSupportedError(config.popup));
18
+ }
19
+ let popupEventListener;
20
+ let timeoutId;
21
+ // Check each second if the popup is closed triggering a PopupCancelledError
22
+ const popupTimer = setInterval(() => {
23
+ if (config.popup?.closed) {
24
+ clearInterval(popupTimer);
25
+ clearTimeout(timeoutId);
26
+ window.removeEventListener("message", popupEventListener, false);
27
+ reject(new common_1.PopupCancelledError(config.popup));
28
+ }
29
+ }, 1000);
30
+ timeoutId = setTimeout(
31
+ () => {
32
+ clearInterval(popupTimer);
33
+ reject(new common_1.PopupTimeoutError(config.popup));
34
+ window.removeEventListener("message", popupEventListener, false);
35
+ },
36
+ (config.timeoutInSeconds ?? 3000) * 1000,
37
+ );
38
+ popupEventListener = (e) => {
39
+ const { joyidAppURL } = config;
40
+ const appURL = new URL(joyidAppURL);
41
+ if (e.origin !== appURL.origin) {
42
+ return;
43
+ }
44
+ if (!e.data || e.data?.type !== config.type) {
45
+ return;
46
+ }
47
+ clearTimeout(timeoutId);
48
+ clearInterval(popupTimer);
49
+ window.removeEventListener("message", popupEventListener, false);
50
+ config.popup.close();
51
+ if (e.data.error) {
52
+ reject(new Error(e.data.error));
53
+ }
54
+ resolve(e.data.data);
55
+ };
56
+ window.addEventListener("message", popupEventListener);
57
+ });
53
58
  }
54
59
  exports.createPopup = createPopup;
@@ -1,23 +1,32 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  export type AccountSelector = {
3
- uri: string;
4
- addressType: string;
3
+ uri: string;
4
+ addressType: string;
5
5
  };
6
- export declare function isSelectorEq(a: AccountSelector, b: AccountSelector): boolean;
6
+ export declare function isSelectorEq(
7
+ a: AccountSelector,
8
+ b: AccountSelector,
9
+ ): boolean;
7
10
  export type Connection = {
8
- readonly address: string;
9
- readonly publicKey: ccc.Hex;
10
- readonly keyType: string;
11
+ readonly address: string;
12
+ readonly publicKey: ccc.Hex;
13
+ readonly keyType: string;
11
14
  };
12
15
  export interface ConnectionsRepo {
13
- get(selector: AccountSelector): Promise<Connection | undefined>;
14
- set(selector: AccountSelector, connection: Connection | undefined): Promise<void>;
16
+ get(selector: AccountSelector): Promise<Connection | undefined>;
17
+ set(
18
+ selector: AccountSelector,
19
+ connection: Connection | undefined,
20
+ ): Promise<void>;
15
21
  }
16
22
  export declare class ConnectionsRepoLocalStorage implements ConnectionsRepo {
17
- private readonly storageKey;
18
- constructor(storageKey?: string);
19
- readConnections(): Promise<[AccountSelector, Connection][]>;
20
- get(selector: AccountSelector): Promise<Connection | undefined>;
21
- set(selector: AccountSelector, connection: Connection | undefined): Promise<void>;
23
+ private readonly storageKey;
24
+ constructor(storageKey?: string);
25
+ readConnections(): Promise<[AccountSelector, Connection][]>;
26
+ get(selector: AccountSelector): Promise<Connection | undefined>;
27
+ set(
28
+ selector: AccountSelector,
29
+ connection: Connection | undefined,
30
+ ): Promise<void>;
22
31
  }
23
- //# sourceMappingURL=index.d.ts.map
32
+ //# sourceMappingURL=index.d.ts.map
@@ -2,34 +2,37 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConnectionsRepoLocalStorage = exports.isSelectorEq = void 0;
4
4
  function isSelectorEq(a, b) {
5
- return a.uri === b.uri && a.addressType === b.addressType;
5
+ return a.uri === b.uri && a.addressType === b.addressType;
6
6
  }
7
7
  exports.isSelectorEq = isSelectorEq;
8
8
  class ConnectionsRepoLocalStorage {
9
- constructor(storageKey = "ccc-joy-id-signer") {
10
- this.storageKey = storageKey;
11
- }
12
- async readConnections() {
13
- return JSON.parse(window.localStorage.getItem(this.storageKey) ?? "[]");
14
- }
15
- async get(selector) {
16
- return (await this.readConnections()).find(([s]) => isSelectorEq(selector, s))?.[1];
17
- }
18
- async set(selector, connection) {
19
- const connections = await this.readConnections();
20
- if (connection) {
21
- const existed = connections.find(([s]) => isSelectorEq(s, selector));
22
- if (existed) {
23
- existed[1] = connection;
24
- }
25
- else {
26
- connections.push([selector, connection]);
27
- }
28
- window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
29
- }
30
- else {
31
- window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !isSelectorEq(s, selector))));
32
- }
9
+ constructor(storageKey = "ccc-joy-id-signer") {
10
+ this.storageKey = storageKey;
11
+ }
12
+ async readConnections() {
13
+ return JSON.parse(window.localStorage.getItem(this.storageKey) ?? "[]");
14
+ }
15
+ async get(selector) {
16
+ return (await this.readConnections()).find(([s]) =>
17
+ isSelectorEq(selector, s),
18
+ )?.[1];
19
+ }
20
+ async set(selector, connection) {
21
+ const connections = await this.readConnections();
22
+ if (connection) {
23
+ const existed = connections.find(([s]) => isSelectorEq(s, selector));
24
+ if (existed) {
25
+ existed[1] = connection;
26
+ } else {
27
+ connections.push([selector, connection]);
28
+ }
29
+ window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
30
+ } else {
31
+ window.localStorage.setItem(
32
+ this.storageKey,
33
+ JSON.stringify(connections.filter(([s]) => !isSelectorEq(s, selector))),
34
+ );
33
35
  }
36
+ }
34
37
  }
35
38
  exports.ConnectionsRepoLocalStorage = ConnectionsRepoLocalStorage;
@@ -1,20 +1,25 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { ConnectionsRepo } from "../connectionsStorage";
3
3
  export declare class EvmSigner extends ccc.SignerEvm {
4
- private readonly name;
5
- private readonly icon;
6
- private readonly appUri;
7
- private readonly connectionsRepo;
8
- private connection?;
9
- private assertConnection;
10
- constructor(client: ccc.Client, name: string, icon: string, appUri?: string, connectionsRepo?: ConnectionsRepo);
11
- replaceClient(client: ccc.Client): Promise<EvmSigner>;
12
- private getConfig;
13
- getEvmAccount(): Promise<string>;
14
- connect(): Promise<void>;
15
- isConnected(): Promise<boolean>;
16
- signMessage(message: string | ccc.BytesLike): Promise<ccc.Hex>;
17
- private saveConnection;
18
- private restoreConnection;
4
+ private readonly name;
5
+ private readonly icon;
6
+ private readonly appUri;
7
+ private readonly connectionsRepo;
8
+ private connection?;
9
+ private assertConnection;
10
+ constructor(
11
+ client: ccc.Client,
12
+ name: string,
13
+ icon: string,
14
+ appUri?: string,
15
+ connectionsRepo?: ConnectionsRepo,
16
+ );
17
+ private getConfig;
18
+ getEvmAccount(): Promise<string>;
19
+ connect(): Promise<void>;
20
+ isConnected(): Promise<boolean>;
21
+ signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex>;
22
+ private saveConnection;
23
+ private restoreConnection;
19
24
  }
20
- //# sourceMappingURL=index.d.ts.map
25
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,SAAU,SAAQ,GAAG,CAAC,SAAS;IAaxC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAflC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC,OAAO,CAAC,gBAAgB;gBAStB,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,SAAuB,EAC7B,eAAe,GAAE,eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAU3D,OAAO,CAAC,SAAS;IAUX,aAAa;IAIb,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAQ/B,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;YAuBtD,cAAc;YAUd,iBAAiB;CAMhC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,SAAU,SAAQ,GAAG,CAAC,SAAS;IAaxC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAflC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC,OAAO,CAAC,gBAAgB;gBAStB,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,SAAuB,EAC7B,eAAe,GAAE,eAAmD;IAKvF,OAAO,CAAC,SAAS;IAUX,aAAa;IAIb,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAQ/B,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;YAuBzD,cAAc;YAUd,iBAAiB;CAMhC"}
@@ -6,77 +6,96 @@ const common_1 = require("@joyid/common");
6
6
  const common_2 = require("../common");
7
7
  const connectionsStorage_1 = require("../connectionsStorage");
8
8
  class EvmSigner extends core_1.ccc.SignerEvm {
9
- assertConnection() {
10
- if (!this.isConnected() || !this.connection) {
11
- throw new Error("Not connected");
12
- }
13
- return this.connection;
9
+ assertConnection() {
10
+ if (!this.isConnected() || !this.connection) {
11
+ throw new Error("Not connected");
14
12
  }
15
- constructor(client, name, icon, appUri = "https://app.joy.id", connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
16
- super(client);
17
- this.name = name;
18
- this.icon = icon;
19
- this.appUri = appUri;
20
- this.connectionsRepo = connectionsRepo;
21
- }
22
- async replaceClient(client) {
23
- return new EvmSigner(client, this.name, this.icon, this.appUri, this.connectionsRepo);
24
- }
25
- getConfig() {
26
- return {
27
- redirectURL: location.href,
28
- joyidAppURL: this.appUri,
29
- requestNetwork: `ethereum`,
30
- name: this.name,
31
- logo: this.icon,
32
- };
33
- }
34
- async getEvmAccount() {
35
- return this.assertConnection().address;
36
- }
37
- async connect() {
38
- const config = await this.getConfig();
39
- const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
40
- ...config,
41
- type: common_1.DappRequestType.Auth,
42
- });
43
- this.connection = {
44
- address: res.ethAddress,
45
- publicKey: core_1.ccc.hexFrom(res.pubkey),
46
- keyType: res.keyType,
47
- };
48
- await this.saveConnection();
49
- }
50
- async isConnected() {
51
- if (this.connection) {
52
- return true;
53
- }
54
- await this.restoreConnection();
55
- return this.connection !== undefined;
56
- }
57
- async signMessage(message) {
58
- const { address } = this.assertConnection();
59
- const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
60
- const config = this.getConfig();
61
- const { signature } = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
62
- ...config,
63
- challenge,
64
- isData: typeof message !== "string",
65
- address,
66
- }, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
67
- return core_1.ccc.hexFrom(signature);
68
- }
69
- async saveConnection() {
70
- return this.connectionsRepo.set({
71
- uri: this.getConfig().joyidAppURL,
72
- addressType: "ethereum",
73
- }, this.connection);
74
- }
75
- async restoreConnection() {
76
- this.connection = await this.connectionsRepo.get({
77
- uri: this.getConfig().joyidAppURL,
78
- addressType: "ethereum",
79
- });
13
+ return this.connection;
14
+ }
15
+ constructor(
16
+ client,
17
+ name,
18
+ icon,
19
+ appUri = "https://app.joy.id",
20
+ connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage(),
21
+ ) {
22
+ super(client);
23
+ this.name = name;
24
+ this.icon = icon;
25
+ this.appUri = appUri;
26
+ this.connectionsRepo = connectionsRepo;
27
+ }
28
+ getConfig() {
29
+ return {
30
+ redirectURL: location.href,
31
+ joyidAppURL: this.appUri,
32
+ requestNetwork: `ethereum`,
33
+ name: this.name,
34
+ logo: this.icon,
35
+ };
36
+ }
37
+ async getEvmAccount() {
38
+ return this.assertConnection().address;
39
+ }
40
+ async connect() {
41
+ const config = await this.getConfig();
42
+ const res = await (0, common_2.createPopup)(
43
+ (0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
44
+ {
45
+ ...config,
46
+ type: common_1.DappRequestType.Auth,
47
+ },
48
+ );
49
+ this.connection = {
50
+ address: res.ethAddress,
51
+ publicKey: core_1.ccc.hexFrom(res.pubkey),
52
+ keyType: res.keyType,
53
+ };
54
+ await this.saveConnection();
55
+ }
56
+ async isConnected() {
57
+ if (this.connection) {
58
+ return true;
80
59
  }
60
+ await this.restoreConnection();
61
+ return this.connection !== undefined;
62
+ }
63
+ async signMessageRaw(message) {
64
+ const { address } = this.assertConnection();
65
+ const challenge =
66
+ typeof message === "string"
67
+ ? message
68
+ : core_1.ccc.hexFrom(message).slice(2);
69
+ const config = this.getConfig();
70
+ const { signature } = await (0, common_2.createPopup)(
71
+ (0, common_1.buildJoyIDURL)(
72
+ {
73
+ ...config,
74
+ challenge,
75
+ isData: typeof message !== "string",
76
+ address,
77
+ },
78
+ "popup",
79
+ "/sign-message",
80
+ ),
81
+ { ...config, type: common_1.DappRequestType.SignMessage },
82
+ );
83
+ return core_1.ccc.hexFrom(signature);
84
+ }
85
+ async saveConnection() {
86
+ return this.connectionsRepo.set(
87
+ {
88
+ uri: this.getConfig().joyidAppURL,
89
+ addressType: "ethereum",
90
+ },
91
+ this.connection,
92
+ );
93
+ }
94
+ async restoreConnection() {
95
+ this.connection = await this.connectionsRepo.get({
96
+ uri: this.getConfig().joyidAppURL,
97
+ addressType: "ethereum",
98
+ });
99
+ }
81
100
  }
82
101
  exports.EvmSigner = EvmSigner;
@@ -1,2 +1,2 @@
1
1
  export * as JoyId from "./barrel";
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=index.d.ts.map
@@ -1,27 +1,48 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __setModuleDefault =
26
+ (this && this.__setModuleDefault) ||
27
+ (Object.create
28
+ ? function (o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }
31
+ : function (o, v) {
32
+ o["default"] = v;
33
+ });
34
+ var __importStar =
35
+ (this && this.__importStar) ||
36
+ function (mod) {
19
37
  if (mod && mod.__esModule) return mod;
20
38
  var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
39
+ if (mod != null)
40
+ for (var k in mod)
41
+ if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
42
+ __createBinding(result, mod, k);
22
43
  __setModuleDefault(result, mod);
23
44
  return result;
24
- };
45
+ };
25
46
  Object.defineProperty(exports, "__esModule", { value: true });
26
47
  exports.JoyId = void 0;
27
48
  exports.JoyId = __importStar(require("./barrel"));
@@ -1,3 +1,7 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- export declare function getJoyIdSigners(client: ccc.Client, name: string, icon: string): ccc.SignerInfo[];
3
- //# sourceMappingURL=index.d.ts.map
2
+ export declare function getJoyIdSigners(
3
+ client: ccc.Client,
4
+ name: string,
5
+ icon: string,
6
+ ): ccc.SignerInfo[];
7
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signerFactory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAKpC,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,GAAG,CAAC,UAAU,EAAE,CA4BlB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signerFactory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAMpC,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,GAAG,CAAC,UAAU,EAAE,CAoClB"}