@ckb-ccc/joy-id 0.0.5-alpha.10 → 0.0.5-alpha.11
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/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +11 -1
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +19 -40
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +14 -30
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +14 -30
- package/dist.commonjs/btc/index.d.ts +15 -22
- package/dist.commonjs/btc/index.js +73 -99
- package/dist.commonjs/ckb/index.d.ts +26 -33
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +171 -204
- package/dist.commonjs/common/index.d.ts +21 -34
- package/dist.commonjs/common/index.js +45 -50
- package/dist.commonjs/connectionsStorage/index.d.ts +14 -23
- package/dist.commonjs/connectionsStorage/index.js +25 -28
- package/dist.commonjs/evm/index.d.ts +15 -21
- package/dist.commonjs/evm/index.js +67 -89
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +19 -40
- package/dist.commonjs/signerFactory/index.d.ts +2 -6
- package/dist.commonjs/signerFactory/index.js +27 -38
- package/package.json +3 -3
- package/src/ckb/index.ts +16 -1
|
@@ -2,37 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConnectionsRepoLocalStorage = exports.isSelectorEq = void 0;
|
|
4
4
|
function isSelectorEq(a, b) {
|
|
5
|
-
|
|
5
|
+
return a.uri === b.uri && a.addressType === b.addressType;
|
|
6
6
|
}
|
|
7
7
|
exports.isSelectorEq = isSelectorEq;
|
|
8
8
|
class ConnectionsRepoLocalStorage {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
JSON.stringify(connections.filter(([s]) => !isSelectorEq(s, selector))),
|
|
34
|
-
);
|
|
9
|
+
constructor(storageKey = "ccc-joy-id-signer") {
|
|
10
|
+
this.storageKey = storageKey;
|
|
11
|
+
}
|
|
12
|
+
async readConnections() {
|
|
13
|
+
return JSON.parse(window.localStorage.getItem(this.storageKey) ?? "[]");
|
|
14
|
+
}
|
|
15
|
+
async get(selector) {
|
|
16
|
+
return (await this.readConnections()).find(([s]) => isSelectorEq(selector, s))?.[1];
|
|
17
|
+
}
|
|
18
|
+
async set(selector, connection) {
|
|
19
|
+
const connections = await this.readConnections();
|
|
20
|
+
if (connection) {
|
|
21
|
+
const existed = connections.find(([s]) => isSelectorEq(s, selector));
|
|
22
|
+
if (existed) {
|
|
23
|
+
existed[1] = connection;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
connections.push([selector, connection]);
|
|
27
|
+
}
|
|
28
|
+
window.localStorage.setItem(this.storageKey, JSON.stringify(connections));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
window.localStorage.setItem(this.storageKey, JSON.stringify(connections.filter(([s]) => !isSelectorEq(s, selector))));
|
|
32
|
+
}
|
|
35
33
|
}
|
|
36
|
-
}
|
|
37
34
|
}
|
|
38
35
|
exports.ConnectionsRepoLocalStorage = ConnectionsRepoLocalStorage;
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { ConnectionsRepo } from "../connectionsStorage";
|
|
3
3
|
export declare class EvmSigner extends ccc.SignerEvm {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
getEvmAccount(): Promise<string>;
|
|
19
|
-
connect(): Promise<void>;
|
|
20
|
-
isConnected(): Promise<boolean>;
|
|
21
|
-
signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex>;
|
|
22
|
-
private saveConnection;
|
|
23
|
-
private restoreConnection;
|
|
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;
|
|
24
18
|
}
|
|
25
|
-
//# sourceMappingURL=index.d.ts.map
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -6,96 +6,74 @@ const common_1 = require("@joyid/common");
|
|
|
6
6
|
const common_2 = require("../common");
|
|
7
7
|
const connectionsStorage_1 = require("../connectionsStorage");
|
|
8
8
|
class EvmSigner extends core_1.ccc.SignerEvm {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
assertConnection() {
|
|
10
|
+
if (!this.isConnected() || !this.connection) {
|
|
11
|
+
throw new Error("Not connected");
|
|
12
|
+
}
|
|
13
|
+
return this.connection;
|
|
12
14
|
}
|
|
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
|
-
|
|
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
|
+
getConfig() {
|
|
23
|
+
return {
|
|
24
|
+
redirectURL: location.href,
|
|
25
|
+
joyidAppURL: this.appUri,
|
|
26
|
+
requestNetwork: `ethereum`,
|
|
27
|
+
name: this.name,
|
|
28
|
+
logo: this.icon,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async getEvmAccount() {
|
|
32
|
+
return this.assertConnection().address;
|
|
33
|
+
}
|
|
34
|
+
async connect() {
|
|
35
|
+
const config = await this.getConfig();
|
|
36
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
|
|
37
|
+
...config,
|
|
38
|
+
type: common_1.DappRequestType.Auth,
|
|
39
|
+
});
|
|
40
|
+
this.connection = {
|
|
41
|
+
address: res.ethAddress,
|
|
42
|
+
publicKey: core_1.ccc.hexFrom(res.pubkey),
|
|
43
|
+
keyType: res.keyType,
|
|
44
|
+
};
|
|
45
|
+
await this.saveConnection();
|
|
46
|
+
}
|
|
47
|
+
async isConnected() {
|
|
48
|
+
if (this.connection) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
await this.restoreConnection();
|
|
52
|
+
return this.connection !== undefined;
|
|
53
|
+
}
|
|
54
|
+
async signMessageRaw(message) {
|
|
55
|
+
const { address } = this.assertConnection();
|
|
56
|
+
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
57
|
+
const config = this.getConfig();
|
|
58
|
+
const { signature } = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
|
|
59
|
+
...config,
|
|
60
|
+
challenge,
|
|
61
|
+
isData: typeof message !== "string",
|
|
62
|
+
address,
|
|
63
|
+
}, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
|
|
64
|
+
return core_1.ccc.hexFrom(signature);
|
|
65
|
+
}
|
|
66
|
+
async saveConnection() {
|
|
67
|
+
return this.connectionsRepo.set({
|
|
68
|
+
uri: this.getConfig().joyidAppURL,
|
|
69
|
+
addressType: "ethereum",
|
|
70
|
+
}, this.connection);
|
|
71
|
+
}
|
|
72
|
+
async restoreConnection() {
|
|
73
|
+
this.connection = await this.connectionsRepo.get({
|
|
74
|
+
uri: this.getConfig().joyidAppURL,
|
|
75
|
+
addressType: "ethereum",
|
|
76
|
+
});
|
|
59
77
|
}
|
|
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
78
|
}
|
|
101
79
|
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,48 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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) {
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
37
19
|
if (mod && mod.__esModule) return mod;
|
|
38
20
|
var result = {};
|
|
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);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
43
22
|
__setModuleDefault(result, mod);
|
|
44
23
|
return result;
|
|
45
|
-
|
|
24
|
+
};
|
|
46
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
26
|
exports.JoyId = void 0;
|
|
48
27
|
exports.JoyId = __importStar(require("./barrel"));
|
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
export declare function getJoyIdSigners(
|
|
3
|
-
|
|
4
|
-
name: string,
|
|
5
|
-
icon: string,
|
|
6
|
-
): ccc.SignerInfo[];
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
2
|
+
export declare function getJoyIdSigners(client: ccc.Client, name: string, icon: string): ccc.SignerInfo[];
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -7,44 +7,33 @@ const btc_1 = require("../btc");
|
|
|
7
7
|
const ckb_1 = require("../ckb");
|
|
8
8
|
const evm_1 = require("../evm");
|
|
9
9
|
function getJoyIdSigners(client, name, icon) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
if ((0, common_1.isStandaloneBrowser)() || core_1.ccc.isWebview(window.navigator.userAgent)) {
|
|
11
|
+
return [core_1.ccc.SignerType.CKB, core_1.ccc.SignerType.EVM, core_1.ccc.SignerType.BTC].map((type) => ({
|
|
12
|
+
name: type,
|
|
13
|
+
signer: new core_1.ccc.SignerAlwaysError(client, type, "JoyID can only be used with standard browsers"),
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
14
16
|
return [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
];
|
|
17
|
+
{
|
|
18
|
+
name: "CKB",
|
|
19
|
+
signer: new ckb_1.CkbSigner(client, name, icon),
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "BTC",
|
|
23
|
+
signer: new btc_1.BitcoinSigner(client, name, icon),
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "EVM",
|
|
27
|
+
signer: new evm_1.EvmSigner(client, name, icon),
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "BTC (P2WPKH)",
|
|
31
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, "p2wpkh"),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "BTC (P2TR)",
|
|
35
|
+
signer: new btc_1.BitcoinSigner(client, name, icon, "p2tr"),
|
|
36
|
+
},
|
|
37
|
+
];
|
|
49
38
|
}
|
|
50
39
|
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.11",
|
|
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.11",
|
|
42
42
|
"@joyid/ckb": "^0.0.11",
|
|
43
43
|
"@joyid/common": "^0.0.3"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "91d312cf8246dbe772ed163a8d970e6af6c55368"
|
|
46
46
|
}
|
package/src/ckb/index.ts
CHANGED
|
@@ -178,13 +178,28 @@ export class CkbSigner extends ccc.Signer {
|
|
|
178
178
|
const { script } = await this.getAddressObj();
|
|
179
179
|
|
|
180
180
|
const config = this.getConfig();
|
|
181
|
+
|
|
182
|
+
const witnessIndexes = await tx.inputs.map(async (input, i) => {
|
|
183
|
+
await input.completeExtraInfos(this.client);
|
|
184
|
+
|
|
185
|
+
if (!input.cellOutput) {
|
|
186
|
+
throw Error("Unable to resolve inputs info");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!script.eq(input.cellOutput.lock)) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return i;
|
|
194
|
+
});
|
|
195
|
+
|
|
181
196
|
const res = await createPopup(
|
|
182
197
|
buildJoyIDURL(
|
|
183
198
|
{
|
|
184
199
|
...config,
|
|
185
200
|
tx: JSON.parse(tx.stringify()),
|
|
186
201
|
signerAddress: (await this.assertConnection()).address,
|
|
187
|
-
|
|
202
|
+
witnessIndexes: witnessIndexes.filter((i) => i !== undefined),
|
|
188
203
|
},
|
|
189
204
|
"popup",
|
|
190
205
|
"/sign-ckb-raw-tx",
|