@chipi-stack/chipi-react 14.15.1 → 14.17.0

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/hooks.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { g as ChipiWalletData, a2 as PrivacyConfig, a3 as PrivacyKeys, a6 as PrivacyLedgerEvent, a4 as PrivacyStep, a7 as PrivateBalanceInput, R as RegisterSessionConfig, S as SessionState, k as SessionWallet, a5 as ShieldHookInput, Y as ThresholdSignState, i as UseChipiSessionConfig, j as UseChipiSessionReturn, e as UseChipiWalletConfig, U as UseChipiWalletObjectConfig, f as UseChipiWalletReturn, T as UseGuardianRecoveryReturn, P as UseShhhSignerReturn, X as UseThresholdSignOptions, W as UseThresholdSignReturn, p as UseTransferConfig, M as UseX402PaymentConfig, N as UseX402PaymentReturn, a0 as derivePrivacyAccount, a1 as netPrivateBalance, H as useAddSessionKeyToContract, q as useApprove, A as useCallAnyContract, h as useChipiSession, d as useChipiWallet, D as useChipiWalletObject, G as useCreateSessionKey, u as useCreateWallet, K as useExecuteWithSession, J as useGetSessionData, z as useGetSku, y as useGetSkuList, x as useGetSkuPurchase, F as useGetTokenBalance, s as useGetTransaction, r as useGetTransactionList, t as useGetTransactionStatus, c as useGetWallet, Q as useGuardianRecovery, l as useMigrateWalletToPasskey, n as useMigrateWalletToShhh, $ as usePrivateBalance, w as usePurchaseSku, E as useRecordSendTransaction, I as useRevokeSessionKey, O as useShhhSigner, Z as useShield, B as useSignTypedData, v as useSyncOnChainTransfers, V as useThresholdSign, o as useTransfer, _ as useUnshield, m as useUpdateWalletEncryption, L as useX402Payment } from './index-gNLTF6ix.mjs';
1
+ export { j as ChipiWalletData, H as ExternalSignerExecuteInput, a7 as PrivacyConfig, a8 as PrivacyKeys, ab as PrivacyLedgerEvent, a9 as PrivacyStep, ac as PrivateBalanceInput, R as RegisterSessionConfig, S as SessionState, n as SessionWallet, aa as ShieldHookInput, a1 as ThresholdSignState, l as UseChipiSessionConfig, m as UseChipiSessionReturn, h as UseChipiWalletConfig, U as UseChipiWalletObjectConfig, i as UseChipiWalletReturn, Z as UseGuardianRecoveryReturn, X as UseShhhSignerReturn, a0 as UseThresholdSignOptions, $ as UseThresholdSignReturn, s as UseTransferConfig, T as UseX402PaymentConfig, V as UseX402PaymentReturn, a5 as derivePrivacyAccount, a6 as netPrivateBalance, M as useAddSessionKeyToContract, t as useApprove, E as useCallAnyContract, k as useChipiSession, g as useChipiWallet, I as useChipiWalletObject, L as useCreateSessionKey, u as useCreateWallet, P as useExecuteWithSession, G as useExternalSignerExecute, O as useGetSessionData, D as useGetSku, B as useGetSkuList, A as useGetSkuPurchase, K as useGetTokenBalance, w as useGetTransaction, v as useGetTransactionList, x as useGetTransactionStatus, f as useGetWallet, Y as useGuardianRecovery, o as useMigrateWalletToPasskey, q as useMigrateWalletToShhh, a4 as usePrivateBalance, z as usePurchaseSku, J as useRecordSendTransaction, N as useRevokeSessionKey, W as useShhhSigner, a2 as useShield, F as useSignTypedData, y as useSyncOnChainTransfers, _ as useThresholdSign, r as useTransfer, a3 as useUnshield, p as useUpdateWalletEncryption, Q as useX402Payment } from './index-CUfzUBgv.mjs';
2
2
  import '@chipi-stack/types';
3
3
  import '@tanstack/react-query';
4
4
  import 'react';
