@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.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([
|
|
@@ -106018,16 +106061,52 @@ var AssetService = class extends EventEmitter {
|
|
|
106018
106061
|
checkStatus();
|
|
106019
106062
|
}
|
|
106020
106063
|
async addToken(params) {
|
|
106064
|
+
const hasMeta = !!params.name && !!params.symbol && typeof params.decimals === "number";
|
|
106065
|
+
const meta = hasMeta ? {
|
|
106066
|
+
name: params.name,
|
|
106067
|
+
symbol: params.symbol,
|
|
106068
|
+
decimals: params.decimals
|
|
106069
|
+
} : await this.getTokenInfo({
|
|
106070
|
+
networkId: params.networkId,
|
|
106071
|
+
tokenAddress: params.address
|
|
106072
|
+
});
|
|
106073
|
+
try {
|
|
106074
|
+
await this.userClient.registerToken({
|
|
106075
|
+
blockchainId: params.networkId,
|
|
106076
|
+
contractAddress: params.address,
|
|
106077
|
+
name: meta.name,
|
|
106078
|
+
symbol: meta.symbol,
|
|
106079
|
+
decimals: meta.decimals
|
|
106080
|
+
});
|
|
106081
|
+
} catch (error) {
|
|
106082
|
+
throw new SDKError(
|
|
106083
|
+
"Failed to register token",
|
|
106084
|
+
"REQUEST_FAILED" /* REQUEST_FAILED */,
|
|
106085
|
+
error
|
|
106086
|
+
);
|
|
106087
|
+
}
|
|
106021
106088
|
const key = `${this.orgHost}:token:${params.networkId}:${params.address}`;
|
|
106022
106089
|
await LocalForage.save(key, params);
|
|
106023
106090
|
}
|
|
106091
|
+
async getRegisteredCoins(networkId) {
|
|
106092
|
+
try {
|
|
106093
|
+
return await this.userClient.getRegisteredCoins(networkId);
|
|
106094
|
+
} catch (error) {
|
|
106095
|
+
throw new SDKError(
|
|
106096
|
+
"Failed to get registered tokens",
|
|
106097
|
+
"REQUEST_FAILED" /* REQUEST_FAILED */,
|
|
106098
|
+
error
|
|
106099
|
+
);
|
|
106100
|
+
}
|
|
106101
|
+
}
|
|
106024
106102
|
async getTokenBalance(params) {
|
|
106025
106103
|
try {
|
|
106104
|
+
const chainId = await this.resolveChainId(params.networkId);
|
|
106026
106105
|
const data = this.erc20Interface.encodeFunctionData("balanceOf", [
|
|
106027
106106
|
params.walletAddress
|
|
106028
106107
|
]);
|
|
106029
106108
|
const response = await this.rpcClient.sendRpc({
|
|
106030
|
-
chainId
|
|
106109
|
+
chainId,
|
|
106031
106110
|
method: "eth_call" /* ETH_CALL */,
|
|
106032
106111
|
params: [
|
|
106033
106112
|
{
|
|
@@ -106048,12 +106127,13 @@ var AssetService = class extends EventEmitter {
|
|
|
106048
106127
|
}
|
|
106049
106128
|
async approveToken(params) {
|
|
106050
106129
|
try {
|
|
106130
|
+
const chainId = await this.resolveChainId(params.networkId);
|
|
106051
106131
|
const data = this.erc20Interface.encodeFunctionData("approve", [
|
|
106052
106132
|
params.spender,
|
|
106053
106133
|
params.amount
|
|
106054
106134
|
]);
|
|
106055
106135
|
const response = await this.rpcClient.sendRpc({
|
|
106056
|
-
chainId
|
|
106136
|
+
chainId,
|
|
106057
106137
|
method: "eth_sendRawTransaction" /* ETH_SEND_RAW_TRANSACTION */,
|
|
106058
106138
|
params: [
|
|
106059
106139
|
{
|
|
@@ -106073,12 +106153,13 @@ var AssetService = class extends EventEmitter {
|
|
|
106073
106153
|
}
|
|
106074
106154
|
async getAllowance(params) {
|
|
106075
106155
|
try {
|
|
106156
|
+
const chainId = await this.resolveChainId(params.networkId);
|
|
106076
106157
|
const data = this.erc20Interface.encodeFunctionData("allowance", [
|
|
106077
106158
|
params.owner,
|
|
106078
106159
|
params.spender
|
|
106079
106160
|
]);
|
|
106080
106161
|
const response = await this.rpcClient.sendRpc({
|
|
106081
|
-
chainId
|
|
106162
|
+
chainId,
|
|
106082
106163
|
method: "eth_call" /* ETH_CALL */,
|
|
106083
106164
|
params: [
|
|
106084
106165
|
{
|
|
@@ -106098,9 +106179,10 @@ var AssetService = class extends EventEmitter {
|
|
|
106098
106179
|
}
|
|
106099
106180
|
}
|
|
106100
106181
|
async callTokenMethod(tokenAddress, networkId, method) {
|
|
106182
|
+
const chainId = await this.resolveChainId(networkId);
|
|
106101
106183
|
const data = this.erc20Interface.encodeFunctionData(method, []);
|
|
106102
106184
|
const response = await this.rpcClient.sendRpc({
|
|
106103
|
-
chainId
|
|
106185
|
+
chainId,
|
|
106104
106186
|
method: "eth_call" /* ETH_CALL */,
|
|
106105
106187
|
params: [
|
|
106106
106188
|
{
|
|
@@ -106158,7 +106240,6 @@ var InternalCoreImpl = class {
|
|
|
106158
106240
|
getAddress: () => this.walletService.getAddress(),
|
|
106159
106241
|
create: (password) => this.walletService.create(password),
|
|
106160
106242
|
retrieveWallet: (password) => this.walletService.retrieveWallet(password),
|
|
106161
|
-
resetPin: (newPassword) => this.walletService.resetPin(newPassword),
|
|
106162
106243
|
getBalance: (address, chainId) => this.walletService.getBalance(address, chainId),
|
|
106163
106244
|
getTokenBalance: (tokenAddress, walletAddress, chainId) => this.walletService.getTokenBalance(tokenAddress, walletAddress, chainId),
|
|
106164
106245
|
sendTransaction: (params) => this.walletService.sendTransaction(params),
|
|
@@ -106180,25 +106261,27 @@ var InternalCoreImpl = class {
|
|
|
106180
106261
|
};
|
|
106181
106262
|
this.asset = {
|
|
106182
106263
|
transfer: (params) => this.assetService.transfer(params),
|
|
106183
|
-
|
|
106184
|
-
|
|
106185
|
-
* - InternalCore는 decimals?: number
|
|
106186
|
-
* - 기존 AssetService 내부 구현이 decimals를 string으로 받는 경우가 있어,
|
|
106187
|
-
* 여기서 안전하게 string으로 변환해서 전달합니다.
|
|
106188
|
-
*/
|
|
106189
|
-
addToken: (params) => this.assetService.addToken({
|
|
106190
|
-
...params,
|
|
106191
|
-
decimals: typeof params.decimals === "number" ? String(params.decimals) : void 0
|
|
106192
|
-
}),
|
|
106264
|
+
addToken: (params) => this.assetService.addToken(params),
|
|
106265
|
+
// New ERC20 methods
|
|
106193
106266
|
getTokenBalance: (params) => this.assetService.getTokenBalance(params),
|
|
106194
106267
|
approveToken: (params) => this.assetService.approveToken(params),
|
|
106195
106268
|
getAllowance: (params) => this.assetService.getAllowance(params),
|
|
106269
|
+
// getTokenInfo: (params: TokenInfoParams) =>
|
|
106270
|
+
// this.assetService.getTokenInfo(params),
|
|
106196
106271
|
addNFTCollection: (params) => this.assetService.addNFTCollection(params),
|
|
106272
|
+
// checkSecurityTokenCompliance: (params: {
|
|
106273
|
+
// networkId: string
|
|
106274
|
+
// tokenAddress: string
|
|
106275
|
+
// from: string
|
|
106276
|
+
// to: string
|
|
106277
|
+
// amount: string
|
|
106278
|
+
// }) => this.assetService.checkSecurityTokenCompliance(params),
|
|
106197
106279
|
on: (event, listener) => this.assetService.on(event, listener),
|
|
106198
106280
|
off: (event, listener) => this.assetService.off(event, listener),
|
|
106199
106281
|
getTokenInfo: (params) => this.assetService.getTokenInfo(params),
|
|
106200
106282
|
registerToken: (params) => this.assetService.registerToken(params),
|
|
106201
|
-
getTokenFullInfo: (params) => this.assetService.getTokenFullInfo(params)
|
|
106283
|
+
getTokenFullInfo: (params) => this.assetService.getTokenFullInfo(params),
|
|
106284
|
+
getRegisteredCoins: (networkId) => this.assetService.getRegisteredCoins(networkId)
|
|
106202
106285
|
};
|
|
106203
106286
|
const httpClient = new HttpClient(options);
|
|
106204
106287
|
const firebase = new FirebaseAuth(options);
|
|
@@ -106353,6 +106436,34 @@ var WalletModule = class {
|
|
|
106353
106436
|
network.chainId
|
|
106354
106437
|
);
|
|
106355
106438
|
console.log("\uCD5C\uADFC \uD2B8\uB79C\uC7AD\uC158:", latestTransaction);
|
|
106439
|
+
let tokens = [];
|
|
106440
|
+
try {
|
|
106441
|
+
const registered = await this.core.asset.getRegisteredCoins(network.id);
|
|
106442
|
+
if (registered?.length) {
|
|
106443
|
+
const unique = new Map(
|
|
106444
|
+
registered.map((c5) => [c5.contractAddress.toLowerCase(), c5])
|
|
106445
|
+
);
|
|
106446
|
+
tokens = await Promise.all(
|
|
106447
|
+
Array.from(unique.values()).map(async (coin) => {
|
|
106448
|
+
const full = await this.core.asset.getTokenFullInfo({
|
|
106449
|
+
networkId: network.id,
|
|
106450
|
+
tokenAddress: coin.contractAddress,
|
|
106451
|
+
walletAddress: address
|
|
106452
|
+
});
|
|
106453
|
+
return {
|
|
106454
|
+
...full,
|
|
106455
|
+
address: coin.contractAddress,
|
|
106456
|
+
name: coin.name ?? full.name,
|
|
106457
|
+
symbol: coin.symbol ?? full.symbol,
|
|
106458
|
+
decimals: typeof coin.decimals === "number" ? coin.decimals : full.decimals
|
|
106459
|
+
};
|
|
106460
|
+
})
|
|
106461
|
+
);
|
|
106462
|
+
}
|
|
106463
|
+
} catch (e7) {
|
|
106464
|
+
console.warn("Registered token load failed:", e7);
|
|
106465
|
+
tokens = [];
|
|
106466
|
+
}
|
|
106356
106467
|
const walletInfo = {
|
|
106357
106468
|
address,
|
|
106358
106469
|
network: {
|
|
@@ -106365,40 +106476,7 @@ var WalletModule = class {
|
|
|
106365
106476
|
balance: nativeBalance,
|
|
106366
106477
|
decimals: 18
|
|
106367
106478
|
},
|
|
106368
|
-
tokens
|
|
106369
|
-
// {
|
|
106370
|
-
// symbol: rbtBalance.symbol,
|
|
106371
|
-
// name: 'Real-estate Backed Token',
|
|
106372
|
-
// address: '0xB10536cC40Cb6E6415f70d3a4C1AF7Fa638AE829',
|
|
106373
|
-
// balance: rbtBalance,
|
|
106374
|
-
// decimals: rbtBalance.decimals,
|
|
106375
|
-
// totalSupply: rbtBalance,
|
|
106376
|
-
// },
|
|
106377
|
-
// {
|
|
106378
|
-
// symbol: usdrBalance.symbol,
|
|
106379
|
-
// name: 'USD Real-estate',
|
|
106380
|
-
// address: '0x8d335fe5B30e27F2B21F057a4766cf4BB8c30785',
|
|
106381
|
-
// balance: usdrBalance,
|
|
106382
|
-
// decimals: usdrBalance.decimals,
|
|
106383
|
-
// totalSupply: usdrBalance,
|
|
106384
|
-
// },
|
|
106385
|
-
// {
|
|
106386
|
-
// symbol: wftBalance.symbol,
|
|
106387
|
-
// name: 'WeBlock Foundation Token',
|
|
106388
|
-
// address: '0x6fa62Eda03956ef4E54f3C8597E8c3f3bE40A45B',
|
|
106389
|
-
// balance: wftBalance,
|
|
106390
|
-
// decimals: wftBalance.decimals,
|
|
106391
|
-
// totalSupply: wftBalance,
|
|
106392
|
-
// },
|
|
106393
|
-
// {
|
|
106394
|
-
// symbol: usdtBalance.symbol,
|
|
106395
|
-
// name: 'USD Tether',
|
|
106396
|
-
// address: '0xfF54B9ebe777f528E64C74bc95c68433B7546038',
|
|
106397
|
-
// balance: usdtBalance,
|
|
106398
|
-
// decimals: usdtBalance.decimals,
|
|
106399
|
-
// totalSupply: usdtBalance,
|
|
106400
|
-
// },
|
|
106401
|
-
],
|
|
106479
|
+
tokens,
|
|
106402
106480
|
nfts: [],
|
|
106403
106481
|
securities: []
|
|
106404
106482
|
},
|