@ckb-ccc/joy-id 0.0.7-alpha.1 → 0.0.8-alpha.0
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/barrel.d.ts +1 -0
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -0
- package/dist/ckb/index.js +1 -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 +2 -1
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +15 -30
- package/dist.commonjs/btc/index.d.ts +56 -63
- package/dist.commonjs/btc/index.js +114 -140
- package/dist.commonjs/ckb/index.d.ts +114 -121
- package/dist.commonjs/ckb/index.js +250 -307
- 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 -47
- package/dist.commonjs/evm/index.d.ts +61 -67
- package/dist.commonjs/evm/index.js +113 -135
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +19 -40
- package/dist.commonjs/nostr/index.d.ts +42 -48
- package/dist.commonjs/nostr/index.js +91 -110
- package/dist.commonjs/signerFactory/index.d.ts +2 -6
- package/dist.commonjs/signerFactory/index.js +31 -42
- package/package.json +3 -3
- package/src/barrel.ts +1 -0
- package/src/ckb/index.ts +1 -1
package/dist/barrel.d.ts
CHANGED
package/dist/barrel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC"}
|
package/dist/barrel.js
CHANGED
package/dist/ckb/index.js
CHANGED
|
@@ -171,7 +171,7 @@ export class CkbSigner extends ccc.Signer {
|
|
|
171
171
|
}
|
|
172
172
|
const pubkeyHash = ccc.ckbHash(this.connection.publicKey).substring(0, 42);
|
|
173
173
|
const lock = (await this.getAddressObj()).script;
|
|
174
|
-
const aggregator = new Aggregator(
|
|
174
|
+
const aggregator = new Aggregator(this.getAggregatorUri());
|
|
175
175
|
const { unlock_entry: unlockEntry } = await aggregator.generateSubkeyUnlockSmt({
|
|
176
176
|
alg_index: 1,
|
|
177
177
|
pubkey_hash: pubkeyHash,
|
|
@@ -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);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC"}
|
package/dist.commonjs/barrel.js
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
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);
|
|
35
19
|
__exportStar(require("./evm"), exports);
|
|
20
|
+
__exportStar(require("./nostr"), exports);
|
|
36
21
|
__exportStar(require("./signerFactory"), exports);
|
|
@@ -6,67 +6,60 @@ 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
|
-
isConnected(): Promise<boolean>;
|
|
65
|
-
/**
|
|
66
|
-
* Signs a raw message with the Bitcoin account.
|
|
67
|
-
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
68
|
-
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
69
|
-
*/
|
|
70
|
-
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
9
|
+
private readonly name;
|
|
10
|
+
private readonly icon;
|
|
11
|
+
private readonly addressType;
|
|
12
|
+
private readonly appUri;
|
|
13
|
+
private readonly connectionsRepo;
|
|
14
|
+
private connection?;
|
|
15
|
+
/**
|
|
16
|
+
* Ensures that the signer is connected and returns the connection.
|
|
17
|
+
* @private
|
|
18
|
+
* @throws Will throw an error if not connected.
|
|
19
|
+
* @returns {Connection} The current connection.
|
|
20
|
+
*/
|
|
21
|
+
private assertConnection;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of BitcoinSigner.
|
|
24
|
+
* @param {ccc.Client} client - The client instance.
|
|
25
|
+
* @param {string} name - The name of the signer.
|
|
26
|
+
* @param {string} icon - The icon URL of the signer.
|
|
27
|
+
* @param {"auto" | "p2wpkh" | "p2tr"} [addressType="auto"] - The address type.
|
|
28
|
+
* @param {string} [appUri="https://app.joy.id"] - The application URI.
|
|
29
|
+
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
30
|
+
*/
|
|
31
|
+
constructor(client: ccc.Client, name: string, icon: string, addressType?: "auto" | "p2wpkh" | "p2tr", appUri?: string, connectionsRepo?: ConnectionsRepo);
|
|
32
|
+
/**
|
|
33
|
+
* Gets the configuration for JoyID.
|
|
34
|
+
* @private
|
|
35
|
+
* @returns {object} The configuration object.
|
|
36
|
+
*/
|
|
37
|
+
private getConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the Bitcoin account address.
|
|
40
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
41
|
+
*/
|
|
42
|
+
getBtcAccount(): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the Bitcoin public key.
|
|
45
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
46
|
+
*/
|
|
47
|
+
getBtcPublicKey(): Promise<ccc.Hex>;
|
|
48
|
+
/**
|
|
49
|
+
* Connects to the provider by requesting authentication.
|
|
50
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
51
|
+
*/
|
|
52
|
+
connect(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if the signer is connected.
|
|
55
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
56
|
+
*/
|
|
57
|
+
isConnected(): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Signs a raw message with the Bitcoin account.
|
|
60
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
61
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
62
|
+
*/
|
|
63
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
71
64
|
}
|
|
72
|
-
//# sourceMappingURL=index.d.ts.map
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -11,147 +11,121 @@ 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
|
-
|
|
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
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of BitcoinSigner.
|
|
28
|
+
* @param {ccc.Client} client - The client instance.
|
|
29
|
+
* @param {string} name - The name of the signer.
|
|
30
|
+
* @param {string} icon - The icon URL of the signer.
|
|
31
|
+
* @param {"auto" | "p2wpkh" | "p2tr"} [addressType="auto"] - The address type.
|
|
32
|
+
* @param {string} [appUri="https://app.joy.id"] - The application URI.
|
|
33
|
+
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
34
|
+
*/
|
|
35
|
+
constructor(client, name, icon, addressType = "auto", appUri = "https://app.joy.id", connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
|
|
36
|
+
super(client);
|
|
37
|
+
this.name = name;
|
|
38
|
+
this.icon = icon;
|
|
39
|
+
this.addressType = addressType;
|
|
40
|
+
this.appUri = appUri;
|
|
41
|
+
this.connectionsRepo = connectionsRepo;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets the configuration for JoyID.
|
|
45
|
+
* @private
|
|
46
|
+
* @returns {object} The configuration object.
|
|
47
|
+
*/
|
|
48
|
+
getConfig() {
|
|
49
|
+
return {
|
|
50
|
+
redirectURL: location.href,
|
|
51
|
+
joyidAppURL: this.appUri,
|
|
52
|
+
requestNetwork: `btc-${this.addressType}`,
|
|
53
|
+
name: this.name,
|
|
54
|
+
logo: this.icon,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets the Bitcoin account address.
|
|
59
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
60
|
+
*/
|
|
61
|
+
async getBtcAccount() {
|
|
62
|
+
const { address } = this.assertConnection();
|
|
63
|
+
return address;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the Bitcoin public key.
|
|
67
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
68
|
+
*/
|
|
69
|
+
async getBtcPublicKey() {
|
|
70
|
+
const { publicKey } = this.assertConnection();
|
|
71
|
+
return publicKey;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Connects to the provider by requesting authentication.
|
|
75
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
76
|
+
*/
|
|
77
|
+
async connect() {
|
|
78
|
+
const config = this.getConfig();
|
|
79
|
+
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
|
|
80
|
+
...config,
|
|
81
|
+
type: common_1.DappRequestType.Auth,
|
|
82
|
+
});
|
|
83
|
+
const { address, pubkey } = (() => {
|
|
84
|
+
if (this.addressType === "auto") {
|
|
85
|
+
return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
|
|
86
|
+
}
|
|
87
|
+
return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
|
|
88
|
+
})();
|
|
89
|
+
this.connection = {
|
|
90
|
+
address,
|
|
91
|
+
publicKey: core_1.ccc.hexFrom(pubkey),
|
|
92
|
+
keyType: res.keyType,
|
|
93
|
+
};
|
|
94
|
+
await Promise.all([
|
|
95
|
+
this.connectionsRepo.set({ uri: this.appUri, addressType: `btc-${res.btcAddressType}` }, this.connection),
|
|
96
|
+
this.connectionsRepo.set({ uri: this.appUri, addressType: "btc-auto" }, this.connection),
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Checks if the signer is connected.
|
|
101
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
102
|
+
*/
|
|
103
|
+
async isConnected() {
|
|
104
|
+
if (this.connection) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
this.connection = await this.connectionsRepo.get({
|
|
108
|
+
uri: this.appUri,
|
|
109
|
+
addressType: `btc-${this.addressType}`,
|
|
110
|
+
});
|
|
111
|
+
return this.connection !== undefined;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Signs a raw message with the Bitcoin account.
|
|
115
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
116
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
117
|
+
*/
|
|
118
|
+
async signMessageRaw(message) {
|
|
119
|
+
const { address } = this.assertConnection();
|
|
120
|
+
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
121
|
+
const config = this.getConfig();
|
|
122
|
+
const { signature } = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
|
|
123
|
+
...config,
|
|
124
|
+
challenge,
|
|
125
|
+
address,
|
|
126
|
+
signMessageType: "ecdsa",
|
|
127
|
+
}, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
|
|
128
|
+
return signature;
|
|
122
129
|
}
|
|
123
|
-
this.connection = await this.connectionsRepo.get({
|
|
124
|
-
uri: this.appUri,
|
|
125
|
-
addressType: `btc-${this.addressType}`,
|
|
126
|
-
});
|
|
127
|
-
return this.connection !== undefined;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Signs a raw message with the Bitcoin account.
|
|
131
|
-
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
132
|
-
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
133
|
-
*/
|
|
134
|
-
async signMessageRaw(message) {
|
|
135
|
-
const { address } = this.assertConnection();
|
|
136
|
-
const challenge =
|
|
137
|
-
typeof message === "string"
|
|
138
|
-
? message
|
|
139
|
-
: core_1.ccc.hexFrom(message).slice(2);
|
|
140
|
-
const config = this.getConfig();
|
|
141
|
-
const { signature } = await (0, common_2.createPopup)(
|
|
142
|
-
(0, common_1.buildJoyIDURL)(
|
|
143
|
-
{
|
|
144
|
-
...config,
|
|
145
|
-
challenge,
|
|
146
|
-
address,
|
|
147
|
-
signMessageType: "ecdsa",
|
|
148
|
-
},
|
|
149
|
-
"popup",
|
|
150
|
-
"/sign-message",
|
|
151
|
-
),
|
|
152
|
-
{ ...config, type: common_1.DappRequestType.SignMessage },
|
|
153
|
-
);
|
|
154
|
-
return signature;
|
|
155
|
-
}
|
|
156
130
|
}
|
|
157
131
|
exports.BitcoinSigner = BitcoinSigner;
|