@chipi-stack/chipi-react 14.15.1 → 14.16.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 +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.js +72 -18
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +72 -18
- package/dist/hooks.mjs.map +1 -1
- package/dist/{index-gNLTF6ix.d.mts → index-Dbqp9oNS.d.mts} +59 -9
- package/dist/{index-gNLTF6ix.d.ts → index-Dbqp9oNS.d.ts} +59 -9
- package/dist/index.d.mts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +132 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +132 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/hooks.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { j as ChipiWalletData, a5 as PrivacyConfig, a6 as PrivacyKeys, a9 as PrivacyLedgerEvent, a7 as PrivacyStep, aa as PrivateBalanceInput, R as RegisterSessionConfig, S as SessionState, n as SessionWallet, a8 as ShieldHookInput, $ as ThresholdSignState, l as UseChipiSessionConfig, m as UseChipiSessionReturn, h as UseChipiWalletConfig, U as UseChipiWalletObjectConfig, i as UseChipiWalletReturn, X as UseGuardianRecoveryReturn, V as UseShhhSignerReturn, _ as UseThresholdSignOptions, Z as UseThresholdSignReturn, s as UseTransferConfig, P as UseX402PaymentConfig, Q as UseX402PaymentReturn, a3 as derivePrivacyAccount, a4 as netPrivateBalance, K as useAddSessionKeyToContract, t as useApprove, E as useCallAnyContract, k as useChipiSession, g as useChipiWallet, G as useChipiWalletObject, J as useCreateSessionKey, u as useCreateWallet, N as useExecuteWithSession, M as useGetSessionData, D as useGetSku, B as useGetSkuList, A as useGetSkuPurchase, I as useGetTokenBalance, w as useGetTransaction, v as useGetTransactionList, x as useGetTransactionStatus, f as useGetWallet, W as useGuardianRecovery, o as useMigrateWalletToPasskey, q as useMigrateWalletToShhh, a2 as usePrivateBalance, z as usePurchaseSku, H as useRecordSendTransaction, L as useRevokeSessionKey, T as useShhhSigner, a0 as useShield, F as useSignTypedData, y as useSyncOnChainTransfers, Y as useThresholdSign, r as useTransfer, a1 as useUnshield, p as useUpdateWalletEncryption, O as useX402Payment } from './index-Dbqp9oNS.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 {
|
|
1
|
+
export { j as ChipiWalletData, a5 as PrivacyConfig, a6 as PrivacyKeys, a9 as PrivacyLedgerEvent, a7 as PrivacyStep, aa as PrivateBalanceInput, R as RegisterSessionConfig, S as SessionState, n as SessionWallet, a8 as ShieldHookInput, $ as ThresholdSignState, l as UseChipiSessionConfig, m as UseChipiSessionReturn, h as UseChipiWalletConfig, U as UseChipiWalletObjectConfig, i as UseChipiWalletReturn, X as UseGuardianRecoveryReturn, V as UseShhhSignerReturn, _ as UseThresholdSignOptions, Z as UseThresholdSignReturn, s as UseTransferConfig, P as UseX402PaymentConfig, Q as UseX402PaymentReturn, a3 as derivePrivacyAccount, a4 as netPrivateBalance, K as useAddSessionKeyToContract, t as useApprove, E as useCallAnyContract, k as useChipiSession, g as useChipiWallet, G as useChipiWalletObject, J as useCreateSessionKey, u as useCreateWallet, N as useExecuteWithSession, M as useGetSessionData, D as useGetSku, B as useGetSkuList, A as useGetSkuPurchase, I as useGetTokenBalance, w as useGetTransaction, v as useGetTransactionList, x as useGetTransactionStatus, f as useGetWallet, W as useGuardianRecovery, o as useMigrateWalletToPasskey, q as useMigrateWalletToShhh, a2 as usePrivateBalance, z as usePurchaseSku, H as useRecordSendTransaction, L as useRevokeSessionKey, T as useShhhSigner, a0 as useShield, F as useSignTypedData, y as useSyncOnChainTransfers, Y as useThresholdSign, r as useTransfer, a1 as useUnshield, p as useUpdateWalletEncryption, O as useX402Payment } from './index-Dbqp9oNS.js';
|
|
2
2
|
import '@chipi-stack/types';
|
|
3
3
|
import '@tanstack/react-query';
|
|
4
4
|
import 'react';
|
package/dist/hooks.js
CHANGED
|
@@ -20368,6 +20368,41 @@ function hexEq(a, b) {
|
|
|
20368
20368
|
return a === b;
|
|
20369
20369
|
}
|
|
20370
20370
|
}
|
|
20371
|
+
function parseCapAmount(value, field, token) {
|
|
20372
|
+
try {
|
|
20373
|
+
const v = typeof value === "bigint" ? value : BigInt(String(value).trim());
|
|
20374
|
+
if (v < 0n) throw new Error("negative");
|
|
20375
|
+
return v;
|
|
20376
|
+
} catch {
|
|
20377
|
+
throw new Error(
|
|
20378
|
+
`session_spend_cap_invalid: ${field} for token ${token} must be a non-negative integer in base units (got "${String(value)}")`
|
|
20379
|
+
);
|
|
20380
|
+
}
|
|
20381
|
+
}
|
|
20382
|
+
function toSpendingPolicies(caps, lifetimeSeconds) {
|
|
20383
|
+
return caps.map((cap) => {
|
|
20384
|
+
const policy = "maxPerWindow" in cap ? {
|
|
20385
|
+
token: cap.token,
|
|
20386
|
+
maxPerCall: parseCapAmount(cap.maxPerCall, "maxPerCall", cap.token),
|
|
20387
|
+
maxPerWindow: parseCapAmount(cap.maxPerWindow, "maxPerWindow", cap.token),
|
|
20388
|
+
windowSeconds: cap.windowSeconds
|
|
20389
|
+
} : (() => {
|
|
20390
|
+
const amount = parseCapAmount(cap.amount, "amount", cap.token);
|
|
20391
|
+
return {
|
|
20392
|
+
token: cap.token,
|
|
20393
|
+
maxPerCall: amount,
|
|
20394
|
+
maxPerWindow: amount,
|
|
20395
|
+
windowSeconds: Math.max(1, lifetimeSeconds)
|
|
20396
|
+
};
|
|
20397
|
+
})();
|
|
20398
|
+
if (policy.maxPerWindow === 0n) {
|
|
20399
|
+
throw new Error(
|
|
20400
|
+
`session_spend_cap_zero: the cap for token ${cap.token} resolves to maxPerWindow = 0, which means unlimited on-chain. Use a positive cap.`
|
|
20401
|
+
);
|
|
20402
|
+
}
|
|
20403
|
+
return policy;
|
|
20404
|
+
});
|
|
20405
|
+
}
|
|
20371
20406
|
function sessionCovers(policy, calls) {
|
|
20372
20407
|
if (!policy?.allowedCalls?.length) return false;
|
|
20373
20408
|
return calls.every(
|
|
@@ -20382,6 +20417,10 @@ function useChipiWalletObject(config3) {
|
|
|
20382
20417
|
const { signTypedDataAsync } = useSignTypedData();
|
|
20383
20418
|
const { createSessionKeyAsync } = useCreateSessionKey();
|
|
20384
20419
|
const { addSessionKeyToContractAsync } = useAddSessionKeyToContract();
|
|
20420
|
+
const { chipiSDK } = useChipiContext();
|
|
20421
|
+
const sdk = react.useRef(chipiSDK);
|
|
20422
|
+
sdk.current = chipiSDK;
|
|
20423
|
+
const warnedMissingApproval = react.useRef(false);
|
|
20385
20424
|
const cfg = react.useRef(config3);
|
|
20386
20425
|
cfg.current = config3;
|
|
20387
20426
|
const requireWallet = () => {
|
|
@@ -20394,28 +20433,33 @@ function useChipiWalletObject(config3) {
|
|
|
20394
20433
|
if (policy.validUntil <= nowSec()) throw new Error("session_policy_expired");
|
|
20395
20434
|
const c = cfg.current;
|
|
20396
20435
|
const wallet = requireWallet();
|
|
20436
|
+
const lifetimeSeconds = Math.max(1, policy.validUntil - nowSec());
|
|
20437
|
+
const spendingPolicies = policy.spendCaps?.length ? toSpendingPolicies(policy.spendCaps, lifetimeSeconds) : [];
|
|
20397
20438
|
const encryptKey = await c.getEncryptKey();
|
|
20398
20439
|
const session = await createSessionKeyAsync({
|
|
20399
20440
|
encryptKey,
|
|
20400
|
-
durationSeconds:
|
|
20441
|
+
durationSeconds: lifetimeSeconds
|
|
20401
20442
|
});
|
|
20402
20443
|
const bearerToken = await c.getBearerToken();
|
|
20403
|
-
|
|
20404
|
-
|
|
20405
|
-
|
|
20406
|
-
|
|
20407
|
-
|
|
20408
|
-
|
|
20409
|
-
|
|
20410
|
-
|
|
20411
|
-
|
|
20412
|
-
|
|
20413
|
-
|
|
20414
|
-
|
|
20415
|
-
|
|
20416
|
-
|
|
20417
|
-
|
|
20418
|
-
|
|
20444
|
+
const params = {
|
|
20445
|
+
encryptKey,
|
|
20446
|
+
wallet,
|
|
20447
|
+
sessionConfig: {
|
|
20448
|
+
sessionPublicKey: session.publicKey,
|
|
20449
|
+
validUntil: policy.validUntil,
|
|
20450
|
+
maxCalls: 1e3,
|
|
20451
|
+
// Selectors; empty = all entrypoints allowed. On-chain this is a
|
|
20452
|
+
// per-selector whitelist, NOT scoped to allowedCalls' contracts.
|
|
20453
|
+
allowedEntrypoints: policy.allowedCalls.map(
|
|
20454
|
+
(a) => hash_exports.getSelectorFromName(a.entrypoint)
|
|
20455
|
+
)
|
|
20456
|
+
}
|
|
20457
|
+
};
|
|
20458
|
+
if (spendingPolicies.length > 0) {
|
|
20459
|
+
await sdk.current.sessions.setupSession({ ...params, spendingPolicies }, bearerToken);
|
|
20460
|
+
} else {
|
|
20461
|
+
await addSessionKeyToContractAsync({ params, bearerToken });
|
|
20462
|
+
}
|
|
20419
20463
|
return session;
|
|
20420
20464
|
},
|
|
20421
20465
|
[createSessionKeyAsync, addSessionKeyToContractAsync]
|
|
@@ -20460,7 +20504,17 @@ function useChipiWalletObject(config3) {
|
|
|
20460
20504
|
createSession: async (policy) => {
|
|
20461
20505
|
await createSession(policy);
|
|
20462
20506
|
},
|
|
20463
|
-
requestApproval: (req) =>
|
|
20507
|
+
requestApproval: (req) => {
|
|
20508
|
+
const gate = cfg.current.requestApproval;
|
|
20509
|
+
if (gate) return gate(req);
|
|
20510
|
+
if (!warnedMissingApproval.current) {
|
|
20511
|
+
warnedMissingApproval.current = true;
|
|
20512
|
+
console.warn(
|
|
20513
|
+
"[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."
|
|
20514
|
+
);
|
|
20515
|
+
}
|
|
20516
|
+
return Promise.resolve(false);
|
|
20517
|
+
}
|
|
20464
20518
|
}),
|
|
20465
20519
|
[callAnyContractAsync, executeWithSessionAsync, signTypedDataAsync, createSession]
|
|
20466
20520
|
);
|