@avacuscc/sdk 0.2.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 CHANGED
@@ -315,6 +315,27 @@ await client.gasAccount.useBalance({
315
315
  });
316
316
  ```
317
317
 
318
+ Use balance from another owner's gas account via delegated spender permission:
319
+
320
+ ```ts
321
+ await client.gasAccount.useBalance({
322
+ toAddress: '0x9876543210987654321098765432109876543210',
323
+ chainId: 97,
324
+ gasLimit: 21000,
325
+ gasPrice: 5,
326
+ sourceAddress: '0x610b463d2f57d2e0d9e785a7ff423fbae36f0624',
327
+ notes: 'Use gas from delegated source account',
328
+ });
329
+ ```
330
+
331
+ `sourceAddress` is important for delegated spending flows:
332
+
333
+ - omit `sourceAddress` to spend from the currently authenticated user's own gas account
334
+ - provide `sourceAddress` to spend from another owner's gas account
335
+ - to make that possible, the owner must first authorize the caller with `registerWhitelistSpenders(...)` or one of the helper methods
336
+ - the logged-in user must already be whitelisted as a spender for that `sourceAddress`
337
+ - when `sourceAddress` is used, the returned balance payload reflects the source owner's balance
338
+
318
339
  Create sponsored transfer:
319
340
 
320
341
  ```ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@avacuscc/sdk",
3
- "version": "0.2.0",
4
- "description": "SDK for interacting with services in the Wakumo ecosystem",
3
+ "version": "0.2.1",
4
+ "description": "SDK for interacting with Avacuscc services",
5
5
  "main": "./packages/sdk/dist/index.js",
6
6
  "module": "./packages/sdk/dist/index.mjs",
7
7
  "types": "./packages/sdk/dist/index.d.ts",
@@ -22,8 +22,8 @@
22
22
  "README.md"
23
23
  ],
24
24
  "scripts": {
25
- "build": "tsup packages/sdk/src/index.ts packages/sdk/src/sns.ts --format cjs,esm --dts --clean --out-dir packages/sdk/dist",
26
- "dev": "tsup packages/sdk/src/index.ts packages/sdk/src/sns.ts --format cjs,esm --dts --watch --out-dir packages/sdk/dist",
25
+ "build": "tsup",
26
+ "dev": "tsup --watch",
27
27
  "test": "echo \"Error: no test specified\" && exit 1"
28
28
  },
29
29
  "keywords": [],
@@ -1,5 +1,5 @@
1
- import { H as HttpAdapter, S as SnsService, B as BaseClientOptions } from './sns-Zwan9DNM.mjs';
2
- export { A as AVACUS_ENDPOINTS, a as AuthState, b as AvacusEnvironment, c as BASE_CONNECT_SIGNED_MSG, d as BASE_GAS_SPONSOR_SIGNED_MSG, e as BASE_REDIRECT_SIGNED_MSG, D as DEFAULT_BASE_SIGNED_MESSAGE, R as RequestOptions, f as ResolvedClientSettings, g as SNS_SERVICE_PATH, h as SignMessageFn, i as SnsAuthClient, j as SnsAuthClientOptions, k as SnsAuthTokenPayload, l as SnsAuthenticateParams, m as SnsAvatar, n as SnsCreateUserDeviceParams, o as SnsCreateUserParams, p as SnsCreateUserPayload, q as SnsCreateUserResult, r as SnsCreateUserWithSignatureParams, s as SnsDevice, t as SnsGetNonceParams, u as SnsGetProfilesParams, v as SnsLoginParams, w as SnsLoginResult, x as SnsNonceResponse, y as SnsProfile, z as SnsServiceName, C as SnsServiceOptions, E as isKnownAvacusBaseUrl, F as loginWithSns, G as resolveAvacusBaseUrl, I as resolveClientSettings, J as resolveServiceUrl } from './sns-Zwan9DNM.mjs';
1
+ import { H as HttpAdapter, S as SnsService, B as BaseClientOptions } from './sns-NuV2JpAA.mjs';
2
+ export { A as AVACUS_ENDPOINTS, a as AvacusEnvironment, b as BASE_CONNECT_SIGNED_MSG, c as BASE_GAS_SPONSOR_SIGNED_MSG, d as BASE_REDIRECT_SIGNED_MSG, D as DEFAULT_BASE_SIGNED_MESSAGE, R as ResolvedClientSettings, e as SNS_SERVICE_PATH, f as SignMessageFn, g as SnsAuthClient, h as SnsAuthClientOptions, i as SnsAuthTokenPayload, j as SnsAuthenticateParams, k as SnsAvatar, l as SnsCreateUserDeviceParams, m as SnsCreateUserParams, n as SnsCreateUserPayload, o as SnsCreateUserResult, p as SnsCreateUserWithSignatureParams, q as SnsDevice, r as SnsGetNonceParams, s as SnsGetProfilesParams, t as SnsLoginParams, u as SnsLoginResult, v as SnsNonceResponse, w as SnsProfile, x as SnsServiceName, y as SnsServiceOptions, z as isKnownAvacusBaseUrl, C as loginWithSns, E as resolveAvacusBaseUrl, F as resolveClientSettings, G as resolveServiceUrl } from './sns-NuV2JpAA.mjs';
3
3
 
