@yeying-community/web3-bs 1.0.13 → 1.0.14
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 +9 -1
- package/dist/auth/provider.d.ts +2 -1
- package/dist/auth/types.d.ts +29 -0
- package/dist/web3-bs.esm.js +55 -1
- package/dist/web3-bs.esm.js.map +1 -1
- package/dist/web3-bs.umd.js +55 -0
- package/dist/web3-bs.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/web3-bs.umd.js
CHANGED
|
@@ -79,6 +79,17 @@
|
|
|
79
79
|
}
|
|
80
80
|
return accounts[0] || null;
|
|
81
81
|
}
|
|
82
|
+
function normalizeAccount(account) {
|
|
83
|
+
const normalized = (account || '').trim();
|
|
84
|
+
return normalized || null;
|
|
85
|
+
}
|
|
86
|
+
function isSameAccount(left, right) {
|
|
87
|
+
const normalizedLeft = normalizeAccount(left);
|
|
88
|
+
const normalizedRight = normalizeAccount(right);
|
|
89
|
+
return Boolean(normalizedLeft &&
|
|
90
|
+
normalizedRight &&
|
|
91
|
+
normalizedLeft.toLowerCase() === normalizedRight.toLowerCase());
|
|
92
|
+
}
|
|
82
93
|
function isYeYingProvider(provider, info) {
|
|
83
94
|
if (!provider)
|
|
84
95
|
return false;
|
|
@@ -342,6 +353,49 @@
|
|
|
342
353
|
writeStoredAccount(storageKey, account);
|
|
343
354
|
return { account, accounts };
|
|
344
355
|
}
|
|
356
|
+
async function resolveWalletAccount(options = {}) {
|
|
357
|
+
const provider = options.provider || (await requireProvider());
|
|
358
|
+
let accounts = await getAccounts(provider);
|
|
359
|
+
if (accounts.length === 0 && options.autoConnect) {
|
|
360
|
+
accounts = await requestAccounts({ provider });
|
|
361
|
+
}
|
|
362
|
+
const expectedAccount = normalizeAccount(options.expectedAccount);
|
|
363
|
+
const walletAccount = normalizeAccount(accounts[0]);
|
|
364
|
+
if (!walletAccount) {
|
|
365
|
+
return {
|
|
366
|
+
status: 'unavailable',
|
|
367
|
+
account: null,
|
|
368
|
+
walletAccount: null,
|
|
369
|
+
expectedAccount,
|
|
370
|
+
accounts,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
if (!expectedAccount) {
|
|
374
|
+
return {
|
|
375
|
+
status: 'wallet',
|
|
376
|
+
account: walletAccount,
|
|
377
|
+
walletAccount,
|
|
378
|
+
expectedAccount: null,
|
|
379
|
+
accounts,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
if (isSameAccount(expectedAccount, walletAccount)) {
|
|
383
|
+
return {
|
|
384
|
+
status: 'matched',
|
|
385
|
+
account: walletAccount,
|
|
386
|
+
walletAccount,
|
|
387
|
+
expectedAccount,
|
|
388
|
+
accounts,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
status: 'mismatch',
|
|
393
|
+
account: null,
|
|
394
|
+
walletAccount,
|
|
395
|
+
expectedAccount,
|
|
396
|
+
accounts,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
345
399
|
function watchAccounts(provider, handler, options = {}) {
|
|
346
400
|
const storageKey = options.storageKey || DEFAULT_ACCOUNT_STORAGE_KEY;
|
|
347
401
|
const preferStored = options.preferStored !== false;
|
|
@@ -2541,6 +2595,7 @@
|
|
|
2541
2595
|
exports.refreshAccessToken = refreshAccessToken;
|
|
2542
2596
|
exports.requestAccounts = requestAccounts;
|
|
2543
2597
|
exports.requireProvider = requireProvider;
|
|
2598
|
+
exports.resolveWalletAccount = resolveWalletAccount;
|
|
2544
2599
|
exports.setAccessToken = setAccessToken;
|
|
2545
2600
|
exports.setCentralSessionToken = setCentralSessionToken;
|
|
2546
2601
|
exports.signMessage = signMessage;
|