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

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 (51) hide show
  1. package/dist/advancedBarrel.d.ts +1 -0
  2. package/dist/advancedBarrel.d.ts.map +1 -1
  3. package/dist/advancedBarrel.js +1 -0
  4. package/dist/barrel.d.ts +1 -0
  5. package/dist/barrel.d.ts.map +1 -1
  6. package/dist/barrel.js +1 -0
  7. package/dist/btc/index.d.ts +5 -2
  8. package/dist/btc/index.d.ts.map +1 -1
  9. package/dist/btc/index.js +27 -16
  10. package/dist/ckb/index.d.ts +5 -3
  11. package/dist/ckb/index.d.ts.map +1 -1
  12. package/dist/ckb/index.js +28 -28
  13. package/dist/common/index.d.ts +24 -0
  14. package/dist/common/index.d.ts.map +1 -0
  15. package/dist/common/index.js +50 -0
  16. package/dist/evm/index.d.ts +20 -0
  17. package/dist/evm/index.d.ts.map +1 -0
  18. package/dist/evm/index.js +78 -0
  19. package/dist/signerFactory/index.d.ts +1 -1
  20. package/dist/signerFactory/index.d.ts.map +1 -1
  21. package/dist/signerFactory/index.js +11 -5
  22. package/dist.commonjs/advancedBarrel.d.ts +1 -0
  23. package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
  24. package/dist.commonjs/advancedBarrel.js +1 -0
  25. package/dist.commonjs/barrel.d.ts +1 -0
  26. package/dist.commonjs/barrel.d.ts.map +1 -1
  27. package/dist.commonjs/barrel.js +1 -0
  28. package/dist.commonjs/btc/index.d.ts +5 -2
  29. package/dist.commonjs/btc/index.d.ts.map +1 -1
  30. package/dist.commonjs/btc/index.js +26 -15
  31. package/dist.commonjs/ckb/index.d.ts +5 -3
  32. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  33. package/dist.commonjs/ckb/index.js +27 -27
  34. package/dist.commonjs/common/index.d.ts +24 -0
  35. package/dist.commonjs/common/index.d.ts.map +1 -0
  36. package/dist.commonjs/common/index.js +54 -0
  37. package/dist.commonjs/evm/index.d.ts +20 -0
  38. package/dist.commonjs/evm/index.d.ts.map +1 -0
  39. package/dist.commonjs/evm/index.js +82 -0
  40. package/dist.commonjs/signerFactory/index.d.ts +1 -1
  41. package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
  42. package/dist.commonjs/signerFactory/index.js +11 -5
  43. package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +1 -1
  44. package/package.json +3 -3
  45. package/src/advancedBarrel.ts +1 -0
  46. package/src/barrel.ts +1 -0
  47. package/src/btc/index.ts +44 -18
  48. package/src/ckb/index.ts +45 -42
  49. package/src/common/index.ts +100 -0
  50. package/src/evm/index.ts +118 -0
  51. package/src/signerFactory/index.ts +15 -5
@@ -1,2 +1,3 @@
1
+ export * from "./common";
1
2
  export * from "./connectionsStorage";
2
3
  //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC"}
@@ -1 +1,2 @@
1
+ export * from "./common";
1
2
  export * from "./connectionsStorage";
package/dist/barrel.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./btc";
2
2
  export * from "./ckb";
3
+ export * from "./evm";
3
4
  export * from "./signerFactory";
4
5
  //# sourceMappingURL=barrel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,iBAAiB,CAAC"}
package/dist/barrel.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./btc";
2
2
  export * from "./ckb";
3
+ export * from "./evm";
3
4
  export * from "./signerFactory";
