@nadohq/mobile-client 0.29.0 → 0.31.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 +15 -8
- package/dist/{MobileClient-9JSAzblH.cjs → MobileClient-_i0ZV6Dq.cjs} +104 -44
- package/dist/MobileClient-_i0ZV6Dq.cjs.map +1 -0
- package/dist/MobileClient.cjs +1 -1
- package/dist/MobileClient.d.cts +77 -36
- package/dist/MobileClient.d.cts.map +1 -1
- package/dist/MobileClient.d.ts +77 -36
- package/dist/MobileClient.d.ts.map +1 -1
- package/dist/MobileClient.js +105 -45
- package/dist/MobileClient.js.map +1 -1
- package/dist/{MobileServerFailureError-ZggEcEda.d.cts → MobileServerFailureError-BoyAfEZA.d.cts} +3 -2
- package/dist/MobileServerFailureError-BoyAfEZA.d.cts.map +1 -0
- package/dist/{MobileServerFailureError-f9KhKnJj.d.ts → MobileServerFailureError-MgYVBh5p.d.ts} +3 -2
- package/dist/MobileServerFailureError-MgYVBh5p.d.ts.map +1 -0
- package/dist/{buildSignedMobileRequest-BsbBkU0K.d.cts → buildSignedMobileRequest-CBMt97aY.d.cts} +2 -2
- package/dist/{buildSignedMobileRequest-BsbBkU0K.d.cts.map → buildSignedMobileRequest-CBMt97aY.d.cts.map} +1 -1
- package/dist/{buildSignedMobileRequest-CDRsRNHm.d.ts → buildSignedMobileRequest-qEC4gWaI.d.ts} +2 -2
- package/dist/{buildSignedMobileRequest-CDRsRNHm.d.ts.map → buildSignedMobileRequest-qEC4gWaI.d.ts.map} +1 -1
- package/dist/{canonicalize-PX6dTIdF.d.ts → canonicalize-QNARV_Xc.d.cts} +4 -4
- package/dist/canonicalize-QNARV_Xc.d.cts.map +1 -0
- package/dist/{canonicalize-Dm7sXwPg.d.cts → canonicalize-wVdGejB1.d.ts} +4 -4
- package/dist/canonicalize-wVdGejB1.d.ts.map +1 -0
- package/dist/clientTypes-6utzUU-b.d.ts +240 -0
- package/dist/clientTypes-6utzUU-b.d.ts.map +1 -0
- package/dist/clientTypes-D9qgtNlE.d.cts +240 -0
- package/dist/clientTypes-D9qgtNlE.d.cts.map +1 -0
- package/dist/dataMappers.cjs +35 -1
- package/dist/dataMappers.cjs.map +1 -1
- package/dist/dataMappers.d.cts +8 -3
- package/dist/dataMappers.d.cts.map +1 -1
- package/dist/dataMappers.d.ts +8 -3
- package/dist/dataMappers.d.ts.map +1 -1
- package/dist/dataMappers.js +35 -2
- package/dist/dataMappers.js.map +1 -1
- package/dist/{eip712MethodByType-DLh9MRsD.d.cts → eip712MethodByType-CroIPqsJ.d.cts} +2 -2
- package/dist/eip712MethodByType-CroIPqsJ.d.cts.map +1 -0
- package/dist/{eip712MethodByType-DJgXal9r.d.ts → eip712MethodByType-DBUy4AdI.d.ts} +2 -2
- package/dist/eip712MethodByType-DBUy4AdI.d.ts.map +1 -0
- package/dist/feed-BF5k6Ryu.d.ts +14 -0
- package/dist/feed-BF5k6Ryu.d.ts.map +1 -0
- package/dist/feed-CBIwOhTO.d.cts +14 -0
- package/dist/feed-CBIwOhTO.d.cts.map +1 -0
- package/dist/index.cjs +8 -1
- package/dist/index.d.cts +17 -15
- package/dist/index.d.ts +17 -15
- package/dist/index.js +3 -1
- package/dist/{mobileErrorCodes-BeyBKmwh.d.cts → mobileErrorCodes-CuQ5lyBV.d.ts} +8 -8
- package/dist/mobileErrorCodes-CuQ5lyBV.d.ts.map +1 -0
- package/dist/{mobileErrorCodes-QG5XbEY6.d.ts → mobileErrorCodes-D_SyBm0k.d.cts} +8 -8
- package/dist/mobileErrorCodes-D_SyBm0k.d.cts.map +1 -0
- package/dist/{patterns-BbxH3_VA.d.ts → patterns-B5gi7OfV.d.ts} +1 -1
- package/dist/patterns-B5gi7OfV.d.ts.map +1 -0
- package/dist/{patterns-B9J2ldpx.d.cts → patterns-Db6fgz8i.d.cts} +1 -1
- package/dist/patterns-Db6fgz8i.d.cts.map +1 -0
- package/dist/{payloadHash-nj8WuLUP.d.cts → payloadHash-B0tlFOK8.d.cts} +2 -2
- package/dist/payloadHash-B0tlFOK8.d.cts.map +1 -0
- package/dist/{payloadHash-Bmhzs78N.d.ts → payloadHash-D1yTQSF4.d.ts} +2 -2
- package/dist/payloadHash-D1yTQSF4.d.ts.map +1 -0
- package/dist/serverBaseTypes-CzRgwUvA.d.ts +25 -0
- package/dist/serverBaseTypes-CzRgwUvA.d.ts.map +1 -0
- package/dist/serverBaseTypes-DSRgU2Fb.d.cts +25 -0
- package/dist/serverBaseTypes-DSRgU2Fb.d.cts.map +1 -0
- package/dist/serverExecuteTypes-BCb6bUMP.d.cts +19 -0
- package/dist/serverExecuteTypes-BCb6bUMP.d.cts.map +1 -0
- package/dist/serverExecuteTypes-CI3NBW2Z.d.ts +19 -0
- package/dist/serverExecuteTypes-CI3NBW2Z.d.ts.map +1 -0
- package/dist/serverModelTypes-BYQcsRrx.d.cts +146 -0
- package/dist/serverModelTypes-BYQcsRrx.d.cts.map +1 -0
- package/dist/serverModelTypes-DvPs5qs3.d.ts +146 -0
- package/dist/serverModelTypes-DvPs5qs3.d.ts.map +1 -0
- package/dist/serverQueryTypes-9H6P1vJ5.d.cts +92 -0
- package/dist/serverQueryTypes-9H6P1vJ5.d.cts.map +1 -0
- package/dist/serverQueryTypes-Cbjx0bIj.d.ts +92 -0
- package/dist/serverQueryTypes-Cbjx0bIj.d.ts.map +1 -0
- package/dist/serverRequestTypes-CHDk6JwE.d.cts +85 -0
- package/dist/serverRequestTypes-CHDk6JwE.d.cts.map +1 -0
- package/dist/serverRequestTypes-DYTLrCpz.d.ts +85 -0
- package/dist/serverRequestTypes-DYTLrCpz.d.ts.map +1 -0
- package/dist/{serverResponseGuards-DjCNL3CR.d.cts → serverResponseGuards-DRMHmfXh.d.cts} +2 -2
- package/dist/{serverResponseGuards-DjCNL3CR.d.cts.map → serverResponseGuards-DRMHmfXh.d.cts.map} +1 -1
- package/dist/{serverResponseGuards-C_vZIgGl.d.ts → serverResponseGuards-DpbZvJfL.d.ts} +2 -2
- package/dist/{serverResponseGuards-C_vZIgGl.d.ts.map → serverResponseGuards-DpbZvJfL.d.ts.map} +1 -1
- package/dist/signing/buildSignedMobileRequest.cjs +1 -1
- package/dist/signing/buildSignedMobileRequest.d.cts +1 -1
- package/dist/signing/buildSignedMobileRequest.d.ts +1 -1
- package/dist/signing/canonicalize.cjs +4 -37
- package/dist/signing/canonicalize.cjs.map +1 -1
- package/dist/signing/canonicalize.d.cts +1 -1
- package/dist/signing/canonicalize.d.ts +1 -1
- package/dist/signing/canonicalize.js +4 -37
- package/dist/signing/canonicalize.js.map +1 -1
- package/dist/signing/eip712MethodByType.cjs +1 -5
- package/dist/signing/eip712MethodByType.cjs.map +1 -1
- package/dist/signing/eip712MethodByType.d.cts +1 -1
- package/dist/signing/eip712MethodByType.d.ts +1 -1
- package/dist/signing/eip712MethodByType.js +1 -5
- package/dist/signing/eip712MethodByType.js.map +1 -1
- package/dist/signing/index.d.cts +5 -5
- package/dist/signing/index.d.ts +5 -5
- package/dist/signing/payloadHash.cjs +1 -1
- package/dist/signing/payloadHash.d.cts +1 -1
- package/dist/signing/payloadHash.d.ts +1 -1
- package/dist/signing/types.d.cts +1 -1
- package/dist/signing/types.d.ts +1 -1
- package/dist/types/MobileServerFailureError.cjs +1 -1
- package/dist/types/MobileServerFailureError.cjs.map +1 -1
- package/dist/types/MobileServerFailureError.d.cts +1 -1
- package/dist/types/MobileServerFailureError.d.ts +1 -1
- package/dist/types/MobileServerFailureError.js.map +1 -1
- package/dist/types/clientTypes.d.cts +2 -2
- package/dist/types/clientTypes.d.ts +2 -2
- package/dist/types/index.cjs +4 -0
- package/dist/types/index.d.cts +9 -8
- package/dist/types/index.d.ts +9 -8
- package/dist/types/index.js +2 -1
- package/dist/types/mobileErrorCodes.cjs +10 -7
- package/dist/types/mobileErrorCodes.cjs.map +1 -1
- package/dist/types/mobileErrorCodes.d.cts +1 -1
- package/dist/types/mobileErrorCodes.d.ts +1 -1
- package/dist/types/mobileErrorCodes.js +9 -6
- package/dist/types/mobileErrorCodes.js.map +1 -1
- package/dist/types/serverBaseTypes.d.cts +2 -2
- package/dist/types/serverBaseTypes.d.ts +2 -2
- package/dist/types/serverExecuteTypes.d.cts +2 -2
- package/dist/types/serverExecuteTypes.d.ts +2 -2
- package/dist/types/serverModelTypes.cjs +29 -0
- package/dist/types/serverModelTypes.cjs.map +1 -0
- package/dist/types/serverModelTypes.d.cts +2 -2
- package/dist/types/serverModelTypes.d.ts +2 -2
- package/dist/types/serverModelTypes.js +26 -1
- package/dist/types/serverModelTypes.js.map +1 -0
- package/dist/types/serverQueryTypes.d.cts +2 -2
- package/dist/types/serverQueryTypes.d.ts +2 -2
- package/dist/types/serverRequestTypes.cjs +0 -0
- package/dist/types/serverRequestTypes.d.cts +2 -0
- package/dist/types/serverRequestTypes.d.ts +2 -0
- package/dist/types/serverRequestTypes.js +1 -0
- package/dist/{types-B76Pn7Sy.d.ts → types-CQE3HD2V.d.ts} +4 -15
- package/dist/types-CQE3HD2V.d.ts.map +1 -0
- package/dist/{types-uCD4BNZR.d.cts → types-bNB98pYk.d.cts} +4 -15
- package/dist/types-bNB98pYk.d.cts.map +1 -0
- package/dist/utils/feed.cjs +17 -0
- package/dist/utils/feed.cjs.map +1 -0
- package/dist/utils/feed.d.cts +2 -0
- package/dist/utils/feed.d.ts +2 -0
- package/dist/utils/feed.js +15 -0
- package/dist/utils/feed.js.map +1 -0
- package/dist/utils/index.cjs +3 -0
- package/dist/utils/index.d.cts +4 -3
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +2 -1
- package/dist/utils/patterns.d.cts +1 -1
- package/dist/utils/patterns.d.ts +1 -1
- package/dist/utils/serverResponseGuards.d.cts +1 -1
- package/dist/utils/serverResponseGuards.d.ts +1 -1
- package/package.json +3 -3
- package/src/MobileClient.ts +163 -112
- package/src/dataMappers.ts +41 -0
- package/src/signing/canonicalize.ts +4 -37
- package/src/signing/eip712MethodByType.ts +1 -5
- package/src/signing/signing.test.ts +17 -60
- package/src/signing/types.ts +2 -12
- package/src/types/MobileServerFailureError.ts +2 -4
- package/src/types/clientTypes.ts +105 -27
- package/src/types/index.ts +1 -0
- package/src/types/mobileErrorCodes.ts +8 -5
- package/src/types/serverBaseTypes.ts +7 -28
- package/src/types/serverExecuteTypes.ts +17 -0
- package/src/types/serverModelTypes.ts +104 -8
- package/src/types/serverQueryTypes.ts +84 -39
- package/src/types/serverRequestTypes.ts +91 -0
- package/src/utils/feed.ts +11 -0
- package/src/utils/index.ts +1 -0
- package/dist/MobileClient-9JSAzblH.cjs.map +0 -1
- package/dist/MobileServerFailureError-ZggEcEda.d.cts.map +0 -1
- package/dist/MobileServerFailureError-f9KhKnJj.d.ts.map +0 -1
- package/dist/canonicalize-Dm7sXwPg.d.cts.map +0 -1
- package/dist/canonicalize-PX6dTIdF.d.ts.map +0 -1
- package/dist/clientTypes-DWW2N66c.d.ts +0 -168
- package/dist/clientTypes-DWW2N66c.d.ts.map +0 -1
- package/dist/clientTypes-Et0PUa2d.d.cts +0 -168
- package/dist/clientTypes-Et0PUa2d.d.cts.map +0 -1
- package/dist/eip712MethodByType-DJgXal9r.d.ts.map +0 -1
- package/dist/eip712MethodByType-DLh9MRsD.d.cts.map +0 -1
- package/dist/mobileErrorCodes-BeyBKmwh.d.cts.map +0 -1
- package/dist/mobileErrorCodes-QG5XbEY6.d.ts.map +0 -1
- package/dist/patterns-B9J2ldpx.d.cts.map +0 -1
- package/dist/patterns-BbxH3_VA.d.ts.map +0 -1
- package/dist/payloadHash-Bmhzs78N.d.ts.map +0 -1
- package/dist/payloadHash-nj8WuLUP.d.cts.map +0 -1
- package/dist/serverBaseTypes-BicXMrZV.d.cts +0 -43
- package/dist/serverBaseTypes-BicXMrZV.d.cts.map +0 -1
- package/dist/serverBaseTypes-ewbo8l4R.d.ts +0 -43
- package/dist/serverBaseTypes-ewbo8l4R.d.ts.map +0 -1
- package/dist/serverExecuteTypes-CXnMjKnt.d.ts +0 -11
- package/dist/serverExecuteTypes-CXnMjKnt.d.ts.map +0 -1
- package/dist/serverExecuteTypes-DKYK1V7C.d.cts +0 -11
- package/dist/serverExecuteTypes-DKYK1V7C.d.cts.map +0 -1
- package/dist/serverModelTypes-CQgfqgW3.d.cts +0 -69
- package/dist/serverModelTypes-CQgfqgW3.d.cts.map +0 -1
- package/dist/serverModelTypes-vEPhHIit.d.ts +0 -69
- package/dist/serverModelTypes-vEPhHIit.d.ts.map +0 -1
- package/dist/serverQueryTypes-BI-2TD8F.d.ts +0 -53
- package/dist/serverQueryTypes-BI-2TD8F.d.ts.map +0 -1
- package/dist/serverQueryTypes-D7Yharse.d.cts +0 -53
- package/dist/serverQueryTypes-D7Yharse.d.cts.map +0 -1
- package/dist/types-B76Pn7Sy.d.ts.map +0 -1
- package/dist/types-uCD4BNZR.d.cts.map +0 -1
package/dist/MobileClient.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import { i as MobileSignedRequest, n as MobileSignedInner, r as MobileSignedInnerParams } from "./types-
|
|
3
|
-
import { a as
|
|
1
|
+
import { S as MobileUsernameAvailability, _ as MobileSetPrivateModeParams, a as GetMobileSelfIdentityParams, b as MobileUnregisterExpoTokenParams, c as MobileFeedPage, g as MobileRegisteredDevice, h as MobileRegisterExpoTokenParams, i as GetMobileRegisteredDevicesParams, m as MobilePublicProfile, n as GetMobileNotificationPreferencesParams, o as GetMobileUsernameAvailabilityParams, p as MobileNotificationPreferences, r as GetMobilePublicProfileParams, t as GetMobileFeedParams, u as MobileIdentity, v as MobileSetUsernameParams, x as MobileUpdateNotificationPreferencesParams, y as MobileSignedRequestParams } from "./clientTypes-6utzUU-b.js";
|
|
2
|
+
import { i as MobileSignedRequest, n as MobileSignedInner, r as MobileSignedInnerParams } from "./types-CQE3HD2V.js";
|
|
3
|
+
import { a as MobileServerPublicQueryRequestType, c as MobileServerSignedQueryRequestType, i as MobileServerPublicQueryRequestByType } from "./serverRequestTypes-DYTLrCpz.js";
|
|
4
|
+
import { n as MobileServerSuccessResponse } from "./serverBaseTypes-CzRgwUvA.js";
|
|
5
|
+
import { n as MobileServerPublicExecuteRequest } from "./serverExecuteTypes-CI3NBW2Z.js";
|
|
6
|
+
import { o as MobileServerPublicQuerySuccessResponse, u as MobileServerSignedQuerySuccessResponse } from "./serverQueryTypes-Cbjx0bIj.js";
|
|
4
7
|
import { WalletClientWithAccount } from "@nadohq/shared";
|
|
5
8
|
import { AxiosInstance } from "axios";
|
|
6
9
|
|
|
@@ -23,8 +26,8 @@ interface MobileClientOpts {
|
|
|
23
26
|
linkedSignerWalletClient?: WalletClientWithAccount;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
|
-
* Client for the Nado mobile service API:
|
|
27
|
-
* push notification device/preference management.
|
|
29
|
+
* Client for the Nado mobile service API: usernames, public profile lookups, the global trade feed, privacy
|
|
30
|
+
* settings, and push notification device/preference management.
|
|
28
31
|
*/
|
|
29
32
|
declare class MobileClient {
|
|
30
33
|
readonly opts: MobileClientOpts;
|
|
@@ -41,34 +44,84 @@ declare class MobileClient {
|
|
|
41
44
|
*/
|
|
42
45
|
getUsernameAvailability(params: GetMobileUsernameAvailabilityParams): Promise<MobileUsernameAvailability>;
|
|
43
46
|
/**
|
|
44
|
-
* Looks up a subaccount's public profile
|
|
47
|
+
* Looks up a subaccount's public profile. Every non-isolated subaccount resolves, with `username` and
|
|
48
|
+
* `displayName` `null` until a username is claimed. Private Mode does not hide the profile itself, only the
|
|
49
|
+
* account's activity.
|
|
45
50
|
*
|
|
46
|
-
* @throws {MobileServerFailureError} With error code `PROFILE_NOT_FOUND` if
|
|
47
|
-
*
|
|
51
|
+
* @throws {MobileServerFailureError} With error code `PROFILE_NOT_FOUND` if the subaccount is in the
|
|
52
|
+
* engine-created isolated namespace, which cannot own a profile.
|
|
48
53
|
*/
|
|
49
54
|
getPublicProfile(params: GetMobilePublicProfileParams): Promise<MobilePublicProfile>;
|
|
50
55
|
/**
|
|
51
|
-
* Fetches
|
|
52
|
-
*
|
|
56
|
+
* Fetches a page of the global trade feed: public perpetual trades, newest first, optionally filtered by a
|
|
57
|
+
* whole-dollar minimum notional (omitted means unfiltered). Trades by subaccounts that have not claimed a
|
|
58
|
+
* username are included with `null` name fields; only private accounts are filtered out. The feed is
|
|
59
|
+
* best-effort rather than authoritative history, and pagination is live (not snapshot), so deduplicate pages
|
|
60
|
+
* by {@link MobileFeedTrade.orderDigest}.
|
|
61
|
+
*
|
|
62
|
+
* @throws {MobileServerFailureError} With error code `INVALID_FEED_FILTER` if `minimumNotional` or
|
|
63
|
+
* `limit` is outside its allowed domain (fix the request; do not retry unchanged), or
|
|
64
|
+
* `INVALID_FEED_CURSOR` if the cursor is malformed or was issued for a different `minimumNotional`
|
|
65
|
+
* (discard the cursor and restart from the first page).
|
|
53
66
|
*/
|
|
54
|
-
|
|
67
|
+
getFeed(params?: GetMobileFeedParams): Promise<MobileFeedPage>;
|
|
55
68
|
/**
|
|
56
|
-
* Fetches
|
|
57
|
-
*
|
|
69
|
+
* Fetches the push notification preferences of the wallet that owns the given Expo push token. Unsigned —
|
|
70
|
+
* the token identifies the wallet on its own. Falls back to the backend's defaults if the wallet has never
|
|
71
|
+
* updated its preferences.
|
|
72
|
+
*
|
|
73
|
+
* @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is malformed, or is
|
|
74
|
+
* not currently registered to a wallet.
|
|
58
75
|
*/
|
|
59
76
|
getNotificationPreferences(params: GetMobileNotificationPreferencesParams): Promise<MobileNotificationPreferences>;
|
|
60
77
|
/**
|
|
61
|
-
*
|
|
78
|
+
* Unregisters an Expo push token, stopping delivery to that device. Unsigned, so it still works at logout
|
|
79
|
+
* when a wallet signature may no longer be obtainable. Idempotent: unregistering an inactive or unknown
|
|
80
|
+
* well-formed token succeeds.
|
|
81
|
+
*
|
|
82
|
+
* A registration that commits after this call re-activates the token, so stop or await any in-flight
|
|
83
|
+
* {@link MobileClient.registerExpoToken} before unregistering.
|
|
84
|
+
*
|
|
85
|
+
* @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is malformed.
|
|
62
86
|
*/
|
|
63
|
-
|
|
87
|
+
unregisterExpoToken(params: MobileUnregisterExpoTokenParams): Promise<MobileServerSuccessResponse>;
|
|
64
88
|
/**
|
|
65
|
-
*
|
|
89
|
+
* Replaces the push notification preferences of the wallet that owns the given Expo push token. Possession
|
|
90
|
+
* of an active token is the credential rather than a signature, so anyone holding the token can overwrite
|
|
91
|
+
* that wallet's preferences. The backend requires `schemaVersion` of 1, exactly one entry per known
|
|
92
|
+
* category, and empty `scopes` on every entry.
|
|
93
|
+
*
|
|
94
|
+
* Writes are last-write-wins on commit order rather than ordered by a client nonce, so callers must
|
|
95
|
+
* serialize their own preference writes.
|
|
96
|
+
*
|
|
97
|
+
* @throws {MobileServerFailureError} With error code `INVALID_PREFERENCES` if those rules are violated, or
|
|
98
|
+
* `INVALID_EXPO_TOKEN` if the token is malformed or is not currently registered to a wallet.
|
|
66
99
|
*/
|
|
67
|
-
|
|
100
|
+
updateNotificationPreferences(params: MobileUpdateNotificationPreferencesParams): Promise<MobileServerSuccessResponse>;
|
|
68
101
|
/**
|
|
69
|
-
*
|
|
102
|
+
* Fetches the caller's own identity for a subaccount. Every non-isolated subaccount has an implicit
|
|
103
|
+
* identity, so this resolves for any valid sender with `username` and `displayName` `null` until a username
|
|
104
|
+
* is claimed.
|
|
105
|
+
*
|
|
106
|
+
* @throws {MobileServerFailureError} With error code `INVALID_IDENTITY_TARGET` if the sender is in the
|
|
107
|
+
* engine-created isolated namespace, which cannot own an identity.
|
|
70
108
|
*/
|
|
71
|
-
|
|
109
|
+
getSelfIdentity(params: GetMobileSelfIdentityParams): Promise<MobileIdentity | null>;
|
|
110
|
+
/**
|
|
111
|
+
* Fetches the devices registered for push notifications for a wallet.
|
|
112
|
+
*/
|
|
113
|
+
getRegisteredDevices(params: GetMobileRegisteredDevicesParams): Promise<MobileRegisteredDevice[]>;
|
|
114
|
+
/**
|
|
115
|
+
* Sets a subaccount's username, derived from the given display name. Upserts: the same call claims a first
|
|
116
|
+
* username and renames an existing one, so callers never need to read the current identity first.
|
|
117
|
+
*
|
|
118
|
+
* @throws {MobileServerFailureError} With error code `INVALID_DISPLAY_NAME` if the display name violates
|
|
119
|
+
* `MOBILE_DISPLAY_NAME_PATTERN`, `USERNAME_UNAVAILABLE` if the derived username is reserved or already
|
|
120
|
+
* taken by another subaccount, `INVALID_IDENTITY_TARGET` if the sender is in the engine-created isolated
|
|
121
|
+
* namespace, or `STALE_IDENTITY_UPDATE` if another identity write for this subaccount committed with a
|
|
122
|
+
* later nonce (re-read the identity before retrying).
|
|
123
|
+
*/
|
|
124
|
+
setUsername(params: MobileSetUsernameParams): Promise<MobileServerSuccessResponse>;
|
|
72
125
|
/**
|
|
73
126
|
* Sets whether a subaccount's profile is private.
|
|
74
127
|
*/
|
|
@@ -82,24 +135,12 @@ declare class MobileClient {
|
|
|
82
135
|
* too long.
|
|
83
136
|
*/
|
|
84
137
|
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
138
|
protected getSignedRequest<T extends MobileSignedInner['type']>(type: T, params: MobileSignedRequestParams, innerParams: MobileSignedInnerParams<T>): Promise<MobileSignedRequest>;
|
|
97
|
-
protected publicQuery<
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
protected
|
|
101
|
-
|
|
102
|
-
}>(body: MobileSignedRequest): Promise<TResponse>;
|
|
139
|
+
protected publicQuery<T extends MobileServerPublicQueryRequestType>(body: {
|
|
140
|
+
type: T;
|
|
141
|
+
} & MobileServerPublicQueryRequestByType[T]): Promise<MobileServerPublicQuerySuccessResponse<T>>;
|
|
142
|
+
protected publicExecute(body: MobileServerPublicExecuteRequest): Promise<MobileServerSuccessResponse>;
|
|
143
|
+
protected query<T extends MobileServerSignedQueryRequestType>(body: MobileSignedRequest): Promise<MobileServerSignedQuerySuccessResponse<T>>;
|
|
103
144
|
protected execute(body: MobileSignedRequest): Promise<MobileServerSuccessResponse>;
|
|
104
145
|
/**
|
|
105
146
|
* Validates the HTTP status before interpreting the body. Unlike the engine, the mobile backend returns
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileClient.d.ts","names":[],"sources":["../src/src/MobileClient.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"MobileClient.d.ts","names":[],"sources":["../src/src/MobileClient.ts"],"mappings":";;;;;;;;;;;;;UAgEiB,gBAAA;EAAgB;;;EAI/B,GAAA;EAIA;;;EAAA,YAAA,GAAe,uBAAA;EAImC;AAAA;AAOpD;EAPE,wBAAA,GAA2B,uBAAuB;AAAA;;;;;cAOvC,YAAA;EAAA,SACF,IAAA,EAAM,gBAAA;EAAA,SACN,aAAA,EAAe,aAAA;cAEZ,IAAA,EAAM,gBAAA;EAgDP;;;;;EAlCJ,eAAA,CACL,wBAAA,EAA0B,uBAAA;EA2EjB;;;EA/DL,uBAAA,CACJ,MAAA,EAAQ,mCAAA,GACP,OAAA,CAAQ,0BAAA;EAsFR;;;;;;;;EArEG,gBAAA,CACJ,MAAA,EAAQ,4BAAA,GACP,OAAA,CAAQ,mBAAA;EA+HR;;;;;;;;;;;;EA1GG,OAAA,CAAQ,MAAA,GAAQ,mBAAA,GAA2B,OAAA,CAA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A,QAYA,iBAAA;AAAA"}
|
package/dist/MobileClient.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { mapMobileIdentity, mapMobileNotificationPreferences, mapMobileNotificationPreferencesToServer, mapMobilePublicProfile, mapMobileRegisteredDevice } from "./dataMappers.js";
|
|
1
|
+
import { mapMobileFeedPage, mapMobileIdentity, mapMobileNotificationPreferences, mapMobileNotificationPreferencesToServer, mapMobilePublicProfile, mapMobileRegisteredDevice } from "./dataMappers.js";
|
|
2
2
|
import { buildSignedMobileRequest } from "./signing/buildSignedMobileRequest.js";
|
|
3
3
|
import "./signing/index.js";
|
|
4
4
|
import { MobileServerFailureError } from "./types/MobileServerFailureError.js";
|
|
5
5
|
import { isMobileServerFailureResponse, isMobileServerSuccessResponse } from "./utils/serverResponseGuards.js";
|
|
6
|
-
import { WalletNotProvidedError } from "@nadohq/shared";
|
|
6
|
+
import { WalletNotProvidedError, subaccountToHex } from "@nadohq/shared";
|
|
7
7
|
import axios from "axios";
|
|
8
8
|
//#region src/MobileClient.ts
|
|
9
9
|
/**
|
|
10
|
-
* Client for the Nado mobile service API:
|
|
11
|
-
* push notification device/preference management.
|
|
10
|
+
* Client for the Nado mobile service API: usernames, public profile lookups, the global trade feed, privacy
|
|
11
|
+
* settings, and push notification device/preference management.
|
|
12
12
|
*/
|
|
13
13
|
var MobileClient = class {
|
|
14
14
|
constructor(opts) {
|
|
@@ -41,34 +41,105 @@ var MobileClient = class {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* Looks up a subaccount's public profile
|
|
44
|
+
* Looks up a subaccount's public profile. Every non-isolated subaccount resolves, with `username` and
|
|
45
|
+
* `displayName` `null` until a username is claimed. Private Mode does not hide the profile itself, only the
|
|
46
|
+
* account's activity.
|
|
45
47
|
*
|
|
46
|
-
* @throws {MobileServerFailureError} With error code `PROFILE_NOT_FOUND` if
|
|
47
|
-
*
|
|
48
|
+
* @throws {MobileServerFailureError} With error code `PROFILE_NOT_FOUND` if the subaccount is in the
|
|
49
|
+
* engine-created isolated namespace, which cannot own a profile.
|
|
48
50
|
*/
|
|
49
51
|
async getPublicProfile(params) {
|
|
50
52
|
const body = {
|
|
51
53
|
type: "profile",
|
|
52
|
-
|
|
54
|
+
subaccount: subaccountToHex(params)
|
|
53
55
|
};
|
|
54
56
|
return mapMobilePublicProfile((await this.publicQuery(body)).profile);
|
|
55
57
|
}
|
|
56
58
|
/**
|
|
57
|
-
* Fetches
|
|
58
|
-
*
|
|
59
|
+
* Fetches a page of the global trade feed: public perpetual trades, newest first, optionally filtered by a
|
|
60
|
+
* whole-dollar minimum notional (omitted means unfiltered). Trades by subaccounts that have not claimed a
|
|
61
|
+
* username are included with `null` name fields; only private accounts are filtered out. The feed is
|
|
62
|
+
* best-effort rather than authoritative history, and pagination is live (not snapshot), so deduplicate pages
|
|
63
|
+
* by {@link MobileFeedTrade.orderDigest}.
|
|
64
|
+
*
|
|
65
|
+
* @throws {MobileServerFailureError} With error code `INVALID_FEED_FILTER` if `minimumNotional` or
|
|
66
|
+
* `limit` is outside its allowed domain (fix the request; do not retry unchanged), or
|
|
67
|
+
* `INVALID_FEED_CURSOR` if the cursor is malformed or was issued for a different `minimumNotional`
|
|
68
|
+
* (discard the cursor and restart from the first page).
|
|
59
69
|
*/
|
|
60
|
-
async
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
async getFeed(params = {}) {
|
|
71
|
+
const body = {
|
|
72
|
+
type: "feed",
|
|
73
|
+
minimum_notional: params.minimumNotional,
|
|
74
|
+
limit: params.limit,
|
|
75
|
+
cursor: params.cursor
|
|
76
|
+
};
|
|
77
|
+
return mapMobileFeedPage(await this.publicQuery(body));
|
|
64
78
|
}
|
|
65
79
|
/**
|
|
66
|
-
* Fetches
|
|
67
|
-
*
|
|
80
|
+
* Fetches the push notification preferences of the wallet that owns the given Expo push token. Unsigned —
|
|
81
|
+
* the token identifies the wallet on its own. Falls back to the backend's defaults if the wallet has never
|
|
82
|
+
* updated its preferences.
|
|
83
|
+
*
|
|
84
|
+
* @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is malformed, or is
|
|
85
|
+
* not currently registered to a wallet.
|
|
68
86
|
*/
|
|
69
87
|
async getNotificationPreferences(params) {
|
|
70
|
-
const
|
|
71
|
-
|
|
88
|
+
const body = {
|
|
89
|
+
type: "notification_preferences",
|
|
90
|
+
expo_token: params.expoToken
|
|
91
|
+
};
|
|
92
|
+
return mapMobileNotificationPreferences((await this.publicQuery(body)).preferences);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Unregisters an Expo push token, stopping delivery to that device. Unsigned, so it still works at logout
|
|
96
|
+
* when a wallet signature may no longer be obtainable. Idempotent: unregistering an inactive or unknown
|
|
97
|
+
* well-formed token succeeds.
|
|
98
|
+
*
|
|
99
|
+
* A registration that commits after this call re-activates the token, so stop or await any in-flight
|
|
100
|
+
* {@link MobileClient.registerExpoToken} before unregistering.
|
|
101
|
+
*
|
|
102
|
+
* @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is malformed.
|
|
103
|
+
*/
|
|
104
|
+
async unregisterExpoToken(params) {
|
|
105
|
+
const body = {
|
|
106
|
+
type: "unregister_expo_token",
|
|
107
|
+
expo_token: params.expoToken
|
|
108
|
+
};
|
|
109
|
+
return this.publicExecute(body);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Replaces the push notification preferences of the wallet that owns the given Expo push token. Possession
|
|
113
|
+
* of an active token is the credential rather than a signature, so anyone holding the token can overwrite
|
|
114
|
+
* that wallet's preferences. The backend requires `schemaVersion` of 1, exactly one entry per known
|
|
115
|
+
* category, and empty `scopes` on every entry.
|
|
116
|
+
*
|
|
117
|
+
* Writes are last-write-wins on commit order rather than ordered by a client nonce, so callers must
|
|
118
|
+
* serialize their own preference writes.
|
|
119
|
+
*
|
|
120
|
+
* @throws {MobileServerFailureError} With error code `INVALID_PREFERENCES` if those rules are violated, or
|
|
121
|
+
* `INVALID_EXPO_TOKEN` if the token is malformed or is not currently registered to a wallet.
|
|
122
|
+
*/
|
|
123
|
+
async updateNotificationPreferences(params) {
|
|
124
|
+
const body = {
|
|
125
|
+
type: "update_preferences",
|
|
126
|
+
expo_token: params.expoToken,
|
|
127
|
+
preferences: mapMobileNotificationPreferencesToServer(params.preferences)
|
|
128
|
+
};
|
|
129
|
+
return this.publicExecute(body);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Fetches the caller's own identity for a subaccount. Every non-isolated subaccount has an implicit
|
|
133
|
+
* identity, so this resolves for any valid sender with `username` and `displayName` `null` until a username
|
|
134
|
+
* is claimed.
|
|
135
|
+
*
|
|
136
|
+
* @throws {MobileServerFailureError} With error code `INVALID_IDENTITY_TARGET` if the sender is in the
|
|
137
|
+
* engine-created isolated namespace, which cannot own an identity.
|
|
138
|
+
*/
|
|
139
|
+
async getSelfIdentity(params) {
|
|
140
|
+
const signedRequest = await this.getSignedRequest("self_identity", params, {});
|
|
141
|
+
const data = await this.query(signedRequest);
|
|
142
|
+
return data.identity ? mapMobileIdentity(data.identity) : null;
|
|
72
143
|
}
|
|
73
144
|
/**
|
|
74
145
|
* Fetches the devices registered for push notifications for a wallet.
|
|
@@ -78,17 +149,17 @@ var MobileClient = class {
|
|
|
78
149
|
return (await this.query(signedRequest)).devices.map(mapMobileRegisteredDevice);
|
|
79
150
|
}
|
|
80
151
|
/**
|
|
81
|
-
*
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
*
|
|
152
|
+
* Sets a subaccount's username, derived from the given display name. Upserts: the same call claims a first
|
|
153
|
+
* username and renames an existing one, so callers never need to read the current identity first.
|
|
154
|
+
*
|
|
155
|
+
* @throws {MobileServerFailureError} With error code `INVALID_DISPLAY_NAME` if the display name violates
|
|
156
|
+
* `MOBILE_DISPLAY_NAME_PATTERN`, `USERNAME_UNAVAILABLE` if the derived username is reserved or already
|
|
157
|
+
* taken by another subaccount, `INVALID_IDENTITY_TARGET` if the sender is in the engine-created isolated
|
|
158
|
+
* namespace, or `STALE_IDENTITY_UPDATE` if another identity write for this subaccount committed with a
|
|
159
|
+
* later nonce (re-read the identity before retrying).
|
|
89
160
|
*/
|
|
90
|
-
async
|
|
91
|
-
const signedRequest = await this.getSignedRequest("
|
|
161
|
+
async setUsername(params) {
|
|
162
|
+
const signedRequest = await this.getSignedRequest("set_username", params, { display_name: params.displayName });
|
|
92
163
|
return this.execute(signedRequest);
|
|
93
164
|
}
|
|
94
165
|
/**
|
|
@@ -115,23 +186,6 @@ var MobileClient = class {
|
|
|
115
186
|
});
|
|
116
187
|
return this.execute(signedRequest);
|
|
117
188
|
}
|
|
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
189
|
async getSignedRequest(type, params, innerParams) {
|
|
136
190
|
const walletClient = this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
|
|
137
191
|
if (walletClient == null) throw new WalletNotProvidedError();
|
|
@@ -151,6 +205,12 @@ var MobileClient = class {
|
|
|
151
205
|
this.checkServerStatus(response);
|
|
152
206
|
return response.data;
|
|
153
207
|
}
|
|
208
|
+
async publicExecute(body) {
|
|
209
|
+
const response = await this.axiosInstance.post(`${this.opts.url}/mobile/public_execute`, body);
|
|
210
|
+
this.checkResponseStatus(response);
|
|
211
|
+
this.checkServerStatus(response);
|
|
212
|
+
return response.data;
|
|
213
|
+
}
|
|
154
214
|
async query(body) {
|
|
155
215
|
const response = await this.axiosInstance.post(`${this.opts.url}/mobile/query`, body);
|
|
156
216
|
this.checkResponseStatus(response);
|
package/dist/MobileClient.js.map
CHANGED
|
@@ -1 +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;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,OAAO,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,WAAW,kBAAkB,KAAK,QAAQ,IAAI;CAC5D;;;;;CAMA,MAAM,2BACJ,QACwC;EACxC,MAAM,gBAAgB,MAAM,KAAK,iBAC/B,4BACA,QACA,CAAC,CACH;EAKA,OAAO,kCAAiC,MAHhC,KA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js","names":[],"sources":["../src/MobileClient.ts"],"sourcesContent":["import {\n subaccountToHex,\n WalletClientWithAccount,\n WalletNotProvidedError,\n} from '@nadohq/shared';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n mapMobileFeedPage,\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 GetMobileFeedParams,\n GetMobileNotificationPreferencesParams,\n GetMobilePublicProfileParams,\n GetMobileRegisteredDevicesParams,\n GetMobileSelfIdentityParams,\n GetMobileUsernameAvailabilityParams,\n MobileFeedPage,\n MobileIdentity,\n MobileNotificationPreferences,\n MobilePublicProfile,\n MobileRegisteredDevice,\n MobileRegisterExpoTokenParams,\n MobileSetPrivateModeParams,\n MobileSetUsernameParams,\n MobileSignedRequestParams,\n MobileUnregisterExpoTokenParams,\n MobileUpdateNotificationPreferencesParams,\n MobileUsernameAvailability,\n} from './types/clientTypes';\nimport { MobileServerFailureError } from './types/MobileServerFailureError';\nimport { MobileServerSuccessResponse } from './types/serverBaseTypes';\nimport {\n MobileServerExecuteResult,\n MobileServerPublicExecuteRequest,\n} from './types/serverExecuteTypes';\nimport {\n MobileServerPublicQueryRequest,\n MobileServerPublicQuerySuccessResponse,\n MobileServerSignedQuerySuccessResponse,\n} from './types/serverQueryTypes';\nimport {\n MobileServerPublicQueryRequestByType,\n MobileServerPublicQueryRequestType,\n MobileServerSignedQueryRequestType,\n} from './types/serverRequestTypes';\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: usernames, public profile lookups, the global trade feed, privacy\n * settings, and 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: MobileServerPublicQueryRequest<'username_availability'> = {\n type: 'username_availability',\n display_name: params.displayName,\n };\n const data = await this.publicQuery(body);\n return { username: data.username, available: data.available };\n }\n\n /**\n * Looks up a subaccount's public profile. Every non-isolated subaccount resolves, with `username` and\n * `displayName` `null` until a username is claimed. Private Mode does not hide the profile itself, only the\n * account's activity.\n *\n * @throws {MobileServerFailureError} With error code `PROFILE_NOT_FOUND` if the subaccount is in the\n * engine-created isolated namespace, which cannot own a profile.\n */\n async getPublicProfile(\n params: GetMobilePublicProfileParams,\n ): Promise<MobilePublicProfile> {\n const body: MobileServerPublicQueryRequest<'profile'> = {\n type: 'profile',\n subaccount: subaccountToHex(params),\n };\n const data = await this.publicQuery(body);\n return mapMobilePublicProfile(data.profile);\n }\n\n /**\n * Fetches a page of the global trade feed: public perpetual trades, newest first, optionally filtered by a\n * whole-dollar minimum notional (omitted means unfiltered). Trades by subaccounts that have not claimed a\n * username are included with `null` name fields; only private accounts are filtered out. The feed is\n * best-effort rather than authoritative history, and pagination is live (not snapshot), so deduplicate pages\n * by {@link MobileFeedTrade.orderDigest}.\n *\n * @throws {MobileServerFailureError} With error code `INVALID_FEED_FILTER` if `minimumNotional` or\n * `limit` is outside its allowed domain (fix the request; do not retry unchanged), or\n * `INVALID_FEED_CURSOR` if the cursor is malformed or was issued for a different `minimumNotional`\n * (discard the cursor and restart from the first page).\n */\n async getFeed(params: GetMobileFeedParams = {}): Promise<MobileFeedPage> {\n const body: MobileServerPublicQueryRequest<'feed'> = {\n type: 'feed',\n minimum_notional: params.minimumNotional,\n limit: params.limit,\n cursor: params.cursor,\n };\n const data = await this.publicQuery(body);\n return mapMobileFeedPage(data);\n }\n\n /**\n * Fetches the push notification preferences of the wallet that owns the given Expo push token. Unsigned —\n * the token identifies the wallet on its own. Falls back to the backend's defaults if the wallet has never\n * updated its preferences.\n *\n * @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is malformed, or is\n * not currently registered to a wallet.\n */\n async getNotificationPreferences(\n params: GetMobileNotificationPreferencesParams,\n ): Promise<MobileNotificationPreferences> {\n const body: MobileServerPublicQueryRequest<'notification_preferences'> = {\n type: 'notification_preferences',\n expo_token: params.expoToken,\n };\n const data = await this.publicQuery(body);\n return mapMobileNotificationPreferences(data.preferences);\n }\n\n /*\n Public executes\n */\n\n /**\n * Unregisters an Expo push token, stopping delivery to that device. Unsigned, so it still works at logout\n * when a wallet signature may no longer be obtainable. Idempotent: unregistering an inactive or unknown\n * well-formed token succeeds.\n *\n * A registration that commits after this call re-activates the token, so stop or await any in-flight\n * {@link MobileClient.registerExpoToken} before unregistering.\n *\n * @throws {MobileServerFailureError} With error code `INVALID_EXPO_TOKEN` if the token is malformed.\n */\n async unregisterExpoToken(\n params: MobileUnregisterExpoTokenParams,\n ): Promise<MobileServerSuccessResponse> {\n const body: MobileServerPublicExecuteRequest<'unregister_expo_token'> = {\n type: 'unregister_expo_token',\n expo_token: params.expoToken,\n };\n return this.publicExecute(body);\n }\n\n /**\n * Replaces the push notification preferences of the wallet that owns the given Expo push token. Possession\n * of an active token is the credential rather than a signature, so anyone holding the token can overwrite\n * that wallet's preferences. The backend requires `schemaVersion` of 1, exactly one entry per known\n * category, and empty `scopes` on every entry.\n *\n * Writes are last-write-wins on commit order rather than ordered by a client nonce, so callers must\n * serialize their own preference writes.\n *\n * @throws {MobileServerFailureError} With error code `INVALID_PREFERENCES` if those rules are violated, or\n * `INVALID_EXPO_TOKEN` if the token is malformed or is not currently registered to a wallet.\n */\n async updateNotificationPreferences(\n params: MobileUpdateNotificationPreferencesParams,\n ): Promise<MobileServerSuccessResponse> {\n const body: MobileServerPublicExecuteRequest<'update_preferences'> = {\n type: 'update_preferences',\n expo_token: params.expoToken,\n preferences: mapMobileNotificationPreferencesToServer(params.preferences),\n };\n return this.publicExecute(body);\n }\n\n /*\n Signed queries\n */\n\n /**\n * Fetches the caller's own identity for a subaccount. Every non-isolated subaccount has an implicit\n * identity, so this resolves for any valid sender with `username` and `displayName` `null` until a username\n * is claimed.\n *\n * @throws {MobileServerFailureError} With error code `INVALID_IDENTITY_TARGET` if the sender is in the\n * engine-created isolated namespace, which cannot own an identity.\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 = await this.query<'self_identity'>(signedRequest);\n return data.identity ? mapMobileIdentity(data.identity) : null;\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 = await this.query<'registered_devices'>(signedRequest);\n return data.devices.map(mapMobileRegisteredDevice);\n }\n\n /*\n Signed executes\n */\n\n /**\n * Sets a subaccount's username, derived from the given display name. Upserts: the same call claims a first\n * username and renames an existing one, so callers never need to read the current identity first.\n *\n * @throws {MobileServerFailureError} With error code `INVALID_DISPLAY_NAME` if the display name violates\n * `MOBILE_DISPLAY_NAME_PATTERN`, `USERNAME_UNAVAILABLE` if the derived username is reserved or already\n * taken by another subaccount, `INVALID_IDENTITY_TARGET` if the sender is in the engine-created isolated\n * namespace, or `STALE_IDENTITY_UPDATE` if another identity write for this subaccount committed with a\n * later nonce (re-read the identity before retrying).\n */\n async setUsername(\n params: MobileSetUsernameParams,\n ): Promise<MobileServerSuccessResponse> {\n const signedRequest = await this.getSignedRequest('set_username', 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 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 // Spelled out as an intersection rather than `MobileServerPublicQueryRequest<T>`: the latter is an indexed\n // access on a mapped type, which is not an inference site, so `T` would always widen to the full union.\n protected async publicQuery<T extends MobileServerPublicQueryRequestType>(\n body: { type: T } & MobileServerPublicQueryRequestByType[T],\n ): Promise<MobileServerPublicQuerySuccessResponse<T>> {\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 MobileServerPublicQuerySuccessResponse<T>;\n }\n\n protected async publicExecute(\n body: MobileServerPublicExecuteRequest,\n ): Promise<MobileServerSuccessResponse> {\n const response = await this.axiosInstance.post<MobileServerExecuteResult>(\n `${this.opts.url}/mobile/public_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 protected async query<T extends MobileServerSignedQueryRequestType>(\n body: MobileSignedRequest,\n ): Promise<MobileServerSignedQuerySuccessResponse<T>> {\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 MobileServerSignedQuerySuccessResponse<T>;\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":";;;;;;;;;;;;AAmFA,IAAa,eAAb,MAA0B;CAIxB,YAAY,MAAwB;EAClC,KAAK,OAAO;EACZ,KAAK,gBAAgB,MAAM,OAAO;GAChC,iBAAiB;GAEjB,sBAAsB;EACxB,CAAC;CACH;;;;;;CAOA,gBACE,0BACA;EACA,KAAK,KAAK,2BAA2B,4BAA4B,KAAA;CACnE;;;;CASA,MAAM,wBACJ,QACqC;EACrC,MAAM,OAAgE;GACpE,MAAM;GACN,cAAc,OAAO;EACvB;EACA,MAAM,OAAO,MAAM,KAAK,YAAY,IAAI;EACxC,OAAO;GAAE,UAAU,KAAK;GAAU,WAAW,KAAK;EAAU;CAC9D;;;;;;;;;CAUA,MAAM,iBACJ,QAC8B;EAC9B,MAAM,OAAkD;GACtD,MAAM;GACN,YAAY,gBAAgB,MAAM;EACpC;EAEA,OAAO,wBAAuB,MADX,KAAK,YAAY,IAAI,GACL,OAAO;CAC5C;;;;;;;;;;;;;CAcA,MAAM,QAAQ,SAA8B,CAAC,GAA4B;EACvE,MAAM,OAA+C;GACnD,MAAM;GACN,kBAAkB,OAAO;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AAS,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"}
|
package/dist/{MobileServerFailureError-ZggEcEda.d.cts → MobileServerFailureError-BoyAfEZA.d.cts}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as MobileServerRequestType } from "./serverRequestTypes-CHDk6JwE.cjs";
|
|
2
|
+
import { t as MobileServerFailureResponse } from "./serverBaseTypes-DSRgU2Fb.cjs";
|
|
2
3
|
import { BaseServerFailureError } from "@nadohq/shared";
|
|
3
4
|
|
|
4
5
|
//#region src/types/MobileServerFailureError.d.ts
|
|
@@ -19,4 +20,4 @@ declare class MobileServerFailureError extends BaseServerFailureError {
|
|
|
19
20
|
}
|
|
20
21
|
//#endregion
|
|
21
22
|
export { MobileServerFailureError as t };
|
|
22
|
-
//# sourceMappingURL=MobileServerFailureError-
|
|
23
|
+
//# sourceMappingURL=MobileServerFailureError-BoyAfEZA.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileServerFailureError-BoyAfEZA.d.cts","names":[],"sources":["../src/types/src/types/MobileServerFailureError.ts"],"mappings":";;;;;;;AASA;;;cAAa,wBAAA,SAAiC,sBAAA;EAAA,SAC3B,YAAA,EAAc,2BAAA;EAAA,SACd,WAAA,EAAa,uBAAA;EAFc;;;;EAAA,SAQnC,UAAA;cAEG,YAAA,EAAc,2BAAA,EAA6B,UAAA;AAAA"}
|
package/dist/{MobileServerFailureError-f9KhKnJj.d.ts → MobileServerFailureError-MgYVBh5p.d.ts}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as MobileServerRequestType } from "./serverRequestTypes-DYTLrCpz.js";
|
|
2
|
+
import { t as MobileServerFailureResponse } from "./serverBaseTypes-CzRgwUvA.js";
|
|
2
3
|
import { BaseServerFailureError } from "@nadohq/shared";
|
|
3
4
|
|
|
4
5
|
//#region src/types/MobileServerFailureError.d.ts
|
|
@@ -19,4 +20,4 @@ declare class MobileServerFailureError extends BaseServerFailureError {
|
|
|
19
20
|
}
|
|
20
21
|
//#endregion
|
|
21
22
|
export { MobileServerFailureError as t };
|
|
22
|
-
//# sourceMappingURL=MobileServerFailureError-
|
|
23
|
+
//# sourceMappingURL=MobileServerFailureError-MgYVBh5p.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileServerFailureError-MgYVBh5p.d.ts","names":[],"sources":["../src/types/src/types/MobileServerFailureError.ts"],"mappings":";;;;;;;AASA;;;cAAa,wBAAA,SAAiC,sBAAA;EAAA,SAC3B,YAAA,EAAc,2BAAA;EAAA,SACd,WAAA,EAAa,uBAAA;EAFc;;;;EAAA,SAQnC,UAAA;cAEG,YAAA,EAAc,2BAAA,EAA6B,UAAA;AAAA"}
|
package/dist/{buildSignedMobileRequest-BsbBkU0K.d.cts → buildSignedMobileRequest-CBMt97aY.d.cts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as MobileSignedRequest, n as MobileSignedInner, t as BuildSignedMobileRequestParams } from "./types-
|
|
1
|
+
import { i as MobileSignedRequest, n as MobileSignedInner, t as BuildSignedMobileRequestParams } from "./types-bNB98pYk.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/signing/buildSignedMobileRequest.d.ts
|
|
4
4
|
/**
|
|
@@ -11,4 +11,4 @@ declare function buildSignedMobileRequest<T extends MobileSignedInner>(params: B
|
|
|
11
11
|
}): Promise<MobileSignedRequest<T>>;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { buildSignedMobileRequest as t };
|
|
14
|
-
//# sourceMappingURL=buildSignedMobileRequest-
|
|
14
|
+
//# sourceMappingURL=buildSignedMobileRequest-CBMt97aY.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSignedMobileRequest-
|
|
1
|
+
{"version":3,"file":"buildSignedMobileRequest-CBMt97aY.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"}
|
package/dist/{buildSignedMobileRequest-CDRsRNHm.d.ts → buildSignedMobileRequest-qEC4gWaI.d.ts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as MobileSignedRequest, n as MobileSignedInner, t as BuildSignedMobileRequestParams } from "./types-
|
|
1
|
+
import { i as MobileSignedRequest, n as MobileSignedInner, t as BuildSignedMobileRequestParams } from "./types-CQE3HD2V.js";
|
|
2
2
|
|
|
3
3
|
//#region src/signing/buildSignedMobileRequest.d.ts
|
|
4
4
|
/**
|
|
@@ -11,4 +11,4 @@ declare function buildSignedMobileRequest<T extends MobileSignedInner>(params: B
|
|
|
11
11
|
}): Promise<MobileSignedRequest<T>>;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { buildSignedMobileRequest as t };
|
|
14
|
-
//# sourceMappingURL=buildSignedMobileRequest-
|
|
14
|
+
//# sourceMappingURL=buildSignedMobileRequest-qEC4gWaI.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSignedMobileRequest-
|
|
1
|
+
{"version":3,"file":"buildSignedMobileRequest-qEC4gWaI.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"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { n as MobileSignedInner } from "./types-
|
|
1
|
+
import { n as MobileSignedInner } from "./types-bNB98pYk.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/signing/canonicalize.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Rebuilds an inner payload with its keys in the backend's struct declaration order (`type` first, then the
|
|
6
6
|
* remaining fields in the exact order the backend serializes them). msgpack encodes object keys in insertion
|
|
7
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
|
|
9
|
-
*
|
|
8
|
+
* every inner payload — and each of its sub-types — is canonicalized here before hashing. This function is
|
|
9
|
+
* the source of truth for that order.
|
|
10
10
|
*/
|
|
11
11
|
declare function canonicalizeMobileInner(inner: MobileSignedInner): MobileSignedInner;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { canonicalizeMobileInner as t };
|
|
14
|
-
//# sourceMappingURL=canonicalize-
|
|
14
|
+
//# sourceMappingURL=canonicalize-QNARV_Xc.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalize-QNARV_Xc.d.cts","names":[],"sources":["../src/signing/src/signing/canonicalize.ts"],"mappings":";;;;;AASA;;;;;iBAAgB,uBAAA,CACd,KAAA,EAAO,iBAAA,GACN,iBAAiB"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { n as MobileSignedInner } from "./types-
|
|
1
|
+
import { n as MobileSignedInner } from "./types-CQE3HD2V.js";
|
|
2
2
|
|
|
3
3
|
//#region src/signing/canonicalize.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Rebuilds an inner payload with its keys in the backend's struct declaration order (`type` first, then the
|
|
6
6
|
* remaining fields in the exact order the backend serializes them). msgpack encodes object keys in insertion
|
|
7
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
|
|
9
|
-
*
|
|
8
|
+
* every inner payload — and each of its sub-types — is canonicalized here before hashing. This function is
|
|
9
|
+
* the source of truth for that order.
|
|
10
10
|
*/
|
|
11
11
|
declare function canonicalizeMobileInner(inner: MobileSignedInner): MobileSignedInner;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { canonicalizeMobileInner as t };
|
|
14
|
-
//# sourceMappingURL=canonicalize-
|
|
14
|
+
//# sourceMappingURL=canonicalize-wVdGejB1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalize-wVdGejB1.d.ts","names":[],"sources":["../src/signing/src/signing/canonicalize.ts"],"mappings":";;;;;AASA;;;;;iBAAgB,uBAAA,CACd,KAAA,EAAO,iBAAA,GACN,iBAAiB"}
|