package/dist/hooks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { g as ChipiWalletData, a2 as PrivacyConfig, a3 as PrivacyKeys, a6 as PrivacyLedgerEvent, a4 as PrivacyStep, a7 as PrivateBalanceInput, R as RegisterSessionConfig, S as SessionState, k as SessionWallet, a5 as ShieldHookInput, Y as ThresholdSignState, i as UseChipiSessionConfig, j as UseChipiSessionReturn, e as UseChipiWalletConfig, U as UseChipiWalletObjectConfig, f as UseChipiWalletReturn, T as UseGuardianRecoveryReturn, P as UseShhhSignerReturn, X as UseThresholdSignOptions, W as UseThresholdSignReturn, p as UseTransferConfig, M as UseX402PaymentConfig, N as UseX402PaymentReturn, a0 as derivePrivacyAccount, a1 as netPrivateBalance, H as useAddSessionKeyToContract, q as useApprove, A as useCallAnyContract, h as useChipiSession, d as useChipiWallet, D as useChipiWalletObject, G as useCreateSessionKey, u as useCreateWallet, K as useExecuteWithSession, J as useGetSessionData, z as useGetSku, y as useGetSkuList, x as useGetSkuPurchase, F as useGetTokenBalance, s as useGetTransaction, r as useGetTransactionList, t as useGetTransactionStatus, c as useGetWallet, Q as useGuardianRecovery, l as useMigrateWalletToPasskey, n as useMigrateWalletToShhh, $ as usePrivateBalance, w as usePurchaseSku, E as useRecordSendTransaction, I as useRevokeSessionKey, O as useShhhSigner, Z as useShield, B as useSignTypedData, v as useSyncOnChainTransfers, V as useThresholdSign, o as useTransfer, _ as useUnshield, m as useUpdateWalletEncryption, L as useX402Payment } from './index-gNLTF6ix.js';
1
+ export { j as ChipiWalletData, H as ExternalSignerExecuteInput, a7 as PrivacyConfig, a8 as PrivacyKeys, ab as PrivacyLedgerEvent, a9 as PrivacyStep, ac as PrivateBalanceInput, R as RegisterSessionConfig, S as SessionState, n as SessionWallet, aa as ShieldHookInput, a1 as ThresholdSignState, l as UseChipiSessionConfig, m as UseChipiSessionReturn, h as UseChipiWalletConfig, U as UseChipiWalletObjectConfig, i as UseChipiWalletReturn, Z as UseGuardianRecoveryReturn, X as UseShhhSignerReturn, a0 as UseThresholdSignOptions, $ as UseThresholdSignReturn, s as UseTransferConfig, T as UseX402PaymentConfig, V as UseX402PaymentReturn, a5 as derivePrivacyAccount, a6 as netPrivateBalance, M as useAddSessionKeyToContract, t as useApprove, E as useCallAnyContract, k as useChipiSession, g as useChipiWallet, I as useChipiWalletObject, L as useCreateSessionKey, u as useCreateWallet, P as useExecuteWithSession, G as useExternalSignerExecute, O as useGetSessionData, D as useGetSku, B as useGetSkuList, A as useGetSkuPurchase, K as useGetTokenBalance, w as useGetTransaction, v as useGetTransactionList, x as useGetTransactionStatus, f as useGetWallet, Y as useGuardianRecovery, o as useMigrateWalletToPasskey, q as useMigrateWalletToShhh, a4 as usePrivateBalance, z as usePurchaseSku, J as useRecordSendTransaction, N as useRevokeSessionKey, W as useShhhSigner, a2 as useShield, F as useSignTypedData, y as useSyncOnChainTransfers, _ as useThresholdSign, r as useTransfer, a3 as useUnshield, p as useUpdateWalletEncryption, Q as useX402Payment } from './index-CUfzUBgv.js';
2
2
  import '@chipi-stack/types';
3
3
  import '@tanstack/react-query';
4
4
  import 'react';
package/dist/hooks.js CHANGED
@@ -1290,6 +1290,22 @@ function useSignTypedData() {
1290
1290
  reset: mutation.reset
1291
1291
  };
1292
1292
  }
