@ckb-ccc/utxo-global 0.0.16-alpha.7 → 0.0.17
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/CHANGELOG.md +20 -0
- package/dist/doge/index.d.ts +22 -0
- package/dist/doge/index.d.ts.map +1 -0
- package/dist/doge/index.js +84 -0
- package/dist/signersFactory.d.ts.map +1 -1
- package/dist/signersFactory.js +5 -0
- package/dist.commonjs/doge/index.d.ts +22 -0
- package/dist.commonjs/doge/index.d.ts.map +1 -0
- package/dist.commonjs/doge/index.js +88 -0
- package/dist.commonjs/signersFactory.d.ts.map +1 -1
- package/dist.commonjs/signersFactory.js +5 -0
- package/package.json +7 -2
- package/src/doge/index.ts +114 -0
- package/src/signersFactory.ts +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ckb-ccc/utxo-global
|
|
2
2
|
|
|
3
|
+
## 0.0.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#101](https://github.com/ckb-devrel/ccc/pull/101) [`d9affcc`](https://github.com/ckb-devrel/ccc/commit/d9affcc01c7b839b227e4d79bcb66e717577502a) Thanks [@Hanssen0](https://github.com/Hanssen0)! - fix: commonjs
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`d9affcc`](https://github.com/ckb-devrel/ccc/commit/d9affcc01c7b839b227e4d79bcb66e717577502a)]:
|
|
10
|
+
- @ckb-ccc/core@0.1.1
|
|
11
|
+
|
|
12
|
+
## 0.0.16
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#70](https://github.com/ckb-devrel/ccc/pull/70) [`acfc050`](https://github.com/ckb-devrel/ccc/commit/acfc0502cd6beb48b9310dec8411dcd630507366) Thanks [@Hanssen0](https://github.com/Hanssen0)! - fix(core): websocket transport
|
|
17
|
+
|
|
18
|
+
- [#96](https://github.com/ckb-devrel/ccc/pull/96) [`e63a06e`](https://github.com/ckb-devrel/ccc/commit/e63a06ee75ac8595208d216dec88a4228c465e23) Thanks [@Hanssen0](https://github.com/Hanssen0)! - feat: support doge signer
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`a3d5359`](https://github.com/ckb-devrel/ccc/commit/a3d53595f6dd11f2f59cdf0086b3d7ce558a2fdd), [`8824ff2`](https://github.com/ckb-devrel/ccc/commit/8824ff27af3b76186f1a7d6db8c907cd66f09d6a), [`f07a506`](https://github.com/ckb-devrel/ccc/commit/f07a506bd6fc27fe659a17d2f7baaeec54716d81), [`f21d7e4`](https://github.com/ckb-devrel/ccc/commit/f21d7e4cf422edab4a836ef6d678b620594fef8d), [`acfc050`](https://github.com/ckb-devrel/ccc/commit/acfc0502cd6beb48b9310dec8411dcd630507366), [`1720d5a`](https://github.com/ckb-devrel/ccc/commit/1720d5a398543f1c6e24763eeaf15d84cd2214bf), [`e63a06e`](https://github.com/ckb-devrel/ccc/commit/e63a06ee75ac8595208d216dec88a4228c465e23), [`c092988`](https://github.com/ckb-devrel/ccc/commit/c092988e7765b9ac79498d6bd72a6a2f62859b6f), [`50f2ce0`](https://github.com/ckb-devrel/ccc/commit/50f2ce08e74cb3fbeae926267d42e28b426fd7f4), [`4709384`](https://github.com/ckb-devrel/ccc/commit/4709384e37188991cb937b16f99f47ca82c912b8)]:
|
|
21
|
+
- @ckb-ccc/core@0.1.0
|
|
22
|
+
|
|
3
23
|
## 0.0.16-alpha.7
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { Provider } from "../advancedBarrel.js";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class SignerDoge extends ccc.SignerDoge {
|
|
7
|
+
readonly provider: Provider;
|
|
8
|
+
private readonly preferredNetworks;
|
|
9
|
+
private accountCache;
|
|
10
|
+
constructor(client: ccc.Client, provider: Provider, preferredNetworks?: ccc.NetworkPreference[]);
|
|
11
|
+
getDogeAddress(): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Ensure the BTC network is the same as CKB network.
|
|
14
|
+
*/
|
|
15
|
+
ensureNetwork(): Promise<void>;
|
|
16
|
+
_getNetworkToChange(): Promise<string | undefined>;
|
|
17
|
+
onReplaced(listener: () => void): () => void;
|
|
18
|
+
connect(): Promise<void>;
|
|
19
|
+
isConnected(): Promise<boolean>;
|
|
20
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/doge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD;;GAEG;AACH,qBAAa,UAAW,SAAQ,GAAG,CAAC,UAAU;aAK1B,QAAQ,EAAE,QAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IALpC,OAAO,CAAC,YAAY,CAAqB;gBAGvC,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ,EACjB,iBAAiB,GAAE,GAAG,CAAC,iBAAiB,EAWxD;IAKG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAMvC;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB9B,mBAAmB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAiBxD,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAiBtC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAKxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAQ/B,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAQvE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export class SignerDoge extends ccc.SignerDoge {
|
|
6
|
+
constructor(client, provider, preferredNetworks = [
|
|
7
|
+
{
|
|
8
|
+
addressPrefix: "ckb",
|
|
9
|
+
signerType: ccc.SignerType.Doge,
|
|
10
|
+
network: "doge",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
addressPrefix: "ckt",
|
|
14
|
+
signerType: ccc.SignerType.Doge,
|
|
15
|
+
network: "dogeTestnet",
|
|
16
|
+
},
|
|
17
|
+
]) {
|
|
18
|
+
super(client);
|
|
19
|
+
this.provider = provider;
|
|
20
|
+
this.preferredNetworks = preferredNetworks;
|
|
21
|
+
}
|
|
22
|
+
async getDogeAddress() {
|
|
23
|
+
const accounts = await this.provider.getAccount();
|
|
24
|
+
this.accountCache = accounts[0];
|
|
25
|
+
return this.accountCache;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Ensure the BTC network is the same as CKB network.
|
|
29
|
+
*/
|
|
30
|
+
async ensureNetwork() {
|
|
31
|
+
const network = await this._getNetworkToChange();
|
|
32
|
+
if (!network) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const chain = {
|
|
36
|
+
doge: "dogecoin",
|
|
37
|
+
dogeTestnet: "dogecoin_testnet",
|
|
38
|
+
}[network];
|
|
39
|
+
if (chain) {
|
|
40
|
+
await this.provider.switchNetwork(chain);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`UTXO Global Doge wallet doesn't support the requested chain ${network}`);
|
|
44
|
+
}
|
|
45
|
+
async _getNetworkToChange() {
|
|
46
|
+
const currentNetwork = {
|
|
47
|
+
dogecoin: "doge",
|
|
48
|
+
dogecoin_testnet: "dogeTestnet",
|
|
49
|
+
}[await this.provider.getNetwork()];
|
|
50
|
+
const { network } = this.matchNetworkPreference(this.preferredNetworks, currentNetwork) ?? { network: currentNetwork };
|
|
51
|
+
if (network === currentNetwork) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
return network;
|
|
55
|
+
}
|
|
56
|
+
onReplaced(listener) {
|
|
57
|
+
const stop = [];
|
|
58
|
+
const replacer = async () => {
|
|
59
|
+
listener();
|
|
60
|
+
stop[0]?.();
|
|
61
|
+
};
|
|
62
|
+
stop.push(() => {
|
|
63
|
+
this.provider.removeListener("accountsChanged", replacer);
|
|
64
|
+
this.provider.removeListener("networkChanged", replacer);
|
|
65
|
+
});
|
|
66
|
+
this.provider.on("accountsChanged", replacer);
|
|
67
|
+
this.provider.on("networkChanged", replacer);
|
|
68
|
+
return stop[0];
|
|
69
|
+
}
|
|
70
|
+
async connect() {
|
|
71
|
+
await this.provider.connect();
|
|
72
|
+
await this.ensureNetwork();
|
|
73
|
+
}
|
|
74
|
+
async isConnected() {
|
|
75
|
+
if ((await this._getNetworkToChange()) !== undefined) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return await this.provider.isConnected();
|
|
79
|
+
}
|
|
80
|
+
async signMessageRaw(message) {
|
|
81
|
+
const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
|
|
82
|
+
return this.provider.signMessage(challenge, this.accountCache ?? (await this.getDogeAddress()));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAMpC;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,iBAAiB,CAAC,EAAE,GAAG,CAAC,iBAAiB,EAAE,GAC1C,GAAG,CAAC,UAAU,EAAE,CAmClB"}
|
package/dist/signersFactory.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SignerBtc } from "./btc/index.js";
|
|
2
2
|
import { SignerCkb } from "./ckb/index.js";
|
|
3
|
+
import { SignerDoge } from "./doge/index.js";
|
|
3
4
|
/**
|
|
4
5
|
* @public
|
|
5
6
|
*/
|
|
@@ -17,5 +18,9 @@ export function getUtxoGlobalSigners(client, preferredNetworks) {
|
|
|
17
18
|
name: "BTC",
|
|
18
19
|
signer: new SignerBtc(client, windowRef.utxoGlobal.bitcoinSigner, preferredNetworks),
|
|
19
20
|
},
|
|
21
|
+
{
|
|
22
|
+
name: "DOGE",
|
|
23
|
+
signer: new SignerDoge(client, windowRef.utxoGlobal.dogeSigner, preferredNetworks),
|
|
24
|
+
},
|
|
20
25
|
];
|
|
21
26
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { Provider } from "../advancedBarrel.js";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class SignerDoge extends ccc.SignerDoge {
|
|
7
|
+
readonly provider: Provider;
|
|
8
|
+
private readonly preferredNetworks;
|
|
9
|
+
private accountCache;
|
|
10
|
+
constructor(client: ccc.Client, provider: Provider, preferredNetworks?: ccc.NetworkPreference[]);
|
|
11
|
+
getDogeAddress(): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Ensure the BTC network is the same as CKB network.
|
|
14
|
+
*/
|
|
15
|
+
ensureNetwork(): Promise<void>;
|
|
16
|
+
_getNetworkToChange(): Promise<string | undefined>;
|
|
17
|
+
onReplaced(listener: () => void): () => void;
|
|
18
|
+
connect(): Promise<void>;
|
|
19
|
+
isConnected(): Promise<boolean>;
|
|
20
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/doge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD;;GAEG;AACH,qBAAa,UAAW,SAAQ,GAAG,CAAC,UAAU;aAK1B,QAAQ,EAAE,QAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IALpC,OAAO,CAAC,YAAY,CAAqB;gBAGvC,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ,EACjB,iBAAiB,GAAE,GAAG,CAAC,iBAAiB,EAWxD;IAKG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAMvC;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB9B,mBAAmB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAiBxD,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAiBtC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAKxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAQ/B,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAQvE"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerDoge = void 0;
|
|
4
|
+
const core_1 = require("@ckb-ccc/core");
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
class SignerDoge extends core_1.ccc.SignerDoge {
|
|
9
|
+
constructor(client, provider, preferredNetworks = [
|
|
10
|
+
{
|
|
11
|
+
addressPrefix: "ckb",
|
|
12
|
+
signerType: core_1.ccc.SignerType.Doge,
|
|
13
|
+
network: "doge",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
addressPrefix: "ckt",
|
|
17
|
+
signerType: core_1.ccc.SignerType.Doge,
|
|
18
|
+
network: "dogeTestnet",
|
|
19
|
+
},
|
|
20
|
+
]) {
|
|
21
|
+
super(client);
|
|
22
|
+
this.provider = provider;
|
|
23
|
+
this.preferredNetworks = preferredNetworks;
|
|
24
|
+
}
|
|
25
|
+
async getDogeAddress() {
|
|
26
|
+
const accounts = await this.provider.getAccount();
|
|
27
|
+
this.accountCache = accounts[0];
|
|
28
|
+
return this.accountCache;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Ensure the BTC network is the same as CKB network.
|
|
32
|
+
*/
|
|
33
|
+
async ensureNetwork() {
|
|
34
|
+
const network = await this._getNetworkToChange();
|
|
35
|
+
if (!network) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const chain = {
|
|
39
|
+
doge: "dogecoin",
|
|
40
|
+
dogeTestnet: "dogecoin_testnet",
|
|
41
|
+
}[network];
|
|
42
|
+
if (chain) {
|
|
43
|
+
await this.provider.switchNetwork(chain);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`UTXO Global Doge wallet doesn't support the requested chain ${network}`);
|
|
47
|
+
}
|
|
48
|
+
async _getNetworkToChange() {
|
|
49
|
+
const currentNetwork = {
|
|
50
|
+
dogecoin: "doge",
|
|
51
|
+
dogecoin_testnet: "dogeTestnet",
|
|
52
|
+
}[await this.provider.getNetwork()];
|
|
53
|
+
const { network } = this.matchNetworkPreference(this.preferredNetworks, currentNetwork) ?? { network: currentNetwork };
|
|
54
|
+
if (network === currentNetwork) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return network;
|
|
58
|
+
}
|
|
59
|
+
onReplaced(listener) {
|
|
60
|
+
const stop = [];
|
|
61
|
+
const replacer = async () => {
|
|
62
|
+
listener();
|
|
63
|
+
stop[0]?.();
|
|
64
|
+
};
|
|
65
|
+
stop.push(() => {
|
|
66
|
+
this.provider.removeListener("accountsChanged", replacer);
|
|
67
|
+
this.provider.removeListener("networkChanged", replacer);
|
|
68
|
+
});
|
|
69
|
+
this.provider.on("accountsChanged", replacer);
|
|
70
|
+
this.provider.on("networkChanged", replacer);
|
|
71
|
+
return stop[0];
|
|
72
|
+
}
|
|
73
|
+
async connect() {
|
|
74
|
+
await this.provider.connect();
|
|
75
|
+
await this.ensureNetwork();
|
|
76
|
+
}
|
|
77
|
+
async isConnected() {
|
|
78
|
+
if ((await this._getNetworkToChange()) !== undefined) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return await this.provider.isConnected();
|
|
82
|
+
}
|
|
83
|
+
async signMessageRaw(message) {
|
|
84
|
+
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
85
|
+
return this.provider.signMessage(challenge, this.accountCache ?? (await this.getDogeAddress()));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.SignerDoge = SignerDoge;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAMpC;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,iBAAiB,CAAC,EAAE,GAAG,CAAC,iBAAiB,EAAE,GAC1C,GAAG,CAAC,UAAU,EAAE,CAmClB"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getUtxoGlobalSigners = getUtxoGlobalSigners;
|
|
4
4
|
const index_js_1 = require("./btc/index.js");
|
|
5
5
|
const index_js_2 = require("./ckb/index.js");
|
|
6
|
+
const index_js_3 = require("./doge/index.js");
|
|
6
7
|
/**
|
|
7
8
|
* @public
|
|
8
9
|
*/
|
|
@@ -20,5 +21,9 @@ function getUtxoGlobalSigners(client, preferredNetworks) {
|
|
|
20
21
|
name: "BTC",
|
|
21
22
|
signer: new index_js_1.SignerBtc(client, windowRef.utxoGlobal.bitcoinSigner, preferredNetworks),
|
|
22
23
|
},
|
|
24
|
+
{
|
|
25
|
+
name: "DOGE",
|
|
26
|
+
signer: new index_js_3.SignerDoge(client, windowRef.utxoGlobal.dogeSigner, preferredNetworks),
|
|
27
|
+
},
|
|
23
28
|
];
|
|
24
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/utxo-global",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "Common Chains Connector's support for UTXO Global",
|
|
5
5
|
"author": "Trong Dinh <trong@nexm.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,23 +10,28 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git://github.com/ckb-devrel/ccc.git"
|
|
12
12
|
},
|
|
13
|
+
"sideEffects": false,
|
|
13
14
|
"main": "dist.commonjs/index.js",
|
|
14
15
|
"module": "dist/index.js",
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|
|
17
18
|
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist.commonjs/index.js",
|
|
18
20
|
"default": "./dist.commonjs/index.js"
|
|
19
21
|
},
|
|
20
22
|
"./barrel": {
|
|
21
23
|
"import": "./dist/barrel.js",
|
|
24
|
+
"require": "./dist.commonjs/barrel.js",
|
|
22
25
|
"default": "./dist.commonjs/barrel.js"
|
|
23
26
|
},
|
|
24
27
|
"./advancedBarrel": {
|
|
25
28
|
"import": "./dist/advancedBarrel.js",
|
|
29
|
+
"require": "./dist.commonjs/advancedBarrel.js",
|
|
26
30
|
"default": "./dist.commonjs/advancedBarrel.js"
|
|
27
31
|
},
|
|
28
32
|
"./advanced": {
|
|
29
33
|
"import": "./dist/advanced.js",
|
|
34
|
+
"require": "./dist.commonjs/advanced.js",
|
|
30
35
|
"default": "./dist.commonjs/advanced.js"
|
|
31
36
|
}
|
|
32
37
|
},
|
|
@@ -46,7 +51,7 @@
|
|
|
46
51
|
"access": "public"
|
|
47
52
|
},
|
|
48
53
|
"dependencies": {
|
|
49
|
-
"@ckb-ccc/core": "0.1.
|
|
54
|
+
"@ckb-ccc/core": "0.1.1"
|
|
50
55
|
},
|
|
51
56
|
"scripts": {
|
|
52
57
|
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { Provider } from "../advancedBarrel.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class SignerDoge extends ccc.SignerDoge {
|
|
8
|
+
private accountCache: string | undefined;
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
client: ccc.Client,
|
|
12
|
+
public readonly provider: Provider,
|
|
13
|
+
private readonly preferredNetworks: ccc.NetworkPreference[] = [
|
|
14
|
+
{
|
|
15
|
+
addressPrefix: "ckb",
|
|
16
|
+
signerType: ccc.SignerType.Doge,
|
|
17
|
+
network: "doge",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
addressPrefix: "ckt",
|
|
21
|
+
signerType: ccc.SignerType.Doge,
|
|
22
|
+
network: "dogeTestnet",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
) {
|
|
26
|
+
super(client);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getDogeAddress(): Promise<string> {
|
|
30
|
+
const accounts = await this.provider.getAccount();
|
|
31
|
+
this.accountCache = accounts[0];
|
|
32
|
+
return this.accountCache;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Ensure the BTC network is the same as CKB network.
|
|
37
|
+
*/
|
|
38
|
+
async ensureNetwork(): Promise<void> {
|
|
39
|
+
const network = await this._getNetworkToChange();
|
|
40
|
+
if (!network) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const chain = {
|
|
45
|
+
doge: "dogecoin",
|
|
46
|
+
dogeTestnet: "dogecoin_testnet",
|
|
47
|
+
}[network];
|
|
48
|
+
|
|
49
|
+
if (chain) {
|
|
50
|
+
await this.provider.switchNetwork(chain);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
throw new Error(
|
|
55
|
+
`UTXO Global Doge wallet doesn't support the requested chain ${network}`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async _getNetworkToChange(): Promise<string | undefined> {
|
|
60
|
+
const currentNetwork = {
|
|
61
|
+
dogecoin: "doge",
|
|
62
|
+
dogecoin_testnet: "dogeTestnet",
|
|
63
|
+
}[await this.provider.getNetwork()];
|
|
64
|
+
|
|
65
|
+
const { network } = this.matchNetworkPreference(
|
|
66
|
+
this.preferredNetworks,
|
|
67
|
+
currentNetwork,
|
|
68
|
+
) ?? { network: currentNetwork };
|
|
69
|
+
if (network === currentNetwork) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return network;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
onReplaced(listener: () => void): () => void {
|
|
77
|
+
const stop: (() => void)[] = [];
|
|
78
|
+
const replacer = async () => {
|
|
79
|
+
listener();
|
|
80
|
+
stop[0]?.();
|
|
81
|
+
};
|
|
82
|
+
stop.push(() => {
|
|
83
|
+
this.provider.removeListener("accountsChanged", replacer);
|
|
84
|
+
this.provider.removeListener("networkChanged", replacer);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
this.provider.on("accountsChanged", replacer);
|
|
88
|
+
this.provider.on("networkChanged", replacer);
|
|
89
|
+
|
|
90
|
+
return stop[0];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async connect(): Promise<void> {
|
|
94
|
+
await this.provider.connect();
|
|
95
|
+
await this.ensureNetwork();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async isConnected(): Promise<boolean> {
|
|
99
|
+
if ((await this._getNetworkToChange()) !== undefined) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return await this.provider.isConnected();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async signMessageRaw(message: string | ccc.BytesLike): Promise<string> {
|
|
107
|
+
const challenge =
|
|
108
|
+
typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
|
|
109
|
+
return this.provider.signMessage(
|
|
110
|
+
challenge,
|
|
111
|
+
this.accountCache ?? (await this.getDogeAddress()),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
package/src/signersFactory.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ccc } from "@ckb-ccc/core";
|
|
|
2
2
|
import { Provider } from "./advancedBarrel.js";
|
|
3
3
|
import { SignerBtc } from "./btc/index.js";
|
|
4
4
|
import { SignerCkb } from "./ckb/index.js";
|
|
5
|
+
import { SignerDoge } from "./doge/index.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @public
|
|
@@ -14,6 +15,7 @@ export function getUtxoGlobalSigners(
|
|
|
14
15
|
utxoGlobal?: {
|
|
15
16
|
bitcoinSigner: Provider;
|
|
16
17
|
ckbSigner: Provider;
|
|
18
|
+
dogeSigner: Provider;
|
|
17
19
|
};
|
|
18
20
|
};
|
|
19
21
|
|
|
@@ -34,5 +36,13 @@ export function getUtxoGlobalSigners(
|
|
|
34
36
|
preferredNetworks,
|
|
35
37
|
),
|
|
36
38
|
},
|
|
39
|
+
{
|
|
40
|
+
name: "DOGE",
|
|
41
|
+
signer: new SignerDoge(
|
|
42
|
+
client,
|
|
43
|
+
windowRef.utxoGlobal.dogeSigner,
|
|
44
|
+
preferredNetworks,
|
|
45
|
+
),
|
|
46
|
+
},
|
|
37
47
|
];
|
|
38
48
|
}
|