@babylonlabs-io/wallet-连接器
巴比伦钱包连接器
巴比伦钱包连接器仓库提供钱包连接组件 用于巴比伦 dApps. 这个组件可以连接比特币,巴比伦 创世纪连锁店 还有伊特鲁姆钱包.
关键特性
- 比特币、巴比伦和Ethereum钱包连接的统一接口
- 支持浏览器扩展钱包
- 支持硬件钱包
- 通过可注入接口实现移动钱包兼容性
- Tomo 为更广泛的钱包生态系统连接集成
* 概览
巴比伦钱包连接器提供了整合的统一接口 比特币,巴比伦,和伊特鲁姆钱包入巴比伦dApps. 它支持本土 钱包扩展名,可注入的移动钱包,以及ETH的AppKit/WalletConnect.
主要的建筑区别在于 原生钱包被安装在
库,而可注入的钱包可以通过插入其
落实到网页 window dApp 装入前的对象.
* 安装
npm i @babylonlabs-io/wallet-connector
QQ 提交格式和自动发布
这个项目使用 常规武器委员会 财务报告和审定财务报表 语义释放 自动化 版本化,更动日志生成,和npm出版.
* 如何运作
- 所有承诺都必须遵循 常规武器委员会 格式.
- 当更改合并为
main分支 :semantic-release分析消息- 确定适当的语义版本凸起( E)
major, (中文(简体) ),minor, (中文(简体) ),patch(中文(简体) ) - 用 Git 标记发布时的更改日志
- 将新版本发布到 npm
QQ 提交信件示例
feat: add support for slashing script
fix: handle invalid staking tx gracefully
docs: update README with commit conventions
refactor!: remove deprecated method and cleanup types
说明: 对于断开更改,添加一个
!在类型之后(例如:.feat!:或者说refactor!:(a) 并包括说明所犯罪行的突破性变化 躯体.
· 释出
只需使用适当的格式将您的更改输入并合并到 main. 犯罪调查
管道将自动处理版本和释放——不手工标记
或需要版本的凸起.
· 故事本
npm run dev
钱包整合
⚠️ 重要性: 打破巴比伦人使用的钱包方法的修改 网络应用程序可能造成与其不相容或导致 有严重后果的出乎意料的行为.
请确保始终保持后向兼容和测试 所有影响巴比伦网络所需方法的变化 应用。 如果你不确定有什么变化 请联系巴比伦 实验室团队.
本指南解释了如何将钱包与巴比伦dApps整合. 这个 钱包连接器通过两个集成路径支持比特币,巴比伦和埃特鲁姆钱包:
1. 浏览器扩展钱包
建议的将钱包与巴比伦dApps整合的方法是: Tomo 连接 SDK 字节。 。 。 . 有关整合详情,请参见托莫的文档.
2. 移动钱包
完整的界面定义可见于 弧度/分数/类型。 。 。 .
下面我们概述了比特币、巴比伦和伊特鲁姆钱包的接口,这些钱包需要 与巴比伦dApps合并.
IProvider 软件
export interface IProvider {
/**
* Connects to the wallet and returns the instance of the wallet provider.
* Currently Bitcoin only supports Native SegWit and Taproot address types.
* @returns A promise that resolves to an instance of the wrapper wallet provider.
* @throws An error if the wallet is not installed or if connection fails.
*/
connectWallet(): Promise<void>;
/**
* Gets the address of the connected wallet.
* @returns A promise that resolves to the address of the connected wallet.
*/
getAddress(): Promise<string>;
/**
* Gets the public key of the connected wallet.
* @returns A promise that resolves to the public key of the connected wallet.
*/
getPublicKeyHex(): Promise<string>;
}
IBTC 服务器
interface IBTCProvider extends IProvider {
/**
* Signs the given PSBT in hex format.
* @param psbtHex - The hex string of the unsigned PSBT to sign.
* @param options - Optional parameters for signing the PSBT.
* @returns A promise that resolves to the hex string of the signed PSBT.
*/
signPsbt(psbtHex: string, options?: SignPsbtOptions): Promise<string>;
/**
* Signs multiple PSBTs in hex format.
* @param psbtsHexes - The hex strings of the unsigned PSBTs to sign.
* @param options - Optional parameters for signing the PSBTs.
* @returns A promise that resolves to an array of hex strings, each representing a signed PSBT.
*/
signPsbts(
psbtsHexes: string[],
options?: SignPsbtOptions[],
): Promise<string[]>;
/**
* Gets the network of the current account.
* @returns A promise that resolves to the network of the current account.
*/
getNetwork(): Promise<Network>;
/**
* Signs a message using either BIP322-Simple or ECDSA signing method.
* @param message - The message to sign.
* @param type - The signing method to use.
* @returns A promise that resolves to the signed message.
*/
signMessage(
message: string,
type: "bip322-simple" | "ecdsa",
): Promise<string>;
/**
* Lists the wallet's inscribed outpoints, read from the wallet's own
* inscription index, so callers can keep those UTXOs out of funding.
*
* Resolve only from a real index. An empty array means "checked, none
* inscribed", and `fetchOrdinals` then skips the ordinals API, which it uses
* only when this call rejects, times out or resolves a non-array. A wallet
* without an inscription index must reject, never resolve `[]`.
* @returns A promise that resolves to the inscribed outpoints.
*/
getInscriptions(): Promise<InscriptionIdentifier[]>;
/**
* Registers an event listener for the specified event.
* At the moment, only the "accountChanged" event is supported.
* @param eventName - The name of the event to listen for.
* @param callBack - The callback function to be executed when the event occurs.
*/
on(eventName: string, callBack: () => void): void;
/**
* Unregisters an event listener for the specified event.
* @param eventName - The name of the event to listen for.
* @param callBack - The callback function to be executed when the event occurs.
*/
off(eventName: string, callBack: () => void): void;
/**
* Gets the name of the wallet provider.
* @returns A promise that resolves to the name of the wallet provider.
*/
getWalletProviderName(): Promise<string>;
/**
* Gets the icon of the wallet provider.
* @returns A promise that resolves to the icon of the wallet provider.
*/
getWalletProviderIcon(): Promise<string>;
/**
* Gets the version of the wallet provider.
* @returns A promise that resolves to the version of the wallet provider.
*/
getVersion?(): Promise<string>;
}
ISBN 提供
export interface IBBNProvider extends IProvider {
/**
* Gets the name of the wallet provider.
* @returns A promise that resolves to the name of the wallet provider.
*/
getWalletProviderName(): Promise<string>;
/**
* Gets the icon of the wallet provider.
* @returns A promise that resolves to the icon of the wallet provider.
*/
getWalletProviderIcon(): Promise<string>;
/**
* Retrieves an offline signer that supports both Amino and Direct signing methods.
* This signer is used for signing transactions offline before broadcasting them to the network.
*
* @returns {Promise<OfflineAminoSigner & OfflineDirectSigner>} A promise that resolves to a signer supporting both Amino and Direct signing
* @throws {Error} If wallet connection is not established or signer cannot be retrieved
*/
getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>;
/**
* Retrieves an offline signer that supports either Amino or Direct signing methods.
* This is required for compatibility with older wallets and hardware wallets (like Ledger) that do not support both signing methods.
* This signer is used for signing transactions offline before broadcasting them to the network.
*
* @returns {Promise<OfflineAminoSigner & OfflineDirectSigner>} A promise that resolves to a signer supporting either Amino or Direct signing
* @throws {Error} If wallet connection is not established or signer cannot be retrieved
*/
getOfflineSignerAuto?(): Promise<OfflineAminoSigner | OfflineDirectSigner>;
/**
* Registers an event listener for the specified event.
* At the moment, only the "accountChanged" event is supported.
* @param eventName - The name of the event to listen for.
* @param callBack - The callback function to be executed when the event occurs.
*/
on(eventName: string, callBack: () => void): void;
/**
* Unregisters an event listener for the specified event.
* @param eventName - The name of the event to listen for.
* @param callBack - The callback function to be executed when the event occurs.
*/
off(eventName: string, callBack: () => void): void;
/**
* Gets the version of the wallet provider.
* @returns A promise that resolves to the version of the wallet provider.
*/
getVersion?(): Promise<string>;
}
签名 Psbt 选项
export interface SignInputOptions {
/** Input index to sign */
index: number;
/** Address for signing (optional) */
address?: string;
/** Public key for signing (optional, hex string) */
publicKey?: string;
/** Sighash types (optional) */
sighashTypes?: number[];
/**
* Whether the wallet should sign with the tweaked (key-path) signer.
* Set `false` for Taproot script-path spends, where signing uses
* the untweaked internal key. If omitted, the wallet applies its
* default behavior.
*/
useTweakedSigner?: boolean;
}
export interface SignPsbtOptions {
/** Whether to automatically finalize the PSBT after signing */
autoFinalized?: boolean;
/**
* Specific inputs to sign.
* If not provided, wallet will attempt to sign all inputs it
* can.
*/
signInputs?: SignInputOptions[];
}
IETH 提供
export interface IETHProvider extends IProvider {
/**
* Signs a message using personal_sign (EIP-191).
*/
signMessage(message: string): Promise<string>;
/**
* Signs structured data using eth_signTypedData_v4 (EIP-712).
*/
signTypedData(typedData: ETHTypedData): Promise<string>;
/**
* Sends a transaction to the blockchain.
* @returns Transaction hash
*/
sendTransaction(
tx: ETHTransactionRequest,
): Promise<string>;
/**
* Estimates gas for a transaction.
*/
estimateGas(
tx: ETHTransactionRequest,
): Promise<bigint>;
/**
* Gets the current chain ID.
*/
getChainId(): Promise<number>;
/**
* Switches to a different chain.
*/
switchChain(chainId: number): Promise<void>;
/**
* Gets the account balance in wei.
*/
getBalance(): Promise<bigint>;
/**
* Gets the account nonce.
*/
getNonce(): Promise<number>;
/**
* Gets network information.
*/
getNetworkInfo(): Promise<NetworkInfo>;
/**
* Gets the wallet provider name (synchronous).
*/
getWalletProviderName(): string;
/**
* Gets the wallet provider icon (synchronous).
*/
getWalletProviderIcon(): string;
on(eventName: string, handler: Function): void;
off(eventName: string, handler: Function): void;
}
export interface ETHTransactionRequest {
to: string;
value?: string;
data?: string;
gasLimit?: bigint;
maxFeePerGas?: bigint;
maxPriorityFeePerGas?: bigint;
nonce?: number;
}
export interface ETHTypedData {
domain: {
name?: string;
version?: string;
chainId?: number;
verifyingContract?: string;
salt?: string;
};
types: Record<
string,
Array<{ name: string; type: string }>
>;
primaryType: string;
message: Record<string, any>;
}
export interface NetworkInfo {
name: string;
chainId: string;
}
说明数字 :
getWalletProviderName()财务报告和审定财务报表getWalletProviderIcon()打开IETHProvider为: 同步 (返回数)string),不同于在IBTCProvider财务报告和审定财务报表IBBNProvider。 。 。 .
ETH 钱包通过 AppKit / 钱包连接( 标准)
EIP-1193 (英语). 没有 window.ethwallet 支持注射.
钱包注射
- 执行提供者接口
- 输入
window装入 dApp 之前 :
// For Bitcoin wallets
window.btcwallet = new BTCWalletImplementation();
// For Babylon wallets
window.bbnwallet = new BBNWalletImplementation();
// For Ethereum wallets — no injection needed.
// ETH connects via AppKit / WalletConnect.
默认整合指南
关于将钱包与巴比伦的"无信取出比特币"(TBV)整合的详细文件,包括完整的存款交易流量,签名选项和参考执行,参见: 默认整合指南。 。 。 .