@avacuscc/sdk 0.1.0 → 0.2.1
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/README.md +267 -0
- package/package.json +4 -4
- package/packages/sdk/dist/index.d.mts +675 -7
- package/packages/sdk/dist/index.d.ts +675 -7
- package/packages/sdk/dist/index.js +532 -18
- package/packages/sdk/dist/index.mjs +844 -18
- package/packages/sdk/dist/{sns-D0rtlsZp.d.mts → sns-NuV2JpAA.d.mts} +24 -1
- package/packages/sdk/dist/{sns-D0rtlsZp.d.ts → sns-NuV2JpAA.d.ts} +24 -1
- package/packages/sdk/dist/sns.d.mts +1 -1
- package/packages/sdk/dist/sns.d.ts +1 -1
- package/packages/sdk/dist/sns.js +71 -14
- package/packages/sdk/dist/sns.mjs +383 -9
- package/packages/sdk/dist/chunk-T5BAFYHX.mjs +0 -342
|
@@ -22,11 +22,14 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
AVACUS_ENDPOINTS: () => AVACUS_ENDPOINTS,
|
|
24
24
|
AvacusClient: () => AvacusClient,
|
|
25
|
+
BASE_CONNECT_SIGNED_MSG: () => BASE_CONNECT_SIGNED_MSG,
|
|
26
|
+
BASE_GAS_SPONSOR_SIGNED_MSG: () => BASE_GAS_SPONSOR_SIGNED_MSG,
|
|
27
|
+
BASE_REDIRECT_SIGNED_MSG: () => BASE_REDIRECT_SIGNED_MSG,
|
|
25
28
|
BalancerService: () => BalancerService,
|
|
26
29
|
DEFAULT_BASE_SIGNED_MESSAGE: () => DEFAULT_BASE_SIGNED_MESSAGE,
|
|
30
|
+
DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION: () => DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION,
|
|
27
31
|
GAS_ACCOUNT_SERVICE_PATH: () => GAS_ACCOUNT_SERVICE_PATH,
|
|
28
32
|
GasAccountService: () => GasAccountService,
|
|
29
|
-
HttpAdapter: () => HttpAdapter,
|
|
30
33
|
SNS_SERVICE_PATH: () => SNS_SERVICE_PATH,
|
|
31
34
|
SnsAuthClient: () => SnsAuthClient,
|
|
32
35
|
SnsService: () => SnsService,
|
|
@@ -136,6 +139,49 @@ var HttpAdapter = class {
|
|
|
136
139
|
});
|
|
137
140
|
return this.parseResponse(response, "POST", path);
|
|
138
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Sends an HTTP PUT request with a JSON body to a path relative to this adapter base URL.
|
|
144
|
+
*
|
|
145
|
+
* @param path Relative endpoint path.
|
|
146
|
+
* @param body Serializable request payload.
|
|
147
|
+
* @param options Request behavior such as auth requirement and extra headers.
|
|
148
|
+
*/
|
|
149
|
+
async put(path, body, options = {}) {
|
|
150
|
+
const response = await fetch(this.buildUrl(path), {
|
|
151
|
+
method: "PUT",
|
|
152
|
+
headers: this.buildHeaders({
|
|
153
|
+
...options,
|
|
154
|
+
headers: {
|
|
155
|
+
"Content-Type": "application/json",
|
|
156
|
+
...options.headers
|
|
157
|
+
}
|
|
158
|
+
}),
|
|
159
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
160
|
+
});
|
|
161
|
+
return this.parseResponse(response, "PUT", path);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Sends an HTTP DELETE request with an optional JSON body to a path relative to this adapter base URL.
|
|
165
|
+
*
|
|
166
|
+
* @param path Relative endpoint path.
|
|
167
|
+
* @param body Optional serializable request payload.
|
|
168
|
+
* @param options Request behavior such as auth requirement and extra headers.
|
|
169
|
+
*/
|
|
170
|
+
async delete(path, body, options = {}) {
|
|
171
|
+
const headers = body === void 0 ? this.buildHeaders(options) : this.buildHeaders({
|
|
172
|
+
...options,
|
|
173
|
+
headers: {
|
|
174
|
+
"Content-Type": "application/json",
|
|
175
|
+
...options.headers
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
const response = await fetch(this.buildUrl(path), {
|
|
179
|
+
method: "DELETE",
|
|
180
|
+
headers,
|
|
181
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
182
|
+
});
|
|
183
|
+
return this.parseResponse(response, "DELETE", path);
|
|
184
|
+
}
|
|
139
185
|
/**
|
|
140
186
|
* Builds the final request headers by combining default headers, per-request
|
|
141
187
|
* headers, and an authorization header when the request requires auth.
|
|
@@ -187,6 +233,14 @@ var BalancerService = class {
|
|
|
187
233
|
this.http = http;
|
|
188
234
|
}
|
|
189
235
|
http;
|
|
236
|
+
/**
|
|
237
|
+
* Returns the list of balancer pools.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```ts
|
|
241
|
+
* const pools = await client.balancer.getPools();
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
190
244
|
async getPools() {
|
|
191
245
|
return this.http.get("balancer/pools");
|
|
192
246
|
}
|
|
@@ -194,6 +248,30 @@ var BalancerService = class {
|
|
|
194
248
|
|
|
195
249
|
// packages/sdk/src/services/gasAccount.ts
|
|
196
250
|
var GAS_ACCOUNT_SERVICE_PATH = "1/gas-account/";
|
|
251
|
+
var DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION = "1";
|
|
252
|
+
var REGISTER_WHITELIST_SPENDERS_TYPED_DATA = {
|
|
253
|
+
domain: {
|
|
254
|
+
name: "AvacusGasAccount"
|
|
255
|
+
},
|
|
256
|
+
types: {
|
|
257
|
+
SpenderEntry: [
|
|
258
|
+
{ name: "address", type: "address" },
|
|
259
|
+
{ name: "expiresAt", type: "uint256" }
|
|
260
|
+
],
|
|
261
|
+
RegisterSpenders: [
|
|
262
|
+
{ name: "owner", type: "address" },
|
|
263
|
+
{ name: "spenders", type: "SpenderEntry[]" },
|
|
264
|
+
{ name: "nonce", type: "uint256" },
|
|
265
|
+
{ name: "deadline", type: "uint256" }
|
|
266
|
+
]
|
|
267
|
+
},
|
|
268
|
+
primaryType: "RegisterSpenders"
|
|
269
|
+
};
|
|
270
|
+
function toMutableTypedDataTypes(types) {
|
|
271
|
+
return Object.fromEntries(
|
|
272
|
+
Object.entries(types).map(([key, fields]) => [key, [...fields]])
|
|
273
|
+
);
|
|
274
|
+
}
|
|
197
275
|
var GasAccountService = class {
|
|
198
276
|
/**
|
|
199
277
|
* Creates the gas-account service using a service-scoped HTTP adapter.
|
|
@@ -207,21 +285,452 @@ var GasAccountService = class {
|
|
|
207
285
|
/**
|
|
208
286
|
* Returns the deposit vault address mapping keyed by chain ID.
|
|
209
287
|
* Requires a JWT token from a successful SNS login.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* await client.sns.login({
|
|
292
|
+
* walletAddress,
|
|
293
|
+
* signMessage,
|
|
294
|
+
* });
|
|
295
|
+
*
|
|
296
|
+
* const vaults = await client.gasAccount.getDepositVaults();
|
|
297
|
+
* ```
|
|
210
298
|
*/
|
|
211
299
|
async getDepositVaults() {
|
|
212
300
|
return this.http.get("deposit_vaults", { auth: true });
|
|
213
301
|
}
|
|
214
302
|
/**
|
|
215
|
-
* Returns the authenticated gas
|
|
216
|
-
*
|
|
303
|
+
* Returns the authenticated user's gas account summary, including balances,
|
|
304
|
+
* recent transactions, and pending transactions.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```ts
|
|
308
|
+
* const summary = await client.gasAccount.getSummary();
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
async getSummary() {
|
|
312
|
+
return this.http.get("summary", { auth: true });
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Returns supported stable tokens, optionally filtered by chain ID.
|
|
316
|
+
*
|
|
317
|
+
* @param chainId Optional network chain ID used to filter supported tokens.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* const tokens = await client.gasAccount.getStableTokens();
|
|
322
|
+
* const bscTestnetTokens = await client.gasAccount.getStableTokens(97);
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
async getStableTokens(chainId) {
|
|
326
|
+
const searchParams = new URLSearchParams();
|
|
327
|
+
if (chainId !== void 0) {
|
|
328
|
+
searchParams.set("chainId", String(chainId));
|
|
329
|
+
}
|
|
330
|
+
const path = searchParams.size > 0 ? `stable_tokens?${searchParams.toString()}` : "stable_tokens";
|
|
331
|
+
return this.http.get(path, { auth: true });
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Returns the authenticated user's current whitelist spender entries and nonce.
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```ts
|
|
338
|
+
* const whitelist = await client.gasAccount.getWhitelistSpenders();
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
async getWhitelistSpenders() {
|
|
342
|
+
return this.http.get("whitelist-spenders", { auth: true });
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Adds or updates whitelist spender entries using a signed EIP-712 payload.
|
|
346
|
+
*
|
|
347
|
+
* @param params Spenders, signature, nonce, and deadline for registration.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* const { data } = await client.gasAccount.getWhitelistSpenders();
|
|
352
|
+
* const typedData = client.gasAccount.buildRegisterWhitelistSpendersTypedData({
|
|
353
|
+
* owner: wallet.address,
|
|
354
|
+
* spenders,
|
|
355
|
+
* nonce: data.nonce,
|
|
356
|
+
* deadline: Math.floor(Date.now() / 1000) + 600,
|
|
357
|
+
* });
|
|
358
|
+
*
|
|
359
|
+
* const signature = await wallet.signTypedData(
|
|
360
|
+
* typedData.domain,
|
|
361
|
+
* typedData.types,
|
|
362
|
+
* typedData.message,
|
|
363
|
+
* );
|
|
364
|
+
*
|
|
365
|
+
* await client.gasAccount.registerWhitelistSpenders({
|
|
366
|
+
* spenders,
|
|
367
|
+
* nonce: data.nonce,
|
|
368
|
+
* deadline: typedData.message.deadline,
|
|
369
|
+
* signature,
|
|
370
|
+
* });
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
async registerWhitelistSpenders(params) {
|
|
374
|
+
return this.http.post("whitelist-spenders", params, {
|
|
375
|
+
auth: true
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Convenience helper that fetches the current whitelist nonce, builds the
|
|
380
|
+
* typed-data payload, asks the caller to sign it, and submits the request.
|
|
381
|
+
*
|
|
382
|
+
* @param params Owner address, spender entries, optional deadline, and a typed-data signer.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* await client.gasAccount.registerWhitelistSpendersWithSignature({
|
|
387
|
+
* owner: wallet.address,
|
|
388
|
+
* spenders,
|
|
389
|
+
* signTypedData: (typedData) =>
|
|
390
|
+
* wallet.signTypedData(
|
|
391
|
+
* typedData.domain,
|
|
392
|
+
* typedData.types,
|
|
393
|
+
* typedData.message,
|
|
394
|
+
* ),
|
|
395
|
+
* });
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
async registerWhitelistSpendersWithSignature(params) {
|
|
399
|
+
const { data } = await this.getWhitelistSpenders();
|
|
400
|
+
const nonce = data.nonce;
|
|
401
|
+
const deadline = params.deadline ?? Math.floor(Date.now() / 1e3) + 600;
|
|
402
|
+
const typedData = this.buildRegisterWhitelistSpendersTypedData({
|
|
403
|
+
owner: params.owner,
|
|
404
|
+
spenders: params.spenders,
|
|
405
|
+
version: params.version,
|
|
406
|
+
nonce,
|
|
407
|
+
deadline
|
|
408
|
+
});
|
|
409
|
+
const signature = await params.signTypedData(typedData);
|
|
410
|
+
return this.registerWhitelistSpenders({
|
|
411
|
+
spenders: params.spenders,
|
|
412
|
+
signature,
|
|
413
|
+
nonce,
|
|
414
|
+
deadline
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Convenience helper for ethers-compatible signers.
|
|
419
|
+
*
|
|
420
|
+
* @param params Owner address, spender entries, optional domain version/deadline, and an ethers-compatible signer.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```ts
|
|
424
|
+
* await client.gasAccount.registerWhitelistSpendersWithEthers({
|
|
425
|
+
* owner: wallet.address,
|
|
426
|
+
* spenders,
|
|
427
|
+
* signer: wallet,
|
|
428
|
+
* });
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
async registerWhitelistSpendersWithEthers(params) {
|
|
432
|
+
return this.registerWhitelistSpendersWithSignature({
|
|
433
|
+
owner: params.owner,
|
|
434
|
+
spenders: params.spenders,
|
|
435
|
+
version: params.version,
|
|
436
|
+
deadline: params.deadline,
|
|
437
|
+
signTypedData: (typedData) => params.signer.signTypedData(
|
|
438
|
+
typedData.domain,
|
|
439
|
+
toMutableTypedDataTypes(typedData.types),
|
|
440
|
+
typedData.message
|
|
441
|
+
)
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Builds the EIP-712 typed-data payload required by whitelist registration.
|
|
446
|
+
*
|
|
447
|
+
* @param params Owner, spenders, nonce, and deadline used in the signature payload.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```ts
|
|
451
|
+
* const typedData = client.gasAccount.buildRegisterWhitelistSpendersTypedData({
|
|
452
|
+
* owner: wallet.address,
|
|
453
|
+
* spenders,
|
|
454
|
+
* nonce: 0,
|
|
455
|
+
* deadline: Math.floor(Date.now() / 1000) + 600,
|
|
456
|
+
* });
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
buildRegisterWhitelistSpendersTypedData(params) {
|
|
460
|
+
return {
|
|
461
|
+
...REGISTER_WHITELIST_SPENDERS_TYPED_DATA,
|
|
462
|
+
domain: {
|
|
463
|
+
...REGISTER_WHITELIST_SPENDERS_TYPED_DATA.domain,
|
|
464
|
+
version: params.version ?? DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION
|
|
465
|
+
},
|
|
466
|
+
message: {
|
|
467
|
+
owner: params.owner,
|
|
468
|
+
spenders: params.spenders,
|
|
469
|
+
nonce: params.nonce,
|
|
470
|
+
deadline: params.deadline
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Removes one or more whitelist spender addresses from the authenticated account.
|
|
476
|
+
*
|
|
477
|
+
* @param params Spender addresses to revoke.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```ts
|
|
481
|
+
* await client.gasAccount.removeWhitelistSpenders({
|
|
482
|
+
* spenders: ['0x9876543210987654321098765432109876543210'],
|
|
483
|
+
* });
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
486
|
+
async removeWhitelistSpenders(params) {
|
|
487
|
+
return this.http.delete("whitelist-spenders", params, {
|
|
488
|
+
auth: true
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Returns the authenticated user's balance summary.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```ts
|
|
496
|
+
* const balance = await client.gasAccount.getBalance();
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
async getBalance() {
|
|
500
|
+
return this.http.get("gas-account-balance", { auth: true });
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Returns the authenticated user's balance summary with pending transaction lists.
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```ts
|
|
507
|
+
* const detailedBalance = await client.gasAccount.getDetailedBalance();
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
async getDetailedBalance() {
|
|
511
|
+
return this.http.get("gas-account-balance/detailed", {
|
|
512
|
+
auth: true
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Returns balance statistics for the authenticated user's gas account.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```ts
|
|
520
|
+
* const stats = await client.gasAccount.getBalanceStats();
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
|
523
|
+
async getBalanceStats() {
|
|
524
|
+
return this.http.get("gas-account-balance/stats", {
|
|
525
|
+
auth: true
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Returns balances for a batch of addresses through the public balances endpoint.
|
|
530
|
+
*
|
|
531
|
+
* @param params Address batch to query.
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```ts
|
|
535
|
+
* const balances = await client.gasAccount.getBalances({
|
|
536
|
+
* addresses: [
|
|
537
|
+
* '0x3a0430580303f4De9C5320aC013f14cd92192bfA',
|
|
538
|
+
* '0x610b463d2f57d2e0d9e785a7ff423fbae36f0624',
|
|
539
|
+
* ],
|
|
540
|
+
* });
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
async getBalances(params) {
|
|
544
|
+
return this.http.put("gas-account-balance/balances", params);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Returns a paginated transaction list for the authenticated user's gas account.
|
|
548
|
+
*
|
|
549
|
+
* @param params Optional pagination and filter parameters.
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```ts
|
|
553
|
+
* const transactions = await client.gasAccount.listTransactions({
|
|
554
|
+
* page: 1,
|
|
555
|
+
* per: 10,
|
|
556
|
+
* type: 'DEPOSIT',
|
|
557
|
+
* status: 'CONFIRMED',
|
|
558
|
+
* });
|
|
559
|
+
* ```
|
|
560
|
+
*/
|
|
561
|
+
async listTransactions(params = {}) {
|
|
562
|
+
const searchParams = new URLSearchParams();
|
|
563
|
+
if (params.page !== void 0) {
|
|
564
|
+
searchParams.set("page", String(params.page));
|
|
565
|
+
}
|
|
566
|
+
if (params.per !== void 0) {
|
|
567
|
+
searchParams.set("per", String(params.per));
|
|
568
|
+
}
|
|
569
|
+
if (params.type) {
|
|
570
|
+
searchParams.set("type", params.type);
|
|
571
|
+
}
|
|
572
|
+
if (params.status) {
|
|
573
|
+
searchParams.set("status", params.status);
|
|
574
|
+
}
|
|
575
|
+
const path = searchParams.size > 0 ? `gas-account-transaction?${searchParams.toString()}` : "gas-account-transaction";
|
|
576
|
+
return this.http.get(path, { auth: true });
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Returns detailed data for a specific transaction ID.
|
|
580
|
+
*
|
|
581
|
+
* @param transactionId Transaction UUID.
|
|
582
|
+
*
|
|
583
|
+
* @example
|
|
584
|
+
* ```ts
|
|
585
|
+
* const transaction = await client.gasAccount.getTransactionById(transactionId);
|
|
586
|
+
* ```
|
|
217
587
|
*/
|
|
218
|
-
async
|
|
219
|
-
return this.http.get(
|
|
588
|
+
async getTransactionById(transactionId) {
|
|
589
|
+
return this.http.get(
|
|
590
|
+
`gas-account-transaction/${transactionId}`,
|
|
591
|
+
{ auth: true }
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Creates a pending deposit transaction for the authenticated user.
|
|
596
|
+
*
|
|
597
|
+
* @param params Deposit payload.
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* ```ts
|
|
601
|
+
* await client.gasAccount.createDeposit({
|
|
602
|
+
* chainId: 97,
|
|
603
|
+
* amount: '100.00000000',
|
|
604
|
+
* tokenAddress: '0x5bF5121A17e3329D07Ba43f758dEC271D9105132',
|
|
605
|
+
* txHash: '0xe3844e7bc420b2d409058e6bf5534fdba69b917907d691abf65862654df749d7',
|
|
606
|
+
* actor: walletAddress,
|
|
607
|
+
* notes: 'Deposit from wallet',
|
|
608
|
+
* });
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
async createDeposit(params) {
|
|
612
|
+
return this.http.post("gas-account-transaction/deposit", params, {
|
|
613
|
+
auth: true
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Creates a gas-usage request against the caller's balance or a whitelisted source address.
|
|
618
|
+
* When `sourceAddress` is provided, the caller spends from another owner's
|
|
619
|
+
* gas account and therefore must already be registered as a whitelist spender
|
|
620
|
+
* for that source account.
|
|
621
|
+
*
|
|
622
|
+
* @param params Usage request payload.
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* ```ts
|
|
626
|
+
* await client.gasAccount.useBalance({
|
|
627
|
+
* toAddress: '0x9876543210987654321098765432109876543210',
|
|
628
|
+
* chainId: 97,
|
|
629
|
+
* gasLimit: 21000,
|
|
630
|
+
* gasPrice: 5,
|
|
631
|
+
* notes: 'Gas for token transfer',
|
|
632
|
+
* });
|
|
633
|
+
*
|
|
634
|
+
* await client.gasAccount.useBalance({
|
|
635
|
+
* toAddress: '0x9876543210987654321098765432109876543210',
|
|
636
|
+
* chainId: 97,
|
|
637
|
+
* gasLimit: 21000,
|
|
638
|
+
* gasPrice: 5,
|
|
639
|
+
* sourceAddress: '0x610b463d2f57d2e0d9e785a7ff423fbae36f0624',
|
|
640
|
+
* notes: 'Use gas from delegated source account',
|
|
641
|
+
* });
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
async useBalance(params) {
|
|
645
|
+
return this.http.post("gas-account-transaction/use-balance", params, {
|
|
646
|
+
auth: true
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Creates a sponsored transfer request.
|
|
651
|
+
*
|
|
652
|
+
* @param params Sponsored transfer payload.
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```ts
|
|
656
|
+
* await client.gasAccount.createSponsoredTransfer({
|
|
657
|
+
* transactions: [
|
|
658
|
+
* {
|
|
659
|
+
* tokenAddress: '0x409E7b65eF7B243529e3F97be2A122123c55DE63',
|
|
660
|
+
* from: '0x1234567890123456789012345678901234567890',
|
|
661
|
+
* to: '0x9876543210987654321098765432109876543210',
|
|
662
|
+
* value: '1000000000000000000',
|
|
663
|
+
* validBefore: 1735689600,
|
|
664
|
+
* validAfter: 0,
|
|
665
|
+
* nonce: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
666
|
+
* signature: '0x...',
|
|
667
|
+
* },
|
|
668
|
+
* ],
|
|
669
|
+
* chainId: 97,
|
|
670
|
+
* type: 'ADMIN',
|
|
671
|
+
* notes: 'JPYC transfer sponsorship',
|
|
672
|
+
* });
|
|
673
|
+
* ```
|
|
674
|
+
*/
|
|
675
|
+
async createSponsoredTransfer(params) {
|
|
676
|
+
return this.http.post(
|
|
677
|
+
"gas-account-transaction/sponsored-transfers",
|
|
678
|
+
params,
|
|
679
|
+
{ auth: true }
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Cancels a pending gas-account transaction that has not yet been broadcast.
|
|
684
|
+
*
|
|
685
|
+
* @param transactionId Transaction UUID.
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
* ```ts
|
|
689
|
+
* await client.gasAccount.cancelTransaction(transactionId);
|
|
690
|
+
* ```
|
|
691
|
+
*/
|
|
692
|
+
async cancelTransaction(transactionId) {
|
|
693
|
+
return this.http.put(
|
|
694
|
+
`gas-account-transaction/${transactionId}/cancel`,
|
|
695
|
+
void 0,
|
|
696
|
+
{ auth: true }
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Creates an internal funding request on behalf of another service.
|
|
701
|
+
*
|
|
702
|
+
* @param params Funding request payload.
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
705
|
+
* ```ts
|
|
706
|
+
* await client.gasAccount.createFundingRequest({
|
|
707
|
+
* sourceAddress: '0x610b463d2f57d2e0d9e785a7ff423fbae36f0624',
|
|
708
|
+
* toAddress: '0x9876543210987654321098765432109876543210',
|
|
709
|
+
* chainId: 97,
|
|
710
|
+
* gasLimit: 21000,
|
|
711
|
+
* gasPrice: 5,
|
|
712
|
+
* notes: 'Gas for token transfer',
|
|
713
|
+
* });
|
|
714
|
+
* ```
|
|
715
|
+
*/
|
|
716
|
+
async createFundingRequest(params) {
|
|
717
|
+
return this.http.post(
|
|
718
|
+
"internal/gas-account-transaction/funding-requests",
|
|
719
|
+
params
|
|
720
|
+
);
|
|
220
721
|
}
|
|
221
722
|
};
|
|
222
723
|
|
|
223
724
|
// packages/sdk/src/services/sns.ts
|
|
224
725
|
var DEFAULT_BASE_SIGNED_MESSAGE = "Hi there from Avacus Wallet! Please sign this message to prove that you can access to secure chat. To stop hackers access to your secure chat, do not sign this message outside Avacus Wallet, and here's a unique message ID they can't guess: ";
|
|
726
|
+
var BASE_CONNECT_SIGNED_MSG = "Hi there from Avacus Connect! Please sign this message to prove that you can access our service. For security reasons, do not sign this message outside Avacus Connect, and here's a unique message ID they can't guess: ";
|
|
727
|
+
var BASE_REDIRECT_SIGNED_MSG = "Hi there from Avacus Redirect! Please sign this message to prove that you can access our service. For security reasons, do not sign this message outside Avacus Redirect, and here's a unique message ID they can't guess: ";
|
|
728
|
+
var BASE_GAS_SPONSOR_SIGNED_MSG = "Hi there from Avacus Gas Sponsor! Please sign this message to prove that you can access our service. For security reasons, do not sign this message outside Avacus Gas Sponsor, and here's a unique message ID they can't guess: ";
|
|
729
|
+
var BASE_SIGNED_MESSAGE_BY_SERVICE = {
|
|
730
|
+
connect: BASE_CONNECT_SIGNED_MSG,
|
|
731
|
+
redirect: BASE_REDIRECT_SIGNED_MSG,
|
|
732
|
+
"gas-sponsor": BASE_GAS_SPONSOR_SIGNED_MSG
|
|
733
|
+
};
|
|
225
734
|
var SNS_SERVICE_PATH = "1/secure-chat/";
|
|
226
735
|
var SnsService = class {
|
|
227
736
|
/**
|
|
@@ -255,7 +764,7 @@ var SnsService = class {
|
|
|
255
764
|
* @param params Payload expected by the SNS auth API.
|
|
256
765
|
*/
|
|
257
766
|
async requestAuthToken(params) {
|
|
258
|
-
return this.http.post("
|
|
767
|
+
return this.http.post("v2/public/users/request_auth_token", params);
|
|
259
768
|
}
|
|
260
769
|
/**
|
|
261
770
|
* Returns public user profiles for a batch of wallet addresses and/or user IDs.
|
|
@@ -332,7 +841,8 @@ var SnsService = class {
|
|
|
332
841
|
return this.requestAuthToken({
|
|
333
842
|
wallet_address: params.walletAddress,
|
|
334
843
|
message: params.message,
|
|
335
|
-
signature: params.signature
|
|
844
|
+
signature: params.signature,
|
|
845
|
+
service_name: params.serviceName
|
|
336
846
|
});
|
|
337
847
|
}
|
|
338
848
|
/**
|
|
@@ -346,14 +856,15 @@ var SnsService = class {
|
|
|
346
856
|
* @param params Wallet address and async signing callback.
|
|
347
857
|
*/
|
|
348
858
|
async login(params) {
|
|
349
|
-
const { walletAddress, signMessage } = params;
|
|
859
|
+
const { walletAddress, signMessage, serviceName } = params;
|
|
350
860
|
const { nonce } = await this.getNonce({ walletAddress });
|
|
351
|
-
const message = this.buildLoginMessage(nonce);
|
|
861
|
+
const message = this.buildLoginMessage(nonce, serviceName);
|
|
352
862
|
const signature = await signMessage(message);
|
|
353
863
|
const result = await this.authenticate({
|
|
354
864
|
walletAddress,
|
|
355
865
|
message,
|
|
356
|
-
signature
|
|
866
|
+
signature,
|
|
867
|
+
serviceName
|
|
357
868
|
});
|
|
358
869
|
const accessToken = extractAccessToken(result);
|
|
359
870
|
if (accessToken) {
|
|
@@ -364,16 +875,16 @@ var SnsService = class {
|
|
|
364
875
|
/**
|
|
365
876
|
* Builds the exact message string that the wallet must sign during login.
|
|
366
877
|
*/
|
|
367
|
-
buildLoginMessage(nonce) {
|
|
368
|
-
|
|
878
|
+
buildLoginMessage(nonce, serviceName) {
|
|
879
|
+
const baseMessage = serviceName != null ? BASE_SIGNED_MESSAGE_BY_SERVICE[serviceName] : this.options.baseSignedMessage ?? DEFAULT_BASE_SIGNED_MESSAGE;
|
|
880
|
+
return `${baseMessage}${nonce}`;
|
|
369
881
|
}
|
|
370
882
|
};
|
|
371
883
|
function extractAccessToken(result) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
return value;
|
|
884
|
+
if ("data" in result && typeof result.data === "object" && result.data !== null) {
|
|
885
|
+
const token = result.data.token;
|
|
886
|
+
if (typeof token === "string" && token.length > 0) {
|
|
887
|
+
return token;
|
|
377
888
|
}
|
|
378
889
|
}
|
|
379
890
|
return void 0;
|
|
@@ -444,11 +955,14 @@ var SnsAuthClient = class extends SnsService {
|
|
|
444
955
|
0 && (module.exports = {
|
|
445
956
|
AVACUS_ENDPOINTS,
|
|
446
957
|
AvacusClient,
|
|
958
|
+
BASE_CONNECT_SIGNED_MSG,
|
|
959
|
+
BASE_GAS_SPONSOR_SIGNED_MSG,
|
|
960
|
+
BASE_REDIRECT_SIGNED_MSG,
|
|
447
961
|
BalancerService,
|
|
448
962
|
DEFAULT_BASE_SIGNED_MESSAGE,
|
|
963
|
+
DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION,
|
|
449
964
|
GAS_ACCOUNT_SERVICE_PATH,
|
|
450
965
|
GasAccountService,
|
|
451
|
-
HttpAdapter,
|
|
452
966
|
SNS_SERVICE_PATH,
|
|
453
967
|
SnsAuthClient,
|
|
454
968
|
SnsService,
|