@yeying-community/web3-bs 1.0.10 → 1.0.11
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/README.md +13 -2
- package/dist/auth/provider.d.ts +2 -1
- package/dist/auth/types.d.ts +7 -0
- package/dist/web3-bs.esm.js +20 -1
- package/dist/web3-bs.esm.js.map +1 -1
- package/dist/web3-bs.umd.js +20 -0
- package/dist/web3-bs.umd.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,12 +22,13 @@ npm install @yeying-community/web3-bs
|
|
|
22
22
|
|
|
23
23
|
- `getProvider` / `requireProvider`
|
|
24
24
|
- `watchProvider`
|
|
25
|
-
- `requestAccounts` / `getAccounts` / `getPreferredAccount` / `watchAccounts`
|
|
25
|
+
- `requestAccounts` / `focusPendingApproval` / `getAccounts` / `getPreferredAccount` / `watchAccounts`
|
|
26
26
|
- `getChainId` / `getBalance`
|
|
27
27
|
- `onAccountsChanged` / `onChainChanged`
|
|
28
28
|
- `classifyWalletError` / `isUserRejectedWalletAction` / `isWalletReconnectError`
|
|
29
29
|
|
|
30
30
|
`requestAccounts` 默认会复用同一 provider 上尚未完成的连接请求,避免用户重复点击时触发多个钱包授权弹窗。
|
|
31
|
+
当钱包已经存在待确认的连接、签名或解锁窗口时,可调用 `focusPendingApproval` 将该窗口重新拉到前台,而不是再发起一次新的请求。
|
|
31
32
|
|
|
32
33
|
### 2) SIWE + JWT
|
|
33
34
|
|
|
@@ -72,7 +73,17 @@ npm install @yeying-community/web3-bs
|
|
|
72
73
|
### 单后端登录(SIWE + JWT)
|
|
73
74
|
|
|
74
75
|
```ts
|
|
75
|
-
import {
|
|
76
|
+
import {
|
|
77
|
+
authFetch,
|
|
78
|
+
focusPendingApproval,
|
|
79
|
+
loginWithChallenge,
|
|
80
|
+
requestAccounts,
|
|
81
|
+
} from '@yeying-community/web3-bs';
|
|
82
|
+
|
|
83
|
+
const pending = await focusPendingApproval().catch(() => ({ focused: false }));
|
|
84
|
+
if (!pending.focused) {
|
|
85
|
+
await requestAccounts();
|
|
86
|
+
}
|
|
76
87
|
|
|
77
88
|
await loginWithChallenge({
|
|
78
89
|
baseUrl: 'http://localhost:3203/api/v1/public/auth',
|
package/dist/auth/provider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Eip1193Provider, ProviderDiscoveryOptions, ProviderInfo, RequestAccountsOptions, AccountSelection, PreferredAccountOptions, WatchAccountsOptions, AccountsChangedHandler, WatchProviderOptions, ProviderChangedHandler, WalletErrorInfo } from './types';
|
|
1
|
+
import { Eip1193Provider, ProviderDiscoveryOptions, ProviderInfo, RequestAccountsOptions, AccountSelection, PreferredAccountOptions, WatchAccountsOptions, AccountsChangedHandler, WatchProviderOptions, ProviderChangedHandler, WalletErrorInfo, FocusPendingApprovalResult } from './types';
|
|
2
2
|
export declare function isYeYingProvider(provider?: Eip1193Provider | null, info?: ProviderInfo): boolean;
|
|
3
3
|
export declare function getProvider(options?: ProviderDiscoveryOptions): Promise<Eip1193Provider | null>;
|
|
4
4
|
export declare function watchProvider(handler: ProviderChangedHandler, options?: WatchProviderOptions): () => void;
|
|
@@ -9,6 +9,7 @@ export declare function isUserRejectedWalletAction(error: unknown): boolean;
|
|
|
9
9
|
export declare function isWalletReconnectError(error: unknown): boolean;
|
|
10
10
|
export declare function requireProvider(options?: ProviderDiscoveryOptions): Promise<Eip1193Provider>;
|
|
11
11
|
export declare function requestAccounts(options?: RequestAccountsOptions): Promise<string[]>;
|
|
12
|
+
export declare function focusPendingApproval(provider?: Eip1193Provider): Promise<FocusPendingApprovalResult>;
|
|
12
13
|
export declare function getAccounts(provider?: Eip1193Provider): Promise<string[]>;
|
|
13
14
|
export declare function getChainId(provider?: Eip1193Provider): Promise<string | null>;
|
|
14
15
|
export declare function getPreferredAccount(options?: PreferredAccountOptions): Promise<AccountSelection>;
|
package/dist/auth/types.d.ts
CHANGED
|
@@ -51,6 +51,13 @@ export interface RequestAccountsOptions {
|
|
|
51
51
|
provider?: Eip1193Provider;
|
|
52
52
|
dedupe?: boolean;
|
|
53
53
|
}
|
|
54
|
+
export type FocusPendingApprovalResult = {
|
|
55
|
+
focused: boolean;
|
|
56
|
+
type: string | null;
|
|
57
|
+
requestId?: string | null;
|
|
58
|
+
origin?: string;
|
|
59
|
+
tabId?: number | null;
|
|
60
|
+
};
|
|
54
61
|
export type AccountSelection = {
|
|
55
62
|
account: string | null;
|
|
56
63
|
accounts: string[];
|
package/dist/web3-bs.esm.js
CHANGED
|
@@ -294,6 +294,25 @@ async function requestAccounts(options = {}) {
|
|
|
294
294
|
requestAccountsInFlight.delete(provider);
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
+
async function focusPendingApproval(provider) {
|
|
298
|
+
const p = provider || (await requireProvider());
|
|
299
|
+
const result = await p.request({
|
|
300
|
+
method: 'wallet_focusPendingApproval',
|
|
301
|
+
});
|
|
302
|
+
if (!result || typeof result !== 'object') {
|
|
303
|
+
return { focused: false, type: null };
|
|
304
|
+
}
|
|
305
|
+
const payload = result;
|
|
306
|
+
return {
|
|
307
|
+
focused: Boolean(payload.focused),
|
|
308
|
+
type: typeof payload.type === 'string' ? payload.type : null,
|
|
309
|
+
requestId: typeof payload.requestId === 'string' ? payload.requestId : null,
|
|
310
|
+
origin: typeof payload.origin === 'string' ? payload.origin : '',
|
|
311
|
+
tabId: typeof payload.tabId === 'number' && Number.isFinite(payload.tabId)
|
|
312
|
+
? payload.tabId
|
|
313
|
+
: null,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
297
316
|
async function getAccounts(provider) {
|
|
298
317
|
const p = provider || (await requireProvider());
|
|
299
318
|
const accounts = (await p.request({ method: 'eth_accounts' }));
|
|
@@ -2166,5 +2185,5 @@ async function initDappSession(options) {
|
|
|
2166
2185
|
return result;
|
|
2167
2186
|
}
|
|
2168
2187
|
|
|
2169
|
-
export { WebDavClient, authCentralUcanFetch, authFetch, authUcanFetch, classifyWalletError, clearAccessToken, clearCentralSessionToken, clearUcanSession, createAndIssueCentralUcan, createCentralSession, createDelegationUcan, createInvocationUcan, createRootUcan, createUcanSession, createWebDavClient, deriveAppIdFromHost, deriveAppIdFromLocation, getAccessToken, getAccounts, getBalance, getCapabilityAction, getCapabilityResource, getCentralIssuerInfo, getCentralSessionToken, getChainId, getOrCreateUcanRoot, getPreferredAccount, getProvider, getStoredUcanRoot, getUcanSession, getWalletErrorCode, getWalletErrorMessage, initDappSession, initWebDavStorage, isUserRejectedWalletAction, isWalletReconnectError, isYeYingProvider, issueCentralUcan, loginWithChallenge, logout, normalizeAppHostnameForAppId, normalizeUcanCapabilities, normalizeUcanCapability, onAccountsChanged, onChainChanged, refreshAccessToken, requestAccounts, requireProvider, setAccessToken, setCentralSessionToken, signMessage, storeUcanRoot, watchAccounts, watchProvider };
|
|
2188
|
+
export { WebDavClient, authCentralUcanFetch, authFetch, authUcanFetch, classifyWalletError, clearAccessToken, clearCentralSessionToken, clearUcanSession, createAndIssueCentralUcan, createCentralSession, createDelegationUcan, createInvocationUcan, createRootUcan, createUcanSession, createWebDavClient, deriveAppIdFromHost, deriveAppIdFromLocation, focusPendingApproval, getAccessToken, getAccounts, getBalance, getCapabilityAction, getCapabilityResource, getCentralIssuerInfo, getCentralSessionToken, getChainId, getOrCreateUcanRoot, getPreferredAccount, getProvider, getStoredUcanRoot, getUcanSession, getWalletErrorCode, getWalletErrorMessage, initDappSession, initWebDavStorage, isUserRejectedWalletAction, isWalletReconnectError, isYeYingProvider, issueCentralUcan, loginWithChallenge, logout, normalizeAppHostnameForAppId, normalizeUcanCapabilities, normalizeUcanCapability, onAccountsChanged, onChainChanged, refreshAccessToken, requestAccounts, requireProvider, setAccessToken, setCentralSessionToken, signMessage, storeUcanRoot, watchAccounts, watchProvider };
|
|
2170
2189
|
//# sourceMappingURL=web3-bs.esm.js.map
|