@ckb-ccc/joy-id 0.0.8-alpha.0 → 0.0.8-alpha.3
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/README.md +6 -4
- package/dist/nostr/index.d.ts.map +1 -1
- package/dist/nostr/index.js +1 -4
- 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 +63 -56
- package/dist.commonjs/btc/index.js +140 -114
- package/dist.commonjs/ckb/index.d.ts +121 -114
- package/dist.commonjs/ckb/index.js +307 -250
- package/dist.commonjs/common/index.d.ts +34 -21
- package/dist.commonjs/common/index.js +50 -45
- package/dist.commonjs/connectionsStorage/index.d.ts +53 -44
- package/dist.commonjs/connectionsStorage/index.js +47 -44
- package/dist.commonjs/evm/index.d.ts +67 -61
- package/dist.commonjs/evm/index.js +135 -113
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +40 -19
- package/dist.commonjs/nostr/index.d.ts +48 -42
- package/dist.commonjs/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/nostr/index.js +108 -92
- package/dist.commonjs/signerFactory/index.d.ts +6 -2
- package/dist.commonjs/signerFactory/index.js +42 -31
- package/package.json +3 -3
- package/src/nostr/index.ts +1 -5
package/README.md
CHANGED
|
@@ -21,11 +21,13 @@
|
|
|
21
21
|
</p>
|
|
22
22
|
|
|
23
23
|
<p align="center">
|
|
24
|
-
"
|
|
24
|
+
"CCC - CKBers' Codebase" is the next step of "Common Chains Connector".
|
|
25
25
|
<br />
|
|
26
|
-
|
|
26
|
+
Empower yourself with CCC to discover the unlimited potential of CKB.
|
|
27
27
|
<br />
|
|
28
|
-
|
|
28
|
+
Interoperate with wallets from different chain ecosystems.
|
|
29
|
+
<br />
|
|
30
|
+
Fully enabling CKB's Turing completeness and cryptographic freedom power.
|
|
29
31
|
</p>
|
|
30
32
|
|
|
31
33
|
## Preview
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
</a>
|
|
37
39
|
</p>
|
|
38
40
|
|
|
39
|
-
This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/).
|
|
41
|
+
This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/). It showcases how to use CCC for some basic scenarios in CKB.
|
|
40
42
|
|
|
41
43
|
<h3 align="center">
|
|
42
44
|
Read more about CCC on its <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;IA2B5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IA7BlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;OAOG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,SAAuB,EAC7B,eAAe,GAAE,eAAmD;IAKvF,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO;IAI3C,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOzD;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAUjB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB9B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAY/B,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;IA2B5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IA7BlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;OAOG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,SAAuB,EAC7B,eAAe,GAAE,eAAmD;IAKvF,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO;IAI3C,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOzD;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAUjB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB9B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAY/B,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAIrC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;CAWrC"}
|
package/dist/nostr/index.js
CHANGED
|
@@ -90,10 +90,7 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
90
90
|
return this.connection !== undefined;
|
|
91
91
|
}
|
|
92
92
|
async getNostrPublicKey() {
|
|
93
|
-
|
|
94
|
-
throw new Error("Not connected");
|
|
95
|
-
}
|
|
96
|
-
return this.connection.publicKey;
|
|
93
|
+
return this.assertConnection().publicKey;
|
|
97
94
|
}
|
|
98
95
|
async signNostrEvent(event) {
|
|
99
96
|
const config = this.getConfig();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * as JoyIdA from "./advancedBarrel";
|
|
2
|
-
//# sourceMappingURL=advanced.d.ts.map
|
|
2
|
+
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -1,27 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
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) {
|
|
19
37
|
if (mod && mod.__esModule) return mod;
|
|
20
38
|
var result = {};
|
|
21
|
-
if (mod != null)
|
|
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);
|
|
22
43
|
__setModuleDefault(result, mod);
|
|
23
44
|
return result;
|
|
24
|
-
};
|
|
45
|
+
};
|
|
25
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
47
|
exports.JoyIdA = void 0;
|
|
27
48
|
exports.JoyIdA = __importStar(require("./advancedBarrel"));
|
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
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
|
+
};
|
|
16
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
33
|
__exportStar(require("./common"), exports);
|
|
18
34
|
__exportStar(require("./connectionsStorage"), exports);
|
package/dist.commonjs/barrel.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
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
|
+
};
|
|
16
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
33
|
__exportStar(require("./btc"), exports);
|
|
18
34
|
__exportStar(require("./ckb"), exports);
|
|
@@ -6,60 +6,67 @@ 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
|
-
|
|
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(
|
|
32
|
+
client: ccc.Client,
|
|
33
|
+
name: string,
|
|
34
|
+
icon: string,
|
|
35
|
+
addressType?: "auto" | "p2wpkh" | "p2tr",
|
|
36
|
+
appUri?: string,
|
|
37
|
+
connectionsRepo?: ConnectionsRepo,
|
|
38
|
+
);
|
|
39
|
+
/**
|
|
40
|
+
* Gets the configuration for JoyID.
|
|
41
|
+
* @private
|
|
42
|
+
* @returns {object} The configuration object.
|
|
43
|
+
*/
|
|
44
|
+
private getConfig;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the Bitcoin account address.
|
|
47
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
48
|
+
*/
|
|
49
|
+
getBtcAccount(): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the Bitcoin public key.
|
|
52
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
53
|
+
*/
|
|
54
|
+
getBtcPublicKey(): Promise<ccc.Hex>;
|
|
55
|
+
/**
|
|
56
|
+
* Connects to the provider by requesting authentication.
|
|
57
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
58
|
+
*/
|
|
59
|
+
connect(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Checks if the signer is connected.
|
|
62
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
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>;
|
|
64
71
|
}
|
|
65
|
-
//# sourceMappingURL=index.d.ts.map
|
|
72
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -11,121 +11,147 @@ 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
|
-
|
|
23
|
-
}
|
|
24
|
-
return this.connection;
|
|
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");
|
|
25
23
|
}
|
|
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
|
-
challenge,
|
|
125
|
-
address,
|
|
126
|
-
signMessageType: "ecdsa",
|
|
127
|
-
}, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
|
|
128
|
-
return signature;
|
|
24
|
+
return this.connection;
|
|
25
|
+
}
|
|
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(
|
|
36
|
+
client,
|
|
37
|
+
name,
|
|
38
|
+
icon,
|
|
39
|
+
addressType = "auto",
|
|
40
|
+
appUri = "https://app.joy.id",
|
|
41
|
+
connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage(),
|
|
42
|
+
) {
|
|
43
|
+
super(client);
|
|
44
|
+
this.name = name;
|
|
45
|
+
this.icon = icon;
|
|
46
|
+
this.addressType = addressType;
|
|
47
|
+
this.appUri = appUri;
|
|
48
|
+
this.connectionsRepo = connectionsRepo;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Gets the configuration for JoyID.
|
|
52
|
+
* @private
|
|
53
|
+
* @returns {object} The configuration object.
|
|
54
|
+
*/
|
|
55
|
+
getConfig() {
|
|
56
|
+
return {
|
|
57
|
+
redirectURL: location.href,
|
|
58
|
+
joyidAppURL: this.appUri,
|
|
59
|
+
requestNetwork: `btc-${this.addressType}`,
|
|
60
|
+
name: this.name,
|
|
61
|
+
logo: this.icon,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Gets the Bitcoin account address.
|
|
66
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
67
|
+
*/
|
|
68
|
+
async getBtcAccount() {
|
|
69
|
+
const { address } = this.assertConnection();
|
|
70
|
+
return address;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets the Bitcoin public key.
|
|
74
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
75
|
+
*/
|
|
76
|
+
async getBtcPublicKey() {
|
|
77
|
+
const { publicKey } = this.assertConnection();
|
|
78
|
+
return publicKey;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Connects to the provider by requesting authentication.
|
|
82
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
83
|
+
*/
|
|
84
|
+
async connect() {
|
|
85
|
+
const config = this.getConfig();
|
|
86
|
+
const res = await (0, common_2.createPopup)(
|
|
87
|
+
(0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
|
|
88
|
+
{
|
|
89
|
+
...config,
|
|
90
|
+
type: common_1.DappRequestType.Auth,
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
const { address, pubkey } = (() => {
|
|
94
|
+
if (this.addressType === "auto") {
|
|
95
|
+
return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
|
|
96
|
+
}
|
|
97
|
+
return res.btcAddressType === "p2wpkh" ? res.nativeSegwit : res.taproot;
|
|
98
|
+
})();
|
|
99
|
+
this.connection = {
|
|
100
|
+
address,
|
|
101
|
+
publicKey: core_1.ccc.hexFrom(pubkey),
|
|
102
|
+
keyType: res.keyType,
|
|
103
|
+
};
|
|
104
|
+
await Promise.all([
|
|
105
|
+
this.connectionsRepo.set(
|
|
106
|
+
{ uri: this.appUri, addressType: `btc-${res.btcAddressType}` },
|
|
107
|
+
this.connection,
|
|
108
|
+
),
|
|
109
|
+
this.connectionsRepo.set(
|
|
110
|
+
{ uri: this.appUri, addressType: "btc-auto" },
|
|
111
|
+
this.connection,
|
|
112
|
+
),
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Checks if the signer is connected.
|
|
117
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
118
|
+
*/
|
|
119
|
+
async isConnected() {
|
|
120
|
+
if (this.connection) {
|
|
121
|
+
return true;
|
|
129
122
|
}
|
|
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
|
+
}
|
|
130
156
|
}
|
|
131
157
|
exports.BitcoinSigner = BitcoinSigner;
|