@textrp/briij-js-sdk 43.0.0 → 43.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +7 -4
  2. package/lib/@types/auth.d.ts +7 -5
  3. package/lib/@types/auth.d.ts.map +1 -1
  4. package/lib/@types/auth.js.map +1 -1
  5. package/lib/@types/event.d.ts +3 -32
  6. package/lib/@types/event.d.ts.map +1 -1
  7. package/lib/@types/event.js.map +1 -1
  8. package/lib/@types/synapse.d.ts +64 -0
  9. package/lib/@types/synapse.d.ts.map +1 -1
  10. package/lib/@types/synapse.js.map +1 -1
  11. package/lib/briij.d.ts +1 -0
  12. package/lib/briij.d.ts.map +1 -1
  13. package/lib/briij.js +1 -0
  14. package/lib/briij.js.map +1 -1
  15. package/lib/client.d.ts +72 -1
  16. package/lib/client.d.ts.map +1 -1
  17. package/lib/client.js +369 -196
  18. package/lib/client.js.map +1 -1
  19. package/lib/wallet-recovery.d.ts +1 -1
  20. package/lib/wallet-recovery.d.ts.map +1 -1
  21. package/lib/wallet-recovery.js +32 -8
  22. package/lib/wallet-recovery.js.map +1 -1
  23. package/lib/xrpl/identity.d.ts +2 -1
  24. package/lib/xrpl/identity.d.ts.map +1 -1
  25. package/lib/xrpl/identity.js +70 -47
  26. package/lib/xrpl/identity.js.map +1 -1
  27. package/lib/xrpl/trust.d.ts +4 -2
  28. package/lib/xrpl/trust.d.ts.map +1 -1
  29. package/lib/xrpl/trust.js +31 -19
  30. package/lib/xrpl/trust.js.map +1 -1
  31. package/lib/xrpl/verification.js +17 -6
  32. package/lib/xrpl/verification.js.map +1 -1
  33. package/package.json +127 -129
  34. package/src/@types/auth.ts +6 -7
  35. package/src/@types/event.ts +3 -32
  36. package/src/@types/synapse.ts +77 -0
  37. package/src/briij.ts +1 -0
  38. package/src/client.ts +261 -36
  39. package/src/wallet-recovery.ts +101 -26
  40. package/src/xrpl/identity.ts +66 -39
  41. package/src/xrpl/trust.ts +35 -18
  42. package/src/xrpl/verification.ts +19 -6
@@ -65,6 +65,7 @@ import { type LocalNotificationSettings } from "./local_notifications.ts";
65
65
  import { type IPushRules } from "./PushRules.ts";
66
66
  import { type SecretInfo, type SecretStorageKeyDescription } from "../secret-storage.ts";
67
67
  import { type POLICIES_ACCOUNT_EVENT_TYPE } from "../models/invites-ignorer-types.ts";
68
+ import { type WalletE2eeRecoveryEnvelope, type WalletIdentityAccountData } from "./auth.ts";
68
69
 
