Skip to content

Commit

Permalink
Merge pull request #80 from dotbitHQ/develop
Browse files Browse the repository at this point in the history
feat: support UniSat wallet protocol.
  • Loading branch information
web3max authored Sep 24, 2024
2 parents 5d8c57a + bd8887e commit cbf56d0
Show file tree
Hide file tree
Showing 41 changed files with 821 additions and 404 deletions.
12 changes: 6 additions & 6 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## 主要特性

- **支持的链**: Ethereum、BNB Smart Chain、Polygon、TRON、Dogecoin。
- **登录方式**: Passkey、Torus。
- **登录方式**: WalletConnect、Passkey、Torus。
- **行业标准**: 我们依赖于 [viem](https://viem.sh/)[@wagmi/core](https://wagmi.sh/core/getting-started)[@wagmi/connectors](https://wagmi.sh/core/api/connectors) 这是 Web3 中最常用的库。

[Documentation in English](README.md)
Expand Down Expand Up @@ -62,7 +62,7 @@ const { Wallet } = await import('wallet-bridge')
```js
import { Wallet } from 'wallet-bridge'
import { createConfig, http } from '@wagmi/core'
import { bsc, bscTestnet, holesky, mainnet as ethereum, polygon, polygonMumbai } from '@wagmi/core/chains'
import { bsc, bscTestnet, holesky, mainnet as ethereum, polygon, polygonAmoy } from '@wagmi/core/chains'
import { injected, walletConnect } from '@wagmi/connectors'

const walletConnectOptions = {
Expand All @@ -76,14 +76,14 @@ const walletConnectOptions = {
}

const wagmiConfig = createConfig({
chains: [ethereum, holesky, bsc, bscTestnet, polygon, polygonMumbai],
chains: [ethereum, holesky, bsc, bscTestnet, polygon, polygonAmoy],
transports: {
[ethereum.id]: http(),
[holesky.id]: http(),
[bsc.id]: http(),
[bscTestnet.id]: http(),
[polygon.id]: http(),
[polygonMumbai.id]: http(),
[polygonAmoy.id]: http(),
},
connectors: [injected(), walletConnect(walletConnectOptions)],
})
Expand Down Expand Up @@ -244,10 +244,10 @@ await onClose()
- `canAddDevice`: 是否可以添加备份设备,类型为`boolean`
- `iCloudPasskeySupport`: 当前环境是否支持将 passkey 存储在 iCloud 中,类型为`boolean`
- `customChains`: 自定义显示的链,类型为`CustomChain[]`
- `customWallets`: 自定义显示的钱包,类型为`CustomWallet[]`
- `customWallets`: 自定义显示的钱包,类型为`string[]`
- `alias`: 当前登录的钱包地址设置的 .bit alias,类型为`string`
- `locale`: 当前使用的语言,类型为`string`
- `chainId`: 当使用 EVM 链钱包登录时表示对应的链 ID,类型为`number`
- `chainId`: 当使用 EVM 链钱包登录时表示对应的链 ID,类型为`number`当使用 TRON 钱包登录时表示对应的链 ID,类型为`string`

**示例**:

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Features

- **Supported Chains**: Ethereum, BNB Smart Chain, Polygon, TRON, Dogecoin.
- **Login Methods**: Passkey, Torus.
- **Login Methods**: WalletConnect, Passkey, Torus.
- **Industry Standards**: We rely on [viem](https://viem.sh/), [@wagmi/core](https://wagmi.sh/core/getting-started), and [@wagmi/connectors](https://wagmi.sh/core/api/connectors), which are among the most commonly used libraries in Web3.

[中文文档](README-CN.md)
Expand Down Expand Up @@ -62,7 +62,7 @@ To create a new `Wallet` object, you can use its constructor and provide the fol
```js
import { Wallet } from 'wallet-bridge'
import { createConfig, http } from '@wagmi/core'
import { bsc, bscTestnet, holesky, mainnet as ethereum, polygon, polygonMumbai } from '@wagmi/core/chains'
import { bsc, bscTestnet, holesky, mainnet as ethereum, polygon, polygonAmoy } from '@wagmi/core/chains'
import { injected, walletConnect } from '@wagmi/connectors'

const walletConnectOptions = {
Expand All @@ -76,14 +76,14 @@ const walletConnectOptions = {
}

const wagmiConfig = createConfig({
chains: [ethereum, holesky, bsc, bscTestnet, polygon, polygonMumbai],
chains: [ethereum, holesky, bsc, bscTestnet, polygon, polygonAmoy],
transports: {
[ethereum.id]: http(),
[holesky.id]: http(),
[bsc.id]: http(),
[bscTestnet.id]: http(),
[polygon.id]: http(),
[polygonMumbai.id]: http(),
[polygonAmoy.id]: http(),
},
connectors: [injected(), walletConnect(walletConnectOptions)],
})
Expand Down Expand Up @@ -244,10 +244,10 @@ await onClose()
- `canAddDevice`: Whether a backup device can be added or not, of type `boolean`.
- `iCloudPasskeySupport`: Whether the current environment supports storing the passkey in iCloud, of type `boolean`.
- `customChains`: Custom chains to be displayed, of type `CustomChain[]`.
- `customWallets`: Custom wallets to be displayed, of type `CustomWallet[]`.
- `customWallets`: Custom wallets to be displayed, of type `string[]`.
- `alias`: The .bit alias set for the currently logged-in wallet address, of type `string`.
- `locale`: The language currently in use, of type `string`.
- `chainId`: When logging in with an EVM chain wallet, it represents the corresponding chain ID, of type `number`.
- `chainId`: When logging in with an EVM chain wallet, it represents the corresponding chain ID, of type `number`. When logging in with an TRON wallet, it represents the corresponding chain ID, of type `string`.

**Example**:

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wallet-bridge",
"private": false,
"version": "1.0.0-beta.5",
"version": "1.0.0-beta.13",
"main": "./dist/wallet-bridge.umd.js",
"module": "./dist/wallet-bridge.es.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -32,7 +32,7 @@
"@lingui/detect-locale": "^4.5.0",
"@lingui/macro": "^4.5.0",
"@lingui/react": "^4.5.0",
"@metamask/eth-sig-util": "^6.0.0",
"@metamask/eth-sig-util": "^6.0.2",
"@tanstack/react-query": "^4.29.19",
"@toruslabs/torus-embed": "^4.1.3",
"@wagmi/connectors": "^4.1.18",
Expand Down
148 changes: 52 additions & 96 deletions src/lib/constant/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ export enum ChainId {
bsc = 56,
bscTestnet = 97,
polygon = 137,
polygonMumbai = 80001,
tron = 728126428,
tronNile = 3448148188,
polygonAmoy = 80002,
tron = '0x2b6653dc',
tronNile = '0xcd8690dc',
btc = 'livenet',
btcTestnet = 'testnet',
}

// SLIP-0044 : Registered coin types for BIP-0044 https://github.com/satoshilabs/slips/blob/master/slip-0044.md
Expand All @@ -18,51 +20,51 @@ export enum CoinType {
trx = '195',
ckb = '309',
bsc = '9006',
matic = '966',
pol = '966',
}

export const CoinTypeToChainIdMap: Record<string, number> = {
export const CoinTypeToChainIdMap: Record<string, number | string> = {
[CoinType.eth]: ChainId.eth,
[CoinType.bsc]: ChainId.bsc,
[CoinType.matic]: ChainId.polygon,
[CoinType.pol]: ChainId.polygon,
[CoinType.trx]: ChainId.tron,
[CoinType.btc]: ChainId.btc,
}

export const CoinTypeToTestNetChainIdMap: Record<string, number> = {
export const CoinTypeToTestNetChainIdMap: Record<string, number | string> = {
[CoinType.eth]: ChainId.ethHolesky,
[CoinType.bsc]: ChainId.bscTestnet,
[CoinType.matic]: ChainId.polygonMumbai,
[CoinType.pol]: ChainId.polygonAmoy,
[CoinType.trx]: ChainId.tronNile,
[CoinType.btc]: ChainId.btcTestnet,
}

export const CoinTypeToTorusHostMap: Record<string, string> = {
[CoinType.eth]: 'mainnet',
[CoinType.bsc]: 'bsc_mainnet',
[CoinType.matic]: 'matic',
[CoinType.pol]: 'pol',
}

export const CoinTypeToTorusHostTestNetMap: Record<string, string> = {
[CoinType.eth]: 'holesky',
[CoinType.bsc]: 'bsc_testnet',
[CoinType.matic]: 'mumbai',
}

export const CoinTypeToGenesisHash: Record<string, string> = {
[CoinType.doge]: '1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691',
[CoinType.pol]: 'amoy',
}

export const ChainIdToCoinTypeMap: Record<string, CoinType> = {
[ChainId.eth]: CoinType.eth,
[ChainId.bsc]: CoinType.bsc,
[ChainId.polygon]: CoinType.matic,
[ChainId.polygon]: CoinType.pol,
[ChainId.tron]: CoinType.trx,
[ChainId.btc]: CoinType.btc,
}

export const ChainIdToCoinTypeTestNetMap: Record<string, CoinType> = {
[ChainId.ethHolesky]: CoinType.eth,
[ChainId.bscTestnet]: CoinType.bsc,
[ChainId.polygonMumbai]: CoinType.matic,
[ChainId.polygonAmoy]: CoinType.pol,
[ChainId.tronNile]: CoinType.trx,
[ChainId.btcTestnet]: CoinType.btc,
}

export enum SIGN_TYPE {
Expand All @@ -75,6 +77,7 @@ export enum SIGN_TYPE {
ed25519,
doge,
webauthn,
btc,
}

export enum CustomChain {
Expand All @@ -83,6 +86,7 @@ export enum CustomChain {
bsc = 'BNB Smart Chain',
tron = 'TRON',
doge = 'Dogecoin',
btc = 'Bitcoin',
polygon = 'Polygon',
torus = 'Torus',
}
Expand Down Expand Up @@ -145,103 +149,55 @@ export const BSC: IMainChain = {

export const Polygon: IMainChain = {
name: CustomChain.polygon,
symbol: 'MATIC',
coinType: CoinType.matic,
symbol: 'POL',
coinType: CoinType.pol,
decimals: 18,
icon: 'polygon',
tokenId: 'polygon_matic',
tokenId: 'polygon_pol',
explorerTrx: 'https://polygonscan.com/tx/',
testExplorerTrx: 'https://mumbai.polygonscan.com/tx/',
testExplorerTrx: 'https://amoy.polygonscan.com/tx/',
}

export const BTC: IMainChain = {
// eslint-disable-next-line lingui/no-unlocalized-strings
name: 'Bitcoin',
symbol: 'BTC',
coinType: CoinType.btc,
decimals: 8,
icon: 'bitcoin',
tokenId: 'btc_btc',
explorerTrx: 'https://explorer.btc.com/btc/address/',
testExplorerTrx: '',
}
export const DOGE: IMainChain = {
name: CustomChain.doge,
symbol: 'DOGE',
coinType: CoinType.doge,
decimals: 8,
icon: 'dogecoin',
tokenId: 'doge_doge',
explorerTrx: 'https://dogechain.info/tx/',
testExplorerTrx: 'https://dogechain.info/tx/',
explorerTrx: 'https://blockchair.com/dogecoin/transaction/',
testExplorerTrx: 'https://blockexplorer.one/dogecoin/testnet/tx/',
}

export const BTC: IMainChain = {
name: CustomChain.btc,
symbol: 'BTC',
coinType: CoinType.btc,
decimals: 8,
icon: 'bitcoin',
tokenId: 'btc_btc',
explorerTrx: 'https://blockchair.com/bitcoin/transaction/',
testExplorerTrx: 'https://blockchair.com/bitcoin/testnet/transaction/',
}

export const CoinTypeToChainMap: Record<string, IMainChain> = {
[CoinType.eth]: ETH,
[CoinType.bsc]: BSC,
[CoinType.matic]: Polygon,
[CoinType.pol]: Polygon,
[CoinType.trx]: TRON,
[CoinType.doge]: DOGE,
}

export const ChainIdToChainInfoMap: Record<string, any> = {
[ChainId.eth]: {
// eslint-disable-next-line lingui/no-unlocalized-strings
networkName: 'Ethereum Mainnet',
symbol: 'ETH',
decimals: 18,
rpcUrl: 'https://mainnet.infura.io/v3/',
blockExplorerUrl: 'https://etherscan.io',
},
[ChainId.ethHolesky]: {
// eslint-disable-next-line lingui/no-unlocalized-strings
networkName: 'Ethereum Holesky Testnet',
symbol: 'ETH',
decimals: 18,
rpcUrl: 'https://rpc.ankr.com/eth_holesky/',
blockExplorerUrl: 'https://holesky.etherscan.io',
},
[ChainId.bsc]: {
// eslint-disable-next-line lingui/no-unlocalized-strings
networkName: 'Binance Smart Chain Mainnet',
symbol: 'BNB',
decimals: 18,
rpcUrl: 'https://bsc-dataseed1.binance.org',
blockExplorerUrl: 'https://bscscan.com',
},
[ChainId.bscTestnet]: {
// eslint-disable-next-line lingui/no-unlocalized-strings
networkName: 'Binance Smart Chain Testnet',
symbol: 'BNB',
decimals: 18,
rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545',
blockExplorerUrl: 'https://testnet.bscscan.com',
},
[ChainId.polygon]: {
// eslint-disable-next-line lingui/no-unlocalized-strings
networkName: 'Polygon Mainnet',
symbol: 'MATIC',
decimals: 18,
rpcUrl: 'https://polygon-rpc.com/',
blockExplorerUrl: 'https://polygonscan.com',
},
[ChainId.polygonMumbai]: {
// eslint-disable-next-line lingui/no-unlocalized-strings
networkName: 'Polygon Testnet Mumbai',
symbol: 'MATIC',
decimals: 18,
rpcUrl: 'https://matic-mumbai.chainstacklabs.com',
blockExplorerUrl: 'https://mumbai.polygonscan.com',
},
}

export enum CustomWallet {
metaMask = 'MetaMask',
trustWallet = 'TrustWallet',
imToken = 'imToken',
tokenPocket = 'TokenPocket',
oneKey = 'OneKey',
iToken = 'iToken',
tronLink = 'TronLink',
walletConnect = 'WalletConnect',
[CoinType.btc]: BTC,
[CoinType.ckb]: CKB,
}

export const CustomWallet: Record<string, string> = {
metaMask: 'MetaMask',
trustWallet: 'TrustWallet',
imToken: 'imToken',
tokenPocket: 'TokenPocket',
unisat: 'Unisat',
oneKey: 'OneKey',
iToken: 'iToken',
tronLink: 'TronLink',
walletConnect: 'WalletConnect',
}
2 changes: 1 addition & 1 deletion src/lib/constant/errno.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable lingui/no-unlocalized-strings */
import { ActionErrorCode } from 'connect-did-sdk'

const errno = {
Expand All @@ -12,6 +11,7 @@ const errno = {
metaMaskUserRejectedAccountAccess: -32603,
metaMaskReplacementTransactionUnderpriced: 'replacement transaction underpriced',
metaMaskTransactionHasBeenAborted: 'the transaction has been aborted',
metaMaskUserRejectedTheRequest: 'User rejected the request',
// WalletConnect
walletConnectUserRejectedTheTransaction: 'User rejected the transaction',
walletConnectInsufficientFundsForTransfer: 'insufficient funds for transfer',
Expand Down
1 change: 1 addition & 0 deletions src/lib/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum WalletProtocol {
tronLink = 'tronLink',
torus = 'torus',
tokenPocketUTXO = 'tokenPocketUTXO',
unisat = 'unisat',
walletConnect = 'walletConnect',
webAuthn = 'webAuthn',
}
Expand Down
Loading

0 comments on commit cbf56d0

Please sign in to comment.