@ckb-ccc/utxo-global 0.0.11-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.
Files changed (55) hide show
  1. package/README.md +45 -0
  2. package/dist/advanced.d.ts +2 -0
  3. package/dist/advanced.d.ts.map +1 -0
  4. package/dist/advanced.js +1 -0
  5. package/dist/advancedBarrel.d.ts +19 -0
  6. package/dist/advancedBarrel.d.ts.map +1 -0
  7. package/dist/advancedBarrel.js +1 -0
  8. package/dist/barrel.d.ts +4 -0
  9. package/dist/barrel.d.ts.map +1 -0
  10. package/dist/barrel.js +3 -0
  11. package/dist/btc/index.d.ts +13 -0
  12. package/dist/btc/index.d.ts.map +1 -0
  13. package/dist/btc/index.js +31 -0
  14. package/dist/ckb/index.d.ts +25 -0
  15. package/dist/ckb/index.d.ts.map +1 -0
  16. package/dist/ckb/index.js +65 -0
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +1 -0
  20. package/dist/package.json +3 -0
  21. package/dist/signersFactory.d.ts +3 -0
  22. package/dist/signersFactory.d.ts.map +1 -0
  23. package/dist/signersFactory.js +18 -0
  24. package/dist.commonjs/advanced.d.ts +2 -0
  25. package/dist.commonjs/advanced.d.ts.map +1 -0
  26. package/dist.commonjs/advanced.js +27 -0
  27. package/dist.commonjs/advancedBarrel.d.ts +19 -0
  28. package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
  29. package/dist.commonjs/advancedBarrel.js +2 -0
  30. package/dist.commonjs/barrel.d.ts +4 -0
  31. package/dist.commonjs/barrel.d.ts.map +1 -0
  32. package/dist.commonjs/barrel.js +19 -0
  33. package/dist.commonjs/btc/index.d.ts +13 -0
  34. package/dist.commonjs/btc/index.d.ts.map +1 -0
  35. package/dist.commonjs/btc/index.js +35 -0
  36. package/dist.commonjs/ckb/index.d.ts +25 -0
  37. package/dist.commonjs/ckb/index.d.ts.map +1 -0
  38. package/dist.commonjs/ckb/index.js +69 -0
  39. package/dist.commonjs/index.d.ts +2 -0
  40. package/dist.commonjs/index.d.ts.map +1 -0
  41. package/dist.commonjs/index.js +27 -0
  42. package/dist.commonjs/package.json +3 -0
  43. package/dist.commonjs/signersFactory.d.ts +3 -0
  44. package/dist.commonjs/signersFactory.d.ts.map +1 -0
  45. package/dist.commonjs/signersFactory.js +22 -0
  46. package/misc/basedirs/dist/package.json +3 -0
  47. package/misc/basedirs/dist.commonjs/package.json +3 -0
  48. package/package.json +57 -0
  49. package/src/advanced.ts +1 -0
  50. package/src/advancedBarrel.ts +20 -0
  51. package/src/barrel.ts +3 -0
  52. package/src/btc/index.ts +48 -0
  53. package/src/ckb/index.ts +98 -0
  54. package/src/index.ts +1 -0
  55. package/src/signersFactory.ts +28 -0
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ <p align="center">
2
+ <a href="https://ckbccc-demo.vercel.app/">
3
+ <img alt="Logo" src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/logo.svg" width="20%" />
4
+ </a>
5
+ </p>
6
+
7
+ <h1 align="center" style="font-size: 64px;">
8
+ UTXO Global Wallet for Nervos - A New Horizon for Your Crypto Adventures!
9
+ </h1>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@ckb-ccc/ccc"><img
13
+ alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Fccc"
14
+ /></a>
15
+ <img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-ecofund/ccc" />
16
+ <img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-ecofund/ccc/master" />
17
+ <img alt="GitHub deployments" src="https://img.shields.io/github/deployments/ckb-ecofund/ccc/production" />
18
+ <a href="https://ckbccc-demo.vercel.app/"><img
19
+ alt="Demo" src="https://img.shields.io/website?url=https%3A%2F%2Fckbccc-demo.vercel.app%2F&label=Demo"
20
+ /></a>
21
+ </p>
22
+
23
+ <p align="center">
24
+ "CCC - CKBers' Codebase" is the next step of "Common Chains Connector".
25
+ <br />
26
+ Empower yourself with CCC to discover the unlimited potential of CKB.
27
+ <br />
28
+ Interoperate with wallets from different chain ecosystems.
29
+ <br />
30
+ Fully enabling CKB's Turing completeness and cryptographic freedom power.
31
+ </p>
32
+
33
+ ## Preview
34
+
35
+ <p align="center">
36
+ <a href="https://ckbccc-demo.vercel.app/">
37
+ <img src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/preview.png" width="30%" />
38
+ </a>
39
+ </p>
40
+
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/).
42
+
43
+ <h3 align="center">
44
+ Read more about CCC on its <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
45
+ </h3>
@@ -0,0 +1,2 @@
1
+ export * as UtxoGlobalA from "./advancedBarrel.js";
2
+ //# sourceMappingURL=advanced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1 @@
1
+ export * as UtxoGlobalA from "./advancedBarrel.js";
@@ -0,0 +1,19 @@
1
+ export interface Provider {
2
+ requestAccounts(): Promise<string[]>;
3
+ getAccount(): Promise<string[]>;
4
+ getPublicKey(): Promise<{
5
+ address: string;
6
+ publicKey: string;
7
+ }[]>;
8
+ connect(): Promise<void>;
9
+ isConnected(): Promise<boolean>;
10
+ signMessage(msg: string, address: string): Promise<string>;
11
+ createTx(tx: any): Promise<string>;
12
+ signTransaction(tx: any): Promise<any>;
13
+ on: OnMethod;
14
+ removeListener(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
15
+ }
16
+ export interface OnMethod {
17
+ (eventName: string, listener: (...args: unknown[]) => unknown): Provider;
18
+ }
19
+ //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAChC,YAAY,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,CAAC;IAClE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3D,QAAQ,CAAC,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAEvC,EAAE,EAAE,QAAQ,CAAC;IACb,cAAc,CACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,QAAQ,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,QAAQ,CAAC;CAC1E"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export * from "./btc/index.js";
2
+ export * from "./ckb/index.js";
3
+ export * from "./signersFactory.js";
4
+ //# sourceMappingURL=barrel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
package/dist/barrel.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./btc/index.js";
2
+ export * from "./ckb/index.js";
3
+ export * from "./signersFactory.js";
@@ -0,0 +1,13 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { Provider } from "../advancedBarrel.js";
3
+ export declare class SignerBtc extends ccc.SignerBtc {
4
+ readonly provider: Provider;
5
+ private accountCache;
6
+ constructor(client: ccc.Client, provider: Provider);
7
+ getBtcAccount(): Promise<string>;
8
+ getBtcPublicKey(): Promise<ccc.Hex>;
9
+ connect(): Promise<void>;
10
+ isConnected(): Promise<boolean>;
11
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
12
+ }
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,qBAAa,SAAU,SAAQ,GAAG,CAAC,SAAS;aAKxB,QAAQ,EAAE,QAAQ;IAJpC,OAAO,CAAC,YAAY,CAAqB;gBAGvC,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAK9B,aAAa;IAMb,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAYnC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAQvE"}
@@ -0,0 +1,31 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ export class SignerBtc extends ccc.SignerBtc {
3
+ constructor(client, provider) {
4
+ super(client);
5
+ this.provider = provider;
6
+ }
7
+ async getBtcAccount() {
8
+ const accounts = await this.provider.getAccount();
9
+ this.accountCache = accounts[0];
10
+ return this.accountCache;
11
+ }
12
+ async getBtcPublicKey() {
13
+ const pubKeys = await this.provider.getPublicKey();
14
+ const account = await this.getBtcAccount();
15
+ const pubKey = pubKeys.find((p) => p.address === account);
16
+ if (!pubKey) {
17
+ throw new Error("pubKey not found");
18
+ }
19
+ return ccc.hexFrom(pubKey.publicKey);
20
+ }
21
+ async connect() {
22
+ await this.provider.connect();
23
+ }
24
+ async isConnected() {
25
+ return await this.provider.isConnected();
26
+ }
27
+ async signMessageRaw(message) {
28
+ const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
29
+ return this.provider.signMessage(challenge, this.accountCache ?? (await this.getBtcAccount()));
30
+ }
31
+ }
@@ -0,0 +1,25 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { Provider } from "../advancedBarrel.js";
3
+ export declare class SignerCkb extends ccc.Signer {
4
+ readonly provider: Provider;
5
+ private accountCache;
6
+ get type(): ccc.SignerType;
7
+ /**
8
+ * Gets the sign type.
9
+ * @returns {ccc.SignerSignType} The sign type.
10
+ */
11
+ get signType(): ccc.SignerSignType;
12
+ constructor(client: ccc.Client, provider: Provider);
13
+ getInternalAddress(): Promise<string>;
14
+ getIdentity(): Promise<string>;
15
+ getAddressObj(): Promise<ccc.Address>;
16
+ getAddressObjs(): Promise<ccc.Address[]>;
17
+ getAccount(): Promise<string>;
18
+ getPublicKey(): Promise<ccc.Hex>;
19
+ connect(): Promise<void>;
20
+ isConnected(): Promise<boolean>;
21
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
22
+ signOnlyTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
23
+ prepareTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
24
+ }
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ckb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;aAgBrB,QAAQ,EAAE,QAAQ;IAfpC,OAAO,CAAC,YAAY,CAAqB;IACzC,IAAI,IAAI,IAAI,GAAG,CAAC,UAAU,CAEzB;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,GAAG,CAAC,cAAc,CAEjC;gBAGC,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAKpC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI/B,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IAKrC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAIxC,UAAU;IAMV,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAYhC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAUhE,mBAAmB,CACvB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAKrB,kBAAkB,CACtB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;CAW5B"}
@@ -0,0 +1,65 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ export class SignerCkb extends ccc.Signer {
3
+ get type() {
4
+ return ccc.SignerType.CKB;
5
+ }
6
+ /**
7
+ * Gets the sign type.
8
+ * @returns {ccc.SignerSignType} The sign type.
9
+ */
10
+ get signType() {
11
+ return ccc.SignerSignType.CkbSecp256k1;
12
+ }
13
+ constructor(client, provider) {
14
+ super(client);
15
+ this.provider = provider;
16
+ }
17
+ getInternalAddress() {
18
+ return this.getAccount();
19
+ }
20
+ async getIdentity() {
21
+ return this.getPublicKey();
22
+ }
23
+ async getAddressObj() {
24
+ const address = await this.getInternalAddress();
25
+ return ccc.Address.fromString(address, this.client);
26
+ }
27
+ async getAddressObjs() {
28
+ return [await this.getAddressObj()];
29
+ }
30
+ async getAccount() {
31
+ const accounts = await this.provider.getAccount();
32
+ this.accountCache = accounts[0];
33
+ return this.accountCache;
34
+ }
35
+ async getPublicKey() {
36
+ const pubKeys = await this.provider.getPublicKey();
37
+ const account = await this.getAccount();
38
+ const pubKey = pubKeys.find((p) => p.address === account);
39
+ if (!pubKey) {
40
+ throw new Error("pubKey not found");
41
+ }
42
+ return ccc.hexFrom(pubKey.publicKey);
43
+ }
44
+ async connect() {
45
+ await this.provider.connect();
46
+ }
47
+ async isConnected() {
48
+ return await this.provider.isConnected();
49
+ }
50
+ async signMessageRaw(message) {
51
+ const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
52
+ return this.provider.signMessage(challenge, this.accountCache ?? (await this.getAccount()));
53
+ }
54
+ async signOnlyTransaction(txLike) {
55
+ const txSigned = await this.provider.signTransaction(txLike);
56
+ return ccc.Transaction.from(txSigned);
57
+ }
58
+ async prepareTransaction(txLike) {
59
+ const tx = ccc.Transaction.from(txLike);
60
+ const { script } = await this.getAddressObj();
61
+ await tx.addCellDepsOfKnownScripts(this.client, ccc.KnownScript.Secp256k1Blake160);
62
+ await tx.prepareSighashAllWitness(script, 65, this.client);
63
+ return tx;
64
+ }
65
+ }
@@ -0,0 +1,2 @@
1
+ export * as UtxoGlobal from "./barrel.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * as UtxoGlobal from "./barrel.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,3 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ export declare function getUtxoGlobalSigners(client: ccc.Client): ccc.SignerInfo[];
3
+ //# sourceMappingURL=signersFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAKpC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,UAAU,EAAE,CAsBzE"}
@@ -0,0 +1,18 @@
1
+ import { SignerBtc } from "./btc/index.js";
2
+ import { SignerCkb } from "./ckb/index.js";
3
+ export function getUtxoGlobalSigners(client) {
4
+ const windowRef = window;
5
+ if (typeof windowRef.utxoGlobal === "undefined") {
6
+ return [];
7
+ }
8
+ return [
9
+ {
10
+ name: "CKB",
11
+ signer: new SignerCkb(client, windowRef.utxoGlobal.ckbSigner),
12
+ },
13
+ {
14
+ name: "BTC",
15
+ signer: new SignerBtc(client, windowRef.utxoGlobal.bitcoinSigner),
16
+ },
17
+ ];
18
+ }
@@ -0,0 +1,2 @@
1
+ export * as UtxoGlobalA from "./advancedBarrel.js";
2
+ //# sourceMappingURL=advanced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
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) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.UtxoGlobalA = void 0;
27
+ exports.UtxoGlobalA = __importStar(require("./advancedBarrel.js"));
@@ -0,0 +1,19 @@
1
+ export interface Provider {
2
+ requestAccounts(): Promise<string[]>;
3
+ getAccount(): Promise<string[]>;
4
+ getPublicKey(): Promise<{
5
+ address: string;
6
+ publicKey: string;
7
+ }[]>;
8
+ connect(): Promise<void>;
9
+ isConnected(): Promise<boolean>;
10
+ signMessage(msg: string, address: string): Promise<string>;
11
+ createTx(tx: any): Promise<string>;
12
+ signTransaction(tx: any): Promise<any>;
13
+ on: OnMethod;
14
+ removeListener(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
15
+ }
16
+ export interface OnMethod {
17
+ (eventName: string, listener: (...args: unknown[]) => unknown): Provider;
18
+ }
19
+ //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAChC,YAAY,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,CAAC;IAClE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3D,QAAQ,CAAC,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAEvC,EAAE,EAAE,QAAQ,CAAC;IACb,cAAc,CACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,QAAQ,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,QAAQ,CAAC;CAC1E"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export * from "./btc/index.js";
2
+ export * from "./ckb/index.js";
3
+ export * from "./signersFactory.js";
4
+ //# sourceMappingURL=barrel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./btc/index.js"), exports);
18
+ __exportStar(require("./ckb/index.js"), exports);
19
+ __exportStar(require("./signersFactory.js"), exports);
@@ -0,0 +1,13 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { Provider } from "../advancedBarrel.js";
3
+ export declare class SignerBtc extends ccc.SignerBtc {
4
+ readonly provider: Provider;
5
+ private accountCache;
6
+ constructor(client: ccc.Client, provider: Provider);
7
+ getBtcAccount(): Promise<string>;
8
+ getBtcPublicKey(): Promise<ccc.Hex>;
9
+ connect(): Promise<void>;
10
+ isConnected(): Promise<boolean>;
11
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
12
+ }
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,qBAAa,SAAU,SAAQ,GAAG,CAAC,SAAS;aAKxB,QAAQ,EAAE,QAAQ;IAJpC,OAAO,CAAC,YAAY,CAAqB;gBAGvC,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAK9B,aAAa;IAMb,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAYnC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAQvE"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignerBtc = void 0;
4
+ const core_1 = require("@ckb-ccc/core");
5
+ class SignerBtc extends core_1.ccc.SignerBtc {
6
+ constructor(client, provider) {
7
+ super(client);
8
+ this.provider = provider;
9
+ }
10
+ async getBtcAccount() {
11
+ const accounts = await this.provider.getAccount();
12
+ this.accountCache = accounts[0];
13
+ return this.accountCache;
14
+ }
15
+ async getBtcPublicKey() {
16
+ const pubKeys = await this.provider.getPublicKey();
17
+ const account = await this.getBtcAccount();
18
+ const pubKey = pubKeys.find((p) => p.address === account);
19
+ if (!pubKey) {
20
+ throw new Error("pubKey not found");
21
+ }
22
+ return core_1.ccc.hexFrom(pubKey.publicKey);
23
+ }
24
+ async connect() {
25
+ await this.provider.connect();
26
+ }
27
+ async isConnected() {
28
+ return await this.provider.isConnected();
29
+ }
30
+ async signMessageRaw(message) {
31
+ const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
32
+ return this.provider.signMessage(challenge, this.accountCache ?? (await this.getBtcAccount()));
33
+ }
34
+ }
35
+ exports.SignerBtc = SignerBtc;
@@ -0,0 +1,25 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { Provider } from "../advancedBarrel.js";
3
+ export declare class SignerCkb extends ccc.Signer {
4
+ readonly provider: Provider;
5
+ private accountCache;
6
+ get type(): ccc.SignerType;
7
+ /**
8
+ * Gets the sign type.
9
+ * @returns {ccc.SignerSignType} The sign type.
10
+ */
11
+ get signType(): ccc.SignerSignType;
12
+ constructor(client: ccc.Client, provider: Provider);
13
+ getInternalAddress(): Promise<string>;
14
+ getIdentity(): Promise<string>;
15
+ getAddressObj(): Promise<ccc.Address>;
16
+ getAddressObjs(): Promise<ccc.Address[]>;
17
+ getAccount(): Promise<string>;
18
+ getPublicKey(): Promise<ccc.Hex>;
19
+ connect(): Promise<void>;
20
+ isConnected(): Promise<boolean>;
21
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
22
+ signOnlyTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
23
+ prepareTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
24
+ }
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ckb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;aAgBrB,QAAQ,EAAE,QAAQ;IAfpC,OAAO,CAAC,YAAY,CAAqB;IACzC,IAAI,IAAI,IAAI,GAAG,CAAC,UAAU,CAEzB;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,GAAG,CAAC,cAAc,CAEjC;gBAGC,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAKpC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI/B,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IAKrC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAIxC,UAAU;IAMV,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAYhC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAUhE,mBAAmB,CACvB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAKrB,kBAAkB,CACtB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;CAW5B"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignerCkb = void 0;
4
+ const core_1 = require("@ckb-ccc/core");
5
+ class SignerCkb extends core_1.ccc.Signer {
6
+ get type() {
7
+ return core_1.ccc.SignerType.CKB;
8
+ }
9
+ /**
10
+ * Gets the sign type.
11
+ * @returns {ccc.SignerSignType} The sign type.
12
+ */
13
+ get signType() {
14
+ return core_1.ccc.SignerSignType.CkbSecp256k1;
15
+ }
16
+ constructor(client, provider) {
17
+ super(client);
18
+ this.provider = provider;
19
+ }
20
+ getInternalAddress() {
21
+ return this.getAccount();
22
+ }
23
+ async getIdentity() {
24
+ return this.getPublicKey();
25
+ }
26
+ async getAddressObj() {
27
+ const address = await this.getInternalAddress();
28
+ return core_1.ccc.Address.fromString(address, this.client);
29
+ }
30
+ async getAddressObjs() {
31
+ return [await this.getAddressObj()];
32
+ }
33
+ async getAccount() {
34
+ const accounts = await this.provider.getAccount();
35
+ this.accountCache = accounts[0];
36
+ return this.accountCache;
37
+ }
38
+ async getPublicKey() {
39
+ const pubKeys = await this.provider.getPublicKey();
40
+ const account = await this.getAccount();
41
+ const pubKey = pubKeys.find((p) => p.address === account);
42
+ if (!pubKey) {
43
+ throw new Error("pubKey not found");
44
+ }
45
+ return core_1.ccc.hexFrom(pubKey.publicKey);
46
+ }
47
+ async connect() {
48
+ await this.provider.connect();
49
+ }
50
+ async isConnected() {
51
+ return await this.provider.isConnected();
52
+ }
53
+ async signMessageRaw(message) {
54
+ const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
55
+ return this.provider.signMessage(challenge, this.accountCache ?? (await this.getAccount()));
56
+ }
57
+ async signOnlyTransaction(txLike) {
58
+ const txSigned = await this.provider.signTransaction(txLike);
59
+ return core_1.ccc.Transaction.from(txSigned);
60
+ }
61
+ async prepareTransaction(txLike) {
62
+ const tx = core_1.ccc.Transaction.from(txLike);
63
+ const { script } = await this.getAddressObj();
64
+ await tx.addCellDepsOfKnownScripts(this.client, core_1.ccc.KnownScript.Secp256k1Blake160);
65
+ await tx.prepareSighashAllWitness(script, 65, this.client);
66
+ return tx;
67
+ }
68
+ }
69
+ exports.SignerCkb = SignerCkb;
@@ -0,0 +1,2 @@
1
+ export * as UtxoGlobal from "./barrel.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
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) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.UtxoGlobal = void 0;
27
+ exports.UtxoGlobal = __importStar(require("./barrel.js"));
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,3 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ export declare function getUtxoGlobalSigners(client: ccc.Client): ccc.SignerInfo[];
3
+ //# sourceMappingURL=signersFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAKpC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,UAAU,EAAE,CAsBzE"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUtxoGlobalSigners = void 0;
4
+ const index_js_1 = require("./btc/index.js");
5
+ const index_js_2 = require("./ckb/index.js");
6
+ function getUtxoGlobalSigners(client) {
7
+ const windowRef = window;
8
+ if (typeof windowRef.utxoGlobal === "undefined") {
9
+ return [];
10
+ }
11
+ return [
12
+ {
13
+ name: "CKB",
14
+ signer: new index_js_2.SignerCkb(client, windowRef.utxoGlobal.ckbSigner),
15
+ },
16
+ {
17
+ name: "BTC",
18
+ signer: new index_js_1.SignerBtc(client, windowRef.utxoGlobal.bitcoinSigner),
19
+ },
20
+ ];
21
+ }
22
+ exports.getUtxoGlobalSigners = getUtxoGlobalSigners;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@ckb-ccc/utxo-global",
3
+ "version": "0.0.11-alpha.0",
4
+ "description": "Common Chains Connector's support for UTXO Global",
5
+ "author": "Trong Dinh <trong@nexm.io>",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "homepage": "https://github.com/ckb-ecofund/ccc",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git://github.com/ckb-ecofund/ccc.git"
12
+ },
13
+ "main": "dist.commonjs/index.js",
14
+ "module": "dist/index.js",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "default": "./dist.commonjs/index.js"
19
+ },
20
+ "./barrel": {
21
+ "import": "./dist/barrel.js",
22
+ "default": "./dist.commonjs/barrel.js"
23
+ },
24
+ "./advancedBarrel": {
25
+ "import": "./dist/advancedBarrel.js",
26
+ "default": "./dist.commonjs/advancedBarrel.js"
27
+ },
28
+ "./advanced": {
29
+ "import": "./dist/advanced.js",
30
+ "default": "./dist.commonjs/advanced.js"
31
+ }
32
+ },
33
+ "scripts": {
34
+ "build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
35
+ "lint": "eslint",
36
+ "format": "prettier --write . && eslint --fix"
37
+ },
38
+ "devDependencies": {
39
+ "@eslint/js": "^9.1.1",
40
+ "copyfiles": "^2.4.1",
41
+ "eslint": "^9.1.0",
42
+ "eslint-config-prettier": "^9.1.0",
43
+ "eslint-plugin-prettier": "^5.1.3",
44
+ "prettier": "^3.2.5",
45
+ "prettier-plugin-organize-imports": "^3.2.4",
46
+ "rimraf": "^5.0.5",
47
+ "typescript": "^5.4.5",
48
+ "typescript-eslint": "^7.7.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "dependencies": {
54
+ "@ckb-ccc/core": "0.0.11-alpha.0"
55
+ },
56
+ "gitHead": "1daf9e21ef56b6a5aa40136aae0e22f8921d5316"
57
+ }
@@ -0,0 +1 @@
1
+ export * as UtxoGlobalA from "./advancedBarrel.js";
@@ -0,0 +1,20 @@
1
+ export interface Provider {
2
+ requestAccounts(): Promise<string[]>;
3
+ getAccount(): Promise<string[]>;
4
+ getPublicKey(): Promise<{ address: string; publicKey: string }[]>;
5
+ connect(): Promise<void>;
6
+ isConnected(): Promise<boolean>;
7
+ signMessage(msg: string, address: string): Promise<string>;
8
+ createTx(tx: any): Promise<string>;
9
+ signTransaction(tx: any): Promise<any>;
10
+
11
+ on: OnMethod;
12
+ removeListener(
13
+ eventName: string,
14
+ listener: (...args: unknown[]) => unknown,
15
+ ): Provider;
16
+ }
17
+
18
+ export interface OnMethod {
19
+ (eventName: string, listener: (...args: unknown[]) => unknown): Provider;
20
+ }
package/src/barrel.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./btc/index.js";
2
+ export * from "./ckb/index.js";
3
+ export * from "./signersFactory.js";
@@ -0,0 +1,48 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { Provider } from "../advancedBarrel.js";
3
+
4
+ export class SignerBtc extends ccc.SignerBtc {
5
+ private accountCache: string | undefined;
6
+
7
+ constructor(
8
+ client: ccc.Client,
9
+ public readonly provider: Provider,
10
+ ) {
11
+ super(client);
12
+ }
13
+
14
+ async getBtcAccount() {
15
+ const accounts = await this.provider.getAccount();
16
+ this.accountCache = accounts[0];
17
+ return this.accountCache;
18
+ }
19
+
20
+ async getBtcPublicKey(): Promise<ccc.Hex> {
21
+ const pubKeys = await this.provider.getPublicKey();
22
+ const account = await this.getBtcAccount();
23
+ const pubKey = pubKeys.find((p) => p.address === account);
24
+
25
+ if (!pubKey) {
26
+ throw new Error("pubKey not found");
27
+ }
28
+
29
+ return ccc.hexFrom(pubKey.publicKey);
30
+ }
31
+
32
+ async connect(): Promise<void> {
33
+ await this.provider.connect();
34
+ }
35
+
36
+ async isConnected(): Promise<boolean> {
37
+ return await this.provider.isConnected();
38
+ }
39
+
40
+ async signMessageRaw(message: string | ccc.BytesLike): Promise<string> {
41
+ const challenge =
42
+ typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
43
+ return this.provider.signMessage(
44
+ challenge,
45
+ this.accountCache ?? (await this.getBtcAccount()),
46
+ );
47
+ }
48
+ }
@@ -0,0 +1,98 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { Provider } from "../advancedBarrel.js";
3
+
4
+ export class SignerCkb extends ccc.Signer {
5
+ private accountCache: string | undefined;
6
+ get type(): ccc.SignerType {
7
+ return ccc.SignerType.CKB;
8
+ }
9
+
10
+ /**
11
+ * Gets the sign type.
12
+ * @returns {ccc.SignerSignType} The sign type.
13
+ */
14
+ get signType(): ccc.SignerSignType {
15
+ return ccc.SignerSignType.CkbSecp256k1;
16
+ }
17
+
18
+ constructor(
19
+ client: ccc.Client,
20
+ public readonly provider: Provider,
21
+ ) {
22
+ super(client);
23
+ }
24
+
25
+ getInternalAddress(): Promise<string> {
26
+ return this.getAccount();
27
+ }
28
+
29
+ async getIdentity(): Promise<string> {
30
+ return this.getPublicKey();
31
+ }
32
+
33
+ async getAddressObj(): Promise<ccc.Address> {
34
+ const address = await this.getInternalAddress();
35
+ return ccc.Address.fromString(address, this.client);
36
+ }
37
+
38
+ async getAddressObjs(): Promise<ccc.Address[]> {
39
+ return [await this.getAddressObj()];
40
+ }
41
+
42
+ async getAccount() {
43
+ const accounts = await this.provider.getAccount();
44
+ this.accountCache = accounts[0];
45
+ return this.accountCache;
46
+ }
47
+
48
+ async getPublicKey(): Promise<ccc.Hex> {
49
+ const pubKeys = await this.provider.getPublicKey();
50
+ const account = await this.getAccount();
51
+ const pubKey = pubKeys.find((p) => p.address === account);
52
+
53
+ if (!pubKey) {
54
+ throw new Error("pubKey not found");
55
+ }
56
+
57
+ return ccc.hexFrom(pubKey.publicKey);
58
+ }
59
+
60
+ async connect(): Promise<void> {
61
+ await this.provider.connect();
62
+ }
63
+
64
+ async isConnected(): Promise<boolean> {
65
+ return await this.provider.isConnected();
66
+ }
67
+
68
+ async signMessageRaw(message: string | ccc.BytesLike): Promise<string> {
69
+ const challenge =
70
+ typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
71
+
72
+ return this.provider.signMessage(
73
+ challenge,
74
+ this.accountCache ?? (await this.getAccount()),
75
+ );
76
+ }
77
+
78
+ async signOnlyTransaction(
79
+ txLike: ccc.TransactionLike,
80
+ ): Promise<ccc.Transaction> {
81
+ const txSigned = await this.provider.signTransaction(txLike);
82
+ return ccc.Transaction.from(txSigned);
83
+ }
84
+
85
+ async prepareTransaction(
86
+ txLike: ccc.TransactionLike,
87
+ ): Promise<ccc.Transaction> {
88
+ const tx = ccc.Transaction.from(txLike);
89
+ const { script } = await this.getAddressObj();
90
+
91
+ await tx.addCellDepsOfKnownScripts(
92
+ this.client,
93
+ ccc.KnownScript.Secp256k1Blake160,
94
+ );
95
+ await tx.prepareSighashAllWitness(script, 65, this.client);
96
+ return tx;
97
+ }
98
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * as UtxoGlobal from "./barrel.js";
@@ -0,0 +1,28 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { Provider } from "./advancedBarrel.js";
3
+ import { SignerBtc } from "./btc/index.js";
4
+ import { SignerCkb } from "./ckb/index.js";
5
+
6
+ export function getUtxoGlobalSigners(client: ccc.Client): ccc.SignerInfo[] {
7
+ const windowRef = window as {
8
+ utxoGlobal?: {
9
+ bitcoinSigner: Provider;
10
+ ckbSigner: Provider;
11
+ };
12
+ };
13
+
14
+ if (typeof windowRef.utxoGlobal === "undefined") {
15
+ return [];
16
+ }
17
+
18
+ return [
19
+ {
20
+ name: "CKB",
21
+ signer: new SignerCkb(client, windowRef.utxoGlobal.ckbSigner),
22
+ },
23
+ {
24
+ name: "BTC",
25
+ signer: new SignerBtc(client, windowRef.utxoGlobal.bitcoinSigner),
26
+ },
27
+ ];
28
+ }