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

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 +6 -3
  8. package/dist/btc/index.d.ts.map +1 -1
  9. package/dist/btc/index.js +28 -17
  10. package/dist/ckb/index.d.ts +9 -3
  11. package/dist/ckb/index.d.ts.map +1 -1
  12. package/dist/ckb/index.js +58 -30
  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 +10 -10
  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 +6 -3
  29. package/dist.commonjs/btc/index.d.ts.map +1 -1
  30. package/dist.commonjs/btc/index.js +27 -16
  31. package/dist.commonjs/ckb/index.d.ts +9 -3
  32. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  33. package/dist.commonjs/ckb/index.js +57 -29
  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 +10 -10
  43. package/package.json +3 -3
  44. package/src/advancedBarrel.ts +1 -0
  45. package/src/barrel.ts +1 -0
  46. package/src/btc/index.ts +45 -19
  47. package/src/ckb/index.ts +89 -44
  48. package/src/common/index.ts +100 -0
  49. package/src/evm/index.ts +118 -0
  50. package/src/signerFactory/index.ts +14 -9
  51. package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
@@ -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,17 +1,20 @@
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>;
14
17
  isConnected(): Promise<boolean>;
15
- signMessage(message: string | ccc.BytesLike): Promise<string>;
18
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
16
19
  }
17
20
  //# sourceMappingURL=index.d.ts.map
@@ -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,C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eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAW/D,OAAO,CAAC,SAAS;IAUX,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,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAsBvE"}
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,22 +64,21 @@ 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;
59
71
  }
