@avacuscc/sdk 0.1.0 → 0.2.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/README.md +246 -0
- package/package.json +1 -1
- package/packages/sdk/dist/{chunk-T5BAFYHX.mjs → chunk-XWC6XZPN.mjs} +68 -12
- package/packages/sdk/dist/index.d.mts +663 -7
- package/packages/sdk/dist/index.d.ts +663 -7
- package/packages/sdk/dist/index.js +520 -16
- package/packages/sdk/dist/index.mjs +455 -5
- package/packages/sdk/dist/{sns-D0rtlsZp.d.mts → sns-Zwan9DNM.d.mts} +24 -1
- package/packages/sdk/dist/{sns-D0rtlsZp.d.ts → sns-Zwan9DNM.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 -12
- package/packages/sdk/dist/sns.mjs +7 -1
package/packages/sdk/dist/sns.js
CHANGED
|
@@ -21,6 +21,9 @@ 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
28
|
HttpAdapter: () => HttpAdapter,
|
|
26
29
|
SnsAuthClient: () => SnsAuthClient,
|
|
@@ -100,6 +103,49 @@ var HttpAdapter = class {
|
|
|
100
103
|
});
|
|
101
104
|
return this.parseResponse(response, "POST", path);
|
|
102
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Sends an HTTP PUT request with a JSON body to a path relative to this adapter base URL.
|
|
108
|
+
*
|
|
109
|
+
* @param path Relative endpoint path.
|
|
110
|
+
* @param body Serializable request payload.
|
|
111
|
+
* @param options Request behavior such as auth requirement and extra headers.
|
|
112
|
+
*/
|
|
113
|
+
async put(path, body, options = {}) {
|
|
114
|
+
const response = await fetch(this.buildUrl(path), {
|
|
115
|
+
method: "PUT",
|
|
116
|
+
headers: this.buildHeaders({
|
|
117
|
+
...options,
|
|
118
|
+
headers: {
|
|
119
|
+
"Content-Type": "application/json",
|
|
120
|
+
...options.headers
|
|
121
|
+
}
|
|
122
|
+
}),
|
|
123
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
124
|
+
});
|
|
125
|
+
return this.parseResponse(response, "PUT", path);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Sends an HTTP DELETE request with an optional JSON body to a path relative to this adapter base URL.
|
|
129
|
+
*
|
|
130
|
+
* @param path Relative endpoint path.
|
|
131
|
+
* @param body Optional serializable request payload.
|
|
132
|
+
* @param options Request behavior such as auth requirement and extra headers.
|
|
133
|
+
*/
|
|
134
|
+
async delete(path, body, options = {}) {
|
|
135
|
+
const headers = body === void 0 ? this.buildHeaders(options) : this.buildHeaders({
|
|
136
|
+
...options,
|
|
137
|
+
headers: {
|
|
138
|
+
"Content-Type": "application/json",
|
|
139
|
+
...options.headers
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const response = await fetch(this.buildUrl(path), {
|
|
143
|
+
method: "DELETE",
|
|
144
|
+
headers,
|
|
145
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
146
|
+
});
|
|
147
|
+
return this.parseResponse(response, "DELETE", path);
|
|
148
|
+
}
|
|
103
149
|
/**
|
|
104
150
|
* Builds the final request headers by combining default headers, per-request
|
|
105
151
|
* headers, and an authorization header when the request requires auth.
|
|
@@ -174,6 +220,14 @@ function resolveServiceUrl(baseUrl, servicePath) {
|
|
|
174
220
|
|
|
175
221
|
// packages/sdk/src/services/sns.ts
|
|
176
222
|
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: ";
|
|
223
|
+
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: ";
|
|
224
|
+
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: ";
|
|
225
|
+
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: ";
|
|
226
|
+
var BASE_SIGNED_MESSAGE_BY_SERVICE = {
|
|
227
|
+
connect: BASE_CONNECT_SIGNED_MSG,
|
|
228
|
+
redirect: BASE_REDIRECT_SIGNED_MSG,
|
|
229
|
+
"gas-sponsor": BASE_GAS_SPONSOR_SIGNED_MSG
|
|
230
|
+
};
|
|
177
231
|
var SnsService = class {
|
|
178
232
|
/**
|
|
179
233
|
* Creates the SNS service using a service-scoped HTTP adapter.
|
|
@@ -206,7 +260,7 @@ var SnsService = class {
|
|
|
206
260
|
* @param params Payload expected by the SNS auth API.
|
|
207
261
|
*/
|
|
208
262
|
async requestAuthToken(params) {
|
|
209
|
-
return this.http.post("
|
|
263
|
+
return this.http.post("v2/public/users/request_auth_token", params);
|
|
210
264
|
}
|
|
211
265
|
/**
|
|
212
266
|
* Returns public user profiles for a batch of wallet addresses and/or user IDs.
|
|
@@ -283,7 +337,8 @@ var SnsService = class {
|
|
|
283
337
|
return this.requestAuthToken({
|
|
284
338
|
wallet_address: params.walletAddress,
|
|
285
339
|
message: params.message,
|
|
286
|
-
signature: params.signature
|
|
340
|
+
signature: params.signature,
|
|
341
|
+
service_name: params.serviceName
|
|
287
342
|
});
|
|
288
343
|
}
|
|
289
344
|
/**
|
|
@@ -297,14 +352,15 @@ var SnsService = class {
|
|
|
297
352
|
* @param params Wallet address and async signing callback.
|
|
298
353
|
*/
|
|
299
354
|
async login(params) {
|
|
300
|
-
const { walletAddress, signMessage } = params;
|
|
355
|
+
const { walletAddress, signMessage, serviceName } = params;
|
|
301
356
|
const { nonce } = await this.getNonce({ walletAddress });
|
|
302
|
-
const message = this.buildLoginMessage(nonce);
|
|
357
|
+
const message = this.buildLoginMessage(nonce, serviceName);
|
|
303
358
|
const signature = await signMessage(message);
|
|
304
359
|
const result = await this.authenticate({
|
|
305
360
|
walletAddress,
|
|
306
361
|
message,
|
|
307
|
-
signature
|
|
362
|
+
signature,
|
|
363
|
+
serviceName
|
|
308
364
|
});
|
|
309
365
|
const accessToken = extractAccessToken(result);
|
|
310
366
|
if (accessToken) {
|
|
@@ -315,16 +371,16 @@ var SnsService = class {
|
|
|
315
371
|
/**
|
|
316
372
|
* Builds the exact message string that the wallet must sign during login.
|
|
317
373
|
*/
|
|
318
|
-
buildLoginMessage(nonce) {
|
|
319
|
-
|
|
374
|
+
buildLoginMessage(nonce, serviceName) {
|
|
375
|
+
const baseMessage = serviceName != null ? BASE_SIGNED_MESSAGE_BY_SERVICE[serviceName] : this.options.baseSignedMessage ?? DEFAULT_BASE_SIGNED_MESSAGE;
|
|
376
|
+
return `${baseMessage}${nonce}`;
|
|
320
377
|
}
|
|
321
378
|
};
|
|
322
379
|
function extractAccessToken(result) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return value;
|
|
380
|
+
if ("data" in result && typeof result.data === "object" && result.data !== null) {
|
|
381
|
+
const token = result.data.token;
|
|
382
|
+
if (typeof token === "string" && token.length > 0) {
|
|
383
|
+
return token;
|
|
328
384
|
}
|
|
329
385
|
}
|
|
330
386
|
return void 0;
|
|
@@ -359,6 +415,9 @@ var SnsAuthClient = class extends SnsService {
|
|
|
359
415
|
// Annotate the CommonJS export names for ESM import in node:
|
|
360
416
|
0 && (module.exports = {
|
|
361
417
|
AVACUS_ENDPOINTS,
|
|
418
|
+
BASE_CONNECT_SIGNED_MSG,
|
|
419
|
+
BASE_GAS_SPONSOR_SIGNED_MSG,
|
|
420
|
+
BASE_REDIRECT_SIGNED_MSG,
|
|
362
421
|
DEFAULT_BASE_SIGNED_MESSAGE,
|
|
363
422
|
HttpAdapter,
|
|
364
423
|
SnsAuthClient,
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AVACUS_ENDPOINTS,
|
|
3
|
+
BASE_CONNECT_SIGNED_MSG,
|
|
4
|
+
BASE_GAS_SPONSOR_SIGNED_MSG,
|
|
5
|
+
BASE_REDIRECT_SIGNED_MSG,
|
|
3
6
|
DEFAULT_BASE_SIGNED_MESSAGE,
|
|
4
7
|
HttpAdapter,
|
|
5
8
|
SnsAuthClient,
|
|
6
9
|
SnsService,
|
|
7
10
|
loginWithSns
|
|
8
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-XWC6XZPN.mjs";
|
|
9
12
|
export {
|
|
10
13
|
AVACUS_ENDPOINTS,
|
|
14
|
+
BASE_CONNECT_SIGNED_MSG,
|
|
15
|
+
BASE_GAS_SPONSOR_SIGNED_MSG,
|
|
16
|
+
BASE_REDIRECT_SIGNED_MSG,
|
|
11
17
|
DEFAULT_BASE_SIGNED_MESSAGE,
|
|
12
18
|
HttpAdapter,
|
|
13
19
|
SnsAuthClient,
|