@ckb-ccc/uni-sat 1.0.33 → 1.1.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/CHANGELOG.md +13 -0
- package/dist/advanced.d.mts +2 -0
- package/dist/advanced.mjs +1 -0
- package/dist/advancedBarrel-6fyDO_pc.d.mts +100 -0
- package/dist/advancedBarrel-6fyDO_pc.d.mts.map +1 -0
- package/dist/advancedBarrel.d.mts +2 -0
- package/dist/advancedBarrel.mjs +2 -0
- package/dist/advancedBarrel.mjs.map +1 -0
- package/dist/barrel.d.mts +81 -0
- package/dist/barrel.d.mts.map +1 -0
- package/dist/barrel.mjs +2 -0
- package/dist/barrel.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/rolldown-runtime-DK3Fl9T5.mjs +1 -0
- package/dist.commonjs/advanced.d.ts +2 -2
- package/dist.commonjs/advanced.js +1 -37
- package/dist.commonjs/advancedBarrel-C8SL2uu7.d.ts +100 -0
- package/dist.commonjs/advancedBarrel-C8SL2uu7.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.d.ts +2 -93
- package/dist.commonjs/advancedBarrel.js +2 -2
- package/dist.commonjs/advancedBarrel.js.map +1 -0
- package/dist.commonjs/barrel.d.ts +80 -2
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +2 -18
- package/dist.commonjs/barrel.js.map +1 -0
- package/dist.commonjs/index.d.ts +2 -2
- package/dist.commonjs/index.js +1 -37
- package/dist.commonjs/rolldown-runtime-BIInC43l.js +1 -0
- package/package.json +26 -29
- package/tsdown.config.mts +43 -0
- package/dist/advanced.d.ts +0 -2
- package/dist/advanced.d.ts.map +0 -1
- package/dist/advanced.js +0 -1
- package/dist/advancedBarrel.d.ts +0 -93
- package/dist/advancedBarrel.d.ts.map +0 -1
- package/dist/advancedBarrel.js +0 -1
- package/dist/barrel.d.ts +0 -3
- package/dist/barrel.d.ts.map +0 -1
- package/dist/barrel.js +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -1
- package/dist/signer.d.ts +0 -64
- package/dist/signer.d.ts.map +0 -1
- package/dist/signer.js +0 -147
- package/dist/signersFactory.d.ts +0 -10
- package/dist/signersFactory.d.ts.map +0 -1
- package/dist/signersFactory.js +0 -20
- package/dist.commonjs/advanced.d.ts.map +0 -1
- package/dist.commonjs/advancedBarrel.d.ts.map +0 -1
- package/dist.commonjs/index.d.ts.map +0 -1
- package/dist.commonjs/signer.d.ts +0 -64
- package/dist.commonjs/signer.d.ts.map +0 -1
- package/dist.commonjs/signer.js +0 -151
- package/dist.commonjs/signersFactory.d.ts +0 -10
- package/dist.commonjs/signersFactory.d.ts.map +0 -1
- package/dist.commonjs/signersFactory.js +0 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ckb-ccc/uni-sat
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
### Minor Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#381](https://github.com/ckb-devrel/ccc/pull/381) [`46cc045`](https://github.com/ckb-devrel/ccc/commit/46cc045a3eefe9ba6625482dc7f740a0c59c99d4) Thanks [@Hanssen0](https://github.com/Hanssen0)! - chore: bump packages
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`46cc045`](https://github.com/ckb-devrel/ccc/commit/46cc045a3eefe9ba6625482dc7f740a0c59c99d4)]:
|
|
14
|
+
- @ckb-ccc/core@1.14.0
|
|
15
|
+
|
|
3
16
|
## 1.0.33
|
|
4
17
|
### Patch Changes
|
|
5
18
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./advancedBarrel.mjs";export{e as UniSatA};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
|
|
3
|
+
//#region src/advancedBarrel.d.ts
|
|
4
|
+
declare namespace advancedBarrel_d_exports {
|
|
5
|
+
export { OnMethod, Provider };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Interface representing a provider for interacting with accounts and signing messages.
|
|
9
|
+
*/
|
|
10
|
+
interface Provider {
|
|
11
|
+
/**
|
|
12
|
+
* Signs a PSBT using UniSat wallet.
|
|
13
|
+
*
|
|
14
|
+
* @param psbtHex - The hex string of PSBT to sign
|
|
15
|
+
* @param options - Options for signing the PSBT
|
|
16
|
+
* @returns A promise that resolves to the signed PSBT hex string
|
|
17
|
+
*/
|
|
18
|
+
signPsbt(psbtHex: string, options?: ccc.SignPsbtOptionsLike): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Broadcasts a signed PSBT to the Bitcoin network.
|
|
21
|
+
*
|
|
22
|
+
* @param psbtHex - The hex string of the signed PSBT to broadcast.
|
|
23
|
+
* @returns A promise that resolves to the transaction ID.
|
|
24
|
+
*/
|
|
25
|
+
pushPsbt(psbtHex: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Requests user accounts.
|
|
28
|
+
* @returns A promise that resolves to an array of account addresses.
|
|
29
|
+
*/
|
|
30
|
+
requestAccounts(): Promise<string[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the current network.
|
|
33
|
+
* @returns current network.
|
|
34
|
+
*/
|
|
35
|
+
getNetwork(): Promise<"livenet" | "testnet">;
|
|
36
|
+
/**
|
|
37
|
+
* Switch the current network.
|
|
38
|
+
*/
|
|
39
|
+
switchNetwork(chain: "livenet" | "testnet"): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the current chain.
|
|
42
|
+
* @returns current chain.
|
|
43
|
+
*/
|
|
44
|
+
getChain?(): Promise<{
|
|
45
|
+
enum: string;
|
|
46
|
+
name: string;
|
|
47
|
+
network: string;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Switch the current chain.
|
|
51
|
+
*/
|
|
52
|
+
switchChain?(chain: string): Promise<{
|
|
53
|
+
enum: string;
|
|
54
|
+
name: string;
|
|
55
|
+
network: string;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the current accounts.
|
|
59
|
+
* @returns A promise that resolves to an array of account addresses.
|
|
60
|
+
*/
|
|
61
|
+
getAccounts(): Promise<string[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the public key of the account.
|
|
64
|
+
* @returns A promise that resolves to the public key.
|
|
65
|
+
*/
|
|
66
|
+
getPublicKey(): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Signs a message with the specified type.
|
|
69
|
+
* @param msg - The message to sign.
|
|
70
|
+
* @param type - The type of signature.
|
|
71
|
+
* @returns A promise that resolves to the signed message.
|
|
72
|
+
*/
|
|
73
|
+
signMessage(msg: string, type: "ecdsa" | "bip322-simple"): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Adds an event listener to the provider.
|
|
76
|
+
*/
|
|
77
|
+
on: OnMethod;
|
|
78
|
+
/**
|
|
79
|
+
* Removes an event listener from the provider.
|
|
80
|
+
* @param eventName - The name of the event to remove the listener from.
|
|
81
|
+
* @param listener - The listener function to remove.
|
|
82
|
+
* @returns The provider instance.
|
|
83
|
+
*/
|
|
84
|
+
removeListener(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Interface representing a method to add event listeners to the provider.
|
|
88
|
+
*/
|
|
89
|
+
interface OnMethod {
|
|
90
|
+
/**
|
|
91
|
+
* Adds an event listener to the provider.
|
|
92
|
+
* @param eventName - The name of the event.
|
|
93
|
+
* @param listener - The listener function.
|
|
94
|
+
* @returns The provider instance.
|
|
95
|
+
*/
|
|
96
|
+
(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
export { Provider as n, advancedBarrel_d_exports as r, OnMethod as t };
|
|
100
|
+
//# sourceMappingURL=advancedBarrel-6fyDO_pc.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel-6fyDO_pc.d.mts","names":[],"sources":["../src/advancedBarrel.ts"],"mappings":";;;;;;;;;UAKiB,QAAA;;;;AAAjB;;;;EAQE,QAAA,CAAS,OAAA,UAAiB,OAAA,GAAU,GAAA,CAAI,mBAAA,GAAsB,OAAA;EAQnC;;;;;;EAA3B,QAAA,CAAS,OAAA,WAAkB,OAAA;EA0CX;;;;EApChB,eAAA,IAAmB,OAAA;EA4DR;;;;EAtDX,UAAA,IAAc,OAAA;EApBY;;;EAyB1B,aAAA,CAAc,KAAA,0BAA+B,OAAA;EAjBlB;;;;EAuB3B,QAAA,KAAa,OAAA;IAAU,IAAA;IAAc,IAAA;IAAc,OAAA;EAAA;EAAtC;;;EAKb,WAAA,EACE,KAAA,WACC,OAAA;IAAU,IAAA;IAAc,IAAA;IAAc,OAAA;EAAA;EAAd;;;;EAM3B,WAAA,IAAe,OAAA;EAMC;;;;EAAhB,YAAA,IAAgB,OAAA;EAahB;;;;;;EALA,WAAA,CAAY,GAAA,UAAa,IAAA,8BAAkC,OAAA;EAgBhD;AAAA;AAMb;EAjBE,EAAA,EAAI,QAAA;;;;;;;EAQJ,cAAA,CACE,SAAA,UACA,QAAA,MAAc,IAAA,0BACb,QAAA;AAAA;;;;UAMY,QAAA;;;;;;;GAOd,SAAA,UAAmB,QAAA,MAAc,IAAA,0BAA8B,QAAQ;AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel.mjs","names":[],"sources":["../src/advancedBarrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\n\n/**\n * Interface representing a provider for interacting with accounts and signing messages.\n */\nexport interface Provider {\n /**\n * Signs a PSBT using UniSat wallet.\n *\n * @param psbtHex - The hex string of PSBT to sign\n * @param options - Options for signing the PSBT\n * @returns A promise that resolves to the signed PSBT hex string\n */\n signPsbt(psbtHex: string, options?: ccc.SignPsbtOptionsLike): Promise<string>;\n\n /**\n * Broadcasts a signed PSBT to the Bitcoin network.\n *\n * @param psbtHex - The hex string of the signed PSBT to broadcast.\n * @returns A promise that resolves to the transaction ID.\n */\n pushPsbt(psbtHex: string): Promise<string>;\n\n /**\n * Requests user accounts.\n * @returns A promise that resolves to an array of account addresses.\n */\n requestAccounts(): Promise<string[]>;\n\n /**\n * Gets the current network.\n * @returns current network.\n */\n getNetwork(): Promise<\"livenet\" | \"testnet\">;\n\n /**\n * Switch the current network.\n */\n switchNetwork(chain: \"livenet\" | \"testnet\"): Promise<void>;\n\n /**\n * Gets the current chain.\n * @returns current chain.\n */\n getChain?(): Promise<{ enum: string; name: string; network: string }>;\n\n /**\n * Switch the current chain.\n */\n switchChain?(\n chain: string,\n ): Promise<{ enum: string; name: string; network: string }>;\n\n /**\n * Gets the current accounts.\n * @returns A promise that resolves to an array of account addresses.\n */\n getAccounts(): Promise<string[]>;\n\n /**\n * Gets the public key of the account.\n * @returns A promise that resolves to the public key.\n */\n getPublicKey(): Promise<string>;\n\n /**\n * Signs a message with the specified type.\n * @param msg - The message to sign.\n * @param type - The type of signature.\n * @returns A promise that resolves to the signed message.\n */\n signMessage(msg: string, type: \"ecdsa\" | \"bip322-simple\"): Promise<string>;\n\n /**\n * Adds an event listener to the provider.\n */\n on: OnMethod;\n\n /**\n * Removes an event listener from the provider.\n * @param eventName - The name of the event to remove the listener from.\n * @param listener - The listener function to remove.\n * @returns The provider instance.\n */\n removeListener(\n eventName: string,\n listener: (...args: unknown[]) => unknown,\n ): Provider;\n}\n\n/**\n * Interface representing a method to add event listeners to the provider.\n */\nexport interface OnMethod {\n /**\n * Adds an event listener to the provider.\n * @param eventName - The name of the event.\n * @param listener - The listener function.\n * @returns The provider instance.\n */\n (eventName: string, listener: (...args: unknown[]) => unknown): Provider;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { n as Provider } from "./advancedBarrel-6fyDO_pc.mjs";
|
|
2
|
+
import { ccc } from "@ckb-ccc/core";
|
|
3
|
+
|
|
4
|
+
//#region src/signer.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a Bitcoin signer that extends SignerBtc
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
declare class Signer extends ccc.SignerBtc {
|
|
10
|
+
readonly provider: Provider;
|
|
11
|
+
private readonly preferredNetworks;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of Signer.
|
|
14
|
+
* @param client - The client instance.
|
|
15
|
+
* @param provider - The provider instance.
|
|
16
|
+
*/
|
|
17
|
+
constructor(client: ccc.Client, provider: Provider, preferredNetworks?: ccc.NetworkPreference[]);
|
|
18
|
+
_getNetworkToChange(): Promise<string | undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* Ensure the BTC network is the same as CKB network.
|
|
21
|
+
*/
|
|
22
|
+
ensureNetwork(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the Bitcoin account address.
|
|
25
|
+
* @returns A promise that resolves to the Bitcoin account address.
|
|
26
|
+
*/
|
|
27
|
+
getBtcAccount(): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the Bitcoin public key.
|
|
30
|
+
* @returns A promise that resolves to the Bitcoin public key.
|
|
31
|
+
*/
|
|
32
|
+
getBtcPublicKey(): Promise<ccc.Hex>;
|
|
33
|
+
/**
|
|
34
|
+
* Connects to the provider by requesting accounts.
|
|
35
|
+
* @returns A promise that resolves when the connection is established.
|
|
36
|
+
*/
|
|
37
|
+
connect(): Promise<void>;
|
|
38
|
+
onReplaced(listener: () => void): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if the signer is connected.
|
|
41
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
42
|
+
*/
|
|
43
|
+
isConnected(): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Signs a raw message with the Bitcoin account.
|
|
46
|
+
* @param message - The message to sign.
|
|
47
|
+
* @returns A promise that resolves to the signed message.
|
|
48
|
+
*/
|
|
49
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Signs a PSBT using UniSat wallet.
|
|
52
|
+
*
|
|
53
|
+
* @param psbtHex - The hex string of PSBT to sign.
|
|
54
|
+
* @param options - Options for signing the PSBT
|
|
55
|
+
* @returns A promise that resolves to the signed PSBT as a Hex string
|
|
56
|
+
*/
|
|
57
|
+
signPsbt(psbtHex: ccc.HexLike, options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
|
|
58
|
+
/**
|
|
59
|
+
* Broadcasts a signed PSBT to the Bitcoin network.
|
|
60
|
+
*
|
|
61
|
+
* @param psbtHex - The hex string of signed PSBT to broadcast.
|
|
62
|
+
* @returns A promise that resolves to the transaction ID as a Hex string
|
|
63
|
+
*/
|
|
64
|
+
broadcastPsbt(psbtHex: ccc.HexLike, _options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/signersFactory.d.ts
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves the UniSat signer if available.
|
|
70
|
+
* @public
|
|
71
|
+
*
|
|
72
|
+
* @param client - The client instance.
|
|
73
|
+
* @returns The Signer instance if the UniSat provider is available, otherwise undefined.
|
|
74
|
+
*/
|
|
75
|
+
declare function getUniSatSigners(client: ccc.Client, preferredNetworks?: ccc.NetworkPreference[]): ccc.SignerInfo[];
|
|
76
|
+
declare namespace barrel_d_exports {
|
|
77
|
+
export { Signer, getUniSatSigners };
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { Signer, getUniSatSigners, barrel_d_exports as t };
|
|
81
|
+
//# sourceMappingURL=barrel.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.d.mts","names":[],"sources":["../src/signer.ts","../src/signersFactory.ts","../src/barrel.ts"],"mappings":";;;;;;;AAOA;cAAa,MAAA,SAAe,GAAA,CAAI,SAAA;EAAA,SAQZ,QAAA,EAAU,QAAA;EAAA,iBACT,iBAAA;EAFT;;;;;cAAR,MAAA,EAAQ,GAAA,CAAI,MAAA,EACI,QAAA,EAAU,QAAA,EACT,iBAAA,GAAmB,GAAA,CAAI,iBAAA;EAgBpC,mBAAA,IAAuB,OAAA;EAoEJ;;;EAvCnB,aAAA,IAAiB,OAAA;EAqFgC;;;;EAtDjD,aAAA,IAAiB,OAAA;EAoFZ;;;;EA5EL,eAAA,IAAmB,OAAA,CAAQ,GAAA,CAAI,GAAA;EA7FE;;;;EAqGjC,OAAA,IAAW,OAAA;EAKjB,UAAA,CAAW,QAAA;EAjGQ;;;;EAsHb,WAAA,IAAe,OAAA;EAvHO;;;;;EAmItB,cAAA,CAAe,OAAA,WAAkB,GAAA,CAAI,SAAA,GAAY,OAAA;EAlH1B;;;;;;;EAgIvB,QAAA,CACJ,OAAA,EAAS,GAAA,CAAI,OAAA,EACb,OAAA,GAAU,GAAA,CAAI,mBAAA,GACb,OAAA,CAAQ,GAAA,CAAI,GAAA;EA/DsB;;;;;;EA2E/B,aAAA,CACJ,OAAA,EAAS,GAAA,CAAI,OAAA,EACb,QAAA,GAAW,GAAA,CAAI,mBAAA,GACd,OAAA,CAAQ,GAAA,CAAI,GAAA;AAAA;;;;;;;AA3KjB;;;iBCIgB,gBAAA,CACd,MAAA,EAAQ,GAAA,CAAI,MAAA,EACZ,iBAAA,GAAoB,GAAA,CAAI,iBAAA,KACvB,GAAA,CAAI,UAAA;AAAA"}
|
package/dist/barrel.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.mjs";import{ccc as t}from"@ckb-ccc/core";var n=class extends t.SignerBtc{constructor(e,n,r=[{addressPrefix:`ckb`,signerType:t.SignerType.BTC,network:`btc`},{addressPrefix:`ckt`,signerType:t.SignerType.BTC,network:`btcTestnet`}]){super(e),this.provider=n,this.preferredNetworks=r}async _getNetworkToChange(){let e=await(async()=>this.provider.getChain?{BITCOIN_MAINNET:`btc`,BITCOIN_TESTNET:`btcTestnet`,FRACTAL_BITCOIN_MAINNET:`fractalBtc`}[(await this.provider.getChain()).enum]??``:await this.provider.getNetwork()===`livenet`?`btc`:`btcTestnet`)(),{network:t}=this.matchNetworkPreference(this.preferredNetworks,e)??{network:e};if(t!==e)return t}async ensureNetwork(){let e=await this._getNetworkToChange();if(e){if(this.provider.switchChain){let t={btc:`BITCOIN_MAINNET`,btcTestnet:`BITCOIN_TESTNET`,fractalBtc:`FRACTAL_BITCOIN_MAINNET`}[e];if(t){await this.provider.switchChain(t);return}}else if(e===`btc`||e===`btcTestnet`){await this.provider.switchNetwork(e===`btc`?`livenet`:`testnet`);return}throw Error(`UniSat wallet doesn't support the requested chain ${e}`)}}async getBtcAccount(){return(await this.provider.getAccounts())[0]}async getBtcPublicKey(){return t.hexFrom(await this.provider.getPublicKey())}async connect(){await this.provider.requestAccounts(),await this.ensureNetwork()}onReplaced(e){let t=[],n=async()=>{e(),t[0]?.()};return t.push(()=>{this.provider.removeListener(`accountsChanged`,n),this.provider.removeListener(`networkChanged`,n)}),this.provider.on(`accountsChanged`,n),this.provider.on(`networkChanged`,n),t[0]}async isConnected(){return await this._getNetworkToChange()?!1:(await this.provider.getAccounts()).length!==0}async signMessageRaw(e){let n=typeof e==`string`?e:t.hexFrom(e).slice(2);return this.provider.signMessage(n,`ecdsa`)}async signPsbt(e,n){return t.hexFrom(await this.provider.signPsbt(t.hexFrom(e).slice(2),n))}async broadcastPsbt(e,n){let r=await this.provider.pushPsbt(t.hexFrom(e).slice(2));return t.hexFrom(r)}};function r(e,t){let r=window;return r.unisat===void 0?[]:[{signer:new n(e,r.unisat,t),name:`BTC`}]}var i=e({Signer:()=>n,getUniSatSigners:()=>r});export{n as Signer,r as getUniSatSigners,i as t};
|
|
2
|
+
//# sourceMappingURL=barrel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.mjs","names":[],"sources":["../src/signer.ts","../src/signersFactory.ts","../src/barrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\nimport { Provider } from \"./advancedBarrel.js\";\n\n/**\n * Class representing a Bitcoin signer that extends SignerBtc\n * @public\n */\nexport class Signer extends ccc.SignerBtc {\n /**\n * Creates an instance of Signer.\n * @param client - The client instance.\n * @param provider - The provider instance.\n */\n constructor(\n client: ccc.Client,\n public readonly provider: Provider,\n private readonly preferredNetworks: ccc.NetworkPreference[] = [\n {\n addressPrefix: \"ckb\",\n signerType: ccc.SignerType.BTC,\n network: \"btc\",\n },\n {\n addressPrefix: \"ckt\",\n signerType: ccc.SignerType.BTC,\n network: \"btcTestnet\",\n },\n ],\n ) {\n super(client);\n }\n\n async _getNetworkToChange(): Promise<string | undefined> {\n const currentNetwork = await (async () => {\n if (this.provider.getChain) {\n return (\n {\n BITCOIN_MAINNET: \"btc\",\n BITCOIN_TESTNET: \"btcTestnet\",\n FRACTAL_BITCOIN_MAINNET: \"fractalBtc\",\n }[(await this.provider.getChain()).enum] ?? \"\"\n );\n }\n return (await this.provider.getNetwork()) === \"livenet\"\n ? \"btc\"\n : \"btcTestnet\";\n })();\n const { network } = this.matchNetworkPreference(\n this.preferredNetworks,\n currentNetwork,\n ) ?? { network: currentNetwork };\n if (network === currentNetwork) {\n return;\n }\n\n return network;\n }\n\n /**\n * Ensure the BTC network is the same as CKB network.\n */\n async ensureNetwork(): Promise<void> {\n const network = await this._getNetworkToChange();\n if (!network) {\n return;\n }\n if (this.provider.switchChain) {\n const chain = {\n btc: \"BITCOIN_MAINNET\",\n btcTestnet: \"BITCOIN_TESTNET\",\n fractalBtc: \"FRACTAL_BITCOIN_MAINNET\",\n }[network];\n if (chain) {\n await this.provider.switchChain(chain);\n return;\n }\n } else if (network === \"btc\" || network === \"btcTestnet\") {\n await this.provider.switchNetwork(\n network === \"btc\" ? \"livenet\" : \"testnet\",\n );\n return;\n }\n\n throw new Error(\n `UniSat wallet doesn't support the requested chain ${network}`,\n );\n }\n\n /**\n * Gets the Bitcoin account address.\n * @returns A promise that resolves to the Bitcoin account address.\n */\n async getBtcAccount(): Promise<string> {\n return (await this.provider.getAccounts())[0];\n }\n\n /**\n * Gets the Bitcoin public key.\n * @returns A promise that resolves to the Bitcoin public key.\n */\n async getBtcPublicKey(): Promise<ccc.Hex> {\n return ccc.hexFrom(await this.provider.getPublicKey());\n }\n\n /**\n * Connects to the provider by requesting accounts.\n * @returns A promise that resolves when the connection is established.\n */\n async connect(): Promise<void> {\n await this.provider.requestAccounts();\n await this.ensureNetwork();\n }\n\n onReplaced(listener: () => void): () => void {\n const stop: (() => void)[] = [];\n const replacer = async () => {\n listener();\n stop[0]?.();\n };\n stop.push(() => {\n this.provider.removeListener(\"accountsChanged\", replacer);\n this.provider.removeListener(\"networkChanged\", replacer);\n });\n\n this.provider.on(\"accountsChanged\", replacer);\n this.provider.on(\"networkChanged\", replacer);\n\n return stop[0];\n }\n\n /**\n * Checks if the signer is connected.\n * @returns A promise that resolves to true if connected, false otherwise.\n */\n async isConnected(): Promise<boolean> {\n if (await this._getNetworkToChange()) {\n return false;\n }\n return (await this.provider.getAccounts()).length !== 0;\n }\n\n /**\n * Signs a raw message with the Bitcoin account.\n * @param message - The message to sign.\n * @returns A promise that resolves to the signed message.\n */\n async signMessageRaw(message: string | ccc.BytesLike): Promise<string> {\n const challenge =\n typeof message === \"string\" ? message : ccc.hexFrom(message).slice(2);\n\n return this.provider.signMessage(challenge, \"ecdsa\");\n }\n\n /**\n * Signs a PSBT using UniSat wallet.\n *\n * @param psbtHex - The hex string of PSBT to sign.\n * @param options - Options for signing the PSBT\n * @returns A promise that resolves to the signed PSBT as a Hex string\n */\n async signPsbt(\n psbtHex: ccc.HexLike,\n options?: ccc.SignPsbtOptionsLike,\n ): Promise<ccc.Hex> {\n return ccc.hexFrom(\n await this.provider.signPsbt(ccc.hexFrom(psbtHex).slice(2), options),\n );\n }\n\n /**\n * Broadcasts a signed PSBT to the Bitcoin network.\n *\n * @param psbtHex - The hex string of signed PSBT to broadcast.\n * @returns A promise that resolves to the transaction ID as a Hex string\n */\n async broadcastPsbt(\n psbtHex: ccc.HexLike,\n _options?: ccc.SignPsbtOptionsLike,\n ): Promise<ccc.Hex> {\n const txid = await this.provider.pushPsbt(ccc.hexFrom(psbtHex).slice(2));\n return ccc.hexFrom(txid);\n }\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { Provider } from \"./advancedBarrel.js\";\nimport { Signer } from \"./signer.js\";\n\n/**\n * Retrieves the UniSat signer if available.\n * @public\n *\n * @param client - The client instance.\n * @returns The Signer instance if the UniSat provider is available, otherwise undefined.\n */\nexport function getUniSatSigners(\n client: ccc.Client,\n preferredNetworks?: ccc.NetworkPreference[],\n): ccc.SignerInfo[] {\n const windowRef = window as { unisat?: Provider };\n\n if (typeof windowRef.unisat === \"undefined\") {\n return [];\n }\n\n return [\n {\n signer: new Signer(client, windowRef.unisat, preferredNetworks),\n name: \"BTC\",\n },\n ];\n}\n","export * from \"./signer.js\";\nexport * from \"./signersFactory.js\";\n"],"mappings":"wFAOA,IAAa,EAAb,cAA4B,EAAI,SAAU,CAMxC,YACE,EACA,EACA,EAA8D,CAC5D,CACE,cAAe,MACf,WAAY,EAAI,WAAW,IAC3B,QAAS,KACX,EACA,CACE,cAAe,MACf,WAAY,EAAI,WAAW,IAC3B,QAAS,YACX,CACF,EACA,CACA,MAAM,CAAM,EAdI,KAAA,SAAA,EACC,KAAA,kBAAA,CAcnB,CAEA,MAAM,qBAAmD,CACvD,IAAM,EAAiB,MAAO,SACxB,KAAK,SAAS,SAEd,CACE,gBAAiB,MACjB,gBAAiB,aACjB,wBAAyB,YAC3B,GAAG,MAAM,KAAK,SAAS,SAAS,EAAA,CAAG,OAAS,GAGxC,MAAM,KAAK,SAAS,WAAW,IAAO,UAC1C,MACA,aACN,CAAG,EACG,CAAE,WAAY,KAAK,uBACvB,KAAK,kBACL,CACF,GAAK,CAAE,QAAS,CAAe,EAC3B,OAAY,EAIhB,OAAO,CACT,CAKA,MAAM,eAA+B,CACnC,IAAM,EAAU,MAAM,KAAK,oBAAoB,EAC1C,KAGL,IAAI,KAAK,SAAS,YAAa,CAC7B,IAAM,EAAQ,CACZ,IAAK,kBACL,WAAY,kBACZ,WAAY,yBACd,EAAE,GACF,GAAI,EAAO,CACT,MAAM,KAAK,SAAS,YAAY,CAAK,EACrC,MACF,CACF,MAAO,GAAI,IAAY,OAAS,IAAY,aAAc,CACxD,MAAM,KAAK,SAAS,cAClB,IAAY,MAAQ,UAAY,SAClC,EACA,MACF,CAEA,MAAU,MACR,qDAAqD,GACvD,CAJA,CAKF,CAMA,MAAM,eAAiC,CACrC,OAAQ,MAAM,KAAK,SAAS,YAAY,EAAA,CAAG,EAC7C,CAMA,MAAM,iBAAoC,CACxC,OAAO,EAAI,QAAQ,MAAM,KAAK,SAAS,aAAa,CAAC,CACvD,CAMA,MAAM,SAAyB,CAC7B,MAAM,KAAK,SAAS,gBAAgB,EACpC,MAAM,KAAK,cAAc,CAC3B,CAEA,WAAW,EAAkC,CAC3C,IAAM,EAAuB,CAAC,EACxB,EAAW,SAAY,CAC3B,EAAS,EACT,EAAK,EAAE,GAAG,CACZ,EASA,OARA,EAAK,SAAW,CACd,KAAK,SAAS,eAAe,kBAAmB,CAAQ,EACxD,KAAK,SAAS,eAAe,iBAAkB,CAAQ,CACzD,CAAC,EAED,KAAK,SAAS,GAAG,kBAAmB,CAAQ,EAC5C,KAAK,SAAS,GAAG,iBAAkB,CAAQ,EAEpC,EAAK,EACd,CAMA,MAAM,aAAgC,CAIpC,OAHI,MAAM,KAAK,oBAAoB,EAC1B,IAED,MAAM,KAAK,SAAS,YAAY,EAAA,CAAG,SAAW,CACxD,CAOA,MAAM,eAAe,EAAkD,CACrE,IAAM,EACJ,OAAO,GAAY,SAAW,EAAU,EAAI,QAAQ,CAAO,CAAC,CAAC,MAAM,CAAC,EAEtE,OAAO,KAAK,SAAS,YAAY,EAAW,OAAO,CACrD,CASA,MAAM,SACJ,EACA,EACkB,CAClB,OAAO,EAAI,QACT,MAAM,KAAK,SAAS,SAAS,EAAI,QAAQ,CAAO,CAAC,CAAC,MAAM,CAAC,EAAG,CAAO,CACrE,CACF,CAQA,MAAM,cACJ,EACA,EACkB,CAClB,IAAM,EAAO,MAAM,KAAK,SAAS,SAAS,EAAI,QAAQ,CAAO,CAAC,CAAC,MAAM,CAAC,CAAC,EACvE,OAAO,EAAI,QAAQ,CAAI,CACzB,CACF,EC3KA,SAAgB,EACd,EACA,EACkB,CAClB,IAAM,EAAY,OAMlB,OAJW,EAAU,SAAW,OACvB,CAAC,EAGH,CACL,CACE,OAAQ,IAAI,EAAO,EAAQ,EAAU,OAAQ,CAAiB,EAC9D,KAAM,KACR,CACF,CACF"}
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./barrel.mjs";export{e as UniSat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};export{t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { r as advancedBarrel_d_exports } from "./advancedBarrel-C8SL2uu7.js";
|
|
2
|
+
export { advancedBarrel_d_exports as UniSatA };
|
|
@@ -1,37 +1 @@
|
|
|
1
|
-
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.UniSatA = void 0;
|
|
37
|
-
exports.UniSatA = __importStar(require("./advancedBarrel.js"));
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./advancedBarrel.js");Object.defineProperty(exports,"UniSatA",{enumerable:!0,get:function(){return e.t}});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
declare namespace advancedBarrel_d_exports {
|
|
5
|
+
export { OnMethod, Provider };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Interface representing a provider for interacting with accounts and signing messages.
|
|
9
|
+
*/
|
|
10
|
+
interface Provider {
|
|
11
|
+
/**
|
|
12
|
+
* Signs a PSBT using UniSat wallet.
|
|
13
|
+
*
|
|
14
|
+
* @param psbtHex - The hex string of PSBT to sign
|
|
15
|
+
* @param options - Options for signing the PSBT
|
|
16
|
+
* @returns A promise that resolves to the signed PSBT hex string
|
|
17
|
+
*/
|
|
18
|
+
signPsbt(psbtHex: string, options?: ccc.SignPsbtOptionsLike): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Broadcasts a signed PSBT to the Bitcoin network.
|
|
21
|
+
*
|
|
22
|
+
* @param psbtHex - The hex string of the signed PSBT to broadcast.
|
|
23
|
+
* @returns A promise that resolves to the transaction ID.
|
|
24
|
+
*/
|
|
25
|
+
pushPsbt(psbtHex: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Requests user accounts.
|
|
28
|
+
* @returns A promise that resolves to an array of account addresses.
|
|
29
|
+
*/
|
|
30
|
+
requestAccounts(): Promise<string[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the current network.
|
|
33
|
+
* @returns current network.
|
|
34
|
+
*/
|
|
35
|
+
getNetwork(): Promise<"livenet" | "testnet">;
|
|
36
|
+
/**
|
|
37
|
+
* Switch the current network.
|
|
38
|
+
*/
|
|
39
|
+
switchNetwork(chain: "livenet" | "testnet"): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the current chain.
|
|
42
|
+
* @returns current chain.
|
|
43
|
+
*/
|
|
44
|
+
getChain?(): Promise<{
|
|
45
|
+
enum: string;
|
|
46
|
+
name: string;
|
|
47
|
+
network: string;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Switch the current chain.
|
|
51
|
+
*/
|
|
52
|
+
switchChain?(chain: string): Promise<{
|
|
53
|
+
enum: string;
|
|
54
|
+
name: string;
|
|
55
|
+
network: string;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the current accounts.
|
|
59
|
+
* @returns A promise that resolves to an array of account addresses.
|
|
60
|
+
*/
|
|
61
|
+
getAccounts(): Promise<string[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the public key of the account.
|
|
64
|
+
* @returns A promise that resolves to the public key.
|
|
65
|
+
*/
|
|
66
|
+
getPublicKey(): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Signs a message with the specified type.
|
|
69
|
+
* @param msg - The message to sign.
|
|
70
|
+
* @param type - The type of signature.
|
|
71
|
+
* @returns A promise that resolves to the signed message.
|
|
72
|
+
*/
|
|
73
|
+
signMessage(msg: string, type: "ecdsa" | "bip322-simple"): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Adds an event listener to the provider.
|
|
76
|
+
*/
|
|
77
|
+
on: OnMethod;
|
|
78
|
+
/**
|
|
79
|
+
* Removes an event listener from the provider.
|
|
80
|
+
* @param eventName - The name of the event to remove the listener from.
|
|
81
|
+
* @param listener - The listener function to remove.
|
|
82
|
+
* @returns The provider instance.
|
|
83
|
+
*/
|
|
84
|
+
removeListener(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Interface representing a method to add event listeners to the provider.
|
|
88
|
+
*/
|
|
89
|
+
interface OnMethod {
|
|
90
|
+
/**
|
|
91
|
+
* Adds an event listener to the provider.
|
|
92
|
+
* @param eventName - The name of the event.
|
|
93
|
+
* @param listener - The listener function.
|
|
94
|
+
* @returns The provider instance.
|
|
95
|
+
*/
|
|
96
|
+
(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
export { __exportAll as i, Provider as n, advancedBarrel_d_exports as r, OnMethod as t };
|
|
100
|
+
//# sourceMappingURL=advancedBarrel-C8SL2uu7.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel-C8SL2uu7.d.ts","names":[],"sources":["../src/advancedBarrel.ts"],"mappings":";;;;;;;;;UAKiB,QAAA;;;;;;;;EAQf,QAAA,CAAS,OAAA,UAAiB,OAAA,GAAU,GAAA,CAAI,mBAAA,GAAsB,OAAA;;;;;;;EAQ9D,QAAA,CAAS,OAAA,WAAkB,OAAA;;;;;EAM3B,eAAA,IAAmB,OAAA;EAtBI;;;;EA4BvB,UAAA,IAAc,OAAA;EANK;;;EAWnB,aAAA,CAAc,KAAA,0BAA+B,OAAA;EAa1C;;;;EAPH,QAAA,KAAa,OAAA;IAAU,IAAA;IAAc,IAAA;IAAc,OAAA;EAAA;EA/B1C;;;EAoCT,WAAA,EACE,KAAA,WACC,OAAA;IAAU,IAAA;IAAc,IAAA;IAAc,OAAA;EAAA;EAxBzC;;;;EA8BA,WAAA,IAAe,OAAA;EAnBD;;;;EAyBd,YAAA,IAAgB,OAAA;EAnBqB;;;;;;EA2BrC,WAAA,CAAY,GAAA,UAAa,IAAA,8BAAkC,OAAA;EApBlB;;;EAyBzC,EAAA,EAAI,QAAA;EAbY;;;;;;EAqBhB,cAAA,CACE,SAAA,UACA,QAAA,MAAc,IAAA,0BACb,QAAA;AAAA;;;;UAMY,QAAA;EANJ;AAAA;AAMb;;;;EANa,CAaV,SAAA,UAAmB,QAAA,MAAc,IAAA,0BAA8B,QAAQ;AAAA"}
|
|
@@ -1,93 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
* Interface representing a provider for interacting with accounts and signing messages.
|
|
4
|
-
*/
|
|
5
|
-
export interface Provider {
|
|
6
|
-
/**
|
|
7
|
-
* Signs a PSBT using UniSat wallet.
|
|
8
|
-
*
|
|
9
|
-
* @param psbtHex - The hex string of PSBT to sign
|
|
10
|
-
* @param options - Options for signing the PSBT
|
|
11
|
-
* @returns A promise that resolves to the signed PSBT hex string
|
|
12
|
-
*/
|
|
13
|
-
signPsbt(psbtHex: string, options?: ccc.SignPsbtOptionsLike): Promise<string>;
|
|
14
|
-
/**
|
|
15
|
-
* Broadcasts a signed PSBT to the Bitcoin network.
|
|
16
|
-
*
|
|
17
|
-
* @param psbtHex - The hex string of the signed PSBT to broadcast.
|
|
18
|
-
* @returns A promise that resolves to the transaction ID.
|
|
19
|
-
*/
|
|
20
|
-
pushPsbt(psbtHex: string): Promise<string>;
|
|
21
|
-
/**
|
|
22
|
-
* Requests user accounts.
|
|
23
|
-
* @returns A promise that resolves to an array of account addresses.
|
|
24
|
-
*/
|
|
25
|
-
requestAccounts(): Promise<string[]>;
|
|
26
|
-
/**
|
|
27
|
-
* Gets the current network.
|
|
28
|
-
* @returns current network.
|
|
29
|
-
*/
|
|
30
|
-
getNetwork(): Promise<"livenet" | "testnet">;
|
|
31
|
-
/**
|
|
32
|
-
* Switch the current network.
|
|
33
|
-
*/
|
|
34
|
-
switchNetwork(chain: "livenet" | "testnet"): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Gets the current chain.
|
|
37
|
-
* @returns current chain.
|
|
38
|
-
*/
|
|
39
|
-
getChain?(): Promise<{
|
|
40
|
-
enum: string;
|
|
41
|
-
name: string;
|
|
42
|
-
network: string;
|
|
43
|
-
}>;
|
|
44
|
-
/**
|
|
45
|
-
* Switch the current chain.
|
|
46
|
-
*/
|
|
47
|
-
switchChain?(chain: string): Promise<{
|
|
48
|
-
enum: string;
|
|
49
|
-
name: string;
|
|
50
|
-
network: string;
|
|
51
|
-
}>;
|
|
52
|
-
/**
|
|
53
|
-
* Gets the current accounts.
|
|
54
|
-
* @returns A promise that resolves to an array of account addresses.
|
|
55
|
-
*/
|
|
56
|
-
getAccounts(): Promise<string[]>;
|
|
57
|
-
/**
|
|
58
|
-
* Gets the public key of the account.
|
|
59
|
-
* @returns A promise that resolves to the public key.
|
|
60
|
-
*/
|
|
61
|
-
getPublicKey(): Promise<string>;
|
|
62
|
-
/**
|
|
63
|
-
* Signs a message with the specified type.
|
|
64
|
-
* @param msg - The message to sign.
|
|
65
|
-
* @param type - The type of signature.
|
|
66
|
-
* @returns A promise that resolves to the signed message.
|
|
67
|
-
*/
|
|
68
|
-
signMessage(msg: string, type: "ecdsa" | "bip322-simple"): Promise<string>;
|
|
69
|
-
/**
|
|
70
|
-
* Adds an event listener to the provider.
|
|
71
|
-
*/
|
|
72
|
-
on: OnMethod;
|
|
73
|
-
/**
|
|
74
|
-
* Removes an event listener from the provider.
|
|
75
|
-
* @param eventName - The name of the event to remove the listener from.
|
|
76
|
-
* @param listener - The listener function to remove.
|
|
77
|
-
* @returns The provider instance.
|
|
78
|
-
*/
|
|
79
|
-
removeListener(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Interface representing a method to add event listeners to the provider.
|
|
83
|
-
*/
|
|
84
|
-
export interface OnMethod {
|
|
85
|
-
/**
|
|
86
|
-
* Adds an event listener to the provider.
|
|
87
|
-
* @param eventName - The name of the event.
|
|
88
|
-
* @param listener - The listener function.
|
|
89
|
-
* @returns The provider instance.
|
|
90
|
-
*/
|
|
91
|
-
(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=advancedBarrel.d.ts.map
|
|
1
|
+
import { n as Provider, t as OnMethod } from "./advancedBarrel-C8SL2uu7.js";
|
|
2
|
+
export { OnMethod, Provider };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=require("./rolldown-runtime-BIInC43l.js").t({});Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return e}});
|
|
2
|
+
//# sourceMappingURL=advancedBarrel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel.js","names":[],"sources":["../src/advancedBarrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\n\n/**\n * Interface representing a provider for interacting with accounts and signing messages.\n */\nexport interface Provider {\n /**\n * Signs a PSBT using UniSat wallet.\n *\n * @param psbtHex - The hex string of PSBT to sign\n * @param options - Options for signing the PSBT\n * @returns A promise that resolves to the signed PSBT hex string\n */\n signPsbt(psbtHex: string, options?: ccc.SignPsbtOptionsLike): Promise<string>;\n\n /**\n * Broadcasts a signed PSBT to the Bitcoin network.\n *\n * @param psbtHex - The hex string of the signed PSBT to broadcast.\n * @returns A promise that resolves to the transaction ID.\n */\n pushPsbt(psbtHex: string): Promise<string>;\n\n /**\n * Requests user accounts.\n * @returns A promise that resolves to an array of account addresses.\n */\n requestAccounts(): Promise<string[]>;\n\n /**\n * Gets the current network.\n * @returns current network.\n */\n getNetwork(): Promise<\"livenet\" | \"testnet\">;\n\n /**\n * Switch the current network.\n */\n switchNetwork(chain: \"livenet\" | \"testnet\"): Promise<void>;\n\n /**\n * Gets the current chain.\n * @returns current chain.\n */\n getChain?(): Promise<{ enum: string; name: string; network: string }>;\n\n /**\n * Switch the current chain.\n */\n switchChain?(\n chain: string,\n ): Promise<{ enum: string; name: string; network: string }>;\n\n /**\n * Gets the current accounts.\n * @returns A promise that resolves to an array of account addresses.\n */\n getAccounts(): Promise<string[]>;\n\n /**\n * Gets the public key of the account.\n * @returns A promise that resolves to the public key.\n */\n getPublicKey(): Promise<string>;\n\n /**\n * Signs a message with the specified type.\n * @param msg - The message to sign.\n * @param type - The type of signature.\n * @returns A promise that resolves to the signed message.\n */\n signMessage(msg: string, type: \"ecdsa\" | \"bip322-simple\"): Promise<string>;\n\n /**\n * Adds an event listener to the provider.\n */\n on: OnMethod;\n\n /**\n * Removes an event listener from the provider.\n * @param eventName - The name of the event to remove the listener from.\n * @param listener - The listener function to remove.\n * @returns The provider instance.\n */\n removeListener(\n eventName: string,\n listener: (...args: unknown[]) => unknown,\n ): Provider;\n}\n\n/**\n * Interface representing a method to add event listeners to the provider.\n */\nexport interface OnMethod {\n /**\n * Adds an event listener to the provider.\n * @param eventName - The name of the event.\n * @param listener - The listener function.\n * @returns The provider instance.\n */\n (eventName: string, listener: (...args: unknown[]) => unknown): Provider;\n}\n"],"mappings":""}
|
|
@@ -1,3 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { i as __exportAll, n as Provider } from "./advancedBarrel-C8SL2uu7.js";
|
|
2
|
+
import { ccc } from "@ckb-ccc/core";
|
|
3
|
+
|
|
4
|
+
//#region src/signer.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a Bitcoin signer that extends SignerBtc
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
declare class Signer extends ccc.SignerBtc {
|
|
10
|
+
readonly provider: Provider;
|
|
11
|
+
private readonly preferredNetworks;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of Signer.
|
|
14
|
+
* @param client - The client instance.
|
|
15
|
+
* @param provider - The provider instance.
|
|
16
|
+
*/
|
|
17
|
+
constructor(client: ccc.Client, provider: Provider, preferredNetworks?: ccc.NetworkPreference[]);
|
|
18
|
+
_getNetworkToChange(): Promise<string | undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* Ensure the BTC network is the same as CKB network.
|
|
21
|
+
*/
|
|
22
|
+
ensureNetwork(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the Bitcoin account address.
|
|
25
|
+
* @returns A promise that resolves to the Bitcoin account address.
|
|
26
|
+
*/
|
|
27
|
+
getBtcAccount(): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the Bitcoin public key.
|
|
30
|
+
* @returns A promise that resolves to the Bitcoin public key.
|
|
31
|
+
*/
|
|
32
|
+
getBtcPublicKey(): Promise<ccc.Hex>;
|
|
33
|
+
/**
|
|
34
|
+
* Connects to the provider by requesting accounts.
|
|
35
|
+
* @returns A promise that resolves when the connection is established.
|
|
36
|
+
*/
|
|
37
|
+
connect(): Promise<void>;
|
|
38
|
+
onReplaced(listener: () => void): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if the signer is connected.
|
|
41
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
42
|
+
*/
|
|
43
|
+
isConnected(): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Signs a raw message with the Bitcoin account.
|
|
46
|
+
* @param message - The message to sign.
|
|
47
|
+
* @returns A promise that resolves to the signed message.
|
|
48
|
+
*/
|
|
49
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Signs a PSBT using UniSat wallet.
|
|
52
|
+
*
|
|
53
|
+
* @param psbtHex - The hex string of PSBT to sign.
|
|
54
|
+
* @param options - Options for signing the PSBT
|
|
55
|
+
* @returns A promise that resolves to the signed PSBT as a Hex string
|
|
56
|
+
*/
|
|
57
|
+
signPsbt(psbtHex: ccc.HexLike, options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
|
|
58
|
+
/**
|
|
59
|
+
* Broadcasts a signed PSBT to the Bitcoin network.
|
|
60
|
+
*
|
|
61
|
+
* @param psbtHex - The hex string of signed PSBT to broadcast.
|
|
62
|
+
* @returns A promise that resolves to the transaction ID as a Hex string
|
|
63
|
+
*/
|
|
64
|
+
broadcastPsbt(psbtHex: ccc.HexLike, _options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/signersFactory.d.ts
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves the UniSat signer if available.
|
|
70
|
+
* @public
|
|
71
|
+
*
|
|
72
|
+
* @param client - The client instance.
|
|
73
|
+
* @returns The Signer instance if the UniSat provider is available, otherwise undefined.
|
|
74
|
+
*/
|
|
75
|
+
declare function getUniSatSigners(client: ccc.Client, preferredNetworks?: ccc.NetworkPreference[]): ccc.SignerInfo[];
|
|
76
|
+
declare namespace barrel_d_exports {
|
|
77
|
+
export { Signer, getUniSatSigners };
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { Signer, getUniSatSigners, barrel_d_exports as t };
|
|
3
81
|
//# sourceMappingURL=barrel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barrel.d.ts","
|
|
1
|
+
{"version":3,"file":"barrel.d.ts","names":[],"sources":["../src/signer.ts","../src/signersFactory.ts","../src/barrel.ts"],"mappings":";;;;;;AAOA;;cAAa,MAAA,SAAe,GAAA,CAAI,SAAA;EAAA,SAQZ,QAAA,EAAU,QAAA;EAAA,iBACT,iBAAA;EADS;;;;;cAD1B,MAAA,EAAQ,GAAA,CAAI,MAAA,EACI,QAAA,EAAU,QAAA,EACT,iBAAA,GAAmB,GAAA,CAAI,iBAAA;EAgBpC,mBAAA,IAAuB,OAAA;EA4EZ;;;EA/CX,aAAA,IAAiB,OAAA;EAoGZ;;;;EArEL,aAAA,IAAiB,OAAA;EAqFV;;;;EA7EP,eAAA,IAAmB,OAAA,CAAQ,GAAA,CAAI,GAAA;EA7FE;;;;EAqGjC,OAAA,IAAW,OAAA;EAKjB,UAAA,CAAW,QAAA;;;;;EAqBL,WAAA,IAAe,OAAA;EAvHH;;;;;EAmIZ,cAAA,CAAe,OAAA,WAAkB,GAAA,CAAI,SAAA,GAAY,OAAA;EArFjD;;;;;;;EAmGA,QAAA,CACJ,OAAA,EAAS,GAAA,CAAI,OAAA,EACb,OAAA,GAAU,GAAA,CAAI,mBAAA,GACb,OAAA,CAAQ,GAAA,CAAI,GAAA;EAvDT;;;;;;EAmEA,aAAA,CACJ,OAAA,EAAS,GAAA,CAAI,OAAA,EACb,QAAA,GAAW,GAAA,CAAI,mBAAA,GACd,OAAA,CAAQ,GAAA,CAAI,GAAA;AAAA;;;;;;AA3KjB;;;;iBCIgB,gBAAA,CACd,MAAA,EAAQ,GAAA,CAAI,MAAA,EACZ,iBAAA,GAAoB,GAAA,CAAI,iBAAA,KACvB,GAAA,CAAI,UAAA;AAAA"}
|
package/dist.commonjs/barrel.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
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("./signer.js"), exports);
|
|
18
|
-
__exportStar(require("./signersFactory.js"), exports);
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.js");let t=require("@ckb-ccc/core");var n=class extends t.ccc.SignerBtc{constructor(e,n,r=[{addressPrefix:`ckb`,signerType:t.ccc.SignerType.BTC,network:`btc`},{addressPrefix:`ckt`,signerType:t.ccc.SignerType.BTC,network:`btcTestnet`}]){super(e),this.provider=n,this.preferredNetworks=r}async _getNetworkToChange(){let e=await(async()=>this.provider.getChain?{BITCOIN_MAINNET:`btc`,BITCOIN_TESTNET:`btcTestnet`,FRACTAL_BITCOIN_MAINNET:`fractalBtc`}[(await this.provider.getChain()).enum]??``:await this.provider.getNetwork()===`livenet`?`btc`:`btcTestnet`)(),{network:t}=this.matchNetworkPreference(this.preferredNetworks,e)??{network:e};if(t!==e)return t}async ensureNetwork(){let e=await this._getNetworkToChange();if(e){if(this.provider.switchChain){let t={btc:`BITCOIN_MAINNET`,btcTestnet:`BITCOIN_TESTNET`,fractalBtc:`FRACTAL_BITCOIN_MAINNET`}[e];if(t){await this.provider.switchChain(t);return}}else if(e===`btc`||e===`btcTestnet`){await this.provider.switchNetwork(e===`btc`?`livenet`:`testnet`);return}throw Error(`UniSat wallet doesn't support the requested chain ${e}`)}}async getBtcAccount(){return(await this.provider.getAccounts())[0]}async getBtcPublicKey(){return t.ccc.hexFrom(await this.provider.getPublicKey())}async connect(){await this.provider.requestAccounts(),await this.ensureNetwork()}onReplaced(e){let t=[],n=async()=>{e(),t[0]?.()};return t.push(()=>{this.provider.removeListener(`accountsChanged`,n),this.provider.removeListener(`networkChanged`,n)}),this.provider.on(`accountsChanged`,n),this.provider.on(`networkChanged`,n),t[0]}async isConnected(){return await this._getNetworkToChange()?!1:(await this.provider.getAccounts()).length!==0}async signMessageRaw(e){let n=typeof e==`string`?e:t.ccc.hexFrom(e).slice(2);return this.provider.signMessage(n,`ecdsa`)}async signPsbt(e,n){return t.ccc.hexFrom(await this.provider.signPsbt(t.ccc.hexFrom(e).slice(2),n))}async broadcastPsbt(e,n){let r=await this.provider.pushPsbt(t.ccc.hexFrom(e).slice(2));return t.ccc.hexFrom(r)}};function r(e,t){let r=window;return r.unisat===void 0?[]:[{signer:new n(e,r.unisat,t),name:`BTC`}]}var i=e.t({Signer:()=>n,getUniSatSigners:()=>r});exports.Signer=n,exports.getUniSatSigners=r,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
|
2
|
+
//# sourceMappingURL=barrel.js.map
|