zopassport 0.1.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/LICENSE +22 -0
- package/README.md +407 -0
- package/app/.env.example +15 -0
- package/app/README.md +28 -0
- package/app/package.json +24 -0
- package/app/reanimated-mock.js +102 -0
- package/app/reanimated-mock.jsx +97 -0
- package/app/src/App.tsx +331 -0
- package/app/src/components/FounderBadge.tsx +26 -0
- package/app/src/components/OTPInput.tsx +149 -0
- package/app/src/components/PhoneInput.tsx +109 -0
- package/app/src/components/ZoAuth.tsx +320 -0
- package/app/src/components/ZoAvatar.tsx +87 -0
- package/app/src/components/ZoLanding.tsx +231 -0
- package/app/src/components/ZoOnboarding.tsx +524 -0
- package/app/src/components/ZoPassportCard.tsx +183 -0
- package/app/src/components/ZoProgressRing.tsx +57 -0
- package/app/src/components/index.ts +16 -0
- package/app/src/components/wallet/MovingShine.tsx +43 -0
- package/app/src/components/wallet/TransactionItem.tsx +84 -0
- package/app/src/components/wallet/TransactionList.tsx +65 -0
- package/app/src/components/wallet/WalletCard.tsx +152 -0
- package/app/src/components/wallet/WalletScreen.tsx +190 -0
- package/app/src/components/wallet/ZoToken.tsx +69 -0
- package/app/src/components/wallet/index.ts +8 -0
- package/app/src/components/wallet/styles/index.ts +4 -0
- package/app/src/components/wallet/styles/walletStyles.ts +210 -0
- package/app/src/sdk/ZoPassportSDK.ts +277 -0
- package/app/src/sdk/lib/api/auth.ts +223 -0
- package/app/src/sdk/lib/api/avatar.ts +155 -0
- package/app/src/sdk/lib/api/client.ts +135 -0
- package/app/src/sdk/lib/api/index.ts +8 -0
- package/app/src/sdk/lib/api/profile.ts +80 -0
- package/app/src/sdk/lib/api/wallet.ts +59 -0
- package/app/src/sdk/lib/types/auth.ts +78 -0
- package/app/src/sdk/lib/types/avatar.ts +22 -0
- package/app/src/sdk/lib/types/index.ts +8 -0
- package/app/src/sdk/lib/types/profile.ts +18 -0
- package/app/src/sdk/lib/types/wallet.ts +103 -0
- package/app/src/sdk/lib/types.ts +205 -0
- package/app/src/sdk/lib/utils/index.ts +6 -0
- package/app/src/sdk/lib/utils/phone.ts +71 -0
- package/app/src/sdk/lib/utils/storage.ts +116 -0
- package/app/src/sdk/lib/utils/wallet.ts +73 -0
- package/app/src/sdk/types.ts +205 -0
- package/app/src/styles.css +154 -0
- package/app/svg-mock.js +125 -0
- package/app/svg-mock.jsx +120 -0
- package/app/vite.config.ts +70 -0
- package/assets/ASSETS_MANIFEST.md +124 -0
- package/assets/bae.png +0 -0
- package/assets/bro.png +0 -0
- package/assets/cultural-stickers/Business.png +0 -0
- package/assets/cultural-stickers/Default (2).jpg +0 -0
- package/assets/cultural-stickers/Design.png +0 -0
- package/assets/cultural-stickers/FollowYourHeart.png +0 -0
- package/assets/cultural-stickers/Food.png +0 -0
- package/assets/cultural-stickers/Game.png +0 -0
- package/assets/cultural-stickers/Health&Fitness.png +0 -0
- package/assets/cultural-stickers/Home&Lifestyle.png +0 -0
- package/assets/cultural-stickers/Law.png +0 -0
- package/assets/cultural-stickers/Literature&Stories.png +0 -0
- package/assets/cultural-stickers/Music&Entertainment.png +0 -0
- package/assets/cultural-stickers/Nature&Wildlife.png +0 -0
- package/assets/cultural-stickers/Photography.png +0 -0
- package/assets/cultural-stickers/Science&Technology.png +0 -0
- package/assets/cultural-stickers/Spiritual.png +0 -0
- package/assets/cultural-stickers/Sport.png +0 -0
- package/assets/cultural-stickers/Stories&Journal.png +0 -0
- package/assets/cultural-stickers/Television&Cinema.png +0 -0
- package/assets/cultural-stickers/Travel&Adventure.png +0 -0
- package/assets/cultural-stickers/z.jpg (1).jpg +0 -0
- package/assets/figma-assets/landing-zo-logo.png +0 -0
- package/assets/images/rank1.jpeg +0 -0
- package/assets/index.ts +76 -0
- package/assets/lotties/loader.json +1216 -0
- package/assets/lotties/spinner.json +1 -0
- package/assets/videos/loading-screen-background.mp4 +0 -0
- package/assets/videos/opening-disks.mp4 +0 -0
- package/assets/wallet/constants.ts +38 -0
- package/assets/zo-coin.gif +0 -0
- package/assets/zo-fallback.png +0 -0
- package/dist/assets/index.d.mts +136 -0
- package/dist/assets/index.d.ts +136 -0
- package/dist/assets/index.js +133 -0
- package/dist/assets/index.js.map +1 -0
- package/dist/assets/index.mjs +100 -0
- package/dist/assets/index.mjs.map +1 -0
- package/dist/index.d.mts +789 -0
- package/dist/index.d.ts +789 -0
- package/dist/index.js +1118 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1060 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react-native.d.mts +537 -0
- package/dist/react-native.d.ts +537 -0
- package/dist/react-native.js +1617 -0
- package/dist/react-native.js.map +1 -0
- package/dist/react-native.mjs +1588 -0
- package/dist/react-native.mjs.map +1 -0
- package/dist/react.d.mts +824 -0
- package/dist/react.d.ts +824 -0
- package/dist/react.js +3856 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +3801 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +112 -0
- package/scripts/init.js +196 -0
- package/scripts/postinstall.js +174 -0
- package/scripts/verify-build.js +121 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
ASSETS: () => ASSETS,
|
|
34
|
+
AsyncStorageAdapter: () => AsyncStorageAdapter,
|
|
35
|
+
COUNTRY_CODES: () => COUNTRY_CODES,
|
|
36
|
+
CULTURES: () => CULTURES,
|
|
37
|
+
CULTURE_STICKERS: () => CULTURE_STICKERS,
|
|
38
|
+
LocalStorageAdapter: () => LocalStorageAdapter,
|
|
39
|
+
STORAGE_KEYS: () => STORAGE_KEYS,
|
|
40
|
+
ZoApiClient: () => ZoApiClient,
|
|
41
|
+
ZoAuth: () => ZoAuth,
|
|
42
|
+
ZoAvatar: () => ZoAvatar,
|
|
43
|
+
ZoPassportSDK: () => ZoPassportSDK,
|
|
44
|
+
ZoProfile: () => ZoProfile,
|
|
45
|
+
ZoWallet: () => ZoWallet,
|
|
46
|
+
formatBalance: () => formatBalance,
|
|
47
|
+
formatBalanceShort: () => formatBalanceShort,
|
|
48
|
+
formatNickname: () => formatNickname,
|
|
49
|
+
formatPhoneNumber: () => formatPhoneNumber,
|
|
50
|
+
formatTransactionAmount: () => formatTransactionAmount,
|
|
51
|
+
formatWalletAddress: () => formatWalletAddress,
|
|
52
|
+
getTransactionColor: () => getTransactionColor,
|
|
53
|
+
logger: () => logger,
|
|
54
|
+
parsePhoneNumber: () => parsePhoneNumber
|
|
55
|
+
});
|
|
56
|
+
module.exports = __toCommonJS(index_exports);
|
|
57
|
+
|
|
58
|
+
// src/lib/api/client.ts
|
|
59
|
+
var import_axios = __toESM(require("axios"));
|
|
60
|
+
|
|
61
|
+
// src/lib/utils/logger.ts
|
|
62
|
+
var LOG_LEVELS = {
|
|
63
|
+
debug: 0,
|
|
64
|
+
info: 1,
|
|
65
|
+
warn: 2,
|
|
66
|
+
error: 3,
|
|
67
|
+
none: 4
|
|
68
|
+
};
|
|
69
|
+
var Logger = class {
|
|
70
|
+
constructor() {
|
|
71
|
+
this.config = {
|
|
72
|
+
enabled: false,
|
|
73
|
+
level: "warn",
|
|
74
|
+
prefix: "[ZoPassport]"
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Configure the logger
|
|
79
|
+
* @param options - Logger configuration
|
|
80
|
+
*/
|
|
81
|
+
configure(options) {
|
|
82
|
+
this.config = { ...this.config, ...options };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Enable debug logging
|
|
86
|
+
*/
|
|
87
|
+
enable() {
|
|
88
|
+
this.config.enabled = true;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Disable all logging
|
|
92
|
+
*/
|
|
93
|
+
disable() {
|
|
94
|
+
this.config.enabled = false;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Set log level
|
|
98
|
+
*/
|
|
99
|
+
setLevel(level) {
|
|
100
|
+
this.config.level = level;
|
|
101
|
+
}
|
|
102
|
+
shouldLog(level) {
|
|
103
|
+
if (!this.config.enabled) return false;
|
|
104
|
+
return LOG_LEVELS[level] >= LOG_LEVELS[this.config.level];
|
|
105
|
+
}
|
|
106
|
+
debug(...args) {
|
|
107
|
+
if (this.shouldLog("debug")) {
|
|
108
|
+
console.log(this.config.prefix, ...args);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
info(...args) {
|
|
112
|
+
if (this.shouldLog("info")) {
|
|
113
|
+
console.info(this.config.prefix, ...args);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
warn(...args) {
|
|
117
|
+
if (this.shouldLog("warn")) {
|
|
118
|
+
console.warn(this.config.prefix, ...args);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
error(...args) {
|
|
122
|
+
if (this.shouldLog("error")) {
|
|
123
|
+
console.error(this.config.prefix, ...args);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var logger = new Logger();
|
|
128
|
+
|
|
129
|
+
// src/lib/utils/storage.ts
|
|
130
|
+
var STORAGE_KEYS = {
|
|
131
|
+
ACCESS_TOKEN: "zo_access_token",
|
|
132
|
+
REFRESH_TOKEN: "zo_refresh_token",
|
|
133
|
+
TOKEN_EXPIRY: "zo_token_expiry",
|
|
134
|
+
REFRESH_EXPIRY: "zo_refresh_expiry",
|
|
135
|
+
USER: "zo_user",
|
|
136
|
+
CLIENT_DEVICE_ID: "zo_device_id",
|
|
137
|
+
CLIENT_DEVICE_SECRET: "zo_device_secret",
|
|
138
|
+
AVATAR_URL: "zo_avatar_url",
|
|
139
|
+
NICKNAME: "zo_nickname",
|
|
140
|
+
CITY: "zo_city",
|
|
141
|
+
BODY_TYPE: "zo_body_type"
|
|
142
|
+
};
|
|
143
|
+
var LocalStorageAdapter = class {
|
|
144
|
+
async getItem(key) {
|
|
145
|
+
if (typeof window === "undefined") return null;
|
|
146
|
+
try {
|
|
147
|
+
return localStorage.getItem(key);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
logger.warn(`LocalStorage.getItem failed for key "${key}":`, error);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async setItem(key, value) {
|
|
154
|
+
if (typeof window === "undefined") return;
|
|
155
|
+
try {
|
|
156
|
+
localStorage.setItem(key, value);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
logger.warn(`LocalStorage.setItem failed for key "${key}":`, error);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async removeItem(key) {
|
|
162
|
+
if (typeof window === "undefined") return;
|
|
163
|
+
try {
|
|
164
|
+
localStorage.removeItem(key);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
logger.warn(`LocalStorage.removeItem failed for key "${key}":`, error);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var AsyncStorageAdapter = class {
|
|
171
|
+
constructor(asyncStorage) {
|
|
172
|
+
this.storage = asyncStorage;
|
|
173
|
+
}
|
|
174
|
+
async getItem(key) {
|
|
175
|
+
try {
|
|
176
|
+
return await this.storage.getItem(key);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
logger.warn(`AsyncStorage.getItem failed for key "${key}":`, error);
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async setItem(key, value) {
|
|
183
|
+
try {
|
|
184
|
+
await this.storage.setItem(key, value);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
logger.warn(`AsyncStorage.setItem failed for key "${key}":`, error);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async removeItem(key) {
|
|
190
|
+
try {
|
|
191
|
+
await this.storage.removeItem(key);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
logger.warn(`AsyncStorage.removeItem failed for key "${key}":`, error);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// src/lib/api/client.ts
|
|
199
|
+
function generateDeviceCredentials() {
|
|
200
|
+
const deviceId = `web-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
201
|
+
const deviceSecret = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
202
|
+
return { deviceId, deviceSecret };
|
|
203
|
+
}
|
|
204
|
+
var ZoApiClient = class {
|
|
205
|
+
constructor(config) {
|
|
206
|
+
this.config = config;
|
|
207
|
+
this.storage = config.storageAdapter || new LocalStorageAdapter();
|
|
208
|
+
this.client = import_axios.default.create({
|
|
209
|
+
baseURL: config.baseUrl || "https://api.io.zo.xyz",
|
|
210
|
+
timeout: config.timeout || 1e4,
|
|
211
|
+
headers: {
|
|
212
|
+
"Content-Type": "application/json",
|
|
213
|
+
"Accept": "application/json"
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
this.setupInterceptors();
|
|
217
|
+
}
|
|
218
|
+
async setupInterceptors() {
|
|
219
|
+
this.client.interceptors.request.use(async (config) => {
|
|
220
|
+
config.headers["client-key"] = this.config.clientKey;
|
|
221
|
+
const credentials = await this.getOrCreateDeviceCredentials();
|
|
222
|
+
config.headers["client-device-id"] = credentials.deviceId;
|
|
223
|
+
config.headers["client-device-secret"] = credentials.deviceSecret;
|
|
224
|
+
const token = await this.storage.getItem(STORAGE_KEYS.ACCESS_TOKEN);
|
|
225
|
+
if (token) {
|
|
226
|
+
config.headers["Authorization"] = `Bearer ${token}`;
|
|
227
|
+
}
|
|
228
|
+
return config;
|
|
229
|
+
});
|
|
230
|
+
this.client.interceptors.response.use(
|
|
231
|
+
(response) => response,
|
|
232
|
+
async (error) => {
|
|
233
|
+
const originalRequest = error.config;
|
|
234
|
+
if (error.response?.status === 401 && !originalRequest._retry) {
|
|
235
|
+
originalRequest._retry = true;
|
|
236
|
+
const refreshToken = await this.storage.getItem(STORAGE_KEYS.REFRESH_TOKEN);
|
|
237
|
+
if (refreshToken) {
|
|
238
|
+
try {
|
|
239
|
+
const response = await this.client.post("/api/v1/auth/token/refresh/", {
|
|
240
|
+
refresh_token: refreshToken
|
|
241
|
+
});
|
|
242
|
+
if (response.data?.access) {
|
|
243
|
+
await this.storage.setItem(STORAGE_KEYS.ACCESS_TOKEN, response.data.access);
|
|
244
|
+
if (response.data.refresh) {
|
|
245
|
+
await this.storage.setItem(STORAGE_KEYS.REFRESH_TOKEN, response.data.refresh);
|
|
246
|
+
}
|
|
247
|
+
originalRequest.headers["Authorization"] = `Bearer ${response.data.access}`;
|
|
248
|
+
return this.client(originalRequest);
|
|
249
|
+
}
|
|
250
|
+
} catch (refreshError) {
|
|
251
|
+
await this.storage.removeItem(STORAGE_KEYS.ACCESS_TOKEN);
|
|
252
|
+
await this.storage.removeItem(STORAGE_KEYS.REFRESH_TOKEN);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return Promise.reject(error);
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
async getOrCreateDeviceCredentials() {
|
|
261
|
+
const storedId = await this.storage.getItem(STORAGE_KEYS.CLIENT_DEVICE_ID);
|
|
262
|
+
const storedSecret = await this.storage.getItem(STORAGE_KEYS.CLIENT_DEVICE_SECRET);
|
|
263
|
+
if (storedId && storedSecret) {
|
|
264
|
+
return { deviceId: storedId, deviceSecret: storedSecret };
|
|
265
|
+
}
|
|
266
|
+
const credentials = generateDeviceCredentials();
|
|
267
|
+
await this.storage.setItem(STORAGE_KEYS.CLIENT_DEVICE_ID, credentials.deviceId);
|
|
268
|
+
await this.storage.setItem(STORAGE_KEYS.CLIENT_DEVICE_SECRET, credentials.deviceSecret);
|
|
269
|
+
return credentials;
|
|
270
|
+
}
|
|
271
|
+
get axiosInstance() {
|
|
272
|
+
return this.client;
|
|
273
|
+
}
|
|
274
|
+
getStorage() {
|
|
275
|
+
return this.storage;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// src/lib/api/auth.ts
|
|
280
|
+
var ZoAuth = class {
|
|
281
|
+
constructor(client) {
|
|
282
|
+
this.client = client;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Send OTP to phone number
|
|
286
|
+
* Step 1 of ZO phone authentication
|
|
287
|
+
*/
|
|
288
|
+
async sendOTP(countryCode, phoneNumber) {
|
|
289
|
+
try {
|
|
290
|
+
const payload = {
|
|
291
|
+
mobile_country_code: countryCode,
|
|
292
|
+
mobile_number: phoneNumber,
|
|
293
|
+
message_channel: ""
|
|
294
|
+
// Empty string as per ZO API spec
|
|
295
|
+
};
|
|
296
|
+
const response = await this.client.axiosInstance.post(
|
|
297
|
+
"/api/v1/auth/login/mobile/otp/",
|
|
298
|
+
payload
|
|
299
|
+
);
|
|
300
|
+
if (response.status >= 200 && response.status < 300) {
|
|
301
|
+
return {
|
|
302
|
+
success: true,
|
|
303
|
+
message: response.data?.message || "OTP sent successfully"
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
success: false,
|
|
308
|
+
message: response.data?.message || `Unexpected status: ${response.status}`
|
|
309
|
+
};
|
|
310
|
+
} catch (error) {
|
|
311
|
+
const errorData = error.response?.data;
|
|
312
|
+
const errorMessage = errorData?.detail || errorData?.message || errorData?.error || error.message || "Failed to send OTP";
|
|
313
|
+
return {
|
|
314
|
+
success: false,
|
|
315
|
+
message: errorMessage
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Verify OTP and authenticate user
|
|
321
|
+
* Step 2 of ZO phone authentication
|
|
322
|
+
* Returns full auth response with tokens and user profile
|
|
323
|
+
*/
|
|
324
|
+
async verifyOTP(countryCode, phoneNumber, otp) {
|
|
325
|
+
try {
|
|
326
|
+
const payload = {
|
|
327
|
+
mobile_country_code: countryCode,
|
|
328
|
+
mobile_number: phoneNumber,
|
|
329
|
+
otp
|
|
330
|
+
};
|
|
331
|
+
const response = await this.client.axiosInstance.post(
|
|
332
|
+
"/api/v1/auth/login/mobile/",
|
|
333
|
+
payload
|
|
334
|
+
);
|
|
335
|
+
let responseData;
|
|
336
|
+
if (typeof response.data === "string") {
|
|
337
|
+
try {
|
|
338
|
+
responseData = JSON.parse(response.data);
|
|
339
|
+
} catch {
|
|
340
|
+
return {
|
|
341
|
+
success: false,
|
|
342
|
+
error: "Invalid response format from authentication service"
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
responseData = response.data;
|
|
347
|
+
}
|
|
348
|
+
if (!responseData || !responseData.user || !responseData.access_token) {
|
|
349
|
+
return {
|
|
350
|
+
success: false,
|
|
351
|
+
error: "Invalid response structure from authentication service"
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
success: true,
|
|
356
|
+
data: responseData
|
|
357
|
+
};
|
|
358
|
+
} catch (error) {
|
|
359
|
+
const errorMessage = this.extractErrorMessage(error);
|
|
360
|
+
return {
|
|
361
|
+
success: false,
|
|
362
|
+
error: errorMessage
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Refresh access token using refresh token
|
|
368
|
+
*/
|
|
369
|
+
async refreshAccessToken(refreshToken) {
|
|
370
|
+
try {
|
|
371
|
+
const response = await this.client.axiosInstance.post("/api/v1/auth/token/refresh/", {
|
|
372
|
+
refresh_token: refreshToken
|
|
373
|
+
});
|
|
374
|
+
return {
|
|
375
|
+
success: true,
|
|
376
|
+
tokens: response.data
|
|
377
|
+
};
|
|
378
|
+
} catch (error) {
|
|
379
|
+
return {
|
|
380
|
+
success: false,
|
|
381
|
+
error: "Failed to refresh authentication"
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Check if user is authenticated
|
|
387
|
+
*/
|
|
388
|
+
async checkLoginStatus(accessToken) {
|
|
389
|
+
try {
|
|
390
|
+
const response = await this.client.axiosInstance.get("/api/v1/auth/login/check/", {
|
|
391
|
+
headers: {
|
|
392
|
+
Authorization: `Bearer ${accessToken}`
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
return {
|
|
396
|
+
success: true,
|
|
397
|
+
isAuthenticated: response.data.authenticated === true
|
|
398
|
+
};
|
|
399
|
+
} catch {
|
|
400
|
+
return {
|
|
401
|
+
success: false,
|
|
402
|
+
isAuthenticated: false
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Extract error message from various ZO API error formats
|
|
408
|
+
*/
|
|
409
|
+
extractErrorMessage(error) {
|
|
410
|
+
const errorData = error.response?.data;
|
|
411
|
+
if (errorData) {
|
|
412
|
+
if (errorData.errors && Array.isArray(errorData.errors)) {
|
|
413
|
+
return errorData.errors[0] || "Invalid OTP";
|
|
414
|
+
}
|
|
415
|
+
if (errorData.detail) return errorData.detail;
|
|
416
|
+
if (errorData.message) return errorData.message;
|
|
417
|
+
if (errorData.error) return errorData.error;
|
|
418
|
+
}
|
|
419
|
+
return "Authentication failed";
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
// src/lib/api/profile.ts
|
|
424
|
+
var ZoProfile = class {
|
|
425
|
+
constructor(client) {
|
|
426
|
+
this.client = client;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Get user profile
|
|
430
|
+
*/
|
|
431
|
+
async getProfile(accessToken) {
|
|
432
|
+
try {
|
|
433
|
+
const response = await this.client.axiosInstance.get(
|
|
434
|
+
"/api/v1/profile/me/",
|
|
435
|
+
{
|
|
436
|
+
headers: {
|
|
437
|
+
Authorization: `Bearer ${accessToken}`
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
);
|
|
441
|
+
return {
|
|
442
|
+
success: true,
|
|
443
|
+
profile: response.data
|
|
444
|
+
};
|
|
445
|
+
} catch (error) {
|
|
446
|
+
const errorData = error.response?.data;
|
|
447
|
+
return {
|
|
448
|
+
success: false,
|
|
449
|
+
error: errorData?.detail || errorData?.message || "Failed to fetch profile"
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Update user profile (partial updates supported)
|
|
455
|
+
*/
|
|
456
|
+
async updateProfile(accessToken, updates) {
|
|
457
|
+
try {
|
|
458
|
+
const response = await this.client.axiosInstance.post(
|
|
459
|
+
"/api/v1/profile/me/",
|
|
460
|
+
updates,
|
|
461
|
+
{
|
|
462
|
+
headers: {
|
|
463
|
+
Authorization: `Bearer ${accessToken}`
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
);
|
|
467
|
+
return {
|
|
468
|
+
success: true,
|
|
469
|
+
profile: response.data
|
|
470
|
+
};
|
|
471
|
+
} catch (error) {
|
|
472
|
+
const errorData = error.response?.data;
|
|
473
|
+
return {
|
|
474
|
+
success: false,
|
|
475
|
+
error: errorData?.detail || errorData?.message || "Failed to update profile"
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
// src/lib/api/avatar.ts
|
|
482
|
+
var ZoAvatar = class {
|
|
483
|
+
constructor(client) {
|
|
484
|
+
this.client = client;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Generate avatar for user
|
|
488
|
+
*/
|
|
489
|
+
async generateAvatar(accessToken, bodyType) {
|
|
490
|
+
try {
|
|
491
|
+
const payload = {
|
|
492
|
+
body_type: bodyType
|
|
493
|
+
};
|
|
494
|
+
const response = await this.client.axiosInstance.post(
|
|
495
|
+
"/api/v1/avatar/generate/",
|
|
496
|
+
payload,
|
|
497
|
+
{
|
|
498
|
+
headers: {
|
|
499
|
+
Authorization: `Bearer ${accessToken}`
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
);
|
|
503
|
+
return {
|
|
504
|
+
success: true,
|
|
505
|
+
task_id: response.data.task_id,
|
|
506
|
+
status: response.data.status
|
|
507
|
+
};
|
|
508
|
+
} catch (error) {
|
|
509
|
+
const errorData = error.response?.data;
|
|
510
|
+
return {
|
|
511
|
+
success: false,
|
|
512
|
+
error: errorData?.detail || errorData?.message || "Failed to generate avatar"
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Check avatar generation status
|
|
518
|
+
*/
|
|
519
|
+
async getAvatarStatus(accessToken, taskId) {
|
|
520
|
+
try {
|
|
521
|
+
const response = await this.client.axiosInstance.get(
|
|
522
|
+
`/api/v1/avatar/status/${taskId}/`,
|
|
523
|
+
{
|
|
524
|
+
headers: {
|
|
525
|
+
Authorization: `Bearer ${accessToken}`
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
);
|
|
529
|
+
return {
|
|
530
|
+
success: true,
|
|
531
|
+
status: response.data.status,
|
|
532
|
+
avatarUrl: response.data.result?.avatar_url
|
|
533
|
+
};
|
|
534
|
+
} catch (error) {
|
|
535
|
+
const errorData = error.response?.data;
|
|
536
|
+
return {
|
|
537
|
+
success: false,
|
|
538
|
+
error: errorData?.detail || errorData?.message || "Failed to get avatar status"
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Poll avatar status until completion
|
|
544
|
+
*/
|
|
545
|
+
async pollAvatarStatus(accessToken, taskId, options = {}) {
|
|
546
|
+
const {
|
|
547
|
+
onProgress,
|
|
548
|
+
onComplete,
|
|
549
|
+
onError,
|
|
550
|
+
maxAttempts = 30,
|
|
551
|
+
interval = 2e3
|
|
552
|
+
} = options;
|
|
553
|
+
let attempts = 0;
|
|
554
|
+
const poll = async () => {
|
|
555
|
+
attempts++;
|
|
556
|
+
if (attempts > maxAttempts) {
|
|
557
|
+
const timeoutError = "Avatar generation timed out";
|
|
558
|
+
onError?.(timeoutError);
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const result = await this.getAvatarStatus(accessToken, taskId);
|
|
562
|
+
if (!result.success) {
|
|
563
|
+
onError?.(result.error || "Unknown error");
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
onProgress?.(result.status || "unknown");
|
|
567
|
+
if (result.status === "completed" && result.avatarUrl) {
|
|
568
|
+
onComplete?.(result.avatarUrl);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
if (result.status === "failed") {
|
|
572
|
+
onError?.("Avatar generation failed");
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
setTimeout(poll, interval);
|
|
576
|
+
};
|
|
577
|
+
poll();
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
// src/lib/api/wallet.ts
|
|
582
|
+
var ZO_TOKEN_CONFIG = {
|
|
583
|
+
base: {
|
|
584
|
+
rpc: "https://mainnet.base.org",
|
|
585
|
+
contractAddress: "0x111142c7ecaf39797b7865b82034269962142069",
|
|
586
|
+
// $Zo token on Base
|
|
587
|
+
decimals: 18
|
|
588
|
+
},
|
|
589
|
+
avalanche: {
|
|
590
|
+
rpc: "https://api.avax.network/ext/bc/C/rpc",
|
|
591
|
+
contractAddress: "0x111142c7ecaf39797b7865b82034269962142069",
|
|
592
|
+
// $Zo token on Avalanche (update if different)
|
|
593
|
+
decimals: 18
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
var ERC20_BALANCE_ABI = "0x70a08231";
|
|
597
|
+
var ZoWallet = class {
|
|
598
|
+
constructor(client) {
|
|
599
|
+
this.cachedBalance = 0;
|
|
600
|
+
this.userWalletAddress = null;
|
|
601
|
+
this.network = "base";
|
|
602
|
+
this.client = client;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Set the user's wallet address for on-chain queries
|
|
606
|
+
*/
|
|
607
|
+
setWalletAddress(address, network = "base") {
|
|
608
|
+
this.userWalletAddress = address;
|
|
609
|
+
this.network = network;
|
|
610
|
+
logger.debug(`Wallet address set: ${address} on ${network}`);
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Get wallet balance - tries on-chain first, then API fallback
|
|
614
|
+
* @returns Wallet balance amount
|
|
615
|
+
*/
|
|
616
|
+
async getBalance() {
|
|
617
|
+
if (this.userWalletAddress) {
|
|
618
|
+
try {
|
|
619
|
+
const onChainBalance = await this.getOnChainBalance();
|
|
620
|
+
if (onChainBalance !== null) {
|
|
621
|
+
this.cachedBalance = onChainBalance;
|
|
622
|
+
return onChainBalance;
|
|
623
|
+
}
|
|
624
|
+
} catch (error) {
|
|
625
|
+
logger.warn("On-chain balance check failed, falling back to API:", error);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
const apiBalance = await this.getBalanceFromAPI();
|
|
629
|
+
if (apiBalance !== null) {
|
|
630
|
+
return apiBalance;
|
|
631
|
+
}
|
|
632
|
+
logger.debug("Returning cached/default balance:", this.cachedBalance);
|
|
633
|
+
return this.cachedBalance;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Fetch balance directly from blockchain via JSON-RPC
|
|
637
|
+
*/
|
|
638
|
+
async getOnChainBalance() {
|
|
639
|
+
if (!this.userWalletAddress) {
|
|
640
|
+
logger.warn("No wallet address set for on-chain query");
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
const config = ZO_TOKEN_CONFIG[this.network];
|
|
644
|
+
try {
|
|
645
|
+
const paddedAddress = this.userWalletAddress.toLowerCase().replace("0x", "").padStart(64, "0");
|
|
646
|
+
const data = ERC20_BALANCE_ABI + paddedAddress;
|
|
647
|
+
const response = await fetch(config.rpc, {
|
|
648
|
+
method: "POST",
|
|
649
|
+
headers: { "Content-Type": "application/json" },
|
|
650
|
+
body: JSON.stringify({
|
|
651
|
+
jsonrpc: "2.0",
|
|
652
|
+
id: 1,
|
|
653
|
+
method: "eth_call",
|
|
654
|
+
params: [
|
|
655
|
+
{
|
|
656
|
+
to: config.contractAddress,
|
|
657
|
+
data
|
|
658
|
+
},
|
|
659
|
+
"latest"
|
|
660
|
+
]
|
|
661
|
+
})
|
|
662
|
+
});
|
|
663
|
+
const result = await response.json();
|
|
664
|
+
if (result.error) {
|
|
665
|
+
logger.warn("RPC error:", result.error);
|
|
666
|
+
return null;
|
|
667
|
+
}
|
|
668
|
+
const rawBalance = BigInt(result.result || "0x0");
|
|
669
|
+
const balance = Number(rawBalance) / Math.pow(10, config.decimals);
|
|
670
|
+
logger.debug(`On-chain balance fetched: ${balance} $Zo`);
|
|
671
|
+
return balance;
|
|
672
|
+
} catch (error) {
|
|
673
|
+
logger.warn("Failed to fetch on-chain balance:", error);
|
|
674
|
+
return null;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Fetch balance from Zo API endpoints (tries multiple endpoints with fallback)
|
|
679
|
+
*/
|
|
680
|
+
async getBalanceFromAPI() {
|
|
681
|
+
const endpoints = [
|
|
682
|
+
"/api/v1/web3/token/airdrops/summary",
|
|
683
|
+
"/api/v1/wallet/balance",
|
|
684
|
+
"/api/v1/profile/wallet"
|
|
685
|
+
];
|
|
686
|
+
const errors = [];
|
|
687
|
+
for (const endpoint of endpoints) {
|
|
688
|
+
try {
|
|
689
|
+
const response = await this.client.axiosInstance.get(endpoint);
|
|
690
|
+
const balance = response.data?.data?.total_amount ?? response.data?.balance ?? response.data?.total_amount;
|
|
691
|
+
if (typeof balance === "number") {
|
|
692
|
+
logger.debug(`Balance fetched from API ${endpoint}:`, balance);
|
|
693
|
+
this.cachedBalance = balance;
|
|
694
|
+
return balance;
|
|
695
|
+
}
|
|
696
|
+
} catch (error) {
|
|
697
|
+
if (error?.response?.status !== 404) {
|
|
698
|
+
errors.push({
|
|
699
|
+
endpoint,
|
|
700
|
+
status: error?.response?.status,
|
|
701
|
+
message: error?.message || "Unknown error"
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
if (errors.length > 0) {
|
|
707
|
+
logger.warn("All balance API endpoints failed:", errors);
|
|
708
|
+
}
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Get transaction history
|
|
713
|
+
* @param page - Optional page number for pagination
|
|
714
|
+
* @returns Array of transactions
|
|
715
|
+
*/
|
|
716
|
+
async getTransactions(page) {
|
|
717
|
+
const endpoints = [
|
|
718
|
+
page ? `/api/v1/profile/completion-grants/claims?page=${page}` : "/api/v1/profile/completion-grants/claims",
|
|
719
|
+
page ? `/api/v1/wallet/transactions?page=${page}` : "/api/v1/wallet/transactions"
|
|
720
|
+
];
|
|
721
|
+
const errors = [];
|
|
722
|
+
for (const url of endpoints) {
|
|
723
|
+
try {
|
|
724
|
+
const response = await this.client.axiosInstance.get(url);
|
|
725
|
+
const data = response.data?.data || response.data;
|
|
726
|
+
return {
|
|
727
|
+
transactions: data?.results ?? data?.transactions ?? [],
|
|
728
|
+
next: data?.next,
|
|
729
|
+
previous: data?.previous,
|
|
730
|
+
count: data?.count ?? 0
|
|
731
|
+
};
|
|
732
|
+
} catch (error) {
|
|
733
|
+
if (error?.response?.status !== 404) {
|
|
734
|
+
errors.push({
|
|
735
|
+
endpoint: url,
|
|
736
|
+
status: error?.response?.status,
|
|
737
|
+
message: error?.message || "Unknown error"
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
if (errors.length > 0) {
|
|
743
|
+
logger.warn("All transaction API endpoints failed:", errors);
|
|
744
|
+
}
|
|
745
|
+
return {
|
|
746
|
+
transactions: [],
|
|
747
|
+
next: void 0,
|
|
748
|
+
previous: void 0,
|
|
749
|
+
count: 0
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
// src/lib/utils/phone.ts
|
|
755
|
+
var COUNTRY_CODES = [
|
|
756
|
+
{ code: "1", country: "US", flag: "\u{1F1FA}\u{1F1F8}", name: "United States" },
|
|
757
|
+
{ code: "91", country: "IN", flag: "\u{1F1EE}\u{1F1F3}", name: "India" },
|
|
758
|
+
{ code: "44", country: "GB", flag: "\u{1F1EC}\u{1F1E7}", name: "United Kingdom" },
|
|
759
|
+
{ code: "86", country: "CN", flag: "\u{1F1E8}\u{1F1F3}", name: "China" },
|
|
760
|
+
{ code: "81", country: "JP", flag: "\u{1F1EF}\u{1F1F5}", name: "Japan" },
|
|
761
|
+
{ code: "82", country: "KR", flag: "\u{1F1F0}\u{1F1F7}", name: "South Korea" },
|
|
762
|
+
{ code: "33", country: "FR", flag: "\u{1F1EB}\u{1F1F7}", name: "France" },
|
|
763
|
+
{ code: "49", country: "DE", flag: "\u{1F1E9}\u{1F1EA}", name: "Germany" },
|
|
764
|
+
{ code: "7", country: "RU", flag: "\u{1F1F7}\u{1F1FA}", name: "Russia" },
|
|
765
|
+
{ code: "55", country: "BR", flag: "\u{1F1E7}\u{1F1F7}", name: "Brazil" },
|
|
766
|
+
{ code: "61", country: "AU", flag: "\u{1F1E6}\u{1F1FA}", name: "Australia" },
|
|
767
|
+
{ code: "65", country: "SG", flag: "\u{1F1F8}\u{1F1EC}", name: "Singapore" },
|
|
768
|
+
{ code: "971", country: "AE", flag: "\u{1F1E6}\u{1F1EA}", name: "UAE" },
|
|
769
|
+
{ code: "966", country: "SA", flag: "\u{1F1F8}\u{1F1E6}", name: "Saudi Arabia" },
|
|
770
|
+
{ code: "62", country: "ID", flag: "\u{1F1EE}\u{1F1E9}", name: "Indonesia" },
|
|
771
|
+
{ code: "60", country: "MY", flag: "\u{1F1F2}\u{1F1FE}", name: "Malaysia" },
|
|
772
|
+
{ code: "66", country: "TH", flag: "\u{1F1F9}\u{1F1ED}", name: "Thailand" },
|
|
773
|
+
{ code: "84", country: "VN", flag: "\u{1F1FB}\u{1F1F3}", name: "Vietnam" },
|
|
774
|
+
{ code: "63", country: "PH", flag: "\u{1F1F5}\u{1F1ED}", name: "Philippines" },
|
|
775
|
+
{ code: "31", country: "NL", flag: "\u{1F1F3}\u{1F1F1}", name: "Netherlands" }
|
|
776
|
+
];
|
|
777
|
+
function formatPhoneNumber(phone) {
|
|
778
|
+
const cleaned = phone.replace(/\D/g, "");
|
|
779
|
+
if (cleaned.length === 10) {
|
|
780
|
+
return `${cleaned.slice(0, 3)}-${cleaned.slice(3, 6)}-${cleaned.slice(6)}`;
|
|
781
|
+
}
|
|
782
|
+
return cleaned;
|
|
783
|
+
}
|
|
784
|
+
function parsePhoneNumber(phone) {
|
|
785
|
+
return phone.replace(/\D/g, "");
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// src/lib/utils/wallet.ts
|
|
789
|
+
var formatBalance = (balance) => {
|
|
790
|
+
if (balance === 0) return "0";
|
|
791
|
+
const formatted = balance.toLocaleString("en-US", {
|
|
792
|
+
minimumFractionDigits: 0,
|
|
793
|
+
maximumFractionDigits: 2
|
|
794
|
+
});
|
|
795
|
+
return formatted;
|
|
796
|
+
};
|
|
797
|
+
var formatBalanceShort = (balance) => {
|
|
798
|
+
if (balance === 0) return "0";
|
|
799
|
+
if (balance < 1e3) return formatBalance(balance);
|
|
800
|
+
if (balance < 1e6) return `${(balance / 1e3).toFixed(1)}K`;
|
|
801
|
+
return `${(balance / 1e6).toFixed(1)}M`;
|
|
802
|
+
};
|
|
803
|
+
var formatWalletAddress = (address) => {
|
|
804
|
+
if (!address || address.length < 8) return address;
|
|
805
|
+
return `${address.slice(0, 4)}...${address.slice(-4)}`;
|
|
806
|
+
};
|
|
807
|
+
var formatNickname = (nickname) => {
|
|
808
|
+
if (!nickname) return "";
|
|
809
|
+
return nickname.startsWith("@") ? nickname : `@${nickname}`;
|
|
810
|
+
};
|
|
811
|
+
var formatTransactionAmount = (amount, action) => {
|
|
812
|
+
const formatted = formatBalance(amount);
|
|
813
|
+
return action === "spend" ? `- ${formatted}` : `+ ${formatted}`;
|
|
814
|
+
};
|
|
815
|
+
var getTransactionColor = (action) => {
|
|
816
|
+
return action === "spend" ? "#FF4444" : "#00C853";
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
// src/ZoPassportSDK.ts
|
|
820
|
+
var ZoPassportSDK = class {
|
|
821
|
+
constructor(config) {
|
|
822
|
+
this.refreshTimer = null;
|
|
823
|
+
this._user = null;
|
|
824
|
+
this._isAuthenticated = false;
|
|
825
|
+
if (config.debug) {
|
|
826
|
+
logger.enable();
|
|
827
|
+
logger.setLevel("debug");
|
|
828
|
+
}
|
|
829
|
+
this.storage = config.storageAdapter || new LocalStorageAdapter();
|
|
830
|
+
this.client = new ZoApiClient({
|
|
831
|
+
...config,
|
|
832
|
+
storageAdapter: this.storage
|
|
833
|
+
});
|
|
834
|
+
this.auth = new ZoAuth(this.client);
|
|
835
|
+
this.profile = new ZoProfile(this.client);
|
|
836
|
+
this.avatar = new ZoAvatar(this.client);
|
|
837
|
+
this.wallet = new ZoWallet(this.client);
|
|
838
|
+
if (config.autoRefresh !== false) {
|
|
839
|
+
this.startAutoRefresh(config.refreshInterval || 6e4);
|
|
840
|
+
}
|
|
841
|
+
this._readyPromise = this.loadSession();
|
|
842
|
+
logger.debug("SDK initialized with config:", {
|
|
843
|
+
baseUrl: config.baseUrl,
|
|
844
|
+
autoRefresh: config.autoRefresh !== false
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Wait for the SDK to be ready (session loaded from storage)
|
|
849
|
+
* Use this if you need to check isAuthenticated immediately after construction
|
|
850
|
+
*/
|
|
851
|
+
async ready() {
|
|
852
|
+
return this._readyPromise;
|
|
853
|
+
}
|
|
854
|
+
// =====================
|
|
855
|
+
// Session Management
|
|
856
|
+
// =====================
|
|
857
|
+
async loadSession() {
|
|
858
|
+
try {
|
|
859
|
+
const userJson = await this.storage.getItem(STORAGE_KEYS.USER);
|
|
860
|
+
const accessToken = await this.storage.getItem(STORAGE_KEYS.ACCESS_TOKEN);
|
|
861
|
+
if (userJson && accessToken) {
|
|
862
|
+
this._user = JSON.parse(userJson);
|
|
863
|
+
this._isAuthenticated = true;
|
|
864
|
+
}
|
|
865
|
+
} catch (error) {
|
|
866
|
+
logger.warn("Failed to load session:", error);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
async saveSession(authResponse) {
|
|
870
|
+
await this.storage.setItem(STORAGE_KEYS.ACCESS_TOKEN, authResponse.access_token);
|
|
871
|
+
await this.storage.setItem(STORAGE_KEYS.REFRESH_TOKEN, authResponse.refresh_token);
|
|
872
|
+
await this.storage.setItem(STORAGE_KEYS.TOKEN_EXPIRY, authResponse.access_token_expiry);
|
|
873
|
+
await this.storage.setItem(STORAGE_KEYS.REFRESH_EXPIRY, authResponse.refresh_token_expiry);
|
|
874
|
+
await this.storage.setItem(STORAGE_KEYS.USER, JSON.stringify(authResponse.user));
|
|
875
|
+
await this.storage.setItem(STORAGE_KEYS.CLIENT_DEVICE_ID, authResponse.device_id || "");
|
|
876
|
+
await this.storage.setItem(STORAGE_KEYS.CLIENT_DEVICE_SECRET, authResponse.device_secret || "");
|
|
877
|
+
this._user = authResponse.user;
|
|
878
|
+
this._isAuthenticated = true;
|
|
879
|
+
}
|
|
880
|
+
async clearSession() {
|
|
881
|
+
await this.storage.removeItem(STORAGE_KEYS.ACCESS_TOKEN);
|
|
882
|
+
await this.storage.removeItem(STORAGE_KEYS.REFRESH_TOKEN);
|
|
883
|
+
await this.storage.removeItem(STORAGE_KEYS.TOKEN_EXPIRY);
|
|
884
|
+
await this.storage.removeItem(STORAGE_KEYS.REFRESH_EXPIRY);
|
|
885
|
+
await this.storage.removeItem(STORAGE_KEYS.USER);
|
|
886
|
+
await this.storage.removeItem(STORAGE_KEYS.CLIENT_DEVICE_ID);
|
|
887
|
+
await this.storage.removeItem(STORAGE_KEYS.CLIENT_DEVICE_SECRET);
|
|
888
|
+
this._user = null;
|
|
889
|
+
this._isAuthenticated = false;
|
|
890
|
+
}
|
|
891
|
+
// =====================
|
|
892
|
+
// Auto Token Refresh
|
|
893
|
+
// =====================
|
|
894
|
+
startAutoRefresh(interval) {
|
|
895
|
+
this.refreshTimer = setInterval(async () => {
|
|
896
|
+
await this.refreshTokenIfNeeded();
|
|
897
|
+
}, interval);
|
|
898
|
+
}
|
|
899
|
+
stopAutoRefresh() {
|
|
900
|
+
if (this.refreshTimer) {
|
|
901
|
+
clearInterval(this.refreshTimer);
|
|
902
|
+
this.refreshTimer = null;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
async refreshTokenIfNeeded() {
|
|
906
|
+
const tokenExpiry = await this.storage.getItem(STORAGE_KEYS.TOKEN_EXPIRY);
|
|
907
|
+
const refreshToken = await this.storage.getItem(STORAGE_KEYS.REFRESH_TOKEN);
|
|
908
|
+
if (!tokenExpiry || !refreshToken) return;
|
|
909
|
+
const expiryDate = new Date(tokenExpiry);
|
|
910
|
+
const now = /* @__PURE__ */ new Date();
|
|
911
|
+
const twoMinutes = 2 * 60 * 1e3;
|
|
912
|
+
if (expiryDate.getTime() - now.getTime() < twoMinutes) {
|
|
913
|
+
const result = await this.auth.refreshAccessToken(refreshToken);
|
|
914
|
+
if (result.success && result.tokens) {
|
|
915
|
+
await this.storage.setItem(STORAGE_KEYS.ACCESS_TOKEN, result.tokens.access);
|
|
916
|
+
await this.storage.setItem(STORAGE_KEYS.REFRESH_TOKEN, result.tokens.refresh);
|
|
917
|
+
await this.storage.setItem(STORAGE_KEYS.TOKEN_EXPIRY, result.tokens.access_expiry);
|
|
918
|
+
await this.storage.setItem(STORAGE_KEYS.REFRESH_EXPIRY, result.tokens.refresh_expiry);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
// =====================
|
|
923
|
+
// Public API
|
|
924
|
+
// =====================
|
|
925
|
+
get user() {
|
|
926
|
+
return this._user;
|
|
927
|
+
}
|
|
928
|
+
get isAuthenticated() {
|
|
929
|
+
return this._isAuthenticated;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Complete phone authentication flow
|
|
933
|
+
*/
|
|
934
|
+
async loginWithPhone(countryCode, phoneNumber, otp) {
|
|
935
|
+
const result = await this.auth.verifyOTP(countryCode, phoneNumber, otp);
|
|
936
|
+
if (result.success && result.data) {
|
|
937
|
+
await this.saveSession(result.data);
|
|
938
|
+
if (result.data.user?.wallet_address) {
|
|
939
|
+
this.wallet.setWalletAddress(result.data.user.wallet_address, "base");
|
|
940
|
+
}
|
|
941
|
+
return { success: true, user: result.data.user };
|
|
942
|
+
}
|
|
943
|
+
return { success: false, error: result.error };
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Logout and clear session
|
|
947
|
+
*/
|
|
948
|
+
async logout() {
|
|
949
|
+
await this.clearSession();
|
|
950
|
+
this.stopAutoRefresh();
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Get current user profile
|
|
954
|
+
*/
|
|
955
|
+
async getProfile() {
|
|
956
|
+
const accessToken = await this.storage.getItem(STORAGE_KEYS.ACCESS_TOKEN);
|
|
957
|
+
if (!accessToken) return null;
|
|
958
|
+
const result = await this.profile.getProfile(accessToken);
|
|
959
|
+
if (result.success && result.profile) {
|
|
960
|
+
this._user = result.profile;
|
|
961
|
+
await this.storage.setItem(STORAGE_KEYS.USER, JSON.stringify(result.profile));
|
|
962
|
+
if (result.profile.wallet_address) {
|
|
963
|
+
this.wallet.setWalletAddress(result.profile.wallet_address, "base");
|
|
964
|
+
}
|
|
965
|
+
return result.profile;
|
|
966
|
+
}
|
|
967
|
+
return null;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Update user profile
|
|
971
|
+
*/
|
|
972
|
+
async updateProfile(updates) {
|
|
973
|
+
const accessToken = await this.storage.getItem(STORAGE_KEYS.ACCESS_TOKEN);
|
|
974
|
+
if (!accessToken) return { success: false, error: "Not authenticated" };
|
|
975
|
+
const result = await this.profile.updateProfile(accessToken, updates);
|
|
976
|
+
if (result.success && result.profile) {
|
|
977
|
+
this._user = result.profile;
|
|
978
|
+
await this.storage.setItem(STORAGE_KEYS.USER, JSON.stringify(result.profile));
|
|
979
|
+
return { success: true, profile: result.profile };
|
|
980
|
+
}
|
|
981
|
+
return { success: false, error: result.error };
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Generate avatar
|
|
985
|
+
*/
|
|
986
|
+
async generateAvatar(bodyType) {
|
|
987
|
+
const accessToken = await this.storage.getItem(STORAGE_KEYS.ACCESS_TOKEN);
|
|
988
|
+
if (!accessToken) return { success: false, error: "Not authenticated" };
|
|
989
|
+
const startResult = await this.avatar.generateAvatar(accessToken, bodyType);
|
|
990
|
+
if (!startResult.success || !startResult.task_id) {
|
|
991
|
+
return { success: false, error: startResult.error };
|
|
992
|
+
}
|
|
993
|
+
return new Promise((resolve) => {
|
|
994
|
+
this.avatar.pollAvatarStatus(accessToken, startResult.task_id, {
|
|
995
|
+
onComplete: (avatarUrl) => {
|
|
996
|
+
resolve({ success: true, avatarUrl });
|
|
997
|
+
},
|
|
998
|
+
onError: (error) => {
|
|
999
|
+
resolve({ success: false, error });
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Get wallet balance
|
|
1006
|
+
*/
|
|
1007
|
+
async getWalletBalance() {
|
|
1008
|
+
return this.wallet.getBalance();
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Get wallet transactions
|
|
1012
|
+
*/
|
|
1013
|
+
async getWalletTransactions(page) {
|
|
1014
|
+
return this.wallet.getTransactions(page);
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Cleanup
|
|
1018
|
+
*/
|
|
1019
|
+
destroy() {
|
|
1020
|
+
this.stopAutoRefresh();
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
|
|
1024
|
+
// assets/wallet/constants.ts
|
|
1025
|
+
var WALLET_DIMENSIONS = {
|
|
1026
|
+
cardAspectRatio: 312 / 200,
|
|
1027
|
+
coverAspectRatio: 312 / 120,
|
|
1028
|
+
cardBorderRadius: 16,
|
|
1029
|
+
innerBorderRadius: 12,
|
|
1030
|
+
avatarSize: 32,
|
|
1031
|
+
tokenSize: 16,
|
|
1032
|
+
tokenVideoSize: 24
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
// assets/index.ts
|
|
1036
|
+
var ASSETS = {
|
|
1037
|
+
// Core avatars
|
|
1038
|
+
BRO_AVATAR: "/bro.png",
|
|
1039
|
+
BAE_AVATAR: "/bae.png",
|
|
1040
|
+
FALLBACK_AVATAR: "/zo-fallback.png",
|
|
1041
|
+
DEFAULT_AVATAR: "/images/rank1.jpeg",
|
|
1042
|
+
// Branding
|
|
1043
|
+
ZO_LOGO: "/figma-assets/landing-zo-logo.png",
|
|
1044
|
+
ZO_COIN: "/zo-coin.gif",
|
|
1045
|
+
// Videos
|
|
1046
|
+
LANDING_VIDEO: "/videos/loading-screen-background.mp4",
|
|
1047
|
+
PORTAL_VIDEO: "/videos/opening-disks.mp4",
|
|
1048
|
+
// Passport backgrounds (CDN)
|
|
1049
|
+
FOUNDER_BG: "https://proxy.cdn.zo.xyz/gallery/media/images/a1659b07-94f0-4490-9b3c-3366715d9717_20250515053726.png",
|
|
1050
|
+
CITIZEN_BG: "https://proxy.cdn.zo.xyz/gallery/media/images/bda9da5a-eefe-411d-8d90-667c80024463_20250515053805.png",
|
|
1051
|
+
// Lotties
|
|
1052
|
+
LOADER: "/lotties/loader.json",
|
|
1053
|
+
SPINNER: "/lotties/spinner.json"
|
|
1054
|
+
};
|
|
1055
|
+
var CULTURE_STICKERS = {
|
|
1056
|
+
travel: "/cultural-stickers/Travel&Adventure.png",
|
|
1057
|
+
design: "/cultural-stickers/Design.png",
|
|
1058
|
+
tech: "/cultural-stickers/Science&Technology.png",
|
|
1059
|
+
food: "/cultural-stickers/Food.png",
|
|
1060
|
+
music: "/cultural-stickers/Music&Entertainment.png",
|
|
1061
|
+
photography: "/cultural-stickers/Photography.png",
|
|
1062
|
+
fitness: "/cultural-stickers/Health&Fitness.png",
|
|
1063
|
+
sports: "/cultural-stickers/Sport.png",
|
|
1064
|
+
literature: "/cultural-stickers/Literature&Stories.png",
|
|
1065
|
+
cinema: "/cultural-stickers/Television&Cinema.png",
|
|
1066
|
+
spiritual: "/cultural-stickers/Spiritual.png",
|
|
1067
|
+
nature: "/cultural-stickers/Nature&Wildlife.png",
|
|
1068
|
+
business: "/cultural-stickers/Business.png",
|
|
1069
|
+
law: "/cultural-stickers/Law.png",
|
|
1070
|
+
lifestyle: "/cultural-stickers/Home&Lifestyle.png",
|
|
1071
|
+
gaming: "/cultural-stickers/Game.png",
|
|
1072
|
+
stories: "/cultural-stickers/Stories&Journal.png"
|
|
1073
|
+
};
|
|
1074
|
+
var CULTURES = [
|
|
1075
|
+
{ id: "travel", name: "Travel & Adventure", icon: CULTURE_STICKERS.travel },
|
|
1076
|
+
{ id: "design", name: "Design", icon: CULTURE_STICKERS.design },
|
|
1077
|
+
{ id: "tech", name: "Science & Technology", icon: CULTURE_STICKERS.tech },
|
|
1078
|
+
{ id: "food", name: "Food", icon: CULTURE_STICKERS.food },
|
|
1079
|
+
{ id: "music", name: "Music & Entertainment", icon: CULTURE_STICKERS.music },
|
|
1080
|
+
{ id: "photography", name: "Photography", icon: CULTURE_STICKERS.photography },
|
|
1081
|
+
{ id: "fitness", name: "Health & Fitness", icon: CULTURE_STICKERS.fitness },
|
|
1082
|
+
{ id: "sports", name: "Sport", icon: CULTURE_STICKERS.sports },
|
|
1083
|
+
{ id: "literature", name: "Literature & Stories", icon: CULTURE_STICKERS.literature },
|
|
1084
|
+
{ id: "cinema", name: "Television & Cinema", icon: CULTURE_STICKERS.cinema },
|
|
1085
|
+
{ id: "spiritual", name: "Spiritual", icon: CULTURE_STICKERS.spiritual },
|
|
1086
|
+
{ id: "nature", name: "Nature & Wildlife", icon: CULTURE_STICKERS.nature },
|
|
1087
|
+
{ id: "business", name: "Business", icon: CULTURE_STICKERS.business },
|
|
1088
|
+
{ id: "law", name: "Law", icon: CULTURE_STICKERS.law },
|
|
1089
|
+
{ id: "lifestyle", name: "Home & Lifestyle", icon: CULTURE_STICKERS.lifestyle },
|
|
1090
|
+
{ id: "gaming", name: "Game", icon: CULTURE_STICKERS.gaming },
|
|
1091
|
+
{ id: "stories", name: "Stories & Journal", icon: CULTURE_STICKERS.stories }
|
|
1092
|
+
];
|
|
1093
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1094
|
+
0 && (module.exports = {
|
|
1095
|
+
ASSETS,
|
|
1096
|
+
AsyncStorageAdapter,
|
|
1097
|
+
COUNTRY_CODES,
|
|
1098
|
+
CULTURES,
|
|
1099
|
+
CULTURE_STICKERS,
|
|
1100
|
+
LocalStorageAdapter,
|
|
1101
|
+
STORAGE_KEYS,
|
|
1102
|
+
ZoApiClient,
|
|
1103
|
+
ZoAuth,
|
|
1104
|
+
ZoAvatar,
|
|
1105
|
+
ZoPassportSDK,
|
|
1106
|
+
ZoProfile,
|
|
1107
|
+
ZoWallet,
|
|
1108
|
+
formatBalance,
|
|
1109
|
+
formatBalanceShort,
|
|
1110
|
+
formatNickname,
|
|
1111
|
+
formatPhoneNumber,
|
|
1112
|
+
formatTransactionAmount,
|
|
1113
|
+
formatWalletAddress,
|
|
1114
|
+
getTransactionColor,
|
|
1115
|
+
logger,
|
|
1116
|
+
parsePhoneNumber
|
|
1117
|
+
});
|
|
1118
|
+
//# sourceMappingURL=index.js.map
|