@autogames/sdk 1.1.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.
Files changed (72) hide show
  1. package/README.md +732 -0
  2. package/dist/PhArrowCircleDown-Db_5u1DC.js +73 -0
  3. package/dist/PhArrowClockwise-D5uNEUen.js +73 -0
  4. package/dist/PhArrowDown-CKkl0Ow8.js +73 -0
  5. package/dist/PhArrowLeft-5Y_-c8ih.js +73 -0
  6. package/dist/PhArrowRight-BAENQRa7.js +73 -0
  7. package/dist/PhArrowSquareOut-DlfAcw2e.js +73 -0
  8. package/dist/PhArrowUp-8KZkS1Bo.js +73 -0
  9. package/dist/PhArrowUpRight-DU3GSwzb.js +73 -0
  10. package/dist/PhArrowsClockwise-CShJ-Teu.js +73 -0
  11. package/dist/PhArrowsDownUp-BL_LzwqW.js +73 -0
  12. package/dist/PhArrowsLeftRight-B8vh7AsL.js +73 -0
  13. package/dist/PhBank-CP_QveNf.js +73 -0
  14. package/dist/PhBrowser-CCSpUQte.js +73 -0
  15. package/dist/PhCaretDown-C4u7yn0j.js +73 -0
  16. package/dist/PhCaretLeft-BSbx9BBc.js +73 -0
  17. package/dist/PhCaretRight-B1CumbxI.js +73 -0
  18. package/dist/PhCaretUp-CqiATiNS.js +73 -0
  19. package/dist/PhCheck-DNkwyplN.js +73 -0
  20. package/dist/PhCircleHalf-D4fgYYPo.js +73 -0
  21. package/dist/PhClock-DkIJeKoF.js +73 -0
  22. package/dist/PhCompass-CwVX0Z1y.js +73 -0
  23. package/dist/PhCopy-C0BiDhpw.js +73 -0
  24. package/dist/PhCreditCard-Bv5P9lrI.js +73 -0
  25. package/dist/PhCurrencyDollar-BCl4tAtz.js +73 -0
  26. package/dist/PhDesktop-DREPgw1q.js +73 -0
  27. package/dist/PhDeviceMobile-CM6lQlUa.js +73 -0
  28. package/dist/PhDotsThree-dmgI5Eht.js +73 -0
  29. package/dist/PhEnvelope-D7EatbfP.js +73 -0
  30. package/dist/PhFunnelSimple-Bs-Zsz_A.js +73 -0
  31. package/dist/PhGlobe-Azwq0DDw.js +73 -0
  32. package/dist/PhIdentificationCard-BZpHUHrg.js +73 -0
  33. package/dist/PhImage-CuSFzxM3.js +73 -0
  34. package/dist/PhInfo-B4SBturW.js +73 -0
  35. package/dist/PhLightbulb-79sWB45x.js +73 -0
  36. package/dist/PhMagnifyingGlass-CojwRGSu.js +73 -0
  37. package/dist/PhPaperPlaneRight-C3krm3eP.js +73 -0
  38. package/dist/PhPlus-DDYz48cV.js +73 -0
  39. package/dist/PhPower-CZWV02MF.js +73 -0
  40. package/dist/PhPuzzlePiece-fazdHBSU.js +73 -0
  41. package/dist/PhQrCode-BbBdb_ct.js +73 -0
  42. package/dist/PhQuestion-B6cc25Dw.js +73 -0
  43. package/dist/PhQuestionMark-TmZ4Sxa8.js +73 -0
  44. package/dist/PhSealCheck-CdKeNk5K.js +73 -0
  45. package/dist/PhSignOut-BBNQiKWI.js +73 -0
  46. package/dist/PhSpinner-BwqRA0He.js +73 -0
  47. package/dist/PhTrash-CXtQYiKu.js +73 -0
  48. package/dist/PhUser-DVV5XCqw.js +73 -0
  49. package/dist/PhVault-B73IPDB0.js +73 -0
  50. package/dist/PhWarning-BEhs8fc4.js +73 -0
  51. package/dist/PhWarningCircle-BA0Qvc1c.js +73 -0
  52. package/dist/PhX-CifUIiFs.js +73 -0
  53. package/dist/autogames-sdk.esm.js +5 -0
  54. package/dist/autogames-sdk.js +5247 -0
  55. package/dist/basic-R2aK52rX.js +4875 -0
  56. package/dist/bridge-mount-Bhf05oeO.js +89817 -0
  57. package/dist/ccip-Bg_nydEz.js +145 -0
  58. package/dist/ccip-CjgrAp_t.js +147 -0
  59. package/dist/core-CnCeDQAm.js +17712 -0
  60. package/dist/features-BrlR4_0m.js +268 -0
  61. package/dist/index-C9RsDt_J.js +8044 -0
  62. package/dist/index-Chq42DrS.js +2010 -0
  63. package/dist/index-HQNbtrlg.js +341 -0
  64. package/dist/index-zA8BVXWW.js +264 -0
  65. package/dist/main-oRLGGL0R.js +2284 -0
  66. package/dist/main.d.ts +342 -0
  67. package/dist/parseSignature-DFDCc7FD.js +131 -0
  68. package/dist/property-DkPmFHg2.js +587 -0
  69. package/dist/secp256k1-UpZfvHa8.js +1347 -0
  70. package/dist/stats-confirm.html +4949 -0
  71. package/dist/w3m-modal-ClvdQLsb.js +2822 -0
  72. package/package.json +48 -0
