wallaby-cash 2.3.7 → 3.0.1-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/generated/api.d.ts +1 -56
- package/dist/index.cjs.js +97 -242
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +97 -242
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +97 -242
- package/dist/index.js.map +1 -1
- package/dist/lib/swap/index.d.ts +2 -2
- package/dist/lib/wallet/wallet-data.service.d.ts +1 -1
- package/dist/lib/wallet/wallet-handlers.service.d.ts +7 -6
- package/dist/lib/wallet/wallet.service.d.ts +1 -17
- package/dist/package.json +2 -1
- package/dist/routes/wallet.d.ts +0 -5
- package/dist/types/swap.d.ts +9 -4
- package/dist/types/wallet.d.ts +18 -11
- package/package.json +2 -1
package/dist/generated/api.d.ts
CHANGED
|
@@ -124,18 +124,8 @@ export type AddNewDeviceData = AddNewDeviceResponseDto;
|
|
|
124
124
|
export interface AddNewDeviceRequestDto {
|
|
125
125
|
/** @example "e3421d7f9d6888ea83bef6b28ce0a2ab6eb6fe8a8fbfa3743240992590816b08f9a62edcc63296d056c552054d583fec36d23ef11dffb24c95aaf4a47d50dccc" */
|
|
126
126
|
clientAuthPubKey: string;
|
|
127
|
-
/**
|
|
128
|
-
* Message retrieved from the backend
|
|
129
|
-
* @example "717ea458b62a430cb37ced7c22ebec97"
|
|
130
|
-
*/
|
|
131
|
-
message: string;
|
|
132
127
|
/** Backup share encrypted by the Wallaby pub key */
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Signature generated after signing the provided data field
|
|
136
|
-
* @example "0xb44e88ff3c67de6e6548a6caf006bf6e1cb841119d0b9ea1b7e9b2d36a5e0ed42fd9f5e543243d1d73dc4b7800cc2026f74961f4edc769699678a316abb34e661c"
|
|
137
|
-
*/
|
|
138
|
-
signature: string;
|
|
128
|
+
encryptedBackupShare: SymmetricEncrypted | AsymmetricEncryptedDto;
|
|
139
129
|
/**
|
|
140
130
|
* The ID of the wallet to add a new device to
|
|
141
131
|
* @format uuid
|
|
@@ -4036,23 +4026,6 @@ export interface ResolvePendingTransactionResponseDto {
|
|
|
4036
4026
|
*/
|
|
4037
4027
|
status: "confirmed" | "denied";
|
|
4038
4028
|
}
|
|
4039
|
-
export type RetrieveSharesData = WalletSharesRetrievedDto;
|
|
4040
|
-
export interface RetrieveWalletShareRequestDto {
|
|
4041
|
-
/** @example "e3421d7f9d6888ea83bef6b28ce0a2ab6eb6fe8a8fbfa3743240992590816b08f9a62edcc63296d056c552054d583fec36d23ef11dffb24c95aaf4a47d50dccc" */
|
|
4042
|
-
clientAuthPubKey: string;
|
|
4043
|
-
/**
|
|
4044
|
-
* Message retrieved from the backend
|
|
4045
|
-
* @example "717ea458b62a430cb37ced7c22ebec97"
|
|
4046
|
-
*/
|
|
4047
|
-
message: string;
|
|
4048
|
-
/**
|
|
4049
|
-
* Signature generated after signing the provided data field
|
|
4050
|
-
* @example "0xb44e88ff3c67de6e6548a6caf006bf6e1cb841119d0b9ea1b7e9b2d36a5e0ed42fd9f5e543243d1d73dc4b7800cc2026f74961f4edc769699678a316abb34e661c"
|
|
4051
|
-
*/
|
|
4052
|
-
signature: string;
|
|
4053
|
-
/** The wallet ID to retrieve shares from */
|
|
4054
|
-
walletId: string;
|
|
4055
|
-
}
|
|
4056
4029
|
export type RevokeMerchantAdminsData = GetMerchantUsersResponseDto;
|
|
4057
4030
|
export interface RevokeMerchantAdminsParams {
|
|
4058
4031
|
/**
|
|
@@ -7319,24 +7292,6 @@ export declare namespace Wallets {
|
|
|
7319
7292
|
};
|
|
7320
7293
|
type ResponseBody = ImportWalletSeedPhraseV2Data;
|
|
7321
7294
|
}
|
|
7322
|
-
/**
|
|
7323
|
-
* No description
|
|
7324
|
-
* @tags Wallets, MPC
|
|
7325
|
-
* @name RetrieveShares
|
|
7326
|
-
* @summary Retrieve shares which belong to the user on a specified wallet
|
|
7327
|
-
* @request POST:/api/v1/wallets/retrieve-shares
|
|
7328
|
-
* @secure
|
|
7329
|
-
*/
|
|
7330
|
-
namespace RetrieveShares {
|
|
7331
|
-
type RequestParams = {};
|
|
7332
|
-
type RequestQuery = {};
|
|
7333
|
-
type RequestBody = RetrieveWalletShareRequestDto;
|
|
7334
|
-
type RequestHeaders = {
|
|
7335
|
-
/** A unique identifier for the request, used for tracing and debugging */
|
|
7336
|
-
"x-client-request-id"?: string;
|
|
7337
|
-
};
|
|
7338
|
-
type ResponseBody = RetrieveSharesData;
|
|
7339
|
-
}
|
|
7340
7295
|
/**
|
|
7341
7296
|
* No description
|
|
7342
7297
|
* @tags Wallets, MPC
|
|
@@ -10045,16 +10000,6 @@ export declare class Api<SecurityDataType extends unknown> {
|
|
|
10045
10000
|
* @secure
|
|
10046
10001
|
*/
|
|
10047
10002
|
importWalletSeedPhraseV2: (data: ImportSeedPhraseV2RequestDto, params?: RequestParams) => Promise<WalletCreatedDto>;
|
|
10048
|
-
/**
|
|
10049
|
-
* No description
|
|
10050
|
-
*
|
|
10051
|
-
* @tags Wallets, MPC
|
|
10052
|
-
* @name RetrieveShares
|
|
10053
|
-
* @summary Retrieve shares which belong to the user on a specified wallet
|
|
10054
|
-
* @request POST:/api/v1/wallets/retrieve-shares
|
|
10055
|
-
* @secure
|
|
10056
|
-
*/
|
|
10057
|
-
retrieveShares: (data: RetrieveWalletShareRequestDto, params?: RequestParams) => Promise<WalletSharesRetrievedDto>;
|
|
10058
10003
|
/**
|
|
10059
10004
|
* No description
|
|
10060
10005
|
*
|
package/dist/index.cjs.js
CHANGED
|
@@ -579,8 +579,6 @@ const defaultNetwork = 'testnet';
|
|
|
579
579
|
const isTest = browser$1.env.NODE_ENV === 'test';
|
|
580
580
|
const DEFAULT_ENTROPY_BYTES$1 = 32;
|
|
581
581
|
const PBKDF2_ITERATIONS = 131072;
|
|
582
|
-
const DEFAULT_PRIMARY_SHARE_INDEX = 0;
|
|
583
|
-
const DEFAULT_BACKUP_SHARE_INDEX = 1;
|
|
584
582
|
const DEFAULT_HOSTNAME = 'https://www.republic.com';
|
|
585
583
|
const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe75d907fe6db9e4c';
|
|
586
584
|
/**
|
|
@@ -599,7 +597,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
|
|
|
599
597
|
{ type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
|
|
600
598
|
];
|
|
601
599
|
const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
602
|
-
const currentPackageVersion = "
|
|
600
|
+
const currentPackageVersion = "3.0.1-alpha.0" ;
|
|
603
601
|
|
|
604
602
|
/**
|
|
605
603
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -6005,16 +6003,6 @@ class Api {
|
|
|
6005
6003
|
* @secure
|
|
6006
6004
|
*/
|
|
6007
6005
|
importWalletSeedPhraseV2: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/wallets/create-shares-based-wallet-from-seed`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
|
|
6008
|
-
/**
|
|
6009
|
-
* No description
|
|
6010
|
-
*
|
|
6011
|
-
* @tags Wallets, MPC
|
|
6012
|
-
* @name RetrieveShares
|
|
6013
|
-
* @summary Retrieve shares which belong to the user on a specified wallet
|
|
6014
|
-
* @request POST:/api/v1/wallets/retrieve-shares
|
|
6015
|
-
* @secure
|
|
6016
|
-
*/
|
|
6017
|
-
retrieveShares: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/wallets/retrieve-shares`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
|
|
6018
6006
|
/**
|
|
6019
6007
|
* No description
|
|
6020
6008
|
*
|
|
@@ -7140,11 +7128,6 @@ const WalletRoutes = {
|
|
|
7140
7128
|
method: exports.RequestMethod.Post,
|
|
7141
7129
|
requiresAccessToken: true,
|
|
7142
7130
|
},
|
|
7143
|
-
retrieveShares: {
|
|
7144
|
-
fullPath: '/wallets/retrieve-shares',
|
|
7145
|
-
method: exports.RequestMethod.Post,
|
|
7146
|
-
requiresAccessToken: true,
|
|
7147
|
-
},
|
|
7148
7131
|
create: {
|
|
7149
7132
|
fullPath: '/wallets/create',
|
|
7150
7133
|
method: exports.RequestMethod.Post,
|
|
@@ -8586,13 +8569,12 @@ class WalletHandlersService extends Base {
|
|
|
8586
8569
|
credentialsKeyPair,
|
|
8587
8570
|
});
|
|
8588
8571
|
}
|
|
8589
|
-
|
|
8590
|
-
if (importWalletRequest.shares) {
|
|
8572
|
+
if (importWalletRequest.shares && importWalletRequest.encryptedBackupShare) {
|
|
8591
8573
|
await this.handleKeySharesFromResponse({
|
|
8592
8574
|
walletId: importWalletRequest.wallet.id,
|
|
8593
|
-
|
|
8594
|
-
devicePrivateKey: deviceAuthKeys.privateKey,
|
|
8575
|
+
shares: importWalletRequest.shares,
|
|
8595
8576
|
credentialsKeyPair,
|
|
8577
|
+
encryptedBackupShare: importWalletRequest.encryptedBackupShare,
|
|
8596
8578
|
});
|
|
8597
8579
|
}
|
|
8598
8580
|
return Object.assign({}, importWalletRequest);
|
|
@@ -8673,13 +8655,12 @@ class WalletHandlersService extends Base {
|
|
|
8673
8655
|
credentialsKeyPair,
|
|
8674
8656
|
});
|
|
8675
8657
|
}
|
|
8676
|
-
|
|
8677
|
-
if (walletCreationResponse.shares) {
|
|
8658
|
+
if (walletCreationResponse.shares && walletCreationResponse.encryptedBackupShare) {
|
|
8678
8659
|
await this.handleKeySharesFromResponse({
|
|
8679
8660
|
walletId: walletCreationResponse.wallet.id,
|
|
8680
|
-
|
|
8681
|
-
devicePrivateKey: deviceAuthKeys.privateKey,
|
|
8661
|
+
shares: walletCreationResponse.shares,
|
|
8682
8662
|
credentialsKeyPair,
|
|
8663
|
+
encryptedBackupShare: walletCreationResponse.encryptedBackupShare,
|
|
8683
8664
|
});
|
|
8684
8665
|
}
|
|
8685
8666
|
return Object.assign(Object.assign({}, walletCreationResponse), { standardSeedPhrase: decryptedSeedPhrase });
|
|
@@ -8695,44 +8676,29 @@ class WalletHandlersService extends Base {
|
|
|
8695
8676
|
});
|
|
8696
8677
|
}
|
|
8697
8678
|
}
|
|
8698
|
-
async handleKeySharesFromResponse({ walletId,
|
|
8679
|
+
async handleKeySharesFromResponse({ walletId, shares, credentialsKeyPair, encryptedBackupShare, }) {
|
|
8699
8680
|
try {
|
|
8700
|
-
const
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
|
|
8721
|
-
return keyShare;
|
|
8722
|
-
}
|
|
8723
|
-
catch (error) {
|
|
8724
|
-
logger.error('SDK::handleKeySharesFromResponse::error', error);
|
|
8725
|
-
throw new WallabyError({
|
|
8726
|
-
message: (_a = error.message) !== null && _a !== void 0 ? _a : 'Failed to handle key shares from response',
|
|
8727
|
-
statusCode: 500,
|
|
8728
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
8729
|
-
data: error,
|
|
8730
|
-
cause: error.cause,
|
|
8731
|
-
onError: () => logger.log('Reported the error'),
|
|
8732
|
-
});
|
|
8733
|
-
}
|
|
8734
|
-
}));
|
|
8735
|
-
return encryptedKeyShares;
|
|
8681
|
+
const encryptedWithCredentialsKeyShare = await this.cipher.encrypt({
|
|
8682
|
+
data: JSON.stringify(shares[0].encrypted),
|
|
8683
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
8684
|
+
});
|
|
8685
|
+
const encryptedWithCredentialsBackupShare = await this.cipher.encrypt({
|
|
8686
|
+
data: JSON.stringify(encryptedBackupShare),
|
|
8687
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
8688
|
+
});
|
|
8689
|
+
await this.localStorageService.saveInBulk([
|
|
8690
|
+
{
|
|
8691
|
+
key: exports.V2KeyNames.PrimaryDeviceKeyShare,
|
|
8692
|
+
value: encryptedWithCredentialsKeyShare,
|
|
8693
|
+
walletId,
|
|
8694
|
+
},
|
|
8695
|
+
{
|
|
8696
|
+
key: exports.V2KeyNames.BackupDeviceKeyShare,
|
|
8697
|
+
value: encryptedWithCredentialsBackupShare,
|
|
8698
|
+
walletId,
|
|
8699
|
+
},
|
|
8700
|
+
]);
|
|
8701
|
+
return [encryptedWithCredentialsKeyShare, encryptedWithCredentialsBackupShare];
|
|
8736
8702
|
}
|
|
8737
8703
|
catch (error) {
|
|
8738
8704
|
logger.error('SDK::handleKeySharesFromResponse::error', error);
|
|
@@ -9140,7 +9106,6 @@ class WalletService extends Base {
|
|
|
9140
9106
|
* Use `import` instead with the `RETURN_ONLY_ENCRYPTED_SEED_PHRASE` option to maintain the same behavior.
|
|
9141
9107
|
*/
|
|
9142
9108
|
async recover(input) {
|
|
9143
|
-
var _a, _b;
|
|
9144
9109
|
try {
|
|
9145
9110
|
const wallabyPublicKey = input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
|
|
9146
9111
|
input.authenticationOptions.user.wallabyAuthPubKey;
|
|
@@ -9168,12 +9133,12 @@ class WalletService extends Base {
|
|
|
9168
9133
|
storeSeedPhrase: true,
|
|
9169
9134
|
});
|
|
9170
9135
|
}
|
|
9171
|
-
if (
|
|
9136
|
+
if (recoverWithSeedPhraseResponse.shares && recoverWithSeedPhraseResponse.encryptedBackupShare) {
|
|
9172
9137
|
await this.handlers.handleKeySharesFromResponse({
|
|
9173
9138
|
walletId: recoverWithSeedPhraseResponse.wallet.id,
|
|
9174
|
-
|
|
9175
|
-
devicePrivateKey: deviceAuthKeyPair.privateKey,
|
|
9139
|
+
shares: recoverWithSeedPhraseResponse.shares,
|
|
9176
9140
|
credentialsKeyPair,
|
|
9141
|
+
encryptedBackupShare: recoverWithSeedPhraseResponse.encryptedBackupShare,
|
|
9177
9142
|
});
|
|
9178
9143
|
}
|
|
9179
9144
|
await this.authService.storeDeviceKeyPair({
|
|
@@ -9231,12 +9196,12 @@ class WalletService extends Base {
|
|
|
9231
9196
|
storeSeedPhrase: input.storeSeedPhrase,
|
|
9232
9197
|
});
|
|
9233
9198
|
}
|
|
9234
|
-
if (
|
|
9199
|
+
if (recoverWithSeedPhraseResponse.shares && recoverWithSeedPhraseResponse.encryptedBackupShare) {
|
|
9235
9200
|
await this.handlers.handleKeySharesFromResponse({
|
|
9236
9201
|
walletId: recoverWithSeedPhraseResponse.wallet.id,
|
|
9237
|
-
|
|
9238
|
-
devicePrivateKey: deviceAuthKeyPair.privateKey,
|
|
9202
|
+
shares: recoverWithSeedPhraseResponse.shares,
|
|
9239
9203
|
credentialsKeyPair,
|
|
9204
|
+
encryptedBackupShare: recoverWithSeedPhraseResponse.encryptedBackupShare,
|
|
9240
9205
|
});
|
|
9241
9206
|
}
|
|
9242
9207
|
await this.authService.storeDeviceKeyPair({
|
|
@@ -9258,46 +9223,6 @@ class WalletService extends Base {
|
|
|
9258
9223
|
throw error;
|
|
9259
9224
|
}
|
|
9260
9225
|
}
|
|
9261
|
-
/**
|
|
9262
|
-
* @public
|
|
9263
|
-
* Retrieves the encrypted shares for a specified wallet
|
|
9264
|
-
*
|
|
9265
|
-
* @param {string} walletId - The Wallaby wallet ID.
|
|
9266
|
-
* @param {string} [password] - The password for decrypting the shares, if required.
|
|
9267
|
-
* @param {Uint8Array} [prfValue] - The PRF value used for encryption, if applicable.
|
|
9268
|
-
*
|
|
9269
|
-
* @returns {Promise<EncryptedSharesResponse>} A promise that resolves with the encrypted shares.
|
|
9270
|
-
*/
|
|
9271
|
-
async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
|
|
9272
|
-
try {
|
|
9273
|
-
const signatureMessage = await this.authService.getSignature({
|
|
9274
|
-
deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
|
|
9275
|
-
walletId,
|
|
9276
|
-
});
|
|
9277
|
-
const response = await this.api.wallets.retrieveShares({
|
|
9278
|
-
walletId: walletId,
|
|
9279
|
-
signature: signatureMessage.signature,
|
|
9280
|
-
message: signatureMessage.message,
|
|
9281
|
-
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
9282
|
-
});
|
|
9283
|
-
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9284
|
-
authType: this.deviceAuthType,
|
|
9285
|
-
password: authenticationOptions.password,
|
|
9286
|
-
salt: authenticationOptions.user.clientSalt,
|
|
9287
|
-
prfValue: authenticationOptions.prfValue,
|
|
9288
|
-
});
|
|
9289
|
-
return await this.handlers.handleKeySharesFromResponse({
|
|
9290
|
-
walletId: walletId,
|
|
9291
|
-
keyShares: response.shares,
|
|
9292
|
-
devicePrivateKey: deviceAuthKeys.privateKey,
|
|
9293
|
-
credentialsKeyPair,
|
|
9294
|
-
});
|
|
9295
|
-
}
|
|
9296
|
-
catch (error) {
|
|
9297
|
-
logger.error('SDK::Wallet::retrieveShares::error', error);
|
|
9298
|
-
throw error;
|
|
9299
|
-
}
|
|
9300
|
-
}
|
|
9301
9226
|
/**
|
|
9302
9227
|
* @public
|
|
9303
9228
|
* Updates the wallet password.
|
|
@@ -9454,7 +9379,6 @@ class WalletService extends Base {
|
|
|
9454
9379
|
*/
|
|
9455
9380
|
async initAddNewDevice(input) {
|
|
9456
9381
|
const { walletId, backupUrl, authenticationOptions } = input;
|
|
9457
|
-
const wallabyPublicKey = authenticationOptions.signatureMessageResponse.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
9458
9382
|
const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
9459
9383
|
if (!encryptedDevicePrivateKey) {
|
|
9460
9384
|
throw new WallabyError({
|
|
@@ -9480,20 +9404,14 @@ class WalletService extends Base {
|
|
|
9480
9404
|
});
|
|
9481
9405
|
}
|
|
9482
9406
|
}
|
|
9483
|
-
const
|
|
9484
|
-
|
|
9485
|
-
});
|
|
9486
|
-
const storedEncryptedBackupShare = await this.localStorageService.fetch(exports.LocalStorageItems.BackupDeviceKeyShare, {
|
|
9487
|
-
walletId,
|
|
9488
|
-
});
|
|
9489
|
-
if (!storedEncryptedPrimaryShare || !storedEncryptedBackupShare) {
|
|
9407
|
+
const storedEncryptedBackupShare = await this.localStorageService.fetch(exports.LocalStorageItems.BackupDeviceKeyShare, { walletId });
|
|
9408
|
+
if (!storedEncryptedBackupShare) {
|
|
9490
9409
|
throw new WallabyError({
|
|
9491
9410
|
message: 'You do not have any additional key shares stored on this device, you cannot add a new device from here.',
|
|
9492
9411
|
statusCode: 404,
|
|
9493
9412
|
errorCode: exports.ErrorResponseCodes.sdk_key_shares_not_found,
|
|
9494
9413
|
});
|
|
9495
9414
|
}
|
|
9496
|
-
const parsedPrimaryShare = safeJsonParse(storedEncryptedPrimaryShare);
|
|
9497
9415
|
const parsedBackupShare = safeJsonParse(storedEncryptedBackupShare);
|
|
9498
9416
|
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9499
9417
|
authType: this.deviceAuthType,
|
|
@@ -9512,17 +9430,6 @@ class WalletService extends Base {
|
|
|
9512
9430
|
errorCode: exports.ErrorResponseCodes.sdk_private_key_decryption_failed,
|
|
9513
9431
|
});
|
|
9514
9432
|
}
|
|
9515
|
-
const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
|
|
9516
|
-
storedEncryptedData: parsedPrimaryShare,
|
|
9517
|
-
encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
|
|
9518
|
-
wallabyPublicKey,
|
|
9519
|
-
options: {
|
|
9520
|
-
authType: this.deviceAuthType,
|
|
9521
|
-
password: authenticationOptions.password,
|
|
9522
|
-
prfValue: authenticationOptions.prfValue,
|
|
9523
|
-
salt: authenticationOptions.user.clientSalt,
|
|
9524
|
-
},
|
|
9525
|
-
});
|
|
9526
9433
|
const decryptedOnceBackupShare = await this.cipher.decrypt({
|
|
9527
9434
|
cipherText: parsedBackupShare,
|
|
9528
9435
|
decryptionKey: credentialsKeyPair.privateKey,
|
|
@@ -9531,7 +9438,7 @@ class WalletService extends Base {
|
|
|
9531
9438
|
return {
|
|
9532
9439
|
walletId,
|
|
9533
9440
|
backupUrl,
|
|
9534
|
-
|
|
9441
|
+
encryptedBackupShare: wallabyBoundBackupShare,
|
|
9535
9442
|
};
|
|
9536
9443
|
}
|
|
9537
9444
|
/**
|
|
@@ -9573,38 +9480,31 @@ class WalletService extends Base {
|
|
|
9573
9480
|
});
|
|
9574
9481
|
}
|
|
9575
9482
|
const devicePublicKey = (_a = (await this.localStorageService.fetch(exports.LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9576
|
-
const
|
|
9577
|
-
deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedDevicePrivateKey },
|
|
9483
|
+
const storedEncryptedBackupShare = await this.localStorageService.fetch(exports.LocalStorageItems.BackupDeviceKeyShare, {
|
|
9578
9484
|
walletId: input.walletId,
|
|
9579
|
-
passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
|
|
9580
9485
|
});
|
|
9581
|
-
|
|
9486
|
+
if (!storedEncryptedBackupShare) {
|
|
9487
|
+
throw new WallabyError({
|
|
9488
|
+
message: 'Backup share could not be found',
|
|
9489
|
+
statusCode: 404,
|
|
9490
|
+
errorCode: exports.ErrorResponseCodes.sdk_key_shares_not_found,
|
|
9491
|
+
});
|
|
9492
|
+
}
|
|
9493
|
+
const encryptedBackupShareString = await this.cipher.decrypt({
|
|
9494
|
+
cipherText: safeJsonParse(storedEncryptedBackupShare),
|
|
9495
|
+
decryptionKey: credentialsKeyPair.privateKey,
|
|
9496
|
+
});
|
|
9497
|
+
const encryptedBackupShare = safeJsonParse(encryptedBackupShareString);
|
|
9582
9498
|
const backUpResponse = await this.api.wallets.addNewDevice({
|
|
9583
9499
|
walletId: input.walletId,
|
|
9584
|
-
message: signatureMessage.message,
|
|
9585
|
-
signature: signatureMessage.signature,
|
|
9586
9500
|
clientAuthPubKey: devicePublicKey,
|
|
9587
|
-
|
|
9588
|
-
encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
|
|
9589
|
-
wrappingPublicKey: wallabyPublicKey,
|
|
9590
|
-
type: exports.KeyTypeName.OwnerBackupDeviceShare,
|
|
9591
|
-
},
|
|
9501
|
+
encryptedBackupShare: encryptedBackupShare,
|
|
9592
9502
|
});
|
|
9593
|
-
const keyShares = [
|
|
9594
|
-
backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
|
|
9595
|
-
{
|
|
9596
|
-
encrypted: input.encryptedShares[DEFAULT_PRIMARY_SHARE_INDEX],
|
|
9597
|
-
wrappingPublicKey: input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
|
|
9598
|
-
input.authenticationOptions.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
|
|
9599
|
-
type: exports.KeyTypeName.OwnerMainDeviceShare,
|
|
9600
|
-
},
|
|
9601
|
-
];
|
|
9602
9503
|
await this.handlers.handleKeySharesFromResponse({
|
|
9603
9504
|
walletId: input.walletId,
|
|
9604
|
-
|
|
9605
|
-
keyShares: keyShares,
|
|
9606
|
-
devicePrivateKey: decryptedDevicePrivateKey,
|
|
9505
|
+
shares: [backUpResponse.share],
|
|
9607
9506
|
credentialsKeyPair,
|
|
9507
|
+
encryptedBackupShare: encryptedBackupShare,
|
|
9608
9508
|
});
|
|
9609
9509
|
return { success: true, reference: backUpResponse.reference };
|
|
9610
9510
|
}
|
|
@@ -9639,78 +9539,18 @@ class WalletService extends Base {
|
|
|
9639
9539
|
}
|
|
9640
9540
|
}
|
|
9641
9541
|
try {
|
|
9642
|
-
const
|
|
9643
|
-
const primaryKeyShare = await this.localStorageService.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare, { walletId });
|
|
9644
|
-
const devicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
9645
|
-
let transportSeed = undefined;
|
|
9646
|
-
let transportKeyShare = undefined;
|
|
9647
|
-
if (!devicePrivateKey) {
|
|
9648
|
-
throw new WallabyError({
|
|
9649
|
-
message: 'Missing device private key on this device, please recover your wallet first.',
|
|
9650
|
-
statusCode: 404,
|
|
9651
|
-
errorCode: exports.ErrorResponseCodes.sdk_private_key_not_found,
|
|
9652
|
-
});
|
|
9653
|
-
}
|
|
9654
|
-
const parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
|
|
9655
|
-
const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9656
|
-
authType: this.deviceAuthType,
|
|
9657
|
-
password: input.authenticationOptions.password,
|
|
9658
|
-
salt: input.authenticationOptions.clientSalt,
|
|
9659
|
-
prfValue: input.authenticationOptions.prfValue,
|
|
9660
|
-
});
|
|
9661
|
-
const decryptedDevicePrivateKey = await this.cipher.decrypt({
|
|
9662
|
-
cipherText: parsedDevicePrivateKey,
|
|
9663
|
-
decryptionKey: derivedCredentialsKeyPair.privateKey,
|
|
9664
|
-
});
|
|
9665
|
-
const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9666
|
-
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
9667
|
-
deviceAuthKeys: { privateKey: decryptedDevicePrivateKey, publicKey: devicePublicKey },
|
|
9542
|
+
const walletOperationAuth = await this.prepareWalletOperationAuth({
|
|
9668
9543
|
walletId,
|
|
9544
|
+
authenticationOptions: input.authenticationOptions,
|
|
9669
9545
|
});
|
|
9670
|
-
const wallabyPublicKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9671
|
-
if (storedSeedPhrase) {
|
|
9672
|
-
const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
|
|
9673
|
-
transportSeed = await this.cipher.prepareStoredDataForTransport({
|
|
9674
|
-
storedEncryptedData: parsedStoredSeedPhrase,
|
|
9675
|
-
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9676
|
-
wallabyPublicKey,
|
|
9677
|
-
options: {
|
|
9678
|
-
authType: this.deviceAuthType,
|
|
9679
|
-
password: input.authenticationOptions.password,
|
|
9680
|
-
salt: input.authenticationOptions.clientSalt,
|
|
9681
|
-
prfValue: input.authenticationOptions.prfValue,
|
|
9682
|
-
},
|
|
9683
|
-
});
|
|
9684
|
-
}
|
|
9685
|
-
else if (primaryKeyShare) {
|
|
9686
|
-
const parsedPrimaryKeyShare = safeJsonParse(primaryKeyShare);
|
|
9687
|
-
transportKeyShare = await this.cipher.prepareStoredDataForTransport({
|
|
9688
|
-
storedEncryptedData: parsedPrimaryKeyShare,
|
|
9689
|
-
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9690
|
-
wallabyPublicKey,
|
|
9691
|
-
options: {
|
|
9692
|
-
authType: this.deviceAuthType,
|
|
9693
|
-
password: input.authenticationOptions.password,
|
|
9694
|
-
salt: input.authenticationOptions.clientSalt,
|
|
9695
|
-
prfValue: input.authenticationOptions.prfValue,
|
|
9696
|
-
},
|
|
9697
|
-
});
|
|
9698
|
-
}
|
|
9699
|
-
else {
|
|
9700
|
-
throw new WallabyError({
|
|
9701
|
-
message: 'Missing stored seed phrase or primary key share on this device, please recover your wallet first.',
|
|
9702
|
-
statusCode: 404,
|
|
9703
|
-
errorCode: 'sdk_private_key_not_found',
|
|
9704
|
-
});
|
|
9705
|
-
}
|
|
9706
9546
|
const response = await this.request(WalletRoutes.generateWalletAddresses, {
|
|
9707
9547
|
payload: {
|
|
9708
9548
|
walletId,
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
encryptedSeed:
|
|
9713
|
-
encryptedShares:
|
|
9549
|
+
message: walletOperationAuth.signatureMessage.message,
|
|
9550
|
+
clientAuthPubKey: walletOperationAuth.deviceAuthPublicKey,
|
|
9551
|
+
signature: walletOperationAuth.signatureMessage.signature,
|
|
9552
|
+
encryptedSeed: walletOperationAuth.readyForTransportSeedPhrase,
|
|
9553
|
+
encryptedShares: walletOperationAuth.sharesEncryptedWithWallabyPubKey,
|
|
9714
9554
|
chainName: input.blockchainName,
|
|
9715
9555
|
},
|
|
9716
9556
|
});
|
|
@@ -10551,7 +10391,7 @@ class WalletDataService extends Base {
|
|
|
10551
10391
|
*
|
|
10552
10392
|
* @throws {Error} If required parameters are missing or invalid.
|
|
10553
10393
|
*/
|
|
10554
|
-
async addTokenToWallet({ assetConfigId, walletId, userId, config, }) {
|
|
10394
|
+
async addTokenToWallet({ assetConfigId, walletId, userId, config, authenticationOptions, }) {
|
|
10555
10395
|
try {
|
|
10556
10396
|
if (!walletId) {
|
|
10557
10397
|
throw new WallabyError({
|
|
@@ -10567,14 +10407,25 @@ class WalletDataService extends Base {
|
|
|
10567
10407
|
errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
|
|
10568
10408
|
});
|
|
10569
10409
|
}
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
|
|
10410
|
+
let authPayload = {};
|
|
10411
|
+
if (authenticationOptions) {
|
|
10412
|
+
const walletOperationAuth = await this.walletService.prepareWalletOperationAuth({
|
|
10573
10413
|
walletId,
|
|
10414
|
+
authenticationOptions,
|
|
10415
|
+
});
|
|
10416
|
+
authPayload = {
|
|
10417
|
+
message: walletOperationAuth.signatureMessage.message,
|
|
10418
|
+
clientAuthPubKey: walletOperationAuth.deviceAuthPublicKey,
|
|
10419
|
+
signature: walletOperationAuth.signatureMessage.signature,
|
|
10420
|
+
encryptedSeed: walletOperationAuth.readyForTransportSeedPhrase,
|
|
10421
|
+
encryptedShares: walletOperationAuth.sharesEncryptedWithWallabyPubKey,
|
|
10422
|
+
};
|
|
10423
|
+
}
|
|
10424
|
+
const response = await this.request(WalletRoutes.addTokenToWallet, {
|
|
10425
|
+
payload: Object.assign({ assetConfigId,
|
|
10426
|
+
walletId,
|
|
10574
10427
|
// backend validates and automatically detects userId when none is provided
|
|
10575
|
-
userId: userId || undefined,
|
|
10576
|
-
config,
|
|
10577
|
-
},
|
|
10428
|
+
userId: userId || undefined, config }, authPayload),
|
|
10578
10429
|
});
|
|
10579
10430
|
return response;
|
|
10580
10431
|
}
|
|
@@ -10620,6 +10471,7 @@ class WalletDataService extends Base {
|
|
|
10620
10471
|
assetConfigId: assetConfigId,
|
|
10621
10472
|
walletId: walletId,
|
|
10622
10473
|
userId: userId,
|
|
10474
|
+
authenticationOptions: input.authenticationOptions,
|
|
10623
10475
|
});
|
|
10624
10476
|
return response;
|
|
10625
10477
|
}
|
|
@@ -10999,17 +10851,18 @@ class Swap extends Base {
|
|
|
10999
10851
|
this.walletService = new WalletService(config);
|
|
11000
10852
|
}
|
|
11001
10853
|
/**
|
|
11002
|
-
* Gets a swap quote between two assets
|
|
10854
|
+
* Gets a swap quote between two assets, including fees, min output, and slippage limits.
|
|
11003
10855
|
*
|
|
11004
10856
|
* @public
|
|
11005
10857
|
* @param {SwapQuoteRequest} request - The swap quote request parameters
|
|
11006
10858
|
* @returns {Promise<SwapQuoteResponse>} A promise that resolves with the swap quote
|
|
11007
10859
|
*/
|
|
11008
|
-
async getQuote(
|
|
10860
|
+
async getQuote(request) {
|
|
11009
10861
|
try {
|
|
11010
|
-
|
|
10862
|
+
const { walletId, fromAssetConfigId, toAssetConfigId, fromAmount, toAmount, slippage } = request;
|
|
10863
|
+
if (!walletId || !fromAssetConfigId || !toAssetConfigId) {
|
|
11011
10864
|
throw new WallabyError({
|
|
11012
|
-
message: 'Missing required parameters: walletId,
|
|
10865
|
+
message: 'Missing required parameters: walletId, fromAssetConfigId, and toAssetConfigId',
|
|
11013
10866
|
statusCode: 400,
|
|
11014
10867
|
errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
|
|
11015
10868
|
});
|
|
@@ -11021,10 +10874,16 @@ class Swap extends Base {
|
|
|
11021
10874
|
errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
|
|
11022
10875
|
});
|
|
11023
10876
|
}
|
|
11024
|
-
|
|
10877
|
+
if (fromAmount && toAmount) {
|
|
10878
|
+
throw new WallabyError({
|
|
10879
|
+
message: 'Only one of fromAmount or toAmount may be provided, not both',
|
|
10880
|
+
statusCode: 400,
|
|
10881
|
+
errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
|
|
10882
|
+
});
|
|
10883
|
+
}
|
|
11025
10884
|
const routePayload = { walletId };
|
|
11026
|
-
const requestBody = Object.assign(Object.assign({
|
|
11027
|
-
|
|
10885
|
+
const requestBody = Object.assign(Object.assign(Object.assign({ fromAssetConfigId,
|
|
10886
|
+
toAssetConfigId }, (fromAmount && { fromAmount })), (toAmount && { toAmount })), (slippage != null && { slippage }));
|
|
11028
10887
|
const response = await this.request(Object.assign(Object.assign({}, SwapRoutes.getQuote), { fullPath: SwapRoutes.getQuote.fullPath(routePayload) }), {
|
|
11029
10888
|
payload: requestBody,
|
|
11030
10889
|
});
|
|
@@ -11466,15 +11325,11 @@ class Transactions extends Base {
|
|
|
11466
11325
|
async estimateFee({ originAddress, recipientAddress, amount, transactionType, token, }) {
|
|
11467
11326
|
try {
|
|
11468
11327
|
const response = await this.request(TransactionsRoutes.estimateFee, {
|
|
11469
|
-
queryParams: {
|
|
11470
|
-
chainName: token.chainName,
|
|
11471
|
-
originAddress,
|
|
11328
|
+
queryParams: Object.assign({ chainName: token.chainName, originAddress,
|
|
11472
11329
|
recipientAddress,
|
|
11473
|
-
amount,
|
|
11474
|
-
assetSymbol: token.symbol,
|
|
11475
|
-
transactionType,
|
|
11330
|
+
amount, assetSymbol: token.symbol, transactionType }, (token.tokenStandard && {
|
|
11476
11331
|
tokenStandard: token.tokenStandard,
|
|
11477
|
-
},
|
|
11332
|
+
})),
|
|
11478
11333
|
});
|
|
11479
11334
|
return response;
|
|
11480
11335
|
}
|