@chipi-stack/backend 14.13.0 → 14.13.1
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.js +51 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -14
- package/dist/index.mjs.map +1 -1
- package/dist/skuPurchases.js +2 -2
- package/dist/skuPurchases.js.map +1 -1
- package/dist/skuPurchases.mjs +2 -2
- package/dist/skuPurchases.mjs.map +1 -1
- package/dist/transactions.js +2 -2
- package/dist/transactions.js.map +1 -1
- package/dist/transactions.mjs +2 -2
- package/dist/transactions.mjs.map +1 -1
- package/dist/wallets.js +2 -2
- package/dist/wallets.js.map +1 -1
- package/dist/wallets.mjs +2 -2
- package/dist/wallets.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -84,7 +84,7 @@ function hashCall(call) {
|
|
|
84
84
|
return poseidonSpan([
|
|
85
85
|
CALL_TYPE_HASH_REV1,
|
|
86
86
|
toBigInt(call.contractAddress),
|
|
87
|
-
toBigInt(hash.
|
|
87
|
+
toBigInt(hash.getSelector(call.entrypoint)),
|
|
88
88
|
calldataHash
|
|
89
89
|
]);
|
|
90
90
|
}
|
|
@@ -567,7 +567,7 @@ function serializeExecuteFromOutsideV2Calldata(params) {
|
|
|
567
567
|
out.push(BigInt(oe.calls.length));
|
|
568
568
|
for (const call of oe.calls) {
|
|
569
569
|
out.push(BigInt(call.contractAddress));
|
|
570
|
-
out.push(BigInt(hash.
|
|
570
|
+
out.push(BigInt(hash.getSelector(call.entrypoint)));
|
|
571
571
|
const callData = Array.isArray(call.calldata) ? call.calldata : [];
|
|
572
572
|
out.push(BigInt(callData.length));
|
|
573
573
|
for (const datum of callData) {
|
|
@@ -1947,9 +1947,9 @@ var ChipiTransactions = class {
|
|
|
1947
1947
|
/**
|
|
1948
1948
|
* Get on-chain transaction status
|
|
1949
1949
|
*/
|
|
1950
|
-
async getTransactionStatus(
|
|
1950
|
+
async getTransactionStatus(hash10, bearerToken) {
|
|
1951
1951
|
return this.client.get({
|
|
1952
|
-
endpoint: `${API_ENDPOINTS.TRANSACTIONS}/${
|
|
1952
|
+
endpoint: `${API_ENDPOINTS.TRANSACTIONS}/${hash10}/status`,
|
|
1953
1953
|
bearerToken
|
|
1954
1954
|
});
|
|
1955
1955
|
}
|
|
@@ -2119,6 +2119,42 @@ var ChipiSkus = class {
|
|
|
2119
2119
|
|
|
2120
2120
|
// src/sessions.ts
|
|
2121
2121
|
init_encryption2();
|
|
2122
|
+
var FIELD_PRIME = 2n ** 251n + 17n * 2n ** 192n + 1n;
|
|
2123
|
+
var HEX_FELT = /^0x[0-9a-fA-F]{1,64}$/;
|
|
2124
|
+
var DECIMAL_FELT = /^\d+$/;
|
|
2125
|
+
var CAIRO_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
2126
|
+
function normalizeEntrypoints(entrypoints) {
|
|
2127
|
+
return entrypoints.map((entry) => {
|
|
2128
|
+
const value = String(entry).trim();
|
|
2129
|
+
if (HEX_FELT.test(value) || DECIMAL_FELT.test(value)) {
|
|
2130
|
+
const felt = BigInt(value);
|
|
2131
|
+
if (felt >= FIELD_PRIME) {
|
|
2132
|
+
throw new ChipiSessionError(
|
|
2133
|
+
`Session entrypoint ${value} is not a valid felt (>= field prime).`,
|
|
2134
|
+
SESSION_ERRORS.SESSION_ENTRYPOINT_NOT_ALLOWED
|
|
2135
|
+
);
|
|
2136
|
+
}
|
|
2137
|
+
return num.toHex(felt);
|
|
2138
|
+
}
|
|
2139
|
+
if (CAIRO_IDENTIFIER.test(value)) {
|
|
2140
|
+
return hash.getSelectorFromName(value);
|
|
2141
|
+
}
|
|
2142
|
+
throw new ChipiSessionError(
|
|
2143
|
+
`Session entrypoint "${value}" is neither a selector (0x\u2026) nor a function name.`,
|
|
2144
|
+
SESSION_ERRORS.SESSION_ENTRYPOINT_NOT_ALLOWED
|
|
2145
|
+
);
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
function decodeSessionData(result, nowSeconds) {
|
|
2149
|
+
const validUntil = Number(BigInt(result[0]));
|
|
2150
|
+
const maxCalls = Number(BigInt(result[1]));
|
|
2151
|
+
const callsUsed = Number(BigInt(result[2]));
|
|
2152
|
+
const remainingCalls = Math.max(maxCalls - callsUsed, 0);
|
|
2153
|
+
const isActive = validUntil !== 0 && nowSeconds <= validUntil && remainingCalls > 0;
|
|
2154
|
+
return { isActive, validUntil, remainingCalls, allowedEntrypoints: [] };
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
// src/sessions.ts
|
|
2122
2158
|
var ChipiSessions = class {
|
|
2123
2159
|
constructor(client) {
|
|
2124
2160
|
this.client = client;
|
|
@@ -2258,13 +2294,14 @@ var ChipiSessions = class {
|
|
|
2258
2294
|
maxCalls: sessionConfig.maxCalls,
|
|
2259
2295
|
allowedEntrypoints: sessionConfig.allowedEntrypoints.length
|
|
2260
2296
|
});
|
|
2297
|
+
const allowedEntrypoints = normalizeEntrypoints(sessionConfig.allowedEntrypoints);
|
|
2261
2298
|
const calldata = [
|
|
2262
2299
|
sessionConfig.sessionPublicKey,
|
|
2263
2300
|
num.toHex(sessionConfig.validUntil),
|
|
2264
2301
|
num.toHex(sessionConfig.maxCalls),
|
|
2265
2302
|
// Array: first element is length, then elements
|
|
2266
|
-
num.toHex(
|
|
2267
|
-
...
|
|
2303
|
+
num.toHex(allowedEntrypoints.length),
|
|
2304
|
+
...allowedEntrypoints
|
|
2268
2305
|
];
|
|
2269
2306
|
const txHash = await executePaymasterTransaction({
|
|
2270
2307
|
params: {
|
|
@@ -2414,11 +2451,10 @@ var ChipiSessions = class {
|
|
|
2414
2451
|
allowedEntrypoints: []
|
|
2415
2452
|
};
|
|
2416
2453
|
}
|
|
2417
|
-
const isActive
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
const allowedEntrypoints = resultArray.slice(4, 4 + entrypointsLen);
|
|
2454
|
+
const { isActive, validUntil, remainingCalls, allowedEntrypoints } = decodeSessionData(
|
|
2455
|
+
resultArray,
|
|
2456
|
+
Math.floor(Date.now() / 1e3)
|
|
2457
|
+
);
|
|
2422
2458
|
const sessionData = {
|
|
2423
2459
|
isActive,
|
|
2424
2460
|
validUntil,
|
|
@@ -2429,7 +2465,8 @@ var ChipiSessions = class {
|
|
|
2429
2465
|
isActive,
|
|
2430
2466
|
validUntil: new Date(validUntil * 1e3).toISOString(),
|
|
2431
2467
|
remainingCalls,
|
|
2432
|
-
|
|
2468
|
+
// The struct carries the whitelist length, not the selectors.
|
|
2469
|
+
allowedEntrypointsLen: Number(BigInt(resultArray[3]))
|
|
2433
2470
|
});
|
|
2434
2471
|
return sessionData;
|
|
2435
2472
|
} catch (error) {
|
|
@@ -3581,8 +3618,8 @@ var ChipiSDK = class {
|
|
|
3581
3618
|
/**
|
|
3582
3619
|
* Get on-chain transaction status (supports polling for confirmation)
|
|
3583
3620
|
*/
|
|
3584
|
-
async getTransactionStatus(
|
|
3585
|
-
return this.transactions.getTransactionStatus(
|
|
3621
|
+
async getTransactionStatus(hash10, bearerToken) {
|
|
3622
|
+
return this.transactions.getTransactionStatus(hash10, this.resolveBearerToken(bearerToken));
|
|
3586
3623
|
}
|
|
3587
3624
|
/**
|
|
3588
3625
|
* Prepare a wallet upgrade (e.g., READY → CHIPI or CHIPI v29 → v33).
|