@rhinestone/deposit-modal 0.1.25 → 0.1.27

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.
@@ -1,11 +1,9 @@
1
1
  import {
2
2
  CHAIN_BY_ID,
3
3
  NATIVE_TOKEN_ADDRESS,
4
- SUPPORTED_CHAINS,
5
4
  getChainIcon,
6
5
  getChainName,
7
6
  getExplorerTxUrl,
8
- getSupportedTokenSymbolsForChain,
9
7
  getTokenAddress,
10
8
  getTokenDecimalsByAddress,
11
9
  getTokenSymbol,
@@ -146,6 +144,67 @@ Modal.displayName = "Modal";
146
144
  function jsonReplacer(_key, value) {
147
145
  return typeof value === "bigint" ? value.toString() : value;
148
146
  }
147
+ function asRecord(value) {
148
+ return typeof value === "object" && value !== null ? value : null;
149
+ }
150
+ function toBigInt(value) {
151
+ if (typeof value === "bigint") return value;
152
+ if (typeof value === "number" && Number.isInteger(value)) return BigInt(value);
153
+ if (typeof value === "string" && value.trim() !== "") return BigInt(value);
154
+ throw new Error("Invalid bigint value");
155
+ }
156
+ function normalizeSessionTypedData(raw) {
157
+ const data = structuredClone(raw);
158
+ const domain = asRecord(data.domain);
159
+ if (domain && domain.chainId !== void 0 && domain.chainId !== null) {
160
+ domain.chainId = toBigInt(domain.chainId);
161
+ }
162
+ const message = asRecord(data.message);
163
+ if (!message || !Array.isArray(message.sessionsAndChainIds)) {
164
+ return data;
165
+ }
166
+ for (const entry of message.sessionsAndChainIds) {
167
+ const chainSession = asRecord(entry);
168
+ if (!chainSession) continue;
169
+ if (chainSession.chainId !== void 0 && chainSession.chainId !== null) {
170
+ chainSession.chainId = toBigInt(chainSession.chainId);
171
+ }
172
+ const session = asRecord(chainSession.session);
173
+ if (!session) continue;
174
+ if (session.nonce !== void 0 && session.nonce !== null) {
175
+ session.nonce = toBigInt(session.nonce);
176
+ }
177
+ if (session.expires !== void 0 && session.expires !== null) {
178
+ session.expires = toBigInt(session.expires);
179
+ }
180
+ }
181
+ return data;
182
+ }
183
+ function normalizePrepareAccountResponse(raw) {
184
+ const data = raw;
185
+ return {
186
+ smartAccount: data.smartAccount,
187
+ accountParams: data.accountParams,
188
+ sessionDetailsUnsigned: {
189
+ hashesAndChainIds: data.sessionDetailsUnsigned.hashesAndChainIds.map(
190
+ (h) => ({
191
+ chainId: toBigInt(h.chainId),
192
+ sessionDigest: h.sessionDigest
193
+ })
194
+ ),
195
+ data: normalizeSessionTypedData(data.sessionDetailsUnsigned.data)
196
+ }
197
+ };
198
+ }
199
+ function buildSessionDetails(unsigned, signature) {
200
+ return {
201
+ hashesAndChainIds: unsigned.hashesAndChainIds.map((h) => ({
202
+ chainId: toBigInt(h.chainId),
203
+ sessionDigest: h.sessionDigest
204
+ })),
205
+ signature
206
+ };
207
+ }
149
208
  function createDepositService(baseUrl) {
150
209
  const normalizedBaseUrl = baseUrl.replace(/\/$/, "");
151
210
  function apiUrl(path) {
@@ -153,6 +212,34 @@ function createDepositService(baseUrl) {
153
212
  return `${normalizedBaseUrl}${normalizedPath}`;
154
213
  }
155
214
  return {
215
+ async computeAddress(ownerAddress, sessionOwnerAddress) {
216
+ const response = await fetch(apiUrl("/compute-address"), {
217
+ method: "POST",
218
+ headers: { "Content-Type": "application/json" },
219
+ body: JSON.stringify({ ownerAddress, sessionOwnerAddress })
220
+ });
221
+ if (!response.ok) {
222
+ const error = await response.json().catch(() => ({ error: "Unknown error" }));
223
+ throw new Error(
224
+ error.error || `Compute address failed: ${response.status}`
225
+ );
226
+ }
227
+ return response.json();
228
+ },
229
+ async prepareAccount(params) {
230
+ const response = await fetch(apiUrl("/prepare-account"), {
231
+ method: "POST",
232
+ headers: { "Content-Type": "application/json" },
233
+ body: JSON.stringify(params)
234
+ });
235
+ if (!response.ok) {
236
+ const error = await response.json().catch(() => ({ error: "Unknown error" }));
237
+ throw new Error(
238
+ error.error || `Prepare account failed: ${response.status}`
239
+ );
240
+ }
241
+ return normalizePrepareAccountResponse(await response.json());
242
+ },
156
243
  async registerAccount(params) {
157
244
  const { eoaAddress, sessionOwner, ...account } = params;
158
245
  const response = await fetch(apiUrl("/register"), {
@@ -803,165 +890,6 @@ function ConnectStep({
803
890
  }
804
891
  ConnectStep.displayName = "ConnectStep";
805
892
 
806
- // src/core/account.ts
807
- import {
808
- RhinestoneSDK
809
- } from "@rhinestone/sdk";
810
- import { zeroAddress } from "viem";
811
- import { toAccount } from "viem/accounts";
812
- function createViewOnlyAccount(address) {
813
- if (!address || address === zeroAddress) {
814
- throw new Error("Address is required");
815
- }
816
- return toAccount({
817
- address,
818
- signMessage: async () => {
819
- throw new Error("Account is view-only");
820
- },
821
- signTransaction: async () => {
822
- throw new Error("Account is view-only");
823
- },
824
- signTypedData: async () => {
825
- throw new Error("Account is view-only");
826
- }
827
- });
828
- }
829
- function getSessionSignerAccount(signerAddress) {
830
- if (!signerAddress || signerAddress === zeroAddress) {
831
- throw new Error("Signer address is required");
832
- }
833
- return toAccount({
834
- address: signerAddress,
835
- signMessage: async () => {
836
- throw new Error("Session signer is view-only");
837
- },
838
- signTransaction: async () => {
839
- throw new Error("Session signer is view-only");
840
- },
841
- signTypedData: async () => {
842
- throw new Error("Session signer is view-only");
843
- }
844
- });
845
- }
846
- function buildSession(chain, signerAddress) {
847
- const sessionSignerAccount = getSessionSignerAccount(signerAddress);
848
- return {
849
- owners: {
850
- type: "ecdsa",
851
- accounts: [sessionSignerAccount]
852
- },
853
- chain
854
- };
855
- }
856
- async function createSmartAccount(userSigner, sessionSigner, sdkApiKey) {
857
- const rhinestone = new RhinestoneSDK({
858
- apiKey: sdkApiKey ?? ""
859
- });
860
- const ownerAccounts = sessionSigner ? [userSigner, sessionSigner] : [userSigner];
861
- const config = {
862
- account: {
863
- type: "nexus"
864
- },
865
- owners: {
866
- type: "ecdsa",
867
- accounts: ownerAccounts,
868
- ...sessionSigner ? { threshold: 1 } : {}
869
- },
870
- experimental_sessions: {
871
- enabled: true
872
- }
873
- };
874
- const account = await rhinestone.createAccount(config);
875
- return account;
876
- }
877
- function getAccountAddress(account) {
878
- return account.getAddress();
879
- }
880
- function getAccountInitData(account) {
881
- const { factory, factoryData } = account.getInitData();
882
- if (!factory) {
883
- throw new Error("Account init data is not available");
884
- }
885
- return {
886
- factory,
887
- factoryData
888
- };
889
- }
890
- async function signEnableSessionWithOwner(rhinestoneAccount, sessionDetails, signer) {
891
- const originalOwners = rhinestoneAccount.config.owners;
892
- rhinestoneAccount.config.owners = {
893
- type: "ecdsa",
894
- accounts: [signer],
895
- threshold: 1,
896
- ...originalOwners?.type === "ecdsa" && originalOwners.module ? { module: originalOwners.module } : {}
897
- };
898
- try {
899
- return await rhinestoneAccount.experimental_signEnableSession(
900
- sessionDetails
901
- );
902
- } finally {
903
- rhinestoneAccount.config.owners = originalOwners;
904
- }
905
- }
906
- async function getSessionDetails(rhinestoneAccount, targetChain, signerAddress, sessionSigner, targetToken, sessionChainIds) {
907
- const isTargetTestnet = Boolean(targetChain.testnet);
908
- const chainsByNetworkType = SUPPORTED_CHAINS.filter(
909
- (chain) => Boolean(chain.testnet) === isTargetTestnet
910
- );
911
- const chainsById = new Map(
912
- chainsByNetworkType.map((chain) => [chain.id, chain])
913
- );
914
- let selectedChains = [...chainsByNetworkType];
915
- if (sessionChainIds && sessionChainIds.length > 0) {
916
- const selectedByCaller = [];
917
- for (const chainId of sessionChainIds) {
918
- const chain = chainsById.get(chainId);
919
- if (chain) {
920
- selectedByCaller.push(chain);
921
- }
922
- }
923
- if (selectedByCaller.length > 0) {
924
- selectedChains = selectedByCaller;
925
- }
926
- }
927
- if (targetToken) {
928
- const targetSymbol = getTokenSymbol(
929
- targetToken,
930
- targetChain.id
931
- ).toUpperCase();
932
- if (targetSymbol && targetSymbol !== "TOKEN") {
933
- const chainsForToken = selectedChains.filter(
934
- (chain) => getSupportedTokenSymbolsForChain(chain.id).includes(targetSymbol)
935
- );
936
- if (chainsForToken.length > 0) {
937
- selectedChains = chainsForToken;
938
- }
939
- }
940
- }
941
- if (!selectedChains.some((c) => c.id === targetChain.id)) {
942
- selectedChains.push(targetChain);
943
- }
944
- const uniqueChains = Array.from(
945
- new Map(selectedChains.map((chain) => [chain.id, chain])).values()
946
- );
947
- const sessions = uniqueChains.map(
948
- (chain) => buildSession(chain, signerAddress)
949
- );
950
- const sessionDetails = await rhinestoneAccount.experimental_getSessionDetails(sessions);
951
- const enableSignature = sessionSigner ? await signEnableSessionWithOwner(
952
- rhinestoneAccount,
953
- sessionDetails,
954
- sessionSigner
955
- ) : await rhinestoneAccount.experimental_signEnableSession(sessionDetails);
956
- if (!sessionDetails.hashesAndChainIds?.length) {
957
- throw new Error("Session details missing chain digests");
958
- }
959
- return {
960
- hashesAndChainIds: sessionDetails.hashesAndChainIds,
961
- signature: enableSignature
962
- };
963
- }
964
-
965
893
  // src/core/session-owner.ts
966
894
  import { isAddress } from "viem";
967
895
  import {
@@ -1657,20 +1585,16 @@ export {
1657
1585
  Spinner,
1658
1586
  Button,
1659
1587
  ConnectStep,
1660
- createViewOnlyAccount,
1661
- createSmartAccount,
1662
- getAccountAddress,
1663
- getAccountInitData,
1664
- getSessionDetails,
1588
+ buildSessionDetails,
1589
+ createDepositService,
1590
+ getAssetId,
1591
+ portfolioToAssets,
1592
+ isNativeAsset,
1665
1593
  loadSessionOwnerFromStorage,
1666
1594
  saveSessionOwnerToStorage,
1667
1595
  createSessionOwnerKey,
1668
1596
  accountFromPrivateKey,
1669
1597
  PoweredBy,
1670
- createDepositService,
1671
- getAssetId,
1672
- portfolioToAssets,
1673
- isNativeAsset,
1674
1598
  currencyFormatter,
1675
1599
  tokenFormatter,
1676
1600
  formatUserError,
package/dist/deposit.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkVBNFP3JFcjs = require('./chunk-VBNFP3JF.cjs');
4
- require('./chunk-CZWAKYDR.cjs');
3
+ var _chunk7MQU2SR7cjs = require('./chunk-7MQU2SR7.cjs');
4
+ require('./chunk-QWYZJL3L.cjs');
5
5
  require('./chunk-CEIWN53N.cjs');
6
6
 
7
7
 
8
- exports.DepositModal = _chunkVBNFP3JFcjs.DepositModal;
8
+ exports.DepositModal = _chunk7MQU2SR7cjs.DepositModal;
package/dist/deposit.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DepositModal
3
- } from "./chunk-JAR372KJ.mjs";
4
- import "./chunk-GAFLOODV.mjs";
3
+ } from "./chunk-AJALMXW4.mjs";
4
+ import "./chunk-YOFGP4FV.mjs";
5
5
  import "./chunk-A6QLADED.mjs";
6
6
  export {
7
7
  DepositModal
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkVBNFP3JFcjs = require('./chunk-VBNFP3JF.cjs');
3
+ var _chunk7MQU2SR7cjs = require('./chunk-7MQU2SR7.cjs');
4
4
 
5
5
 
6
- var _chunk4QDHXCPGcjs = require('./chunk-4QDHXCPG.cjs');
7
- require('./chunk-CZWAKYDR.cjs');
6
+ var _chunkXIS33BZ6cjs = require('./chunk-XIS33BZ6.cjs');
7
+ require('./chunk-QWYZJL3L.cjs');
8
8
 
9
9
 
10
10
 
@@ -64,4 +64,4 @@ var _chunkCEIWN53Ncjs = require('./chunk-CEIWN53N.cjs');
64
64
 
65
65
 
66
66
 
67
- exports.CHAIN_BY_ID = _chunkCEIWN53Ncjs.CHAIN_BY_ID; exports.DEFAULT_BACKEND_URL = _chunkCEIWN53Ncjs.DEFAULT_BACKEND_URL; exports.DEFAULT_SIGNER_ADDRESS = _chunkCEIWN53Ncjs.DEFAULT_SIGNER_ADDRESS; exports.DepositModal = _chunkVBNFP3JFcjs.DepositModal; exports.NATIVE_TOKEN_ADDRESS = _chunkCEIWN53Ncjs.NATIVE_TOKEN_ADDRESS; exports.SOURCE_CHAINS = _chunkCEIWN53Ncjs.SOURCE_CHAINS; exports.SUPPORTED_CHAINS = _chunkCEIWN53Ncjs.SUPPORTED_CHAINS; exports.WithdrawModal = _chunk4QDHXCPGcjs.WithdrawModal; exports.chainRegistry = _chunkCEIWN53Ncjs.chainRegistry; exports.findChainIdForToken = _chunkCEIWN53Ncjs.findChainIdForToken; exports.getChainBadge = _chunkCEIWN53Ncjs.getChainBadge; exports.getChainIcon = _chunkCEIWN53Ncjs.getChainIcon; exports.getChainId = _chunkCEIWN53Ncjs.getChainId; exports.getChainName = _chunkCEIWN53Ncjs.getChainName; exports.getChainObject = _chunkCEIWN53Ncjs.getChainObject; exports.getExplorerName = _chunkCEIWN53Ncjs.getExplorerName; exports.getExplorerTxUrl = _chunkCEIWN53Ncjs.getExplorerTxUrl; exports.getExplorerUrl = _chunkCEIWN53Ncjs.getExplorerUrl; exports.getSupportedChainIds = _chunkCEIWN53Ncjs.getSupportedChainIds; exports.getSupportedTargetTokens = _chunkCEIWN53Ncjs.getSupportedTargetTokens; exports.getSupportedTokenSymbolsForChain = _chunkCEIWN53Ncjs.getSupportedTokenSymbolsForChain; exports.getTokenAddress = _chunkCEIWN53Ncjs.getTokenAddress; exports.getTokenDecimals = _chunkCEIWN53Ncjs.getTokenDecimals; exports.getTokenDecimalsByAddress = _chunkCEIWN53Ncjs.getTokenDecimalsByAddress; exports.getTokenIcon = _chunkCEIWN53Ncjs.getTokenIcon; exports.getTokenSymbol = _chunkCEIWN53Ncjs.getTokenSymbol; exports.getUsdcAddress = _chunkCEIWN53Ncjs.getUsdcAddress; exports.getUsdcDecimals = _chunkCEIWN53Ncjs.getUsdcDecimals; exports.isSupportedTokenAddressForChain = _chunkCEIWN53Ncjs.isSupportedTokenAddressForChain;
67
+ exports.CHAIN_BY_ID = _chunkCEIWN53Ncjs.CHAIN_BY_ID; exports.DEFAULT_BACKEND_URL = _chunkCEIWN53Ncjs.DEFAULT_BACKEND_URL; exports.DEFAULT_SIGNER_ADDRESS = _chunkCEIWN53Ncjs.DEFAULT_SIGNER_ADDRESS; exports.DepositModal = _chunk7MQU2SR7cjs.DepositModal; exports.NATIVE_TOKEN_ADDRESS = _chunkCEIWN53Ncjs.NATIVE_TOKEN_ADDRESS; exports.SOURCE_CHAINS = _chunkCEIWN53Ncjs.SOURCE_CHAINS; exports.SUPPORTED_CHAINS = _chunkCEIWN53Ncjs.SUPPORTED_CHAINS; exports.WithdrawModal = _chunkXIS33BZ6cjs.WithdrawModal; exports.chainRegistry = _chunkCEIWN53Ncjs.chainRegistry; exports.findChainIdForToken = _chunkCEIWN53Ncjs.findChainIdForToken; exports.getChainBadge = _chunkCEIWN53Ncjs.getChainBadge; exports.getChainIcon = _chunkCEIWN53Ncjs.getChainIcon; exports.getChainId = _chunkCEIWN53Ncjs.getChainId; exports.getChainName = _chunkCEIWN53Ncjs.getChainName; exports.getChainObject = _chunkCEIWN53Ncjs.getChainObject; exports.getExplorerName = _chunkCEIWN53Ncjs.getExplorerName; exports.getExplorerTxUrl = _chunkCEIWN53Ncjs.getExplorerTxUrl; exports.getExplorerUrl = _chunkCEIWN53Ncjs.getExplorerUrl; exports.getSupportedChainIds = _chunkCEIWN53Ncjs.getSupportedChainIds; exports.getSupportedTargetTokens = _chunkCEIWN53Ncjs.getSupportedTargetTokens; exports.getSupportedTokenSymbolsForChain = _chunkCEIWN53Ncjs.getSupportedTokenSymbolsForChain; exports.getTokenAddress = _chunkCEIWN53Ncjs.getTokenAddress; exports.getTokenDecimals = _chunkCEIWN53Ncjs.getTokenDecimals; exports.getTokenDecimalsByAddress = _chunkCEIWN53Ncjs.getTokenDecimalsByAddress; exports.getTokenIcon = _chunkCEIWN53Ncjs.getTokenIcon; exports.getTokenSymbol = _chunkCEIWN53Ncjs.getTokenSymbol; exports.getUsdcAddress = _chunkCEIWN53Ncjs.getUsdcAddress; exports.getUsdcDecimals = _chunkCEIWN53Ncjs.getUsdcDecimals; exports.isSupportedTokenAddressForChain = _chunkCEIWN53Ncjs.isSupportedTokenAddressForChain;
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  DepositModal
3
- } from "./chunk-JAR372KJ.mjs";
3
+ } from "./chunk-AJALMXW4.mjs";
4
4
  import {
5
5
  WithdrawModal
6
- } from "./chunk-B3HMNWR4.mjs";
7
- import "./chunk-GAFLOODV.mjs";
6
+ } from "./chunk-QCRZCGAE.mjs";
7
+ import "./chunk-YOFGP4FV.mjs";
8
8
  import {
9
9
  CHAIN_BY_ID,
10
10
  DEFAULT_BACKEND_URL,
package/dist/reown.cjs CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkVBNFP3JFcjs = require('./chunk-VBNFP3JF.cjs');
3
+ var _chunk7MQU2SR7cjs = require('./chunk-7MQU2SR7.cjs');
4
4
 
5
5
 
6
- var _chunk4QDHXCPGcjs = require('./chunk-4QDHXCPG.cjs');
7
- require('./chunk-CZWAKYDR.cjs');
6
+ var _chunkXIS33BZ6cjs = require('./chunk-XIS33BZ6.cjs');
7
+ require('./chunk-QWYZJL3L.cjs');
8
8
  require('./chunk-CEIWN53N.cjs');
9
9
 
10
10
 
11
11
 
12
- exports.DepositModal = _chunkVBNFP3JFcjs.DepositModal; exports.WithdrawModal = _chunk4QDHXCPGcjs.WithdrawModal;
12
+ exports.DepositModal = _chunk7MQU2SR7cjs.DepositModal; exports.WithdrawModal = _chunkXIS33BZ6cjs.WithdrawModal;
package/dist/reown.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  DepositModal
3
- } from "./chunk-JAR372KJ.mjs";
3
+ } from "./chunk-AJALMXW4.mjs";
4
4
  import {
5
5
  WithdrawModal
6
- } from "./chunk-B3HMNWR4.mjs";
7
- import "./chunk-GAFLOODV.mjs";
6
+ } from "./chunk-QCRZCGAE.mjs";
7
+ import "./chunk-YOFGP4FV.mjs";
8
8
  import "./chunk-A6QLADED.mjs";
9
9
  export {
10
10
  DepositModal,
package/dist/withdraw.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunk4QDHXCPGcjs = require('./chunk-4QDHXCPG.cjs');
4
- require('./chunk-CZWAKYDR.cjs');
3
+ var _chunkXIS33BZ6cjs = require('./chunk-XIS33BZ6.cjs');
4
+ require('./chunk-QWYZJL3L.cjs');
5
5
  require('./chunk-CEIWN53N.cjs');
6
6
 
7
7
 
8
- exports.WithdrawModal = _chunk4QDHXCPGcjs.WithdrawModal;
8
+ exports.WithdrawModal = _chunkXIS33BZ6cjs.WithdrawModal;
package/dist/withdraw.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  WithdrawModal
3
- } from "./chunk-B3HMNWR4.mjs";
4
- import "./chunk-GAFLOODV.mjs";
3
+ } from "./chunk-QCRZCGAE.mjs";
4
+ import "./chunk-YOFGP4FV.mjs";
5
5
  import "./chunk-A6QLADED.mjs";
6
6
  export {
7
7
  WithdrawModal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinestone/deposit-modal",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "description": "React modal component for Rhinestone cross-chain deposits",
5
5
  "author": "Rhinestone <dev@rhinestone.wtf>",
6
6
  "bugs": {
@@ -65,7 +65,6 @@
65
65
  "viem": ">=2"
66
66
  },
67
67
  "dependencies": {
68
- "@rhinestone/sdk": "^1.2.11",
69
68
  "@rhinestone/shared-configs": "^1.4.93",
70
69
  "@reown/appkit": "^1.8.17",
71
70
  "@reown/appkit-adapter-wagmi": "^1.8.17",