@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.
@@ -70,6 +70,22 @@ declare class HttpAdapter {
70
70
  * @param options Request behavior such as auth requirement and extra headers.
71
71
  */
72
72
  post<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
73
+ /**
74
+ * Sends an HTTP PUT request with a JSON body to a path relative to this adapter base URL.
75
+ *
76
+ * @param path Relative endpoint path.
77
+ * @param body Serializable request payload.
78
+ * @param options Request behavior such as auth requirement and extra headers.
79
+ */
80
+ put<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
81
+ /**
82
+ * Sends an HTTP DELETE request with an optional JSON body to a path relative to this adapter base URL.
83
+ *
84
+ * @param path Relative endpoint path.
85
+ * @param body Optional serializable request payload.
86
+ * @param options Request behavior such as auth requirement and extra headers.
87
+ */
88
+ delete<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
73
89
  /**
74
90
  * Builds the final request headers by combining default headers, per-request
75
91
  * headers, and an authorization header when the request requires auth.
@@ -86,9 +102,11 @@ declare class HttpAdapter {
86
102
  }
87
103
 
88
104
  type SignMessageFn = (message: string) => Promise<string>;
105
+ type SnsServiceName = 'connect' | 'redirect' | 'gas-sponsor';
89
106
  interface SnsLoginParams {
90
107
  walletAddress: string;
91
108
  signMessage: SignMessageFn;
109
+ serviceName?: SnsServiceName;
92
110
  }
93
111
  interface SnsGetNonceParams {
94
112
  walletAddress: string;
@@ -97,11 +115,13 @@ interface SnsAuthenticateParams {
97
115
  walletAddress: string;
98
116
  message: string;
99
117
  signature: string;
118
+ serviceName?: SnsServiceName;
100
119
  }
101
120
  interface SnsAuthTokenPayload {
102
121
  wallet_address: string;
103
122
  message: string;
104
123
  signature: string;
124
+ service_name?: SnsServiceName;
105
125
  }
106
126
  interface SnsGetProfilesParams {
107
127
  wallets?: string[];
@@ -175,6 +195,9 @@ interface SnsServiceOptions {
175
195
  }
176
196
 
177
197
  declare const 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: ";
198
+ declare const 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: ";
199
+ declare const 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: ";
200
+ declare const 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: ";
178
201
  /**
179
202
  * Base path for all SNS endpoints. The client composes this with the resolved
180
203
  * environment host before injecting the HTTP adapter into the service.
@@ -264,4 +287,4 @@ declare class SnsAuthClient extends SnsService {
264
287
  isUsingCustomBaseUrl(): boolean;
265
288
  }
266
289
 
267
- export { AVACUS_ENDPOINTS as A, type BaseClientOptions as B, resolveClientSettings as C, DEFAULT_BASE_SIGNED_MESSAGE as D, resolveServiceUrl as E, HttpAdapter as H, type RequestOptions as R, SnsService as S, type AuthState as a, type AvacusEnvironment as b, type ResolvedClientSettings as c, SNS_SERVICE_PATH as d, type SignMessageFn as e, SnsAuthClient as f, type SnsAuthClientOptions as g, type SnsAuthTokenPayload as h, type SnsAuthenticateParams as i, type SnsAvatar as j, type SnsCreateUserDeviceParams as k, type SnsCreateUserParams as l, type SnsCreateUserPayload as m, type SnsCreateUserResult as n, type SnsCreateUserWithSignatureParams as o, type SnsDevice as p, type SnsGetNonceParams as q, type SnsGetProfilesParams as r, type SnsLoginParams as s, type SnsLoginResult as t, type SnsNonceResponse as u, type SnsProfile as v, type SnsServiceOptions as w, isKnownAvacusBaseUrl as x, loginWithSns as y, resolveAvacusBaseUrl 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 };
@@ -70,6 +70,22 @@ declare class HttpAdapter {
70
70
  * @param options Request behavior such as auth requirement and extra headers.
71
71
  */
72
72
  post<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
73
+ /**
74
+ * Sends an HTTP PUT request with a JSON body to a path relative to this adapter base URL.
75
+ *
76
+ * @param path Relative endpoint path.
77
+ * @param body Serializable request payload.
78
+ * @param options Request behavior such as auth requirement and extra headers.
79
+ */
80
+ put<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
81
+ /**
82
+ * Sends an HTTP DELETE request with an optional JSON body to a path relative to this adapter base URL.
83
+ *
84
+ * @param path Relative endpoint path.
85
+ * @param body Optional serializable request payload.
86
+ * @param options Request behavior such as auth requirement and extra headers.
87
+ */
88
+ delete<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
73
89
  /**
74
90
  * Builds the final request headers by combining default headers, per-request
75
91
  * headers, and an authorization header when the request requires auth.
@@ -86,9 +102,11 @@ declare class HttpAdapter {
86
102
  }
87
103
 
88
104
  type SignMessageFn = (message: string) => Promise<string>;
105
+ type SnsServiceName = 'connect' | 'redirect' | 'gas-sponsor';
89
106
  interface SnsLoginParams {
90
107
  walletAddress: string;
91
108
  signMessage: SignMessageFn;
109
+ serviceName?: SnsServiceName;
92
110
  }
93
111
  interface SnsGetNonceParams {
94
112
  walletAddress: string;
@@ -97,11 +115,13 @@ interface SnsAuthenticateParams {
97
115
  walletAddress: string;
98
116
  message: string;
99
117
  signature: string;
118
+ serviceName?: SnsServiceName;
100
119
  }
101
120
  interface SnsAuthTokenPayload {
102
121
  wallet_address: string;
103
122
  message: string;
104
123
  signature: string;
124
+ service_name?: SnsServiceName;
105
125
  }
106
126
  interface SnsGetProfilesParams {
107
127
  wallets?: string[];
@@ -175,6 +195,9 @@ interface SnsServiceOptions {
175
195
  }
176
196
 
177
197
  declare const 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: ";
198
+ declare const 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: ";
199
+ declare const 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: ";
200
+ declare const 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: ";
178
201
  /**
179
202
  * Base path for all SNS endpoints. The client composes this with the resolved
180
203
  * environment host before injecting the HTTP adapter into the service.
@@ -264,4 +287,4 @@ declare class SnsAuthClient extends SnsService {
264
287
  isUsingCustomBaseUrl(): boolean;
265
288
  }
266
289
 
267
- export { AVACUS_ENDPOINTS as A, type BaseClientOptions as B, resolveClientSettings as C, DEFAULT_BASE_SIGNED_MESSAGE as D, resolveServiceUrl as E, HttpAdapter as H, type RequestOptions as R, SnsService as S, type AuthState as a, type AvacusEnvironment as b, type ResolvedClientSettings as c, SNS_SERVICE_PATH as d, type SignMessageFn as e, SnsAuthClient as f, type SnsAuthClientOptions as g, type SnsAuthTokenPayload as h, type SnsAuthenticateParams as i, type SnsAvatar as j, type SnsCreateUserDeviceParams as k, type SnsCreateUserParams as l, type SnsCreateUserPayload as m, type SnsCreateUserResult as n, type SnsCreateUserWithSignatureParams as o, type SnsDevice as p, type SnsGetNonceParams as q, type SnsGetProfilesParams as r, type SnsLoginParams as s, type SnsLoginResult as t, type SnsNonceResponse as u, type SnsProfile as v, type SnsServiceOptions as w, isKnownAvacusBaseUrl as x, loginWithSns as y, resolveAvacusBaseUrl 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, D as DEFAULT_BASE_SIGNED_MESSAGE, H as HttpAdapter, R as RequestOptions, c as ResolvedClientSettings, e as SignMessageFn, f as SnsAuthClient, g as SnsAuthClientOptions, h as SnsAuthTokenPayload, i as SnsAuthenticateParams, j as SnsAvatar, k as SnsCreateUserDeviceParams, l as SnsCreateUserParams, m as SnsCreateUserPayload, n as SnsCreateUserResult, o as SnsCreateUserWithSignatureParams, p as SnsDevice, q as SnsGetNonceParams, r as SnsGetProfilesParams, s as SnsLoginParams, t as SnsLoginResult, u as SnsNonceResponse, v as SnsProfile, S as SnsService, w as SnsServiceOptions, y as loginWithSns } from './sns-D0rtlsZp.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';
@@ -1 +1 @@
1
- export { A as AVACUS_ENDPOINTS, a as AuthState, b as AvacusEnvironment, D as DEFAULT_BASE_SIGNED_MESSAGE, H as HttpAdapter, R as RequestOptions, c as ResolvedClientSettings, e as SignMessageFn, f as SnsAuthClient, g as SnsAuthClientOptions, h as SnsAuthTokenPayload, i as SnsAuthenticateParams, j as SnsAvatar, k as SnsCreateUserDeviceParams, l as SnsCreateUserParams, m as SnsCreateUserPayload, n as SnsCreateUserResult, o as SnsCreateUserWithSignatureParams, p as SnsDevice, q as SnsGetNonceParams, r as SnsGetProfilesParams, s as SnsLoginParams, t as SnsLoginResult, u as SnsNonceResponse, v as SnsProfile, S as SnsService, w as SnsServiceOptions, y as loginWithSns } from './sns-D0rtlsZp.js';
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.js';
@@ -21,8 +21,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var sns_exports = {};
22
22
  __export(sns_exports, {
23
23
  AVACUS_ENDPOINTS: () => AVACUS_ENDPOINTS,
24
+ BASE_CONNECT_SIGNED_MSG: () => BASE_CONNECT_SIGNED_MSG,
25
+ BASE_GAS_SPONSOR_SIGNED_MSG: () => BASE_GAS_SPONSOR_SIGNED_MSG,
26
+ BASE_REDIRECT_SIGNED_MSG: () => BASE_REDIRECT_SIGNED_MSG,
24
27
  DEFAULT_BASE_SIGNED_MESSAGE: () => DEFAULT_BASE_SIGNED_MESSAGE,
25
- HttpAdapter: () => HttpAdapter,
26
28
  SnsAuthClient: () => SnsAuthClient,
27
29
  SnsService: () => SnsService,
28
30
  loginWithSns: () => loginWithSns
@@ -100,6 +102,49 @@ var HttpAdapter = class {
100
102
  });
101
103
  return this.parseResponse(response, "POST", path);
102
104
  }
105
+ /**
106
+ * Sends an HTTP PUT request with a JSON body to a path relative to this adapter base URL.
107
+ *
108
+ * @param path Relative endpoint path.
109
+ * @param body Serializable request payload.
110
+ * @param options Request behavior such as auth requirement and extra headers.
111
+ */
112
+ async put(path, body, options = {}) {
113
+ const response = await fetch(this.buildUrl(path), {
114
+ method: "PUT",
115
+ headers: this.buildHeaders({
116
+ ...options,
117
+ headers: {
118
+ "Content-Type": "application/json",
119
+ ...options.headers
120
+ }
121
+ }),
122
+ body: body === void 0 ? void 0 : JSON.stringify(body)
123
+ });
124
+ return this.parseResponse(response, "PUT", path);
125
+ }
126
+ /**
127
+ * Sends an HTTP DELETE request with an optional JSON body to a path relative to this adapter base URL.
128
+ *
129
+ * @param path Relative endpoint path.
130
+ * @param body Optional serializable request payload.
131
+ * @param options Request behavior such as auth requirement and extra headers.
132
+ */
133
+ async delete(path, body, options = {}) {
134
+ const headers = body === void 0 ? this.buildHeaders(options) : this.buildHeaders({
135
+ ...options,
136
+ headers: {
137
+ "Content-Type": "application/json",
138
+ ...options.headers
139
+ }
140
+ });
141
+ const response = await fetch(this.buildUrl(path), {
142
+ method: "DELETE",
143
+ headers,
144
+ body: body === void 0 ? void 0 : JSON.stringify(body)
145
+ });
146
+ return this.parseResponse(response, "DELETE", path);
147
+ }
103
148
  /**
104
149
  * Builds the final request headers by combining default headers, per-request
105
150
  * headers, and an authorization header when the request requires auth.
@@ -174,6 +219,14 @@ function resolveServiceUrl(baseUrl, servicePath) {
174
219
 
175
220
  // packages/sdk/src/services/sns.ts
176
221
  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: ";
222
+ 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: ";
223
+ 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: ";
224
+ 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: ";
225
+ var BASE_SIGNED_MESSAGE_BY_SERVICE = {
226
+ connect: BASE_CONNECT_SIGNED_MSG,
227
+ redirect: BASE_REDIRECT_SIGNED_MSG,
228
+ "gas-sponsor": BASE_GAS_SPONSOR_SIGNED_MSG
229
+ };
177
230
  var SnsService = class {
178
231
  /**
179
232
  * Creates the SNS service using a service-scoped HTTP adapter.
@@ -206,7 +259,7 @@ var SnsService = class {
206
259
  * @param params Payload expected by the SNS auth API.
207
260
  */
208
261
  async requestAuthToken(params) {
209
- return this.http.post("v1/public/users/request_auth_token", params);
262
+ return this.http.post("v2/public/users/request_auth_token", params);
210
263
  }
211
264
  /**
212
265
  * Returns public user profiles for a batch of wallet addresses and/or user IDs.
@@ -283,7 +336,8 @@ var SnsService = class {
283
336
  return this.requestAuthToken({
284
337
  wallet_address: params.walletAddress,
285
338
  message: params.message,
286
- signature: params.signature
339
+ signature: params.signature,
340
+ service_name: params.serviceName
287
341
  });
288
342
  }
289
343
  /**
@@ -297,14 +351,15 @@ var SnsService = class {
297
351
  * @param params Wallet address and async signing callback.
298
352
  */
299
353
  async login(params) {
300
- const { walletAddress, signMessage } = params;
354
+ const { walletAddress, signMessage, serviceName } = params;
301
355
  const { nonce } = await this.getNonce({ walletAddress });
302
- const message = this.buildLoginMessage(nonce);
356
+ const message = this.buildLoginMessage(nonce, serviceName);
303
357
  const signature = await signMessage(message);
304
358
  const result = await this.authenticate({
305
359
  walletAddress,
306
360
  message,
307
- signature
361
+ signature,
362
+ serviceName
308
363
  });
309
364
  const accessToken = extractAccessToken(result);
310
365
  if (accessToken) {
@@ -315,16 +370,16 @@ var SnsService = class {
315
370
  /**
316
371
  * Builds the exact message string that the wallet must sign during login.
317
372
  */
318
- buildLoginMessage(nonce) {
319
- return `${this.options.baseSignedMessage ?? DEFAULT_BASE_SIGNED_MESSAGE}${nonce}`;
373
+ buildLoginMessage(nonce, serviceName) {
374
+ const baseMessage = serviceName != null ? BASE_SIGNED_MESSAGE_BY_SERVICE[serviceName] : this.options.baseSignedMessage ?? DEFAULT_BASE_SIGNED_MESSAGE;
375
+ return `${baseMessage}${nonce}`;
320
376
  }
321
377
  };
322
378
  function extractAccessToken(result) {
323
- const candidateKeys = ["access_token", "accessToken", "token", "jwt"];
324
- for (const key of candidateKeys) {
325
- const value = result[key];
326
- if (typeof value === "string" && value.length > 0) {
327
- return value;
379
+ if ("data" in result && typeof result.data === "object" && result.data !== null) {
380
+ const token = result.data.token;
381
+ if (typeof token === "string" && token.length > 0) {
382
+ return token;
328
383
  }
329
384
  }
330
385
  return void 0;
@@ -359,8 +414,10 @@ var SnsAuthClient = class extends SnsService {
359
414
  // Annotate the CommonJS export names for ESM import in node:
360
415
  0 && (module.exports = {
361
416
  AVACUS_ENDPOINTS,
417
+ BASE_CONNECT_SIGNED_MSG,
418
+ BASE_GAS_SPONSOR_SIGNED_MSG,
419
+ BASE_REDIRECT_SIGNED_MSG,
362
420
  DEFAULT_BASE_SIGNED_MESSAGE,
363
- HttpAdapter,
364
421
  SnsAuthClient,
365
422
  SnsService,
366
423
  loginWithSns