dotswap-wallet
v1.0.58
Published
用于web钱包集合调用
Downloads
947
Readme
web3 钱包聚合库
设计的初衷
- 使用立即执行函数保持私有域变量,确定钱包信息变量锁定,并脱离所有框架的生命周期。
- 磨平不同平台调用不同钱包api内容
- 脱离于各项目,物理隔离wallet钱包和项目业务逻辑两者产生的问题
主要的 api 与变量
- walletApi 用于调用钱包 api 的。
- walletDict 支持的钱包的字典对应
- hasWallet 获取浏览器中是否存在对应的钱包
walletApi 提供的 api 与方法
- connect 用于连接钱包
- disconnect 用于断开钱包
- getInfo 获取用户信息
- sign 用于签名
- signPsbt 用于签名 psbt
- signPsbts 用于多签签名 psbts
- sendBitcoin 用于发送 btc
- getNetwork 用于获取钱包当前网络
import { walletApi, walletDict } from "dotswap-wallet";
const {connect, disconnect, sign, signPsbt, sendBitcoin } = walletApi;
// 连接钱包
const connectFn = async () {
const data = await connect({
name: walletDict.unisat,
network: network || "testnet",
handleMismatchNetwork: true,
});
console.log("data", data)
// 输出的data内容
// {
// name: WalletName | null; // 钱包名称
// network: Network; // 当前网络
// publicKey: string; // 公钥
// accounts: string[]; // 账户
// address: string; // 钱包地址
// btcAddress: string; // BTC钱包地址
// btcPublicKey: string; // BTC钱包公钥
// balance?: {
// confirmed?: number; // 确认的余额
// total?: number; // 总余额
// unconfirmed?: number; // 未确认的余额
// };
// }
}
// 断链
const disconnectFn = () => {
disconnect()
}
// 签名
const signMessage = () => {
return await sign({
msg,
});
// signMsgStr
}
// 签psbt
const signPsbtFn = () => {
return await signPsbt({
psbt,
});
// hex psbt
}
// 签psbts
const signPsbtsFn = () => {
return await signPsbts({ psbt: psbts, option: options });
// ['hex psbt'....]
}
// 发送btc
const sendBitcoinFn = () => {
return await sendBitcoin({
address,
satoshis,
option,
});
}
Api 部分
- getBase64Str 获取 base64 字符串
- getHexStr 获取 hex 字符串
- getNeedFinalList 获取 finalze 的列表
- completeFinalList 用于手动finalze