@avalabs/avacloud-waas-react 1.0.10 → 1.0.12

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 CHANGED
@@ -73,9 +73,9 @@ The main provider component that wraps your application and provides wallet cont
73
73
 
74
74
  ```tsx
75
75
  <AvaCloudWalletProvider
76
- orgId="your-avacloud-org-id" // Required
77
- chainId={43113}
78
- darkMode={false}
76
+ orgId="your-avacloud-org-id" // Required - your AvaCloud organization ID
77
+ chainId={43113} // Optional - defaults to Avalanche Fuji Testnet
78
+ darkMode={false} // Optional - theme mode for UI components
79
79
  onAuthSuccess={(user) => console.log('Auth success', user)}
80
80
  onAuthError={(error) => console.error('Auth error', error)}
81
81
  onWalletUpdate={(wallet) => console.log('Wallet updated', wallet)}
@@ -88,13 +88,13 @@ The main provider component that wraps your application and provides wallet cont
88
88
 
89
89
  | Prop | Type | Description |
90
90
  |------|------|-------------|
91
- | `orgId` | `string` | Required AvaCloud organization ID |
92
- | `env` | `'local' \| 'development' \| 'prod'` | (Optional) Environment to use. Defaults to 'prod'. |
93
- | `chainId` | `number` | (Optional) EVM chain ID to use (defaults to Avalanche Fuji Testnet - 43113) |
94
- | `darkMode` | `boolean` | (Optional) Whether to use dark mode for UI components |
95
- | `onAuthSuccess` | `(user: Auth0User) => void` | (Optional) Callback called when authentication is successful |
96
- | `onAuthError` | `(error: Error) => void` | (Optional) Callback called when authentication fails |
97
- | `onWalletUpdate` | `(wallet: WalletInfo) => void` | (Optional) Callback called when wallet information is updated |
91
+ | `orgId` | `string` | **Required** - Your AvaCloud organization ID used to fetch wallet configuration |
92
+ | `env` | `'local' \| 'development' \| 'prod'` | Environment to use (default: `'prod'`) |
93
+ | `chainId` | `number` | EVM chain ID (default: `43113` - Avalanche Fuji Testnet) |
94
+ | `darkMode` | `boolean` | Enable dark mode for UI components (default: `false`) |
95
+ | `onAuthSuccess` | `(user: Auth0User) => void` | Callback on successful authentication |
96
+ | `onAuthError` | `(error: Error) => void` | Callback on authentication error |
97
+ | `onWalletUpdate` | `(wallet: WalletInfo) => void` | Callback when wallet information updates |
98
98
 
99
99
  ### UI Components
100
100
 
@@ -209,6 +209,100 @@ Hook for accessing and setting the current chain ID.
209
209
  const { chainId, setChainId } = useChainId();
210
210
  ```
211
211
 
