@chipi-stack/backend 13.1.0 → 13.3.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/index.d.mts +1 -42
- package/dist/index.d.ts +1 -42
- package/dist/index.js +25 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -106
- package/dist/index.mjs.map +1 -1
- package/dist/skuPurchases.js +25 -1
- package/dist/skuPurchases.js.map +1 -1
- package/dist/skuPurchases.mjs +25 -1
- package/dist/skuPurchases.mjs.map +1 -1
- package/dist/transactions.js +25 -1
- package/dist/transactions.js.map +1 -1
- package/dist/transactions.mjs +25 -1
- package/dist/transactions.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isValidApiKey, ChipiAuthError, STARKNET_NETWORKS, API_VERSIONING, validateErrorResponse, ChipiApiError, handleApiError, WALLET_RPC_ENDPOINTS, WALLET_CLASS_HASHES, API_ENDPOINTS, ChipiTransactionError, formatAmount, SKU_CONTRACTS, CARRIER_IDS, SERVICE_TYPES, ChipiSessionError, SESSION_ERRORS, SESSION_DEFAULTS, SESSION_ENTRYPOINTS
|
|
1
|
+
import { isValidApiKey, ChipiAuthError, STARKNET_NETWORKS, API_VERSIONING, validateErrorResponse, ChipiApiError, handleApiError, WALLET_RPC_ENDPOINTS, WALLET_CLASS_HASHES, API_ENDPOINTS, ChipiTransactionError, formatAmount, SKU_CONTRACTS, CARRIER_IDS, SERVICE_TYPES, ChipiSessionError, SESSION_ERRORS, SESSION_DEFAULTS, SESSION_ENTRYPOINTS } from '@chipi-stack/shared';
|
|
2
2
|
import CryptoES from 'crypto-es';
|
|
3
3
|
import { RpcProvider, ec, hash, Account, num, CairoCustomEnum, CairoOption, CairoOptionVariant, CallData, cairo, typedData } from 'starknet';
|
|
4
4
|
import { STARKNET_CONTRACTS } from '@chipi-stack/types';
|
|
@@ -372,7 +372,7 @@ var executePaymasterTransaction = async ({
|
|
|
372
372
|
wallet.publicKey,
|
|
373
373
|
privateKeyDecrypted
|
|
374
374
|
);
|
|
375
|
-
const
|
|
375
|
+
const prepareResponse = await client.post({
|
|
376
376
|
endpoint: "/transactions/prepare-typed-data",
|
|
377
377
|
bearerToken,
|
|
378
378
|
body: {
|
|
@@ -381,6 +381,30 @@ var executePaymasterTransaction = async ({
|
|
|
381
381
|
accountClassHash
|
|
382
382
|
}
|
|
383
383
|
});
|
|
384
|
+
if (!prepareResponse || typeof prepareResponse !== "object") {
|
|
385
|
+
throw new Error(
|
|
386
|
+
"Invalid response from /transactions/prepare-typed-data: response is not an object"
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
let typedData2;
|
|
390
|
+
let walletType;
|
|
391
|
+
if ("typedData" in prepareResponse) {
|
|
392
|
+
const resp = prepareResponse;
|
|
393
|
+
typedData2 = resp.typedData;
|
|
394
|
+
walletType = resp.walletType;
|
|
395
|
+
} else if (prepareResponse && "types" in prepareResponse && "message" in prepareResponse) {
|
|
396
|
+
typedData2 = prepareResponse;
|
|
397
|
+
} else {
|
|
398
|
+
const apiMessage = prepareResponse && typeof prepareResponse.message === "string" ? prepareResponse.message : void 0;
|
|
399
|
+
throw new Error(
|
|
400
|
+
apiMessage ?? "Invalid response from /transactions/prepare-typed-data: typedData is missing. This may occur for older STARKNET wallets that don't support paymaster transactions. Please ensure the wallet is a CHIPI wallet type."
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
if (!typedData2 || typeof typedData2 !== "object" || !("message" in typedData2)) {
|
|
404
|
+
throw new Error(
|
|
405
|
+
"Invalid typedData received from backend: missing 'message' field. This may occur for older STARKNET wallets that don't support paymaster transactions."
|
|
406
|
+
);
|
|
407
|
+
}
|
|
384
408
|
const userSignature = await account.signMessage(typedData2);
|
|
385
409
|
const result = await client.post({
|
|
386
410
|
endpoint: "/transactions/execute-sponsored-transaction",
|
|
@@ -810,43 +834,6 @@ var ChipiSkus = class {
|
|
|
810
834
|
});
|
|
811
835
|
}
|
|
812
836
|
};
|
|
813
|
-
var Users = class {
|
|
814
|
-
constructor(client) {
|
|
815
|
-
this.client = client;
|
|
816
|
-
}
|
|
817
|
-
/**
|
|
818
|
-
* Get a single SKU by ID
|
|
819
|
-
* @param bearerToken - Authentication token for API calls
|
|
820
|
-
* @param id - SKU ID
|
|
821
|
-
* @returns Promise<Sku> - Single SKU
|
|
822
|
-
*/
|
|
823
|
-
async getUser(params, bearerToken) {
|
|
824
|
-
const { phone, ...rest } = params;
|
|
825
|
-
const queryParams = {
|
|
826
|
-
...rest,
|
|
827
|
-
phoneCountryCode: phone?.phoneCountryCode?.toString() || void 0,
|
|
828
|
-
phoneNumber: phone?.phoneNumber?.toString() || void 0
|
|
829
|
-
};
|
|
830
|
-
return this.client.get({
|
|
831
|
-
endpoint: `${API_ENDPOINTS.USERS}`,
|
|
832
|
-
params: queryParams,
|
|
833
|
-
bearerToken
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
/**
|
|
837
|
-
* Create a new user
|
|
838
|
-
* @param bearerToken - Authentication token for API calls
|
|
839
|
-
* @param params - CreateUserParams
|
|
840
|
-
* @returns Promise<User> - Single User
|
|
841
|
-
*/
|
|
842
|
-
async createUser(params, bearerToken) {
|
|
843
|
-
return this.client.post({
|
|
844
|
-
endpoint: `${API_ENDPOINTS.USERS}`,
|
|
845
|
-
bearerToken,
|
|
846
|
-
body: params
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
837
|
var ChipiSessions = class {
|
|
851
838
|
constructor(client) {
|
|
852
839
|
this.client = client;
|
|
@@ -1234,15 +1221,12 @@ var ChipiSDK = class {
|
|
|
1234
1221
|
this.transactions = new ChipiTransactions(this.client);
|
|
1235
1222
|
this.skuPurchases = new ChipiSkuPurchases(this.client);
|
|
1236
1223
|
this.skus = new ChipiSkus(this.client);
|
|
1237
|
-
this.users = new Users(this.client);
|
|
1238
1224
|
this.sessions = new ChipiSessions(this.client);
|
|
1239
1225
|
this.exchanges = new ChipiExchanges(this.client);
|
|
1240
1226
|
this.executeTransaction = this.executeTransaction.bind(this);
|
|
1241
1227
|
this.executeTransactionWithSession = this.executeTransactionWithSession.bind(this);
|
|
1242
1228
|
this.transfer = this.transfer.bind(this);
|
|
1243
1229
|
this.approve = this.approve.bind(this);
|
|
1244
|
-
this.stakeVesuUsdc = this.stakeVesuUsdc.bind(this);
|
|
1245
|
-
this.withdrawVesuUsdc = this.withdrawVesuUsdc.bind(this);
|
|
1246
1230
|
this.callAnyContract = this.callAnyContract.bind(this);
|
|
1247
1231
|
this.createWallet = this.createWallet.bind(this);
|
|
1248
1232
|
this.recordSendTransaction = this.recordSendTransaction.bind(this);
|
|
@@ -1351,63 +1335,6 @@ var ChipiSDK = class {
|
|
|
1351
1335
|
bearerToken: this.resolveBearerToken(bearerToken)
|
|
1352
1336
|
});
|
|
1353
1337
|
}
|
|
1354
|
-
/**
|
|
1355
|
-
* Stake USDC in Vesu protocol
|
|
1356
|
-
*/
|
|
1357
|
-
async stakeVesuUsdc({
|
|
1358
|
-
params,
|
|
1359
|
-
bearerToken
|
|
1360
|
-
}) {
|
|
1361
|
-
const { encryptKey, wallet, amount, receiverWallet } = params;
|
|
1362
|
-
const formattedAmount = formatAmount(amount, 6);
|
|
1363
|
-
return this.executeTransaction({
|
|
1364
|
-
params: {
|
|
1365
|
-
encryptKey,
|
|
1366
|
-
wallet,
|
|
1367
|
-
calls: [
|
|
1368
|
-
{
|
|
1369
|
-
contractAddress: CONTRACT_ADDRESSES.USDC_MAINNET,
|
|
1370
|
-
entrypoint: "approve",
|
|
1371
|
-
calldata: [
|
|
1372
|
-
CONTRACT_ADDRESSES.VESU_USDC_MAINNET,
|
|
1373
|
-
formattedAmount,
|
|
1374
|
-
"0x0"
|
|
1375
|
-
]
|
|
1376
|
-
},
|
|
1377
|
-
{
|
|
1378
|
-
contractAddress: CONTRACT_ADDRESSES.VESU_USDC_MAINNET,
|
|
1379
|
-
entrypoint: "deposit",
|
|
1380
|
-
calldata: [formattedAmount, "0x0", receiverWallet]
|
|
1381
|
-
}
|
|
1382
|
-
]
|
|
1383
|
-
},
|
|
1384
|
-
bearerToken: this.resolveBearerToken(bearerToken)
|
|
1385
|
-
});
|
|
1386
|
-
}
|
|
1387
|
-
/**
|
|
1388
|
-
* Withdraw USDC from Vesu protocol
|
|
1389
|
-
*/
|
|
1390
|
-
async withdrawVesuUsdc({
|
|
1391
|
-
params,
|
|
1392
|
-
bearerToken
|
|
1393
|
-
}) {
|
|
1394
|
-
const { encryptKey, wallet, amount, recipient } = params;
|
|
1395
|
-
const formattedAmount = formatAmount(amount, 6);
|
|
1396
|
-
return this.executeTransaction({
|
|
1397
|
-
params: {
|
|
1398
|
-
encryptKey,
|
|
1399
|
-
wallet,
|
|
1400
|
-
calls: [
|
|
1401
|
-
{
|
|
1402
|
-
contractAddress: CONTRACT_ADDRESSES.VESU_USDC_MAINNET,
|
|
1403
|
-
entrypoint: "withdraw",
|
|
1404
|
-
calldata: [formattedAmount, recipient, "0x0"]
|
|
1405
|
-
}
|
|
1406
|
-
]
|
|
1407
|
-
},
|
|
1408
|
-
bearerToken: this.resolveBearerToken(bearerToken)
|
|
1409
|
-
});
|
|
1410
|
-
}
|
|
1411
1338
|
/**
|
|
1412
1339
|
* Call any contract method
|
|
1413
1340
|
*/
|
|
@@ -1489,13 +1416,6 @@ var ChipiSDK = class {
|
|
|
1489
1416
|
async getSku(id, bearerToken) {
|
|
1490
1417
|
return this.skus.getSku(id, this.resolveBearerToken(bearerToken));
|
|
1491
1418
|
}
|
|
1492
|
-
// USERS
|
|
1493
|
-
async getUser(params, bearerToken) {
|
|
1494
|
-
return this.users.getUser(params, this.resolveBearerToken(bearerToken));
|
|
1495
|
-
}
|
|
1496
|
-
async createUser(params, bearerToken) {
|
|
1497
|
-
return this.users.createUser(params, this.resolveBearerToken(bearerToken));
|
|
1498
|
-
}
|
|
1499
1419
|
async getUsdAmount(currencyAmount, currency, bearerToken) {
|
|
1500
1420
|
return this.exchanges.getUsdAmount(
|
|
1501
1421
|
currencyAmount,
|