@ckb-ccc/joy-id 0.0.5-alpha.1 → 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/btc/index.d.ts +1 -2
- package/dist/btc/index.d.ts.map +1 -1
- package/dist/btc/index.js +1 -4
- package/dist/ckb/index.d.ts +4 -1
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +41 -15
- package/dist/evm/index.d.ts +1 -2
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +1 -4
- package/dist/signerFactory/index.d.ts.map +1 -1
- package/dist/signerFactory/index.js +7 -5
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +40 -19
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +30 -14
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +30 -14
- package/dist.commonjs/btc/index.d.ts +22 -16
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +99 -76
- package/dist.commonjs/ckb/index.d.ts +33 -23
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +204 -135
- package/dist.commonjs/common/index.d.ts +34 -21
- package/dist.commonjs/common/index.js +50 -45
- package/dist.commonjs/connectionsStorage/index.d.ts +23 -14
- package/dist.commonjs/connectionsStorage/index.js +28 -25
- package/dist.commonjs/evm/index.d.ts +21 -16
- package/dist.commonjs/evm/index.d.ts.map +1 -1
- package/dist.commonjs/evm/index.js +89 -70
- 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 +39 -26
- package/package.json +3 -3
- package/src/btc/index.ts +1 -12
- package/src/ckb/index.ts +55 -22
- package/src/evm/index.ts +1 -11
- package/src/signerFactory/index.ts +14 -5
- package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
|
@@ -6,83 +6,106 @@ const common_1 = require("@joyid/common");
|
|
|
6
6
|
const common_2 = require("../common");
|
|
7
7
|
const connectionsStorage_1 = require("../connectionsStorage");
|
|
8
8
|
class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
return this.connection;
|
|
9
|
+
assertConnection() {
|
|
10
|
+
if (!this.isConnected() || !this.connection) {
|
|
11
|
+
throw new Error("Not connected");
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
signMessageType: "ecdsa",
|
|
84
|
-
}, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
|
|
85
|
-
return signature;
|
|
13
|
+
return this.connection;
|
|
14
|
+
}
|
|
15
|
+
constructor(
|
|
16
|
+
client,
|
|
17
|
+
name,
|
|
18
|
+
icon,
|
|
19
|
+
addressType = "auto",
|
|
20
|
+
appUri = "https://app.joy.id",
|
|
21
|
+
connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage(),
|
|
22
|
+
) {
|
|
23
|
+
super(client);
|
|
24
|
+
this.name = name;
|
|
25
|
+
this.icon = icon;
|
|
26
|
+
this.addressType = addressType;
|
|
27
|
+
this.appUri = appUri;
|
|
28
|
+
this.connectionsRepo = connectionsRepo;
|
|
29
|
+
}
|
|
30
|
+
getConfig() {
|
|
31
|
+
return {
|
|
32
|
+
redirectURL: location.href,
|
|
33
|
+
joyidAppURL: this.appUri,
|
|
34
|
+
requestNetwork: `btc-${this.addressType}`,
|
|
35
|
+
name: this.name,
|
|
36
|
+
logo: this.icon,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async getBtcAccount() {
|
|
40
|
+
const { address } = this.assertConnection();
|
|
41
|
+
return address;
|
|
42
|
+
}
|
|
43
|
+
async getBtcPublicKey() {
|
|
44
|
+
const { publicKey } = this.assertConnection();
|
|
45
|
+
return publicKey;
|
|
46
|
+
}
|
|
47
|
+
async connect() {
|
|
48
|
+
const config = this.getConfig();
|
|
49
|
+
const res = await (0, common_2.createPopup)(
|
|
50
|
+
(0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
|
|
51
|
+
{
|
|
52
|
+
...config,
|
|
53
|
+
type: common_1.DappRequestType.Auth,
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
const { address, pubkey } = (() => {
|
|
57
|
+
if (this.addressType === "auto") {
|
|
58
|
+
return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
|
|
59
|
+
}
|
|
60
|
+
return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
|
|
61
|
+
})();
|
|
62
|
+
this.connection = {
|
|
63
|
+
address,
|
|
64
|
+
publicKey: core_1.ccc.hexFrom(pubkey),
|
|
65
|
+
keyType: res.keyType,
|
|
66
|
+
};
|
|
67
|
+
await Promise.all([
|
|
68
|
+
this.connectionsRepo.set(
|
|
69
|
+
{ uri: this.appUri, addressType: `btc-${res.btcAddressType}` },
|
|
70
|
+
this.connection,
|
|
71
|
+
),
|
|
72
|
+
this.connectionsRepo.set(
|
|
73
|
+
{ uri: this.appUri, addressType: "btc-auto" },
|
|
74
|
+
this.connection,
|
|
75
|
+
),
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
async isConnected() {
|
|
79
|
+
if (this.connection) {
|
|
80
|
+
return true;
|
|
86
81
|
}
|
|
82
|
+
this.connection = await this.connectionsRepo.get({
|
|
83
|
+
uri: this.appUri,
|
|
84
|
+
addressType: `btc-${this.addressType}`,
|
|
85
|
+
});
|
|
86
|
+
return this.connection !== undefined;
|
|
87
|
+
}
|
|
88
|
+
async signMessageRaw(message) {
|
|
89
|
+
const { address } = this.assertConnection();
|
|
90
|
+
const challenge =
|
|
91
|
+
typeof message === "string"
|
|
92
|
+
? message
|
|
93
|
+
: core_1.ccc.hexFrom(message).slice(2);
|
|
94
|
+
const config = this.getConfig();
|
|
95
|
+
const { signature } = await (0, common_2.createPopup)(
|
|
96
|
+
(0, common_1.buildJoyIDURL)(
|
|
97
|
+
{
|
|
98
|
+
...config,
|
|
99
|
+
challenge,
|
|
100
|
+
address,
|
|
101
|
+
signMessageType: "ecdsa",
|
|
102
|
+
},
|
|
103
|
+
"popup",
|
|
104
|
+
"/sign-message",
|
|
105
|
+
),
|
|
106
|
+
{ ...config, type: common_1.DappRequestType.SignMessage },
|
|
107
|
+
);
|
|
108
|
+
return signature;
|
|
109
|
+
}
|
|
87
110
|
}
|
|
88
111
|
exports.BitcoinSigner = BitcoinSigner;
|
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { ConnectionsRepo } from "../connectionsStorage";
|
|
3
3
|
export declare class CkbSigner extends ccc.Signer {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
private readonly name;
|
|
5
|
+
private readonly icon;
|
|
6
|
+
private readonly _appUri?;
|
|
7
|
+
private readonly _aggregatorUri?;
|
|
8
|
+
private readonly connectionsRepo;
|
|
9
|
+
get type(): ccc.SignerType;
|
|
10
|
+
get signType(): ccc.SignerSignType;
|
|
11
|
+
private connection?;
|
|
12
|
+
private assertConnection;
|
|
13
|
+
constructor(
|
|
14
|
+
client: ccc.Client,
|
|
15
|
+
name: string,
|
|
16
|
+
icon: string,
|
|
17
|
+
_appUri?: string | undefined,
|
|
18
|
+
_aggregatorUri?: string | undefined,
|
|
19
|
+
connectionsRepo?: ConnectionsRepo,
|
|
20
|
+
);
|
|
21
|
+
private getConfig;
|
|
22
|
+
private getAggregatorUri;
|
|
23
|
+
connect(): Promise<void>;
|
|
24
|
+
disconnect(): Promise<void>;
|
|
25
|
+
isConnected(): Promise<boolean>;
|
|
26
|
+
getInternalAddress(): Promise<string>;
|
|
27
|
+
getIdentity(): Promise<string>;
|
|
28
|
+
getAddressObj(): Promise<ccc.Address>;
|
|
29
|
+
getAddressObjs(): Promise<ccc.Address[]>;
|
|
30
|
+
prepareTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
|
|
31
|
+
private prepareTransactionForSubKey;
|
|
32
|
+
signOnlyTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
|
|
33
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
34
|
+
private saveConnection;
|
|
35
|
+
private restoreConnection;
|
|
26
36
|
}
|
|
27
|
-
//# sourceMappingURL=index.d.ts.map
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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;AAIpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ckb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;IAqBrC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAxBlC,IAAI,IAAI,IAAI,GAAG,CAAC,UAAU,CAEzB;IAED,IAAI,QAAQ,IAAI,GAAG,CAAC,cAAc,CAEjC;IAED,OAAO,CAAC,UAAU,CAAC,CAAa;YAElB,gBAAgB;gBAS5B,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,oBAAQ,EAChB,cAAc,CAAC,oBAAQ,EACvB,eAAe,GAAE,eAAmD;IAKvF,OAAO,CAAC,SAAS;IAYjB,OAAO,CAAC,gBAAgB;IAUlB,OAAO,IAAI,OAAO,CAAC,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,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAQ9B,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;YAkBb,2BAA2B;IAuCnC,mBAAmB,CACvB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAyBrB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;YA2BxD,cAAc;YAUd,iBAAiB;CAMhC"}
|
|
@@ -7,140 +7,209 @@ const common_1 = require("@joyid/common");
|
|
|
7
7
|
const common_2 = require("../common");
|
|
8
8
|
const connectionsStorage_1 = require("../connectionsStorage");
|
|
9
9
|
class CkbSigner extends core_1.ccc.Signer {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
})
|
|
144
|
-
|
|
10
|
+
get type() {
|
|
11
|
+
return core_1.ccc.SignerType.CKB;
|
|
12
|
+
}
|
|
13
|
+
get signType() {
|
|
14
|
+
return core_1.ccc.SignerSignType.JoyId;
|
|
15
|
+
}
|
|
16
|
+
async assertConnection() {
|
|
17
|
+
if (!(await this.isConnected()) || !this.connection) {
|
|
18
|
+
throw new Error("Not connected");
|
|
19
|
+
}
|
|
20
|
+
return this.connection;
|
|
21
|
+
}
|
|
22
|
+
constructor(
|
|
23
|
+
client,
|
|
24
|
+
name,
|
|
25
|
+
icon,
|
|
26
|
+
_appUri,
|
|
27
|
+
_aggregatorUri,
|
|
28
|
+
connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage(),
|
|
29
|
+
) {
|
|
30
|
+
super(client);
|
|
31
|
+
this.name = name;
|
|
32
|
+
this.icon = icon;
|
|
33
|
+
this._appUri = _appUri;
|
|
34
|
+
this._aggregatorUri = _aggregatorUri;
|
|
35
|
+
this.connectionsRepo = connectionsRepo;
|
|
36
|
+
}
|
|
37
|
+
getConfig() {
|
|
38
|
+
return {
|
|
39
|
+
redirectURL: location.href,
|
|
40
|
+
joyidAppURL:
|
|
41
|
+
this._appUri ?? this.client.addressPrefix === "ckb"
|
|
42
|
+
? "https://app.joy.id"
|
|
43
|
+
: "https://testnet.joyid.dev",
|
|
44
|
+
name: this.name,
|
|
45
|
+
logo: this.icon,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
getAggregatorUri() {
|
|
49
|
+
if (this._aggregatorUri) {
|
|
50
|
+
return this._aggregatorUri;
|
|
51
|
+
}
|
|
52
|
+
return this.client.addressPrefix === "ckb"
|
|
53
|
+
? "https://cota.nervina.dev/mainnet-aggregator"
|
|
54
|
+
: "https://cota.nervina.dev/aggregator";
|
|
55
|
+
}
|
|
56
|
+
async connect() {
|
|
57
|
+
const config = this.getConfig();
|
|
58
|
+
const res = await (0, common_2.createPopup)(
|
|
59
|
+
(0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
|
|
60
|
+
{
|
|
61
|
+
...config,
|
|
62
|
+
type: common_1.DappRequestType.Auth,
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
this.connection = {
|
|
66
|
+
address: res.address,
|
|
67
|
+
publicKey: core_1.ccc.hexFrom(res.pubkey),
|
|
68
|
+
keyType: res.keyType,
|
|
69
|
+
};
|
|
70
|
+
await this.saveConnection();
|
|
71
|
+
}
|
|
72
|
+
async disconnect() {
|
|
73
|
+
this.connection = undefined;
|
|
74
|
+
await this.saveConnection();
|
|
75
|
+
}
|
|
76
|
+
async isConnected() {
|
|
77
|
+
if (this.connection) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
await this.restoreConnection();
|
|
81
|
+
return this.connection !== undefined;
|
|
82
|
+
}
|
|
83
|
+
async getInternalAddress() {
|
|
84
|
+
return (await this.assertConnection()).address;
|
|
85
|
+
}
|
|
86
|
+
async getIdentity() {
|
|
87
|
+
const connection = await this.assertConnection();
|
|
88
|
+
return JSON.stringify({
|
|
89
|
+
keyType: connection.keyType,
|
|
90
|
+
publicKey: connection.publicKey.slice(2),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async getAddressObj() {
|
|
94
|
+
return await core_1.ccc.Address.fromString(
|
|
95
|
+
await this.getInternalAddress(),
|
|
96
|
+
this.client,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
async getAddressObjs() {
|
|
100
|
+
return [await this.getAddressObj()];
|
|
101
|
+
}
|
|
102
|
+
async prepareTransaction(txLike) {
|
|
103
|
+
const tx = core_1.ccc.Transaction.from(txLike);
|
|
104
|
+
const position = await tx.findInputIndexByLock(
|
|
105
|
+
(await this.getAddressObj()).script,
|
|
106
|
+
this.client,
|
|
107
|
+
);
|
|
108
|
+
if (position === undefined) {
|
|
109
|
+
return tx;
|
|
110
|
+
}
|
|
111
|
+
const witness =
|
|
112
|
+
tx.getWitnessArgsAt(position) ?? core_1.ccc.WitnessArgs.from({});
|
|
113
|
+
witness.lock = "0x";
|
|
114
|
+
await this.prepareTransactionForSubKey(tx, witness);
|
|
115
|
+
tx.setWitnessArgsAt(position, witness);
|
|
116
|
+
return tx;
|
|
117
|
+
}
|
|
118
|
+
async prepareTransactionForSubKey(tx, witness) {
|
|
119
|
+
if (this.connection?.keyType !== "sub_key") {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
const pubkeyHash = core_1.ccc
|
|
123
|
+
.ckbHash(this.connection.publicKey)
|
|
124
|
+
.substring(0, 42);
|
|
125
|
+
const lock = (await this.getAddressObj()).script;
|
|
126
|
+
const aggregator = new ckb_1.Aggregator(await this.getAggregatorUri());
|
|
127
|
+
const { unlock_entry: unlockEntry } =
|
|
128
|
+
await aggregator.generateSubkeyUnlockSmt({
|
|
129
|
+
alg_index: 1,
|
|
130
|
+
pubkey_hash: pubkeyHash,
|
|
131
|
+
lock_script: core_1.ccc.hexFrom(lock.toBytes()),
|
|
132
|
+
});
|
|
133
|
+
witness.outputType = core_1.ccc.hexFrom(unlockEntry);
|
|
134
|
+
const cotaDeps = [];
|
|
135
|
+
for await (const cell of this.client.findCellsByLockAndType(lock, {
|
|
136
|
+
...(await this.client.getKnownScript(core_1.ccc.KnownScript.COTA)),
|
|
137
|
+
args: "0x",
|
|
138
|
+
})) {
|
|
139
|
+
cotaDeps.push(
|
|
140
|
+
core_1.ccc.CellDep.from({
|
|
141
|
+
depType: "code",
|
|
142
|
+
outPoint: cell.outPoint,
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
if (cotaDeps.length === 0) {
|
|
147
|
+
throw new Error("No COTA cells for sub key wallet");
|
|
148
|
+
}
|
|
149
|
+
tx.cellDeps.unshift(...cotaDeps);
|
|
150
|
+
}
|
|
151
|
+
async signOnlyTransaction(txLike) {
|
|
152
|
+
const tx = core_1.ccc.Transaction.from(txLike);
|
|
153
|
+
const { script } = await this.getAddressObj();
|
|
154
|
+
const config = this.getConfig();
|
|
155
|
+
const res = await (0, common_2.createPopup)(
|
|
156
|
+
(0, common_1.buildJoyIDURL)(
|
|
157
|
+
{
|
|
158
|
+
...config,
|
|
159
|
+
tx: JSON.parse(tx.stringify()),
|
|
160
|
+
signerAddress: (await this.assertConnection()).address,
|
|
161
|
+
witnessIndex: await tx.findInputIndexByLock(script, this.client),
|
|
162
|
+
},
|
|
163
|
+
"popup",
|
|
164
|
+
"/sign-ckb-raw-tx",
|
|
165
|
+
),
|
|
166
|
+
{
|
|
167
|
+
...config,
|
|
168
|
+
type: common_1.DappRequestType.SignCkbRawTx,
|
|
169
|
+
},
|
|
170
|
+
);
|
|
171
|
+
return core_1.ccc.Transaction.from(res.tx);
|
|
172
|
+
}
|
|
173
|
+
async signMessageRaw(message) {
|
|
174
|
+
const { address } = await this.assertConnection();
|
|
175
|
+
const challenge =
|
|
176
|
+
typeof message === "string"
|
|
177
|
+
? message
|
|
178
|
+
: core_1.ccc.hexFrom(message).slice(2);
|
|
179
|
+
const config = this.getConfig();
|
|
180
|
+
const res = await (0, common_2.createPopup)(
|
|
181
|
+
(0, common_1.buildJoyIDURL)(
|
|
182
|
+
{
|
|
183
|
+
...config,
|
|
184
|
+
challenge,
|
|
185
|
+
isData: typeof message !== "string",
|
|
186
|
+
address,
|
|
187
|
+
},
|
|
188
|
+
"popup",
|
|
189
|
+
"/sign-message",
|
|
190
|
+
),
|
|
191
|
+
{ ...config, type: common_1.DappRequestType.SignMessage },
|
|
192
|
+
);
|
|
193
|
+
return JSON.stringify({
|
|
194
|
+
signature: res.signature,
|
|
195
|
+
alg: res.alg,
|
|
196
|
+
message: res.message,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
async saveConnection() {
|
|
200
|
+
return this.connectionsRepo.set(
|
|
201
|
+
{
|
|
202
|
+
uri: this.getConfig().joyidAppURL,
|
|
203
|
+
addressType: "ckb",
|
|
204
|
+
},
|
|
205
|
+
this.connection,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
async restoreConnection() {
|
|
209
|
+
this.connection = await this.connectionsRepo.get({
|
|
210
|
+
uri: this.getConfig().joyidAppURL,
|
|
211
|
+
addressType: "ckb",
|
|
212
|
+
});
|
|
213
|
+
}
|
|
145
214
|
}
|
|
146
215
|
exports.CkbSigner = CkbSigner;
|