@chipi-stack/backend 6.0.0 → 8.0.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/{client-BaNfges3.d.mts → client-D4ZnPqgQ.d.mts} +5 -5
- package/dist/{client-BaNfges3.d.ts → client-D4ZnPqgQ.d.ts} +5 -5
- package/dist/index.d.mts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +91 -182
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -182
- package/dist/index.mjs.map +1 -1
- package/dist/skus.d.mts +1 -2
- package/dist/skus.d.ts +1 -2
- package/dist/transactions.d.mts +1 -2
- package/dist/transactions.d.ts +1 -2
- package/dist/transactions.js +43 -53
- package/dist/transactions.js.map +1 -1
- package/dist/transactions.mjs +42 -52
- package/dist/transactions.mjs.map +1 -1
- package/dist/wallets.d.mts +4 -14
- package/dist/wallets.d.ts +4 -14
- package/dist/wallets.js +36 -93
- package/dist/wallets.js.map +1 -1
- package/dist/wallets.mjs +35 -92
- package/dist/wallets.mjs.map +1 -1
- package/package.json +4 -5
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ChipiSDKConfig } from '@chipi-stack/types';
|
|
2
|
-
import { ApiResponse } from '@chipi-stack/shared';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* HTTP client for Chipi API interactions
|
|
@@ -7,6 +6,7 @@ import { ApiResponse } from '@chipi-stack/shared';
|
|
|
7
6
|
declare class ChipiClient {
|
|
8
7
|
private apiPublicKey;
|
|
9
8
|
baseUrl: string;
|
|
9
|
+
nodeUrl: string;
|
|
10
10
|
private environment;
|
|
11
11
|
constructor(config: ChipiSDKConfig);
|
|
12
12
|
/**
|
|
@@ -19,21 +19,21 @@ declare class ChipiClient {
|
|
|
19
19
|
endpoint: string;
|
|
20
20
|
params?: Record<string, any>;
|
|
21
21
|
bearerToken?: string;
|
|
22
|
-
}): Promise<
|
|
22
|
+
}): Promise<T>;
|
|
23
23
|
post<T>({ endpoint, bearerToken, body, }: {
|
|
24
24
|
endpoint: string;
|
|
25
25
|
bearerToken: string;
|
|
26
26
|
body?: Record<string, any>;
|
|
27
|
-
}): Promise<
|
|
27
|
+
}): Promise<T>;
|
|
28
28
|
put<T>({ endpoint, bearerToken, body, }: {
|
|
29
29
|
endpoint: string;
|
|
30
30
|
bearerToken: string;
|
|
31
31
|
body?: Record<string, any>;
|
|
32
|
-
}): Promise<
|
|
32
|
+
}): Promise<T>;
|
|
33
33
|
delete<T>({ endpoint, bearerToken, }: {
|
|
34
34
|
endpoint: string;
|
|
35
35
|
bearerToken: string;
|
|
36
|
-
}): Promise<
|
|
36
|
+
}): Promise<T>;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export { ChipiClient as C };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ChipiSDKConfig } from '@chipi-stack/types';
|
|
2
|
-
import { ApiResponse } from '@chipi-stack/shared';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* HTTP client for Chipi API interactions
|
|
@@ -7,6 +6,7 @@ import { ApiResponse } from '@chipi-stack/shared';
|
|
|
7
6
|
declare class ChipiClient {
|
|
8
7
|
private apiPublicKey;
|
|
9
8
|
baseUrl: string;
|
|
9
|
+
nodeUrl: string;
|
|
10
10
|
private environment;
|
|
11
11
|
constructor(config: ChipiSDKConfig);
|
|
12
12
|
/**
|
|
@@ -19,21 +19,21 @@ declare class ChipiClient {
|
|
|
19
19
|
endpoint: string;
|
|
20
20
|
params?: Record<string, any>;
|
|
21
21
|
bearerToken?: string;
|
|
22
|
-
}): Promise<
|
|
22
|
+
}): Promise<T>;
|
|
23
23
|
post<T>({ endpoint, bearerToken, body, }: {
|
|
24
24
|
endpoint: string;
|
|
25
25
|
bearerToken: string;
|
|
26
26
|
body?: Record<string, any>;
|
|
27
|
-
}): Promise<
|
|
27
|
+
}): Promise<T>;
|
|
28
28
|
put<T>({ endpoint, bearerToken, body, }: {
|
|
29
29
|
endpoint: string;
|
|
30
30
|
bearerToken: string;
|
|
31
31
|
body?: Record<string, any>;
|
|
32
|
-
}): Promise<
|
|
32
|
+
}): Promise<T>;
|
|
33
33
|
delete<T>({ endpoint, bearerToken, }: {
|
|
34
34
|
endpoint: string;
|
|
35
35
|
bearerToken: string;
|
|
36
|
-
}): Promise<
|
|
36
|
+
}): Promise<T>;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export { ChipiClient as C };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetWalletParams,
|
|
1
|
+
import { ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetWalletParams, WalletDataResponse } from '@chipi-stack/types';
|
|
2
2
|
export * from '@chipi-stack/types';
|
|
3
3
|
import { ChipiWallets } from './wallets.mjs';
|
|
4
4
|
import { ChipiTransactions } from './transactions.mjs';
|
|
5
5
|
import { ChipiSkus } from './skus.mjs';
|
|
6
|
-
export { C as ChipiClient } from './client-
|
|
7
|
-
import '@chipi-stack/shared';
|
|
6
|
+
export { C as ChipiClient } from './client-D4ZnPqgQ.mjs';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Main Chipi SDK class
|
|
@@ -47,17 +46,17 @@ declare class ChipiSDK {
|
|
|
47
46
|
* Create a new wallet
|
|
48
47
|
*/
|
|
49
48
|
createWallet({ params, bearerToken, }: {
|
|
50
|
-
params:
|
|
49
|
+
params: CreateWalletParams;
|
|
51
50
|
bearerToken: string;
|
|
52
51
|
}): Promise<CreateWalletResponse>;
|
|
53
52
|
recordSendTransaction({ params, bearerToken, }: {
|
|
54
53
|
params: RecordSendTransactionParams;
|
|
55
54
|
bearerToken: string;
|
|
56
55
|
}): Promise<Transaction>;
|
|
57
|
-
getWallet(params: Omit<GetWalletParams, "apiPublicKey"
|
|
56
|
+
getWallet(params: Omit<GetWalletParams, "apiPublicKey">): Promise<WalletDataResponse>;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
declare const encryptPrivateKey: (privateKey: string, password: string) => string;
|
|
61
|
-
declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string
|
|
60
|
+
declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string;
|
|
62
61
|
|
|
63
62
|
export { ChipiSDK, ChipiSkus, ChipiTransactions, ChipiWallets, decryptPrivateKey, encryptPrivateKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetWalletParams,
|
|
1
|
+
import { ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetWalletParams, WalletDataResponse } from '@chipi-stack/types';
|
|
2
2
|
export * from '@chipi-stack/types';
|
|
3
3
|
import { ChipiWallets } from './wallets.js';
|
|
4
4
|
import { ChipiTransactions } from './transactions.js';
|
|
5
5
|
import { ChipiSkus } from './skus.js';
|
|
6
|
-
export { C as ChipiClient } from './client-
|
|
7
|
-
import '@chipi-stack/shared';
|
|
6
|
+
export { C as ChipiClient } from './client-D4ZnPqgQ.js';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Main Chipi SDK class
|
|
@@ -47,17 +46,17 @@ declare class ChipiSDK {
|
|
|
47
46
|
* Create a new wallet
|
|
48
47
|
*/
|
|
49
48
|
createWallet({ params, bearerToken, }: {
|
|
50
|
-
params:
|
|
49
|
+
params: CreateWalletParams;
|
|
51
50
|
bearerToken: string;
|
|
52
51
|
}): Promise<CreateWalletResponse>;
|
|
53
52
|
recordSendTransaction({ params, bearerToken, }: {
|
|
54
53
|
params: RecordSendTransactionParams;
|
|
55
54
|
bearerToken: string;
|
|
56
55
|
}): Promise<Transaction>;
|
|
57
|
-
getWallet(params: Omit<GetWalletParams, "apiPublicKey"
|
|
56
|
+
getWallet(params: Omit<GetWalletParams, "apiPublicKey">): Promise<WalletDataResponse>;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
declare const encryptPrivateKey: (privateKey: string, password: string) => string;
|
|
61
|
-
declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string
|
|
60
|
+
declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string;
|
|
62
61
|
|
|
63
62
|
export { ChipiSDK, ChipiSkus, ChipiTransactions, ChipiWallets, decryptPrivateKey, encryptPrivateKey };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var shared = require('@chipi-stack/shared');
|
|
4
|
+
var CryptoES = require('crypto-es');
|
|
4
5
|
var starknet = require('starknet');
|
|
5
|
-
var CryptoJS = require('crypto-js');
|
|
6
6
|
var types = require('@chipi-stack/types');
|
|
7
7
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var CryptoES__default = /*#__PURE__*/_interopDefault(CryptoES);
|
|
11
11
|
|
|
12
12
|
// src/chipi-sdk.ts
|
|
13
13
|
var ChipiClient = class {
|
|
@@ -18,6 +18,7 @@ var ChipiClient = class {
|
|
|
18
18
|
this.apiPublicKey = config.apiPublicKey;
|
|
19
19
|
this.environment = config.environment || "production";
|
|
20
20
|
this.baseUrl = this.getBaseUrl();
|
|
21
|
+
this.nodeUrl = config.nodeUrl || shared.STARKNET_NETWORKS.MAINNET;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* Get the API public key (for internal SDK use)
|
|
@@ -29,7 +30,7 @@ var ChipiClient = class {
|
|
|
29
30
|
if (this.environment === "development") {
|
|
30
31
|
return "http://localhost:3000/v1";
|
|
31
32
|
}
|
|
32
|
-
return "https://
|
|
33
|
+
return "https://api.chipipay.com/v1";
|
|
33
34
|
}
|
|
34
35
|
getHeaders(bearerToken) {
|
|
35
36
|
const headers = {
|
|
@@ -68,10 +69,7 @@ var ChipiClient = class {
|
|
|
68
69
|
response.status
|
|
69
70
|
);
|
|
70
71
|
}
|
|
71
|
-
return
|
|
72
|
-
success: true,
|
|
73
|
-
data
|
|
74
|
-
};
|
|
72
|
+
return data;
|
|
75
73
|
} catch (error) {
|
|
76
74
|
throw shared.handleApiError(error);
|
|
77
75
|
}
|
|
@@ -97,10 +95,7 @@ var ChipiClient = class {
|
|
|
97
95
|
response.status
|
|
98
96
|
);
|
|
99
97
|
}
|
|
100
|
-
return
|
|
101
|
-
success: true,
|
|
102
|
-
data
|
|
103
|
-
};
|
|
98
|
+
return data;
|
|
104
99
|
} catch (error) {
|
|
105
100
|
throw shared.handleApiError(error);
|
|
106
101
|
}
|
|
@@ -125,10 +120,7 @@ var ChipiClient = class {
|
|
|
125
120
|
response.status
|
|
126
121
|
);
|
|
127
122
|
}
|
|
128
|
-
return
|
|
129
|
-
success: true,
|
|
130
|
-
data
|
|
131
|
-
};
|
|
123
|
+
return data;
|
|
132
124
|
} catch (error) {
|
|
133
125
|
throw shared.handleApiError(error);
|
|
134
126
|
}
|
|
@@ -151,66 +143,46 @@ var ChipiClient = class {
|
|
|
151
143
|
response.status
|
|
152
144
|
);
|
|
153
145
|
}
|
|
154
|
-
return
|
|
155
|
-
success: true,
|
|
156
|
-
data
|
|
157
|
-
};
|
|
146
|
+
return data;
|
|
158
147
|
} catch (error) {
|
|
159
148
|
throw shared.handleApiError(error);
|
|
160
149
|
}
|
|
161
150
|
}
|
|
162
151
|
};
|
|
152
|
+
var encryptPrivateKey = (privateKey, password) => {
|
|
153
|
+
return CryptoES__default.default.AES.encrypt(privateKey, password).toString();
|
|
154
|
+
};
|
|
155
|
+
var decryptPrivateKey = (encryptedPrivateKey, password) => {
|
|
156
|
+
try {
|
|
157
|
+
const bytes = CryptoES__default.default.AES.decrypt(encryptedPrivateKey, password);
|
|
158
|
+
const decrypted = bytes.toString(CryptoES__default.default.enc.Utf8);
|
|
159
|
+
if (!decrypted) throw new Error("Decryption failed");
|
|
160
|
+
return decrypted;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error("Decryption failed:", error);
|
|
163
|
+
throw new Error(`Decryption failed: ${error}`);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/wallets.ts
|
|
163
168
|
var ChipiWallets = class {
|
|
164
169
|
constructor(client) {
|
|
165
170
|
this.client = client;
|
|
166
|
-
this.
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
} catch (error) {
|
|
176
|
-
console.error("Decryption failed:", error);
|
|
177
|
-
throw new Error(`Failed to decrypt private key: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
178
|
-
}
|
|
171
|
+
this.getPrivateKeyAX = () => {
|
|
172
|
+
const privateKeyBytes = CryptoES__default.default.lib.WordArray.random(32);
|
|
173
|
+
const privateKey = privateKeyBytes.toString(CryptoES__default.default.enc.Hex);
|
|
174
|
+
const fullPrivateKey = `0x${privateKey}`;
|
|
175
|
+
const maxStarknetValue = BigInt(
|
|
176
|
+
"0x800000000000000000000000000000000000000000000000000000000000000"
|
|
177
|
+
);
|
|
178
|
+
const privateKeyBigInt = BigInt(fullPrivateKey) % maxStarknetValue;
|
|
179
|
+
return `0x${privateKeyBigInt.toString(16)}`;
|
|
179
180
|
};
|
|
180
181
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Prepare wallet creation data
|
|
183
|
-
*/
|
|
184
|
-
// async prepareWalletCreation(
|
|
185
|
-
// params: Omit<PrepareWalletCreationParams, 'apiPublicKey'>
|
|
186
|
-
// ): Promise<PrepareWalletCreationResponse> {
|
|
187
|
-
// const response = await this.client.post<PrepareWalletCreationResponse>(
|
|
188
|
-
// `${API_ENDPOINTS.CHIPI_WALLETS}/prepare-creation`,
|
|
189
|
-
// params
|
|
190
|
-
// );
|
|
191
|
-
// return response.data!;
|
|
192
|
-
// }
|
|
193
|
-
/**
|
|
194
|
-
* Create a new wallet
|
|
195
|
-
*/
|
|
196
|
-
// async createWallet(
|
|
197
|
-
// params: Omit<CreateWalletParams, 'apiPublicKey' | 'nodeUrl'>,
|
|
198
|
-
// nodeUrl?: string
|
|
199
|
-
// ): Promise<CreateWalletResponse> {
|
|
200
|
-
// const response = await this.client.post<CreateWalletResponse>(
|
|
201
|
-
// API_ENDPOINTS.CHIPI_WALLETS,
|
|
202
|
-
// {
|
|
203
|
-
// ...params,
|
|
204
|
-
// nodeUrl,
|
|
205
|
-
// },
|
|
206
|
-
// params.bearerToken
|
|
207
|
-
// );
|
|
208
|
-
// return response.data!;
|
|
209
|
-
// }
|
|
210
182
|
async createWallet(params) {
|
|
211
183
|
try {
|
|
212
|
-
const { encryptKey,
|
|
213
|
-
const provider = new starknet.RpcProvider({ nodeUrl });
|
|
184
|
+
const { encryptKey, externalUserId, bearerToken } = params;
|
|
185
|
+
const provider = new starknet.RpcProvider({ nodeUrl: this.client.nodeUrl });
|
|
214
186
|
const privateKeyAX = starknet.stark.randomAddress();
|
|
215
187
|
const starkKeyPubAX = starknet.ec.starkCurve.getStarkKey(privateKeyAX);
|
|
216
188
|
const accountClassHash = "0x036078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f";
|
|
@@ -236,7 +208,7 @@ var ChipiWallets = class {
|
|
|
236
208
|
publicKey
|
|
237
209
|
}
|
|
238
210
|
});
|
|
239
|
-
const { typeData, accountClassHash: accountClassHashResponse } = typeDataResponse
|
|
211
|
+
const { typeData, accountClassHash: accountClassHashResponse } = typeDataResponse;
|
|
240
212
|
const userSignature = await account.signMessage(typeData);
|
|
241
213
|
const deploymentData = {
|
|
242
214
|
class_hash: accountClassHashResponse,
|
|
@@ -244,10 +216,7 @@ var ChipiWallets = class {
|
|
|
244
216
|
unique: `${starknet.num.toHex(0)}`,
|
|
245
217
|
calldata: AXConstructorCallData.map((value) => starknet.num.toHex(value))
|
|
246
218
|
};
|
|
247
|
-
const encryptedPrivateKey =
|
|
248
|
-
privateKeyAX,
|
|
249
|
-
encryptKey
|
|
250
|
-
);
|
|
219
|
+
const encryptedPrivateKey = encryptPrivateKey(privateKeyAX, encryptKey);
|
|
251
220
|
const executeTransactionResponse = await this.client.post({
|
|
252
221
|
endpoint: `${shared.API_ENDPOINTS.CHIPI_WALLETS}`,
|
|
253
222
|
bearerToken,
|
|
@@ -268,20 +237,11 @@ var ChipiWallets = class {
|
|
|
268
237
|
}
|
|
269
238
|
}
|
|
270
239
|
});
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
walletPublicKey: executeTransaction.walletPublicKey,
|
|
277
|
-
wallet: executeTransaction.wallet
|
|
278
|
-
};
|
|
279
|
-
} else {
|
|
280
|
-
throw new shared.ChipiTransactionError(
|
|
281
|
-
`Failed to create wallet: ${executeTransaction.message}`,
|
|
282
|
-
"WALLET_CREATION_FAILED"
|
|
283
|
-
);
|
|
284
|
-
}
|
|
240
|
+
return {
|
|
241
|
+
txHash: executeTransactionResponse.txHash,
|
|
242
|
+
walletPublicKey: executeTransactionResponse.walletPublicKey,
|
|
243
|
+
wallet: executeTransactionResponse.wallet
|
|
244
|
+
};
|
|
285
245
|
} catch (error) {
|
|
286
246
|
console.error("Error detallado:", error);
|
|
287
247
|
if (error instanceof Error && error.message.includes("SSL")) {
|
|
@@ -307,79 +267,27 @@ var ChipiWallets = class {
|
|
|
307
267
|
bearerToken,
|
|
308
268
|
body: params
|
|
309
269
|
});
|
|
310
|
-
return response
|
|
270
|
+
return response;
|
|
311
271
|
}
|
|
312
272
|
async getWallet(params) {
|
|
313
273
|
try {
|
|
314
|
-
const { externalUserId, bearerToken
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const { data } = getExternalUserWalletResponse.data;
|
|
321
|
-
if (getExternalUserWalletResponse.success) {
|
|
322
|
-
const decryptedKey = this.decryptPrivateKey(
|
|
323
|
-
data.encryptedPrivateKey,
|
|
324
|
-
encryptKey
|
|
325
|
-
);
|
|
326
|
-
return {
|
|
327
|
-
success: true,
|
|
328
|
-
wallet: {
|
|
329
|
-
publicKey: data.publicKey,
|
|
330
|
-
decryptedWallet: decryptedKey,
|
|
331
|
-
encryptedPrivateKey: data.encryptedPrivateKey
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
return {
|
|
336
|
-
success: false,
|
|
337
|
-
wallet: {
|
|
338
|
-
publicKey: "",
|
|
339
|
-
decryptedWallet: "",
|
|
340
|
-
encryptedPrivateKey: ""
|
|
274
|
+
const { externalUserId, bearerToken } = params;
|
|
275
|
+
const getWalletResponse = await this.client.get(
|
|
276
|
+
{
|
|
277
|
+
endpoint: `${shared.API_ENDPOINTS.CHIPI_WALLETS}/by-user`,
|
|
278
|
+
params: { externalUserId },
|
|
279
|
+
bearerToken
|
|
341
280
|
}
|
|
281
|
+
);
|
|
282
|
+
return {
|
|
283
|
+
publicKey: getWalletResponse.publicKey,
|
|
284
|
+
encryptedPrivateKey: getWalletResponse.encryptedPrivateKey
|
|
342
285
|
};
|
|
343
286
|
} catch (err) {
|
|
344
287
|
throw new Error(`getWallet error: ${String(err)}`);
|
|
345
288
|
}
|
|
346
289
|
}
|
|
347
290
|
};
|
|
348
|
-
var encryptPrivateKey = (privateKey, password) => {
|
|
349
|
-
if (!privateKey || !password) {
|
|
350
|
-
throw new Error("Private key and password are required");
|
|
351
|
-
}
|
|
352
|
-
return CryptoJS__default.default.AES.encrypt(privateKey, password).toString();
|
|
353
|
-
};
|
|
354
|
-
var decryptPrivateKey = (encryptedPrivateKey, password) => {
|
|
355
|
-
if (!encryptedPrivateKey || !password) {
|
|
356
|
-
console.error("Encrypted private key and password are required");
|
|
357
|
-
return null;
|
|
358
|
-
}
|
|
359
|
-
try {
|
|
360
|
-
console.log("Attempting to decrypt:", {
|
|
361
|
-
encryptedLength: encryptedPrivateKey.length,
|
|
362
|
-
passwordLength: password.length,
|
|
363
|
-
encryptedStart: encryptedPrivateKey.substring(0, 20)
|
|
364
|
-
});
|
|
365
|
-
const bytes = CryptoJS__default.default.AES.decrypt(encryptedPrivateKey, password);
|
|
366
|
-
const decrypted = bytes.toString(CryptoJS__default.default.enc.Utf8);
|
|
367
|
-
console.log("Decryption result:", {
|
|
368
|
-
decryptedLength: decrypted.length,
|
|
369
|
-
decrypted: decrypted ? "SUCCESS" : "EMPTY"
|
|
370
|
-
});
|
|
371
|
-
if (!decrypted) {
|
|
372
|
-
console.error("Decryption resulted in empty string");
|
|
373
|
-
return null;
|
|
374
|
-
}
|
|
375
|
-
return decrypted;
|
|
376
|
-
} catch (error) {
|
|
377
|
-
console.error("Decryption failed:", error);
|
|
378
|
-
return null;
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
// src/gasless.ts
|
|
383
291
|
var executePaymasterTransaction = async (params) => {
|
|
384
292
|
try {
|
|
385
293
|
const { encryptKey, wallet, calls, apiPublicKey, bearerToken, backendUrl } = params;
|
|
@@ -398,42 +306,48 @@ var executePaymasterTransaction = async (params) => {
|
|
|
398
306
|
wallet.publicKey,
|
|
399
307
|
privateKeyDecrypted
|
|
400
308
|
);
|
|
401
|
-
const typeDataResponse = await fetch(
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
309
|
+
const typeDataResponse = await fetch(
|
|
310
|
+
`${backendUrl}/transactions/prepare-typed-data`,
|
|
311
|
+
{
|
|
312
|
+
method: "POST",
|
|
313
|
+
headers: {
|
|
314
|
+
"Content-Type": "application/json",
|
|
315
|
+
Authorization: `Bearer ${bearerToken}`,
|
|
316
|
+
"X-API-Key": apiPublicKey
|
|
317
|
+
},
|
|
318
|
+
body: JSON.stringify({
|
|
319
|
+
publicKey: wallet.publicKey,
|
|
320
|
+
calls,
|
|
321
|
+
accountClassHash: "0x036078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f"
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
);
|
|
414
325
|
if (!typeDataResponse.ok) {
|
|
415
326
|
const errorText = await typeDataResponse.text();
|
|
416
327
|
throw new Error(`Error en la API: ${errorText}`);
|
|
417
328
|
}
|
|
418
329
|
const typeData = await typeDataResponse.json();
|
|
419
330
|
const userSignature = await account.signMessage(typeData);
|
|
420
|
-
const executeTransaction = await fetch(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
331
|
+
const executeTransaction = await fetch(
|
|
332
|
+
`${backendUrl}/transactions/execute-sponsored-transaction`,
|
|
333
|
+
{
|
|
334
|
+
method: "POST",
|
|
335
|
+
headers: {
|
|
336
|
+
"Content-Type": "application/json",
|
|
337
|
+
Authorization: `Bearer ${bearerToken}`,
|
|
338
|
+
"X-API-Key": apiPublicKey
|
|
339
|
+
},
|
|
340
|
+
body: JSON.stringify({
|
|
341
|
+
publicKey: wallet.publicKey,
|
|
342
|
+
typeData,
|
|
343
|
+
userSignature: {
|
|
344
|
+
r: userSignature.r.toString(),
|
|
345
|
+
s: userSignature.s.toString(),
|
|
346
|
+
recovery: userSignature.recovery
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
}
|
|
350
|
+
);
|
|
437
351
|
if (!executeTransaction.ok) {
|
|
438
352
|
const errorText = await executeTransaction.text();
|
|
439
353
|
throw new Error(`Error en la API de ejecuci\xF3n: ${errorText}`);
|
|
@@ -545,7 +459,7 @@ var ChipiTransactions = class {
|
|
|
545
459
|
bearerToken,
|
|
546
460
|
body: params
|
|
547
461
|
});
|
|
548
|
-
return response
|
|
462
|
+
return response;
|
|
549
463
|
}
|
|
550
464
|
};
|
|
551
465
|
|
|
@@ -685,7 +599,6 @@ var ChipiSDK = class {
|
|
|
685
599
|
}) {
|
|
686
600
|
return this.wallets.createWallet({
|
|
687
601
|
...params,
|
|
688
|
-
nodeUrl: this.nodeUrl,
|
|
689
602
|
bearerToken
|
|
690
603
|
});
|
|
691
604
|
}
|
|
@@ -699,13 +612,9 @@ var ChipiSDK = class {
|
|
|
699
612
|
});
|
|
700
613
|
}
|
|
701
614
|
async getWallet(params) {
|
|
702
|
-
const {
|
|
615
|
+
const { bearerToken, externalUserId } = params;
|
|
703
616
|
return this.wallets.getWallet({
|
|
704
|
-
encryptKey,
|
|
705
|
-
apiPublicKey: this.client.getApiPublicKey(),
|
|
706
617
|
bearerToken,
|
|
707
|
-
nodeUrl: this.nodeUrl,
|
|
708
|
-
backendUrl: this.client.baseUrl,
|
|
709
618
|
externalUserId
|
|
710
619
|
});
|
|
711
620
|
}
|