@@ -0,0 +1,268 @@
1
+ import { C as l, N as k, S as g, g as w, a as f, b as u, B as A, A as N } from "./core-CnCeDQAm.js";
2
+ class m {
3
+ constructor(e) {
4
+ this.getNonce = e.getNonce;
5
+ }
6
+ async createMessage(e) {
7
+ const t = {
8
+ accountAddress: e.accountAddress,
9
+ chainId: e.chainId,
10
+ version: "1",
11
+ domain: typeof document > "u" ? "Unknown Domain" : document.location.host,
12
+ uri: typeof document > "u" ? "Unknown URI" : document.location.href,
13
+ resources: this.resources,
14
+ nonce: await this.getNonce(e),
15
+ issuedAt: this.stringifyDate(/* @__PURE__ */ new Date()),
16
+ statement: void 0,
17
+ expirationTime: void 0,
18
+ notBefore: void 0
19
+ };
20
+ return Object.assign(t, {
21
+ toString: () => this.stringify(t)
22
+ });
23
+ }
24
+ stringify(e) {
25
+ const t = this.getNetworkName(e.chainId);
26
+ return [
27
+ `${e.domain} wants you to sign in with your ${t} account:`,
28
+ e.accountAddress,
29
+ e.statement ? `
30
+ ${e.statement}
31
+ ` : "",
32
+ `URI: ${e.uri}`,
33
+ `Version: ${e.version}`,
34
+ `Chain ID: ${e.chainId}`,
35
+ `Nonce: ${e.nonce}`,
36
+ e.issuedAt && `Issued At: ${e.issuedAt}`,
37
+ e.expirationTime && `Expiration Time: ${e.expirationTime}`,
38
+ e.notBefore && `Not Before: ${e.notBefore}`,
39
+ e.requestId && `Request ID: ${e.requestId}`,
40
+ e.resources?.length && e.resources.reduce((n, s) => `${n}
41
+ - ${s}`, "Resources:")
42
+ ].filter((n) => typeof n == "string").join(`
43
+ `).trim();
44
+ }
45
+ getNetworkName(e) {
46
+ const t = l.getAllRequestedCaipNetworks();
47
+ return k.getNetworkNameByCaipNetworkId(t, e);
48
+ }
49
+ stringifyDate(e) {
50
+ return e.toISOString();
51
+ }
52
+ }
53
+ class T {
54
+ constructor(e = {}) {
55
+ this.otpUuid = null, this.listeners = {
56
+ sessionChanged: []
57
+ }, this.localAuthStorageKey = e.localAuthStorageKey || g.SIWX_AUTH_TOKEN, this.localNonceStorageKey = e.localNonceStorageKey || g.SIWX_NONCE_TOKEN, this.required = e.required ?? !0, this.messenger = new m({
58
+ getNonce: this.getNonce.bind(this)
59
+ });
60
+ }
61
+ async createMessage(e) {
62
+ return this.messenger.createMessage(e);
63
+ }
64
+ async addSession(e) {
65
+ const t = await this.request({
66
+ method: "POST",
67
+ key: "authenticate",
68
+ body: {
69
+ data: e.data,
70
+ message: e.message,
71
+ signature: e.signature,
72
+ clientId: this.getClientId(),
73
+ walletInfo: this.getWalletInfo()
74
+ },
75
+ headers: ["nonce", "otp"]
76
+ });
77
+ this.setStorageToken(t.token, this.localAuthStorageKey), this.emit("sessionChanged", e), this.setAppKitAccountUser(p(t.token)), this.otpUuid = null;
78
+ }
79
+ async getSessions(e, t) {
80
+ try {
81
+ if (!this.getStorageToken(this.localAuthStorageKey))
82
+ return [];
83
+ const n = await this.request({
84
+ method: "GET",
85
+ key: "me",
86
+ query: {},
87
+ headers: ["auth"]
88
+ });
89
+ if (!n)
90
+ return [];
91
+ const s = n.address.toLowerCase() === t.toLowerCase(), o = n.caip2Network === e;
92
+ if (!s || !o)
93
+ return [];
94
+ const r = {
95
+ data: {
96
+ accountAddress: n.address,
97
+ chainId: n.caip2Network
98
+ },
99
+ message: "",
100
+ signature: ""
101
+ };
102
+ return this.emit("sessionChanged", r), this.setAppKitAccountUser(n), [r];
103
+ } catch {
104
+ return [];
105
+ }
106
+ }
107
+ async revokeSession(e, t) {
108
+ return Promise.resolve(this.clearStorageTokens());
109
+ }
110
+ async setSessions(e) {
111
+ if (e.length === 0)
112
+ this.clearStorageTokens();
113
+ else {
114
+ const t = e.find((n) => n.data.chainId === w()?.caipNetworkId) || e[0];
115
+ await this.addSession(t);
116
+ }
117
+ }
118
+ getRequired() {
119
+ return this.required;
120
+ }
121
+ async getSessionAccount() {
122
+ if (!this.getStorageToken(this.localAuthStorageKey))
123
+ throw new Error("Not authenticated");
124
+ return this.request({
125
+ method: "GET",
126
+ key: "me",
127
+ body: void 0,
128
+ query: {
129
+ includeAppKitAccount: !0
130
+ },
131
+ headers: ["auth"]
132
+ });
133
+ }
134
+ async setSessionAccountMetadata(e = null) {
135
+ if (!this.getStorageToken(this.localAuthStorageKey))
136
+ throw new Error("Not authenticated");
137
+ return this.request({
138
+ method: "PUT",
139
+ key: "account-metadata",
140
+ body: { metadata: e },
141
+ headers: ["auth"]
142
+ });
143
+ }
144
+ on(e, t) {
145
+ return this.listeners[e].push(t), () => {
146
+ this.listeners[e] = this.listeners[e].filter((n) => n !== t);
147
+ };
148
+ }
149
+ removeAllListeners() {
150
+ Object.keys(this.listeners).forEach((t) => {
151
+ this.listeners[t] = [];
152
+ });
153
+ }
154
+ async requestEmailOtp({ email: e, account: t }) {
155
+ const n = await this.request({
156
+ method: "POST",
157
+ key: "otp",
158
+ body: { email: e, account: t }
159
+ });
160
+ return this.otpUuid = n.uuid, this.messenger.resources = [`email:${e}`], n;
161
+ }
162
+ confirmEmailOtp({ code: e }) {
163
+ return this.request({
164
+ method: "PUT",
165
+ key: "otp",
166
+ body: { code: e },
167
+ headers: ["otp"]
168
+ });
169
+ }
170
+ async request({ method: e, key: t, query: n, body: s, headers: o }) {
171
+ const { projectId: r, st: y, sv: S } = this.getSDKProperties(), a = new URL(`${f.W3M_API_URL}/auth/v1/${String(t)}`);
172
+ a.searchParams.set("projectId", r), a.searchParams.set("st", y), a.searchParams.set("sv", S), n && Object.entries(n).forEach(([i, h]) => a.searchParams.set(i, String(h)));
173
+ const c = await fetch(a, {
174
+ method: e,
175
+ body: s ? JSON.stringify(s) : void 0,
176
+ headers: Array.isArray(o) ? o.reduce((i, h) => {
177
+ switch (h) {
178
+ case "nonce":
179
+ i["x-nonce-jwt"] = `Bearer ${this.getStorageToken(this.localNonceStorageKey)}`;
180
+ break;
181
+ case "auth":
182
+ i.Authorization = `Bearer ${this.getStorageToken(this.localAuthStorageKey)}`;
183
+ break;
184
+ case "otp":
185
+ this.otpUuid && (i["x-otp"] = this.otpUuid);
186
+ break;
187
+ }
188
+ return i;
189
+ }, {}) : void 0
190
+ });
191
+ if (!c.ok)
192
+ throw new Error(await c.text());
193
+ return c.headers.get("content-type")?.includes("application/json") ? c.json() : null;
194
+ }
195
+ getStorageToken(e) {
196
+ return u.getItem(e);
197
+ }
198
+ setStorageToken(e, t) {
199
+ u.setItem(t, e);
200
+ }
201
+ clearStorageTokens() {
202
+ this.otpUuid = null, u.removeItem(this.localAuthStorageKey), u.removeItem(this.localNonceStorageKey), this.emit("sessionChanged", void 0);
203
+ }
204
+ async getNonce() {
205
+ const { nonce: e, token: t } = await this.request({
206
+ method: "GET",
207
+ key: "nonce"
208
+ });
209
+ return this.setStorageToken(t, this.localNonceStorageKey), e;
210
+ }
211
+ getClientId() {
212
+ return A.state.clientId;
213
+ }
214
+ getWalletInfo() {
215
+ const e = l.getAccountData()?.connectedWalletInfo;
216
+ if (!e)
217
+ return;
218
+ if ("social" in e && "identifier" in e) {
219
+ const o = e.social, r = e.identifier;
220
+ return { type: "social", social: o, identifier: r };
221
+ }
222
+ const { name: t, icon: n } = e;
223
+ let s = "unknown";
224
+ switch (e.type) {
225
+ case "EXTERNAL":
226
+ case "INJECTED":
227
+ case "ANNOUNCED":
228
+ s = "extension";
229
+ break;
230
+ case "WALLET_CONNECT":
231
+ s = "walletconnect";
232
+ break;
233
+ default:
234
+ s = "unknown";
235
+ }
236
+ return {
237
+ type: s,
238
+ name: t,
239
+ icon: n
240
+ };
241
+ }
242
+ getSDKProperties() {
243
+ return N._getSdkProperties();
244
+ }
245
+ emit(e, t) {
246
+ this.listeners[e].forEach((n) => n(t));
247
+ }
248
+ setAppKitAccountUser(e) {
249
+ const { email: t } = e;
250
+ t && Object.values(f.CHAIN).forEach((n) => {
251
+ l.setAccountProp("user", { email: t }, n);
252
+ });
253
+ }
254
+ }
255
+ function p(d) {
256
+ const e = d.split(".");
257
+ if (e.length !== 3)
258
+ throw new Error("Invalid token");
259
+ const t = e[1];
260
+ if (typeof t != "string")
261
+ throw new Error("Invalid token");
262
+ const n = t.replace(/-/gu, "+").replace(/_/gu, "/"), s = n.padEnd(n.length + (4 - n.length % 4) % 4, "=");
263
+ return JSON.parse(atob(s));
264
+ }
265
+ export {
266
+ T as ReownAuthentication,
267
+ m as ReownAuthenticationMessenger
268
+ };