@ckb-ccc/joy-id 0.0.5-alpha.0 → 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 (57) 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 -4
  8. package/dist/btc/index.d.ts.map +1 -1
  9. package/dist/btc/index.js +26 -18
  10. package/dist/ckb/index.d.ts +9 -4
  11. package/dist/ckb/index.d.ts.map +1 -1
  12. package/dist/ckb/index.js +59 -33
  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 +19 -0
  17. package/dist/evm/index.d.ts.map +1 -0
  18. package/dist/evm/index.js +75 -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 +17 -9
  22. package/dist.commonjs/advanced.d.ts +1 -1
  23. package/dist.commonjs/advanced.js +40 -19
  24. package/dist.commonjs/advancedBarrel.d.ts +2 -1
  25. package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
  26. package/dist.commonjs/advancedBarrel.js +31 -14
  27. package/dist.commonjs/barrel.d.ts +2 -1
  28. package/dist.commonjs/barrel.d.ts.map +1 -1
  29. package/dist.commonjs/barrel.js +31 -14
  30. package/dist.commonjs/btc/index.d.ts +22 -13
  31. package/dist.commonjs/btc/index.d.ts.map +1 -1
  32. package/dist.commonjs/btc/index.js +100 -66
  33. package/dist.commonjs/ckb/index.d.ts +33 -21
  34. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  35. package/dist.commonjs/ckb/index.js +205 -136
  36. package/dist.commonjs/common/index.d.ts +37 -0
  37. package/dist.commonjs/common/index.d.ts.map +1 -0
  38. package/dist.commonjs/common/index.js +59 -0
  39. package/dist.commonjs/connectionsStorage/index.d.ts +23 -14
  40. package/dist.commonjs/connectionsStorage/index.js +28 -25
  41. package/dist.commonjs/evm/index.d.ts +25 -0
  42. package/dist.commonjs/evm/index.d.ts.map +1 -0
  43. package/dist.commonjs/evm/index.js +101 -0
  44. package/dist.commonjs/index.d.ts +1 -1
  45. package/dist.commonjs/index.js +40 -19
  46. package/dist.commonjs/signerFactory/index.d.ts +6 -2
  47. package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
  48. package/dist.commonjs/signerFactory/index.js +41 -22
  49. package/package.json +3 -3
  50. package/src/advancedBarrel.ts +1 -0
  51. package/src/barrel.ts +1 -0
  52. package/src/btc/index.ts +35 -20
  53. package/src/ckb/index.ts +84 -48
  54. package/src/common/index.ts +100 -0
  55. package/src/evm/index.ts +108 -0
  56. package/src/signerFactory/index.ts +28 -9
  57. 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,19 @@
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);
10
- replaceClient(client: ccc.Client): Promise<BitcoinSigner>;
11
+ constructor(client: ccc.Client, name: string, icon: string, addressType?: "auto" | "p2wpkh" | "p2tr", appUri?: string, connectionsRepo?: ConnectionsRepo);
12
+ private getConfig;
11
13
  getBtcAccount(): Promise<string>;
12
14
  getBtcPublicKey(): Promise<ccc.Hex>;
13
15
  connect(): Promise<void>;
14
16
  isConnected(): Promise<boolean>;
15
- signMessage(message: string | ccc.BytesLike): Promise<string>;
17
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
16
18
  }
17
19
  //# 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,CAA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AAO,CAAC,gBAAgB;gBAStB,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,MAAM,GAAG,QAAQ,GAAG,MAAe,EAChD,MAAM,SAAuB,EAC7B,eAAe,GAAE,eAAmD;IAKvF,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,22 @@ 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
