@chipi-stack/backend 12.1.0 → 12.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.js CHANGED
@@ -203,9 +203,18 @@ var ChipiWallets = class {
203
203
  externalUserId,
204
204
  bearerToken,
205
205
  userId,
206
- walletType = "CHIPI"
206
+ walletType = "CHIPI",
207
207
  // Default to CHIPI wallet
208
+ usePasskey
208
209
  } = params;
210
+ if (!encryptKey) {
211
+ if (usePasskey) {
212
+ throw new Error(
213
+ "encryptKey is required when using passkey. The passkey authentication should have provided the encryptKey."
214
+ );
215
+ }
216
+ throw new Error("encryptKey is required for wallet creation");
217
+ }
209
218
  const rpcUrl = walletType === "READY" ? shared.WALLET_RPC_ENDPOINTS.READY : shared.WALLET_RPC_ENDPOINTS.CHIPI;
210
219
  const provider = new starknet.RpcProvider({ nodeUrl: rpcUrl });
211
220
  const privateKeyAX = this.getPrivateKeyAX();
@@ -222,7 +231,7 @@ var ChipiWallets = class {
222
231
  0
223
232
  );
224
233
  const account = new starknet.Account(provider, publicKey, privateKeyAX);
225
- const typeDataResponse = await this.client.post({
234
+ const typedDataResponse = await this.client.post({
226
235
  endpoint: `${shared.API_ENDPOINTS.CHIPI_WALLETS}/prepare-creation`,
227
236
  bearerToken,
228
237
  body: {
@@ -232,8 +241,8 @@ var ChipiWallets = class {
232
241
  // Needed for backend to build deployment data
233
242
  }
234
243
  });
235
- const { typeData, accountClassHash: accountClassHashResponse } = typeDataResponse;
236
- const userSignature = await account.signMessage(typeData);
244
+ const { typedData: typedData2, accountClassHash: accountClassHashResponse } = typedDataResponse;
245
+ const userSignature = await account.signMessage(typedData2);
237
246
  const deploymentData = {
238
247
  class_hash: accountClassHashResponse,
239
248
  salt: starkKeyPubAX,
@@ -254,7 +263,7 @@ var ChipiWallets = class {
254
263
  s: userSignature.s.toString(),
255
264
  recovery: userSignature.recovery
256
265
  },
257
- typeData,
266
+ typedData: typedData2,
258
267
  encryptedPrivateKey,
259
268
  deploymentData: {
260
269
  ...deploymentData,
@@ -263,11 +272,7 @@ var ChipiWallets = class {
263
272
  }
264
273
  }
265
274
  });
266
- return {
267
- txHash: executeTransactionResponse.txHash,
268
- walletPublicKey: executeTransactionResponse.walletPublicKey,
269
- wallet: executeTransactionResponse.wallet
270
- };
275
+ return executeTransactionResponse;
271
276
  } catch (error) {
272
277
  console.error("Detailed error:", error);
273
278
  if (error instanceof Error && error.message.includes("SSL")) {
@@ -349,15 +354,14 @@ var executePaymasterTransaction = async ({
349
354
  client
350
355
  }) => {
351
356
  try {
352
- const { encryptKey, wallet, calls, saveToDatabase } = params;
353
- if (!wallet.walletType) {
354
- console.warn(
355
- `[ChipiSDK] Wallet ${wallet.publicKey.slice(0, 10)}... has no walletType - defaulting to ARGENT for backward compatibility`
357
+ const { encryptKey, wallet, calls, saveToDatabase, usePasskey } = params;
358
+ if (!encryptKey) {
359
+ throw new Error(
360
+ usePasskey ? "encryptKey is required when using passkey. The passkey authentication should have provided the encryptKey." : "encryptKey is required for transaction execution"
356
361
  );
357
362
  }
358
- const walletType = wallet.walletType ?? "READY";
359
- const rpcUrl = walletType === "READY" ? shared.WALLET_RPC_ENDPOINTS.READY : shared.WALLET_RPC_ENDPOINTS.CHIPI;
360
- const accountClassHash = walletType === "READY" ? shared.WALLET_CLASS_HASHES.READY : shared.WALLET_CLASS_HASHES.CHIPI;
363
+ const rpcUrl = shared.WALLET_RPC_ENDPOINTS.READY;
364
+ const accountClassHash = shared.WALLET_CLASS_HASHES.READY;
361
365
  const privateKeyDecrypted = decryptPrivateKey(
362
366
  wallet.encryptedPrivateKey,
363
367
  encryptKey
@@ -371,23 +375,22 @@ var executePaymasterTransaction = async ({
371
375
  wallet.publicKey,
372
376
  privateKeyDecrypted
373
377
  );
374
- const typeData = await client.post({
378
+ const { typedData: typedData2, walletType } = await client.post({
375
379
  endpoint: "/transactions/prepare-typed-data",
376
380
  bearerToken,
377
381
  body: {
378
382
  publicKey: wallet.publicKey,
379
- walletType,
380
383
  calls,
381
384
  accountClassHash
382
385
  }
383
386
  });
384
- const userSignature = await account.signMessage(typeData);
387
+ const userSignature = await account.signMessage(typedData2);
385
388
  const result = await client.post({
386
389
  endpoint: "/transactions/execute-sponsored-transaction",
387
390
  bearerToken,
388
391
  body: {
389
392
  publicKey: wallet.publicKey,
390
- typeData,
393
+ typedData: typedData2,
391
394
  userSignature: {
392
395
  r: userSignature.r.toString(),
393
396
  s: userSignature.s.toString(),