wallaby-cash 3.4.0 → 3.5.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/dist/base.d.ts +4 -1
- package/dist/index.cjs.js +74 -266
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +74 -266
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +74 -266
- package/dist/index.js.map +1 -1
- package/dist/lib/api/api.d.ts +2 -1
- package/dist/lib/auth/auth.service.d.ts +2 -1
- package/dist/lib/auth/passkey.service.base.d.ts +2 -1
- package/dist/lib/swap/index.d.ts +2 -1
- package/dist/lib/system/index.d.ts +3 -6
- package/dist/lib/transactions/index.d.ts +2 -1
- package/dist/lib/utils/index.d.ts +2 -1
- package/dist/lib/utils/is-jwt-expired.d.ts +3 -3
- package/dist/lib/utils/ports.d.ts +22 -0
- package/dist/lib/utils/storage.service.d.ts +0 -13
- package/dist/lib/wallet/wallet-data.service.d.ts +2 -1
- package/dist/lib/wallet/wallet-handlers.service.d.ts +2 -1
- package/dist/lib/wallet/wallet.service.d.ts +2 -2
- package/dist/package.json +2 -2
- package/dist/types/storage.d.ts +1 -3
- package/package.json +1 -1
- package/dist/lib/utils/extract-sui-asset-symbol.d.ts +0 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WallabyConfig } from './types';
|
|
2
|
+
import { Ports } from './lib/utils/ports';
|
|
2
3
|
import { AuthService, WalletService, WalletDataService, Utils } from './lib';
|
|
3
4
|
import { System } from './lib/system';
|
|
4
5
|
import { Transactions } from './lib/transactions';
|
|
@@ -63,6 +64,6 @@ export declare class Wallaby {
|
|
|
63
64
|
* @param {string} [config.clientAuthToken] - A web token generated by the client for authorization.
|
|
64
65
|
* @public
|
|
65
66
|
*/
|
|
66
|
-
constructor(config: WallabyConfig);
|
|
67
|
+
constructor(config: WallabyConfig, ports?: Partial<Ports>);
|
|
67
68
|
get version(): string;
|
|
68
69
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -315,8 +315,6 @@ var V2KeyNames;
|
|
|
315
315
|
V2KeyNames["LastMigratedAt"] = "wsdk_last_migrated_at";
|
|
316
316
|
V2KeyNames["PasswordResetAttempts"] = "wsdk_password_reset_attempts";
|
|
317
317
|
V2KeyNames["MigrationAttempts"] = "wsdk_migration_attempts";
|
|
318
|
-
V2KeyNames["CredentialConversionInProgress"] = "credential-conversion-in-progress";
|
|
319
|
-
V2KeyNames["PendingCommit"] = "pending-commit";
|
|
320
318
|
})(V2KeyNames || (V2KeyNames = {}));
|
|
321
319
|
|
|
322
320
|
var ErrorResponseCodes;
|
|
@@ -572,7 +570,6 @@ const defaultEnvironment = (_a = browser$1.env.NODE_ENV) !== null && _a !== void
|
|
|
572
570
|
* Please pass the network value in the WallabyConfigOptions object to override it for production-mainnet.
|
|
573
571
|
*/
|
|
574
572
|
const defaultNetwork = 'testnet';
|
|
575
|
-
const isTest = browser$1.env.NODE_ENV === 'test';
|
|
576
573
|
const DEFAULT_ENTROPY_BYTES$1 = 32;
|
|
577
574
|
const PBKDF2_ITERATIONS = 131072;
|
|
578
575
|
const DEFAULT_HOSTNAME = 'https://www.republic.com';
|
|
@@ -598,7 +595,7 @@ const env = {
|
|
|
598
595
|
isNative: !isWeb,
|
|
599
596
|
isWeb,
|
|
600
597
|
};
|
|
601
|
-
const currentPackageVersion = "3.
|
|
598
|
+
const currentPackageVersion = "3.3.0" ;
|
|
602
599
|
|
|
603
600
|
/**
|
|
604
601
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -3511,7 +3508,7 @@ const createPrivateKey = (entropy) => {
|
|
|
3511
3508
|
}
|
|
3512
3509
|
// Check byte diversity. This catches genuinely broken inputs (all-zeros, all-same-byte)
|
|
3513
3510
|
// without false-positiving on 32-byte KDF output (~30 unique bytes expected).
|
|
3514
|
-
// the sampled Shannon-entropy check was removed (WAL-1465) — it's unsound for
|
|
3511
|
+
// ponytail: the sampled Shannon-entropy check was removed (WAL-1465) — it's unsound for
|
|
3515
3512
|
// 32 samples (max measurable = log2(32) ≈ 5 bits/byte vs a 4-bit threshold), so deterministic
|
|
3516
3513
|
// KDF output could be rejected, permanently locking the user out.
|
|
3517
3514
|
const uniqueBytes = new Set(entropy);
|
|
@@ -4822,14 +4819,6 @@ class StorageService {
|
|
|
4822
4819
|
return;
|
|
4823
4820
|
}
|
|
4824
4821
|
async fetch(key, options) {
|
|
4825
|
-
var _a;
|
|
4826
|
-
// Recover once per session; memoize the promise so concurrent first-fetches all await the same
|
|
4827
|
-
// recovery instead of racing past it and reading pre-recovery storage. recoverCommit uses
|
|
4828
|
-
// getItem/removeItem (not fetch), so there's no recursion. Swallow errors: recovery is
|
|
4829
|
-
// best-effort and a failure must not wedge every subsequent fetch.
|
|
4830
|
-
await ((_a = this._walRecovery) !== null && _a !== void 0 ? _a : (this._walRecovery = this.recoverCommit().catch((error) => {
|
|
4831
|
-
logger.error('SDK::StorageService::fetch::wal recovery failed', error);
|
|
4832
|
-
})));
|
|
4833
4822
|
let storageKey;
|
|
4834
4823
|
if (this._walletSpecificKeys.includes(key)) {
|
|
4835
4824
|
if (!(options === null || options === void 0 ? void 0 : options.walletId)) {
|
|
@@ -4889,75 +4878,6 @@ class StorageService {
|
|
|
4889
4878
|
async saveInBulk(data) {
|
|
4890
4879
|
await Promise.all(data.map((item) => this.save(item.key, item.value, { walletId: item.walletId })));
|
|
4891
4880
|
}
|
|
4892
|
-
// Compute the final storage key the same way save/fetch/delete do.
|
|
4893
|
-
_computeRawKey(key, walletId) {
|
|
4894
|
-
let storageKey;
|
|
4895
|
-
if (this._walletSpecificKeys.includes(key)) {
|
|
4896
|
-
if (!walletId)
|
|
4897
|
-
throw new Error(`A walletId is required to compute key: ${key}`);
|
|
4898
|
-
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}:${walletId}`;
|
|
4899
|
-
}
|
|
4900
|
-
else {
|
|
4901
|
-
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}`;
|
|
4902
|
-
}
|
|
4903
|
-
return isWeb ? storageKey : normalizeKey(storageKey);
|
|
4904
|
-
}
|
|
4905
|
-
_serializeValue(key, value) {
|
|
4906
|
-
if (this._keysProtectedByMasterKey.includes(key)) {
|
|
4907
|
-
return this.cipher.encryptWithMasterKey({ data: value });
|
|
4908
|
-
}
|
|
4909
|
-
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
4910
|
-
}
|
|
4911
|
-
async _applyWAL(record) {
|
|
4912
|
-
for (const { rawKey, value } of record.writes) {
|
|
4913
|
-
await this.setItem(rawKey, value);
|
|
4914
|
-
}
|
|
4915
|
-
for (const rawKey of record.deletes) {
|
|
4916
|
-
await this.removeItem(rawKey);
|
|
4917
|
-
}
|
|
4918
|
-
}
|
|
4919
|
-
// Atomically commit a batch of writes and deletes via a write-ahead log.
|
|
4920
|
-
// The WAL record is written in a single setItem before any credential key is
|
|
4921
|
-
// touched. A crash between that write and the individual setItem calls leaves
|
|
4922
|
-
// the WAL in place; recoverCommit() finishes the batch on the next call.
|
|
4923
|
-
async commitBatch(writes, deletes) {
|
|
4924
|
-
const record = {
|
|
4925
|
-
writes: writes.map(({ key, value, walletId }) => ({
|
|
4926
|
-
rawKey: this._computeRawKey(key, walletId),
|
|
4927
|
-
value: this._serializeValue(key, value),
|
|
4928
|
-
})),
|
|
4929
|
-
deletes: (deletes !== null && deletes !== void 0 ? deletes : []).map(({ key, walletId }) => this._computeRawKey(key, walletId)),
|
|
4930
|
-
};
|
|
4931
|
-
// Finish any dangling WAL from a prior partially-applied commit before writing a new one —
|
|
4932
|
-
// otherwise this setItem clobbers it and those half-written credentials become unrecoverable.
|
|
4933
|
-
await this.recoverCommit();
|
|
4934
|
-
const walKey = this._computeRawKey(V2KeyNames.PendingCommit);
|
|
4935
|
-
await this.setItem(walKey, JSON.stringify(record));
|
|
4936
|
-
await this._applyWAL(record);
|
|
4937
|
-
await this.removeItem(walKey);
|
|
4938
|
-
}
|
|
4939
|
-
// Re-apply a pending WAL commit if the process was killed mid-batch.
|
|
4940
|
-
// Call at the start of any operation that writes credential blobs.
|
|
4941
|
-
async recoverCommit() {
|
|
4942
|
-
const walKey = this._computeRawKey(V2KeyNames.PendingCommit);
|
|
4943
|
-
const raw = await this.getItem(walKey);
|
|
4944
|
-
if (!raw)
|
|
4945
|
-
return;
|
|
4946
|
-
let record;
|
|
4947
|
-
try {
|
|
4948
|
-
record = safeJsonParse(raw);
|
|
4949
|
-
}
|
|
4950
|
-
catch (error) {
|
|
4951
|
-
// Corrupt/unparseable WAL can never be replayed — discard so it doesn't wedge every fetch.
|
|
4952
|
-
logger.error('SDK::StorageService::recoverCommit::corrupt WAL, discarding', error);
|
|
4953
|
-
await this.removeItem(walKey);
|
|
4954
|
-
return;
|
|
4955
|
-
}
|
|
4956
|
-
// _applyWAL is idempotent. If it throws (transient storage error) keep the WAL and let the
|
|
4957
|
-
// caller retry — don't delete the only record needed to finish the batch. Remove only on success.
|
|
4958
|
-
await this._applyWAL(record);
|
|
4959
|
-
await this.removeItem(walKey);
|
|
4960
|
-
}
|
|
4961
4881
|
async delete(key, options) {
|
|
4962
4882
|
let storageKey;
|
|
4963
4883
|
if (this._walletSpecificKeys.includes(key)) {
|
|
@@ -5242,8 +5162,6 @@ class StorageService {
|
|
|
5242
5162
|
V2KeyNames.ClientAuthToken,
|
|
5243
5163
|
V2KeyNames.PasswordResetAttempts,
|
|
5244
5164
|
V2KeyNames.MigrationAttempts,
|
|
5245
|
-
V2KeyNames.CredentialConversionInProgress,
|
|
5246
|
-
V2KeyNames.PendingCommit,
|
|
5247
5165
|
];
|
|
5248
5166
|
await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
|
|
5249
5167
|
if (walletId) {
|
|
@@ -5290,11 +5208,11 @@ class StorageService {
|
|
|
5290
5208
|
* @param jwt - The JWT string to check. If null, the function will return true.
|
|
5291
5209
|
* @returns `true` if the JWT has expired or is null, otherwise `false`.
|
|
5292
5210
|
*/
|
|
5293
|
-
function jwtHasExpired(jwt) {
|
|
5211
|
+
function jwtHasExpired(jwt, now = Date.now) {
|
|
5294
5212
|
if (!jwt) {
|
|
5295
5213
|
return true;
|
|
5296
5214
|
}
|
|
5297
|
-
return millisecondsToJWTTimeout(jwt) <= 0;
|
|
5215
|
+
return millisecondsToJWTTimeout(jwt, now) <= 0;
|
|
5298
5216
|
}
|
|
5299
5217
|
function jwtHasSameUser(jwt, userId) {
|
|
5300
5218
|
if (!jwt || !userId) {
|
|
@@ -5314,11 +5232,11 @@ function userIsMfaVerified(jwt) {
|
|
|
5314
5232
|
* @param thresholdSeconds - Number of seconds before expiry to consider "near expiry".
|
|
5315
5233
|
* @returns `true` if the JWT expires within `thresholdSeconds` seconds, otherwise `false`.
|
|
5316
5234
|
*/
|
|
5317
|
-
function isJwtNearExpiry(jwt, thresholdSeconds) {
|
|
5235
|
+
function isJwtNearExpiry(jwt, thresholdSeconds, now = Date.now) {
|
|
5318
5236
|
if (!jwt) {
|
|
5319
5237
|
return false;
|
|
5320
5238
|
}
|
|
5321
|
-
return millisecondsToJWTTimeout(jwt) <= thresholdSeconds * 1000;
|
|
5239
|
+
return millisecondsToJWTTimeout(jwt, now) <= thresholdSeconds * 1000;
|
|
5322
5240
|
}
|
|
5323
5241
|
/**
|
|
5324
5242
|
* Calculates the remaining time in milliseconds until a given JWT expires.
|
|
@@ -5326,11 +5244,11 @@ function isJwtNearExpiry(jwt, thresholdSeconds) {
|
|
|
5326
5244
|
* @param jwt - The JWT string to decode and check.
|
|
5327
5245
|
* @returns The number of milliseconds until the JWT expires. If the JWT has already expired, the returned value will be less than or equal to 0.
|
|
5328
5246
|
*/
|
|
5329
|
-
function millisecondsToJWTTimeout(jwt) {
|
|
5247
|
+
function millisecondsToJWTTimeout(jwt, now = Date.now) {
|
|
5330
5248
|
const jwtDecoded = jwtDecode(jwt);
|
|
5331
5249
|
const jwtExpirationTimeSeconds = jwtDecoded.exp;
|
|
5332
5250
|
const jwtExpirationTimeMilliseconds = (jwtExpirationTimeSeconds !== null && jwtExpirationTimeSeconds !== void 0 ? jwtExpirationTimeSeconds : 0) * 1000;
|
|
5333
|
-
const timeNowMilliseconds =
|
|
5251
|
+
const timeNowMilliseconds = now();
|
|
5334
5252
|
return jwtExpirationTimeMilliseconds - timeNowMilliseconds;
|
|
5335
5253
|
}
|
|
5336
5254
|
|
|
@@ -6979,8 +6897,8 @@ function shouldClearTokensAfterRefreshFailure(error) {
|
|
|
6979
6897
|
// Module-level dedupe manager for token refresh to ensure only one refresh request per user/environment/network at a time
|
|
6980
6898
|
const refreshDedupeManager = new DedupeManagerService();
|
|
6981
6899
|
class Base {
|
|
6982
|
-
constructor(config) {
|
|
6983
|
-
var _a, _b;
|
|
6900
|
+
constructor(config, ports = {}) {
|
|
6901
|
+
var _a, _b, _c, _d, _e;
|
|
6984
6902
|
const sanitizedConfig = sanitizeConfig(config);
|
|
6985
6903
|
this.apiKey = sanitizedConfig.apiKey;
|
|
6986
6904
|
this.baseUrl = sanitizedConfig.baseUrl;
|
|
@@ -6991,7 +6909,9 @@ class Base {
|
|
|
6991
6909
|
env.isNative = this.options.platform === 'ios' || this.options.platform === 'android';
|
|
6992
6910
|
env.isWeb = !env.isNative;
|
|
6993
6911
|
}
|
|
6994
|
-
this.cipher = new Cipher();
|
|
6912
|
+
this.cipher = (_b = ports.cipher) !== null && _b !== void 0 ? _b : new Cipher();
|
|
6913
|
+
this.transport = (_c = ports.transport) !== null && _c !== void 0 ? _c : ((...args) => fetch(...args));
|
|
6914
|
+
this.clock = (_d = ports.clock) !== null && _d !== void 0 ? _d : { now: () => Date.now() };
|
|
6995
6915
|
this.lockManager = new LockManagerService();
|
|
6996
6916
|
this._initializeClientAuthToken(sanitizedConfig.clientAuthToken);
|
|
6997
6917
|
this.request = this.request.bind(this);
|
|
@@ -7005,6 +6925,7 @@ class Base {
|
|
|
7005
6925
|
secure: true, // Enable security worker for all requests by default
|
|
7006
6926
|
},
|
|
7007
6927
|
securityWorker: this.securityWorker.bind(this),
|
|
6928
|
+
customFetch: this.transport,
|
|
7008
6929
|
});
|
|
7009
6930
|
/**
|
|
7010
6931
|
* This intercepts all API responses and transforms errors into WallabyError format.
|
|
@@ -7049,7 +6970,7 @@ class Base {
|
|
|
7049
6970
|
return attemptRequest(false);
|
|
7050
6971
|
};
|
|
7051
6972
|
this.api = new Api(httpClient);
|
|
7052
|
-
this.api.http.setSecurityData(Object.assign({ 'x-api-key': config.apiKey, 'x-client-jwt': config.clientAuthToken }, (
|
|
6973
|
+
this.api.http.setSecurityData(Object.assign({ 'x-api-key': config.apiKey, 'x-client-jwt': config.clientAuthToken }, (_e = this.options) === null || _e === void 0 ? void 0 : _e.headers));
|
|
7053
6974
|
}
|
|
7054
6975
|
set setClientAuthToken(token) {
|
|
7055
6976
|
this._initializeClientAuthToken(token);
|
|
@@ -7168,7 +7089,7 @@ class Base {
|
|
|
7168
7089
|
// Proactive token refresh: if access token is near expiry, refresh before making the request
|
|
7169
7090
|
if (route !== AuthRoutes.refreshAccessToken && !retried) {
|
|
7170
7091
|
const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
|
|
7171
|
-
if (accessToken && isJwtNearExpiry(accessToken, 60)) {
|
|
7092
|
+
if (accessToken && isJwtNearExpiry(accessToken, 60, this.clock.now)) {
|
|
7172
7093
|
await this._performTokenRefresh();
|
|
7173
7094
|
}
|
|
7174
7095
|
}
|
|
@@ -7192,7 +7113,7 @@ class Base {
|
|
|
7192
7113
|
fetchOptions.body = JSON.stringify(options.payload);
|
|
7193
7114
|
}
|
|
7194
7115
|
logger.debug(`SDK::Base::${route.method}::Request`, { path: fullUrl, payload: options === null || options === void 0 ? void 0 : options.payload });
|
|
7195
|
-
const response = await
|
|
7116
|
+
const response = await this.transport(fullUrl, fetchOptions);
|
|
7196
7117
|
const contentType = response.headers.get('content-type');
|
|
7197
7118
|
let data;
|
|
7198
7119
|
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json')) {
|
|
@@ -7263,7 +7184,7 @@ class Base {
|
|
|
7263
7184
|
}
|
|
7264
7185
|
async _getRequestHeaders() {
|
|
7265
7186
|
const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
|
|
7266
|
-
if (
|
|
7187
|
+
if (jwtHasExpired(this.clientAuthToken, this.clock.now)) {
|
|
7267
7188
|
throw new WallabyError({
|
|
7268
7189
|
message: 'Auth token has expired',
|
|
7269
7190
|
statusCode: 401,
|
|
@@ -7285,7 +7206,7 @@ class Base {
|
|
|
7285
7206
|
// Proactive token refresh before building headers for the generated client
|
|
7286
7207
|
try {
|
|
7287
7208
|
const accessToken = await this.localStorageService.fetch(LocalStorageItems.AccessToken);
|
|
7288
|
-
if (accessToken && isJwtNearExpiry(accessToken, 60)) {
|
|
7209
|
+
if (accessToken && isJwtNearExpiry(accessToken, 60, this.clock.now)) {
|
|
7289
7210
|
await this._performTokenRefresh();
|
|
7290
7211
|
}
|
|
7291
7212
|
}
|
|
@@ -7666,8 +7587,8 @@ function decodeBase64URL(base64url) {
|
|
|
7666
7587
|
}
|
|
7667
7588
|
|
|
7668
7589
|
class PasskeyService {
|
|
7669
|
-
constructor(userId, storageService, request) {
|
|
7670
|
-
this.cipher =
|
|
7590
|
+
constructor(userId, storageService, request, cipher = new Cipher()) {
|
|
7591
|
+
this.cipher = cipher;
|
|
7671
7592
|
this.localStorageService = storageService;
|
|
7672
7593
|
this.userId = userId;
|
|
7673
7594
|
this.request = request;
|
|
@@ -8189,10 +8110,10 @@ function WithLock(lockKey) {
|
|
|
8189
8110
|
}
|
|
8190
8111
|
|
|
8191
8112
|
class AuthService extends Base {
|
|
8192
|
-
constructor(config) {
|
|
8193
|
-
super(config);
|
|
8113
|
+
constructor(config, ports = {}) {
|
|
8114
|
+
super(config, ports);
|
|
8194
8115
|
this.getUserSalt = this.getUserSalt.bind(this);
|
|
8195
|
-
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request);
|
|
8116
|
+
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request, this.cipher);
|
|
8196
8117
|
}
|
|
8197
8118
|
/**
|
|
8198
8119
|
* @description
|
|
@@ -8779,9 +8700,9 @@ function assertBackupSharePayloadShape(encrypted) {
|
|
|
8779
8700
|
}
|
|
8780
8701
|
}
|
|
8781
8702
|
class WalletHandlersService extends Base {
|
|
8782
|
-
constructor(config) {
|
|
8783
|
-
super(config);
|
|
8784
|
-
this.authService = new AuthService(config);
|
|
8703
|
+
constructor(config, ports = {}) {
|
|
8704
|
+
super(config, ports);
|
|
8705
|
+
this.authService = new AuthService(config, ports);
|
|
8785
8706
|
this.userId = config.userId;
|
|
8786
8707
|
}
|
|
8787
8708
|
async handleImportWallet(deviceAuthKeys, importWalletInput) {
|
|
@@ -9087,12 +9008,12 @@ class WalletHandlersService extends Base {
|
|
|
9087
9008
|
}
|
|
9088
9009
|
|
|
9089
9010
|
class WalletService extends Base {
|
|
9090
|
-
constructor(config) {
|
|
9091
|
-
super(config);
|
|
9092
|
-
this.authService = new AuthService(config);
|
|
9093
|
-
this.handlers = new WalletHandlersService(config);
|
|
9011
|
+
constructor(config, ports = {}) {
|
|
9012
|
+
super(config, ports);
|
|
9013
|
+
this.authService = new AuthService(config, ports);
|
|
9014
|
+
this.handlers = new WalletHandlersService(config, ports);
|
|
9094
9015
|
this.userId = config.userId;
|
|
9095
|
-
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request);
|
|
9016
|
+
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request, this.cipher);
|
|
9096
9017
|
}
|
|
9097
9018
|
/**
|
|
9098
9019
|
* Reads the persisted sliding-window rate-limit state for a counter key.
|
|
@@ -9613,7 +9534,7 @@ class WalletService extends Base {
|
|
|
9613
9534
|
password: newPassword,
|
|
9614
9535
|
salt: clientSalt,
|
|
9615
9536
|
});
|
|
9616
|
-
if (!newCredentialsKeyPair.publicKey
|
|
9537
|
+
if (!newCredentialsKeyPair.publicKey) {
|
|
9617
9538
|
throw new WallabyError({
|
|
9618
9539
|
message: 'Could not derive keys for new password.',
|
|
9619
9540
|
statusCode: 500,
|
|
@@ -9636,9 +9557,6 @@ class WalletService extends Base {
|
|
|
9636
9557
|
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
9637
9558
|
});
|
|
9638
9559
|
}
|
|
9639
|
-
// Round-trip validate: decrypt the re-wrapped blob with the new key before committing.
|
|
9640
|
-
// Catches a malformed re-encryption before it overwrites the live credential.
|
|
9641
|
-
await this.assertRoundTrip(reWrappedDevicePrivateKey, newCredentialsKeyPair.privateKey, 'device key');
|
|
9642
9560
|
const reWrappedSeedPhrase = encryptedSeedPhraseString
|
|
9643
9561
|
? await this.cipher.flipEncryptedData({
|
|
9644
9562
|
cipherText: safeJsonParse(encryptedSeedPhraseString),
|
|
@@ -9660,13 +9578,9 @@ class WalletService extends Base {
|
|
|
9660
9578
|
encryptionKey: newCredentialsKeyPair.publicKey,
|
|
9661
9579
|
})
|
|
9662
9580
|
: null;
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
await this.assertRoundTrip(reWrappedPrimaryShare, newCredentialsKeyPair.privateKey, 'primary share');
|
|
9667
|
-
if (reWrappedBackupShare)
|
|
9668
|
-
await this.assertRoundTrip(reWrappedBackupShare, newCredentialsKeyPair.privateKey, 'backup share');
|
|
9669
|
-
await this.localStorageService.commitBatch([
|
|
9581
|
+
// Commit all re-wrapped blobs in one batch so a partial failure cannot leave the device
|
|
9582
|
+
// in a half-migrated state (some items under the new password, others under the old).
|
|
9583
|
+
await this.localStorageService.saveInBulk([
|
|
9670
9584
|
{ key: LocalStorageItems.EncryptedDevicePrivateKey, value: reWrappedDevicePrivateKey },
|
|
9671
9585
|
...(reWrappedSeedPhrase
|
|
9672
9586
|
? [{ key: LocalStorageItems.EncryptedStandardSeedPhrase, value: reWrappedSeedPhrase, walletId }]
|
|
@@ -10251,28 +10165,7 @@ class WalletService extends Base {
|
|
|
10251
10165
|
* @returns { boolean } whether the operation was successful
|
|
10252
10166
|
*/
|
|
10253
10167
|
async convertToPasskey(input) {
|
|
10254
|
-
let passkeyRegistered = false;
|
|
10255
10168
|
try {
|
|
10256
|
-
// Recover an interrupted conversion BEFORE reading any credential blob. A prior attempt may have
|
|
10257
|
-
// already rewrapped EncryptedDevicePrivateKey to passkey form (addNewPasskey persists it outside
|
|
10258
|
-
// this method's atomic commit), which the password can no longer decrypt — and deriving the passkey
|
|
10259
|
-
// key to decrypt it needs the device key itself (circular). The marker stashes the original
|
|
10260
|
-
// password-encrypted device key; restore it so the rest of the flow runs as a fresh conversion.
|
|
10261
|
-
const rawConversionMarker = (await this.localStorageService.fetch(V2KeyNames.CredentialConversionInProgress));
|
|
10262
|
-
const existingConversionMarker = rawConversionMarker
|
|
10263
|
-
? safeJsonParse(rawConversionMarker)
|
|
10264
|
-
: undefined;
|
|
10265
|
-
// Restore the stashed device key whenever a marker carries one — independent of walletId. The
|
|
10266
|
-
// device key is per-user (not wallet-scoped), so a conversion interrupted on a different wallet
|
|
10267
|
-
// leaves the shared device key passkey-wrapped too. Restoring is idempotent (rewrites the
|
|
10268
|
-
// original password-encrypted blob) and stops a second wallet's conversion from destroying the
|
|
10269
|
-
// first's recovery state. v2 only — a v1 wallet's untouched v1 key still decrypts.
|
|
10270
|
-
if (existingConversionMarker === null || existingConversionMarker === void 0 ? void 0 : existingConversionMarker.encryptedDevicePrivateKey) {
|
|
10271
|
-
await this.localStorageService.save(LocalStorageItems.EncryptedDevicePrivateKey, existingConversionMarker.encryptedDevicePrivateKey);
|
|
10272
|
-
}
|
|
10273
|
-
if ((existingConversionMarker === null || existingConversionMarker === void 0 ? void 0 : existingConversionMarker.walletId) === input.walletId) {
|
|
10274
|
-
logger.info('SDK::WalletService::convertToPasskey::resuming interrupted conversion');
|
|
10275
|
-
}
|
|
10276
10169
|
const v2EncryptedPriv = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
|
|
10277
10170
|
const v2EncryptedSeed = await this.localStorageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase, {
|
|
10278
10171
|
walletId: input.walletId,
|
|
@@ -10321,10 +10214,6 @@ class WalletService extends Base {
|
|
|
10321
10214
|
});
|
|
10322
10215
|
}
|
|
10323
10216
|
const clientPublicKey = publicKeyByPrivateKey(decryptedClientAuthPrivKey);
|
|
10324
|
-
// Write-ahead marker: set before the unrevocable passkey registration so an interrupted
|
|
10325
|
-
// conversion can be resumed on the next attempt. Stash the original password-encrypted device
|
|
10326
|
-
// key so resume survives addNewPasskey rewrapping the stored device key to passkey form.
|
|
10327
|
-
await this.localStorageService.save(V2KeyNames.CredentialConversionInProgress, Object.assign({ walletId: input.walletId }, (v2EncryptedPriv ? { encryptedDevicePrivateKey: v2EncryptedPriv } : {})));
|
|
10328
10217
|
const authentication = await this.passkeyService.addNewPasskey({
|
|
10329
10218
|
deviceKeyPair: {
|
|
10330
10219
|
publicKey: clientPublicKey,
|
|
@@ -10332,7 +10221,6 @@ class WalletService extends Base {
|
|
|
10332
10221
|
},
|
|
10333
10222
|
getSignature: this.authService.getSignature.bind(this),
|
|
10334
10223
|
});
|
|
10335
|
-
passkeyRegistered = true;
|
|
10336
10224
|
const prfValue = authentication.prfValue;
|
|
10337
10225
|
if (!prfValue || !(prfValue instanceof Uint8Array) || prfValue.length === 0) {
|
|
10338
10226
|
logger.error('SDK::WalletService::convertToPasskey::prfValue is required and must be a non-empty Uint8Array');
|
|
@@ -10429,13 +10317,8 @@ class WalletService extends Base {
|
|
|
10429
10317
|
storeOneKeyShareWithWallaby: true,
|
|
10430
10318
|
},
|
|
10431
10319
|
});
|
|
10432
|
-
//
|
|
10433
|
-
|
|
10434
|
-
// safely; this atomic delete clears the stale seed + marker together.
|
|
10435
|
-
await this.localStorageService.commitBatch([], [
|
|
10436
|
-
{ key: LocalStorageItems.EncryptedStandardSeedPhrase, walletId: input.walletId },
|
|
10437
|
-
{ key: V2KeyNames.CredentialConversionInProgress },
|
|
10438
|
-
]);
|
|
10320
|
+
// Delete the old password-encrypted seed phrase since import stored the new passkey-encrypted version
|
|
10321
|
+
await this.localStorageService.delete(LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
|
|
10439
10322
|
logger.info('SDK::WalletService::convertToPasskey::Wallet imported and converted successfully, old seed phrase removed');
|
|
10440
10323
|
return { authentication, seedPhrase: decryptedSeedPhrase };
|
|
10441
10324
|
}
|
|
@@ -10453,24 +10336,6 @@ class WalletService extends Base {
|
|
|
10453
10336
|
privateKey: decryptedClientAuthPrivKey,
|
|
10454
10337
|
},
|
|
10455
10338
|
});
|
|
10456
|
-
// assertRoundTrip below only strips the outer (passkey) layer — validate the inner (device key) layer here.
|
|
10457
|
-
const outerDecrypted = await this.cipher.decrypt({
|
|
10458
|
-
cipherText: encryptedPrimaryShare,
|
|
10459
|
-
decryptionKey: passkeyDerivedKeyPair.privateKey,
|
|
10460
|
-
});
|
|
10461
|
-
const innerDecrypted = outerDecrypted
|
|
10462
|
-
? await this.cipher.decrypt({
|
|
10463
|
-
cipherText: safeJsonParse(outerDecrypted),
|
|
10464
|
-
decryptionKey: decryptedClientAuthPrivKey,
|
|
10465
|
-
})
|
|
10466
|
-
: null;
|
|
10467
|
-
if (innerDecrypted !== decryptedPrimaryShare) {
|
|
10468
|
-
throw new WallabyError({
|
|
10469
|
-
message: 'Re-wrap validation failed for primary share: inner layer round-trip mismatch. Aborting to prevent credential corruption.',
|
|
10470
|
-
statusCode: 500,
|
|
10471
|
-
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
10472
|
-
});
|
|
10473
|
-
}
|
|
10474
10339
|
convertedShares.push({
|
|
10475
10340
|
key: V2KeyNames.PrimaryDeviceKeyShare,
|
|
10476
10341
|
value: encryptedPrimaryShare,
|
|
@@ -10489,16 +10354,9 @@ class WalletService extends Base {
|
|
|
10489
10354
|
walletId: input.walletId,
|
|
10490
10355
|
});
|
|
10491
10356
|
}
|
|
10492
|
-
|
|
10493
|
-
// A failed decrypt here means re-encryption produced an unreadable blob — abort before overwriting live credentials.
|
|
10494
|
-
for (const share of convertedShares) {
|
|
10495
|
-
await this.assertRoundTrip(share.value, passkeyDerivedKeyPair.privateKey, share.key);
|
|
10496
|
-
}
|
|
10497
|
-
await this.localStorageService.commitBatch(convertedShares, [
|
|
10498
|
-
...(v2EncryptedSeed ? [{ key: LocalStorageItems.EncryptedStandardSeedPhrase, walletId: input.walletId }] : []),
|
|
10499
|
-
{ key: V2KeyNames.CredentialConversionInProgress },
|
|
10500
|
-
]);
|
|
10357
|
+
await this.localStorageService.saveInBulk(convertedShares);
|
|
10501
10358
|
if (v2EncryptedSeed) {
|
|
10359
|
+
await this.localStorageService.delete(LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
|
|
10502
10360
|
logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
|
|
10503
10361
|
}
|
|
10504
10362
|
if (!decryptedSeedPhrase && decryptedPrimaryShare) {
|
|
@@ -10541,30 +10399,11 @@ class WalletService extends Base {
|
|
|
10541
10399
|
}
|
|
10542
10400
|
catch (error) {
|
|
10543
10401
|
logger.error('SDK::WalletService::convertToPasskey::error', error);
|
|
10544
|
-
// Only clear the marker if the passkey was not yet registered. After registration the
|
|
10545
|
-
// marker must survive for roll-forward on the next attempt.
|
|
10546
|
-
if (!passkeyRegistered) {
|
|
10547
|
-
await this.localStorageService.delete(V2KeyNames.CredentialConversionInProgress);
|
|
10548
|
-
}
|
|
10549
10402
|
throw error;
|
|
10550
10403
|
}
|
|
10551
10404
|
}
|
|
10552
|
-
// shared guard — decrypt-tests a re-wrapped blob before any write so a malformed
|
|
10553
|
-
// re-encryption is caught before it overwrites the live credential.
|
|
10554
|
-
async assertRoundTrip(blob, decryptionKey, label) {
|
|
10555
|
-
try {
|
|
10556
|
-
await this.cipher.decrypt({ cipherText: blob, decryptionKey });
|
|
10557
|
-
}
|
|
10558
|
-
catch (_a) {
|
|
10559
|
-
throw new WallabyError({
|
|
10560
|
-
message: `Re-wrap validation failed for ${label}: decryption of the re-encrypted blob failed. Aborting to prevent credential corruption.`,
|
|
10561
|
-
statusCode: 500,
|
|
10562
|
-
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
10563
|
-
});
|
|
10564
|
-
}
|
|
10565
|
-
}
|
|
10566
10405
|
}
|
|
10567
|
-
// soft client-side guardrail against runaway retries; server-side rate limiting is the real control.
|
|
10406
|
+
// ponytail: soft client-side guardrail against runaway retries; server-side rate limiting is the real control.
|
|
10568
10407
|
// Counters are persisted (sliding window) so rebuilding the service no longer resets them. Tune freely.
|
|
10569
10408
|
WalletService.RATE_LIMIT_MAX = 5;
|
|
10570
10409
|
WalletService.RATE_LIMIT_WINDOW_MS = 30 * 60000; // 30 min
|
|
@@ -10587,7 +10426,7 @@ __decorate([
|
|
|
10587
10426
|
__metadata("design:returntype", Promise)
|
|
10588
10427
|
], WalletService.prototype, "recover", null);
|
|
10589
10428
|
__decorate([
|
|
10590
|
-
WithLock('
|
|
10429
|
+
WithLock('changePassword'),
|
|
10591
10430
|
__metadata("design:type", Function),
|
|
10592
10431
|
__metadata("design:paramtypes", [Object]),
|
|
10593
10432
|
__metadata("design:returntype", Promise)
|
|
@@ -10598,18 +10437,12 @@ __decorate([
|
|
|
10598
10437
|
__metadata("design:paramtypes", [Object]),
|
|
10599
10438
|
__metadata("design:returntype", Promise)
|
|
10600
10439
|
], WalletService.prototype, "handleUpdateToV2", null);
|
|
10601
|
-
__decorate([
|
|
10602
|
-
WithLock('credential-rewrap'),
|
|
10603
|
-
__metadata("design:type", Function),
|
|
10604
|
-
__metadata("design:paramtypes", [Object]),
|
|
10605
|
-
__metadata("design:returntype", Promise)
|
|
10606
|
-
], WalletService.prototype, "convertToPasskey", null);
|
|
10607
10440
|
|
|
10608
10441
|
class WalletDataService extends Base {
|
|
10609
|
-
constructor(config) {
|
|
10610
|
-
super(config);
|
|
10442
|
+
constructor(config, ports = {}) {
|
|
10443
|
+
super(config, ports);
|
|
10611
10444
|
this.userId = config.userId;
|
|
10612
|
-
this.walletService = new WalletService(config);
|
|
10445
|
+
this.walletService = new WalletService(config, ports);
|
|
10613
10446
|
}
|
|
10614
10447
|
/**
|
|
10615
10448
|
* @description Validates the wallet address info for a given blockchain.
|
|
@@ -10930,8 +10763,8 @@ class WalletDataService extends Base {
|
|
|
10930
10763
|
}
|
|
10931
10764
|
|
|
10932
10765
|
class Utils extends Base {
|
|
10933
|
-
constructor(config) {
|
|
10934
|
-
super(config);
|
|
10766
|
+
constructor(config, ports = {}) {
|
|
10767
|
+
super(config, ports);
|
|
10935
10768
|
/**
|
|
10936
10769
|
*
|
|
10937
10770
|
* Decrypts user private key
|
|
@@ -10964,7 +10797,7 @@ class Utils extends Base {
|
|
|
10964
10797
|
return undefined;
|
|
10965
10798
|
}
|
|
10966
10799
|
};
|
|
10967
|
-
this.auth = new AuthService(config);
|
|
10800
|
+
this.auth = new AuthService(config, ports);
|
|
10968
10801
|
}
|
|
10969
10802
|
/**
|
|
10970
10803
|
*
|
|
@@ -11071,16 +10904,16 @@ class HttpApi extends Base {
|
|
|
11071
10904
|
* @param config - The Wallaby configuration object
|
|
11072
10905
|
* @public
|
|
11073
10906
|
*/
|
|
11074
|
-
constructor(config) {
|
|
11075
|
-
super(config);
|
|
10907
|
+
constructor(config, ports = {}) {
|
|
10908
|
+
super(config, ports);
|
|
11076
10909
|
}
|
|
11077
10910
|
}
|
|
11078
10911
|
|
|
11079
10912
|
class Swap extends Base {
|
|
11080
|
-
constructor(config) {
|
|
11081
|
-
super(config);
|
|
11082
|
-
this.authService = new AuthService(config);
|
|
11083
|
-
this.walletService = new WalletService(config);
|
|
10913
|
+
constructor(config, ports = {}) {
|
|
10914
|
+
super(config, ports);
|
|
10915
|
+
this.authService = new AuthService(config, ports);
|
|
10916
|
+
this.walletService = new WalletService(config, ports);
|
|
11084
10917
|
}
|
|
11085
10918
|
/**
|
|
11086
10919
|
* Gets a swap quote between two assets, including fees, min output, and slippage limits.
|
|
@@ -11332,30 +11165,9 @@ const sanitizeSuiObjectId = (objectId) => {
|
|
|
11332
11165
|
return objectId.split('::')[0];
|
|
11333
11166
|
};
|
|
11334
11167
|
|
|
11335
|
-
/**
|
|
11336
|
-
* Extracts the asset symbol from a fully-qualified Sui coin type.
|
|
11337
|
-
*
|
|
11338
|
-
* A Sui coin type has the shape `<package>::<module>::<TYPE>`, where the final
|
|
11339
|
-
* segment is the coin's struct name and doubles as its symbol.
|
|
11340
|
-
*
|
|
11341
|
-
* @param objectId - The Sui object id / coin type. Example input:
|
|
11342
|
-
* "0xc91acfb75009c5ff2fd57c54f3caaee12ad1fbe997681334adc0b574fc277a07::icorgi::ICORGI"
|
|
11343
|
-
* @returns The symbol (e.g. "ICORGI"), or undefined when the id carries no
|
|
11344
|
-
* `::module::TYPE` suffix to derive it from.
|
|
11345
|
-
*/
|
|
11346
|
-
const extractSuiAssetSymbol = (objectId) => {
|
|
11347
|
-
var _a;
|
|
11348
|
-
if (!objectId || !objectId.includes('::')) {
|
|
11349
|
-
return undefined;
|
|
11350
|
-
}
|
|
11351
|
-
const segments = objectId.split('::');
|
|
11352
|
-
const symbol = (_a = segments[segments.length - 1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
11353
|
-
return symbol || undefined;
|
|
11354
|
-
};
|
|
11355
|
-
|
|
11356
11168
|
class System extends Base {
|
|
11357
|
-
constructor(config) {
|
|
11358
|
-
super(config);
|
|
11169
|
+
constructor(config, ports = {}) {
|
|
11170
|
+
super(config, ports);
|
|
11359
11171
|
}
|
|
11360
11172
|
/**
|
|
11361
11173
|
* @public
|
|
@@ -11441,9 +11253,6 @@ class System extends Base {
|
|
|
11441
11253
|
* @param {BlockchainName} blockchain - The name of the blockchain.
|
|
11442
11254
|
* @param {string} contractAddress - The contract address of the token (optional for non-SUI blockchains).
|
|
11443
11255
|
* @param {string} suiObjectId - The SUI object ID of the token (optional for SUI blockchain).
|
|
11444
|
-
* @param {string} assetSymbol - The asset symbol; disambiguates new SUI assets. For SUI it is
|
|
11445
|
-
* optional: when omitted, it is derived from the `::module::TYPE` suffix of `suiObjectId`
|
|
11446
|
-
* (which is otherwise trimmed off before the request is sent).
|
|
11447
11256
|
*
|
|
11448
11257
|
* @returns {Promise<{ decimals: number; symbol: string; name: string; tokenContractAddress: string }>} A promise that resolves to an object containing token information.
|
|
11449
11258
|
*
|
|
@@ -11452,19 +11261,18 @@ class System extends Base {
|
|
|
11452
11261
|
* @throws Will throw an error if `contractAddress` is not provided for non-SUI blockchains.
|
|
11453
11262
|
* @throws Will throw an error if the response is invalid or contains an error.
|
|
11454
11263
|
*/
|
|
11455
|
-
async fetchTokenInfo({ blockchain, contractAddress, suiObjectId,
|
|
11264
|
+
async fetchTokenInfo({ blockchain, contractAddress, suiObjectId, }) {
|
|
11456
11265
|
try {
|
|
11457
11266
|
const validatedContractAddress = this.validateContractAddress({
|
|
11458
11267
|
blockchain,
|
|
11459
11268
|
contractAddress,
|
|
11460
11269
|
suiObjectId,
|
|
11461
11270
|
});
|
|
11462
|
-
// For SUI, the coin symbol is the last segment of the coin type
|
|
11463
|
-
// (`<package>::<module>::<TYPE>`), which sanitizeSuiObjectId strips out.
|
|
11464
|
-
// Derive it so callers don't have to pass assetSymbol explicitly.
|
|
11465
|
-
const resolvedAssetSymbol = assetSymbol !== null && assetSymbol !== void 0 ? assetSymbol : (blockchain === BlockchainName.Sui ? extractSuiAssetSymbol(suiObjectId) : undefined);
|
|
11466
11271
|
const response = await this.request(SystemRoutes.fetchTokenInfo, {
|
|
11467
|
-
queryParams:
|
|
11272
|
+
queryParams: {
|
|
11273
|
+
chainName: blockchain,
|
|
11274
|
+
tokenContractAddress: validatedContractAddress,
|
|
11275
|
+
},
|
|
11468
11276
|
});
|
|
11469
11277
|
return response;
|
|
11470
11278
|
}
|
|
@@ -11552,10 +11360,10 @@ class System extends Base {
|
|
|
11552
11360
|
}
|
|
11553
11361
|
|
|
11554
11362
|
class Transactions extends Base {
|
|
11555
|
-
constructor(config) {
|
|
11556
|
-
super(config);
|
|
11557
|
-
this.authService = new AuthService(config);
|
|
11558
|
-
this.walletService = new WalletService(config);
|
|
11363
|
+
constructor(config, ports = {}) {
|
|
11364
|
+
super(config, ports);
|
|
11365
|
+
this.authService = new AuthService(config, ports);
|
|
11366
|
+
this.walletService = new WalletService(config, ports);
|
|
11559
11367
|
this.userId = config.userId;
|
|
11560
11368
|
}
|
|
11561
11369
|
/**
|
|
@@ -11996,15 +11804,15 @@ class Wallaby {
|
|
|
11996
11804
|
* @param {string} [config.clientAuthToken] - A web token generated by the client for authorization.
|
|
11997
11805
|
* @public
|
|
11998
11806
|
*/
|
|
11999
|
-
constructor(config) {
|
|
12000
|
-
this.wallet = new WalletService(config);
|
|
12001
|
-
this.walletData = new WalletDataService(config);
|
|
12002
|
-
this.utils = new Utils(config);
|
|
12003
|
-
this.auth = new AuthService(config);
|
|
12004
|
-
this.system = new System(config);
|
|
12005
|
-
this.transactions = new Transactions(config);
|
|
12006
|
-
this.swap = new Swap(config);
|
|
12007
|
-
this.httpApi = new HttpApi(config);
|
|
11807
|
+
constructor(config, ports = {}) {
|
|
11808
|
+
this.wallet = new WalletService(config, ports);
|
|
11809
|
+
this.walletData = new WalletDataService(config, ports);
|
|
11810
|
+
this.utils = new Utils(config, ports);
|
|
11811
|
+
this.auth = new AuthService(config, ports);
|
|
11812
|
+
this.system = new System(config, ports);
|
|
11813
|
+
this.transactions = new Transactions(config, ports);
|
|
11814
|
+
this.swap = new Swap(config, ports);
|
|
11815
|
+
this.httpApi = new HttpApi(config, ports);
|
|
12008
11816
|
}
|
|
12009
11817
|
get version() {
|
|
12010
11818
|
return currentPackageVersion;
|