@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.d.cts CHANGED
@@ -316,6 +316,35 @@ interface TokenInfoParams {
316
316
  networkId: string;
317
317
  tokenAddress: string;
318
318
  }
319
+ /**
320
+ * ERC-1155 balanceOf params
321
+ */
322
+ interface ERC1155BalanceParams {
323
+ networkId: string;
324
+ tokenAddress: string;
325
+ walletAddress: string;
326
+ tokenId: string | number;
327
+ }
328
+ /**
329
+ * RBTPropertyToken claimable() params
330
+ */
331
+ interface RbtClaimableParams {
332
+ networkId: string;
333
+ tokenAddress: string;
334
+ walletAddress: string;
335
+ tokenId: string | number;
336
+ }
337
+ /**
338
+ * RBTPropertyToken claim() params
339
+ */
340
+ interface RbtClaimParams {
341
+ networkId: string;
342
+ tokenAddress: string;
343
+ tokenId: string | number;
344
+ gasLimit?: string;
345
+ gasPrice?: string;
346
+ nonce?: number;
347
+ }
319
348
  interface SendTransactionParams {
320
349
  to: string;
321
350
  value: string;
@@ -465,6 +494,12 @@ declare class WeBlockSDK {
465
494
  on: (event: string, listener: (...args: any[]) => void) => void;
466
495
  off: (event: string, listener: (...args: any[]) => void) => void;
467
496
  getTokenInfo: (params: TokenInfoParams) => Promise<TokenMetadata>;
497
+ getTokenBalance: (params: TokenBalanceParams) => Promise<string>;
498
+ approveToken: (params: TokenApprovalParams) => Promise<string>;
499
+ getAllowance: (params: TokenAllowanceParams) => Promise<string>;
500
+ getERC1155Balance: (params: ERC1155BalanceParams) => Promise<string>;
501
+ getRbtClaimable: (params: RbtClaimableParams) => Promise<string>;
502
+ claimRbt: (params: RbtClaimParams) => Promise<string>;
468
503
  registerToken: (params: {
469
504
  networkId: string;
470
505
  tokenAddress: string;
@@ -477,4 +512,4 @@ declare class WeBlockSDK {
477
512
  };
478
513
  }
479
514
 
480
- export { type AddNetworkRequest, DECIMALS, type NFTCollection, type NetworkInfo, SDKError, SDKErrorCode, type SDKOptions, type SecurityTokenInfo, type SendTransactionParams, type SignInResponse, SignInStatus, type SwitchNetworkResponse, type TokenAllowanceParams, TokenAmount, type TokenApprovalParams, type TokenBalance, type TokenBalanceParams, type TokenInfo, type TokenInfoParams, type TokenMetadata, TokenType, type Transaction, type TransactionReceipt, TransactionStatus, type TransactionStatusEvent, TransactionType, type TransferRequest, type TransferResponse, type WalletInfo, type WalletResponse, WeBlockSDK, WeBlockSDK as default };
515
+ export { type AddNetworkRequest, DECIMALS, type ERC1155BalanceParams, type NFTCollection, type NetworkInfo, type RbtClaimParams, type RbtClaimableParams, SDKError, SDKErrorCode, type SDKOptions, type SecurityTokenInfo, type SendTransactionParams, type SignInResponse, SignInStatus, type SwitchNetworkResponse, type TokenAllowanceParams, TokenAmount, type TokenApprovalParams, type TokenBalance, type TokenBalanceParams, type TokenInfo, type TokenInfoParams, type TokenMetadata, TokenType, type Transaction, type TransactionReceipt, TransactionStatus, type TransactionStatusEvent, TransactionType, type TransferRequest, type TransferResponse, type WalletInfo, type WalletResponse, WeBlockSDK, WeBlockSDK as default };
package/dist/index.d.ts CHANGED
@@ -316,6 +316,35 @@ interface TokenInfoParams {
316
316
  networkId: string;
317
317
  tokenAddress: string;
318
318
  }
319
+ /**
320
+ * ERC-1155 balanceOf params
321
+ */
322
+ interface ERC1155BalanceParams {
323
+ networkId: string;
324
+ tokenAddress: string;
325
+ walletAddress: string;
326
+ tokenId: string | number;
327
+ }
328
+ /**
329
+ * RBTPropertyToken claimable() params
330
+ */
331
+ interface RbtClaimableParams {
332
+ networkId: string;
333
+ tokenAddress: string;
334
+ walletAddress: string;
335
+ tokenId: string | number;
336
+ }
337
+ /**
338
+ * RBTPropertyToken claim() params
339
+ */
340
+ interface RbtClaimParams {
341
+ networkId: string;
342
+ tokenAddress: string;
343
+ tokenId: string | number;
344
+ gasLimit?: string;
345
+ gasPrice?: string;
346
+ nonce?: number;
347
+ }
319
348
  interface SendTransactionParams {
320
349
  to: string;
321
350
  value: string;
@@ -465,6 +494,12 @@ declare class WeBlockSDK {
465
494
  on: (event: string, listener: (...args: any[]) => void) => void;
466
495
  off: (event: string, listener: (...args: any[]) => void) => void;
467
496
  getTokenInfo: (params: TokenInfoParams) => Promise<TokenMetadata>;
497
+ getTokenBalance: (params: TokenBalanceParams) => Promise<string>;
498
+ approveToken: (params: TokenApprovalParams) => Promise<string>;
499
+ getAllowance: (params: TokenAllowanceParams) => Promise<string>;
500
+ getERC1155Balance: (params: ERC1155BalanceParams) => Promise<string>;
501
+ getRbtClaimable: (params: RbtClaimableParams) => Promise<string>;
502
+ claimRbt: (params: RbtClaimParams) => Promise<string>;
468
503
  registerToken: (params: {
469
504
  networkId: string;
470
505
  tokenAddress: string;
@@ -477,4 +512,4 @@ declare class WeBlockSDK {
477
512
  };
478
513
  }
479
514
 
480
- export { type AddNetworkRequest, DECIMALS, type NFTCollection, type NetworkInfo, SDKError, SDKErrorCode, type SDKOptions, type SecurityTokenInfo, type SendTransactionParams, type SignInResponse, SignInStatus, type SwitchNetworkResponse, type TokenAllowanceParams, TokenAmount, type TokenApprovalParams, type TokenBalance, type TokenBalanceParams, type TokenInfo, type TokenInfoParams, type TokenMetadata, TokenType, type Transaction, type TransactionReceipt, TransactionStatus, type TransactionStatusEvent, TransactionType, type TransferRequest, type TransferResponse, type WalletInfo, type WalletResponse, WeBlockSDK, WeBlockSDK as default };
515
+ export { type AddNetworkRequest, DECIMALS, type ERC1155BalanceParams, type NFTCollection, type NetworkInfo, type RbtClaimParams, type RbtClaimableParams, SDKError, SDKErrorCode, type SDKOptions, type SecurityTokenInfo, type SendTransactionParams, type SignInResponse, SignInStatus, type SwitchNetworkResponse, type TokenAllowanceParams, TokenAmount, type TokenApprovalParams, type TokenBalance, type TokenBalanceParams, type TokenInfo, type TokenInfoParams, type TokenMetadata, TokenType, type Transaction, type TransactionReceipt, TransactionStatus, type TransactionStatusEvent, TransactionType, type TransferRequest, type TransferResponse, type WalletInfo, type WalletResponse, WeBlockSDK, WeBlockSDK as default };
package/dist/index.js CHANGED
@@ -104971,21 +104971,19 @@ var UserClient = class {
104971
104971
  * - { coin: CoinResponse }
104972
104972
  * - { data: CoinResponse }
104973
104973
  */
104974
- // UserClient 클래스 내부의 registerToken()을 아래로 교체
104975
104974
  async registerToken(req) {
104976
- const blockchainId = req.blockchainId ?? req.networkId;
104977
- const contractAddress = String(
104978
- req.contractAddress ?? req.tokenAddress ?? req.address ?? ""
104979
- ).trim().toLowerCase();
104975
+ const blockchainId = req.blockchainId;
104976
+ const contractAddress = this.normalizeAddress(req.contractAddress);
104980
104977
  const name2 = req.name;
104981
104978
  const symbol = req.symbol;
104982
104979
  const decimals = req.decimals;
104983
104980
  const candidates = [
104984
- // 1) 주소만 받는 케이스
104981
+ // 1) 최신 스펙으로 바뀌며 "주소만" 받는 경우
104985
104982
  { blockchainId, contractAddress },
104983
+ // 2) 필드명이 tokenAddress / address로 바뀐 경우
104986
104984
  { blockchainId, tokenAddress: contractAddress },
104987
104985
  { blockchainId, address: contractAddress },
104988
- // 2) 메타까지 받는 케이스
104986
+ // 3) 스펙(메타 포함) 유지/필요한 경우
104989
104987
  ...name2 && symbol && typeof decimals === "number" ? [
104990
104988
  { blockchainId, contractAddress, name: name2, symbol, decimals },
104991
104989
  {
@@ -104997,32 +104995,45 @@ var UserClient = class {
104997
104995
  },
104998
104996
  { blockchainId, address: contractAddress, name: name2, symbol, decimals }
104999
104997
  ] : [],
105000
- // 3) 파라미터명이 networkId로 바뀐 케이스
105001
- { networkId: blockchainId, contractAddress },
105002
- ...name2 && symbol && typeof decimals === "number" ? [{ networkId: blockchainId, contractAddress, name: name2, symbol, decimals }] : []
104998
+ // 4) blockchainId가 networkId로 바뀐 경우
104999
+ ...name2 && symbol && typeof decimals === "number" ? [
105000
+ {
105001
+ networkId: blockchainId,
105002
+ contractAddress,
105003
+ name: name2,
105004
+ symbol,
105005
+ decimals
105006
+ },
105007
+ {
105008
+ networkId: blockchainId,
105009
+ tokenAddress: contractAddress,
105010
+ name: name2,
105011
+ symbol,
105012
+ decimals
105013
+ }
105014
+ ] : [{ networkId: blockchainId, contractAddress }]
105003
105015
  ];
105004
105016
  let lastError = null;
105005
105017
  for (const body of candidates) {
105006
105018
  try {
105007
105019
  const res = await this.client.post(
105008
- "/v1/users/register-token",
105009
- body,
105010
- {
105011
- needsAccessToken: true
105012
- }
105020
+ `${this.baseUrl}/register-token`,
105021
+ body
105013
105022
  );
105014
- const coin = res?.coin ?? res?.data ?? res;
105015
- if (coin?.contractAddress) {
105016
- return {
105017
- ...coin,
105018
- contractAddress: String(coin.contractAddress).trim().toLowerCase(),
105019
- decimals: typeof coin.decimals === "number" ? coin.decimals : Number(coin.decimals)
105020
- };
105023
+ const coin = this.unwrapCoin(res);
105024
+ if (!coin?.contractAddress) {
105025
+ continue;
105021
105026
  }
105027
+ return {
105028
+ ...coin,
105029
+ contractAddress: this.normalizeAddress(coin.contractAddress),
105030
+ decimals: Number(coin.decimals)
105031
+ };
105022
105032
  } catch (e7) {
105023
105033
  lastError = e7;
105024
- const status = e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
105025
- if (status === 400 || status === 409 || status === 422) continue;
105034
+ const status = this.extractStatus(e7);
105035
+ if (status === 400 || status === 422) continue;
105036
+ if (status === 409) continue;
105026
105037
  throw e7;
105027
105038
  }
105028
105039
  }
@@ -105046,32 +105057,6 @@ var UserClient = class {
105046
105057
  { needsAccessToken: true }
105047
105058
  );
105048
105059
  }
105049
- // UserClient 클래스 내부에 추가
105050
- async postAuthed(path, body) {
105051
- const httpAny = this.client;
105052
- const headers = (typeof httpAny.getAuthHeaders === "function" ? await httpAny.getAuthHeaders() : typeof httpAny.getHeaders === "function" ? await httpAny.getHeaders() : void 0) ?? void 0;
105053
- const attempts = [];
105054
- if (typeof httpAny.post === "function") {
105055
- attempts.push(() => httpAny.post(path, body, headers));
105056
- attempts.push(() => httpAny.post(path, body, { headers }));
105057
- attempts.push(() => httpAny.post(path, body));
105058
- }
105059
- if (typeof httpAny.request === "function") {
105060
- attempts.push(
105061
- () => httpAny.request({ method: "POST", path, body, headers })
105062
- );
105063
- attempts.push(() => httpAny.request("POST", path, body, headers));
105064
- }
105065
- let lastError = null;
105066
- for (const fn of attempts) {
105067
- try {
105068
- return await fn();
105069
- } catch (e7) {
105070
- lastError = e7;
105071
- }
105072
- }
105073
- throw lastError ?? new Error(`POST ${path} failed`);
105074
- }
105075
105060
  };
105076
105061
 
105077
105062
  // src/clients/api/wallets.ts
@@ -105210,6 +105195,44 @@ var ERC20_ABI2 = [
105210
105195
  type: "function"
105211
105196
  }
105212
105197
  ];
105198
+ var ERC1155_ABI = [
105199
+ {
105200
+ constant: true,
105201
+ inputs: [
105202
+ { name: "account", type: "address" },
105203
+ { name: "id", type: "uint256" }
105204
+ ],
105205
+ name: "balanceOf",
105206
+ outputs: [{ name: "", type: "uint256" }],
105207
+ payable: false,
105208
+ stateMutability: "view",
105209
+ type: "function"
105210
+ }
105211
+ ];
105212
+ var RBT_PROPERTY_TOKEN_ABI = [
105213
+ ...ERC1155_ABI,
105214
+ {
105215
+ constant: true,
105216
+ inputs: [
105217
+ { name: "tokenId", type: "uint256" },
105218
+ { name: "account", type: "address" }
105219
+ ],
105220
+ name: "claimable",
105221
+ outputs: [{ name: "", type: "uint256" }],
105222
+ payable: false,
105223
+ stateMutability: "view",
105224
+ type: "function"
105225
+ },
105226
+ {
105227
+ constant: false,
105228
+ inputs: [{ name: "tokenId", type: "uint256" }],
105229
+ name: "claim",
105230
+ outputs: [],
105231
+ payable: false,
105232
+ stateMutability: "nonpayable",
105233
+ type: "function"
105234
+ }
105235
+ ];
105213
105236
 
105214
105237
  // src/core/services/asset.ts
105215
105238
  import { Interface as Interface2 } from "ethers";
@@ -105894,6 +105917,7 @@ var AssetService = class extends EventEmitter {
105894
105917
  this.orgHost = orgHost;
105895
105918
  this.chainIdCache = /* @__PURE__ */ new Map();
105896
105919
  this.erc20Interface = new Interface2(ERC20_ABI2);
105920
+ this.rbtInterface = new Interface2(RBT_PROPERTY_TOKEN_ABI);
105897
105921
  }
105898
105922
  /**
105899
105923
  * Resolve a user-facing networkId (blockchainId) into an EVM chainId for /v1/rpcs.
@@ -106191,6 +106215,98 @@ var AssetService = class extends EventEmitter {
106191
106215
  );
106192
106216
  }
106193
106217
  }
106218
+ /**
106219
+ * ERC-1155 balanceOf(account, tokenId)
106220
+ * - Returns raw hex string (0x...)
106221
+ */
106222
+ async getERC1155Balance(params) {
106223
+ try {
106224
+ const chainId = await this.resolveChainId(params.networkId);
106225
+ const data = this.rbtInterface.encodeFunctionData("balanceOf", [
106226
+ params.walletAddress,
106227
+ params.tokenId
106228
+ ]);
106229
+ const response = await this.rpcClient.sendRpc({
106230
+ chainId,
106231
+ method: "eth_call" /* ETH_CALL */,
106232
+ params: [
106233
+ {
106234
+ to: params.tokenAddress,
106235
+ data
106236
+ },
106237
+ "latest"
106238
+ ]
106239
+ });
106240
+ return response.result;
106241
+ } catch (error) {
106242
+ throw new SDKError(
106243
+ "Failed to get ERC1155 balance",
106244
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106245
+ error
106246
+ );
106247
+ }
106248
+ }
106249
+ /**
106250
+ * RBTPropertyToken claimable(tokenId, account)
106251
+ * - Returns raw hex string (0x...)
106252
+ */
106253
+ async getRbtClaimable(params) {
106254
+ try {
106255
+ const chainId = await this.resolveChainId(params.networkId);
106256
+ const data = this.rbtInterface.encodeFunctionData("claimable", [
106257
+ params.tokenId,
106258
+ params.walletAddress
106259
+ ]);
106260
+ const response = await this.rpcClient.sendRpc({
106261
+ chainId,
106262
+ method: "eth_call" /* ETH_CALL */,
106263
+ params: [
106264
+ {
106265
+ to: params.tokenAddress,
106266
+ data
106267
+ },
106268
+ "latest"
106269
+ ]
106270
+ });
106271
+ return response.result;
106272
+ } catch (error) {
106273
+ throw new SDKError(
106274
+ "Failed to get claimable amount",
106275
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106276
+ error
106277
+ );
106278
+ }
106279
+ }
106280
+ /**
106281
+ * RBTPropertyToken claim(tokenId)
106282
+ * - Sends a signed transaction via WalletService
106283
+ * - Returns txHash
106284
+ */
106285
+ async claimRbt(params) {
106286
+ try {
106287
+ const chainId = await this.resolveChainId(params.networkId);
106288
+ const data = this.rbtInterface.encodeFunctionData("claim", [
106289
+ params.tokenId
106290
+ ]);
106291
+ const txHash = await this.walletService.sendTransaction({
106292
+ to: params.tokenAddress,
106293
+ value: "0",
106294
+ data,
106295
+ chainId,
106296
+ gasLimit: params.gasLimit,
106297
+ gasPrice: params.gasPrice,
106298
+ nonce: params.nonce
106299
+ });
106300
+ this.trackTransaction(txHash, chainId);
106301
+ return txHash;
106302
+ } catch (error) {
106303
+ throw new SDKError(
106304
+ "Failed to claim RBT",
106305
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106306
+ error
106307
+ );
106308
+ }
106309
+ }
106194
106310
  async approveToken(params) {
106195
106311
  try {
106196
106312
  const chainId = await this.resolveChainId(params.networkId);
@@ -106330,6 +106446,10 @@ var InternalCoreImpl = class {
106330
106446
  addToken: (params) => this.assetService.addToken(params),
106331
106447
  // New ERC20 methods
106332
106448
  getTokenBalance: (params) => this.assetService.getTokenBalance(params),
106449
+ // ERC1155 / RBT helpers
106450
+ getERC1155Balance: (params) => this.assetService.getERC1155Balance(params),
106451
+ getRbtClaimable: (params) => this.assetService.getRbtClaimable(params),
106452
+ claimRbt: (params) => this.assetService.claimRbt(params),
106333
106453
  approveToken: (params) => this.assetService.approveToken(params),
106334
106454
  getAllowance: (params) => this.assetService.getAllowance(params),
106335
106455
  // getTokenInfo: (params: TokenInfoParams) =>
@@ -106626,6 +106746,15 @@ var AssetModule = class {
106626
106746
  async getTokenBalance(params) {
106627
106747
  return this.core.asset.getTokenBalance(params);
106628
106748
  }
106749
+ async getERC1155Balance(params) {
106750
+ return this.core.asset.getERC1155Balance(params);
106751
+ }
106752
+ async getRbtClaimable(params) {
106753
+ return this.core.asset.getRbtClaimable(params);
106754
+ }
106755
+ async claimRbt(params) {
106756
+ return this.core.asset.claimRbt(params);
106757
+ }
106629
106758
  async approveToken(params) {
106630
106759
  return this.core.asset.approveToken(params);
106631
106760
  }
@@ -106797,6 +106926,32 @@ var WeBlockSDK = class {
106797
106926
  getTokenInfo: async (params) => {
106798
106927
  return this.assetModule.getTokenInfo(params);
106799
106928
  },
106929
+ // ERC20 helpers
106930
+ getTokenBalance: async (params) => {
106931
+ this.ensureInitialized();
106932
+ return this.assetModule.getTokenBalance(params);
106933
+ },
106934
+ approveToken: async (params) => {
106935
+ this.ensureInitialized();
106936
+ return this.assetModule.approveToken(params);
106937
+ },
106938
+ getAllowance: async (params) => {
106939
+ this.ensureInitialized();
106940
+ return this.assetModule.getAllowance(params);
106941
+ },
106942
+ // ERC1155 / RBT helpers
106943
+ getERC1155Balance: async (params) => {
106944
+ this.ensureInitialized();
106945
+ return this.assetModule.getERC1155Balance(params);
106946
+ },
106947
+ getRbtClaimable: async (params) => {
106948
+ this.ensureInitialized();
106949
+ return this.assetModule.getRbtClaimable(params);
106950
+ },
106951
+ claimRbt: async (params) => {
106952
+ this.ensureInitialized();
106953
+ return this.assetModule.claimRbt(params);
106954
+ },
106800
106955
  registerToken: async (params) => {
106801
106956
  return this.assetModule.registerToken(params);
106802
106957
  },