@awarizon/web3 1.1.0 → 1.2.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/dist/index.d.mts +136 -4
- package/dist/index.d.ts +136 -4
- package/dist/index.js +180 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +177 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Chain, WalletClient, Address, Abi, PublicClient, Hex } from 'viem';
|
|
2
2
|
export { Abi, Address, Chain, Hash, TransactionReceipt, WalletClient } from 'viem';
|
|
3
|
-
import { WalletEngine, CreatedWallet, ImportedWalletFromMnemonic, ImportedWalletFromPrivateKey, ExternalWalletClient } from '@awarizon/wallet-engine';
|
|
4
|
-
export { ChainSwitchError, InvalidMnemonicError, InvalidPrivateKeyError, WalletEngine, WalletNotConnectedError } from '@awarizon/wallet-engine';
|
|
3
|
+
import { WalletEngine, CreatedWallet, ImportedWalletFromMnemonic, ImportedWalletFromPrivateKey, ConnectorInfo, ExternalWalletClient, EIP1193Provider, SignTypedDataParams, WalletChangeEvent, ChainChangeEvent } from '@awarizon/wallet-engine';
|
|
4
|
+
export { ChainChangeEvent, ChainMismatchError, ChainSwitchError, ConnectorInfo, CreatedWallet, EIP1193Provider, ImportedWalletFromMnemonic, ImportedWalletFromPrivateKey, InvalidMnemonicError, InvalidPrivateKeyError, SignTypedDataParams, WalletChangeEvent, WalletEngine, WalletNotConnectedError } from '@awarizon/wallet-engine';
|
|
5
5
|
import { TransactionResult } from '@awarizon/tx-engine';
|
|
6
6
|
export { ContractExecutionError, GasEstimationError, SimulationError, TransactionEngine, TransactionResult, TransactionTimeoutError } from '@awarizon/tx-engine';
|
|
7
7
|
export { DuplicateFunctionError, InvalidABIError, UnsupportedABIItemError, generateAllMethodSignatures, generateMethodSignature, isPayableFunction, isWriteFunction, parseABI } from '@awarizon/abi-engine';
|
|
@@ -34,6 +34,23 @@ interface AwarizonConfig {
|
|
|
34
34
|
* Override for local development or staging environments.
|
|
35
35
|
*/
|
|
36
36
|
baseUrl?: string;
|
|
37
|
+
/**
|
|
38
|
+
* When true, the SDK automatically requests a chain switch on the external
|
|
39
|
+
* wallet before every write if the wallet is on the wrong network.
|
|
40
|
+
* Only affects external wallets (wagmi, RainbowKit, EIP-1193).
|
|
41
|
+
*/
|
|
42
|
+
autoSwitchChain?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* WalletConnect v2 project ID.
|
|
45
|
+
* Required when using `awarizon.connectWalletConnect()` or the built-in
|
|
46
|
+
* `<ConnectButton />` to connect mobile wallets via WalletConnect.
|
|
47
|
+
*
|
|
48
|
+
* Get a free project ID at https://cloud.walletconnect.com
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* new AwarizonWeb3({ chain: "base", apiKey: "awz_live_...", walletConnectProjectId: "abc123" })
|
|
52
|
+
*/
|
|
53
|
+
walletConnectProjectId?: string;
|
|
37
54
|
}
|
|
38
55
|
interface ContractConfig<TAbi extends Abi = Abi> {
|
|
39
56
|
/** The deployed contract address */
|
|
@@ -76,6 +93,8 @@ interface SDKWalletInfo {
|
|
|
76
93
|
address: Address;
|
|
77
94
|
chain: Chain;
|
|
78
95
|
isExternal: boolean;
|
|
96
|
+
/** Name of the connector if an external wallet is active, e.g. "MetaMask" */
|
|
97
|
+
connectorName?: string;
|
|
79
98
|
}
|
|
80
99
|
interface ContractRegistryEntry {
|
|
81
100
|
address: Address;
|
|
@@ -661,10 +680,26 @@ declare class WalletProxy {
|
|
|
661
680
|
isConnected(): boolean;
|
|
662
681
|
hasExternalWallet(): boolean;
|
|
663
682
|
hasInternalWallet(): boolean;
|
|
664
|
-
|
|
683
|
+
getConnectorInfo(): ConnectorInfo;
|
|
684
|
+
connectExternal(c: ExternalWalletClient, info?: {
|
|
685
|
+
name?: string;
|
|
686
|
+
icon?: string;
|
|
687
|
+
}): void;
|
|
665
688
|
disconnectExternal(): void;
|
|
666
689
|
disconnect(): void;
|
|
667
690
|
switchChain(chain: Chain): Promise<void>;
|
|
691
|
+
connectEIP1193(provider: EIP1193Provider, info?: {
|
|
692
|
+
name?: string;
|
|
693
|
+
icon?: string;
|
|
694
|
+
}): Promise<void>;
|
|
695
|
+
signMessage(message: string | {
|
|
696
|
+
raw: Hex | Uint8Array;
|
|
697
|
+
}): Promise<Hex>;
|
|
698
|
+
signTypedData(params: SignTypedDataParams): Promise<Hex>;
|
|
699
|
+
getChainId(): Promise<number>;
|
|
700
|
+
isChainMismatch(): Promise<boolean>;
|
|
701
|
+
onWalletChange(cb: (event: WalletChangeEvent) => void): () => void;
|
|
702
|
+
onChainChange(cb: (event: ChainChangeEvent) => void): () => void;
|
|
668
703
|
}
|
|
669
704
|
/**
|
|
670
705
|
* Primary entry point for the Awarizon Web3 SDK.
|
|
@@ -691,13 +726,110 @@ declare class AwarizonWeb3 {
|
|
|
691
726
|
private readonly _engine;
|
|
692
727
|
private readonly _txEngine;
|
|
693
728
|
private readonly _telemetry;
|
|
729
|
+
private readonly _walletConnectProjectId;
|
|
694
730
|
private _contractCache;
|
|
695
731
|
private _registry;
|
|
696
732
|
constructor(config: AwarizonConfig);
|
|
697
|
-
|
|
733
|
+
/**
|
|
734
|
+
* Connect any viem WalletClient (wagmi, RainbowKit, custom).
|
|
735
|
+
* Optionally pass connector metadata to display in the UI.
|
|
736
|
+
*
|
|
737
|
+
* @example
|
|
738
|
+
* awarizon.connectWallet(walletClient, { name: "MetaMask" })
|
|
739
|
+
*/
|
|
740
|
+
connectWallet(walletClient: WalletClient, connectorInfo?: {
|
|
741
|
+
name?: string;
|
|
742
|
+
icon?: string;
|
|
743
|
+
}): this;
|
|
744
|
+
/**
|
|
745
|
+
* Connect directly from a raw EIP-1193 provider without needing wagmi.
|
|
746
|
+
* Works with window.ethereum, WalletConnect v2, and any EIP-1193 object.
|
|
747
|
+
*
|
|
748
|
+
* @example
|
|
749
|
+
* await awarizon.connectEIP1193Provider(window.ethereum, { name: "MetaMask" })
|
|
750
|
+
*/
|
|
751
|
+
connectEIP1193Provider(provider: EIP1193Provider, connectorInfo?: {
|
|
752
|
+
name?: string;
|
|
753
|
+
icon?: string;
|
|
754
|
+
}): Promise<this>;
|
|
755
|
+
/**
|
|
756
|
+
* Connect a mobile or desktop wallet using the WalletConnect v2 protocol.
|
|
757
|
+
* Opens a QR-code modal (or deeplink on mobile) so the user can scan with
|
|
758
|
+
* MetaMask, Rainbow, Trust Wallet, or any WalletConnect-compatible wallet.
|
|
759
|
+
*
|
|
760
|
+
* Requires `walletConnectProjectId` in the SDK config and the peer package:
|
|
761
|
+
* `npm install @walletconnect/ethereum-provider`
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* ```ts
|
|
765
|
+
* const awarizon = new AwarizonWeb3({ chain: "base", apiKey: "...", walletConnectProjectId: "abc" })
|
|
766
|
+
* await awarizon.connectWalletConnect()
|
|
767
|
+
* ```
|
|
768
|
+
*/
|
|
769
|
+
connectWalletConnect(): Promise<this>;
|
|
770
|
+
/** The WalletConnect project ID passed at construction, if any */
|
|
771
|
+
get walletConnectProjectId(): string | undefined;
|
|
698
772
|
disconnectWallet(): this;
|
|
699
773
|
switchChain(chain: Chain | string): Promise<this>;
|
|
700
774
|
getWalletInfo(): SDKWalletInfo;
|
|
775
|
+
/**
|
|
776
|
+
* Sign a plain text or raw-bytes message.
|
|
777
|
+
* Use for Sign-In with Ethereum (SIWE) and off-chain authorization.
|
|
778
|
+
*
|
|
779
|
+
* @example
|
|
780
|
+
* const sig = await awarizon.signMessage("Hello, Awarizon!")
|
|
781
|
+
*/
|
|
782
|
+
signMessage(message: string | {
|
|
783
|
+
raw: Hex | Uint8Array;
|
|
784
|
+
}): Promise<Hex>;
|
|
785
|
+
/**
|
|
786
|
+
* Sign EIP-712 typed structured data (permit2, SIWE, Seaport orders, etc.).
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* const sig = await awarizon.signTypedData({
|
|
790
|
+
* domain: { name: "MyApp", version: "1", chainId: 8453 },
|
|
791
|
+
* types: { Transfer: [{ name: "to", type: "address" }, { name: "amount", type: "uint256" }] },
|
|
792
|
+
* primaryType: "Transfer",
|
|
793
|
+
* message: { to: "0x...", amount: "1000000" },
|
|
794
|
+
* })
|
|
795
|
+
*/
|
|
796
|
+
signTypedData(params: SignTypedDataParams): Promise<Hex>;
|
|
797
|
+
/**
|
|
798
|
+
* Returns the chain ID the active wallet is currently on.
|
|
799
|
+
* For external wallets this may differ from the SDK's configured chain.
|
|
800
|
+
*/
|
|
801
|
+
getChainId(): Promise<number>;
|
|
802
|
+
/**
|
|
803
|
+
* Returns true when the external wallet is on a different chain than the SDK.
|
|
804
|
+
* Use this to show a "wrong network" banner in your UI.
|
|
805
|
+
*
|
|
806
|
+
* @example
|
|
807
|
+
* if (await awarizon.isChainMismatch()) {
|
|
808
|
+
* alert("Please switch to Base in your wallet")
|
|
809
|
+
* }
|
|
810
|
+
*/
|
|
811
|
+
isChainMismatch(): Promise<boolean>;
|
|
812
|
+
/**
|
|
813
|
+
* Returns metadata about the currently active connector.
|
|
814
|
+
* Useful for displaying "Connected via MetaMask" in the UI.
|
|
815
|
+
*/
|
|
816
|
+
getConnectorInfo(): ConnectorInfo;
|
|
817
|
+
/**
|
|
818
|
+
* Subscribe to wallet changes (connect, disconnect, account switch).
|
|
819
|
+
* Returns an unsubscribe function — call it on cleanup.
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* const unsub = awarizon.onWalletChange(({ address, type, name }) => {
|
|
823
|
+
* console.log("Wallet changed:", address, type, name)
|
|
824
|
+
* })
|
|
825
|
+
* unsub() // stop listening
|
|
826
|
+
*/
|
|
827
|
+
onWalletChange(cb: (event: WalletChangeEvent) => void): () => void;
|
|
828
|
+
/**
|
|
829
|
+
* Subscribe to chain changes (switchChain calls).
|
|
830
|
+
* Returns an unsubscribe function.
|
|
831
|
+
*/
|
|
832
|
+
onChainChange(cb: (event: ChainChangeEvent) => void): () => void;
|
|
701
833
|
/**
|
|
702
834
|
* Load a deployed contract and return a fully typed, ABI-powered instance.
|
|
703
835
|
* Validates the API key on the first call — subsequent calls are instant.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Chain, WalletClient, Address, Abi, PublicClient, Hex } from 'viem';
|
|
2
2
|
export { Abi, Address, Chain, Hash, TransactionReceipt, WalletClient } from 'viem';
|
|
3
|
-
import { WalletEngine, CreatedWallet, ImportedWalletFromMnemonic, ImportedWalletFromPrivateKey, ExternalWalletClient } from '@awarizon/wallet-engine';
|
|
4
|
-
export { ChainSwitchError, InvalidMnemonicError, InvalidPrivateKeyError, WalletEngine, WalletNotConnectedError } from '@awarizon/wallet-engine';
|
|
3
|
+
import { WalletEngine, CreatedWallet, ImportedWalletFromMnemonic, ImportedWalletFromPrivateKey, ConnectorInfo, ExternalWalletClient, EIP1193Provider, SignTypedDataParams, WalletChangeEvent, ChainChangeEvent } from '@awarizon/wallet-engine';
|
|
4
|
+
export { ChainChangeEvent, ChainMismatchError, ChainSwitchError, ConnectorInfo, CreatedWallet, EIP1193Provider, ImportedWalletFromMnemonic, ImportedWalletFromPrivateKey, InvalidMnemonicError, InvalidPrivateKeyError, SignTypedDataParams, WalletChangeEvent, WalletEngine, WalletNotConnectedError } from '@awarizon/wallet-engine';
|
|
5
5
|
import { TransactionResult } from '@awarizon/tx-engine';
|
|
6
6
|
export { ContractExecutionError, GasEstimationError, SimulationError, TransactionEngine, TransactionResult, TransactionTimeoutError } from '@awarizon/tx-engine';
|
|
7
7
|
export { DuplicateFunctionError, InvalidABIError, UnsupportedABIItemError, generateAllMethodSignatures, generateMethodSignature, isPayableFunction, isWriteFunction, parseABI } from '@awarizon/abi-engine';
|
|
@@ -34,6 +34,23 @@ interface AwarizonConfig {
|
|
|
34
34
|
* Override for local development or staging environments.
|
|
35
35
|
*/
|
|
36
36
|
baseUrl?: string;
|
|
37
|
+
/**
|
|
38
|
+
* When true, the SDK automatically requests a chain switch on the external
|
|
39
|
+
* wallet before every write if the wallet is on the wrong network.
|
|
40
|
+
* Only affects external wallets (wagmi, RainbowKit, EIP-1193).
|
|
41
|
+
*/
|
|
42
|
+
autoSwitchChain?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* WalletConnect v2 project ID.
|
|
45
|
+
* Required when using `awarizon.connectWalletConnect()` or the built-in
|
|
46
|
+
* `<ConnectButton />` to connect mobile wallets via WalletConnect.
|
|
47
|
+
*
|
|
48
|
+
* Get a free project ID at https://cloud.walletconnect.com
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* new AwarizonWeb3({ chain: "base", apiKey: "awz_live_...", walletConnectProjectId: "abc123" })
|
|
52
|
+
*/
|
|
53
|
+
walletConnectProjectId?: string;
|
|
37
54
|
}
|
|
38
55
|
interface ContractConfig<TAbi extends Abi = Abi> {
|
|
39
56
|
/** The deployed contract address */
|
|
@@ -76,6 +93,8 @@ interface SDKWalletInfo {
|
|
|
76
93
|
address: Address;
|
|
77
94
|
chain: Chain;
|
|
78
95
|
isExternal: boolean;
|
|
96
|
+
/** Name of the connector if an external wallet is active, e.g. "MetaMask" */
|
|
97
|
+
connectorName?: string;
|
|
79
98
|
}
|
|
80
99
|
interface ContractRegistryEntry {
|
|
81
100
|
address: Address;
|
|
@@ -661,10 +680,26 @@ declare class WalletProxy {
|
|
|
661
680
|
isConnected(): boolean;
|
|
662
681
|
hasExternalWallet(): boolean;
|
|
663
682
|
hasInternalWallet(): boolean;
|
|
664
|
-
|
|
683
|
+
getConnectorInfo(): ConnectorInfo;
|
|
684
|
+
connectExternal(c: ExternalWalletClient, info?: {
|
|
685
|
+
name?: string;
|
|
686
|
+
icon?: string;
|
|
687
|
+
}): void;
|
|
665
688
|
disconnectExternal(): void;
|
|
666
689
|
disconnect(): void;
|
|
667
690
|
switchChain(chain: Chain): Promise<void>;
|
|
691
|
+
connectEIP1193(provider: EIP1193Provider, info?: {
|
|
692
|
+
name?: string;
|
|
693
|
+
icon?: string;
|
|
694
|
+
}): Promise<void>;
|
|
695
|
+
signMessage(message: string | {
|
|
696
|
+
raw: Hex | Uint8Array;
|
|
697
|
+
}): Promise<Hex>;
|
|
698
|
+
signTypedData(params: SignTypedDataParams): Promise<Hex>;
|
|
699
|
+
getChainId(): Promise<number>;
|
|
700
|
+
isChainMismatch(): Promise<boolean>;
|
|
701
|
+
onWalletChange(cb: (event: WalletChangeEvent) => void): () => void;
|
|
702
|
+
onChainChange(cb: (event: ChainChangeEvent) => void): () => void;
|
|
668
703
|
}
|
|
669
704
|
/**
|
|
670
705
|
* Primary entry point for the Awarizon Web3 SDK.
|
|
@@ -691,13 +726,110 @@ declare class AwarizonWeb3 {
|
|
|
691
726
|
private readonly _engine;
|
|
692
727
|
private readonly _txEngine;
|
|
693
728
|
private readonly _telemetry;
|
|
729
|
+
private readonly _walletConnectProjectId;
|
|
694
730
|
private _contractCache;
|
|
695
731
|
private _registry;
|
|
696
732
|
constructor(config: AwarizonConfig);
|
|
697
|
-
|
|
733
|
+
/**
|
|
734
|
+
* Connect any viem WalletClient (wagmi, RainbowKit, custom).
|
|
735
|
+
* Optionally pass connector metadata to display in the UI.
|
|
736
|
+
*
|
|
737
|
+
* @example
|
|
738
|
+
* awarizon.connectWallet(walletClient, { name: "MetaMask" })
|
|
739
|
+
*/
|
|
740
|
+
connectWallet(walletClient: WalletClient, connectorInfo?: {
|
|
741
|
+
name?: string;
|
|
742
|
+
icon?: string;
|
|
743
|
+
}): this;
|
|
744
|
+
/**
|
|
745
|
+
* Connect directly from a raw EIP-1193 provider without needing wagmi.
|
|
746
|
+
* Works with window.ethereum, WalletConnect v2, and any EIP-1193 object.
|
|
747
|
+
*
|
|
748
|
+
* @example
|
|
749
|
+
* await awarizon.connectEIP1193Provider(window.ethereum, { name: "MetaMask" })
|
|
750
|
+
*/
|
|
751
|
+
connectEIP1193Provider(provider: EIP1193Provider, connectorInfo?: {
|
|
752
|
+
name?: string;
|
|
753
|
+
icon?: string;
|
|
754
|
+
}): Promise<this>;
|
|
755
|
+
/**
|
|
756
|
+
* Connect a mobile or desktop wallet using the WalletConnect v2 protocol.
|
|
757
|
+
* Opens a QR-code modal (or deeplink on mobile) so the user can scan with
|
|
758
|
+
* MetaMask, Rainbow, Trust Wallet, or any WalletConnect-compatible wallet.
|
|
759
|
+
*
|
|
760
|
+
* Requires `walletConnectProjectId` in the SDK config and the peer package:
|
|
761
|
+
* `npm install @walletconnect/ethereum-provider`
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* ```ts
|
|
765
|
+
* const awarizon = new AwarizonWeb3({ chain: "base", apiKey: "...", walletConnectProjectId: "abc" })
|
|
766
|
+
* await awarizon.connectWalletConnect()
|
|
767
|
+
* ```
|
|
768
|
+
*/
|
|
769
|
+
connectWalletConnect(): Promise<this>;
|
|
770
|
+
/** The WalletConnect project ID passed at construction, if any */
|
|
771
|
+
get walletConnectProjectId(): string | undefined;
|
|
698
772
|
disconnectWallet(): this;
|
|
699
773
|
switchChain(chain: Chain | string): Promise<this>;
|
|
700
774
|
getWalletInfo(): SDKWalletInfo;
|
|
775
|
+
/**
|
|
776
|
+
* Sign a plain text or raw-bytes message.
|
|
777
|
+
* Use for Sign-In with Ethereum (SIWE) and off-chain authorization.
|
|
778
|
+
*
|
|
779
|
+
* @example
|
|
780
|
+
* const sig = await awarizon.signMessage("Hello, Awarizon!")
|
|
781
|
+
*/
|
|
782
|
+
signMessage(message: string | {
|
|
783
|
+
raw: Hex | Uint8Array;
|
|
784
|
+
}): Promise<Hex>;
|
|
785
|
+
/**
|
|
786
|
+
* Sign EIP-712 typed structured data (permit2, SIWE, Seaport orders, etc.).
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* const sig = await awarizon.signTypedData({
|
|
790
|
+
* domain: { name: "MyApp", version: "1", chainId: 8453 },
|
|
791
|
+
* types: { Transfer: [{ name: "to", type: "address" }, { name: "amount", type: "uint256" }] },
|
|
792
|
+
* primaryType: "Transfer",
|
|
793
|
+
* message: { to: "0x...", amount: "1000000" },
|
|
794
|
+
* })
|
|
795
|
+
*/
|
|
796
|
+
signTypedData(params: SignTypedDataParams): Promise<Hex>;
|
|
797
|
+
/**
|
|
798
|
+
* Returns the chain ID the active wallet is currently on.
|
|
799
|
+
* For external wallets this may differ from the SDK's configured chain.
|
|
800
|
+
*/
|
|
801
|
+
getChainId(): Promise<number>;
|
|
802
|
+
/**
|
|
803
|
+
* Returns true when the external wallet is on a different chain than the SDK.
|
|
804
|
+
* Use this to show a "wrong network" banner in your UI.
|
|
805
|
+
*
|
|
806
|
+
* @example
|
|
807
|
+
* if (await awarizon.isChainMismatch()) {
|
|
808
|
+
* alert("Please switch to Base in your wallet")
|
|
809
|
+
* }
|
|
810
|
+
*/
|
|
811
|
+
isChainMismatch(): Promise<boolean>;
|
|
812
|
+
/**
|
|
813
|
+
* Returns metadata about the currently active connector.
|
|
814
|
+
* Useful for displaying "Connected via MetaMask" in the UI.
|
|
815
|
+
*/
|
|
816
|
+
getConnectorInfo(): ConnectorInfo;
|
|
817
|
+
/**
|
|
818
|
+
* Subscribe to wallet changes (connect, disconnect, account switch).
|
|
819
|
+
* Returns an unsubscribe function — call it on cleanup.
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* const unsub = awarizon.onWalletChange(({ address, type, name }) => {
|
|
823
|
+
* console.log("Wallet changed:", address, type, name)
|
|
824
|
+
* })
|
|
825
|
+
* unsub() // stop listening
|
|
826
|
+
*/
|
|
827
|
+
onWalletChange(cb: (event: WalletChangeEvent) => void): () => void;
|
|
828
|
+
/**
|
|
829
|
+
* Subscribe to chain changes (switchChain calls).
|
|
830
|
+
* Returns an unsubscribe function.
|
|
831
|
+
*/
|
|
832
|
+
onChainChange(cb: (event: ChainChangeEvent) => void): () => void;
|
|
701
833
|
/**
|
|
702
834
|
* Load a deployed contract and return a fully typed, ABI-powered instance.
|
|
703
835
|
* Validates the API key on the first call — subsequent calls are instant.
|
package/dist/index.js
CHANGED
|
@@ -428,8 +428,11 @@ var WalletProxy = class {
|
|
|
428
428
|
hasInternalWallet() {
|
|
429
429
|
return this.engine.hasInternalWallet();
|
|
430
430
|
}
|
|
431
|
-
|
|
432
|
-
this.engine.
|
|
431
|
+
getConnectorInfo() {
|
|
432
|
+
return this.engine.getConnectorInfo();
|
|
433
|
+
}
|
|
434
|
+
connectExternal(c, info) {
|
|
435
|
+
this.engine.connectExternal(c, info);
|
|
433
436
|
}
|
|
434
437
|
disconnectExternal() {
|
|
435
438
|
this.engine.disconnectExternal();
|
|
@@ -440,6 +443,32 @@ var WalletProxy = class {
|
|
|
440
443
|
async switchChain(chain) {
|
|
441
444
|
return this.engine.switchChain(chain);
|
|
442
445
|
}
|
|
446
|
+
// ── Gated async — EIP-1193, signing, chain awareness ───────────────────────
|
|
447
|
+
async connectEIP1193(provider, info) {
|
|
448
|
+
await this.ensureReady();
|
|
449
|
+
return this.engine.connectEIP1193(provider, info);
|
|
450
|
+
}
|
|
451
|
+
async signMessage(message) {
|
|
452
|
+
await this.ensureReady();
|
|
453
|
+
return this.engine.signMessage(message);
|
|
454
|
+
}
|
|
455
|
+
async signTypedData(params) {
|
|
456
|
+
await this.ensureReady();
|
|
457
|
+
return this.engine.signTypedData(params);
|
|
458
|
+
}
|
|
459
|
+
async getChainId() {
|
|
460
|
+
return this.engine.getChainId();
|
|
461
|
+
}
|
|
462
|
+
async isChainMismatch() {
|
|
463
|
+
return this.engine.isChainMismatch();
|
|
464
|
+
}
|
|
465
|
+
// ── Event subscriptions ────────────────────────────────────────────────────
|
|
466
|
+
onWalletChange(cb) {
|
|
467
|
+
return this.engine.onWalletChange(cb);
|
|
468
|
+
}
|
|
469
|
+
onChainChange(cb) {
|
|
470
|
+
return this.engine.onChainChange(cb);
|
|
471
|
+
}
|
|
443
472
|
};
|
|
444
473
|
var AwarizonWeb3 = class {
|
|
445
474
|
constructor(config) {
|
|
@@ -464,6 +493,7 @@ var AwarizonWeb3 = class {
|
|
|
464
493
|
() => this._engine.getWalletClient()
|
|
465
494
|
);
|
|
466
495
|
this._telemetry = new TelemetryClient(config.apiKey, config.baseUrl);
|
|
496
|
+
this._walletConnectProjectId = config.walletConnectProjectId;
|
|
467
497
|
this.wallet = new WalletProxy(
|
|
468
498
|
this._engine,
|
|
469
499
|
() => this._telemetry.ensureValidated()
|
|
@@ -473,10 +503,77 @@ var AwarizonWeb3 = class {
|
|
|
473
503
|
}
|
|
474
504
|
}
|
|
475
505
|
// ─── Wallet API surface ─────────────────────────────────────────────────────
|
|
476
|
-
|
|
477
|
-
|
|
506
|
+
/**
|
|
507
|
+
* Connect any viem WalletClient (wagmi, RainbowKit, custom).
|
|
508
|
+
* Optionally pass connector metadata to display in the UI.
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* awarizon.connectWallet(walletClient, { name: "MetaMask" })
|
|
512
|
+
*/
|
|
513
|
+
connectWallet(walletClient, connectorInfo) {
|
|
514
|
+
this._engine.connectExternal(walletClient, connectorInfo);
|
|
478
515
|
return this;
|
|
479
516
|
}
|
|
517
|
+
/**
|
|
518
|
+
* Connect directly from a raw EIP-1193 provider without needing wagmi.
|
|
519
|
+
* Works with window.ethereum, WalletConnect v2, and any EIP-1193 object.
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* await awarizon.connectEIP1193Provider(window.ethereum, { name: "MetaMask" })
|
|
523
|
+
*/
|
|
524
|
+
async connectEIP1193Provider(provider, connectorInfo) {
|
|
525
|
+
await this._telemetry.ensureValidated();
|
|
526
|
+
await this._engine.connectEIP1193(provider, connectorInfo);
|
|
527
|
+
return this;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Connect a mobile or desktop wallet using the WalletConnect v2 protocol.
|
|
531
|
+
* Opens a QR-code modal (or deeplink on mobile) so the user can scan with
|
|
532
|
+
* MetaMask, Rainbow, Trust Wallet, or any WalletConnect-compatible wallet.
|
|
533
|
+
*
|
|
534
|
+
* Requires `walletConnectProjectId` in the SDK config and the peer package:
|
|
535
|
+
* `npm install @walletconnect/ethereum-provider`
|
|
536
|
+
*
|
|
537
|
+
* @example
|
|
538
|
+
* ```ts
|
|
539
|
+
* const awarizon = new AwarizonWeb3({ chain: "base", apiKey: "...", walletConnectProjectId: "abc" })
|
|
540
|
+
* await awarizon.connectWalletConnect()
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
async connectWalletConnect() {
|
|
544
|
+
if (!this._walletConnectProjectId) {
|
|
545
|
+
throw new Error(
|
|
546
|
+
'[awarizon/web3] walletConnectProjectId is not configured. Pass it when creating the SDK: new AwarizonWeb3({ ..., walletConnectProjectId: "your_id" }).\nGet a free project ID at https://cloud.walletconnect.com'
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
let EthereumProvider;
|
|
550
|
+
try {
|
|
551
|
+
const load = new Function("id", "return import(id)");
|
|
552
|
+
EthereumProvider = (await load("@walletconnect/ethereum-provider")).default;
|
|
553
|
+
} catch {
|
|
554
|
+
throw new Error(
|
|
555
|
+
"[awarizon/web3] @walletconnect/ethereum-provider is not installed.\nRun: npm install @walletconnect/ethereum-provider"
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
const provider = await EthereumProvider.init({
|
|
559
|
+
projectId: this._walletConnectProjectId,
|
|
560
|
+
chains: [this.chain.id],
|
|
561
|
+
showQrModal: true,
|
|
562
|
+
optionalChains: [],
|
|
563
|
+
methods: ["eth_sendTransaction", "personal_sign", "eth_signTypedData_v4"],
|
|
564
|
+
events: ["chainChanged", "accountsChanged"]
|
|
565
|
+
});
|
|
566
|
+
await provider.connect();
|
|
567
|
+
await this.connectEIP1193Provider(provider, {
|
|
568
|
+
name: "WalletConnect",
|
|
569
|
+
icon: "https://avatars.githubusercontent.com/u/37784886"
|
|
570
|
+
});
|
|
571
|
+
return this;
|
|
572
|
+
}
|
|
573
|
+
/** The WalletConnect project ID passed at construction, if any */
|
|
574
|
+
get walletConnectProjectId() {
|
|
575
|
+
return this._walletConnectProjectId;
|
|
576
|
+
}
|
|
480
577
|
disconnectWallet() {
|
|
481
578
|
this._engine.disconnectExternal();
|
|
482
579
|
return this;
|
|
@@ -489,12 +586,86 @@ var AwarizonWeb3 = class {
|
|
|
489
586
|
return this;
|
|
490
587
|
}
|
|
491
588
|
getWalletInfo() {
|
|
589
|
+
const info = this._engine.getConnectorInfo();
|
|
492
590
|
return {
|
|
493
591
|
address: this._engine.address(),
|
|
494
592
|
chain: this.chain,
|
|
495
|
-
isExternal: this._engine.hasExternalWallet()
|
|
593
|
+
isExternal: this._engine.hasExternalWallet(),
|
|
594
|
+
connectorName: info.name
|
|
496
595
|
};
|
|
497
596
|
}
|
|
597
|
+
/**
|
|
598
|
+
* Sign a plain text or raw-bytes message.
|
|
599
|
+
* Use for Sign-In with Ethereum (SIWE) and off-chain authorization.
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* const sig = await awarizon.signMessage("Hello, Awarizon!")
|
|
603
|
+
*/
|
|
604
|
+
async signMessage(message) {
|
|
605
|
+
await this._telemetry.ensureValidated();
|
|
606
|
+
return this._engine.signMessage(message);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Sign EIP-712 typed structured data (permit2, SIWE, Seaport orders, etc.).
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* const sig = await awarizon.signTypedData({
|
|
613
|
+
* domain: { name: "MyApp", version: "1", chainId: 8453 },
|
|
614
|
+
* types: { Transfer: [{ name: "to", type: "address" }, { name: "amount", type: "uint256" }] },
|
|
615
|
+
* primaryType: "Transfer",
|
|
616
|
+
* message: { to: "0x...", amount: "1000000" },
|
|
617
|
+
* })
|
|
618
|
+
*/
|
|
619
|
+
async signTypedData(params) {
|
|
620
|
+
await this._telemetry.ensureValidated();
|
|
621
|
+
return this._engine.signTypedData(params);
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Returns the chain ID the active wallet is currently on.
|
|
625
|
+
* For external wallets this may differ from the SDK's configured chain.
|
|
626
|
+
*/
|
|
627
|
+
async getChainId() {
|
|
628
|
+
return this._engine.getChainId();
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Returns true when the external wallet is on a different chain than the SDK.
|
|
632
|
+
* Use this to show a "wrong network" banner in your UI.
|
|
633
|
+
*
|
|
634
|
+
* @example
|
|
635
|
+
* if (await awarizon.isChainMismatch()) {
|
|
636
|
+
* alert("Please switch to Base in your wallet")
|
|
637
|
+
* }
|
|
638
|
+
*/
|
|
639
|
+
async isChainMismatch() {
|
|
640
|
+
return this._engine.isChainMismatch();
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Returns metadata about the currently active connector.
|
|
644
|
+
* Useful for displaying "Connected via MetaMask" in the UI.
|
|
645
|
+
*/
|
|
646
|
+
getConnectorInfo() {
|
|
647
|
+
return this._engine.getConnectorInfo();
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Subscribe to wallet changes (connect, disconnect, account switch).
|
|
651
|
+
* Returns an unsubscribe function — call it on cleanup.
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* const unsub = awarizon.onWalletChange(({ address, type, name }) => {
|
|
655
|
+
* console.log("Wallet changed:", address, type, name)
|
|
656
|
+
* })
|
|
657
|
+
* unsub() // stop listening
|
|
658
|
+
*/
|
|
659
|
+
onWalletChange(cb) {
|
|
660
|
+
return this._engine.onWalletChange(cb);
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Subscribe to chain changes (switchChain calls).
|
|
664
|
+
* Returns an unsubscribe function.
|
|
665
|
+
*/
|
|
666
|
+
onChainChange(cb) {
|
|
667
|
+
return this._engine.onChainChange(cb);
|
|
668
|
+
}
|
|
498
669
|
// ─── Contract API ───────────────────────────────────────────────────────────
|
|
499
670
|
/**
|
|
500
671
|
* Load a deployed contract and return a fully typed, ABI-powered instance.
|
|
@@ -785,6 +956,10 @@ Currently registered: ${registered}`
|
|
|
785
956
|
}
|
|
786
957
|
};
|
|
787
958
|
|
|
959
|
+
Object.defineProperty(exports, "ChainMismatchError", {
|
|
960
|
+
enumerable: true,
|
|
961
|
+
get: function () { return walletEngine.ChainMismatchError; }
|
|
962
|
+
});
|
|
788
963
|
Object.defineProperty(exports, "ChainSwitchError", {
|
|
789
964
|
enumerable: true,
|
|
790
965
|
get: function () { return walletEngine.ChainSwitchError; }
|