@matchain/matchid-sdk-react 0.1.11 → 0.1.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/dist/index.mjs CHANGED
@@ -983,13 +983,14 @@ var useStore = create2((set) => ({
983
983
  var useStore_default = useStore;
984
984
 
985
985
  // src/hooks/useWallet.tsx
986
+ import { toAccount } from "viem/accounts";
986
987
  var AppClientId = "react-sdk-" + getVersion();
987
988
  function useWallet() {
988
- const { appid, token, overview } = useLocalStore_default();
989
+ const { appid, token, overview, address } = useLocalStore_default();
989
990
  const { setRecoveryModal, closeRecoveryModal } = useStore_default();
990
991
  const initWallet = ({
991
992
  did,
992
- address
993
+ address: address2
993
994
  }) => {
994
995
  return window.waitMatchUntilWalletMessage(
995
996
  "initCore",
@@ -998,7 +999,7 @@ function useWallet() {
998
999
  AppClientId,
999
1000
  UserId: did,
1000
1001
  AccessToken: token,
1001
- Address: address
1002
+ Address: address2
1002
1003
  }
1003
1004
  );
1004
1005
  };
@@ -1011,33 +1012,21 @@ function useWallet() {
1011
1012
  userPasscode
1012
1013
  }) => {
1013
1014
  return await window.waitMatchUntilWalletMessage("generateWallet", {
1015
+ chainType: "ethereum",
1014
1016
  recoveryType: "user_passcode_recovery_key",
1015
1017
  userPasscode
1016
1018
  });
1017
1019
  };
1018
- const signMessage = async (message, type) => {
1020
+ const recoverAfter = async (func) => {
1019
1021
  return new Promise(async (resolve, reject) => {
1020
1022
  const res = await isRecovered();
1021
1023
  matchlog_default.log("isRecovered", res);
1022
- const getSign = async () => {
1023
- try {
1024
- const recoverRes = await window.waitMatchUntilWalletMessage("signMessage", {
1025
- message,
1026
- chainType: type
1027
- });
1028
- closeRecoveryModal();
1029
- resolve(recoverRes);
1030
- } catch (error) {
1031
- console.error("qwe-sign-error", error);
1032
- reject(error);
1033
- }
1034
- };
1035
1024
  if (!res) {
1036
1025
  setRecoveryModal({
1037
1026
  open: true,
1038
1027
  success: async () => {
1039
1028
  matchlog_default.log("recover Success");
1040
- await getSign();
1029
+ await func(resolve, reject);
1041
1030
  },
1042
1031
  close: async () => {
1043
1032
  closeRecoveryModal();
@@ -1050,48 +1039,41 @@ function useWallet() {
1050
1039
  });
1051
1040
  } else {
1052
1041
  await recoveryWallet("ethereum", "user_passcode_recovery_key");
1053
- await getSign();
1042
+ await func(resolve, reject);
1054
1043
  }
1055
1044
  });
1056
1045
  };
1057
- const signTransaction = async (transaction, type) => {
1058
- return new Promise(async (resolve, reject) => {
1059
- const res = await isRecovered();
1060
- matchlog_default.log("isRecovered", res);
1061
- const getSign = async () => {
1062
- try {
1063
- const recoverRes = await window.waitMatchUntilWalletMessage("signTransaction", {
1064
- transaction,
1065
- chainType: type
1066
- });
1067
- closeRecoveryModal();
1068
- resolve(recoverRes);
1069
- } catch (error) {
1070
- console.error("qwe-sign-error", error);
1071
- reject(error);
1072
- }
1073
- };
1074
- if (!res) {
1075
- setRecoveryModal({
1076
- open: true,
1077
- success: async () => {
1078
- matchlog_default.log("recover Success");
1079
- await getSign();
1080
- },
1081
- close: async () => {
1082
- closeRecoveryModal();
1083
- reject(new Error("recover modal close"));
1084
- }
1046
+ const signMessage = async (message, type) => {
1047
+ const getSign = async (resolve, reject) => {
1048
+ try {
1049
+ const recoverRes = await window.waitMatchUntilWalletMessage("signMessage", {
1050
+ message,
1051
+ chainType: type
1085
1052
  });
1086
- await initWallet({
1087
- address: overview?.address || "",
1088
- did: overview?.did?.split(":")[2] || ""
1053
+ closeRecoveryModal();
1054
+ resolve(recoverRes);
1055
+ } catch (error) {
1056
+ console.error("qwe-sign-error", error);
1057
+ reject(error);
1058
+ }
1059
+ };
1060
+ return await recoverAfter(getSign);
1061
+ };
1062
+ const signTransaction = async (transaction, type) => {
1063
+ const getSign = async (resolve, reject) => {
1064
+ try {
1065
+ const recoverRes = await window.waitMatchUntilWalletMessage("signTransaction", {
1066
+ transaction,
1067
+ chainType: type
1089
1068
  });
1090
- } else {
1091
- await recoveryWallet("ethereum", "user_passcode_recovery_key");
1092
- await getSign();
1069
+ closeRecoveryModal();
1070
+ resolve(recoverRes);
1071
+ } catch (error) {
1072
+ console.error("qwe-sign-error", error);
1073
+ reject(error);
1093
1074
  }
1094
- });
1075
+ };
1076
+ return await recoverAfter(getSign);
1095
1077
  };
1096
1078
  const recoveryWallet = async (chainType, recoveryType, userPasscode) => {
1097
1079
  return await window.waitMatchUntilWalletMessage("recoveryWallet", {
@@ -1100,13 +1082,32 @@ function useWallet() {
1100
1082
  userPasscode
1101
1083
  });
1102
1084
  };
1085
+ const evmAccount = address ? toAccount({
1086
+ address,
1087
+ async signMessage({ message }) {
1088
+ return await signMessage(message);
1089
+ },
1090
+ async signTransaction(transaction, options) {
1091
+ const { account, ...restTransaction } = transaction;
1092
+ const sign = await signTransaction({
1093
+ ...restTransaction
1094
+ });
1095
+ return sign;
1096
+ },
1097
+ async signTypedData(typedData) {
1098
+ return "0x";
1099
+ }
1100
+ }) : void 0;
1103
1101
  return {
1102
+ evmAccount,
1103
+ address,
1104
1104
  recoveryWallet,
1105
1105
  initWallet,
1106
1106
  generateWallet,
1107
1107
  signMessage,
1108
1108
  signTransaction,
1109
- isRecovered
1109
+ isRecovered,
1110
+ recoverAfter
1110
1111
  };
1111
1112
  }
1112
1113
 
@@ -2101,8 +2102,78 @@ function usePohList(options) {
2101
2102
  ...options
2102
2103
  });
2103
2104
  }
2105
+
2106
+ // src/config/chains/index.ts
2107
+ var chains_exports = {};
2108
+ __export(chains_exports, {
2109
+ MatchMain: () => matchMain,
2110
+ MatchTest: () => matchTest
2111
+ });
2112
+
2113
+ // src/config/chains/MatchMain.ts
2114
+ import { defineChain } from "viem";
2115
+ var matchMain = /* @__PURE__ */ defineChain({
2116
+ //定义match链
2117
+ id: 698,
2118
+ name: "Matchain",
2119
+ nativeCurrency: { name: "Match Coin", symbol: "BNB", decimals: 18 },
2120
+ rpcUrls: {
2121
+ default: {
2122
+ http: ["https://rpc.matchain.io"]
2123
+ }
2124
+ },
2125
+ blockExplorers: {
2126
+ default: {
2127
+ name: "Matchscan",
2128
+ url: "https://matchscan.io/",
2129
+ apiUrl: "https://matchscan.io/api"
2130
+ }
2131
+ },
2132
+ iconUrl: "https://matchscan.io/static/identicon_logos/blockies.png",
2133
+ contracts: {
2134
+ multicall3: {
2135
+ address: "0xca11bde05977b3631167028862be2a173976ca11"
2136
+ }
2137
+ }
2138
+ // testnet: true,
2139
+ });
2140
+
2141
+ // src/config/chains/MatchTest.ts
2142
+ import { defineChain as defineChain2 } from "viem";
2143
+ var matchTest = /* @__PURE__ */ defineChain2({
2144
+ //定义matchTest链
2145
+ id: 699,
2146
+ name: "MatchTest",
2147
+ nativeCurrency: { name: "Match Coin", symbol: "BNB", decimals: 18 },
2148
+ rpcUrls: {
2149
+ default: {
2150
+ http: ["https://testnet-rpc.matchain.io"]
2151
+ }
2152
+ },
2153
+ blockExplorers: {
2154
+ default: {
2155
+ name: "Matchscan",
2156
+ url: "https://testnet.matchscan.io/",
2157
+ apiUrl: "https://testnet.matchscan.io/api"
2158
+ }
2159
+ },
2160
+ iconUrl: "https://testnet.matchscan.io/static/identicon_logos/blockies.png",
2161
+ contracts: {
2162
+ multicall3: {
2163
+ address: "0xca11bde05977b3631167028862be2a173976ca11",
2164
+ blockCreated: 751532
2165
+ },
2166
+ ensRegistry: { address: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e" },
2167
+ ensUniversalResolver: {
2168
+ address: "0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",
2169
+ blockCreated: 5317080
2170
+ }
2171
+ }
2172
+ // testnet: true,
2173
+ });
2104
2174
  export {
2105
2175
  api_exports as Api,
2176
+ chains_exports as Chains,
2106
2177
  components_exports as Components,
2107
2178
  hooks_exports as Hooks,
2108
2179
  MatchProvider,