@zyfai/sdk 0.1.12 → 0.1.13
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.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -6
- package/dist/index.mjs +15 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -416,6 +416,7 @@ declare class ZyfaiSDK {
|
|
|
416
416
|
private hasActiveSessionKey;
|
|
417
417
|
private environment;
|
|
418
418
|
private currentProvider;
|
|
419
|
+
private currentChainId;
|
|
419
420
|
constructor(config: SDKConfig | string);
|
|
420
421
|
/**
|
|
421
422
|
* Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
|
package/dist/index.d.ts
CHANGED
|
@@ -416,6 +416,7 @@ declare class ZyfaiSDK {
|
|
|
416
416
|
private hasActiveSessionKey;
|
|
417
417
|
private environment;
|
|
418
418
|
private currentProvider;
|
|
419
|
+
private currentChainId;
|
|
419
420
|
constructor(config: SDKConfig | string);
|
|
420
421
|
/**
|
|
421
422
|
* Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
|
package/dist/index.js
CHANGED
|
@@ -374,7 +374,7 @@ var plasma = (0, import_viem2.defineChain)({
|
|
|
374
374
|
},
|
|
375
375
|
rpcUrls: {
|
|
376
376
|
default: {
|
|
377
|
-
http: ["https://rpc.plasma.
|
|
377
|
+
http: ["https://rpc.plasma.to"]
|
|
378
378
|
}
|
|
379
379
|
},
|
|
380
380
|
blockExplorers: {
|
|
@@ -387,7 +387,7 @@ var plasma = (0, import_viem2.defineChain)({
|
|
|
387
387
|
var DEFAULT_RPC_URLS = {
|
|
388
388
|
8453: "https://mainnet.base.org",
|
|
389
389
|
42161: "https://arb1.arbitrum.io/rpc",
|
|
390
|
-
9745: "https://rpc.plasma.
|
|
390
|
+
9745: "https://rpc.plasma.to"
|
|
391
391
|
};
|
|
392
392
|
var CHAINS = {
|
|
393
393
|
8453: import_chains.base,
|
|
@@ -658,7 +658,7 @@ var signSessionKey = async (config, sessions, allPublicClients) => {
|
|
|
658
658
|
// src/core/ZyfaiSDK.ts
|
|
659
659
|
var import_siwe = require("siwe");
|
|
660
660
|
var ZyfaiSDK = class {
|
|
661
|
-
// Store
|
|
661
|
+
// Store current chain ID for private key connections
|
|
662
662
|
constructor(config) {
|
|
663
663
|
this.signer = null;
|
|
664
664
|
this.walletClient = null;
|
|
@@ -667,6 +667,8 @@ var ZyfaiSDK = class {
|
|
|
667
667
|
this.hasActiveSessionKey = false;
|
|
668
668
|
// TODO: The environment should be removed. Having the same key for staging and production is not ideal, but for now it's fine.
|
|
669
669
|
this.currentProvider = null;
|
|
670
|
+
// Store reference to current provider for event handling
|
|
671
|
+
this.currentChainId = null;
|
|
670
672
|
const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
|
|
671
673
|
const { apiKey, dataApiKey, environment, bundlerApiKey } = sdkConfig;
|
|
672
674
|
if (!apiKey) {
|
|
@@ -690,7 +692,7 @@ var ZyfaiSDK = class {
|
|
|
690
692
|
}
|
|
691
693
|
const walletClient = this.getWalletClient();
|
|
692
694
|
const userAddress = (0, import_viem4.getAddress)(walletClient.account.address);
|
|
693
|
-
const chainId = walletClient.chain?.id || 8453;
|
|
695
|
+
const chainId = this.currentChainId || walletClient.chain?.id || 8453;
|
|
694
696
|
const challengeResponse = await this.httpClient.post(ENDPOINTS.AUTH_CHALLENGE, {});
|
|
695
697
|
let uri;
|
|
696
698
|
let domain;
|
|
@@ -832,6 +834,7 @@ var ZyfaiSDK = class {
|
|
|
832
834
|
chain: chainConfig.chain,
|
|
833
835
|
transport: (0, import_viem4.custom)(this.currentProvider)
|
|
834
836
|
});
|
|
837
|
+
this.currentChainId = this.walletClient.chain?.id || null;
|
|
835
838
|
try {
|
|
836
839
|
await this.authenticateUser();
|
|
837
840
|
} catch (error) {
|
|
@@ -864,6 +867,7 @@ var ZyfaiSDK = class {
|
|
|
864
867
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
865
868
|
}
|
|
866
869
|
this.authenticatedUserId = null;
|
|
870
|
+
this.currentChainId = null;
|
|
867
871
|
this.httpClient.clearAuthToken();
|
|
868
872
|
if (this.currentProvider?.removeAllListeners) {
|
|
869
873
|
try {
|
|
@@ -879,6 +883,7 @@ var ZyfaiSDK = class {
|
|
|
879
883
|
privateKey = `0x${privateKey}`;
|
|
880
884
|
}
|
|
881
885
|
this.signer = (0, import_accounts2.privateKeyToAccount)(privateKey);
|
|
886
|
+
this.currentChainId = chainId;
|
|
882
887
|
this.walletClient = (0, import_viem4.createWalletClient)({
|
|
883
888
|
account: this.signer,
|
|
884
889
|
chain: chainConfig.chain,
|
|
@@ -907,6 +912,7 @@ var ZyfaiSDK = class {
|
|
|
907
912
|
});
|
|
908
913
|
connectedAddress = accounts[0];
|
|
909
914
|
this.currentProvider = provider;
|
|
915
|
+
this.currentChainId = chainId;
|
|
910
916
|
if (provider.on) {
|
|
911
917
|
provider.on("accountsChanged", this.handleAccountsChanged.bind(this));
|
|
912
918
|
}
|
|
@@ -918,6 +924,7 @@ var ZyfaiSDK = class {
|
|
|
918
924
|
});
|
|
919
925
|
connectedAddress = provider.account.address;
|
|
920
926
|
this.currentProvider = null;
|
|
927
|
+
this.currentChainId = chainId;
|
|
921
928
|
} else {
|
|
922
929
|
throw new Error(
|
|
923
930
|
"Invalid wallet provider. Expected EIP-1193 provider or viem WalletClient."
|
|
@@ -947,6 +954,7 @@ var ZyfaiSDK = class {
|
|
|
947
954
|
this.signer = null;
|
|
948
955
|
this.walletClient = null;
|
|
949
956
|
this.currentProvider = null;
|
|
957
|
+
this.currentChainId = null;
|
|
950
958
|
this.authenticatedUserId = null;
|
|
951
959
|
this.hasActiveSessionKey = false;
|
|
952
960
|
this.httpClient.clearAuthToken();
|
|
@@ -957,10 +965,11 @@ var ZyfaiSDK = class {
|
|
|
957
965
|
*/
|
|
958
966
|
getWalletClient(chainId) {
|
|
959
967
|
if (this.signer) {
|
|
968
|
+
const targetChainId = chainId || this.currentChainId || 8453;
|
|
960
969
|
return (0, import_viem4.createWalletClient)({
|
|
961
970
|
account: this.signer,
|
|
962
|
-
chain: getChainConfig(
|
|
963
|
-
transport: (0, import_viem4.http)(getChainConfig(
|
|
971
|
+
chain: getChainConfig(targetChainId).chain,
|
|
972
|
+
transport: (0, import_viem4.http)(getChainConfig(targetChainId).rpcUrl)
|
|
964
973
|
});
|
|
965
974
|
} else {
|
|
966
975
|
if (!this.walletClient) {
|
package/dist/index.mjs
CHANGED
|
@@ -340,7 +340,7 @@ var plasma = defineChain({
|
|
|
340
340
|
},
|
|
341
341
|
rpcUrls: {
|
|
342
342
|
default: {
|
|
343
|
-
http: ["https://rpc.plasma.
|
|
343
|
+
http: ["https://rpc.plasma.to"]
|
|
344
344
|
}
|
|
345
345
|
},
|
|
346
346
|
blockExplorers: {
|
|
@@ -353,7 +353,7 @@ var plasma = defineChain({
|
|
|
353
353
|
var DEFAULT_RPC_URLS = {
|
|
354
354
|
8453: "https://mainnet.base.org",
|
|
355
355
|
42161: "https://arb1.arbitrum.io/rpc",
|
|
356
|
-
9745: "https://rpc.plasma.
|
|
356
|
+
9745: "https://rpc.plasma.to"
|
|
357
357
|
};
|
|
358
358
|
var CHAINS = {
|
|
359
359
|
8453: base,
|
|
@@ -638,7 +638,7 @@ var signSessionKey = async (config, sessions, allPublicClients) => {
|
|
|
638
638
|
// src/core/ZyfaiSDK.ts
|
|
639
639
|
import { SiweMessage } from "siwe";
|
|
640
640
|
var ZyfaiSDK = class {
|
|
641
|
-
// Store
|
|
641
|
+
// Store current chain ID for private key connections
|
|
642
642
|
constructor(config) {
|
|
643
643
|
this.signer = null;
|
|
644
644
|
this.walletClient = null;
|
|
@@ -647,6 +647,8 @@ var ZyfaiSDK = class {
|
|
|
647
647
|
this.hasActiveSessionKey = false;
|
|
648
648
|
// TODO: The environment should be removed. Having the same key for staging and production is not ideal, but for now it's fine.
|
|
649
649
|
this.currentProvider = null;
|
|
650
|
+
// Store reference to current provider for event handling
|
|
651
|
+
this.currentChainId = null;
|
|
650
652
|
const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
|
|
651
653
|
const { apiKey, dataApiKey, environment, bundlerApiKey } = sdkConfig;
|
|
652
654
|
if (!apiKey) {
|
|
@@ -670,7 +672,7 @@ var ZyfaiSDK = class {
|
|
|
670
672
|
}
|
|
671
673
|
const walletClient = this.getWalletClient();
|
|
672
674
|
const userAddress = getAddress2(walletClient.account.address);
|
|
673
|
-
const chainId = walletClient.chain?.id || 8453;
|
|
675
|
+
const chainId = this.currentChainId || walletClient.chain?.id || 8453;
|
|
674
676
|
const challengeResponse = await this.httpClient.post(ENDPOINTS.AUTH_CHALLENGE, {});
|
|
675
677
|
let uri;
|
|
676
678
|
let domain;
|
|
@@ -812,6 +814,7 @@ var ZyfaiSDK = class {
|
|
|
812
814
|
chain: chainConfig.chain,
|
|
813
815
|
transport: custom(this.currentProvider)
|
|
814
816
|
});
|
|
817
|
+
this.currentChainId = this.walletClient.chain?.id || null;
|
|
815
818
|
try {
|
|
816
819
|
await this.authenticateUser();
|
|
817
820
|
} catch (error) {
|
|
@@ -844,6 +847,7 @@ var ZyfaiSDK = class {
|
|
|
844
847
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
845
848
|
}
|
|
846
849
|
this.authenticatedUserId = null;
|
|
850
|
+
this.currentChainId = null;
|
|
847
851
|
this.httpClient.clearAuthToken();
|
|
848
852
|
if (this.currentProvider?.removeAllListeners) {
|
|
849
853
|
try {
|
|
@@ -859,6 +863,7 @@ var ZyfaiSDK = class {
|
|
|
859
863
|
privateKey = `0x${privateKey}`;
|
|
860
864
|
}
|
|
861
865
|
this.signer = privateKeyToAccount(privateKey);
|
|
866
|
+
this.currentChainId = chainId;
|
|
862
867
|
this.walletClient = createWalletClient({
|
|
863
868
|
account: this.signer,
|
|
864
869
|
chain: chainConfig.chain,
|
|
@@ -887,6 +892,7 @@ var ZyfaiSDK = class {
|
|
|
887
892
|
});
|
|
888
893
|
connectedAddress = accounts[0];
|
|
889
894
|
this.currentProvider = provider;
|
|
895
|
+
this.currentChainId = chainId;
|
|
890
896
|
if (provider.on) {
|
|
891
897
|
provider.on("accountsChanged", this.handleAccountsChanged.bind(this));
|
|
892
898
|
}
|
|
@@ -898,6 +904,7 @@ var ZyfaiSDK = class {
|
|
|
898
904
|
});
|
|
899
905
|
connectedAddress = provider.account.address;
|
|
900
906
|
this.currentProvider = null;
|
|
907
|
+
this.currentChainId = chainId;
|
|
901
908
|
} else {
|
|
902
909
|
throw new Error(
|
|
903
910
|
"Invalid wallet provider. Expected EIP-1193 provider or viem WalletClient."
|
|
@@ -927,6 +934,7 @@ var ZyfaiSDK = class {
|
|
|
927
934
|
this.signer = null;
|
|
928
935
|
this.walletClient = null;
|
|
929
936
|
this.currentProvider = null;
|
|
937
|
+
this.currentChainId = null;
|
|
930
938
|
this.authenticatedUserId = null;
|
|
931
939
|
this.hasActiveSessionKey = false;
|
|
932
940
|
this.httpClient.clearAuthToken();
|
|
@@ -937,10 +945,11 @@ var ZyfaiSDK = class {
|
|
|
937
945
|
*/
|
|
938
946
|
getWalletClient(chainId) {
|
|
939
947
|
if (this.signer) {
|
|
948
|
+
const targetChainId = chainId || this.currentChainId || 8453;
|
|
940
949
|
return createWalletClient({
|
|
941
950
|
account: this.signer,
|
|
942
|
-
chain: getChainConfig(
|
|
943
|
-
transport: http3(getChainConfig(
|
|
951
|
+
chain: getChainConfig(targetChainId).chain,
|
|
952
|
+
transport: http3(getChainConfig(targetChainId).rpcUrl)
|
|
944
953
|
});
|
|
945
954
|
} else {
|
|
946
955
|
if (!this.walletClient) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "TypeScript SDK for ZyFAI Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|