@chipi-stack/backend 12.7.0 → 13.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/index.d.mts +20 -8
- package/dist/index.d.ts +20 -8
- package/dist/index.js +90 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -57
- package/dist/index.mjs.map +1 -1
- package/dist/skuPurchases.d.mts +25 -0
- package/dist/skuPurchases.d.ts +25 -0
- package/dist/{skuTransactions.js → skuPurchases.js} +64 -44
- package/dist/skuPurchases.js.map +1 -0
- package/dist/{skuTransactions.mjs → skuPurchases.mjs} +65 -45
- package/dist/skuPurchases.mjs.map +1 -0
- package/dist/transactions.js +1 -11
- package/dist/transactions.js.map +1 -1
- package/dist/transactions.mjs +1 -11
- package/dist/transactions.mjs.map +1 -1
- package/dist/wallets.js +4 -1
- package/dist/wallets.js.map +1 -1
- package/dist/wallets.mjs +4 -1
- package/dist/wallets.mjs.map +1 -1
- package/package.json +9 -9
- package/dist/skuTransactions.d.mts +0 -24
- package/dist/skuTransactions.d.ts +0 -24
- package/dist/skuTransactions.js.map +0 -1
- package/dist/skuTransactions.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _chipi_stack_types from '@chipi-stack/types';
|
|
2
|
-
import { GetUserParams, User, WalletData, CreateUserParams, CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse,
|
|
2
|
+
import { GetUserParams, User, WalletData, CreateUserParams, CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, Currency, ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuPurchaseParams, GetSkuListQuery, Sku, ChipiServerSDKConfig, ChipiBrowserSDKConfig } from '@chipi-stack/types';
|
|
3
3
|
export * from '@chipi-stack/types';
|
|
4
4
|
import { ChipiWallets } from './wallets.mjs';
|
|
5
5
|
import { ChipiTransactions } from './transactions.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { ChipiSkuPurchases } from './skuPurchases.mjs';
|
|
7
7
|
import { ChipiSkus } from './skus.mjs';
|
|
8
8
|
import { C as ChipiClient } from './client-43S3tkH3.mjs';
|
|
9
9
|
|
|
@@ -192,6 +192,12 @@ declare class ChipiSessions {
|
|
|
192
192
|
executeTransactionWithSession(params: ExecuteWithSessionParams, bearerToken: string): Promise<string>;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
declare class ChipiExchanges {
|
|
196
|
+
private client;
|
|
197
|
+
constructor(client: ChipiClient);
|
|
198
|
+
getUsdAmount(currencyAmount: number, currency: Currency, bearerToken: string): Promise<number>;
|
|
199
|
+
}
|
|
200
|
+
|
|
195
201
|
/**
|
|
196
202
|
* Main Chipi SDK class
|
|
197
203
|
*/
|
|
@@ -201,10 +207,11 @@ declare class ChipiSDK {
|
|
|
201
207
|
private apiSecretKey?;
|
|
202
208
|
readonly wallets: ChipiWallets;
|
|
203
209
|
readonly transactions: ChipiTransactions;
|
|
204
|
-
readonly
|
|
210
|
+
readonly skuPurchases: ChipiSkuPurchases;
|
|
205
211
|
readonly skus: ChipiSkus;
|
|
206
212
|
readonly users: Users;
|
|
207
213
|
readonly sessions: ChipiSessions;
|
|
214
|
+
readonly exchanges: ChipiExchanges;
|
|
208
215
|
constructor(config: ChipiSDKConfig);
|
|
209
216
|
/**
|
|
210
217
|
* Resolve bearer token - uses provided token or falls back to apiSecretKey
|
|
@@ -305,16 +312,21 @@ declare class ChipiSDK {
|
|
|
305
312
|
getWallet(params: GetWalletParams, bearerToken?: string): Promise<_chipi_stack_types.GetWalletResponse | null>;
|
|
306
313
|
getTokenBalance(params: GetTokenBalanceParams, bearerToken?: string): Promise<GetTokenBalanceResponse>;
|
|
307
314
|
/**
|
|
308
|
-
*
|
|
315
|
+
* Purchase a SKU
|
|
309
316
|
*/
|
|
310
|
-
|
|
311
|
-
params:
|
|
317
|
+
purchaseSku({ params, bearerToken, }: {
|
|
318
|
+
params: CreateSkuPurchaseParams;
|
|
312
319
|
bearerToken?: string;
|
|
313
|
-
}): Promise<
|
|
320
|
+
}): Promise<Transaction>;
|
|
321
|
+
/**
|
|
322
|
+
* Get a SKU purchase by id
|
|
323
|
+
*/
|
|
324
|
+
getSkuPurchase(id: string, bearerToken?: string): Promise<Transaction>;
|
|
314
325
|
getSkuList(params: GetSkuListQuery, bearerToken?: string): Promise<PaginatedResponse<Sku>>;
|
|
315
326
|
getSku(id: string, bearerToken?: string): Promise<Sku>;
|
|
316
327
|
getUser(params: GetUserParams, bearerToken?: string): Promise<User>;
|
|
317
328
|
createUser(params: CreateUserParams, bearerToken?: string): Promise<User>;
|
|
329
|
+
getUsdAmount(currencyAmount: number, currency: Currency, bearerToken?: string): Promise<number>;
|
|
318
330
|
}
|
|
319
331
|
|
|
320
332
|
/**
|
|
@@ -393,4 +405,4 @@ declare class ChipiBrowserSDK extends ChipiSDK {
|
|
|
393
405
|
declare const encryptPrivateKey: (privateKey: string, password: string) => string;
|
|
394
406
|
declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string;
|
|
395
407
|
|
|
396
|
-
export { ChipiBrowserSDK, ChipiClient, ChipiSDK, ChipiServerSDK, ChipiSessions,
|
|
408
|
+
export { ChipiBrowserSDK, ChipiClient, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiWallets, decryptPrivateKey, encryptPrivateKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _chipi_stack_types from '@chipi-stack/types';
|
|
2
|
-
import { GetUserParams, User, WalletData, CreateUserParams, CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse,
|
|
2
|
+
import { GetUserParams, User, WalletData, CreateUserParams, CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, Currency, ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuPurchaseParams, GetSkuListQuery, Sku, ChipiServerSDKConfig, ChipiBrowserSDKConfig } from '@chipi-stack/types';
|
|
3
3
|
export * from '@chipi-stack/types';
|
|
4
4
|
import { ChipiWallets } from './wallets.js';
|
|
5
5
|
import { ChipiTransactions } from './transactions.js';
|
|
6
|
-
import {
|
|
6
|
+
import { ChipiSkuPurchases } from './skuPurchases.js';
|
|
7
7
|
import { ChipiSkus } from './skus.js';
|
|
8
8
|
import { C as ChipiClient } from './client-43S3tkH3.js';
|
|
9
9
|
|
|
@@ -192,6 +192,12 @@ declare class ChipiSessions {
|
|
|
192
192
|
executeTransactionWithSession(params: ExecuteWithSessionParams, bearerToken: string): Promise<string>;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
declare class ChipiExchanges {
|
|
196
|
+
private client;
|
|
197
|
+
constructor(client: ChipiClient);
|
|
198
|
+
getUsdAmount(currencyAmount: number, currency: Currency, bearerToken: string): Promise<number>;
|
|
199
|
+
}
|
|
200
|
+
|
|
195
201
|
/**
|
|
196
202
|
* Main Chipi SDK class
|
|
197
203
|
*/
|
|
@@ -201,10 +207,11 @@ declare class ChipiSDK {
|
|
|
201
207
|
private apiSecretKey?;
|
|
202
208
|
readonly wallets: ChipiWallets;
|
|
203
209
|
readonly transactions: ChipiTransactions;
|
|
204
|
-
readonly
|
|
210
|
+
readonly skuPurchases: ChipiSkuPurchases;
|
|
205
211
|
readonly skus: ChipiSkus;
|
|
206
212
|
readonly users: Users;
|
|
207
213
|
readonly sessions: ChipiSessions;
|
|
214
|
+
readonly exchanges: ChipiExchanges;
|
|
208
215
|
constructor(config: ChipiSDKConfig);
|
|
209
216
|
/**
|
|
210
217
|
* Resolve bearer token - uses provided token or falls back to apiSecretKey
|
|
@@ -305,16 +312,21 @@ declare class ChipiSDK {
|
|
|
305
312
|
getWallet(params: GetWalletParams, bearerToken?: string): Promise<_chipi_stack_types.GetWalletResponse | null>;
|
|
306
313
|
getTokenBalance(params: GetTokenBalanceParams, bearerToken?: string): Promise<GetTokenBalanceResponse>;
|
|
307
314
|
/**
|
|
308
|
-
*
|
|
315
|
+
* Purchase a SKU
|
|
309
316
|
*/
|
|
310
|
-
|
|
311
|
-
params:
|
|
317
|
+
purchaseSku({ params, bearerToken, }: {
|
|
318
|
+
params: CreateSkuPurchaseParams;
|
|
312
319
|
bearerToken?: string;
|
|
313
|
-
}): Promise<
|
|
320
|
+
}): Promise<Transaction>;
|
|
321
|
+
/**
|
|
322
|
+
* Get a SKU purchase by id
|
|
323
|
+
*/
|
|
324
|
+
getSkuPurchase(id: string, bearerToken?: string): Promise<Transaction>;
|
|
314
325
|
getSkuList(params: GetSkuListQuery, bearerToken?: string): Promise<PaginatedResponse<Sku>>;
|
|
315
326
|
getSku(id: string, bearerToken?: string): Promise<Sku>;
|
|
316
327
|
getUser(params: GetUserParams, bearerToken?: string): Promise<User>;
|
|
317
328
|
createUser(params: CreateUserParams, bearerToken?: string): Promise<User>;
|
|
329
|
+
getUsdAmount(currencyAmount: number, currency: Currency, bearerToken?: string): Promise<number>;
|
|
318
330
|
}
|
|
319
331
|
|
|
320
332
|
/**
|
|
@@ -393,4 +405,4 @@ declare class ChipiBrowserSDK extends ChipiSDK {
|
|
|
393
405
|
declare const encryptPrivateKey: (privateKey: string, password: string) => string;
|
|
394
406
|
declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string;
|
|
395
407
|
|
|
396
|
-
export { ChipiBrowserSDK, ChipiClient, ChipiSDK, ChipiServerSDK, ChipiSessions,
|
|
408
|
+
export { ChipiBrowserSDK, ChipiClient, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiWallets, decryptPrivateKey, encryptPrivateKey };
|
package/dist/index.js
CHANGED
|
@@ -205,7 +205,8 @@ var ChipiWallets = class {
|
|
|
205
205
|
userId,
|
|
206
206
|
walletType = "CHIPI",
|
|
207
207
|
// Default to CHIPI wallet
|
|
208
|
-
usePasskey
|
|
208
|
+
usePasskey,
|
|
209
|
+
chain
|
|
209
210
|
} = params;
|
|
210
211
|
if (!encryptKey) {
|
|
211
212
|
if (usePasskey) {
|
|
@@ -235,6 +236,7 @@ var ChipiWallets = class {
|
|
|
235
236
|
endpoint: `${shared.API_ENDPOINTS.CHIPI_WALLETS}/prepare-creation`,
|
|
236
237
|
bearerToken,
|
|
237
238
|
body: {
|
|
239
|
+
chain,
|
|
238
240
|
publicKey,
|
|
239
241
|
walletType,
|
|
240
242
|
starkKeyPubAX
|
|
@@ -258,6 +260,7 @@ var ChipiWallets = class {
|
|
|
258
260
|
userId,
|
|
259
261
|
publicKey,
|
|
260
262
|
walletType,
|
|
263
|
+
chain,
|
|
261
264
|
userSignature: {
|
|
262
265
|
r: userSignature.r.toString(),
|
|
263
266
|
s: userSignature.s.toString(),
|
|
@@ -375,7 +378,7 @@ var executePaymasterTransaction = async ({
|
|
|
375
378
|
wallet.publicKey,
|
|
376
379
|
privateKeyDecrypted
|
|
377
380
|
);
|
|
378
|
-
const
|
|
381
|
+
const { typedData: typedData2, walletType } = await client.post({
|
|
379
382
|
endpoint: "/transactions/prepare-typed-data",
|
|
380
383
|
bearerToken,
|
|
381
384
|
body: {
|
|
@@ -384,15 +387,6 @@ var executePaymasterTransaction = async ({
|
|
|
384
387
|
accountClassHash
|
|
385
388
|
}
|
|
386
389
|
});
|
|
387
|
-
let walletType;
|
|
388
|
-
let typedData2;
|
|
389
|
-
if (response.walletType) {
|
|
390
|
-
walletType = response.walletType;
|
|
391
|
-
typedData2 = response.typedData;
|
|
392
|
-
} else {
|
|
393
|
-
typedData2 = response;
|
|
394
|
-
walletType = "READY";
|
|
395
|
-
}
|
|
396
390
|
const userSignature = await account.signMessage(typedData2);
|
|
397
391
|
const result = await client.post({
|
|
398
392
|
endpoint: "/transactions/execute-sponsored-transaction",
|
|
@@ -410,7 +404,6 @@ var executePaymasterTransaction = async ({
|
|
|
410
404
|
}
|
|
411
405
|
});
|
|
412
406
|
if (!result.transactionHash) {
|
|
413
|
-
console.error("result", result);
|
|
414
407
|
throw new Error("The response does not contain the transaction hash");
|
|
415
408
|
}
|
|
416
409
|
return result.transactionHash;
|
|
@@ -484,7 +477,7 @@ var executePaymasterTransactionWithSession = async ({
|
|
|
484
477
|
);
|
|
485
478
|
}
|
|
486
479
|
const accountClassHash = shared.WALLET_CLASS_HASHES.CHIPI;
|
|
487
|
-
const
|
|
480
|
+
const typeDataResult = await client.post({
|
|
488
481
|
endpoint: "/transactions/prepare-typed-data",
|
|
489
482
|
bearerToken,
|
|
490
483
|
body: {
|
|
@@ -494,13 +487,6 @@ var executePaymasterTransactionWithSession = async ({
|
|
|
494
487
|
walletType: "CHIPI"
|
|
495
488
|
}
|
|
496
489
|
});
|
|
497
|
-
const typeDataResult = prepareResp?.typedData || prepareResp?.typed_data || prepareResp;
|
|
498
|
-
if (!typeDataResult || !typeDataResult.message || !typeDataResult.domain || !typeDataResult.types) {
|
|
499
|
-
console.error("[ChipiSDK:Session:Execute] Invalid typed data response", {
|
|
500
|
-
prepareResp
|
|
501
|
-
});
|
|
502
|
-
throw new Error("Invalid typed data response from prepare-typed-data");
|
|
503
|
-
}
|
|
504
490
|
const msgHash = starknet.typedData.getMessageHash(typeDataResult, wallet.publicKey);
|
|
505
491
|
const { r, s } = starknet.ec.starkCurve.sign(msgHash, sessionPrivateKey);
|
|
506
492
|
const sessionSignature = [
|
|
@@ -518,7 +504,7 @@ var executePaymasterTransactionWithSession = async ({
|
|
|
518
504
|
// Session signature format - array of 4 hex strings
|
|
519
505
|
userSignature: sessionSignature,
|
|
520
506
|
saveToDatabase,
|
|
521
|
-
walletType:
|
|
507
|
+
walletType: "CHIPI",
|
|
522
508
|
isSessionSignature: true
|
|
523
509
|
// Flag to indicate session signature format
|
|
524
510
|
}
|
|
@@ -669,27 +655,59 @@ var ChipiTransactions = class {
|
|
|
669
655
|
return response;
|
|
670
656
|
}
|
|
671
657
|
};
|
|
672
|
-
var
|
|
658
|
+
var ChipiExchanges = class {
|
|
659
|
+
constructor(client) {
|
|
660
|
+
this.client = client;
|
|
661
|
+
}
|
|
662
|
+
async getUsdAmount(currencyAmount, currency, bearerToken) {
|
|
663
|
+
return this.client.get({
|
|
664
|
+
endpoint: `${shared.API_ENDPOINTS.EXCHANGES}/usd-amount`,
|
|
665
|
+
bearerToken,
|
|
666
|
+
params: { currencyAmount, currency }
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
// src/sku-purchases.ts
|
|
672
|
+
var ChipiSkuPurchases = class {
|
|
673
673
|
constructor(client) {
|
|
674
674
|
this.client = client;
|
|
675
675
|
this.transactions = new ChipiTransactions(client);
|
|
676
|
+
this.exchanges = new ChipiExchanges(client);
|
|
676
677
|
}
|
|
677
678
|
/**
|
|
678
|
-
*
|
|
679
|
-
* @param params -
|
|
679
|
+
* Purchase a SKU with gasless execution
|
|
680
|
+
* @param params - Purchase parameters including transaction hash, SKU ID, wallet, etc.
|
|
680
681
|
* @param bearerToken - Authentication token for API calls
|
|
681
|
-
* @returns Promise<
|
|
682
|
+
* @returns Promise<SkuPurchaseResponse> - The purchase response with transaction details
|
|
682
683
|
*/
|
|
683
|
-
async
|
|
684
|
-
const {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
684
|
+
async purchaseSku(params, bearerToken) {
|
|
685
|
+
const {
|
|
686
|
+
skuId,
|
|
687
|
+
skuReference,
|
|
688
|
+
currencyAmount,
|
|
689
|
+
currency,
|
|
690
|
+
chain,
|
|
691
|
+
token,
|
|
692
|
+
encryptKey,
|
|
693
|
+
wallet
|
|
694
|
+
} = params;
|
|
695
|
+
const usdAmount = await this.exchanges.getUsdAmount(
|
|
696
|
+
currencyAmount,
|
|
697
|
+
currency,
|
|
698
|
+
bearerToken
|
|
699
|
+
);
|
|
700
|
+
const tokenAddress = types.STARKNET_CONTRACTS[token].contractAddress;
|
|
688
701
|
if (usdAmount <= 0) {
|
|
689
|
-
throw new Error(
|
|
702
|
+
throw new Error(
|
|
703
|
+
`Invalid USD amount: ${usdAmount}. Amount must be positive.`
|
|
704
|
+
);
|
|
690
705
|
}
|
|
691
706
|
const minUsdAmount = Math.max(usdAmount, 1e-6);
|
|
692
|
-
const parsedAmount = shared.formatAmount(
|
|
707
|
+
const parsedAmount = shared.formatAmount(
|
|
708
|
+
minUsdAmount.toString(),
|
|
709
|
+
types.STARKNET_CONTRACTS[token].decimals
|
|
710
|
+
);
|
|
693
711
|
const calls = [
|
|
694
712
|
{
|
|
695
713
|
contractAddress: tokenAddress,
|
|
@@ -721,49 +739,47 @@ var ChipiSkuTransactions = class {
|
|
|
721
739
|
metadata: {
|
|
722
740
|
service_type: shared.SERVICE_TYPES.BUY_SERVICE,
|
|
723
741
|
timestamp: Date.now(),
|
|
724
|
-
chipi_user_id: starknet.hash.starknetKeccak(
|
|
742
|
+
chipi_user_id: starknet.hash.starknetKeccak(wallet.publicKey || "0x0").toString(),
|
|
725
743
|
kyc: true,
|
|
726
744
|
amount: starknet.cairo.uint256(parsedAmount)
|
|
727
745
|
}
|
|
728
746
|
})
|
|
729
747
|
}
|
|
730
748
|
];
|
|
731
|
-
const
|
|
749
|
+
const txHash = await this.transactions.executeTransaction({
|
|
732
750
|
params: {
|
|
733
|
-
encryptKey
|
|
751
|
+
encryptKey,
|
|
734
752
|
wallet,
|
|
735
753
|
calls
|
|
736
754
|
},
|
|
737
755
|
bearerToken,
|
|
738
756
|
saveToDatabase: false
|
|
739
|
-
// Internal: SKU transactions don't save to transactions table
|
|
740
757
|
});
|
|
741
|
-
const
|
|
758
|
+
const body = {
|
|
759
|
+
transactionHash: txHash,
|
|
742
760
|
walletAddress: wallet.publicKey,
|
|
743
761
|
skuId,
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
transactionHash,
|
|
749
|
-
usdAmount: minUsdAmount
|
|
762
|
+
skuReference,
|
|
763
|
+
chain,
|
|
764
|
+
token,
|
|
765
|
+
currencyAmount
|
|
750
766
|
};
|
|
751
767
|
const response = await this.client.post({
|
|
752
|
-
endpoint: `${shared.API_ENDPOINTS.
|
|
768
|
+
endpoint: `${shared.API_ENDPOINTS.SKU_PURCHASES}`,
|
|
753
769
|
bearerToken,
|
|
754
|
-
body
|
|
770
|
+
body
|
|
755
771
|
});
|
|
756
772
|
return response;
|
|
757
773
|
}
|
|
758
774
|
/**
|
|
759
|
-
* Get a SKU
|
|
760
|
-
* @param id - The SKU
|
|
775
|
+
* Get a SKU purchase by id
|
|
776
|
+
* @param id - The SKU purchase id
|
|
761
777
|
* @param bearerToken - Authentication token for API calls
|
|
762
|
-
* @returns Promise<
|
|
778
|
+
* @returns Promise<SkuPurchaseResponse> - Single SKU purchase
|
|
763
779
|
*/
|
|
764
|
-
async
|
|
780
|
+
async getSkuPurchase(id, bearerToken) {
|
|
765
781
|
const response = await this.client.get({
|
|
766
|
-
endpoint: `${shared.API_ENDPOINTS.
|
|
782
|
+
endpoint: `${shared.API_ENDPOINTS.SKU_PURCHASES}/${id}`,
|
|
767
783
|
bearerToken
|
|
768
784
|
});
|
|
769
785
|
return response;
|
|
@@ -1222,10 +1238,11 @@ var ChipiSDK = class {
|
|
|
1222
1238
|
this.apiSecretKey = config.apiSecretKey;
|
|
1223
1239
|
this.wallets = new ChipiWallets(this.client);
|
|
1224
1240
|
this.transactions = new ChipiTransactions(this.client);
|
|
1225
|
-
this.
|
|
1241
|
+
this.skuPurchases = new ChipiSkuPurchases(this.client);
|
|
1226
1242
|
this.skus = new ChipiSkus(this.client);
|
|
1227
1243
|
this.users = new Users(this.client);
|
|
1228
1244
|
this.sessions = new ChipiSessions(this.client);
|
|
1245
|
+
this.exchanges = new ChipiExchanges(this.client);
|
|
1229
1246
|
this.executeTransaction = this.executeTransaction.bind(this);
|
|
1230
1247
|
this.executeTransactionWithSession = this.executeTransactionWithSession.bind(this);
|
|
1231
1248
|
this.transfer = this.transfer.bind(this);
|
|
@@ -1235,7 +1252,8 @@ var ChipiSDK = class {
|
|
|
1235
1252
|
this.callAnyContract = this.callAnyContract.bind(this);
|
|
1236
1253
|
this.createWallet = this.createWallet.bind(this);
|
|
1237
1254
|
this.recordSendTransaction = this.recordSendTransaction.bind(this);
|
|
1238
|
-
this.
|
|
1255
|
+
this.purchaseSku = this.purchaseSku.bind(this);
|
|
1256
|
+
this.getUsdAmount = this.getUsdAmount.bind(this);
|
|
1239
1257
|
}
|
|
1240
1258
|
/**
|
|
1241
1259
|
* Resolve bearer token - uses provided token or falls back to apiSecretKey
|
|
@@ -1450,17 +1468,26 @@ var ChipiSDK = class {
|
|
|
1450
1468
|
});
|
|
1451
1469
|
}
|
|
1452
1470
|
/**
|
|
1453
|
-
*
|
|
1471
|
+
* Purchase a SKU
|
|
1454
1472
|
*/
|
|
1455
|
-
async
|
|
1473
|
+
async purchaseSku({
|
|
1456
1474
|
params,
|
|
1457
1475
|
bearerToken
|
|
1458
1476
|
}) {
|
|
1459
|
-
return this.
|
|
1477
|
+
return this.skuPurchases.purchaseSku(
|
|
1460
1478
|
params,
|
|
1461
1479
|
this.resolveBearerToken(bearerToken)
|
|
1462
1480
|
);
|
|
1463
1481
|
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Get a SKU purchase by id
|
|
1484
|
+
*/
|
|
1485
|
+
async getSkuPurchase(id, bearerToken) {
|
|
1486
|
+
return this.skuPurchases.getSkuPurchase(
|
|
1487
|
+
id,
|
|
1488
|
+
this.resolveBearerToken(bearerToken)
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1464
1491
|
/// SKUS
|
|
1465
1492
|
async getSkuList(params, bearerToken) {
|
|
1466
1493
|
return this.skus.getSkuList(params, this.resolveBearerToken(bearerToken));
|
|
@@ -1475,6 +1502,13 @@ var ChipiSDK = class {
|
|
|
1475
1502
|
async createUser(params, bearerToken) {
|
|
1476
1503
|
return this.users.createUser(params, this.resolveBearerToken(bearerToken));
|
|
1477
1504
|
}
|
|
1505
|
+
async getUsdAmount(currencyAmount, currency, bearerToken) {
|
|
1506
|
+
return this.exchanges.getUsdAmount(
|
|
1507
|
+
currencyAmount,
|
|
1508
|
+
currency,
|
|
1509
|
+
this.resolveBearerToken(bearerToken)
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1478
1512
|
};
|
|
1479
1513
|
|
|
1480
1514
|
// src/chipi-server-sdk.ts
|
|
@@ -1505,7 +1539,7 @@ exports.ChipiClient = ChipiClient;
|
|
|
1505
1539
|
exports.ChipiSDK = ChipiSDK;
|
|
1506
1540
|
exports.ChipiServerSDK = ChipiServerSDK;
|
|
1507
1541
|
exports.ChipiSessions = ChipiSessions;
|
|
1508
|
-
exports.
|
|
1542
|
+
exports.ChipiSkuPurchases = ChipiSkuPurchases;
|
|
1509
1543
|
exports.ChipiSkus = ChipiSkus;
|
|
1510
1544
|
exports.ChipiTransactions = ChipiTransactions;
|
|
1511
1545
|
exports.ChipiWallets = ChipiWallets;
|