@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.
Files changed (204) hide show
  1. package/README.md +73 -0
  2. package/dist/MobileClient-9JSAzblH.cjs +218 -0
  3. package/dist/MobileClient-9JSAzblH.cjs.map +1 -0
  4. package/dist/MobileClient.cjs +4 -0
  5. package/dist/MobileClient.d.cts +114 -0
  6. package/dist/MobileClient.d.cts.map +1 -0
  7. package/dist/MobileClient.d.ts +114 -0
  8. package/dist/MobileClient.d.ts.map +1 -0
  9. package/dist/MobileClient.js +185 -0
  10. package/dist/MobileClient.js.map +1 -0
  11. package/dist/MobileServerFailureError-Belp_yef.d.cts +25 -0
  12. package/dist/MobileServerFailureError-Belp_yef.d.cts.map +1 -0
  13. package/dist/MobileServerFailureError-DqM0T6CB.d.ts +25 -0
  14. package/dist/MobileServerFailureError-DqM0T6CB.d.ts.map +1 -0
  15. package/dist/buildSignedMobileRequest-BsbBkU0K.d.cts +14 -0
  16. package/dist/buildSignedMobileRequest-BsbBkU0K.d.cts.map +1 -0
  17. package/dist/buildSignedMobileRequest-CDRsRNHm.d.ts +14 -0
  18. package/dist/buildSignedMobileRequest-CDRsRNHm.d.ts.map +1 -0
  19. package/dist/canonicalize-Dm7sXwPg.d.cts +14 -0
  20. package/dist/canonicalize-Dm7sXwPg.d.cts.map +1 -0
  21. package/dist/canonicalize-PX6dTIdF.d.ts +14 -0
  22. package/dist/canonicalize-PX6dTIdF.d.ts.map +1 -0
  23. package/dist/clientTypes-DWW2N66c.d.ts +168 -0
  24. package/dist/clientTypes-DWW2N66c.d.ts.map +1 -0
  25. package/dist/clientTypes-Et0PUa2d.d.cts +168 -0
  26. package/dist/clientTypes-Et0PUa2d.d.cts.map +1 -0
  27. package/dist/dataMappers.cjs +89 -0
  28. package/dist/dataMappers.cjs.map +1 -0
  29. package/dist/dataMappers.d.cts +27 -0
  30. package/dist/dataMappers.d.cts.map +1 -0
  31. package/dist/dataMappers.d.ts +27 -0
  32. package/dist/dataMappers.d.ts.map +1 -0
  33. package/dist/dataMappers.js +84 -0
  34. package/dist/dataMappers.js.map +1 -0
  35. package/dist/eip712MethodByType-DJgXal9r.d.ts +10 -0
  36. package/dist/eip712MethodByType-DJgXal9r.d.ts.map +1 -0
  37. package/dist/eip712MethodByType-DLh9MRsD.d.cts +10 -0
  38. package/dist/eip712MethodByType-DLh9MRsD.d.cts.map +1 -0
  39. package/dist/endpoints.cjs +14 -0
  40. package/dist/endpoints.cjs.map +1 -0
  41. package/dist/endpoints.d.cts +10 -0
  42. package/dist/endpoints.d.cts.map +1 -0
  43. package/dist/endpoints.d.ts +10 -0
  44. package/dist/endpoints.d.ts.map +1 -0
  45. package/dist/endpoints.js +13 -0
  46. package/dist/endpoints.js.map +1 -0
  47. package/dist/index.cjs +27 -0
  48. package/dist/index.d.cts +18 -0
  49. package/dist/index.d.ts +18 -0
  50. package/dist/index.js +15 -0
  51. package/dist/mobileErrorCodes-D8KzJXbU.d.cts +29 -0
  52. package/dist/mobileErrorCodes-D8KzJXbU.d.cts.map +1 -0
  53. package/dist/mobileErrorCodes-DM09jnNe.d.ts +29 -0
  54. package/dist/mobileErrorCodes-DM09jnNe.d.ts.map +1 -0
  55. package/dist/nonce-DCOrXXkQ.d.ts +15 -0
  56. package/dist/nonce-DCOrXXkQ.d.ts.map +1 -0
  57. package/dist/nonce-zGyisRlj.d.cts +15 -0
  58. package/dist/nonce-zGyisRlj.d.cts.map +1 -0
  59. package/dist/patterns-B9J2ldpx.d.cts +8 -0
  60. package/dist/patterns-B9J2ldpx.d.cts.map +1 -0
  61. package/dist/patterns-BbxH3_VA.d.ts +8 -0
  62. package/dist/patterns-BbxH3_VA.d.ts.map +1 -0
  63. package/dist/payloadHash-Bmhzs78N.d.ts +13 -0
  64. package/dist/payloadHash-Bmhzs78N.d.ts.map +1 -0
  65. package/dist/payloadHash-nj8WuLUP.d.cts +13 -0
  66. package/dist/payloadHash-nj8WuLUP.d.cts.map +1 -0
  67. package/dist/serverBaseTypes-BicXMrZV.d.cts +43 -0
  68. package/dist/serverBaseTypes-BicXMrZV.d.cts.map +1 -0
  69. package/dist/serverBaseTypes-ewbo8l4R.d.ts +43 -0
  70. package/dist/serverBaseTypes-ewbo8l4R.d.ts.map +1 -0
  71. package/dist/serverExecuteTypes-CXnMjKnt.d.ts +11 -0
  72. package/dist/serverExecuteTypes-CXnMjKnt.d.ts.map +1 -0
  73. package/dist/serverExecuteTypes-DKYK1V7C.d.cts +11 -0
  74. package/dist/serverExecuteTypes-DKYK1V7C.d.cts.map +1 -0
  75. package/dist/serverModelTypes-CQgfqgW3.d.cts +69 -0
  76. package/dist/serverModelTypes-CQgfqgW3.d.cts.map +1 -0
  77. package/dist/serverModelTypes-vEPhHIit.d.ts +69 -0
  78. package/dist/serverModelTypes-vEPhHIit.d.ts.map +1 -0
  79. package/dist/serverQueryTypes-BI-2TD8F.d.ts +53 -0
  80. package/dist/serverQueryTypes-BI-2TD8F.d.ts.map +1 -0
  81. package/dist/serverQueryTypes-D7Yharse.d.cts +53 -0
  82. package/dist/serverQueryTypes-D7Yharse.d.cts.map +1 -0
  83. package/dist/serverResponseGuards-C_vZIgGl.d.ts +16 -0
  84. package/dist/serverResponseGuards-C_vZIgGl.d.ts.map +1 -0
  85. package/dist/serverResponseGuards-DjCNL3CR.d.cts +16 -0
  86. package/dist/serverResponseGuards-DjCNL3CR.d.cts.map +1 -0
  87. package/dist/signing/buildSignedMobileRequest.cjs +47 -0
  88. package/dist/signing/buildSignedMobileRequest.cjs.map +1 -0
  89. package/dist/signing/buildSignedMobileRequest.d.cts +2 -0
  90. package/dist/signing/buildSignedMobileRequest.d.ts +2 -0
  91. package/dist/signing/buildSignedMobileRequest.js +45 -0
  92. package/dist/signing/buildSignedMobileRequest.js.map +1 -0
  93. package/dist/signing/canonicalize.cjs +68 -0
  94. package/dist/signing/canonicalize.cjs.map +1 -0
  95. package/dist/signing/canonicalize.d.cts +2 -0
  96. package/dist/signing/canonicalize.d.ts +2 -0
  97. package/dist/signing/canonicalize.js +67 -0
  98. package/dist/signing/canonicalize.js.map +1 -0
  99. package/dist/signing/eip712MethodByType.cjs +20 -0
  100. package/dist/signing/eip712MethodByType.cjs.map +1 -0
  101. package/dist/signing/eip712MethodByType.d.cts +2 -0
  102. package/dist/signing/eip712MethodByType.d.ts +2 -0
  103. package/dist/signing/eip712MethodByType.js +19 -0
  104. package/dist/signing/eip712MethodByType.js.map +1 -0
  105. package/dist/signing/index.cjs +11 -0
  106. package/dist/signing/index.d.cts +7 -0
  107. package/dist/signing/index.d.ts +7 -0
  108. package/dist/signing/index.js +6 -0
  109. package/dist/signing/nonce.cjs +19 -0
  110. package/dist/signing/nonce.cjs.map +1 -0
  111. package/dist/signing/nonce.d.cts +2 -0
  112. package/dist/signing/nonce.d.ts +2 -0
  113. package/dist/signing/nonce.js +18 -0
  114. package/dist/signing/nonce.js.map +1 -0
  115. package/dist/signing/payloadHash.cjs +17 -0
  116. package/dist/signing/payloadHash.cjs.map +1 -0
  117. package/dist/signing/payloadHash.d.cts +2 -0
  118. package/dist/signing/payloadHash.d.ts +2 -0
  119. package/dist/signing/payloadHash.js +15 -0
  120. package/dist/signing/payloadHash.js.map +1 -0
  121. package/dist/signing/types.cjs +0 -0
  122. package/dist/signing/types.d.cts +2 -0
  123. package/dist/signing/types.d.ts +2 -0
  124. package/dist/signing/types.js +1 -0
  125. package/dist/types/MobileServerFailureError.cjs +17 -0
  126. package/dist/types/MobileServerFailureError.cjs.map +1 -0
  127. package/dist/types/MobileServerFailureError.d.cts +2 -0
  128. package/dist/types/MobileServerFailureError.d.ts +2 -0
  129. package/dist/types/MobileServerFailureError.js +16 -0
  130. package/dist/types/MobileServerFailureError.js.map +1 -0
  131. package/dist/types/clientTypes.cjs +0 -0
  132. package/dist/types/clientTypes.d.cts +2 -0
  133. package/dist/types/clientTypes.d.ts +2 -0
  134. package/dist/types/clientTypes.js +1 -0
  135. package/dist/types/index.cjs +5 -0
  136. package/dist/types/index.d.cts +8 -0
  137. package/dist/types/index.d.ts +8 -0
  138. package/dist/types/index.js +3 -0
  139. package/dist/types/mobileErrorCodes.cjs +27 -0
  140. package/dist/types/mobileErrorCodes.cjs.map +1 -0
  141. package/dist/types/mobileErrorCodes.d.cts +2 -0
  142. package/dist/types/mobileErrorCodes.d.ts +2 -0
  143. package/dist/types/mobileErrorCodes.js +26 -0
  144. package/dist/types/mobileErrorCodes.js.map +1 -0
  145. package/dist/types/serverBaseTypes.cjs +0 -0
  146. package/dist/types/serverBaseTypes.d.cts +2 -0
  147. package/dist/types/serverBaseTypes.d.ts +2 -0
  148. package/dist/types/serverBaseTypes.js +1 -0
  149. package/dist/types/serverExecuteTypes.cjs +0 -0
  150. package/dist/types/serverExecuteTypes.d.cts +2 -0
  151. package/dist/types/serverExecuteTypes.d.ts +2 -0
  152. package/dist/types/serverExecuteTypes.js +1 -0
  153. package/dist/types/serverModelTypes.cjs +0 -0
  154. package/dist/types/serverModelTypes.d.cts +2 -0
  155. package/dist/types/serverModelTypes.d.ts +2 -0
  156. package/dist/types/serverModelTypes.js +1 -0
  157. package/dist/types/serverQueryTypes.cjs +0 -0
  158. package/dist/types/serverQueryTypes.d.cts +2 -0
  159. package/dist/types/serverQueryTypes.d.ts +2 -0
  160. package/dist/types/serverQueryTypes.js +1 -0
  161. package/dist/types-B76Pn7Sy.d.ts +73 -0
  162. package/dist/types-B76Pn7Sy.d.ts.map +1 -0
  163. package/dist/types-uCD4BNZR.d.cts +73 -0
  164. package/dist/types-uCD4BNZR.d.cts.map +1 -0
  165. package/dist/utils/index.cjs +6 -0
  166. package/dist/utils/index.d.cts +3 -0
  167. package/dist/utils/index.d.ts +3 -0
  168. package/dist/utils/index.js +3 -0
  169. package/dist/utils/patterns.cjs +10 -0
  170. package/dist/utils/patterns.cjs.map +1 -0
  171. package/dist/utils/patterns.d.cts +2 -0
  172. package/dist/utils/patterns.d.ts +2 -0
  173. package/dist/utils/patterns.js +9 -0
  174. package/dist/utils/patterns.js.map +1 -0
  175. package/dist/utils/serverResponseGuards.cjs +19 -0
  176. package/dist/utils/serverResponseGuards.cjs.map +1 -0
  177. package/dist/utils/serverResponseGuards.d.cts +2 -0
  178. package/dist/utils/serverResponseGuards.d.ts +2 -0
  179. package/dist/utils/serverResponseGuards.js +17 -0
  180. package/dist/utils/serverResponseGuards.js.map +1 -0
  181. package/package.json +58 -0
  182. package/src/MobileClient.ts +395 -0
  183. package/src/dataMappers.ts +106 -0
  184. package/src/endpoints.ts +10 -0
  185. package/src/index.ts +5 -0
  186. package/src/signing/buildSignedMobileRequest.ts +58 -0
  187. package/src/signing/canonicalize.ts +69 -0
  188. package/src/signing/eip712MethodByType.ts +19 -0
  189. package/src/signing/index.ts +6 -0
  190. package/src/signing/nonce.ts +16 -0
  191. package/src/signing/payloadHash.ts +12 -0
  192. package/src/signing/signing.test.ts +224 -0
  193. package/src/signing/types.ts +71 -0
  194. package/src/types/MobileServerFailureError.ts +18 -0
  195. package/src/types/clientTypes.ts +182 -0
  196. package/src/types/index.ts +7 -0
  197. package/src/types/mobileErrorCodes.ts +27 -0
  198. package/src/types/serverBaseTypes.ts +43 -0
  199. package/src/types/serverExecuteTypes.ts +12 -0
  200. package/src/types/serverModelTypes.ts +74 -0
  201. package/src/types/serverQueryTypes.ts +74 -0
  202. package/src/utils/index.ts +2 -0
  203. package/src/utils/patterns.ts +4 -0
  204. package/src/utils/serverResponseGuards.ts +27 -0
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # `@nadohq/mobile-client`
2
+
3
+ HTTP client for the Nado mobile service API. Manages username claims, public profile lookups, privacy settings, and
4
+ push notification devices/preferences, using EIP-712 + msgpack signed authentication.
5
+
6
+ [Full SDK Documentation](https://nadohq.github.io/nado-typescript-sdk/index.html)
7
+
8
+ ## Usage
9
+
10
+ ```ts
11
+ import { MobileClient, MOBILE_CLIENT_ENDPOINTS } from '@nadohq/mobile-client';
12
+ import { createWalletClient, http } from 'viem';
13
+ import { privateKeyToAccount } from 'viem/accounts';
14
+ import { ink } from 'viem/chains';
15
+
16
+ const walletClient = createWalletClient({
17
+ account: privateKeyToAccount('0x...'),
18
+ chain: ink,
19
+ transport: http(),
20
+ });
21
+
22
+ const mobile = new MobileClient({
23
+ url: MOBILE_CLIENT_ENDPOINTS.inkMainnet,
24
+ walletClient,
25
+ });
26
+
27
+ // Unsigned public lookups
28
+ const availability = await mobile.getUsernameAvailability({ displayName: 'Alice.One' });
29
+ const profile = await mobile.getPublicProfile({ username: 'alice.one' });
30
+
31
+ // Signed operations
32
+ const identity = await mobile.getSelfIdentity({
33
+ subaccountOwner: walletClient.account.address,
34
+ subaccountName: 'default',
35
+ chainId: ink.id,
36
+ verifyingAddr: '0x...',
37
+ });
38
+
39
+ await mobile.claimUsername({
40
+ subaccountOwner: walletClient.account.address,
41
+ subaccountName: 'default',
42
+ chainId: ink.id,
43
+ verifyingAddr: '0x...',
44
+ displayName: 'Alice.One',
45
+ });
46
+ ```
47
+
48
+ ## API Surface
49
+
50
+ ### Public Queries
51
+
52
+ `getUsernameAvailability`, `getPublicProfile`.
53
+
54
+ ### Signed Queries
55
+
56
+ `getSelfIdentity`, `getNotificationPreferences`, `getRegisteredDevices`.
57
+
58
+ ### Signed Executes
59
+
60
+ `claimUsername`, `updateUsername`, `setPrivateMode`, `registerExpoToken`, `unregisterExpoToken`,
61
+ `updateNotificationPreferences`.
62
+
63
+ ### Linked Signers
64
+
65
+ The mobile client supports linked signers for delegated transaction signing:
66
+
67
+ ```ts
68
+ mobile.setLinkedSigner(linkedSignerWalletClient);
69
+ ```
70
+
71
+ ## License
72
+
73
+ ISC
@@ -0,0 +1,218 @@
1
+ //#region \0rolldown/runtime.js
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 __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ const require_dataMappers = require("./dataMappers.cjs");
24
+ const require_signing_buildSignedMobileRequest = require("./signing/buildSignedMobileRequest.cjs");
25
+ const require_types_MobileServerFailureError = require("./types/MobileServerFailureError.cjs");
26
+ const require_utils_serverResponseGuards = require("./utils/serverResponseGuards.cjs");
27
+ let _nadohq_shared = require("@nadohq/shared");
28
+ let axios = require("axios");
29
+ axios = __toESM(axios, 1);
30
+ //#region src/MobileClient.ts
31
+ /**
32
+ * Client for the Nado mobile service API: username claims, public profile lookups, privacy settings, and
33
+ * push notification device/preference management.
34
+ */
35
+ var MobileClient = class {
36
+ constructor(opts) {
37
+ this.opts = opts;
38
+ this.axiosInstance = axios.default.create({
39
+ withCredentials: true,
40
+ validateStatus: () => true
41
+ });
42
+ }
43
+ /**
44
+ * Sets the linked signer for requests
45
+ *
46
+ * @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer
47
+ */
48
+ setLinkedSigner(linkedSignerWalletClient) {
49
+ this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? void 0;
50
+ }
51
+ /**
52
+ * Checks whether a username derived from the given display name is available to claim.
53
+ */
54
+ async getUsernameAvailability(params) {
55
+ const body = {
56
+ type: "username_availability",
57
+ display_name: params.displayName
58
+ };
59
+ const data = await this.publicQuery(body);
60
+ return {
61
+ username: data.username,
62
+ available: data.available
63
+ };
64
+ }
65
+ /**
66
+ * Looks up a subaccount's public profile by username.
67
+ *
68
+ * @throws {MobileServerFailureError} With error code `PROFILE_NOT_FOUND` if no identity has claimed the
69
+ * username or it is invalid. Private Mode does not hide the profile itself, only the account's activity.
70
+ */
71
+ async getPublicProfile(params) {
72
+ const body = {
73
+ type: "profile",
74
+ username: params.username
75
+ };
76
+ return require_dataMappers.mapMobilePublicProfile((await this.publicQuery(body)).profile);
77
+ }
78
+ /**
79
+ * Fetches the caller's own identity for a subaccount. Returns `null` if the subaccount has not claimed a
80
+ * username yet — this is normal data, not an error.
81
+ */
82
+ async getSelfIdentity(params) {
83
+ const signedRequest = await this.getSignedRequest("self_identity", params, {});
84
+ const data = await this.query(signedRequest);
85
+ return data.identity ? require_dataMappers.mapMobileIdentity(data.identity) : null;
86
+ }
87
+ /**
88
+ * Fetches a wallet's push notification preferences. Falls back to the backend's defaults if the wallet has
89
+ * never updated its preferences.
90
+ */
91
+ async getNotificationPreferences(params) {
92
+ const signedRequest = await this.getSignedRequest("notification_preferences", params, {});
93
+ return require_dataMappers.mapMobileNotificationPreferences((await this.query(signedRequest)).preferences);
94
+ }
95
+ /**
96
+ * Fetches the devices registered for push notifications for a wallet.
97
+ */
98
+ async getRegisteredDevices(params) {
99
+ const signedRequest = await this.getSignedRequest("registered_devices", params, {});
100
+ return (await this.query(signedRequest)).devices.map(require_dataMappers.mapMobileRegisteredDevice);
101
+ }
102
+ /**
103
+ * Claims a username for a subaccount, derived from the given display name.
104
+ */
105
+ async claimUsername(params) {
106
+ const signedRequest = await this.getSignedRequest("claim_username", params, { display_name: params.displayName });
107
+ return this.execute(signedRequest);
108
+ }
109
+ /**
110
+ * Updates the display name for a subaccount's already-claimed identity.
111
+ */
112
+ async updateUsername(params) {
113
+ const signedRequest = await this.getSignedRequest("update_username", params, { display_name: params.displayName });
114
+ return this.execute(signedRequest);
115
+ }
116
+ /**
117
+ * Sets whether a subaccount's profile is private.
118
+ */
119
+ async setPrivateMode(params) {
120
+ const signedRequest = await this.getSignedRequest("set_private_mode", params, { private_mode: params.privateMode });
121
+ return this.execute(signedRequest);
122
+ }
123
+ /**
124
+ * Registers an Expo push token for the wallet, transferring active ownership of the token if another
125
+ * wallet had registered it. Idempotent per `(wallet, token)`.
126
+ *
127
+ * @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is not a valid Expo
128
+ * push token, or `INVALID_DEVICE_METADATA` if `locale` (max 35 chars) or `appVersion` (max 64 chars) is
129
+ * too long.
130
+ */
131
+ async registerExpoToken(params) {
132
+ const signedRequest = await this.getSignedRequest("register_expo_token", params, {
133
+ expo_token: params.expoToken,
134
+ platform: params.platform,
135
+ locale: params.locale ?? null,
136
+ app_version: params.appVersion ?? null
137
+ });
138
+ return this.execute(signedRequest);
139
+ }
140
+ /**
141
+ * Unregisters an Expo push token for the wallet. Idempotent — unregistering an unknown token succeeds.
142
+ */
143
+ async unregisterExpoToken(params) {
144
+ const signedRequest = await this.getSignedRequest("unregister_expo_token", params, { expo_token: params.expoToken });
145
+ return this.execute(signedRequest);
146
+ }
147
+ /**
148
+ * Replaces the wallet's push notification preferences. The backend requires `schemaVersion` of 1, exactly
149
+ * one entry per known category, and empty `scopes` on every entry.
150
+ *
151
+ * @throws {MobileServerFailureError} With error code `INVALID_PREFERENCES` if those rules are violated.
152
+ */
153
+ async updateNotificationPreferences(params) {
154
+ const signedRequest = await this.getSignedRequest("update_preferences", params, { preferences: require_dataMappers.mapMobileNotificationPreferencesToServer(params.preferences) });
155
+ return this.execute(signedRequest);
156
+ }
157
+ async getSignedRequest(type, params, innerParams) {
158
+ const walletClient = this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
159
+ if (walletClient == null) throw new _nadohq_shared.WalletNotProvidedError();
160
+ const inner = {
161
+ type,
162
+ ...innerParams
163
+ };
164
+ return require_signing_buildSignedMobileRequest.buildSignedMobileRequest({
165
+ ...params,
166
+ walletClient,
167
+ inner
168
+ });
169
+ }
170
+ async publicQuery(body) {
171
+ const response = await this.axiosInstance.post(`${this.opts.url}/mobile/public_query`, body);
172
+ this.checkResponseStatus(response);
173
+ this.checkServerStatus(response);
174
+ return response.data;
175
+ }
176
+ async query(body) {
177
+ const response = await this.axiosInstance.post(`${this.opts.url}/mobile/query`, body);
178
+ this.checkResponseStatus(response);
179
+ this.checkServerStatus(response);
180
+ return response.data;
181
+ }
182
+ async execute(body) {
183
+ const response = await this.axiosInstance.post(`${this.opts.url}/mobile/execute`, body);
184
+ this.checkResponseStatus(response);
185
+ this.checkServerStatus(response);
186
+ return response.data;
187
+ }
188
+ /**
189
+ * Validates the HTTP status before interpreting the body. Unlike the engine, the mobile backend returns
190
+ * failure envelopes with non-2xx statuses (e.g. 404 for `PROFILE_NOT_FOUND`), so a non-2xx response with a
191
+ * failure envelope still throws the typed error; anything else is a transport-level error.
192
+ */
193
+ checkResponseStatus(response) {
194
+ if (response.status >= 200 && response.status < 300) return;
195
+ if (require_utils_serverResponseGuards.isMobileServerFailureResponse(response.data)) throw new require_types_MobileServerFailureError.MobileServerFailureError(response.data, response.status);
196
+ throw new Error(`Unexpected response from mobile service: ${response.status} ${response.statusText}. Data: ${JSON.stringify(response.data)}`);
197
+ }
198
+ checkServerStatus(response) {
199
+ const { data } = response;
200
+ if (require_utils_serverResponseGuards.isMobileServerFailureResponse(data)) throw new require_types_MobileServerFailureError.MobileServerFailureError(data, response.status);
201
+ if (!require_utils_serverResponseGuards.isMobileServerSuccessResponse(data)) throw new Error(`Unexpected response from mobile service: missing success envelope. Data: ${JSON.stringify(data)}`);
202
+ }
203
+ };
204
+ //#endregion
205
+ Object.defineProperty(exports, "MobileClient", {
206
+ enumerable: true,
207
+ get: function() {
208
+ return MobileClient;
209
+ }
210
+ });
211
+ Object.defineProperty(exports, "__toESM", {
212
+ enumerable: true,
213
+ get: function() {
214
+ return __toESM;
215
+ }
216
+ });
217
+
218
+ //# sourceMappingURL=MobileClient-9JSAzblH.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MobileClient-9JSAzblH.cjs","names":["mapMobilePublicProfile","mapMobileIdentity","mapMobileNotificationPreferences","mapMobileRegisteredDevice","mapMobileNotificationPreferencesToServer","WalletNotProvidedError","buildSignedMobileRequest","isMobileServerFailureResponse","MobileServerFailureError","isMobileServerSuccessResponse"],"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,MAAA,QAAM,OAAO;GAChC,iBAAiB;GAEjB,sBAAsB;EACxB,CAAC;CACH;;;;;;CAOA,gBACE,0BACA;EACA,KAAK,KAAK,2BAA2B,4BAA4B,KAAA;CACnE;;;;CASA,MAAM,wBACJ,QACqC;EACrC,MAAM,OAAgD;GACpD,MAAM;GACN,cAAc,OAAO;EACvB;EACA,MAAM,OACJ,MAAM,KAAK,YAAsD,IAAI;EACvE,OAAO;GAAE,UAAU,KAAK;GAAU,WAAW,KAAK;EAAU;CAC9D;;;;;;;CAQA,MAAM,iBACJ,QAC8B;EAC9B,MAAM,OAAmC;GACvC,MAAM;GACN,UAAU,OAAO;EACnB;EAEA,OAAOA,oBAAAA,wBAAuB,MADX,KAAK,YAAyC,IAAI,GAClC,OAAO;CAC5C;;;;;CAUA,MAAM,gBACJ,QACgC;EAChC,MAAM,gBAAgB,MAAM,KAAK,iBAC/B,iBACA,QACA,CAAC,CACH;EACA,MAAM,OACJ,MAAM,KAAK,MAAwC,aAAa;EAClE,OAAO,KAAK,WAAWC,oBAAAA,kBAAkB,KAAK,QAAQ,IAAI;CAC5D;;;;;CAMA,MAAM,2BACJ,QACwC;EACxC,MAAM,gBAAgB,MAAM,KAAK,iBAC/B,4BACA,QACA,CAAC,CACH;EAKA,OAAOC,oBAAAA,kCAAiC,MAHhC,KAAK,MACT,aACF,GAC2C,WAAW;CAC1D;;;;CAKA,MAAM,qBACJ,QACmC;EACnC,MAAM,gBAAgB,MAAM,KAAK,iBAC/B,sBACA,QACA,CAAC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const require_MobileClient = require("./MobileClient-9JSAzblH.cjs");
3
+ require("./signing/index.cjs");
4
+ exports.MobileClient = require_MobileClient.MobileClient;
@@ -0,0 +1,114 @@
1
+ import { _ as MobileUpdateNotificationPreferencesParams, a as GetMobileUsernameAvailabilityParams, d as MobilePublicProfile, f as MobileRegisterExpoTokenParams, g as MobileUnregisterExpoTokenParams, h as MobileSignedRequestParams, i as GetMobileSelfIdentityParams, m as MobileSetPrivateModeParams, n as GetMobilePublicProfileParams, o as MobileClaimUsernameParams, p as MobileRegisteredDevice, r as GetMobileRegisteredDevicesParams, s as MobileIdentity, t as GetMobileNotificationPreferencesParams, u as MobileNotificationPreferences, v as MobileUpdateUsernameParams, y as MobileUsernameAvailability } from "./clientTypes-Et0PUa2d.cjs";
2
+ import { i as MobileSignedRequest, n as MobileSignedInner, r as MobileSignedInnerParams } from "./types-uCD4BNZR.cjs";
3
+ import { a as MobileServerSuccessResponse } from "./serverBaseTypes-BicXMrZV.cjs";
4
+ import { WalletClientWithAccount } from "@nadohq/shared";
5
+ import { AxiosInstance } from "axios";
6
+
7
+ //#region src/MobileClient.d.ts
8
+ /**
9
+ * Options for constructing a {@link MobileClient}.
10
+ */
11
+ interface MobileClientOpts {
12
+ /**
13
+ * Base URL of the mobile service API, e.g. {@link MOBILE_CLIENT_ENDPOINTS}.
14
+ */
15
+ url: string;
16
+ /**
17
+ * Wallet client used to sign requests.
18
+ */
19
+ walletClient?: WalletClientWithAccount;
20
+ /**
21
+ * If provided, this signer is used instead of `walletClient` for all signed requests.
22
+ */
23
+ linkedSignerWalletClient?: WalletClientWithAccount;
24
+ }
25
+ /**
26
+ * Client for the Nado mobile service API: username claims, public profile lookups, privacy settings, and
27
+ * push notification device/preference management.
28
+ */
29
+ declare class MobileClient {
30
+ readonly opts: MobileClientOpts;
31
+ readonly axiosInstance: AxiosInstance;
32
+ constructor(opts: MobileClientOpts);
33
+ /**
34
+ * Sets the linked signer for requests
35
+ *
36
+ * @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer
37
+ */
38
+ setLinkedSigner(linkedSignerWalletClient: WalletClientWithAccount | null): void;
39
+ /**
40
+ * Checks whether a username derived from the given display name is available to claim.
41
+ */
42
+ getUsernameAvailability(params: GetMobileUsernameAvailabilityParams): Promise<MobileUsernameAvailability>;
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
+ getPublicProfile(params: GetMobilePublicProfileParams): Promise<MobilePublicProfile>;
50
+ /**
51
+ * Fetches the caller's own identity for a subaccount. Returns `null` if the subaccount has not claimed a
52
+ * username yet — this is normal data, not an error.
53
+ */
54
+ getSelfIdentity(params: GetMobileSelfIdentityParams): Promise<MobileIdentity | null>;
55
+ /**
56
+ * Fetches a wallet's push notification preferences. Falls back to the backend's defaults if the wallet has
57
+ * never updated its preferences.
58
+ */
59
+ getNotificationPreferences(params: GetMobileNotificationPreferencesParams): Promise<MobileNotificationPreferences>;
60
+ /**
61
+ * Fetches the devices registered for push notifications for a wallet.
62
+ */
63
+ getRegisteredDevices(params: GetMobileRegisteredDevicesParams): Promise<MobileRegisteredDevice[]>;
64
+ /**
65
+ * Claims a username for a subaccount, derived from the given display name.
66
+ */
67
+ claimUsername(params: MobileClaimUsernameParams): Promise<MobileServerSuccessResponse>;
68
+ /**
69
+ * Updates the display name for a subaccount's already-claimed identity.
70
+ */
71
+ updateUsername(params: MobileUpdateUsernameParams): Promise<MobileServerSuccessResponse>;
72
+ /**
73
+ * Sets whether a subaccount's profile is private.
74
+ */
75
+ setPrivateMode(params: MobileSetPrivateModeParams): Promise<MobileServerSuccessResponse>;
76
+ /**
77
+ * Registers an Expo push token for the wallet, transferring active ownership of the token if another
78
+ * wallet had registered it. Idempotent per `(wallet, token)`.
79
+ *
80
+ * @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is not a valid Expo
81
+ * push token, or `INVALID_DEVICE_METADATA` if `locale` (max 35 chars) or `appVersion` (max 64 chars) is
82
+ * too long.
83
+ */
84
+ registerExpoToken(params: MobileRegisterExpoTokenParams): Promise<MobileServerSuccessResponse>;
85
+ /**
86
+ * Unregisters an Expo push token for the wallet. Idempotent — unregistering an unknown token succeeds.
87
+ */
88
+ unregisterExpoToken(params: MobileUnregisterExpoTokenParams): Promise<MobileServerSuccessResponse>;
89
+ /**
90
+ * Replaces the wallet's push notification preferences. The backend requires `schemaVersion` of 1, exactly
91
+ * one entry per known category, and empty `scopes` on every entry.
92
+ *
93
+ * @throws {MobileServerFailureError} With error code `INVALID_PREFERENCES` if those rules are violated.
94
+ */
95
+ updateNotificationPreferences(params: MobileUpdateNotificationPreferencesParams): Promise<MobileServerSuccessResponse>;
96
+ protected getSignedRequest<T extends MobileSignedInner['type']>(type: T, params: MobileSignedRequestParams, innerParams: MobileSignedInnerParams<T>): Promise<MobileSignedRequest>;
97
+ protected publicQuery<TResponse extends {
98
+ status: 'success';
99
+ }>(body: object): Promise<TResponse>;
100
+ protected query<TResponse extends {
101
+ status: 'success';
102
+ }>(body: MobileSignedRequest): Promise<TResponse>;
103
+ protected execute(body: MobileSignedRequest): Promise<MobileServerSuccessResponse>;
104
+ /**
105
+ * Validates the HTTP status before interpreting the body. Unlike the engine, the mobile backend returns
106
+ * failure envelopes with non-2xx statuses (e.g. 404 for `PROFILE_NOT_FOUND`), so a non-2xx response with a
107
+ * failure envelope still throws the typed error; anything else is a transport-level error.
108
+ */
109
+ private checkResponseStatus;
110
+ private checkServerStatus;
111
+ }
112
+ //#endregion
113
+ export { MobileClient, MobileClientOpts };
114
+ //# sourceMappingURL=MobileClient.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MobileClient.d.cts","names":[],"sources":["../src/src/MobileClient.ts"],"mappings":";;;;;;;;;;UAyDiB,gBAAA;EAAgB;;;EAI/B,GAAA;EAIA;;;EAAA,YA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,UAaK,WAAA;IAAgC,MAAA;EAAA,EAAA,CAC9C,IAAA,WACC,OAAA,CAAQ,SAAA;EAAA,UAaK,KAAA;IAA0B,MAAA;EAAA,EAAA,CACxC,IAAA,EAAM,mBAAA,GACL,OAAA,CAAQ,SAAA;EAAA,UAaK,OAAA,CACd,IAAA,EAAM,mBAAA,GACL,OAAA,CAAQ,2BAAA;EA/LL;;;;;EAAA,QAiNE,mBAAA;EAAA,QAYA,iBAAA;AAAA"}
@@ -0,0 +1,114 @@
1
+ import { _ as MobileUpdateNotificationPreferencesParams, a as GetMobileUsernameAvailabilityParams, d as MobilePublicProfile, f as MobileRegisterExpoTokenParams, g as MobileUnregisterExpoTokenParams, h as MobileSignedRequestParams, i as GetMobileSelfIdentityParams, m as MobileSetPrivateModeParams, n as GetMobilePublicProfileParams, o as MobileClaimUsernameParams, p as MobileRegisteredDevice, r as GetMobileRegisteredDevicesParams, s as MobileIdentity, t as GetMobileNotificationPreferencesParams, u as MobileNotificationPreferences, v as MobileUpdateUsernameParams, y as MobileUsernameAvailability } from "./clientTypes-DWW2N66c.js";
2
+ import { i as MobileSignedRequest, n as MobileSignedInner, r as MobileSignedInnerParams } from "./types-B76Pn7Sy.js";
3
+ import { a as MobileServerSuccessResponse } from "./serverBaseTypes-ewbo8l4R.js";
4
+ import { WalletClientWithAccount } from "@nadohq/shared";
5
+ import { AxiosInstance } from "axios";
6
+
7
+ //#region src/MobileClient.d.ts
8
+ /**
9
+ * Options for constructing a {@link MobileClient}.
10
+ */
11
+ interface MobileClientOpts {
12
+ /**
13
+ * Base URL of the mobile service API, e.g. {@link MOBILE_CLIENT_ENDPOINTS}.
14
+ */
15
+ url: string;
16
+ /**
17
+ * Wallet client used to sign requests.
18
+ */
19
+ walletClient?: WalletClientWithAccount;
20
+ /**
21
+ * If provided, this signer is used instead of `walletClient` for all signed requests.
22
+ */
23
+ linkedSignerWalletClient?: WalletClientWithAccount;
24
+ }
25
+ /**
26
+ * Client for the Nado mobile service API: username claims, public profile lookups, privacy settings, and
27
+ * push notification device/preference management.
28
+ */
29
+ declare class MobileClient {
30
+ readonly opts: MobileClientOpts;
31
+ readonly axiosInstance: AxiosInstance;
32
+ constructor(opts: MobileClientOpts);
33
+ /**
34
+ * Sets the linked signer for requests
35
+ *
36
+ * @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer
37
+ */
38
+ setLinkedSigner(linkedSignerWalletClient: WalletClientWithAccount | null): void;
39
+ /**
40
+ * Checks whether a username derived from the given display name is available to claim.
41
+ */
42
+ getUsernameAvailability(params: GetMobileUsernameAvailabilityParams): Promise<MobileUsernameAvailability>;
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
+ getPublicProfile(params: GetMobilePublicProfileParams): Promise<MobilePublicProfile>;
50
+ /**
51
+ * Fetches the caller's own identity for a subaccount. Returns `null` if the subaccount has not claimed a
52
+ * username yet — this is normal data, not an error.
53
+ */
54
+ getSelfIdentity(params: GetMobileSelfIdentityParams): Promise<MobileIdentity | null>;
55
+ /**
56
+ * Fetches a wallet's push notification preferences. Falls back to the backend's defaults if the wallet has
57
+ * never updated its preferences.
58
+ */
59
+ getNotificationPreferences(params: GetMobileNotificationPreferencesParams): Promise<MobileNotificationPreferences>;
60
+ /**
61
+ * Fetches the devices registered for push notifications for a wallet.
62
+ */
63
+ getRegisteredDevices(params: GetMobileRegisteredDevicesParams): Promise<MobileRegisteredDevice[]>;
64
+ /**
65
+ * Claims a username for a subaccount, derived from the given display name.
66
+ */
67
+ claimUsername(params: MobileClaimUsernameParams): Promise<MobileServerSuccessResponse>;
68
+ /**
69
+ * Updates the display name for a subaccount's already-claimed identity.
70
+ */
71
+ updateUsername(params: MobileUpdateUsernameParams): Promise<MobileServerSuccessResponse>;
72
+ /**
73
+ * Sets whether a subaccount's profile is private.
74
+ */
75
+ setPrivateMode(params: MobileSetPrivateModeParams): Promise<MobileServerSuccessResponse>;
76
+ /**
77
+ * Registers an Expo push token for the wallet, transferring active ownership of the token if another
78
+ * wallet had registered it. Idempotent per `(wallet, token)`.
79
+ *
80
+ * @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is not a valid Expo
81
+ * push token, or `INVALID_DEVICE_METADATA` if `locale` (max 35 chars) or `appVersion` (max 64 chars) is
82
+ * too long.
83
+ */
84
+ registerExpoToken(params: MobileRegisterExpoTokenParams): Promise<MobileServerSuccessResponse>;
85
+ /**
86
+ * Unregisters an Expo push token for the wallet. Idempotent — unregistering an unknown token succeeds.
87
+ */
88
+ unregisterExpoToken(params: MobileUnregisterExpoTokenParams): Promise<MobileServerSuccessResponse>;
89
+ /**
90
+ * Replaces the wallet's push notification preferences. The backend requires `schemaVersion` of 1, exactly
91
+ * one entry per known category, and empty `scopes` on every entry.
92
+ *
93
+ * @throws {MobileServerFailureError} With error code `INVALID_PREFERENCES` if those rules are violated.
94
+ */
95
+ updateNotificationPreferences(params: MobileUpdateNotificationPreferencesParams): Promise<MobileServerSuccessResponse>;
96
+ protected getSignedRequest<T extends MobileSignedInner['type']>(type: T, params: MobileSignedRequestParams, innerParams: MobileSignedInnerParams<T>): Promise<MobileSignedRequest>;
97
+ protected publicQuery<TResponse extends {
98
+ status: 'success';
99
+ }>(body: object): Promise<TResponse>;
100
+ protected query<TResponse extends {
101
+ status: 'success';
102
+ }>(body: MobileSignedRequest): Promise<TResponse>;
103
+ protected execute(body: MobileSignedRequest): Promise<MobileServerSuccessResponse>;
104
+ /**
105
+ * Validates the HTTP status before interpreting the body. Unlike the engine, the mobile backend returns
106
+ * failure envelopes with non-2xx statuses (e.g. 404 for `PROFILE_NOT_FOUND`), so a non-2xx response with a
107
+ * failure envelope still throws the typed error; anything else is a transport-level error.
108
+ */
109
+ private checkResponseStatus;
110
+ private checkServerStatus;
111
+ }
112
+ //#endregion
113
+ export { Mobile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