1293
+ function useExternalSignerExecute() {
1294
+ const { chipiSDK } = useChipiContext();
1295
+ const mutation = reactQuery.useMutation({
1296
+ mutationFn: async (input) => chipiSDK.executeWithExternalSigner(input)
1297
+ });
1298
+ return {
1299
+ execute: mutation.mutate,
1300
+ executeAsync: mutation.mutateAsync,
1301
+ data: mutation.data,
1302
+ isLoading: mutation.isPending,
1303
+ isError: mutation.isError,
1304
+ error: mutation.error,
1305
+ isSuccess: mutation.isSuccess,
1306
+ reset: mutation.reset
1307
+ };
1308
+ }
1293
1309
 
1294
1310
  // ../node_modules/.pnpm/@starknet-io+types-js@0.9.2/node_modules/@starknet-io/types-js/dist/esm/index.js
1295
1311
  var esm_exports = {};
@@ -20368,6 +20384,41 @@ function hexEq(a, b) {
20368
20384
  return a === b;
20369
20385
  }
20370
20386
  }
20387
+ function parseCapAmount(value, field, token) {
20388
+ try {
20389
+ const v = typeof value === "bigint" ? value : BigInt(String(value).trim());
20390
+ if (v < 0n) throw new Error("negative");
20391
+ return v;
20392
+ } catch {
20393
+ throw new Error(
20394
+ `session_spend_cap_invalid: ${field} for token ${token} must be a non-negative integer in base units (got "${String(value)}")`
20395
+ );
20396
+ }
20397
+ }
20398
+ function toSpendingPolicies(caps, lifetimeSeconds) {
20399
+ return caps.map((cap) => {
20400
+ const policy = "maxPerWindow" in cap ? {
20401
+ token: cap.token,
20402
+ maxPerCall: parseCapAmount(cap.maxPerCall, "maxPerCall", cap.token),
20403
+ maxPerWindow: parseCapAmount(cap.maxPerWindow, "maxPerWindow", cap.token),
20404
+ windowSeconds: cap.windowSeconds
20405
+ } : (() => {
20406
+ const amount = parseCapAmount(cap.amount, "amount", cap.token);
20407
+ return {
20408
+ token: cap.token,
20409
+ maxPerCall: amount,
20410
+ maxPerWindow: amount,
20411
+ windowSeconds: Math.max(1, lifetimeSeconds)
20412
+ };
20413
+ })();
20414
+ if (policy.maxPerWindow === 0n) {
20415
+ throw new Error(
20416
+ `session_spend_cap_zero: the cap for token ${cap.token} resolves to maxPerWindow = 0, which means unlimited on-chain. Use a positive cap.`
20417
+ );
20418
+ }
20419
+ return policy;
20420
+ });
20421
+ }
20371
20422
  function sessionCovers(policy, calls) {
20372
20423
  if (!policy?.allowedCalls?.length) return false;
20373
20424
  return calls.every(
@@ -20382,6 +20433,10 @@ function useChipiWalletObject(config3) {
20382
20433
  const { signTypedDataAsync } = useSignTypedData();
20383
20434
  const { createSessionKeyAsync } = useCreateSessionKey();
20384
20435
  const { addSessionKeyToContractAsync } = useAddSessionKeyToContract();
20436
+ const { chipiSDK } = useChipiContext();
20437
+ const sdk = react.useRef(chipiSDK);
20438
+ sdk.current = chipiSDK;
20439
+ const warnedMissingApproval = react.useRef(false);
20385
20440
  const cfg = react.useRef(config3);
20386
20441
  cfg.current = config3;
20387
20442
  const requireWallet = () => {
@@ -20394,28 +20449,33 @@ function useChipiWalletObject(config3) {
20394
20449
  if (policy.validUntil <= nowSec()) throw new Error("session_policy_expired");
20395
20450
  const c = cfg.current;
20396
20451
  const wallet = requireWallet();
20452
+ const lifetimeSeconds = Math.max(1, policy.validUntil - nowSec());
20453
+ const spendingPolicies = policy.spendCaps?.length ? toSpendingPolicies(policy.spendCaps, lifetimeSeconds) : [];
20397
20454
  const encryptKey = await c.getEncryptKey();
20398
20455
  const session = await createSessionKeyAsync({
20399
20456
  encryptKey,
20400
- durationSeconds: Math.max(1, policy.validUntil - nowSec())
20457
+ durationSeconds: lifetimeSeconds
20401
20458
  });
20402
20459
  const bearerToken = await c.getBearerToken();
20403
- await addSessionKeyToContractAsync({
20404
- params: {
20405
- encryptKey,
20406
- wallet,
20407
- sessionConfig: {
20408
- sessionPublicKey: session.publicKey,
20409
- validUntil: policy.validUntil,
20410
- maxCalls: 1e3,
20411
- // selectors; empty = all entrypoints allowed
20412
- allowedEntrypoints: policy.allowedCalls.map(
20413
- (a) => hash_exports.getSelectorFromName(a.entrypoint)
20414
- )
20415
- }
20416
- },
20417
- bearerToken
20418
- });
20460
+ const params = {
20461
+ encryptKey,
20462
+ wallet,
20463
+ sessionConfig: {
20464
+ sessionPublicKey: session.publicKey,
20465
+ validUntil: policy.validUntil,
20466
+ maxCalls: 1e3,
20467
+ // Selectors; empty = all entrypoints allowed. On-chain this is a
20468
+ // per-selector whitelist, NOT scoped to allowedCalls' contracts.
20469
+ allowedEntrypoints: policy.allowedCalls.map(
20470
+ (a) => hash_exports.getSelectorFromName(a.entrypoint)
20471
+ )
20472
+ }
20473
+ };
20474
+ if (spendingPolicies.length > 0) {
20475
+ await sdk.current.sessions.setupSession({ ...params, spendingPolicies }, bearerToken);
20476
+ } else {
20477
+ await addSessionKeyToContractAsync({ params, bearerToken });
20478
+ }
20419
20479
  return session;
20420
20480
  },
20421
20481
  [createSessionKeyAsync, addSessionKeyToContractAsync]
@@ -20455,12 +20515,23 @@ function useChipiWalletObject(config3) {
20455
20515
  return signTypedDataAsync({ encryptKey, wallet, typedData });
20456
20516
  },
20457
20517
  getDeploymentData: async () => {
20458
- throw new Error("account_already_deployed");
20518
+ if (cfg.current.isDeployed === true) throw new Error("account_already_deployed");
20519
+ throw new Error("account_deployment_data_unavailable");
20459
20520
  },
20460
20521
  createSession: async (policy) => {
20461
20522
  await createSession(policy);
20462
20523
  },
20463
- requestApproval: (req) => cfg.current.requestApproval?.(req) ?? Promise.resolve(true)
20524
+ requestApproval: (req) => {
20525
+ const gate = cfg.current.requestApproval;
20526
+ if (gate) return gate(req);
20527
+ if (!warnedMissingApproval.current) {
20528
+ warnedMissingApproval.current = true;
20529
+ console.warn(
20530
+ "[ChipiSDK:Connect] No `requestApproval` was provided to useChipiWalletObject, so every approval (connect, execute, signTypedData, session) is denied. Pass `requestApproval` to show the user an approval UI and resolve true/false."
20531
+ );
20532
+ }
20533
+ return Promise.resolve(false);
20534
+ }
20464
20535
  }),
20465
20536
  [callAnyContractAsync, executeWithSessionAsync, signTypedDataAsync, createSession]
20466
20537
  );
@@ -21152,6 +21223,7 @@ exports.useChipiWalletObject = useChipiWalletObject;
21152
21223
  exports.useCreateSessionKey = useCreateSessionKey;
21153
21224
  exports.useCreateWallet = useCreateWallet;
21154
21225
  exports.useExecuteWithSession = useExecuteWithSession;
21226
+ exports.useExternalSignerExecute = useExternalSignerExecute;
21155
21227
  exports.useGetSessionData = useGetSessionData;
21156
21228
  exports.useGetSku = useGetSku;
21157
21229
  exports.useGetSkuList = useGetSkuList;