wallaby-cash 3.2.1 → 3.4.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/eth-crypto-utils/createIdentity.d.ts +0 -1
- package/dist/generated/api.d.ts +689 -143
- package/dist/helpers/base64.d.ts +5 -4
- package/dist/index.cjs.js +602 -430
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -8
- package/dist/index.esm.js +602 -430
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +582 -404
- package/dist/index.js.map +1 -1
- package/dist/lib/auth/auth.service.d.ts +8 -1
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/system/index.d.ts +5 -1
- package/dist/lib/transactions/index.d.ts +19 -13
- package/dist/lib/utils/cipher.service.d.ts +6 -0
- package/dist/lib/utils/extract-sui-asset-symbol.d.ts +12 -0
- package/dist/lib/utils/storage.service.d.ts +13 -0
- package/dist/lib/wallet/wallet-handlers.service.d.ts +18 -1
- package/dist/lib/wallet/wallet.service.d.ts +20 -2
- package/dist/package.json +8 -5
- package/dist/routes/auth.d.ts +5 -0
- package/dist/routes/transactions.d.ts +15 -0
- package/dist/types/storage.d.ts +5 -1
- package/package.json +8 -5
- package/dist/lib/merchants/index.d.ts +0 -59
- package/dist/routes/merchants.d.ts +0 -48
package/dist/index.cjs.js
CHANGED
|
@@ -342,6 +342,10 @@ exports.V2KeyNames = void 0;
|
|
|
342
342
|
V2KeyNames["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
|
|
343
343
|
V2KeyNames["MigrationVersion"] = "wsdk_migrated_with_version";
|
|
344
344
|
V2KeyNames["LastMigratedAt"] = "wsdk_last_migrated_at";
|
|
345
|
+
V2KeyNames["PasswordResetAttempts"] = "wsdk_password_reset_attempts";
|
|
346
|
+
V2KeyNames["MigrationAttempts"] = "wsdk_migration_attempts";
|
|
347
|
+
V2KeyNames["CredentialConversionInProgress"] = "credential-conversion-in-progress";
|
|
348
|
+
V2KeyNames["PendingCommit"] = "pending-commit";
|
|
345
349
|
})(exports.V2KeyNames || (exports.V2KeyNames = {}));
|
|
346
350
|
|
|
347
351
|
exports.ErrorResponseCodes = void 0;
|
|
@@ -572,7 +576,7 @@ const global$1 = (typeof global !== "undefined" ? global :
|
|
|
572
576
|
typeof self !== "undefined" ? self :
|
|
573
577
|
typeof window !== "undefined" ? window : {});
|
|
574
578
|
|
|
575
|
-
var env = {};
|
|
579
|
+
var env$1 = {};
|
|
576
580
|
|
|
577
581
|
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
|
|
578
582
|
var performance = global$1.performance || {};
|
|
@@ -584,7 +588,7 @@ performance.now ||
|
|
|
584
588
|
function(){ return (new Date()).getTime() };
|
|
585
589
|
|
|
586
590
|
var browser$1 = {
|
|
587
|
-
env: env};
|
|
591
|
+
env: env$1};
|
|
588
592
|
|
|
589
593
|
var _a;
|
|
590
594
|
/**
|
|
@@ -618,7 +622,12 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
|
|
|
618
622
|
{ type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
|
|
619
623
|
];
|
|
620
624
|
const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
621
|
-
const
|
|
625
|
+
const env = {
|
|
626
|
+
platform: 'web',
|
|
627
|
+
isNative: !isWeb,
|
|
628
|
+
isWeb,
|
|
629
|
+
};
|
|
630
|
+
const currentPackageVersion = "3.4.0" ;
|
|
622
631
|
|
|
623
632
|
/**
|
|
624
633
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -3519,7 +3528,6 @@ const keccak256$1 = (() => {
|
|
|
3519
3528
|
})();
|
|
3520
3529
|
|
|
3521
3530
|
const DEFAULT_ENTROPY_BYTES = 32;
|
|
3522
|
-
const MINIMUM_SHANNON_ENTROPY = 4;
|
|
3523
3531
|
/**
|
|
3524
3532
|
* creates a new private key
|
|
3525
3533
|
* @param { Uint8Array } entropy - optional entropy to create the private key
|
|
@@ -3530,25 +3538,15 @@ const createPrivateKey = (entropy) => {
|
|
|
3530
3538
|
if (!(entropy instanceof Uint8Array) || entropy.length < DEFAULT_ENTROPY_BYTES) {
|
|
3531
3539
|
throw new Error(`entropy must be a Uint8Array of at least ${DEFAULT_ENTROPY_BYTES} bytes`);
|
|
3532
3540
|
}
|
|
3533
|
-
// Check byte diversity
|
|
3541
|
+
// Check byte diversity. This catches genuinely broken inputs (all-zeros, all-same-byte)
|
|
3542
|
+
// 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
|
|
3544
|
+
// 32 samples (max measurable = log2(32) ≈ 5 bits/byte vs a 4-bit threshold), so deterministic
|
|
3545
|
+
// KDF output could be rejected, permanently locking the user out.
|
|
3534
3546
|
const uniqueBytes = new Set(entropy);
|
|
3535
3547
|
if (uniqueBytes.size < Math.min(8, entropy.length / 4)) {
|
|
3536
3548
|
throw new Error(`entropy is too repetitive (only ${uniqueBytes.size} unique byte values)`);
|
|
3537
3549
|
}
|
|
3538
|
-
// Estimate Shannon entropy
|
|
3539
|
-
const byteCounts = new Uint32Array(256);
|
|
3540
|
-
entropy.forEach((b) => byteCounts[b]++);
|
|
3541
|
-
const total = entropy.length;
|
|
3542
|
-
let shannonEntropy = 0;
|
|
3543
|
-
for (let i = 0; i < 256; i++) {
|
|
3544
|
-
if (byteCounts[i] > 0) {
|
|
3545
|
-
const p = byteCounts[i] / total;
|
|
3546
|
-
shannonEntropy -= p * Math.log2(p);
|
|
3547
|
-
}
|
|
3548
|
-
}
|
|
3549
|
-
if (shannonEntropy < MINIMUM_SHANNON_ENTROPY) {
|
|
3550
|
-
throw new Error(`entropy has low Shannon entropy (${shannonEntropy.toFixed(2)} bits/byte)`);
|
|
3551
|
-
}
|
|
3552
3550
|
const outerHex = keccak256$1(entropy);
|
|
3553
3551
|
return addLeading0x(bytesToHex$1(outerHex));
|
|
3554
3552
|
}
|
|
@@ -4423,6 +4421,11 @@ function pbkdf2Sync(password, salt, iterations, keylen, digest) {
|
|
|
4423
4421
|
});
|
|
4424
4422
|
}
|
|
4425
4423
|
|
|
4424
|
+
// Version marker prepended to values wrapped by the master key, so wrapped vs raw is deterministic.
|
|
4425
|
+
const MASTER_KEY_WRAP_PREFIX = 'wsdkmk:v1:';
|
|
4426
|
+
// crypto-js AES.encrypt with a string passphrase emits an OpenSSL "Salted__" header; its base64 always
|
|
4427
|
+
// starts with this. Used to recognize legacy wrapped values stored before MASTER_KEY_WRAP_PREFIX existed.
|
|
4428
|
+
const LEGACY_CRYPTOJS_PREFIX = 'U2FsdGVkX1';
|
|
4426
4429
|
class Cipher {
|
|
4427
4430
|
constructor() { }
|
|
4428
4431
|
/**
|
|
@@ -4453,17 +4456,34 @@ class Cipher {
|
|
|
4453
4456
|
* @returns The encrypted data as a string.
|
|
4454
4457
|
*/
|
|
4455
4458
|
encryptWithMasterKey({ data }) {
|
|
4456
|
-
|
|
4459
|
+
const ciphertext = cryptoJs.AES.encrypt(typeof data === 'string' ? data : JSON.stringify(data), this.getMasterKey().key).toString();
|
|
4460
|
+
return MASTER_KEY_WRAP_PREFIX + ciphertext;
|
|
4461
|
+
}
|
|
4462
|
+
/**
|
|
4463
|
+
* @description Determines deterministically whether a stored value was wrapped by the master key,
|
|
4464
|
+
* without inferring from decrypt behavior. Returns true for values carrying the version marker, or
|
|
4465
|
+
* legacy crypto-js ciphertext stored before the marker existed. Everything else is treated as raw.
|
|
4466
|
+
*/
|
|
4467
|
+
isWrappedByMasterKey(value) {
|
|
4468
|
+
return value.startsWith(MASTER_KEY_WRAP_PREFIX) || value.startsWith(LEGACY_CRYPTOJS_PREFIX);
|
|
4457
4469
|
}
|
|
4458
4470
|
decryptWithMasterKey({ cipherText }) {
|
|
4459
|
-
const
|
|
4460
|
-
|
|
4461
|
-
|
|
4471
|
+
const ciphertext = cipherText.startsWith(MASTER_KEY_WRAP_PREFIX)
|
|
4472
|
+
? cipherText.slice(MASTER_KEY_WRAP_PREFIX.length)
|
|
4473
|
+
: cipherText;
|
|
4474
|
+
try {
|
|
4475
|
+
const decrypted = cryptoJs.AES.decrypt(ciphertext, this.getMasterKey().key).toString(cryptoJs.enc.Utf8);
|
|
4476
|
+
if (decrypted) {
|
|
4477
|
+
return isJsonString(decrypted) ? safeJsonParse(decrypted) : decrypted;
|
|
4478
|
+
}
|
|
4462
4479
|
}
|
|
4463
|
-
|
|
4464
|
-
|
|
4480
|
+
catch (error) {
|
|
4481
|
+
// crypto-js throws "Malformed UTF-8 data" when the ciphertext can't be decrypted
|
|
4482
|
+
logger.error('Decryption failed with master key', error);
|
|
4465
4483
|
return undefined;
|
|
4466
4484
|
}
|
|
4485
|
+
logger.error('Decryption failed with master key');
|
|
4486
|
+
return undefined;
|
|
4467
4487
|
}
|
|
4468
4488
|
/**
|
|
4469
4489
|
* Validate that a public key is the correct length and format.
|
|
@@ -4570,6 +4590,8 @@ class Cipher {
|
|
|
4570
4590
|
}
|
|
4571
4591
|
derivedKeyPair = await this.deriveKeyPairFromPasskey({ inputKeyMaterial: options.prfValue });
|
|
4572
4592
|
return derivedKeyPair;
|
|
4593
|
+
default:
|
|
4594
|
+
throw new Error(`Unknown AuthType: ${options.authType}`);
|
|
4573
4595
|
}
|
|
4574
4596
|
}
|
|
4575
4597
|
catch (error) {
|
|
@@ -4829,6 +4851,14 @@ class StorageService {
|
|
|
4829
4851
|
return;
|
|
4830
4852
|
}
|
|
4831
4853
|
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
|
+
})));
|
|
4832
4862
|
let storageKey;
|
|
4833
4863
|
if (this._walletSpecificKeys.includes(key)) {
|
|
4834
4864
|
if (!(options === null || options === void 0 ? void 0 : options.walletId)) {
|
|
@@ -4839,7 +4869,7 @@ class StorageService {
|
|
|
4839
4869
|
else {
|
|
4840
4870
|
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}`;
|
|
4841
4871
|
}
|
|
4842
|
-
if (
|
|
4872
|
+
if (env.isNative) {
|
|
4843
4873
|
storageKey = normalizeKey(storageKey);
|
|
4844
4874
|
}
|
|
4845
4875
|
const item = await this.getItem(storageKey);
|
|
@@ -4848,14 +4878,11 @@ class StorageService {
|
|
|
4848
4878
|
return undefined;
|
|
4849
4879
|
}
|
|
4850
4880
|
if (this._keysProtectedByMasterKey.includes(key)) {
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
unwrapped = this.cipher.decryptWithMasterKey({ cipherText: item });
|
|
4855
|
-
}
|
|
4856
|
-
catch (_a) {
|
|
4857
|
-
unwrapped = item;
|
|
4881
|
+
// Raw legacy value stored before master-key wrapping: return as-is instead of attempting decrypt.
|
|
4882
|
+
if (!this.cipher.isWrappedByMasterKey(item)) {
|
|
4883
|
+
return item;
|
|
4858
4884
|
}
|
|
4885
|
+
const unwrapped = this.cipher.decryptWithMasterKey({ cipherText: item });
|
|
4859
4886
|
if (!unwrapped) {
|
|
4860
4887
|
logger.error(`Failed to decrypt item with key ${storageKey}`);
|
|
4861
4888
|
return undefined;
|
|
@@ -4875,7 +4902,7 @@ class StorageService {
|
|
|
4875
4902
|
else {
|
|
4876
4903
|
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}`;
|
|
4877
4904
|
}
|
|
4878
|
-
if (
|
|
4905
|
+
if (env.isNative) {
|
|
4879
4906
|
storageKey = normalizeKey(storageKey);
|
|
4880
4907
|
}
|
|
4881
4908
|
let valueToStore;
|
|
@@ -4891,6 +4918,75 @@ class StorageService {
|
|
|
4891
4918
|
async saveInBulk(data) {
|
|
4892
4919
|
await Promise.all(data.map((item) => this.save(item.key, item.value, { walletId: item.walletId })));
|
|
4893
4920
|
}
|
|
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
|
+
}
|
|
4894
4990
|
async delete(key, options) {
|
|
4895
4991
|
let storageKey;
|
|
4896
4992
|
if (this._walletSpecificKeys.includes(key)) {
|
|
@@ -4902,7 +4998,7 @@ class StorageService {
|
|
|
4902
4998
|
else {
|
|
4903
4999
|
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}`;
|
|
4904
5000
|
}
|
|
4905
|
-
if (
|
|
5001
|
+
if (env.isNative) {
|
|
4906
5002
|
storageKey = normalizeKey(storageKey);
|
|
4907
5003
|
}
|
|
4908
5004
|
return await this.removeItem(storageKey);
|
|
@@ -5167,11 +5263,16 @@ class StorageService {
|
|
|
5167
5263
|
exports.LocalStorageItems.AccessToken,
|
|
5168
5264
|
exports.LocalStorageItems.RefreshToken,
|
|
5169
5265
|
exports.V2KeyNames.EncryptedDevicePrivateKey,
|
|
5266
|
+
exports.V2KeyNames.ClientAuthPublicKey,
|
|
5170
5267
|
exports.V2KeyNames.WallabyAuthPubKey,
|
|
5171
5268
|
exports.V2KeyNames.PasskeyCredential,
|
|
5172
5269
|
exports.V2KeyNames.MigrationVersion,
|
|
5173
5270
|
exports.V2KeyNames.LastMigratedAt,
|
|
5174
5271
|
exports.V2KeyNames.ClientAuthToken,
|
|
5272
|
+
exports.V2KeyNames.PasswordResetAttempts,
|
|
5273
|
+
exports.V2KeyNames.MigrationAttempts,
|
|
5274
|
+
exports.V2KeyNames.CredentialConversionInProgress,
|
|
5275
|
+
exports.V2KeyNames.PendingCommit,
|
|
5175
5276
|
];
|
|
5176
5277
|
await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
|
|
5177
5278
|
if (walletId) {
|
|
@@ -5303,6 +5404,11 @@ const AuthRoutes = {
|
|
|
5303
5404
|
method: exports.RequestMethod.Get,
|
|
5304
5405
|
requiresAccessToken: true,
|
|
5305
5406
|
},
|
|
5407
|
+
issueJwtToken: {
|
|
5408
|
+
fullPath: '/auth/issue-jwt-token',
|
|
5409
|
+
method: exports.RequestMethod.Post,
|
|
5410
|
+
requiresAccessToken: false,
|
|
5411
|
+
},
|
|
5306
5412
|
};
|
|
5307
5413
|
|
|
5308
5414
|
class LockManagerService {
|
|
@@ -5682,6 +5788,16 @@ class Api {
|
|
|
5682
5788
|
* @secure
|
|
5683
5789
|
*/
|
|
5684
5790
|
signIn: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/auth/sign-in`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
|
|
5791
|
+
/**
|
|
5792
|
+
* No description
|
|
5793
|
+
*
|
|
5794
|
+
* @tags Auth
|
|
5795
|
+
* @name IssueJwtToken
|
|
5796
|
+
* @summary Issue a Wallaby JWT token for a user using only x-api-key and x-client-jwt headers. Requires mfaVerified and that the user belongs to the API key merchant.
|
|
5797
|
+
* @request POST:/api/v1/auth/issue-jwt-token
|
|
5798
|
+
* @secure
|
|
5799
|
+
*/
|
|
5800
|
+
issueJwtToken: (params = {}) => this.http.request(Object.assign({ path: `/api/v1/auth/issue-jwt-token`, method: "POST", secure: true, format: "json" }, params)),
|
|
5685
5801
|
/**
|
|
5686
5802
|
* No description
|
|
5687
5803
|
*
|
|
@@ -6180,6 +6296,20 @@ class Api {
|
|
|
6180
6296
|
if (params === void 0) { params = {}; }
|
|
6181
6297
|
return this.http.request(Object.assign({ path: `/api/v1/wallets/${walletId}/assets`, method: "GET", query: query, secure: true, format: "json" }, params));
|
|
6182
6298
|
},
|
|
6299
|
+
/**
|
|
6300
|
+
* No description
|
|
6301
|
+
*
|
|
6302
|
+
* @tags Wallets
|
|
6303
|
+
* @name GetWalletAddresses
|
|
6304
|
+
* @summary Get all assets that exist in a certain wallet, by specifying a wallet ID
|
|
6305
|
+
* @request GET:/api/v1/wallets/{walletId}/addresses
|
|
6306
|
+
* @secure
|
|
6307
|
+
*/
|
|
6308
|
+
getWalletAddresses: (_a, params) => {
|
|
6309
|
+
var { walletId } = _a, query = __rest(_a, ["walletId"]);
|
|
6310
|
+
if (params === void 0) { params = {}; }
|
|
6311
|
+
return this.http.request(Object.assign({ path: `/api/v1/wallets/${walletId}/addresses`, method: "GET", query: query, secure: true, format: "json" }, params));
|
|
6312
|
+
},
|
|
6183
6313
|
/**
|
|
6184
6314
|
* No description
|
|
6185
6315
|
*
|
|
@@ -6379,23 +6509,35 @@ class Api {
|
|
|
6379
6509
|
/**
|
|
6380
6510
|
* No description
|
|
6381
6511
|
*
|
|
6382
|
-
* @tags Transactions, Transactions
|
|
6512
|
+
* @tags Transactions, Transactions
|
|
6383
6513
|
* @name DetectTransferRestriction
|
|
6384
6514
|
* @summary Request to detect whether there is a transfer restriction on a particular transaction
|
|
6385
6515
|
* @request GET:/api/v1/transactions/detect-transfers-restrictions
|
|
6516
|
+
* @deprecated
|
|
6386
6517
|
* @secure
|
|
6387
6518
|
*/
|
|
6388
6519
|
detectTransferRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/detect-transfers-restrictions`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6389
6520
|
/**
|
|
6390
6521
|
* No description
|
|
6391
6522
|
*
|
|
6392
|
-
* @tags Transactions, Transactions
|
|
6523
|
+
* @tags Transactions, Transactions
|
|
6393
6524
|
* @name FetchMessageForTransferRestriction
|
|
6394
6525
|
* @summary Request restriction message by providing a restriction code
|
|
6395
6526
|
* @request GET:/api/v1/transactions/transfer-restriction-message
|
|
6527
|
+
* @deprecated
|
|
6396
6528
|
* @secure
|
|
6397
6529
|
*/
|
|
6398
6530
|
fetchMessageForTransferRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/transfer-restriction-message`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6531
|
+
/**
|
|
6532
|
+
* No description
|
|
6533
|
+
*
|
|
6534
|
+
* @tags Transactions, Transactions
|
|
6535
|
+
* @name GetRestriction
|
|
6536
|
+
* @summary Request to detect whether there is a transfer restriction on a particular transaction
|
|
6537
|
+
* @request GET:/api/v1/transactions/restriction
|
|
6538
|
+
* @secure
|
|
6539
|
+
*/
|
|
6540
|
+
getRestriction: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/restriction`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6399
6541
|
/**
|
|
6400
6542
|
* No description
|
|
6401
6543
|
*
|
|
@@ -6874,8 +7016,9 @@ class Base {
|
|
|
6874
7016
|
this.userId = sanitizedConfig.userId;
|
|
6875
7017
|
this.options = sanitizedConfig.options;
|
|
6876
7018
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.platform) {
|
|
6877
|
-
this.options.platform;
|
|
6878
|
-
this.options.platform === 'ios' || this.options.platform === 'android';
|
|
7019
|
+
env.platform = this.options.platform;
|
|
7020
|
+
env.isNative = this.options.platform === 'ios' || this.options.platform === 'android';
|
|
7021
|
+
env.isWeb = !env.isNative;
|
|
6879
7022
|
}
|
|
6880
7023
|
this.cipher = new Cipher();
|
|
6881
7024
|
this.lockManager = new LockManagerService();
|
|
@@ -7369,7 +7512,22 @@ const TransactionsRoutes = {
|
|
|
7369
7512
|
requiresAccessToken: true,
|
|
7370
7513
|
},
|
|
7371
7514
|
getTransactions: {
|
|
7372
|
-
fullPath: '/
|
|
7515
|
+
fullPath: '/transactions',
|
|
7516
|
+
method: exports.RequestMethod.Get,
|
|
7517
|
+
requiresAccessToken: true,
|
|
7518
|
+
},
|
|
7519
|
+
detectTransferRestrictions: {
|
|
7520
|
+
fullPath: '/transactions/detect-transfers-restrictions',
|
|
7521
|
+
method: exports.RequestMethod.Get,
|
|
7522
|
+
requiresAccessToken: true,
|
|
7523
|
+
},
|
|
7524
|
+
transferRestrictionMessage: {
|
|
7525
|
+
fullPath: '/transactions/transfer-restriction-message',
|
|
7526
|
+
method: exports.RequestMethod.Get,
|
|
7527
|
+
requiresAccessToken: true,
|
|
7528
|
+
},
|
|
7529
|
+
restriction: {
|
|
7530
|
+
fullPath: '/transactions/restriction',
|
|
7373
7531
|
method: exports.RequestMethod.Get,
|
|
7374
7532
|
requiresAccessToken: true,
|
|
7375
7533
|
},
|
|
@@ -7515,6 +7673,17 @@ function normalizeAndPadBase64(s) {
|
|
|
7515
7673
|
function decodeBase64String(s) {
|
|
7516
7674
|
return jsBase64.toUint8Array(normalizeAndPadBase64(s));
|
|
7517
7675
|
}
|
|
7676
|
+
/**
|
|
7677
|
+
* Single-decode only: decode base64 (or base64url) to bytes. No round-trip double-decode.
|
|
7678
|
+
*/
|
|
7679
|
+
function base64ToUint8Array(base64) {
|
|
7680
|
+
try {
|
|
7681
|
+
return jsBase64.toUint8Array(base64);
|
|
7682
|
+
}
|
|
7683
|
+
catch (_a) {
|
|
7684
|
+
return decodeBase64String(base64);
|
|
7685
|
+
}
|
|
7686
|
+
}
|
|
7518
7687
|
function decodeBase64URL(base64url) {
|
|
7519
7688
|
const padded = normalizeAndPadBase64(base64url);
|
|
7520
7689
|
const binary = jsBase64.atob(padded);
|
|
@@ -7525,29 +7694,6 @@ function decodeBase64URL(base64url) {
|
|
|
7525
7694
|
return bytes;
|
|
7526
7695
|
}
|
|
7527
7696
|
|
|
7528
|
-
/**
|
|
7529
|
-
* Web: round-trip with uint8ArrayToBase64 (which does btoa(fromUint8Array(bytes, true))).
|
|
7530
|
-
* Single decode first; if the result looks like a base64 string, decode again to get original bytes.
|
|
7531
|
-
*/
|
|
7532
|
-
function base64ToUint8Array(base64) {
|
|
7533
|
-
try {
|
|
7534
|
-
const first = jsBase64.toUint8Array(base64);
|
|
7535
|
-
const asStr = String.fromCharCode.apply(null, first);
|
|
7536
|
-
if (/^[A-Za-z0-9+/\-_=]*$/.test(asStr) && asStr.length >= 4) {
|
|
7537
|
-
try {
|
|
7538
|
-
return decodeBase64String(asStr);
|
|
7539
|
-
}
|
|
7540
|
-
catch (_a) {
|
|
7541
|
-
// fall through
|
|
7542
|
-
}
|
|
7543
|
-
}
|
|
7544
|
-
return first;
|
|
7545
|
-
}
|
|
7546
|
-
catch (_b) {
|
|
7547
|
-
return decodeBase64String(base64);
|
|
7548
|
-
}
|
|
7549
|
-
}
|
|
7550
|
-
|
|
7551
7697
|
class PasskeyService {
|
|
7552
7698
|
constructor(userId, storageService, request) {
|
|
7553
7699
|
this.cipher = new Cipher();
|
|
@@ -7850,7 +7996,6 @@ class PasskeyService {
|
|
|
7850
7996
|
}
|
|
7851
7997
|
logger.log('SDK::PasskeyService::register:: getting signature', {
|
|
7852
7998
|
message: challengeResponse.message,
|
|
7853
|
-
privateKey: deviceKeyPair.privateKey,
|
|
7854
7999
|
});
|
|
7855
8000
|
const { signature, message } = await this.cipher.sign({
|
|
7856
8001
|
message: challengeResponse.message,
|
|
@@ -8496,7 +8641,7 @@ class AuthService extends Base {
|
|
|
8496
8641
|
data: deviceKeyPair.privateKey,
|
|
8497
8642
|
encryptionKey: credentialsKeyPair.publicKey,
|
|
8498
8643
|
});
|
|
8499
|
-
this.localStorageService.saveInBulk([
|
|
8644
|
+
await this.localStorageService.saveInBulk([
|
|
8500
8645
|
{
|
|
8501
8646
|
key: exports.LocalStorageItems.EncryptedDevicePrivateKey,
|
|
8502
8647
|
value: encryptedDevicePrivKey,
|
|
@@ -8567,6 +8712,24 @@ class AuthService extends Base {
|
|
|
8567
8712
|
valid: true,
|
|
8568
8713
|
};
|
|
8569
8714
|
}
|
|
8715
|
+
/**
|
|
8716
|
+
* @description Exchanges the client JWT (set at SDK initialisation) for a
|
|
8717
|
+
* Wallaby access + refresh token pair. Tokens are persisted to storage so
|
|
8718
|
+
* subsequent SDK calls use them automatically.
|
|
8719
|
+
* @returns {Promise<IssueJWTTokenResponseDto>} The issued access/refresh tokens and basic user info.
|
|
8720
|
+
*/
|
|
8721
|
+
async exchangeClientToken() {
|
|
8722
|
+
try {
|
|
8723
|
+
const response = await this.request(AuthRoutes.issueJwtToken);
|
|
8724
|
+
await this.localStorageService.save(exports.LocalStorageItems.AccessToken, response.accessToken);
|
|
8725
|
+
await this.localStorageService.save(exports.LocalStorageItems.RefreshToken, response.refreshToken);
|
|
8726
|
+
return response;
|
|
8727
|
+
}
|
|
8728
|
+
catch (error) {
|
|
8729
|
+
logger.error('SDK::Auth::exchangeClientToken::error', error);
|
|
8730
|
+
throw error;
|
|
8731
|
+
}
|
|
8732
|
+
}
|
|
8570
8733
|
}
|
|
8571
8734
|
__decorate([
|
|
8572
8735
|
WithLock('signUp'),
|
|
@@ -8587,6 +8750,63 @@ __decorate([
|
|
|
8587
8750
|
__metadata("design:returntype", Promise)
|
|
8588
8751
|
], AuthService.prototype, "storeDeviceKeyPair", null);
|
|
8589
8752
|
|
|
8753
|
+
const ENCRYPTED_PAYLOAD_FIELDS = ['iv', 'ephemPublicKey', 'ciphertext', 'mac'];
|
|
8754
|
+
// Backup share may be ECIES or symmetric ({ iv, ciphertext, mac, tag }) — both share these three fields.
|
|
8755
|
+
const SYMMETRIC_PAYLOAD_FIELDS = ['iv', 'ciphertext', 'mac', 'tag'];
|
|
8756
|
+
// API is the trust boundary: confirm every named field is a non-empty string.
|
|
8757
|
+
function hasNonEmptyStringFields(payload, fields) {
|
|
8758
|
+
return (!!payload &&
|
|
8759
|
+
typeof payload === 'object' &&
|
|
8760
|
+
fields.every((field) => {
|
|
8761
|
+
const value = payload[field];
|
|
8762
|
+
return typeof value === 'string' && value.length > 0;
|
|
8763
|
+
}));
|
|
8764
|
+
}
|
|
8765
|
+
/**
|
|
8766
|
+
* Fail fast if an encrypted payload from the API does not match the expected
|
|
8767
|
+
* ECIES structure ({ iv, ephemPublicKey, ciphertext, mac }). See the contract
|
|
8768
|
+
* note on `handleKeySharesFromResponse`.
|
|
8769
|
+
*/
|
|
8770
|
+
function assertEncryptedPayloadShape(encrypted) {
|
|
8771
|
+
if (!hasNonEmptyStringFields(encrypted, ENCRYPTED_PAYLOAD_FIELDS)) {
|
|
8772
|
+
throw new WallabyError({
|
|
8773
|
+
message: 'Encrypted share does not match the expected { iv, ephemPublicKey, ciphertext, mac } format.',
|
|
8774
|
+
statusCode: 422,
|
|
8775
|
+
errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
|
|
8776
|
+
});
|
|
8777
|
+
}
|
|
8778
|
+
}
|
|
8779
|
+
/**
|
|
8780
|
+
* Shape-assert every share returned by the API. Empty arrays are rejected here
|
|
8781
|
+
* so callers get a clean error instead of crashing on `shares[0]`.
|
|
8782
|
+
*/
|
|
8783
|
+
function assertSharesPayloadShape(shares) {
|
|
8784
|
+
if (!shares.length) {
|
|
8785
|
+
throw new WallabyError({
|
|
8786
|
+
message: 'No key shares were returned from the API.',
|
|
8787
|
+
statusCode: 422,
|
|
8788
|
+
errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
|
|
8789
|
+
});
|
|
8790
|
+
}
|
|
8791
|
+
for (const share of shares) {
|
|
8792
|
+
assertEncryptedPayloadShape(share.encrypted);
|
|
8793
|
+
}
|
|
8794
|
+
}
|
|
8795
|
+
/**
|
|
8796
|
+
* The backup share is stored as-is (the device can't peel it), so we only
|
|
8797
|
+
* shape-check it. It may be ECIES or symmetric, so accept either variant.
|
|
8798
|
+
*/
|
|
8799
|
+
function assertBackupSharePayloadShape(encrypted) {
|
|
8800
|
+
const isEcies = hasNonEmptyStringFields(encrypted, ENCRYPTED_PAYLOAD_FIELDS);
|
|
8801
|
+
const isSymmetric = hasNonEmptyStringFields(encrypted, SYMMETRIC_PAYLOAD_FIELDS);
|
|
8802
|
+
if (!isEcies && !isSymmetric) {
|
|
8803
|
+
throw new WallabyError({
|
|
8804
|
+
message: 'Encrypted backup share does not match the expected ECIES ({ iv, ephemPublicKey, ciphertext, mac }) or symmetric ({ iv, ciphertext, mac, tag }) format.',
|
|
8805
|
+
statusCode: 422,
|
|
8806
|
+
errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
|
|
8807
|
+
});
|
|
8808
|
+
}
|
|
8809
|
+
}
|
|
8590
8810
|
class WalletHandlersService extends Base {
|
|
8591
8811
|
constructor(config) {
|
|
8592
8812
|
super(config);
|
|
@@ -8667,6 +8887,7 @@ class WalletHandlersService extends Base {
|
|
|
8667
8887
|
shares: importWalletRequest.shares,
|
|
8668
8888
|
credentialsKeyPair,
|
|
8669
8889
|
encryptedBackupShare: importWalletRequest.encryptedBackupShare,
|
|
8890
|
+
devicePrivateKey: deviceAuthKeys.privateKey,
|
|
8670
8891
|
});
|
|
8671
8892
|
}
|
|
8672
8893
|
return Object.assign({}, importWalletRequest);
|
|
@@ -8753,6 +8974,7 @@ class WalletHandlersService extends Base {
|
|
|
8753
8974
|
shares: walletCreationResponse.shares,
|
|
8754
8975
|
credentialsKeyPair,
|
|
8755
8976
|
encryptedBackupShare: walletCreationResponse.encryptedBackupShare,
|
|
8977
|
+
devicePrivateKey: deviceAuthKeys.privateKey,
|
|
8756
8978
|
});
|
|
8757
8979
|
}
|
|
8758
8980
|
return Object.assign(Object.assign({}, walletCreationResponse), { standardSeedPhrase: decryptedSeedPhrase });
|
|
@@ -8768,8 +8990,41 @@ class WalletHandlersService extends Base {
|
|
|
8768
8990
|
});
|
|
8769
8991
|
}
|
|
8770
8992
|
}
|
|
8771
|
-
|
|
8993
|
+
/**
|
|
8994
|
+
* Encrypted share format contract (WAL-1467)
|
|
8995
|
+
* --------------------------------------------------------------------------
|
|
8996
|
+
* Every flow that ingests shares from the API (import, create, recover,
|
|
8997
|
+
* addNewDevice) routes through here, so the contract is asserted in one place.
|
|
8998
|
+
*
|
|
8999
|
+
* The API returns the main device share as `shares[0]`, an ECIES payload
|
|
9000
|
+
* ({ iv, ephemPublicKey, ciphertext, mac }) wrapped to the device public key,
|
|
9001
|
+
* so it MUST peel with the device private key. `encryptedBackupShare` is an
|
|
9002
|
+
* already-wrapped blob (ECIES or symmetric) that the device cannot decrypt, so
|
|
9003
|
+
* it is stored as-is.
|
|
9004
|
+
*
|
|
9005
|
+
* We shape-assert every share (and the backup share) here, at ingestion, so a
|
|
9006
|
+
* server-side wrapping change fails loudly now instead of silently breaking
|
|
9007
|
+
* export/recovery later.
|
|
9008
|
+
*/
|
|
9009
|
+
async handleKeySharesFromResponse({ walletId, shares, credentialsKeyPair, encryptedBackupShare, devicePrivateKey, }) {
|
|
8772
9010
|
try {
|
|
9011
|
+
assertSharesPayloadShape(shares);
|
|
9012
|
+
assertBackupSharePayloadShape(encryptedBackupShare);
|
|
9013
|
+
// Decrypt-test the contract: shares[0] is wrapped to the device public key and must peel with the device private key.
|
|
9014
|
+
try {
|
|
9015
|
+
await this.cipher.decrypt({
|
|
9016
|
+
cipherText: shares[0].encrypted,
|
|
9017
|
+
decryptionKey: devicePrivateKey,
|
|
9018
|
+
});
|
|
9019
|
+
}
|
|
9020
|
+
catch (error) {
|
|
9021
|
+
throw new WallabyError({
|
|
9022
|
+
message: 'Device-wrapped key share (shares[0]) could not be decrypted with the device private key; the share wrapping format may have changed.',
|
|
9023
|
+
statusCode: 422,
|
|
9024
|
+
errorCode: exports.ErrorResponseCodes.sdk_key_share_decryption_failed,
|
|
9025
|
+
cause: error,
|
|
9026
|
+
});
|
|
9027
|
+
}
|
|
8773
9028
|
const encryptedWithCredentialsKeyShare = await this.cipher.encrypt({
|
|
8774
9029
|
data: JSON.stringify(shares[0].encrypted),
|
|
8775
9030
|
encryptionKey: credentialsKeyPair.publicKey,
|
|
@@ -8863,13 +9118,42 @@ class WalletHandlersService extends Base {
|
|
|
8863
9118
|
class WalletService extends Base {
|
|
8864
9119
|
constructor(config) {
|
|
8865
9120
|
super(config);
|
|
8866
|
-
this.passwordResetAttempts = 0;
|
|
8867
|
-
this.migrationAttempts = 0;
|
|
8868
9121
|
this.authService = new AuthService(config);
|
|
8869
9122
|
this.handlers = new WalletHandlersService(config);
|
|
8870
9123
|
this.userId = config.userId;
|
|
8871
9124
|
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request);
|
|
8872
9125
|
}
|
|
9126
|
+
/**
|
|
9127
|
+
* Reads the persisted sliding-window rate-limit state for a counter key.
|
|
9128
|
+
* Returns a fresh window ({ count: 0 }) when none is stored or the window has expired.
|
|
9129
|
+
*/
|
|
9130
|
+
async getRateState(key) {
|
|
9131
|
+
const now = Date.now();
|
|
9132
|
+
const raw = await this.localStorageService.fetch(key);
|
|
9133
|
+
const state = raw ? safeJsonParse(raw) : undefined;
|
|
9134
|
+
if (!state || now - state.windowStart > WalletService.RATE_LIMIT_WINDOW_MS) {
|
|
9135
|
+
return { count: 0, windowStart: now };
|
|
9136
|
+
}
|
|
9137
|
+
return state;
|
|
9138
|
+
}
|
|
9139
|
+
/** Increments and persists the counter (resetting an expired window). Returns the new count. */
|
|
9140
|
+
async recordRateAttempt(key) {
|
|
9141
|
+
const state = await this.getRateState(key);
|
|
9142
|
+
state.count += 1;
|
|
9143
|
+
await this.localStorageService.save(key, JSON.stringify(state));
|
|
9144
|
+
return state.count;
|
|
9145
|
+
}
|
|
9146
|
+
/** Throws a 429 when the counter is already over the limit, without incrementing it. */
|
|
9147
|
+
async assertUnderRateLimit(key, message) {
|
|
9148
|
+
const { count } = await this.getRateState(key);
|
|
9149
|
+
if (count > WalletService.RATE_LIMIT_MAX) {
|
|
9150
|
+
throw new WallabyError({
|
|
9151
|
+
message,
|
|
9152
|
+
statusCode: 429,
|
|
9153
|
+
errorCode: exports.ErrorResponseCodes.sdk_too_many_requests,
|
|
9154
|
+
});
|
|
9155
|
+
}
|
|
9156
|
+
}
|
|
8873
9157
|
/**
|
|
8874
9158
|
* @public
|
|
8875
9159
|
* @returns {boolean} Returns true if the device has a seed phrase.
|
|
@@ -8975,20 +9259,7 @@ class WalletService extends Base {
|
|
|
8975
9259
|
});
|
|
8976
9260
|
}
|
|
8977
9261
|
if (this.deviceAuthType === exports.AuthType.Password && authenticationOptions.password) {
|
|
8978
|
-
|
|
8979
|
-
await this.handleUpdateToV2({
|
|
8980
|
-
password: authenticationOptions.password,
|
|
8981
|
-
walletId: walletId,
|
|
8982
|
-
});
|
|
8983
|
-
}
|
|
8984
|
-
catch (error) {
|
|
8985
|
-
logger.error('SDK::WalletService::export::handleUpdateToV2::error', error);
|
|
8986
|
-
throw new WallabyError({
|
|
8987
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
8988
|
-
statusCode: 500,
|
|
8989
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
8990
|
-
});
|
|
8991
|
-
}
|
|
9262
|
+
await this.migrateToV2Safe({ password: authenticationOptions.password, walletId });
|
|
8992
9263
|
}
|
|
8993
9264
|
const encryptedSeed = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase, { walletId });
|
|
8994
9265
|
const encryptedPrimaryDeviceShare = await this.localStorageService.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare, {
|
|
@@ -9231,6 +9502,7 @@ class WalletService extends Base {
|
|
|
9231
9502
|
shares: recoverWithSeedPhraseResponse.shares,
|
|
9232
9503
|
credentialsKeyPair,
|
|
9233
9504
|
encryptedBackupShare: recoverWithSeedPhraseResponse.encryptedBackupShare,
|
|
9505
|
+
devicePrivateKey: deviceAuthKeyPair.privateKey,
|
|
9234
9506
|
});
|
|
9235
9507
|
}
|
|
9236
9508
|
await this.authService.storeDeviceKeyPair({
|
|
@@ -9294,6 +9566,7 @@ class WalletService extends Base {
|
|
|
9294
9566
|
shares: recoverWithSeedPhraseResponse.shares,
|
|
9295
9567
|
credentialsKeyPair,
|
|
9296
9568
|
encryptedBackupShare: recoverWithSeedPhraseResponse.encryptedBackupShare,
|
|
9569
|
+
devicePrivateKey: deviceAuthKeyPair.privateKey,
|
|
9297
9570
|
});
|
|
9298
9571
|
}
|
|
9299
9572
|
await this.authService.storeDeviceKeyPair({
|
|
@@ -9326,8 +9599,7 @@ class WalletService extends Base {
|
|
|
9326
9599
|
*/
|
|
9327
9600
|
async changePassword({ walletId, oldPassword, newPassword, }) {
|
|
9328
9601
|
try {
|
|
9329
|
-
this.
|
|
9330
|
-
if (this.passwordResetAttempts > 5) {
|
|
9602
|
+
if ((await this.recordRateAttempt(exports.V2KeyNames.PasswordResetAttempts)) > WalletService.RATE_LIMIT_MAX) {
|
|
9331
9603
|
throw new WallabyError({
|
|
9332
9604
|
message: 'Too many password change attempts. Please try again later.',
|
|
9333
9605
|
statusCode: 429,
|
|
@@ -9336,20 +9608,7 @@ class WalletService extends Base {
|
|
|
9336
9608
|
}
|
|
9337
9609
|
if (this.deviceAuthType === exports.AuthType.Password && oldPassword) {
|
|
9338
9610
|
// Handle migration to V2 first then change the password to the new one.
|
|
9339
|
-
|
|
9340
|
-
await this.handleUpdateToV2({
|
|
9341
|
-
password: oldPassword,
|
|
9342
|
-
walletId,
|
|
9343
|
-
});
|
|
9344
|
-
}
|
|
9345
|
-
catch (error) {
|
|
9346
|
-
logger.error('SDK::WalletService::changePassword::handleUpdateToV2::error', error);
|
|
9347
|
-
throw new WallabyError({
|
|
9348
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
9349
|
-
statusCode: 500,
|
|
9350
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
9351
|
-
});
|
|
9352
|
-
}
|
|
9611
|
+
await this.migrateToV2Safe({ password: oldPassword, walletId });
|
|
9353
9612
|
}
|
|
9354
9613
|
const encryptedDevicePrivateKeyString = await this.localStorageService.fetch(exports.V2KeyNames.EncryptedDevicePrivateKey);
|
|
9355
9614
|
const encryptedSeedPhraseString = await this.localStorageService.fetch(exports.V2KeyNames.EncryptedStandardSeedPhrase, {
|
|
@@ -9383,7 +9642,7 @@ class WalletService extends Base {
|
|
|
9383
9642
|
password: newPassword,
|
|
9384
9643
|
salt: clientSalt,
|
|
9385
9644
|
});
|
|
9386
|
-
if (!newCredentialsKeyPair.publicKey) {
|
|
9645
|
+
if (!newCredentialsKeyPair.publicKey || !newCredentialsKeyPair.privateKey) {
|
|
9387
9646
|
throw new WallabyError({
|
|
9388
9647
|
message: 'Could not derive keys for new password.',
|
|
9389
9648
|
statusCode: 500,
|
|
@@ -9395,40 +9654,59 @@ class WalletService extends Base {
|
|
|
9395
9654
|
decryptionKey: oldCredentialsKeyPair.privateKey,
|
|
9396
9655
|
encryptionKey: newCredentialsKeyPair.publicKey,
|
|
9397
9656
|
});
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
walletId,
|
|
9657
|
+
// Guard against persisting an empty/invalid re-wrap, which would lock the user out of
|
|
9658
|
+
// their device private key (the one mandatory item) under the new password. The type says
|
|
9659
|
+
// this is always defined, but we defend against a runtime contract violation regardless.
|
|
9660
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
9661
|
+
if (!reWrappedDevicePrivateKey) {
|
|
9662
|
+
throw new WallabyError({
|
|
9663
|
+
message: 'Failed to re-wrap device private key during password change.',
|
|
9664
|
+
statusCode: 500,
|
|
9665
|
+
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
9408
9666
|
});
|
|
9409
9667
|
}
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
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
|
+
const reWrappedSeedPhrase = encryptedSeedPhraseString
|
|
9672
|
+
? await this.cipher.flipEncryptedData({
|
|
9673
|
+
cipherText: safeJsonParse(encryptedSeedPhraseString),
|
|
9414
9674
|
decryptionKey: oldCredentialsKeyPair.privateKey,
|
|
9415
9675
|
encryptionKey: newCredentialsKeyPair.publicKey,
|
|
9416
|
-
})
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
if (encryptedBackupShareString) {
|
|
9422
|
-
const parsedBackupShare = safeJsonParse(encryptedBackupShareString);
|
|
9423
|
-
const reWrappedBackupShare = await this.cipher.flipEncryptedData({
|
|
9424
|
-
cipherText: parsedBackupShare,
|
|
9676
|
+
})
|
|
9677
|
+
: null;
|
|
9678
|
+
const reWrappedPrimaryShare = encryptedPrimaryShareString
|
|
9679
|
+
? await this.cipher.flipEncryptedData({
|
|
9680
|
+
cipherText: safeJsonParse(encryptedPrimaryShareString),
|
|
9425
9681
|
decryptionKey: oldCredentialsKeyPair.privateKey,
|
|
9426
9682
|
encryptionKey: newCredentialsKeyPair.publicKey,
|
|
9427
|
-
})
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9683
|
+
})
|
|
9684
|
+
: null;
|
|
9685
|
+
const reWrappedBackupShare = encryptedBackupShareString
|
|
9686
|
+
? await this.cipher.flipEncryptedData({
|
|
9687
|
+
cipherText: safeJsonParse(encryptedBackupShareString),
|
|
9688
|
+
decryptionKey: oldCredentialsKeyPair.privateKey,
|
|
9689
|
+
encryptionKey: newCredentialsKeyPair.publicKey,
|
|
9690
|
+
})
|
|
9691
|
+
: null;
|
|
9692
|
+
if (reWrappedSeedPhrase)
|
|
9693
|
+
await this.assertRoundTrip(reWrappedSeedPhrase, newCredentialsKeyPair.privateKey, 'seed phrase');
|
|
9694
|
+
if (reWrappedPrimaryShare)
|
|
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([
|
|
9699
|
+
{ key: exports.LocalStorageItems.EncryptedDevicePrivateKey, value: reWrappedDevicePrivateKey },
|
|
9700
|
+
...(reWrappedSeedPhrase
|
|
9701
|
+
? [{ key: exports.LocalStorageItems.EncryptedStandardSeedPhrase, value: reWrappedSeedPhrase, walletId }]
|
|
9702
|
+
: []),
|
|
9703
|
+
...(reWrappedPrimaryShare
|
|
9704
|
+
? [{ key: exports.LocalStorageItems.PrimaryDeviceKeyShare, value: reWrappedPrimaryShare, walletId }]
|
|
9705
|
+
: []),
|
|
9706
|
+
...(reWrappedBackupShare ? [{ key: exports.LocalStorageItems.BackupDeviceKeyShare, value: reWrappedBackupShare, walletId }] : []),
|
|
9707
|
+
]);
|
|
9708
|
+
// Reset the rate-limit window on success so a normal change does not count against future ones.
|
|
9709
|
+
await this.localStorageService.delete(exports.V2KeyNames.PasswordResetAttempts);
|
|
9432
9710
|
return true;
|
|
9433
9711
|
}
|
|
9434
9712
|
catch (error) {
|
|
@@ -9481,20 +9759,7 @@ class WalletService extends Base {
|
|
|
9481
9759
|
}
|
|
9482
9760
|
const parsedEncryptedDevicePrivateKey = safeJsonParse(encryptedDevicePrivateKey);
|
|
9483
9761
|
if (this.deviceAuthType === exports.AuthType.Password && input.authenticationOptions.password) {
|
|
9484
|
-
|
|
9485
|
-
await this.handleUpdateToV2({
|
|
9486
|
-
password: input.authenticationOptions.password,
|
|
9487
|
-
walletId: input.walletId,
|
|
9488
|
-
});
|
|
9489
|
-
}
|
|
9490
|
-
catch (error) {
|
|
9491
|
-
logger.error('SDK::WalletService::initAddNewDevice::handleUpdateToV2::error', error);
|
|
9492
|
-
throw new WallabyError({
|
|
9493
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
9494
|
-
statusCode: 500,
|
|
9495
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
9496
|
-
});
|
|
9497
|
-
}
|
|
9762
|
+
await this.migrateToV2Safe({ password: input.authenticationOptions.password, walletId: input.walletId });
|
|
9498
9763
|
}
|
|
9499
9764
|
const storedEncryptedBackupShare = await this.localStorageService.fetch(exports.LocalStorageItems.BackupDeviceKeyShare, { walletId });
|
|
9500
9765
|
if (!storedEncryptedBackupShare) {
|
|
@@ -9592,6 +9857,7 @@ class WalletService extends Base {
|
|
|
9592
9857
|
shares: [backUpResponse.share],
|
|
9593
9858
|
credentialsKeyPair,
|
|
9594
9859
|
encryptedBackupShare: input.encryptedBackupShare,
|
|
9860
|
+
devicePrivateKey: decryptedDevicePrivateKey,
|
|
9595
9861
|
});
|
|
9596
9862
|
return { success: true, reference: backUpResponse.reference };
|
|
9597
9863
|
}
|
|
@@ -9610,20 +9876,7 @@ class WalletService extends Base {
|
|
|
9610
9876
|
});
|
|
9611
9877
|
}
|
|
9612
9878
|
if (this.deviceAuthType === exports.AuthType.Password && input.authenticationOptions.password) {
|
|
9613
|
-
|
|
9614
|
-
await this.handleUpdateToV2({
|
|
9615
|
-
password: input.authenticationOptions.password,
|
|
9616
|
-
walletId: input.walletId,
|
|
9617
|
-
});
|
|
9618
|
-
}
|
|
9619
|
-
catch (error) {
|
|
9620
|
-
logger.error('SDK::WalletService::generateWalletAddresses::handleUpdateToV2::error', error);
|
|
9621
|
-
throw new WallabyError({
|
|
9622
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
9623
|
-
statusCode: 500,
|
|
9624
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
9625
|
-
});
|
|
9626
|
-
}
|
|
9879
|
+
await this.migrateToV2Safe({ password: input.authenticationOptions.password, walletId: input.walletId });
|
|
9627
9880
|
}
|
|
9628
9881
|
try {
|
|
9629
9882
|
const walletOperationAuth = await this.prepareWalletOperationAuth({
|
|
@@ -9648,6 +9901,23 @@ class WalletService extends Base {
|
|
|
9648
9901
|
throw error;
|
|
9649
9902
|
}
|
|
9650
9903
|
}
|
|
9904
|
+
/**
|
|
9905
|
+
* Wraps handleUpdateToV2 with the standard user-facing error. All call sites that gate on
|
|
9906
|
+
* `AuthType.Password` should go through here so the error message stays consistent.
|
|
9907
|
+
*/
|
|
9908
|
+
async migrateToV2Safe({ password, walletId }) {
|
|
9909
|
+
try {
|
|
9910
|
+
await this.handleUpdateToV2({ password, walletId });
|
|
9911
|
+
}
|
|
9912
|
+
catch (error) {
|
|
9913
|
+
logger.error('SDK::WalletService::migrateToV2Safe::error', error);
|
|
9914
|
+
throw new WallabyError({
|
|
9915
|
+
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
9916
|
+
statusCode: 500,
|
|
9917
|
+
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
9918
|
+
});
|
|
9919
|
+
}
|
|
9920
|
+
}
|
|
9651
9921
|
/**
|
|
9652
9922
|
* Detects and migrates legacy/v1 storage items to v2 format.
|
|
9653
9923
|
* This function should be called in methods that use password as input when v2 items are missing.
|
|
@@ -9656,13 +9926,7 @@ class WalletService extends Base {
|
|
|
9656
9926
|
*/
|
|
9657
9927
|
async handleUpdateToV2({ password, walletId }) {
|
|
9658
9928
|
const migrationStartTime = Date.now();
|
|
9659
|
-
|
|
9660
|
-
throw new WallabyError({
|
|
9661
|
-
message: 'Too many migration attempts. Please try again later.',
|
|
9662
|
-
statusCode: 429,
|
|
9663
|
-
errorCode: exports.ErrorResponseCodes.sdk_too_many_requests,
|
|
9664
|
-
});
|
|
9665
|
-
}
|
|
9929
|
+
await this.assertUnderRateLimit(exports.V2KeyNames.MigrationAttempts, 'Too many migration attempts. Please try again later.');
|
|
9666
9930
|
try {
|
|
9667
9931
|
if (!password) {
|
|
9668
9932
|
throw new WallabyError({
|
|
@@ -9733,7 +9997,7 @@ class WalletService extends Base {
|
|
|
9733
9997
|
}
|
|
9734
9998
|
}
|
|
9735
9999
|
// Increment counter after V2 validation to avoid counting when migration not needed
|
|
9736
|
-
this.
|
|
10000
|
+
await this.recordRateAttempt(exports.V2KeyNames.MigrationAttempts);
|
|
9737
10001
|
let decryptedSeedPhrase;
|
|
9738
10002
|
let decryptedPrivateKey;
|
|
9739
10003
|
// Check for legacy format: `{item}_{userId}`
|
|
@@ -9786,7 +10050,10 @@ class WalletService extends Base {
|
|
|
9786
10050
|
try {
|
|
9787
10051
|
// Decrypt V1 items using storage service method (handles double encryption)
|
|
9788
10052
|
logger.log('Attempting to decrypt V1 items during migration...');
|
|
9789
|
-
logger.log('getV1DecryptedSeedPhrase should be called with password and clientSalt:', {
|
|
10053
|
+
logger.log('getV1DecryptedSeedPhrase should be called with password and clientSalt:', {
|
|
10054
|
+
hasPassword: !!password,
|
|
10055
|
+
hasClientSalt: !!clientSalt,
|
|
10056
|
+
});
|
|
9790
10057
|
decryptedSeedPhrase = await this.localStorageService.getV1DecryptedSeedPhrase(password, clientSalt);
|
|
9791
10058
|
// For V1 format, private key is encrypted with just the password (not salt+password like legacy)
|
|
9792
10059
|
decryptedPrivateKey = await this.localStorageService.getDecryptedV1PrivateKey(password);
|
|
@@ -10013,7 +10280,28 @@ class WalletService extends Base {
|
|
|
10013
10280
|
* @returns { boolean } whether the operation was successful
|
|
10014
10281
|
*/
|
|
10015
10282
|
async convertToPasskey(input) {
|
|
10283
|
+
let passkeyRegistered = false;
|
|
10016
10284
|
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
|
+
}
|
|
10017
10305
|
const v2EncryptedPriv = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
10018
10306
|
const v2EncryptedSeed = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase, {
|
|
10019
10307
|
walletId: input.walletId,
|
|
@@ -10062,6 +10350,10 @@ class WalletService extends Base {
|
|
|
10062
10350
|
});
|
|
10063
10351
|
}
|
|
10064
10352
|
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 } : {})));
|
|
10065
10357
|
const authentication = await this.passkeyService.addNewPasskey({
|
|
10066
10358
|
deviceKeyPair: {
|
|
10067
10359
|
publicKey: clientPublicKey,
|
|
@@ -10069,6 +10361,7 @@ class WalletService extends Base {
|
|
|
10069
10361
|
},
|
|
10070
10362
|
getSignature: this.authService.getSignature.bind(this),
|
|
10071
10363
|
});
|
|
10364
|
+
passkeyRegistered = true;
|
|
10072
10365
|
const prfValue = authentication.prfValue;
|
|
10073
10366
|
if (!prfValue || !(prfValue instanceof Uint8Array) || prfValue.length === 0) {
|
|
10074
10367
|
logger.error('SDK::WalletService::convertToPasskey::prfValue is required and must be a non-empty Uint8Array');
|
|
@@ -10165,8 +10458,13 @@ class WalletService extends Base {
|
|
|
10165
10458
|
storeOneKeyShareWithWallaby: true,
|
|
10166
10459
|
},
|
|
10167
10460
|
});
|
|
10168
|
-
//
|
|
10169
|
-
|
|
10461
|
+
// idempotent — on retry (marker present, primary now passkey-encrypted so
|
|
10462
|
+
// decryptedPrimaryShare is undefined → Branch A re-enters), handleImportWallet re-shares
|
|
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
|
+
]);
|
|
10170
10468
|
logger.info('SDK::WalletService::convertToPasskey::Wallet imported and converted successfully, old seed phrase removed');
|
|
10171
10469
|
return { authentication, seedPhrase: decryptedSeedPhrase };
|
|
10172
10470
|
}
|
|
@@ -10184,6 +10482,24 @@ class WalletService extends Base {
|
|
|
10184
10482
|
privateKey: decryptedClientAuthPrivKey,
|
|
10185
10483
|
},
|
|
10186
10484
|
});
|
|
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
|
+
}
|
|
10187
10503
|
convertedShares.push({
|
|
10188
10504
|
key: exports.V2KeyNames.PrimaryDeviceKeyShare,
|
|
10189
10505
|
value: encryptedPrimaryShare,
|
|
@@ -10202,9 +10518,16 @@ class WalletService extends Base {
|
|
|
10202
10518
|
walletId: input.walletId,
|
|
10203
10519
|
});
|
|
10204
10520
|
}
|
|
10205
|
-
|
|
10521
|
+
// Round-trip validate each re-encrypted blob (outer layer only) before writing.
|
|
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
|
+
]);
|
|
10206
10530
|
if (v2EncryptedSeed) {
|
|
10207
|
-
await this.localStorageService.delete(exports.LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
|
|
10208
10531
|
logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
|
|
10209
10532
|
}
|
|
10210
10533
|
if (!decryptedSeedPhrase && decryptedPrimaryShare) {
|
|
@@ -10247,10 +10570,33 @@ class WalletService extends Base {
|
|
|
10247
10570
|
}
|
|
10248
10571
|
catch (error) {
|
|
10249
10572
|
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
|
+
}
|
|
10250
10578
|
throw error;
|
|
10251
10579
|
}
|
|
10252
10580
|
}
|
|
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
|
+
}
|
|
10253
10595
|
}
|
|
10596
|
+
// soft client-side guardrail against runaway retries; server-side rate limiting is the real control.
|
|
10597
|
+
// Counters are persisted (sliding window) so rebuilding the service no longer resets them. Tune freely.
|
|
10598
|
+
WalletService.RATE_LIMIT_MAX = 5;
|
|
10599
|
+
WalletService.RATE_LIMIT_WINDOW_MS = 30 * 60000; // 30 min
|
|
10254
10600
|
__decorate([
|
|
10255
10601
|
WithLock('create'),
|
|
10256
10602
|
__metadata("design:type", Function),
|
|
@@ -10270,7 +10616,7 @@ __decorate([
|
|
|
10270
10616
|
__metadata("design:returntype", Promise)
|
|
10271
10617
|
], WalletService.prototype, "recover", null);
|
|
10272
10618
|
__decorate([
|
|
10273
|
-
WithLock('
|
|
10619
|
+
WithLock('credential-rewrap'),
|
|
10274
10620
|
__metadata("design:type", Function),
|
|
10275
10621
|
__metadata("design:paramtypes", [Object]),
|
|
10276
10622
|
__metadata("design:returntype", Promise)
|
|
@@ -10281,6 +10627,12 @@ __decorate([
|
|
|
10281
10627
|
__metadata("design:paramtypes", [Object]),
|
|
10282
10628
|
__metadata("design:returntype", Promise)
|
|
10283
10629
|
], 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);
|
|
10284
10636
|
|
|
10285
10637
|
class WalletDataService extends Base {
|
|
10286
10638
|
constructor(config) {
|
|
@@ -10533,20 +10885,7 @@ class WalletDataService extends Base {
|
|
|
10533
10885
|
});
|
|
10534
10886
|
}
|
|
10535
10887
|
if (this.deviceAuthType === exports.AuthType.Password && authenticationOptions.password) {
|
|
10536
|
-
|
|
10537
|
-
await this.walletService.handleUpdateToV2({
|
|
10538
|
-
password: authenticationOptions.password,
|
|
10539
|
-
walletId: walletId,
|
|
10540
|
-
});
|
|
10541
|
-
}
|
|
10542
|
-
catch (error) {
|
|
10543
|
-
logger.error('SDK::WalletDataService::addNewChainAndTokenToWallet::handleUpdateToV2::error', error);
|
|
10544
|
-
throw new WallabyError({
|
|
10545
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
10546
|
-
statusCode: 500,
|
|
10547
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
10548
|
-
});
|
|
10549
|
-
}
|
|
10888
|
+
await this.walletService.migrateToV2Safe({ password: authenticationOptions.password, walletId });
|
|
10550
10889
|
}
|
|
10551
10890
|
try {
|
|
10552
10891
|
const addressInfo = await this.walletService.generateWalletAddresses({
|
|
@@ -10747,179 +11086,6 @@ class Utils extends Base {
|
|
|
10747
11086
|
}
|
|
10748
11087
|
}
|
|
10749
11088
|
|
|
10750
|
-
const MerchantsRoutes = {
|
|
10751
|
-
create: {
|
|
10752
|
-
fullPath: '/merchants',
|
|
10753
|
-
method: exports.RequestMethod.Post,
|
|
10754
|
-
requiresAccessToken: false,
|
|
10755
|
-
},
|
|
10756
|
-
update: {
|
|
10757
|
-
fullPath: ({ merchantId }) => `/merchants/${merchantId}`,
|
|
10758
|
-
method: exports.RequestMethod.Put,
|
|
10759
|
-
requiresAccessToken: false,
|
|
10760
|
-
},
|
|
10761
|
-
getMerchantData: {
|
|
10762
|
-
fullPath: ({ merchantId }) => `/merchants/${merchantId}`,
|
|
10763
|
-
method: exports.RequestMethod.Get,
|
|
10764
|
-
requiresAccessToken: false,
|
|
10765
|
-
},
|
|
10766
|
-
list: {
|
|
10767
|
-
fullPath: '/merchants',
|
|
10768
|
-
method: exports.RequestMethod.Get,
|
|
10769
|
-
requiresAccessToken: false,
|
|
10770
|
-
},
|
|
10771
|
-
getAssets: {
|
|
10772
|
-
fullPath: () => `/users/merchant/assets`,
|
|
10773
|
-
method: exports.RequestMethod.Get,
|
|
10774
|
-
requiresAccessToken: true,
|
|
10775
|
-
},
|
|
10776
|
-
addAsset: {
|
|
10777
|
-
fullPath: ({ merchantId, configId }) => `/merchants/${merchantId}/assets/${configId}`,
|
|
10778
|
-
method: exports.RequestMethod.Post,
|
|
10779
|
-
requiresAccessToken: false,
|
|
10780
|
-
},
|
|
10781
|
-
deleteAsset: {
|
|
10782
|
-
fullPath: ({ merchantId, configId }) => `/merchants/${merchantId}/assets/${configId}`,
|
|
10783
|
-
method: exports.RequestMethod.Delete,
|
|
10784
|
-
requiresAccessToken: false,
|
|
10785
|
-
},
|
|
10786
|
-
};
|
|
10787
|
-
|
|
10788
|
-
class Merchants extends Base {
|
|
10789
|
-
constructor(config) {
|
|
10790
|
-
super(config);
|
|
10791
|
-
}
|
|
10792
|
-
/**
|
|
10793
|
-
* @description
|
|
10794
|
-
* Retrieves the merchant ID from access token `aud` claim.
|
|
10795
|
-
* Even though merchantId is possibly undefined. If an access token is not stored on device, the request will most likely
|
|
10796
|
-
* not have it in headers and will fail with 401 regardless.
|
|
10797
|
-
*
|
|
10798
|
-
* @returns { string | undefined } Merchant ID
|
|
10799
|
-
*/
|
|
10800
|
-
async _getMerchantId() {
|
|
10801
|
-
const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
|
|
10802
|
-
if (!accessToken)
|
|
10803
|
-
return;
|
|
10804
|
-
const jwtDecoded = jwtDecode.jwtDecode(accessToken);
|
|
10805
|
-
return jwtDecoded.aud;
|
|
10806
|
-
}
|
|
10807
|
-
/**
|
|
10808
|
-
*
|
|
10809
|
-
* @public
|
|
10810
|
-
* List of all merchants in the system
|
|
10811
|
-
* @returns { ListMerchantsResponse } Array of all merchants
|
|
10812
|
-
*/
|
|
10813
|
-
async list() {
|
|
10814
|
-
try {
|
|
10815
|
-
const response = await this.request(MerchantsRoutes.list, {
|
|
10816
|
-
payload: {},
|
|
10817
|
-
});
|
|
10818
|
-
return response;
|
|
10819
|
-
}
|
|
10820
|
-
catch (error) {
|
|
10821
|
-
logger.error('SDK::Merchants::list::error', error);
|
|
10822
|
-
return Promise.reject(error);
|
|
10823
|
-
}
|
|
10824
|
-
}
|
|
10825
|
-
/**
|
|
10826
|
-
*
|
|
10827
|
-
* @public
|
|
10828
|
-
* Allows to create a new merchant
|
|
10829
|
-
* @returns { Merchant } Merchant data
|
|
10830
|
-
*/
|
|
10831
|
-
async create({ name }) {
|
|
10832
|
-
try {
|
|
10833
|
-
const response = await this.request(MerchantsRoutes.create, {
|
|
10834
|
-
payload: { name },
|
|
10835
|
-
});
|
|
10836
|
-
return response;
|
|
10837
|
-
}
|
|
10838
|
-
catch (error) {
|
|
10839
|
-
logger.error('SDK::Merchants::list::error', error);
|
|
10840
|
-
return Promise.reject(error);
|
|
10841
|
-
}
|
|
10842
|
-
}
|
|
10843
|
-
/**
|
|
10844
|
-
*
|
|
10845
|
-
* @public
|
|
10846
|
-
* Allows to update merchant data
|
|
10847
|
-
* @returns { Merchant } Merchant data
|
|
10848
|
-
*/
|
|
10849
|
-
async update({ name, status }) {
|
|
10850
|
-
try {
|
|
10851
|
-
const merchantId = await this._getMerchantId();
|
|
10852
|
-
const response = await this.request(MerchantsRoutes.update, {
|
|
10853
|
-
payload: { merchantId, name, status },
|
|
10854
|
-
});
|
|
10855
|
-
return response;
|
|
10856
|
-
}
|
|
10857
|
-
catch (error) {
|
|
10858
|
-
logger.error('SDK::Merchants::list::error', error);
|
|
10859
|
-
return Promise.reject(error);
|
|
10860
|
-
}
|
|
10861
|
-
}
|
|
10862
|
-
/**
|
|
10863
|
-
*
|
|
10864
|
-
* @public
|
|
10865
|
-
* @returns { Merchant } Merchant data
|
|
10866
|
-
*/
|
|
10867
|
-
async getMerchantData() {
|
|
10868
|
-
try {
|
|
10869
|
-
const merchantId = await this._getMerchantId();
|
|
10870
|
-
const response = await this.request(MerchantsRoutes.getMerchantData, {
|
|
10871
|
-
payload: { merchantId },
|
|
10872
|
-
});
|
|
10873
|
-
return response.merchant;
|
|
10874
|
-
}
|
|
10875
|
-
catch (error) {
|
|
10876
|
-
logger.error('SDK::Merchants::list::error', error);
|
|
10877
|
-
return Promise.reject(error);
|
|
10878
|
-
}
|
|
10879
|
-
}
|
|
10880
|
-
/**
|
|
10881
|
-
*
|
|
10882
|
-
* @public
|
|
10883
|
-
* @returns { MerchantAsset[] } List of merchant assets
|
|
10884
|
-
*/
|
|
10885
|
-
async getAssets() {
|
|
10886
|
-
try {
|
|
10887
|
-
const response = await this.request(MerchantsRoutes.getAssets);
|
|
10888
|
-
return response.merchantAssets;
|
|
10889
|
-
}
|
|
10890
|
-
catch (error) {
|
|
10891
|
-
logger.error('SDK::Merchants::list::error', error);
|
|
10892
|
-
return Promise.reject(error);
|
|
10893
|
-
}
|
|
10894
|
-
}
|
|
10895
|
-
async addAsset({ configId }) {
|
|
10896
|
-
try {
|
|
10897
|
-
const merchantId = await this._getMerchantId();
|
|
10898
|
-
const response = await this.request(MerchantsRoutes.addAsset, {
|
|
10899
|
-
payload: { merchantId, configId },
|
|
10900
|
-
});
|
|
10901
|
-
return response;
|
|
10902
|
-
}
|
|
10903
|
-
catch (error) {
|
|
10904
|
-
logger.error('SDK::Merchants::list::error', error);
|
|
10905
|
-
return Promise.reject(error);
|
|
10906
|
-
}
|
|
10907
|
-
}
|
|
10908
|
-
async deleteAsset({ configId }) {
|
|
10909
|
-
try {
|
|
10910
|
-
const merchantId = await this._getMerchantId();
|
|
10911
|
-
const response = await this.request(MerchantsRoutes.deleteAsset, {
|
|
10912
|
-
payload: { merchantId, configId },
|
|
10913
|
-
});
|
|
10914
|
-
return response;
|
|
10915
|
-
}
|
|
10916
|
-
catch (error) {
|
|
10917
|
-
logger.error('SDK::Merchants::list::error', error);
|
|
10918
|
-
return Promise.reject(error);
|
|
10919
|
-
}
|
|
10920
|
-
}
|
|
10921
|
-
}
|
|
10922
|
-
|
|
10923
11089
|
/**
|
|
10924
11090
|
* HttpApi provides direct access to all REST API endpoints.
|
|
10925
11091
|
* This class extends the Base class and includes the generated API client
|
|
@@ -11000,20 +11166,7 @@ class Swap extends Base {
|
|
|
11000
11166
|
try {
|
|
11001
11167
|
// Only attempt migration if we have password auth and V2 storage might be incomplete
|
|
11002
11168
|
if (this.deviceAuthType === exports.AuthType.Password && authenticationOptions.password) {
|
|
11003
|
-
|
|
11004
|
-
await this.walletService.handleUpdateToV2({
|
|
11005
|
-
password: authenticationOptions.password,
|
|
11006
|
-
walletId: walletId,
|
|
11007
|
-
});
|
|
11008
|
-
}
|
|
11009
|
-
catch (error) {
|
|
11010
|
-
logger.error('SDK::Swap::executeSwap::handleUpdateToV2::error', error);
|
|
11011
|
-
throw new WallabyError({
|
|
11012
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
11013
|
-
statusCode: 500,
|
|
11014
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
11015
|
-
});
|
|
11016
|
-
}
|
|
11169
|
+
await this.walletService.migrateToV2Safe({ password: authenticationOptions.password, walletId });
|
|
11017
11170
|
}
|
|
11018
11171
|
const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareSwapAuth(authenticationOptions, walletId);
|
|
11019
11172
|
let swapResponse;
|
|
@@ -11042,6 +11195,7 @@ class Swap extends Base {
|
|
|
11042
11195
|
});
|
|
11043
11196
|
}
|
|
11044
11197
|
else {
|
|
11198
|
+
// Unreachable in practice: prepareSwapAuth throws sdk_seed_phrase_not_found before we get here; kept as a defensive guard.
|
|
11045
11199
|
throw new WallabyError({
|
|
11046
11200
|
message: 'No valid seed option found on this device.',
|
|
11047
11201
|
statusCode: 400,
|
|
@@ -11207,6 +11361,27 @@ const sanitizeSuiObjectId = (objectId) => {
|
|
|
11207
11361
|
return objectId.split('::')[0];
|
|
11208
11362
|
};
|
|
11209
11363
|
|
|
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
|
+
|
|
11210
11385
|
class System extends Base {
|
|
11211
11386
|
constructor(config) {
|
|
11212
11387
|
super(config);
|
|
@@ -11295,6 +11470,9 @@ class System extends Base {
|
|
|
11295
11470
|
* @param {BlockchainName} blockchain - The name of the blockchain.
|
|
11296
11471
|
* @param {string} contractAddress - The contract address of the token (optional for non-SUI blockchains).
|
|
11297
11472
|
* @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).
|
|
11298
11476
|
*
|
|
11299
11477
|
* @returns {Promise<{ decimals: number; symbol: string; name: string; tokenContractAddress: string }>} A promise that resolves to an object containing token information.
|
|
11300
11478
|
*
|
|
@@ -11303,18 +11481,19 @@ class System extends Base {
|
|
|
11303
11481
|
* @throws Will throw an error if `contractAddress` is not provided for non-SUI blockchains.
|
|
11304
11482
|
* @throws Will throw an error if the response is invalid or contains an error.
|
|
11305
11483
|
*/
|
|
11306
|
-
async fetchTokenInfo({ blockchain, contractAddress, suiObjectId, }) {
|
|
11484
|
+
async fetchTokenInfo({ blockchain, contractAddress, suiObjectId, assetSymbol, }) {
|
|
11307
11485
|
try {
|
|
11308
11486
|
const validatedContractAddress = this.validateContractAddress({
|
|
11309
11487
|
blockchain,
|
|
11310
11488
|
contractAddress,
|
|
11311
11489
|
suiObjectId,
|
|
11312
11490
|
});
|
|
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);
|
|
11313
11495
|
const response = await this.request(SystemRoutes.fetchTokenInfo, {
|
|
11314
|
-
queryParams: {
|
|
11315
|
-
chainName: blockchain,
|
|
11316
|
-
tokenContractAddress: validatedContractAddress,
|
|
11317
|
-
},
|
|
11496
|
+
queryParams: Object.assign({ chainName: blockchain, tokenContractAddress: validatedContractAddress }, (resolvedAssetSymbol ? { assetSymbol: resolvedAssetSymbol } : {})),
|
|
11318
11497
|
});
|
|
11319
11498
|
return response;
|
|
11320
11499
|
}
|
|
@@ -11463,27 +11642,54 @@ class Transactions extends Base {
|
|
|
11463
11642
|
/**
|
|
11464
11643
|
*
|
|
11465
11644
|
* @public
|
|
11466
|
-
* @param {
|
|
11467
|
-
* @
|
|
11468
|
-
* @param {TokenStandard} tokenStandard an optional param used when dealing with non native assets
|
|
11469
|
-
* @returns {Promise<{ address: string; transactions: Transaction[] }>}
|
|
11645
|
+
* @param {GetTransactionsParams} params - Query parameters for filtering and paginating transactions
|
|
11646
|
+
* @returns {GetTransactionsResponseDto} Paginated list of transactions matching the given criteria
|
|
11470
11647
|
*/
|
|
11471
|
-
async getTransactions(
|
|
11648
|
+
async getTransactions(params) {
|
|
11472
11649
|
try {
|
|
11473
|
-
|
|
11474
|
-
|
|
11475
|
-
address,
|
|
11476
|
-
tokenSymbol: symbol,
|
|
11477
|
-
tokenType: tokenStandard,
|
|
11478
|
-
},
|
|
11650
|
+
return await this.request(TransactionsRoutes.getTransactions, {
|
|
11651
|
+
queryParams: params,
|
|
11479
11652
|
});
|
|
11480
|
-
return response;
|
|
11481
11653
|
}
|
|
11482
11654
|
catch (error) {
|
|
11483
11655
|
logger.error('SDK::Transactions::getTransactions::error', error);
|
|
11484
11656
|
throw error;
|
|
11485
11657
|
}
|
|
11486
11658
|
}
|
|
11659
|
+
/**
|
|
11660
|
+
*
|
|
11661
|
+
* @public
|
|
11662
|
+
* @param {GetRestrictionParams} params - Parameters to detect transfer restrictions (addresses, asset, value)
|
|
11663
|
+
* - {string} fromAddress
|
|
11664
|
+
* - {string} toAddress
|
|
11665
|
+
* - {string} amount
|
|
11666
|
+
* - [string] assetId
|
|
11667
|
+
* - [string] contractAddress
|
|
11668
|
+
* - [BlockchainName] blockchainName
|
|
11669
|
+
* @returns {Promise<DetectRestrictionResponseDto>}
|
|
11670
|
+
* Detection result; when transfer is blocked, also includes the human-readable restriction message and a boolean canTransfer
|
|
11671
|
+
*/
|
|
11672
|
+
async getRestriction(params) {
|
|
11673
|
+
try {
|
|
11674
|
+
const hasAssetId = Boolean(params.assetId);
|
|
11675
|
+
const hasContractAndChain = Boolean(params.contractAddress && params.blockchainName);
|
|
11676
|
+
if (!hasAssetId && !hasContractAndChain) {
|
|
11677
|
+
throw new WallabyError({
|
|
11678
|
+
message: 'Either assetId or both contractAddress and blockchainName must be provided.',
|
|
11679
|
+
statusCode: 400,
|
|
11680
|
+
errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
|
|
11681
|
+
});
|
|
11682
|
+
}
|
|
11683
|
+
const restrictionData = await this.request(TransactionsRoutes.restriction, {
|
|
11684
|
+
queryParams: Object.assign(Object.assign(Object.assign({ fromAddress: params.fromAddress, toAddress: params.toAddress, amount: params.amount }, (params.assetId && { assetId: params.assetId })), (params.contractAddress && { contractAddress: params.contractAddress })), (params.blockchainName && { blockchainName: params.blockchainName })),
|
|
11685
|
+
});
|
|
11686
|
+
return restrictionData;
|
|
11687
|
+
}
|
|
11688
|
+
catch (error) {
|
|
11689
|
+
logger.error('SDK::Transactions::getRestriction::error', error);
|
|
11690
|
+
throw error;
|
|
11691
|
+
}
|
|
11692
|
+
}
|
|
11487
11693
|
/**
|
|
11488
11694
|
*
|
|
11489
11695
|
* @public
|
|
@@ -11501,20 +11707,7 @@ class Transactions extends Base {
|
|
|
11501
11707
|
try {
|
|
11502
11708
|
// Only attempt migration if we have password auth and V2 storage might be incomplete
|
|
11503
11709
|
if (this.deviceAuthType === exports.AuthType.Password && authenticationOptions.password) {
|
|
11504
|
-
|
|
11505
|
-
await this.walletService.handleUpdateToV2({
|
|
11506
|
-
password: authenticationOptions.password,
|
|
11507
|
-
walletId: walletId,
|
|
11508
|
-
});
|
|
11509
|
-
}
|
|
11510
|
-
catch (error) {
|
|
11511
|
-
logger.error('SDK::Transactions::transfer::handleUpdateToV2::error', error);
|
|
11512
|
-
throw new WallabyError({
|
|
11513
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
11514
|
-
statusCode: 500,
|
|
11515
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
11516
|
-
});
|
|
11517
|
-
}
|
|
11710
|
+
await this.walletService.migrateToV2Safe({ password: authenticationOptions.password, walletId });
|
|
11518
11711
|
}
|
|
11519
11712
|
const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
|
|
11520
11713
|
let transferResponse;
|
|
@@ -11602,20 +11795,7 @@ class Transactions extends Base {
|
|
|
11602
11795
|
}
|
|
11603
11796
|
// Only attempt migration if we have password auth and V2 storage might be incomplete
|
|
11604
11797
|
if (this.deviceAuthType === exports.AuthType.Password && authenticationOptions.password) {
|
|
11605
|
-
|
|
11606
|
-
await this.walletService.handleUpdateToV2({
|
|
11607
|
-
password: authenticationOptions.password,
|
|
11608
|
-
walletId: walletId,
|
|
11609
|
-
});
|
|
11610
|
-
}
|
|
11611
|
-
catch (error) {
|
|
11612
|
-
logger.error('SDK::Transactions::createAllowance::handleUpdateToV2::error', error);
|
|
11613
|
-
throw new WallabyError({
|
|
11614
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
11615
|
-
statusCode: 500,
|
|
11616
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
11617
|
-
});
|
|
11618
|
-
}
|
|
11798
|
+
await this.walletService.migrateToV2Safe({ password: authenticationOptions.password, walletId });
|
|
11619
11799
|
}
|
|
11620
11800
|
const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
|
|
11621
11801
|
const { message, signature } = signatureMessage;
|
|
@@ -11680,20 +11860,7 @@ class Transactions extends Base {
|
|
|
11680
11860
|
try {
|
|
11681
11861
|
// Only attempt migration if we have password auth and V2 storage might be incomplete
|
|
11682
11862
|
if (this.deviceAuthType === exports.AuthType.Password && authenticationOptions.password) {
|
|
11683
|
-
|
|
11684
|
-
await this.walletService.handleUpdateToV2({
|
|
11685
|
-
password: authenticationOptions.password,
|
|
11686
|
-
walletId: walletId,
|
|
11687
|
-
});
|
|
11688
|
-
}
|
|
11689
|
-
catch (error) {
|
|
11690
|
-
logger.error('SDK::Transactions::resolvePendingTransaction::handleUpdateToV2::error', error);
|
|
11691
|
-
throw new WallabyError({
|
|
11692
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
11693
|
-
statusCode: 500,
|
|
11694
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
11695
|
-
});
|
|
11696
|
-
}
|
|
11863
|
+
await this.walletService.migrateToV2Safe({ password: authenticationOptions.password, walletId });
|
|
11697
11864
|
}
|
|
11698
11865
|
const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
|
|
11699
11866
|
if (!readyForTransportSeedPhrase && !hasShares) {
|
|
@@ -11818,6 +11985,12 @@ class Transactions extends Base {
|
|
|
11818
11985
|
});
|
|
11819
11986
|
}
|
|
11820
11987
|
}
|
|
11988
|
+
__decorate([
|
|
11989
|
+
WithLock('transaction-restriction-message'),
|
|
11990
|
+
__metadata("design:type", Function),
|
|
11991
|
+
__metadata("design:paramtypes", [Object]),
|
|
11992
|
+
__metadata("design:returntype", Promise)
|
|
11993
|
+
], Transactions.prototype, "getRestriction", null);
|
|
11821
11994
|
__decorate([
|
|
11822
11995
|
WithLock('transfer'),
|
|
11823
11996
|
__metadata("design:type", Function),
|
|
@@ -11860,7 +12033,6 @@ class Wallaby {
|
|
|
11860
12033
|
this.system = new System(config);
|
|
11861
12034
|
this.transactions = new Transactions(config);
|
|
11862
12035
|
this.swap = new Swap(config);
|
|
11863
|
-
this.merchants = new Merchants(config);
|
|
11864
12036
|
this.httpApi = new HttpApi(config);
|
|
11865
12037
|
}
|
|
11866
12038
|
get version() {
|