@veridex/sdk 1.0.0-beta.1 → 1.0.0-beta.3
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/README.md +3 -0
- package/dist/index.d.mts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +93 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# @veridex/sdk
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@veridex/sdk)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
3
6
|
Veridex Protocol SDK - Client library for **Passkey-based cross-chain authentication**.
|
|
4
7
|
|
|
5
8
|
Build applications with WebAuthn/Passkeys (P-256) that work across EVM, Solana, Aptos, Sui, and Starknet.
|
package/dist/index.d.mts
CHANGED
|
@@ -1881,6 +1881,24 @@ declare class VeridexSDK {
|
|
|
1881
1881
|
* @returns The deterministic vault address
|
|
1882
1882
|
*/
|
|
1883
1883
|
getVaultAddressForKeyHash(keyHash: string): string;
|
|
1884
|
+
/**
|
|
1885
|
+
* Get the vault address for a specific chain
|
|
1886
|
+
* Each EVM chain has its own factory contract, so vault addresses are chain-specific.
|
|
1887
|
+
*
|
|
1888
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
1889
|
+
* @param keyHash - Optional key hash (defaults to current credential)
|
|
1890
|
+
* @returns The deterministic vault address for that chain, or null if chain not supported
|
|
1891
|
+
*/
|
|
1892
|
+
getVaultAddressForChain(wormholeChainId: number, keyHash?: string): string | null;
|
|
1893
|
+
/**
|
|
1894
|
+
* Get vault balances for a specific chain
|
|
1895
|
+
* Unlike getVaultBalances() which uses the hub chain, this fetches for any EVM chain.
|
|
1896
|
+
*
|
|
1897
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
1898
|
+
* @param includeZeroBalances - Whether to include tokens with 0 balance
|
|
1899
|
+
* @returns PortfolioBalance with all token balances for that chain
|
|
1900
|
+
*/
|
|
1901
|
+
getVaultBalancesForChain(wormholeChainId: number, includeZeroBalances?: boolean): Promise<PortfolioBalance>;
|
|
1884
1902
|
/**
|
|
1885
1903
|
* Get unified identity with addresses across chains
|
|
1886
1904
|
*
|
|
@@ -2635,6 +2653,10 @@ declare class RelayerClient {
|
|
|
2635
2653
|
* Get relay history for a user
|
|
2636
2654
|
*/
|
|
2637
2655
|
getRelayHistory(userKeyHash: string, limit?: number, offset?: number): Promise<RelayRequest[]>;
|
|
2656
|
+
/**
|
|
2657
|
+
* SDK version for telemetry
|
|
2658
|
+
*/
|
|
2659
|
+
private static readonly SDK_VERSION;
|
|
2638
2660
|
/**
|
|
2639
2661
|
* Make an HTTP request to the relayer
|
|
2640
2662
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1881,6 +1881,24 @@ declare class VeridexSDK {
|
|
|
1881
1881
|
* @returns The deterministic vault address
|
|
1882
1882
|
*/
|
|
1883
1883
|
getVaultAddressForKeyHash(keyHash: string): string;
|
|
1884
|
+
/**
|
|
1885
|
+
* Get the vault address for a specific chain
|
|
1886
|
+
* Each EVM chain has its own factory contract, so vault addresses are chain-specific.
|
|
1887
|
+
*
|
|
1888
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
1889
|
+
* @param keyHash - Optional key hash (defaults to current credential)
|
|
1890
|
+
* @returns The deterministic vault address for that chain, or null if chain not supported
|
|
1891
|
+
*/
|
|
1892
|
+
getVaultAddressForChain(wormholeChainId: number, keyHash?: string): string | null;
|
|
1893
|
+
/**
|
|
1894
|
+
* Get vault balances for a specific chain
|
|
1895
|
+
* Unlike getVaultBalances() which uses the hub chain, this fetches for any EVM chain.
|
|
1896
|
+
*
|
|
1897
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
1898
|
+
* @param includeZeroBalances - Whether to include tokens with 0 balance
|
|
1899
|
+
* @returns PortfolioBalance with all token balances for that chain
|
|
1900
|
+
*/
|
|
1901
|
+
getVaultBalancesForChain(wormholeChainId: number, includeZeroBalances?: boolean): Promise<PortfolioBalance>;
|
|
1884
1902
|
/**
|
|
1885
1903
|
* Get unified identity with addresses across chains
|
|
1886
1904
|
*
|
|
@@ -2635,6 +2653,10 @@ declare class RelayerClient {
|
|
|
2635
2653
|
* Get relay history for a user
|
|
2636
2654
|
*/
|
|
2637
2655
|
getRelayHistory(userKeyHash: string, limit?: number, offset?: number): Promise<RelayRequest[]>;
|
|
2656
|
+
/**
|
|
2657
|
+
* SDK version for telemetry
|
|
2658
|
+
*/
|
|
2659
|
+
private static readonly SDK_VERSION;
|
|
2638
2660
|
/**
|
|
2639
2661
|
* Make an HTTP request to the relayer
|
|
2640
2662
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2984,7 +2984,7 @@ var DEFAULT_CONFIG2 = {
|
|
|
2984
2984
|
timeoutMs: 3e4,
|
|
2985
2985
|
maxRetries: 3
|
|
2986
2986
|
};
|
|
2987
|
-
var RelayerClient = class {
|
|
2987
|
+
var RelayerClient = class _RelayerClient {
|
|
2988
2988
|
baseUrl;
|
|
2989
2989
|
config;
|
|
2990
2990
|
constructor(config) {
|
|
@@ -3208,12 +3208,17 @@ var RelayerClient = class {
|
|
|
3208
3208
|
// ========================================================================
|
|
3209
3209
|
// Internal Helpers
|
|
3210
3210
|
// ========================================================================
|
|
3211
|
+
/**
|
|
3212
|
+
* SDK version for telemetry
|
|
3213
|
+
*/
|
|
3214
|
+
static SDK_VERSION = "1.0.0-beta.1";
|
|
3211
3215
|
/**
|
|
3212
3216
|
* Make an HTTP request to the relayer
|
|
3213
3217
|
*/
|
|
3214
3218
|
async fetch(path, options = {}) {
|
|
3215
3219
|
const headers = {
|
|
3216
3220
|
"Content-Type": "application/json",
|
|
3221
|
+
"User-Agent": `@veridex/sdk/${_RelayerClient.SDK_VERSION}`,
|
|
3217
3222
|
...options.headers || {}
|
|
3218
3223
|
};
|
|
3219
3224
|
if (this.config.apiKey) {
|
|
@@ -9242,6 +9247,93 @@ var VeridexSDK = class {
|
|
|
9242
9247
|
getVaultAddressForKeyHash(keyHash) {
|
|
9243
9248
|
return this.chain.computeVaultAddress(keyHash);
|
|
9244
9249
|
}
|
|
9250
|
+
/**
|
|
9251
|
+
* Get the vault address for a specific chain
|
|
9252
|
+
* Each EVM chain has its own factory contract, so vault addresses are chain-specific.
|
|
9253
|
+
*
|
|
9254
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
9255
|
+
* @param keyHash - Optional key hash (defaults to current credential)
|
|
9256
|
+
* @returns The deterministic vault address for that chain, or null if chain not supported
|
|
9257
|
+
*/
|
|
9258
|
+
getVaultAddressForChain(wormholeChainId, keyHash) {
|
|
9259
|
+
const hash = keyHash ?? this.passkey.getCredential()?.keyHash;
|
|
9260
|
+
if (!hash) {
|
|
9261
|
+
throw new Error("No credential set and no keyHash provided");
|
|
9262
|
+
}
|
|
9263
|
+
const credential = { keyHash: hash };
|
|
9264
|
+
const derived = this.chainDetector.deriveVaultAddress(credential, wormholeChainId);
|
|
9265
|
+
return derived?.address ?? null;
|
|
9266
|
+
}
|
|
9267
|
+
/**
|
|
9268
|
+
* Get vault balances for a specific chain
|
|
9269
|
+
* Unlike getVaultBalances() which uses the hub chain, this fetches for any EVM chain.
|
|
9270
|
+
*
|
|
9271
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
9272
|
+
* @param includeZeroBalances - Whether to include tokens with 0 balance
|
|
9273
|
+
* @returns PortfolioBalance with all token balances for that chain
|
|
9274
|
+
*/
|
|
9275
|
+
async getVaultBalancesForChain(wormholeChainId, includeZeroBalances = false) {
|
|
9276
|
+
const credential = this.passkey.getCredential();
|
|
9277
|
+
if (!credential) {
|
|
9278
|
+
throw new Error("No credential set");
|
|
9279
|
+
}
|
|
9280
|
+
const vaultAddress = this.getVaultAddressForChain(wormholeChainId, credential.keyHash);
|
|
9281
|
+
if (!vaultAddress) {
|
|
9282
|
+
throw new Error(`Cannot derive vault address for chain ${wormholeChainId}`);
|
|
9283
|
+
}
|
|
9284
|
+
const chainConfig = this.chainDetector.getChainConfig(wormholeChainId);
|
|
9285
|
+
if (!chainConfig) {
|
|
9286
|
+
throw new Error(`Unknown chain ${wormholeChainId}`);
|
|
9287
|
+
}
|
|
9288
|
+
if (this.queryApiKey) {
|
|
9289
|
+
try {
|
|
9290
|
+
const tokenList = getAllTokens(wormholeChainId);
|
|
9291
|
+
const erc20Tokens = tokenList.filter((t) => !isNativeToken(t.address)).map((t) => t.address);
|
|
9292
|
+
const rpcUrl = this.chainRpcUrls?.[wormholeChainId] ?? chainConfig.rpcUrl;
|
|
9293
|
+
const result = await queryPortfolio(credential.keyHash, this.queryApiKey, {
|
|
9294
|
+
network: this.testnet ? "testnet" : "mainnet",
|
|
9295
|
+
vaultAddresses: { [wormholeChainId]: vaultAddress },
|
|
9296
|
+
evmTokenAddresses: { [wormholeChainId]: erc20Tokens },
|
|
9297
|
+
rpcUrls: { [wormholeChainId]: rpcUrl },
|
|
9298
|
+
maxAge: 60,
|
|
9299
|
+
timeout: this.testnet ? 15e3 : 1e4,
|
|
9300
|
+
maxAttempts: this.testnet ? 3 : 2
|
|
9301
|
+
});
|
|
9302
|
+
const chain = result.chains.find((c) => c.wormholeChainId === wormholeChainId);
|
|
9303
|
+
if (chain && !chain.error) {
|
|
9304
|
+
const byAssetId = new Map(chain.balances.map((b) => [b.assetId.toLowerCase(), b]));
|
|
9305
|
+
const tokens = tokenList.map((t) => {
|
|
9306
|
+
if (isNativeToken(t.address)) {
|
|
9307
|
+
return null;
|
|
9308
|
+
}
|
|
9309
|
+
const found = byAssetId.get(t.address.toLowerCase());
|
|
9310
|
+
const amount = found?.amount ?? 0n;
|
|
9311
|
+
const formatted = import_ethers15.ethers.formatUnits(amount, t.decimals);
|
|
9312
|
+
return {
|
|
9313
|
+
token: t,
|
|
9314
|
+
balance: amount,
|
|
9315
|
+
formatted,
|
|
9316
|
+
usdValue: found?.usdValue
|
|
9317
|
+
};
|
|
9318
|
+
}).filter((t) => !!t);
|
|
9319
|
+
const native = await this.balance.getNativeBalance(wormholeChainId, vaultAddress);
|
|
9320
|
+
const merged = [native, ...tokens];
|
|
9321
|
+
const filtered = includeZeroBalances ? merged : merged.filter((t) => t.balance > 0n);
|
|
9322
|
+
const totalUsdValue = filtered.reduce((sum, t) => sum + (t.usdValue ?? 0), 0);
|
|
9323
|
+
return {
|
|
9324
|
+
wormholeChainId,
|
|
9325
|
+
chainName: chainConfig.name,
|
|
9326
|
+
address: vaultAddress,
|
|
9327
|
+
tokens: filtered,
|
|
9328
|
+
totalUsdValue: totalUsdValue || void 0,
|
|
9329
|
+
lastUpdated: Date.now()
|
|
9330
|
+
};
|
|
9331
|
+
}
|
|
9332
|
+
} catch {
|
|
9333
|
+
}
|
|
9334
|
+
}
|
|
9335
|
+
return await this.balance.getPortfolioBalance(wormholeChainId, vaultAddress, includeZeroBalances);
|
|
9336
|
+
}
|
|
9245
9337
|
/**
|
|
9246
9338
|
* Get unified identity with addresses across chains
|
|
9247
9339
|
*
|