@weblock-wallet/sdk 0.1.51 → 0.1.53

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
@@ -105012,21 +105012,19 @@ var UserClient = class {
105012
105012
  * - { coin: CoinResponse }
105013
105013
  * - { data: CoinResponse }
105014
105014
  */
105015
- // UserClient 클래스 내부의 registerToken()을 아래로 교체
105016
105015
  async registerToken(req) {
105017
- const blockchainId = req.blockchainId ?? req.networkId;
105018
- const contractAddress = String(
105019
- req.contractAddress ?? req.tokenAddress ?? req.address ?? ""
105020
- ).trim().toLowerCase();
105016
+ const blockchainId = req.blockchainId;
105017
+ const contractAddress = this.normalizeAddress(req.contractAddress);
105021
105018
  const name2 = req.name;
105022
105019
  const symbol = req.symbol;
105023
105020
  const decimals = req.decimals;
105024
105021
  const candidates = [
105025
- // 1) 주소만 받는 케이스
105022
+ // 1) 최신 스펙으로 바뀌며 "주소만" 받는 경우
105026
105023
  { blockchainId, contractAddress },
105024
+ // 2) 필드명이 tokenAddress / address로 바뀐 경우
105027
105025
  { blockchainId, tokenAddress: contractAddress },
105028
105026
  { blockchainId, address: contractAddress },
105029
- // 2) 메타까지 받는 케이스
105027
+ // 3) 스펙(메타 포함) 유지/필요한 경우
105030
105028
  ...name2 && symbol && typeof decimals === "number" ? [
105031
105029
  { blockchainId, contractAddress, name: name2, symbol, decimals },
105032
105030
  {
@@ -105038,32 +105036,45 @@ var UserClient = class {
105038
105036
  },
105039
105037
  { blockchainId, address: contractAddress, name: name2, symbol, decimals }
105040
105038
  ] : [],
105041
- // 3) 파라미터명이 networkId로 바뀐 케이스
105042
- { networkId: blockchainId, contractAddress },
105043
- ...name2 && symbol && typeof decimals === "number" ? [{ networkId: blockchainId, contractAddress, name: name2, symbol, decimals }] : []
105039
+ // 4) blockchainId가 networkId로 바뀐 경우
105040
+ ...name2 && symbol && typeof decimals === "number" ? [
105041
+ {
105042
+ networkId: blockchainId,
105043
+ contractAddress,
105044
+ name: name2,
105045
+ symbol,
105046
+ decimals
105047
+ },
105048
+ {
105049
+ networkId: blockchainId,
105050
+ tokenAddress: contractAddress,
105051
+ name: name2,
105052
+ symbol,
105053
+ decimals
105054
+ }
105055
+ ] : [{ networkId: blockchainId, contractAddress }]
105044
105056
  ];
105045
105057
  let lastError = null;
105046
105058
  for (const body of candidates) {
105047
105059
  try {
105048
105060
  const res = await this.client.post(
105049
- "/v1/users/register-token",
105050
- body,
105051
- {
105052
- needsAccessToken: true
105053
- }
105061
+ `${this.baseUrl}/register-token`,
105062
+ body
105054
105063
  );
105055
- const coin = res?.coin ?? res?.data ?? res;
105056
- if (coin?.contractAddress) {
105057
- return {
105058
- ...coin,
105059
- contractAddress: String(coin.contractAddress).trim().toLowerCase(),
105060
- decimals: typeof coin.decimals === "number" ? coin.decimals : Number(coin.decimals)
105061
- };
105064
+ const coin = this.unwrapCoin(res);
105065
+ if (!coin?.contractAddress) {
105066
+ continue;
105062
105067
  }
105068
+ return {
105069
+ ...coin,
105070
+ contractAddress: this.normalizeAddress(coin.contractAddress),
105071
+ decimals: Number(coin.decimals)
105072
+ };
105063
105073
  } catch (e7) {
105064
105074
  lastError = e7;
105065
- const status = e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
105066
- if (status === 400 || status === 409 || status === 422) continue;
105075
+ const status = this.extractStatus(e7);
105076
+ if (status === 400 || status === 422) continue;
105077
+ if (status === 409) continue;
105067
105078
  throw e7;
105068
105079
  }
105069
105080
  }
@@ -105087,32 +105098,6 @@ var UserClient = class {
105087
105098
  { needsAccessToken: true }
105088
105099
  );
105089
105100
  }
105090
- // UserClient 클래스 내부에 추가
105091
- async postAuthed(path, body) {
105092
- const httpAny = this.client;
105093
- const headers = (typeof httpAny.getAuthHeaders === "function" ? await httpAny.getAuthHeaders() : typeof httpAny.getHeaders === "function" ? await httpAny.getHeaders() : void 0) ?? void 0;
105094
- const attempts = [];
105095
- if (typeof httpAny.post === "function") {
105096
- attempts.push(() => httpAny.post(path, body, headers));
105097
- attempts.push(() => httpAny.post(path, body, { headers }));
105098
- attempts.push(() => httpAny.post(path, body));
105099
- }
105100
- if (typeof httpAny.request === "function") {
105101
- attempts.push(
105102
- () => httpAny.request({ method: "POST", path, body, headers })
105103
- );
105104
- attempts.push(() => httpAny.request("POST", path, body, headers));
105105
- }
105106
- let lastError = null;
105107
- for (const fn of attempts) {
105108
- try {
105109
- return await fn();
105110
- } catch (e7) {
105111
- lastError = e7;
105112
- }
105113
- }
105114
- throw lastError ?? new Error(`POST ${path} failed`);
105115
- }
105116
105101
  };
105117
105102
 
105118
105103
  // src/clients/api/wallets.ts
@@ -105251,6 +105236,44 @@ var ERC20_ABI2 = [
105251
105236
  type: "function"
105252
105237
  }
105253
105238
  ];
105239
+ var ERC1155_ABI = [
105240
+ {
105241
+ constant: true,
105242
+ inputs: [
105243
+ { name: "account", type: "address" },
105244
+ { name: "id", type: "uint256" }
105245
+ ],
105246
+ name: "balanceOf",
105247
+ outputs: [{ name: "", type: "uint256" }],
105248
+ payable: false,
105249
+ stateMutability: "view",
105250
+ type: "function"
105251
+ }
105252
+ ];
105253
+ var RBT_PROPERTY_TOKEN_ABI = [
105254
+ ...ERC1155_ABI,
105255
+ {
105256
+ constant: true,
105257
+ inputs: [
105258
+ { name: "tokenId", type: "uint256" },
105259
+ { name: "account", type: "address" }
105260
+ ],
105261
+ name: "claimable",
105262
+ outputs: [{ name: "", type: "uint256" }],
105263
+ payable: false,
105264
+ stateMutability: "view",
105265
+ type: "function"
105266
+ },
105267
+ {
105268
+ constant: false,
105269
+ inputs: [{ name: "tokenId", type: "uint256" }],
105270
+ name: "claim",
105271
+ outputs: [],
105272
+ payable: false,
105273
+ stateMutability: "nonpayable",
105274
+ type: "function"
105275
+ }
105276
+ ];
105254
105277
 
105255
105278
  // src/core/services/asset.ts
105256
105279
  var import_ethers3 = require("ethers");
@@ -105935,6 +105958,7 @@ var AssetService = class extends EventEmitter {
105935
105958
  this.orgHost = orgHost;
105936
105959
  this.chainIdCache = /* @__PURE__ */ new Map();
105937
105960
  this.erc20Interface = new import_ethers3.Interface(ERC20_ABI2);
105961
+ this.rbtInterface = new import_ethers3.Interface(RBT_PROPERTY_TOKEN_ABI);
105938
105962
  }
105939
105963
  /**
105940
105964
  * Resolve a user-facing networkId (blockchainId) into an EVM chainId for /v1/rpcs.
@@ -106232,6 +106256,98 @@ var AssetService = class extends EventEmitter {
106232
106256
  );
106233
106257
  }
106234
106258
  }
106259
+ /**
106260
+ * ERC-1155 balanceOf(account, tokenId)
106261
+ * - Returns raw hex string (0x...)
106262
+ */
106263
+ async getERC1155Balance(params) {
106264
+ try {
106265
+ const chainId = await this.resolveChainId(params.networkId);
106266
+ const data = this.rbtInterface.encodeFunctionData("balanceOf", [
106267
+ params.walletAddress,
106268
+ params.tokenId
106269
+ ]);
106270
+ const response = await this.rpcClient.sendRpc({
106271
+ chainId,
106272
+ method: "eth_call" /* ETH_CALL */,
106273
+ params: [
106274
+ {
106275
+ to: params.tokenAddress,
106276
+ data
106277
+ },
106278
+ "latest"
106279
+ ]
106280
+ });
106281
+ return response.result;
106282
+ } catch (error) {
106283
+ throw new SDKError(
106284
+ "Failed to get ERC1155 balance",
106285
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106286
+ error
106287
+ );
106288
+ }
106289
+ }
106290
+ /**
106291
+ * RBTPropertyToken claimable(tokenId, account)
106292
+ * - Returns raw hex string (0x...)
106293
+ */
106294
+ async getRbtClaimable(params) {
106295
+ try {
106296
+ const chainId = await this.resolveChainId(params.networkId);
106297
+ const data = this.rbtInterface.encodeFunctionData("claimable", [
106298
+ params.tokenId,
106299
+ params.walletAddress
106300
+ ]);
106301
+ const response = await this.rpcClient.sendRpc({
106302
+ chainId,
106303
+ method: "eth_call" /* ETH_CALL */,
106304
+ params: [
106305
+ {
106306
+ to: params.tokenAddress,
106307
+ data
106308
+ },
106309
+ "latest"
106310
+ ]
106311
+ });
106312
+ return response.result;
106313
+ } catch (error) {
106314
+ throw new SDKError(
106315
+ "Failed to get claimable amount",
106316
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106317
+ error
106318
+ );
106319
+ }
106320
+ }
106321
+ /**
106322
+ * RBTPropertyToken claim(tokenId)
106323
+ * - Sends a signed transaction via WalletService
106324
+ * - Returns txHash
106325
+ */
106326
+ async claimRbt(params) {
106327
+ try {
106328
+ const chainId = await this.resolveChainId(params.networkId);
106329
+ const data = this.rbtInterface.encodeFunctionData("claim", [
106330
+ params.tokenId
106331
+ ]);
106332
+ const txHash = await this.walletService.sendTransaction({
106333
+ to: params.tokenAddress,
106334
+ value: "0",
106335
+ data,
106336
+ chainId,
106337
+ gasLimit: params.gasLimit,
106338
+ gasPrice: params.gasPrice,
106339
+ nonce: params.nonce
106340
+ });
106341
+ this.trackTransaction(txHash, chainId);
106342
+ return txHash;
106343
+ } catch (error) {
106344
+ throw new SDKError(
106345
+ "Failed to claim RBT",
106346
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106347
+ error
106348
+ );
106349
+ }
106350
+ }
106235
106351
  async approveToken(params) {
106236
106352
  try {
106237
106353
  const chainId = await this.resolveChainId(params.networkId);
@@ -106371,6 +106487,10 @@ var InternalCoreImpl = class {
106371
106487
  addToken: (params) => this.assetService.addToken(params),
106372
106488
  // New ERC20 methods
106373
106489
  getTokenBalance: (params) => this.assetService.getTokenBalance(params),
106490
+ // ERC1155 / RBT helpers
106491
+ getERC1155Balance: (params) => this.assetService.getERC1155Balance(params),
106492
+ getRbtClaimable: (params) => this.assetService.getRbtClaimable(params),
106493
+ claimRbt: (params) => this.assetService.claimRbt(params),
106374
106494
  approveToken: (params) => this.assetService.approveToken(params),
106375
106495
  getAllowance: (params) => this.assetService.getAllowance(params),
106376
106496
  // getTokenInfo: (params: TokenInfoParams) =>
@@ -106667,6 +106787,15 @@ var AssetModule = class {
106667
106787
  async getTokenBalance(params) {
106668
106788
  return this.core.asset.getTokenBalance(params);
106669
106789
  }
106790
+ async getERC1155Balance(params) {
106791
+ return this.core.asset.getERC1155Balance(params);
106792
+ }
106793
+ async getRbtClaimable(params) {
106794
+ return this.core.asset.getRbtClaimable(params);
106795
+ }
106796
+ async claimRbt(params) {
106797
+ return this.core.asset.claimRbt(params);
106798
+ }
106670
106799
  async approveToken(params) {
106671
106800
  return this.core.asset.approveToken(params);
106672
106801
  }
@@ -106838,6 +106967,32 @@ var WeBlockSDK = class {
106838
106967
  getTokenInfo: async (params) => {
106839
106968
  return this.assetModule.getTokenInfo(params);
106840
106969
  },
106970
+ // ERC20 helpers
106971
+ getTokenBalance: async (params) => {
106972
+ this.ensureInitialized();
106973
+ return this.assetModule.getTokenBalance(params);
106974
+ },
106975
+ approveToken: async (params) => {
106976
+ this.ensureInitialized();
106977
+ return this.assetModule.approveToken(params);
106978
+ },
106979
+ getAllowance: async (params) => {
106980
+ this.ensureInitialized();
106981
+ return this.assetModule.getAllowance(params);
106982
+ },
106983
+ // ERC1155 / RBT helpers
106984
+ getERC1155Balance: async (params) => {
106985
+ this.ensureInitialized();
106986
+ return this.assetModule.getERC1155Balance(params);
106987
+ },
106988
+ getRbtClaimable: async (params) => {
106989
+ this.ensureInitialized();
106990
+ return this.assetModule.getRbtClaimable(params);
106991
+ },
106992
+ claimRbt: async (params) => {
106993
+ this.ensureInitialized();
106994
+ return this.assetModule.claimRbt(params);
106995
+ },
106841
106996
  registerToken: async (params) => {
106842
106997
  return this.assetModule.registerToken(params);
106843
106998
  },