212
+ ## WAGMI Integration
213
+
214
+ This SDK includes a WAGMI connector that allows you to use AvaCloud wallets with WAGMI (React Ethereum Library).
215
+
216
+ ### Prerequisites
217
+
218
+ Install the required WAGMI dependencies:
219
+
220
+ ```bash
221
+ npm install wagmi viem@2.x @tanstack/react-query
222
+ ```
223
+
224
+ ### Setting up WAGMI with AvaCloud
225
+
226
+ ```tsx
227
+ import { WagmiProvider, createConfig } from 'wagmi';
228
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
229
+ import { avaCloudWallet } from '@avalabs/avacloud-waas-react';
230
+ import { avalancheFuji } from 'wagmi/chains';
231
+ import { http } from 'wagmi';
232
+
233
+ const queryClient = new QueryClient();
234
+
235
+ const config = createConfig({
236
+ chains: [avalancheFuji],
237
+ connectors: [
238
+ avaCloudWallet(),
239
+ ],
240
+ transports: {
241
+ [avalancheFuji.id]: http(),
242
+ },
243
+ });
244
+
245
+ function App() {
246
+ return (
247
+ <QueryClientProvider client={queryClient}>
248
+ <WagmiProvider config={config}>
249
+ <AvaCloudWalletProvider orgId="your-avacloud-org-id">
250
+ <YourApp />
251
+ </AvaCloudWalletProvider>
252
+ </WagmiProvider>
253
+ </QueryClientProvider>
254
+ );
255
+ }
256
+ ```
257
+
258
+ ### Using WAGMI Hooks
259
+
260
+ Once configured, use standard WAGMI hooks with your AvaCloud wallet:
261
+
262
+ ```tsx
263
+ import { useAccount, useConnect, useDisconnect, useSignMessage } from 'wagmi';
264
+
265
+ function WagmiExample() {
266
+ const { address, isConnected } = useAccount();
267
+ const { connect, connectors } = useConnect();
268
+ const { disconnect } = useDisconnect();
269
+ const { signMessage } = useSignMessage();
270
+
271
+ const handleConnect = () => {
272
+ const avaCloudConnector = connectors.find(c => c.id === 'avaCloudWallet');
273
+ if (avaCloudConnector) {
274
+ connect({ connector: avaCloudConnector });
275
+ }
276
+ };
277
+
278
+ const handleSign = async () => {
279
+ const signature = await signMessage({ message: 'Hello from WAGMI!' });
280
+ console.log('Signature:', signature);
281
+ };
282
+
283
+ return (
284
+ <div>
285
+ {isConnected ? (
286
+ <>
287
+ <p>Connected: {address}</p>
288
+ <button onClick={() => disconnect()}>Disconnect</button>
289
+ <button onClick={handleSign}>Sign Message</button>
290
+ </>
291
+ ) : (
292
+ <button onClick={handleConnect}>Connect AvaCloud Wallet</button>
293
+ )}
294
+ </div>
295
+ );
296
+ }
297
+ ```
298
+
299
+ ### Important Notes
300
+
301
+ - The AvaCloud WAGMI connector requires the `AvaCloudWalletProvider` to be present in your component tree
302
+ - Authentication is still managed through the AvaCloud SDK's authentication flow
303
+ - The connector automatically syncs with the wallet state from `AvaCloudWalletProvider`
304
+ - All standard WAGMI hooks and functionality are supported
305
+
212
306
  ## Advanced Usage
213
307
 
214
308
  ### Theme Customization
