wallaby-cash 2.3.6 → 2.3.7-alpha.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 +1 -0
- package/dist/generated/api.d.ts +84 -55
- package/dist/helpers/omit.d.ts +1 -0
- package/dist/index.cjs.js +443 -231
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +443 -232
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +443 -232
- package/dist/index.js.map +1 -1
- package/dist/lib/auth/auth.service.d.ts +2 -3
- package/dist/lib/network/network-diagnostic.d.ts +43 -0
- package/dist/lib/transactions/index.d.ts +2 -3
- package/dist/lib/utils/storage.service.d.ts +0 -12
- package/dist/lib/wallet/wallet-data.service.d.ts +1 -1
- package/dist/lib/wallet/wallet-handlers.service.d.ts +1 -16
- package/dist/lib/wallet/wallet.service.d.ts +3 -0
- package/dist/package.json +1 -2
- package/dist/types/auth.d.ts +9 -7
- package/dist/types/common.d.ts +4 -0
- package/dist/types/error-response-codes.d.ts +6 -1
- package/dist/types/network-diagnostic.d.ts +23 -0
- package/dist/types/storage.d.ts +0 -1
- package/dist/types/transactions.d.ts +7 -4
- package/dist/types/wallet.d.ts +3 -3
- package/package.json +1 -2
- package/dist/lib/auth/auth.model.d.ts +0 -108
- package/dist/lib/transactions/transactions.model.d.ts +0 -22
package/dist/index.cjs.js
CHANGED
|
@@ -4,13 +4,12 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
4
4
|
|
|
5
5
|
const algosdk = require('algosdk');
|
|
6
6
|
const bip39 = require('bip39');
|
|
7
|
+
const uuid = require('uuid');
|
|
7
8
|
const log = require('loglevel');
|
|
8
9
|
const cryptoJs = require('crypto-js');
|
|
9
10
|
const jwtDecode = require('jwt-decode');
|
|
10
|
-
const lodash = require('lodash');
|
|
11
11
|
const WebAuthn = require('@simplewebauthn/browser');
|
|
12
12
|
const jsBase64 = require('js-base64');
|
|
13
|
-
const uuid = require('uuid');
|
|
14
13
|
|
|
15
14
|
const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
|
16
15
|
|
|
@@ -109,10 +108,11 @@ exports.TransportEnum = void 0;
|
|
|
109
108
|
* @property {string} [errorCode] - Specific error code for categorizing the error.
|
|
110
109
|
* @property {any} [data] - Additional data related to the error.
|
|
111
110
|
* @property {number} [status] - Alias for statusCode for compatibility.
|
|
111
|
+
* @property {NetworkDiagnosticResult} [networkDiagnostic] - Optional network diagnostic information for network-related errors.
|
|
112
112
|
*/
|
|
113
113
|
class WallabyError extends Error {
|
|
114
114
|
constructor(errorPayload) {
|
|
115
|
-
const { message, statusCode, errorCode, data, cause, onError } = errorPayload;
|
|
115
|
+
const { message, statusCode, errorCode, data, cause, onError, networkDiagnostic } = errorPayload;
|
|
116
116
|
super(message);
|
|
117
117
|
this.name = 'WallabyError';
|
|
118
118
|
this.status = statusCode;
|
|
@@ -120,6 +120,7 @@ class WallabyError extends Error {
|
|
|
120
120
|
this.cause = cause;
|
|
121
121
|
this.onError = onError;
|
|
122
122
|
this.data = data;
|
|
123
|
+
this.networkDiagnostic = networkDiagnostic;
|
|
123
124
|
Error.captureStackTrace(this, WallabyError);
|
|
124
125
|
}
|
|
125
126
|
static isWallabyError(error) {
|
|
@@ -295,7 +296,6 @@ exports.LocalStorageItems = void 0;
|
|
|
295
296
|
LocalStorageItems["EncryptedAlgorandSeedPhrase"] = "encrypted-algorand-seedPhrase";
|
|
296
297
|
LocalStorageItems["EncryptedDevicePrivateKey"] = "encrypted-private-key";
|
|
297
298
|
LocalStorageItems["ClientAuthPublicKey"] = "client-auth-pub-key";
|
|
298
|
-
LocalStorageItems["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
|
|
299
299
|
LocalStorageItems["ClientAuthToken"] = "republic-jwt";
|
|
300
300
|
LocalStorageItems["PasskeyCredential"] = "pass-key-credential";
|
|
301
301
|
LocalStorageItems["Blob"] = "blob";
|
|
@@ -400,6 +400,12 @@ exports.ErrorResponseCodes = void 0;
|
|
|
400
400
|
ErrorResponseCodes["sdk_passkey_challenge_unavailable"] = "sdk_passkey_challenge_unavailable";
|
|
401
401
|
ErrorResponseCodes["sdk_passkey_authentication_failed"] = "sdk_passkey_authentication_failed";
|
|
402
402
|
ErrorResponseCodes["sdk_passkey_registration_failed"] = "sdk_passkey_registration_failed";
|
|
403
|
+
// network diagnostic errors
|
|
404
|
+
ErrorResponseCodes["sdk_network_offline"] = "sdk_network_offline";
|
|
405
|
+
ErrorResponseCodes["sdk_network_connectivity"] = "sdk_network_connectivity";
|
|
406
|
+
ErrorResponseCodes["sdk_network_likely_cors_or_auth"] = "sdk_network_likely_cors_or_auth";
|
|
407
|
+
ErrorResponseCodes["sdk_network_fast_failure"] = "sdk_network_fast_failure";
|
|
408
|
+
ErrorResponseCodes["sdk_network_unknown"] = "sdk_network_unknown";
|
|
403
409
|
})(exports.ErrorResponseCodes || (exports.ErrorResponseCodes = {}));
|
|
404
410
|
|
|
405
411
|
const UnknownError = {
|
|
@@ -556,12 +562,12 @@ const global$1 = (typeof global !== "undefined" ? global :
|
|
|
556
562
|
var env = {};
|
|
557
563
|
|
|
558
564
|
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
|
|
559
|
-
var performance = global$1.performance || {};
|
|
560
|
-
performance.now ||
|
|
561
|
-
performance.mozNow ||
|
|
562
|
-
performance.msNow ||
|
|
563
|
-
performance.oNow ||
|
|
564
|
-
performance.webkitNow ||
|
|
565
|
+
var performance$1 = global$1.performance || {};
|
|
566
|
+
performance$1.now ||
|
|
567
|
+
performance$1.mozNow ||
|
|
568
|
+
performance$1.msNow ||
|
|
569
|
+
performance$1.oNow ||
|
|
570
|
+
performance$1.webkitNow ||
|
|
565
571
|
function(){ return (new Date()).getTime() };
|
|
566
572
|
|
|
567
573
|
var browser$1 = {
|
|
@@ -601,7 +607,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
|
|
|
601
607
|
{ type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
|
|
602
608
|
];
|
|
603
609
|
const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
604
|
-
const currentPackageVersion = "2.3.
|
|
610
|
+
const currentPackageVersion = "2.3.7-alpha.0" ;
|
|
605
611
|
|
|
606
612
|
/**
|
|
607
613
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -4933,43 +4939,6 @@ class StorageService {
|
|
|
4933
4939
|
}
|
|
4934
4940
|
throw new Error(`Unsupported seed phrase type: ${seedPhraseType}`);
|
|
4935
4941
|
}
|
|
4936
|
-
/**
|
|
4937
|
-
*
|
|
4938
|
-
* Stores Wallaby auth public key to local storage
|
|
4939
|
-
* @param wallabyAuthPubKey
|
|
4940
|
-
*/
|
|
4941
|
-
async setWallabyAuthPubKey(wallabyAuthPubKey) {
|
|
4942
|
-
await this.save(exports.V2KeyNames.WallabyAuthPubKey, wallabyAuthPubKey);
|
|
4943
|
-
}
|
|
4944
|
-
/**
|
|
4945
|
-
*
|
|
4946
|
-
* Fetches Wallaby auth public key from local storage
|
|
4947
|
-
* @returns { string | undefined } Wallaby Auth Public key or undefined.
|
|
4948
|
-
*/
|
|
4949
|
-
async getWallabyAuthPubKey() {
|
|
4950
|
-
let wallabyAuthPubKey = await this.fetch(exports.V2KeyNames.WallabyAuthPubKey);
|
|
4951
|
-
if (wallabyAuthPubKey) {
|
|
4952
|
-
return wallabyAuthPubKey;
|
|
4953
|
-
}
|
|
4954
|
-
// Legacy key migration
|
|
4955
|
-
const legacyKey = `wallabyAuthPubKey_${this.userId}`;
|
|
4956
|
-
const legacyPubKey = await this.getItem(legacyKey);
|
|
4957
|
-
if (legacyPubKey) {
|
|
4958
|
-
wallabyAuthPubKey = legacyPubKey;
|
|
4959
|
-
}
|
|
4960
|
-
else {
|
|
4961
|
-
const v1Key = `${this.environment}-wallaby-auth-public-key-${this.userId}`;
|
|
4962
|
-
const v1PubKey = await this.getItem(v1Key);
|
|
4963
|
-
if (v1PubKey) {
|
|
4964
|
-
wallabyAuthPubKey = v1PubKey;
|
|
4965
|
-
}
|
|
4966
|
-
}
|
|
4967
|
-
if (wallabyAuthPubKey) {
|
|
4968
|
-
await this.setWallabyAuthPubKey(wallabyAuthPubKey);
|
|
4969
|
-
return wallabyAuthPubKey;
|
|
4970
|
-
}
|
|
4971
|
-
return undefined;
|
|
4972
|
-
}
|
|
4973
4942
|
/**
|
|
4974
4943
|
* @deprecated This function is only used in tests, and should not be used anywhere else.
|
|
4975
4944
|
* Encrypts and stores device auth private key
|
|
@@ -6344,16 +6313,6 @@ class Api {
|
|
|
6344
6313
|
* @secure
|
|
6345
6314
|
*/
|
|
6346
6315
|
getEstimateFee: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/estimate-fee`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6347
|
-
/**
|
|
6348
|
-
* No description
|
|
6349
|
-
*
|
|
6350
|
-
* @tags Transactions, Query
|
|
6351
|
-
* @name FetchTransactionByHashOrReference
|
|
6352
|
-
* @summary Fetch transaction status data using a reference or transaction hash
|
|
6353
|
-
* @request GET:/api/v1/transactions/status
|
|
6354
|
-
* @secure
|
|
6355
|
-
*/
|
|
6356
|
-
fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6357
6316
|
/**
|
|
6358
6317
|
* @description The sign and broadcast transaction API was designed and implemented specifically for uses cases where the caller has their own custom raw transaction that is not yet currently supported by Wallaby
|
|
6359
6318
|
*
|
|
@@ -6364,6 +6323,16 @@ class Api {
|
|
|
6364
6323
|
* @secure
|
|
6365
6324
|
*/
|
|
6366
6325
|
signAndBroadcastRawTx: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/sign-broadcast-rawtx`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
|
|
6326
|
+
/**
|
|
6327
|
+
* No description
|
|
6328
|
+
*
|
|
6329
|
+
* @tags Transactions, Query
|
|
6330
|
+
* @name FetchTransactionByHashOrReference
|
|
6331
|
+
* @summary Fetch transaction status data using a reference or transaction hash
|
|
6332
|
+
* @request GET:/api/v1/transactions/status
|
|
6333
|
+
* @secure
|
|
6334
|
+
*/
|
|
6335
|
+
fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6367
6336
|
/**
|
|
6368
6337
|
* No description
|
|
6369
6338
|
*
|
|
@@ -6875,6 +6844,184 @@ function objectToQueryParams(obj) {
|
|
|
6875
6844
|
return params.toString();
|
|
6876
6845
|
}
|
|
6877
6846
|
|
|
6847
|
+
var NetworkDiagnosticCategory;
|
|
6848
|
+
(function (NetworkDiagnosticCategory) {
|
|
6849
|
+
NetworkDiagnosticCategory["OfflineHint"] = "offline_hint";
|
|
6850
|
+
NetworkDiagnosticCategory["LikelyCorsOrAuthOrExtension"] = "likely_cors_or_auth_or_extension";
|
|
6851
|
+
NetworkDiagnosticCategory["ConnectivityOrDns"] = "connectivity_or_dns";
|
|
6852
|
+
NetworkDiagnosticCategory["FastFailureHint"] = "fast_failure_hint";
|
|
6853
|
+
NetworkDiagnosticCategory["UnknownNetwork"] = "unknown_network";
|
|
6854
|
+
})(NetworkDiagnosticCategory || (NetworkDiagnosticCategory = {}));
|
|
6855
|
+
|
|
6856
|
+
const HEALTH_CHECK_TIMEOUT_MS = 5000;
|
|
6857
|
+
class NetworkDiagnostic {
|
|
6858
|
+
/**
|
|
6859
|
+
* Run comprehensive network diagnostics after a fetch failure.
|
|
6860
|
+
* Combines multiple signals to determine the likely cause of the failure.
|
|
6861
|
+
*/
|
|
6862
|
+
static async run(context) {
|
|
6863
|
+
const { failedUrl, originalError } = context;
|
|
6864
|
+
logger.info('Running network diagnostic', { failedUrl, originalError });
|
|
6865
|
+
const signals = {
|
|
6866
|
+
online: NetworkDiagnostic.getNavigatorOnline(),
|
|
6867
|
+
healthCheck: 'unavailable',
|
|
6868
|
+
failedRequestUrl: failedUrl,
|
|
6869
|
+
};
|
|
6870
|
+
const hints = [];
|
|
6871
|
+
const resourceTiming = NetworkDiagnostic.getResourceTimingForUrl(failedUrl);
|
|
6872
|
+
if (resourceTiming) {
|
|
6873
|
+
signals.resourceTiming = {
|
|
6874
|
+
nextHopProtocol: resourceTiming.nextHopProtocol,
|
|
6875
|
+
duration: resourceTiming.duration,
|
|
6876
|
+
transferSize: resourceTiming.transferSize,
|
|
6877
|
+
};
|
|
6878
|
+
if (resourceTiming.duration < 50) {
|
|
6879
|
+
hints.push('Very fast failure may indicate a local blocker or extension.');
|
|
6880
|
+
}
|
|
6881
|
+
}
|
|
6882
|
+
const healthUrl = NetworkDiagnostic.deriveHealthUrl(failedUrl);
|
|
6883
|
+
signals.healthCheck = await NetworkDiagnostic.simpleHealthCheck(healthUrl);
|
|
6884
|
+
const category = NetworkDiagnostic.determineCategory(signals);
|
|
6885
|
+
const message = NetworkDiagnostic.getCategoryMessage(category);
|
|
6886
|
+
return {
|
|
6887
|
+
category,
|
|
6888
|
+
message,
|
|
6889
|
+
signals,
|
|
6890
|
+
hints: hints.length > 0 ? hints : undefined,
|
|
6891
|
+
};
|
|
6892
|
+
}
|
|
6893
|
+
/**
|
|
6894
|
+
* Check if navigator.onLine is available and return its value.
|
|
6895
|
+
*/
|
|
6896
|
+
static getNavigatorOnline() {
|
|
6897
|
+
if (typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean') {
|
|
6898
|
+
return navigator.onLine;
|
|
6899
|
+
}
|
|
6900
|
+
return 'unknown';
|
|
6901
|
+
}
|
|
6902
|
+
/**
|
|
6903
|
+
* Get the PerformanceResourceTiming entry for the given URL.
|
|
6904
|
+
* Returns the most recent entry if multiple matches exist.
|
|
6905
|
+
*/
|
|
6906
|
+
static getResourceTimingForUrl(url) {
|
|
6907
|
+
if (typeof performance === 'undefined' || typeof performance.getEntriesByType !== 'function') {
|
|
6908
|
+
return undefined;
|
|
6909
|
+
}
|
|
6910
|
+
try {
|
|
6911
|
+
const entries = performance.getEntriesByType('resource');
|
|
6912
|
+
const matchingEntries = entries.filter((entry) => entry.name && entry.name.includes(url));
|
|
6913
|
+
if (matchingEntries.length === 0) {
|
|
6914
|
+
return undefined;
|
|
6915
|
+
}
|
|
6916
|
+
return matchingEntries[matchingEntries.length - 1];
|
|
6917
|
+
}
|
|
6918
|
+
catch (_a) {
|
|
6919
|
+
return undefined;
|
|
6920
|
+
}
|
|
6921
|
+
}
|
|
6922
|
+
/**
|
|
6923
|
+
* Perform a simple no-cors health check to the `/healthz` endpoint.
|
|
6924
|
+
* This uses mode: 'no-cors' to avoid CORS preflight and credential issues.
|
|
6925
|
+
*/
|
|
6926
|
+
static async simpleHealthCheck(healthUrl) {
|
|
6927
|
+
if (typeof fetch === 'undefined') {
|
|
6928
|
+
return 'unavailable';
|
|
6929
|
+
}
|
|
6930
|
+
const controller = new AbortController();
|
|
6931
|
+
const timeoutId = setTimeout(() => controller.abort(), HEALTH_CHECK_TIMEOUT_MS);
|
|
6932
|
+
try {
|
|
6933
|
+
const response = await fetch(healthUrl, {
|
|
6934
|
+
method: 'HEAD',
|
|
6935
|
+
mode: 'no-cors',
|
|
6936
|
+
cache: 'no-store',
|
|
6937
|
+
signal: controller.signal,
|
|
6938
|
+
});
|
|
6939
|
+
if (response.type === 'opaque') {
|
|
6940
|
+
return 'ok';
|
|
6941
|
+
}
|
|
6942
|
+
return 'failed';
|
|
6943
|
+
}
|
|
6944
|
+
catch (_a) {
|
|
6945
|
+
return 'failed';
|
|
6946
|
+
}
|
|
6947
|
+
finally {
|
|
6948
|
+
clearTimeout(timeoutId);
|
|
6949
|
+
}
|
|
6950
|
+
}
|
|
6951
|
+
/**
|
|
6952
|
+
* Derive the health check URL from the base URL origin and `/healthz`.
|
|
6953
|
+
*/
|
|
6954
|
+
static deriveHealthUrl(baseUrl) {
|
|
6955
|
+
try {
|
|
6956
|
+
const url = new URL(baseUrl);
|
|
6957
|
+
const origin = url.origin;
|
|
6958
|
+
return `${origin}/healthz`;
|
|
6959
|
+
}
|
|
6960
|
+
catch (_a) {
|
|
6961
|
+
return `${baseUrl}/healthz`;
|
|
6962
|
+
}
|
|
6963
|
+
}
|
|
6964
|
+
/**
|
|
6965
|
+
* Determine the diagnostic category based on collected signals.
|
|
6966
|
+
* Order matters - checks are performed in priority order.
|
|
6967
|
+
*/
|
|
6968
|
+
static determineCategory(signals) {
|
|
6969
|
+
if (signals.online === false) {
|
|
6970
|
+
return NetworkDiagnosticCategory.OfflineHint;
|
|
6971
|
+
}
|
|
6972
|
+
if (signals.healthCheck === 'ok') {
|
|
6973
|
+
return NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension;
|
|
6974
|
+
}
|
|
6975
|
+
if (signals.resourceTiming && signals.resourceTiming.duration !== undefined && signals.resourceTiming.duration < 50) {
|
|
6976
|
+
return NetworkDiagnosticCategory.FastFailureHint;
|
|
6977
|
+
}
|
|
6978
|
+
if (signals.healthCheck === 'failed') {
|
|
6979
|
+
return NetworkDiagnosticCategory.ConnectivityOrDns;
|
|
6980
|
+
}
|
|
6981
|
+
return NetworkDiagnosticCategory.UnknownNetwork;
|
|
6982
|
+
}
|
|
6983
|
+
/**
|
|
6984
|
+
* Get a user-facing message for the given diagnostic category.
|
|
6985
|
+
*/
|
|
6986
|
+
static getCategoryMessage(category) {
|
|
6987
|
+
switch (category) {
|
|
6988
|
+
case NetworkDiagnosticCategory.OfflineHint:
|
|
6989
|
+
return 'Device reports offline; check Wi-Fi or mobile data.';
|
|
6990
|
+
case NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension:
|
|
6991
|
+
return 'Reachability to the API is OK; the failure may be due to CORS, authentication headers, or a browser extension blocking authenticated requests.';
|
|
6992
|
+
case NetworkDiagnosticCategory.ConnectivityOrDns:
|
|
6993
|
+
return 'Cannot reach the API host; check DNS, VPN, firewall, or ISP filtering.';
|
|
6994
|
+
case NetworkDiagnosticCategory.FastFailureHint:
|
|
6995
|
+
return 'Very fast failure may indicate a local blocker or extension.';
|
|
6996
|
+
case NetworkDiagnosticCategory.UnknownNetwork:
|
|
6997
|
+
default:
|
|
6998
|
+
return 'Network request failed; see diagnostic details.';
|
|
6999
|
+
}
|
|
7000
|
+
}
|
|
7001
|
+
/**
|
|
7002
|
+
* Check if an error is a network-layer failure candidate that should trigger diagnostics.
|
|
7003
|
+
* Returns true for TypeErrors with fetch-related messages, or DOMException with NetworkError name.
|
|
7004
|
+
*/
|
|
7005
|
+
static isNetworkFailureCandidate(error) {
|
|
7006
|
+
if (!error)
|
|
7007
|
+
return false;
|
|
7008
|
+
if (error instanceof TypeError) {
|
|
7009
|
+
const message = error.message.toLowerCase();
|
|
7010
|
+
return (message.includes('failed to fetch') ||
|
|
7011
|
+
message.includes('load failed') ||
|
|
7012
|
+
message.includes('networkerror') ||
|
|
7013
|
+
message.includes('network request failed'));
|
|
7014
|
+
}
|
|
7015
|
+
if (error instanceof Error && error.name === 'NetworkError') {
|
|
7016
|
+
return true;
|
|
7017
|
+
}
|
|
7018
|
+
if (typeof DOMException !== 'undefined' && error instanceof DOMException && error.name === 'NetworkError') {
|
|
7019
|
+
return true;
|
|
7020
|
+
}
|
|
7021
|
+
return false;
|
|
7022
|
+
}
|
|
7023
|
+
}
|
|
7024
|
+
|
|
6878
7025
|
class Base {
|
|
6879
7026
|
constructor(config) {
|
|
6880
7027
|
var _a, _b;
|
|
@@ -6925,6 +7072,26 @@ class Base {
|
|
|
6925
7072
|
if (error instanceof WallabyError) {
|
|
6926
7073
|
throw error;
|
|
6927
7074
|
}
|
|
7075
|
+
// Handle network-level failures with diagnostics
|
|
7076
|
+
if (NetworkDiagnostic.isNetworkFailureCandidate(error)) {
|
|
7077
|
+
const fullUrl = `${this.baseUrl.replace(/\/api\/v1\/?$/, '')}${params.path || ''}`;
|
|
7078
|
+
const diagnostic = await NetworkDiagnostic.run({
|
|
7079
|
+
failedUrl: fullUrl,
|
|
7080
|
+
originalError: error,
|
|
7081
|
+
});
|
|
7082
|
+
const errorCode = this.mapCategoryToErrorCode(diagnostic.category);
|
|
7083
|
+
throw new WallabyError({
|
|
7084
|
+
message: diagnostic.message,
|
|
7085
|
+
statusCode: 0,
|
|
7086
|
+
errorCode,
|
|
7087
|
+
data: {
|
|
7088
|
+
originalError: error,
|
|
7089
|
+
networkDiagnostic: diagnostic,
|
|
7090
|
+
},
|
|
7091
|
+
cause: error.cause,
|
|
7092
|
+
networkDiagnostic: diagnostic,
|
|
7093
|
+
});
|
|
7094
|
+
}
|
|
6928
7095
|
// Wrap any other errors
|
|
6929
7096
|
throw new WallabyError({
|
|
6930
7097
|
message: error.message || 'Unknown error occurred',
|
|
@@ -7094,6 +7261,25 @@ class Base {
|
|
|
7094
7261
|
name: error.name,
|
|
7095
7262
|
error,
|
|
7096
7263
|
});
|
|
7264
|
+
if (NetworkDiagnostic.isNetworkFailureCandidate(error)) {
|
|
7265
|
+
const diagnostic = await NetworkDiagnostic.run({
|
|
7266
|
+
failedUrl: fullUrl,
|
|
7267
|
+
originalError: error,
|
|
7268
|
+
});
|
|
7269
|
+
const errorCode = this.mapCategoryToErrorCode(diagnostic.category);
|
|
7270
|
+
throw new WallabyError({
|
|
7271
|
+
message: diagnostic.message,
|
|
7272
|
+
statusCode: 0,
|
|
7273
|
+
errorCode,
|
|
7274
|
+
data: {
|
|
7275
|
+
code: error.name,
|
|
7276
|
+
originalError: error,
|
|
7277
|
+
networkDiagnostic: diagnostic,
|
|
7278
|
+
},
|
|
7279
|
+
cause: error.cause,
|
|
7280
|
+
networkDiagnostic: diagnostic,
|
|
7281
|
+
});
|
|
7282
|
+
}
|
|
7097
7283
|
throw new WallabyError({
|
|
7098
7284
|
message: error.message || 'Network request failed',
|
|
7099
7285
|
statusCode: 0,
|
|
@@ -7106,6 +7292,20 @@ class Base {
|
|
|
7106
7292
|
});
|
|
7107
7293
|
}
|
|
7108
7294
|
}
|
|
7295
|
+
mapCategoryToErrorCode(category) {
|
|
7296
|
+
switch (category) {
|
|
7297
|
+
case NetworkDiagnosticCategory.OfflineHint:
|
|
7298
|
+
return exports.ErrorResponseCodes.sdk_network_offline;
|
|
7299
|
+
case NetworkDiagnosticCategory.ConnectivityOrDns:
|
|
7300
|
+
return exports.ErrorResponseCodes.sdk_network_connectivity;
|
|
7301
|
+
case NetworkDiagnosticCategory.LikelyCorsOrAuthOrExtension:
|
|
7302
|
+
return exports.ErrorResponseCodes.sdk_network_likely_cors_or_auth;
|
|
7303
|
+
case NetworkDiagnosticCategory.FastFailureHint:
|
|
7304
|
+
return exports.ErrorResponseCodes.sdk_network_fast_failure;
|
|
7305
|
+
default:
|
|
7306
|
+
return exports.ErrorResponseCodes.sdk_network_unknown;
|
|
7307
|
+
}
|
|
7308
|
+
}
|
|
7109
7309
|
async _getRequestHeaders() {
|
|
7110
7310
|
const accessToken = await this.localStorageService.fetch(exports.LocalStorageItems.AccessToken);
|
|
7111
7311
|
if (!isTest && jwtHasExpired(this.clientAuthToken)) {
|
|
@@ -7400,6 +7600,13 @@ const SwapRoutes = {
|
|
|
7400
7600
|
},
|
|
7401
7601
|
};
|
|
7402
7602
|
|
|
7603
|
+
function omit(obj, keys) {
|
|
7604
|
+
if (!obj)
|
|
7605
|
+
return {};
|
|
7606
|
+
const keysSet = new Set(keys);
|
|
7607
|
+
return Object.fromEntries(Object.entries(obj).filter(([k]) => !keysSet.has(k)));
|
|
7608
|
+
}
|
|
7609
|
+
|
|
7403
7610
|
/* eslint-disable no-useless-catch */
|
|
7404
7611
|
/**
|
|
7405
7612
|
* Web Authenticator Implementation
|
|
@@ -7539,7 +7746,7 @@ class PasskeyService {
|
|
|
7539
7746
|
this.authenticator = new Authenticator();
|
|
7540
7747
|
}
|
|
7541
7748
|
preparePasskeyRequestOptions(options) {
|
|
7542
|
-
var _a, _b, _c, _d, _e, _f;
|
|
7749
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
7543
7750
|
const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
|
|
7544
7751
|
? decodeBase64URL(options.extensions.prf.eval.base64)
|
|
7545
7752
|
: ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
|
|
@@ -7547,11 +7754,13 @@ class PasskeyService {
|
|
|
7547
7754
|
: typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
|
|
7548
7755
|
? new Uint8Array(Object.values(options.extensions.prf.eval.first))
|
|
7549
7756
|
: undefined;
|
|
7550
|
-
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf:
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7757
|
+
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined
|
|
7758
|
+
? {
|
|
7759
|
+
eval: {
|
|
7760
|
+
first: prfExtensionEvaluation,
|
|
7761
|
+
},
|
|
7762
|
+
}
|
|
7763
|
+
: ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
|
|
7555
7764
|
logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
|
|
7556
7765
|
// While the authenticator still works with the prf and would return the response (if any),
|
|
7557
7766
|
// the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
|
|
@@ -7559,7 +7768,7 @@ class PasskeyService {
|
|
|
7559
7768
|
return parsedOptions;
|
|
7560
7769
|
}
|
|
7561
7770
|
preparePasskeyCreationOptions(options) {
|
|
7562
|
-
var _a, _b, _c, _d, _e, _f;
|
|
7771
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
7563
7772
|
const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
|
|
7564
7773
|
? decodeBase64URL(options.extensions.prf.eval.base64)
|
|
7565
7774
|
: ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
|
|
@@ -7567,12 +7776,8 @@ class PasskeyService {
|
|
|
7567
7776
|
: typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
|
|
7568
7777
|
? new Uint8Array(Object.values(options.extensions.prf.eval.first))
|
|
7569
7778
|
: undefined;
|
|
7570
|
-
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
|
|
7571
|
-
|
|
7572
|
-
first: prfExtensionEvaluation,
|
|
7573
|
-
},
|
|
7574
|
-
} }) });
|
|
7575
|
-
logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
|
|
7779
|
+
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined ? { eval: { first: prfExtensionEvaluation } } : ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
|
|
7780
|
+
logger.log('SDK::PasskeyService::preparePasskeyCreationOptions::parsedOptions', !!parsedOptions);
|
|
7576
7781
|
return parsedOptions;
|
|
7577
7782
|
}
|
|
7578
7783
|
/**
|
|
@@ -7587,7 +7792,10 @@ class PasskeyService {
|
|
|
7587
7792
|
let passkeyCredential;
|
|
7588
7793
|
let signInResponse;
|
|
7589
7794
|
try {
|
|
7590
|
-
const registrationChallengeResponse = await getSignature(
|
|
7795
|
+
const registrationChallengeResponse = await getSignature({
|
|
7796
|
+
deviceAuthKeys: deviceKeyPair,
|
|
7797
|
+
passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
|
|
7798
|
+
});
|
|
7591
7799
|
if (!registrationChallengeResponse.registrationOptions)
|
|
7592
7800
|
throw new WallabyError({
|
|
7593
7801
|
message: 'Passkey challenge could not be retrieved, please try again later.',
|
|
@@ -7630,7 +7838,10 @@ class PasskeyService {
|
|
|
7630
7838
|
catch (error) {
|
|
7631
7839
|
logger.error('SDK::PasskeyService::addNewPasskey::error', error);
|
|
7632
7840
|
if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
|
|
7633
|
-
const authenticationChallengeResponse = await getSignature(
|
|
7841
|
+
const authenticationChallengeResponse = await getSignature({
|
|
7842
|
+
deviceAuthKeys: deviceKeyPair,
|
|
7843
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
7844
|
+
});
|
|
7634
7845
|
if (!authenticationChallengeResponse.authenticationOptions)
|
|
7635
7846
|
throw new WallabyError({
|
|
7636
7847
|
message: 'Passkey challenge could not be retrieved, please try again later.',
|
|
@@ -7701,7 +7912,7 @@ class PasskeyService {
|
|
|
7701
7912
|
errorCode: exports.ErrorResponseCodes.sdk_passkey_challenge_unavailable,
|
|
7702
7913
|
});
|
|
7703
7914
|
const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
|
|
7704
|
-
const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({},
|
|
7915
|
+
const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
|
|
7705
7916
|
eval: {
|
|
7706
7917
|
first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
|
|
7707
7918
|
},
|
|
@@ -7930,10 +8141,6 @@ class PasskeyService {
|
|
|
7930
8141
|
key: exports.LocalStorageItems.AccessToken,
|
|
7931
8142
|
value: authenticationResponse.accessToken,
|
|
7932
8143
|
},
|
|
7933
|
-
{
|
|
7934
|
-
key: exports.LocalStorageItems.WallabyAuthPubKey,
|
|
7935
|
-
value: authenticationResponse.user.wallabyAuthPubKey,
|
|
7936
|
-
},
|
|
7937
8144
|
]);
|
|
7938
8145
|
}
|
|
7939
8146
|
/**
|
|
@@ -8142,13 +8349,14 @@ class AuthService extends Base {
|
|
|
8142
8349
|
* @param { PasskeyChallengeType } passkeyChallengeType the type of passkey challenge to request, either for registration or authentication.
|
|
8143
8350
|
* @returns the messaged, the hash, and the signature using the passed private key.
|
|
8144
8351
|
*/
|
|
8145
|
-
async getSignature(deviceAuthKeys, passkeyChallengeType) {
|
|
8352
|
+
async getSignature({ deviceAuthKeys, walletId, passkeyChallengeType, }) {
|
|
8146
8353
|
try {
|
|
8147
8354
|
logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
|
|
8148
8355
|
const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : exports.PasskeyChallengeType.REGISTRATION;
|
|
8149
8356
|
logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
|
|
8150
8357
|
const response = await this.request(AuthRoutes.signatureMessage, {
|
|
8151
8358
|
payload: {
|
|
8359
|
+
walletId,
|
|
8152
8360
|
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
8153
8361
|
passkeyChallengeType: challengeType,
|
|
8154
8362
|
},
|
|
@@ -8179,7 +8387,10 @@ class AuthService extends Base {
|
|
|
8179
8387
|
logger.info('key pair generated', !!deviceKeyPair);
|
|
8180
8388
|
let authentication;
|
|
8181
8389
|
try {
|
|
8182
|
-
const signatureMessageResponse = await this.getSignature(
|
|
8390
|
+
const signatureMessageResponse = await this.getSignature({
|
|
8391
|
+
deviceAuthKeys: deviceKeyPair,
|
|
8392
|
+
passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
|
|
8393
|
+
});
|
|
8183
8394
|
logger.info('signature has been generated', !!signatureMessageResponse);
|
|
8184
8395
|
switch (this.deviceAuthType) {
|
|
8185
8396
|
case exports.AuthType.Passkey:
|
|
@@ -8212,7 +8423,10 @@ class AuthService extends Base {
|
|
|
8212
8423
|
// TODO Add passkey errors to the WallabyError ErrorResponseCodes
|
|
8213
8424
|
if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
|
|
8214
8425
|
logger.info('SDK::AuthService::signUp::handling previously registered passkey error');
|
|
8215
|
-
const newChallenge = await this.getSignature(
|
|
8426
|
+
const newChallenge = await this.getSignature({
|
|
8427
|
+
deviceAuthKeys: deviceKeyPair,
|
|
8428
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
8429
|
+
});
|
|
8216
8430
|
authentication = await this.passkeyService.authenticate({
|
|
8217
8431
|
deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
|
|
8218
8432
|
challengeResponse: newChallenge,
|
|
@@ -8249,10 +8463,7 @@ class AuthService extends Base {
|
|
|
8249
8463
|
errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
|
|
8250
8464
|
});
|
|
8251
8465
|
}
|
|
8252
|
-
await this.localStorageService.
|
|
8253
|
-
{ key: exports.LocalStorageItems.AccessToken, value: authentication.accessToken },
|
|
8254
|
-
{ key: exports.LocalStorageItems.WallabyAuthPubKey, value: authentication.user.wallabyAuthPubKey },
|
|
8255
|
-
]);
|
|
8466
|
+
await this.localStorageService.save(exports.LocalStorageItems.AccessToken, authentication.accessToken);
|
|
8256
8467
|
return Object.freeze(Object.assign(Object.assign({}, authentication), input));
|
|
8257
8468
|
}
|
|
8258
8469
|
catch (error) {
|
|
@@ -8328,7 +8539,9 @@ class AuthService extends Base {
|
|
|
8328
8539
|
},
|
|
8329
8540
|
credentialsKeyPair,
|
|
8330
8541
|
});
|
|
8331
|
-
const signatureMessage = await this.getSignature({
|
|
8542
|
+
const signatureMessage = await this.getSignature({
|
|
8543
|
+
deviceAuthKeys: { publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey },
|
|
8544
|
+
});
|
|
8332
8545
|
const authentication = await this.request(AuthRoutes.signIn, {
|
|
8333
8546
|
payload: {
|
|
8334
8547
|
externalUserId: this.userId,
|
|
@@ -8452,10 +8665,6 @@ class AuthService extends Base {
|
|
|
8452
8665
|
key: exports.LocalStorageItems.AccessToken,
|
|
8453
8666
|
value: authResponse.accessToken,
|
|
8454
8667
|
},
|
|
8455
|
-
{
|
|
8456
|
-
key: exports.LocalStorageItems.WallabyAuthPubKey,
|
|
8457
|
-
value: authResponse.user.wallabyAuthPubKey,
|
|
8458
|
-
},
|
|
8459
8668
|
]);
|
|
8460
8669
|
return authResponse;
|
|
8461
8670
|
});
|
|
@@ -8540,12 +8749,16 @@ class WalletHandlersService extends Base {
|
|
|
8540
8749
|
this.userId = config.userId;
|
|
8541
8750
|
}
|
|
8542
8751
|
async handleImportWallet(deviceAuthKeys, importWalletInput) {
|
|
8543
|
-
var _a, _b, _c, _d;
|
|
8752
|
+
var _a, _b, _c, _d, _e;
|
|
8544
8753
|
try {
|
|
8545
|
-
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
|
|
8754
|
+
// Since users importing a wallet can be requesting to create a new record, walletId is not available yet.
|
|
8755
|
+
// However the enclave needs a uuid to bind the ephemeral wallaby auth public key to it for the first request
|
|
8756
|
+
// Using the reference as the fallback for the walletId in this case.
|
|
8757
|
+
const { signature, message, wallabyAuthPubKey } = await this.authService.getSignature({
|
|
8758
|
+
walletId: (_a = importWalletInput.walletId) !== null && _a !== void 0 ? _a : importWalletInput.reference,
|
|
8759
|
+
deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
|
|
8760
|
+
passkeyChallengeType: this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined,
|
|
8761
|
+
});
|
|
8549
8762
|
if ((importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
|
|
8550
8763
|
importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
|
|
8551
8764
|
!importWalletInput.keyShareOptions) {
|
|
@@ -8555,7 +8768,7 @@ class WalletHandlersService extends Base {
|
|
|
8555
8768
|
errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
|
|
8556
8769
|
});
|
|
8557
8770
|
}
|
|
8558
|
-
const { numberOfKeyShares, threshold } = (
|
|
8771
|
+
const { numberOfKeyShares, threshold } = (_b = importWalletInput.keyShareOptions) !== null && _b !== void 0 ? _b : {};
|
|
8559
8772
|
if (threshold && numberOfKeyShares && numberOfKeyShares < threshold) {
|
|
8560
8773
|
throw new WallabyError({
|
|
8561
8774
|
message: 'Number of shares must be greater than or equal to the threshold',
|
|
@@ -8565,10 +8778,11 @@ class WalletHandlersService extends Base {
|
|
|
8565
8778
|
}
|
|
8566
8779
|
const readyForTransportSeedPhrase = await this.cipher.encrypt({
|
|
8567
8780
|
data: importWalletInput.seedPhrase,
|
|
8568
|
-
encryptionKey:
|
|
8781
|
+
encryptionKey: wallabyAuthPubKey,
|
|
8569
8782
|
});
|
|
8570
8783
|
const importWalletPayload = {
|
|
8571
|
-
reference:
|
|
8784
|
+
reference: importWalletInput.reference,
|
|
8785
|
+
walletId: importWalletInput.walletId,
|
|
8572
8786
|
message,
|
|
8573
8787
|
signature,
|
|
8574
8788
|
encryptedSeed: readyForTransportSeedPhrase,
|
|
@@ -8577,7 +8791,7 @@ class WalletHandlersService extends Base {
|
|
|
8577
8791
|
numShares: numberOfKeyShares !== null && numberOfKeyShares !== void 0 ? numberOfKeyShares : 0,
|
|
8578
8792
|
threshold: threshold !== null && threshold !== void 0 ? threshold : 0,
|
|
8579
8793
|
walletOwnershipType: exports.WalletOwnershipType.SingleOwner,
|
|
8580
|
-
wallabyKeepsOne: (
|
|
8794
|
+
wallabyKeepsOne: (_d = (_c = importWalletInput.keyShareOptions) === null || _c === void 0 ? void 0 : _c.storeOneKeyShareWithWallaby) !== null && _d !== void 0 ? _d : false,
|
|
8581
8795
|
};
|
|
8582
8796
|
const importWalletRequest = await this.request(WalletRoutes.importSeedPhraseV2, {
|
|
8583
8797
|
payload: importWalletPayload,
|
|
@@ -8615,7 +8829,7 @@ class WalletHandlersService extends Base {
|
|
|
8615
8829
|
}
|
|
8616
8830
|
catch (error) {
|
|
8617
8831
|
throw new WallabyError({
|
|
8618
|
-
message: (
|
|
8832
|
+
message: (_e = error.message) !== null && _e !== void 0 ? _e : 'Failed to handle importing the wallet',
|
|
8619
8833
|
statusCode: error.statusCode,
|
|
8620
8834
|
errorCode: error.errorCode,
|
|
8621
8835
|
data: error.data,
|
|
@@ -8637,9 +8851,9 @@ class WalletHandlersService extends Base {
|
|
|
8637
8851
|
var _a, _b, _c, _d, _e, _f;
|
|
8638
8852
|
try {
|
|
8639
8853
|
const { signature, message, hashedMessage } = await this.authService.getSignature({
|
|
8640
|
-
publicKey: deviceAuthKeys.publicKey,
|
|
8641
|
-
|
|
8642
|
-
}
|
|
8854
|
+
deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
|
|
8855
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
8856
|
+
});
|
|
8643
8857
|
if ((walletCreationInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
|
|
8644
8858
|
walletCreationInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
|
|
8645
8859
|
!walletCreationInput.keyShareOptions) {
|
|
@@ -8816,36 +9030,6 @@ class WalletHandlersService extends Base {
|
|
|
8816
9030
|
});
|
|
8817
9031
|
}
|
|
8818
9032
|
}
|
|
8819
|
-
/**
|
|
8820
|
-
*
|
|
8821
|
-
* @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
|
|
8822
|
-
* @param walletId - The ID of the wallet for which the seed phrase is being constructed.
|
|
8823
|
-
* @param deviceAuthKeys - The device authentication key pair used to sign the request.
|
|
8824
|
-
* @description This function constructs the seed phrase from encrypted key shares.
|
|
8825
|
-
* It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
|
|
8826
|
-
* The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
|
|
8827
|
-
* @returns The function returns the encrypted seed phrase wrapped with client device public key.
|
|
8828
|
-
*/
|
|
8829
|
-
async handleConstructingSeedPhraseFromShares({ encryptedKeyShares, walletId, deviceAuthKeys, }) {
|
|
8830
|
-
try {
|
|
8831
|
-
const { signature, message } = await this.authService.getSignature(deviceAuthKeys, exports.PasskeyChallengeType.AUTHENTICATION);
|
|
8832
|
-
const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
|
|
8833
|
-
payload: {
|
|
8834
|
-
walletId: walletId,
|
|
8835
|
-
signature,
|
|
8836
|
-
message,
|
|
8837
|
-
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
8838
|
-
recoveryPubKey: deviceAuthKeys.publicKey,
|
|
8839
|
-
encryptedShares: encryptedKeyShares,
|
|
8840
|
-
},
|
|
8841
|
-
});
|
|
8842
|
-
return retrieveSeedPhraseResponse.encryptedSeed;
|
|
8843
|
-
}
|
|
8844
|
-
catch (error) {
|
|
8845
|
-
logger.error('SDK::handleConstructingSeedPhraseFromShares::error', error);
|
|
8846
|
-
return Promise.reject(error);
|
|
8847
|
-
}
|
|
8848
|
-
}
|
|
8849
9033
|
}
|
|
8850
9034
|
|
|
8851
9035
|
class WalletService extends Base {
|
|
@@ -8955,7 +9139,6 @@ class WalletService extends Base {
|
|
|
8955
9139
|
*/
|
|
8956
9140
|
async export({ walletId, authenticationOptions, exportOptions }) {
|
|
8957
9141
|
try {
|
|
8958
|
-
const { user: { wallabyAuthPubKey }, } = authenticationOptions;
|
|
8959
9142
|
if (!exportOptions.algorandSeedPhrase && !exportOptions.standardSeedPhrase && !exportOptions.keyShares) {
|
|
8960
9143
|
throw new WallabyError({
|
|
8961
9144
|
message: 'exportOptions must be provided with at least one of the following options: algorandSeedPhrase, standardSeedPhrase, keyShares',
|
|
@@ -9065,10 +9248,20 @@ class WalletService extends Base {
|
|
|
9065
9248
|
});
|
|
9066
9249
|
}
|
|
9067
9250
|
const parsedPrimaryShare = safeJsonParse(encryptedPrimaryDeviceShare);
|
|
9251
|
+
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9252
|
+
const deviceAuthKeys = {
|
|
9253
|
+
publicKey: deviceAuthPublicKey,
|
|
9254
|
+
privateKey: decryptedDevicePrivateKey,
|
|
9255
|
+
};
|
|
9256
|
+
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
9257
|
+
deviceAuthKeys,
|
|
9258
|
+
walletId,
|
|
9259
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
9260
|
+
});
|
|
9068
9261
|
const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
|
|
9069
9262
|
storedEncryptedData: parsedPrimaryShare,
|
|
9070
9263
|
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9071
|
-
wallabyPublicKey: wallabyAuthPubKey,
|
|
9264
|
+
wallabyPublicKey: ephemeralWallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey,
|
|
9072
9265
|
options: {
|
|
9073
9266
|
authType: this.deviceAuthType,
|
|
9074
9267
|
password: authenticationOptions.password,
|
|
@@ -9076,17 +9269,18 @@ class WalletService extends Base {
|
|
|
9076
9269
|
prfValue: authenticationOptions.prfValue,
|
|
9077
9270
|
},
|
|
9078
9271
|
});
|
|
9079
|
-
const
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9272
|
+
const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
|
|
9273
|
+
payload: {
|
|
9274
|
+
walletId: walletId,
|
|
9275
|
+
signature,
|
|
9276
|
+
message,
|
|
9277
|
+
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
9278
|
+
recoveryPubKey: deviceAuthKeys.publicKey,
|
|
9279
|
+
encryptedShares: [wallabyBoundPrimaryShare],
|
|
9086
9280
|
},
|
|
9087
9281
|
});
|
|
9088
9282
|
decryptedSeedPhrase = await this.cipher.decrypt({
|
|
9089
|
-
cipherText:
|
|
9283
|
+
cipherText: retrieveSeedPhraseResponse.encryptedSeed,
|
|
9090
9284
|
decryptionKey: decryptedDevicePrivateKey,
|
|
9091
9285
|
});
|
|
9092
9286
|
if (exportOptions.algorandSeedPhrase) {
|
|
@@ -9124,7 +9318,9 @@ class WalletService extends Base {
|
|
|
9124
9318
|
* @returns {ImportWalletResponse} The wallet has been created successfully.
|
|
9125
9319
|
*/
|
|
9126
9320
|
async import(input) {
|
|
9321
|
+
var _a;
|
|
9127
9322
|
try {
|
|
9323
|
+
const requestReference = (_a = input.reference) !== null && _a !== void 0 ? _a : uuid.v4();
|
|
9128
9324
|
const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
9129
9325
|
if (!encryptedDevicePrivateKey) {
|
|
9130
9326
|
throw new WallabyError({
|
|
@@ -9155,7 +9351,7 @@ class WalletService extends Base {
|
|
|
9155
9351
|
const importRequest = await this.handlers.handleImportWallet({
|
|
9156
9352
|
publicKey: clientAuthPubKey,
|
|
9157
9353
|
privateKey: decryptedDevicePrivateKey,
|
|
9158
|
-
}, input);
|
|
9354
|
+
}, Object.assign(Object.assign({}, input), { reference: requestReference }));
|
|
9159
9355
|
return importRequest;
|
|
9160
9356
|
}
|
|
9161
9357
|
catch (error) {
|
|
@@ -9169,11 +9365,15 @@ class WalletService extends Base {
|
|
|
9169
9365
|
*
|
|
9170
9366
|
* @param { RecoverWalletRequest } input - The request object containing the necessary parameters.
|
|
9171
9367
|
* @returns { Promise<RecoverWalletResponse> } The response containing the recovered wallet details.
|
|
9368
|
+
*
|
|
9369
|
+
* @deprecated This function is deprecated and will be removed in the next major release. It only supports seed phrase recovery.
|
|
9370
|
+
* Use `import` instead with the `RETURN_ONLY_ENCRYPTED_SEED_PHRASE` option to maintain the same behavior.
|
|
9172
9371
|
*/
|
|
9173
9372
|
async recover(input) {
|
|
9174
9373
|
var _a, _b;
|
|
9175
9374
|
try {
|
|
9176
|
-
const wallabyPublicKey = input.authenticationOptions.
|
|
9375
|
+
const wallabyPublicKey = input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
|
|
9376
|
+
input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9177
9377
|
const deviceAuthKeyPair = createIdentity();
|
|
9178
9378
|
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9179
9379
|
authType: this.deviceAuthType,
|
|
@@ -9213,27 +9413,37 @@ class WalletService extends Base {
|
|
|
9213
9413
|
return recoverWithSeedPhraseResponse;
|
|
9214
9414
|
}
|
|
9215
9415
|
else if (input.decryptedShares) {
|
|
9216
|
-
|
|
9217
|
-
const encrypted = await this.cipher.encrypt({
|
|
9218
|
-
data: decryptedShare,
|
|
9219
|
-
encryptionKey: wallabyPublicKey,
|
|
9220
|
-
});
|
|
9221
|
-
return encrypted;
|
|
9222
|
-
}));
|
|
9223
|
-
if (!encryptedShares.length) {
|
|
9416
|
+
if (!input.decryptedShares.length) {
|
|
9224
9417
|
throw new WallabyError({
|
|
9225
9418
|
message: 'Decrypted shares are required',
|
|
9226
9419
|
statusCode: 400,
|
|
9227
9420
|
errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
|
|
9228
9421
|
});
|
|
9229
9422
|
}
|
|
9230
|
-
const
|
|
9231
|
-
encryptedKeyShares: encryptedShares,
|
|
9423
|
+
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
9232
9424
|
deviceAuthKeys: deviceAuthKeyPair,
|
|
9233
9425
|
walletId: input.walletId,
|
|
9426
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
9427
|
+
});
|
|
9428
|
+
const transportEncryptionKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9429
|
+
const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
|
|
9430
|
+
return await this.cipher.encrypt({
|
|
9431
|
+
data: decryptedShare,
|
|
9432
|
+
encryptionKey: transportEncryptionKey,
|
|
9433
|
+
});
|
|
9434
|
+
}));
|
|
9435
|
+
const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
|
|
9436
|
+
payload: {
|
|
9437
|
+
walletId: input.walletId,
|
|
9438
|
+
signature,
|
|
9439
|
+
message,
|
|
9440
|
+
clientAuthPubKey: deviceAuthKeyPair.publicKey,
|
|
9441
|
+
recoveryPubKey: deviceAuthKeyPair.publicKey,
|
|
9442
|
+
encryptedShares,
|
|
9443
|
+
},
|
|
9234
9444
|
});
|
|
9235
9445
|
const wallabyBoundRecoverySeedPhrase = await this.cipher.flipEncryptedData({
|
|
9236
|
-
cipherText: encryptedSeed,
|
|
9446
|
+
cipherText: retrieveSeedPhraseResponse.encryptedSeed,
|
|
9237
9447
|
decryptionKey: deviceAuthKeyPair.privateKey,
|
|
9238
9448
|
encryptionKey: wallabyPublicKey,
|
|
9239
9449
|
});
|
|
@@ -9291,17 +9501,9 @@ class WalletService extends Base {
|
|
|
9291
9501
|
async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
|
|
9292
9502
|
try {
|
|
9293
9503
|
const signatureMessage = await this.authService.getSignature({
|
|
9294
|
-
publicKey: deviceAuthKeys.publicKey,
|
|
9295
|
-
|
|
9296
|
-
});
|
|
9297
|
-
// const response = await this.request<RetrieveSharesData>(WalletRoutes.retrieveShares, {
|
|
9298
|
-
// payload: {
|
|
9299
|
-
// walletId,
|
|
9300
|
-
// signature: signatureMessage.signature,
|
|
9301
|
-
// message: signatureMessage.message,
|
|
9302
|
-
// clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
9303
|
-
// },
|
|
9304
|
-
// });
|
|
9504
|
+
deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
|
|
9505
|
+
walletId,
|
|
9506
|
+
});
|
|
9305
9507
|
const response = await this.api.wallets.retrieveShares({
|
|
9306
9508
|
walletId: walletId,
|
|
9307
9509
|
signature: signatureMessage.signature,
|
|
@@ -9482,6 +9684,7 @@ class WalletService extends Base {
|
|
|
9482
9684
|
*/
|
|
9483
9685
|
async initAddNewDevice(input) {
|
|
9484
9686
|
const { walletId, backupUrl, authenticationOptions } = input;
|
|
9687
|
+
const wallabyPublicKey = authenticationOptions.signatureMessageResponse.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
9485
9688
|
const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
9486
9689
|
if (!encryptedDevicePrivateKey) {
|
|
9487
9690
|
throw new WallabyError({
|
|
@@ -9542,7 +9745,7 @@ class WalletService extends Base {
|
|
|
9542
9745
|
const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
|
|
9543
9746
|
storedEncryptedData: parsedPrimaryShare,
|
|
9544
9747
|
encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
|
|
9545
|
-
wallabyPublicKey
|
|
9748
|
+
wallabyPublicKey,
|
|
9546
9749
|
options: {
|
|
9547
9750
|
authType: this.deviceAuthType,
|
|
9548
9751
|
password: authenticationOptions.password,
|
|
@@ -9601,22 +9804,11 @@ class WalletService extends Base {
|
|
|
9601
9804
|
}
|
|
9602
9805
|
const devicePublicKey = (_a = (await this.localStorageService.fetch(exports.LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9603
9806
|
const signatureMessage = await this.authService.getSignature({
|
|
9604
|
-
publicKey: devicePublicKey,
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
// walletId: input.walletId,
|
|
9610
|
-
// message: signatureMessage.message,
|
|
9611
|
-
// signature: signatureMessage.signature,
|
|
9612
|
-
// clientAuthPubKey: devicePublicKey,
|
|
9613
|
-
// share: {
|
|
9614
|
-
// encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
|
|
9615
|
-
// wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
|
|
9616
|
-
// type: KeyTypeName.OwnerBackupDeviceShare,
|
|
9617
|
-
// },
|
|
9618
|
-
// },
|
|
9619
|
-
// });
|
|
9807
|
+
deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedDevicePrivateKey },
|
|
9808
|
+
walletId: input.walletId,
|
|
9809
|
+
passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
|
|
9810
|
+
});
|
|
9811
|
+
const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9620
9812
|
const backUpResponse = await this.api.wallets.addNewDevice({
|
|
9621
9813
|
walletId: input.walletId,
|
|
9622
9814
|
message: signatureMessage.message,
|
|
@@ -9624,7 +9816,7 @@ class WalletService extends Base {
|
|
|
9624
9816
|
clientAuthPubKey: devicePublicKey,
|
|
9625
9817
|
share: {
|
|
9626
9818
|
encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
|
|
9627
|
-
wrappingPublicKey:
|
|
9819
|
+
wrappingPublicKey: wallabyPublicKey,
|
|
9628
9820
|
type: exports.KeyTypeName.OwnerBackupDeviceShare,
|
|
9629
9821
|
},
|
|
9630
9822
|
});
|
|
@@ -9632,7 +9824,8 @@ class WalletService extends Base {
|
|
|
9632
9824
|
backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
|
|
9633
9825
|
{
|
|
9634
9826
|
encrypted: input.encryptedShares[DEFAULT_PRIMARY_SHARE_INDEX],
|
|
9635
|
-
wrappingPublicKey: input.authenticationOptions.
|
|
9827
|
+
wrappingPublicKey: input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
|
|
9828
|
+
input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
|
|
9636
9829
|
type: exports.KeyTypeName.OwnerMainDeviceShare,
|
|
9637
9830
|
},
|
|
9638
9831
|
];
|
|
@@ -9689,12 +9882,28 @@ class WalletService extends Base {
|
|
|
9689
9882
|
});
|
|
9690
9883
|
}
|
|
9691
9884
|
const parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
|
|
9885
|
+
const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9886
|
+
authType: this.deviceAuthType,
|
|
9887
|
+
password: input.authenticationOptions.password,
|
|
9888
|
+
salt: input.authenticationOptions.clientSalt,
|
|
9889
|
+
prfValue: input.authenticationOptions.prfValue,
|
|
9890
|
+
});
|
|
9891
|
+
const decryptedDevicePrivateKey = await this.cipher.decrypt({
|
|
9892
|
+
cipherText: parsedDevicePrivateKey,
|
|
9893
|
+
decryptionKey: derivedCredentialsKeyPair.privateKey,
|
|
9894
|
+
});
|
|
9895
|
+
const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9896
|
+
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
9897
|
+
deviceAuthKeys: { privateKey: decryptedDevicePrivateKey, publicKey: devicePublicKey },
|
|
9898
|
+
walletId,
|
|
9899
|
+
});
|
|
9900
|
+
const wallabyPublicKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9692
9901
|
if (storedSeedPhrase) {
|
|
9693
9902
|
const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
|
|
9694
9903
|
transportSeed = await this.cipher.prepareStoredDataForTransport({
|
|
9695
9904
|
storedEncryptedData: parsedStoredSeedPhrase,
|
|
9696
9905
|
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9697
|
-
wallabyPublicKey
|
|
9906
|
+
wallabyPublicKey,
|
|
9698
9907
|
options: {
|
|
9699
9908
|
authType: this.deviceAuthType,
|
|
9700
9909
|
password: input.authenticationOptions.password,
|
|
@@ -9708,7 +9917,7 @@ class WalletService extends Base {
|
|
|
9708
9917
|
transportKeyShare = await this.cipher.prepareStoredDataForTransport({
|
|
9709
9918
|
storedEncryptedData: parsedPrimaryKeyShare,
|
|
9710
9919
|
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9711
|
-
wallabyPublicKey
|
|
9920
|
+
wallabyPublicKey,
|
|
9712
9921
|
options: {
|
|
9713
9922
|
authType: this.deviceAuthType,
|
|
9714
9923
|
password: input.authenticationOptions.password,
|
|
@@ -9724,21 +9933,6 @@ class WalletService extends Base {
|
|
|
9724
9933
|
errorCode: 'sdk_private_key_not_found',
|
|
9725
9934
|
});
|
|
9726
9935
|
}
|
|
9727
|
-
const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9728
|
-
authType: this.deviceAuthType,
|
|
9729
|
-
password: input.authenticationOptions.password,
|
|
9730
|
-
salt: input.authenticationOptions.clientSalt,
|
|
9731
|
-
prfValue: input.authenticationOptions.prfValue,
|
|
9732
|
-
});
|
|
9733
|
-
const decryptedDevicePrivateKey = await this.cipher.decrypt({
|
|
9734
|
-
cipherText: parsedDevicePrivateKey,
|
|
9735
|
-
decryptionKey: derivedCredentialsKeyPair.privateKey,
|
|
9736
|
-
});
|
|
9737
|
-
const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9738
|
-
const { signature, message } = await this.authService.getSignature({
|
|
9739
|
-
privateKey: decryptedDevicePrivateKey,
|
|
9740
|
-
publicKey: devicePublicKey,
|
|
9741
|
-
});
|
|
9742
9936
|
const response = await this.request(WalletRoutes.generateWalletAddresses, {
|
|
9743
9937
|
payload: {
|
|
9744
9938
|
walletId,
|
|
@@ -9930,8 +10124,8 @@ class WalletService extends Base {
|
|
|
9930
10124
|
// During migration, we need to authenticate but avoid creating conflicting device keypairs
|
|
9931
10125
|
const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
|
|
9932
10126
|
const signInSignatureMessage = await this.authService.getSignature({
|
|
9933
|
-
publicKey: devicePublicKey,
|
|
9934
|
-
|
|
10127
|
+
deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedPrivateKey },
|
|
10128
|
+
walletId,
|
|
9935
10129
|
});
|
|
9936
10130
|
// this would ensure the stored public key is consistent with wallaby and can authenticate the user.
|
|
9937
10131
|
const authResponse = await this.request(AuthRoutes.signIn, {
|
|
@@ -9957,7 +10151,6 @@ class WalletService extends Base {
|
|
|
9957
10151
|
// Store authentication tokens
|
|
9958
10152
|
await this.localStorageService.saveInBulk([
|
|
9959
10153
|
{ key: exports.LocalStorageItems.AccessToken, value: authResponse.accessToken },
|
|
9960
|
-
{ key: exports.LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
|
|
9961
10154
|
{ key: exports.V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
|
|
9962
10155
|
{ key: exports.V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
|
|
9963
10156
|
]);
|
|
@@ -10058,9 +10251,11 @@ class WalletService extends Base {
|
|
|
10058
10251
|
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
10059
10252
|
// Get signature message
|
|
10060
10253
|
const signatureMessage = await this.authService.getSignature({
|
|
10061
|
-
publicKey: deviceAuthPublicKey,
|
|
10062
|
-
|
|
10063
|
-
|
|
10254
|
+
deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
|
|
10255
|
+
walletId,
|
|
10256
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
10257
|
+
});
|
|
10258
|
+
const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
10064
10259
|
// Prepare encrypted data (seed phrase or key shares)
|
|
10065
10260
|
const sharesEncryptedWithWallabyPubKey = [];
|
|
10066
10261
|
let readyForTransportSeedPhrase = undefined;
|
|
@@ -10080,7 +10275,7 @@ class WalletService extends Base {
|
|
|
10080
10275
|
readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
10081
10276
|
storedEncryptedData: parsedSeedPhrase,
|
|
10082
10277
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
10083
|
-
wallabyPublicKey
|
|
10278
|
+
wallabyPublicKey,
|
|
10084
10279
|
options: {
|
|
10085
10280
|
authType: this.deviceAuthType,
|
|
10086
10281
|
password,
|
|
@@ -10095,7 +10290,7 @@ class WalletService extends Base {
|
|
|
10095
10290
|
const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
|
|
10096
10291
|
storedEncryptedData: parsedPrimaryShare,
|
|
10097
10292
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
10098
|
-
wallabyPublicKey
|
|
10293
|
+
wallabyPublicKey,
|
|
10099
10294
|
options: {
|
|
10100
10295
|
authType: this.deviceAuthType,
|
|
10101
10296
|
password,
|
|
@@ -10264,6 +10459,7 @@ class WalletService extends Base {
|
|
|
10264
10459
|
seedPhrase: decryptedSeedPhrase,
|
|
10265
10460
|
storeSeedPhrase: false,
|
|
10266
10461
|
returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
|
|
10462
|
+
walletId: input.walletId,
|
|
10267
10463
|
keyShareOptions: {
|
|
10268
10464
|
threshold: 2,
|
|
10269
10465
|
numberOfKeyShares: 3,
|
|
@@ -10314,20 +10510,31 @@ class WalletService extends Base {
|
|
|
10314
10510
|
logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
|
|
10315
10511
|
}
|
|
10316
10512
|
if (!decryptedSeedPhrase && decryptedPrimaryShare) {
|
|
10513
|
+
const deviceAuthKeys = {
|
|
10514
|
+
publicKey: clientPublicKey,
|
|
10515
|
+
privateKey: decryptedClientAuthPrivKey,
|
|
10516
|
+
};
|
|
10517
|
+
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
10518
|
+
deviceAuthKeys,
|
|
10519
|
+
walletId: input.walletId,
|
|
10520
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
10521
|
+
});
|
|
10317
10522
|
const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
|
|
10318
10523
|
data: decryptedPrimaryShare,
|
|
10319
|
-
encryptionKey: authentication.user.wallabyAuthPubKey,
|
|
10524
|
+
encryptionKey: ephemeralWallabyAuthPubKey || authentication.user.wallabyAuthPubKey,
|
|
10320
10525
|
});
|
|
10321
|
-
const
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10526
|
+
const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
|
|
10527
|
+
payload: {
|
|
10528
|
+
walletId: input.walletId,
|
|
10529
|
+
signature,
|
|
10530
|
+
message,
|
|
10531
|
+
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
10532
|
+
recoveryPubKey: deviceAuthKeys.publicKey,
|
|
10533
|
+
encryptedShares: [flippedEncryptedPrimaryShare],
|
|
10327
10534
|
},
|
|
10328
10535
|
});
|
|
10329
10536
|
decryptedSeedPhrase = await this.cipher.decrypt({
|
|
10330
|
-
cipherText:
|
|
10537
|
+
cipherText: retrieveSeedPhraseResponse.encryptedSeed,
|
|
10331
10538
|
decryptionKey: decryptedClientAuthPrivKey,
|
|
10332
10539
|
});
|
|
10333
10540
|
}
|
|
@@ -10434,7 +10641,7 @@ class WalletDataService extends Base {
|
|
|
10434
10641
|
* Note: Either chainName or tokenStandard must be provided.
|
|
10435
10642
|
* @returns { FetchBalanceData } Returns an array of the requested tokens balances.
|
|
10436
10643
|
*/
|
|
10437
|
-
async getMultiTokenBalances({ walletId, tokensAndAddressesList }) {
|
|
10644
|
+
async getMultiTokenBalances({ walletId, tokensAndAddressesList, }) {
|
|
10438
10645
|
try {
|
|
10439
10646
|
if (!tokensAndAddressesList.length) {
|
|
10440
10647
|
throw new WallabyError({
|
|
@@ -11191,9 +11398,11 @@ class Swap extends Base {
|
|
|
11191
11398
|
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
11192
11399
|
// Get signature message
|
|
11193
11400
|
const signatureMessage = await this.authService.getSignature({
|
|
11194
|
-
publicKey: deviceAuthPublicKey,
|
|
11195
|
-
|
|
11196
|
-
|
|
11401
|
+
deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
|
|
11402
|
+
passkeyChallengeType: this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined,
|
|
11403
|
+
walletId,
|
|
11404
|
+
});
|
|
11405
|
+
const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
11197
11406
|
// Prepare encrypted data (seed phrase or key shares)
|
|
11198
11407
|
const sharesEncryptedWithWallabyPubKey = [];
|
|
11199
11408
|
let readyForTransportSeedPhrase = undefined;
|
|
@@ -11214,7 +11423,7 @@ class Swap extends Base {
|
|
|
11214
11423
|
readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
11215
11424
|
storedEncryptedData: parsedSeedPhrase,
|
|
11216
11425
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11217
|
-
wallabyPublicKey
|
|
11426
|
+
wallabyPublicKey,
|
|
11218
11427
|
options: {
|
|
11219
11428
|
authType: this.deviceAuthType,
|
|
11220
11429
|
password,
|
|
@@ -11229,7 +11438,7 @@ class Swap extends Base {
|
|
|
11229
11438
|
const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
|
|
11230
11439
|
storedEncryptedData: parsedPrimaryShare,
|
|
11231
11440
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11232
|
-
wallabyPublicKey
|
|
11441
|
+
wallabyPublicKey,
|
|
11233
11442
|
options: {
|
|
11234
11443
|
authType: this.deviceAuthType,
|
|
11235
11444
|
password,
|
|
@@ -11484,7 +11693,7 @@ class Transactions extends Base {
|
|
|
11484
11693
|
* @param {BlockchainName} blockchain
|
|
11485
11694
|
* @returns {FeeEstimateRequest}
|
|
11486
11695
|
*/
|
|
11487
|
-
async estimateFee({ originAddress, recipientAddress, amount,
|
|
11696
|
+
async estimateFee({ originAddress, recipientAddress, amount, transactionType, token, }) {
|
|
11488
11697
|
try {
|
|
11489
11698
|
const response = await this.request(TransactionsRoutes.estimateFee, {
|
|
11490
11699
|
queryParams: {
|
|
@@ -11827,9 +12036,11 @@ class Transactions extends Base {
|
|
|
11827
12036
|
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
11828
12037
|
// Get signature message
|
|
11829
12038
|
const signatureMessage = await this.authService.getSignature({
|
|
11830
|
-
publicKey: deviceAuthPublicKey,
|
|
11831
|
-
|
|
11832
|
-
|
|
12039
|
+
deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
|
|
12040
|
+
walletId,
|
|
12041
|
+
passkeyChallengeType: this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined,
|
|
12042
|
+
});
|
|
12043
|
+
const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
11833
12044
|
// Prepare encrypted data (seed phrase or key shares)
|
|
11834
12045
|
const sharesEncryptedWithWallabyPubKey = [];
|
|
11835
12046
|
let readyForTransportSeedPhrase = undefined;
|
|
@@ -11850,7 +12061,7 @@ class Transactions extends Base {
|
|
|
11850
12061
|
readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
11851
12062
|
storedEncryptedData: parsedSeedPhrase,
|
|
11852
12063
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11853
|
-
wallabyPublicKey
|
|
12064
|
+
wallabyPublicKey,
|
|
11854
12065
|
options: {
|
|
11855
12066
|
authType: this.deviceAuthType,
|
|
11856
12067
|
password,
|
|
@@ -11865,7 +12076,7 @@ class Transactions extends Base {
|
|
|
11865
12076
|
const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
|
|
11866
12077
|
storedEncryptedData: parsedPrimaryShare,
|
|
11867
12078
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11868
|
-
wallabyPublicKey
|
|
12079
|
+
wallabyPublicKey,
|
|
11869
12080
|
options: {
|
|
11870
12081
|
authType: this.deviceAuthType,
|
|
11871
12082
|
password,
|
|
@@ -11954,6 +12165,7 @@ exports.InvalidUserIdError = InvalidUserIdError;
|
|
|
11954
12165
|
exports.InvalidUserIdLengthError = InvalidUserIdLengthError;
|
|
11955
12166
|
exports.MalformedPubKeyCredParamsError = MalformedPubKeyCredParamsError;
|
|
11956
12167
|
exports.NativeError = NativeError;
|
|
12168
|
+
exports.NetworkDiagnostic = NetworkDiagnostic;
|
|
11957
12169
|
exports.NoCredentialsError = NoCredentialsError;
|
|
11958
12170
|
exports.NotAllowedError = NotAllowedError;
|
|
11959
12171
|
exports.PasskeyErrorCodes = PasskeyErrorCodes;
|