wallaby-cash 2.3.7 → 2.3.8
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/generated/api.d.ts +55 -84
- package/dist/index.cjs.js +242 -216
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +242 -216
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +242 -216
- package/dist/index.js.map +1 -1
- package/dist/lib/auth/auth.model.d.ts +108 -0
- package/dist/lib/auth/auth.service.d.ts +3 -2
- package/dist/lib/swap/index.d.ts +2 -2
- package/dist/lib/transactions/index.d.ts +3 -2
- package/dist/lib/transactions/transactions.model.d.ts +22 -0
- package/dist/lib/utils/storage.service.d.ts +12 -0
- package/dist/lib/wallet/wallet-data.service.d.ts +1 -1
- package/dist/lib/wallet/wallet-handlers.service.d.ts +16 -1
- package/dist/lib/wallet/wallet.service.d.ts +1 -6
- package/dist/package.json +2 -1
- package/dist/types/auth.d.ts +7 -9
- package/dist/types/storage.d.ts +1 -0
- package/dist/types/swap.d.ts +9 -4
- package/dist/types/transactions.d.ts +4 -7
- package/dist/types/wallet.d.ts +3 -3
- package/package.json +2 -1
- package/dist/helpers/omit.d.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as algosdk from 'algosdk';
|
|
2
2
|
import * as bip39 from 'bip39';
|
|
3
|
-
import { v4 } from 'uuid';
|
|
4
3
|
import log from 'loglevel';
|
|
5
4
|
import { AES, enc } from 'crypto-js';
|
|
6
5
|
import { jwtDecode } from 'jwt-decode';
|
|
7
6
|
import * as NativeWebAuthn from 'react-native-passkey';
|
|
7
|
+
import { omit } from 'lodash';
|
|
8
8
|
import { atob, toUint8Array } from 'js-base64';
|
|
9
|
+
import { v4 } from 'uuid';
|
|
9
10
|
|
|
10
11
|
/******************************************************************************
|
|
11
12
|
Copyright (c) Microsoft Corporation.
|
|
@@ -265,6 +266,7 @@ var LocalStorageItems;
|
|
|
265
266
|
LocalStorageItems["EncryptedAlgorandSeedPhrase"] = "encrypted-algorand-seedPhrase";
|
|
266
267
|
LocalStorageItems["EncryptedDevicePrivateKey"] = "encrypted-private-key";
|
|
267
268
|
LocalStorageItems["ClientAuthPublicKey"] = "client-auth-pub-key";
|
|
269
|
+
LocalStorageItems["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
|
|
268
270
|
LocalStorageItems["ClientAuthToken"] = "republic-jwt";
|
|
269
271
|
LocalStorageItems["PasskeyCredential"] = "pass-key-credential";
|
|
270
272
|
LocalStorageItems["Blob"] = "blob";
|
|
@@ -575,7 +577,7 @@ const env = {
|
|
|
575
577
|
isNative: false,
|
|
576
578
|
isWeb,
|
|
577
579
|
};
|
|
578
|
-
const currentPackageVersion = "2.3.
|
|
580
|
+
const currentPackageVersion = "2.3.8" ;
|
|
579
581
|
|
|
580
582
|
/**
|
|
581
583
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -4907,6 +4909,43 @@ class StorageService {
|
|
|
4907
4909
|
}
|
|
4908
4910
|
throw new Error(`Unsupported seed phrase type: ${seedPhraseType}`);
|
|
4909
4911
|
}
|
|
4912
|
+
/**
|
|
4913
|
+
*
|
|
4914
|
+
* Stores Wallaby auth public key to local storage
|
|
4915
|
+
* @param wallabyAuthPubKey
|
|
4916
|
+
*/
|
|
4917
|
+
async setWallabyAuthPubKey(wallabyAuthPubKey) {
|
|
4918
|
+
await this.save(V2KeyNames.WallabyAuthPubKey, wallabyAuthPubKey);
|
|
4919
|
+
}
|
|
4920
|
+
/**
|
|
4921
|
+
*
|
|
4922
|
+
* Fetches Wallaby auth public key from local storage
|
|
4923
|
+
* @returns { string | undefined } Wallaby Auth Public key or undefined.
|
|
4924
|
+
*/
|
|
4925
|
+
async getWallabyAuthPubKey() {
|
|
4926
|
+
let wallabyAuthPubKey = await this.fetch(V2KeyNames.WallabyAuthPubKey);
|
|
4927
|
+
if (wallabyAuthPubKey) {
|
|
4928
|
+
return wallabyAuthPubKey;
|
|
4929
|
+
}
|
|
4930
|
+
// Legacy key migration
|
|
4931
|
+
const legacyKey = `wallabyAuthPubKey_${this.userId}`;
|
|
4932
|
+
const legacyPubKey = await this.getItem(legacyKey);
|
|
4933
|
+
if (legacyPubKey) {
|
|
4934
|
+
wallabyAuthPubKey = legacyPubKey;
|
|
4935
|
+
}
|
|
4936
|
+
else {
|
|
4937
|
+
const v1Key = `${this.environment}-wallaby-auth-public-key-${this.userId}`;
|
|
4938
|
+
const v1PubKey = await this.getItem(v1Key);
|
|
4939
|
+
if (v1PubKey) {
|
|
4940
|
+
wallabyAuthPubKey = v1PubKey;
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4943
|
+
if (wallabyAuthPubKey) {
|
|
4944
|
+
await this.setWallabyAuthPubKey(wallabyAuthPubKey);
|
|
4945
|
+
return wallabyAuthPubKey;
|
|
4946
|
+
}
|
|
4947
|
+
return undefined;
|
|
4948
|
+
}
|
|
4910
4949
|
/**
|
|
4911
4950
|
* @deprecated This function is only used in tests, and should not be used anywhere else.
|
|
4912
4951
|
* Encrypts and stores device auth private key
|
|
@@ -5115,15 +5154,7 @@ class StorageService {
|
|
|
5115
5154
|
return undefined;
|
|
5116
5155
|
}
|
|
5117
5156
|
async clearLocalStorage(walletId) {
|
|
5118
|
-
const userKeysToRemove = [
|
|
5119
|
-
LocalStorageItems.AccessToken,
|
|
5120
|
-
V2KeyNames.EncryptedDevicePrivateKey,
|
|
5121
|
-
V2KeyNames.WallabyAuthPubKey,
|
|
5122
|
-
V2KeyNames.PasskeyCredential,
|
|
5123
|
-
V2KeyNames.MigrationVersion,
|
|
5124
|
-
V2KeyNames.LastMigratedAt,
|
|
5125
|
-
V2KeyNames.ClientAuthToken,
|
|
5126
|
-
];
|
|
5157
|
+
const userKeysToRemove = [LocalStorageItems.AccessToken, V2KeyNames.EncryptedDevicePrivateKey, V2KeyNames.WallabyAuthPubKey];
|
|
5127
5158
|
await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
|
|
5128
5159
|
if (walletId) {
|
|
5129
5160
|
await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
|
|
@@ -6289,16 +6320,6 @@ class Api {
|
|
|
6289
6320
|
* @secure
|
|
6290
6321
|
*/
|
|
6291
6322
|
getEstimateFee: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/estimate-fee`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6292
|
-
/**
|
|
6293
|
-
* @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
|
|
6294
|
-
*
|
|
6295
|
-
* @tags Transactions, Raw, Transactions
|
|
6296
|
-
* @name SignAndBroadcastRawTx
|
|
6297
|
-
* @summary Sign and broadcast raw transaction API
|
|
6298
|
-
* @request POST:/api/v1/transactions/sign-broadcast-rawtx
|
|
6299
|
-
* @secure
|
|
6300
|
-
*/
|
|
6301
|
-
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)),
|
|
6302
6323
|
/**
|
|
6303
6324
|
* No description
|
|
6304
6325
|
*
|
|
@@ -6309,6 +6330,16 @@ class Api {
|
|
|
6309
6330
|
* @secure
|
|
6310
6331
|
*/
|
|
6311
6332
|
fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6333
|
+
/**
|
|
6334
|
+
* @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
|
|
6335
|
+
*
|
|
6336
|
+
* @tags Transactions, Raw, Transactions
|
|
6337
|
+
* @name SignAndBroadcastRawTx
|
|
6338
|
+
* @summary Sign and broadcast raw transaction API
|
|
6339
|
+
* @request POST:/api/v1/transactions/sign-broadcast-rawtx
|
|
6340
|
+
* @secure
|
|
6341
|
+
*/
|
|
6342
|
+
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)),
|
|
6312
6343
|
/**
|
|
6313
6344
|
* No description
|
|
6314
6345
|
*
|
|
@@ -7346,13 +7377,6 @@ const SwapRoutes = {
|
|
|
7346
7377
|
},
|
|
7347
7378
|
};
|
|
7348
7379
|
|
|
7349
|
-
function omit(obj, keys) {
|
|
7350
|
-
if (!obj)
|
|
7351
|
-
return {};
|
|
7352
|
-
const keysSet = new Set(keys);
|
|
7353
|
-
return Object.fromEntries(Object.entries(obj).filter(([k]) => !keysSet.has(k)));
|
|
7354
|
-
}
|
|
7355
|
-
|
|
7356
7380
|
/**
|
|
7357
7381
|
* React Native Authenticator Implementation
|
|
7358
7382
|
*
|
|
@@ -7596,7 +7620,7 @@ let PasskeyService$1 = class PasskeyService {
|
|
|
7596
7620
|
this.authenticator = new Authenticator();
|
|
7597
7621
|
}
|
|
7598
7622
|
preparePasskeyRequestOptions(options) {
|
|
7599
|
-
var _a, _b, _c, _d, _e, _f
|
|
7623
|
+
var _a, _b, _c, _d, _e, _f;
|
|
7600
7624
|
const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
|
|
7601
7625
|
? decodeBase64URL(options.extensions.prf.eval.base64)
|
|
7602
7626
|
: ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
|
|
@@ -7604,13 +7628,11 @@ let PasskeyService$1 = class PasskeyService {
|
|
|
7604
7628
|
: typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
|
|
7605
7629
|
? new Uint8Array(Object.values(options.extensions.prf.eval.first))
|
|
7606
7630
|
: undefined;
|
|
7607
|
-
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf:
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
}
|
|
7613
|
-
: ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
|
|
7631
|
+
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
|
|
7632
|
+
eval: {
|
|
7633
|
+
first: prfExtensionEvaluation,
|
|
7634
|
+
},
|
|
7635
|
+
} }) });
|
|
7614
7636
|
logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
|
|
7615
7637
|
// While the authenticator still works with the prf and would return the response (if any),
|
|
7616
7638
|
// the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
|
|
@@ -7618,7 +7640,7 @@ let PasskeyService$1 = class PasskeyService {
|
|
|
7618
7640
|
return parsedOptions;
|
|
7619
7641
|
}
|
|
7620
7642
|
preparePasskeyCreationOptions(options) {
|
|
7621
|
-
var _a, _b, _c, _d, _e, _f
|
|
7643
|
+
var _a, _b, _c, _d, _e, _f;
|
|
7622
7644
|
const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
|
|
7623
7645
|
? decodeBase64URL(options.extensions.prf.eval.base64)
|
|
7624
7646
|
: ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
|
|
@@ -7626,8 +7648,12 @@ let PasskeyService$1 = class PasskeyService {
|
|
|
7626
7648
|
: typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
|
|
7627
7649
|
? new Uint8Array(Object.values(options.extensions.prf.eval.first))
|
|
7628
7650
|
: undefined;
|
|
7629
|
-
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf:
|
|
7630
|
-
|
|
7651
|
+
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
|
|
7652
|
+
eval: {
|
|
7653
|
+
first: prfExtensionEvaluation,
|
|
7654
|
+
},
|
|
7655
|
+
} }) });
|
|
7656
|
+
logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
|
|
7631
7657
|
return parsedOptions;
|
|
7632
7658
|
}
|
|
7633
7659
|
/**
|
|
@@ -7642,10 +7668,7 @@ let PasskeyService$1 = class PasskeyService {
|
|
|
7642
7668
|
let passkeyCredential;
|
|
7643
7669
|
let signInResponse;
|
|
7644
7670
|
try {
|
|
7645
|
-
const registrationChallengeResponse = await getSignature(
|
|
7646
|
-
deviceAuthKeys: deviceKeyPair,
|
|
7647
|
-
passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
|
|
7648
|
-
});
|
|
7671
|
+
const registrationChallengeResponse = await getSignature(deviceKeyPair, PasskeyChallengeType.REGISTRATION);
|
|
7649
7672
|
if (!registrationChallengeResponse.registrationOptions)
|
|
7650
7673
|
throw new WallabyError({
|
|
7651
7674
|
message: 'Passkey challenge could not be retrieved, please try again later.',
|
|
@@ -7688,10 +7711,7 @@ let PasskeyService$1 = class PasskeyService {
|
|
|
7688
7711
|
catch (error) {
|
|
7689
7712
|
logger.error('SDK::PasskeyService::addNewPasskey::error', error);
|
|
7690
7713
|
if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
|
|
7691
|
-
const authenticationChallengeResponse = await getSignature(
|
|
7692
|
-
deviceAuthKeys: deviceKeyPair,
|
|
7693
|
-
passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
|
|
7694
|
-
});
|
|
7714
|
+
const authenticationChallengeResponse = await getSignature(deviceKeyPair, PasskeyChallengeType.AUTHENTICATION);
|
|
7695
7715
|
if (!authenticationChallengeResponse.authenticationOptions)
|
|
7696
7716
|
throw new WallabyError({
|
|
7697
7717
|
message: 'Passkey challenge could not be retrieved, please try again later.',
|
|
@@ -7762,10 +7782,9 @@ let PasskeyService$1 = class PasskeyService {
|
|
|
7762
7782
|
errorCode: ErrorResponseCodes.sdk_passkey_challenge_unavailable,
|
|
7763
7783
|
});
|
|
7764
7784
|
const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
|
|
7765
|
-
const
|
|
7766
|
-
const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
|
|
7785
|
+
const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, 'credProps')), { prf: {
|
|
7767
7786
|
eval: {
|
|
7768
|
-
first:
|
|
7787
|
+
first: (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first,
|
|
7769
7788
|
},
|
|
7770
7789
|
} }) });
|
|
7771
7790
|
const passkeyCredential = await this.authenticator.authenticate({
|
|
@@ -7992,6 +8011,10 @@ let PasskeyService$1 = class PasskeyService {
|
|
|
7992
8011
|
key: LocalStorageItems.AccessToken,
|
|
7993
8012
|
value: authenticationResponse.accessToken,
|
|
7994
8013
|
},
|
|
8014
|
+
{
|
|
8015
|
+
key: LocalStorageItems.WallabyAuthPubKey,
|
|
8016
|
+
value: authenticationResponse.user.wallabyAuthPubKey,
|
|
8017
|
+
},
|
|
7995
8018
|
]);
|
|
7996
8019
|
}
|
|
7997
8020
|
/**
|
|
@@ -8211,14 +8234,13 @@ class AuthService extends Base {
|
|
|
8211
8234
|
* @param { PasskeyChallengeType } passkeyChallengeType the type of passkey challenge to request, either for registration or authentication.
|
|
8212
8235
|
* @returns the messaged, the hash, and the signature using the passed private key.
|
|
8213
8236
|
*/
|
|
8214
|
-
async getSignature(
|
|
8237
|
+
async getSignature(deviceAuthKeys, passkeyChallengeType) {
|
|
8215
8238
|
try {
|
|
8216
8239
|
logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
|
|
8217
8240
|
const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : PasskeyChallengeType.REGISTRATION;
|
|
8218
8241
|
logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
|
|
8219
8242
|
const response = await this.request(AuthRoutes.signatureMessage, {
|
|
8220
8243
|
payload: {
|
|
8221
|
-
walletId,
|
|
8222
8244
|
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
8223
8245
|
passkeyChallengeType: challengeType,
|
|
8224
8246
|
},
|
|
@@ -8249,10 +8271,7 @@ class AuthService extends Base {
|
|
|
8249
8271
|
logger.info('key pair generated', !!deviceKeyPair);
|
|
8250
8272
|
let authentication;
|
|
8251
8273
|
try {
|
|
8252
|
-
const signatureMessageResponse = await this.getSignature(
|
|
8253
|
-
deviceAuthKeys: deviceKeyPair,
|
|
8254
|
-
passkeyChallengeType: PasskeyChallengeType.REGISTRATION,
|
|
8255
|
-
});
|
|
8274
|
+
const signatureMessageResponse = await this.getSignature(deviceKeyPair, PasskeyChallengeType.REGISTRATION);
|
|
8256
8275
|
logger.info('signature has been generated', !!signatureMessageResponse);
|
|
8257
8276
|
switch (this.deviceAuthType) {
|
|
8258
8277
|
case AuthType.Passkey:
|
|
@@ -8285,10 +8304,7 @@ class AuthService extends Base {
|
|
|
8285
8304
|
// TODO Add passkey errors to the WallabyError ErrorResponseCodes
|
|
8286
8305
|
if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
|
|
8287
8306
|
logger.info('SDK::AuthService::signUp::handling previously registered passkey error');
|
|
8288
|
-
const newChallenge = await this.getSignature(
|
|
8289
|
-
deviceAuthKeys: deviceKeyPair,
|
|
8290
|
-
passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
|
|
8291
|
-
});
|
|
8307
|
+
const newChallenge = await this.getSignature(deviceKeyPair, PasskeyChallengeType.AUTHENTICATION);
|
|
8292
8308
|
authentication = await this.passkeyService.authenticate({
|
|
8293
8309
|
deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
|
|
8294
8310
|
challengeResponse: newChallenge,
|
|
@@ -8325,7 +8341,10 @@ class AuthService extends Base {
|
|
|
8325
8341
|
errorCode: ErrorResponseCodes.sdk_invalid_parameter,
|
|
8326
8342
|
});
|
|
8327
8343
|
}
|
|
8328
|
-
await this.localStorageService.
|
|
8344
|
+
await this.localStorageService.saveInBulk([
|
|
8345
|
+
{ key: LocalStorageItems.AccessToken, value: authentication.accessToken },
|
|
8346
|
+
{ key: LocalStorageItems.WallabyAuthPubKey, value: authentication.user.wallabyAuthPubKey },
|
|
8347
|
+
]);
|
|
8329
8348
|
return Object.freeze(Object.assign(Object.assign({}, authentication), input));
|
|
8330
8349
|
}
|
|
8331
8350
|
catch (error) {
|
|
@@ -8401,9 +8420,7 @@ class AuthService extends Base {
|
|
|
8401
8420
|
},
|
|
8402
8421
|
credentialsKeyPair,
|
|
8403
8422
|
});
|
|
8404
|
-
const signatureMessage = await this.getSignature({
|
|
8405
|
-
deviceAuthKeys: { publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey },
|
|
8406
|
-
});
|
|
8423
|
+
const signatureMessage = await this.getSignature({ publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey });
|
|
8407
8424
|
const authentication = await this.request(AuthRoutes.signIn, {
|
|
8408
8425
|
payload: {
|
|
8409
8426
|
externalUserId: this.userId,
|
|
@@ -8527,6 +8544,10 @@ class AuthService extends Base {
|
|
|
8527
8544
|
key: LocalStorageItems.AccessToken,
|
|
8528
8545
|
value: authResponse.accessToken,
|
|
8529
8546
|
},
|
|
8547
|
+
{
|
|
8548
|
+
key: LocalStorageItems.WallabyAuthPubKey,
|
|
8549
|
+
value: authResponse.user.wallabyAuthPubKey,
|
|
8550
|
+
},
|
|
8530
8551
|
]);
|
|
8531
8552
|
return authResponse;
|
|
8532
8553
|
});
|
|
@@ -8611,16 +8632,12 @@ class WalletHandlersService extends Base {
|
|
|
8611
8632
|
this.userId = config.userId;
|
|
8612
8633
|
}
|
|
8613
8634
|
async handleImportWallet(deviceAuthKeys, importWalletInput) {
|
|
8614
|
-
var _a, _b, _c, _d
|
|
8635
|
+
var _a, _b, _c, _d;
|
|
8615
8636
|
try {
|
|
8616
|
-
|
|
8617
|
-
|
|
8618
|
-
|
|
8619
|
-
|
|
8620
|
-
walletId: (_a = importWalletInput.walletId) !== null && _a !== void 0 ? _a : importWalletInput.reference,
|
|
8621
|
-
deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
|
|
8622
|
-
passkeyChallengeType: this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined,
|
|
8623
|
-
});
|
|
8637
|
+
const { signature, message } = await this.authService.getSignature({
|
|
8638
|
+
publicKey: deviceAuthKeys.publicKey,
|
|
8639
|
+
privateKey: deviceAuthKeys.privateKey,
|
|
8640
|
+
}, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
|
|
8624
8641
|
if ((importWalletInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
|
|
8625
8642
|
importWalletInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
|
|
8626
8643
|
!importWalletInput.keyShareOptions) {
|
|
@@ -8630,7 +8647,7 @@ class WalletHandlersService extends Base {
|
|
|
8630
8647
|
errorCode: ErrorResponseCodes.sdk_missing_parameter,
|
|
8631
8648
|
});
|
|
8632
8649
|
}
|
|
8633
|
-
const { numberOfKeyShares, threshold } = (
|
|
8650
|
+
const { numberOfKeyShares, threshold } = (_a = importWalletInput.keyShareOptions) !== null && _a !== void 0 ? _a : {};
|
|
8634
8651
|
if (threshold && numberOfKeyShares && numberOfKeyShares < threshold) {
|
|
8635
8652
|
throw new WallabyError({
|
|
8636
8653
|
message: 'Number of shares must be greater than or equal to the threshold',
|
|
@@ -8640,11 +8657,10 @@ class WalletHandlersService extends Base {
|
|
|
8640
8657
|
}
|
|
8641
8658
|
const readyForTransportSeedPhrase = await this.cipher.encrypt({
|
|
8642
8659
|
data: importWalletInput.seedPhrase,
|
|
8643
|
-
encryptionKey: wallabyAuthPubKey,
|
|
8660
|
+
encryptionKey: importWalletInput.authenticationOptions.user.wallabyAuthPubKey,
|
|
8644
8661
|
});
|
|
8645
8662
|
const importWalletPayload = {
|
|
8646
|
-
reference:
|
|
8647
|
-
walletId: importWalletInput.walletId,
|
|
8663
|
+
reference: v4(),
|
|
8648
8664
|
message,
|
|
8649
8665
|
signature,
|
|
8650
8666
|
encryptedSeed: readyForTransportSeedPhrase,
|
|
@@ -8653,7 +8669,7 @@ class WalletHandlersService extends Base {
|
|
|
8653
8669
|
numShares: numberOfKeyShares !== null && numberOfKeyShares !== void 0 ? numberOfKeyShares : 0,
|
|
8654
8670
|
threshold: threshold !== null && threshold !== void 0 ? threshold : 0,
|
|
8655
8671
|
walletOwnershipType: WalletOwnershipType.SingleOwner,
|
|
8656
|
-
wallabyKeepsOne: (
|
|
8672
|
+
wallabyKeepsOne: (_c = (_b = importWalletInput.keyShareOptions) === null || _b === void 0 ? void 0 : _b.storeOneKeyShareWithWallaby) !== null && _c !== void 0 ? _c : false,
|
|
8657
8673
|
};
|
|
8658
8674
|
const importWalletRequest = await this.request(WalletRoutes.importSeedPhraseV2, {
|
|
8659
8675
|
payload: importWalletPayload,
|
|
@@ -8691,7 +8707,7 @@ class WalletHandlersService extends Base {
|
|
|
8691
8707
|
}
|
|
8692
8708
|
catch (error) {
|
|
8693
8709
|
throw new WallabyError({
|
|
8694
|
-
message: (
|
|
8710
|
+
message: (_d = error.message) !== null && _d !== void 0 ? _d : 'Failed to handle importing the wallet',
|
|
8695
8711
|
statusCode: error.statusCode,
|
|
8696
8712
|
errorCode: error.errorCode,
|
|
8697
8713
|
data: error.data,
|
|
@@ -8713,9 +8729,9 @@ class WalletHandlersService extends Base {
|
|
|
8713
8729
|
var _a, _b, _c, _d, _e, _f;
|
|
8714
8730
|
try {
|
|
8715
8731
|
const { signature, message, hashedMessage } = await this.authService.getSignature({
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
});
|
|
8732
|
+
publicKey: deviceAuthKeys.publicKey,
|
|
8733
|
+
privateKey: deviceAuthKeys.privateKey,
|
|
8734
|
+
}, PasskeyChallengeType.AUTHENTICATION);
|
|
8719
8735
|
if ((walletCreationInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
|
|
8720
8736
|
walletCreationInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
|
|
8721
8737
|
!walletCreationInput.keyShareOptions) {
|
|
@@ -8892,6 +8908,36 @@ class WalletHandlersService extends Base {
|
|
|
8892
8908
|
});
|
|
8893
8909
|
}
|
|
8894
8910
|
}
|
|
8911
|
+
/**
|
|
8912
|
+
*
|
|
8913
|
+
* @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
|
|
8914
|
+
* @param walletId - The ID of the wallet for which the seed phrase is being constructed.
|
|
8915
|
+
* @param deviceAuthKeys - The device authentication key pair used to sign the request.
|
|
8916
|
+
* @description This function constructs the seed phrase from encrypted key shares.
|
|
8917
|
+
* It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
|
|
8918
|
+
* The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
|
|
8919
|
+
* @returns The function returns the encrypted seed phrase wrapped with client device public key.
|
|
8920
|
+
*/
|
|
8921
|
+
async handleConstructingSeedPhraseFromShares({ encryptedKeyShares, walletId, deviceAuthKeys, }) {
|
|
8922
|
+
try {
|
|
8923
|
+
const { signature, message } = await this.authService.getSignature(deviceAuthKeys, PasskeyChallengeType.AUTHENTICATION);
|
|
8924
|
+
const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
|
|
8925
|
+
payload: {
|
|
8926
|
+
walletId: walletId,
|
|
8927
|
+
signature,
|
|
8928
|
+
message,
|
|
8929
|
+
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
8930
|
+
recoveryPubKey: deviceAuthKeys.publicKey,
|
|
8931
|
+
encryptedShares: encryptedKeyShares,
|
|
8932
|
+
},
|
|
8933
|
+
});
|
|
8934
|
+
return retrieveSeedPhraseResponse.encryptedSeed;
|
|
8935
|
+
}
|
|
8936
|
+
catch (error) {
|
|
8937
|
+
logger.error('SDK::handleConstructingSeedPhraseFromShares::error', error);
|
|
8938
|
+
return Promise.reject(error);
|
|
8939
|
+
}
|
|
8940
|
+
}
|
|
8895
8941
|
}
|
|
8896
8942
|
|
|
8897
8943
|
class WalletService extends Base {
|
|
@@ -9001,6 +9047,7 @@ class WalletService extends Base {
|
|
|
9001
9047
|
*/
|
|
9002
9048
|
async export({ walletId, authenticationOptions, exportOptions }) {
|
|
9003
9049
|
try {
|
|
9050
|
+
const { user: { wallabyAuthPubKey }, } = authenticationOptions;
|
|
9004
9051
|
if (!exportOptions.algorandSeedPhrase && !exportOptions.standardSeedPhrase && !exportOptions.keyShares) {
|
|
9005
9052
|
throw new WallabyError({
|
|
9006
9053
|
message: 'exportOptions must be provided with at least one of the following options: algorandSeedPhrase, standardSeedPhrase, keyShares',
|
|
@@ -9110,20 +9157,10 @@ class WalletService extends Base {
|
|
|
9110
9157
|
});
|
|
9111
9158
|
}
|
|
9112
9159
|
const parsedPrimaryShare = safeJsonParse(encryptedPrimaryDeviceShare);
|
|
9113
|
-
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9114
|
-
const deviceAuthKeys = {
|
|
9115
|
-
publicKey: deviceAuthPublicKey,
|
|
9116
|
-
privateKey: decryptedDevicePrivateKey,
|
|
9117
|
-
};
|
|
9118
|
-
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
9119
|
-
deviceAuthKeys,
|
|
9120
|
-
walletId,
|
|
9121
|
-
passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
|
|
9122
|
-
});
|
|
9123
9160
|
const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
|
|
9124
9161
|
storedEncryptedData: parsedPrimaryShare,
|
|
9125
9162
|
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9126
|
-
wallabyPublicKey:
|
|
9163
|
+
wallabyPublicKey: wallabyAuthPubKey,
|
|
9127
9164
|
options: {
|
|
9128
9165
|
authType: this.deviceAuthType,
|
|
9129
9166
|
password: authenticationOptions.password,
|
|
@@ -9131,18 +9168,17 @@ class WalletService extends Base {
|
|
|
9131
9168
|
prfValue: authenticationOptions.prfValue,
|
|
9132
9169
|
},
|
|
9133
9170
|
});
|
|
9134
|
-
const
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9141
|
-
encryptedShares: [wallabyBoundPrimaryShare],
|
|
9171
|
+
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9172
|
+
const encryptedReconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
|
|
9173
|
+
encryptedKeyShares: [wallabyBoundPrimaryShare],
|
|
9174
|
+
walletId,
|
|
9175
|
+
deviceAuthKeys: {
|
|
9176
|
+
publicKey: deviceAuthPublicKey,
|
|
9177
|
+
privateKey: decryptedDevicePrivateKey,
|
|
9142
9178
|
},
|
|
9143
9179
|
});
|
|
9144
9180
|
decryptedSeedPhrase = await this.cipher.decrypt({
|
|
9145
|
-
cipherText:
|
|
9181
|
+
cipherText: encryptedReconstructedSeedPhrase,
|
|
9146
9182
|
decryptionKey: decryptedDevicePrivateKey,
|
|
9147
9183
|
});
|
|
9148
9184
|
if (exportOptions.algorandSeedPhrase) {
|
|
@@ -9180,9 +9216,7 @@ class WalletService extends Base {
|
|
|
9180
9216
|
* @returns {ImportWalletResponse} The wallet has been created successfully.
|
|
9181
9217
|
*/
|
|
9182
9218
|
async import(input) {
|
|
9183
|
-
var _a;
|
|
9184
9219
|
try {
|
|
9185
|
-
const requestReference = (_a = input.reference) !== null && _a !== void 0 ? _a : v4();
|
|
9186
9220
|
const encryptedDevicePrivateKey = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
|
|
9187
9221
|
if (!encryptedDevicePrivateKey) {
|
|
9188
9222
|
throw new WallabyError({
|
|
@@ -9213,7 +9247,7 @@ class WalletService extends Base {
|
|
|
9213
9247
|
const importRequest = await this.handlers.handleImportWallet({
|
|
9214
9248
|
publicKey: clientAuthPubKey,
|
|
9215
9249
|
privateKey: decryptedDevicePrivateKey,
|
|
9216
|
-
},
|
|
9250
|
+
}, input);
|
|
9217
9251
|
return importRequest;
|
|
9218
9252
|
}
|
|
9219
9253
|
catch (error) {
|
|
@@ -9227,15 +9261,11 @@ class WalletService extends Base {
|
|
|
9227
9261
|
*
|
|
9228
9262
|
* @param { RecoverWalletRequest } input - The request object containing the necessary parameters.
|
|
9229
9263
|
* @returns { Promise<RecoverWalletResponse> } The response containing the recovered wallet details.
|
|
9230
|
-
*
|
|
9231
|
-
* @deprecated This function is deprecated and will be removed in the next major release. It only supports seed phrase recovery.
|
|
9232
|
-
* Use `import` instead with the `RETURN_ONLY_ENCRYPTED_SEED_PHRASE` option to maintain the same behavior.
|
|
9233
9264
|
*/
|
|
9234
9265
|
async recover(input) {
|
|
9235
9266
|
var _a, _b;
|
|
9236
9267
|
try {
|
|
9237
|
-
const wallabyPublicKey = input.authenticationOptions.
|
|
9238
|
-
input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9268
|
+
const wallabyPublicKey = input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9239
9269
|
const deviceAuthKeyPair = createIdentity();
|
|
9240
9270
|
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9241
9271
|
authType: this.deviceAuthType,
|
|
@@ -9275,37 +9305,27 @@ class WalletService extends Base {
|
|
|
9275
9305
|
return recoverWithSeedPhraseResponse;
|
|
9276
9306
|
}
|
|
9277
9307
|
else if (input.decryptedShares) {
|
|
9278
|
-
|
|
9308
|
+
const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
|
|
9309
|
+
const encrypted = await this.cipher.encrypt({
|
|
9310
|
+
data: decryptedShare,
|
|
9311
|
+
encryptionKey: wallabyPublicKey,
|
|
9312
|
+
});
|
|
9313
|
+
return encrypted;
|
|
9314
|
+
}));
|
|
9315
|
+
if (!encryptedShares.length) {
|
|
9279
9316
|
throw new WallabyError({
|
|
9280
9317
|
message: 'Decrypted shares are required',
|
|
9281
9318
|
statusCode: 400,
|
|
9282
9319
|
errorCode: ErrorResponseCodes.sdk_missing_parameter,
|
|
9283
9320
|
});
|
|
9284
9321
|
}
|
|
9285
|
-
const
|
|
9322
|
+
const encryptedSeed = await this.handlers.handleConstructingSeedPhraseFromShares({
|
|
9323
|
+
encryptedKeyShares: encryptedShares,
|
|
9286
9324
|
deviceAuthKeys: deviceAuthKeyPair,
|
|
9287
9325
|
walletId: input.walletId,
|
|
9288
|
-
passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
|
|
9289
|
-
});
|
|
9290
|
-
const transportEncryptionKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9291
|
-
const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
|
|
9292
|
-
return await this.cipher.encrypt({
|
|
9293
|
-
data: decryptedShare,
|
|
9294
|
-
encryptionKey: transportEncryptionKey,
|
|
9295
|
-
});
|
|
9296
|
-
}));
|
|
9297
|
-
const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
|
|
9298
|
-
payload: {
|
|
9299
|
-
walletId: input.walletId,
|
|
9300
|
-
signature,
|
|
9301
|
-
message,
|
|
9302
|
-
clientAuthPubKey: deviceAuthKeyPair.publicKey,
|
|
9303
|
-
recoveryPubKey: deviceAuthKeyPair.publicKey,
|
|
9304
|
-
encryptedShares,
|
|
9305
|
-
},
|
|
9306
9326
|
});
|
|
9307
9327
|
const wallabyBoundRecoverySeedPhrase = await this.cipher.flipEncryptedData({
|
|
9308
|
-
cipherText:
|
|
9328
|
+
cipherText: encryptedSeed,
|
|
9309
9329
|
decryptionKey: deviceAuthKeyPair.privateKey,
|
|
9310
9330
|
encryptionKey: wallabyPublicKey,
|
|
9311
9331
|
});
|
|
@@ -9363,9 +9383,17 @@ class WalletService extends Base {
|
|
|
9363
9383
|
async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
|
|
9364
9384
|
try {
|
|
9365
9385
|
const signatureMessage = await this.authService.getSignature({
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
});
|
|
9386
|
+
publicKey: deviceAuthKeys.publicKey,
|
|
9387
|
+
privateKey: deviceAuthKeys.privateKey,
|
|
9388
|
+
});
|
|
9389
|
+
// const response = await this.request<RetrieveSharesData>(WalletRoutes.retrieveShares, {
|
|
9390
|
+
// payload: {
|
|
9391
|
+
// walletId,
|
|
9392
|
+
// signature: signatureMessage.signature,
|
|
9393
|
+
// message: signatureMessage.message,
|
|
9394
|
+
// clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
9395
|
+
// },
|
|
9396
|
+
// });
|
|
9369
9397
|
const response = await this.api.wallets.retrieveShares({
|
|
9370
9398
|
walletId: walletId,
|
|
9371
9399
|
signature: signatureMessage.signature,
|
|
@@ -9546,7 +9574,6 @@ class WalletService extends Base {
|
|
|
9546
9574
|
*/
|
|
9547
9575
|
async initAddNewDevice(input) {
|
|
9548
9576
|
const { walletId, backupUrl, authenticationOptions } = input;
|
|
9549
|
-
const wallabyPublicKey = authenticationOptions.signatureMessageResponse.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
9550
9577
|
const encryptedDevicePrivateKey = await this.localStorageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey);
|
|
9551
9578
|
if (!encryptedDevicePrivateKey) {
|
|
9552
9579
|
throw new WallabyError({
|
|
@@ -9607,7 +9634,7 @@ class WalletService extends Base {
|
|
|
9607
9634
|
const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
|
|
9608
9635
|
storedEncryptedData: parsedPrimaryShare,
|
|
9609
9636
|
encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
|
|
9610
|
-
wallabyPublicKey,
|
|
9637
|
+
wallabyPublicKey: authenticationOptions.user.wallabyAuthPubKey,
|
|
9611
9638
|
options: {
|
|
9612
9639
|
authType: this.deviceAuthType,
|
|
9613
9640
|
password: authenticationOptions.password,
|
|
@@ -9666,11 +9693,22 @@ class WalletService extends Base {
|
|
|
9666
9693
|
}
|
|
9667
9694
|
const devicePublicKey = (_a = (await this.localStorageService.fetch(LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9668
9695
|
const signatureMessage = await this.authService.getSignature({
|
|
9669
|
-
|
|
9670
|
-
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9696
|
+
publicKey: devicePublicKey,
|
|
9697
|
+
privateKey: decryptedDevicePrivateKey,
|
|
9698
|
+
}, PasskeyChallengeType.REGISTRATION);
|
|
9699
|
+
// const backUpResponse: AddNewDeviceResponse = await this.request(WalletRoutes.addNewDevice, {
|
|
9700
|
+
// payload: {
|
|
9701
|
+
// walletId: input.walletId,
|
|
9702
|
+
// message: signatureMessage.message,
|
|
9703
|
+
// signature: signatureMessage.signature,
|
|
9704
|
+
// clientAuthPubKey: devicePublicKey,
|
|
9705
|
+
// share: {
|
|
9706
|
+
// encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
|
|
9707
|
+
// wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
|
|
9708
|
+
// type: KeyTypeName.OwnerBackupDeviceShare,
|
|
9709
|
+
// },
|
|
9710
|
+
// },
|
|
9711
|
+
// });
|
|
9674
9712
|
const backUpResponse = await this.api.wallets.addNewDevice({
|
|
9675
9713
|
walletId: input.walletId,
|
|
9676
9714
|
message: signatureMessage.message,
|
|
@@ -9678,7 +9716,7 @@ class WalletService extends Base {
|
|
|
9678
9716
|
clientAuthPubKey: devicePublicKey,
|
|
9679
9717
|
share: {
|
|
9680
9718
|
encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
|
|
9681
|
-
wrappingPublicKey:
|
|
9719
|
+
wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
|
|
9682
9720
|
type: KeyTypeName.OwnerBackupDeviceShare,
|
|
9683
9721
|
},
|
|
9684
9722
|
});
|
|
@@ -9686,8 +9724,7 @@ class WalletService extends Base {
|
|
|
9686
9724
|
backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
|
|
9687
9725
|
{
|
|
9688
9726
|
encrypted: input.encryptedShares[DEFAULT_PRIMARY_SHARE_INDEX],
|
|
9689
|
-
wrappingPublicKey: input.authenticationOptions.
|
|
9690
|
-
input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
|
|
9727
|
+
wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
|
|
9691
9728
|
type: KeyTypeName.OwnerMainDeviceShare,
|
|
9692
9729
|
},
|
|
9693
9730
|
];
|
|
@@ -9744,28 +9781,12 @@ class WalletService extends Base {
|
|
|
9744
9781
|
});
|
|
9745
9782
|
}
|
|
9746
9783
|
const parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
|
|
9747
|
-
const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9748
|
-
authType: this.deviceAuthType,
|
|
9749
|
-
password: input.authenticationOptions.password,
|
|
9750
|
-
salt: input.authenticationOptions.clientSalt,
|
|
9751
|
-
prfValue: input.authenticationOptions.prfValue,
|
|
9752
|
-
});
|
|
9753
|
-
const decryptedDevicePrivateKey = await this.cipher.decrypt({
|
|
9754
|
-
cipherText: parsedDevicePrivateKey,
|
|
9755
|
-
decryptionKey: derivedCredentialsKeyPair.privateKey,
|
|
9756
|
-
});
|
|
9757
|
-
const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9758
|
-
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
9759
|
-
deviceAuthKeys: { privateKey: decryptedDevicePrivateKey, publicKey: devicePublicKey },
|
|
9760
|
-
walletId,
|
|
9761
|
-
});
|
|
9762
|
-
const wallabyPublicKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9763
9784
|
if (storedSeedPhrase) {
|
|
9764
9785
|
const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
|
|
9765
9786
|
transportSeed = await this.cipher.prepareStoredDataForTransport({
|
|
9766
9787
|
storedEncryptedData: parsedStoredSeedPhrase,
|
|
9767
9788
|
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9768
|
-
wallabyPublicKey,
|
|
9789
|
+
wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
|
|
9769
9790
|
options: {
|
|
9770
9791
|
authType: this.deviceAuthType,
|
|
9771
9792
|
password: input.authenticationOptions.password,
|
|
@@ -9779,7 +9800,7 @@ class WalletService extends Base {
|
|
|
9779
9800
|
transportKeyShare = await this.cipher.prepareStoredDataForTransport({
|
|
9780
9801
|
storedEncryptedData: parsedPrimaryKeyShare,
|
|
9781
9802
|
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9782
|
-
wallabyPublicKey,
|
|
9803
|
+
wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
|
|
9783
9804
|
options: {
|
|
9784
9805
|
authType: this.deviceAuthType,
|
|
9785
9806
|
password: input.authenticationOptions.password,
|
|
@@ -9795,6 +9816,21 @@ class WalletService extends Base {
|
|
|
9795
9816
|
errorCode: 'sdk_private_key_not_found',
|
|
9796
9817
|
});
|
|
9797
9818
|
}
|
|
9819
|
+
const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9820
|
+
authType: this.deviceAuthType,
|
|
9821
|
+
password: input.authenticationOptions.password,
|
|
9822
|
+
salt: input.authenticationOptions.clientSalt,
|
|
9823
|
+
prfValue: input.authenticationOptions.prfValue,
|
|
9824
|
+
});
|
|
9825
|
+
const decryptedDevicePrivateKey = await this.cipher.decrypt({
|
|
9826
|
+
cipherText: parsedDevicePrivateKey,
|
|
9827
|
+
decryptionKey: derivedCredentialsKeyPair.privateKey,
|
|
9828
|
+
});
|
|
9829
|
+
const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9830
|
+
const { signature, message } = await this.authService.getSignature({
|
|
9831
|
+
privateKey: decryptedDevicePrivateKey,
|
|
9832
|
+
publicKey: devicePublicKey,
|
|
9833
|
+
});
|
|
9798
9834
|
const response = await this.request(WalletRoutes.generateWalletAddresses, {
|
|
9799
9835
|
payload: {
|
|
9800
9836
|
walletId,
|
|
@@ -9986,8 +10022,8 @@ class WalletService extends Base {
|
|
|
9986
10022
|
// During migration, we need to authenticate but avoid creating conflicting device keypairs
|
|
9987
10023
|
const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
|
|
9988
10024
|
const signInSignatureMessage = await this.authService.getSignature({
|
|
9989
|
-
|
|
9990
|
-
|
|
10025
|
+
publicKey: devicePublicKey,
|
|
10026
|
+
privateKey: decryptedPrivateKey,
|
|
9991
10027
|
});
|
|
9992
10028
|
// this would ensure the stored public key is consistent with wallaby and can authenticate the user.
|
|
9993
10029
|
const authResponse = await this.request(AuthRoutes.signIn, {
|
|
@@ -10013,6 +10049,7 @@ class WalletService extends Base {
|
|
|
10013
10049
|
// Store authentication tokens
|
|
10014
10050
|
await this.localStorageService.saveInBulk([
|
|
10015
10051
|
{ key: LocalStorageItems.AccessToken, value: authResponse.accessToken },
|
|
10052
|
+
{ key: LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
|
|
10016
10053
|
{ key: V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
|
|
10017
10054
|
{ key: V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
|
|
10018
10055
|
]);
|
|
@@ -10075,8 +10112,8 @@ class WalletService extends Base {
|
|
|
10075
10112
|
throw error;
|
|
10076
10113
|
}
|
|
10077
10114
|
}
|
|
10078
|
-
async clearDevice(
|
|
10079
|
-
await this.localStorageService.clearLocalStorage(
|
|
10115
|
+
async clearDevice() {
|
|
10116
|
+
await this.localStorageService.clearLocalStorage();
|
|
10080
10117
|
}
|
|
10081
10118
|
/**
|
|
10082
10119
|
* Prepares authentication data and encrypted payload for any request.
|
|
@@ -10113,11 +10150,9 @@ class WalletService extends Base {
|
|
|
10113
10150
|
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
10114
10151
|
// Get signature message
|
|
10115
10152
|
const signatureMessage = await this.authService.getSignature({
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
});
|
|
10120
|
-
const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
10153
|
+
publicKey: deviceAuthPublicKey,
|
|
10154
|
+
privateKey: decryptedDevicePrivateKey,
|
|
10155
|
+
}, PasskeyChallengeType.AUTHENTICATION);
|
|
10121
10156
|
// Prepare encrypted data (seed phrase or key shares)
|
|
10122
10157
|
const sharesEncryptedWithWallabyPubKey = [];
|
|
10123
10158
|
let readyForTransportSeedPhrase = undefined;
|
|
@@ -10137,7 +10172,7 @@ class WalletService extends Base {
|
|
|
10137
10172
|
readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
10138
10173
|
storedEncryptedData: parsedSeedPhrase,
|
|
10139
10174
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
10140
|
-
wallabyPublicKey,
|
|
10175
|
+
wallabyPublicKey: user.wallabyAuthPubKey,
|
|
10141
10176
|
options: {
|
|
10142
10177
|
authType: this.deviceAuthType,
|
|
10143
10178
|
password,
|
|
@@ -10152,7 +10187,7 @@ class WalletService extends Base {
|
|
|
10152
10187
|
const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
|
|
10153
10188
|
storedEncryptedData: parsedPrimaryShare,
|
|
10154
10189
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
10155
|
-
wallabyPublicKey,
|
|
10190
|
+
wallabyPublicKey: user.wallabyAuthPubKey,
|
|
10156
10191
|
options: {
|
|
10157
10192
|
authType: this.deviceAuthType,
|
|
10158
10193
|
password,
|
|
@@ -10321,7 +10356,6 @@ class WalletService extends Base {
|
|
|
10321
10356
|
seedPhrase: decryptedSeedPhrase,
|
|
10322
10357
|
storeSeedPhrase: false,
|
|
10323
10358
|
returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
|
|
10324
|
-
walletId: input.walletId,
|
|
10325
10359
|
keyShareOptions: {
|
|
10326
10360
|
threshold: 2,
|
|
10327
10361
|
numberOfKeyShares: 3,
|
|
@@ -10372,31 +10406,20 @@ class WalletService extends Base {
|
|
|
10372
10406
|
logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
|
|
10373
10407
|
}
|
|
10374
10408
|
if (!decryptedSeedPhrase && decryptedPrimaryShare) {
|
|
10375
|
-
const deviceAuthKeys = {
|
|
10376
|
-
publicKey: clientPublicKey,
|
|
10377
|
-
privateKey: decryptedClientAuthPrivKey,
|
|
10378
|
-
};
|
|
10379
|
-
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
10380
|
-
deviceAuthKeys,
|
|
10381
|
-
walletId: input.walletId,
|
|
10382
|
-
passkeyChallengeType: PasskeyChallengeType.AUTHENTICATION,
|
|
10383
|
-
});
|
|
10384
10409
|
const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
|
|
10385
10410
|
data: decryptedPrimaryShare,
|
|
10386
|
-
encryptionKey:
|
|
10411
|
+
encryptionKey: authentication.user.wallabyAuthPubKey,
|
|
10387
10412
|
});
|
|
10388
|
-
const
|
|
10389
|
-
|
|
10390
|
-
|
|
10391
|
-
|
|
10392
|
-
|
|
10393
|
-
|
|
10394
|
-
recoveryPubKey: deviceAuthKeys.publicKey,
|
|
10395
|
-
encryptedShares: [flippedEncryptedPrimaryShare],
|
|
10413
|
+
const reconstructedSeedPhrase = await this.handlers.handleConstructingSeedPhraseFromShares({
|
|
10414
|
+
walletId: input.walletId,
|
|
10415
|
+
encryptedKeyShares: [flippedEncryptedPrimaryShare],
|
|
10416
|
+
deviceAuthKeys: {
|
|
10417
|
+
publicKey: clientPublicKey,
|
|
10418
|
+
privateKey: decryptedClientAuthPrivKey,
|
|
10396
10419
|
},
|
|
10397
10420
|
});
|
|
10398
10421
|
decryptedSeedPhrase = await this.cipher.decrypt({
|
|
10399
|
-
cipherText:
|
|
10422
|
+
cipherText: reconstructedSeedPhrase,
|
|
10400
10423
|
decryptionKey: decryptedClientAuthPrivKey,
|
|
10401
10424
|
});
|
|
10402
10425
|
}
|
|
@@ -10503,7 +10526,7 @@ class WalletDataService extends Base {
|
|
|
10503
10526
|
* Note: Either chainName or tokenStandard must be provided.
|
|
10504
10527
|
* @returns { FetchBalanceData } Returns an array of the requested tokens balances.
|
|
10505
10528
|
*/
|
|
10506
|
-
async getMultiTokenBalances({ walletId, tokensAndAddressesList
|
|
10529
|
+
async getMultiTokenBalances({ walletId, tokensAndAddressesList }) {
|
|
10507
10530
|
try {
|
|
10508
10531
|
if (!tokensAndAddressesList.length) {
|
|
10509
10532
|
throw new WallabyError({
|
|
@@ -11091,17 +11114,18 @@ class Swap extends Base {
|
|
|
11091
11114
|
this.walletService = new WalletService(config);
|
|
11092
11115
|
}
|
|
11093
11116
|
/**
|
|
11094
|
-
* Gets a swap quote between two assets
|
|
11117
|
+
* Gets a swap quote between two assets, including fees, min output, and slippage limits.
|
|
11095
11118
|
*
|
|
11096
11119
|
* @public
|
|
11097
11120
|
* @param {SwapQuoteRequest} request - The swap quote request parameters
|
|
11098
11121
|
* @returns {Promise<SwapQuoteResponse>} A promise that resolves with the swap quote
|
|
11099
11122
|
*/
|
|
11100
|
-
async getQuote(
|
|
11123
|
+
async getQuote(request) {
|
|
11101
11124
|
try {
|
|
11102
|
-
|
|
11125
|
+
const { walletId, fromAssetConfigId, toAssetConfigId, fromAmount, toAmount, slippage } = request;
|
|
11126
|
+
if (!walletId || !fromAssetConfigId || !toAssetConfigId) {
|
|
11103
11127
|
throw new WallabyError({
|
|
11104
|
-
message: 'Missing required parameters: walletId,
|
|
11128
|
+
message: 'Missing required parameters: walletId, fromAssetConfigId, and toAssetConfigId',
|
|
11105
11129
|
statusCode: 400,
|
|
11106
11130
|
errorCode: ErrorResponseCodes.sdk_missing_parameter,
|
|
11107
11131
|
});
|
|
@@ -11113,10 +11137,16 @@ class Swap extends Base {
|
|
|
11113
11137
|
errorCode: ErrorResponseCodes.sdk_missing_parameter,
|
|
11114
11138
|
});
|
|
11115
11139
|
}
|
|
11116
|
-
|
|
11140
|
+
if (fromAmount && toAmount) {
|
|
11141
|
+
throw new WallabyError({
|
|
11142
|
+
message: 'Only one of fromAmount or toAmount may be provided, not both',
|
|
11143
|
+
statusCode: 400,
|
|
11144
|
+
errorCode: ErrorResponseCodes.sdk_invalid_parameter,
|
|
11145
|
+
});
|
|
11146
|
+
}
|
|
11117
11147
|
const routePayload = { walletId };
|
|
11118
|
-
const requestBody = Object.assign(Object.assign({
|
|
11119
|
-
|
|
11148
|
+
const requestBody = Object.assign(Object.assign(Object.assign({ fromAssetConfigId,
|
|
11149
|
+
toAssetConfigId }, (fromAmount && { fromAmount })), (toAmount && { toAmount })), (slippage != null && { slippage }));
|
|
11120
11150
|
const response = await this.request(Object.assign(Object.assign({}, SwapRoutes.getQuote), { fullPath: SwapRoutes.getQuote.fullPath(routePayload) }), {
|
|
11121
11151
|
payload: requestBody,
|
|
11122
11152
|
});
|
|
@@ -11260,11 +11290,9 @@ class Swap extends Base {
|
|
|
11260
11290
|
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
11261
11291
|
// Get signature message
|
|
11262
11292
|
const signatureMessage = await this.authService.getSignature({
|
|
11263
|
-
|
|
11264
|
-
|
|
11265
|
-
|
|
11266
|
-
});
|
|
11267
|
-
const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
11293
|
+
publicKey: deviceAuthPublicKey,
|
|
11294
|
+
privateKey: decryptedDevicePrivateKey,
|
|
11295
|
+
}, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
|
|
11268
11296
|
// Prepare encrypted data (seed phrase or key shares)
|
|
11269
11297
|
const sharesEncryptedWithWallabyPubKey = [];
|
|
11270
11298
|
let readyForTransportSeedPhrase = undefined;
|
|
@@ -11285,7 +11313,7 @@ class Swap extends Base {
|
|
|
11285
11313
|
readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
11286
11314
|
storedEncryptedData: parsedSeedPhrase,
|
|
11287
11315
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11288
|
-
wallabyPublicKey,
|
|
11316
|
+
wallabyPublicKey: user.wallabyAuthPubKey,
|
|
11289
11317
|
options: {
|
|
11290
11318
|
authType: this.deviceAuthType,
|
|
11291
11319
|
password,
|
|
@@ -11300,7 +11328,7 @@ class Swap extends Base {
|
|
|
11300
11328
|
const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
|
|
11301
11329
|
storedEncryptedData: parsedPrimaryShare,
|
|
11302
11330
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11303
|
-
wallabyPublicKey,
|
|
11331
|
+
wallabyPublicKey: user.wallabyAuthPubKey,
|
|
11304
11332
|
options: {
|
|
11305
11333
|
authType: this.deviceAuthType,
|
|
11306
11334
|
password,
|
|
@@ -11555,7 +11583,7 @@ class Transactions extends Base {
|
|
|
11555
11583
|
* @param {BlockchainName} blockchain
|
|
11556
11584
|
* @returns {FeeEstimateRequest}
|
|
11557
11585
|
*/
|
|
11558
|
-
async estimateFee({ originAddress, recipientAddress, amount,
|
|
11586
|
+
async estimateFee({ originAddress, recipientAddress, amount, token, transactionType, }) {
|
|
11559
11587
|
try {
|
|
11560
11588
|
const response = await this.request(TransactionsRoutes.estimateFee, {
|
|
11561
11589
|
queryParams: {
|
|
@@ -11898,11 +11926,9 @@ class Transactions extends Base {
|
|
|
11898
11926
|
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
11899
11927
|
// Get signature message
|
|
11900
11928
|
const signatureMessage = await this.authService.getSignature({
|
|
11901
|
-
|
|
11902
|
-
|
|
11903
|
-
|
|
11904
|
-
});
|
|
11905
|
-
const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
11929
|
+
publicKey: deviceAuthPublicKey,
|
|
11930
|
+
privateKey: decryptedDevicePrivateKey,
|
|
11931
|
+
}, this.deviceAuthType === AuthType.Passkey ? PasskeyChallengeType.AUTHENTICATION : undefined);
|
|
11906
11932
|
// Prepare encrypted data (seed phrase or key shares)
|
|
11907
11933
|
const sharesEncryptedWithWallabyPubKey = [];
|
|
11908
11934
|
let readyForTransportSeedPhrase = undefined;
|
|
@@ -11923,7 +11949,7 @@ class Transactions extends Base {
|
|
|
11923
11949
|
readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
11924
11950
|
storedEncryptedData: parsedSeedPhrase,
|
|
11925
11951
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11926
|
-
wallabyPublicKey,
|
|
11952
|
+
wallabyPublicKey: user.wallabyAuthPubKey,
|
|
11927
11953
|
options: {
|
|
11928
11954
|
authType: this.deviceAuthType,
|
|
11929
11955
|
password,
|
|
@@ -11938,7 +11964,7 @@ class Transactions extends Base {
|
|
|
11938
11964
|
const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
|
|
11939
11965
|
storedEncryptedData: parsedPrimaryShare,
|
|
11940
11966
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11941
|
-
wallabyPublicKey,
|
|
11967
|
+
wallabyPublicKey: user.wallabyAuthPubKey,
|
|
11942
11968
|
options: {
|
|
11943
11969
|
authType: this.deviceAuthType,
|
|
11944
11970
|
password,
|