@@ -274,30 +368,4 @@ We welcome contributions! Please see [CONTRIBUTING.md](https://github.com/ava-la
274
368
 
275
369
  ## License
276
370
 
277
- MIT © [Ava Labs, Inc.](https://github.com/ava-labs)
278
-
279
- ## Using the AvaCloud Organization ID
280
-
281
- The `AvaCloudWalletProvider` requires an AvaCloud organization ID (`orgId`). This is used to fetch the organization configuration from the AvaCloud API, which includes the mapping to the appropriate wallet service organization ID used for wallet operations.
282
-
283
- ```jsx
284
- import { AvaCloudWalletProvider } from '@avalabs/avacloud-waas-react';
285
-
286
- function App() {
287
- return (
288
- <AvaCloudWalletProvider
289
- orgId="your-avacloud-org-id" // Required AvaCloud organization ID
290
- >
291
- <YourApp />
292
- </AvaCloudWalletProvider>
293
- );
294
- }
295
- ```
296
-
297
- When provided, the `orgId` will be used to:
298
-
299
- 1. Fetch the organization configuration from the AvaCloud API
300
- 2. Map to the appropriate wallet service organization ID
301
- 3. Use the mapped ID for wallet operations
302
-
303
- This enables organizations to have their AvaCloud identity seamlessly map to their WaaS wallets.
371
+ MIT © [Ava Labs, Inc.](https://github.com/ava-labs)
package/dist/index.d.mts CHANGED
@@ -1,9 +1,10 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as _cubist_labs_cubesigner_sdk from '@cubist-labs/cubesigner-sdk';
3
- import { IdentityProof, CubeSignerClient } from '@cubist-labs/cubesigner-sdk';
3
+ import { CubeSignerClient, IdentityProof } from '@cubist-labs/cubesigner-sdk';
4
4
  import { PropsWithChildren, ButtonHTMLAttributes } from 'react';
5
5
  import { ButtonProps } from '@avalabs/core-k2-components';
6
- import { Hex, TransactionRequest, Signature, Hash } from 'viem';
6
+ import { Hex, Signature, TransactionRequest, Hash } from 'viem';
7
+ import { CreateConnectorFn } from '@wagmi/core';
7
8
 
8
9
  /**
9
10
  * Cubist wallet information
@@ -518,4 +519,6 @@ interface UseUserWalletsResult {
518
519
  }
519
520
  declare function useUserWallets(): UseUserWalletsResult;
520
521
 
521
- export { type AddAccountMessage, type AdminPortalSettings, type Auth0User, type AuthMessage, type AuthMessagePayload, type AuthStateUpdateMessage, type AuthStatusMessage, type AvaCloudEnvironment, type AvaCloudWalletContextType, AvaCloudWalletProvider, type AvaCloudWalletProviderProps, type BaseAuthMessage, type CheckAuthStatusMessage, type CubistWalletInfo, type ErrorMessage, ExportView, type GetOidcMessage, type IframeReadyMessage, LoginButton, type LoginRequestMessage, type LogoutRequestMessage, type MessageType, type OrgConfig, type ReceiveOidcMessage, ReceiveView, type RegisterMessage, type RegisterPayload, type RegisterSuccessMessage, SendView, type SignupRequestMessage, ThemeProvider, TokensView, type UserInfo, UserProfile, VM, WalletButton, WalletCard, WalletDisplay, type WalletInfo, type WalletKeysErrorMessage, type WalletKeysUpdateMessage, useAuth, useAvaCloudWallet, useChainId, usePostMessage, useSignMessage, useSignTransaction, useThemeMode, useTransferTokens, useUserWallets };
522
+ declare function avaCloudWallet(): CreateConnectorFn;
523
+
524
+ export { type AddAccountMessage, type AdminPortalSettings, type Auth0User, type AuthMessage, type AuthMessagePayload, type AuthStateUpdateMessage, type AuthStatusMessage, type AvaCloudEnvironment, type AvaCloudWalletContextType, AvaCloudWalletProvider, type AvaCloudWalletProviderProps, type BaseAuthMessage, type CheckAuthStatusMessage, type CubistWalletInfo, type ErrorMessage, ExportView, type GetOidcMessage, type IframeReadyMessage, LoginButton, type LoginRequestMessage, type LogoutRequestMessage, type MessageType, type OrgConfig, type ReceiveOidcMessage, ReceiveView, type RegisterMessage, type RegisterPayload, type RegisterSuccessMessage, SendView, type SignupRequestMessage, ThemeProvider, TokensView, type UserInfo, UserProfile, VM, WalletButton, WalletCard, WalletDisplay, type WalletInfo, type WalletKeysErrorMessage, type WalletKeysUpdateMessage, avaCloudWallet, useAuth, useAvaCloudWallet, useChainId, usePostMessage, useSignMessage, useSignTransaction, useThemeMode, useTransferTokens, useUserWallets };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as _cubist_labs_cubesigner_sdk from '@cubist-labs/cubesigner-sdk';
3
- import { IdentityProof, CubeSignerClient } from '@cubist-labs/cubesigner-sdk';
3
+ import { CubeSignerClient, IdentityProof } from '@cubist-labs/cubesigner-sdk';
4
4
  import { PropsWithChildren, ButtonHTMLAttributes } from 'react';
5
5
  import { ButtonProps } from '@avalabs/core-k2-components';
6
- import { Hex, TransactionRequest, Signature, Hash } from 'viem';
6
+ import { Hex, Signature, TransactionRequest, Hash } from 'viem';
7
+ import { CreateConnectorFn } from '@wagmi/core';
7
8
 
8
9
  /**
9
10
  * Cubist wallet information
@@ -518,4 +519,6 @@ interface UseUserWalletsResult {
518
519
  }
519
520
  declare function useUserWallets(): UseUserWalletsResult;
520
521
 
521
- export { type AddAccountMessage, type AdminPortalSettings, type Auth0User, type AuthMessage, type AuthMessagePayload, type AuthStateUpdateMessage, type AuthStatusMessage, type AvaCloudEnvironment, type AvaCloudWalletContextType, AvaCloudWalletProvider, type AvaCloudWalletProviderProps, type BaseAuthMessage, type CheckAuthStatusMessage, type CubistWalletInfo, type ErrorMessage, ExportView, type GetOidcMessage, type IframeReadyMessage, LoginButton, type LoginRequestMessage, type LogoutRequestMessage, type MessageType, type OrgConfig, type ReceiveOidcMessage, ReceiveView, type RegisterMessage, type RegisterPayload, type RegisterSuccessMessage, SendView, type SignupRequestMessage, ThemeProvider, TokensView, type UserInfo, UserProfile, VM, WalletButton, WalletCard, WalletDisplay, type WalletInfo, type WalletKeysErrorMessage, type WalletKeysUpdateMessage, useAuth, useAvaCloudWallet, useChainId, usePostMessage, useSignMessage, useSignTransaction, useThemeMode, useTransferTokens, useUserWallets };
522
+ declare function avaCloudWallet(): CreateConnectorFn;
523
+
524
+ export { type AddAccountMessage, type AdminPortalSettings, type Auth0User, type AuthMessage, type AuthMessagePayload, type AuthStateUpdateMessage, type AuthStatusMessage, type AvaCloudEnvironment, type AvaCloudWalletContextType, AvaCloudWalletProvider, type AvaCloudWalletProviderProps, type BaseAuthMessage, type CheckAuthStatusMessage, type CubistWalletInfo, type ErrorMessage, ExportView, type GetOidcMessage, type IframeReadyMessage, LoginButton, type LoginRequestMessage, type LogoutRequestMessage, type MessageType, type OrgConfig, type ReceiveOidcMessage, ReceiveView, type RegisterMessage, type RegisterPayload, type RegisterSuccessMessage, SendView, type SignupRequestMessage, ThemeProvider, TokensView, type UserInfo, UserProfile, VM, WalletButton, WalletCard, WalletDisplay, type WalletInfo, type WalletKeysErrorMessage, type WalletKeysUpdateMessage, avaCloudWallet, useAuth, useAvaCloudWallet, useChainId, usePostMessage, useSignMessage, useSignTransaction, useThemeMode, useTransferTokens, useUserWallets };
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ __export(index_exports, {
32
32
  WalletButton: () => WalletButton,
33
33
  WalletCard: () => WalletCard,
34
34
  WalletDisplay: () => WalletDisplay,
35
+ avaCloudWallet: () => avaCloudWallet,
35
36
  useAuth: () => useAuth,
36
37
  useAvaCloudWallet: () => useAvaCloudWallet,
37
38
  useChainId: () => useChainId,
@@ -1600,7 +1601,7 @@ var queryClient = new import_react_query2.QueryClient({
1600
1601
  }
1601
1602
  });
1602
1603
  function getCubistEnv(environment) {
1603
- return environment === "gamma" || environment === "development" ? import_cubesigner_sdk.envs.gamma : import_cubesigner_sdk.envs.prod;
1604
+ return environment === "production" ? import_cubesigner_sdk.envs.prod : import_cubesigner_sdk.envs.gamma;
1604
1605
  }
1605
1606
  function ViemProviderWrapper({ children, chainId }) {
1606
1607
  const { data: blockchain } = useBlockchain(chainId.toString());
@@ -1692,7 +1693,7 @@ function AvaCloudWalletProvider({
1692
1693
  }
1693
1694
  try {
1694
1695
  const resp = await import_cubesigner_sdk2.CubeSignerClient.createOidcSession(
1695
- getCubistEnv(environment),
1696
+ getCubistEnv(environment === "production" ? "prod" : "gamma"),
1696
1697
  orgConfig.walletProviderOrgID,
1697
1698
  accessToken,
1698
1699
  ["sign:*", "manage:*", "export:*"],
@@ -4524,6 +4525,68 @@ function useUserWallets() {
4524
4525
  isLoading
4525
4526
  };
4526
4527
  }
4528
+
4529
+ // src/wagmi/connector.ts
4530
+ var import_core = require("@wagmi/core");
4531
+ var import_viem5 = require("viem");
4532
+ function avaCloudWallet() {
4533
+ return (0, import_core.createConnector)((config) => ({
4534
+ id: "avaCloudWallet",
4535
+ name: "AvaCloud Wallet",
4536
+ type: "injected",
4537
+ async connect() {
4538
+ const { walletClient } = useViem();
4539
+ if (!walletClient) {
4540
+ throw new Error("AvaCloud Wallet not connected");
4541
+ }
4542
+ const accounts = await this.getAccounts();
4543
+ const chainId = await this.getChainId();
4544
+ config.emitter.emit("connect", { accounts, chainId });
4545
+ return { accounts, chainId };
4546
+ },
4547
+ async disconnect() {
4548
+ config.emitter.emit("disconnect");
4549
+ },
4550
+ async getAccounts() {
4551
+ const { walletClient } = useViem();
4552
+ if (!(walletClient == null ? void 0 : walletClient.account)) {
4553
+ throw new Error("AvaCloud Wallet not connected or account not found.");
4554
+ }
4555
+ return [walletClient.account.address];
4556
+ },
4557
+ async getChainId() {
4558
+ const { chainId } = useViem();
4559
+ return chainId;
4560
+ },
4561
+ async getProvider() {
4562
+ const { publicClient } = useViem();
4563
+ if (!publicClient) {
4564
+ throw new Error("Public client not found.");
4565
+ }
4566
+ return publicClient;
4567
+ },
4568
+ async isAuthorized() {
4569
+ const { walletClient } = useViem();
4570
+ return !!walletClient;
4571
+ },
4572
+ onAccountsChanged(accounts) {
4573
+ if (accounts.length === 0) {
4574
+ this.disconnect();
4575
+ } else {
4576
+ config.emitter.emit("change", {
4577
+ accounts: accounts.map((x) => (0, import_viem5.getAddress)(x))
4578
+ });
4579
+ }
4580
+ },
4581
+ onChainChanged(chain) {
4582
+ const chainId = Number(chain);
4583
+ config.emitter.emit("change", { chainId });
4584
+ },
4585
+ onDisconnect() {
4586
+ config.emitter.emit("disconnect");
4587
+ }
4588
+ }));
4589
+ }
4527
4590
  // Annotate the CommonJS export names for ESM import in node:
4528
4591
  0 && (module.exports = {
4529
4592
  AvaCloudWalletProvider,
@@ -4538,6 +4601,7 @@ function useUserWallets() {
4538
4601
  WalletButton,
4539
4602
  WalletCard,
4540
4603
  WalletDisplay,
4604
+ avaCloudWallet,
4541
4605
  useAuth,
4542
4606
  useAvaCloudWallet,
4543
4607
  useChainId,
package/dist/index.mjs CHANGED
@@ -1554,7 +1554,7 @@ var queryClient = new QueryClient({
1554
1554
  }
1555
1555
  });
1556
1556
  function getCubistEnv(environment) {
1557
- return environment === "gamma" || environment === "development" ? envs.gamma : envs.prod;
1557
+ return environment === "production" ? envs.prod : envs.gamma;
1558
1558
  }
1559
1559
  function ViemProviderWrapper({ children, chainId }) {
1560
1560
  const { data: blockchain } = useBlockchain(chainId.toString());
@@ -1646,7 +1646,7 @@ function AvaCloudWalletProvider({
1646
1646
  }
1647
1647
  try {
1648
1648
  const resp = await CubeSignerClient.createOidcSession(
1649
- getCubistEnv(environment),
1649
+ getCubistEnv(environment === "production" ? "prod" : "gamma"),
1650
1650
  orgConfig.walletProviderOrgID,
1651
1651
  accessToken,
1652
1652
  ["sign:*", "manage:*", "export:*"],
@@ -4556,6 +4556,72 @@ function useUserWallets() {
4556
4556
  isLoading
4557
4557
  };
4558
4558
  }
4559
+
4560
+ // src/wagmi/connector.ts
4561
+ import {
4562
+ createConnector
4563
+ } from "@wagmi/core";
4564
+ import {
4565
+ getAddress
4566
+ } from "viem";
4567
+ function avaCloudWallet() {
4568
+ return createConnector((config) => ({
4569
+ id: "avaCloudWallet",
4570
+ name: "AvaCloud Wallet",
4571
+ type: "injected",
4572
+ async connect() {
4573
+ const { walletClient } = useViem();
4574
+ if (!walletClient) {
4575
+ throw new Error("AvaCloud Wallet not connected");
4576
+ }
4577
+ const accounts = await this.getAccounts();
4578
+ const chainId = await this.getChainId();
4579
+ config.emitter.emit("connect", { accounts, chainId });
4580
+ return { accounts, chainId };
4581
+ },
4582
+ async disconnect() {
4583
+ config.emitter.emit("disconnect");
4584
+ },
4585
+ async getAccounts() {
4586
+ const { walletClient } = useViem();
4587
+ if (!(walletClient == null ? void 0 : walletClient.account)) {
4588
+ throw new Error("AvaCloud Wallet not connected or account not found.");
4589
+ }
4590
+ return [walletClient.account.address];
4591
+ },
4592
+ async getChainId() {
4593
+ const { chainId } = useViem();
4594
+ return chainId;
4595
+ },
4596
+ async getProvider() {
4597
+ const { publicClient } = useViem();
4598
+ if (!publicClient) {
4599
+ throw new Error("Public client not found.");
4600
+ }
4601
+ return publicClient;
4602
+ },
4603
+ async isAuthorized() {
4604
+ const { walletClient } = useViem();
4605
+ return !!walletClient;
4606
+ },
4607
+ onAccountsChanged(accounts) {
4608
+ if (accounts.length === 0) {
4609
+ this.disconnect();
4610
+ } else {
4611
+ config.emitter.emit("change", {
4612
+ accounts: accounts.map((x) => getAddress(x))
4613
+ });
4614
+ }
4615
+ },
4616
+ onChainChanged(chain) {
4617
+ const chainId = Number(chain);
4618
+ config.emitter.emit("change", { chainId });
4619
+ },
4620
+ onDisconnect() {
4621
+ config.emitter.emit("disconnect");
4622
+ }
4623
+ }));
4624
+ }
4559
4625
  export {
4560
4626
  AvaCloudWalletProvider,
4561
4627
  ExportView,
@@ -4569,6 +4635,7 @@ export {
4569
4635
  WalletButton,
4570
4636
  WalletCard,
4571
4637
  WalletDisplay,
4638
+ avaCloudWallet,
4572
4639
  useAuth,
4573
4640
  useAvaCloudWallet,
4574
4641
  useChainId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avalabs/avacloud-waas-react",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "React SDK for AvaCloud Wallet as a Service",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -28,9 +28,10 @@
28
28
  "@cubist-labs/cubesigner-sdk": "0.4.110-0",
29
29
  "@iconify/react": "^4.1.1",
30
30
  "@tanstack/react-query": "^5.64.2",
31
+ "@wagmi/core": "^2.17.3",
31
32
  "lottie-react": "^2.4.0",
32
33
  "qrcode.react": "^3.1.0",
33
- "viem": "^2.5.0"
34
+ "viem": "2.31.2"
34
35
  },
35
36
  "keywords": [
36
37
  "avalanche",