@weblock-wallet/sdk 0.1.46 → 0.1.48
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 +128 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +128 -50
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -105785,8 +105785,51 @@ var AssetService = class extends EventEmitter {
|
|
|
105785
105785
|
this.networkService = networkService;
|
|
105786
105786
|
this.userClient = userClient;
|
|
105787
105787
|
this.orgHost = orgHost;
|
|
105788
|
+
this.chainIdCache = /* @__PURE__ */ new Map();
|
|
105788
105789
|
this.erc20Interface = new Interface2(ERC20_ABI2);
|
|
105789
105790
|
}
|
|
105791
|
+
/**
|
|
105792
|
+
* Resolve a user-facing networkId (blockchainId) into an EVM chainId for /v1/rpcs.
|
|
105793
|
+
*
|
|
105794
|
+
* Notes
|
|
105795
|
+
* - Many SDK APIs use `networkId` to mean the registered blockchain id (UUID).
|
|
105796
|
+
* - The wallet-rpc endpoint (/v1/rpcs) expects `chainId`.
|
|
105797
|
+
* - Some older call-sites may pass chainId as a string; we support both.
|
|
105798
|
+
*/
|
|
105799
|
+
async resolveChainId(networkId) {
|
|
105800
|
+
const trimmed = (networkId ?? "").trim();
|
|
105801
|
+
const cached = this.chainIdCache.get(trimmed);
|
|
105802
|
+
if (cached) return cached;
|
|
105803
|
+
const numeric = Number(trimmed);
|
|
105804
|
+
if (!Number.isNaN(numeric) && Number.isFinite(numeric) && numeric > 0) {
|
|
105805
|
+
this.chainIdCache.set(trimmed, numeric);
|
|
105806
|
+
return numeric;
|
|
105807
|
+
}
|
|
105808
|
+
try {
|
|
105809
|
+
const current = await this.networkService.getCurrentNetwork();
|
|
105810
|
+
if (current && current.id === trimmed) {
|
|
105811
|
+
this.chainIdCache.set(trimmed, current.chainId);
|
|
105812
|
+
return current.chainId;
|
|
105813
|
+
}
|
|
105814
|
+
if (current && String(current.chainId) === trimmed) {
|
|
105815
|
+
this.chainIdCache.set(trimmed, current.chainId);
|
|
105816
|
+
return current.chainId;
|
|
105817
|
+
}
|
|
105818
|
+
} catch {
|
|
105819
|
+
}
|
|
105820
|
+
const networks = await this.networkService.getRegisteredNetworks();
|
|
105821
|
+
const found = networks.find((n5) => n5.id === trimmed);
|
|
105822
|
+
if (found) {
|
|
105823
|
+
this.chainIdCache.set(trimmed, found.chainId);
|
|
105824
|
+
return found.chainId;
|
|
105825
|
+
}
|
|
105826
|
+
const foundByChainId = networks.find((n5) => String(n5.chainId) === trimmed);
|
|
105827
|
+
if (foundByChainId) {
|
|
105828
|
+
this.chainIdCache.set(trimmed, foundByChainId.chainId);
|
|
105829
|
+
return foundByChainId.chainId;
|
|
105830
|
+
}
|
|
105831
|
+
throw new SDKError("Invalid network", "INVALID_NETWORK" /* INVALID_NETWORK */);
|
|
105832
|
+
}
|
|
105790
105833
|
async getTokenInfo(params) {
|
|
105791
105834
|
try {
|
|
105792
105835
|
const [name2, symbol, decimals] = await Promise.all([
|
|
@@ -105977,16 +106020,52 @@ var AssetService = class extends EventEmitter {
|
|
|
105977
106020
|
checkStatus();
|
|
105978
106021
|
}
|
|
105979
106022
|
async addToken(params) {
|
|
106023
|
+
const hasMeta = !!params.name && !!params.symbol && typeof params.decimals === "number";
|
|
106024
|
+
const meta = hasMeta ? {
|
|
106025
|
+
name: params.name,
|
|
106026
|
+
symbol: params.symbol,
|
|
106027
|
+
decimals: params.decimals
|
|
106028
|
+
} : await this.getTokenInfo({
|
|
106029
|
+
networkId: params.networkId,
|
|
106030
|
+
tokenAddress: params.address
|
|
106031
|
+
});
|
|
106032
|
+
try {
|
|
106033
|
+
await this.userClient.registerToken({
|
|
106034
|
+
blockchainId: params.networkId,
|
|
106035
|
+
contractAddress: params.address,
|
|
106036
|
+
name: meta.name,
|
|
106037
|
+
symbol: meta.symbol,
|
|
106038
|
+
decimals: meta.decimals
|
|
106039
|
+
});
|
|
106040
|
+
} catch (error) {
|
|
106041
|
+
throw new SDKError(
|
|
106042
|
+
"Failed to register token",
|
|
106043
|
+
"REQUEST_FAILED" /* REQUEST_FAILED */,
|
|
106044
|
+
error
|
|
106045
|
+
);
|
|
106046
|
+
}
|
|
105980
106047
|
const key = `${this.orgHost}:token:${params.networkId}:${params.address}`;
|
|
105981
106048
|
await LocalForage.save(key, params);
|
|
105982
106049
|
}
|
|
106050
|
+
async getRegisteredCoins(networkId) {
|
|
106051
|
+
try {
|
|
106052
|
+
return await this.userClient.getRegisteredCoins(networkId);
|
|
106053
|
+
} catch (error) {
|
|
106054
|
+
throw new SDKError(
|
|
106055
|
+
"Failed to get registered tokens",
|
|
106056
|
+
"REQUEST_FAILED" /* REQUEST_FAILED */,
|
|
106057
|
+
error
|
|
106058
|
+
);
|
|
106059
|
+
}
|
|
106060
|
+
}
|
|
105983
106061
|
async getTokenBalance(params) {
|
|
105984
106062
|
try {
|
|
106063
|
+
const chainId = await this.resolveChainId(params.networkId);
|
|
105985
106064
|
const data = this.erc20Interface.encodeFunctionData("balanceOf", [
|
|
105986
106065
|
params.walletAddress
|
|
105987
106066
|
]);
|
|
105988
106067
|
const response = await this.rpcClient.sendRpc({
|
|
105989
|
-
chainId
|
|
106068
|
+
chainId,
|
|
105990
106069
|
method: "eth_call" /* ETH_CALL */,
|
|
105991
106070
|
params: [
|
|
105992
106071
|
{
|
|
@@ -106007,12 +106086,13 @@ var AssetService = class extends EventEmitter {
|
|
|
106007
106086
|
}
|
|
106008
106087
|
async approveToken(params) {
|
|
106009
106088
|
try {
|
|
106089
|
+
const chainId = await this.resolveChainId(params.networkId);
|
|
106010
106090
|
const data = this.erc20Interface.encodeFunctionData("approve", [
|
|
106011
106091
|
params.spender,
|
|
106012
106092
|
params.amount
|
|
106013
106093
|
]);
|
|
106014
106094
|
const response = await this.rpcClient.sendRpc({
|
|
106015
|
-
chainId
|
|
106095
|
+
chainId,
|
|
106016
106096
|
method: "eth_sendRawTransaction" /* ETH_SEND_RAW_TRANSACTION */,
|
|
106017
106097
|
params: [
|
|
106018
106098
|
{
|
|
@@ -106032,12 +106112,13 @@ var AssetService = class extends EventEmitter {
|
|
|
106032
106112
|
}
|
|
106033
106113
|
async getAllowance(params) {
|
|
106034
106114
|
try {
|
|
106115
|
+
const chainId = await this.resolveChainId(params.networkId);
|
|
106035
106116
|
const data = this.erc20Interface.encodeFunctionData("allowance", [
|
|
106036
106117
|
params.owner,
|
|
106037
106118
|
params.spender
|
|
106038
106119
|
]);
|
|
106039
106120
|
const response = await this.rpcClient.sendRpc({
|
|
106040
|
-
chainId
|
|
106121
|
+
chainId,
|
|
106041
106122
|
method: "eth_call" /* ETH_CALL */,
|
|
106042
106123
|
params: [
|
|
106043
106124
|
{
|
|
@@ -106057,9 +106138,10 @@ var AssetService = class extends EventEmitter {
|
|
|
106057
106138
|
}
|
|
106058
106139
|
}
|
|
106059
106140
|
async callTokenMethod(tokenAddress, networkId, method) {
|
|
106141
|
+
const chainId = await this.resolveChainId(networkId);
|
|
106060
106142
|
const data = this.erc20Interface.encodeFunctionData(method, []);
|
|
106061
106143
|
const response = await this.rpcClient.sendRpc({
|
|
106062
|
-
chainId
|
|
106144
|
+
chainId,
|
|
106063
106145
|
method: "eth_call" /* ETH_CALL */,
|
|
106064
106146
|
params: [
|
|
106065
106147
|
{
|
|
@@ -106117,7 +106199,6 @@ var InternalCoreImpl = class {
|
|
|
106117
106199
|
getAddress: () => this.walletService.getAddress(),
|
|
106118
106200
|
create: (password) => this.walletService.create(password),
|
|
106119
106201
|
retrieveWallet: (password) => this.walletService.retrieveWallet(password),
|
|
106120
|
-
resetPin: (newPassword) => this.walletService.resetPin(newPassword),
|
|
106121
106202
|
getBalance: (address, chainId) => this.walletService.getBalance(address, chainId),
|
|
106122
106203
|
getTokenBalance: (tokenAddress, walletAddress, chainId) => this.walletService.getTokenBalance(tokenAddress, walletAddress, chainId),
|
|
106123
106204
|
sendTransaction: (params) => this.walletService.sendTransaction(params),
|
|
@@ -106139,25 +106220,27 @@ var InternalCoreImpl = class {
|
|
|
106139
106220
|
};
|
|
106140
106221
|
this.asset = {
|
|
106141
106222
|
transfer: (params) => this.assetService.transfer(params),
|
|
106142
|
-
|
|
106143
|
-
|
|
106144
|
-
* - InternalCore는 decimals?: number
|
|
106145
|
-
* - 기존 AssetService 내부 구현이 decimals를 string으로 받는 경우가 있어,
|
|
106146
|
-
* 여기서 안전하게 string으로 변환해서 전달합니다.
|
|
106147
|
-
*/
|
|
106148
|
-
addToken: (params) => this.assetService.addToken({
|
|
106149
|
-
...params,
|
|
106150
|
-
decimals: typeof params.decimals === "number" ? String(params.decimals) : void 0
|
|
106151
|
-
}),
|
|
106223
|
+
addToken: (params) => this.assetService.addToken(params),
|
|
106224
|
+
// New ERC20 methods
|
|
106152
106225
|
getTokenBalance: (params) => this.assetService.getTokenBalance(params),
|
|
106153
106226
|
approveToken: (params) => this.assetService.approveToken(params),
|
|
106154
106227
|
getAllowance: (params) => this.assetService.getAllowance(params),
|
|
106228
|
+
// getTokenInfo: (params: TokenInfoParams) =>
|
|
106229
|
+
// this.assetService.getTokenInfo(params),
|
|
106155
106230
|
addNFTCollection: (params) => this.assetService.addNFTCollection(params),
|
|
106231
|
+
// checkSecurityTokenCompliance: (params: {
|
|
106232
|
+
// networkId: string
|
|
106233
|
+
// tokenAddress: string
|
|
106234
|
+
// from: string
|
|
106235
|
+
// to: string
|
|
106236
|
+
// amount: string
|
|
106237
|
+
// }) => this.assetService.checkSecurityTokenCompliance(params),
|
|
106156
106238
|
on: (event, listener) => this.assetService.on(event, listener),
|
|
106157
106239
|
off: (event, listener) => this.assetService.off(event, listener),
|
|
106158
106240
|
getTokenInfo: (params) => this.assetService.getTokenInfo(params),
|
|
106159
106241
|
registerToken: (params) => this.assetService.registerToken(params),
|
|
106160
|
-
getTokenFullInfo: (params) => this.assetService.getTokenFullInfo(params)
|
|
106242
|
+
getTokenFullInfo: (params) => this.assetService.getTokenFullInfo(params),
|
|
106243
|
+
getRegisteredCoins: (networkId) => this.assetService.getRegisteredCoins(networkId)
|
|
106161
106244
|
};
|
|
106162
106245
|
const httpClient = new HttpClient(options);
|
|
106163
106246
|
const firebase = new FirebaseAuth(options);
|
|
@@ -106312,6 +106395,34 @@ var WalletModule = class {
|
|
|
106312
106395
|
network.chainId
|
|
106313
106396
|
);
|
|
106314
106397
|
console.log("\uCD5C\uADFC \uD2B8\uB79C\uC7AD\uC158:", latestTransaction);
|
|
106398
|
+
let tokens = [];
|
|
106399
|
+
try {
|
|
106400
|
+
const registered = await this.core.asset.getRegisteredCoins(network.id);
|
|
106401
|
+
if (registered?.length) {
|
|
106402
|
+
const unique = new Map(
|
|
106403
|
+
registered.map((c5) => [c5.contractAddress.toLowerCase(), c5])
|
|
106404
|
+
);
|
|
106405
|
+
tokens = await Promise.all(
|
|
106406
|
+
Array.from(unique.values()).map(async (coin) => {
|
|
106407
|
+
const full = await this.core.asset.getTokenFullInfo({
|
|
106408
|
+
networkId: network.id,
|
|
106409
|
+
tokenAddress: coin.contractAddress,
|
|
106410
|
+
walletAddress: address
|
|
106411
|
+
});
|
|
106412
|
+
return {
|
|
106413
|
+
...full,
|
|
106414
|
+
address: coin.contractAddress,
|
|
106415
|
+
name: coin.name ?? full.name,
|
|
106416
|
+
symbol: coin.symbol ?? full.symbol,
|
|
106417
|
+
decimals: typeof coin.decimals === "number" ? coin.decimals : full.decimals
|
|
106418
|
+
};
|
|
106419
|
+
})
|
|
106420
|
+
);
|
|
106421
|
+
}
|
|
106422
|
+
} catch (e7) {
|
|
106423
|
+
console.warn("Registered token load failed:", e7);
|
|
106424
|
+
tokens = [];
|
|
106425
|
+
}
|
|
106315
106426
|
const walletInfo = {
|
|
106316
106427
|
address,
|
|
106317
106428
|
network: {
|
|
@@ -106324,40 +106435,7 @@ var WalletModule = class {
|
|
|
106324
106435
|
balance: nativeBalance,
|
|
106325
106436
|
decimals: 18
|
|
106326
106437
|
},
|
|
106327
|
-
tokens
|
|
106328
|
-
// {
|
|
106329
|
-
// symbol: rbtBalance.symbol,
|
|
106330
|
-
// name: 'Real-estate Backed Token',
|
|
106331
|
-
// address: '0xB10536cC40Cb6E6415f70d3a4C1AF7Fa638AE829',
|
|
106332
|
-
// balance: rbtBalance,
|
|
106333
|
-
// decimals: rbtBalance.decimals,
|
|
106334
|
-
// totalSupply: rbtBalance,
|
|
106335
|
-
// },
|
|
106336
|
-
// {
|
|
106337
|
-
// symbol: usdrBalance.symbol,
|
|
106338
|
-
// name: 'USD Real-estate',
|
|
106339
|
-
// address: '0x8d335fe5B30e27F2B21F057a4766cf4BB8c30785',
|
|
106340
|
-
// balance: usdrBalance,
|
|
106341
|
-
// decimals: usdrBalance.decimals,
|
|
106342
|
-
// totalSupply: usdrBalance,
|
|
106343
|
-
// },
|
|
106344
|
-
// {
|
|
106345
|
-
// symbol: wftBalance.symbol,
|
|
106346
|
-
// name: 'WeBlock Foundation Token',
|
|
106347
|
-
// address: '0x6fa62Eda03956ef4E54f3C8597E8c3f3bE40A45B',
|
|
106348
|
-
// balance: wftBalance,
|
|
106349
|
-
// decimals: wftBalance.decimals,
|
|
106350
|
-
// totalSupply: wftBalance,
|
|
106351
|
-
// },
|
|
106352
|
-
// {
|
|
106353
|
-
// symbol: usdtBalance.symbol,
|
|
106354
|
-
// name: 'USD Tether',
|
|
106355
|
-
// address: '0xfF54B9ebe777f528E64C74bc95c68433B7546038',
|
|
106356
|
-
// balance: usdtBalance,
|
|
106357
|
-
// decimals: usdtBalance.decimals,
|
|
106358
|
-
// totalSupply: usdtBalance,
|
|
106359
|
-
// },
|
|
106360
|
-
],
|
|
106438
|
+
tokens,
|
|
106361
106439
|
nfts: [],
|
|
106362
106440
|
securities: []
|
|
106363
106441
|
},
|