- async replaceClient(client) {
18
- return new BitcoinSigner(client, this.addressType, this.uri);
20
+ getConfig() {
21
+ return {
22
+ redirectURL: location.href,
23
+ joyidAppURL: this.appUri,
24
+ requestNetwork: `btc-${this.addressType}`,
25
+ name: this.name,
26
+ logo: this.icon,
27
+ };
19
28
  }
20
29
  async getBtcAccount() {
21
30
  const { address } = this.assertConnection();
@@ -26,10 +35,10 @@ export class BitcoinSigner extends ccc.SignerBtc {
26
35
  return publicKey;
27
36
  }
28
37
  async connect() {
29
- const res = await authWithPopup({
30
- joyidAppURL: this.uri,
31
- redirectURL: location.href,
32
- requestNetwork: `btc-${this.addressType}`,
38
+ const config = this.getConfig();
39
+ const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
40
+ ...config,
41
+ type: DappRequestType.Auth,
33
42
  });
34
43
  const { address, pubkey } = (() => {
35
44
  if (this.addressType === "auto") {
@@ -43,8 +52,8 @@ export class BitcoinSigner extends ccc.SignerBtc {
43
52
  keyType: res.keyType,
44
53
  };
45
54
  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),
55
+ this.connectionsRepo.set({ uri: this.appUri, addressType: `btc-${res.btcAddressType}` }, this.connection),
56
+ this.connectionsRepo.set({ uri: this.appUri, addressType: "btc-auto" }, this.connection),
48
57
  ]);
49
58
  }
50
59
  async isConnected() {
@@ -52,22 +61,21 @@ export class BitcoinSigner extends ccc.SignerBtc {
52
61
  return true;
53
62
  }
54
63
  this.connection = await this.connectionsRepo.get({
55
- uri: this.uri,
64
+ uri: this.appUri,
56
65
  addressType: `btc-${this.addressType}`,
57
66
  });
58
67
  return this.connection !== undefined;
59
68
  }
60
- async signMessage(message) {
69
+ async signMessageRaw(message) {
61
70
  const { address } = this.assertConnection();
62
71
  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}`,
72
+ const config = this.getConfig();
73
+ const { signature } = await createPopup(buildJoyIDURL({
74
+ ...config,
66
75
  challenge,
67
76
  address,
68
77
  signMessageType: "ecdsa",
69
- redirectURL: location.href,
70
- });
78
+ }, "popup", "/sign-message"), { ...config, type: DappRequestType.SignMessage });
71
79
  return signature;
72
80
  }
73
81
  }
@@ -1,24 +1,29 @@
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);
10
- replaceClient(client: ccc.Client): Promise<CkbSigner>;
11
- private getUri;
13
+ constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, _aggregatorUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
14
+ private getConfig;
12
15
  private getAggregatorUri;
13
16
  connect(): Promise<void>;
14
17
  disconnect(): Promise<void>;
15
18
  isConnected(): Promise<boolean>;
16
19
  getInternalAddress(): Promise<string>;
20
+ getIdentity(): Promise<string>;
17
21
  getAddressObj(): Promise<ccc.Address>;
18
22
  getAddressObjs(): Promise<ccc.Address[]>;
19
23
  prepareTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
20
24
  private prepareTransactionForSubKey;
21
25
  signOnlyTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
26
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
22
27
  private saveConnection;
23
28
  private restoreConnection;
24
29
  }
@@ -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,O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YAUd,iBAAiB;CAMhC"}
package/dist/ckb/index.js CHANGED
@@ -1,44 +1,52 @@
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
- async replaceClient(client) {
19
- return new CkbSigner(client, this._uri);
20
- }
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";
27
+ getConfig() {
28
+ return {
29
+ redirectURL: location.href,
30
+ joyidAppURL: this._appUri ?? this.client.addressPrefix === "ckb"
31
+ ? "https://app.joy.id"
32
+ : "https://testnet.joyid.dev",
33
+ name: this.name,
34
+ logo: this.icon,
35
+ };
28
36
  }
29
- async getAggregatorUri() {
37
+ getAggregatorUri() {
30
38
  if (this._aggregatorUri) {
31
39
  return this._aggregatorUri;
32
40
  }
33
- return (await this.client.getAddressPrefix()) === "ckb"
41
+ return this.client.addressPrefix === "ckb"
34
42
  ? "https://cota.nervina.dev/mainnet-aggregator"
35
43
  : "https://cota.nervina.dev/aggregator";
36
44
  }
37
45
  async connect() {
38
- const uri = await this.getUri();
39
- const res = await authWithPopup({
40
- joyidAppURL: uri,
41
- redirectURL: location.href,
46
+ const config = this.getConfig();
47
+ const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
48
+ ...config,
49
+ type: DappRequestType.Auth,
42
50
  });
43
51
  this.connection = {
44
52
  address: res.address,
@@ -61,6 +69,13 @@ export class CkbSigner extends ccc.Signer {
61
69
  async getInternalAddress() {
62
70
  return (await this.assertConnection()).address;
63
71
  }
72
+ async getIdentity() {
73
+ const connection = await this.assertConnection();
74
+ return JSON.stringify({
75
+ keyType: connection.keyType,
76
+ publicKey: connection.publicKey.slice(2),
77
+ });
78
+ }
64
79
  async getAddressObj() {
65
80
  return await ccc.Address.fromString(await this.getInternalAddress(), this.client);
66
81
  }
@@ -76,7 +91,8 @@ export class CkbSigner extends ccc.Signer {
76
91
  const witness = tx.getWitnessArgsAt(position) ?? ccc.WitnessArgs.from({});
77
92
  witness.lock = "0x";
78
93
  await this.prepareTransactionForSubKey(tx, witness);
79
- return tx.setWitnessArgsAt(position, witness);
94
+ tx.setWitnessArgsAt(position, witness);
95
+ return tx;
80
96
  }
81
97
  async prepareTransactionForSubKey(tx, witness) {
82
98
  if (this.connection?.keyType !== "sub_key") {
@@ -107,35 +123,45 @@ export class CkbSigner extends ccc.Signer {
107
123
  tx.cellDeps.unshift(...cotaDeps);
108
124
  }
109
125
  async signOnlyTransaction(txLike) {
110
- const popup = openPopup("");
111
- if (!popup) {
112
- return createBlockDialog(async () => this.signOnlyTransaction(txLike));
113
- }
114
126
  const tx = ccc.Transaction.from(txLike);
115
127
  const { script } = await this.getAddressObj();
116
- popup.location.href = buildJoyIDURL({
117
- joyidAppURL: await this.getUri(),
128
+ const config = this.getConfig();
129
+ const res = await createPopup(buildJoyIDURL({
130
+ ...config,
118
131
  tx: JSON.parse(tx.stringify()),
119
132
  signerAddress: (await this.assertConnection()).address,
120
- redirectURL: location.href,
121
133
  witnessIndex: await tx.findInputIndexByLock(script, this.client),
122
- }, "popup", "/sign-ckb-raw-tx");
123
- const res = await runPopup({
124
- timeoutInSeconds: 3600,
125
- popup,
134
+ }, "popup", "/sign-ckb-raw-tx"), {
135
+ ...config,
126
136
  type: DappRequestType.SignCkbRawTx,
127
137
  });
128
138
  return ccc.Transaction.from(res.tx);
129
139
  }
140
+ async signMessageRaw(message) {
141
+ const { address } = await this.assertConnection();
142
+ const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
143
+ const config = this.getConfig();
144
+ const res = await createPopup(buildJoyIDURL({
145
+ ...config,
146
+ challenge,
147
+ isData: typeof message !== "string",
148
+ address,
149
+ }, "popup", "/sign-message"), { ...config, type: DappRequestType.SignMessage });
150
+ return JSON.stringify({
151
+ signature: res.signature,
152
+ alg: res.alg,
153
+ message: res.message,
154
+ });
155
+ }
130
156
  async saveConnection() {
131
157
  return this.connectionsRepo.set({
132
- uri: await this.getUri(),
158
+ uri: this.getConfig().joyidAppURL,
133
159
  addressType: "ckb",
134
160
  }, this.connection);
135
161
  }
136
162
  async restoreConnection() {
137
163
  this.connection = await this.connectionsRepo.get({
138
- uri: await this.getUri(),
164
+ uri: this.getConfig().joyidAppURL,
139
165
  addressType: "ckb",
140
166
  });
141
167
  }
@@ -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,19 @@
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
+ private getConfig;
12
+ getEvmAccount(): Promise<string>;
13
+ connect(): Promise<void>;
14
+ isConnected(): Promise<boolean>;
15
+ signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex>;
16
+ private saveConnection;
17
+ private restoreConnection;
18
+ }
19
+ //# 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;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"}
@@ -0,0 +1,75 @@
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
+ getConfig() {
20
+ return {
21
+ redirectURL: location.href,
22
+ joyidAppURL: this.appUri,
23
+ requestNetwork: `ethereum`,
24
+ name: this.name,
25
+ logo: this.icon,
26
+ };
27
+ }
28
+ async getEvmAccount() {
29
+ return this.assertConnection().address;
30
+ }
31
+ async connect() {
32
+ const config = await this.getConfig();
33
+ const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
34
+ ...config,
35
+ type: DappRequestType.Auth,
36
+ });
37
+ this.connection = {
38
+ address: res.ethAddress,
39
+ publicKey: ccc.hexFrom(res.pubkey),
40
+ keyType: res.keyType,
41
+ };
42
+ await this.saveConnection();
43
+ }
44
+ async isConnected() {
45
+ if (this.connection) {
46
+ return true;
47
+ }
48
+ await this.restoreConnection();
49
+ return this.connection !== undefined;
50
+ }
51
+ async signMessageRaw(message) {
52
+ const { address } = this.assertConnection();
53
+ const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
54
+ const config = this.getConfig();
55
+ const { signature } = await createPopup(buildJoyIDURL({
56
+ ...config,
57
+ challenge,
58
+ isData: typeof message !== "string",
59
+ address,
60
+ }, "popup", "/sign-message"), { ...config, type: DappRequestType.SignMessage });
61
+ return ccc.hexFrom(signature);
62
+ }
63
+ async saveConnection() {
64
+ return this.connectionsRepo.set({
65
+ uri: this.getConfig().joyidAppURL,
66
+ addressType: "ethereum",
67
+ }, this.connection);
68
+ }
69
+ async restoreConnection() {
70
+ this.connection = await this.connectionsRepo.get({
71
+ uri: this.getConfig().joyidAppURL,
72
+ addressType: "ethereum",
73
+ });
74
+ }
75
+ }
@@ -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;AAMpC,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,GAAG,CAAC,UAAU,EAAE,CAoClB"}
@@ -1,27 +1,35 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
+ import { isStandaloneBrowser } from "@joyid/common";
2
3
  import { BitcoinSigner } from "../btc";
3
4
  import { CkbSigner } from "../ckb";
4
- export function getJoyIdSigners(client) {
5
+ import { EvmSigner } from "../evm";
6
+ export function getJoyIdSigners(client, name, icon) {
7
+ if (isStandaloneBrowser() || ccc.isWebview(window.navigator.userAgent)) {
8
+ return [ccc.SignerType.CKB, ccc.SignerType.EVM, ccc.SignerType.BTC].map((type) => ({
9
+ name: type,
10
+ signer: new ccc.SignerAlwaysError(client, type, "JoyID can only be used with standard browsers"),
11
+ }));
12
+ }
5
13
  return [
6
14
  {
7
- type: ccc.SignerType.CKB,
8
15
  name: "CKB",
9
- signer: new CkbSigner(client),
16
+ signer: new CkbSigner(client, name, icon),
10
17
  },
11
18
  {
12
- type: ccc.SignerType.BTC,
13
19
  name: "BTC",
14
- signer: new BitcoinSigner(client),
20
+ signer: new BitcoinSigner(client, name, icon),
21
+ },
22
+ {
23
+ name: "EVM",
24
+ signer: new EvmSigner(client, name, icon),
15
25
  },
16
26
  {
17
- type: ccc.SignerType.BTC,
18
27
  name: "BTC (P2WPKH)",
19
- signer: new BitcoinSigner(client, "p2wpkh"),
28
+ signer: new BitcoinSigner(client, name, icon, "p2wpkh"),
20
29
  },
21
30
  {
22
- type: ccc.SignerType.BTC,
23
31
  name: "BTC (P2TR)",
24
- signer: new BitcoinSigner(client, "p2tr"),
32
+ signer: new BitcoinSigner(client, name, icon, "p2tr"),
25
33
  },
26
34
  ];
27
35
  }
@@ -1,2 +1,2 @@
1
1
  export * as JoyIdA from "./advancedBarrel";
2
- //# sourceMappingURL=advanced.d.ts.map
2
+ //# sourceMappingURL=advanced.d.ts.map