4
4
  declare class BalancerService {
5
5
  private readonly http;
@@ -615,6 +615,9 @@ declare class GasAccountService {
615
615
  createDeposit(params: CreateDepositParams): Promise<CreateDepositResult>;
616
616
  /**
617
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.
618
621
  *
619
622
  * @param params Usage request payload.
620
623
  *
@@ -627,6 +630,15 @@ declare class GasAccountService {
627
630
  * gasPrice: 5,
628
631
  * notes: 'Gas for token transfer',
629
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
+ * });
630
642
  * ```
631
643
  */
632
644
  useBalance(params: UseBalanceParams): Promise<UseBalanceResult>;
@@ -706,4 +718,4 @@ declare class AvacusClient {
706
718
  constructor(options?: AvacusClientOptions);
707
719
  }
708
720
 
709
- export { type ApiEnvelope, type ApiEnvelopeWithMeta, AvacusClient, type AvacusClientOptions, BalancerService, BaseClientOptions, type BuildRegisterWhitelistSpendersTypedDataParams, type CancelGasAccountTransactionData, type CancelGasAccountTransactionResult, type ComputedBalance, type CreateDepositData, type CreateDepositParams, type CreateDepositResult, type CreateFundingRequestParams, type CreateFundingRequestResult, DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION, type EthersLikeTypedDataSigner, GAS_ACCOUNT_SERVICE_PATH, type GasAccountBalanceDetailedResult, type GasAccountBalanceDetailedSnapshot, type GasAccountBalanceResult, type GasAccountBalanceSnapshot, type GasAccountBalanceStatsData, type GasAccountBalanceStatsResult, type GasAccountEntity, GasAccountService, type GasAccountSummaryData, type GasAccountSummaryResult, type GasAccountTransaction, type GasAccountTransactionDetailData, type GasAccountTransactionDetailResult, type GasAccountTransactionListData, type GasAccountTransactionListParams, type GasAccountTransactionListResult, type GasAccountTransactionStatus, type GasAccountTransactionType, type GasAccountWhitelistData, type GasAccountWhitelistEntry, type GasAccountWhitelistResult, type GetMultipleBalancesParams, type GetMultipleBalancesResult, HttpAdapter, type NetworkRef, type PaginationMeta, type PendingBreakdown, type PendingTotals, type PendingTransactions, type RegisterWhitelistSpenderEntry, type RegisterWhitelistSpendersData, type RegisterWhitelistSpendersParams, type RegisterWhitelistSpendersResult, type RegisterWhitelistSpendersTypedData, type RegisterWhitelistSpendersTypedDataDomain, type RegisterWhitelistSpendersTypedDataMessage, type RegisterWhitelistSpendersWithEthersParams, type RegisterWhitelistSpendersWithSignatureParams, type RemoveWhitelistSpendersData, type RemoveWhitelistSpendersParams, type RemoveWhitelistSpendersResult, type SignRegisterWhitelistSpendersTypedDataFn, SnsService, type SponsorType, type SponsoredTransferAuthorization, type SponsoredTransferData, type SponsoredTransferParams, type SponsoredTransferResult, type StableToken, type StableTokenImage, type StableTokenListResult, type UseBalanceData, type UseBalanceParams, type UseBalanceResult };
721
+ export { type ApiEnvelope, type ApiEnvelopeWithMeta, AvacusClient, type AvacusClientOptions, BalancerService, BaseClientOptions, type BuildRegisterWhitelistSpendersTypedDataParams, type CancelGasAccountTransactionData, type CancelGasAccountTransactionResult, type ComputedBalance, type CreateDepositData, type CreateDepositParams, type CreateDepositResult, type CreateFundingRequestParams, type CreateFundingRequestResult, DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION, type EthersLikeTypedDataSigner, GAS_ACCOUNT_SERVICE_PATH, type GasAccountBalanceDetailedResult, type GasAccountBalanceDetailedSnapshot, type GasAccountBalanceResult, type GasAccountBalanceSnapshot, type GasAccountBalanceStatsData, type GasAccountBalanceStatsResult, type GasAccountEntity, GasAccountService, type GasAccountSummaryData, type GasAccountSummaryResult, type GasAccountTransaction, type GasAccountTransactionDetailData, type GasAccountTransactionDetailResult, type GasAccountTransactionListData, type GasAccountTransactionListParams, type GasAccountTransactionListResult, type GasAccountTransactionStatus, type GasAccountTransactionType, type GasAccountWhitelistData, type GasAccountWhitelistEntry, type GasAccountWhitelistResult, type GetMultipleBalancesParams, type GetMultipleBalancesResult, type NetworkRef, type PaginationMeta, type PendingBreakdown, type PendingTotals, type PendingTransactions, type RegisterWhitelistSpenderEntry, type RegisterWhitelistSpendersData, type RegisterWhitelistSpendersParams, type RegisterWhitelistSpendersResult, type RegisterWhitelistSpendersTypedData, type RegisterWhitelistSpendersTypedDataDomain, type RegisterWhitelistSpendersTypedDataMessage, type RegisterWhitelistSpendersWithEthersParams, type RegisterWhitelistSpendersWithSignatureParams, type RemoveWhitelistSpendersData, type RemoveWhitelistSpendersParams, type RemoveWhitelistSpendersResult, type SignRegisterWhitelistSpendersTypedDataFn, SnsService, type SponsorType, type SponsoredTransferAuthorization, type SponsoredTransferData, type SponsoredTransferParams, type SponsoredTransferResult, type StableToken, type StableTokenImage, type StableTokenListResult, type UseBalanceData, type UseBalanceParams, type UseBalanceResult };
@@ -1,5 +1,5 @@
1
- import { H as HttpAdapter, S as SnsService, B as BaseClientOptions } from './sns-Zwan9DNM.js';
2
- export { A as AVACUS_ENDPOINTS, a as AuthState, b as AvacusEnvironment, c as BASE_CONNECT_SIGNED_MSG, d as BASE_GAS_SPONSOR_SIGNED_MSG, e as BASE_REDIRECT_SIGNED_MSG, D as DEFAULT_BASE_SIGNED_MESSAGE, R as RequestOptions, f as ResolvedClientSettings, g as SNS_SERVICE_PATH, h as SignMessageFn, i as SnsAuthClient, j as SnsAuthClientOptions, k as SnsAuthTokenPayload, l as SnsAuthenticateParams, m as SnsAvatar, n as SnsCreateUserDeviceParams, o as SnsCreateUserParams, p as SnsCreateUserPayload, q as SnsCreateUserResult, r as SnsCreateUserWithSignatureParams, s as SnsDevice, t as SnsGetNonceParams, u as SnsGetProfilesParams, v as SnsLoginParams, w as SnsLoginResult, x as SnsNonceResponse, y as SnsProfile, z as SnsServiceName, C as SnsServiceOptions, E as isKnownAvacusBaseUrl, F as loginWithSns, G as resolveAvacusBaseUrl, I as resolveClientSettings, J as resolveServiceUrl } from './sns-Zwan9DNM.js';
1
+ import { H as HttpAdapter, S as SnsService, B as BaseClientOptions } from './sns-NuV2JpAA.js';
2
+ export { A as AVACUS_ENDPOINTS, a as AvacusEnvironment, b as BASE_CONNECT_SIGNED_MSG, c as BASE_GAS_SPONSOR_SIGNED_MSG, d as BASE_REDIRECT_SIGNED_MSG, D as DEFAULT_BASE_SIGNED_MESSAGE, R as ResolvedClientSettings, e as SNS_SERVICE_PATH, f as SignMessageFn, g as SnsAuthClient, h as SnsAuthClientOptions, i as SnsAuthTokenPayload, j as SnsAuthenticateParams, k as SnsAvatar, l as SnsCreateUserDeviceParams, m as SnsCreateUserParams, n as SnsCreateUserPayload, o as SnsCreateUserResult, p as SnsCreateUserWithSignatureParams, q as SnsDevice, r as SnsGetNonceParams, s as SnsGetProfilesParams, t as SnsLoginParams, u as SnsLoginResult, v as SnsNonceResponse, w as SnsProfile, x as SnsServiceName, y as SnsServiceOptions, z as isKnownAvacusBaseUrl, C as loginWithSns, E as resolveAvacusBaseUrl, F as resolveClientSettings, G as resolveServiceUrl } from './sns-NuV2JpAA.js';
3
3
 
4
4
  declare class BalancerService {
5
5
  private readonly http;
@@ -615,6 +615,9 @@ declare class GasAccountService {
615
615
  createDeposit(params: CreateDepositParams): Promise<CreateDepositResult>;
616
616
  /**
617
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.
618
621
  *
619
622
  * @param params Usage request payload.
620
623
  *
@@ -627,6 +630,15 @@ declare class GasAccountService {
627
630
  * gasPrice: 5,
628
631
  * notes: 'Gas for token transfer',
629
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
+ * });
630
642
  * ```
631
643
  */
632
644
  useBalance(params: UseBalanceParams): Promise<UseBalanceResult>;
@@ -706,4 +718,4 @@ declare class AvacusClient {
706
718
  constructor(options?: AvacusClientOptions);
707
719
  }
708
720
 
709
- export { type ApiEnvelope, type ApiEnvelopeWithMeta, AvacusClient, type AvacusClientOptions, BalancerService, BaseClientOptions, type BuildRegisterWhitelistSpendersTypedDataParams, type CancelGasAccountTransactionData, type CancelGasAccountTransactionResult, type ComputedBalance, type CreateDepositData, type CreateDepositParams, type CreateDepositResult, type CreateFundingRequestParams, type CreateFundingRequestResult, DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION, type EthersLikeTypedDataSigner, GAS_ACCOUNT_SERVICE_PATH, type GasAccountBalanceDetailedResult, type GasAccountBalanceDetailedSnapshot, type GasAccountBalanceResult, type GasAccountBalanceSnapshot, type GasAccountBalanceStatsData, type GasAccountBalanceStatsResult, type GasAccountEntity, GasAccountService, type GasAccountSummaryData, type GasAccountSummaryResult, type GasAccountTransaction, type GasAccountTransactionDetailData, type GasAccountTransactionDetailResult, type GasAccountTransactionListData, type GasAccountTransactionListParams, type GasAccountTransactionListResult, type GasAccountTransactionStatus, type GasAccountTransactionType, type GasAccountWhitelistData, type GasAccountWhitelistEntry, type GasAccountWhitelistResult, type GetMultipleBalancesParams, type GetMultipleBalancesResult, HttpAdapter, type NetworkRef, type PaginationMeta, type PendingBreakdown, type PendingTotals, type PendingTransactions, type RegisterWhitelistSpenderEntry, type RegisterWhitelistSpendersData, type RegisterWhitelistSpendersParams, type RegisterWhitelistSpendersResult, type RegisterWhitelistSpendersTypedData, type RegisterWhitelistSpendersTypedDataDomain, type RegisterWhitelistSpendersTypedDataMessage, type RegisterWhitelistSpendersWithEthersParams, type RegisterWhitelistSpendersWithSignatureParams, type RemoveWhitelistSpendersData, type RemoveWhitelistSpendersParams, type RemoveWhitelistSpendersResult, type SignRegisterWhitelistSpendersTypedDataFn, SnsService, type SponsorType, type SponsoredTransferAuthorization, type SponsoredTransferData, type SponsoredTransferParams, type SponsoredTransferResult, type StableToken, type StableTokenImage, type StableTokenListResult, type UseBalanceData, type UseBalanceParams, type UseBalanceResult };
721
+ export { type ApiEnvelope, type ApiEnvelopeWithMeta, AvacusClient, type AvacusClientOptions, BalancerService, BaseClientOptions, type BuildRegisterWhitelistSpendersTypedDataParams, type CancelGasAccountTransactionData, type CancelGasAccountTransactionResult, type ComputedBalance, type CreateDepositData, type CreateDepositParams, type CreateDepositResult, type CreateFundingRequestParams, type CreateFundingRequestResult, DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION, type EthersLikeTypedDataSigner, GAS_ACCOUNT_SERVICE_PATH, type GasAccountBalanceDetailedResult, type GasAccountBalanceDetailedSnapshot, type GasAccountBalanceResult, type GasAccountBalanceSnapshot, type GasAccountBalanceStatsData, type GasAccountBalanceStatsResult, type GasAccountEntity, GasAccountService, type GasAccountSummaryData, type GasAccountSummaryResult, type GasAccountTransaction, type GasAccountTransactionDetailData, type GasAccountTransactionDetailResult, type GasAccountTransactionListData, type GasAccountTransactionListParams, type GasAccountTransactionListResult, type GasAccountTransactionStatus, type GasAccountTransactionType, type GasAccountWhitelistData, type GasAccountWhitelistEntry, type GasAccountWhitelistResult, type GetMultipleBalancesParams, type GetMultipleBalancesResult, type NetworkRef, type PaginationMeta, type PendingBreakdown, type PendingTotals, type PendingTransactions, type RegisterWhitelistSpenderEntry, type RegisterWhitelistSpendersData, type RegisterWhitelistSpendersParams, type RegisterWhitelistSpendersResult, type RegisterWhitelistSpendersTypedData, type RegisterWhitelistSpendersTypedDataDomain, type RegisterWhitelistSpendersTypedDataMessage, type RegisterWhitelistSpendersWithEthersParams, type RegisterWhitelistSpendersWithSignatureParams, type RemoveWhitelistSpendersData, type RemoveWhitelistSpendersParams, type RemoveWhitelistSpendersResult, type SignRegisterWhitelistSpendersTypedDataFn, SnsService, type SponsorType, type SponsoredTransferAuthorization, type SponsoredTransferData, type SponsoredTransferParams, type SponsoredTransferResult, type StableToken, type StableTokenImage, type StableTokenListResult, type UseBalanceData, type UseBalanceParams, type UseBalanceResult };
@@ -30,7 +30,6 @@ __export(index_exports, {
30
30
  DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION: () => DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION,
31
31
  GAS_ACCOUNT_SERVICE_PATH: () => GAS_ACCOUNT_SERVICE_PATH,
32
32
  GasAccountService: () => GasAccountService,
33
- HttpAdapter: () => HttpAdapter,
34
33
  SNS_SERVICE_PATH: () => SNS_SERVICE_PATH,
35
34
  SnsAuthClient: () => SnsAuthClient,
36
35
  SnsService: () => SnsService,
@@ -616,6 +615,9 @@ var GasAccountService = class {
616
615
  }
617
616
  /**
618
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.
619
621
  *
620
622
  * @param params Usage request payload.
621
623
  *
@@ -628,6 +630,15 @@ var GasAccountService = class {
628
630
  * gasPrice: 5,
629
631
  * notes: 'Gas for token transfer',
630
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
+ * });
631
642
  * ```
632
643
  */
633
644
  async useBalance(params) {
@@ -952,7 +963,6 @@ var SnsAuthClient = class extends SnsService {
952
963
  DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION,
953
964
  GAS_ACCOUNT_SERVICE_PATH,
954
965
  GasAccountService,
955
- HttpAdapter,
956
966
  SNS_SERVICE_PATH,
957
967
  SnsAuthClient,
958
968
  SnsService,
@@ -1,19 +1,188 @@
1
- import {
2
- AVACUS_ENDPOINTS,
3
- BASE_CONNECT_SIGNED_MSG,
4
- BASE_GAS_SPONSOR_SIGNED_MSG,
5
- BASE_REDIRECT_SIGNED_MSG,
6
- DEFAULT_BASE_SIGNED_MESSAGE,
7
- HttpAdapter,
8
- SNS_SERVICE_PATH,
9
- SnsAuthClient,
10
- SnsService,
11
- isKnownAvacusBaseUrl,
12
- loginWithSns,
13
- resolveAvacusBaseUrl,
14
- resolveClientSettings,
15
- resolveServiceUrl
16
- } from "./chunk-XWC6XZPN.mjs";
1
+ // packages/sdk/src/config.ts
2
+ var AVACUS_ENDPOINTS = {
3
+ prod: "https://apis.avacus.cc/",
4
+ dev: "https://apis.d.avscc.unit-hosting.net/",
5
+ stg: "https://apis.avacus.cc/stg/"
6
+ };
7
+ function resolveAvacusBaseUrl(options) {
8
+ if (options.baseUrl) {
9
+ return options.baseUrl;
10
+ }
11
+ return AVACUS_ENDPOINTS[options.env ?? "prod"];
12
+ }
13
+ function resolveClientSettings(options = {}) {
14
+ return {
15
+ env: options.env ?? "prod",
16
+ baseUrl: resolveAvacusBaseUrl(options),
17
+ headers: options.headers
18
+ };
19
+ }
20
+ function isKnownAvacusBaseUrl(baseUrl) {
21
+ return Object.values(AVACUS_ENDPOINTS).includes(baseUrl);
22
+ }
23
+ function resolveServiceUrl(baseUrl, servicePath) {
24
+ const normalizedServicePath = servicePath.endsWith("/") ? servicePath : `${servicePath}/`;
25
+ return new URL(normalizedServicePath, baseUrl).toString();
26
+ }
27
+
28
+ // packages/sdk/src/adapters/http.ts
29
+ var HttpAdapter = class {
30
+ /**
31
+ * Creates a reusable HTTP transport bound to one service base URL.
32
+ *
33
+ * @param baseUrl Absolute base URL for the target service namespace.
34
+ * @param headers Default headers sent with every request.
35
+ * @param authState Shared mutable auth state so multiple adapters can reuse the same JWT.
36
+ */
37
+ constructor(baseUrl, headers = {}, authState = {}) {
38
+ this.baseUrl = baseUrl;
39
+ this.headers = headers;
40
+ this.authState = authState;
41
+ }
42
+ baseUrl;
43
+ headers;
44
+ authState;
45
+ /**
46
+ * Stores the JWT access token used by authenticated requests.
47
+ *
48
+ * @param accessToken JWT returned by the authentication flow.
49
+ */
50
+ setAccessToken(accessToken) {
51
+ this.authState.accessToken = accessToken;
52
+ }
53
+ /**
54
+ * Removes the currently stored JWT access token from shared auth state.
55
+ */
56
+ clearAccessToken() {
57
+ delete this.authState.accessToken;
58
+ }
59
+ /**
60
+ * Returns the currently stored JWT access token, if any.
61
+ */
62
+ getAccessToken() {
63
+ return this.authState.accessToken;
64
+ }
65
+ /**
66
+ * Sends an HTTP GET request to a path relative to this adapter base URL.
67
+ *
68
+ * @param path Relative endpoint path.
69
+ * @param options Request behavior such as auth requirement and extra headers.
70
+ */
71
+ async get(path, options = {}) {
72
+ const response = await fetch(this.buildUrl(path), {
73
+ method: "GET",
74
+ headers: this.buildHeaders(options)
75
+ });
76
+ return this.parseResponse(response, "GET", path);
77
+ }
78
+ /**
79
+ * Sends an HTTP POST request with a JSON body to a path relative to this adapter base URL.
80
+ *
81
+ * @param path Relative endpoint path.
82
+ * @param body Serializable request payload.
83
+ * @param options Request behavior such as auth requirement and extra headers.
84
+ */
85
+ async post(path, body, options = {}) {
86
+ const response = await fetch(this.buildUrl(path), {
87
+ method: "POST",
88
+ headers: this.buildHeaders({
89
+ ...options,
90
+ headers: {
91
+ "Content-Type": "application/json",
92
+ ...options.headers
93
+ }
94
+ }),
95
+ body: body === void 0 ? void 0 : JSON.stringify(body)
96
+ });
97
+ return this.parseResponse(response, "POST", path);
98
+ }
99
+ /**
100
+ * Sends an HTTP PUT request with a JSON body to a path relative to this adapter base URL.
101
+ *
102
+ * @param path Relative endpoint path.
103
+ * @param body Serializable request payload.
104
+ * @param options Request behavior such as auth requirement and extra headers.
105
+ */
106
+ async put(path, body, options = {}) {
107
+ const response = await fetch(this.buildUrl(path), {
108
+ method: "PUT",
109
+ headers: this.buildHeaders({
110
+ ...options,
111
+ headers: {
112
+ "Content-Type": "application/json",
113
+ ...options.headers
114
+ }
115
+ }),
116
+ body: body === void 0 ? void 0 : JSON.stringify(body)
117
+ });
118
+ return this.parseResponse(response, "PUT", path);
119
+ }
120
+ /**
121
+ * Sends an HTTP DELETE request with an optional JSON body to a path relative to this adapter base URL.
122
+ *
123
+ * @param path Relative endpoint path.
124
+ * @param body Optional serializable request payload.
125
+ * @param options Request behavior such as auth requirement and extra headers.
126
+ */
127
+ async delete(path, body, options = {}) {
128
+ const headers = body === void 0 ? this.buildHeaders(options) : this.buildHeaders({
129
+ ...options,
130
+ headers: {
131
+ "Content-Type": "application/json",
132
+ ...options.headers
133
+ }
134
+ });
135
+ const response = await fetch(this.buildUrl(path), {
136
+ method: "DELETE",
137
+ headers,
138
+ body: body === void 0 ? void 0 : JSON.stringify(body)
139
+ });
140
+ return this.parseResponse(response, "DELETE", path);
141
+ }
142
+ /**
143
+ * Builds the final request headers by combining default headers, per-request
144
+ * headers, and an authorization header when the request requires auth.
145
+ */
146
+ buildHeaders(options) {
147
+ const accessToken = this.authState.accessToken;
148
+ if (options.auth && !accessToken) {
149
+ throw new Error("This request requires authentication. Call login() first.");
150
+ }
151
+ return {
152
+ ...this.headers,
153
+ ...options.headers,
154
+ ...options.auth && accessToken ? {
155
+ Authorization: `Bearer ${accessToken}`
156
+ } : {}
157
+ };
158
+ }
159
+ /**
160
+ * Resolves a relative path against the adapter base URL.
161
+ */
162
+ buildUrl(path) {
163
+ const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
164
+ return new URL(normalizedPath, this.baseUrl);
165
+ }
166
+ /**
167
+ * Parses a JSON response and converts non-2xx responses into descriptive errors.
168
+ */
169
+ async parseResponse(response, method, path) {
170
+ const bodyText = await response.text();
171
+ if (!response.ok) {
172
+ throw new Error(
173
+ `HTTP ${response.status} ${response.statusText} for ${method} ${path}: ${bodyText}`
174
+ );
175
+ }
176
+ try {
177
+ return JSON.parse(bodyText);
178
+ } catch (error) {
179
+ throw new Error(
180
+ `Invalid JSON response for ${method} ${path}: ${bodyText}`,
181
+ { cause: error }
182
+ );
183
+ }
184
+ }
185
+ };
17
186
 
18
187
  // packages/sdk/src/services/balancer.ts
19
188
  var BalancerService = class {
@@ -403,6 +572,9 @@ var GasAccountService = class {
403
572
  }
404
573
  /**
405
574
  * Creates a gas-usage request against the caller's balance or a whitelisted source address.
575
+ * When `sourceAddress` is provided, the caller spends from another owner's
576
+ * gas account and therefore must already be registered as a whitelist spender
577
+ * for that source account.
406
578
  *
407
579
  * @param params Usage request payload.
408
580
  *
@@ -415,6 +587,15 @@ var GasAccountService = class {
415
587
  * gasPrice: 5,
416
588
  * notes: 'Gas for token transfer',
417
589
  * });
590
+ *
591
+ * await client.gasAccount.useBalance({
592
+ * toAddress: '0x9876543210987654321098765432109876543210',
593
+ * chainId: 97,
594
+ * gasLimit: 21000,
595
+ * gasPrice: 5,
596
+ * sourceAddress: '0x610b463d2f57d2e0d9e785a7ff423fbae36f0624',
597
+ * notes: 'Use gas from delegated source account',
598
+ * });
418
599
  * ```
419
600
  */
420
601
  async useBalance(params) {
@@ -497,6 +678,178 @@ var GasAccountService = class {
497
678
  }
498
679
  };
499
680
 
681
+ // packages/sdk/src/services/sns.ts
682
+ 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: ";
683
+ 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: ";
684
+ 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: ";
685
+ 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: ";
686
+ var BASE_SIGNED_MESSAGE_BY_SERVICE = {
687
+ connect: BASE_CONNECT_SIGNED_MSG,
688
+ redirect: BASE_REDIRECT_SIGNED_MSG,
689
+ "gas-sponsor": BASE_GAS_SPONSOR_SIGNED_MSG
690
+ };
691
+ var SNS_SERVICE_PATH = "1/secure-chat/";
692
+ var SnsService = class {
693
+ /**
694
+ * Creates the SNS service using a service-scoped HTTP adapter.
695
+ *
696
+ * @param http Adapter already configured for the SNS base path.
697
+ * @param options Optional SNS-specific behavior.
698
+ */
699
+ constructor(http, options = {}) {
700
+ this.http = http;
701
+ this.options = options;
702
+ }
703
+ http;
704
+ options;
705
+ /**
706
+ * Requests a one-time nonce used to construct the login signature message.
707
+ * This endpoint is public and does not require a JWT token.
708
+ *
709
+ * @param params Wallet identity used by the backend to mint a nonce.
710
+ */
711
+ async getNonce(params) {
712
+ const searchParams = new URLSearchParams({
713
+ wallet_address: params.walletAddress
714
+ });
715
+ return this.http.get(`v1/public/users/nonce?${searchParams.toString()}`);
716
+ }
717
+ /**
718
+ * Exchanges a signed message payload for an SNS auth token.
719
+ * This is the low-level authentication endpoint behind `login()`.
720
+ *
721
+ * @param params Payload expected by the SNS auth API.
722
+ */
723
+ async requestAuthToken(params) {
724
+ return this.http.post("v2/public/users/request_auth_token", params);
725
+ }
726
+ /**
727
+ * Returns public user profiles for a batch of wallet addresses and/or user IDs.
728
+ * This endpoint is public and does not require authentication.
729
+ *
730
+ * @param params Query payload with wallet addresses and/or user IDs.
731
+ */
732
+ async getPublicProfiles(params) {
733
+ return this.http.post("v1/public/users/profiles", {
734
+ wallets: params.wallets,
735
+ user_ids: params.userIds,
736
+ include_devices: params.includeDevices
737
+ });
738
+ }
739
+ /**
740
+ * Creates a new SNS user account using only the inputs the application already knows:
741
+ * wallet address, signer callback, and optional user profile metadata.
742
+ * The SDK internally fetches a nonce, builds the canonical message, requests
743
+ * the signature, and submits the create-user payload.
744
+ *
745
+ * @param params User creation payload in SDK-friendly camelCase format.
746
+ */
747
+ async createUser(params) {
748
+ const { walletAddress, signMessage } = params;
749
+ const { nonce } = await this.getNonce({ walletAddress });
750
+ const message = this.buildLoginMessage(nonce);
751
+ const signature = await signMessage(message);
752
+ return this.createUserWithSignature({
753
+ walletAddress,
754
+ message,
755
+ signature,
756
+ publicKey: params.publicKey,
757
+ displayName: params.displayName,
758
+ description: params.description,
759
+ device: params.device
760
+ });
761
+ }
762
+ /**
763
+ * Low-level create-user API for callers that already have a prepared message
764
+ * and signature and want direct control over the exact payload.
765
+ *
766
+ * @param params Signed create-user payload.
767
+ */
768
+ async createUserWithSignature(params) {
769
+ const result = await this.http.post(
770
+ "v1/public/users",
771
+ {
772
+ wallet_address: params.walletAddress,
773
+ message: params.message,
774
+ signature: params.signature,
775
+ public_key: params.publicKey,
776
+ display_name: params.displayName,
777
+ description: params.description,
778
+ device: params.device ? {
779
+ device_token: params.device.deviceToken,
780
+ app_name: params.device.appName,
781
+ app_version: params.device.appVersion,
782
+ platform: params.device.platform
783
+ } : void 0
784
+ }
785
+ );
786
+ const accessToken = extractAccessToken(result);
787
+ if (accessToken) {
788
+ this.http.setAccessToken(accessToken);
789
+ }
790
+ return result;
791
+ }
792
+ /**
793
+ * Adapts camelCase SDK parameters to the snake_case payload expected by the backend.
794
+ *
795
+ * @param params Wallet address, signed message, and signature returned by the signer.
796
+ */
797
+ async authenticate(params) {
798
+ return this.requestAuthToken({
799
+ wallet_address: params.walletAddress,
800
+ message: params.message,
801
+ signature: params.signature,
802
+ service_name: params.serviceName
803
+ });
804
+ }
805
+ /**
806
+ * Executes the full SNS login flow:
807
+ * 1. fetch nonce
808
+ * 2. build login message
809
+ * 3. sign message via injected signer callback
810
+ * 4. exchange signature for JWT
811
+ * 5. persist token in shared HTTP auth state
812
+ *
813
+ * @param params Wallet address and async signing callback.
814
+ */
815
+ async login(params) {
816
+ const { walletAddress, signMessage, serviceName } = params;
817
+ const { nonce } = await this.getNonce({ walletAddress });
818
+ const message = this.buildLoginMessage(nonce, serviceName);
819
+ const signature = await signMessage(message);
820
+ const result = await this.authenticate({
821
+ walletAddress,
822
+ message,
823
+ signature,
824
+ serviceName
825
+ });
826
+ const accessToken = extractAccessToken(result);
827
+ if (accessToken) {
828
+ this.http.setAccessToken(accessToken);
829
+ }
830
+ return result;
831
+ }
832
+ /**
833
+ * Builds the exact message string that the wallet must sign during login.
834
+ */
835
+ buildLoginMessage(nonce, serviceName) {
836
+ const baseMessage = serviceName != null ? BASE_SIGNED_MESSAGE_BY_SERVICE[serviceName] : this.options.baseSignedMessage ?? DEFAULT_BASE_SIGNED_MESSAGE;
837
+ return `${baseMessage}${nonce}`;
838
+ }
839
+ };
840
+ function extractAccessToken(result) {
841
+ if ("data" in result && typeof result.data === "object" && result.data !== null) {
842
+ const token = result.data.token;
843
+ if (typeof token === "string" && token.length > 0) {
844
+ return token;
845
+ }
846
+ }
847
+ return void 0;
848
+ }
849
+ async function loginWithSns(sns, params) {
850
+ return sns.login(params);
851
+ }
852
+
500
853
  // packages/sdk/src/core/client.ts
501
854
  var AvacusClient = class {
502
855
  http;
@@ -531,6 +884,30 @@ var AvacusClient = class {
531
884
  this.balancer = new BalancerService(this.http);
532
885
  }
533
886
  };
887
+
888
+ // packages/sdk/src/sns.ts
889
+ var SnsAuthClient = class extends SnsService {
890
+ settings;
891
+ usingCustomBaseUrl;
892
+ constructor(options = {}) {
893
+ const settings = resolveClientSettings(options);
894
+ const http = new HttpAdapter(
895
+ resolveServiceUrl(settings.baseUrl, "1/secure-chat/"),
896
+ settings.headers
897
+ );
898
+ super(http, {
899
+ baseSignedMessage: options.baseSignedMessage
900
+ });
901
+ this.settings = settings;
902
+ this.usingCustomBaseUrl = !isKnownAvacusBaseUrl(settings.baseUrl);
903
+ }
904
+ getSettings() {
905
+ return { ...this.settings };
906
+ }
907
+ isUsingCustomBaseUrl() {
908
+ return this.usingCustomBaseUrl;
909
+ }
910
+ };
534
911
  export {
535
912
  AVACUS_ENDPOINTS,
536
913
  AvacusClient,
@@ -542,7 +919,6 @@ export {
542
919
  DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION,
543
920
  GAS_ACCOUNT_SERVICE_PATH,
544
921
  GasAccountService,
545
- HttpAdapter,
546
922
  SNS_SERVICE_PATH,
547
923
  SnsAuthClient,
548
924
  SnsService,
@@ -287,4 +287,4 @@ declare class SnsAuthClient extends SnsService {
287
287
  isUsingCustomBaseUrl(): boolean;
288
288
  }
289
289
 
290
- export { AVACUS_ENDPOINTS as A, type BaseClientOptions as B, type SnsServiceOptions as C, DEFAULT_BASE_SIGNED_MESSAGE as D, isKnownAvacusBaseUrl as E, loginWithSns as F, resolveAvacusBaseUrl as G, HttpAdapter as H, resolveClientSettings as I, resolveServiceUrl as J, type RequestOptions as R, SnsService as S, type AuthState as a, type AvacusEnvironment as b, BASE_CONNECT_SIGNED_MSG as c, BASE_GAS_SPONSOR_SIGNED_MSG as d, BASE_REDIRECT_SIGNED_MSG as e, type ResolvedClientSettings as f, SNS_SERVICE_PATH as g, type SignMessageFn as h, SnsAuthClient as i, type SnsAuthClientOptions as j, type SnsAuthTokenPayload as k, type SnsAuthenticateParams as l, type SnsAvatar as m, type SnsCreateUserDeviceParams as n, type SnsCreateUserParams as o, type SnsCreateUserPayload as p, type SnsCreateUserResult as q, type SnsCreateUserWithSignatureParams as r, type SnsDevice as s, type SnsGetNonceParams as t, type SnsGetProfilesParams as u, type SnsLoginParams as v, type SnsLoginResult as w, type SnsNonceResponse as x, type SnsProfile as y, type SnsServiceName as z };
290
+ export { AVACUS_ENDPOINTS as A, type BaseClientOptions as B, loginWithSns as C, DEFAULT_BASE_SIGNED_MESSAGE as D, resolveAvacusBaseUrl as E, resolveClientSettings as F, resolveServiceUrl as G, HttpAdapter as H, type ResolvedClientSettings as R, SnsService as S, type AvacusEnvironment as a, BASE_CONNECT_SIGNED_MSG as b, BASE_GAS_SPONSOR_SIGNED_MSG as c, BASE_REDIRECT_SIGNED_MSG as d, SNS_SERVICE_PATH as e, type SignMessageFn as f, SnsAuthClient as g, type SnsAuthClientOptions as h, type SnsAuthTokenPayload as i, type SnsAuthenticateParams as j, type SnsAvatar as k, type SnsCreateUserDeviceParams as l, type SnsCreateUserParams as m, type SnsCreateUserPayload as n, type SnsCreateUserResult as o, type SnsCreateUserWithSignatureParams as p, type SnsDevice as q, type SnsGetNonceParams as r, type SnsGetProfilesParams as s, type SnsLoginParams as t, type SnsLoginResult as u, type SnsNonceResponse as v, type SnsProfile as w, type SnsServiceName as x, type SnsServiceOptions as y, isKnownAvacusBaseUrl as z };
@@ -287,4 +287,4 @@ declare class SnsAuthClient extends SnsService {
287
287
  isUsingCustomBaseUrl(): boolean;
288
288
  }
289
289
 
290
- export { AVACUS_ENDPOINTS as A, type BaseClientOptions as B, type SnsServiceOptions as C, DEFAULT_BASE_SIGNED_MESSAGE as D, isKnownAvacusBaseUrl as E, loginWithSns as F, resolveAvacusBaseUrl as G, HttpAdapter as H, resolveClientSettings as I, resolveServiceUrl as J, type RequestOptions as R, SnsService as S, type AuthState as a, type AvacusEnvironment as b, BASE_CONNECT_SIGNED_MSG as c, BASE_GAS_SPONSOR_SIGNED_MSG as d, BASE_REDIRECT_SIGNED_MSG as e, type ResolvedClientSettings as f, SNS_SERVICE_PATH as g, type SignMessageFn as h, SnsAuthClient as i, type SnsAuthClientOptions as j, type SnsAuthTokenPayload as k, type SnsAuthenticateParams as l, type SnsAvatar as m, type SnsCreateUserDeviceParams as n, type SnsCreateUserParams as o, type SnsCreateUserPayload as p, type SnsCreateUserResult as q, type SnsCreateUserWithSignatureParams as r, type SnsDevice as s, type SnsGetNonceParams as t, type SnsGetProfilesParams as u, type SnsLoginParams as v, type SnsLoginResult as w, type SnsNonceResponse as x, type SnsProfile as y, type SnsServiceName as z };
290
+ export { AVACUS_ENDPOINTS as A, type BaseClientOptions as B, loginWithSns as C, DEFAULT_BASE_SIGNED_MESSAGE as D, resolveAvacusBaseUrl as E, resolveClientSettings as F, resolveServiceUrl as G, HttpAdapter as H, type ResolvedClientSettings as R, SnsService as S, type AvacusEnvironment as a, BASE_CONNECT_SIGNED_MSG as b, BASE_GAS_SPONSOR_SIGNED_MSG as c, BASE_REDIRECT_SIGNED_MSG as d, SNS_SERVICE_PATH as e, type SignMessageFn as f, SnsAuthClient as g, type SnsAuthClientOptions as h, type SnsAuthTokenPayload as i, type SnsAuthenticateParams as j, type SnsAvatar as k, type SnsCreateUserDeviceParams as l, type SnsCreateUserParams as m, type SnsCreateUserPayload as n, type SnsCreateUserResult as o, type SnsCreateUserWithSignatureParams as p, type SnsDevice as q, type SnsGetNonceParams as r, type SnsGetProfilesParams as s, type SnsLoginParams as t, type SnsLoginResult as u, type SnsNonceResponse as v, type SnsProfile as w, type SnsServiceName as x, type SnsServiceOptions as y, isKnownAvacusBaseUrl as z };
@@ -1 +1 @@
1
- export { A as AVACUS_ENDPOINTS, a as AuthState, b as AvacusEnvironment, c as BASE_CONNECT_SIGNED_MSG, d as BASE_GAS_SPONSOR_SIGNED_MSG, e as BASE_REDIRECT_SIGNED_MSG, D as DEFAULT_BASE_SIGNED_MESSAGE, H as HttpAdapter, R as RequestOptions, f as ResolvedClientSettings, h as SignMessageFn, i as SnsAuthClient, j as SnsAuthClientOptions, k as SnsAuthTokenPayload, l as SnsAuthenticateParams, m as SnsAvatar, n as SnsCreateUserDeviceParams, o as SnsCreateUserParams, p as SnsCreateUserPayload, q as SnsCreateUserResult, r as SnsCreateUserWithSignatureParams, s as SnsDevice, t as SnsGetNonceParams, u as SnsGetProfilesParams, v as SnsLoginParams, w as SnsLoginResult, x as SnsNonceResponse, y as SnsProfile, S as SnsService, z as SnsServiceName, C as SnsServiceOptions, F as loginWithSns } from './sns-Zwan9DNM.mjs';
1
+ export { A as AVACUS_ENDPOINTS, a as AvacusEnvironment, b as BASE_CONNECT_SIGNED_MSG, c as BASE_GAS_SPONSOR_SIGNED_MSG, d as BASE_REDIRECT_SIGNED_MSG, D as DEFAULT_BASE_SIGNED_MESSAGE, R as ResolvedClientSettings, f as SignMessageFn, g as SnsAuthClient, h as SnsAuthClientOptions, i as SnsAuthTokenPayload, j as SnsAuthenticateParams, k as SnsAvatar, l as SnsCreateUserDeviceParams, m as SnsCreateUserParams, n as SnsCreateUserPayload, o as SnsCreateUserResult, p as SnsCreateUserWithSignatureParams, q as SnsDevice, r as SnsGetNonceParams, s as SnsGetProfilesParams, t as SnsLoginParams, u as SnsLoginResult, v as SnsNonceResponse, w as SnsProfile, S as SnsService, x as SnsServiceName, y as SnsServiceOptions, C as loginWithSns } from './sns-NuV2JpAA.mjs';