@aurum-sdk/core 0.2.6 → 0.2.8
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 +0 -6
- package/dist/Aurum-B0Okb4Qv.d.mts +294 -0
- package/dist/Aurum-B0Okb4Qv.d.ts +294 -0
- package/dist/{chunk-UPYYZG5D.mjs → chunk-GMFEFDGS.mjs} +2 -2
- package/dist/{chunk-KD3A4VYB.js → chunk-K64T6WW3.js} +2 -2
- package/dist/index.d.mts +55 -268
- package/dist/index.d.ts +55 -268
- package/dist/index.js +399 -236
- package/dist/index.mjs +330 -167
- package/dist/widgets.d.mts +1 -1
- package/dist/widgets.d.ts +1 -1
- package/dist/widgets.js +12 -12
- package/dist/widgets.mjs +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
useAurumStore,
|
|
17
17
|
useNavigation,
|
|
18
18
|
waitForStoreHydration
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-GMFEFDGS.mjs";
|
|
20
20
|
import "./chunk-DRID67T7.mjs";
|
|
21
21
|
import {
|
|
22
22
|
init_polyfills
|
|
@@ -1656,6 +1656,81 @@ var RpcProvider = class {
|
|
|
1656
1656
|
}
|
|
1657
1657
|
};
|
|
1658
1658
|
|
|
1659
|
+
// src/errors.ts
|
|
1660
|
+
init_polyfills();
|
|
1661
|
+
var AurumError = class extends Error {
|
|
1662
|
+
constructor(message, cause) {
|
|
1663
|
+
super(message);
|
|
1664
|
+
this.name = this.constructor.name;
|
|
1665
|
+
this.cause = cause;
|
|
1666
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1669
|
+
var UserRejectedError = class extends AurumError {
|
|
1670
|
+
constructor() {
|
|
1671
|
+
super(...arguments);
|
|
1672
|
+
this.code = "USER_REJECTED";
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
var ChainSwitchRejectedError = class extends AurumError {
|
|
1676
|
+
constructor() {
|
|
1677
|
+
super(...arguments);
|
|
1678
|
+
this.code = "CHAIN_SWITCH_REJECTED";
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
var WalletNotInstalledError = class extends AurumError {
|
|
1682
|
+
constructor(walletId, cause) {
|
|
1683
|
+
super(`${walletId} is not installed`, cause);
|
|
1684
|
+
this.walletId = walletId;
|
|
1685
|
+
this.code = "WALLET_NOT_INSTALLED";
|
|
1686
|
+
}
|
|
1687
|
+
};
|
|
1688
|
+
var WalletNotConfiguredError = class extends AurumError {
|
|
1689
|
+
constructor(walletId, cause) {
|
|
1690
|
+
super(`${walletId} is not configured`, cause);
|
|
1691
|
+
this.walletId = walletId;
|
|
1692
|
+
this.code = "WALLET_NOT_CONFIGURED";
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
var WalletExcludedError = class extends AurumError {
|
|
1696
|
+
constructor(walletId, cause) {
|
|
1697
|
+
super(`${walletId} is excluded from wallet options`, cause);
|
|
1698
|
+
this.walletId = walletId;
|
|
1699
|
+
this.code = "WALLET_EXCLUDED";
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
var ChainNotSupportedError = class extends AurumError {
|
|
1703
|
+
constructor() {
|
|
1704
|
+
super(...arguments);
|
|
1705
|
+
this.code = "CHAIN_NOT_SUPPORTED";
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
var InvalidConfigError = class extends AurumError {
|
|
1709
|
+
constructor() {
|
|
1710
|
+
super(...arguments);
|
|
1711
|
+
this.code = "INVALID_CONFIG";
|
|
1712
|
+
}
|
|
1713
|
+
};
|
|
1714
|
+
var ConnectionError = class extends AurumError {
|
|
1715
|
+
constructor() {
|
|
1716
|
+
super(...arguments);
|
|
1717
|
+
this.code = "CONNECTION_FAILED";
|
|
1718
|
+
}
|
|
1719
|
+
};
|
|
1720
|
+
var USER_REJECTION_REGEX = /user (rejected|denied|cancel(l?)ed)/i;
|
|
1721
|
+
function normalizeError(err, context) {
|
|
1722
|
+
if (err instanceof AurumError) return err;
|
|
1723
|
+
const rawCode = err?.code;
|
|
1724
|
+
const rawMessage = err?.message;
|
|
1725
|
+
const message = typeof rawMessage === "string" ? rawMessage : "Unknown error";
|
|
1726
|
+
const isRejectionCode = rawCode === 4001 || rawCode === "4001" || rawCode === "ACTION_REJECTED";
|
|
1727
|
+
const isRejectionMessage = typeof rawMessage === "string" && USER_REJECTION_REGEX.test(rawMessage);
|
|
1728
|
+
if (isRejectionCode || isRejectionMessage) {
|
|
1729
|
+
return context?.operation === "switchChain" ? new ChainSwitchRejectedError(message, err) : new UserRejectedError(message, err);
|
|
1730
|
+
}
|
|
1731
|
+
return new ConnectionError(message, err);
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1659
1734
|
// src/AurumCore.ts
|
|
1660
1735
|
var _AurumCore = class _AurumCore {
|
|
1661
1736
|
constructor(config) {
|
|
@@ -1664,6 +1739,26 @@ var _AurumCore = class _AurumCore {
|
|
|
1664
1739
|
this.userInfo = void 0;
|
|
1665
1740
|
this.connectedWalletAdapter = null;
|
|
1666
1741
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
1742
|
+
// EIP-1193 event listener passthroughs. Delegates to the proxy rpcProvider so listeners survive
|
|
1743
|
+
// provider swaps (connect/disconnect) without consumers needing to re-register.
|
|
1744
|
+
this.on = (event, listener) => {
|
|
1745
|
+
this.rpcProvider.on(
|
|
1746
|
+
event,
|
|
1747
|
+
listener
|
|
1748
|
+
);
|
|
1749
|
+
};
|
|
1750
|
+
this.off = (event, listener) => {
|
|
1751
|
+
this.rpcProvider.removeListener(
|
|
1752
|
+
event,
|
|
1753
|
+
listener
|
|
1754
|
+
);
|
|
1755
|
+
};
|
|
1756
|
+
this.removeListener = (event, listener) => {
|
|
1757
|
+
this.rpcProvider.removeListener(
|
|
1758
|
+
event,
|
|
1759
|
+
listener
|
|
1760
|
+
);
|
|
1761
|
+
};
|
|
1667
1762
|
if (_AurumCore.instance) {
|
|
1668
1763
|
const incoming = _AurumCore.serializeConfig(config);
|
|
1669
1764
|
if (incoming !== null && incoming !== _AurumCore.storedConfigJson) {
|
|
@@ -1717,79 +1812,87 @@ var _AurumCore = class _AurumCore {
|
|
|
1717
1812
|
return this.excludedWallets;
|
|
1718
1813
|
}
|
|
1719
1814
|
async connect(walletId) {
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
if (this.userInfo?.publicAddress && this.connectedWalletAdapter?.getProvider()) {
|
|
1725
|
-
if (!walletId || this.userInfo.walletId === walletId) {
|
|
1726
|
-
return this.userInfo.publicAddress;
|
|
1727
|
-
}
|
|
1728
|
-
await this.disconnect();
|
|
1729
|
-
}
|
|
1730
|
-
let adapter = null;
|
|
1731
|
-
let result;
|
|
1732
|
-
if (walletId) {
|
|
1733
|
-
if (this.excludedWallets.has(walletId)) {
|
|
1734
|
-
throw new Error(`${walletId} is excluded from wallet options`);
|
|
1815
|
+
try {
|
|
1816
|
+
await this.whenReady();
|
|
1817
|
+
if (walletId === "email") {
|
|
1818
|
+
throw new InvalidConfigError("Use emailAuthStart() and emailAuthVerify() for email wallet connections");
|
|
1735
1819
|
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1820
|
+
if (this.userInfo?.publicAddress && this.connectedWalletAdapter?.getProvider()) {
|
|
1821
|
+
if (!walletId || this.userInfo.walletId === walletId) {
|
|
1822
|
+
return this.userInfo.publicAddress;
|
|
1823
|
+
}
|
|
1824
|
+
await this.disconnect();
|
|
1739
1825
|
}
|
|
1740
|
-
|
|
1741
|
-
|
|
1826
|
+
let adapter = null;
|
|
1827
|
+
let result;
|
|
1828
|
+
if (walletId) {
|
|
1829
|
+
if (this.excludedWallets.has(walletId)) {
|
|
1830
|
+
throw new WalletExcludedError(walletId);
|
|
1831
|
+
}
|
|
1832
|
+
adapter = this.wallets.find((w) => w.id === walletId) || null;
|
|
1833
|
+
if (!adapter) {
|
|
1834
|
+
throw new WalletNotConfiguredError(walletId);
|
|
1835
|
+
}
|
|
1836
|
+
if (walletId === WalletId.WalletConnect && adapter.openModal) {
|
|
1837
|
+
result = await adapter.openModal();
|
|
1838
|
+
} else {
|
|
1839
|
+
if (!adapter.isInstalled()) {
|
|
1840
|
+
throw new WalletNotInstalledError(adapter.name);
|
|
1841
|
+
}
|
|
1842
|
+
result = await adapter.connect();
|
|
1843
|
+
}
|
|
1742
1844
|
} else {
|
|
1743
|
-
|
|
1744
|
-
|
|
1845
|
+
const displayedWallets = this.wallets.filter((w) => !this.excludedWallets.has(w.id));
|
|
1846
|
+
const modalResult = await renderConnectModal({ displayedWallets, brandConfig: this.brandConfig });
|
|
1847
|
+
if (!modalResult) {
|
|
1848
|
+
sentryLogger.error("Missing modal result");
|
|
1849
|
+
throw new ConnectionError("Missing modal result");
|
|
1745
1850
|
}
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
sentryLogger.error("Missing modal result");
|
|
1753
|
-
throw new Error("Missing modal result");
|
|
1851
|
+
adapter = this.wallets.find((w) => w.id === modalResult.walletId) || null;
|
|
1852
|
+
if (!adapter) {
|
|
1853
|
+
sentryLogger.error(`Selected wallet adapter not found: ${modalResult.walletId}`);
|
|
1854
|
+
throw new ConnectionError("Selected wallet adapter not found");
|
|
1855
|
+
}
|
|
1856
|
+
result = modalResult;
|
|
1754
1857
|
}
|
|
1755
|
-
|
|
1756
|
-
if (!
|
|
1757
|
-
sentryLogger.error(`
|
|
1758
|
-
throw new
|
|
1858
|
+
const provider = result.provider ?? adapter.getProvider();
|
|
1859
|
+
if (!provider) {
|
|
1860
|
+
sentryLogger.error(`Error fetching provider on login: ${adapter.id}`);
|
|
1861
|
+
throw new ConnectionError("Error fetching provider. Please try again.");
|
|
1759
1862
|
}
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
this.emitConnect(chainId);
|
|
1780
|
-
this.emitAccountsChanged([checksumAdr]);
|
|
1781
|
-
sentryLogger.info(`Wallet connected: ${adapter.id} (${walletId ? "headless" : "modal"})`);
|
|
1782
|
-
return checksumAdr;
|
|
1863
|
+
const checksumAdr = checksumAddress(result.address);
|
|
1864
|
+
this.connectedWalletAdapter = adapter;
|
|
1865
|
+
this.updateProvider(provider);
|
|
1866
|
+
this.userInfo = {
|
|
1867
|
+
publicAddress: checksumAdr,
|
|
1868
|
+
walletName: adapter.name,
|
|
1869
|
+
walletId: adapter.id,
|
|
1870
|
+
email: result.email
|
|
1871
|
+
};
|
|
1872
|
+
this.persistConnectionState(adapter, checksumAdr, result.email);
|
|
1873
|
+
this.setInternalAccountChangeListener(adapter);
|
|
1874
|
+
const chainId = await provider.request({ method: "eth_chainId" });
|
|
1875
|
+
this.emitConnect(chainId);
|
|
1876
|
+
this.emitAccountsChanged([checksumAdr]);
|
|
1877
|
+
sentryLogger.info(`Wallet connected: ${adapter.id} (${walletId ? "headless" : "modal"})`);
|
|
1878
|
+
return checksumAdr;
|
|
1879
|
+
} catch (err) {
|
|
1880
|
+
throw normalizeError(err, { operation: "connect" });
|
|
1881
|
+
}
|
|
1783
1882
|
}
|
|
1784
1883
|
async disconnect() {
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
this.connectedWalletAdapter
|
|
1788
|
-
|
|
1884
|
+
try {
|
|
1885
|
+
await this.whenReady();
|
|
1886
|
+
if (this.connectedWalletAdapter) {
|
|
1887
|
+
this.connectedWalletAdapter.removeListeners();
|
|
1888
|
+
await this.connectedWalletAdapter.disconnect();
|
|
1889
|
+
}
|
|
1890
|
+
this.resetConnectionState();
|
|
1891
|
+
this.emitDisconnect();
|
|
1892
|
+
this.emitAccountsChanged([]);
|
|
1893
|
+
} catch (err) {
|
|
1894
|
+
throw normalizeError(err, { operation: "disconnect" });
|
|
1789
1895
|
}
|
|
1790
|
-
this.resetConnectionState();
|
|
1791
|
-
this.emitDisconnect();
|
|
1792
|
-
this.emitAccountsChanged([]);
|
|
1793
1896
|
}
|
|
1794
1897
|
async getUserInfo() {
|
|
1795
1898
|
await this.whenReady();
|
|
@@ -1802,30 +1905,34 @@ var _AurumCore = class _AurumCore {
|
|
|
1802
1905
|
);
|
|
1803
1906
|
}
|
|
1804
1907
|
async handleWidgetConnection(result) {
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1908
|
+
try {
|
|
1909
|
+
await this.whenReady();
|
|
1910
|
+
const adapter = this.wallets.find((w) => w.id === result.walletId) || null;
|
|
1911
|
+
if (!adapter) throw new ConnectionError("Selected wallet adapter not found");
|
|
1912
|
+
const provider = result.provider ?? adapter.getProvider();
|
|
1913
|
+
if (!provider) {
|
|
1914
|
+
sentryLogger.error(`Error fetching provider on widget login: ${result?.walletId}`);
|
|
1915
|
+
throw new ConnectionError("Error fetching provider. Please try again.");
|
|
1916
|
+
}
|
|
1917
|
+
const checksumAdr = checksumAddress(result.address);
|
|
1918
|
+
this.connectedWalletAdapter = adapter;
|
|
1919
|
+
this.updateProvider(provider);
|
|
1920
|
+
this.userInfo = {
|
|
1921
|
+
publicAddress: checksumAdr,
|
|
1922
|
+
walletName: adapter.name,
|
|
1923
|
+
walletId: adapter.id,
|
|
1924
|
+
email: result.email
|
|
1925
|
+
};
|
|
1926
|
+
this.persistConnectionState(adapter, checksumAdr, result.email);
|
|
1927
|
+
this.setInternalAccountChangeListener(adapter);
|
|
1928
|
+
const chainId = await provider.request({ method: "eth_chainId" });
|
|
1929
|
+
this.emitConnect(chainId);
|
|
1930
|
+
this.emitAccountsChanged([checksumAdr]);
|
|
1931
|
+
sentryLogger.info(`Wallet connected: ${adapter.id} (widget)`);
|
|
1932
|
+
return this.userInfo;
|
|
1933
|
+
} catch (err) {
|
|
1934
|
+
throw normalizeError(err, { operation: "connect" });
|
|
1935
|
+
}
|
|
1829
1936
|
}
|
|
1830
1937
|
async getChainId() {
|
|
1831
1938
|
await this.whenReady();
|
|
@@ -1833,13 +1940,17 @@ var _AurumCore = class _AurumCore {
|
|
|
1833
1940
|
return Number(chainId);
|
|
1834
1941
|
}
|
|
1835
1942
|
async switchChain(chainId, chain) {
|
|
1836
|
-
await this.whenReady();
|
|
1837
|
-
const hexChainId = normalizeChainId(chainId);
|
|
1838
1943
|
try {
|
|
1839
|
-
await this.
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1944
|
+
await this.whenReady();
|
|
1945
|
+
const hexChainId = normalizeChainId(chainId);
|
|
1946
|
+
try {
|
|
1947
|
+
await this.attemptSwitchChain(hexChainId);
|
|
1948
|
+
} catch (switchError) {
|
|
1949
|
+
if (!isChainNotAddedError(switchError) || !chain) throw switchError;
|
|
1950
|
+
await this.handleMissingChain(hexChainId, chain);
|
|
1951
|
+
}
|
|
1952
|
+
} catch (err) {
|
|
1953
|
+
throw normalizeError(err, { operation: "switchChain" });
|
|
1843
1954
|
}
|
|
1844
1955
|
}
|
|
1845
1956
|
updateBrandConfig(newConfig) {
|
|
@@ -1871,13 +1982,17 @@ var _AurumCore = class _AurumCore {
|
|
|
1871
1982
|
* @returns flowId to use with emailAuthVerify
|
|
1872
1983
|
*/
|
|
1873
1984
|
async emailAuthStart(email) {
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1985
|
+
try {
|
|
1986
|
+
await this.whenReady();
|
|
1987
|
+
const emailAdapter = this.wallets.find((w) => w.id === WalletId.Email);
|
|
1988
|
+
if (!emailAdapter || !emailAdapter.emailAuthStart) {
|
|
1989
|
+
throw new WalletNotConfiguredError("email");
|
|
1990
|
+
}
|
|
1991
|
+
const result = await emailAdapter.emailAuthStart(email);
|
|
1992
|
+
return { flowId: result.flowId };
|
|
1993
|
+
} catch (err) {
|
|
1994
|
+
throw normalizeError(err, { operation: "emailAuthStart" });
|
|
1878
1995
|
}
|
|
1879
|
-
const result = await emailAdapter.emailAuthStart(email);
|
|
1880
|
-
return { flowId: result.flowId };
|
|
1881
1996
|
}
|
|
1882
1997
|
/**
|
|
1883
1998
|
* Verifies the email OTP and completes the connection.
|
|
@@ -1886,77 +2001,89 @@ var _AurumCore = class _AurumCore {
|
|
|
1886
2001
|
* @returns The connected wallet address and email
|
|
1887
2002
|
*/
|
|
1888
2003
|
async emailAuthVerify(flowId, otp) {
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
2004
|
+
try {
|
|
2005
|
+
await this.whenReady();
|
|
2006
|
+
const emailAdapter = this.wallets.find((w) => w.id === WalletId.Email);
|
|
2007
|
+
if (!emailAdapter || !emailAdapter.emailAuthVerify) {
|
|
2008
|
+
throw new WalletNotConfiguredError("email");
|
|
2009
|
+
}
|
|
2010
|
+
const verifyResult = await emailAdapter.emailAuthVerify(flowId, otp);
|
|
2011
|
+
const provider = emailAdapter.getProvider();
|
|
2012
|
+
if (!provider) {
|
|
2013
|
+
sentryLogger.error("Failed to get provider after email verification");
|
|
2014
|
+
throw new ConnectionError("Failed to get provider after email verification");
|
|
2015
|
+
}
|
|
2016
|
+
const address = verifyResult.user?.evmAccounts?.[0];
|
|
2017
|
+
const email = verifyResult.user?.authenticationMethods?.email?.email;
|
|
2018
|
+
if (!address || !email) {
|
|
2019
|
+
sentryLogger.error("Address or email not found after email verification");
|
|
2020
|
+
throw new ConnectionError("Address or email not found after email verification");
|
|
2021
|
+
}
|
|
2022
|
+
const checksumAdr = checksumAddress(address);
|
|
2023
|
+
this.connectedWalletAdapter = emailAdapter;
|
|
2024
|
+
this.updateProvider(provider);
|
|
2025
|
+
this.userInfo = {
|
|
2026
|
+
publicAddress: checksumAdr,
|
|
2027
|
+
walletName: emailAdapter.name,
|
|
2028
|
+
walletId: emailAdapter.id,
|
|
2029
|
+
email
|
|
2030
|
+
};
|
|
2031
|
+
this.persistConnectionState(emailAdapter, checksumAdr, email);
|
|
2032
|
+
this.setInternalAccountChangeListener(emailAdapter);
|
|
2033
|
+
const chainId = await provider.request({ method: "eth_chainId" });
|
|
2034
|
+
this.emitConnect(chainId);
|
|
2035
|
+
this.emitAccountsChanged([checksumAdr]);
|
|
2036
|
+
sentryLogger.info(`Wallet connected: ${emailAdapter.id} (headless)`);
|
|
2037
|
+
return { address: checksumAdr, email: email ?? "", isNewUser: verifyResult.isNewUser ?? false };
|
|
2038
|
+
} catch (err) {
|
|
2039
|
+
throw normalizeError(err, { operation: "emailAuthVerify" });
|
|
2040
|
+
}
|
|
1922
2041
|
}
|
|
1923
2042
|
/**
|
|
1924
2043
|
* Initiates a WalletConnect session and returns the URI for displaying a custom QR code.
|
|
1925
2044
|
* @returns URI string and a promise that resolves when the user connects
|
|
1926
2045
|
*/
|
|
1927
2046
|
async getWalletConnectSession() {
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
const session = await wcAdapter.startSession();
|
|
1934
|
-
return {
|
|
1935
|
-
uri: session.uri,
|
|
1936
|
-
waitForConnection: async () => {
|
|
1937
|
-
const result = await session.waitForConnection();
|
|
1938
|
-
const provider = result.provider ?? wcAdapter.getProvider();
|
|
1939
|
-
if (!provider) {
|
|
1940
|
-
sentryLogger.error("Failed to get provider after WalletConnect connection");
|
|
1941
|
-
throw new Error("Failed to get provider after WalletConnect connection");
|
|
1942
|
-
}
|
|
1943
|
-
const checksumAdr = checksumAddress(result.address);
|
|
1944
|
-
this.connectedWalletAdapter = wcAdapter;
|
|
1945
|
-
this.updateProvider(provider);
|
|
1946
|
-
this.userInfo = {
|
|
1947
|
-
publicAddress: checksumAdr,
|
|
1948
|
-
walletName: wcAdapter.name,
|
|
1949
|
-
walletId: wcAdapter.id
|
|
1950
|
-
};
|
|
1951
|
-
this.persistConnectionState(wcAdapter, checksumAdr);
|
|
1952
|
-
this.setInternalAccountChangeListener(wcAdapter);
|
|
1953
|
-
const chainId = await provider.request({ method: "eth_chainId" });
|
|
1954
|
-
this.emitConnect(chainId);
|
|
1955
|
-
this.emitAccountsChanged([checksumAdr]);
|
|
1956
|
-
sentryLogger.info(`Wallet connected: ${wcAdapter.id} (headless)`);
|
|
1957
|
-
return checksumAdr;
|
|
2047
|
+
try {
|
|
2048
|
+
await this.whenReady();
|
|
2049
|
+
const wcAdapter = this.wallets.find((w) => w.id === WalletId.WalletConnect);
|
|
2050
|
+
if (!wcAdapter) {
|
|
2051
|
+
throw new WalletNotConfiguredError("walletconnect");
|
|
1958
2052
|
}
|
|
1959
|
-
|
|
2053
|
+
const session = await wcAdapter.startSession();
|
|
2054
|
+
return {
|
|
2055
|
+
uri: session.uri,
|
|
2056
|
+
waitForConnection: async () => {
|
|
2057
|
+
try {
|
|
2058
|
+
const result = await session.waitForConnection();
|
|
2059
|
+
const provider = result.provider ?? wcAdapter.getProvider();
|
|
2060
|
+
if (!provider) {
|
|
2061
|
+
sentryLogger.error("Failed to get provider after WalletConnect connection");
|
|
2062
|
+
throw new ConnectionError("Failed to get provider after WalletConnect connection");
|
|
2063
|
+
}
|
|
2064
|
+
const checksumAdr = checksumAddress(result.address);
|
|
2065
|
+
this.connectedWalletAdapter = wcAdapter;
|
|
2066
|
+
this.updateProvider(provider);
|
|
2067
|
+
this.userInfo = {
|
|
2068
|
+
publicAddress: checksumAdr,
|
|
2069
|
+
walletName: wcAdapter.name,
|
|
2070
|
+
walletId: wcAdapter.id
|
|
2071
|
+
};
|
|
2072
|
+
this.persistConnectionState(wcAdapter, checksumAdr);
|
|
2073
|
+
this.setInternalAccountChangeListener(wcAdapter);
|
|
2074
|
+
const chainId = await provider.request({ method: "eth_chainId" });
|
|
2075
|
+
this.emitConnect(chainId);
|
|
2076
|
+
this.emitAccountsChanged([checksumAdr]);
|
|
2077
|
+
sentryLogger.info(`Wallet connected: ${wcAdapter.id} (headless)`);
|
|
2078
|
+
return checksumAdr;
|
|
2079
|
+
} catch (err) {
|
|
2080
|
+
throw normalizeError(err, { operation: "connect" });
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
};
|
|
2084
|
+
} catch (err) {
|
|
2085
|
+
throw normalizeError(err, { operation: "connect" });
|
|
2086
|
+
}
|
|
1960
2087
|
}
|
|
1961
2088
|
/* PROVIDER METHODS */
|
|
1962
2089
|
createProviderProxy() {
|
|
@@ -2141,7 +2268,7 @@ var _AurumCore = class _AurumCore {
|
|
|
2141
2268
|
}
|
|
2142
2269
|
async addChain(chain) {
|
|
2143
2270
|
if (!chain?.id || !chain?.name || !chain?.nativeCurrency || !chain?.rpcUrls?.default?.http) {
|
|
2144
|
-
throw new
|
|
2271
|
+
throw new InvalidConfigError("Invalid chain configuration: missing required properties");
|
|
2145
2272
|
}
|
|
2146
2273
|
await this.rpcProvider.request({
|
|
2147
2274
|
method: "wallet_addEthereumChain",
|
|
@@ -2193,6 +2320,32 @@ var Aurum = class {
|
|
|
2193
2320
|
* ```
|
|
2194
2321
|
*/
|
|
2195
2322
|
constructor(config) {
|
|
2323
|
+
/**
|
|
2324
|
+
* Registers an EIP-1193 event listener on the wallet provider.
|
|
2325
|
+
* Listeners survive provider swaps (connect/disconnect) so consumers register once.
|
|
2326
|
+
*
|
|
2327
|
+
* @example
|
|
2328
|
+
* ```typescript
|
|
2329
|
+
* aurum.on('accountsChanged', (accounts) => console.log(accounts));
|
|
2330
|
+
* aurum.on('chainChanged', (chainId) => console.log(chainId));
|
|
2331
|
+
* ```
|
|
2332
|
+
*/
|
|
2333
|
+
this.on = (event, listener) => {
|
|
2334
|
+
this.core.on(event, listener);
|
|
2335
|
+
};
|
|
2336
|
+
/**
|
|
2337
|
+
* Removes an EIP-1193 event listener previously registered with `on()`.
|
|
2338
|
+
* Alias for `removeListener`.
|
|
2339
|
+
*/
|
|
2340
|
+
this.off = (event, listener) => {
|
|
2341
|
+
this.core.off(event, listener);
|
|
2342
|
+
};
|
|
2343
|
+
/**
|
|
2344
|
+
* Removes an EIP-1193 event listener previously registered with `on()`.
|
|
2345
|
+
*/
|
|
2346
|
+
this.removeListener = (event, listener) => {
|
|
2347
|
+
this.core.removeListener(event, listener);
|
|
2348
|
+
};
|
|
2196
2349
|
this.core = new AurumCore(config);
|
|
2197
2350
|
}
|
|
2198
2351
|
/**
|
|
@@ -2454,6 +2607,16 @@ var Aurum = class {
|
|
|
2454
2607
|
}
|
|
2455
2608
|
};
|
|
2456
2609
|
export {
|
|
2457
|
-
Aurum
|
|
2610
|
+
Aurum,
|
|
2611
|
+
AurumError,
|
|
2612
|
+
ChainNotSupportedError,
|
|
2613
|
+
ChainSwitchRejectedError,
|
|
2614
|
+
ConnectionError,
|
|
2615
|
+
InvalidConfigError,
|
|
2616
|
+
UserRejectedError,
|
|
2617
|
+
WalletExcludedError,
|
|
2618
|
+
WalletNotConfiguredError,
|
|
2619
|
+
WalletNotInstalledError,
|
|
2620
|
+
normalizeError
|
|
2458
2621
|
};
|
|
2459
2622
|
//# sourceMappingURL=index.mjs.map
|
package/dist/widgets.d.mts
CHANGED
package/dist/widgets.d.ts
CHANGED