@binance/w3w-multichain-connector 1.0.1 → 1.0.3
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/dist/index.d.ts +15 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/enum.ts +3 -3
- package/src/type.ts +16 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3';
|
|
2
2
|
|
|
3
|
-
declare
|
|
3
|
+
declare enum ChainType {
|
|
4
4
|
EVM = "EVM",
|
|
5
5
|
SOL = "SOL"
|
|
6
6
|
}
|
|
@@ -8,11 +8,11 @@ declare const enum ChainType {
|
|
|
8
8
|
* privateKey:私钥钱包
|
|
9
9
|
* hd: 助记词钱包
|
|
10
10
|
*/
|
|
11
|
-
declare
|
|
11
|
+
declare enum WalletType {
|
|
12
12
|
privateKey = "privateKey",
|
|
13
13
|
seedPhrase = "hd"
|
|
14
14
|
}
|
|
15
|
-
declare
|
|
15
|
+
declare enum Features {
|
|
16
16
|
requestConnect = "requestConnect",
|
|
17
17
|
checkConnectedWallet = "checkConnectedWallet",
|
|
18
18
|
disconnect = "disconnect",
|
|
@@ -37,19 +37,29 @@ interface IConnectedWallet {
|
|
|
37
37
|
walletType: WalletType;
|
|
38
38
|
addressList: {
|
|
39
39
|
address: string;
|
|
40
|
-
|
|
40
|
+
binanceChainId: string;
|
|
41
41
|
}[];
|
|
42
42
|
}
|
|
43
43
|
interface WalletEvents {
|
|
44
44
|
walletLockedChanged: (isLocked: boolean) => void;
|
|
45
45
|
autoSignEnabledChanged: (isEnabled: boolean) => void;
|
|
46
|
+
connectedWalletsChanged: (connectedWallets: IConnectedWallet[]) => void;
|
|
46
47
|
connectedChainIdChanged: (binanceChainId: string) => void;
|
|
47
48
|
}
|
|
48
49
|
interface IWallet extends EventEmitter<WalletEvents> {
|
|
50
|
+
requestConnect(binanceChainIds: string[]): Promise<IConnectedWallet[]>;
|
|
51
|
+
/**
|
|
52
|
+
* 检查当前连接的钱包
|
|
53
|
+
* 用户的当前活跃钱包会出现在数组的第一个
|
|
54
|
+
*/
|
|
55
|
+
checkConnectedWallet(): Promise<IConnectedWallet[]>;
|
|
49
56
|
getWalletInfo(address: string, binanceChainId: string): Promise<IConnectedWallet | null>;
|
|
57
|
+
/**
|
|
58
|
+
* 断开所有连接的钱包
|
|
59
|
+
*/
|
|
60
|
+
disconnect(): Promise<void>;
|
|
50
61
|
/**
|
|
51
62
|
* 切换网络,若当前活跃钱包不支持该网络,会报4001用户拒绝
|
|
52
|
-
* 这个方法用于异构链如EVM和solana之间的切换
|
|
53
63
|
* @param binanceChainId 请求网络的binanceChainId
|
|
54
64
|
*/
|
|
55
65
|
switchChain(binanceChainId: string): Promise<void>;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/enum.ts","../src/getMultichainWallet.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../src/enum.ts","../src/getMultichainWallet.ts"],"sourcesContent":["export enum ChainType {\n EVM = 'EVM',\n SOL = 'SOL',\n}\n\n/**\n * privateKey:私钥钱包\n * hd: 助记词钱包\n */\nexport enum WalletType {\n privateKey = 'privateKey',\n seedPhrase = 'hd',\n}\n\nexport enum Features {\n requestConnect = 'requestConnect',\n checkConnectedWallet = 'checkConnectedWallet',\n disconnect = 'disconnect',\n switchChain = 'switchChain',\n requestAutoSign = 'requestAutoSign',\n eventWalletLockedChanged = 'eventWalletLockedChanged',\n eventAutoSignEnabledChanged = 'eventAutoSignEnabledChanged',\n eventConnectedWalletsChanged = 'eventConnectedWalletsChanged',\n eventConnectedChainIdChanged = 'eventConnectedChainIdChanged',\n}\n","import { Features } from './enum'\nimport type { IWallet } from './type'\n\nexport const checkExtensionInstalled = () => {\n try {\n return !!(window as any)?.binancew3w?.isExtension\n } catch (error) {\n return false\n }\n}\n\n/**\n * 检查当前用户安装的插件是否支持\n */\nexport const checkExtensionSupported = (feature: Features) => {\n const wallet = getInjectedWallet()\n if (!wallet) {\n return false\n }\n return wallet.checkSupportFeature(feature)\n}\n\nconst getInjectedWallet = () => {\n const isInstalled = checkExtensionInstalled()\n if (!isInstalled) {\n return null\n }\n return (window as any).binancew3w?.wallet\n}\n\nexport const getMultichainWallet = (): IWallet | null => {\n return getInjectedWallet()\n}\n"],"mappings":"AAAO,IAAKA,OACVA,EAAA,IAAM,MACNA,EAAA,IAAM,MAFIA,OAAA,IASAC,OACVA,EAAA,WAAa,aACbA,EAAA,WAAa,KAFHA,OAAA,IAKAC,OACVA,EAAA,eAAiB,iBACjBA,EAAA,qBAAuB,uBACvBA,EAAA,WAAa,aACbA,EAAA,YAAc,cACdA,EAAA,gBAAkB,kBAClBA,EAAA,yBAA2B,2BAC3BA,EAAA,4BAA8B,8BAC9BA,EAAA,6BAA+B,+BAC/BA,EAAA,6BAA+B,+BATrBA,OAAA,ICXL,IAAMC,EAA0B,IAAM,CAC3C,GAAI,CACF,MAAO,CAAC,CAAE,QAAgB,YAAY,WACxC,MAAE,CACA,MAAO,EACT,CACF,EAKaC,EAA2BC,GAAsB,CAC5D,IAAMC,EAASC,EAAkB,EACjC,OAAKD,EAGEA,EAAO,oBAAoBD,CAAO,EAFhC,EAGX,EAEME,EAAoB,IACJJ,EAAwB,EAIpC,OAAe,YAAY,OAF1B,KAKEK,EAAsB,IAC1BD,EAAkB","names":["ChainType","WalletType","Features","checkExtensionInstalled","checkExtensionSupported","feature","wallet","getInjectedWallet","getMultichainWallet"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@binance/w3w-multichain-connector",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A multichain connector for Binance Wallet",
|
|
5
|
-
"main": "dist/index.
|
|
5
|
+
"main": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"keywords": [],
|
|
8
8
|
"author": "Binance",
|
package/src/enum.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export enum ChainType {
|
|
2
2
|
EVM = 'EVM',
|
|
3
3
|
SOL = 'SOL',
|
|
4
4
|
}
|
|
@@ -7,12 +7,12 @@ export const enum ChainType {
|
|
|
7
7
|
* privateKey:私钥钱包
|
|
8
8
|
* hd: 助记词钱包
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export enum WalletType {
|
|
11
11
|
privateKey = 'privateKey',
|
|
12
12
|
seedPhrase = 'hd',
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export enum Features {
|
|
16
16
|
requestConnect = 'requestConnect',
|
|
17
17
|
checkConnectedWallet = 'checkConnectedWallet',
|
|
18
18
|
disconnect = 'disconnect',
|
package/src/type.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type EventEmitter from 'eventemitter3'
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { WalletType } from './enum'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 链接的钱包
|
|
@@ -19,25 +19,38 @@ export interface IConnectedWallet {
|
|
|
19
19
|
|
|
20
20
|
addressList: {
|
|
21
21
|
address: string
|
|
22
|
-
|
|
22
|
+
binanceChainId: string
|
|
23
23
|
}[]
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export interface WalletEvents {
|
|
27
27
|
walletLockedChanged: (isLocked: boolean) => void
|
|
28
28
|
autoSignEnabledChanged: (isEnabled: boolean) => void
|
|
29
|
+
connectedWalletsChanged: (connectedWallets: IConnectedWallet[]) => void
|
|
29
30
|
connectedChainIdChanged: (binanceChainId: string) => void
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export interface IWallet extends EventEmitter<WalletEvents> {
|
|
34
|
+
requestConnect(binanceChainIds: string[]): Promise<IConnectedWallet[]>
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 检查当前连接的钱包
|
|
38
|
+
* 用户的当前活跃钱包会出现在数组的第一个
|
|
39
|
+
*/
|
|
40
|
+
checkConnectedWallet(): Promise<IConnectedWallet[]>
|
|
41
|
+
|
|
33
42
|
getWalletInfo(
|
|
34
43
|
address: string,
|
|
35
44
|
binanceChainId: string
|
|
36
45
|
): Promise<IConnectedWallet | null>
|
|
37
46
|
|
|
47
|
+
/**
|
|
48
|
+
* 断开所有连接的钱包
|
|
49
|
+
*/
|
|
50
|
+
disconnect(): Promise<void>
|
|
51
|
+
|
|
38
52
|
/**
|
|
39
53
|
* 切换网络,若当前活跃钱包不支持该网络,会报4001用户拒绝
|
|
40
|
-
* 这个方法用于异构链如EVM和solana之间的切换
|
|
41
54
|
* @param binanceChainId 请求网络的binanceChainId
|
|
42
55
|
*/
|
|
43
56
|
switchChain(binanceChainId: string): Promise<void>
|