69
70
  export enum EventType {
70
71
  // Room state events
@@ -455,38 +456,8 @@ export interface AccountDataEvents extends SecretStorageAccountDataEvents {
455
456
  [POLICIES_ACCOUNT_EVENT_TYPE.altName]: { [key: string]: any };
456
457
 
457
458
  [EventType.InvitePermissionConfig]: { default_action?: string };
458
- "org.textrp.wallet.e2ee_recovery.v1": {
459
- envelope_version: number;
460
- chain_id: string;
461
- account_id: string;
462
- created_at_ms: number;
463
- key_id: string;
464
- wallet_wrap: {
465
- alg: string;
466
- kdf: string;
467
- salt: string;
468
- nonce: string;
469
- ciphertext: string;
470
- aad?: string;
471
- params?: Record<string, unknown>;
472
- };
473
- password_wrap: {
474
- alg: string;
475
- kdf: string;
476
- salt: string;
477
- nonce: string;
478
- ciphertext: string;
479
- aad?: string;
480
- params?: Record<string, unknown>;
481
- };
482
- };
483
- "org.textrp.wallet.identity": {
484
- chain_id: string;
485
- account_id: string;
486
- public_key: string | null;
487
- network?: string | null;
488
- key_type?: string | null;
489
- };
459
+ "org.textrp.wallet.e2ee_recovery.v1": WalletE2eeRecoveryEnvelope;
460
+ "org.textrp.wallet.identity": WalletIdentityAccountData;
490
461
  }
491
462
 
492
463
  /**
@@ -37,4 +37,81 @@ export interface ISynapseAdminWhoisResponse {
37
37
  export interface ISynapseAdminDeactivateResponse {
38
38
  id_server_unbind_result: IdServerUnbindResult;
39
39
  }
40
+
41
+ export interface IBriijPremiumFeature {
42
+ feature_id: number;
43
+ feature_key: string;
44
+ name: string;
45
+ description: string | null;
46
+ mcredits_cost: number;
47
+ category: string | null;
48
+ is_active: boolean;
49
+ created_ts: number;
50
+ }
51
+
52
+ export interface IBriijMcreditsFeature {
53
+ feature_key: string;
54
+ name: string;
55
+ description: string | null;
56
+ mcredits_cost: number;
57
+ category: string | null;
58
+ is_active: boolean;
59
+ }
60
+
61
+ export interface IBriijMcreditsFeaturesResponse {
62
+ features: IBriijMcreditsFeature[];
63
+ }
64
+
65
+ export interface IBriijMcreditsBalanceResponse {
66
+ balance: number;
67
+ }
68
+
69
+ export interface IBriijMcreditsSpendResponse {
70
+ feature_key: string;
71
+ balance: number;
72
+ }
73
+
74
+ export interface IBriijLegacyMyAddressUserCredit {
75
+ balance?: string;
76
+ }
77
+
78
+ export interface IBriijLegacyMyAddressUser {
79
+ address?: string;
80
+ discount?: Record<string, unknown>;
81
+ subscriptions?: unknown[];
82
+ credit?: IBriijLegacyMyAddressUserCredit;
83
+ }
84
+
85
+ export interface IBriijLegacyMyAddressResponse {
86
+ user: IBriijLegacyMyAddressUser;
87
+ address: string;
88
+ }
89
+
90
+ export interface IBriijLegacyEnabledFeature {
91
+ feature: string;
92
+ [key: string]: unknown;
93
+ }
94
+
95
+ export interface IBriijLegacyEnabledFeaturesResponse {
96
+ nfts?: IBriijLegacyEnabledFeature[];
97
+ [key: string]: unknown;
98
+ }
99
+
100
+ export interface IBriijAdminPremiumFeaturesResponse {
101
+ premium_features: IBriijPremiumFeature[];
102
+ }
103
+
104
+ export interface IBriijAdminCreatePremiumFeatureRequest {
105
+ feature_key: string;
106
+ name: string;
107
+ description?: string | null;
108
+ mcredits_cost: number;
109
+ category?: string | null;
110
+ }
111
+
112
+ export interface IBriijAdminUpdatePremiumFeatureRequest {
113
+ mcredits_cost?: number;
114
+ description?: string | null;
115
+ is_active?: boolean;
116
+ }
40
117
  /* eslint-enable camelcase */
package/src/briij.ts CHANGED
@@ -74,6 +74,7 @@ export * from "./@types/topic.ts";
74
74
  export * from "./@types/location.ts";
75
75
  export * from "./@types/threepids.ts";
76
76
  export * from "./@types/auth.ts";
77
+ export * from "./@types/synapse.ts";
77
78
  export * from "./@types/polls.ts";
78
79
  export type * from "./@types/local_notifications.ts";
79
80
  export type * from "./@types/registration.ts";
package/src/client.ts CHANGED
@@ -170,7 +170,19 @@ import {
170
170
  type IStateEventWithRoomId,
171
171
  SearchOrderBy,
172
172
  } from "./@types/search.ts";
173
- import { type ISynapseAdminDeactivateResponse, type ISynapseAdminWhoisResponse } from "./@types/synapse.ts";
173
+ import {
174
+ type IBriijAdminCreatePremiumFeatureRequest,
175
+ type IBriijAdminPremiumFeaturesResponse,
176
+ type IBriijAdminUpdatePremiumFeatureRequest,
177
+ type IBriijLegacyEnabledFeaturesResponse,
178
+ type IBriijLegacyMyAddressResponse,
179
+ type IBriijMcreditsBalanceResponse,
180
+ type IBriijMcreditsFeaturesResponse,
181
+ type IBriijMcreditsSpendResponse,
182
+ type IBriijPremiumFeature,
183
+ type ISynapseAdminDeactivateResponse,
184
+ type ISynapseAdminWhoisResponse,
185
+ } from "./@types/synapse.ts";
174
186
  import { type IHierarchyRoom } from "./@types/spaces.ts";
175
187
  import {
176
188
  type IPusher,
@@ -255,13 +267,14 @@ import {
255
267
  type OidcClientConfig,
256
268
  validateAuthMetadataAndKeys,
257
269
  } from "./oidc/index.ts";
258
- import { configureXrplIdentityMinting, mintSoulboundIdentityNFT } from "./xrpl/identity.ts";
259
270
  import {
260
- XRPL_VERIFIED_EVENT,
261
- XRPL_VERIFY_ACCEPT_EVENT,
262
- XRPL_VERIFY_REQUEST_EVENT,
263
- } from "./xrpl/verification.ts";
264
- import { configureXrplTrust } from "./xrpl/trust.ts";
271
+ getConfiguredXrplIdentityMintingConfig,
272
+ mintSoulboundIdentityNFT,
273
+ type XamanWalletAdapter,
274
+ type XrplIdentityMintingConfig,
275
+ } from "./xrpl/identity.ts";
276
+ import { XRPL_VERIFIED_EVENT, XRPL_VERIFY_ACCEPT_EVENT, XRPL_VERIFY_REQUEST_EVENT } from "./xrpl/verification.ts";
277
+ import { type XrplTrustConfig } from "./xrpl/trust.ts";
265
278
  import { type EmptyObject } from "./@types/common.ts";
266
279
  import { UnsupportedDelayedEventsEndpointError, UnsupportedStickyEventsEndpointError } from "./errors.ts";
267
280
  import { type Transport } from "./matrixrtc/index.ts";
@@ -289,6 +302,13 @@ export interface IKeysUploadResponse {
289
302
  export interface ICreateClientOpts {
290
303
  baseUrl: string;
291
304
 
305
+ /**
306
+ * Optional override for Briij legacy endpoints mounted at the homeserver root
307
+ * (for example `/my-address` and `/my-features/...`).
308
+ * Use this when `baseUrl` points to a local proxy origin.
309
+ */
310
+ legacyApiBaseUrl?: string;
311
+
292
312
  idBaseUrl?: string;
293
313
 
294
314
  /**
@@ -478,6 +498,17 @@ export interface ICreateClientOpts {
478
498
  * Defaults to the built-in global logger; see {@link DebugLogger} for an alternative.
479
499
  */
480
500
  logger?: Logger;
501
+
502
+ /**
503
+ * Optional per-client XRPL trust configuration.
504
+ */
505
+ xrplTrust?: Partial<XrplTrustConfig>;
506
+
507
+ /**
508
+ * Optional per-client XRPL identity minting configuration.
509
+ */
510
+ xrplIdentityMinting?: Partial<Omit<XrplIdentityMintingConfig, "homeserverBaseUrl" | "accessToken">>;
511
+ xamanWallet?: XamanWalletAdapter;
481
512
  }
482
513
 
483
514
  export interface IBriijClientCreateOpts extends ICreateClientOpts {
@@ -1269,6 +1300,7 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
1269
1300
  public iceCandidatePoolSize = 0; // XXX: Intended private, used in code.
1270
1301
  public idBaseUrl?: string;
1271
1302
  public baseUrl: string;
1303
+ private legacyApiBaseUrl?: string;
1272
1304
  public readonly isVoipWithNoMediaAllowed;
1273
1305
  public disableVoip: boolean;
1274
1306
 
@@ -1298,6 +1330,9 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
1298
1330
  protected clientOpts?: IStoredClientOpts;
1299
1331
  protected clientWellKnownIntervalID?: ReturnType<typeof setInterval>;
1300
1332
  protected canResetTimelineCallback?: ResetTimelineCallback;
1333
+ private xrplTrustConfig?: XrplTrustConfig;
1334
+ private xrplIdentityMintingConfig: Partial<Omit<XrplIdentityMintingConfig, "homeserverBaseUrl" | "accessToken">> =
1335
+ {};
1301
1336
 
1302
1337
  public canSupport = new Map<Feature, ServerSupport>();
1303
1338
 
@@ -1348,6 +1383,7 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
1348
1383
  opts.idBaseUrl = utils.ensureNoTrailingSlash(opts.idBaseUrl);
1349
1384
 
1350
1385
  this.baseUrl = opts.baseUrl;
1386
+ this.legacyApiBaseUrl = utils.ensureNoTrailingSlash(opts.legacyApiBaseUrl);
1351
1387
  this.idBaseUrl = opts.idBaseUrl;
1352
1388
  this.identityServer = opts.identityServer;
1353
1389
 
@@ -1358,6 +1394,17 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
1358
1394
 
1359
1395
  const userId = opts.userId || null;
1360
1396
  this.credentials = { userId };
1397
+ if (opts.xrplTrust) {
1398
+ this.xrplTrustConfig = {
1399
+ homeserverBaseUrl: opts.xrplTrust.homeserverBaseUrl ?? this.baseUrl,
1400
+ accessToken: opts.xrplTrust.accessToken ?? opts.accessToken ?? "",
1401
+ trustPath: opts.xrplTrust.trustPath,
1402
+ };
1403
+ }
1404
+ this.xrplIdentityMintingConfig = {
1405
+ ...(opts.xrplIdentityMinting ?? {}),
1406
+ ...(opts.xamanWallet ? { xamanWallet: opts.xamanWallet } : {}),
1407
+ };
1361
1408
 
1362
1409
  this.http = new BriijHttpApi(this as ConstructorParameters<typeof BriijHttpApi>[0], {
1363
1410
  fetchFn: opts.fetchFn,
@@ -6063,6 +6110,41 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
6063
6110
  return this.fallbackICEServerAllowed;
6064
6111
  }
6065
6112
 
6113
+ /**
6114
+ * Some briij deployments mount admin resources under `/_briij/admin` while
6115
+ * Synapse defaults to `/_synapse/admin`. Try both prefixes to stay compatible.
6116
+ */
6117
+ private async authedRequestWithAdminPrefixes<T>(
6118
+ method: Method,
6119
+ adminSubPath: string,
6120
+ queryParams?: QueryDict,
6121
+ body?: Body,
6122
+ ): Promise<T> {
6123
+ const normalizedSubPath = adminSubPath.replace(/^\/+/, "");
6124
+ const adminPrefixes = ["/_synapse/admin", "/_briij/admin"];
6125
+ let lastError: unknown;
6126
+
6127
+ for (const adminPrefix of adminPrefixes) {
6128
+ try {
6129
+ return await this.http.authedRequest<T>(
6130
+ method,
6131
+ `${adminPrefix}/${normalizedSubPath}`,
6132
+ queryParams,
6133
+ body,
6134
+ { prefix: "" },
6135
+ );
6136
+ } catch (error) {
6137
+ if (error instanceof BriijError && error.httpStatus === 404) {
6138
+ lastError = error;
6139
+ continue;
6140
+ }
6141
+ throw error;
6142
+ }
6143
+ }
6144
+
6145
+ throw lastError ?? new Error("Admin API endpoint not found");
6146
+ }
6147
+
6066
6148
  /**
6067
6149
  * Determines if the current user is an administrator of the Synapse homeserver.
6068
6150
  * Returns false if untrue or the homeserver does not appear to be a Synapse
@@ -6070,11 +6152,20 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
6070
6152
  * as a result.</strong>
6071
6153
  * @returns true if the user appears to be a Synapse administrator.
6072
6154
  */
6073
- public isSynapseAdministrator(): Promise<boolean> {
6074
- const path = utils.encodeUri("/_synapse/admin/v1/users/$userId/admin", { $userId: this.getUserId()! });
6075
- return this.http
6076
- .authedRequest<{ admin: boolean }>(Method.Get, path, undefined, undefined, { prefix: "" })
6077
- .then((r) => r.admin); // pull out the specific boolean we want
6155
+ public async isSynapseAdministrator(): Promise<boolean> {
6156
+ const adminSubPath = utils.encodeUri("v1/users/$userId/admin", { $userId: this.getUserId()! });
6157
+ try {
6158
+ const response = await this.authedRequestWithAdminPrefixes<{ admin: boolean }>(Method.Get, adminSubPath);
6159
+ return response.admin;
6160
+ } catch (error) {
6161
+ if (error instanceof BriijError && error.httpStatus === 404) {
6162
+ return false;
6163
+ }
6164
+ if (error instanceof Error && /Admin API endpoint not found/i.test(error.message)) {
6165
+ return false;
6166
+ }
6167
+ throw error;
6168
+ }
6078
6169
  }
6079
6170
 
6080
6171
  /**
@@ -6085,8 +6176,8 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
6085
6176
  * @returns the whois response - see Synapse docs for information.
6086
6177
  */
6087
6178
  public whoisSynapseUser(userId: string): Promise<ISynapseAdminWhoisResponse> {
6088
- const path = utils.encodeUri("/_synapse/admin/v1/whois/$userId", { $userId: userId });
6089
- return this.http.authedRequest(Method.Get, path, undefined, undefined, { prefix: "" });
6179
+ const adminSubPath = utils.encodeUri("v1/whois/$userId", { $userId: userId });
6180
+ return this.authedRequestWithAdminPrefixes(Method.Get, adminSubPath);
6090
6181
  }
6091
6182
 
6092
6183
  /**
@@ -6096,8 +6187,128 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
6096
6187
  * @returns the deactivate response - see Synapse docs for information.
6097
6188
  */
6098
6189
  public deactivateSynapseUser(userId: string): Promise<ISynapseAdminDeactivateResponse> {
6099
- const path = utils.encodeUri("/_synapse/admin/v1/deactivate/$userId", { $userId: userId });
6100
- return this.http.authedRequest(Method.Post, path, undefined, undefined, { prefix: "" });
6190
+ const adminSubPath = utils.encodeUri("v1/deactivate/$userId", { $userId: userId });
6191
+ return this.authedRequestWithAdminPrefixes(Method.Post, adminSubPath);
6192
+ }
6193
+
6194
+ /**
6195
+ * Lists active mCredits features for the authenticated user.
6196
+ */
6197
+ public getBriijMcreditsFeatures(): Promise<IBriijMcreditsFeaturesResponse> {
6198
+ return this.http.authedRequest(Method.Get, "/mcredits/features", undefined, undefined, {
6199
+ prefix: ClientPrefix.V3,
6200
+ });
6201
+ }
6202
+
6203
+ /**
6204
+ * Retrieves the authenticated user's mCredits balance.
6205
+ */
6206
+ public getBriijMcreditsBalance(): Promise<IBriijMcreditsBalanceResponse> {
6207
+ return this.http.authedRequest(Method.Get, "/mcredits/balance", undefined, undefined, {
6208
+ prefix: ClientPrefix.V3,
6209
+ });
6210
+ }
6211
+
6212
+ /**
6213
+ * Spends mCredits for a premium feature.
6214
+ * @param featureKey - The premium feature identifier to spend against.
6215
+ */
6216
+ public spendBriijMcredits(featureKey: string): Promise<IBriijMcreditsSpendResponse> {
6217
+ return this.http.authedRequest(
6218
+ Method.Post,
6219
+ "/mcredits/spend",
6220
+ undefined,
6221
+ { feature_key: featureKey },
6222
+ {
6223
+ prefix: ClientPrefix.V3,
6224
+ },
6225
+ );
6226
+ }
6227
+
6228
+ /**
6229
+ * Calls Briij's legacy-compatible endpoint to resolve a Matrix user to wallet/mcredit payload.
6230
+ * @param matrixUserId - Matrix user ID used by legacy clients.
6231
+ */
6232
+ public getBriijLegacyMyAddress(matrixUserId: string): Promise<IBriijLegacyMyAddressResponse> {
6233
+ return this.http.authedRequest(
6234
+ Method.Post,
6235
+ "/my-address",
6236
+ undefined,
6237
+ { address: matrixUserId },
6238
+ { prefix: "", baseUrl: this.getLegacyApiBaseUrl() },
6239
+ );
6240
+ }
6241
+
6242
+ /**
6243
+ * Calls Briij's legacy-compatible enabled-features endpoint.
6244
+ * @param walletAddress - XRPL wallet address.
6245
+ * @param network - Legacy network segment; defaults to `main`.
6246
+ */
6247
+ public getBriijLegacyEnabledFeatures(
6248
+ walletAddress: string,
6249
+ network = "main",
6250
+ ): Promise<IBriijLegacyEnabledFeaturesResponse> {
6251
+ const path = utils.encodeUri("/my-features/$walletAddress/$network/enabled", {
6252
+ $walletAddress: walletAddress,
6253
+ $network: network,
6254
+ });
6255
+ return this.http.authedRequest(Method.Get, path, undefined, undefined, {
6256
+ prefix: "",
6257
+ baseUrl: this.getLegacyApiBaseUrl(),
6258
+ });
6259
+ }
6260
+
6261
+ private getLegacyApiBaseUrl(): string {
6262
+ return (
6263
+ this.legacyApiBaseUrl ??
6264
+ utils.ensureNoTrailingSlash(this.xrplTrustConfig?.homeserverBaseUrl) ??
6265
+ this.baseUrl
6266
+ );
6267
+ }
6268
+
6269
+ /**
6270
+ * Lists mCredits premium features from Synapse admin APIs.
6271
+ */
6272
+ public async getBriijAdminPremiumFeatures(): Promise<IBriijPremiumFeature[]> {
6273
+ const response = await this.authedRequestWithAdminPrefixes<IBriijAdminPremiumFeaturesResponse>(
6274
+ Method.Get,
6275
+ "v2/briij/premium_features",
6276
+ );
6277
+ return response.premium_features;
6278
+ }
6279
+
6280
+ /**
6281
+ * Creates an mCredits premium feature via Synapse admin APIs.
6282
+ * @param body - Feature fields to create.
6283
+ */
6284
+ public createBriijAdminPremiumFeature(body: IBriijAdminCreatePremiumFeatureRequest): Promise<IBriijPremiumFeature> {
6285
+ return this.authedRequestWithAdminPrefixes(Method.Post, "v2/briij/premium_features", undefined, body);
6286
+ }
6287
+
6288
+ /**
6289
+ * Updates an mCredits premium feature via Synapse admin APIs.
6290
+ * @param featureKey - The premium feature key to update.
6291
+ * @param body - Updatable feature fields.
6292
+ */
6293
+ public updateBriijAdminPremiumFeature(
6294
+ featureKey: string,
6295
+ body: IBriijAdminUpdatePremiumFeatureRequest,
6296
+ ): Promise<IBriijPremiumFeature> {
6297
+ const adminSubPath = utils.encodeUri("v2/briij/premium_features/$featureKey", {
6298
+ $featureKey: featureKey,
6299
+ });
6300
+ return this.authedRequestWithAdminPrefixes(Method.Put, adminSubPath, undefined, body);
6301
+ }
6302
+
6303
+ /**
6304
+ * Soft-deactivates an mCredits premium feature via Synapse admin APIs.
6305
+ * @param featureKey - The premium feature key to deactivate.
6306
+ */
6307
+ public deactivateBriijAdminPremiumFeature(featureKey: string): Promise<IBriijPremiumFeature> {
6308
+ const adminSubPath = utils.encodeUri("v2/briij/premium_features/$featureKey", {
6309
+ $featureKey: featureKey,
6310
+ });
6311
+ return this.authedRequestWithAdminPrefixes(Method.Delete, adminSubPath);
6101
6312
  }
6102
6313
 
6103
6314
  protected async fetchClientWellKnown(): Promise<void> {
@@ -6687,32 +6898,44 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
6687
6898
  type: loginType,
6688
6899
  });
6689
6900
 
6690
- if (response.access_token && response.user_id) {
6691
- this.http.opts.accessToken = response.access_token;
6692
- this.credentials = {
6693
- userId: response.user_id,
6694
- };
6695
- configureXrplTrust({
6696
- homeserverBaseUrl: this.baseUrl,
6697
- accessToken: response.access_token,
6698
- });
6901
+ await this.applyLoginResponse(response, loginType);
6902
+
6903
+ return response;
6904
+ }
6905
+
6906
+ private async applyLoginResponse(response: LoginResponse, loginType?: LoginRequest["type"]): Promise<void> {
6907
+ if (!response.access_token || !response.user_id) {
6908
+ return;
6699
6909
  }
6700
6910
 
6911
+ this.http.opts.accessToken = response.access_token;
6912
+ this.credentials = {
6913
+ userId: response.user_id,
6914
+ };
6915
+ this.deviceId = response.device_id ?? this.deviceId;
6916
+ this.xrplTrustConfig = {
6917
+ homeserverBaseUrl: this.baseUrl,
6918
+ accessToken: response.access_token,
6919
+ trustPath: this.xrplTrustConfig?.trustPath,
6920
+ };
6921
+
6701
6922
  // After Xaman-backed SSO login, mint once and persist identity metadata in account_data.
6702
- if (loginType === "m.login.token" && response.access_token && response.user_id) {
6703
- configureXrplIdentityMinting({
6704
- homeserverBaseUrl: this.baseUrl,
6705
- accessToken: response.access_token,
6706
- });
6923
+ if (loginType === "m.login.token") {
6924
+ const fallbackMintingConfig = getConfiguredXrplIdentityMintingConfig();
6925
+ const xamanWallet = this.xrplIdentityMintingConfig.xamanWallet ?? fallbackMintingConfig.xamanWallet;
6707
6926
 
6708
6927
  try {
6709
- await mintSoulboundIdentityNFT(response.user_id);
6928
+ await mintSoulboundIdentityNFT(response.user_id, {
6929
+ ...fallbackMintingConfig,
6930
+ ...this.xrplIdentityMintingConfig,
6931
+ homeserverBaseUrl: this.baseUrl,
6932
+ accessToken: response.access_token,
6933
+ xamanWallet,
6934
+ });
6710
6935
  } catch (error) {
6711
6936
  logger.warn("XRPL identity NFT minting skipped/failed", error);
6712
6937
  }
6713
6938
  }
6714
-
6715
- return response;
6716
6939
  }
6717
6940
 
6718
6941
  /**
@@ -6781,8 +7004,8 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
6781
7004
  *
6782
7005
  * @param envelope - Wallet recovery envelope payload.
6783
7006
  */
6784
- public setWalletRecoveryEnvelope(envelope: WalletE2eeRecoveryEnvelope): Promise<EmptyObject> {
6785
- return this.setAccountDataRaw(WALLET_E2EE_RECOVERY_ACCOUNT_DATA_TYPE, envelope);
7007
+ public async setWalletRecoveryEnvelope(envelope: WalletE2eeRecoveryEnvelope): Promise<EmptyObject> {
7008
+ return await this.setAccountData(WALLET_E2EE_RECOVERY_ACCOUNT_DATA_TYPE, envelope);
6786
7009
  }
6787
7010
 
6788
7011
  /**
@@ -6831,7 +7054,7 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
6831
7054
  throw new Error("XRPL challenge payload is missing session; call getXrplAuthChallenge first");
6832
7055
  }
6833
7056
 
6834
- return this.completeXrplAuth({
7057
+ const response = await this.completeXrplAuth({
6835
7058
  user,
6836
7059
  identifier: {
6837
7060
  type: "m.id.user",
@@ -6843,6 +7066,8 @@ export class BriijClient extends TypedEventEmitter<EmittedEvents, ClientEventHan
6843
7066
  public_key: parsedChallenge?.public_key,
6844
7067
  network,
6845
7068
  });
7069
+ await this.applyLoginResponse(response, XRPL_WALLET_LOGIN_TYPE);
7070
+ return response;
6846
7071
  }
6847
7072
 
6848
7073
  /**