@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.
- package/dist/advancedBarrel.d.ts +1 -0
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/advancedBarrel.js +1 -0
- package/dist/barrel.d.ts +1 -0
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -0
- package/dist/btc/index.d.ts +6 -4
- package/dist/btc/index.d.ts.map +1 -1
- package/dist/btc/index.js +26 -18
- package/dist/ckb/index.d.ts +9 -4
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +59 -33
- package/dist/common/index.d.ts +24 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +50 -0
- package/dist/evm/index.d.ts +19 -0
- package/dist/evm/index.d.ts.map +1 -0
- package/dist/evm/index.js +75 -0
- package/dist/signerFactory/index.d.ts +1 -1
- package/dist/signerFactory/index.d.ts.map +1 -1
- package/dist/signerFactory/index.js +17 -9
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +40 -19
- package/dist.commonjs/advancedBarrel.d.ts +2 -1
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
- package/dist.commonjs/advancedBarrel.js +31 -14
- package/dist.commonjs/barrel.d.ts +2 -1
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +31 -14
- package/dist.commonjs/btc/index.d.ts +22 -13
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +100 -66
- package/dist.commonjs/ckb/index.d.ts +33 -21
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +205 -136
- package/dist.commonjs/common/index.d.ts +37 -0
- package/dist.commonjs/common/index.d.ts.map +1 -0
- package/dist.commonjs/common/index.js +59 -0
- package/dist.commonjs/connectionsStorage/index.d.ts +23 -14
- package/dist.commonjs/connectionsStorage/index.js +28 -25
- package/dist.commonjs/evm/index.d.ts +25 -0
- package/dist.commonjs/evm/index.d.ts.map +1 -0
- package/dist.commonjs/evm/index.js +101 -0
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +40 -19
- package/dist.commonjs/signerFactory/index.d.ts +6 -2
- package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
- package/dist.commonjs/signerFactory/index.js +41 -22
- package/package.json +3 -3
- package/src/advancedBarrel.ts +1 -0
- package/src/barrel.ts +1 -0
- package/src/btc/index.ts +35 -20
- package/src/ckb/index.ts +84 -48
- package/src/common/index.ts +100 -0
- package/src/evm/index.ts +108 -0
- package/src/signerFactory/index.ts +28 -9
- package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EvmSigner = void 0;
|
|
4
|
+
const core_1 = require("@ckb-ccc/core");
|
|
5
|
+
const common_1 = require("@joyid/common");
|
|
6
|
+
const common_2 = require("../common");
|
|
7
|
+
const connectionsStorage_1 = require("../connectionsStorage");
|
|
8
|
+
class EvmSigner extends core_1.ccc.SignerEvm {
|
|
9
|
+
assertConnection() {
|
|
10
|
+
if (!this.isConnected() || !this.connection) {
|
|
11
|
+
throw new Error("Not connected");
|
|
12
|
+
}
|
|
13
|
+
return this.connection;
|
|
14
|
+
}
|
|
15
|
+
constructor(
|
|
16
|
+
client,
|
|
17
|
+
name,
|
|
18
|
+
icon,
|
|
19
|
+
appUri = "https://app.joy.id",
|
|
20
|
+
connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage(),
|
|
21
|
+
) {
|
|
22
|
+
super(client);
|
|
23
|
+
this.name = name;
|
|
24
|
+
this.icon = icon;
|
|
25
|
+
this.appUri = appUri;
|
|
26
|
+
this.connectionsRepo = connectionsRepo;
|
|
27
|
+
}
|
|
28
|
+
getConfig() {
|
|
29
|
+
return {
|
|
30
|
+
redirectURL: location.href,
|
|
31
|
+
joyidAppURL: this.appUri,
|
|
32
|
+
requestNetwork: `ethereum`,
|
|
33
|
+
name: this.name,
|
|
34
|
+
logo: this.icon,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async getEvmAccount() {
|
|
38
|
+
return this.assertConnection().address;
|
|
39
|
+
}
|
|
40
|
+
async connect() {
|
|
41
|
+
const config = await this.getConfig();
|
|
42
|
+
const res = await (0, common_2.createPopup)(
|
|
43
|
+
(0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
|
|
44
|
+
{
|
|
45
|
+
...config,
|
|
46
|
+
type: common_1.DappRequestType.Auth,
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
this.connection = {
|
|
50
|
+
address: res.ethAddress,
|
|
51
|
+
publicKey: core_1.ccc.hexFrom(res.pubkey),
|
|
52
|
+
keyType: res.keyType,
|
|
53
|
+
};
|
|
54
|
+
await this.saveConnection();
|
|
55
|
+
}
|
|
56
|
+
async isConnected() {
|
|
57
|
+
if (this.connection) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
await this.restoreConnection();
|
|
61
|
+
return this.connection !== undefined;
|
|
62
|
+
}
|
|
63
|
+
async signMessageRaw(message) {
|
|
64
|
+
const { address } = this.assertConnection();
|
|
65
|
+
const challenge =
|
|
66
|
+
typeof message === "string"
|
|
67
|
+
? message
|
|
68
|
+
: core_1.ccc.hexFrom(message).slice(2);
|
|
69
|
+
const config = this.getConfig();
|
|
70
|
+
const { signature } = await (0, common_2.createPopup)(
|
|
71
|
+
(0, common_1.buildJoyIDURL)(
|
|
72
|
+
{
|
|
73
|
+
...config,
|
|
74
|
+
challenge,
|
|
75
|
+
isData: typeof message !== "string",
|
|
76
|
+
address,
|
|
77
|
+
},
|
|
78
|
+
"popup",
|
|
79
|
+
"/sign-message",
|
|
80
|
+
),
|
|
81
|
+
{ ...config, type: common_1.DappRequestType.SignMessage },
|
|
82
|
+
);
|
|
83
|
+
return core_1.ccc.hexFrom(signature);
|
|
84
|
+
}
|
|
85
|
+
async saveConnection() {
|
|
86
|
+
return this.connectionsRepo.set(
|
|
87
|
+
{
|
|
88
|
+
uri: this.getConfig().joyidAppURL,
|
|
89
|
+
addressType: "ethereum",
|
|
90
|
+
},
|
|
91
|
+
this.connection,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
async restoreConnection() {
|
|
95
|
+
this.connection = await this.connectionsRepo.get({
|
|
96
|
+
uri: this.getConfig().joyidAppURL,
|
|
97
|
+
addressType: "ethereum",
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.EvmSigner = EvmSigner;
|
package/dist.commonjs/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * as JoyId from "./barrel";
|
|
2
|
-
//# sourceMappingURL=index.d.ts.map
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist.commonjs/index.js
CHANGED
|
@@ -1,27 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __setModuleDefault =
|
|
26
|
+
(this && this.__setModuleDefault) ||
|
|
27
|
+
(Object.create
|
|
28
|
+
? function (o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}
|
|
31
|
+
: function (o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar =
|
|
35
|
+
(this && this.__importStar) ||
|
|
36
|
+
function (mod) {
|
|
19
37
|
if (mod && mod.__esModule) return mod;
|
|
20
38
|
var result = {};
|
|
21
|
-
if (mod != null)
|
|
39
|
+
if (mod != null)
|
|
40
|
+
for (var k in mod)
|
|
41
|
+
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
+
__createBinding(result, mod, k);
|
|
22
43
|
__setModuleDefault(result, mod);
|
|
23
44
|
return result;
|
|
24
|
-
};
|
|
45
|
+
};
|
|
25
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
47
|
exports.JoyId = void 0;
|
|
27
48
|
exports.JoyId = __importStar(require("./barrel"));
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
export declare function getJoyIdSigners(
|
|
3
|
-
|
|
2
|
+
export declare function getJoyIdSigners(
|
|
3
|
+
client: ccc.Client,
|
|
4
|
+
name: string,
|
|
5
|
+
icon: string,
|
|
6
|
+
): ccc.SignerInfo[];
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signerFactory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
|
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"}
|
|
@@ -2,30 +2,49 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getJoyIdSigners = void 0;
|
|
4
4
|
const core_1 = require("@ckb-ccc/core");
|
|
5
|
+
const common_1 = require("@joyid/common");
|
|
5
6
|
const btc_1 = require("../btc");
|
|
6
7
|
const ckb_1 = require("../ckb");
|
|
7
|
-
|
|
8
|
+
const evm_1 = require("../evm");
|
|
9
|
+
function getJoyIdSigners(client, name, icon) {
|
|
10
|
+
if (
|
|
11
|
+
(0, common_1.isStandaloneBrowser)() ||
|
|
12
|
+
core_1.ccc.isWebview(window.navigator.userAgent)
|
|
13
|
+
) {
|
|
8
14
|
return [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
core_1.ccc.SignerType.CKB,
|
|
16
|
+
core_1.ccc.SignerType.EVM,
|
|
17
|
+
core_1.ccc.SignerType.BTC,
|
|
18
|
+
].map((type) => ({
|
|
19
|
+
name: type,
|
|
20
|
+
signer: new core_1.ccc.SignerAlwaysError(
|
|
21
|
+
client,
|
|
22
|
+
type,
|
|
23
|
+
"JoyID can only be used with standard browsers",
|
|
24
|
+
),
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
name: "CKB",
|
|
30
|
+
signer: new ckb_1.CkbSigner(client, name, icon),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "BTC",
|
|
34
|
+
signer: new btc_1.BitcoinSigner(client, name, icon),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "EVM",
|
|
38
|
+
signer: new evm_1.EvmSigner(client, name, icon),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "BTC (P2WPKH)",
|
|
42
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, "p2wpkh"),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "BTC (P2TR)",
|
|
46
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, "p2tr"),
|
|
47
|
+
},
|
|
48
|
+
];
|
|
30
49
|
}
|
|
31
50
|
exports.getJoyIdSigners = getJoyIdSigners;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/joy-id",
|
|
3
|
-
"version": "0.0.5-alpha.
|
|
3
|
+
"version": "0.0.5-alpha.10",
|
|
4
4
|
"description": "Connector's support for JoyID",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@ckb-ccc/core": "0.0.5-alpha.
|
|
41
|
+
"@ckb-ccc/core": "0.0.5-alpha.10",
|
|
42
42
|
"@joyid/ckb": "^0.0.11",
|
|
43
43
|
"@joyid/common": "^0.0.3"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "91ea3a92b02117905449ce4d2afef88bd3ffcc60"
|
|
46
46
|
}
|
package/src/advancedBarrel.ts
CHANGED
package/src/barrel.ts
CHANGED
package/src/btc/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import {
|
|
2
|
+
import { DappRequestType, buildJoyIDURL } from "@joyid/common";
|
|
3
|
+
import { createPopup } from "../common";
|
|
3
4
|
import {
|
|
4
5
|
Connection,
|
|
5
6
|
ConnectionsRepo,
|
|
@@ -19,15 +20,23 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
19
20
|
|
|
20
21
|
constructor(
|
|
21
22
|
client: ccc.Client,
|
|
23
|
+
private readonly name: string,
|
|
24
|
+
private readonly icon: string,
|
|
22
25
|
private readonly addressType: "auto" | "p2wpkh" | "p2tr" = "auto",
|
|
23
|
-
private readonly
|
|
26
|
+
private readonly appUri = "https://app.joy.id",
|
|
24
27
|
private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),
|
|
25
28
|
) {
|
|
26
29
|
super(client);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
return
|
|
32
|
+
private getConfig() {
|
|
33
|
+
return {
|
|
34
|
+
redirectURL: location.href,
|
|
35
|
+
joyidAppURL: this.appUri,
|
|
36
|
+
requestNetwork: `btc-${this.addressType}`,
|
|
37
|
+
name: this.name,
|
|
38
|
+
logo: this.icon,
|
|
39
|
+
};
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
async getBtcAccount(): Promise<string> {
|
|
@@ -41,10 +50,10 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
async connect(): Promise<void> {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
const config = this.getConfig();
|
|
54
|
+
const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
|
|
55
|
+
...config,
|
|
56
|
+
type: DappRequestType.Auth,
|
|
48
57
|
});
|
|
49
58
|
|
|
50
59
|
const { address, pubkey } = (() => {
|
|
@@ -61,11 +70,11 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
61
70
|
};
|
|
62
71
|
await Promise.all([
|
|
63
72
|
this.connectionsRepo.set(
|
|
64
|
-
{ uri: this.
|
|
73
|
+
{ uri: this.appUri, addressType: `btc-${res.btcAddressType}` },
|
|
65
74
|
this.connection,
|
|
66
75
|
),
|
|
67
76
|
this.connectionsRepo.set(
|
|
68
|
-
{ uri: this.
|
|
77
|
+
{ uri: this.appUri, addressType: "btc-auto" },
|
|
69
78
|
this.connection,
|
|
70
79
|
),
|
|
71
80
|
]);
|
|
@@ -77,26 +86,32 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
this.connection = await this.connectionsRepo.get({
|
|
80
|
-
uri: this.
|
|
89
|
+
uri: this.appUri,
|
|
81
90
|
addressType: `btc-${this.addressType}`,
|
|
82
91
|
});
|
|
83
92
|
return this.connection !== undefined;
|
|
84
93
|
}
|
|
85
94
|
|
|
86
|
-
async
|
|
95
|
+
async signMessageRaw(message: string | ccc.BytesLike): Promise<string> {
|
|
87
96
|
const { address } = this.assertConnection();
|
|
88
97
|
|
|
89
98
|
const challenge =
|
|
90
99
|
typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
|
|
91
100
|
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
const config = this.getConfig();
|
|
102
|
+
const { signature } = await createPopup(
|
|
103
|
+
buildJoyIDURL(
|
|
104
|
+
{
|
|
105
|
+
...config,
|
|
106
|
+
challenge,
|
|
107
|
+
address,
|
|
108
|
+
signMessageType: "ecdsa",
|
|
109
|
+
},
|
|
110
|
+
"popup",
|
|
111
|
+
"/sign-message",
|
|
112
|
+
),
|
|
113
|
+
{ ...config, type: DappRequestType.SignMessage },
|
|
114
|
+
);
|
|
100
115
|
return signature;
|
|
101
116
|
}
|
|
102
117
|
}
|
package/src/ckb/index.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { Aggregator } from "@joyid/ckb";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
authWithPopup,
|
|
6
|
-
buildJoyIDURL,
|
|
7
|
-
createBlockDialog,
|
|
8
|
-
openPopup,
|
|
9
|
-
runPopup,
|
|
10
|
-
} from "@joyid/common";
|
|
3
|
+
import { DappRequestType, buildJoyIDURL } from "@joyid/common";
|
|
4
|
+
import { createPopup } from "../common";
|
|
11
5
|
import {
|
|
12
6
|
Connection,
|
|
13
7
|
ConnectionsRepo,
|
|
@@ -15,6 +9,14 @@ import {
|
|
|
15
9
|
} from "../connectionsStorage";
|
|
16
10
|
|
|
17
11
|
export class CkbSigner extends ccc.Signer {
|
|
12
|
+
get type(): ccc.SignerType {
|
|
13
|
+
return ccc.SignerType.CKB;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get signType(): ccc.SignerSignType {
|
|
17
|
+
return ccc.SignerSignType.JoyId;
|
|
18
|
+
}
|
|
19
|
+
|
|
18
20
|
private connection?: Connection;
|
|
19
21
|
|
|
20
22
|
private async assertConnection(): Promise<Connection> {
|
|
@@ -27,42 +29,43 @@ export class CkbSigner extends ccc.Signer {
|
|
|
27
29
|
|
|
28
30
|
constructor(
|
|
29
31
|
client: ccc.Client,
|
|
30
|
-
private readonly
|
|
32
|
+
private readonly name: string,
|
|
33
|
+
private readonly icon: string,
|
|
34
|
+
private readonly _appUri?: string,
|
|
31
35
|
private readonly _aggregatorUri?: string,
|
|
32
36
|
private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),
|
|
33
37
|
) {
|
|
34
38
|
super(client);
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
? "https://app.joy.id"
|
|
48
|
-
: "https://testnet.joyid.dev";
|
|
41
|
+
private getConfig() {
|
|
42
|
+
return {
|
|
43
|
+
redirectURL: location.href,
|
|
44
|
+
joyidAppURL:
|
|
45
|
+
this._appUri ?? this.client.addressPrefix === "ckb"
|
|
46
|
+
? "https://app.joy.id"
|
|
47
|
+
: "https://testnet.joyid.dev",
|
|
48
|
+
name: this.name,
|
|
49
|
+
logo: this.icon,
|
|
50
|
+
};
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
private
|
|
53
|
+
private getAggregatorUri(): string {
|
|
52
54
|
if (this._aggregatorUri) {
|
|
53
55
|
return this._aggregatorUri;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
return
|
|
58
|
+
return this.client.addressPrefix === "ckb"
|
|
57
59
|
? "https://cota.nervina.dev/mainnet-aggregator"
|
|
58
60
|
: "https://cota.nervina.dev/aggregator";
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
async connect(): Promise<void> {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const config = this.getConfig();
|
|
65
|
+
|
|
66
|
+
const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
|
|
67
|
+
...config,
|
|
68
|
+
type: DappRequestType.Auth,
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
this.connection = {
|
|
@@ -90,6 +93,14 @@ export class CkbSigner extends ccc.Signer {
|
|
|
90
93
|
return (await this.assertConnection()).address;
|
|
91
94
|
}
|
|
92
95
|
|
|
96
|
+
async getIdentity(): Promise<string> {
|
|
97
|
+
const connection = await this.assertConnection();
|
|
98
|
+
return JSON.stringify({
|
|
99
|
+
keyType: connection.keyType,
|
|
100
|
+
publicKey: connection.publicKey.slice(2),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
93
104
|
async getAddressObj(): Promise<ccc.Address> {
|
|
94
105
|
return await ccc.Address.fromString(
|
|
95
106
|
await this.getInternalAddress(),
|
|
@@ -116,7 +127,9 @@ export class CkbSigner extends ccc.Signer {
|
|
|
116
127
|
const witness = tx.getWitnessArgsAt(position) ?? ccc.WitnessArgs.from({});
|
|
117
128
|
witness.lock = "0x";
|
|
118
129
|
await this.prepareTransactionForSubKey(tx, witness);
|
|
119
|
-
|
|
130
|
+
tx.setWitnessArgsAt(position, witness);
|
|
131
|
+
|
|
132
|
+
return tx;
|
|
120
133
|
}
|
|
121
134
|
|
|
122
135
|
private async prepareTransactionForSubKey(
|
|
@@ -161,38 +174,61 @@ export class CkbSigner extends ccc.Signer {
|
|
|
161
174
|
async signOnlyTransaction(
|
|
162
175
|
txLike: ccc.TransactionLike,
|
|
163
176
|
): Promise<ccc.Transaction> {
|
|
164
|
-
const popup = openPopup("");
|
|
165
|
-
if (!popup) {
|
|
166
|
-
return createBlockDialog(async () => this.signOnlyTransaction(txLike));
|
|
167
|
-
}
|
|
168
177
|
const tx = ccc.Transaction.from(txLike);
|
|
169
178
|
const { script } = await this.getAddressObj();
|
|
170
179
|
|
|
171
|
-
|
|
180
|
+
const config = this.getConfig();
|
|
181
|
+
const res = await createPopup(
|
|
182
|
+
buildJoyIDURL(
|
|
183
|
+
{
|
|
184
|
+
...config,
|
|
185
|
+
tx: JSON.parse(tx.stringify()),
|
|
186
|
+
signerAddress: (await this.assertConnection()).address,
|
|
187
|
+
witnessIndex: await tx.findInputIndexByLock(script, this.client),
|
|
188
|
+
},
|
|
189
|
+
"popup",
|
|
190
|
+
"/sign-ckb-raw-tx",
|
|
191
|
+
),
|
|
172
192
|
{
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
signerAddress: (await this.assertConnection()).address,
|
|
176
|
-
redirectURL: location.href,
|
|
177
|
-
witnessIndex: await tx.findInputIndexByLock(script, this.client),
|
|
193
|
+
...config,
|
|
194
|
+
type: DappRequestType.SignCkbRawTx,
|
|
178
195
|
},
|
|
179
|
-
"popup",
|
|
180
|
-
"/sign-ckb-raw-tx",
|
|
181
196
|
);
|
|
182
197
|
|
|
183
|
-
const res = await runPopup({
|
|
184
|
-
timeoutInSeconds: 3600,
|
|
185
|
-
popup,
|
|
186
|
-
type: DappRequestType.SignCkbRawTx,
|
|
187
|
-
});
|
|
188
|
-
|
|
189
198
|
return ccc.Transaction.from(res.tx);
|
|
190
199
|
}
|
|
191
200
|
|
|
201
|
+
async signMessageRaw(message: string | ccc.BytesLike): Promise<string> {
|
|
202
|
+
const { address } = await this.assertConnection();
|
|
203
|
+
|
|
204
|
+
const challenge =
|
|
205
|
+
typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
|
|
206
|
+
|
|
207
|
+
const config = this.getConfig();
|
|
208
|
+
const res = await createPopup(
|
|
209
|
+
buildJoyIDURL(
|
|
210
|
+
{
|
|
211
|
+
...config,
|
|
212
|
+
challenge,
|
|
213
|
+
isData: typeof message !== "string",
|
|
214
|
+
address,
|
|
215
|
+
},
|
|
216
|
+
"popup",
|
|
217
|
+
"/sign-message",
|
|
218
|
+
),
|
|
219
|
+
{ ...config, type: DappRequestType.SignMessage },
|
|
220
|
+
);
|
|
221
|
+
return JSON.stringify({
|
|
222
|
+
signature: res.signature,
|
|
223
|
+
alg: res.alg,
|
|
224
|
+
message: res.message,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
192
228
|
private async saveConnection() {
|
|
193
229
|
return this.connectionsRepo.set(
|
|
194
230
|
{
|
|
195
|
-
uri:
|
|
231
|
+
uri: this.getConfig().joyidAppURL,
|
|
196
232
|
addressType: "ckb",
|
|
197
233
|
},
|
|
198
234
|
this.connection,
|
|
@@ -201,7 +237,7 @@ export class CkbSigner extends ccc.Signer {
|
|
|
201
237
|
|
|
202
238
|
private async restoreConnection() {
|
|
203
239
|
this.connection = await this.connectionsRepo.get({
|
|
204
|
-
uri:
|
|
240
|
+
uri: this.getConfig().joyidAppURL,
|
|
205
241
|
addressType: "ckb",
|
|
206
242
|
});
|
|
207
243
|
}
|