@nadohq/mobile-client 0.27.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 +73 -0
- package/dist/MobileClient-9JSAzblH.cjs +218 -0
- package/dist/MobileClient-9JSAzblH.cjs.map +1 -0
- package/dist/MobileClient.cjs +4 -0
- package/dist/MobileClient.d.cts +114 -0
- package/dist/MobileClient.d.cts.map +1 -0
- package/dist/MobileClient.d.ts +114 -0
- package/dist/MobileClient.d.ts.map +1 -0
- package/dist/MobileClient.js +185 -0
- package/dist/MobileClient.js.map +1 -0
- package/dist/MobileServerFailureError-Belp_yef.d.cts +25 -0
- package/dist/MobileServerFailureError-Belp_yef.d.cts.map +1 -0
- package/dist/MobileServerFailureError-DqM0T6CB.d.ts +25 -0
- package/dist/MobileServerFailureError-DqM0T6CB.d.ts.map +1 -0
- package/dist/buildSignedMobileRequest-BsbBkU0K.d.cts +14 -0
- package/dist/buildSignedMobileRequest-BsbBkU0K.d.cts.map +1 -0
- package/dist/buildSignedMobileRequest-CDRsRNHm.d.ts +14 -0
- package/dist/buildSignedMobileRequest-CDRsRNHm.d.ts.map +1 -0
- package/dist/canonicalize-Dm7sXwPg.d.cts +14 -0
- package/dist/canonicalize-Dm7sXwPg.d.cts.map +1 -0
- package/dist/canonicalize-PX6dTIdF.d.ts +14 -0
- package/dist/canonicalize-PX6dTIdF.d.ts.map +1 -0
- package/dist/clientTypes-DWW2N66c.d.ts +168 -0
- package/dist/clientTypes-DWW2N66c.d.ts.map +1 -0
- package/dist/clientTypes-Et0PUa2d.d.cts +168 -0
- package/dist/clientTypes-Et0PUa2d.d.cts.map +1 -0
- package/dist/dataMappers.cjs +89 -0
- package/dist/dataMappers.cjs.map +1 -0
- package/dist/dataMappers.d.cts +27 -0
- package/dist/dataMappers.d.cts.map +1 -0
- package/dist/dataMappers.d.ts +27 -0
- package/dist/dataMappers.d.ts.map +1 -0
- package/dist/dataMappers.js +84 -0
- package/dist/dataMappers.js.map +1 -0
- package/dist/eip712MethodByType-DJgXal9r.d.ts +10 -0
- package/dist/eip712MethodByType-DJgXal9r.d.ts.map +1 -0
- package/dist/eip712MethodByType-DLh9MRsD.d.cts +10 -0
- package/dist/eip712MethodByType-DLh9MRsD.d.cts.map +1 -0
- package/dist/endpoints.cjs +14 -0
- package/dist/endpoints.cjs.map +1 -0
- package/dist/endpoints.d.cts +10 -0
- package/dist/endpoints.d.cts.map +1 -0
- package/dist/endpoints.d.ts +10 -0
- package/dist/endpoints.d.ts.map +1 -0
- package/dist/endpoints.js +13 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/index.cjs +27 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +15 -0
- package/dist/mobileErrorCodes-D8KzJXbU.d.cts +29 -0
- package/dist/mobileErrorCodes-D8KzJXbU.d.cts.map +1 -0
- package/dist/mobileErrorCodes-DM09jnNe.d.ts +29 -0
- package/dist/mobileErrorCodes-DM09jnNe.d.ts.map +1 -0
- package/dist/nonce-DCOrXXkQ.d.ts +15 -0
- package/dist/nonce-DCOrXXkQ.d.ts.map +1 -0
- package/dist/nonce-zGyisRlj.d.cts +15 -0
- package/dist/nonce-zGyisRlj.d.cts.map +1 -0
- package/dist/patterns-B9J2ldpx.d.cts +8 -0
- package/dist/patterns-B9J2ldpx.d.cts.map +1 -0
- package/dist/patterns-BbxH3_VA.d.ts +8 -0
- package/dist/patterns-BbxH3_VA.d.ts.map +1 -0
- package/dist/payloadHash-Bmhzs78N.d.ts +13 -0
- package/dist/payloadHash-Bmhzs78N.d.ts.map +1 -0
- package/dist/payloadHash-nj8WuLUP.d.cts +13 -0
- package/dist/payloadHash-nj8WuLUP.d.cts.map +1 -0
- package/dist/serverBaseTypes-BicXMrZV.d.cts +43 -0
- package/dist/serverBaseTypes-BicXMrZV.d.cts.map +1 -0
- package/dist/serverBaseTypes-ewbo8l4R.d.ts +43 -0
- package/dist/serverBaseTypes-ewbo8l4R.d.ts.map +1 -0
- package/dist/serverExecuteTypes-CXnMjKnt.d.ts +11 -0
- package/dist/serverExecuteTypes-CXnMjKnt.d.ts.map +1 -0
- package/dist/serverExecuteTypes-DKYK1V7C.d.cts +11 -0
- package/dist/serverExecuteTypes-DKYK1V7C.d.cts.map +1 -0
- package/dist/serverModelTypes-CQgfqgW3.d.cts +69 -0
- package/dist/serverModelTypes-CQgfqgW3.d.cts.map +1 -0
- package/dist/serverModelTypes-vEPhHIit.d.ts +69 -0
- package/dist/serverModelTypes-vEPhHIit.d.ts.map +1 -0
- package/dist/serverQueryTypes-BI-2TD8F.d.ts +53 -0
- package/dist/serverQueryTypes-BI-2TD8F.d.ts.map +1 -0
- package/dist/serverQueryTypes-D7Yharse.d.cts +53 -0
- package/dist/serverQueryTypes-D7Yharse.d.cts.map +1 -0
- package/dist/serverResponseGuards-C_vZIgGl.d.ts +16 -0
- package/dist/serverResponseGuards-C_vZIgGl.d.ts.map +1 -0
- package/dist/serverResponseGuards-DjCNL3CR.d.cts +16 -0
- package/dist/serverResponseGuards-DjCNL3CR.d.cts.map +1 -0
- package/dist/signing/buildSignedMobileRequest.cjs +47 -0
- package/dist/signing/buildSignedMobileRequest.cjs.map +1 -0
- package/dist/signing/buildSignedMobileRequest.d.cts +2 -0
- package/dist/signing/buildSignedMobileRequest.d.ts +2 -0
- package/dist/signing/buildSignedMobileRequest.js +45 -0
- package/dist/signing/buildSignedMobileRequest.js.map +1 -0
- package/dist/signing/canonicalize.cjs +68 -0
- package/dist/signing/canonicalize.cjs.map +1 -0
- package/dist/signing/canonicalize.d.cts +2 -0
- package/dist/signing/canonicalize.d.ts +2 -0
- package/dist/signing/canonicalize.js +67 -0
- package/dist/signing/canonicalize.js.map +1 -0
- package/dist/signing/eip712MethodByType.cjs +20 -0
- package/dist/signing/eip712MethodByType.cjs.map +1 -0
- package/dist/signing/eip712MethodByType.d.cts +2 -0
- package/dist/signing/eip712MethodByType.d.ts +2 -0
- package/dist/signing/eip712MethodByType.js +19 -0
- package/dist/signing/eip712MethodByType.js.map +1 -0
- package/dist/signing/index.cjs +11 -0
- package/dist/signing/index.d.cts +7 -0
- package/dist/signing/index.d.ts +7 -0
- package/dist/signing/index.js +6 -0
- package/dist/signing/nonce.cjs +19 -0
- package/dist/signing/nonce.cjs.map +1 -0
- package/dist/signing/nonce.d.cts +2 -0
- package/dist/signing/nonce.d.ts +2 -0
- package/dist/signing/nonce.js +18 -0
- package/dist/signing/nonce.js.map +1 -0
- package/dist/signing/payloadHash.cjs +17 -0
- package/dist/signing/payloadHash.cjs.map +1 -0
- package/dist/signing/payloadHash.d.cts +2 -0
- package/dist/signing/payloadHash.d.ts +2 -0
- package/dist/signing/payloadHash.js +15 -0
- package/dist/signing/payloadHash.js.map +1 -0
- package/dist/signing/types.cjs +0 -0
- package/dist/signing/types.d.cts +2 -0
- package/dist/signing/types.d.ts +2 -0
- package/dist/signing/types.js +1 -0
- package/dist/types/MobileServerFailureError.cjs +17 -0
- package/dist/types/MobileServerFailureError.cjs.map +1 -0
- package/dist/types/MobileServerFailureError.d.cts +2 -0
- package/dist/types/MobileServerFailureError.d.ts +2 -0
- package/dist/types/MobileServerFailureError.js +16 -0
- package/dist/types/MobileServerFailureError.js.map +1 -0
- package/dist/types/clientTypes.cjs +0 -0
- package/dist/types/clientTypes.d.cts +2 -0
- package/dist/types/clientTypes.d.ts +2 -0
- package/dist/types/clientTypes.js +1 -0
- package/dist/types/index.cjs +5 -0
- package/dist/types/index.d.cts +8 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +3 -0
- package/dist/types/mobileErrorCodes.cjs +27 -0
- package/dist/types/mobileErrorCodes.cjs.map +1 -0
- package/dist/types/mobileErrorCodes.d.cts +2 -0
- package/dist/types/mobileErrorCodes.d.ts +2 -0
- package/dist/types/mobileErrorCodes.js +26 -0
- package/dist/types/mobileErrorCodes.js.map +1 -0
- package/dist/types/serverBaseTypes.cjs +0 -0
- package/dist/types/serverBaseTypes.d.cts +2 -0
- package/dist/types/serverBaseTypes.d.ts +2 -0
- package/dist/types/serverBaseTypes.js +1 -0
- package/dist/types/serverExecuteTypes.cjs +0 -0
- package/dist/types/serverExecuteTypes.d.cts +2 -0
- package/dist/types/serverExecuteTypes.d.ts +2 -0
- package/dist/types/serverExecuteTypes.js +1 -0
- package/dist/types/serverModelTypes.cjs +0 -0
- package/dist/types/serverModelTypes.d.cts +2 -0
- package/dist/types/serverModelTypes.d.ts +2 -0
- package/dist/types/serverModelTypes.js +1 -0
- package/dist/types/serverQueryTypes.cjs +0 -0
- package/dist/types/serverQueryTypes.d.cts +2 -0
- package/dist/types/serverQueryTypes.d.ts +2 -0
- package/dist/types/serverQueryTypes.js +1 -0
- package/dist/types-B76Pn7Sy.d.ts +73 -0
- package/dist/types-B76Pn7Sy.d.ts.map +1 -0
- package/dist/types-uCD4BNZR.d.cts +73 -0
- package/dist/types-uCD4BNZR.d.cts.map +1 -0
- package/dist/utils/index.cjs +6 -0
- package/dist/utils/index.d.cts +3 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/patterns.cjs +10 -0
- package/dist/utils/patterns.cjs.map +1 -0
- package/dist/utils/patterns.d.cts +2 -0
- package/dist/utils/patterns.d.ts +2 -0
- package/dist/utils/patterns.js +9 -0
- package/dist/utils/patterns.js.map +1 -0
- package/dist/utils/serverResponseGuards.cjs +19 -0
- package/dist/utils/serverResponseGuards.cjs.map +1 -0
- package/dist/utils/serverResponseGuards.d.cts +2 -0
- package/dist/utils/serverResponseGuards.d.ts +2 -0
- package/dist/utils/serverResponseGuards.js +17 -0
- package/dist/utils/serverResponseGuards.js.map +1 -0
- package/package.json +58 -0
- package/src/MobileClient.ts +395 -0
- package/src/dataMappers.ts +106 -0
- package/src/endpoints.ts +10 -0
- package/src/index.ts +5 -0
- package/src/signing/buildSignedMobileRequest.ts +58 -0
- package/src/signing/canonicalize.ts +69 -0
- package/src/signing/eip712MethodByType.ts +19 -0
- package/src/signing/index.ts +6 -0
- package/src/signing/nonce.ts +16 -0
- package/src/signing/payloadHash.ts +12 -0
- package/src/signing/signing.test.ts +224 -0
- package/src/signing/types.ts +71 -0
- package/src/types/MobileServerFailureError.ts +18 -0
- package/src/types/clientTypes.ts +182 -0
- package/src/types/index.ts +7 -0
- package/src/types/mobileErrorCodes.ts +27 -0
- package/src/types/serverBaseTypes.ts +43 -0
- package/src/types/serverExecuteTypes.ts +12 -0
- package/src/types/serverModelTypes.ts +74 -0
- package/src/types/serverQueryTypes.ts +74 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/patterns.ts +4 -0
- package/src/utils/serverResponseGuards.ts +27 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { mapMobileIdentity, mapMobileNotificationPreferences, mapMobileNotificationPreferencesToServer, mapMobilePublicProfile, mapMobileRegisteredDevice } from "./dataMappers.js";
|
|
2
|
+
import { buildSignedMobileRequest } from "./signing/buildSignedMobileRequest.js";
|
|
3
|
+
import "./signing/index.js";
|
|
4
|
+
import { MobileServerFailureError } from "./types/MobileServerFailureError.js";
|
|
5
|
+
import { isMobileServerFailureResponse, isMobileServerSuccessResponse } from "./utils/serverResponseGuards.js";
|
|
6
|
+
import { WalletNotProvidedError } from "@nadohq/shared";
|
|
7
|
+
import axios from "axios";
|
|
8
|
+
//#region src/MobileClient.ts
|
|
9
|
+
/**
|
|
10
|
+
* Client for the Nado mobile service API: username claims, public profile lookups, privacy settings, and
|
|
11
|
+
* push notification device/preference management.
|
|
12
|
+
*/
|
|
13
|
+
var MobileClient = class {
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
this.opts = opts;
|
|
16
|
+
this.axiosInstance = axios.create({
|
|
17
|
+
withCredentials: true,
|
|
18
|
+
validateStatus: () => true
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sets the linked signer for requests
|
|
23
|
+
*
|
|
24
|
+
* @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer
|
|
25
|
+
*/
|
|
26
|
+
setLinkedSigner(linkedSignerWalletClient) {
|
|
27
|
+
this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? void 0;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Checks whether a username derived from the given display name is available to claim.
|
|
31
|
+
*/
|
|
32
|
+
async getUsernameAvailability(params) {
|
|
33
|
+
const body = {
|
|
34
|
+
type: "username_availability",
|
|
35
|
+
display_name: params.displayName
|
|
36
|
+
};
|
|
37
|
+
const data = await this.publicQuery(body);
|
|
38
|
+
return {
|
|
39
|
+
username: data.username,
|
|
40
|
+
available: data.available
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Looks up a subaccount's public profile by username.
|
|
45
|
+
*
|
|
46
|
+
* @throws {MobileServerFailureError} With error code `PROFILE_NOT_FOUND` if no identity has claimed the
|
|
47
|
+
* username or it is invalid. Private Mode does not hide the profile itself, only the account's activity.
|
|
48
|
+
*/
|
|
49
|
+
async getPublicProfile(params) {
|
|
50
|
+
const body = {
|
|
51
|
+
type: "profile",
|
|
52
|
+
username: params.username
|
|
53
|
+
};
|
|
54
|
+
return mapMobilePublicProfile((await this.publicQuery(body)).profile);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Fetches the caller's own identity for a subaccount. Returns `null` if the subaccount has not claimed a
|
|
58
|
+
* username yet — this is normal data, not an error.
|
|
59
|
+
*/
|
|
60
|
+
async getSelfIdentity(params) {
|
|
61
|
+
const signedRequest = await this.getSignedRequest("self_identity", params, {});
|
|
62
|
+
const data = await this.query(signedRequest);
|
|
63
|
+
return data.identity ? mapMobileIdentity(data.identity) : null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Fetches a wallet's push notification preferences. Falls back to the backend's defaults if the wallet has
|
|
67
|
+
* never updated its preferences.
|
|
68
|
+
*/
|
|
69
|
+
async getNotificationPreferences(params) {
|
|
70
|
+
const signedRequest = await this.getSignedRequest("notification_preferences", params, {});
|
|
71
|
+
return mapMobileNotificationPreferences((await this.query(signedRequest)).preferences);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Fetches the devices registered for push notifications for a wallet.
|
|
75
|
+
*/
|
|
76
|
+
async getRegisteredDevices(params) {
|
|
77
|
+
const signedRequest = await this.getSignedRequest("registered_devices", params, {});
|
|
78
|
+
return (await this.query(signedRequest)).devices.map(mapMobileRegisteredDevice);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Claims a username for a subaccount, derived from the given display name.
|
|
82
|
+
*/
|
|
83
|
+
async claimUsername(params) {
|
|
84
|
+
const signedRequest = await this.getSignedRequest("claim_username", params, { display_name: params.displayName });
|
|
85
|
+
return this.execute(signedRequest);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Updates the display name for a subaccount's already-claimed identity.
|
|
89
|
+
*/
|
|
90
|
+
async updateUsername(params) {
|
|
91
|
+
const signedRequest = await this.getSignedRequest("update_username", params, { display_name: params.displayName });
|
|
92
|
+
return this.execute(signedRequest);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Sets whether a subaccount's profile is private.
|
|
96
|
+
*/
|
|
97
|
+
async setPrivateMode(params) {
|
|
98
|
+
const signedRequest = await this.getSignedRequest("set_private_mode", params, { private_mode: params.privateMode });
|
|
99
|
+
return this.execute(signedRequest);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Registers an Expo push token for the wallet, transferring active ownership of the token if another
|
|
103
|
+
* wallet had registered it. Idempotent per `(wallet, token)`.
|
|
104
|
+
*
|
|
105
|
+
* @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is not a valid Expo
|
|
106
|
+
* push token, or `INVALID_DEVICE_METADATA` if `locale` (max 35 chars) or `appVersion` (max 64 chars) is
|
|
107
|
+
* too long.
|
|
108
|
+
*/
|
|
109
|
+
async registerExpoToken(params) {
|
|
110
|
+
const signedRequest = await this.getSignedRequest("register_expo_token", params, {
|
|
111
|
+
expo_token: params.expoToken,
|
|
112
|
+
platform: params.platform,
|
|
113
|
+
locale: params.locale ?? null,
|
|
114
|
+
app_version: params.appVersion ?? null
|
|
115
|
+
});
|
|
116
|
+
return this.execute(signedRequest);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Unregisters an Expo push token for the wallet. Idempotent — unregistering an unknown token succeeds.
|
|
120
|
+
*/
|
|
121
|
+
async unregisterExpoToken(params) {
|
|
122
|
+
const signedRequest = await this.getSignedRequest("unregister_expo_token", params, { expo_token: params.expoToken });
|
|
123
|
+
return this.execute(signedRequest);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Replaces the wallet's push notification preferences. The backend requires `schemaVersion` of 1, exactly
|
|
127
|
+
* one entry per known category, and empty `scopes` on every entry.
|
|
128
|
+
*
|
|
129
|
+
* @throws {MobileServerFailureError} With error code `INVALID_PREFERENCES` if those rules are violated.
|
|
130
|
+
*/
|
|
131
|
+
async updateNotificationPreferences(params) {
|
|
132
|
+
const signedRequest = await this.getSignedRequest("update_preferences", params, { preferences: mapMobileNotificationPreferencesToServer(params.preferences) });
|
|
133
|
+
return this.execute(signedRequest);
|
|
134
|
+
}
|
|
135
|
+
async getSignedRequest(type, params, innerParams) {
|
|
136
|
+
const walletClient = this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
|
|
137
|
+
if (walletClient == null) throw new WalletNotProvidedError();
|
|
138
|
+
const inner = {
|
|
139
|
+
type,
|
|
140
|
+
...innerParams
|
|
141
|
+
};
|
|
142
|
+
return buildSignedMobileRequest({
|
|
143
|
+
...params,
|
|
144
|
+
walletClient,
|
|
145
|
+
inner
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async publicQuery(body) {
|
|
149
|
+
const response = await this.axiosInstance.post(`${this.opts.url}/mobile/public_query`, body);
|
|
150
|
+
this.checkResponseStatus(response);
|
|
151
|
+
this.checkServerStatus(response);
|
|
152
|
+
return response.data;
|
|
153
|
+
}
|
|
154
|
+
async query(body) {
|
|
155
|
+
const response = await this.axiosInstance.post(`${this.opts.url}/mobile/query`, body);
|
|
156
|
+
this.checkResponseStatus(response);
|
|
157
|
+
this.checkServerStatus(response);
|
|
158
|
+
return response.data;
|
|
159
|
+
}
|
|
160
|
+
async execute(body) {
|
|
161
|
+
const response = await this.axiosInstance.post(`${this.opts.url}/mobile/execute`, body);
|
|
162
|
+
this.checkResponseStatus(response);
|
|
163
|
+
this.checkServerStatus(response);
|
|
164
|
+
return response.data;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Validates the HTTP status before interpreting the body. Unlike the engine, the mobile backend returns
|
|
168
|
+
* failure envelopes with non-2xx statuses (e.g. 404 for `PROFILE_NOT_FOUND`), so a non-2xx response with a
|
|
169
|
+
* failure envelope still throws the typed error; anything else is a transport-level error.
|
|
170
|
+
*/
|
|
171
|
+
checkResponseStatus(response) {
|
|
172
|
+
if (response.status >= 200 && response.status < 300) return;
|
|
173
|
+
if (isMobileServerFailureResponse(response.data)) throw new MobileServerFailureError(response.data, response.status);
|
|
174
|
+
throw new Error(`Unexpected response from mobile service: ${response.status} ${response.statusText}. Data: ${JSON.stringify(response.data)}`);
|
|
175
|
+
}
|
|
176
|
+
checkServerStatus(response) {
|
|
177
|
+
const { data } = response;
|
|
178
|
+
if (isMobileServerFailureResponse(data)) throw new MobileServerFailureError(data, response.status);
|
|
179
|
+
if (!isMobileServerSuccessResponse(data)) throw new Error(`Unexpected response from mobile service: missing success envelope. Data: ${JSON.stringify(data)}`);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
//#endregion
|
|
183
|
+
export { MobileClient };
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=MobileClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileClient.js","names":[],"sources":["../src/MobileClient.ts"],"sourcesContent":["import {\n WalletClientWithAccount,\n WalletNotProvidedError,\n} from '@nadohq/shared';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n mapMobileIdentity,\n mapMobileNotificationPreferences,\n mapMobileNotificationPreferencesToServer,\n mapMobilePublicProfile,\n mapMobileRegisteredDevice,\n} from './dataMappers';\nimport {\n buildSignedMobileRequest,\n MobileSignedInner,\n MobileSignedInnerParams,\n MobileSignedRequest,\n} from './signing';\nimport {\n GetMobileNotificationPreferencesParams,\n GetMobilePublicProfileParams,\n GetMobileRegisteredDevicesParams,\n GetMobileSelfIdentityParams,\n GetMobileUsernameAvailabilityParams,\n MobileClaimUsernameParams,\n MobileIdentity,\n MobileNotificationPreferences,\n MobilePublicProfile,\n MobileRegisteredDevice,\n MobileRegisterExpoTokenParams,\n MobileSetPrivateModeParams,\n MobileSignedRequestParams,\n MobileUnregisterExpoTokenParams,\n MobileUpdateNotificationPreferencesParams,\n MobileUpdateUsernameParams,\n MobileUsernameAvailability,\n} from './types/clientTypes';\nimport { MobileServerFailureError } from './types/MobileServerFailureError';\nimport { MobileServerSuccessResponse } from './types/serverBaseTypes';\nimport { MobileServerExecuteResult } from './types/serverExecuteTypes';\nimport {\n MobileServerNotificationPreferencesResponse,\n MobileServerProfileRequest,\n MobileServerProfileResponse,\n MobileServerRegisteredDevicesResponse,\n MobileServerSelfIdentityResponse,\n MobileServerUsernameAvailabilityRequest,\n MobileServerUsernameAvailabilityResponse,\n} from './types/serverQueryTypes';\nimport {\n isMobileServerFailureResponse,\n isMobileServerSuccessResponse,\n} from './utils/serverResponseGuards';\n\n/**\n * Options for constructing a {@link MobileClient}.\n */\nexport interface MobileClientOpts {\n /**\n * Base URL of the mobile service API, e.g. {@link MOBILE_CLIENT_ENDPOINTS}.\n */\n url: string;\n /**\n * Wallet client used to sign requests.\n */\n walletClient?: WalletClientWithAccount;\n /**\n * If provided, this signer is used instead of `walletClient` for all signed requests.\n */\n linkedSignerWalletClient?: WalletClientWithAccount;\n}\n\n/**\n * Client for the Nado mobile service API: username claims, public profile lookups, privacy settings, and\n * push notification device/preference management.\n */\nexport class MobileClient {\n readonly opts: MobileClientOpts;\n readonly axiosInstance: AxiosInstance;\n\n constructor(opts: MobileClientOpts) {\n this.opts = opts;\n this.axiosInstance = axios.create({\n withCredentials: true,\n // We have custom logic to validate response status and create an appropriate error\n validateStatus: () => true,\n });\n }\n\n /**\n * Sets the linked signer for requests\n *\n * @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer\n */\n public setLinkedSigner(\n linkedSignerWalletClient: WalletClientWithAccount | null,\n ) {\n this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? undefined;\n }\n\n /*\n Public queries\n */\n\n /**\n * Checks whether a username derived from the given display name is available to claim.\n */\n async getUsernameAvailability(\n params: GetMobileUsernameAvailabilityParams,\n ): Promise<MobileUsernameAvailability> {\n const body: MobileServerUsernameAvailabilityRequest = {\n type: 'username_availability',\n display_name: params.displayName,\n };\n const data =\n await this.publicQuery<MobileServerUsernameAvailabilityResponse>(body);\n return { username: data.username, available: data.available };\n }\n\n /**\n * Looks up a subaccount's public profile by username.\n *\n * @throws {MobileServerFailureError} With error code `PROFILE_NOT_FOUND` if no identity has claimed the\n * username or it is invalid. Private Mode does not hide the profile itself, only the account's activity.\n */\n async getPublicProfile(\n params: GetMobilePublicProfileParams,\n ): Promise<MobilePublicProfile> {\n const body: MobileServerProfileRequest = {\n type: 'profile',\n username: params.username,\n };\n const data = await this.publicQuery<MobileServerProfileResponse>(body);\n return mapMobilePublicProfile(data.profile);\n }\n\n /*\n Signed queries\n */\n\n /**\n * Fetches the caller's own identity for a subaccount. Returns `null` if the subaccount has not claimed a\n * username yet — this is normal data, not an error.\n */\n async getSelfIdentity(\n params: GetMobileSelfIdentityParams,\n ): Promise<MobileIdentity | null> {\n const signedRequest = await this.getSignedRequest(\n 'self_identity',\n params,\n {},\n );\n const data =\n await this.query<MobileServerSelfIdentityResponse>(signedRequest);\n return data.identity ? mapMobileIdentity(data.identity) : null;\n }\n\n /**\n * Fetches a wallet's push notification preferences. Falls back to the backend's defaults if the wallet has\n * never updated its preferences.\n */\n async getNotificationPreferences(\n params: GetMobileNotificationPreferencesParams,\n ): Promise<MobileNotificationPreferences> {\n const signedRequest = await this.getSignedRequest(\n 'notification_preferences',\n params,\n {},\n );\n const data =\n await this.query<MobileServerNotificationPreferencesResponse>(\n signedRequest,\n );\n return mapMobileNotificationPreferences(data.preferences);\n }\n\n /**\n * Fetches the devices registered for push notifications for a wallet.\n */\n async getRegisteredDevices(\n params: GetMobileRegisteredDevicesParams,\n ): Promise<MobileRegisteredDevice[]> {\n const signedRequest = await this.getSignedRequest(\n 'registered_devices',\n params,\n {},\n );\n const data =\n await this.query<MobileServerRegisteredDevicesResponse>(signedRequest);\n return data.devices.map(mapMobileRegisteredDevice);\n }\n\n /*\n Signed executes\n */\n\n /**\n * Claims a username for a subaccount, derived from the given display name.\n */\n async claimUsername(\n params: MobileClaimUsernameParams,\n ): Promise<MobileServerSuccessResponse> {\n const signedRequest = await this.getSignedRequest(\n 'claim_username',\n params,\n {\n display_name: params.displayName,\n },\n );\n return this.execute(signedRequest);\n }\n\n /**\n * Updates the display name for a subaccount's already-claimed identity.\n */\n async updateUsername(\n params: MobileUpdateUsernameParams,\n ): Promise<MobileServerSuccessResponse> {\n const signedRequest = await this.getSignedRequest(\n 'update_username',\n params,\n { display_name: params.displayName },\n );\n return this.execute(signedRequest);\n }\n\n /**\n * Sets whether a subaccount's profile is private.\n */\n async setPrivateMode(\n params: MobileSetPrivateModeParams,\n ): Promise<MobileServerSuccessResponse> {\n const signedRequest = await this.getSignedRequest(\n 'set_private_mode',\n params,\n { private_mode: params.privateMode },\n );\n return this.execute(signedRequest);\n }\n\n /**\n * Registers an Expo push token for the wallet, transferring active ownership of the token if another\n * wallet had registered it. Idempotent per `(wallet, token)`.\n *\n * @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is not a valid Expo\n * push token, or `INVALID_DEVICE_METADATA` if `locale` (max 35 chars) or `appVersion` (max 64 chars) is\n * too long.\n */\n async registerExpoToken(\n params: MobileRegisterExpoTokenParams,\n ): Promise<MobileServerSuccessResponse> {\n const signedRequest = await this.getSignedRequest(\n 'register_expo_token',\n params,\n {\n expo_token: params.expoToken,\n platform: params.platform,\n locale: params.locale ?? null,\n app_version: params.appVersion ?? null,\n },\n );\n return this.execute(signedRequest);\n }\n\n /**\n * Unregisters an Expo push token for the wallet. Idempotent — unregistering an unknown token succeeds.\n */\n async unregisterExpoToken(\n params: MobileUnregisterExpoTokenParams,\n ): Promise<MobileServerSuccessResponse> {\n const signedRequest = await this.getSignedRequest(\n 'unregister_expo_token',\n params,\n { expo_token: params.expoToken },\n );\n return this.execute(signedRequest);\n }\n\n /**\n * Replaces the wallet's push notification preferences. The backend requires `schemaVersion` of 1, exactly\n * one entry per known category, and empty `scopes` on every entry.\n *\n * @throws {MobileServerFailureError} With error code `INVALID_PREFERENCES` if those rules are violated.\n */\n async updateNotificationPreferences(\n params: MobileUpdateNotificationPreferencesParams,\n ): Promise<MobileServerSuccessResponse> {\n const signedRequest = await this.getSignedRequest(\n 'update_preferences',\n params,\n {\n preferences: mapMobileNotificationPreferencesToServer(\n params.preferences,\n ),\n },\n );\n return this.execute(signedRequest);\n }\n\n /*\n Base Fns\n */\n\n protected async getSignedRequest<T extends MobileSignedInner['type']>(\n type: T,\n params: MobileSignedRequestParams,\n innerParams: MobileSignedInnerParams<T>,\n ): Promise<MobileSignedRequest> {\n // Use the linked signer if provided, otherwise use the default signer provided to the client\n const walletClient =\n this.opts.linkedSignerWalletClient ?? this.opts.walletClient;\n\n if (walletClient == null) {\n throw new WalletNotProvidedError();\n }\n\n const inner = { type, ...innerParams } as MobileSignedInner;\n return buildSignedMobileRequest({ ...params, walletClient, inner });\n }\n\n protected async publicQuery<TResponse extends { status: 'success' }>(\n body: object,\n ): Promise<TResponse> {\n const response = await this.axiosInstance.post<unknown>(\n `${this.opts.url}/mobile/public_query`,\n body,\n );\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus throws on failure responses so the cast to the success response is acceptable here\n return response.data as TResponse;\n }\n\n protected async query<TResponse extends { status: 'success' }>(\n body: MobileSignedRequest,\n ): Promise<TResponse> {\n const response = await this.axiosInstance.post<unknown>(\n `${this.opts.url}/mobile/query`,\n body,\n );\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus throws on failure responses so the cast to the success response is acceptable here\n return response.data as TResponse;\n }\n\n protected async execute(\n body: MobileSignedRequest,\n ): Promise<MobileServerSuccessResponse> {\n const response = await this.axiosInstance.post<MobileServerExecuteResult>(\n `${this.opts.url}/mobile/execute`,\n body,\n );\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus catches the failure result and throws the error, so the cast to the success response is acceptable here\n return response.data as MobileServerSuccessResponse;\n }\n\n /**\n * Validates the HTTP status before interpreting the body. Unlike the engine, the mobile backend returns\n * failure envelopes with non-2xx statuses (e.g. 404 for `PROFILE_NOT_FOUND`), so a non-2xx response with a\n * failure envelope still throws the typed error; anything else is a transport-level error.\n */\n private checkResponseStatus(response: AxiosResponse<unknown>) {\n if (response.status >= 200 && response.status < 300) {\n return;\n }\n if (isMobileServerFailureResponse(response.data)) {\n throw new MobileServerFailureError(response.data, response.status);\n }\n throw new Error(\n `Unexpected response from mobile service: ${response.status} ${response.statusText}. Data: ${JSON.stringify(response.data)}`,\n );\n }\n\n private checkServerStatus(response: AxiosResponse<unknown>) {\n const { data } = response;\n\n if (isMobileServerFailureResponse(data)) {\n throw new MobileServerFailureError(data, response.status);\n }\n if (!isMobileServerSuccessResponse(data)) {\n throw new Error(\n `Unexpected response from mobile service: missing success envelope. Data: ${JSON.stringify(data)}`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AA4EA,IAAa,eAAb,MAA0B;CAIxB,YAAY,MAAwB;EAClC,KAAK,OAAO;EACZ,KAAK,gBAAgB,MAAM,OAAO;GAChC,iBAAiB;GAEjB,sBAAsB;EACxB,CAAC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;EAG/B,OAAO,SAAS;CAClB;CAEA,MAAgB,QACd,MACsC;EACtC,MAAM,WAAW,MAAM,KAAK,cAAc,KACxC,GAAG,KAAK,KAAK,IAAI,kBACjB,IACF;EAEA,KAAK,oBAAoB,QAAQ;EACjC,KAAK,kBAAkB,QAAQ;EAG/B,OAAO,SAAS;CAClB;;;;;;CAOA,oBAA4B,UAAkC;EAC5D,IAAI,SAAS,UAAU,OAAO,SAAS,SAAS,KAC9C;EAEF,IAAI,8BAA8B,SAAS,IAAI,GAC7C,MAAM,IAAI,yBAAyB,SAAS,MAAM,SAAS,MAAM;EAEnE,MAAM,IAAI,MACR,4CAA4C,SAAS,OAAO,GAAG,SAAS,WAAW,UAAU,KAAK,UAAU,SAAS,IAAI,GAC3H;CACF;CAEA,kBAA0B,UAAkC;EAC1D,MAAM,EAAE,SAAS;EAEjB,IAAI,8BAA8B,IAAI,GACpC,MAAM,IAAI,yBAAyB,MAAM,SAAS,MAAM;EAE1D,IAAI,CAAC,8BAA8B,IAAI,GACrC,MAAM,IAAI,MACR,4EAA4E,KAAK,UAAU,IAAI,GACjG;CAEJ;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { t as MobileServerFailureResponse } from "./serverBaseTypes-BicXMrZV.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types/MobileServerFailureError.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when the mobile service API returns a failure envelope, either as a non-2xx HTTP response
|
|
6
|
+
* or a 2xx response with `status: 'failure'`.
|
|
7
|
+
*/
|
|
8
|
+
declare class MobileServerFailureError extends Error {
|
|
9
|
+
readonly responseData: MobileServerFailureResponse;
|
|
10
|
+
/**
|
|
11
|
+
* HTTP status code of the response, e.g. `404` for `PROFILE_NOT_FOUND`. Unlike the engine, the mobile
|
|
12
|
+
* backend maps domain failures onto HTTP statuses.
|
|
13
|
+
*/
|
|
14
|
+
readonly httpStatus: number;
|
|
15
|
+
constructor(responseData: MobileServerFailureResponse,
|
|
16
|
+
/**
|
|
17
|
+
* HTTP status code of the response, e.g. `404` for `PROFILE_NOT_FOUND`. Unlike the engine, the mobile
|
|
18
|
+
* backend maps domain failures onto HTTP statuses.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
httpStatus: number);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { MobileServerFailureError as t };
|
|
25
|
+
//# sourceMappingURL=MobileServerFailureError-Belp_yef.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileServerFailureError-Belp_yef.d.cts","names":[],"sources":["../src/types/src/types/MobileServerFailureError.ts"],"mappings":";;;;;AAMA;;cAAa,wBAAA,SAAiC,KAAA;EAAA,SAEjC,YAAA,EAAc,2BAAA;EAAA;;;;EAAA,SAKd,UAAA;cALA,YAAA,EAAc,2BAAA;EAAA;;;;;EAKd,UAAA;AAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { t as MobileServerFailureResponse } from "./serverBaseTypes-ewbo8l4R.js";
|
|
2
|
+
|
|
3
|
+
//#region src/types/MobileServerFailureError.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when the mobile service API returns a failure envelope, either as a non-2xx HTTP response
|
|
6
|
+
* or a 2xx response with `status: 'failure'`.
|
|
7
|
+
*/
|
|
8
|
+
declare class MobileServerFailureError extends Error {
|
|
9
|
+
readonly responseData: MobileServerFailureResponse;
|
|
10
|
+
/**
|
|
11
|
+
* HTTP status code of the response, e.g. `404` for `PROFILE_NOT_FOUND`. Unlike the engine, the mobile
|
|
12
|
+
* backend maps domain failures onto HTTP statuses.
|
|
13
|
+
*/
|
|
14
|
+
readonly httpStatus: number;
|
|
15
|
+
constructor(responseData: MobileServerFailureResponse,
|
|
16
|
+
/**
|
|
17
|
+
* HTTP status code of the response, e.g. `404` for `PROFILE_NOT_FOUND`. Unlike the engine, the mobile
|
|
18
|
+
* backend maps domain failures onto HTTP statuses.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
httpStatus: number);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { MobileServerFailureError as t };
|
|
25
|
+
//# sourceMappingURL=MobileServerFailureError-DqM0T6CB.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileServerFailureError-DqM0T6CB.d.ts","names":[],"sources":["../src/types/src/types/MobileServerFailureError.ts"],"mappings":";;;;;AAMA;;cAAa,wBAAA,SAAiC,KAAA;EAAA,SAEjC,YAAA,EAAc,2BAAA;EAAA;;;;EAAA,SAKd,UAAA;cALA,YAAA,EAAc,2BAAA;EAAA;;;;;EAKd,UAAA;AAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { i as MobileSignedRequest, n as MobileSignedInner, t as BuildSignedMobileRequestParams } from "./types-uCD4BNZR.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/signing/buildSignedMobileRequest.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Builds and signs a mobile service API request: canonicalizes the inner payload, derives `sender` from the
|
|
6
|
+
* subaccount owner (never the signer), computes the EIP-712 `payloadHash`, signs the `NadoAuthentication`
|
|
7
|
+
* typed data, and returns the flattened signed body ready to POST.
|
|
8
|
+
*/
|
|
9
|
+
declare function buildSignedMobileRequest<T extends MobileSignedInner>(params: BuildSignedMobileRequestParams & {
|
|
10
|
+
inner: T;
|
|
11
|
+
}): Promise<MobileSignedRequest<T>>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { buildSignedMobileRequest as t };
|
|
14
|
+
//# sourceMappingURL=buildSignedMobileRequest-BsbBkU0K.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildSignedMobileRequest-BsbBkU0K.d.cts","names":[],"sources":["../src/signing/src/signing/buildSignedMobileRequest.ts"],"mappings":";;;;;AAgBA;;;iBAAsB,wBAAA,WAAmC,iBAAA,CAAA,CACvD,MAAA,EAAQ,8BAAA;EAAmC,KAAA,EAAO,CAAA;AAAA,IACjD,OAAA,CAAQ,mBAAA,CAAoB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { i as MobileSignedRequest, n as MobileSignedInner, t as BuildSignedMobileRequestParams } from "./types-B76Pn7Sy.js";
|
|
2
|
+
|
|
3
|
+
//#region src/signing/buildSignedMobileRequest.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Builds and signs a mobile service API request: canonicalizes the inner payload, derives `sender` from the
|
|
6
|
+
* subaccount owner (never the signer), computes the EIP-712 `payloadHash`, signs the `NadoAuthentication`
|
|
7
|
+
* typed data, and returns the flattened signed body ready to POST.
|
|
8
|
+
*/
|
|
9
|
+
declare function buildSignedMobileRequest<T extends MobileSignedInner>(params: BuildSignedMobileRequestParams & {
|
|
10
|
+
inner: T;
|
|
11
|
+
}): Promise<MobileSignedRequest<T>>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { buildSignedMobileRequest as t };
|
|
14
|
+
//# sourceMappingURL=buildSignedMobileRequest-CDRsRNHm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildSignedMobileRequest-CDRsRNHm.d.ts","names":[],"sources":["../src/signing/src/signing/buildSignedMobileRequest.ts"],"mappings":";;;;;AAgBA;;;iBAAsB,wBAAA,WAAmC,iBAAA,CAAA,CACvD,MAAA,EAAQ,8BAAA;EAAmC,KAAA,EAAO,CAAA;AAAA,IACjD,OAAA,CAAQ,mBAAA,CAAoB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as MobileSignedInner } from "./types-uCD4BNZR.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/signing/canonicalize.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Rebuilds an inner payload with its keys in the backend's struct declaration order (`type` first, then the
|
|
6
|
+
* remaining fields in the exact order the backend serializes them). msgpack encodes object keys in insertion
|
|
7
|
+
* order and the payload hash must be reproducible regardless of how the caller constructed the object, so
|
|
8
|
+
* every inner payload — and each of its sub-types — is canonicalized here before hashing. This function (with
|
|
9
|
+
* {@link canonicalizeNotificationPreferences} for nested preferences) is the source of truth for that order.
|
|
10
|
+
*/
|
|
11
|
+
declare function canonicalizeMobileInner(inner: MobileSignedInner): MobileSignedInner;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { canonicalizeMobileInner as t };
|
|
14
|
+
//# sourceMappingURL=canonicalize-Dm7sXwPg.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalize-Dm7sXwPg.d.cts","names":[],"sources":["../src/signing/src/signing/canonicalize.ts"],"mappings":";;;;;AAUA;;;;;iBAAgB,uBAAA,CACd,KAAA,EAAO,iBAAA,GACN,iBAAiB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as MobileSignedInner } from "./types-B76Pn7Sy.js";
|
|
2
|
+
|
|
3
|
+
//#region src/signing/canonicalize.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Rebuilds an inner payload with its keys in the backend's struct declaration order (`type` first, then the
|
|
6
|
+
* remaining fields in the exact order the backend serializes them). msgpack encodes object keys in insertion
|
|
7
|
+
* order and the payload hash must be reproducible regardless of how the caller constructed the object, so
|
|
8
|
+
* every inner payload — and each of its sub-types — is canonicalized here before hashing. This function (with
|
|
9
|
+
* {@link canonicalizeNotificationPreferences} for nested preferences) is the source of truth for that order.
|
|
10
|
+
*/
|
|
11
|
+
declare function canonicalizeMobileInner(inner: MobileSignedInner): MobileSignedInner;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { canonicalizeMobileInner as t };
|
|
14
|
+
//# sourceMappingURL=canonicalize-PX6dTIdF.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalize-PX6dTIdF.d.ts","names":[],"sources":["../src/signing/src/signing/canonicalize.ts"],"mappings":";;;;;AAUA;;;;;iBAAgB,uBAAA,CACd,KAAA,EAAO,iBAAA,GACN,iBAAiB"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { n as MobileNotificationPlatform, t as MobileNotificationCategory } from "./serverModelTypes-vEPhHIit.js";
|
|
2
|
+
import { SignatureParams, Subaccount } from "@nadohq/shared";
|
|
3
|
+
import { Hex } from "viem";
|
|
4
|
+
|
|
5
|
+
//#region src/types/clientTypes.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A subaccount's claimed identity on the mobile service API.
|
|
8
|
+
*
|
|
9
|
+
* `username` and `displayName` are two representations of the same claimed name: `displayName` is what the
|
|
10
|
+
* user entered (preserving casing, e.g. `Alice.One`), while `username` is the canonical, lowercased handle
|
|
11
|
+
* derived from it (e.g. `alice.one`). `username` is the unique key used for profile lookups
|
|
12
|
+
* ({@link MobilePublicProfile}); `displayName` is only for presentation.
|
|
13
|
+
*/
|
|
14
|
+
interface MobileIdentity {
|
|
15
|
+
subaccount: Hex;
|
|
16
|
+
/**
|
|
17
|
+
* Canonical, lowercased handle derived from {@link MobileIdentity.displayName}, unique per identity and
|
|
18
|
+
* used for profile lookups.
|
|
19
|
+
*/
|
|
20
|
+
username: string;
|
|
21
|
+
/**
|
|
22
|
+
* User-facing name as claimed, preserving original casing. Validated against `MOBILE_DISPLAY_NAME_PATTERN`.
|
|
23
|
+
*/
|
|
24
|
+
displayName: string;
|
|
25
|
+
privateMode: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A subaccount's public profile, as returned by an unsigned profile lookup.
|
|
29
|
+
*/
|
|
30
|
+
interface MobilePublicProfile {
|
|
31
|
+
subaccount: Hex;
|
|
32
|
+
username: string;
|
|
33
|
+
displayName: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Result of a username availability check.
|
|
37
|
+
*/
|
|
38
|
+
interface MobileUsernameAvailability {
|
|
39
|
+
username: string;
|
|
40
|
+
available: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Scope limiting a notification category preference. Scopes are part of the wire format but rejected by the
|
|
44
|
+
* backend for the MVP — `scopes` must be empty.
|
|
45
|
+
*/
|
|
46
|
+
type MobileNotificationPreferenceScope = {
|
|
47
|
+
type: 'subaccount';
|
|
48
|
+
subaccount: Hex;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'product';
|
|
51
|
+
productId: number;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* A per-category push notification preference.
|
|
55
|
+
*/
|
|
56
|
+
interface MobileNotificationCategoryPreference {
|
|
57
|
+
category: MobileNotificationCategory;
|
|
58
|
+
enabled: boolean;
|
|
59
|
+
scopes: MobileNotificationPreferenceScope[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A wallet's push notification preferences. The backend requires exactly one entry per known category and
|
|
63
|
+
* `schemaVersion` of 1.
|
|
64
|
+
*/
|
|
65
|
+
interface MobileNotificationPreferences {
|
|
66
|
+
/** Only `1` is accepted by the backend for the MVP. */
|
|
67
|
+
schemaVersion: 1;
|
|
68
|
+
categories: MobileNotificationCategoryPreference[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A device registered for push notifications.
|
|
72
|
+
*/
|
|
73
|
+
interface MobileRegisteredDevice {
|
|
74
|
+
/** Push platform the device registered under. */
|
|
75
|
+
platform: MobileNotificationPlatform;
|
|
76
|
+
/** BCP-47 locale tag reported at registration, or `null` if none was provided. */
|
|
77
|
+
locale: string | null;
|
|
78
|
+
/** App version string reported at registration, or `null` if none was provided. */
|
|
79
|
+
appVersion: string | null;
|
|
80
|
+
/**
|
|
81
|
+
* First 8 hex chars of `keccak256` over the bracket-stripped Expo token — a stable, non-reversible
|
|
82
|
+
* identifier for the device's push token. The raw token is never returned by the backend.
|
|
83
|
+
*/
|
|
84
|
+
tokenFingerprintPrefix: string;
|
|
85
|
+
/**
|
|
86
|
+
* Unix timestamp (milliseconds) of the device's last registration refresh.
|
|
87
|
+
*/
|
|
88
|
+
lastSeenAt: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Common params for signed requests that authenticate as a given subaccount.
|
|
92
|
+
*/
|
|
93
|
+
interface MobileSignedRequestParams extends Subaccount, SignatureParams {}
|
|
94
|
+
/**
|
|
95
|
+
* Params for {@link MobileClient.getUsernameAvailability}.
|
|
96
|
+
*/
|
|
97
|
+
interface GetMobileUsernameAvailabilityParams {
|
|
98
|
+
displayName: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Params for {@link MobileClient.getPublicProfile}.
|
|
102
|
+
*/
|
|
103
|
+
interface GetMobilePublicProfileParams {
|
|
104
|
+
username: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Params for {@link MobileClient.getSelfIdentity}.
|
|
108
|
+
*/
|
|
109
|
+
type GetMobileSelfIdentityParams = MobileSignedRequestParams;
|
|
110
|
+
/**
|
|
111
|
+
* Params for {@link MobileClient.claimUsername}.
|
|
112
|
+
*/
|
|
113
|
+
interface MobileClaimUsernameParams extends MobileSignedRequestParams {
|
|
114
|
+
displayName: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Params for {@link MobileClient.updateUsername}.
|
|
118
|
+
*/
|
|
119
|
+
interface MobileUpdateUsernameParams extends MobileSignedRequestParams {
|
|
120
|
+
displayName: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Params for {@link MobileClient.setPrivateMode}.
|
|
124
|
+
*/
|
|
125
|
+
interface MobileSetPrivateModeParams extends MobileSignedRequestParams {
|
|
126
|
+
privateMode: boolean;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Params for {@link MobileClient.registerExpoToken}.
|
|
130
|
+
*/
|
|
131
|
+
interface MobileRegisterExpoTokenParams extends MobileSignedRequestParams {
|
|
132
|
+
/**
|
|
133
|
+
* Expo push token, e.g. `ExponentPushToken[...]`.
|
|
134
|
+
*/
|
|
135
|
+
expoToken: string;
|
|
136
|
+
platform: MobileNotificationPlatform;
|
|
137
|
+
/**
|
|
138
|
+
* BCP-47 locale tag, max 35 chars.
|
|
139
|
+
*/
|
|
140
|
+
locale?: string;
|
|
141
|
+
/**
|
|
142
|
+
* App version string, max 64 chars.
|
|
143
|
+
*/
|
|
144
|
+
appVersion?: string;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Params for {@link MobileClient.unregisterExpoToken}.
|
|
148
|
+
*/
|
|
149
|
+
interface MobileUnregisterExpoTokenParams extends MobileSignedRequestParams {
|
|
150
|
+
expoToken: string;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Params for {@link MobileClient.updateNotificationPreferences}.
|
|
154
|
+
*/
|
|
155
|
+
interface MobileUpdateNotificationPreferencesParams extends MobileSignedRequestParams {
|
|
156
|
+
preferences: MobileNotificationPreferences;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Params for {@link MobileClient.getNotificationPreferences}.
|
|
160
|
+
*/
|
|
161
|
+
type GetMobileNotificationPreferencesParams = MobileSignedRequestParams;
|
|
162
|
+
/**
|
|
163
|
+
* Params for {@link MobileClient.getRegisteredDevices}.
|
|
164
|
+
*/
|
|
165
|
+
type GetMobileRegisteredDevicesParams = MobileSignedRequestParams;
|
|
166
|
+
//#endregion
|
|
167
|
+
export { MobileUpdateNotificationPreferencesParams as _, GetMobileUsernameAvailabilityParams as a, MobileNotificationCategoryPreference as c, MobilePublicProfile as d, MobileRegisterExpoTokenParams as f, MobileUnregisterExpoTokenParams as g, MobileSignedRequestParams as h, GetMobileSelfIdentityParams as i, MobileNotificationPreferenceScope as l, MobileSetPrivateModeParams as m, GetMobilePublicProfileParams as n, MobileClaimUsernameParams as o, MobileRegisteredDevice as p, GetMobileRegisteredDevicesParams as r, MobileIdentity as s, GetMobileNotificationPreferencesParams as t, MobileNotificationPreferences as u, MobileUpdateUsernameParams as v, MobileUsernameAvailability as y };
|
|
168
|
+
//# sourceMappingURL=clientTypes-DWW2N66c.d.ts.map
|
|
@@ -0,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