uvd-x402-sdk 2.14.1 → 2.15.2

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.
@@ -12,6 +12,17 @@ import { c as WalletAdapter, C as ChainConfig, P as PaymentInfo, l as X402Versio
12
12
  * 3. SignedDelegateAction is sent to facilitator
13
13
  * 4. Facilitator wraps it and submits to NEAR, paying all gas
14
14
  *
15
+ * NEP-366 Wallet Support:
16
+ * For apps that need wallet selector integration, call setupWalletSelector() early:
17
+ *
18
+ * ```ts
19
+ * // In your app's initialization (e.g., App.tsx or main.ts)
20
+ * await NEARProvider.setupWalletSelector({
21
+ * walletUrl: 'https://mynearwallet.ultravioletadao.xyz',
22
+ * contractId: '17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1',
23
+ * });
24
+ * ```
25
+ *
15
26
  * @example
16
27
  * ```ts
17
28
  * import { NEARProvider } from 'uvd-x402-sdk/near';
@@ -29,6 +40,17 @@ import { c as WalletAdapter, C as ChainConfig, P as PaymentInfo, l as X402Versio
29
40
  * ```
30
41
  */
31
42
 
43
+ /**
44
+ * Options for configuring the NEAR wallet selector helper
45
+ */
46
+ interface WalletSelectorOptions {
47
+ /** URL of the MyNearWallet instance (default: https://mynearwallet.ultravioletadao.xyz) */
48
+ walletUrl?: string;
49
+ /** USDC contract ID for NEAR (default: 17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1) */
50
+ contractId?: string;
51
+ /** NEAR network ID (default: mainnet) */
52
+ networkId?: string;
53
+ }
32
54
  /**
33
55
  * NEARProvider - Wallet adapter for NEAR Protocol via MyNearWallet/Meteor
34
56
  */
@@ -39,6 +61,22 @@ declare class NEARProvider implements WalletAdapter {
39
61
  private accountId;
40
62
  private publicKey;
41
63
  private rpcUrl;
64
+ /**
65
+ * Setup wallet selector for NEP-366 meta-transaction support.
66
+ *
67
+ * Call this once early in your app initialization (e.g., App.tsx or main.ts)
68
+ * to configure the NEAR wallet selector before using NEARProvider.
69
+ *
70
+ * @param options - Configuration options for wallet selector
71
+ * @example
72
+ * ```ts
73
+ * await NEARProvider.setupWalletSelector({
74
+ * walletUrl: 'https://mynearwallet.ultravioletadao.xyz',
75
+ * contractId: '17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1',
76
+ * });
77
+ * ```
78
+ */
79
+ static setupWalletSelector(options?: WalletSelectorOptions): Promise<void>;
42
80
  /**
43
81
  * Check if NEAR wallet is available
44
82
  */
@@ -100,4 +138,4 @@ declare class NEARProvider implements WalletAdapter {
100
138
  private base58Encode;
101
139
  }
102
140
 
103
- export { NEARProvider, NEARProvider as default };
141
+ export { NEARProvider, type WalletSelectorOptions, NEARProvider as default };
@@ -12,6 +12,17 @@ import { c as WalletAdapter, C as ChainConfig, P as PaymentInfo, l as X402Versio
12
12
  * 3. SignedDelegateAction is sent to facilitator
13
13
  * 4. Facilitator wraps it and submits to NEAR, paying all gas
14
14
  *
15
+ * NEP-366 Wallet Support:
16
+ * For apps that need wallet selector integration, call setupWalletSelector() early:
17
+ *
18
+ * ```ts
19
+ * // In your app's initialization (e.g., App.tsx or main.ts)
20
+ * await NEARProvider.setupWalletSelector({
21
+ * walletUrl: 'https://mynearwallet.ultravioletadao.xyz',
22
+ * contractId: '17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1',
23
+ * });
24
+ * ```
25
+ *
15
26
  * @example
16
27
  * ```ts
17
28
  * import { NEARProvider } from 'uvd-x402-sdk/near';
@@ -29,6 +40,17 @@ import { c as WalletAdapter, C as ChainConfig, P as PaymentInfo, l as X402Versio
29
40
  * ```
30
41
  */
31
42
 
43
+ /**
44
+ * Options for configuring the NEAR wallet selector helper
45
+ */
46
+ interface WalletSelectorOptions {
47
+ /** URL of the MyNearWallet instance (default: https://mynearwallet.ultravioletadao.xyz) */
48
+ walletUrl?: string;
49
+ /** USDC contract ID for NEAR (default: 17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1) */
50
+ contractId?: string;
51
+ /** NEAR network ID (default: mainnet) */
52
+ networkId?: string;
53
+ }
32
54
  /**
33
55
  * NEARProvider - Wallet adapter for NEAR Protocol via MyNearWallet/Meteor
34
56
  */
@@ -39,6 +61,22 @@ declare class NEARProvider implements WalletAdapter {
39
61
  private accountId;
40
62
  private publicKey;
41
63
  private rpcUrl;
64
+ /**
65
+ * Setup wallet selector for NEP-366 meta-transaction support.
66
+ *
67
+ * Call this once early in your app initialization (e.g., App.tsx or main.ts)
68
+ * to configure the NEAR wallet selector before using NEARProvider.
69
+ *
70
+ * @param options - Configuration options for wallet selector
71
+ * @example
72
+ * ```ts
73
+ * await NEARProvider.setupWalletSelector({
74
+ * walletUrl: 'https://mynearwallet.ultravioletadao.xyz',
75
+ * contractId: '17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1',
76
+ * });
77
+ * ```
78
+ */
79
+ static setupWalletSelector(options?: WalletSelectorOptions): Promise<void>;
42
80
  /**
43
81
  * Check if NEAR wallet is available
44
82
  */
@@ -100,4 +138,4 @@ declare class NEARProvider implements WalletAdapter {
100
138
  private base58Encode;
101
139
  }
102
140
 
103
- export { NEARProvider, NEARProvider as default };
141
+ export { NEARProvider, type WalletSelectorOptions, NEARProvider as default };
@@ -785,6 +785,73 @@ var NEARProvider = class {
785
785
  accountId = null;
786
786
  publicKey = null;
787
787
  rpcUrl = NEAR_CONFIG.nodeUrl;
788
+ /**
789
+ * Setup wallet selector for NEP-366 meta-transaction support.
790
+ *
791
+ * Call this once early in your app initialization (e.g., App.tsx or main.ts)
792
+ * to configure the NEAR wallet selector before using NEARProvider.
793
+ *
794
+ * @param options - Configuration options for wallet selector
795
+ * @example
796
+ * ```ts
797
+ * await NEARProvider.setupWalletSelector({
798
+ * walletUrl: 'https://mynearwallet.ultravioletadao.xyz',
799
+ * contractId: '17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1',
800
+ * });
801
+ * ```
802
+ */
803
+ static async setupWalletSelector(options = {}) {
804
+ const {
805
+ walletUrl = "https://mynearwallet.ultravioletadao.xyz",
806
+ contractId = "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
807
+ networkId = "mainnet"
808
+ } = options;
809
+ if (typeof window === "undefined") {
810
+ throw new X402Error(
811
+ "setupWalletSelector() must be called in a browser environment",
812
+ "WALLET_NOT_FOUND"
813
+ );
814
+ }
815
+ try {
816
+ const [{ setupWalletSelector }, { setupMyNearWallet }] = await Promise.all([
817
+ import('@near-wallet-selector/core'),
818
+ import('@near-wallet-selector/my-near-wallet')
819
+ ]);
820
+ const selector = await setupWalletSelector({
821
+ network: networkId,
822
+ modules: [
823
+ setupMyNearWallet({
824
+ walletUrl
825
+ })
826
+ ]
827
+ });
828
+ const win = window;
829
+ win.nearWalletSelector = {
830
+ isSignedIn: () => selector.isSignedIn(),
831
+ getAccountId: () => {
832
+ const state = selector.store.getState();
833
+ return state.accounts[0]?.accountId || null;
834
+ },
835
+ signIn: async (signInOptions) => {
836
+ const wallet = await selector.wallet("my-near-wallet");
837
+ const signInFn = wallet.signIn;
838
+ await signInFn({
839
+ contractId: signInOptions?.contractId || contractId
840
+ });
841
+ },
842
+ signOut: async () => {
843
+ const wallet = await selector.wallet("my-near-wallet");
844
+ await wallet.signOut();
845
+ }
846
+ };
847
+ } catch (error) {
848
+ throw new X402Error(
849
+ `Failed to setup wallet selector: ${error instanceof Error ? error.message : "Unknown error"}. Make sure @near-wallet-selector/core and @near-wallet-selector/my-near-wallet are installed.`,
850
+ "WALLET_NOT_FOUND",
851
+ error
852
+ );
853
+ }
854
+ }
788
855
  /**
789
856
  * Check if NEAR wallet is available
790
857
  */
@@ -830,7 +897,7 @@ var NEARProvider = class {
830
897
  return accountId;
831
898
  }
832
899
  throw new X402Error(
833
- "No NEAR wallet found. Please install MyNearWallet or Meteor.",
900
+ "No NEAR wallet found. Call NEARProvider.setupWalletSelector() first, or install MyNearWallet/Meteor.",
834
901
  "WALLET_NOT_FOUND"
835
902
  );
836
903
  } catch (error) {
@@ -1044,6 +1111,22 @@ var NEARProvider = class {
1044
1111
  */
1045
1112
  async signMessage(message) {
1046
1113
  const win = window;
1114
+ if (win.nearWalletSelector?.wallet) {
1115
+ try {
1116
+ const wallet = await win.nearWalletSelector.wallet();
1117
+ if (wallet?.signMessage) {
1118
+ const nonce = crypto.getRandomValues(new Uint8Array(32));
1119
+ const result = await wallet.signMessage({
1120
+ message,
1121
+ recipient: "uvd-x402-sdk",
1122
+ nonce
1123
+ });
1124
+ return result.signature;
1125
+ }
1126
+ } catch (e) {
1127
+ console.debug("Wallet selector signMessage failed:", e);
1128
+ }
1129
+ }
1047
1130
  if (win.myNearWallet?.signMessage) {
1048
1131
  const result = await win.myNearWallet.signMessage({
1049
1132
  message,