@awarizon/web3 1.1.0 → 1.1.1

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 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,12 @@ 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;
37
43
  }
38
44
  interface ContractConfig<TAbi extends Abi = Abi> {
39
45
  /** The deployed contract address */
@@ -76,6 +82,8 @@ interface SDKWalletInfo {
76
82
  address: Address;
77
83
  chain: Chain;
78
84
  isExternal: boolean;
85
+ /** Name of the connector if an external wallet is active, e.g. "MetaMask" */
86
+ connectorName?: string;
79
87
  }
80
88
  interface ContractRegistryEntry {
81
89
  address: Address;
@@ -661,10 +669,26 @@ declare class WalletProxy {
661
669
  isConnected(): boolean;
662
670
  hasExternalWallet(): boolean;
663
671
  hasInternalWallet(): boolean;
664
- connectExternal(c: ExternalWalletClient): void;
672
+ getConnectorInfo(): ConnectorInfo;
673
+ connectExternal(c: ExternalWalletClient, info?: {
674
+ name?: string;
675
+ icon?: string;
676
+ }): void;
665
677
  disconnectExternal(): void;
666
678
  disconnect(): void;
667
679
  switchChain(chain: Chain): Promise<void>;
680
+ connectEIP1193(provider: EIP1193Provider, info?: {
681
+ name?: string;
682
+ icon?: string;
683
+ }): Promise<void>;
684
+ signMessage(message: string | {
685
+ raw: Hex | Uint8Array;
686
+ }): Promise<Hex>;
687
+ signTypedData(params: SignTypedDataParams): Promise<Hex>;
688
+ getChainId(): Promise<number>;
689
+ isChainMismatch(): Promise<boolean>;
690
+ onWalletChange(cb: (event: WalletChangeEvent) => void): () => void;
691
+ onChainChange(cb: (event: ChainChangeEvent) => void): () => void;
668
692
  }
669
693
  /**
670
694
  * Primary entry point for the Awarizon Web3 SDK.
@@ -694,10 +718,89 @@ declare class AwarizonWeb3 {
694
718
  private _contractCache;
695
719
  private _registry;
696
720
  constructor(config: AwarizonConfig);
697
- connectWallet(walletClient: WalletClient): this;
721
+ /**
722
+ * Connect any viem WalletClient (wagmi, RainbowKit, custom).
723
+ * Optionally pass connector metadata to display in the UI.
724
+ *
725
+ * @example
726
+ * awarizon.connectWallet(walletClient, { name: "MetaMask" })
727
+ */
728
+ connectWallet(walletClient: WalletClient, connectorInfo?: {
729
+ name?: string;
730
+ icon?: string;
731
+ }): this;
732
+ /**
733
+ * Connect directly from a raw EIP-1193 provider without needing wagmi.
734
+ * Works with window.ethereum, WalletConnect v2, and any EIP-1193 object.
735
+ *
736
+ * @example
737
+ * await awarizon.connectEIP1193Provider(window.ethereum, { name: "MetaMask" })
738
+ */
739
+ connectEIP1193Provider(provider: EIP1193Provider, connectorInfo?: {
740
+ name?: string;
741
+ icon?: string;
742
+ }): Promise<this>;
698
743
  disconnectWallet(): this;
699
744
  switchChain(chain: Chain | string): Promise<this>;
700
745
  getWalletInfo(): SDKWalletInfo;
746
+ /**
747
+ * Sign a plain text or raw-bytes message.
748
+ * Use for Sign-In with Ethereum (SIWE) and off-chain authorization.
749
+ *
750
+ * @example
751
+ * const sig = await awarizon.signMessage("Hello, Awarizon!")
752
+ */
753
+ signMessage(message: string | {
754
+ raw: Hex | Uint8Array;
755
+ }): Promise<Hex>;
756
+ /**
757
+ * Sign EIP-712 typed structured data (permit2, SIWE, Seaport orders, etc.).
758
+ *
759
+ * @example
760
+ * const sig = await awarizon.signTypedData({
761
+ * domain: { name: "MyApp", version: "1", chainId: 8453 },
762
+ * types: { Transfer: [{ name: "to", type: "address" }, { name: "amount", type: "uint256" }] },
763
+ * primaryType: "Transfer",
764
+ * message: { to: "0x...", amount: "1000000" },
765
+ * })
766
+ */
767
+ signTypedData(params: SignTypedDataParams): Promise<Hex>;
768
+ /**
769
+ * Returns the chain ID the active wallet is currently on.
770
+ * For external wallets this may differ from the SDK's configured chain.
771
+ */
772
+ getChainId(): Promise<number>;
773
+ /**
774
+ * Returns true when the external wallet is on a different chain than the SDK.
775
+ * Use this to show a "wrong network" banner in your UI.
776
+ *
777
+ * @example
778
+ * if (await awarizon.isChainMismatch()) {
779
+ * alert("Please switch to Base in your wallet")
780
+ * }
781
+ */
782
+ isChainMismatch(): Promise<boolean>;
783
+ /**
784
+ * Returns metadata about the currently active connector.
785
+ * Useful for displaying "Connected via MetaMask" in the UI.
786
+ */
787
+ getConnectorInfo(): ConnectorInfo;
788
+ /**
789
+ * Subscribe to wallet changes (connect, disconnect, account switch).
790
+ * Returns an unsubscribe function — call it on cleanup.
791
+ *
792
+ * @example
793
+ * const unsub = awarizon.onWalletChange(({ address, type, name }) => {
794
+ * console.log("Wallet changed:", address, type, name)
795
+ * })
796
+ * unsub() // stop listening
797
+ */
798
+ onWalletChange(cb: (event: WalletChangeEvent) => void): () => void;
799
+ /**
800
+ * Subscribe to chain changes (switchChain calls).
801
+ * Returns an unsubscribe function.
802
+ */
803
+ onChainChange(cb: (event: ChainChangeEvent) => void): () => void;
701
804
  /**
702
805
  * Load a deployed contract and return a fully typed, ABI-powered instance.
703
806
  * 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,12 @@ 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;
37
43
  }
38
44
  interface ContractConfig<TAbi extends Abi = Abi> {
39
45
  /** The deployed contract address */
@@ -76,6 +82,8 @@ interface SDKWalletInfo {
76
82
  address: Address;
77
83
  chain: Chain;
78
84
  isExternal: boolean;
85
+ /** Name of the connector if an external wallet is active, e.g. "MetaMask" */
86
+ connectorName?: string;
79
87
  }
80
88
  interface ContractRegistryEntry {
81
89
  address: Address;
@@ -661,10 +669,26 @@ declare class WalletProxy {
661
669
  isConnected(): boolean;
662
670
  hasExternalWallet(): boolean;
663
671
  hasInternalWallet(): boolean;
664
- connectExternal(c: ExternalWalletClient): void;
672
+ getConnectorInfo(): ConnectorInfo;
673
+ connectExternal(c: ExternalWalletClient, info?: {
674
+ name?: string;
675
+ icon?: string;
676
+ }): void;
665
677
  disconnectExternal(): void;
666
678
  disconnect(): void;
667
679
  switchChain(chain: Chain): Promise<void>;
680
+ connectEIP1193(provider: EIP1193Provider, info?: {
681
+ name?: string;
682
+ icon?: string;
683
+ }): Promise<void>;
684
+ signMessage(message: string | {
685
+ raw: Hex | Uint8Array;
686
+ }): Promise<Hex>;
687
+ signTypedData(params: SignTypedDataParams): Promise<Hex>;
688
+ getChainId(): Promise<number>;
689
+ isChainMismatch(): Promise<boolean>;
690
+ onWalletChange(cb: (event: WalletChangeEvent) => void): () => void;
691
+ onChainChange(cb: (event: ChainChangeEvent) => void): () => void;
668
692
  }
669
693
  /**
670
694
  * Primary entry point for the Awarizon Web3 SDK.
@@ -694,10 +718,89 @@ declare class AwarizonWeb3 {
694
718
  private _contractCache;
695
719
  private _registry;
696
720
  constructor(config: AwarizonConfig);
697
- connectWallet(walletClient: WalletClient): this;
721
+ /**
722
+ * Connect any viem WalletClient (wagmi, RainbowKit, custom).
723
+ * Optionally pass connector metadata to display in the UI.
724
+ *
725
+ * @example
726
+ * awarizon.connectWallet(walletClient, { name: "MetaMask" })
727
+ */
728
+ connectWallet(walletClient: WalletClient, connectorInfo?: {
729
+ name?: string;
730
+ icon?: string;
731
+ }): this;
732
+ /**
733
+ * Connect directly from a raw EIP-1193 provider without needing wagmi.
734
+ * Works with window.ethereum, WalletConnect v2, and any EIP-1193 object.
735
+ *
736
+ * @example
737
+ * await awarizon.connectEIP1193Provider(window.ethereum, { name: "MetaMask" })
738
+ */
739
+ connectEIP1193Provider(provider: EIP1193Provider, connectorInfo?: {
740
+ name?: string;
741
+ icon?: string;
742
+ }): Promise<this>;
698
743
  disconnectWallet(): this;
699
744
  switchChain(chain: Chain | string): Promise<this>;
700
745
  getWalletInfo(): SDKWalletInfo;
746
+ /**
747
+ * Sign a plain text or raw-bytes message.
748
+ * Use for Sign-In with Ethereum (SIWE) and off-chain authorization.
749
+ *
750
+ * @example
751
+ * const sig = await awarizon.signMessage("Hello, Awarizon!")
752
+ */
753
+ signMessage(message: string | {
754
+ raw: Hex | Uint8Array;
755
+ }): Promise<Hex>;
756
+ /**
757
+ * Sign EIP-712 typed structured data (permit2, SIWE, Seaport orders, etc.).
758
+ *
759
+ * @example
760
+ * const sig = await awarizon.signTypedData({
761
+ * domain: { name: "MyApp", version: "1", chainId: 8453 },
762
+ * types: { Transfer: [{ name: "to", type: "address" }, { name: "amount", type: "uint256" }] },
763
+ * primaryType: "Transfer",
764
+ * message: { to: "0x...", amount: "1000000" },
765
+ * })
766
+ */
767
+ signTypedData(params: SignTypedDataParams): Promise<Hex>;
768
+ /**
769
+ * Returns the chain ID the active wallet is currently on.
770
+ * For external wallets this may differ from the SDK's configured chain.
771
+ */
772
+ getChainId(): Promise<number>;
773
+ /**
774
+ * Returns true when the external wallet is on a different chain than the SDK.
775
+ * Use this to show a "wrong network" banner in your UI.
776
+ *
777
+ * @example
778
+ * if (await awarizon.isChainMismatch()) {
779
+ * alert("Please switch to Base in your wallet")
780
+ * }
781
+ */
782
+ isChainMismatch(): Promise<boolean>;
783
+ /**
784
+ * Returns metadata about the currently active connector.
785
+ * Useful for displaying "Connected via MetaMask" in the UI.
786
+ */
787
+ getConnectorInfo(): ConnectorInfo;
788
+ /**
789
+ * Subscribe to wallet changes (connect, disconnect, account switch).
790
+ * Returns an unsubscribe function — call it on cleanup.
791
+ *
792
+ * @example
793
+ * const unsub = awarizon.onWalletChange(({ address, type, name }) => {
794
+ * console.log("Wallet changed:", address, type, name)
795
+ * })
796
+ * unsub() // stop listening
797
+ */
798
+ onWalletChange(cb: (event: WalletChangeEvent) => void): () => void;
799
+ /**
800
+ * Subscribe to chain changes (switchChain calls).
801
+ * Returns an unsubscribe function.
802
+ */
803
+ onChainChange(cb: (event: ChainChangeEvent) => void): () => void;
701
804
  /**
702
805
  * Load a deployed contract and return a fully typed, ABI-powered instance.
703
806
  * 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
- connectExternal(c) {
432
- this.engine.connectExternal(c);
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) {
@@ -473,8 +502,27 @@ var AwarizonWeb3 = class {
473
502
  }
474
503
  }
475
504
  // ─── Wallet API surface ─────────────────────────────────────────────────────
476
- connectWallet(walletClient) {
477
- this._engine.connectExternal(walletClient);
505
+ /**
506
+ * Connect any viem WalletClient (wagmi, RainbowKit, custom).
507
+ * Optionally pass connector metadata to display in the UI.
508
+ *
509
+ * @example
510
+ * awarizon.connectWallet(walletClient, { name: "MetaMask" })
511
+ */
512
+ connectWallet(walletClient, connectorInfo) {
513
+ this._engine.connectExternal(walletClient, connectorInfo);
514
+ return this;
515
+ }
516
+ /**
517
+ * Connect directly from a raw EIP-1193 provider without needing wagmi.
518
+ * Works with window.ethereum, WalletConnect v2, and any EIP-1193 object.
519
+ *
520
+ * @example
521
+ * await awarizon.connectEIP1193Provider(window.ethereum, { name: "MetaMask" })
522
+ */
523
+ async connectEIP1193Provider(provider, connectorInfo) {
524
+ await this._telemetry.ensureValidated();
525
+ await this._engine.connectEIP1193(provider, connectorInfo);
478
526
  return this;
479
527
  }
480
528
  disconnectWallet() {
@@ -489,12 +537,86 @@ var AwarizonWeb3 = class {
489
537
  return this;
490
538
  }
491
539
  getWalletInfo() {
540
+ const info = this._engine.getConnectorInfo();
492
541
  return {
493
542
  address: this._engine.address(),
494
543
  chain: this.chain,
495
- isExternal: this._engine.hasExternalWallet()
544
+ isExternal: this._engine.hasExternalWallet(),
545
+ connectorName: info.name
496
546
  };
497
547
  }
548
+ /**
549
+ * Sign a plain text or raw-bytes message.
550
+ * Use for Sign-In with Ethereum (SIWE) and off-chain authorization.
551
+ *
552
+ * @example
553
+ * const sig = await awarizon.signMessage("Hello, Awarizon!")
554
+ */
555
+ async signMessage(message) {
556
+ await this._telemetry.ensureValidated();
557
+ return this._engine.signMessage(message);
558
+ }
559
+ /**
560
+ * Sign EIP-712 typed structured data (permit2, SIWE, Seaport orders, etc.).
561
+ *
562
+ * @example
563
+ * const sig = await awarizon.signTypedData({
564
+ * domain: { name: "MyApp", version: "1", chainId: 8453 },
565
+ * types: { Transfer: [{ name: "to", type: "address" }, { name: "amount", type: "uint256" }] },
566
+ * primaryType: "Transfer",
567
+ * message: { to: "0x...", amount: "1000000" },
568
+ * })
569
+ */
570
+ async signTypedData(params) {
571
+ await this._telemetry.ensureValidated();
572
+ return this._engine.signTypedData(params);
573
+ }
574
+ /**
575
+ * Returns the chain ID the active wallet is currently on.
576
+ * For external wallets this may differ from the SDK's configured chain.
577
+ */
578
+ async getChainId() {
579
+ return this._engine.getChainId();
580
+ }
581
+ /**
582
+ * Returns true when the external wallet is on a different chain than the SDK.
583
+ * Use this to show a "wrong network" banner in your UI.
584
+ *
585
+ * @example
586
+ * if (await awarizon.isChainMismatch()) {
587
+ * alert("Please switch to Base in your wallet")
588
+ * }
589
+ */
590
+ async isChainMismatch() {
591
+ return this._engine.isChainMismatch();
592
+ }
593
+ /**
594
+ * Returns metadata about the currently active connector.
595
+ * Useful for displaying "Connected via MetaMask" in the UI.
596
+ */
597
+ getConnectorInfo() {
598
+ return this._engine.getConnectorInfo();
599
+ }
600
+ /**
601
+ * Subscribe to wallet changes (connect, disconnect, account switch).
602
+ * Returns an unsubscribe function — call it on cleanup.
603
+ *
604
+ * @example
605
+ * const unsub = awarizon.onWalletChange(({ address, type, name }) => {
606
+ * console.log("Wallet changed:", address, type, name)
607
+ * })
608
+ * unsub() // stop listening
609
+ */
610
+ onWalletChange(cb) {
611
+ return this._engine.onWalletChange(cb);
612
+ }
613
+ /**
614
+ * Subscribe to chain changes (switchChain calls).
615
+ * Returns an unsubscribe function.
616
+ */
617
+ onChainChange(cb) {
618
+ return this._engine.onChainChange(cb);
619
+ }
498
620
  // ─── Contract API ───────────────────────────────────────────────────────────
499
621
  /**
500
622
  * Load a deployed contract and return a fully typed, ABI-powered instance.
@@ -785,6 +907,10 @@ Currently registered: ${registered}`
785
907
  }
786
908
  };
787
909
 
910
+ Object.defineProperty(exports, "ChainMismatchError", {
911
+ enumerable: true,
912
+ get: function () { return walletEngine.ChainMismatchError; }
913
+ });
788
914
  Object.defineProperty(exports, "ChainSwitchError", {
789
915
  enumerable: true,
790
916
  get: function () { return walletEngine.ChainSwitchError; }