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.cjs.js
CHANGED
|
@@ -344,8 +344,6 @@ exports.V2KeyNames = void 0;
|
|
|
344
344
|
V2KeyNames["LastMigratedAt"] = "wsdk_last_migrated_at";
|
|
345
345
|
V2KeyNames["PasswordResetAttempts"] = "wsdk_password_reset_attempts";
|
|
346
346
|
V2KeyNames["MigrationAttempts"] = "wsdk_migration_attempts";
|
|
347
|
-
V2KeyNames["CredentialConversionInProgress"] = "credential-conversion-in-progress";
|
|
348
|
-
V2KeyNames["PendingCommit"] = "pending-commit";
|
|
349
347
|
})(exports.V2KeyNames || (exports.V2KeyNames = {}));
|
|
350
348
|
|
|
351
349
|
exports.ErrorResponseCodes = void 0;
|
|
@@ -601,7 +599,6 @@ const defaultEnvironment = (_a = browser$1.env.NODE_ENV) !== null && _a !== void
|
|
|
601
599
|
* Please pass the network value in the WallabyConfigOptions object to override it for production-mainnet.
|
|
602
600
|
*/
|
|
603
601
|
const defaultNetwork = 'testnet';
|
|
604
|
-
const isTest = browser$1.env.NODE_ENV === 'test';
|
|
605
602
|
const DEFAULT_ENTROPY_BYTES$1 = 32;
|
|
606
603
|
const PBKDF2_ITERATIONS = 131072;
|
|
607
604
|
const DEFAULT_HOSTNAME = 'https://www.republic.com';
|
|
@@ -627,7 +624,7 @@ const env = {
|
|
|
627
624
|
isNative: !isWeb,
|
|
628
625
|
isWeb,
|
|
629
626
|
};
|
|
630
|
-
const currentPackageVersion = "3.
|
|
627
|
+
const currentPackageVersion = "3.3.0" ;
|
|
631
628
|
|
|
632
629
|
/**
|
|
633
630
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -3540,7 +3537,7 @@ const createPrivateKey = (entropy) => {
|
|
|
3540
3537
|
}
|
|
3541
3538
|
// Check byte diversity. This catches genuinely broken inputs (all-zeros, all-same-byte)
|
|
3542
3539
|
// without false-positiving on 32-byte KDF output (~30 unique bytes expected).
|
|
3543
|
-
// the sampled Shannon-entropy check was removed (WAL-1465) — it's unsound for
|
|
3540
|
+
// ponytail: the sampled Shannon-entropy check was removed (WAL-1465) — it's unsound for
|
|
3544
3541
|
// 32 samples (max measurable = log2(32) ≈ 5 bits/byte vs a 4-bit threshold), so deterministic
|
|
3545
3542
|
// KDF output could be rejected, permanently locking the user out.
|
|
3546
3543
|
const uniqueBytes = new Set(entropy);
|
|
@@ -4851,14 +4848,6 @@ class StorageService {
|
|
|
4851
4848
|
return;
|
|
4852
4849
|
}
|
|
4853
4850
|
async fetch(key, options) {
|
|
4854
|
-
var _a;
|
|
4855
|
-
// Recover once per session; memoize the promise so concurrent first-fetches all await the same
|
|
4856
|
-
// recovery instead of racing past it and reading pre-recovery storage. recoverCommit uses
|
|
4857
|
-
// getItem/removeItem (not fetch), so there's no recursion. Swallow errors: recovery is
|
|
4858
|
-
// best-effort and a failure must not wedge every subsequent fetch.
|
|
4859
|
-
await ((_a = this._walRecovery) !== null && _a !== void 0 ? _a : (this._walRecovery = this.recoverCommit().catch((error) => {
|
|
4860
|
-
logger.error('SDK::StorageService::fetch::wal recovery failed', error);
|
|
4861
|
-
})));
|
|
4862
4851
|
let storageKey;
|
|
4863
4852
|
if (this._walletSpecificKeys.includes(key)) {
|
|
4864
4853
|
if (!(options === null || options === void 0 ? void 0 : options.walletId)) {
|
|
@@ -4918,75 +4907,6 @@ class StorageService {
|
|
|
4918
4907
|
async saveInBulk(data) {
|
|
4919
4908
|
await Promise.all(data.map((item) => this.save(item.key, item.value, { walletId: item.walletId })));
|
|
4920
4909
|
}
|
|
4921
|
-
// Compute the final storage key the same way save/fetch/delete do.
|
|
4922
|
-
_computeRawKey(key, walletId) {
|
|
4923
|
-
let storageKey;
|
|
4924
|
-
if (this._walletSpecificKeys.includes(key)) {
|
|
4925
|
-
if (!walletId)
|
|
4926
|
-
throw new Error(`A walletId is required to compute key: ${key}`);
|
|
4927
|
-
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}:${walletId}`;
|
|
4928
|
-
}
|
|
4929
|
-
else {
|
|
4930
|
-
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}`;
|
|
4931
|
-
}
|
|
4932
|
-
return isWeb ? storageKey : normalizeKey(storageKey);
|
|
4933
|
-
}
|
|
4934
|
-
_serializeValue(key, value) {
|
|
4935
|
-
if (this._keysProtectedByMasterKey.includes(key)) {
|
|
4936
|
-
return this.cipher.encryptWithMasterKey({ data: value });
|
|
4937
|
-
}
|
|
4938
|
-
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
4939
|
-
}
|
|
4940
|
-
async _applyWAL(record) {
|
|
4941
|
-
for (const { rawKey, value } of record.writes) {
|
|
4942
|
-
await this.setItem(rawKey, value);
|
|
4943
|
-
}
|
|
4944
|
-
for (const rawKey of record.deletes) {
|
|
4945
|
-
await this.removeItem(rawKey);
|
|
4946
|
-
}
|
|
4947
|
-
}
|
|
4948
|
-
// Atomically commit a batch of writes and deletes via a write-ahead log.
|
|
4949
|
-
// The WAL record is written in a single setItem before any credential key is
|
|
4950
|
-
// touched. A crash between that write and the individual setItem calls leaves
|
|
4951
|
-
// the WAL in place; recoverCommit() finishes the batch on the next call.
|
|
4952
|
-
async commitBatch(writes, deletes) {
|
|
4953
|
-
const record = {
|
|
4954
|
-
writes: writes.map(({ key, value, walletId }) => ({
|
|
4955
|
-
rawKey: this._computeRawKey(key, walletId),
|
|
4956
|
-
value: this._serializeValue(key, value),
|
|
4957
|
-
})),
|
|
4958
|
-
deletes: (deletes !== null && deletes !== void 0 ? deletes : []).map(({ key, walletId }) => this._computeRawKey(key, walletId)),
|
|
4959
|
-
};
|
|
4960
|
-
// Finish any dangling WAL from a prior partially-applied commit before writing a new one —
|
|
4961
|
-
// otherwise this setItem clobbers it and those half-written credentials become unrecoverable.
|
|
4962
|
-
await this.recoverCommit();
|
|
4963
|
-
const walKey = this._computeRawKey(exports.V2KeyNames.PendingCommit);
|
|
4964
|
-
await this.setItem(walKey, JSON.stringify(record));
|
|
4965
|
-
await this._applyWAL(record);
|
|
4966
|
-
await this.removeItem(walKey);
|
|
4967
|
-
}
|
|
4968
|
-
// Re-apply a pending WAL commit if the process was killed mid-batch.
|
|
4969
|
-
// Call at the start of any operation that writes credential blobs.
|
|
4970
|
-
async recoverCommit() {
|
|
4971
|
-
const walKey = this._computeRawKey(exports.V2KeyNames.PendingCommit);
|
|
4972
|
-
const raw = await this.getItem(walKey);
|
|
4973
|
-
if (!raw)
|
|
4974
|
-
return;
|
|
4975
|
-
let record;
|
|
4976
|
-
try {
|
|
4977
|
-
record = safeJsonParse(raw);
|
|
4978
|
-
}
|
|
4979
|
-
catch (error) {
|
|
4980
|
-
// Corrupt/unparseable WAL can never be replayed — discard so it doesn't wedge every fetch.
|
|
4981
|
-
logger.error('SDK::StorageService::recoverCommit::corrupt WAL, discarding', error);
|
|
4982
|
-
await this.removeItem(walKey);
|
|
4983
|
-
return;
|
|
4984
|
-
}
|
|
4985
|
-
// _applyWAL is idempotent. If it throws (transient storage error) keep the WAL and let the
|
|
4986
|
-
// caller retry — don't delete the only record needed to finish the batch. Remove only on success.
|
|
4987
|
-
await this._applyWAL(record);
|
|
4988
|
-
await this.removeItem(walKey);
|
|
4989
|
-
}
|
|
4990
4910
|
async delete(key, options) {
|
|
4991
4911
|
let storageKey;
|
|
4992
4912
|
if (this._walletSpecificKeys.includes(key)) {
|
|
@@ -5271,8 +5191,6 @@ class StorageService {
|
|
|
5271
5191
|
exports.V2KeyNames.ClientAuthToken,
|
|
5272
5192
|
exports.V2KeyNames.PasswordResetAttempts,
|
|
5273
5193
|
exports.V2KeyNames.MigrationAttempts,
|
|
5274
|
-
exports.V2KeyNames.CredentialConversionInProgress,
|
|
5275
|
-
exports.V2KeyNames.PendingCommit,
|
|
5276
5194
|
];
|
|
5277
5195
|
await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
|
|
5278
5196
|
if (walletId) {
|
|
@@ -5319,11 +5237,11 @@ class StorageService {
|
|
|
5319
5237
|
* @param jwt - The JWT string to check. If null, the function will return true.
|
|
5320
5238
|
* @returns `true` if the JWT has expired or is null, otherwise `false`.
|
|
5321
5239
|
*/
|
|
5322
|
-
function jwtHasExpired(jwt) {
|
|
5240
|
+
function jwtHasExpired(jwt, now = Date.now) {
|
|
5323
5241
|
if (!jwt) {
|
|
5324
5242
|
return true;
|
|
5325
5243
|
}
|
|
5326
|
-
return millisecondsToJWTTimeout(jwt) <= 0;
|
|
5244
|
+
return millisecondsToJWTTimeout(jwt, now) <= 0;
|
|
5327
5245
|
}
|
|
5328
5246
|
function jwtHasSameUser(jwt, userId) {
|
|
5329
5247
|
if (!jwt || !userId) {
|
|
@@ -5343,11 +5261,11 @@ function userIsMfaVerified(jwt) {
|
|
|
5343
5261
|
* @param thresholdSeconds - Number of seconds before expiry to consider "near expiry".
|
|
5344
5262
|
* @returns `true` if the JWT expires within `thresholdSeconds` seconds, otherwise `false`.
|
|
5345
5263
|
*/
|
|
5346
|
-
function isJwtNearExpiry(jwt, thresholdSeconds) {
|
|
5264
|
+
function isJwtNearExpiry(jwt, thresholdSeconds, now = Date.now) {
|
|
5347
5265
|
if (!jwt) {
|
|
5348
5266
|
return false;
|
|
5349
5267
|
}
|
|
5350
|
-
return millisecondsToJWTTimeout(jwt) <= thresholdSeconds * 1000;
|
|
5268
|
+
return millisecondsToJWTTimeout(jwt, now) <= thresholdSeconds * 1000;
|
|
5351
5269
|
}
|
|
5352
5270
|
/**
|
|
5353
5271
|
* Calculates the remaining time in milliseconds until a given JWT expires.
|
|
@@ -5355,11 +5273,11 @@ function isJwtNearExpiry(jwt, thresholdSeconds) {
|
|
|
5355
5273
|
* @param jwt - The JWT string to decode and check.
|
|
5356
5274
|
* @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.
|
|
5357
5275
|
*/
|
|
5358
|
-
function millisecondsToJWTTimeout(jwt) {
|
|
5276
|
+
function millisecondsToJWTTimeout(jwt, now = Date.now) {
|
|
5359
5277
|
const jwtDecoded = jwtDecode.jwtDecode(jwt);
|
|
5360
5278
|
const jwtExpirationTimeSeconds = jwtDecoded.exp;
|
|
5361
5279
|
const jwtExpirationTimeMilliseconds = (jwtExpirationTimeSeconds !== null && jwtExpirationTimeSeconds !== void 0 ? jwtExpirationTimeSeconds : 0) * 1000;
|
|
5362
|
-
const timeNowMilliseconds =
|
|
5280
|
+
const timeNowMilliseconds = now();
|
|
5363
5281
|
return jwtExpirationTimeMilliseconds - timeNowMilliseconds;
|
|
5364
5282
|
}
|
|
5365
5283
|
|
|
@@ -7008,8 +6926,8 @@ function shouldClearTokensAfterRefreshFailure(error) {
|
|
|
7008
6926
|
// Module-level dedupe manager for token refresh to ensure only one refresh request per user/environment/network at a time
|
|
7009
6927
|
const refreshDedupeManager = new DedupeManagerService();
|
|
7010
6928
|
class Base {
|
|
7011
|
-
constructor(config) {
|
|
7012
|
-
var _a, _b;
|
|
6929
|
+
constructor(config, ports = {}) {
|
|
6930
|
+
var _a, _b, _c, _d, _e;
|
|
7013
6931
|
const sanitizedConfig = sanitizeConfig(config);
|
|
7014
6932
|
this.apiKey = sanitizedConfig.apiKey;
|
|
7015
6933
|
this.baseUrl = sanitizedConfig.baseUrl;
|
|
@@ -7020,7 +6938,9 @@ class Base {
|
|
|
7020
6938
|
env.isNative = this.options.platform === 'ios' || this.options.platform === 'android';
|
|
7021
6939
|
env.isWeb = !env.isNative;
|
|
7022
6940
|
}
|
|
7023
|
-
this.cipher = new Cipher();
|
|
6941
|
+
this.cipher = (_b = ports.cipher) !== null && _b !== void 0 ? _b : new Cipher();
|
|
6942
|
+
this.transport = (_c = ports.transport) !== null && _c !== void 0 ? _c : ((...args) => fetch(...args));
|
|
6943
|
+
this.clock = (_d = ports.clock) !== null && _d !== void 0 ? _d : { now: () => Date.now() };
|
|
7024
6944
|
this.lockManager = new LockManagerService();
|
|
7025
6945
|
this._initializeClientAuthToken(sanitizedConfig.clientAuthToken);
|
|
7026
6946
|
this.request = this.request.bind(this);
|
|
@@ -7034,6 +6954,7 @@ class Base {
|
|
|
7034
6954
|
secure: true, // Enable security worker for all requests by default
|
|
7035
6955
|
},
|
|
7036
6956
|
securityWorker: this.securityWorker.bind(this),
|
|
6957
|
+
customFetch: this.transport,
|
|
7037
6958
|
});
|
|
7038
6959
|
/**
|
|
7039
6960
|
* This intercepts all API responses and transforms errors into WallabyError format.
|
|
@@ -7078,7 +6999,7 @@ class Base {
|
|
|
7078
6999
|
return attemptRequest(false);
|
|
7079
7000
|
};
|
|
7080
7001
|
this.api = new Api(httpClient);
|
|
7081
|
-
this.api.http.setSecurityData(Object.assign({ 'x-api-key': config.apiKey, 'x-client-jwt': config.clientAuthToken }, (
|
|
7002
|
+
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));
|
|
7082
7003
|
}
|
|
7083
7004
|
set setClientAuthToken(token) {
|
|
7084
7005
|
this._initializeClientAuthToken(token);
|
|
@@ -7197,7 +7118,7 @@ class Base {
|
|
|
7197
7118
|
// Proactive token refresh: if access token is near expiry, refresh before making the request
|
|
7198
7119
|
if (route !== AuthRoutes.refreshAccessToken && !retried) {
|
|
7199
7120
|
const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
|
|
7200
|
-
if (accessToken && isJwtNearExpiry(accessToken, 60)) {
|
|
7121
|
+
if (accessToken && isJwtNearExpiry(accessToken, 60, this.clock.now)) {
|
|
7201
7122
|
await this._performTokenRefresh();
|
|
7202
7123
|
}
|
|
7203
7124
|
}
|
|
@@ -7221,7 +7142,7 @@ class Base {
|
|
|
7221
7142
|
fetchOptions.body = JSON.stringify(options.payload);
|
|
7222
7143
|
}
|
|
7223
7144
|
logger.debug(`SDK::Base::${route.method}::Request`, { path: fullUrl, payload: options === null || options === void 0 ? void 0 : options.payload });
|
|
7224
|
-
const response = await
|
|
7145
|
+
const response = await this.transport(fullUrl, fetchOptions);
|
|
7225
7146
|
const contentType = response.headers.get('content-type');
|
|
7226
7147
|
let data;
|
|
7227
7148
|
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json')) {
|
|
@@ -7292,7 +7213,7 @@ class Base {
|
|
|
7292
7213
|
}
|
|
7293
7214
|
async _getRequestHeaders() {
|
|
7294
7215
|
const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
|
|
7295
|
-
if (
|
|
7216
|
+
if (jwtHasExpired(this.clientAuthToken, this.clock.now)) {
|
|
7296
7217
|
throw new WallabyError({
|
|
7297
7218
|
message: 'Auth token has expired',
|
|
7298
7219
|
statusCode: 401,
|
|
@@ -7314,7 +7235,7 @@ class Base {
|
|
|
7314
7235
|
// Proactive token refresh before building headers for the generated client
|
|
7315
7236
|
try {
|
|
7316
7237
|
const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
|
|
7317
|
-
if (accessToken && isJwtNearExpiry(accessToken, 60)) {
|
|
7238
|
+
if (accessToken && isJwtNearExpiry(accessToken, 60, this.clock.now)) {
|
|
7318
7239
|
await this._performTokenRefresh();
|
|
7319
7240
|
}
|
|
7320
7241
|
}
|
|
@@ -7695,8 +7616,8 @@ function decodeBase64URL(base64url) {
|
|
|
7695
7616
|
}
|
|
7696
7617
|
|
|
7697
7618
|
class PasskeyService {
|
|
7698
|
-
constructor(userId, storageService, request) {
|
|
7699
|
-
this.cipher =
|
|
7619
|
+
constructor(userId, storageService, request, cipher = new Cipher()) {
|
|
7620
|
+
this.cipher = cipher;
|
|
7700
7621
|
this.localStorageService = storageService;
|
|
7701
7622
|
this.userId = userId;
|
|
7702
7623
|
this.request = request;
|
|
@@ -8218,10 +8139,10 @@ function WithLock(lockKey) {
|
|
|
8218
8139
|
}
|
|
8219
8140
|
|
|
8220
8141
|
class AuthService extends Base {
|
|
8221
|
-
constructor(config) {
|
|
8222
|
-
super(config);
|
|
8142
|
+
constructor(config, ports = {}) {
|
|
8143
|
+
super(config, ports);
|
|
8223
8144
|
this.getUserSalt = this.getUserSalt.bind(this);
|
|
8224
|
-
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request);
|
|
8145
|
+
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request, this.cipher);
|
|
8225
8146
|
}
|
|
8226
8147
|
/**
|
|
8227
8148
|
* @description
|
|
@@ -8808,9 +8729,9 @@ function assertBackupSharePayloadShape(encrypted) {
|
|
|
8808
8729
|
}
|
|
8809
8730
|
}
|
|
8810
8731
|
class WalletHandlersService extends Base {
|
|
8811
|
-
constructor(config) {
|
|
8812
|
-
super(config);
|
|
8813
|
-
this.authService = new AuthService(config);
|
|
8732
|
+
constructor(config, ports = {}) {
|
|
8733
|
+
super(config, ports);
|
|
8734
|
+
this.authService = new AuthService(config, ports);
|
|
8814
8735
|
this.userId = config.userId;
|
|
8815
8736
|
}
|
|
8816
8737
|
async handleImportWallet(deviceAuthKeys, importWalletInput) {
|
|
@@ -9116,12 +9037,12 @@ class WalletHandlersService extends Base {
|
|
|
9116
9037
|
}
|
|
9117
9038
|
|
|
9118
9039
|
class WalletService extends Base {
|
|
9119
|
-
constructor(config) {
|
|
9120
|
-
super(config);
|
|
9121
|
-
this.authService = new AuthService(config);
|
|
9122
|
-
this.handlers = new WalletHandlersService(config);
|
|
9040
|
+
constructor(config, ports = {}) {
|
|
9041
|
+
super(config, ports);
|
|
9042
|
+
this.authService = new AuthService(config, ports);
|
|
9043
|
+
this.handlers = new WalletHandlersService(config, ports);
|
|
9123
9044
|
this.userId = config.userId;
|
|
9124
|
-
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request);
|
|
9045
|
+
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request, this.cipher);
|
|
9125
9046
|
}
|
|
9126
9047
|
/**
|
|
9127
9048
|
* Reads the persisted sliding-window rate-limit state for a counter key.
|
|
@@ -9642,7 +9563,7 @@ class WalletService extends Base {
|
|
|
9642
9563
|
password: newPassword,
|
|
9643
9564
|
salt: clientSalt,
|
|
9644
9565
|
});
|
|
9645
|
-
if (!newCredentialsKeyPair.publicKey
|
|
9566
|
+
if (!newCredentialsKeyPair.publicKey) {
|
|
9646
9567
|
throw new WallabyError({
|
|
9647
9568
|
message: 'Could not derive keys for new password.',
|
|
9648
9569
|
statusCode: 500,
|
|
@@ -9665,9 +9586,6 @@ class WalletService extends Base {
|
|
|
9665
9586
|
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
9666
9587
|
});
|
|
9667
9588
|
}
|
|
9668
|
-
// Round-trip validate: decrypt the re-wrapped blob with the new key before committing.
|
|
9669
|
-
// Catches a malformed re-encryption before it overwrites the live credential.
|
|
9670
|
-
await this.assertRoundTrip(reWrappedDevicePrivateKey, newCredentialsKeyPair.privateKey, 'device key');
|
|
9671
9589
|
const reWrappedSeedPhrase = encryptedSeedPhraseString
|
|
9672
9590
|
? await this.cipher.flipEncryptedData({
|
|
9673
9591
|
cipherText: safeJsonParse(encryptedSeedPhraseString),
|
|
@@ -9689,13 +9607,9 @@ class WalletService extends Base {
|
|
|
9689
9607
|
encryptionKey: newCredentialsKeyPair.publicKey,
|
|
9690
9608
|
})
|
|
9691
9609
|
: null;
|
|
9692
|
-
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
await this.assertRoundTrip(reWrappedPrimaryShare, newCredentialsKeyPair.privateKey, 'primary share');
|
|
9696
|
-
if (reWrappedBackupShare)
|
|
9697
|
-
await this.assertRoundTrip(reWrappedBackupShare, newCredentialsKeyPair.privateKey, 'backup share');
|
|
9698
|
-
await this.localStorageService.commitBatch([
|
|
9610
|
+
// Commit all re-wrapped blobs in one batch so a partial failure cannot leave the device
|
|
9611
|
+
// in a half-migrated state (some items under the new password, others under the old).
|
|
9612
|
+
await this.localStorageService.saveInBulk([
|
|
9699
9613
|
{ key: exports.LocalStorageItems.EncryptedDevicePrivateKey, value: reWrappedDevicePrivateKey },
|
|
9700
9614
|
...(reWrappedSeedPhrase
|
|
9701
9615
|
? [{ key: exports.LocalStorageItems.EncryptedStandardSeedPhrase, value: reWrappedSeedPhrase, walletId }]
|
|
@@ -10280,28 +10194,7 @@ class WalletService extends Base {
|
|
|
10280
10194
|
* @returns { boolean } whether the operation was successful
|
|
10281
10195
|
*/
|
|
10282
10196
|
async convertToPasskey(input) {
|
|
10283
|
-
let passkeyRegistered = false;
|
|
10284
10197
|
try {
|
|
10285
|
-
// Recover an interrupted conversion BEFORE reading any credential blob. A prior attempt may have
|
|
10286
|
-
// already rewrapped EncryptedDevicePrivateKey to passkey form (addNewPasskey persists it outside
|
|
10287
|
-
// this method's atomic commit), which the password can no longer decrypt — and deriving the passkey
|
|
10288
|
-
// key to decrypt it needs the device key itself (circular). The marker stashes the original
|
|
10289
|
-
// password-encrypted device key; restore it so the rest of the flow runs as a fresh conversion.
|
|
10290
|
-
const rawConversionMarker = (await this.localStorageService.fetch(exports.V2KeyNames.CredentialConversionInProgress));
|
|
10291
|
-
const existingConversionMarker = rawConversionMarker
|
|
10292
|
-
? safeJsonParse(rawConversionMarker)
|
|
10293
|
-
: undefined;
|
|
10294
|
-
// Restore the stashed device key whenever a marker carries one — independent of walletId. The
|
|
10295
|
-
// device key is per-user (not wallet-scoped), so a conversion interrupted on a different wallet
|
|
10296
|
-
// leaves the shared device key passkey-wrapped too. Restoring is idempotent (rewrites the
|
|
10297
|
-
// original password-encrypted blob) and stops a second wallet's conversion from destroying the
|
|
10298
|
-
// first's recovery state. v2 only — a v1 wallet's untouched v1 key still decrypts.
|
|
10299
|
-
if (existingConversionMarker === null || existingConversionMarker === void 0 ? void 0 : existingConversionMarker.encryptedDevicePrivateKey) {
|
|
10300
|
-
await this.localStorageService.save(exports.LocalStorageItems.EncryptedDevicePrivateKey, existingConversionMarker.encryptedDevicePrivateKey);
|
|
10301
|
-
}
|
|
10302
|
-
if ((existingConversionMarker === null || existingConversionMarker === void 0 ? void 0 : existingConversionMarker.walletId) === input.walletId) {
|
|
10303
|
-
logger.info('SDK::WalletService::convertToPasskey::resuming interrupted conversion');
|
|
10304
|
-
}
|
|
10305
10198
|
const v2EncryptedPriv = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
10306
10199
|
const v2EncryptedSeed = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase, {
|
|
10307
10200
|
walletId: input.walletId,
|
|
@@ -10350,10 +10243,6 @@ class WalletService extends Base {
|
|
|
10350
10243
|
});
|
|
10351
10244
|
}
|
|
10352
10245
|
const clientPublicKey = publicKeyByPrivateKey(decryptedClientAuthPrivKey);
|
|
10353
|
-
// Write-ahead marker: set before the unrevocable passkey registration so an interrupted
|
|
10354
|
-
// conversion can be resumed on the next attempt. Stash the original password-encrypted device
|
|
10355
|
-
// key so resume survives addNewPasskey rewrapping the stored device key to passkey form.
|
|
10356
|
-
await this.localStorageService.save(exports.V2KeyNames.CredentialConversionInProgress, Object.assign({ walletId: input.walletId }, (v2EncryptedPriv ? { encryptedDevicePrivateKey: v2EncryptedPriv } : {})));
|
|
10357
10246
|
const authentication = await this.passkeyService.addNewPasskey({
|
|
10358
10247
|
deviceKeyPair: {
|
|
10359
10248
|
publicKey: clientPublicKey,
|
|
@@ -10361,7 +10250,6 @@ class WalletService extends Base {
|
|
|
10361
10250
|
},
|
|
10362
10251
|
getSignature: this.authService.getSignature.bind(this),
|
|
10363
10252
|
});
|
|
10364
|
-
passkeyRegistered = true;
|
|
10365
10253
|
const prfValue = authentication.prfValue;
|
|
10366
10254
|
if (!prfValue || !(prfValue instanceof Uint8Array) || prfValue.length === 0) {
|
|
10367
10255
|
logger.error('SDK::WalletService::convertToPasskey::prfValue is required and must be a non-empty Uint8Array');
|
|
@@ -10458,13 +10346,8 @@ class WalletService extends Base {
|
|
|
10458
10346
|
storeOneKeyShareWithWallaby: true,
|
|
10459
10347
|
},
|
|
10460
10348
|
});
|
|
10461
|
-
//
|
|
10462
|
-
|
|
10463
|
-
// safely; this atomic delete clears the stale seed + marker together.
|
|
10464
|
-
await this.localStorageService.commitBatch([], [
|
|
10465
|
-
{ key: exports.LocalStorageItems.EncryptedStandardSeedPhrase, walletId: input.walletId },
|
|
10466
|
-
{ key: exports.V2KeyNames.CredentialConversionInProgress },
|
|
10467
|
-
]);
|
|
10349
|
+
// Delete the old password-encrypted seed phrase since import stored the new passkey-encrypted version
|
|
10350
|
+
await this.localStorageService.delete(exports.LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
|
|
10468
10351
|
logger.info('SDK::WalletService::convertToPasskey::Wallet imported and converted successfully, old seed phrase removed');
|
|
10469
10352
|
return { authentication, seedPhrase: decryptedSeedPhrase };
|
|
10470
10353
|
}
|
|
@@ -10482,24 +10365,6 @@ class WalletService extends Base {
|
|
|
10482
10365
|
privateKey: decryptedClientAuthPrivKey,
|
|
10483
10366
|
},
|
|
10484
10367
|
});
|
|
10485
|
-
// assertRoundTrip below only strips the outer (passkey) layer — validate the inner (device key) layer here.
|
|
10486
|
-
const outerDecrypted = await this.cipher.decrypt({
|
|
10487
|
-
cipherText: encryptedPrimaryShare,
|
|
10488
|
-
decryptionKey: passkeyDerivedKeyPair.privateKey,
|
|
10489
|
-
});
|
|
10490
|
-
const innerDecrypted = outerDecrypted
|
|
10491
|
-
? await this.cipher.decrypt({
|
|
10492
|
-
cipherText: safeJsonParse(outerDecrypted),
|
|
10493
|
-
decryptionKey: decryptedClientAuthPrivKey,
|
|
10494
|
-
})
|
|
10495
|
-
: null;
|
|
10496
|
-
if (innerDecrypted !== decryptedPrimaryShare) {
|
|
10497
|
-
throw new WallabyError({
|
|
10498
|
-
message: 'Re-wrap validation failed for primary share: inner layer round-trip mismatch. Aborting to prevent credential corruption.',
|
|
10499
|
-
statusCode: 500,
|
|
10500
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
10501
|
-
});
|
|
10502
|
-
}
|
|
10503
10368
|
convertedShares.push({
|
|
10504
10369
|
key: exports.V2KeyNames.PrimaryDeviceKeyShare,
|
|
10505
10370
|
value: encryptedPrimaryShare,
|
|
@@ -10518,16 +10383,9 @@ class WalletService extends Base {
|
|
|
10518
10383
|
walletId: input.walletId,
|
|
10519
10384
|
});
|
|
10520
10385
|
}
|
|
10521
|
-
|
|
10522
|
-
// A failed decrypt here means re-encryption produced an unreadable blob — abort before overwriting live credentials.
|
|
10523
|
-
for (const share of convertedShares) {
|
|
10524
|
-
await this.assertRoundTrip(share.value, passkeyDerivedKeyPair.privateKey, share.key);
|
|
10525
|
-
}
|
|
10526
|
-
await this.localStorageService.commitBatch(convertedShares, [
|
|
10527
|
-
...(v2EncryptedSeed ? [{ key: exports.LocalStorageItems.EncryptedStandardSeedPhrase, walletId: input.walletId }] : []),
|
|
10528
|
-
{ key: exports.V2KeyNames.CredentialConversionInProgress },
|
|
10529
|
-
]);
|
|
10386
|
+
await this.localStorageService.saveInBulk(convertedShares);
|
|
10530
10387
|
if (v2EncryptedSeed) {
|
|
10388
|
+
await this.localStorageService.delete(exports.LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
|
|
10531
10389
|
logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
|
|
10532
10390
|
}
|
|
10533
10391
|
if (!decryptedSeedPhrase && decryptedPrimaryShare) {
|
|
@@ -10570,30 +10428,11 @@ class WalletService extends Base {
|
|
|
10570
10428
|
}
|
|
10571
10429
|
catch (error) {
|
|
10572
10430
|
logger.error('SDK::WalletService::convertToPasskey::error', error);
|
|
10573
|
-
// Only clear the marker if the passkey was not yet registered. After registration the
|
|
10574
|
-
// marker must survive for roll-forward on the next attempt.
|
|
10575
|
-
if (!passkeyRegistered) {
|
|
10576
|
-
await this.localStorageService.delete(exports.V2KeyNames.CredentialConversionInProgress);
|
|
10577
|
-
}
|
|
10578
10431
|
throw error;
|
|
10579
10432
|
}
|
|
10580
10433
|
}
|
|
10581
|
-
// shared guard — decrypt-tests a re-wrapped blob before any write so a malformed
|
|
10582
|
-
// re-encryption is caught before it overwrites the live credential.
|
|
10583
|
-
async assertRoundTrip(blob, decryptionKey, label) {
|
|
10584
|
-
try {
|
|
10585
|
-
await this.cipher.decrypt({ cipherText: blob, decryptionKey });
|
|
10586
|
-
}
|
|
10587
|
-
catch (_a) {
|
|
10588
|
-
throw new WallabyError({
|
|
10589
|
-
message: `Re-wrap validation failed for ${label}: decryption of the re-encrypted blob failed. Aborting to prevent credential corruption.`,
|
|
10590
|
-
statusCode: 500,
|
|
10591
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
10592
|
-
});
|
|
10593
|
-
}
|
|
10594
|
-
}
|
|
10595
10434
|
}
|
|
10596
|
-
// soft client-side guardrail against runaway retries; server-side rate limiting is the real control.
|
|
10435
|
+
// ponytail: soft client-side guardrail against runaway retries; server-side rate limiting is the real control.
|
|
10597
10436
|
// Counters are persisted (sliding window) so rebuilding the service no longer resets them. Tune freely.
|
|
10598
10437
|
WalletService.RATE_LIMIT_MAX = 5;
|
|
10599
10438
|
WalletService.RATE_LIMIT_WINDOW_MS = 30 * 60000; // 30 min
|
|
@@ -10616,7 +10455,7 @@ __decorate([
|
|
|
10616
10455
|
__metadata("design:returntype", Promise)
|
|
10617
10456
|
], WalletService.prototype, "recover", null);
|
|
10618
10457
|
__decorate([
|
|
10619
|
-
WithLock('
|
|
10458
|
+
WithLock('changePassword'),
|
|
10620
10459
|
__metadata("design:type", Function),
|
|
10621
10460
|
__metadata("design:paramtypes", [Object]),
|
|
10622
10461
|
__metadata("design:returntype", Promise)
|
|
@@ -10627,18 +10466,12 @@ __decorate([
|
|
|
10627
10466
|
__metadata("design:paramtypes", [Object]),
|
|
10628
10467
|
__metadata("design:returntype", Promise)
|
|
10629
10468
|
], WalletService.prototype, "handleUpdateToV2", null);
|
|
10630
|
-
__decorate([
|
|
10631
|
-
WithLock('credential-rewrap'),
|
|
10632
|
-
__metadata("design:type", Function),
|
|
10633
|
-
__metadata("design:paramtypes", [Object]),
|
|
10634
|
-
__metadata("design:returntype", Promise)
|
|
10635
|
-
], WalletService.prototype, "convertToPasskey", null);
|
|
10636
10469
|
|
|
10637
10470
|
class WalletDataService extends Base {
|
|
10638
|
-
constructor(config) {
|
|
10639
|
-
super(config);
|
|
10471
|
+
constructor(config, ports = {}) {
|
|
10472
|
+
super(config, ports);
|
|
10640
10473
|
this.userId = config.userId;
|
|
10641
|
-
this.walletService = new WalletService(config);
|
|
10474
|
+
this.walletService = new WalletService(config, ports);
|
|
10642
10475
|
}
|
|
10643
10476
|
/**
|
|
10644
10477
|
* @description Validates the wallet address info for a given blockchain.
|
|
@@ -10959,8 +10792,8 @@ class WalletDataService extends Base {
|
|
|
10959
10792
|
}
|
|
10960
10793
|
|
|
10961
10794
|
class Utils extends Base {
|
|
10962
|
-
constructor(config) {
|
|
10963
|
-
super(config);
|
|
10795
|
+
constructor(config, ports = {}) {
|
|
10796
|
+
super(config, ports);
|
|
10964
10797
|
/**
|
|
10965
10798
|
*
|
|
10966
10799
|
* Decrypts user private key
|
|
@@ -10993,7 +10826,7 @@ class Utils extends Base {
|
|
|
10993
10826
|
return undefined;
|
|
10994
10827
|
}
|
|
10995
10828
|
};
|
|
10996
|
-
this.auth = new AuthService(config);
|
|
10829
|
+
this.auth = new AuthService(config, ports);
|
|
10997
10830
|
}
|
|
10998
10831
|
/**
|
|
10999
10832
|
*
|
|
@@ -11100,16 +10933,16 @@ class HttpApi extends Base {
|
|
|
11100
10933
|
* @param config - The Wallaby configuration object
|
|
11101
10934
|
* @public
|
|
11102
10935
|
*/
|
|
11103
|
-
constructor(config) {
|
|
11104
|
-
super(config);
|
|
10936
|
+
constructor(config, ports = {}) {
|
|
10937
|
+
super(config, ports);
|
|
11105
10938
|
}
|
|
11106
10939
|
}
|
|
11107
10940
|
|
|
11108
10941
|
class Swap extends Base {
|
|
11109
|
-
constructor(config) {
|
|
11110
|
-
super(config);
|
|
11111
|
-
this.authService = new AuthService(config);
|
|
11112
|
-
this.walletService = new WalletService(config);
|
|
10942
|
+
constructor(config, ports = {}) {
|
|
10943
|
+
super(config, ports);
|
|
10944
|
+
this.authService = new AuthService(config, ports);
|
|
10945
|
+
this.walletService = new WalletService(config, ports);
|
|
11113
10946
|
}
|
|
11114
10947
|
/**
|
|
11115
10948
|
* Gets a swap quote between two assets, including fees, min output, and slippage limits.
|
|
@@ -11361,30 +11194,9 @@ const sanitizeSuiObjectId = (objectId) => {
|
|
|
11361
11194
|
return objectId.split('::')[0];
|
|
11362
11195
|
};
|
|
11363
11196
|
|
|
11364
|
-
/**
|
|
11365
|
-
* Extracts the asset symbol from a fully-qualified Sui coin type.
|
|
11366
|
-
*
|
|
11367
|
-
* A Sui coin type has the shape `<package>::<module>::<TYPE>`, where the final
|
|
11368
|
-
* segment is the coin's struct name and doubles as its symbol.
|
|
11369
|
-
*
|
|
11370
|
-
* @param objectId - The Sui object id / coin type. Example input:
|
|
11371
|
-
* "0xc91acfb75009c5ff2fd57c54f3caaee12ad1fbe997681334adc0b574fc277a07::icorgi::ICORGI"
|
|
11372
|
-
* @returns The symbol (e.g. "ICORGI"), or undefined when the id carries no
|
|
11373
|
-
* `::module::TYPE` suffix to derive it from.
|
|
11374
|
-
*/
|
|
11375
|
-
const extractSuiAssetSymbol = (objectId) => {
|
|
11376
|
-
var _a;
|
|
11377
|
-
if (!objectId || !objectId.includes('::')) {
|
|
11378
|
-
return undefined;
|
|
11379
|
-
}
|
|
11380
|
-
const segments = objectId.split('::');
|
|
11381
|
-
const symbol = (_a = segments[segments.length - 1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
11382
|
-
return symbol || undefined;
|
|
11383
|
-
};
|
|
11384
|
-
|
|
11385
11197
|
class System extends Base {
|
|
11386
|
-
constructor(config) {
|
|
11387
|
-
super(config);
|
|
11198
|
+
constructor(config, ports = {}) {
|
|
11199
|
+
super(config, ports);
|
|
11388
11200
|
}
|
|
11389
11201
|
/**
|
|
11390
11202
|
* @public
|
|
@@ -11470,9 +11282,6 @@ class System extends Base {
|
|
|
11470
11282
|
* @param {BlockchainName} blockchain - The name of the blockchain.
|
|
11471
11283
|
* @param {string} contractAddress - The contract address of the token (optional for non-SUI blockchains).
|
|
11472
11284
|
* @param {string} suiObjectId - The SUI object ID of the token (optional for SUI blockchain).
|
|
11473
|
-
* @param {string} assetSymbol - The asset symbol; disambiguates new SUI assets. For SUI it is
|
|
11474
|
-
* optional: when omitted, it is derived from the `::module::TYPE` suffix of `suiObjectId`
|
|
11475
|
-
* (which is otherwise trimmed off before the request is sent).
|
|
11476
11285
|
*
|
|
11477
11286
|
* @returns {Promise<{ decimals: number; symbol: string; name: string; tokenContractAddress: string }>} A promise that resolves to an object containing token information.
|
|
11478
11287
|
*
|
|
@@ -11481,19 +11290,18 @@ class System extends Base {
|
|
|
11481
11290
|
* @throws Will throw an error if `contractAddress` is not provided for non-SUI blockchains.
|
|
11482
11291
|
* @throws Will throw an error if the response is invalid or contains an error.
|
|
11483
11292
|
*/
|
|
11484
|
-
async fetchTokenInfo({ blockchain, contractAddress, suiObjectId,
|
|
11293
|
+
async fetchTokenInfo({ blockchain, contractAddress, suiObjectId, }) {
|
|
11485
11294
|
try {
|
|
11486
11295
|
const validatedContractAddress = this.validateContractAddress({
|
|
11487
11296
|
blockchain,
|
|
11488
11297
|
contractAddress,
|
|
11489
11298
|
suiObjectId,
|
|
11490
11299
|
});
|
|
11491
|
-
// For SUI, the coin symbol is the last segment of the coin type
|
|
11492
|
-
// (`<package>::<module>::<TYPE>`), which sanitizeSuiObjectId strips out.
|
|
11493
|
-
// Derive it so callers don't have to pass assetSymbol explicitly.
|
|
11494
|
-
const resolvedAssetSymbol = assetSymbol !== null && assetSymbol !== void 0 ? assetSymbol : (blockchain === exports.BlockchainName.Sui ? extractSuiAssetSymbol(suiObjectId) : undefined);
|
|
11495
11300
|
const response = await this.request(SystemRoutes.fetchTokenInfo, {
|
|
11496
|
-
queryParams:
|
|
11301
|
+
queryParams: {
|
|
11302
|
+
chainName: blockchain,
|
|
11303
|
+
tokenContractAddress: validatedContractAddress,
|
|
11304
|
+
},
|
|
11497
11305
|
});
|
|
11498
11306
|
return response;
|
|
11499
11307
|
}
|
|
@@ -11581,10 +11389,10 @@ class System extends Base {
|
|
|
11581
11389
|
}
|
|
11582
11390
|
|
|
11583
11391
|
class Transactions extends Base {
|
|
11584
|
-
constructor(config) {
|
|
11585
|
-
super(config);
|
|
11586
|
-
this.authService = new AuthService(config);
|
|
11587
|
-
this.walletService = new WalletService(config);
|
|
11392
|
+
constructor(config, ports = {}) {
|
|
11393
|
+
super(config, ports);
|
|
11394
|
+
this.authService = new AuthService(config, ports);
|
|
11395
|
+
this.walletService = new WalletService(config, ports);
|
|
11588
11396
|
this.userId = config.userId;
|
|
11589
11397
|
}
|
|
11590
11398
|
/**
|
|
@@ -12025,15 +11833,15 @@ class Wallaby {
|
|
|
12025
11833
|
* @param {string} [config.clientAuthToken] - A web token generated by the client for authorization.
|
|
12026
11834
|
* @public
|
|
12027
11835
|
*/
|
|
12028
|
-
constructor(config) {
|
|
12029
|
-
this.wallet = new WalletService(config);
|
|
12030
|
-
this.walletData = new WalletDataService(config);
|
|
12031
|
-
this.utils = new Utils(config);
|
|
12032
|
-
this.auth = new AuthService(config);
|
|
12033
|
-
this.system = new System(config);
|
|
12034
|
-
this.transactions = new Transactions(config);
|
|
12035
|
-
this.swap = new Swap(config);
|
|
12036
|
-
this.httpApi = new HttpApi(config);
|
|
11836
|
+
constructor(config, ports = {}) {
|
|
11837
|
+
this.wallet = new WalletService(config, ports);
|
|
11838
|
+
this.walletData = new WalletDataService(config, ports);
|
|
11839
|
+
this.utils = new Utils(config, ports);
|
|
11840
|
+
this.auth = new AuthService(config, ports);
|
|
11841
|
+
this.system = new System(config, ports);
|
|
11842
|
+
this.transactions = new Transactions(config, ports);
|
|
11843
|
+
this.swap = new Swap(config, ports);
|
|
11844
|
+
this.httpApi = new HttpApi(config, ports);
|
|
12037
11845
|
}
|
|
12038
11846
|
get version() {
|
|
12039
11847
|
return currentPackageVersion;
|