@btc-vision/walletconnect 1.9.9 → 1.9.11

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.
@@ -1,5 +1,14 @@
1
+ /*!
2
+ * The buffer module from node.js, for the browser.
3
+ *
4
+ * @author Feross Aboukhadijeh <https://feross.org>
5
+ * @license MIT
6
+ */
7
+
1
8
  /*! For license information please see index.js.LICENSE.txt */
2
9
 
10
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
11
+
3
12
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
4
13
 
5
14
  /**
@@ -1,11 +1,12 @@
1
1
  import { type Network } from '@btc-vision/bitcoin';
2
2
  import { UnisatChainType } from '@btc-vision/transaction';
3
+ import type { SupportedWallets } from './wallets';
3
4
  export interface WalletConnectNetwork extends Network {
4
5
  chainType: UnisatChainType;
5
6
  network: string;
6
7
  }
7
8
  export interface WalletInformation {
8
- name: string;
9
+ name: SupportedWallets;
9
10
  icon: string;
10
11
  isInstalled: boolean;
11
12
  isConnected: boolean;
@@ -1,4 +1,4 @@
1
- import { type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
1
+ import { type MLDSASignature, type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import { type WalletConnectNetwork } from '../types';
4
4
  import { type SupportedWallets } from './index';
@@ -27,5 +27,9 @@ declare class WalletController {
27
27
  static removeChainChangedHook(): void;
28
28
  static registerWallet: (wallet: WalletConnectWallet) => void;
29
29
  static unbindHooks(): void;
30
+ static getMLDSAPublicKey(): Promise<string | null>;
31
+ static getHashedMLDSAKey(): Promise<string | null>;
32
+ static signMLDSAMessage(message: string): Promise<MLDSASignature | null>;
33
+ static verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
30
34
  }
31
35
  export { WalletController };
@@ -1,4 +1,4 @@
1
- import { type Unisat, UnisatChainType } from '@btc-vision/transaction';
1
+ import { type MLDSASignature, type Unisat, UnisatChainType } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import { type WalletBase } from '../types';
4
4
  declare class OPWallet implements WalletBase {
@@ -24,5 +24,9 @@ declare class OPWallet implements WalletBase {
24
24
  removeDisconnectHook(): void;
25
25
  setChainChangedHook(fn: (chainType: UnisatChainType) => void): void;
26
26
  removeChainChangedHook(): void;
27
+ getMLDSAPublicKey(): Promise<string | null>;
28
+ getHashedMLDSAKey(): Promise<string | null>;
29
+ signMLDSAMessage(message: string): Promise<MLDSASignature | null>;
30
+ verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
27
31
  }
28
32
  export default OPWallet;
@@ -1,4 +1,4 @@
1
- import { type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
1
+ import { type MLDSASignature, type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import { type SupportedWallets } from './index';
4
4
  export { type AbstractRpcProvider } from 'opnet';
@@ -20,6 +20,10 @@ export interface WalletBase {
20
20
  setChainChangedHook(fn: (network: UnisatChainType) => void): void;
21
21
  removeChainChangedHook(): void;
22
22
  getChainId(): void;
23
+ getMLDSAPublicKey(): Promise<string | null>;
24
+ getHashedMLDSAKey(): Promise<string | null>;
25
+ signMLDSAMessage(message: string): Promise<MLDSASignature | null>;
26
+ verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
23
27
  }
24
28
  export interface WalletConnectWallet {
25
29
  name: SupportedWallets;
@@ -1,4 +1,4 @@
1
- import { type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
1
+ import { type MLDSASignature, type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import { type WalletBase } from '../types';
4
4
  declare class UnisatWallet implements WalletBase {
@@ -24,5 +24,9 @@ declare class UnisatWallet implements WalletBase {
24
24
  removeDisconnectHook(): void;
25
25
  setChainChangedHook(fn: (chainType: UnisatChainType) => void): void;
26
26
  removeChainChangedHook(): void;
27
+ getMLDSAPublicKey(): Promise<string | null>;
28
+ getHashedMLDSAKey(): Promise<string | null>;
29
+ signMLDSAMessage(_message: string): Promise<MLDSASignature | null>;
30
+ verifyMLDSASignature(_message: string, _signature: MLDSASignature): Promise<boolean>;
27
31
  }
28
32
  export default UnisatWallet;
@@ -1,4 +1,4 @@
1
- import { Address, type Unisat, UnisatSigner } from '@btc-vision/transaction';
1
+ import { Address, type MLDSASignature, type Unisat, UnisatSigner } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import type { WalletBalance, WalletConnectNetwork, WalletInformation } from '../types.ts';
4
4
  import { type SupportedWallets } from '../wallets';
@@ -17,5 +17,9 @@ export type WalletConnectContextType = {
17
17
  provider: AbstractRpcProvider | null;
18
18
  signer: UnisatSigner | null;
19
19
  walletBalance: WalletBalance | null;
20
+ mldsaPublicKey: string | null;
21
+ hashedMLDSAKey: string | null;
22
+ signMLDSAMessage: (message: string) => Promise<MLDSASignature | null>;
23
+ verifyMLDSASignature: (message: string, signature: MLDSASignature) => Promise<boolean>;
20
24
  };
21
25
  export declare const WalletConnectContext: import("react").Context<WalletConnectContextType | undefined>;
@@ -23,6 +23,8 @@ const WalletConnectProvider = ({ theme, children }) => {
23
23
  const [provider, setProvider] = useState(null);
24
24
  const [signer, setSigner] = useState(null);
25
25
  const [walletBalance, setWalletBalance] = useState(null);
26
+ const [mldsaPublicKey, setMldsaPublicKey] = useState(null);
27
+ const [hashedMLDSAKey, setHashedMLDSAKey] = useState(null);
26
28
  const clearConnectError = useCallback(() => {
27
29
  if (timeoutRef.current)
28
30
  clearTimeout(timeoutRef.current);
@@ -206,13 +208,38 @@ const WalletConnectProvider = ({ theme, children }) => {
206
208
  };
207
209
  void fetchBalance();
208
210
  }, [walletAddress, walletInstance]);
211
+ useEffect(() => {
212
+ const fetchMLDSAKeys = async () => {
213
+ if (publicKey) {
214
+ const mldsaPubKey = await WalletController.getMLDSAPublicKey();
215
+ setMldsaPublicKey(mldsaPubKey);
216
+ const hashedKey = await WalletController.getHashedMLDSAKey();
217
+ setHashedMLDSAKey(hashedKey);
218
+ }
219
+ else {
220
+ setMldsaPublicKey(null);
221
+ setHashedMLDSAKey(null);
222
+ }
223
+ };
224
+ void fetchMLDSAKeys();
225
+ }, [publicKey]);
226
+ const signMLDSAMessage = useCallback(async (message) => {
227
+ return WalletController.signMLDSAMessage(message);
228
+ }, []);
229
+ const verifyMLDSASignature = useCallback(async (message, signature) => {
230
+ return WalletController.verifyMLDSASignature(message, signature);
231
+ }, []);
209
232
  const currentTheme = useMemo(() => {
210
233
  const currentTheme = theme || 'light';
211
234
  return `wallet-connect-${currentTheme}-theme`;
212
235
  }, [theme]);
213
236
  const address = useMemo(() => {
214
- return publicKey ? Address.fromString(publicKey) : null;
215
- }, [publicKey]);
237
+ return mldsaPublicKey && publicKey
238
+ ? Address.fromString(mldsaPublicKey, publicKey)
239
+ : mldsaPublicKey
240
+ ? Address.fromString(mldsaPublicKey)
241
+ : null;
242
+ }, [mldsaPublicKey, publicKey]);
216
243
  return (_jsxs(WalletConnectContext.Provider, { value: {
217
244
  walletAddress,
218
245
  publicKey,
@@ -228,6 +255,10 @@ const WalletConnectProvider = ({ theme, children }) => {
228
255
  signer,
229
256
  walletBalance,
230
257
  walletType,
258
+ mldsaPublicKey,
259
+ hashedMLDSAKey,
260
+ signMLDSAMessage,
261
+ verifyMLDSASignature,
231
262
  }, children: [children, modalOpen && (_jsx("div", { className: `wallet-connect-modal-backdrop ${currentTheme}`, children: _jsxs("div", { className: "wallet-connect-modal", role: "dialog", "aria-modal": "true", "aria-labelledby": "wallet-connect-modal-title", children: [_jsxs("div", { className: "wallet-connect-header", children: [_jsx("span", { children: "Connect Wallet" }), _jsx("button", { className: "close", onClick: () => closeConnectModal(), children: _jsx("span", { className: "close-icon", children: _jsx("svg", { width: "30px", height: "30px", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { className: "close-x-path", d: "M16 8L8 16M8.00001 8L16 16", stroke: "#fff", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) }) })] }), connectError && (_jsx("div", { className: "wallet-connect-error", children: _jsx("p", { className: "error-message", children: connectError }) })), availableWallets.length > 0 ? (_jsx("div", { className: "wallet-list", children: availableWallets.map((wallet) => (_jsxs("button", { onClick: () => connectToWallet(wallet.name), disabled: connecting || !wallet.controller.isInstalled(), className: `wallet-button ${wallet.controller.isInstalled()
232
263
  ? 'wallet-installed'
233
264
  : 'wallet-not-installed'}`, children: [wallet.icon ? (_jsx("div", { className: "wallet-icon", title: wallet.name, children: _jsx("img", { src: wallet.icon, alt: wallet.name }) })) : (_jsx("div", { className: "wallet-name", children: wallet.name })), wallet.controller.isConnected() ? (_jsx("div", { className: "wallet-connected", children: "(Connected)" })) : (_jsx(_Fragment, {})), wallet.controller.isInstalled() ? (_jsx(_Fragment, {})) : (_jsx("div", { className: "wallet-not-installed", children: "(Not Installed)" }))] }, wallet.name))) })) : pageLoaded ? (_jsxs("div", { children: [_jsx("p", { children: "No wallets available" }), _jsx("p", { children: "Supporting the following wallets" }), _jsx("div", { className: "wallet-list", children: supportedWallets.map((wallet) => (_jsx("a", { href: `https://chromewebstore.google.com/search/${wallet.name}`, children: wallet.icon ? (_jsx("div", { className: "wallet-icon", title: wallet.name, children: _jsx("img", { src: wallet.icon, alt: wallet.name }) })) : (_jsx("div", { className: "wallet-name", children: wallet.name })) }))) })] })) : (_jsxs("div", { className: "wallet-waiting-plugin", children: [_jsx("p", { children: "Loading plugins..." }), _jsx("p", { children: "Please wait" })] }))] }) }))] }));
package/build/types.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { type Network } from '@btc-vision/bitcoin';
2
2
  import { UnisatChainType } from '@btc-vision/transaction';
3
+ import type { SupportedWallets } from './wallets';
3
4
  export interface WalletConnectNetwork extends Network {
4
5
  chainType: UnisatChainType;
5
6
  network: string;
6
7
  }
7
8
  export interface WalletInformation {
8
- name: string;
9
+ name: SupportedWallets;
9
10
  icon: string;
10
11
  isInstalled: boolean;
11
12
  isConnected: boolean;
@@ -1,4 +1,4 @@
1
- import { type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
1
+ import { type MLDSASignature, type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import { type WalletConnectNetwork } from '../types';
4
4
  import { type SupportedWallets } from './index';
@@ -27,5 +27,9 @@ declare class WalletController {
27
27
  static removeChainChangedHook(): void;
28
28
  static registerWallet: (wallet: WalletConnectWallet) => void;
29
29
  static unbindHooks(): void;
30
+ static getMLDSAPublicKey(): Promise<string | null>;
31
+ static getHashedMLDSAKey(): Promise<string | null>;
32
+ static signMLDSAMessage(message: string): Promise<MLDSASignature | null>;
33
+ static verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
30
34
  }
31
35
  export { WalletController };
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  import { networks } from '@btc-vision/bitcoin';
3
- import { UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
3
+ import { UnisatChainType, UnisatSigner, } from '@btc-vision/transaction';
4
4
  import { AbstractRpcProvider } from 'opnet';
5
5
  import {} from '../types';
6
6
  import { _e } from '../utils/accessibility/errorDecoder';
@@ -190,6 +190,30 @@ class WalletController {
190
190
  this.removeChainChangedHook();
191
191
  this.removeAccountsChangedHook();
192
192
  }
193
+ static async getMLDSAPublicKey() {
194
+ const wallet = this.currentWallet;
195
+ if (!wallet)
196
+ return null;
197
+ return wallet.controller.getMLDSAPublicKey();
198
+ }
199
+ static async getHashedMLDSAKey() {
200
+ const wallet = this.currentWallet;
201
+ if (!wallet)
202
+ return null;
203
+ return wallet.controller.getHashedMLDSAKey();
204
+ }
205
+ static async signMLDSAMessage(message) {
206
+ const wallet = this.currentWallet;
207
+ if (!wallet)
208
+ return null;
209
+ return wallet.controller.signMLDSAMessage(message);
210
+ }
211
+ static async verifyMLDSASignature(message, signature) {
212
+ const wallet = this.currentWallet;
213
+ if (!wallet)
214
+ return false;
215
+ return wallet.controller.verifyMLDSASignature(message, signature);
216
+ }
193
217
  }
194
218
  _a = WalletController;
195
219
  WalletController.wallets = new Map();
@@ -1,4 +1,4 @@
1
- import { type Unisat, UnisatChainType } from '@btc-vision/transaction';
1
+ import { type MLDSASignature, type Unisat, UnisatChainType } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import { type WalletBase } from '../types';
4
4
  declare class OPWallet implements WalletBase {
@@ -24,5 +24,9 @@ declare class OPWallet implements WalletBase {
24
24
  removeDisconnectHook(): void;
25
25
  setChainChangedHook(fn: (chainType: UnisatChainType) => void): void;
26
26
  removeChainChangedHook(): void;
27
+ getMLDSAPublicKey(): Promise<string | null>;
28
+ getHashedMLDSAKey(): Promise<string | null>;
29
+ signMLDSAMessage(message: string): Promise<MLDSASignature | null>;
30
+ verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
27
31
  }
28
32
  export default OPWallet;
@@ -1,5 +1,5 @@
1
1
  import { networks } from '@btc-vision/bitcoin';
2
- import { UnisatChainType } from '@btc-vision/transaction';
2
+ import { MessageSigner, UnisatChainType, } from '@btc-vision/transaction';
3
3
  import { AbstractRpcProvider, JSONRpcProvider } from 'opnet';
4
4
  import {} from '../types';
5
5
  import {} from './interface';
@@ -151,5 +151,28 @@ class OPWallet {
151
151
  this.chainChangedHookWrapper = undefined;
152
152
  }
153
153
  }
154
+ async getMLDSAPublicKey() {
155
+ if (!this._isConnected || !this.walletBase?.web3)
156
+ return null;
157
+ return this.walletBase.web3.getMLDSAPublicKey();
158
+ }
159
+ async getHashedMLDSAKey() {
160
+ const mldsaPublicKey = await this.getMLDSAPublicKey();
161
+ if (!mldsaPublicKey)
162
+ return null;
163
+ const publicKeyBuffer = Buffer.from(mldsaPublicKey, 'hex');
164
+ const hash = MessageSigner.sha256(publicKeyBuffer);
165
+ return hash.toString('hex');
166
+ }
167
+ async signMLDSAMessage(message) {
168
+ if (!this._isConnected || !this.walletBase?.web3)
169
+ return null;
170
+ return this.walletBase.web3.signMLDSAMessage(message);
171
+ }
172
+ async verifyMLDSASignature(message, signature) {
173
+ if (!this._isConnected || !this.walletBase?.web3)
174
+ return false;
175
+ return this.walletBase.web3.verifyMLDSASignature(message, signature);
176
+ }
154
177
  }
155
178
  export default OPWallet;
@@ -1,4 +1,4 @@
1
- import { type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
1
+ import { type MLDSASignature, type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import { type SupportedWallets } from './index';
4
4
  export { type AbstractRpcProvider } from 'opnet';
@@ -20,6 +20,10 @@ export interface WalletBase {
20
20
  setChainChangedHook(fn: (network: UnisatChainType) => void): void;
21
21
  removeChainChangedHook(): void;
22
22
  getChainId(): void;
23
+ getMLDSAPublicKey(): Promise<string | null>;
24
+ getHashedMLDSAKey(): Promise<string | null>;
25
+ signMLDSAMessage(message: string): Promise<MLDSASignature | null>;
26
+ verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
23
27
  }
24
28
  export interface WalletConnectWallet {
25
29
  name: SupportedWallets;
@@ -1,4 +1,4 @@
1
- import { UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
1
+ import { UnisatChainType, UnisatSigner, } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import {} from './index';
4
4
  export {} from 'opnet';
@@ -1,4 +1,4 @@
1
- import { type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
1
+ import { type MLDSASignature, type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import { type WalletBase } from '../types';
4
4
  declare class UnisatWallet implements WalletBase {
@@ -24,5 +24,9 @@ declare class UnisatWallet implements WalletBase {
24
24
  removeDisconnectHook(): void;
25
25
  setChainChangedHook(fn: (chainType: UnisatChainType) => void): void;
26
26
  removeChainChangedHook(): void;
27
+ getMLDSAPublicKey(): Promise<string | null>;
28
+ getHashedMLDSAKey(): Promise<string | null>;
29
+ signMLDSAMessage(_message: string): Promise<MLDSASignature | null>;
30
+ verifyMLDSASignature(_message: string, _signature: MLDSASignature): Promise<boolean>;
27
31
  }
28
32
  export default UnisatWallet;
@@ -153,5 +153,17 @@ class UnisatWallet {
153
153
  this.chainChangedHookWrapper = undefined;
154
154
  }
155
155
  }
156
+ getMLDSAPublicKey() {
157
+ return Promise.resolve(null);
158
+ }
159
+ getHashedMLDSAKey() {
160
+ return Promise.resolve(null);
161
+ }
162
+ signMLDSAMessage(_message) {
163
+ return Promise.resolve(null);
164
+ }
165
+ verifyMLDSASignature(_message, _signature) {
166
+ return Promise.resolve(false);
167
+ }
156
168
  }
157
169
  export default UnisatWallet;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/walletconnect",
3
3
  "type": "module",
4
- "version": "1.9.9",
4
+ "version": "1.9.11",
5
5
  "author": "impredmet",
6
6
  "description": "The OP_NET Wallet Connect library helps your dApp connect to any compatible wallet.",
7
7
  "engines": {
@@ -67,35 +67,36 @@
67
67
  "react-dom": "^19"
68
68
  },
69
69
  "devDependencies": {
70
- "@babel/preset-env": "^7.28.3",
71
- "@babel/preset-react": "^7.27.1",
72
- "@babel/preset-typescript": "^7.27.1",
73
- "@types/react": "^19.2.2",
74
- "eslint-plugin-react-hooks": "^7.0.0",
70
+ "@babel/preset-env": "^7.28.5",
71
+ "@babel/preset-react": "^7.28.5",
72
+ "@babel/preset-typescript": "^7.28.5",
73
+ "@types/react": "^19.2.7",
74
+ "baseline-browser-mapping": "^2.9.7",
75
+ "eslint-plugin-react-hooks": "^7.0.1",
75
76
  "eslint-plugin-react-refresh": "^0.4.24",
76
77
  "gulp": "^5.0.1",
77
78
  "gulp-cached": "^1.1.1",
78
79
  "gulp-typescript": "^6.0.0-alpha.1",
79
80
  "https-browserify": "^1.0.0",
80
81
  "os-browserify": "^0.3.0",
81
- "react": "^19.2.0",
82
- "react-dom": "^19.2.0",
82
+ "react": "^19.2.3",
83
+ "react-dom": "^19.2.3",
83
84
  "stream-browserify": "^3.0.0",
84
85
  "stream-http": "^3.2.0",
85
- "typescript-eslint": "^8.46.1",
86
+ "typescript-eslint": "^8.49.0",
86
87
  "webpack-cli": "^6.0.1"
87
88
  },
88
89
  "dependencies": {
89
- "@btc-vision/bitcoin": "^6.4.10",
90
- "@btc-vision/transaction": "^1.6.18",
91
- "@eslint/js": "^9.38.0",
90
+ "@btc-vision/bitcoin": "^6.4.11",
91
+ "@btc-vision/transaction": "^1.7.19",
92
+ "@eslint/js": "^9.39.1",
92
93
  "css-loader": "^7.1.2",
93
- "eslint-plugin-react-hooks": "^7.0.0",
94
+ "eslint-plugin-react-hooks": "^7.0.1",
94
95
  "gulp-clean": "^0.4.0",
95
96
  "gulp-eslint-new": "^2.5.0",
96
97
  "gulp-logger-new": "^1.0.1",
97
- "opnet": "^1.6.41",
98
+ "opnet": "^1.7.16",
98
99
  "style-loader": "^4.0.0",
99
- "webpack": "^5.102.1"
100
+ "webpack": "^5.103.0"
100
101
  }
101
102
  }
@@ -1,4 +1,4 @@
1
- import { Address, type Unisat, UnisatSigner } from '@btc-vision/transaction';
1
+ import { Address, type MLDSASignature, type Unisat, UnisatSigner } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import { createContext } from 'react';
4
4
  import type { WalletBalance, WalletConnectNetwork, WalletInformation } from '../types.ts';
@@ -19,6 +19,10 @@ export type WalletConnectContextType = {
19
19
  provider: AbstractRpcProvider | null;
20
20
  signer: UnisatSigner | null;
21
21
  walletBalance: WalletBalance | null;
22
+ mldsaPublicKey: string | null;
23
+ hashedMLDSAKey: string | null;
24
+ signMLDSAMessage: (message: string) => Promise<MLDSASignature | null>;
25
+ verifyMLDSASignature: (message: string, signature: MLDSASignature) => Promise<boolean>;
22
26
  };
23
27
 
24
28
  export const WalletConnectContext = createContext<WalletConnectContextType | undefined>(undefined);
@@ -1,4 +1,4 @@
1
- import { Address, type Unisat, UnisatSigner } from '@btc-vision/transaction';
1
+ import { Address, type MLDSASignature, type Unisat, UnisatSigner } from '@btc-vision/transaction';
2
2
  import { AbstractRpcProvider } from 'opnet';
3
3
  import React, { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import { WalletConnectContext } from '../context/WalletConnectContext';
@@ -40,6 +40,9 @@ const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({ theme, ch
40
40
  const [signer, setSigner] = useState<UnisatSigner | null>(null);
41
41
  const [walletBalance, setWalletBalance] = useState<WalletBalance | null>(null);
42
42
 
43
+ const [mldsaPublicKey, setMldsaPublicKey] = useState<string | null>(null);
44
+ const [hashedMLDSAKey, setHashedMLDSAKey] = useState<string | null>(null);
45
+
43
46
  const clearConnectError = useCallback(() => {
44
47
  if (timeoutRef.current) clearTimeout(timeoutRef.current);
45
48
  timeoutRef.current = setTimeout(() => setConnectError(undefined), 5000);
@@ -260,14 +263,48 @@ const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({ theme, ch
260
263
  void fetchBalance();
261
264
  }, [walletAddress, walletInstance]);
262
265
 
266
+ useEffect(() => {
267
+ const fetchMLDSAKeys = async () => {
268
+ if (publicKey) {
269
+ const mldsaPubKey = await WalletController.getMLDSAPublicKey();
270
+ setMldsaPublicKey(mldsaPubKey);
271
+
272
+ const hashedKey = await WalletController.getHashedMLDSAKey();
273
+ setHashedMLDSAKey(hashedKey);
274
+ } else {
275
+ setMldsaPublicKey(null);
276
+ setHashedMLDSAKey(null);
277
+ }
278
+ };
279
+ void fetchMLDSAKeys();
280
+ }, [publicKey]);
281
+
282
+ const signMLDSAMessage = useCallback(
283
+ async (message: string): Promise<MLDSASignature | null> => {
284
+ return WalletController.signMLDSAMessage(message);
285
+ },
286
+ [],
287
+ );
288
+
289
+ const verifyMLDSASignature = useCallback(
290
+ async (message: string, signature: MLDSASignature): Promise<boolean> => {
291
+ return WalletController.verifyMLDSASignature(message, signature);
292
+ },
293
+ [],
294
+ );
295
+
263
296
  const currentTheme = useMemo(() => {
264
297
  const currentTheme = theme || 'light';
265
298
  return `wallet-connect-${currentTheme}-theme`;
266
299
  }, [theme]);
267
300
 
268
301
  const address = useMemo(() => {
269
- return publicKey ? Address.fromString(publicKey) : null;
270
- }, [publicKey]);
302
+ return mldsaPublicKey && publicKey
303
+ ? Address.fromString(mldsaPublicKey, publicKey)
304
+ : mldsaPublicKey
305
+ ? Address.fromString(mldsaPublicKey)
306
+ : null;
307
+ }, [mldsaPublicKey, publicKey]);
271
308
 
272
309
  return (
273
310
  <WalletConnectContext.Provider
@@ -286,6 +323,10 @@ const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({ theme, ch
286
323
  signer,
287
324
  walletBalance,
288
325
  walletType,
326
+ mldsaPublicKey,
327
+ hashedMLDSAKey,
328
+ signMLDSAMessage,
329
+ verifyMLDSASignature,
289
330
  }}>
290
331
  {children}
291
332
  {modalOpen && (
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type Network } from '@btc-vision/bitcoin';
2
2
  import { UnisatChainType } from '@btc-vision/transaction';
3
+ import type { SupportedWallets } from './wallets';
3
4
 
4
5
  export interface WalletConnectNetwork extends Network {
5
6
  chainType: UnisatChainType;
@@ -7,7 +8,7 @@ export interface WalletConnectNetwork extends Network {
7
8
  }
8
9
 
9
10
  export interface WalletInformation {
10
- name: string;
11
+ name: SupportedWallets;
11
12
  icon: string;
12
13
  isInstalled: boolean;
13
14
  isConnected: boolean;
@@ -1,5 +1,10 @@
1
1
  import { type Network, networks } from '@btc-vision/bitcoin';
2
- import { type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
2
+ import {
3
+ type MLDSASignature,
4
+ type Unisat,
5
+ UnisatChainType,
6
+ UnisatSigner,
7
+ } from '@btc-vision/transaction';
3
8
  import { AbstractRpcProvider } from 'opnet';
4
9
  import { type WalletConnectNetwork } from '../types';
5
10
  import { _e } from '../utils/accessibility/errorDecoder';
@@ -227,6 +232,37 @@ class WalletController {
227
232
  this.removeChainChangedHook();
228
233
  this.removeAccountsChangedHook();
229
234
  }
235
+
236
+ static async getMLDSAPublicKey(): Promise<string | null> {
237
+ const wallet = this.currentWallet;
238
+ if (!wallet) return null;
239
+
240
+ return wallet.controller.getMLDSAPublicKey();
241
+ }
242
+
243
+ static async getHashedMLDSAKey(): Promise<string | null> {
244
+ const wallet = this.currentWallet;
245
+ if (!wallet) return null;
246
+
247
+ return wallet.controller.getHashedMLDSAKey();
248
+ }
249
+
250
+ static async signMLDSAMessage(message: string): Promise<MLDSASignature | null> {
251
+ const wallet = this.currentWallet;
252
+ if (!wallet) return null;
253
+
254
+ return wallet.controller.signMLDSAMessage(message);
255
+ }
256
+
257
+ static async verifyMLDSASignature(
258
+ message: string,
259
+ signature: MLDSASignature,
260
+ ): Promise<boolean> {
261
+ const wallet = this.currentWallet;
262
+ if (!wallet) return false;
263
+
264
+ return wallet.controller.verifyMLDSASignature(message, signature);
265
+ }
230
266
  }
231
267
 
232
268
  export { WalletController };
@@ -1,5 +1,11 @@
1
1
  import { networks } from '@btc-vision/bitcoin';
2
- import { type Unisat, type UnisatChainInfo, UnisatChainType } from '@btc-vision/transaction';
2
+ import {
3
+ MessageSigner,
4
+ type MLDSASignature,
5
+ type Unisat,
6
+ type UnisatChainInfo,
7
+ UnisatChainType,
8
+ } from '@btc-vision/transaction';
3
9
  import { AbstractRpcProvider, JSONRpcProvider } from 'opnet';
4
10
  import { type WalletBase } from '../types';
5
11
  import { type OPWalletInterface } from './interface';
@@ -194,6 +200,33 @@ class OPWallet implements WalletBase {
194
200
  this.chainChangedHookWrapper = undefined;
195
201
  }
196
202
  }
203
+
204
+ async getMLDSAPublicKey(): Promise<string | null> {
205
+ if (!this._isConnected || !this.walletBase?.web3) return null;
206
+
207
+ return this.walletBase.web3.getMLDSAPublicKey();
208
+ }
209
+
210
+ async getHashedMLDSAKey(): Promise<string | null> {
211
+ const mldsaPublicKey = await this.getMLDSAPublicKey();
212
+ if (!mldsaPublicKey) return null;
213
+
214
+ const publicKeyBuffer = Buffer.from(mldsaPublicKey, 'hex');
215
+ const hash = MessageSigner.sha256(publicKeyBuffer);
216
+ return hash.toString('hex');
217
+ }
218
+
219
+ async signMLDSAMessage(message: string): Promise<MLDSASignature | null> {
220
+ if (!this._isConnected || !this.walletBase?.web3) return null;
221
+
222
+ return this.walletBase.web3.signMLDSAMessage(message);
223
+ }
224
+
225
+ async verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean> {
226
+ if (!this._isConnected || !this.walletBase?.web3) return false;
227
+
228
+ return this.walletBase.web3.verifyMLDSASignature(message, signature);
229
+ }
197
230
  }
198
231
 
199
232
  export default OPWallet;
@@ -1,4 +1,9 @@
1
- import { type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
1
+ import {
2
+ type MLDSASignature,
3
+ type Unisat,
4
+ UnisatChainType,
5
+ UnisatSigner,
6
+ } from '@btc-vision/transaction';
2
7
  import { AbstractRpcProvider } from 'opnet';
3
8
  import { type SupportedWallets } from './index';
4
9
  export { type AbstractRpcProvider } from 'opnet';
@@ -21,6 +26,10 @@ export interface WalletBase {
21
26
  setChainChangedHook(fn: (network: UnisatChainType) => void): void;
22
27
  removeChainChangedHook(): void;
23
28
  getChainId(): void;
29
+ getMLDSAPublicKey(): Promise<string | null>;
30
+ getHashedMLDSAKey(): Promise<string | null>;
31
+ signMLDSAMessage(message: string): Promise<MLDSASignature | null>;
32
+ verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
24
33
  }
25
34
 
26
35
  export interface WalletConnectWallet {