@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.
- 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 -3
- package/dist/btc/index.d.ts.map +1 -1
- package/dist/btc/index.js +28 -17
- package/dist/ckb/index.d.ts +9 -3
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +58 -30
- 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 +20 -0
- package/dist/evm/index.d.ts.map +1 -0
- package/dist/evm/index.js +78 -0
- package/dist/signerFactory/index.d.ts +1 -1
- package/dist/signerFactory/index.d.ts.map +1 -1
- package/dist/signerFactory/index.js +10 -10
- package/dist.commonjs/advancedBarrel.d.ts +1 -0
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
- package/dist.commonjs/advancedBarrel.js +1 -0
- package/dist.commonjs/barrel.d.ts +1 -0
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +1 -0
- package/dist.commonjs/btc/index.d.ts +6 -3
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +27 -16
- package/dist.commonjs/ckb/index.d.ts +9 -3
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +57 -29
- package/dist.commonjs/common/index.d.ts +24 -0
- package/dist.commonjs/common/index.d.ts.map +1 -0
- package/dist.commonjs/common/index.js +54 -0
- package/dist.commonjs/evm/index.d.ts +20 -0
- package/dist.commonjs/evm/index.d.ts.map +1 -0
- package/dist.commonjs/evm/index.js +82 -0
- package/dist.commonjs/signerFactory/index.d.ts +1 -1
- package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
- package/dist.commonjs/signerFactory/index.js +10 -10
- package/package.json +3 -3
- package/src/advancedBarrel.ts +1 -0
- package/src/barrel.ts +1 -0
- package/src/btc/index.ts +45 -19
- package/src/ckb/index.ts +89 -44
- package/src/common/index.ts +100 -0
- package/src/evm/index.ts +118 -0
- package/src/signerFactory/index.ts +14 -9
- package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;IAa5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAhBlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC,OAAO,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;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"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BitcoinSigner = void 0;
|
|
4
4
|
const core_1 = require("@ckb-ccc/core");
|
|
5
5
|
const common_1 = require("@joyid/common");
|
|
6
|
+
const common_2 = require("../common");
|
|
6
7
|
const connectionsStorage_1 = require("../connectionsStorage");
|
|
7
8
|
class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
8
9
|
assertConnection() {
|
|
@@ -11,14 +12,25 @@ class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
|
11
12
|
}
|
|
12
13
|
return this.connection;
|
|
13
14
|
}
|
|
14
|
-
constructor(client, addressType = "auto",
|
|
15
|
+
constructor(client, name, icon, addressType = "auto", appUri = "https://app.joy.id", connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
|
|
15
16
|
super(client);
|
|
17
|
+
this.name = name;
|
|
18
|
+
this.icon = icon;
|
|
16
19
|
this.addressType = addressType;
|
|
17
|
-
this.
|
|
20
|
+
this.appUri = appUri;
|
|
18
21
|
this.connectionsRepo = connectionsRepo;
|
|
19
22
|
}
|
|
20
23
|
async replaceClient(client) {
|
|
21
|
-
return new BitcoinSigner(client, this.addressType, this.
|
|
24
|
+
return new BitcoinSigner(client, this.name, this.icon, this.addressType, this.appUri, this.connectionsRepo);
|
|
25
|
+
}
|
|
26
|
+
getConfig() {
|
|
27
|
+
return {
|
|
28
|
+
redirectURL: location.href,
|
|
29
|
+
joyidAppURL: this.appUri,
|
|
30
|
+
requestNetwork: `btc-${this.addressType}`,
|
|
31
|
+
name: this.name,
|
|
32
|
+
logo: this.icon,
|
|
33
|
+
};
|
|
22
34
|
}
|
|
23
35
|
async getBtcAccount() {
|
|
24
36
|
const { address } = this.assertConnection();
|
|
@@ -29,10 +41,10 @@ class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
|
29
41
|
return publicKey;
|
|
30
42
|
}
|
|
31
43
|
async connect() {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
const config = this.getConfig();
|
|
45
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
|
|
46
|
+
...config,
|
|
47
|
+
type: common_1.DappRequestType.Auth,
|
|
36
48
|
});
|
|
37
49
|
const { address, pubkey } = (() => {
|
|
38
50
|
if (this.addressType === "auto") {
|
|
@@ -46,8 +58,8 @@ class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
|
46
58
|
keyType: res.keyType,
|
|
47
59
|
};
|
|
48
60
|
await Promise.all([
|
|
49
|
-
this.connectionsRepo.set({ uri: this.
|
|
50
|
-
this.connectionsRepo.set({ uri: this.
|
|
61
|
+
this.connectionsRepo.set({ uri: this.appUri, addressType: `btc-${res.btcAddressType}` }, this.connection),
|
|
62
|
+
this.connectionsRepo.set({ uri: this.appUri, addressType: "btc-auto" }, this.connection),
|
|
51
63
|
]);
|
|
52
64
|
}
|
|
53
65
|
async isConnected() {
|
|
@@ -55,22 +67,21 @@ class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
|
55
67
|
return true;
|
|
56
68
|
}
|
|
57
69
|
this.connection = await this.connectionsRepo.get({
|
|
58
|
-
uri: this.
|
|
70
|
+
uri: this.appUri,
|
|
59
71
|
addressType: `btc-${this.addressType}`,
|
|
60
72
|
});
|
|
61
73
|
return this.connection !== undefined;
|
|
62
74
|
}
|
|
63
|
-
async
|
|
75
|
+
async signMessageRaw(message) {
|
|
64
76
|
const { address } = this.assertConnection();
|
|
65
77
|
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
const config = this.getConfig();
|
|
79
|
+
const { signature } = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
|
|
80
|
+
...config,
|
|
69
81
|
challenge,
|
|
70
82
|
address,
|
|
71
83
|
signMessageType: "ecdsa",
|
|
72
|
-
|
|
73
|
-
});
|
|
84
|
+
}, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
|
|
74
85
|
return signature;
|
|
75
86
|
}
|
|
76
87
|
}
|
|
@@ -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
|
|
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,
|
|
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
|
|
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;
|
|
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;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAW3D,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;YAgBb,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"}
|
|
@@ -4,44 +4,55 @@ exports.CkbSigner = void 0;
|
|
|
4
4
|
const core_1 = require("@ckb-ccc/core");
|
|
5
5
|
const ckb_1 = require("@joyid/ckb");
|
|
6
6
|
const common_1 = require("@joyid/common");
|
|
7
|
+
const common_2 = require("../common");
|
|
7
8
|
const connectionsStorage_1 = require("../connectionsStorage");
|
|
8
9
|
class CkbSigner extends core_1.ccc.Signer {
|
|
10
|
+
get type() {
|
|
11
|
+
return core_1.ccc.SignerType.CKB;
|
|
12
|
+
}
|
|
13
|
+
get signType() {
|
|
14
|
+
return core_1.ccc.SignerSignType.JoyId;
|
|
15
|
+
}
|
|
9
16
|
async assertConnection() {
|
|
10
17
|
if (!(await this.isConnected()) || !this.connection) {
|
|
11
18
|
throw new Error("Not connected");
|
|
12
19
|
}
|
|
13
20
|
return this.connection;
|
|
14
21
|
}
|
|
15
|
-
constructor(client,
|
|
22
|
+
constructor(client, name, icon, _appUri, _aggregatorUri, connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
|
|
16
23
|
super(client);
|
|
17
|
-
this.
|
|
24
|
+
this.name = name;
|
|
25
|
+
this.icon = icon;
|
|
26
|
+
this._appUri = _appUri;
|
|
18
27
|
this._aggregatorUri = _aggregatorUri;
|
|
19
28
|
this.connectionsRepo = connectionsRepo;
|
|
20
29
|
}
|
|
21
30
|
async replaceClient(client) {
|
|
22
|
-
return new CkbSigner(client, this.
|
|
31
|
+
return new CkbSigner(client, this.name, this.icon, this._appUri, this._aggregatorUri, this.connectionsRepo);
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
:
|
|
33
|
+
getConfig() {
|
|
34
|
+
return {
|
|
35
|
+
redirectURL: location.href,
|
|
36
|
+
joyidAppURL: this._appUri ?? this.client.addressPrefix === "ckb"
|
|
37
|
+
? "https://app.joy.id"
|
|
38
|
+
: "https://testnet.joyid.dev",
|
|
39
|
+
name: this.name,
|
|
40
|
+
logo: this.icon,
|
|
41
|
+
};
|
|
31
42
|
}
|
|
32
|
-
|
|
43
|
+
getAggregatorUri() {
|
|
33
44
|
if (this._aggregatorUri) {
|
|
34
45
|
return this._aggregatorUri;
|
|
35
46
|
}
|
|
36
|
-
return
|
|
47
|
+
return this.client.addressPrefix === "ckb"
|
|
37
48
|
? "https://cota.nervina.dev/mainnet-aggregator"
|
|
38
49
|
: "https://cota.nervina.dev/aggregator";
|
|
39
50
|
}
|
|
40
51
|
async connect() {
|
|
41
|
-
const
|
|
42
|
-
const res = await (0, common_1.
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
const config = this.getConfig();
|
|
53
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
|
|
54
|
+
...config,
|
|
55
|
+
type: common_1.DappRequestType.Auth,
|
|
45
56
|
});
|
|
46
57
|
this.connection = {
|
|
47
58
|
address: res.address,
|
|
@@ -64,6 +75,13 @@ class CkbSigner extends core_1.ccc.Signer {
|
|
|
64
75
|
async getInternalAddress() {
|
|
65
76
|
return (await this.assertConnection()).address;
|
|
66
77
|
}
|
|
78
|
+
async getIdentity() {
|
|
79
|
+
const connection = await this.assertConnection();
|
|
80
|
+
return JSON.stringify({
|
|
81
|
+
keyType: connection.keyType,
|
|
82
|
+
publicKey: connection.publicKey.slice(2),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
67
85
|
async getAddressObj() {
|
|
68
86
|
return await core_1.ccc.Address.fromString(await this.getInternalAddress(), this.client);
|
|
69
87
|
}
|
|
@@ -110,35 +128,45 @@ class CkbSigner extends core_1.ccc.Signer {
|
|
|
110
128
|
tx.cellDeps.unshift(...cotaDeps);
|
|
111
129
|
}
|
|
112
130
|
async signOnlyTransaction(txLike) {
|
|
113
|
-
const popup = (0, common_1.openPopup)("");
|
|
114
|
-
if (!popup) {
|
|
115
|
-
return (0, common_1.createBlockDialog)(async () => this.signOnlyTransaction(txLike));
|
|
116
|
-
}
|
|
117
131
|
const tx = core_1.ccc.Transaction.from(txLike);
|
|
118
132
|
const { script } = await this.getAddressObj();
|
|
119
|
-
|
|
120
|
-
|
|
133
|
+
const config = this.getConfig();
|
|
134
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
|
|
135
|
+
...config,
|
|
121
136
|
tx: JSON.parse(tx.stringify()),
|
|
122
137
|
signerAddress: (await this.assertConnection()).address,
|
|
123
|
-
redirectURL: location.href,
|
|
124
138
|
witnessIndex: await tx.findInputIndexByLock(script, this.client),
|
|
125
|
-
}, "popup", "/sign-ckb-raw-tx")
|
|
126
|
-
|
|
127
|
-
timeoutInSeconds: 3600,
|
|
128
|
-
popup,
|
|
139
|
+
}, "popup", "/sign-ckb-raw-tx"), {
|
|
140
|
+
...config,
|
|
129
141
|
type: common_1.DappRequestType.SignCkbRawTx,
|
|
130
142
|
});
|
|
131
143
|
return core_1.ccc.Transaction.from(res.tx);
|
|
132
144
|
}
|
|
145
|
+
async signMessageRaw(message) {
|
|
146
|
+
const { address } = await this.assertConnection();
|
|
147
|
+
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
148
|
+
const config = this.getConfig();
|
|
149
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
|
|
150
|
+
...config,
|
|
151
|
+
challenge,
|
|
152
|
+
isData: typeof message !== "string",
|
|
153
|
+
address,
|
|
154
|
+
}, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
|
|
155
|
+
return JSON.stringify({
|
|
156
|
+
signature: res.signature,
|
|
157
|
+
alg: res.alg,
|
|
158
|
+
message: res.message,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
133
161
|
async saveConnection() {
|
|
134
162
|
return this.connectionsRepo.set({
|
|
135
|
-
uri:
|
|
163
|
+
uri: this.getConfig().joyidAppURL,
|
|
136
164
|
addressType: "ckb",
|
|
137
165
|
}, this.connection);
|
|
138
166
|
}
|
|
139
167
|
async restoreConnection() {
|
|
140
168
|
this.connection = await this.connectionsRepo.get({
|
|
141
|
-
uri:
|
|
169
|
+
uri: this.getConfig().joyidAppURL,
|
|
142
170
|
addressType: "ckb",
|
|
143
171
|
});
|
|
144
172
|
}
|
|
@@ -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,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPopup = void 0;
|
|
4
|
+
const common_1 = require("@joyid/common");
|
|
5
|
+
async function createPopup(url, config) {
|
|
6
|
+
if (config.popup == null) {
|
|
7
|
+
config.popup = (0, common_1.openPopup)("");
|
|
8
|
+
if (config.popup == null) {
|
|
9
|
+
return (0, common_1.createBlockDialog)(async () => createPopup(url, config));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
config.popup.location.href = url;
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
if ((0, common_1.isStandaloneBrowser)()) {
|
|
15
|
+
reject(new common_1.PopupNotSupportedError(config.popup));
|
|
16
|
+
}
|
|
17
|
+
let popupEventListener;
|
|
18
|
+
let timeoutId;
|
|
19
|
+
// Check each second if the popup is closed triggering a PopupCancelledError
|
|
20
|
+
const popupTimer = setInterval(() => {
|
|
21
|
+
if (config.popup?.closed) {
|
|
22
|
+
clearInterval(popupTimer);
|
|
23
|
+
clearTimeout(timeoutId);
|
|
24
|
+
window.removeEventListener("message", popupEventListener, false);
|
|
25
|
+
reject(new common_1.PopupCancelledError(config.popup));
|
|
26
|
+
}
|
|
27
|
+
}, 1000);
|
|
28
|
+
timeoutId = setTimeout(() => {
|
|
29
|
+
clearInterval(popupTimer);
|
|
30
|
+
reject(new common_1.PopupTimeoutError(config.popup));
|
|
31
|
+
window.removeEventListener("message", popupEventListener, false);
|
|
32
|
+
}, (config.timeoutInSeconds ?? 3000) * 1000);
|
|
33
|
+
popupEventListener = (e) => {
|
|
34
|
+
const { joyidAppURL } = config;
|
|
35
|
+
const appURL = new URL(joyidAppURL);
|
|
36
|
+
if (e.origin !== appURL.origin) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!e.data || e.data?.type !== config.type) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
clearTimeout(timeoutId);
|
|
43
|
+
clearInterval(popupTimer);
|
|
44
|
+
window.removeEventListener("message", popupEventListener, false);
|
|
45
|
+
config.popup.close();
|
|
46
|
+
if (e.data.error) {
|
|
47
|
+
reject(new Error(e.data.error));
|
|
48
|
+
}
|
|
49
|
+
resolve(e.data.data);
|
|
50
|
+
};
|
|
51
|
+
window.addEventListener("message", popupEventListener);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.createPopup = createPopup;
|
|
@@ -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,82 @@
|
|
|
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(client, name, icon, appUri = "https://app.joy.id", connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
|
|
16
|
+
super(client);
|
|
17
|
+
this.name = name;
|
|
18
|
+
this.icon = icon;
|
|
19
|
+
this.appUri = appUri;
|
|
20
|
+
this.connectionsRepo = connectionsRepo;
|
|
21
|
+
}
|
|
22
|
+
async replaceClient(client) {
|
|
23
|
+
return new EvmSigner(client, this.name, this.icon, this.appUri, this.connectionsRepo);
|
|
24
|
+
}
|
|
25
|
+
getConfig() {
|
|
26
|
+
return {
|
|
27
|
+
redirectURL: location.href,
|
|
28
|
+
joyidAppURL: this.appUri,
|
|
29
|
+
requestNetwork: `ethereum`,
|
|
30
|
+
name: this.name,
|
|
31
|
+
logo: this.icon,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async getEvmAccount() {
|
|
35
|
+
return this.assertConnection().address;
|
|
36
|
+
}
|
|
37
|
+
async connect() {
|
|
38
|
+
const config = await this.getConfig();
|
|
39
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
|
|
40
|
+
...config,
|
|
41
|
+
type: common_1.DappRequestType.Auth,
|
|
42
|
+
});
|
|
43
|
+
this.connection = {
|
|
44
|
+
address: res.ethAddress,
|
|
45
|
+
publicKey: core_1.ccc.hexFrom(res.pubkey),
|
|
46
|
+
keyType: res.keyType,
|
|
47
|
+
};
|
|
48
|
+
await this.saveConnection();
|
|
49
|
+
}
|
|
50
|
+
async isConnected() {
|
|
51
|
+
if (this.connection) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
await this.restoreConnection();
|
|
55
|
+
return this.connection !== undefined;
|
|
56
|
+
}
|
|
57
|
+
async signMessageRaw(message) {
|
|
58
|
+
const { address } = this.assertConnection();
|
|
59
|
+
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
60
|
+
const config = this.getConfig();
|
|
61
|
+
const { signature } = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
|
|
62
|
+
...config,
|
|
63
|
+
challenge,
|
|
64
|
+
isData: typeof message !== "string",
|
|
65
|
+
address,
|
|
66
|
+
}, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
|
|
67
|
+
return core_1.ccc.hexFrom(signature);
|
|
68
|
+
}
|
|
69
|
+
async saveConnection() {
|
|
70
|
+
return this.connectionsRepo.set({
|
|
71
|
+
uri: this.getConfig().joyidAppURL,
|
|
72
|
+
addressType: "ethereum",
|
|
73
|
+
}, this.connection);
|
|
74
|
+
}
|
|
75
|
+
async restoreConnection() {
|
|
76
|
+
this.connection = await this.connectionsRepo.get({
|
|
77
|
+
uri: this.getConfig().joyidAppURL,
|
|
78
|
+
addressType: "ethereum",
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.EvmSigner = EvmSigner;
|
|
@@ -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;AAKpC,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,GAAG,CAAC,UAAU,EAAE,CAuBlB"}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getJoyIdSigners = void 0;
|
|
4
|
-
const core_1 = require("@ckb-ccc/core");
|
|
5
4
|
const btc_1 = require("../btc");
|
|
6
5
|
const ckb_1 = require("../ckb");
|
|
7
|
-
|
|
6
|
+
const evm_1 = require("../evm");
|
|
7
|
+
function getJoyIdSigners(client, name, icon) {
|
|
8
8
|
return [
|
|
9
9
|
{
|
|
10
|
-
type: core_1.ccc.SignerType.CKB,
|
|
11
10
|
name: "CKB",
|
|
12
|
-
signer: new ckb_1.CkbSigner(client),
|
|
11
|
+
signer: new ckb_1.CkbSigner(client, name, icon),
|
|
13
12
|
},
|
|
14
13
|
{
|
|
15
|
-
type: core_1.ccc.SignerType.BTC,
|
|
16
14
|
name: "BTC",
|
|
17
|
-
signer: new btc_1.BitcoinSigner(client),
|
|
15
|
+
signer: new btc_1.BitcoinSigner(client, name, icon),
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "EVM",
|
|
19
|
+
signer: new evm_1.EvmSigner(client, name, icon),
|
|
18
20
|
},
|
|
19
21
|
{
|
|
20
|
-
type: core_1.ccc.SignerType.BTC,
|
|
21
22
|
name: "BTC (P2WPKH)",
|
|
22
|
-
signer: new btc_1.BitcoinSigner(client, "p2wpkh"),
|
|
23
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, "p2wpkh"),
|
|
23
24
|
},
|
|
24
25
|
{
|
|
25
|
-
type: core_1.ccc.SignerType.BTC,
|
|
26
26
|
name: "BTC (P2TR)",
|
|
27
|
-
signer: new btc_1.BitcoinSigner(client, "p2tr"),
|
|
27
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, "p2tr"),
|
|
28
28
|
},
|
|
29
29
|
];
|
|
30
30
|
}
|
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.2",
|
|
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.2",
|
|
42
42
|
"@joyid/ckb": "^0.0.11",
|
|
43
43
|
"@joyid/common": "^0.0.3"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "abbcbe8e25dc561e0a134d3906f40bb49b8a035f"
|
|
46
46
|
}
|
package/src/advancedBarrel.ts
CHANGED
package/src/barrel.ts
CHANGED