@@ -1,13 +1,16 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { ConnectionsRepo } from "../connectionsStorage";
3
3
  export declare class BitcoinSigner extends ccc.SignerBtc {
4
+ private readonly name;
5
+ private readonly icon;
4
6
  private readonly addressType;
5
- private readonly uri;
7
+ private readonly appUri;
6
8
  private readonly connectionsRepo;
7
9
  private connection?;
8
10
  private assertConnection;
9
- constructor(client: ccc.Client, addressType?: "auto" | "p2wpkh" | "p2tr", uri?: string, connectionsRepo?: ConnectionsRepo);
11
+ constructor(client: ccc.Client, name: string, icon: string, addressType?: "auto" | "p2wpkh" | "p2tr", appUri?: string, connectionsRepo?: ConnectionsRepo);
10
12
  replaceClient(client: ccc.Client): Promise<BitcoinSigner>;
13
+ private getConfig;
11
14
  getBtcAccount(): Promise<string>;
12
15
  getBtcPublicKey(): Promise<ccc.Hex>;
13
16
  connect(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;IAa5C,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAdlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC,OAAO,CAAC,gBAAgB;gBAStB,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,WAAW,GAA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,MAAM,CAAC;IAKhC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAKnC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAY/B,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAsBpE"}
package/dist/btc/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import { authWithPopup, signMessageWithPopup } from "@joyid/common";
2
+ import { DappRequestType, buildJoyIDURL } from "@joyid/common";
3
+ import { createPopup } from "../common";
3
4
  import { ConnectionsRepoLocalStorage, } from "../connectionsStorage";
4
5
  export class BitcoinSigner extends ccc.SignerBtc {
5
6
  assertConnection() {
@@ -8,14 +9,25 @@ export class BitcoinSigner extends ccc.SignerBtc {
8
9
  }
9
10
  return this.connection;
10
11
  }
11
- constructor(client, addressType = "auto", uri = "https://app.joy.id", connectionsRepo = new ConnectionsRepoLocalStorage()) {
12
+ constructor(client, name, icon, addressType = "auto", appUri = "https://app.joy.id", connectionsRepo = new ConnectionsRepoLocalStorage()) {
12
13
  super(client);
14
+ this.name = name;
15
+ this.icon = icon;
13
16
  this.addressType = addressType;
14
- this.uri = uri;
17
+ this.appUri = appUri;
15
18
  this.connectionsRepo = connectionsRepo;
16
19
  }
17
20
  async replaceClient(client) {
18
- return new BitcoinSigner(client, this.addressType, this.uri);
21
+ return new BitcoinSigner(client, this.name, this.icon, this.addressType, this.appUri, this.connectionsRepo);
22
+ }
23
+ getConfig() {
24
+ return {
25
+ redirectURL: location.href,
26
+ joyidAppURL: this.appUri,
27
+ requestNetwork: `btc-${this.addressType}`,
28
+ name: this.name,
29
+ logo: this.icon,
30
+ };
19
31
  }
20
32
  async getBtcAccount() {
21
33
  const { address } = this.assertConnection();
@@ -26,10 +38,10 @@ export class BitcoinSigner extends ccc.SignerBtc {
26
38
  return publicKey;
27
39
  }
28
40
  async connect() {
29
- const res = await authWithPopup({
30
- joyidAppURL: this.uri,
31
- redirectURL: location.href,
32
- requestNetwork: `btc-${this.addressType}`,
41
+ const config = this.getConfig();
42
+ const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
43
+ ...config,
44
+ type: DappRequestType.Auth,
33
45
  });
34
46
  const { address, pubkey } = (() => {
35
47
  if (this.addressType === "auto") {
@@ -43,8 +55,8 @@ export class BitcoinSigner extends ccc.SignerBtc {
43
55
  keyType: res.keyType,
44
56
  };
45
57
  await Promise.all([
46
- this.connectionsRepo.set({ uri: this.uri, addressType: `btc-${res.btcAddressType}` }, this.connection),
47
- this.connectionsRepo.set({ uri: this.uri, addressType: "btc-auto" }, this.connection),
58
+ this.connectionsRepo.set({ uri: this.appUri, addressType: `btc-${res.btcAddressType}` }, this.connection),
59
+ this.connectionsRepo.set({ uri: this.appUri, addressType: "btc-auto" }, this.connection),
48
60
  ]);
49
61
  }
50
62
  async isConnected() {
@@ -52,7 +64,7 @@ export class BitcoinSigner extends ccc.SignerBtc {
52
64
  return true;
53
65
  }
54
66
  this.connection = await this.connectionsRepo.get({
55
- uri: this.uri,
67
+ uri: this.appUri,
56
68
  addressType: `btc-${this.addressType}`,
57
69
  });
58
70
  return this.connection !== undefined;
@@ -60,14 +72,13 @@ export class BitcoinSigner extends ccc.SignerBtc {
60
72
  async signMessage(message) {
61
73
  const { address } = this.assertConnection();
62
74
  const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
63
- const { signature } = await signMessageWithPopup({
64
- joyidAppURL: this.uri,
65
- requestNetwork: `btc-${this.addressType}`,
75
+ const config = this.getConfig();
76
+ const { signature } = await createPopup(buildJoyIDURL({
77
+ ...config,
66
78
  challenge,
67
79
  address,
68
80
  signMessageType: "ecdsa",
69
- redirectURL: location.href,
70
- });
81
+ }, "popup", "/sign-message"), { ...config, type: DappRequestType.SignMessage });
71
82
  return signature;
72
83
  }
73
84
  }
@@ -1,14 +1,16 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { ConnectionsRepo } from "../connectionsStorage";
3
3
  export declare class CkbSigner extends ccc.Signer {
4
- private readonly _uri?;
4
+ private readonly name;
5
+ private readonly icon;
6
+ private readonly _appUri?;
5
7
  private readonly _aggregatorUri?;
6
8
  private readonly connectionsRepo;
7
9
  private connection?;
8
10
  private assertConnection;
9
- constructor(client: ccc.Client, _uri?: string | undefined, _aggregatorUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
11
+ constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, _aggregatorUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
10
12
  replaceClient(client: ccc.Client): Promise<CkbSigner>;
11
- private getUri;
13
+ private getConfig;
12
14
  private getAggregatorUri;
13
15
  connect(): Promise<void>;
14
16
  disconnect(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ckb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAUpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;IAarC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAdlC,OAAO,CAAC,UAAU,CAAC,CAAa;YAElB,gBAAgB;gBAS5B,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,CAAC,oBAAQ,EACb,cAAc,CAAC,oBAAQ,EACvB,eAAe,GAAE,eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;YAI7C,MAAM;YAUN,gBAAgB;IAUxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAexB,UAAU,IAAI,OAAO,CAAC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AAC,IAAI,CAAC;IAgBxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAQ/B,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IAOrC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAIxC,kBAAkB,CACtB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;YAgBb,2BAA2B;IAuCnC,mBAAmB,CACvB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;YAyBb,cAAc;YAUd,iBAAiB;CAMhC"}
package/dist/ckb/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { Aggregator } from "@joyid/ckb";
3
- import { DappRequestType, authWithPopup, buildJoyIDURL, createBlockDialog, openPopup, runPopup, } from "@joyid/common";
3
+ import { DappRequestType, buildJoyIDURL } from "@joyid/common";
4
+ import { createPopup } from "../common";
4
5
  import { ConnectionsRepoLocalStorage, } from "../connectionsStorage";
5
6
  export class CkbSigner extends ccc.Signer {
6
7
  async assertConnection() {
@@ -9,22 +10,27 @@ export class CkbSigner extends ccc.Signer {
9
10
  }
10
11
  return this.connection;
11
12
  }
12
- constructor(client, _uri, _aggregatorUri, connectionsRepo = new ConnectionsRepoLocalStorage()) {
13
+ constructor(client, name, icon, _appUri, _aggregatorUri, connectionsRepo = new ConnectionsRepoLocalStorage()) {
13
14
  super(client);
14
- this._uri = _uri;
15
+ this.name = name;
16
+ this.icon = icon;
17
+ this._appUri = _appUri;
15
18
  this._aggregatorUri = _aggregatorUri;
16
19
  this.connectionsRepo = connectionsRepo;
17
20
  }
18
21
  async replaceClient(client) {
19
- return new CkbSigner(client, this._uri);
22
+ return new CkbSigner(client, this.name, this.icon, this._appUri, this._aggregatorUri, this.connectionsRepo);
20
23
  }
21
- async getUri() {
22
- if (this._uri) {
23
- return this._uri;
24
- }
25
- return (await this.client.getAddressPrefix()) === "ckb"
26
- ? "https://app.joy.id"
27
- : "https://testnet.joyid.dev";
24
+ async getConfig() {
25
+ return {
26
+ redirectURL: location.href,
27
+ joyidAppURL: this._appUri ??
28
+ ((await this.client.getAddressPrefix()) === "ckb"
29
+ ? "https://app.joy.id"
30
+ : "https://testnet.joyid.dev"),
31
+ name: this.name,
32
+ logo: this.icon,
33
+ };
28
34
  }
29
35
  async getAggregatorUri() {
30
36
  if (this._aggregatorUri) {
@@ -35,10 +41,10 @@ export class CkbSigner extends ccc.Signer {
35
41
  : "https://cota.nervina.dev/aggregator";
36
42
  }
37
43
  async connect() {
38
- const uri = await this.getUri();
39
- const res = await authWithPopup({
40
- joyidAppURL: uri,
41
- redirectURL: location.href,
44
+ const config = await this.getConfig();
45
+ const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
46
+ ...config,
47
+ type: DappRequestType.Auth,
42
48
  });
43
49
  this.connection = {
44
50
  address: res.address,
@@ -107,35 +113,29 @@ export class CkbSigner extends ccc.Signer {
107
113
  tx.cellDeps.unshift(...cotaDeps);
108
114
  }
109
115
  async signOnlyTransaction(txLike) {
110
- const popup = openPopup("");
111
- if (!popup) {
112
- return createBlockDialog(async () => this.signOnlyTransaction(txLike));
113
- }
114
116
  const tx = ccc.Transaction.from(txLike);
115
117
  const { script } = await this.getAddressObj();
116
- popup.location.href = buildJoyIDURL({
117
- joyidAppURL: await this.getUri(),
118
+ const config = await this.getConfig();
119
+ const res = await createPopup(buildJoyIDURL({
120
+ ...config,
118
121
  tx: JSON.parse(tx.stringify()),
119
122
  signerAddress: (await this.assertConnection()).address,
120
- redirectURL: location.href,
121
123
  witnessIndex: await tx.findInputIndexByLock(script, this.client),
122
- }, "popup", "/sign-ckb-raw-tx");
123
- const res = await runPopup({
124
- timeoutInSeconds: 3600,
125
- popup,
124
+ }, "popup", "/sign-ckb-raw-tx"), {
125
+ ...config,
126
126
  type: DappRequestType.SignCkbRawTx,
127
127
  });
128
128
  return ccc.Transaction.from(res.tx);
129
129
  }
130
130
  async saveConnection() {
131
131
  return this.connectionsRepo.set({
132
- uri: await this.getUri(),
132
+ uri: (await this.getConfig()).joyidAppURL,
133
133
  addressType: "ckb",
134
134
  }, this.connection);
135
135
  }
136
136
  async restoreConnection() {
137
137
  this.connection = await this.connectionsRepo.get({
138
- uri: await this.getUri(),
138
+ uri: (await this.getConfig()).joyidAppURL,
139
139
  addressType: "ckb",
140
140
  });
141
141
  }
@@ -0,0 +1,24 @@
1
+ import { AuthResponseData, DappRequestType, EvmWeb2LoginResponse, PopupConfigOptions, SignCkbTxResponseData, SignCotaNFTResponseData, SignEvmTxResponseData, SignMessageResponseData, SignNostrEventData } from "@joyid/common";
2
+ 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;
20
+ }
21
+ export declare function createPopup<T extends DappRequestType>(url: string, config: PopupConfigOptions<T> & {
22
+ joyidAppURL: string;
23
+ }): Promise<PopupReturnType[T]>;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EAEpB,kBAAkB,EAGlB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAInB,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,eAAe;IAC9B,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACzC,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACvD,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IACjD,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IAClD,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE;QAC/B,KAAK,EAAE,MAAM,EAAE,CAAC;KACjB,CAAC;IACF,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,qBAAqB,CAAC;IACnD,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACvD,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,qBAAqB,CAAC;IACtD,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACrD,CAAC,eAAe,CAAC,mBAAmB,CAAC,EAAE,GAAG,CAAC;IAC3C,CAAC,eAAe,CAAC,mBAAmB,CAAC,EAAE,GAAG,CAAC;IAC3C,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC;IACnC,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,GAAG,CAAC;IACtC,CAAC,eAAe,CAAC,kBAAkB,CAAC,EAAE,GAAG,CAAC;IAC1C,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACtD;AAED,wBAAsB,WAAW,CAAC,CAAC,SAAS,eAAe,EACzD,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GACtD,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CA0D7B"}
@@ -0,0 +1,50 @@
1
+ import { DappRequestType, PopupCancelledError, PopupNotSupportedError, PopupTimeoutError, createBlockDialog, isStandaloneBrowser, openPopup, } from "@joyid/common";
2
+ export async function createPopup(url, config) {
3
+ if (config.popup == null) {
4
+ config.popup = openPopup("");
5
+ if (config.popup == null) {
6
+ return createBlockDialog(async () => createPopup(url, config));
7
+ }
8
+ }
9
+ config.popup.location.href = url;
10
+ return new Promise((resolve, reject) => {
11
+ if (isStandaloneBrowser()) {
12
+ reject(new PopupNotSupportedError(config.popup));
13
+ }
14
+ let popupEventListener;
15
+ let timeoutId;
16
+ // Check each second if the popup is closed triggering a PopupCancelledError
17
+ const popupTimer = setInterval(() => {
18
+ if (config.popup?.closed) {
19
+ clearInterval(popupTimer);
20
+ clearTimeout(timeoutId);
21
+ window.removeEventListener("message", popupEventListener, false);
22
+ reject(new PopupCancelledError(config.popup));
23
+ }
24
+ }, 1000);
25
+ timeoutId = setTimeout(() => {
26
+ clearInterval(popupTimer);
27
+ reject(new PopupTimeoutError(config.popup));
28
+ window.removeEventListener("message", popupEventListener, false);
29
+ }, (config.timeoutInSeconds ?? 3000) * 1000);
30
+ popupEventListener = (e) => {
31
+ const { joyidAppURL } = config;
32
+ const appURL = new URL(joyidAppURL);
33
+ if (e.origin !== appURL.origin) {
34
+ return;
35
+ }
36
+ if (!e.data || e.data?.type !== config.type) {
37
+ return;
38
+ }
39
+ clearTimeout(timeoutId);
40
+ clearInterval(popupTimer);
41
+ window.removeEventListener("message", popupEventListener, false);
42
+ config.popup.close();
43
+ if (e.data.error) {
44
+ reject(new Error(e.data.error));
45
+ }
46
+ resolve(e.data.data);
47
+ };
48
+ window.addEventListener("message", popupEventListener);
49
+ });
50
+ }
@@ -0,0 +1,20 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { ConnectionsRepo } from "../connectionsStorage";
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;
19
+ }
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,78 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { DappRequestType, buildJoyIDURL } from "@joyid/common";
3
+ import { createPopup } from "../common";
4
+ import { ConnectionsRepoLocalStorage, } from "../connectionsStorage";
5
+ export class EvmSigner extends ccc.SignerEvm {
6
+ assertConnection() {
7
+ if (!this.isConnected() || !this.connection) {
8
+ throw new Error("Not connected");
9
+ }
10
+ return this.connection;
11
+ }
12
+ constructor(client, name, icon, appUri = "https://app.joy.id", connectionsRepo = new ConnectionsRepoLocalStorage()) {
13
+ super(client);
14
+ this.name = name;
15
+ this.icon = icon;
16
+ this.appUri = appUri;
17
+ this.connectionsRepo = connectionsRepo;
18
+ }
19
+ async replaceClient(client) {
20
+ return new EvmSigner(client, this.name, this.icon, this.appUri, this.connectionsRepo);
21
+ }
22
+ getConfig() {
23
+ return {
24
+ redirectURL: location.href,
25
+ joyidAppURL: this.appUri,
26
+ requestNetwork: `ethereum`,
27
+ name: this.name,
28
+ logo: this.icon,
29
+ };
30
+ }
31
+ async getEvmAccount() {
32
+ return this.assertConnection().address;
33
+ }
34
+ async connect() {
35
+ const config = await this.getConfig();
36
+ const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
37
+ ...config,
38
+ type: DappRequestType.Auth,
39
+ });
40
+ this.connection = {
41
+ address: res.ethAddress,
42
+ publicKey: ccc.hexFrom(res.pubkey),
43
+ keyType: res.keyType,
44
+ };
45
+ await this.saveConnection();
46
+ }
47
+ async isConnected() {
48
+ if (this.connection) {
49
+ return true;
50
+ }
51
+ await this.restoreConnection();
52
+ return this.connection !== undefined;
53
+ }
54
+ async signMessage(message) {
55
+ const { address } = this.assertConnection();
56
+ const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
57
+ const config = this.getConfig();
58
+ const { signature } = await createPopup(buildJoyIDURL({
59
+ ...config,
60
+ challenge,
61
+ isData: typeof message !== "string",
62
+ address,
63
+ }, "popup", "/sign-message"), { ...config, type: DappRequestType.SignMessage });
64
+ return ccc.hexFrom(signature);
65
+ }
66
+ async saveConnection() {
67
+ return this.connectionsRepo.set({
68
+ uri: this.getConfig().joyidAppURL,
69
+ addressType: "ethereum",
70
+ }, this.connection);
71
+ }
72
+ async restoreConnection() {
73
+ this.connection = await this.connectionsRepo.get({
74
+ uri: this.getConfig().joyidAppURL,
75
+ addressType: "ethereum",
76
+ });
77
+ }
78
+ }
@@ -1,3 +1,3 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- export declare function getJoyIdSigners(client: ccc.Client): ccc.SignerInfo[];
2
+ export declare function getJoyIdSigners(client: ccc.Client, name: string, icon: string): ccc.SignerInfo[];
3
3
  //# 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;AAIpC,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,UAAU,EAAE,CAuBpE"}
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,27 +1,33 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { BitcoinSigner } from "../btc";
3
3
  import { CkbSigner } from "../ckb";
4
- export function getJoyIdSigners(client) {
4
+ import { EvmSigner } from "../evm";
5
+ export function getJoyIdSigners(client, name, icon) {
5
6
  return [
6
7
  {
7
8
  type: ccc.SignerType.CKB,
8
9
  name: "CKB",
9
- signer: new CkbSigner(client),
10
+ signer: new CkbSigner(client, name, icon),
10
11
  },
11
12
  {
12
13
  type: ccc.SignerType.BTC,
13
14
  name: "BTC",
14
- signer: new BitcoinSigner(client),
15
+ signer: new BitcoinSigner(client, name, icon),
16
+ },
17
+ {
18
+ type: ccc.SignerType.EVM,
19
+ name: "EVM",
20
+ signer: new EvmSigner(client, name, icon),
15
21
  },
16
22
  {
17
23
  type: ccc.SignerType.BTC,
18
24
  name: "BTC (P2WPKH)",
19
- signer: new BitcoinSigner(client, "p2wpkh"),
25
+ signer: new BitcoinSigner(client, name, icon, "p2wpkh"),
20
26
  },
21
27
  {
22
28
  type: ccc.SignerType.BTC,
23
29
  name: "BTC (P2TR)",
24
- signer: new BitcoinSigner(client, "p2tr"),
30
+ signer: new BitcoinSigner(client, name, icon, "p2tr"),
25
31
  },
26
32
  ];
27
33
  }
@@ -1,2 +1,3 @@
1
+ export * from "./common";
1
2
  export * from "./connectionsStorage";
2
3
  //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC"}
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./common"), exports);
17
18
  __exportStar(require("./connectionsStorage"), exports);
@@ -1,4 +1,5 @@
1
1
  export * from "./btc";
2
2
  export * from "./ckb";
3
+ export * from "./evm";
3
4
  export * from "./signerFactory";
4
5
  //# sourceMappingURL=barrel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,iBAAiB,CAAC"}
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./btc"), exports);
18
18
  __exportStar(require("./ckb"), exports);
19
+ __exportStar(require("./evm"), exports);
19
20
  __exportStar(require("./signerFactory"), exports);
@@ -1,13 +1,16 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { ConnectionsRepo } from "../connectionsStorage";
3
3
  export declare class BitcoinSigner extends ccc.SignerBtc {
4
+ private readonly name;
5
+ private readonly icon;
4
6
  private readonly addressType;
5
- private readonly uri;
7
+ private readonly appUri;
6
8
  private readonly connectionsRepo;
7
9
  private connection?;
8
10
  private assertConnection;
9
- constructor(client: ccc.Client, addressType?: "auto" | "p2wpkh" | "p2tr", uri?: string, connectionsRepo?: ConnectionsRepo);
11
+ constructor(client: ccc.Client, name: string, icon: string, addressType?: "auto" | "p2wpkh" | "p2tr", appUri?: string, connectionsRepo?: ConnectionsRepo);
10
12
  replaceClient(client: ccc.Client): Promise<BitcoinSigner>;
13
+ private getConfig;
11
14
  getBtcAccount(): Promise<string>;
12
15
  getBtcPublicKey(): Promise<ccc.Hex>;
13
16
  connect(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;IAa5C,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAdlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC,OAAO,CAAC,gBAAgB;gBAStB,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,WAAW,GAAE,MAAM,GAAG,QAAQ,GAAG,MAAe,EAChD,GAAG,SAAuB,EAC1B,eAAe,GAAE,eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAIzD,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKhC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAKnC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAY/B,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAgBpE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;IAa5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,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