60
- async signMessage(message) {
72
+ async signMessageRaw(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,24 +1,30 @@
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;
9
+ get type(): ccc.SignerType;
10
+ get signType(): ccc.SignerSignType;
7
11
  private connection?;
8
12
  private assertConnection;
9
- constructor(client: ccc.Client, _uri?: string | undefined, _aggregatorUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
13
+ constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, _aggregatorUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
10
14
  replaceClient(client: ccc.Client): Promise<CkbSigner>;
11
- private getUri;
15
+ private getConfig;
12
16
  private getAggregatorUri;
13
17
  connect(): Promise<void>;
14
18
  disconnect(): Promise<void>;
15
19
  isConnected(): Promise<boolean>;
16
20
  getInternalAddress(): Promise<string>;
21
+ getIdentity(): Promise<string>;
17
22
  getAddressObj(): Promise<ccc.Address>;
18
23
  getAddressObjs(): Promise<ccc.Address[]>;
19
24
  prepareTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
20
25
  private prepareTransactionForSubKey;
21
26
  signOnlyTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
27
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
22
28
  private saveConnection;
23
29
  private restoreConnection;
24
30
  }
@@ -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,CA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OAAO,CAAC,MAAM,CAAC;YA2BxD,cAAc;YAUd,iBAAiB;CAMhC"}
package/dist/ckb/index.js CHANGED
@@ -1,44 +1,55 @@
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 {
7
+ get type() {
8
+ return ccc.SignerType.CKB;
9
+ }
10
+ get signType() {
11
+ return ccc.SignerSignType.JoyId;
12
+ }
6
13
  async assertConnection() {
7
14
  if (!(await this.isConnected()) || !this.connection) {
8
15
  throw new Error("Not connected");
9
16
  }
10
17
  return this.connection;
11
18
  }
12
- constructor(client, _uri, _aggregatorUri, connectionsRepo = new ConnectionsRepoLocalStorage()) {
19
+ constructor(client, name, icon, _appUri, _aggregatorUri, connectionsRepo = new ConnectionsRepoLocalStorage()) {
13
20
  super(client);
14
- this._uri = _uri;
21
+ this.name = name;
22
+ this.icon = icon;
23
+ this._appUri = _appUri;
15
24
  this._aggregatorUri = _aggregatorUri;
16
25
  this.connectionsRepo = connectionsRepo;
17
26
  }
18
27
  async replaceClient(client) {
19
- return new CkbSigner(client, this._uri);
28
+ return new CkbSigner(client, this.name, this.icon, this._appUri, this._aggregatorUri, this.connectionsRepo);
20
29
  }
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";
30
+ getConfig() {
31
+ return {
32
+ redirectURL: location.href,
33
+ joyidAppURL: this._appUri ?? this.client.addressPrefix === "ckb"
34
+ ? "https://app.joy.id"
35
+ : "https://testnet.joyid.dev",
36
+ name: this.name,
37
+ logo: this.icon,
38
+ };
28
39
  }
29
- async getAggregatorUri() {
40
+ getAggregatorUri() {
30
41
  if (this._aggregatorUri) {
31
42
  return this._aggregatorUri;
32
43
  }
33
- return (await this.client.getAddressPrefix()) === "ckb"
44
+ return this.client.addressPrefix === "ckb"
34
45
  ? "https://cota.nervina.dev/mainnet-aggregator"
35
46
  : "https://cota.nervina.dev/aggregator";
36
47
  }
37
48
  async connect() {
38
- const uri = await this.getUri();
39
- const res = await authWithPopup({
40
- joyidAppURL: uri,
41
- redirectURL: location.href,
49
+ const config = this.getConfig();
50
+ const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
51
+ ...config,
52
+ type: DappRequestType.Auth,
42
53
  });
43
54
  this.connection = {
44
55
  address: res.address,
@@ -61,6 +72,13 @@ export class CkbSigner extends ccc.Signer {
61
72
  async getInternalAddress() {
62
73
  return (await this.assertConnection()).address;
63
74
  }
75
+ async getIdentity() {
76
+ const connection = await this.assertConnection();
77
+ return JSON.stringify({
78
+ keyType: connection.keyType,
79
+ publicKey: connection.publicKey.slice(2),
80
+ });
81
+ }
64
82
  async getAddressObj() {
65
83
  return await ccc.Address.fromString(await this.getInternalAddress(), this.client);
66
84
  }
@@ -107,35 +125,45 @@ export class CkbSigner extends ccc.Signer {
107
125
  tx.cellDeps.unshift(...cotaDeps);
108
126
  }
109
127
  async signOnlyTransaction(txLike) {
110
- const popup = openPopup("");
111
- if (!popup) {
112
- return createBlockDialog(async () => this.signOnlyTransaction(txLike));
113
- }
114
128
  const tx = ccc.Transaction.from(txLike);
115
129
  const { script } = await this.getAddressObj();
116
- popup.location.href = buildJoyIDURL({
117
- joyidAppURL: await this.getUri(),
130
+ const config = this.getConfig();
131
+ const res = await createPopup(buildJoyIDURL({
132
+ ...config,
118
133
  tx: JSON.parse(tx.stringify()),
119
134
  signerAddress: (await this.assertConnection()).address,
120
- redirectURL: location.href,
121
135
  witnessIndex: await tx.findInputIndexByLock(script, this.client),
122
- }, "popup", "/sign-ckb-raw-tx");
123
- const res = await runPopup({
124
- timeoutInSeconds: 3600,
125
- popup,
136
+ }, "popup", "/sign-ckb-raw-tx"), {
137
+ ...config,
126
138
  type: DappRequestType.SignCkbRawTx,
127
139
  });
128
140
  return ccc.Transaction.from(res.tx);
129
141
  }
142
+ async signMessageRaw(message) {
143
+ const { address } = await this.assertConnection();
144
+ const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
145
+ const config = this.getConfig();
146
+ const res = await createPopup(buildJoyIDURL({
147
+ ...config,
148
+ challenge,
149
+ isData: typeof message !== "string",
150
+ address,
151
+ }, "popup", "/sign-message"), { ...config, type: DappRequestType.SignMessage });
152
+ return JSON.stringify({
153
+ signature: res.signature,
154
+ alg: res.alg,
155
+ message: res.message,
156
+ });
157
+ }
130
158
  async saveConnection() {
131
159
  return this.connectionsRepo.set({
132
- uri: await this.getUri(),
160
+ uri: this.getConfig().joyidAppURL,
133
161
  addressType: "ckb",
134
162
  }, this.connection);
135
163
  }
136
164
  async restoreConnection() {
137
165
  this.connection = await this.connectionsRepo.get({
138
- uri: await this.getUri(),
166
+ uri: this.getConfig().joyidAppURL,
139
167
  addressType: "ckb",
140
168
  });
141
169
  }
@@ -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
+ signMessageRaw(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,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;YAuBzD,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 signMessageRaw(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,CAuBlB"}
@@ -1,27 +1,27 @@
1
- import { ccc } from "@ckb-ccc/core";
2
1
  import { BitcoinSigner } from "../btc";
3
2
  import { CkbSigner } from "../ckb";
4
- export function getJoyIdSigners(client) {
3
+ import { EvmSigner } from "../evm";
4
+ export function getJoyIdSigners(client, name, icon) {
5
5
  return [
6
6
  {
7
- type: ccc.SignerType.CKB,
8
7
  name: "CKB",
9
- signer: new CkbSigner(client),
8
+ signer: new CkbSigner(client, name, icon),
10
9
  },
11
10
  {
12
- type: ccc.SignerType.BTC,
13
11
  name: "BTC",
14
- signer: new BitcoinSigner(client),
12
+ signer: new BitcoinSigner(client, name, icon),
13
+ },
14
+ {
15
+ name: "EVM",
16
+ signer: new EvmSigner(client, name, icon),
15
17
  },
16
18
  {
17
- type: ccc.SignerType.BTC,
18
19
  name: "BTC (P2WPKH)",
19
- signer: new BitcoinSigner(client, "p2wpkh"),
20
+ signer: new BitcoinSigner(client, name, icon, "p2wpkh"),
20
21
  },
21
22
  {
22
- type: ccc.SignerType.BTC,
23
23
  name: "BTC (P2TR)",
24
- signer: new BitcoinSigner(client, "p2tr"),
24
+ signer: new BitcoinSigner(client, name, icon, "p2tr"),
25
25
  },
26
26
  ];
27
27
  }
@@ -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,17 +1,20 @@
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>;
14
17
  isConnected(): Promise<boolean>;
15
- signMessage(message: string | ccc.BytesLike): Promise<string>;
18
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
16
19
  }
17
20
  //# sourceMappingURL=index.d.ts.map