@aurum-sdk/core 0.1.0
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 +420 -0
- package/dist/chunk-DHEVW7CR.js +2432 -0
- package/dist/chunk-DHEVW7CR.js.map +1 -0
- package/dist/chunk-U5BSED2R.mjs +2432 -0
- package/dist/chunk-U5BSED2R.mjs.map +1 -0
- package/dist/index.css +743 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +273 -0
- package/dist/index.d.ts +273 -0
- package/dist/index.js +2433 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2433 -0
- package/dist/index.mjs.map +1 -0
- package/dist/widgets.css +743 -0
- package/dist/widgets.css.map +1 -0
- package/dist/widgets.d.mts +88 -0
- package/dist/widgets.d.ts +88 -0
- package/dist/widgets.js +78 -0
- package/dist/widgets.js.map +1 -0
- package/dist/widgets.mjs +78 -0
- package/dist/widgets.mjs.map +1 -0
- package/package.json +113 -0
package/README.md
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
# @aurum-sdk/core
|
|
2
|
+
|
|
3
|
+
<!-- [Live Demo](https://demo.aurumsdk.com/)
|
|
4
|
+
[Aurum Website](https://aurumsdk.com/) -->
|
|
5
|
+
|
|
6
|
+
Aurum is a frontend JavaScript SDK that makes it easy to add wallets to your dapp.
|
|
7
|
+
|
|
8
|
+
**Using React? Check out @aurum-sdk/hooks on [github](https://github.com/aurum-sdk/aurum/packages/hooks) or [npm](https://www.npmjs.com/package/@aurum-sdk/hooks)**
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Quick Start](#quick-start)
|
|
14
|
+
- [Configuration](#configuration)
|
|
15
|
+
- [BrandConfig](#brandconfig)
|
|
16
|
+
- [WalletsConfig](#walletsconfig)
|
|
17
|
+
- [Excluding Wallets](#excluding-wallets)
|
|
18
|
+
- [API Reference](#api-reference)
|
|
19
|
+
- [Properties](#properties)
|
|
20
|
+
- [Methods](#methods)
|
|
21
|
+
- [Embedded Widgets](#embedded-widgets)
|
|
22
|
+
- [Headless API](#headless-api)
|
|
23
|
+
- [Direct Wallet Connection](#direct-wallet-connection)
|
|
24
|
+
- [Email Authentication](#email-authentication)
|
|
25
|
+
- [WalletConnect URI Flow](#walletconnect-uri-flow)
|
|
26
|
+
- [Web3 Library Integrations](#web3-library-integrations)
|
|
27
|
+
- [Viem](#viem)
|
|
28
|
+
- [Ethers v5](#ethers-v5)
|
|
29
|
+
- [Ethers v6](#ethers-v6)
|
|
30
|
+
- [Troubleshooting](#troubleshooting)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm add @aurum-sdk/core
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { Aurum } from '@aurum-sdk/core';
|
|
44
|
+
|
|
45
|
+
const aurum = new Aurum({
|
|
46
|
+
brand: { appName: 'Your App Name' },
|
|
47
|
+
wallets: {
|
|
48
|
+
email: { projectId: 'cdp-project-id' },
|
|
49
|
+
walletConnect: { projectId: 'reown-project-id' },
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Open connect modal
|
|
54
|
+
const address = await aurum.connect();
|
|
55
|
+
console.log('Connected:', address);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
### `AurumConfig`
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
interface AurumConfig {
|
|
66
|
+
wallets?: WalletsConfig;
|
|
67
|
+
brand?: BrandConfig;
|
|
68
|
+
telemetry?: boolean; // enable/disable error tracking (default: true)
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### `BrandConfig`
|
|
73
|
+
|
|
74
|
+
Customize the look and feel of the connect modal.
|
|
75
|
+
|
|
76
|
+
| Property | Type | Default | Description |
|
|
77
|
+
| -------------- | --------------------- | ---------------- | --------------------------------------------------------- |
|
|
78
|
+
| `appName` | `string` | `'Aurum'` | Your application name |
|
|
79
|
+
| `logo` | `string` | - | URL to your app logo (https or data:image/svg+xml;base64) |
|
|
80
|
+
| `theme` | `'light' \| 'dark'` | `'dark'` | Color theme for the modal |
|
|
81
|
+
| `primaryColor` | `string` | `#000` or `#FFF` | Primary accent color (hex) |
|
|
82
|
+
| `borderRadius` | `string` | `'md'` | Corner roundness of UI elements |
|
|
83
|
+
| `modalZIndex` | `number` | `1000` | z-index for the modal overlay |
|
|
84
|
+
| `hideFooter` | `boolean` | `false` | Hide the "Powered by Aurum" footer in modal |
|
|
85
|
+
| `font` | `string` | Inter | Custom font family for all modal UI elements |
|
|
86
|
+
| `walletLayout` | `'stacked' \| 'grid'` | `'stacked'` | Layout for wallet buttons |
|
|
87
|
+
|
|
88
|
+
### `WalletsConfig`
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
interface WalletsConfig {
|
|
92
|
+
email?: {
|
|
93
|
+
projectId: string; // Coinbase CDP project ID for email wallet
|
|
94
|
+
};
|
|
95
|
+
walletConnect?: {
|
|
96
|
+
projectId: string; // Reown project ID for WalletConnect, AppKit modal, and Ledger
|
|
97
|
+
};
|
|
98
|
+
exclude?: WalletId[]; // Wallets to hide from the connect modal
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Getting Project IDs:**
|
|
103
|
+
|
|
104
|
+
- **Coinbase CDP:** Register at [portal.cdp.coinbase.com](https://portal.cdp.coinbase.com/)
|
|
105
|
+
- **WalletConnect:** Register at [cloud.walletconnect.com](https://dashboard.reown.com/)
|
|
106
|
+
|
|
107
|
+
Don't forget to configure the domain allowlist for both project IDs.
|
|
108
|
+
|
|
109
|
+
### Excluding Wallets
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { WalletId } from '@aurum-sdk/types';
|
|
113
|
+
|
|
114
|
+
const aurum = new Aurum({
|
|
115
|
+
brand: { appName: 'Your App Name' },
|
|
116
|
+
wallets: { ... },
|
|
117
|
+
exclude: [WalletId.MetaMask], // or ['metamask']
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Notes:**
|
|
122
|
+
|
|
123
|
+
- If you exclude `WalletId.Email`, you don't need `wallets.email.projectId`
|
|
124
|
+
- If you exclude `WalletId.WalletConnect`, `WalletId.AppKit`, and `WalletId.Ledger`, you don't need `wallets.walletConnect.projectId`
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## API Reference
|
|
129
|
+
|
|
130
|
+
### Properties
|
|
131
|
+
|
|
132
|
+
#### `rpcProvider: AurumRpcProvider`
|
|
133
|
+
|
|
134
|
+
EIP-1193 compatible provider. Works with viem, ethers.js, and other web3 libraries.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// Direct RPC request
|
|
138
|
+
const accounts = await aurum.rpcProvider.request({ method: 'eth_accounts' });
|
|
139
|
+
|
|
140
|
+
// Event listeners
|
|
141
|
+
aurum.rpcProvider.on?.('accountsChanged', (accounts: string[]) => { ... });
|
|
142
|
+
aurum.rpcProvider.on?.('chainChanged', (chainId: string) => { ... });
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### `ready: boolean`
|
|
146
|
+
|
|
147
|
+
Whether the SDK has finished initializing (including connection restoration).
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
### Methods
|
|
152
|
+
|
|
153
|
+
#### `whenReady(): Promise<void>`
|
|
154
|
+
|
|
155
|
+
Waits for the SDK to finish initializing, including restoring any previous connection, such as after a page refresh.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
await aurum.whenReady();
|
|
159
|
+
// Safe to use the provider
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
#### ``connect(walletId?: WalletId): Promise<`0x${string}`>``
|
|
165
|
+
|
|
166
|
+
Opens the wallet connection modal or connects directly to a specific wallet.
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// Show modal
|
|
170
|
+
const address = await aurum.connect();
|
|
171
|
+
|
|
172
|
+
// Connect directly to a specific wallet
|
|
173
|
+
import { WalletId } from '@aurum-sdk/types';
|
|
174
|
+
const address = await aurum.connect(WalletId.MetaMask);
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Available Wallet IDs:**
|
|
178
|
+
|
|
179
|
+
| WalletId | Description |
|
|
180
|
+
| ------------------------- | ------------------------------ |
|
|
181
|
+
| `WalletId.Email` | Coinbase Embedded email wallet |
|
|
182
|
+
| `WalletId.MetaMask` | MetaMask |
|
|
183
|
+
| `WalletId.Phantom` | Phantom wallet |
|
|
184
|
+
| `WalletId.CoinbaseWallet` | Coinbase Wallet |
|
|
185
|
+
| `WalletId.Rabby` | Rabby wallet |
|
|
186
|
+
| `WalletId.Brave` | Brave Browser wallet |
|
|
187
|
+
| `WalletId.Ledger` | Ledger Live wallet |
|
|
188
|
+
| `WalletId.WalletConnect` | WalletConnect protocol |
|
|
189
|
+
| `WalletId.AppKit` | AppKit (Reown) |
|
|
190
|
+
|
|
191
|
+
**Throws:** Error if user closes the modal without connecting.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
#### `disconnect(): Promise<void>`
|
|
196
|
+
|
|
197
|
+
Disconnects the currently connected wallet.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
#### `isConnected(): Promise<boolean>`
|
|
202
|
+
|
|
203
|
+
Returns whether a wallet is currently connected.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
#### `getUserInfo(): Promise<UserInfo | undefined>`
|
|
208
|
+
|
|
209
|
+
Returns info about the connected user, or `undefined` if not connected.
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
interface UserInfo {
|
|
213
|
+
publicAddress: string;
|
|
214
|
+
walletName: WalletName;
|
|
215
|
+
walletId: WalletId;
|
|
216
|
+
email?: string;
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
#### `getChainId(): Promise<number>`
|
|
223
|
+
|
|
224
|
+
Returns the current chain ID.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
#### `switchChain(chainId, chain?): Promise<void>`
|
|
229
|
+
|
|
230
|
+
Switches to a different network. If the chain isn't added to the wallet, it will attempt to add it.
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { polygon } from 'viem/chains';
|
|
234
|
+
await aurum.switchChain(polygon.id, polygon);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
#### `updateBrandConfig(newConfig): void`
|
|
240
|
+
|
|
241
|
+
Updates the brand configuration (e.g., theme).
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
aurum.updateBrandConfig({ theme: 'light' });
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
#### `updateWalletsConfig(newConfig): void`
|
|
250
|
+
|
|
251
|
+
Updates the wallets configuration (currently supports `exclude`).
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
aurum.updateWalletsConfig({ exclude: [WalletId.MetaMask] });
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Embedded Widgets
|
|
260
|
+
|
|
261
|
+
React components for embedded wallet connection UI (instead of modal).
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
import { ConnectWidget } from '@aurum-sdk/core/widgets';
|
|
265
|
+
|
|
266
|
+
<ConnectWidget
|
|
267
|
+
aurum={aurum}
|
|
268
|
+
onConnect={(result) => {
|
|
269
|
+
console.log('Connected:', result.address, result.walletId);
|
|
270
|
+
}}
|
|
271
|
+
/>;
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
| Property | Type | Description |
|
|
275
|
+
| ----------- | ------------------------------------------------- | -------------------------------------- |
|
|
276
|
+
| `aurum` | `Aurum` | Your Aurum instance |
|
|
277
|
+
| `onConnect` | `(result: { address, walletId, email? }) => void` | Called when user successfully connects |
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Headless API
|
|
282
|
+
|
|
283
|
+
Build custom wallet connection UIs while using Aurum's wallet management.
|
|
284
|
+
|
|
285
|
+
### Direct Wallet Connection
|
|
286
|
+
|
|
287
|
+
Use `connect(walletId)` to connect directly without showing the modal:
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
const address = await aurum.connect(WalletId.MetaMask);
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
**Note:** `WalletId.Email` and `WalletId.WalletConnect` have dedicated methods below and cannot be used with `connect(walletId)`.
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
### Email Authentication
|
|
298
|
+
|
|
299
|
+
Two-step flow for Coinbase Embedded Wallet:
|
|
300
|
+
|
|
301
|
+
#### `emailAuthStart(email): Promise<{ flowId: string }>`
|
|
302
|
+
|
|
303
|
+
Sends an OTP code to the provided email.
|
|
304
|
+
|
|
305
|
+
#### `emailAuthVerify(flowId, otp): Promise<{ address: string, email: string, isNewUser: boolean }>`
|
|
306
|
+
|
|
307
|
+
Verifies the OTP and completes connection.
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
// Step 1: Send OTP
|
|
311
|
+
const { flowId } = await aurum.emailAuthStart('user@example.com');
|
|
312
|
+
|
|
313
|
+
// Step 2: User enters OTP from their email
|
|
314
|
+
const otp = await promptUserForOTP();
|
|
315
|
+
|
|
316
|
+
// Step 3: Verify and connect
|
|
317
|
+
const { address, email, isNewUser } = await aurum.emailAuthVerify(flowId, otp);
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
### WalletConnect URI Flow
|
|
323
|
+
|
|
324
|
+
For custom QR code displays:
|
|
325
|
+
|
|
326
|
+
#### `getWalletConnectSession(): Promise<{ uri: string, waitForConnection: () => Promise<string> }>`
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
const { uri, waitForConnection } = await aurum.getWalletConnectSession();
|
|
330
|
+
|
|
331
|
+
// Display your own QR code
|
|
332
|
+
renderQRCode(uri);
|
|
333
|
+
|
|
334
|
+
// Wait for user to scan and approve
|
|
335
|
+
const address = await waitForConnection();
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Web3 Library Integrations
|
|
341
|
+
|
|
342
|
+
### Viem
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
import { createPublicClient, createWalletClient, custom, http } from 'viem';
|
|
346
|
+
import { mainnet } from 'viem/chains';
|
|
347
|
+
|
|
348
|
+
const publicClient = createPublicClient({
|
|
349
|
+
chain: mainnet,
|
|
350
|
+
transport: http('YOUR_NODE_URL'),
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
const walletClient = createWalletClient({
|
|
354
|
+
transport: custom(aurum.rpcProvider),
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
// Sign a message
|
|
358
|
+
const [address] = await walletClient.getAddresses();
|
|
359
|
+
const signature = await walletClient.signMessage({ account: address, message: 'Hello!' });
|
|
360
|
+
|
|
361
|
+
// Send a transaction
|
|
362
|
+
const hash = await walletClient.sendTransaction({
|
|
363
|
+
account: address,
|
|
364
|
+
to: '0x...',
|
|
365
|
+
value: parseEther('0.01'),
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
### Ethers v5
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
import { ethers } from 'ethers';
|
|
375
|
+
|
|
376
|
+
const provider = new ethers.providers.Web3Provider(aurum.rpcProvider);
|
|
377
|
+
const signer = provider.getSigner();
|
|
378
|
+
|
|
379
|
+
const signature = await signer.signMessage('Hello!');
|
|
380
|
+
const tx = await signer.sendTransaction({ to: '0x...', value: ethers.utils.parseEther('0.01') });
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
### Ethers v6
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
import { BrowserProvider } from 'ethers';
|
|
389
|
+
|
|
390
|
+
const provider = new BrowserProvider(aurum.rpcProvider);
|
|
391
|
+
const signer = await provider.getSigner();
|
|
392
|
+
|
|
393
|
+
const signature = await signer.signMessage('Hello!');
|
|
394
|
+
const tx = await signer.sendTransaction({ to: '0x...', value: ethers.parseEther('0.01') });
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## Troubleshooting
|
|
400
|
+
|
|
401
|
+
### Sourcemap warnings in console
|
|
402
|
+
|
|
403
|
+
Add to your `.env` file:
|
|
404
|
+
|
|
405
|
+
```
|
|
406
|
+
GENERATE_SOURCEMAP=false
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Email wallet fails to send OTP
|
|
410
|
+
|
|
411
|
+
Ensure your domain is added to the **Coinbase Developer Platform** domain allowlist:
|
|
412
|
+
[How to Configure Domains](https://docs.cdp.coinbase.com/embedded-wallets/domains#how-to-configure-domains)
|
|
413
|
+
|
|
414
|
+
### WalletConnect does not prompt user to connect
|
|
415
|
+
|
|
416
|
+
Add your domain to the **Reown** dashboard allowlist at [dashboard.reown.com](https://dashboard.reown.com/).
|
|
417
|
+
|
|
418
|
+
### AppKit modal login methods
|
|
419
|
+
|
|
420
|
+
Configure available login methods (email, social) in the [Reown dashboard](https://dashboard.reown.com/), not in the SDK.
|