@chipi-stack/backend 11.21.0 → 12.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-E8WQVssY.d.mts → client-43S3tkH3.d.mts} +6 -0
- package/dist/{client-E8WQVssY.d.ts → client-43S3tkH3.d.ts} +6 -0
- package/dist/index.d.mts +204 -6
- package/dist/index.d.ts +204 -6
- package/dist/index.js +645 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +647 -79
- package/dist/index.mjs.map +1 -1
- package/dist/skuTransactions.d.mts +1 -1
- package/dist/skuTransactions.d.ts +1 -1
- package/dist/skuTransactions.js +38 -58
- package/dist/skuTransactions.js.map +1 -1
- package/dist/skuTransactions.mjs +39 -59
- package/dist/skuTransactions.mjs.map +1 -1
- package/dist/skus.d.mts +1 -1
- package/dist/skus.d.ts +1 -1
- package/dist/transactions.d.mts +1 -1
- package/dist/transactions.d.ts +1 -1
- package/dist/transactions.js +33 -53
- package/dist/transactions.js.map +1 -1
- package/dist/transactions.mjs +34 -54
- package/dist/transactions.mjs.map +1 -1
- package/dist/wallets.d.mts +8 -4
- package/dist/wallets.d.ts +8 -4
- package/dist/wallets.js +43 -15
- package/dist/wallets.js.map +1 -1
- package/dist/wallets.mjs +45 -17
- package/dist/wallets.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -8,12 +8,18 @@ declare class ChipiClient {
|
|
|
8
8
|
baseUrl: string;
|
|
9
9
|
nodeUrl: string;
|
|
10
10
|
private customAlphaUrl?;
|
|
11
|
+
private sdkVersion;
|
|
11
12
|
constructor(config: ChipiSDKConfig);
|
|
12
13
|
/**
|
|
13
14
|
* Get the API public key (for internal SDK use)
|
|
14
15
|
*/
|
|
15
16
|
getApiPublicKey(): string;
|
|
16
17
|
private getBaseUrl;
|
|
18
|
+
/**
|
|
19
|
+
* Add API version query parameters to track the API version being used
|
|
20
|
+
* This helps the backend handle versioning and track which SDK versions are in use
|
|
21
|
+
*/
|
|
22
|
+
private addVersionParams;
|
|
17
23
|
private getHeaders;
|
|
18
24
|
get<T>({ endpoint, params, bearerToken, }: {
|
|
19
25
|
endpoint: string;
|
|
@@ -8,12 +8,18 @@ declare class ChipiClient {
|
|
|
8
8
|
baseUrl: string;
|
|
9
9
|
nodeUrl: string;
|
|
10
10
|
private customAlphaUrl?;
|
|
11
|
+
private sdkVersion;
|
|
11
12
|
constructor(config: ChipiSDKConfig);
|
|
12
13
|
/**
|
|
13
14
|
* Get the API public key (for internal SDK use)
|
|
14
15
|
*/
|
|
15
16
|
getApiPublicKey(): string;
|
|
16
17
|
private getBaseUrl;
|
|
18
|
+
/**
|
|
19
|
+
* Add API version query parameters to track the API version being used
|
|
20
|
+
* This helps the backend handle versioning and track which SDK versions are in use
|
|
21
|
+
*/
|
|
22
|
+
private addVersionParams;
|
|
17
23
|
private getHeaders;
|
|
18
24
|
get<T>({ endpoint, params, bearerToken, }: {
|
|
19
25
|
endpoint: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as _chipi_stack_types from '@chipi-stack/types';
|
|
2
|
-
import { GetUserParams, User, WalletData, CreateUserParams, ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuTransactionParams, SkuTransaction, GetSkuListQuery, Sku, ChipiServerSDKConfig, ChipiBrowserSDKConfig } 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, CreateSkuTransactionParams, SkuTransaction, 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
6
|
import { ChipiSkuTransactions } from './skuTransactions.mjs';
|
|
7
7
|
import { ChipiSkus } from './skus.mjs';
|
|
8
|
-
import { C as ChipiClient } from './client-
|
|
8
|
+
import { C as ChipiClient } from './client-43S3tkH3.mjs';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* User management
|
|
@@ -31,6 +31,167 @@ declare class Users {
|
|
|
31
31
|
createUser(params: CreateUserParams, bearerToken: string): Promise<User>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Session key management for CHIPI wallets (SNIP-9 compatible).
|
|
36
|
+
*
|
|
37
|
+
* Session keys enable temporary, delegated access to execute transactions
|
|
38
|
+
* without requiring the owner's private key for each operation.
|
|
39
|
+
*
|
|
40
|
+
* @see https://github.com/chipi-pay/sessions-smart-contract
|
|
41
|
+
*/
|
|
42
|
+
declare class ChipiSessions {
|
|
43
|
+
private client;
|
|
44
|
+
constructor(client: ChipiClient);
|
|
45
|
+
/**
|
|
46
|
+
* Validate that the wallet is a CHIPI wallet (required for session operations).
|
|
47
|
+
* Throws ChipiSessionError if wallet type is not CHIPI.
|
|
48
|
+
*/
|
|
49
|
+
private validateChipiWallet;
|
|
50
|
+
/**
|
|
51
|
+
* Convert a Uint8Array to hex string with 0x prefix.
|
|
52
|
+
*/
|
|
53
|
+
private toHex;
|
|
54
|
+
/**
|
|
55
|
+
* Generate a new session keypair locally.
|
|
56
|
+
*
|
|
57
|
+
* This method generates the session keys but does NOT register them on-chain.
|
|
58
|
+
* The returned SessionKeyData should be stored by the developer externally
|
|
59
|
+
* (e.g., in Clerk metadata, database, etc.) - the SDK does NOT persist this.
|
|
60
|
+
*
|
|
61
|
+
* After generating, call `addSessionKeyToContract()` to register the session on-chain.
|
|
62
|
+
*
|
|
63
|
+
* @param params - Session creation parameters
|
|
64
|
+
* @returns SessionKeyData for external storage
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const session = sdk.sessions.createSessionKey({
|
|
69
|
+
* encryptKey: userEncryptKey,
|
|
70
|
+
* durationSeconds: 21600 // 6 hours
|
|
71
|
+
* });
|
|
72
|
+
* // Store session externally (e.g., in Clerk metadata)
|
|
73
|
+
* await saveToClerk(session);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
createSessionKey(params: CreateSessionKeyParams): SessionKeyData;
|
|
77
|
+
/**
|
|
78
|
+
* Register a session key on the smart contract.
|
|
79
|
+
*
|
|
80
|
+
* This executes a sponsored transaction (using owner signature) to call
|
|
81
|
+
* `add_or_update_session_key` on the CHIPI wallet contract.
|
|
82
|
+
*
|
|
83
|
+
* The session must be registered before it can be used for transactions.
|
|
84
|
+
*
|
|
85
|
+
* @param params - Session registration parameters
|
|
86
|
+
* @param bearerToken - Authentication token
|
|
87
|
+
* @returns Transaction hash
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const txHash = await sdk.sessions.addSessionKeyToContract({
|
|
92
|
+
* encryptKey: userEncryptKey,
|
|
93
|
+
* wallet: userWallet,
|
|
94
|
+
* sessionConfig: {
|
|
95
|
+
* sessionPublicKey: session.publicKey,
|
|
96
|
+
* validUntil: session.validUntil,
|
|
97
|
+
* maxCalls: 1000,
|
|
98
|
+
* allowedEntrypoints: [] // empty = all allowed
|
|
99
|
+
* }
|
|
100
|
+
* }, bearerToken);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
addSessionKeyToContract(params: AddSessionKeyParams, bearerToken: string): Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Revoke a session key from the smart contract.
|
|
106
|
+
*
|
|
107
|
+
* This executes a sponsored transaction (using owner signature) to call
|
|
108
|
+
* `revoke_session_key` on the CHIPI wallet contract.
|
|
109
|
+
*
|
|
110
|
+
* After revocation, the session key can no longer be used for transactions.
|
|
111
|
+
*
|
|
112
|
+
* @param params - Session revocation parameters
|
|
113
|
+
* @param bearerToken - Authentication token
|
|
114
|
+
* @returns Transaction hash
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const txHash = await sdk.sessions.revokeSessionKey({
|
|
119
|
+
* encryptKey: userEncryptKey,
|
|
120
|
+
* wallet: userWallet,
|
|
121
|
+
* sessionPublicKey: session.publicKey
|
|
122
|
+
* }, bearerToken);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
revokeSessionKey(params: RevokeSessionKeyParams, bearerToken: string): Promise<string>;
|
|
126
|
+
/**
|
|
127
|
+
* Query session data from the smart contract.
|
|
128
|
+
*
|
|
129
|
+
* This is a read-only call that does not require signing or gas.
|
|
130
|
+
*
|
|
131
|
+
* @param params - Query parameters
|
|
132
|
+
* @returns Session data including status, remaining calls, and allowed entrypoints
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const sessionData = await sdk.sessions.getSessionData({
|
|
137
|
+
* walletAddress: userWallet.publicKey,
|
|
138
|
+
* sessionPublicKey: session.publicKey
|
|
139
|
+
* });
|
|
140
|
+
* if (sessionData.isActive) {
|
|
141
|
+
* console.log(`Session has ${sessionData.remainingCalls} calls remaining`);
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* NOTE: This method intentionally does NOT validate walletType because:
|
|
146
|
+
* 1. It's a read-only query - no state change or risk
|
|
147
|
+
* 2. Non-CHIPI wallets will simply return isActive=false (graceful failure)
|
|
148
|
+
* 3. It doesn't require walletType parameter at all - only walletAddress
|
|
149
|
+
* Adding validation would require changing the interface for no functional benefit.
|
|
150
|
+
*/
|
|
151
|
+
getSessionData(params: GetSessionDataParams): Promise<SessionDataResponse>;
|
|
152
|
+
/**
|
|
153
|
+
* Execute a gasless transaction using a session key.
|
|
154
|
+
*
|
|
155
|
+
* This uses the 4-element session signature format instead of owner signature.
|
|
156
|
+
* The session must be:
|
|
157
|
+
* 1. Generated via `createSessionKey()`
|
|
158
|
+
* 2. Registered on-chain via `addSessionKeyToContract()`
|
|
159
|
+
*
|
|
160
|
+
* CHIPI wallets only - will throw if wallet type is not CHIPI.
|
|
161
|
+
*
|
|
162
|
+
* @param params - Session execution parameters
|
|
163
|
+
* @param bearerToken - Authentication token
|
|
164
|
+
* @returns Transaction hash
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* // 1. Create session key (store externally)
|
|
169
|
+
* const session = sdk.sessions.createSessionKey({ encryptKey });
|
|
170
|
+
*
|
|
171
|
+
* // 2. Register on contract (one-time)
|
|
172
|
+
* await sdk.sessions.addSessionKeyToContract({
|
|
173
|
+
* encryptKey,
|
|
174
|
+
* wallet,
|
|
175
|
+
* sessionConfig: {
|
|
176
|
+
* sessionPublicKey: session.publicKey,
|
|
177
|
+
* validUntil: session.validUntil,
|
|
178
|
+
* maxCalls: 1000,
|
|
179
|
+
* allowedEntrypoints: []
|
|
180
|
+
* }
|
|
181
|
+
* }, bearerToken);
|
|
182
|
+
*
|
|
183
|
+
* // 3. Execute transactions with session (no owner key needed)
|
|
184
|
+
* const txHash = await sdk.sessions.executeTransactionWithSession({
|
|
185
|
+
* encryptKey,
|
|
186
|
+
* wallet,
|
|
187
|
+
* session,
|
|
188
|
+
* calls
|
|
189
|
+
* }, bearerToken);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
executeTransactionWithSession(params: ExecuteWithSessionParams, bearerToken: string): Promise<string>;
|
|
193
|
+
}
|
|
194
|
+
|
|
34
195
|
/**
|
|
35
196
|
* Main Chipi SDK class
|
|
36
197
|
*/
|
|
@@ -43,6 +204,7 @@ declare class ChipiSDK {
|
|
|
43
204
|
readonly skuTransactions: ChipiSkuTransactions;
|
|
44
205
|
readonly skus: ChipiSkus;
|
|
45
206
|
readonly users: Users;
|
|
207
|
+
readonly sessions: ChipiSessions;
|
|
46
208
|
constructor(config: ChipiSDKConfig);
|
|
47
209
|
/**
|
|
48
210
|
* Resolve bearer token - uses provided token or falls back to apiSecretKey
|
|
@@ -55,6 +217,44 @@ declare class ChipiSDK {
|
|
|
55
217
|
params: ExecuteTransactionParams;
|
|
56
218
|
bearerToken?: string;
|
|
57
219
|
}): Promise<string>;
|
|
220
|
+
/**
|
|
221
|
+
* Execute a gasless transaction using a session key.
|
|
222
|
+
*
|
|
223
|
+
* This uses the 4-element session signature format instead of owner signature.
|
|
224
|
+
* The session must be:
|
|
225
|
+
* 1. Generated via `sessions.createSessionKey()`
|
|
226
|
+
* 2. Registered on-chain via `sessions.addSessionKeyToContract()`
|
|
227
|
+
*
|
|
228
|
+
* CHIPI wallets only - will throw if wallet type is not CHIPI.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* // 1. Create session key (store externally)
|
|
233
|
+
* const session = sdk.sessions.createSessionKey({ encryptKey });
|
|
234
|
+
*
|
|
235
|
+
* // 2. Register on contract (one-time)
|
|
236
|
+
* await sdk.sessions.addSessionKeyToContract({
|
|
237
|
+
* encryptKey,
|
|
238
|
+
* wallet,
|
|
239
|
+
* sessionConfig: {
|
|
240
|
+
* sessionPublicKey: session.publicKey,
|
|
241
|
+
* validUntil: session.validUntil,
|
|
242
|
+
* maxCalls: 1000,
|
|
243
|
+
* allowedEntrypoints: []
|
|
244
|
+
* }
|
|
245
|
+
* }, bearerToken);
|
|
246
|
+
*
|
|
247
|
+
* // 3. Execute transactions with session (no owner key needed)
|
|
248
|
+
* const txHash = await sdk.executeTransactionWithSession({
|
|
249
|
+
* params: { encryptKey, wallet, session, calls },
|
|
250
|
+
* bearerToken
|
|
251
|
+
* });
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
executeTransactionWithSession({ params, bearerToken, }: {
|
|
255
|
+
params: ExecuteWithSessionParams;
|
|
256
|
+
bearerToken?: string;
|
|
257
|
+
}): Promise<string>;
|
|
58
258
|
/**
|
|
59
259
|
* Transfer tokens
|
|
60
260
|
*/
|
|
@@ -102,9 +302,7 @@ declare class ChipiSDK {
|
|
|
102
302
|
bearerToken?: string;
|
|
103
303
|
}): Promise<Transaction>;
|
|
104
304
|
getTransactionList(query: GetTransactionListQuery, bearerToken?: string): Promise<PaginatedResponse<Transaction>>;
|
|
105
|
-
getWallet(params: GetWalletParams, bearerToken?: string): Promise<
|
|
106
|
-
normalizedPublicKey: string;
|
|
107
|
-
}) | null>;
|
|
305
|
+
getWallet(params: GetWalletParams, bearerToken?: string): Promise<_chipi_stack_types.GetWalletResponse | null>;
|
|
108
306
|
getTokenBalance(params: GetTokenBalanceParams, bearerToken?: string): Promise<GetTokenBalanceResponse>;
|
|
109
307
|
/**
|
|
110
308
|
* Create a SKU transaction
|
|
@@ -195,4 +393,4 @@ declare class ChipiBrowserSDK extends ChipiSDK {
|
|
|
195
393
|
declare const encryptPrivateKey: (privateKey: string, password: string) => string;
|
|
196
394
|
declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string;
|
|
197
395
|
|
|
198
|
-
export { ChipiBrowserSDK, ChipiClient, ChipiSDK, ChipiServerSDK, ChipiSkuTransactions, ChipiSkus, ChipiTransactions, ChipiWallets, decryptPrivateKey, encryptPrivateKey };
|
|
396
|
+
export { ChipiBrowserSDK, ChipiClient, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuTransactions, ChipiSkus, ChipiTransactions, ChipiWallets, decryptPrivateKey, encryptPrivateKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as _chipi_stack_types from '@chipi-stack/types';
|
|
2
|
-
import { GetUserParams, User, WalletData, CreateUserParams, ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuTransactionParams, SkuTransaction, GetSkuListQuery, Sku, ChipiServerSDKConfig, ChipiBrowserSDKConfig } 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, CreateSkuTransactionParams, SkuTransaction, 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
6
|
import { ChipiSkuTransactions } from './skuTransactions.js';
|
|
7
7
|
import { ChipiSkus } from './skus.js';
|
|
8
|
-
import { C as ChipiClient } from './client-
|
|
8
|
+
import { C as ChipiClient } from './client-43S3tkH3.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* User management
|
|
@@ -31,6 +31,167 @@ declare class Users {
|
|
|
31
31
|
createUser(params: CreateUserParams, bearerToken: string): Promise<User>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Session key management for CHIPI wallets (SNIP-9 compatible).
|
|
36
|
+
*
|
|
37
|
+
* Session keys enable temporary, delegated access to execute transactions
|
|
38
|
+
* without requiring the owner's private key for each operation.
|
|
39
|
+
*
|
|
40
|
+
* @see https://github.com/chipi-pay/sessions-smart-contract
|
|
41
|
+
*/
|
|
42
|
+
declare class ChipiSessions {
|
|
43
|
+
private client;
|
|
44
|
+
constructor(client: ChipiClient);
|
|
45
|
+
/**
|
|
46
|
+
* Validate that the wallet is a CHIPI wallet (required for session operations).
|
|
47
|
+
* Throws ChipiSessionError if wallet type is not CHIPI.
|
|
48
|
+
*/
|
|
49
|
+
private validateChipiWallet;
|
|
50
|
+
/**
|
|
51
|
+
* Convert a Uint8Array to hex string with 0x prefix.
|
|
52
|
+
*/
|
|
53
|
+
private toHex;
|
|
54
|
+
/**
|
|
55
|
+
* Generate a new session keypair locally.
|
|
56
|
+
*
|
|
57
|
+
* This method generates the session keys but does NOT register them on-chain.
|
|
58
|
+
* The returned SessionKeyData should be stored by the developer externally
|
|
59
|
+
* (e.g., in Clerk metadata, database, etc.) - the SDK does NOT persist this.
|
|
60
|
+
*
|
|
61
|
+
* After generating, call `addSessionKeyToContract()` to register the session on-chain.
|
|
62
|
+
*
|
|
63
|
+
* @param params - Session creation parameters
|
|
64
|
+
* @returns SessionKeyData for external storage
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const session = sdk.sessions.createSessionKey({
|
|
69
|
+
* encryptKey: userEncryptKey,
|
|
70
|
+
* durationSeconds: 21600 // 6 hours
|
|
71
|
+
* });
|
|
72
|
+
* // Store session externally (e.g., in Clerk metadata)
|
|
73
|
+
* await saveToClerk(session);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
createSessionKey(params: CreateSessionKeyParams): SessionKeyData;
|
|
77
|
+
/**
|
|
78
|
+
* Register a session key on the smart contract.
|
|
79
|
+
*
|
|
80
|
+
* This executes a sponsored transaction (using owner signature) to call
|
|
81
|
+
* `add_or_update_session_key` on the CHIPI wallet contract.
|
|
82
|
+
*
|
|
83
|
+
* The session must be registered before it can be used for transactions.
|
|
84
|
+
*
|
|
85
|
+
* @param params - Session registration parameters
|
|
86
|
+
* @param bearerToken - Authentication token
|
|
87
|
+
* @returns Transaction hash
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const txHash = await sdk.sessions.addSessionKeyToContract({
|
|
92
|
+
* encryptKey: userEncryptKey,
|
|
93
|
+
* wallet: userWallet,
|
|
94
|
+
* sessionConfig: {
|
|
95
|
+
* sessionPublicKey: session.publicKey,
|
|
96
|
+
* validUntil: session.validUntil,
|
|
97
|
+
* maxCalls: 1000,
|
|
98
|
+
* allowedEntrypoints: [] // empty = all allowed
|
|
99
|
+
* }
|
|
100
|
+
* }, bearerToken);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
addSessionKeyToContract(params: AddSessionKeyParams, bearerToken: string): Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Revoke a session key from the smart contract.
|
|
106
|
+
*
|
|
107
|
+
* This executes a sponsored transaction (using owner signature) to call
|
|
108
|
+
* `revoke_session_key` on the CHIPI wallet contract.
|
|
109
|
+
*
|
|
110
|
+
* After revocation, the session key can no longer be used for transactions.
|
|
111
|
+
*
|
|
112
|
+
* @param params - Session revocation parameters
|
|
113
|
+
* @param bearerToken - Authentication token
|
|
114
|
+
* @returns Transaction hash
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const txHash = await sdk.sessions.revokeSessionKey({
|
|
119
|
+
* encryptKey: userEncryptKey,
|
|
120
|
+
* wallet: userWallet,
|
|
121
|
+
* sessionPublicKey: session.publicKey
|
|
122
|
+
* }, bearerToken);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
revokeSessionKey(params: RevokeSessionKeyParams, bearerToken: string): Promise<string>;
|
|
126
|
+
/**
|
|
127
|
+
* Query session data from the smart contract.
|
|
128
|
+
*
|
|
129
|
+
* This is a read-only call that does not require signing or gas.
|
|
130
|
+
*
|
|
131
|
+
* @param params - Query parameters
|
|
132
|
+
* @returns Session data including status, remaining calls, and allowed entrypoints
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const sessionData = await sdk.sessions.getSessionData({
|
|
137
|
+
* walletAddress: userWallet.publicKey,
|
|
138
|
+
* sessionPublicKey: session.publicKey
|
|
139
|
+
* });
|
|
140
|
+
* if (sessionData.isActive) {
|
|
141
|
+
* console.log(`Session has ${sessionData.remainingCalls} calls remaining`);
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* NOTE: This method intentionally does NOT validate walletType because:
|
|
146
|
+
* 1. It's a read-only query - no state change or risk
|
|
147
|
+
* 2. Non-CHIPI wallets will simply return isActive=false (graceful failure)
|
|
148
|
+
* 3. It doesn't require walletType parameter at all - only walletAddress
|
|
149
|
+
* Adding validation would require changing the interface for no functional benefit.
|
|
150
|
+
*/
|
|
151
|
+
getSessionData(params: GetSessionDataParams): Promise<SessionDataResponse>;
|
|
152
|
+
/**
|
|
153
|
+
* Execute a gasless transaction using a session key.
|
|
154
|
+
*
|
|
155
|
+
* This uses the 4-element session signature format instead of owner signature.
|
|
156
|
+
* The session must be:
|
|
157
|
+
* 1. Generated via `createSessionKey()`
|
|
158
|
+
* 2. Registered on-chain via `addSessionKeyToContract()`
|
|
159
|
+
*
|
|
160
|
+
* CHIPI wallets only - will throw if wallet type is not CHIPI.
|
|
161
|
+
*
|
|
162
|
+
* @param params - Session execution parameters
|
|
163
|
+
* @param bearerToken - Authentication token
|
|
164
|
+
* @returns Transaction hash
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* // 1. Create session key (store externally)
|
|
169
|
+
* const session = sdk.sessions.createSessionKey({ encryptKey });
|
|
170
|
+
*
|
|
171
|
+
* // 2. Register on contract (one-time)
|
|
172
|
+
* await sdk.sessions.addSessionKeyToContract({
|
|
173
|
+
* encryptKey,
|
|
174
|
+
* wallet,
|
|
175
|
+
* sessionConfig: {
|
|
176
|
+
* sessionPublicKey: session.publicKey,
|
|
177
|
+
* validUntil: session.validUntil,
|
|
178
|
+
* maxCalls: 1000,
|
|
179
|
+
* allowedEntrypoints: []
|
|
180
|
+
* }
|
|
181
|
+
* }, bearerToken);
|
|
182
|
+
*
|
|
183
|
+
* // 3. Execute transactions with session (no owner key needed)
|
|
184
|
+
* const txHash = await sdk.sessions.executeTransactionWithSession({
|
|
185
|
+
* encryptKey,
|
|
186
|
+
* wallet,
|
|
187
|
+
* session,
|
|
188
|
+
* calls
|
|
189
|
+
* }, bearerToken);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
executeTransactionWithSession(params: ExecuteWithSessionParams, bearerToken: string): Promise<string>;
|
|
193
|
+
}
|
|
194
|
+
|
|
34
195
|
/**
|
|
35
196
|
* Main Chipi SDK class
|
|
36
197
|
*/
|
|
@@ -43,6 +204,7 @@ declare class ChipiSDK {
|
|
|
43
204
|
readonly skuTransactions: ChipiSkuTransactions;
|
|
44
205
|
readonly skus: ChipiSkus;
|
|
45
206
|
readonly users: Users;
|
|
207
|
+
readonly sessions: ChipiSessions;
|
|
46
208
|
constructor(config: ChipiSDKConfig);
|
|
47
209
|
/**
|
|
48
210
|
* Resolve bearer token - uses provided token or falls back to apiSecretKey
|
|
@@ -55,6 +217,44 @@ declare class ChipiSDK {
|
|
|
55
217
|
params: ExecuteTransactionParams;
|
|
56
218
|
bearerToken?: string;
|
|
57
219
|
}): Promise<string>;
|
|
220
|
+
/**
|
|
221
|
+
* Execute a gasless transaction using a session key.
|
|
222
|
+
*
|
|
223
|
+
* This uses the 4-element session signature format instead of owner signature.
|
|
224
|
+
* The session must be:
|
|
225
|
+
* 1. Generated via `sessions.createSessionKey()`
|
|
226
|
+
* 2. Registered on-chain via `sessions.addSessionKeyToContract()`
|
|
227
|
+
*
|
|
228
|
+
* CHIPI wallets only - will throw if wallet type is not CHIPI.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* // 1. Create session key (store externally)
|
|
233
|
+
* const session = sdk.sessions.createSessionKey({ encryptKey });
|
|
234
|
+
*
|
|
235
|
+
* // 2. Register on contract (one-time)
|
|
236
|
+
* await sdk.sessions.addSessionKeyToContract({
|
|
237
|
+
* encryptKey,
|
|
238
|
+
* wallet,
|
|
239
|
+
* sessionConfig: {
|
|
240
|
+
* sessionPublicKey: session.publicKey,
|
|
241
|
+
* validUntil: session.validUntil,
|
|
242
|
+
* maxCalls: 1000,
|
|
243
|
+
* allowedEntrypoints: []
|
|
244
|
+
* }
|
|
245
|
+
* }, bearerToken);
|
|
246
|
+
*
|
|
247
|
+
* // 3. Execute transactions with session (no owner key needed)
|
|
248
|
+
* const txHash = await sdk.executeTransactionWithSession({
|
|
249
|
+
* params: { encryptKey, wallet, session, calls },
|
|
250
|
+
* bearerToken
|
|
251
|
+
* });
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
executeTransactionWithSession({ params, bearerToken, }: {
|
|
255
|
+
params: ExecuteWithSessionParams;
|
|
256
|
+
bearerToken?: string;
|
|
257
|
+
}): Promise<string>;
|
|
58
258
|
/**
|
|
59
259
|
* Transfer tokens
|
|
60
260
|
*/
|
|
@@ -102,9 +302,7 @@ declare class ChipiSDK {
|
|
|
102
302
|
bearerToken?: string;
|
|
103
303
|
}): Promise<Transaction>;
|
|
104
304
|
getTransactionList(query: GetTransactionListQuery, bearerToken?: string): Promise<PaginatedResponse<Transaction>>;
|
|
105
|
-
getWallet(params: GetWalletParams, bearerToken?: string): Promise<
|
|
106
|
-
normalizedPublicKey: string;
|
|
107
|
-
}) | null>;
|
|
305
|
+
getWallet(params: GetWalletParams, bearerToken?: string): Promise<_chipi_stack_types.GetWalletResponse | null>;
|
|
108
306
|
getTokenBalance(params: GetTokenBalanceParams, bearerToken?: string): Promise<GetTokenBalanceResponse>;
|
|
109
307
|
/**
|
|
110
308
|
* Create a SKU transaction
|
|
@@ -195,4 +393,4 @@ declare class ChipiBrowserSDK extends ChipiSDK {
|
|
|
195
393
|
declare const encryptPrivateKey: (privateKey: string, password: string) => string;
|
|
196
394
|
declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string;
|
|
197
395
|
|
|
198
|
-
export { ChipiBrowserSDK, ChipiClient, ChipiSDK, ChipiServerSDK, ChipiSkuTransactions, ChipiSkus, ChipiTransactions, ChipiWallets, decryptPrivateKey, encryptPrivateKey };
|
|
396
|
+
export { ChipiBrowserSDK, ChipiClient, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuTransactions, ChipiSkus, ChipiTransactions, ChipiWallets, decryptPrivateKey, encryptPrivateKey };
|