@ckb-ccc/eip6963 0.0.3 → 0.0.4-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/signer.d.ts CHANGED
@@ -1,13 +1,10 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { ProviderDetail as EIP6963ProviderDetail } from "./eip6963.advanced";
3
- export declare class Signer extends ccc.Signer {
3
+ export declare class Signer extends ccc.SignerEvm {
4
4
  readonly detail: EIP6963ProviderDetail;
5
5
  constructor(client: ccc.Client, detail: EIP6963ProviderDetail);
6
- getEVMAccount(): Promise<`0x${string}`>;
7
- getInternalAddress(): Promise<string>;
8
- getAddressObjs(): Promise<ccc.Address[]>;
6
+ getEvmAccount(): Promise<`0x${string}`>;
9
7
  connect(): Promise<void>;
10
8
  signMessage(message: string | ccc.BytesLike): Promise<ccc.Hex>;
11
- signOnlyTransaction(tx: ccc.Transaction): Promise<ccc.Transaction>;
12
9
  }
13
10
  //# sourceMappingURL=signer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE7E,qBAAa,MAAO,SAAQ,GAAG,CAAC,MAAM;aAGlB,MAAM,EAAE,qBAAqB;gBAD7C,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,MAAM,EAAE,qBAAqB;IAKzC,aAAa;IAIb,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAWxC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAW9D,mBAAmB,CAAC,EAAE,EAAE,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;CA8BzE"}
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE7E,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAGrB,MAAM,EAAE,qBAAqB;gBAD7C,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,MAAM,EAAE,qBAAqB;IAKzC,aAAa;IAIb,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;CAUrE"}
package/dist/signer.js CHANGED
@@ -1,45 +1,21 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- export class Signer extends ccc.Signer {
2
+ export class Signer extends ccc.SignerEvm {
3
3
  constructor(client, detail) {
4
4
  super(client);
5
5
  this.detail = detail;
6
6
  }
7
- async getEVMAccount() {
7
+ async getEvmAccount() {
8
8
  return (await this.detail.provider.request({ method: "eth_accounts" }))[0];
9
9
  }
10
- async getInternalAddress() {
11
- return this.getEVMAccount();
12
- }
13
- async getAddressObjs() {
14
- const account = await this.getEVMAccount();
15
- return [
16
- await ccc.Address.fromKnownScript(ccc.KnownScript.OmniLock, ccc.hexFrom([0x12, ...ccc.bytesFrom(account), 0x00]), this.client),
17
- ];
18
- }
19
10
  async connect() {
20
11
  await this.detail.provider.request({ method: "eth_requestAccounts" });
21
12
  }
22
13
  async signMessage(message) {
23
14
  const challenge = typeof message === "string" ? ccc.bytesFrom(message, "utf8") : message;
24
- const address = await this.getEVMAccount();
15
+ const address = await this.getEvmAccount();
25
16
  return this.detail.provider.request({
26
17
  method: "personal_sign",
27
18
  params: [ccc.hexFrom(challenge), address],
28
19
  });
29
20
  }
30
- async signOnlyTransaction(tx) {
31
- const { script } = await this.getRecommendedAddressObj();
32
- const info = await ccc.getSignHashInfo(tx, script);
33
- if (!info) {
34
- return tx;
35
- }
36
- const signature = ccc.bytesFrom(await this.signMessage(`CKB transaction: ${info.message}`));
37
- if (signature[signature.length - 1] >= 27) {
38
- signature[signature.length - 1] -= 27;
39
- }
40
- const witness = ccc.WitnessArgs.fromBytes(tx.witnesses[info.position]);
41
- witness.lock = ccc.hexFrom(ccc.bytesConcat(ccc.numToBytes(5 * 4 + signature.length, 4), ccc.numToBytes(4 * 4, 4), ccc.numToBytes(5 * 4 + signature.length, 4), ccc.numToBytes(5 * 4 + signature.length, 4), ccc.numToBytes(signature.length, 4), signature));
42
- tx.witnesses[info.position] = ccc.hexFrom(witness.toBytes());
43
- return tx;
44
- }
45
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/eip6963",
3
- "version": "0.0.3",
3
+ "version": "0.0.4-alpha.0",
4
4
  "description": "Common Chains Connector's support for EIP6963",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@ckb-ccc/core": "0.0.3"
38
+ "@ckb-ccc/core": "0.0.4-alpha.0"
39
39
  },
40
- "gitHead": "9df1bbe0007136568914d8a73fe39f898d636a12"
40
+ "gitHead": "e49045ed4b2778c92d6f49b79c17125245141a21"
41
41
  }
package/src/signer.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { ProviderDetail as EIP6963ProviderDetail } from "./eip6963.advanced";
3
3
 
4
- export class Signer extends ccc.Signer {
4
+ export class Signer extends ccc.SignerEvm {
5
5
  constructor(
6
6
  client: ccc.Client,
7
7
  public readonly detail: EIP6963ProviderDetail,
@@ -9,25 +9,10 @@ export class Signer extends ccc.Signer {
9
9
  super(client);
10
10
  }
11
11
 
12
- async getEVMAccount() {
12
+ async getEvmAccount() {
13
13
  return (await this.detail.provider.request({ method: "eth_accounts" }))[0];
14
14
  }
15
15
 
16
- async getInternalAddress(): Promise<string> {
17
- return this.getEVMAccount();
18
- }
19
-
20
- async getAddressObjs(): Promise<ccc.Address[]> {
21
- const account = await this.getEVMAccount();
22
- return [
23
- await ccc.Address.fromKnownScript(
24
- ccc.KnownScript.OmniLock,
25
- ccc.hexFrom([0x12, ...ccc.bytesFrom(account), 0x00]),
26
- this.client,
27
- ),
28
- ];
29
- }
30
-
31
16
  async connect(): Promise<void> {
32
17
  await this.detail.provider.request({ method: "eth_requestAccounts" });
33
18
  }
@@ -35,42 +20,11 @@ export class Signer extends ccc.Signer {
35
20
  async signMessage(message: string | ccc.BytesLike): Promise<ccc.Hex> {
36
21
  const challenge =
37
22
  typeof message === "string" ? ccc.bytesFrom(message, "utf8") : message;
38
- const address = await this.getEVMAccount();
23
+ const address = await this.getEvmAccount();
39
24
 
40
25
  return this.detail.provider.request({
41
26
  method: "personal_sign",
42
27
  params: [ccc.hexFrom(challenge), address],
43
28
  });
44
29
  }
45
-
46
- async signOnlyTransaction(tx: ccc.Transaction): Promise<ccc.Transaction> {
47
- const { script } = await this.getRecommendedAddressObj();
48
- const info = await ccc.getSignHashInfo(tx, script);
49
- if (!info) {
50
- return tx;
51
- }
52
-
53
- const signature = ccc.bytesFrom(
54
- await this.signMessage(`CKB transaction: ${info.message}`),
55
- );
56
- if (signature[signature.length - 1] >= 27) {
57
- signature[signature.length - 1] -= 27;
58
- }
59
-
60
- const witness = ccc.WitnessArgs.fromBytes(tx.witnesses[info.position]);
61
- witness.lock = ccc.hexFrom(
62
- ccc.bytesConcat(
63
- ccc.numToBytes(5 * 4 + signature.length, 4),
64
- ccc.numToBytes(4 * 4, 4),
65
- ccc.numToBytes(5 * 4 + signature.length, 4),
66
- ccc.numToBytes(5 * 4 + signature.length, 4),
67
- ccc.numToBytes(signature.length, 4),
68
- signature,
69
- ),
70
- );
71
-
72
- tx.witnesses[info.position] = ccc.hexFrom(witness.toBytes());
73
-
74
- return tx;
75
- }
76
30
  }