@ckb-ccc/joy-id 0.0.10-alpha.4 → 0.0.10-alpha.5
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.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 +59 -67
- package/dist.commonjs/btc/index.js +141 -176
- package/dist.commonjs/ckb/index.d.ts +115 -122
- package/dist.commonjs/ckb/index.js +255 -312
- package/dist.commonjs/common/index.d.ts +21 -34
- package/dist.commonjs/common/index.js +45 -50
- package/dist.commonjs/connectionsStorage/index.d.ts +44 -53
- package/dist.commonjs/connectionsStorage/index.js +44 -49
- package/dist.commonjs/evm/index.d.ts +62 -68
- package/dist.commonjs/evm/index.js +120 -143
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +19 -40
- package/dist.commonjs/nostr/index.d.ts +53 -59
- package/dist.commonjs/nostr/index.js +107 -127
- package/dist.commonjs/signerFactory/index.d.ts +2 -7
- package/dist.commonjs/signerFactory/index.js +31 -54
- package/package.json +4 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * as JoyIdA from "./advancedBarrel";
|
|
2
|
-
//# sourceMappingURL=advanced.d.ts.map
|
|
2
|
+
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -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.JoyIdA = void 0;
|
|
48
27
|
exports.JoyIdA = __importStar(require("./advancedBarrel"));
|
|
@@ -1,34 +1,18 @@
|
|
|
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 __exportStar =
|
|
26
|
-
(this && this.__exportStar) ||
|
|
27
|
-
function (m, exports) {
|
|
28
|
-
for (var p in m)
|
|
29
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
30
|
-
__createBinding(exports, m, p);
|
|
31
|
-
};
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
32
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
17
|
__exportStar(require("./common"), exports);
|
|
34
18
|
__exportStar(require("./connectionsStorage"), exports);
|
package/dist.commonjs/barrel.js
CHANGED
|
@@ -1,34 +1,18 @@
|
|
|
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 __exportStar =
|
|
26
|
-
(this && this.__exportStar) ||
|
|
27
|
-
function (m, exports) {
|
|
28
|
-
for (var p in m)
|
|
29
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
30
|
-
__createBinding(exports, m, p);
|
|
31
|
-
};
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
32
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
17
|
__exportStar(require("./btc"), exports);
|
|
34
18
|
__exportStar(require("./ckb"), exports);
|
|
@@ -6,71 +6,63 @@ import { ConnectionsRepo } from "../connectionsStorage";
|
|
|
6
6
|
* @extends {ccc.SignerBtc}
|
|
7
7
|
*/
|
|
8
8
|
export declare class BitcoinSigner extends ccc.SignerBtc {
|
|
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
|
-
|
|
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
|
-
isConnected(): Promise<boolean>;
|
|
69
|
-
/**
|
|
70
|
-
* Signs a raw message with the Bitcoin account.
|
|
71
|
-
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
72
|
-
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
73
|
-
*/
|
|
74
|
-
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly icon: string;
|
|
11
|
+
private readonly preferredNetworks;
|
|
12
|
+
readonly addressType: "auto" | "p2wpkh" | "p2tr";
|
|
13
|
+
private readonly _appUri?;
|
|
14
|
+
private readonly connectionsRepo;
|
|
15
|
+
private connection?;
|
|
16
|
+
private network;
|
|
17
|
+
/**
|
|
18
|
+
* Ensures that the signer is connected and returns the connection.
|
|
19
|
+
* @private
|
|
20
|
+
* @throws Will throw an error if not connected.
|
|
21
|
+
* @returns {Connection} The current connection.
|
|
22
|
+
*/
|
|
23
|
+
private assertConnection;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an instance of BitcoinSigner.
|
|
26
|
+
* @param client - The client instance.
|
|
27
|
+
* @param name - The name of the signer.
|
|
28
|
+
* @param icon - The icon URL of the signer.
|
|
29
|
+
* @param addressType - The address type.
|
|
30
|
+
* @param _appUri - The application URI.
|
|
31
|
+
* @param connectionsRepo - The connections repository.
|
|
32
|
+
*/
|
|
33
|
+
constructor(client: ccc.Client, name: string, icon: string, preferredNetworks?: ccc.NetworkPreference[], addressType?: "auto" | "p2wpkh" | "p2tr", _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
34
|
+
/**
|
|
35
|
+
* Gets the configuration for JoyID.
|
|
36
|
+
* @private
|
|
37
|
+
* @returns The configuration object.
|
|
38
|
+
*/
|
|
39
|
+
private getConfig;
|
|
40
|
+
disconnect(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets the Bitcoin account address.
|
|
43
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
44
|
+
*/
|
|
45
|
+
getBtcAccount(): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Gets the Bitcoin public key.
|
|
48
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
49
|
+
*/
|
|
50
|
+
getBtcPublicKey(): Promise<ccc.Hex>;
|
|
51
|
+
/**
|
|
52
|
+
* Connects to the provider by requesting authentication.
|
|
53
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
54
|
+
*/
|
|
55
|
+
connect(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Checks if the signer is connected.
|
|
58
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
59
|
+
*/
|
|
60
|
+
isConnected(): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Signs a raw message with the Bitcoin account.
|
|
63
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
64
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
65
|
+
*/
|
|
66
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
75
67
|
}
|
|
76
|
-
//# sourceMappingURL=index.d.ts.map
|
|
68
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -11,185 +11,150 @@ const connectionsStorage_1 = require("../connectionsStorage");
|
|
|
11
11
|
* @extends {ccc.SignerBtc}
|
|
12
12
|
*/
|
|
13
13
|
class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Ensures that the signer is connected and returns the connection.
|
|
16
|
+
* @private
|
|
17
|
+
* @throws Will throw an error if not connected.
|
|
18
|
+
* @returns {Connection} The current connection.
|
|
19
|
+
*/
|
|
20
|
+
assertConnection() {
|
|
21
|
+
if (!this.isConnected() || !this.connection) {
|
|
22
|
+
throw new Error("Not connected");
|
|
23
|
+
}
|
|
24
|
+
return this.connection;
|
|
23
25
|
}
|
|
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
|
-
connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage(),
|
|
54
|
-
) {
|
|
55
|
-
super(client);
|
|
56
|
-
this.name = name;
|
|
57
|
-
this.icon = icon;
|
|
58
|
-
this.preferredNetworks = preferredNetworks;
|
|
59
|
-
this.addressType = addressType;
|
|
60
|
-
this._appUri = _appUri;
|
|
61
|
-
this.connectionsRepo = connectionsRepo;
|
|
62
|
-
this.network = "btcTestnet";
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Gets the configuration for JoyID.
|
|
66
|
-
* @private
|
|
67
|
-
* @returns The configuration object.
|
|
68
|
-
*/
|
|
69
|
-
getConfig() {
|
|
70
|
-
const { network } = this.matchNetworkPreference(
|
|
71
|
-
this.preferredNetworks,
|
|
72
|
-
this.network,
|
|
73
|
-
) ?? { network: this.network };
|
|
74
|
-
if (this.network !== network) {
|
|
75
|
-
this.connection = undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of BitcoinSigner.
|
|
28
|
+
* @param client - The client instance.
|
|
29
|
+
* @param name - The name of the signer.
|
|
30
|
+
* @param icon - The icon URL of the signer.
|
|
31
|
+
* @param addressType - The address type.
|
|
32
|
+
* @param _appUri - The application URI.
|
|
33
|
+
* @param connectionsRepo - The connections repository.
|
|
34
|
+
*/
|
|
35
|
+
constructor(client, name, icon, preferredNetworks = [
|
|
36
|
+
{
|
|
37
|
+
addressPrefix: "ckb",
|
|
38
|
+
signerType: core_1.ccc.SignerType.BTC,
|
|
39
|
+
network: "btc",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
addressPrefix: "ckt",
|
|
43
|
+
signerType: core_1.ccc.SignerType.BTC,
|
|
44
|
+
network: "btcTestnet",
|
|
45
|
+
},
|
|
46
|
+
], addressType = "auto", _appUri, connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
|
|
47
|
+
super(client);
|
|
48
|
+
this.name = name;
|
|
49
|
+
this.icon = icon;
|
|
50
|
+
this.preferredNetworks = preferredNetworks;
|
|
51
|
+
this.addressType = addressType;
|
|
52
|
+
this._appUri = _appUri;
|
|
53
|
+
this.connectionsRepo = connectionsRepo;
|
|
54
|
+
this.network = "btcTestnet";
|
|
76
55
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Gets the configuration for JoyID.
|
|
58
|
+
* @private
|
|
59
|
+
* @returns The configuration object.
|
|
60
|
+
*/
|
|
61
|
+
getConfig() {
|
|
62
|
+
const { network } = this.matchNetworkPreference(this.preferredNetworks, this.network) ?? { network: this.network };
|
|
63
|
+
if (this.network !== network) {
|
|
64
|
+
this.connection = undefined;
|
|
65
|
+
}
|
|
66
|
+
this.network = network;
|
|
67
|
+
const url = {
|
|
68
|
+
btc: "https://app.joy.id",
|
|
69
|
+
btcTestnet: "https://testnet.joyid.dev",
|
|
70
|
+
}[network];
|
|
71
|
+
if (!url) {
|
|
72
|
+
throw new Error(`JoyID wallet doesn't support the requested chain ${this.network}`);
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
redirectURL: location.href,
|
|
76
|
+
joyidAppURL: this._appUri ?? url,
|
|
77
|
+
requestNetwork: `btc-${this.addressType}`,
|
|
78
|
+
name: this.name,
|
|
79
|
+
logo: this.icon,
|
|
80
|
+
};
|
|
86
81
|
}
|
|
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
|
-
|
|
145
|
-
this.connection
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
82
|
+
async disconnect() {
|
|
83
|
+
await super.disconnect();
|
|
84
|
+
await this.connectionsRepo.set({ uri: this.getConfig().joyidAppURL, addressType: "btc" }, undefined);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Gets the Bitcoin account address.
|
|
88
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
89
|
+
*/
|
|
90
|
+
async getBtcAccount() {
|
|
91
|
+
const { address } = this.assertConnection();
|
|
92
|
+
return address;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Gets the Bitcoin public key.
|
|
96
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
97
|
+
*/
|
|
98
|
+
async getBtcPublicKey() {
|
|
99
|
+
const { publicKey } = this.assertConnection();
|
|
100
|
+
return publicKey;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Connects to the provider by requesting authentication.
|
|
104
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
105
|
+
*/
|
|
106
|
+
async connect() {
|
|
107
|
+
const config = this.getConfig();
|
|
108
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
|
|
109
|
+
...config,
|
|
110
|
+
type: common_1.DappRequestType.Auth,
|
|
111
|
+
});
|
|
112
|
+
const { address, pubkey } = (() => {
|
|
113
|
+
if (this.addressType === "auto") {
|
|
114
|
+
return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
|
|
115
|
+
}
|
|
116
|
+
return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
|
|
117
|
+
})();
|
|
118
|
+
this.connection = {
|
|
119
|
+
address,
|
|
120
|
+
publicKey: core_1.ccc.hexFrom(pubkey),
|
|
121
|
+
keyType: res.keyType,
|
|
122
|
+
};
|
|
123
|
+
await Promise.all([
|
|
124
|
+
this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: `btc-${res.btcAddressType}` }, this.connection),
|
|
125
|
+
this.connectionsRepo.set({ uri: config.joyidAppURL, addressType: "btc-auto" }, this.connection),
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Checks if the signer is connected.
|
|
130
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
131
|
+
*/
|
|
132
|
+
async isConnected() {
|
|
133
|
+
if (this.connection) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
this.connection = await this.connectionsRepo.get({
|
|
137
|
+
uri: this.getConfig().joyidAppURL,
|
|
138
|
+
addressType: `btc-${this.addressType}`,
|
|
139
|
+
});
|
|
140
|
+
return this.connection !== undefined;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Signs a raw message with the Bitcoin account.
|
|
144
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
145
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
146
|
+
*/
|
|
147
|
+
async signMessageRaw(message) {
|
|
148
|
+
const { address } = this.assertConnection();
|
|
149
|
+
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
150
|
+
const config = this.getConfig();
|
|
151
|
+
const { signature } = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
|
|
152
|
+
...config,
|
|
153
|
+
challenge,
|
|
154
|
+
address,
|
|
155
|
+
signMessageType: "ecdsa",
|
|
156
|
+
}, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
|
|
157
|
+
return signature;
|
|
160
158
|
}
|
|
161
|
-
this.connection = await this.connectionsRepo.get({
|
|
162
|
-
uri: this.getConfig().joyidAppURL,
|
|
163
|
-
addressType: `btc-${this.addressType}`,
|
|
164
|
-
});
|
|
165
|
-
return this.connection !== undefined;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Signs a raw message with the Bitcoin account.
|
|
169
|
-
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
170
|
-
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
171
|
-
*/
|
|
172
|
-
async signMessageRaw(message) {
|
|
173
|
-
const { address } = this.assertConnection();
|
|
174
|
-
const challenge =
|
|
175
|
-
typeof message === "string"
|
|
176
|
-
? message
|
|
177
|
-
: core_1.ccc.hexFrom(message).slice(2);
|
|
178
|
-
const config = this.getConfig();
|
|
179
|
-
const { signature } = await (0, common_2.createPopup)(
|
|
180
|
-
(0, common_1.buildJoyIDURL)(
|
|
181
|
-
{
|
|
182
|
-
...config,
|
|
183
|
-
challenge,
|
|
184
|
-
address,
|
|
185
|
-
signMessageType: "ecdsa",
|
|
186
|
-
},
|
|
187
|
-
"popup",
|
|
188
|
-
"/sign-message",
|
|
189
|
-
),
|
|
190
|
-
{ ...config, type: common_1.DappRequestType.SignMessage },
|
|
191
|
-
);
|
|
192
|
-
return signature;
|
|
193
|
-
}
|
|
194
159
|
}
|
|
195
160
|
exports.BitcoinSigner = BitcoinSigner;
|