@aurum-sdk/core 0.2.5 → 0.2.7
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/Aurum-B0Okb4Qv.d.mts +294 -0
- package/dist/Aurum-B0Okb4Qv.d.ts +294 -0
- package/dist/{chunk-27AOACEW.js → chunk-2P33GXLJ.js} +2 -2
- package/dist/{chunk-X6ADRWYF.mjs → chunk-64XDE56K.mjs} +2 -2
- package/dist/empty-stub-JW2K2GSS.js +14 -0
- package/dist/empty-stub-X6WHS3X3.mjs +14 -0
- package/dist/index.d.mts +55 -268
- package/dist/index.d.ts +55 -268
- package/dist/index.js +428 -243
- package/dist/index.mjs +357 -172
- package/dist/{index.web-T26HBS3X.mjs → index.web-Q2L3EMC3.mjs} +2 -2
- package/dist/{index.web-WXUV52ZW.js → index.web-V7DLWC7H.js} +2 -2
- 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 +5 -5
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-64XDE56K.mjs";
|
|
20
20
|
import "./chunk-DRID67T7.mjs";
|
|
21
21
|
import {
|
|
22
22
|
init_polyfills
|
|
@@ -1396,7 +1396,7 @@ var _EmailAdapter = class _EmailAdapter {
|
|
|
1396
1396
|
sentryLogger.error("Email is not available");
|
|
1397
1397
|
throw new Error("Email is not available");
|
|
1398
1398
|
}
|
|
1399
|
-
const { signInWithEmail } = await import("./index.web-
|
|
1399
|
+
const { signInWithEmail } = await import("./index.web-Q2L3EMC3.mjs");
|
|
1400
1400
|
const authResult = await signInWithEmail({ email });
|
|
1401
1401
|
return authResult;
|
|
1402
1402
|
}
|
|
@@ -1409,7 +1409,7 @@ var _EmailAdapter = class _EmailAdapter {
|
|
|
1409
1409
|
sentryLogger.error("Email provider not initialized");
|
|
1410
1410
|
throw new Error("Email provider not initialized");
|
|
1411
1411
|
}
|
|
1412
|
-
const { verifyEmailOTP } = await import("./index.web-
|
|
1412
|
+
const { verifyEmailOTP } = await import("./index.web-Q2L3EMC3.mjs");
|
|
1413
1413
|
return verifyEmailOTP({ flowId, otp });
|
|
1414
1414
|
}
|
|
1415
1415
|
async connect() {
|
|
@@ -1441,7 +1441,7 @@ var _EmailAdapter = class _EmailAdapter {
|
|
|
1441
1441
|
async disconnect() {
|
|
1442
1442
|
try {
|
|
1443
1443
|
await this.ensureInitialized();
|
|
1444
|
-
const { signOut } = await import("./index.web-
|
|
1444
|
+
const { signOut } = await import("./index.web-Q2L3EMC3.mjs");
|
|
1445
1445
|
await signOut();
|
|
1446
1446
|
} catch {
|
|
1447
1447
|
}
|
|
@@ -1487,7 +1487,7 @@ var _EmailAdapter = class _EmailAdapter {
|
|
|
1487
1487
|
* Called by ensureInitialized() - deduplication handled via initPromise.
|
|
1488
1488
|
*/
|
|
1489
1489
|
async initializeProvider() {
|
|
1490
|
-
const { initialize } = await import("./index.web-
|
|
1490
|
+
const { initialize } = await import("./index.web-Q2L3EMC3.mjs");
|
|
1491
1491
|
await initialize({
|
|
1492
1492
|
projectId: this.projectId,
|
|
1493
1493
|
ethereum: {
|
|
@@ -1505,7 +1505,7 @@ var _EmailAdapter = class _EmailAdapter {
|
|
|
1505
1505
|
async createProvider() {
|
|
1506
1506
|
try {
|
|
1507
1507
|
await _EmailAdapter.initializeChainData();
|
|
1508
|
-
const { createCDPEmbeddedWallet } = await import("./index.web-
|
|
1508
|
+
const { createCDPEmbeddedWallet } = await import("./index.web-Q2L3EMC3.mjs");
|
|
1509
1509
|
const wallet = createCDPEmbeddedWallet({
|
|
1510
1510
|
chains: _EmailAdapter.viemChains,
|
|
1511
1511
|
transports: _EmailAdapter.viemTransports
|
|
@@ -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,9 +1739,36 @@ 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) {
|
|
1763
|
+
const incoming = _AurumCore.serializeConfig(config);
|
|
1764
|
+
if (incoming !== null && incoming !== _AurumCore.storedConfigJson) {
|
|
1765
|
+
console.warn(
|
|
1766
|
+
"Aurum Constructor called a second time with a different config; the original config is kept. Use updateBrandConfig() / updateWalletsConfig() to change config at runtime."
|
|
1767
|
+
);
|
|
1768
|
+
}
|
|
1668
1769
|
return _AurumCore.instance;
|
|
1669
1770
|
}
|
|
1771
|
+
_AurumCore.storedConfigJson = _AurumCore.serializeConfig(config);
|
|
1670
1772
|
const telemetryEnabled = config.telemetry !== false;
|
|
1671
1773
|
initSentry(telemetryEnabled);
|
|
1672
1774
|
this.brandConfig = this.resolveBrandConfig(config);
|
|
@@ -1685,6 +1787,13 @@ var _AurumCore = class _AurumCore {
|
|
|
1685
1787
|
this.readyPromise = this.tryRestoreConnection();
|
|
1686
1788
|
_AurumCore.instance = this;
|
|
1687
1789
|
}
|
|
1790
|
+
static serializeConfig(config) {
|
|
1791
|
+
try {
|
|
1792
|
+
return JSON.stringify(config);
|
|
1793
|
+
} catch {
|
|
1794
|
+
return null;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1688
1797
|
async whenReady() {
|
|
1689
1798
|
try {
|
|
1690
1799
|
await this.readyPromise;
|
|
@@ -1703,79 +1812,87 @@ var _AurumCore = class _AurumCore {
|
|
|
1703
1812
|
return this.excludedWallets;
|
|
1704
1813
|
}
|
|
1705
1814
|
async connect(walletId) {
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
if (this.userInfo?.publicAddress && this.connectedWalletAdapter?.getProvider()) {
|
|
1711
|
-
if (!walletId || this.userInfo.walletId === walletId) {
|
|
1712
|
-
return this.userInfo.publicAddress;
|
|
1713
|
-
}
|
|
1714
|
-
await this.disconnect();
|
|
1715
|
-
}
|
|
1716
|
-
let adapter = null;
|
|
1717
|
-
let result;
|
|
1718
|
-
if (walletId) {
|
|
1719
|
-
if (this.excludedWallets.has(walletId)) {
|
|
1720
|
-
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");
|
|
1721
1819
|
}
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
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();
|
|
1725
1825
|
}
|
|
1726
|
-
|
|
1727
|
-
|
|
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
|
+
}
|
|
1728
1844
|
} else {
|
|
1729
|
-
|
|
1730
|
-
|
|
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");
|
|
1731
1850
|
}
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
sentryLogger.error("Missing modal result");
|
|
1739
|
-
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;
|
|
1740
1857
|
}
|
|
1741
|
-
|
|
1742
|
-
if (!
|
|
1743
|
-
sentryLogger.error(`
|
|
1744
|
-
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.");
|
|
1745
1862
|
}
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
this.emitConnect(chainId);
|
|
1766
|
-
this.emitAccountsChanged([checksumAdr]);
|
|
1767
|
-
sentryLogger.info(`Wallet connected: ${adapter.id} (${walletId ? "headless" : "modal"})`);
|
|
1768
|
-
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
|
+
}
|
|
1769
1882
|
}
|
|
1770
1883
|
async disconnect() {
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
this.connectedWalletAdapter
|
|
1774
|
-
|
|
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" });
|
|
1775
1895
|
}
|
|
1776
|
-
this.resetConnectionState();
|
|
1777
|
-
this.emitDisconnect();
|
|
1778
|
-
this.emitAccountsChanged([]);
|
|
1779
1896
|
}
|
|
1780
1897
|
async getUserInfo() {
|
|
1781
1898
|
await this.whenReady();
|
|
@@ -1788,30 +1905,34 @@ var _AurumCore = class _AurumCore {
|
|
|
1788
1905
|
);
|
|
1789
1906
|
}
|
|
1790
1907
|
async handleWidgetConnection(result) {
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
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
|
+
}
|
|
1815
1936
|
}
|
|
1816
1937
|
async getChainId() {
|
|
1817
1938
|
await this.whenReady();
|
|
@@ -1819,13 +1940,17 @@ var _AurumCore = class _AurumCore {
|
|
|
1819
1940
|
return Number(chainId);
|
|
1820
1941
|
}
|
|
1821
1942
|
async switchChain(chainId, chain) {
|
|
1822
|
-
await this.whenReady();
|
|
1823
|
-
const hexChainId = normalizeChainId(chainId);
|
|
1824
1943
|
try {
|
|
1825
|
-
await this.
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
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" });
|
|
1829
1954
|
}
|
|
1830
1955
|
}
|
|
1831
1956
|
updateBrandConfig(newConfig) {
|
|
@@ -1857,13 +1982,17 @@ var _AurumCore = class _AurumCore {
|
|
|
1857
1982
|
* @returns flowId to use with emailAuthVerify
|
|
1858
1983
|
*/
|
|
1859
1984
|
async emailAuthStart(email) {
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
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" });
|
|
1864
1995
|
}
|
|
1865
|
-
const result = await emailAdapter.emailAuthStart(email);
|
|
1866
|
-
return { flowId: result.flowId };
|
|
1867
1996
|
}
|
|
1868
1997
|
/**
|
|
1869
1998
|
* Verifies the email OTP and completes the connection.
|
|
@@ -1872,77 +2001,89 @@ var _AurumCore = class _AurumCore {
|
|
|
1872
2001
|
* @returns The connected wallet address and email
|
|
1873
2002
|
*/
|
|
1874
2003
|
async emailAuthVerify(flowId, otp) {
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
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
|
+
}
|
|
1908
2041
|
}
|
|
1909
2042
|
/**
|
|
1910
2043
|
* Initiates a WalletConnect session and returns the URI for displaying a custom QR code.
|
|
1911
2044
|
* @returns URI string and a promise that resolves when the user connects
|
|
1912
2045
|
*/
|
|
1913
2046
|
async getWalletConnectSession() {
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
const session = await wcAdapter.startSession();
|
|
1920
|
-
return {
|
|
1921
|
-
uri: session.uri,
|
|
1922
|
-
waitForConnection: async () => {
|
|
1923
|
-
const result = await session.waitForConnection();
|
|
1924
|
-
const provider = result.provider ?? wcAdapter.getProvider();
|
|
1925
|
-
if (!provider) {
|
|
1926
|
-
sentryLogger.error("Failed to get provider after WalletConnect connection");
|
|
1927
|
-
throw new Error("Failed to get provider after WalletConnect connection");
|
|
1928
|
-
}
|
|
1929
|
-
const checksumAdr = checksumAddress(result.address);
|
|
1930
|
-
this.connectedWalletAdapter = wcAdapter;
|
|
1931
|
-
this.updateProvider(provider);
|
|
1932
|
-
this.userInfo = {
|
|
1933
|
-
publicAddress: checksumAdr,
|
|
1934
|
-
walletName: wcAdapter.name,
|
|
1935
|
-
walletId: wcAdapter.id
|
|
1936
|
-
};
|
|
1937
|
-
this.persistConnectionState(wcAdapter, checksumAdr);
|
|
1938
|
-
this.setInternalAccountChangeListener(wcAdapter);
|
|
1939
|
-
const chainId = await provider.request({ method: "eth_chainId" });
|
|
1940
|
-
this.emitConnect(chainId);
|
|
1941
|
-
this.emitAccountsChanged([checksumAdr]);
|
|
1942
|
-
sentryLogger.info(`Wallet connected: ${wcAdapter.id} (headless)`);
|
|
1943
|
-
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");
|
|
1944
2052
|
}
|
|
1945
|
-
|
|
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
|
+
}
|
|
1946
2087
|
}
|
|
1947
2088
|
/* PROVIDER METHODS */
|
|
1948
2089
|
createProviderProxy() {
|
|
@@ -2010,6 +2151,10 @@ var _AurumCore = class _AurumCore {
|
|
|
2010
2151
|
};
|
|
2011
2152
|
}
|
|
2012
2153
|
async tryRestoreConnection() {
|
|
2154
|
+
if (typeof window === "undefined") {
|
|
2155
|
+
this.ready = true;
|
|
2156
|
+
return;
|
|
2157
|
+
}
|
|
2013
2158
|
try {
|
|
2014
2159
|
await waitForStoreHydration();
|
|
2015
2160
|
const store = useAurumStore.getState();
|
|
@@ -2123,7 +2268,7 @@ var _AurumCore = class _AurumCore {
|
|
|
2123
2268
|
}
|
|
2124
2269
|
async addChain(chain) {
|
|
2125
2270
|
if (!chain?.id || !chain?.name || !chain?.nativeCurrency || !chain?.rpcUrls?.default?.http) {
|
|
2126
|
-
throw new
|
|
2271
|
+
throw new InvalidConfigError("Invalid chain configuration: missing required properties");
|
|
2127
2272
|
}
|
|
2128
2273
|
await this.rpcProvider.request({
|
|
2129
2274
|
method: "wallet_addEthereumChain",
|
|
@@ -2148,6 +2293,10 @@ var _AurumCore = class _AurumCore {
|
|
|
2148
2293
|
};
|
|
2149
2294
|
// Singleton instance
|
|
2150
2295
|
_AurumCore.instance = null;
|
|
2296
|
+
// Serialized first-construction config used to detect mismatched re-inits (dev footgun: HMR,
|
|
2297
|
+
// cross-module imports, etc). Stored as a string so re-construction with structurally-equal
|
|
2298
|
+
// config doesn't false-positive.
|
|
2299
|
+
_AurumCore.storedConfigJson = null;
|
|
2151
2300
|
// Events managed by AurumCore (not forwarded to underlying provider)
|
|
2152
2301
|
_AurumCore.MANAGED_EVENTS = ["accountsChanged", "connect", "disconnect"];
|
|
2153
2302
|
var AurumCore = _AurumCore;
|
|
@@ -2171,6 +2320,32 @@ var Aurum = class {
|
|
|
2171
2320
|
* ```
|
|
2172
2321
|
*/
|
|
2173
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
|
+
};
|
|
2174
2349
|
this.core = new AurumCore(config);
|
|
2175
2350
|
}
|
|
2176
2351
|
/**
|
|
@@ -2432,6 +2607,16 @@ var Aurum = class {
|
|
|
2432
2607
|
}
|
|
2433
2608
|
};
|
|
2434
2609
|
export {
|
|
2435
|
-
Aurum
|
|
2610
|
+
Aurum,
|
|
2611
|
+
AurumError,
|
|
2612
|
+
ChainNotSupportedError,
|
|
2613
|
+
ChainSwitchRejectedError,
|
|
2614
|
+
ConnectionError,
|
|
2615
|
+
InvalidConfigError,
|
|
2616
|
+
UserRejectedError,
|
|
2617
|
+
WalletExcludedError,
|
|
2618
|
+
WalletNotConfiguredError,
|
|
2619
|
+
WalletNotInstalledError,
|
|
2620
|
+
normalizeError
|
|
2436
2621
|
};
|
|
2437
2622
|
//# sourceMappingURL=index.mjs.map
|