@weblock-wallet/sdk 0.1.45 → 0.1.47

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.cjs CHANGED
@@ -105826,8 +105826,51 @@ var AssetService = class extends EventEmitter {
105826
105826
  this.networkService = networkService;
105827
105827
  this.userClient = userClient;
105828
105828
  this.orgHost = orgHost;
105829
+ this.chainIdCache = /* @__PURE__ */ new Map();
105829
105830
  this.erc20Interface = new import_ethers3.Interface(ERC20_ABI2);
105830
105831
  }
105832
+ /**
105833
+ * Resolve a user-facing networkId (blockchainId) into an EVM chainId for /v1/rpcs.
105834
+ *
105835
+ * Notes
105836
+ * - Many SDK APIs use `networkId` to mean the registered blockchain id (UUID).
105837
+ * - The wallet-rpc endpoint (/v1/rpcs) expects `chainId`.
105838
+ * - Some older call-sites may pass chainId as a string; we support both.
105839
+ */
105840
+ async resolveChainId(networkId) {
105841
+ const trimmed = (networkId ?? "").trim();
105842
+ const cached = this.chainIdCache.get(trimmed);
105843
+ if (cached) return cached;
105844
+ const numeric = Number(trimmed);
105845
+ if (!Number.isNaN(numeric) && Number.isFinite(numeric) && numeric > 0) {
105846
+ this.chainIdCache.set(trimmed, numeric);
105847
+ return numeric;
105848
+ }
105849
+ try {
105850
+ const current = await this.networkService.getCurrentNetwork();
105851
+ if (current && current.id === trimmed) {
105852
+ this.chainIdCache.set(trimmed, current.chainId);
105853
+ return current.chainId;
105854
+ }
105855
+ if (current && String(current.chainId) === trimmed) {
105856
+ this.chainIdCache.set(trimmed, current.chainId);
105857
+ return current.chainId;
105858
+ }
105859
+ } catch {
105860
+ }
105861
+ const networks = await this.networkService.getRegisteredNetworks();
105862
+ const found = networks.find((n5) => n5.id === trimmed);
105863
+ if (found) {
105864
+ this.chainIdCache.set(trimmed, found.chainId);
105865
+ return found.chainId;
105866
+ }
105867
+ const foundByChainId = networks.find((n5) => String(n5.chainId) === trimmed);
105868
+ if (foundByChainId) {
105869
+ this.chainIdCache.set(trimmed, foundByChainId.chainId);
105870
+ return foundByChainId.chainId;
105871
+ }
105872
+ throw new SDKError("Invalid network", "INVALID_NETWORK" /* INVALID_NETWORK */);
105873
+ }
105831
105874
  async getTokenInfo(params) {
105832
105875
  try {
105833
105876
  const [name2, symbol, decimals] = await Promise.all([
@@ -106023,11 +106066,12 @@ var AssetService = class extends EventEmitter {
106023
106066
  }
106024
106067
  async getTokenBalance(params) {
106025
106068
  try {
106069
+ const chainId = await this.resolveChainId(params.networkId);
106026
106070
  const data = this.erc20Interface.encodeFunctionData("balanceOf", [
106027
106071
  params.walletAddress
106028
106072
  ]);
106029
106073
  const response = await this.rpcClient.sendRpc({
106030
- chainId: Number(params.networkId),
106074
+ chainId,
106031
106075
  method: "eth_call" /* ETH_CALL */,
106032
106076
  params: [
106033
106077
  {
@@ -106048,12 +106092,13 @@ var AssetService = class extends EventEmitter {
106048
106092
  }
106049
106093
  async approveToken(params) {
106050
106094
  try {
106095
+ const chainId = await this.resolveChainId(params.networkId);
106051
106096
  const data = this.erc20Interface.encodeFunctionData("approve", [
106052
106097
  params.spender,
106053
106098
  params.amount
106054
106099
  ]);
106055
106100
  const response = await this.rpcClient.sendRpc({
106056
- chainId: Number(params.networkId),
106101
+ chainId,
106057
106102
  method: "eth_sendRawTransaction" /* ETH_SEND_RAW_TRANSACTION */,
106058
106103
  params: [
106059
106104
  {
@@ -106073,12 +106118,13 @@ var AssetService = class extends EventEmitter {
106073
106118
  }
106074
106119
  async getAllowance(params) {
106075
106120
  try {
106121
+ const chainId = await this.resolveChainId(params.networkId);
106076
106122
  const data = this.erc20Interface.encodeFunctionData("allowance", [
106077
106123
  params.owner,
106078
106124
  params.spender
106079
106125
  ]);
106080
106126
  const response = await this.rpcClient.sendRpc({
106081
- chainId: Number(params.networkId),
106127
+ chainId,
106082
106128
  method: "eth_call" /* ETH_CALL */,
106083
106129
  params: [
106084
106130
  {
@@ -106098,9 +106144,10 @@ var AssetService = class extends EventEmitter {
106098
106144
  }
106099
106145
  }
106100
106146
  async callTokenMethod(tokenAddress, networkId, method) {
106147
+ const chainId = await this.resolveChainId(networkId);
106101
106148
  const data = this.erc20Interface.encodeFunctionData(method, []);
106102
106149
  const response = await this.rpcClient.sendRpc({
106103
- chainId: Number(networkId),
106150
+ chainId,
106104
106151
  method: "eth_call" /* ETH_CALL */,
106105
106152
  params: [
106106
106153
  {
@@ -106128,19 +106175,6 @@ var AssetService = class extends EventEmitter {
106128
106175
  const key = `${this.orgHost}:nft:${params.networkId}:${params.address}`;
106129
106176
  await LocalForage.save(key, params);
106130
106177
  }
106131
- // async checkSecurityTokenCompliance(params: {
106132
- // networkId: string
106133
- // tokenAddress: string
106134
- // from: string
106135
- // to: string
106136
- // amount: string
106137
- // }): Promise<{
106138
- // canTransfer: boolean
106139
- // reasons?: string[]
106140
- // }> {
106141
- // // TODO: Implement security token compliance check
106142
- // return { canTransfer: true }
106143
- // }
106144
106178
  };
106145
106179
 
106146
106180
  // src/core/internal.ts
@@ -106580,6 +106614,12 @@ var WeBlockSDK = class {
106580
106614
  retrieveWallet: async (password) => {
106581
106615
  return this.userModule.retrieveWallet(password);
106582
106616
  },
106617
+ /**
106618
+ * ✅ 추가: PIN reset API 노출
106619
+ */
106620
+ resetPin: async (newPassword) => {
106621
+ return this.userModule.resetPin(newPassword);
106622
+ },
106583
106623
  signOut: async () => {
106584
106624
  return this.userModule.signOut();
106585
106625
  }
@@ -106638,37 +106678,6 @@ var WeBlockSDK = class {
106638
106678
  addNFTCollection: async (params) => {
106639
106679
  return this.assetModule.addNFTCollection(params);
106640
106680
  },
106641
- // checkSecurityTokenCompliance: async (params: {
106642
- // networkId: string
106643
- // tokenAddress: string
106644
- // from: string
106645
- // to: string
106646
- // amount: string
106647
- // }): Promise<{
106648
- // canTransfer: boolean
106649
- // reasons?: string[]
106650
- // }> => {
106651
- // return this.assetModule.checkSecurityTokenCompliance(params)
106652
- // },
106653
- getTokenBalance: async (params) => {
106654
- return this.assetModule.getTokenBalance(params);
106655
- },
106656
- approveToken: async (params) => {
106657
- return this.assetModule.approveToken(params);
106658
- },
106659
- getAllowance: async (params) => {
106660
- return this.assetModule.getAllowance(params);
106661
- },
106662
- // getTokenInfo: async (params: {
106663
- // networkId: string
106664
- // tokenAddress: string
106665
- // }): Promise<{
106666
- // name: string
106667
- // symbol: string
106668
- // decimals: number
106669
- // }> => {
106670
- // return this.assetModule.getTokenInfo(params)
106671
- // },
106672
106681
  on: (event, listener) => {
106673
106682
  this.assetModule.on(event, listener);
106674
106683
  },